tried VAOs, didnt help

This commit is contained in:
aap 2020-05-15 10:55:01 +02:00
parent 90ce0f90be
commit d541301588
7 changed files with 93 additions and 15 deletions

View File

@ -20,6 +20,9 @@ namespace rw {
namespace gl3 { namespace gl3 {
uint32 im2DVbo, im2DIbo; uint32 im2DVbo, im2DIbo;
#ifdef RW_GL_USE_VAOS
uint32 im2DVao;
#endif
static int32 u_xform; static int32 u_xform;
#define STARTINDICES 10000 #define STARTINDICES 10000
@ -65,12 +68,16 @@ openIm2D(void)
glGenBuffers(1, &im2DIbo); glGenBuffers(1, &im2DIbo);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, im2DIbo); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, im2DIbo);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, STARTINDICES*2, nil, GL_STREAM_DRAW); glBufferData(GL_ELEMENT_ARRAY_BUFFER, STARTINDICES*2, nil, GL_STREAM_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glGenBuffers(1, &im2DVbo); glGenBuffers(1, &im2DVbo);
glBindBuffer(GL_ARRAY_BUFFER, im2DVbo); glBindBuffer(GL_ARRAY_BUFFER, im2DVbo);
glBufferData(GL_ARRAY_BUFFER, STARTVERTICES*sizeof(Im2DVertex), nil, GL_STREAM_DRAW); glBufferData(GL_ARRAY_BUFFER, STARTVERTICES*sizeof(Im2DVertex), nil, GL_STREAM_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
#ifdef RW_GL_USE_VAOS
glGenVertexArrays(1, &im2DVao);
glBindVertexArray(im2DVao);
setAttribPointers(im2dattribDesc, 3);
#endif
} }
void void
@ -110,6 +117,10 @@ im2DRenderPrimitive(PrimitiveType primType, void *vertices, int32 numVertices)
Camera *cam; Camera *cam;
cam = (Camera*)engine->currentCamera; cam = (Camera*)engine->currentCamera;
#ifdef RW_GL_USE_VAOS
glBindVertexArray(im2DVao);
#endif
glBindBuffer(GL_ARRAY_BUFFER, im2DVbo); glBindBuffer(GL_ARRAY_BUFFER, im2DVbo);
glBufferData(GL_ARRAY_BUFFER, STARTVERTICES*sizeof(Im2DVertex), nil, GL_STREAM_DRAW); glBufferData(GL_ARRAY_BUFFER, STARTVERTICES*sizeof(Im2DVertex), nil, GL_STREAM_DRAW);
glBufferSubData(GL_ARRAY_BUFFER, 0, numVertices*sizeof(Im2DVertex), vertices); glBufferSubData(GL_ARRAY_BUFFER, 0, numVertices*sizeof(Im2DVertex), vertices);
@ -120,13 +131,17 @@ im2DRenderPrimitive(PrimitiveType primType, void *vertices, int32 numVertices)
xform[3] = 1.0f; xform[3] = 1.0f;
im2dShader->use(); im2dShader->use();
#ifndef RW_GL_USE_VAOS
setAttribPointers(im2dattribDesc, 3); setAttribPointers(im2dattribDesc, 3);
#endif
glUniform4fv(currentShader->uniformLocations[u_xform], 1, xform); glUniform4fv(currentShader->uniformLocations[u_xform], 1, xform);
flushCache(); flushCache();
glDrawArrays(primTypeMap[primType], 0, numVertices); glDrawArrays(primTypeMap[primType], 0, numVertices);
#ifndef RW_GL_USE_VAOS
disableAttribPointers(im2dattribDesc, 3); disableAttribPointers(im2dattribDesc, 3);
#endif
} }
void void
@ -138,7 +153,10 @@ im2DRenderIndexedPrimitive(PrimitiveType primType,
Camera *cam; Camera *cam;
cam = (Camera*)engine->currentCamera; cam = (Camera*)engine->currentCamera;
// TODO: fixed size #ifdef RW_GL_USE_VAOS
glBindVertexArray(im2DVao);
#endif
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, im2DIbo); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, im2DIbo);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, STARTINDICES*2, nil, GL_STREAM_DRAW); glBufferData(GL_ELEMENT_ARRAY_BUFFER, STARTINDICES*2, nil, GL_STREAM_DRAW);
glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, numIndices*2, indices); glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, numIndices*2, indices);
@ -153,14 +171,18 @@ im2DRenderIndexedPrimitive(PrimitiveType primType,
xform[3] = 1.0f; xform[3] = 1.0f;
im2dShader->use(); im2dShader->use();
#ifndef RW_GL_USE_VAOS
setAttribPointers(im2dattribDesc, 3); setAttribPointers(im2dattribDesc, 3);
#endif
glUniform4fv(currentShader->uniformLocations[u_xform], 1, xform); glUniform4fv(currentShader->uniformLocations[u_xform], 1, xform);
flushCache(); flushCache();
glDrawElements(primTypeMap[primType], numIndices, glDrawElements(primTypeMap[primType], numIndices,
GL_UNSIGNED_SHORT, nil); GL_UNSIGNED_SHORT, nil);
#ifndef RW_GL_USE_VAOS
disableAttribPointers(im2dattribDesc, 3); disableAttribPointers(im2dattribDesc, 3);
#endif
} }
@ -177,6 +199,9 @@ static AttribDesc im3dattribDesc[3] = {
sizeof(Im3DVertex), offsetof(Im3DVertex, u) }, sizeof(Im3DVertex), offsetof(Im3DVertex, u) },
}; };
static uint32 im3DVbo, im3DIbo; static uint32 im3DVbo, im3DIbo;
#ifdef RW_GL_USE_VAOS
static uint32 im3DVao;
#endif
static int32 num3DVertices; // not actually needed here static int32 num3DVertices; // not actually needed here
void void
@ -197,12 +222,16 @@ openIm3D(void)
glGenBuffers(1, &im3DIbo); glGenBuffers(1, &im3DIbo);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, im3DIbo); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, im3DIbo);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, STARTINDICES*2, nil, GL_STREAM_DRAW); glBufferData(GL_ELEMENT_ARRAY_BUFFER, STARTINDICES*2, nil, GL_STREAM_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glGenBuffers(1, &im3DVbo); glGenBuffers(1, &im3DVbo);
glBindBuffer(GL_ARRAY_BUFFER, im3DVbo); glBindBuffer(GL_ARRAY_BUFFER, im3DVbo);
glBufferData(GL_ARRAY_BUFFER, STARTVERTICES*sizeof(Im3DVertex), nil, GL_STREAM_DRAW); glBufferData(GL_ARRAY_BUFFER, STARTVERTICES*sizeof(Im3DVertex), nil, GL_STREAM_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
#ifdef RW_GL_USE_VAOS
glGenVertexArrays(1, &im3DVao);
glBindVertexArray(im3DVao);
setAttribPointers(im3dattribDesc, 3);
#endif
} }
void void
@ -228,11 +257,16 @@ im3DTransform(void *vertices, int32 numVertices, Matrix *world, uint32 flags)
if((flags & im3d::VERTEXUV) == 0) if((flags & im3d::VERTEXUV) == 0)
SetRenderStatePtr(TEXTURERASTER, nil); SetRenderStatePtr(TEXTURERASTER, nil);
// TODO: fixed size #ifdef RW_GL_USE_VAOS
glBindVertexArray(im2DVao);
#endif
glBindBuffer(GL_ARRAY_BUFFER, im3DVbo); glBindBuffer(GL_ARRAY_BUFFER, im3DVbo);
glBufferData(GL_ARRAY_BUFFER, STARTVERTICES*sizeof(Im3DVertex), nil, GL_STREAM_DRAW); glBufferData(GL_ARRAY_BUFFER, STARTVERTICES*sizeof(Im3DVertex), nil, GL_STREAM_DRAW);
glBufferSubData(GL_ARRAY_BUFFER, 0, numVertices*sizeof(Im3DVertex), vertices); glBufferSubData(GL_ARRAY_BUFFER, 0, numVertices*sizeof(Im3DVertex), vertices);
#ifndef RW_GL_USE_VAOS
setAttribPointers(im3dattribDesc, 3); setAttribPointers(im3dattribDesc, 3);
#endif
num3DVertices = numVertices; num3DVertices = numVertices;
} }
@ -243,7 +277,6 @@ im3DRenderPrimitive(PrimitiveType primType)
flushCache(); flushCache();
glDrawArrays(primTypeMap[primType], 0, num3DVertices); glDrawArrays(primTypeMap[primType], 0, num3DVertices);
disableAttribPointers(im3dattribDesc, 3);
} }
void void
@ -256,12 +289,14 @@ im3DRenderIndexedPrimitive(PrimitiveType primType, void *indices, int32 numIndic
flushCache(); flushCache();
glDrawElements(primTypeMap[primType], numIndices, glDrawElements(primTypeMap[primType], numIndices,
GL_UNSIGNED_SHORT, nil); GL_UNSIGNED_SHORT, nil);
disableAttribPointers(im3dattribDesc, 3);
} }
void void
im3DEnd(void) im3DEnd(void)
{ {
#ifndef RW_GL_USE_VAOS
disableAttribPointers(im3dattribDesc, 3);
#endif
} }
} }

