Changeset 1773


Ignore:
Timestamp:
Aug 18, 2012, 9:26:03 PM (8 years ago)
Author:
sam
Message:

gpu: create the ShaderTexture class, replace Shader::SetTexture with a
Shader::SetUniform override, and implement most of the FBO code for
the Direct3D backend.

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/gpu/framebuffer.cpp

    r1761 r1773  
    4545
    4646#if defined USE_D3D9
     47    LPDIRECT3DTEXTURE9 m_texture;
     48    LPDIRECT3DSURFACE9 m_surface, m_back_surface;
    4749#elif defined _XBOX
    4850#else
     
    6163    m_data->m_size = size;
    6264#if defined USE_D3D9 || defined _XBOX
    63     /* FIXME: not implemented on Direct3D */
     65    if (FAILED(g_d3ddevice->CreateTexture(size.x, size.y, 1,
     66                                          D3DUSAGE_RENDERTARGET,
     67                                          D3DFMT_R8G8B8, D3DPOOL_DEFAULT,
     68                                          &m_data->m_texture, NULL)))
     69        Abort();
     70    if (FAILED(m_data->m_texture->GetSurfaceLevel(0, &m_data->m_surface)))
     71        Abort();
    6472#else
    6573#   if GL_VERSION_1_1
     
    125133{
    126134#if defined USE_D3D9 || defined _XBOX
     135    m_data->m_surface->Release();
     136    m_data->m_texture->Release();
    127137#else
    128138#   if GL_VERSION_1_1 || GL_ES_VERSION_2_0
     
    140150}
    141151
    142 int FrameBuffer::GetTexture() const
     152ShaderTexture FrameBuffer::GetTexture() const
    143153{
     154    ShaderTexture ret;
    144155#if defined USE_D3D9 || defined _XBOX
    145     return 0;
     156    ret.m_flags = (uint64_t)(uintptr_t)m_data->m_texture;
    146157#else
    147     return m_data->m_texture;
     158    ret.m_flags = m_data->m_texture;
    148159#endif
     160    return ret;
    149161}
    150162
     
    152164{
    153165#if defined USE_D3D9 || defined _XBOX
     166    if (FAILED(g_d3ddevice->GetRenderTarget(0, &m_data->m_back_surface)))
     167        Abort();
     168    if (FAILED(g_d3ddevice->SetRenderTarget(0, m_data->m_surface)))
     169        Abort();
    154170#else
    155171#   if GL_VERSION_1_1 || GL_ES_VERSION_2_0
     
    164180{
    165181#if defined USE_D3D9 || defined _XBOX
     182    if (FAILED(g_d3ddevice->SetRenderTarget(0, m_data->m_back_surface)))
     183        Abort();
    166184#else
    167185#   if GL_VERSION_1_1 || GL_ES_VERSION_2_0
  • trunk/src/gpu/framebuffer.h

    r1455 r1773  
    2828    ~FrameBuffer();
    2929
    30     int GetTexture() const;
    31     void Clear(vec4 color);
    32     void Clear(vec4 color, float depth);
     30    ShaderTexture GetTexture() const;
    3331
    3432    void Bind();
  • trunk/src/gpu/shader.cpp

    r1690 r1773  
    537537}
    538538
    539 void Shader::SetTexture(ShaderUniform const &uni, int id, int index)
    540 {
    541 #if defined USE_D3D9 || defined _XBOX
    542     /* FIXME: unimplemented */
     539void Shader::SetUniform(ShaderUniform const &uni, ShaderTexture tex, int index)
     540{
     541#if defined USE_D3D9 || defined _XBOX
     542    g_d3ddevice->SetTexture(index, (LPDIRECT3DTEXTURE9)tex.m_flags);
    543543#elif !defined __CELLOS_LV2__
    544544    glActiveTexture(GL_TEXTURE0 + index);
    545545    //glEnable(GL_TEXTURE_2D);
    546     glBindTexture(GL_TEXTURE_2D, id);
     546    glBindTexture(GL_TEXTURE_2D, (int)tex.m_flags);
    547547    SetUniform(uni, index);
    548548#else
  • trunk/src/gpu/shader.h

    r1452 r1773  
    4747};
    4848
     49struct ShaderTexture
     50{
     51    friend class Shader;
     52    friend class FrameBuffer;
     53
     54public:
     55    inline ShaderTexture() : m_flags(0) {}
     56
     57private:
     58    uint64_t m_flags;
     59};
     60
    4961class ShaderData;
    5062
     
    7183    void SetUniform(ShaderUniform const &uni, mat3 const &m);
    7284    void SetUniform(ShaderUniform const &uni, mat4 const &m);
    73 
    74     /* FIXME: this should be called SetUniform, too, but we need a new
    75      * type to represent textures. */
    76     void SetTexture(ShaderUniform const &uni, int id, int index);
     85    void SetUniform(ShaderUniform const &uni, ShaderTexture tex, int index);
    7786
    7887    void Bind() const;
  • trunk/tools/neercs/video/render.cpp

    r1771 r1773  
    417417{
    418418    shader_simple->Bind();
    419     shader_simple->SetTexture(shader_simple_texture, fbo_output->GetTexture(), n);
     419    shader_simple->SetUniform(shader_simple_texture, fbo_output->GetTexture(), n);
    420420    fs_quad();
    421421    shader_simple->Unbind();
     
    858858        fbo_ping->Bind();
    859859        shader_remanency->Bind();
    860         shader_remanency->SetTexture(shader_remanency_source, fbo_back->GetTexture(), 0);
    861         shader_remanency->SetTexture(shader_remanency_buffer, fbo_buffer->GetTexture(), 1);
     860        shader_remanency->SetUniform(shader_remanency_source, fbo_back->GetTexture(), 0);
     861        shader_remanency->SetUniform(shader_remanency_buffer, fbo_buffer->GetTexture(), 1);
    862862        shader_remanency->SetUniform(shader_remanency_mix, remanency);
    863863        fs_quad();
     
    871871        fbo_ping->Bind();
    872872        shader_remanency->Bind();
    873         shader_remanency->SetTexture(shader_remanency_source, fbo_front->GetTexture(), 0);
    874         shader_remanency->SetTexture(shader_remanency_buffer, fbo_buffer->GetTexture(), 1);
     873        shader_remanency->SetUniform(shader_remanency_source, fbo_front->GetTexture(), 0);
     874        shader_remanency->SetUniform(shader_remanency_buffer, fbo_buffer->GetTexture(), 1);
    875875        shader_remanency->SetUniform(shader_remanency_mix, buffer);
    876876        fs_quad();
     
    889889        fbo_blur_h->Bind();
    890890        shader_blur_h->Bind();
    891         shader_blur_h->SetTexture(shader_blur_h_texture, fbo_back->GetTexture(), 0);
     891        shader_blur_h->SetUniform(shader_blur_h_texture, fbo_back->GetTexture(), 0);
    892892        shader_blur_h->SetUniform(shader_blur_h_radius, glow_large / screen_size.x);
    893893        fs_quad();
     
    897897        fbo_blur_v->Bind();
    898898        shader_blur_v->Bind();
    899         shader_blur_v->SetTexture(shader_blur_v_texture, fbo_blur_h->GetTexture(), 0);
     899        shader_blur_v->SetUniform(shader_blur_v_texture, fbo_blur_h->GetTexture(), 0);
    900900        shader_blur_v->SetUniform(shader_blur_v_radius, glow_large / screen_size.y);
    901901        fs_quad();
     
    905905        fbo_blur_h->Bind();
    906906        shader_blur_h->Bind();
    907         shader_blur_h->SetTexture(shader_blur_h_texture, fbo_blur_v->GetTexture(), 0);
     907        shader_blur_h->SetUniform(shader_blur_h_texture, fbo_blur_v->GetTexture(), 0);
    908908        shader_blur_h->SetUniform(shader_blur_h_radius, glow_small / screen_size.x);
    909909        fs_quad();
     
    913913        fbo_blur_v->Bind();
    914914        shader_blur_v->Bind();
    915         shader_blur_v->SetTexture(shader_blur_v_texture, fbo_blur_h->GetTexture(), 0);
     915        shader_blur_v->SetUniform(shader_blur_v_texture, fbo_blur_h->GetTexture(), 0);
    916916        shader_blur_v->SetUniform(shader_blur_v_radius, glow_small / screen_size.y);
    917917        fs_quad();
     
    921921        fbo_front->Bind();
    922922        shader_glow->Bind();
    923         shader_glow->SetTexture(shader_glow_glow, fbo_blur_v->GetTexture(), 0);
    924         shader_glow->SetTexture(shader_glow_source, fbo_back->GetTexture(), 1);
     923        shader_glow->SetUniform(shader_glow_glow, fbo_blur_v->GetTexture(), 0);
     924        shader_glow->SetUniform(shader_glow_source, fbo_back->GetTexture(), 1);
    925925        shader_glow->SetUniform(shader_glow_mix, glow_mix);
    926926        fs_quad();
     
    941941        fbo_ping->Bind();
    942942        shader_blur_h->Bind();
    943         shader_blur_h->SetTexture(shader_blur_h_texture, fbo_front->GetTexture(), 0);
     943        shader_blur_h->SetUniform(shader_blur_h_texture, fbo_front->GetTexture(), 0);
    944944        shader_blur_h->SetUniform(shader_blur_h_radius, blur / screen_size.x);
    945945        fs_quad();
     
    949949        fbo_front->Bind();
    950950        shader_blur_v->Bind();
    951         shader_blur_v->SetTexture(shader_blur_v_texture, fbo_ping->GetTexture(), 0);
     951        shader_blur_v->SetUniform(shader_blur_v_texture, fbo_ping->GetTexture(), 0);
    952952        shader_blur_v->SetUniform(shader_blur_v_radius, blur / screen_size.y);
    953953        fs_quad();
     
    960960        // shader postfx
    961961        shader_postfx->Bind();
    962         shader_postfx->SetTexture(shader_postfx_texture, fbo_front->GetTexture(), 0);
     962        shader_postfx->SetUniform(shader_postfx_texture, fbo_front->GetTexture(), 0);
    963963        shader_postfx->SetUniform(shader_postfx_screen_size, (vec2)screen_size);
    964964        shader_postfx->SetUniform(shader_postfx_time, fx_angle);
  • trunk/tools/neercs/video/text-render.cpp

    r1706 r1773  
    151151void TextRender::Blit(ivec2 pos, ivec2 size)
    152152{
     153    /* FIXME: this is ugly! But we will get rid of it when we
     154     * do the Direct3D port, so don't worry too much. */
     155    ShaderTexture t = m_fbo->GetTexture();
     156    uint64_t const &x = *(uint64_t const *)&t;
     157
    153158    glDisable(GL_BLEND);
    154159    glEnable(GL_TEXTURE_2D);
    155     glBindTexture(GL_TEXTURE_2D, m_fbo->GetTexture());
     160    glBindTexture(GL_TEXTURE_2D, (int)x);
    156161    glColor3f(1.0f, 1.0f, 1.0f);
    157162
     
    170175    glEnd();
    171176}
     177
  • trunk/tutorial/08_fbo.cpp

    r1771 r1773  
    103103        m_shader->Bind();
    104104        m_shader->SetUniform(m_uni_flag, 1.f);
    105         m_shader->SetTexture(m_uni_texture, m_fbo->GetTexture(), 0);
     105        m_shader->SetUniform(m_uni_texture, m_fbo->GetTexture(), 0);
    106106        m_vdecl->SetStream(m_vbo, m_coord);
    107107        m_vdecl->Bind();
Note: See TracChangeset for help on using the changeset viewer.