Shader::SetUniform override, and implement most of the FBO code for the Direct3D backend.legacy
@@ -44,6 +44,8 @@ class FrameBufferData | |||||
ivec2 m_size; | ivec2 m_size; | ||||
#if defined USE_D3D9 | #if defined USE_D3D9 | ||||
LPDIRECT3DTEXTURE9 m_texture; | |||||
LPDIRECT3DSURFACE9 m_surface, m_back_surface; | |||||
#elif defined _XBOX | #elif defined _XBOX | ||||
#else | #else | ||||
GLuint m_fbo, m_texture, m_depth; | GLuint m_fbo, m_texture, m_depth; | ||||
@@ -60,7 +62,13 @@ FrameBuffer::FrameBuffer(ivec2 size) | |||||
{ | { | ||||
m_data->m_size = size; | m_data->m_size = size; | ||||
#if defined USE_D3D9 || defined _XBOX | #if defined USE_D3D9 || defined _XBOX | ||||
/* FIXME: not implemented on Direct3D */ | |||||
if (FAILED(g_d3ddevice->CreateTexture(size.x, size.y, 1, | |||||
D3DUSAGE_RENDERTARGET, | |||||
D3DFMT_R8G8B8, D3DPOOL_DEFAULT, | |||||
&m_data->m_texture, NULL))) | |||||
Abort(); | |||||
if (FAILED(m_data->m_texture->GetSurfaceLevel(0, &m_data->m_surface))) | |||||
Abort(); | |||||
#else | #else | ||||
# if GL_VERSION_1_1 | # if GL_VERSION_1_1 | ||||
GLenum internal_format = GL_RGBA8; | GLenum internal_format = GL_RGBA8; | ||||
@@ -124,6 +132,8 @@ FrameBuffer::FrameBuffer(ivec2 size) | |||||
FrameBuffer::~FrameBuffer() | FrameBuffer::~FrameBuffer() | ||||
{ | { | ||||
#if defined USE_D3D9 || defined _XBOX | #if defined USE_D3D9 || defined _XBOX | ||||
m_data->m_surface->Release(); | |||||
m_data->m_texture->Release(); | |||||
#else | #else | ||||
# if GL_VERSION_1_1 || GL_ES_VERSION_2_0 | # if GL_VERSION_1_1 || GL_ES_VERSION_2_0 | ||||
glDeleteFramebuffers(1, &m_data->m_fbo); | glDeleteFramebuffers(1, &m_data->m_fbo); | ||||
@@ -139,18 +149,24 @@ FrameBuffer::~FrameBuffer() | |||||
delete m_data; | delete m_data; | ||||
} | } | ||||
int FrameBuffer::GetTexture() const | |||||
ShaderTexture FrameBuffer::GetTexture() const | |||||
{ | { | ||||
ShaderTexture ret; | |||||
#if defined USE_D3D9 || defined _XBOX | #if defined USE_D3D9 || defined _XBOX | ||||
return 0; | |||||
ret.m_flags = (uint64_t)(uintptr_t)m_data->m_texture; | |||||
#else | #else | ||||
return m_data->m_texture; | |||||
ret.m_flags = m_data->m_texture; | |||||
#endif | #endif | ||||
return ret; | |||||
} | } | ||||
void FrameBuffer::Bind() | void FrameBuffer::Bind() | ||||
{ | { | ||||
#if defined USE_D3D9 || defined _XBOX | #if defined USE_D3D9 || defined _XBOX | ||||
if (FAILED(g_d3ddevice->GetRenderTarget(0, &m_data->m_back_surface))) | |||||
Abort(); | |||||
if (FAILED(g_d3ddevice->SetRenderTarget(0, m_data->m_surface))) | |||||
Abort(); | |||||
#else | #else | ||||
# if GL_VERSION_1_1 || GL_ES_VERSION_2_0 | # if GL_VERSION_1_1 || GL_ES_VERSION_2_0 | ||||
glBindFramebuffer(GL_FRAMEBUFFER, m_data->m_fbo); | glBindFramebuffer(GL_FRAMEBUFFER, m_data->m_fbo); | ||||
@@ -163,6 +179,8 @@ void FrameBuffer::Bind() | |||||
void FrameBuffer::Unbind() | void FrameBuffer::Unbind() | ||||
{ | { | ||||
#if defined USE_D3D9 || defined _XBOX | #if defined USE_D3D9 || defined _XBOX | ||||
if (FAILED(g_d3ddevice->SetRenderTarget(0, m_data->m_back_surface))) | |||||
Abort(); | |||||
#else | #else | ||||
# if GL_VERSION_1_1 || GL_ES_VERSION_2_0 | # if GL_VERSION_1_1 || GL_ES_VERSION_2_0 | ||||
glBindFramebuffer(GL_FRAMEBUFFER, NULL); | glBindFramebuffer(GL_FRAMEBUFFER, NULL); | ||||
@@ -27,9 +27,7 @@ public: | |||||
FrameBuffer(ivec2 size); | FrameBuffer(ivec2 size); | ||||
~FrameBuffer(); | ~FrameBuffer(); | ||||
int GetTexture() const; | |||||
void Clear(vec4 color); | |||||
void Clear(vec4 color, float depth); | |||||
ShaderTexture GetTexture() const; | |||||
void Bind(); | void Bind(); | ||||
void Unbind(); | void Unbind(); | ||||
@@ -536,14 +536,14 @@ void Shader::SetUniform(ShaderUniform const &uni, mat4 const &m) | |||||
#endif | #endif | ||||
} | } | ||||
void Shader::SetTexture(ShaderUniform const &uni, int id, int index) | |||||
void Shader::SetUniform(ShaderUniform const &uni, ShaderTexture tex, int index) | |||||
{ | { | ||||
#if defined USE_D3D9 || defined _XBOX | #if defined USE_D3D9 || defined _XBOX | ||||
/* FIXME: unimplemented */ | |||||
g_d3ddevice->SetTexture(index, (LPDIRECT3DTEXTURE9)tex.m_flags); | |||||
#elif !defined __CELLOS_LV2__ | #elif !defined __CELLOS_LV2__ | ||||
glActiveTexture(GL_TEXTURE0 + index); | glActiveTexture(GL_TEXTURE0 + index); | ||||
//glEnable(GL_TEXTURE_2D); | //glEnable(GL_TEXTURE_2D); | ||||
glBindTexture(GL_TEXTURE_2D, id); | |||||
glBindTexture(GL_TEXTURE_2D, (int)tex.m_flags); | |||||
SetUniform(uni, index); | SetUniform(uni, index); | ||||
#else | #else | ||||
/* FIXME: unimplemented */ | /* FIXME: unimplemented */ | ||||
@@ -46,6 +46,18 @@ private: | |||||
uint64_t m_flags; | uint64_t m_flags; | ||||
}; | }; | ||||
struct ShaderTexture | |||||
{ | |||||
friend class Shader; | |||||
friend class FrameBuffer; | |||||
public: | |||||
inline ShaderTexture() : m_flags(0) {} | |||||
private: | |||||
uint64_t m_flags; | |||||
}; | |||||
class ShaderData; | class ShaderData; | ||||
class Shader | class Shader | ||||
@@ -70,10 +82,7 @@ public: | |||||
void SetUniform(ShaderUniform const &uni, mat2 const &m); | void SetUniform(ShaderUniform const &uni, mat2 const &m); | ||||
void SetUniform(ShaderUniform const &uni, mat3 const &m); | void SetUniform(ShaderUniform const &uni, mat3 const &m); | ||||
void SetUniform(ShaderUniform const &uni, mat4 const &m); | void SetUniform(ShaderUniform const &uni, mat4 const &m); | ||||
/* FIXME: this should be called SetUniform, too, but we need a new | |||||
* type to represent textures. */ | |||||
void SetTexture(ShaderUniform const &uni, int id, int index); | |||||
void SetUniform(ShaderUniform const &uni, ShaderTexture tex, int index); | |||||
void Bind() const; | void Bind() const; | ||||
void Unbind() const; | void Unbind() const; | ||||
@@ -102,7 +102,7 @@ public: | |||||
m_shader->Bind(); | m_shader->Bind(); | ||||
m_shader->SetUniform(m_uni_flag, 1.f); | m_shader->SetUniform(m_uni_flag, 1.f); | ||||
m_shader->SetTexture(m_uni_texture, m_fbo->GetTexture(), 0); | |||||
m_shader->SetUniform(m_uni_texture, m_fbo->GetTexture(), 0); | |||||
m_vdecl->SetStream(m_vbo, m_coord); | m_vdecl->SetStream(m_vbo, m_coord); | ||||
m_vdecl->Bind(); | m_vdecl->Bind(); | ||||
m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 2); | m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 2); | ||||