View File

@ -174,9 +174,13 @@ matfxRenderCB(Atomic *atomic, InstanceDataHeader *header)
setWorldMatrix(atomic->getFrame()->getLTM()); setWorldMatrix(atomic->getFrame()->getLTM());
lightingCB(atomic); lightingCB(atomic);
glBindBuffer(GL_ARRAY_BUFFER, header->vbo); #ifdef RW_GL_USE_VAOS
glBindVertexArray(header->vao);
#else
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, header->ibo); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, header->ibo);
glBindBuffer(GL_ARRAY_BUFFER, header->vbo);
setAttribPointers(header->attribDesc, header->numAttribs); setAttribPointers(header->attribDesc, header->numAttribs);
#endif
lastEnvFrame = nil; lastEnvFrame = nil;
@ -198,7 +202,9 @@ matfxRenderCB(Atomic *atomic, InstanceDataHeader *header)
} }
inst++; inst++;
} }
#ifndef RW_GL_USE_VAOS
disableAttribPointers(header->attribDesc, header->numAttribs); disableAttribPointers(header->attribDesc, header->numAttribs);
#endif
} }
ObjPipeline* ObjPipeline*

View File

@ -32,6 +32,9 @@ freeInstanceData(Geometry *geometry)
geometry->instData = nil; geometry->instData = nil;
glDeleteBuffers(1, &header->ibo); glDeleteBuffers(1, &header->ibo);
glDeleteBuffers(1, &header->vbo); glDeleteBuffers(1, &header->vbo);
#ifdef RW_GL_USE_VAOS
glDeleteBuffers(1, &header->vao);
#endif
rwFree(header->indexBuffer); rwFree(header->indexBuffer);
rwFree(header->vertexBuffer); rwFree(header->vertexBuffer);
rwFree(header->attribDesc); rwFree(header->attribDesc);
@ -86,11 +89,14 @@ instanceMesh(rw::ObjPipeline *rwpipe, Geometry *geo)
header->ibo = 0; header->ibo = 0;
header->vbo = 0; header->vbo = 0;
#ifdef RW_GL_USE_VAOS
glGenVertexArrays(1, &header->vao);
glBindVertexArray(header->vao);
#endif
glGenBuffers(1, &header->ibo); glGenBuffers(1, &header->ibo);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, header->ibo); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, header->ibo);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, header->totalNumIndex*2, glBufferData(GL_ELEMENT_ARRAY_BUFFER, header->totalNumIndex*2,
header->indexBuffer, GL_STATIC_DRAW); header->indexBuffer, GL_STATIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
return header; return header;
} }
@ -282,10 +288,17 @@ defaultInstanceCB(Geometry *geo, InstanceDataHeader *header, bool32 reinstance)
} }
} }
#ifdef RW_GL_USE_VAOS
glBindVertexArray(header->vao);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, header->ibo);
#endif
glBindBuffer(GL_ARRAY_BUFFER, header->vbo); glBindBuffer(GL_ARRAY_BUFFER, header->vbo);
glBufferData(GL_ARRAY_BUFFER, header->totalNumVertex*attribs[0].stride, glBufferData(GL_ARRAY_BUFFER, header->totalNumVertex*attribs[0].stride,
header->vertexBuffer, GL_STATIC_DRAW); header->vertexBuffer, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0); #ifdef RW_GL_USE_VAOS
setAttribPointers(header->attribDesc, header->numAttribs);
glBindVertexArray(0);
#endif
} }
void void

