Changeset 1233


Ignore:
Timestamp:
Apr 16, 2012, 8:25:05 PM (8 years ago)
Author:
sam
Message:

gpu: add an Unbind() method for textures for clean up. Unfortunately
the Scene code still breaks Direct3D rendering.

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/gradient.cpp

    r1229 r1233  
    1515#include <cmath>
    1616
    17 #ifdef WIN32
    18 #   define WIN32_LEAN_AND_MEAN
    19 #   include <windows.h>
    20 #   if defined USE_D3D9
    21 #       include <algorithm>
    22         using std::min;
    23         using std::max;
    24 #       include <d3d9.h>
    25 #       include <d3dx9shader.h>
    26 #   endif
    27 #endif
    28 
    2917#include "core.h"
    3018#include "lolgl.h"
    3119
    3220using namespace std;
    33 
    34 #if defined USE_D3D9
    35 extern IDirect3DDevice9 *g_d3ddevice;
    36 #elif defined _XBOX
    37 extern D3DDevice *g_d3ddevice;
    38 #endif
    3921
    4022namespace lol
     
    222204
    223205    /* Draw arrays */
    224 #if defined _XBOX || defined USE_D3D9
    225     g_d3ddevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 2);
    226 #else
    227     glDrawArrays(GL_TRIANGLES, 0, 6);
    228 #endif
     206    data->m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 2);
    229207}
    230208
  • trunk/src/scene.cpp

    r1230 r1233  
    111111    free(data->bufs);
    112112#endif
     113    delete data->m_vdecl;
    113114    delete data;
    114115}
     
    327328    stdshader->SetUniform(uni_mat, data->model_matrix);
    328329
    329     data->m_vdecl->Bind();
    330330#if defined USE_D3D9 || defined _XBOX
    331     //g_d3ddevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW);
    332     g_d3ddevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
    333331#else
    334332    uni_tex = stdshader->GetUniformLocation("in_Texture");
     
    390388
    391389        /* Bind vertex and texture coordinate buffers */
     390        data->m_vdecl->Bind();
    392391        data->m_vdecl->SetStream(data->bufs[buf], attr_pos);
    393392        data->m_vdecl->SetStream(data->bufs[buf + 1], attr_tex);
    394393
    395394        /* Draw arrays */
    396 #if defined USE_D3D9 || defined _XBOX
    397         g_d3ddevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, (n - i) * 2);
    398 #else
    399         glDrawArrays(GL_TRIANGLES, 0, (n - i) * 6);
    400 
    401 #   if defined HAVE_GL_2X && !defined __APPLE__
    402         //glBindVertexArray(0);
    403 #   endif
    404 #   if !defined __CELLOS_LV2__ // Use cgGLEnableClientState etc.
    405 #   else
    406         //glDisableClientState(GL_VERTEX_ARRAY);
    407         //glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    408 #   endif
    409 #endif
     395#if 0
     396        data->m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, (n - i) * 2);
     397#endif
     398        data->m_vdecl->Unbind();
     399        data->tiles[i].tileset->Unbind();
    410400    }
    411401
  • trunk/src/tileset.cpp

    r1221 r1233  
    238238}
    239239
     240void TileSet::Unbind()
     241{
     242#if defined USE_D3D9 || defined _XBOX
     243    g_d3ddevice->SetTexture(0, NULL);
     244#else
     245    glActiveTexture(GL_TEXTURE0);
     246    glBindTexture(GL_TEXTURE_2D, 0);
     247#endif
     248}
     249
    240250void TileSet::BlitTile(uint32_t id, vec3 pos, int o, vec2 scale,
    241251                       float *vertex, float *texture)
  • trunk/src/tileset.h

    r1198 r1233  
    4545    ivec2 GetSize(int tileid) const;
    4646    void Bind();
     47    void Unbind();
    4748    void BlitTile(uint32_t id, vec3 pos, int o, vec2 scale,
    4849                  float *vertex, float *texture);
  • trunk/src/video.cpp

    r1208 r1233  
    1515#include <cmath>
    1616
    17 #if defined USE_D3D9
    18 #   include <d3d9.h>
    19 #elif defined _XBOX
     17#if defined _XBOX
    2018#   include <xtl.h>
    2119#   undef near /* Fuck Microsoft */
    2220#   undef far /* Fuck Microsoft again */
    2321#elif defined _WIN32
     22#   if defined USE_D3D9
     23#      include <d3d9.h>
     24#   endif
    2425#   define WIN32_LEAN_AND_MEAN
    2526#   include <windows.h>
  • trunk/test/tutorial/tut02.cpp

    r1228 r1233  
    205205        glDisableClientState(GL_VERTEX_ARRAY);
    206206#endif
     207        m_vdecl->Unbind();
    207208    }
    208209
Note: See TracChangeset for help on using the changeset viewer.