Browse Source

gpu: create the ShaderTexture class, replace Shader::SetTexture with a

Shader::SetUniform override, and implement most of the FBO code for
the Direct3D backend.
legacy
Sam Hocevar sam 12 years ago
parent
commit
7d5fe8a7c6
5 changed files with 40 additions and 15 deletions
  1. +22
    -4
      src/gpu/framebuffer.cpp
  2. +1
    -3
      src/gpu/framebuffer.h
  3. +3
    -3
      src/gpu/shader.cpp
  4. +13
    -4
      src/gpu/shader.h
  5. +1
    -1
      tutorial/08_fbo.cpp

+ 22
- 4
src/gpu/framebuffer.cpp View File

@@ -44,6 +44,8 @@ class FrameBufferData
ivec2 m_size;

#if defined USE_D3D9
LPDIRECT3DTEXTURE9 m_texture;
LPDIRECT3DSURFACE9 m_surface, m_back_surface;
#elif defined _XBOX
#else
GLuint m_fbo, m_texture, m_depth;
@@ -60,7 +62,13 @@ FrameBuffer::FrameBuffer(ivec2 size)
{
m_data->m_size = size;
#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
# if GL_VERSION_1_1
GLenum internal_format = GL_RGBA8;
@@ -124,6 +132,8 @@ FrameBuffer::FrameBuffer(ivec2 size)
FrameBuffer::~FrameBuffer()
{
#if defined USE_D3D9 || defined _XBOX
m_data->m_surface->Release();
m_data->m_texture->Release();
#else
# if GL_VERSION_1_1 || GL_ES_VERSION_2_0
glDeleteFramebuffers(1, &m_data->m_fbo);
@@ -139,18 +149,24 @@ FrameBuffer::~FrameBuffer()
delete m_data;
}

int FrameBuffer::GetTexture() const
ShaderTexture FrameBuffer::GetTexture() const
{
ShaderTexture ret;
#if defined USE_D3D9 || defined _XBOX
return 0;
ret.m_flags = (uint64_t)(uintptr_t)m_data->m_texture;
#else
return m_data->m_texture;
ret.m_flags = m_data->m_texture;
#endif
return ret;
}

void FrameBuffer::Bind()
{
#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
# if GL_VERSION_1_1 || GL_ES_VERSION_2_0
glBindFramebuffer(GL_FRAMEBUFFER, m_data->m_fbo);
@@ -163,6 +179,8 @@ void FrameBuffer::Bind()
void FrameBuffer::Unbind()
{
#if defined USE_D3D9 || defined _XBOX
if (FAILED(g_d3ddevice->SetRenderTarget(0, m_data->m_back_surface)))
Abort();
#else
# if GL_VERSION_1_1 || GL_ES_VERSION_2_0
glBindFramebuffer(GL_FRAMEBUFFER, NULL);


+ 1
- 3
src/gpu/framebuffer.h View File

@@ -27,9 +27,7 @@ public:
FrameBuffer(ivec2 size);
~FrameBuffer();

int GetTexture() const;
void Clear(vec4 color);
void Clear(vec4 color, float depth);
ShaderTexture GetTexture() const;

void Bind();
void Unbind();


+ 3
- 3
src/gpu/shader.cpp View File

@@ -536,14 +536,14 @@ void Shader::SetUniform(ShaderUniform const &uni, mat4 const &m)
#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
/* FIXME: unimplemented */
g_d3ddevice->SetTexture(index, (LPDIRECT3DTEXTURE9)tex.m_flags);
#elif !defined __CELLOS_LV2__
glActiveTexture(GL_TEXTURE0 + index);
//glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, id);
glBindTexture(GL_TEXTURE_2D, (int)tex.m_flags);
SetUniform(uni, index);
#else
/* FIXME: unimplemented */


+ 13
- 4
src/gpu/shader.h View File

@@ -46,6 +46,18 @@ private:
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 Shader
@@ -70,10 +82,7 @@ public:
void SetUniform(ShaderUniform const &uni, mat2 const &m);
void SetUniform(ShaderUniform const &uni, mat3 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 Unbind() const;


+ 1
- 1
tutorial/08_fbo.cpp View File

@@ -102,7 +102,7 @@ public:

m_shader->Bind();
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->Bind();
m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 2);


Loading…
Cancel
Save