View File

@ -128,9 +128,13 @@ defaultRenderCB(Atomic *atomic, InstanceDataHeader *header)
setWorldMatrix(atomic->getFrame()->getLTM()); setWorldMatrix(atomic->getFrame()->getLTM());
lightingCB(atomic); lightingCB(atomic);
glBindBuffer(GL_ARRAY_BUFFER, header->vbo); #ifdef RW_GL_USE_VAOS
glBindVertexArray(header->vao);
#else
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, header->ibo); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, header->ibo);
glBindBuffer(GL_ARRAY_BUFFER, header->vbo);
setAttribPointers(header->attribDesc, header->numAttribs); setAttribPointers(header->attribDesc, header->numAttribs);
#endif
InstanceData *inst = header->inst; InstanceData *inst = header->inst;
int32 n = header->numMeshes; int32 n = header->numMeshes;
@ -156,7 +160,9 @@ defaultRenderCB(Atomic *atomic, InstanceDataHeader *header)
drawInst(header, inst); drawInst(header, inst);
inst++; inst++;
} }
#ifndef RW_GL_USE_VAOS
disableAttribPointers(header->attribDesc, header->numAttribs); disableAttribPointers(header->attribDesc, header->numAttribs);
#endif
} }

View File

@ -226,10 +226,17 @@ skinInstanceCB(Geometry *geo, InstanceDataHeader *header, bool32 reinstance)
header->totalNumVertex, a->stride); header->totalNumVertex, a->stride);
} }
#ifdef RW_GL_USE_VAOS
glBindVertexArray(header->vao);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, header->ibo);
#endif
glBindBuffer(GL_ARRAY_BUFFER, header->vbo); glBindBuffer(GL_ARRAY_BUFFER, header->vbo);
glBufferData(GL_ARRAY_BUFFER, header->totalNumVertex*attribs[0].stride, glBufferData(GL_ARRAY_BUFFER, header->totalNumVertex*attribs[0].stride,
header->vertexBuffer, GL_STATIC_DRAW); header->vertexBuffer, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0); #ifdef RW_GL_USE_VAOS
setAttribPointers(header->attribDesc, header->numAttribs);
glBindVertexArray(0);
#endif
} }
void void
@ -281,9 +288,13 @@ skinRenderCB(Atomic *atomic, InstanceDataHeader *header)
setWorldMatrix(atomic->getFrame()->getLTM()); setWorldMatrix(atomic->getFrame()->getLTM());
lightingCB(atomic); lightingCB(atomic);
glBindBuffer(GL_ARRAY_BUFFER, header->vbo); #ifdef RW_GL_USE_VAOS
glBindVertexArray(header->vao);
#else
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, header->ibo); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, header->ibo);
glBindBuffer(GL_ARRAY_BUFFER, header->vbo);
setAttribPointers(header->attribDesc, header->numAttribs); setAttribPointers(header->attribDesc, header->numAttribs);
#endif
InstanceData *inst = header->inst; InstanceData *inst = header->inst;
int32 n = header->numMeshes; int32 n = header->numMeshes;
@ -311,7 +322,9 @@ skinRenderCB(Atomic *atomic, InstanceDataHeader *header)
drawInst(header, inst); drawInst(header, inst);
inst++; inst++;
} }
#ifndef RW_GL_USE_VAOS
disableAttribPointers(header->attribDesc, header->numAttribs); disableAttribPointers(header->attribDesc, header->numAttribs);
#endif
} }
ObjPipeline* ObjPipeline*

View File

@ -76,7 +76,7 @@ struct InstanceData
struct InstanceDataHeader : rw::InstanceDataHeader struct InstanceDataHeader : rw::InstanceDataHeader
{ {
uint32 serialNumber; // not really needed right now uint32 serialNumber;
uint32 numMeshes; uint32 numMeshes;
uint16 *indexBuffer; uint16 *indexBuffer;
uint32 primType; uint32 primType;
@ -88,6 +88,9 @@ struct InstanceDataHeader : rw::InstanceDataHeader
uint32 ibo; uint32 ibo;
uint32 vbo; // or 2? uint32 vbo; // or 2?
#ifdef RW_GL_USE_VAOS
uint32 vao;
#endif
InstanceData *inst; InstanceData *inst;
}; };

View File

@ -11,6 +11,8 @@
#ifdef RW_GL3 #ifdef RW_GL3
#define RW_OPENGL #define RW_OPENGL
#define RWDEVICE gl3 #define RWDEVICE gl3
// doesn't help
//#define RW_GL_USE_VAOS
#endif #endif
#ifdef RW_GLES2 #ifdef RW_GLES2