~aavoodoo/+junk/0.2.8-armagetronad-gles2

« back to all changes in this revision

Viewing changes to src/render/rModel.cpp

  • Committer: Voodoo
  • Date: 2011-08-19 09:18:43 UTC
  • Revision ID: erollet@yahoo.fr-20110819091843-opca51tbad5bjsm3
fully removed display lists as they are not compatible with gles and using dl and vbo together is not working well as far as I've seen in different forums and articles

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
#define DONTDOIT
41
41
#include "rRender.h"
42
42
 
43
 
tCONFIG_ENUM(rDisplayListUsage);
44
 
 
45
 
static tConfItem<rDisplayListUsage> mod_udl("USE_DISPLAYLISTS", sr_useDisplayLists);
46
 
 
47
43
#ifndef DEDICATED
48
44
 
49
45
void Vec3::RenderVertex(){
265
261
void rModel::Render(){
266
262
    if (!sr_glOut)
267
263
        return;
268
 
    if ( !displayList_.Call() )
269
 
    {
270
 
        // close pending glBegin() blocks
271
 
        RenderEnd();
272
 
 
273
 
        // model display lists should definitely be compiled before other lists
274
 
        rDisplayList::Cancel();
275
 
 
276
 
        bool texcoord=true;
277
 
        if (texVert.Len()<0)
278
 
            texcoord=false;
279
 
        if (modelTexFaces.Len()!=modelFaces.Len())
280
 
            texcoord=false;
281
 
        if ( !modelTexFacesCoherent )
282
 
            texcoord=false;
283
 
 
284
 
        if (texcoord)
285
 
        {
286
 
            glTexCoordPointer(3,GL_FLOAT,0,&texVert[0]);
287
 
            glEnableClientState(GL_TEXTURE_COORD_ARRAY);
288
 
        }
289
 
 
290
 
           
291
 
 
292
 
        if ( !modelTexFacesCoherent )
293
 
        {
294
 
            rDisplayListFiller filler( displayList_, false );
295
 
            glEnable(GL_CULL_FACE);
296
 
 
297
 
            // sigh, we need to do it the complicated way
298
 
            glBegin( GL_TRIANGLES );
299
 
            for(int i=modelFaces.Len()-1;i>=0;i--)
300
 
            {
301
 
                for(int j=0;j<=2;j++)
302
 
                {
303
 
                    if ( modelTexFaces.Len() > 0 )
304
 
                    {
305
 
                        glTexCoord3fv(reinterpret_cast<REAL *>(&(texVert(modelTexFaces(i).A[j]))));
306
 
                    }
307
 
                    if ( normals.Len() > 0 )
308
 
                    {
309
 
                        glNormal3fv(reinterpret_cast<REAL *>(&(normals(modelFaces(i).A[j]))));
310
 
                    }
311
 
                    glVertex3fv(reinterpret_cast<REAL *>(&(vertices(modelFaces(i).A[j]))));
312
 
                }
313
 
            }
314
 
            glEnd();
315
 
 
316
 
            glDisable(GL_CULL_FACE);
317
 
        }
318
 
        else
319
 
        {
320
 
            // glDrawElements works
321
 
            if (normals.Len()>=vertices.Len())
322
 
            {
323
 
                glNormalPointer(GL_FLOAT,0,&normals[0]);
324
 
                glEnableClientState(GL_NORMAL_ARRAY);
325
 
            }
326
 
            glVertexPointer(3,GL_FLOAT,0,&vertices[0]);
327
 
            glEnableClientState(GL_VERTEX_ARRAY);
328
 
 
329
 
            rDisplayListFiller filler( displayList_, false );
330
 
            glEnable(GL_CULL_FACE);
331
 
 
332
 
            glDrawElements(GL_TRIANGLES,
333
 
                           modelFaces.Len()*3,
334
 
                           GL_UNSIGNED_INT,
335
 
                           &modelFaces(0));
336
 
 
337
 
            glDisable(GL_CULL_FACE);
338
 
        }
339
 
 
340
 
 
341
 
        glDisableClientState(GL_TEXTURE_COORD_ARRAY);
342
 
        glDisableClientState(GL_VERTEX_ARRAY);
343
 
        glDisableClientState(GL_NORMAL_ARRAY);
344
 
    }
 
264
 
 
265
    // close pending glBegin() blocks
 
266
    RenderEnd();
 
267
 
 
268
    bool texcoord=true;
 
269
    if (texVert.Len()<0)
 
270
        texcoord=false;
 
271
    if (modelTexFaces.Len()!=modelFaces.Len())
 
272
        texcoord=false;
 
273
    if ( !modelTexFacesCoherent )
 
274
        texcoord=false;
 
275
 
 
276
    if (texcoord)
 
277
    {
 
278
        glTexCoordPointer(3,GL_FLOAT,0,&texVert[0]);
 
279
        glEnableClientState(GL_TEXTURE_COORD_ARRAY);
 
280
    }
 
281
 
 
282
    if ( !modelTexFacesCoherent )
 
283
    {
 
284
        // sigh, we need to do it the complicated way
 
285
        glBegin( GL_TRIANGLES );
 
286
        for(int i=modelFaces.Len()-1;i>=0;i--)
 
287
        {
 
288
            for(int j=0;j<=2;j++)
 
289
            {
 
290
                if ( modelTexFaces.Len() > 0 )
 
291
                {
 
292
                    glTexCoord3fv(reinterpret_cast<REAL *>(&(texVert(modelTexFaces(i).A[j]))));
 
293
                }
 
294
                if ( normals.Len() > 0 )
 
295
                {
 
296
                    glNormal3fv(reinterpret_cast<REAL *>(&(normals(modelFaces(i).A[j]))));
 
297
                }
 
298
                glVertex3fv(reinterpret_cast<REAL *>(&(vertices(modelFaces(i).A[j]))));
 
299
            }
 
300
        }
 
301
        glEnd();
 
302
 
 
303
        glDisable(GL_CULL_FACE);
 
304
    }
 
305
    else
 
306
    {
 
307
        // glDrawElements works
 
308
        if (normals.Len()>=vertices.Len())
 
309
        {
 
310
            glNormalPointer(GL_FLOAT,0,&normals[0]);
 
311
            glEnableClientState(GL_NORMAL_ARRAY);
 
312
        }
 
313
        glVertexPointer(3,GL_FLOAT,0,&vertices[0]);
 
314
        glEnableClientState(GL_VERTEX_ARRAY);
 
315
 
 
316
        glEnable(GL_CULL_FACE);
 
317
 
 
318
        glDrawElements(GL_TRIANGLES,
 
319
                       modelFaces.Len()*3,
 
320
                       GL_UNSIGNED_INT,
 
321
                       &modelFaces(0));
 
322
 
 
323
        glDisable(GL_CULL_FACE);
 
324
    }
 
325
 
 
326
 
 
327
    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
 
328
    glDisableClientState(GL_VERTEX_ARRAY);
 
329
    glDisableClientState(GL_NORMAL_ARRAY);
345
330
}
346
331
#endif
347
332