From 7f93c4a0c143db64985895cca15f347bd95b0fcd Mon Sep 17 00:00:00 2001 From: havoc Date: Thu, 28 Feb 2013 11:41:40 +0000 Subject: [PATCH] implemented r_batch_dynamicbuffer which allows the rsurface batching code to produce dynamic vertex/index buffers using R_BufferData_Store git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@11920 d7cf8633-e32d-0410-b094-e92efae38249 --- cl_screen.c | 2 +- client.h | 20 +++-- gl_backend.c | 76 +++++++++---------- gl_backend.h | 6 +- gl_rmain.c | 197 +++++++++++++++++++++++++++++++++---------------- gl_rsurf.c | 5 +- model_shared.c | 43 ++--------- model_shared.h | 47 ++++++------ r_shadow.c | 20 ++--- render.h | 54 +++++++------- 10 files changed, 254 insertions(+), 216 deletions(-) diff --git a/cl_screen.c b/cl_screen.c index 249ee222..7d476645 100644 --- a/cl_screen.c +++ b/cl_screen.c @@ -314,7 +314,7 @@ static void SCR_DrawNetGraph_DrawGraph (int graphx, int graphy, int graphwidth, } if (numlines > 0) { - R_Mesh_PrepareVertices_Generic(numlines*2, vertex, NULL); + R_Mesh_PrepareVertices_Generic(numlines*2, vertex, NULL, 0); DrawQ_Lines(0.0f, numlines, 0, false); } x = graphx; diff --git a/client.h b/client.h index 29de924a..becccd5a 100644 --- a/client.h +++ b/client.h @@ -539,14 +539,22 @@ typedef struct entity_render_s // animation cache (pointers allocated using R_FrameData_Alloc) // ONLY valid during R_RenderView! may be NULL (not cached) - float *animcache_vertex3f; - float *animcache_normal3f; - float *animcache_svector3f; - float *animcache_tvector3f; + float *animcache_vertex3f; + r_meshbuffer_t *animcache_vertex3f_vertexbuffer; + int animcache_vertex3f_bufferoffset; + float *animcache_normal3f; + r_meshbuffer_t *animcache_normal3f_vertexbuffer; + int animcache_normal3f_bufferoffset; + float *animcache_svector3f; + r_meshbuffer_t *animcache_svector3f_vertexbuffer; + int animcache_svector3f_bufferoffset; + float *animcache_tvector3f; + r_meshbuffer_t *animcache_tvector3f_vertexbuffer; + int animcache_tvector3f_bufferoffset; // interleaved arrays for rendering and dynamic vertex buffers for them - r_meshbuffer_t *animcache_vertex3fbuffer; r_vertexmesh_t *animcache_vertexmesh; - r_meshbuffer_t *animcache_vertexmeshbuffer; + r_meshbuffer_t *animcache_vertexmesh_vertexbuffer; + int animcache_vertexmesh_bufferoffset; // gpu-skinning shader needs transforms in a certain format, we have to // upload this to a uniform buffer for the shader to use, and also keep a // backup copy in system memory for the dynamic batch fallback code diff --git a/gl_backend.c b/gl_backend.c index 981c9ec2..e435aef0 100644 --- a/gl_backend.c +++ b/gl_backend.c @@ -4225,7 +4225,7 @@ static void R_Mesh_DestroyVertexDeclarations(void) #endif } -void R_Mesh_PrepareVertices_Vertex3f(int numvertices, const float *vertex3f, const r_meshbuffer_t *vertexbuffer) +void R_Mesh_PrepareVertices_Vertex3f(int numvertices, const float *vertex3f, const r_meshbuffer_t *vertexbuffer, int bufferoffset) { // upload temporary vertexbuffer for this rendering if (!gl_state.usevbo_staticvertex) @@ -4244,7 +4244,7 @@ void R_Mesh_PrepareVertices_Vertex3f(int numvertices, const float *vertex3f, con case RENDERPATH_GLES2: if (vertexbuffer) { - R_Mesh_VertexPointer(3, GL_FLOAT, sizeof(float[3]), vertex3f, vertexbuffer, 0); + R_Mesh_VertexPointer(3, GL_FLOAT, sizeof(float[3]), vertex3f, vertexbuffer, bufferoffset); R_Mesh_ColorPointer(4, GL_FLOAT, sizeof(float[4]), NULL, NULL, 0); R_Mesh_TexCoordPointer(0, 2, GL_FLOAT, sizeof(float[2]), NULL, NULL, 0); R_Mesh_TexCoordPointer(1, 2, GL_FLOAT, sizeof(float[2]), NULL, NULL, 0); @@ -4273,7 +4273,7 @@ void R_Mesh_PrepareVertices_Vertex3f(int numvertices, const float *vertex3f, con case RENDERPATH_GLES1: if (vertexbuffer) { - R_Mesh_VertexPointer(3, GL_FLOAT, sizeof(float[3]), vertex3f, vertexbuffer, 0); + R_Mesh_VertexPointer(3, GL_FLOAT, sizeof(float[3]), vertex3f, vertexbuffer, bufferoffset); R_Mesh_ColorPointer(4, GL_FLOAT, sizeof(float[4]), NULL, NULL, 0); R_Mesh_TexCoordPointer(0, 2, GL_FLOAT, sizeof(float[2]), NULL, NULL, 0); R_Mesh_TexCoordPointer(1, 2, GL_FLOAT, sizeof(float[2]), NULL, NULL, 0); @@ -4289,7 +4289,7 @@ void R_Mesh_PrepareVertices_Vertex3f(int numvertices, const float *vertex3f, con case RENDERPATH_GL11: if (vertexbuffer) { - R_Mesh_VertexPointer(3, GL_FLOAT, sizeof(float[3]), vertex3f, vertexbuffer, 0); + R_Mesh_VertexPointer(3, GL_FLOAT, sizeof(float[3]), vertex3f, vertexbuffer, bufferoffset); R_Mesh_ColorPointer(4, GL_FLOAT, sizeof(float[4]), NULL, NULL, 0); R_Mesh_TexCoordPointer(0, 2, GL_FLOAT, sizeof(float[2]), NULL, NULL, 0); } @@ -4304,7 +4304,7 @@ void R_Mesh_PrepareVertices_Vertex3f(int numvertices, const float *vertex3f, con #ifdef SUPPORTD3D IDirect3DDevice9_SetVertexDeclaration(vid_d3d9dev, r_vertex3f_d3d9decl); if (vertexbuffer) - IDirect3DDevice9_SetStreamSource(vid_d3d9dev, 0, (IDirect3DVertexBuffer9*)vertexbuffer->devicebuffer, 0, sizeof(float[3])); + IDirect3DDevice9_SetStreamSource(vid_d3d9dev, 0, (IDirect3DVertexBuffer9*)vertexbuffer->devicebuffer, bufferoffset, sizeof(float[3])); else IDirect3DDevice9_SetStreamSource(vid_d3d9dev, 0, NULL, 0, 0); gl_state.d3dvertexbuffer = (void *)vertexbuffer; @@ -4348,7 +4348,7 @@ r_vertexgeneric_t *R_Mesh_PrepareVertices_Generic_Lock(int numvertices) qboolean R_Mesh_PrepareVertices_Generic_Unlock(void) { - R_Mesh_PrepareVertices_Generic(gl_state.preparevertices_numvertices, gl_state.preparevertices_vertexgeneric, NULL); + R_Mesh_PrepareVertices_Generic(gl_state.preparevertices_numvertices, gl_state.preparevertices_vertexgeneric, NULL, 0); gl_state.preparevertices_vertexgeneric = NULL; gl_state.preparevertices_numvertices = 0; return true; @@ -4425,10 +4425,10 @@ void R_Mesh_PrepareVertices_Generic_Arrays(int numvertices, const float *vertex3 for (i = 0;i < numvertices;i++) Vector2Copy(texcoord2f + 2*i, vertex[i].texcoord2f); R_Mesh_PrepareVertices_Generic_Unlock(); - R_Mesh_PrepareVertices_Generic(numvertices, vertex, NULL); + R_Mesh_PrepareVertices_Generic(numvertices, vertex, NULL, 0); } -void R_Mesh_PrepareVertices_Generic(int numvertices, const r_vertexgeneric_t *vertex, const r_meshbuffer_t *vertexbuffer) +void R_Mesh_PrepareVertices_Generic(int numvertices, const r_vertexgeneric_t *vertex, const r_meshbuffer_t *vertexbuffer, int bufferoffset) { // upload temporary vertexbuffer for this rendering if (!gl_state.usevbo_staticvertex) @@ -4447,9 +4447,9 @@ void R_Mesh_PrepareVertices_Generic(int numvertices, const r_vertexgeneric_t *ve case RENDERPATH_GLES2: if (vertexbuffer) { - R_Mesh_VertexPointer( 3, GL_FLOAT , sizeof(*vertex), vertex->vertex3f , vertexbuffer, (int)((unsigned char *)vertex->vertex3f - (unsigned char *)vertex)); - R_Mesh_ColorPointer( 4, GL_FLOAT , sizeof(*vertex), vertex->color4f , vertexbuffer, (int)((unsigned char *)vertex->color4f - (unsigned char *)vertex)); - R_Mesh_TexCoordPointer(0, 2, GL_FLOAT , sizeof(*vertex), vertex->texcoord2f , vertexbuffer, (int)((unsigned char *)vertex->texcoord2f - (unsigned char *)vertex)); + R_Mesh_VertexPointer( 3, GL_FLOAT , sizeof(*vertex), vertex->vertex3f , vertexbuffer, bufferoffset + (int)((unsigned char *)vertex->vertex3f - (unsigned char *)vertex)); + R_Mesh_ColorPointer( 4, GL_FLOAT , sizeof(*vertex), vertex->color4f , vertexbuffer, bufferoffset + (int)((unsigned char *)vertex->color4f - (unsigned char *)vertex)); + R_Mesh_TexCoordPointer(0, 2, GL_FLOAT , sizeof(*vertex), vertex->texcoord2f , vertexbuffer, bufferoffset + (int)((unsigned char *)vertex->texcoord2f - (unsigned char *)vertex)); R_Mesh_TexCoordPointer(1, 2, GL_FLOAT, sizeof(float[2]), NULL, NULL, 0); R_Mesh_TexCoordPointer(2, 2, GL_FLOAT, sizeof(float[2]), NULL, NULL, 0); R_Mesh_TexCoordPointer(3, 2, GL_FLOAT, sizeof(float[2]), NULL, NULL, 0); @@ -4476,9 +4476,9 @@ void R_Mesh_PrepareVertices_Generic(int numvertices, const r_vertexgeneric_t *ve case RENDERPATH_GLES1: if (vertexbuffer) { - R_Mesh_VertexPointer( 3, GL_FLOAT , sizeof(*vertex), vertex->vertex3f , vertexbuffer, (int)((unsigned char *)vertex->vertex3f - (unsigned char *)vertex)); - R_Mesh_ColorPointer( 4, GL_FLOAT , sizeof(*vertex), vertex->color4f , vertexbuffer, (int)((unsigned char *)vertex->color4f - (unsigned char *)vertex)); - R_Mesh_TexCoordPointer(0, 2, GL_FLOAT , sizeof(*vertex), vertex->texcoord2f , vertexbuffer, (int)((unsigned char *)vertex->texcoord2f - (unsigned char *)vertex)); + R_Mesh_VertexPointer( 3, GL_FLOAT , sizeof(*vertex), vertex->vertex3f , vertexbuffer, bufferoffset + (int)((unsigned char *)vertex->vertex3f - (unsigned char *)vertex)); + R_Mesh_ColorPointer( 4, GL_FLOAT , sizeof(*vertex), vertex->color4f , vertexbuffer, bufferoffset + (int)((unsigned char *)vertex->color4f - (unsigned char *)vertex)); + R_Mesh_TexCoordPointer(0, 2, GL_FLOAT , sizeof(*vertex), vertex->texcoord2f , vertexbuffer, bufferoffset + (int)((unsigned char *)vertex->texcoord2f - (unsigned char *)vertex)); R_Mesh_TexCoordPointer(1, 2, GL_FLOAT, sizeof(float[2]), NULL, NULL, 0); } else @@ -4492,9 +4492,9 @@ void R_Mesh_PrepareVertices_Generic(int numvertices, const r_vertexgeneric_t *ve case RENDERPATH_GL11: if (vertexbuffer) { - R_Mesh_VertexPointer( 3, GL_FLOAT , sizeof(*vertex), vertex->vertex3f , vertexbuffer, (int)((unsigned char *)vertex->vertex3f - (unsigned char *)vertex)); - R_Mesh_ColorPointer( 4, GL_FLOAT , sizeof(*vertex), vertex->color4f , vertexbuffer, (int)((unsigned char *)vertex->color4f - (unsigned char *)vertex)); - R_Mesh_TexCoordPointer(0, 2, GL_FLOAT , sizeof(*vertex), vertex->texcoord2f , vertexbuffer, (int)((unsigned char *)vertex->texcoord2f - (unsigned char *)vertex)); + R_Mesh_VertexPointer( 3, GL_FLOAT , sizeof(*vertex), vertex->vertex3f , vertexbuffer, bufferoffset + (int)((unsigned char *)vertex->vertex3f - (unsigned char *)vertex)); + R_Mesh_ColorPointer( 4, GL_FLOAT , sizeof(*vertex), vertex->color4f , vertexbuffer, bufferoffset + (int)((unsigned char *)vertex->color4f - (unsigned char *)vertex)); + R_Mesh_TexCoordPointer(0, 2, GL_FLOAT , sizeof(*vertex), vertex->texcoord2f , vertexbuffer, bufferoffset + (int)((unsigned char *)vertex->texcoord2f - (unsigned char *)vertex)); } else { @@ -4507,7 +4507,7 @@ void R_Mesh_PrepareVertices_Generic(int numvertices, const r_vertexgeneric_t *ve #ifdef SUPPORTD3D IDirect3DDevice9_SetVertexDeclaration(vid_d3d9dev, r_vertexgeneric_d3d9decl); if (vertexbuffer) - IDirect3DDevice9_SetStreamSource(vid_d3d9dev, 0, (IDirect3DVertexBuffer9*)vertexbuffer->devicebuffer, 0, sizeof(*vertex)); + IDirect3DDevice9_SetStreamSource(vid_d3d9dev, 0, (IDirect3DVertexBuffer9*)vertexbuffer->devicebuffer, bufferoffset, sizeof(*vertex)); else IDirect3DDevice9_SetStreamSource(vid_d3d9dev, 0, NULL, 0, 0); gl_state.d3dvertexbuffer = (void *)vertexbuffer; @@ -4551,7 +4551,7 @@ r_vertexmesh_t *R_Mesh_PrepareVertices_Mesh_Lock(int numvertices) qboolean R_Mesh_PrepareVertices_Mesh_Unlock(void) { - R_Mesh_PrepareVertices_Mesh(gl_state.preparevertices_numvertices, gl_state.preparevertices_vertexmesh, NULL); + R_Mesh_PrepareVertices_Mesh(gl_state.preparevertices_numvertices, gl_state.preparevertices_vertexmesh, NULL, 0); gl_state.preparevertices_vertexmesh = NULL; gl_state.preparevertices_numvertices = 0; return true; @@ -4639,10 +4639,10 @@ void R_Mesh_PrepareVertices_Mesh_Arrays(int numvertices, const float *vertex3f, for (i = 0;i < numvertices;i++) Vector2Copy(texcoordlightmap2f + 2*i, vertex[i].texcoordlightmap2f); R_Mesh_PrepareVertices_Mesh_Unlock(); - R_Mesh_PrepareVertices_Mesh(numvertices, vertex, NULL); + R_Mesh_PrepareVertices_Mesh(numvertices, vertex, NULL, 0); } -void R_Mesh_PrepareVertices_Mesh(int numvertices, const r_vertexmesh_t *vertex, const r_meshbuffer_t *vertexbuffer) +void R_Mesh_PrepareVertices_Mesh(int numvertices, const r_vertexmesh_t *vertex, const r_meshbuffer_t *vertexbuffer, int bufferoffset) { // upload temporary vertexbuffer for this rendering if (!gl_state.usevbo_staticvertex) @@ -4661,16 +4661,16 @@ void R_Mesh_PrepareVertices_Mesh(int numvertices, const r_vertexmesh_t *vertex, case RENDERPATH_GLES2: if (vertexbuffer) { - R_Mesh_VertexPointer( 3, GL_FLOAT , sizeof(*vertex), vertex->vertex3f , vertexbuffer, (int)((unsigned char *)vertex->vertex3f - (unsigned char *)vertex)); - R_Mesh_ColorPointer( 4, GL_FLOAT , sizeof(*vertex), vertex->color4f , vertexbuffer, (int)((unsigned char *)vertex->color4f - (unsigned char *)vertex)); - R_Mesh_TexCoordPointer(0, 2, GL_FLOAT , sizeof(*vertex), vertex->texcoordtexture2f , vertexbuffer, (int)((unsigned char *)vertex->texcoordtexture2f - (unsigned char *)vertex)); - R_Mesh_TexCoordPointer(1, 3, GL_FLOAT , sizeof(*vertex), vertex->svector3f , vertexbuffer, (int)((unsigned char *)vertex->svector3f - (unsigned char *)vertex)); - R_Mesh_TexCoordPointer(2, 3, GL_FLOAT , sizeof(*vertex), vertex->tvector3f , vertexbuffer, (int)((unsigned char *)vertex->tvector3f - (unsigned char *)vertex)); - R_Mesh_TexCoordPointer(3, 3, GL_FLOAT , sizeof(*vertex), vertex->normal3f , vertexbuffer, (int)((unsigned char *)vertex->normal3f - (unsigned char *)vertex)); - R_Mesh_TexCoordPointer(4, 2, GL_FLOAT , sizeof(*vertex), vertex->texcoordlightmap2f, vertexbuffer, (int)((unsigned char *)vertex->texcoordlightmap2f - (unsigned char *)vertex)); + R_Mesh_VertexPointer( 3, GL_FLOAT , sizeof(*vertex), vertex->vertex3f , vertexbuffer, bufferoffset + (int)((unsigned char *)vertex->vertex3f - (unsigned char *)vertex)); + R_Mesh_ColorPointer( 4, GL_FLOAT , sizeof(*vertex), vertex->color4f , vertexbuffer, bufferoffset + (int)((unsigned char *)vertex->color4f - (unsigned char *)vertex)); + R_Mesh_TexCoordPointer(0, 2, GL_FLOAT , sizeof(*vertex), vertex->texcoordtexture2f , vertexbuffer, bufferoffset + (int)((unsigned char *)vertex->texcoordtexture2f - (unsigned char *)vertex)); + R_Mesh_TexCoordPointer(1, 3, GL_FLOAT , sizeof(*vertex), vertex->svector3f , vertexbuffer, bufferoffset + (int)((unsigned char *)vertex->svector3f - (unsigned char *)vertex)); + R_Mesh_TexCoordPointer(2, 3, GL_FLOAT , sizeof(*vertex), vertex->tvector3f , vertexbuffer, bufferoffset + (int)((unsigned char *)vertex->tvector3f - (unsigned char *)vertex)); + R_Mesh_TexCoordPointer(3, 3, GL_FLOAT , sizeof(*vertex), vertex->normal3f , vertexbuffer, bufferoffset + (int)((unsigned char *)vertex->normal3f - (unsigned char *)vertex)); + R_Mesh_TexCoordPointer(4, 2, GL_FLOAT , sizeof(*vertex), vertex->texcoordlightmap2f, vertexbuffer, bufferoffset + (int)((unsigned char *)vertex->texcoordlightmap2f - (unsigned char *)vertex)); R_Mesh_TexCoordPointer(5, 2, GL_FLOAT , sizeof(*vertex), NULL, NULL, 0); - R_Mesh_TexCoordPointer(6, 4, GL_UNSIGNED_BYTE | 0x80000000, sizeof(*vertex), vertex->skeletalindex4ub , vertexbuffer, (int)((unsigned char *)vertex->skeletalindex4ub - (unsigned char *)vertex)); - R_Mesh_TexCoordPointer(7, 4, GL_UNSIGNED_BYTE, sizeof(*vertex), vertex->skeletalweight4ub , vertexbuffer, (int)((unsigned char *)vertex->skeletalweight4ub - (unsigned char *)vertex)); + R_Mesh_TexCoordPointer(6, 4, GL_UNSIGNED_BYTE | 0x80000000, sizeof(*vertex), vertex->skeletalindex4ub , vertexbuffer, bufferoffset + (int)((unsigned char *)vertex->skeletalindex4ub - (unsigned char *)vertex)); + R_Mesh_TexCoordPointer(7, 4, GL_UNSIGNED_BYTE, sizeof(*vertex), vertex->skeletalweight4ub , vertexbuffer, bufferoffset + (int)((unsigned char *)vertex->skeletalweight4ub - (unsigned char *)vertex)); } else { @@ -4690,10 +4690,10 @@ void R_Mesh_PrepareVertices_Mesh(int numvertices, const r_vertexmesh_t *vertex, case RENDERPATH_GLES1: if (vertexbuffer) { - R_Mesh_VertexPointer( 3, GL_FLOAT , sizeof(*vertex), vertex->vertex3f , vertexbuffer, (int)((unsigned char *)vertex->vertex3f - (unsigned char *)vertex)); - R_Mesh_ColorPointer( 4, GL_FLOAT , sizeof(*vertex), vertex->color4f , vertexbuffer, (int)((unsigned char *)vertex->color4f - (unsigned char *)vertex)); - R_Mesh_TexCoordPointer(0, 2, GL_FLOAT , sizeof(*vertex), vertex->texcoordtexture2f , vertexbuffer, (int)((unsigned char *)vertex->texcoordtexture2f - (unsigned char *)vertex)); - R_Mesh_TexCoordPointer(1, 2, GL_FLOAT , sizeof(*vertex), vertex->texcoordlightmap2f, vertexbuffer, (int)((unsigned char *)vertex->texcoordlightmap2f - (unsigned char *)vertex)); + R_Mesh_VertexPointer( 3, GL_FLOAT , sizeof(*vertex), vertex->vertex3f , vertexbuffer, bufferoffset + (int)((unsigned char *)vertex->vertex3f - (unsigned char *)vertex)); + R_Mesh_ColorPointer( 4, GL_FLOAT , sizeof(*vertex), vertex->color4f , vertexbuffer, bufferoffset + (int)((unsigned char *)vertex->color4f - (unsigned char *)vertex)); + R_Mesh_TexCoordPointer(0, 2, GL_FLOAT , sizeof(*vertex), vertex->texcoordtexture2f , vertexbuffer, bufferoffset + (int)((unsigned char *)vertex->texcoordtexture2f - (unsigned char *)vertex)); + R_Mesh_TexCoordPointer(1, 2, GL_FLOAT , sizeof(*vertex), vertex->texcoordlightmap2f, vertexbuffer, bufferoffset + (int)((unsigned char *)vertex->texcoordlightmap2f - (unsigned char *)vertex)); } else { @@ -4706,9 +4706,9 @@ void R_Mesh_PrepareVertices_Mesh(int numvertices, const r_vertexmesh_t *vertex, case RENDERPATH_GL11: if (vertexbuffer) { - R_Mesh_VertexPointer( 3, GL_FLOAT , sizeof(*vertex), vertex->vertex3f , vertexbuffer, (int)((unsigned char *)vertex->vertex3f - (unsigned char *)vertex)); - R_Mesh_ColorPointer( 4, GL_FLOAT , sizeof(*vertex), vertex->color4f , vertexbuffer, (int)((unsigned char *)vertex->color4f - (unsigned char *)vertex)); - R_Mesh_TexCoordPointer(0, 2, GL_FLOAT , sizeof(*vertex), vertex->texcoordtexture2f , vertexbuffer, (int)((unsigned char *)vertex->texcoordtexture2f - (unsigned char *)vertex)); + R_Mesh_VertexPointer( 3, GL_FLOAT , sizeof(*vertex), vertex->vertex3f , vertexbuffer, bufferoffset + (int)((unsigned char *)vertex->vertex3f - (unsigned char *)vertex)); + R_Mesh_ColorPointer( 4, GL_FLOAT , sizeof(*vertex), vertex->color4f , vertexbuffer, bufferoffset + (int)((unsigned char *)vertex->color4f - (unsigned char *)vertex)); + R_Mesh_TexCoordPointer(0, 2, GL_FLOAT , sizeof(*vertex), vertex->texcoordtexture2f , vertexbuffer, bufferoffset + (int)((unsigned char *)vertex->texcoordtexture2f - (unsigned char *)vertex)); } else { @@ -4721,7 +4721,7 @@ void R_Mesh_PrepareVertices_Mesh(int numvertices, const r_vertexmesh_t *vertex, #ifdef SUPPORTD3D IDirect3DDevice9_SetVertexDeclaration(vid_d3d9dev, r_vertexmesh_d3d9decl); if (vertexbuffer) - IDirect3DDevice9_SetStreamSource(vid_d3d9dev, 0, (IDirect3DVertexBuffer9*)vertexbuffer->devicebuffer, 0, sizeof(*vertex)); + IDirect3DDevice9_SetStreamSource(vid_d3d9dev, 0, (IDirect3DVertexBuffer9*)vertexbuffer->devicebuffer, bufferoffset, sizeof(*vertex)); else IDirect3DDevice9_SetStreamSource(vid_d3d9dev, 0, NULL, 0, 0); gl_state.d3dvertexbuffer = (void *)vertexbuffer; diff --git a/gl_backend.h b/gl_backend.h index dcfacf08..981ae6f0 100644 --- a/gl_backend.h +++ b/gl_backend.h @@ -77,17 +77,17 @@ void R_Mesh_UpdateMeshBuffer(r_meshbuffer_t *buffer, const void *data, size_t si void R_Mesh_DestroyMeshBuffer(r_meshbuffer_t *buffer); void GL_Mesh_ListVBOs(qboolean printeach); -void R_Mesh_PrepareVertices_Vertex3f(int numvertices, const float *vertex3f, const r_meshbuffer_t *buffer); +void R_Mesh_PrepareVertices_Vertex3f(int numvertices, const float *vertex3f, const r_meshbuffer_t *buffer, int bufferoffset); r_vertexgeneric_t *R_Mesh_PrepareVertices_Generic_Lock(int numvertices); qboolean R_Mesh_PrepareVertices_Generic_Unlock(void); void R_Mesh_PrepareVertices_Generic_Arrays(int numvertices, const float *vertex3f, const float *color4f, const float *texcoord2f); -void R_Mesh_PrepareVertices_Generic(int numvertices, const r_vertexgeneric_t *vertex, const r_meshbuffer_t *vertexbuffer); +void R_Mesh_PrepareVertices_Generic(int numvertices, const r_vertexgeneric_t *vertex, const r_meshbuffer_t *vertexbuffer, int bufferoffset); r_vertexmesh_t *R_Mesh_PrepareVertices_Mesh_Lock(int numvertices); qboolean R_Mesh_PrepareVertices_Mesh_Unlock(void); // if this returns false, you need to prepare the mesh again! void R_Mesh_PrepareVertices_Mesh_Arrays(int numvertices, const float *vertex3f, const float *svector3f, const float *tvector3f, const float *normal3f, const float *color4f, const float *texcoordtexture2f, const float *texcoordlightmap2f); -void R_Mesh_PrepareVertices_Mesh(int numvertices, const r_vertexmesh_t *vertex, const r_meshbuffer_t *buffer); +void R_Mesh_PrepareVertices_Mesh(int numvertices, const r_vertexmesh_t *vertex, const r_meshbuffer_t *buffer, int bufferoffset); // sets up the requested vertex transform matrix void R_EntityMatrix(const matrix4x4_t *matrix); diff --git a/gl_rmain.c b/gl_rmain.c index bd0f43c5..a1530a6f 100644 --- a/gl_rmain.c +++ b/gl_rmain.c @@ -230,6 +230,7 @@ cvar_t r_test = {0, "r_test", "0", "internal development use only, leave it alon cvar_t r_batch_multidraw = {CVAR_SAVE, "r_batch_multidraw", "1", "issue multiple glDrawElements calls when rendering a batch of surfaces with the same texture (otherwise the index data is copied to make it one draw)"}; cvar_t r_batch_multidraw_mintriangles = {CVAR_SAVE, "r_batch_multidraw_mintriangles", "0", "minimum number of triangles to activate multidraw path (copying small groups of triangles may be faster)"}; cvar_t r_batch_debugdynamicvertexpath = {CVAR_SAVE, "r_batch_debugdynamicvertexpath", "0", "force the dynamic batching code path for debugging purposes"}; +cvar_t r_batch_dynamicbuffer = {CVAR_SAVE, "r_batch_dynamicbuffer", "0", "use vertex/index buffers for drawing dynamic and copytriangles batches"}; cvar_t r_glsl_saturation = {CVAR_SAVE, "r_glsl_saturation", "1", "saturation multiplier (only working in glsl!)"}; cvar_t r_glsl_saturation_redcompensate = {CVAR_SAVE, "r_glsl_saturation_redcompensate", "0", "a 'vampire sight' addition to desaturation effect, does compensation for red color, r_glsl_restart is required"}; @@ -2548,7 +2549,7 @@ void R_SetupShader_Surface(const vec3_t lightcolorbase, qboolean modellighting, case RENDERPATH_D3D9: #ifdef SUPPORTD3D RSurf_PrepareVerticesForBatch(BATCHNEED_VERTEXMESH_VERTEX | BATCHNEED_VERTEXMESH_NORMAL | BATCHNEED_VERTEXMESH_VECTOR | (rsurface.modellightmapcolor4f ? BATCHNEED_VERTEXMESH_VERTEXCOLOR : 0) | BATCHNEED_VERTEXMESH_TEXCOORD | (rsurface.uselightmaptexture ? BATCHNEED_VERTEXMESH_LIGHTMAP : 0) | BATCHNEED_ALLOWMULTIDRAW, texturenumsurfaces, texturesurfacelist); - R_Mesh_PrepareVertices_Mesh(rsurface.batchnumvertices, rsurface.batchvertexmesh, rsurface.batchvertexmeshbuffer); + R_Mesh_PrepareVertices_Mesh(rsurface.batchnumvertices, rsurface.batchvertexmesh, rsurface.batchvertexmesh_vertexbuffer, rsurface.batchvertexmesh_bufferoffset); R_SetupShader_SetPermutationHLSL(mode, permutation); Matrix4x4_ToArrayFloatGL(&rsurface.matrix, m16f);hlslPSSetParameter16f(D3DPSREGISTER_ModelToReflectCube, m16f); if (mode == SHADERMODE_LIGHTSOURCE) @@ -2715,7 +2716,7 @@ void R_SetupShader_Surface(const vec3_t lightcolorbase, qboolean modellighting, else { RSurf_PrepareVerticesForBatch(BATCHNEED_VERTEXMESH_VERTEX | BATCHNEED_VERTEXMESH_NORMAL | BATCHNEED_VERTEXMESH_VECTOR | (rsurface.modellightmapcolor4f ? BATCHNEED_VERTEXMESH_VERTEXCOLOR : 0) | BATCHNEED_VERTEXMESH_TEXCOORD | (rsurface.uselightmaptexture ? BATCHNEED_VERTEXMESH_LIGHTMAP : 0) | (rsurface.entityskeletaltransform3x4 ? BATCHNEED_VERTEXMESH_SKELETAL : 0) | BATCHNEED_ALLOWMULTIDRAW, texturenumsurfaces, texturesurfacelist); - R_Mesh_PrepareVertices_Mesh(rsurface.batchnumvertices, rsurface.batchvertexmesh, rsurface.batchvertexmeshbuffer); + R_Mesh_PrepareVertices_Mesh(rsurface.batchnumvertices, rsurface.batchvertexmesh, rsurface.batchvertexmesh_vertexbuffer, rsurface.batchvertexmesh_bufferoffset); } // this has to be after RSurf_PrepareVerticesForBatch if (rsurface.batchskeletaltransform3x4buffer) @@ -4353,6 +4354,7 @@ void GL_Main_Init(void) Cvar_RegisterVariable(&r_framedatasize); for (i = 0;i < R_BUFFERDATA_COUNT;i++) Cvar_RegisterVariable(&r_bufferdatasize[i]); + Cvar_RegisterVariable(&r_batch_dynamicbuffer); if (gamemode == GAME_NEHAHRA || gamemode == GAME_TENEBRAE) Cvar_SetValue("r_fullbrights", 0); R_RegisterModule("GL_Main", gl_main_start, gl_main_shutdown, gl_main_newmap, NULL, NULL); @@ -4785,15 +4787,23 @@ void R_AnimCache_ClearCache(void) for (i = 0;i < r_refdef.scene.numentities;i++) { ent = r_refdef.scene.entities[i]; - ent->animcache_vertex3f = NULL; // for shadow geometry - ent->animcache_normal3f = NULL; // for lit geometry - ent->animcache_svector3f = NULL; // for lit geometry - ent->animcache_tvector3f = NULL; // for lit geometry - ent->animcache_vertexmesh = NULL; // interleaved vertex arrays for D3D - ent->animcache_vertex3fbuffer = NULL; // vertex buffer for D3D - ent->animcache_vertexmeshbuffer = NULL; // vertex buffer for D3D - ent->animcache_skeletaltransform3x4 = NULL; // for dynamic batch fallback with r_glsl_skeletal - ent->animcache_skeletaltransform3x4buffer = NULL; // for r_glsl_skeletal + ent->animcache_vertex3f = NULL; + ent->animcache_vertex3f_vertexbuffer = NULL; + ent->animcache_vertex3f_bufferoffset = 0; + ent->animcache_normal3f = NULL; + ent->animcache_normal3f_vertexbuffer = NULL; + ent->animcache_normal3f_bufferoffset = 0; + ent->animcache_svector3f = NULL; + ent->animcache_svector3f_vertexbuffer = NULL; + ent->animcache_svector3f_bufferoffset = 0; + ent->animcache_tvector3f = NULL; + ent->animcache_tvector3f_vertexbuffer = NULL; + ent->animcache_tvector3f_bufferoffset = 0; + ent->animcache_vertexmesh = NULL; + ent->animcache_vertexmesh_vertexbuffer = NULL; + ent->animcache_vertexmesh_bufferoffset = 0; + ent->animcache_skeletaltransform3x4 = NULL; + ent->animcache_skeletaltransform3x4buffer = NULL; ent->animcache_skeletaltransform3x4offset = 0; ent->animcache_skeletaltransform3x4size = 0; } @@ -4809,13 +4819,13 @@ static void R_AnimCache_UpdateEntityMeshBuffers(entity_render_t *ent, int numver if (!ent->animcache_vertexmesh && ent->animcache_normal3f) ent->animcache_vertexmesh = (r_vertexmesh_t *)R_FrameData_Alloc(sizeof(r_vertexmesh_t)*numvertices); - // TODO: upload vertex3f buffer? + // TODO: upload vertexbuffer? if (ent->animcache_vertexmesh) { r_refdef.stats[r_stat_animcache_vertexmesh_count] += 1; r_refdef.stats[r_stat_animcache_vertexmesh_vertices] += numvertices; r_refdef.stats[r_stat_animcache_vertexmesh_maxvertices] = max(r_refdef.stats[r_stat_animcache_vertexmesh_maxvertices], numvertices); - memcpy(ent->animcache_vertexmesh, ent->model->surfmesh.vertexmesh, sizeof(r_vertexmesh_t)*numvertices); + memcpy(ent->animcache_vertexmesh, ent->model->surfmesh.data_vertexmesh, sizeof(r_vertexmesh_t)*numvertices); for (i = 0;i < numvertices;i++) memcpy(ent->animcache_vertexmesh[i].vertex3f, ent->animcache_vertex3f + 3*i, sizeof(float[3])); if (ent->animcache_svector3f) @@ -4827,7 +4837,6 @@ static void R_AnimCache_UpdateEntityMeshBuffers(entity_render_t *ent, int numver if (ent->animcache_normal3f) for (i = 0;i < numvertices;i++) memcpy(ent->animcache_vertexmesh[i].normal3f, ent->animcache_normal3f + 3*i, sizeof(float[3])); - // TODO: upload vertexmeshbuffer? } } @@ -8482,9 +8491,9 @@ void RSurf_ActiveWorldEntity(void) rsurface.modelnumvertices = model->surfmesh.num_vertices; rsurface.modelnumtriangles = model->surfmesh.num_triangles; rsurface.modelsurfaces = model->data_surfaces; - rsurface.modelvertexmesh = model->surfmesh.vertexmesh; - rsurface.modelvertexmeshbuffer = model->surfmesh.vertexmeshbuffer; - rsurface.modelvertex3fbuffer = model->surfmesh.vertex3fbuffer; + rsurface.modelvertexmesh = model->surfmesh.data_vertexmesh; + rsurface.modelvertexmesh_vertexbuffer = model->surfmesh.vbo_vertexbuffer; + rsurface.modelvertexmesh_bufferoffset = model->surfmesh.vbooffset_vertex3f; rsurface.modelgeneratedvertex = false; rsurface.batchgeneratedvertex = false; rsurface.batchfirstvertex = 0; @@ -8519,8 +8528,8 @@ void RSurf_ActiveWorldEntity(void) rsurface.batchskeletalweight4ub_vertexbuffer = NULL; rsurface.batchskeletalweight4ub_bufferoffset = 0; rsurface.batchvertexmesh = NULL; - rsurface.batchvertexmeshbuffer = NULL; - rsurface.batchvertex3fbuffer = NULL; + rsurface.batchvertexmesh_vertexbuffer = NULL; + rsurface.batchvertexmesh_bufferoffset = 0; rsurface.batchelement3i = NULL; rsurface.batchelement3i_indexbuffer = NULL; rsurface.batchelement3i_bufferoffset = 0; @@ -8588,12 +8597,20 @@ void RSurf_ActiveModelEntity(const entity_render_t *ent, qboolean wantnormals, q r_refdef.stats[r_stat_batch_entitycache_vertices] += model->surfmesh.num_vertices; r_refdef.stats[r_stat_batch_entitycache_triangles] += model->surfmesh.num_triangles; rsurface.modelvertex3f = ent->animcache_vertex3f; + rsurface.modelvertex3f_vertexbuffer = ent->animcache_vertex3f_vertexbuffer; + rsurface.modelvertex3f_bufferoffset = ent->animcache_vertex3f_bufferoffset; rsurface.modelsvector3f = wanttangents ? ent->animcache_svector3f : NULL; + rsurface.modelsvector3f_vertexbuffer = wanttangents ? ent->animcache_svector3f_vertexbuffer : NULL; + rsurface.modelsvector3f_bufferoffset = wanttangents ? ent->animcache_svector3f_bufferoffset : 0; rsurface.modeltvector3f = wanttangents ? ent->animcache_tvector3f : NULL; + rsurface.modeltvector3f_vertexbuffer = wanttangents ? ent->animcache_tvector3f_vertexbuffer : NULL; + rsurface.modeltvector3f_bufferoffset = wanttangents ? ent->animcache_tvector3f_bufferoffset : 0; rsurface.modelnormal3f = wantnormals ? ent->animcache_normal3f : NULL; + rsurface.modelnormal3f_vertexbuffer = wantnormals ? ent->animcache_normal3f_vertexbuffer : NULL; + rsurface.modelnormal3f_bufferoffset = wantnormals ? ent->animcache_normal3f_bufferoffset : 0; rsurface.modelvertexmesh = ent->animcache_vertexmesh; - rsurface.modelvertexmeshbuffer = ent->animcache_vertexmeshbuffer; - rsurface.modelvertex3fbuffer = ent->animcache_vertex3fbuffer; + rsurface.modelvertexmesh_vertexbuffer = ent->animcache_vertexmesh_vertexbuffer; + rsurface.modelvertexmesh_bufferoffset = ent->animcache_vertexmesh_bufferoffset; } else if (wanttangents) { @@ -8607,8 +8624,18 @@ void RSurf_ActiveModelEntity(const entity_render_t *ent, qboolean wantnormals, q rsurface.modelnormal3f = (float *)R_FrameData_Alloc(model->surfmesh.num_vertices * sizeof(float[3])); model->AnimateVertices(model, rsurface.frameblend, rsurface.skeleton, rsurface.modelvertex3f, rsurface.modelnormal3f, rsurface.modelsvector3f, rsurface.modeltvector3f); rsurface.modelvertexmesh = NULL; - rsurface.modelvertexmeshbuffer = NULL; - rsurface.modelvertex3fbuffer = NULL; + rsurface.modelvertexmesh_vertexbuffer = NULL; + rsurface.modelvertexmesh_bufferoffset = 0; + rsurface.modelvertex3f_vertexbuffer = NULL; + rsurface.modelvertex3f_bufferoffset = 0; + rsurface.modelvertex3f_vertexbuffer = 0; + rsurface.modelvertex3f_bufferoffset = 0; + rsurface.modelsvector3f_vertexbuffer = 0; + rsurface.modelsvector3f_bufferoffset = 0; + rsurface.modeltvector3f_vertexbuffer = 0; + rsurface.modeltvector3f_bufferoffset = 0; + rsurface.modelnormal3f_vertexbuffer = 0; + rsurface.modelnormal3f_bufferoffset = 0; } else if (wantnormals) { @@ -8622,8 +8649,18 @@ void RSurf_ActiveModelEntity(const entity_render_t *ent, qboolean wantnormals, q rsurface.modelnormal3f = (float *)R_FrameData_Alloc(model->surfmesh.num_vertices * sizeof(float[3])); model->AnimateVertices(model, rsurface.frameblend, rsurface.skeleton, rsurface.modelvertex3f, rsurface.modelnormal3f, NULL, NULL); rsurface.modelvertexmesh = NULL; - rsurface.modelvertexmeshbuffer = NULL; - rsurface.modelvertex3fbuffer = NULL; + rsurface.modelvertexmesh_vertexbuffer = NULL; + rsurface.modelvertexmesh_bufferoffset = 0; + rsurface.modelvertex3f_vertexbuffer = NULL; + rsurface.modelvertex3f_bufferoffset = 0; + rsurface.modelvertex3f_vertexbuffer = 0; + rsurface.modelvertex3f_bufferoffset = 0; + rsurface.modelsvector3f_vertexbuffer = 0; + rsurface.modelsvector3f_bufferoffset = 0; + rsurface.modeltvector3f_vertexbuffer = 0; + rsurface.modeltvector3f_bufferoffset = 0; + rsurface.modelnormal3f_vertexbuffer = 0; + rsurface.modelnormal3f_bufferoffset = 0; } else { @@ -8637,17 +8674,19 @@ void RSurf_ActiveModelEntity(const entity_render_t *ent, qboolean wantnormals, q rsurface.modelnormal3f = NULL; model->AnimateVertices(model, rsurface.frameblend, rsurface.skeleton, rsurface.modelvertex3f, NULL, NULL, NULL); rsurface.modelvertexmesh = NULL; - rsurface.modelvertexmeshbuffer = NULL; - rsurface.modelvertex3fbuffer = NULL; - } - rsurface.modelvertex3f_vertexbuffer = 0; - rsurface.modelvertex3f_bufferoffset = 0; - rsurface.modelsvector3f_vertexbuffer = 0; - rsurface.modelsvector3f_bufferoffset = 0; - rsurface.modeltvector3f_vertexbuffer = 0; - rsurface.modeltvector3f_bufferoffset = 0; - rsurface.modelnormal3f_vertexbuffer = 0; - rsurface.modelnormal3f_bufferoffset = 0; + rsurface.modelvertexmesh_vertexbuffer = NULL; + rsurface.modelvertexmesh_bufferoffset = 0; + rsurface.modelvertex3f_vertexbuffer = NULL; + rsurface.modelvertex3f_bufferoffset = 0; + rsurface.modelvertex3f_vertexbuffer = 0; + rsurface.modelvertex3f_bufferoffset = 0; + rsurface.modelsvector3f_vertexbuffer = 0; + rsurface.modelsvector3f_bufferoffset = 0; + rsurface.modeltvector3f_vertexbuffer = 0; + rsurface.modeltvector3f_bufferoffset = 0; + rsurface.modelnormal3f_vertexbuffer = 0; + rsurface.modelnormal3f_bufferoffset = 0; + } rsurface.modelgeneratedvertex = true; } else @@ -8678,9 +8717,9 @@ void RSurf_ActiveModelEntity(const entity_render_t *ent, qboolean wantnormals, q rsurface.modelnormal3f = model->surfmesh.data_normal3f; rsurface.modelnormal3f_vertexbuffer = model->surfmesh.vbo_vertexbuffer; rsurface.modelnormal3f_bufferoffset = model->surfmesh.vbooffset_normal3f; - rsurface.modelvertexmesh = model->surfmesh.vertexmesh; - rsurface.modelvertexmeshbuffer = model->surfmesh.vertexmeshbuffer; - rsurface.modelvertex3fbuffer = model->surfmesh.vertex3fbuffer; + rsurface.modelvertexmesh = model->surfmesh.data_vertexmesh; + rsurface.modelvertexmesh_vertexbuffer = model->surfmesh.vbo_vertexbuffer; + rsurface.modelvertexmesh_bufferoffset = model->surfmesh.vbooffset_vertex3f; rsurface.modelgeneratedvertex = false; } rsurface.modellightmapcolor4f = model->surfmesh.data_lightmapcolor4f; @@ -8741,8 +8780,8 @@ void RSurf_ActiveModelEntity(const entity_render_t *ent, qboolean wantnormals, q rsurface.batchskeletalweight4ub_vertexbuffer = NULL; rsurface.batchskeletalweight4ub_bufferoffset = 0; rsurface.batchvertexmesh = NULL; - rsurface.batchvertexmeshbuffer = NULL; - rsurface.batchvertex3fbuffer = NULL; + rsurface.batchvertexmesh_vertexbuffer = NULL; + rsurface.batchvertexmesh_bufferoffset = 0; rsurface.batchelement3i = NULL; rsurface.batchelement3i_indexbuffer = NULL; rsurface.batchelement3i_bufferoffset = 0; @@ -8819,8 +8858,8 @@ void RSurf_ActiveCustomEntity(const matrix4x4_t *matrix, const matrix4x4_t *inve rsurface.modelnormal3f = NULL; } rsurface.modelvertexmesh = NULL; - rsurface.modelvertexmeshbuffer = NULL; - rsurface.modelvertex3fbuffer = NULL; + rsurface.modelvertexmesh_vertexbuffer = NULL; + rsurface.modelvertexmesh_bufferoffset = 0; rsurface.modelvertex3f_vertexbuffer = 0; rsurface.modelvertex3f_bufferoffset = 0; rsurface.modelsvector3f_vertexbuffer = 0; @@ -8886,8 +8925,8 @@ void RSurf_ActiveCustomEntity(const matrix4x4_t *matrix, const matrix4x4_t *inve rsurface.batchskeletalweight4ub_vertexbuffer = NULL; rsurface.batchskeletalweight4ub_bufferoffset = 0; rsurface.batchvertexmesh = NULL; - rsurface.batchvertexmeshbuffer = NULL; - rsurface.batchvertex3fbuffer = NULL; + rsurface.batchvertexmesh_vertexbuffer = NULL; + rsurface.batchvertexmesh_bufferoffset = 0; rsurface.batchelement3i = NULL; rsurface.batchelement3i_indexbuffer = NULL; rsurface.batchelement3i_bufferoffset = 0; @@ -9223,7 +9262,7 @@ void RSurf_PrepareVerticesForBatch(int batchneed, int texturenumsurfaces, const // when the model data has no vertex buffer (dynamic mesh), we need to // eliminate gaps - if (vid.useinterleavedarrays && !rsurface.modelvertexmeshbuffer) + if (vid.useinterleavedarrays && !rsurface.modelvertexmesh_vertexbuffer) batchneed |= BATCHNEED_NOGAPS; // the caller can specify BATCHNEED_NOGAPS to force a batch with @@ -9310,9 +9349,9 @@ void RSurf_PrepareVerticesForBatch(int batchneed, int texturenumsurfaces, const rsurface.batchskeletalweight4ub = rsurface.modelskeletalweight4ub; rsurface.batchskeletalweight4ub_vertexbuffer = rsurface.modelskeletalweight4ub_vertexbuffer; rsurface.batchskeletalweight4ub_bufferoffset = rsurface.modelskeletalweight4ub_bufferoffset; - rsurface.batchvertex3fbuffer = rsurface.modelvertex3fbuffer; rsurface.batchvertexmesh = rsurface.modelvertexmesh; - rsurface.batchvertexmeshbuffer = rsurface.modelvertexmeshbuffer; + rsurface.batchvertexmesh_vertexbuffer = rsurface.modelvertexmesh_vertexbuffer; + rsurface.batchvertexmesh_bufferoffset = rsurface.modelvertexmesh_bufferoffset; rsurface.batchelement3i = rsurface.modelelement3i; rsurface.batchelement3i_indexbuffer = rsurface.modelelement3i_indexbuffer; rsurface.batchelement3i_bufferoffset = rsurface.modelelement3i_bufferoffset; @@ -9385,6 +9424,14 @@ void RSurf_PrepareVerticesForBatch(int batchneed, int texturenumsurfaces, const for (i = 0;i < numtriangles*3;i++) rsurface.batchelement3s[i] = rsurface.batchelement3i[i]; } + // upload buffer data for the copytriangles batch + if (vid.forcevbo || (r_batch_dynamicbuffer.integer && vid.support.arb_vertex_buffer_object)) + { + if (rsurface.batchelement3s) + rsurface.batchelement3s_indexbuffer = R_BufferData_Store(rsurface.batchnumtriangles * sizeof(short[3]), rsurface.batchelement3s, R_BUFFERDATA_INDEX16, &rsurface.batchelement3s_bufferoffset, !vid.forcevbo); + else if (rsurface.batchelement3i) + rsurface.batchelement3i_indexbuffer = R_BufferData_Store(rsurface.batchnumtriangles * sizeof(int[3]), rsurface.batchelement3i, R_BUFFERDATA_INDEX32, &rsurface.batchelement3i_bufferoffset, !vid.forcevbo); + } } else { @@ -9412,9 +9459,9 @@ void RSurf_PrepareVerticesForBatch(int batchneed, int texturenumsurfaces, const // need actual vertex positions and normals //if (dynamicvertex) { - rsurface.batchvertex3fbuffer = NULL; rsurface.batchvertexmesh = NULL; - rsurface.batchvertexmeshbuffer = NULL; + rsurface.batchvertexmesh_vertexbuffer = NULL; + rsurface.batchvertexmesh_bufferoffset = 0; rsurface.batchvertex3f = NULL; rsurface.batchvertex3f_vertexbuffer = NULL; rsurface.batchvertex3f_bufferoffset = 0; @@ -10117,7 +10164,8 @@ void RSurf_PrepareVerticesForBatch(int batchneed, int texturenumsurfaces, const { // convert the modified arrays to vertex structs // rsurface.batchvertexmesh = R_FrameData_Alloc(batchnumvertices * sizeof(r_vertexmesh_t)); -// rsurface.batchvertexmeshbuffer = NULL; +// rsurface.batchvertexmesh_vertexbuffer = NULL; +// rsurface.batchvertexmesh_bufferoffset = 0; if (batchneed & BATCHNEED_VERTEXMESH_VERTEX) for (j = 0, vertexmesh = rsurface.batchvertexmesh;j < batchnumvertices;j++, vertexmesh++) VectorCopy(rsurface.batchvertex3f + 3*j, vertexmesh->vertex3f); @@ -10150,6 +10198,38 @@ void RSurf_PrepareVerticesForBatch(int batchneed, int texturenumsurfaces, const } } } + + // upload buffer data for the dynamic batch + if (vid.forcevbo || (r_batch_dynamicbuffer.integer && vid.support.arb_vertex_buffer_object)) + { + if (rsurface.batchvertexmesh) + rsurface.batchvertexmesh_vertexbuffer = R_BufferData_Store(rsurface.batchnumvertices * sizeof(r_vertexmesh_t), rsurface.batchvertexmesh, R_BUFFERDATA_VERTEX, &rsurface.batchvertexmesh_bufferoffset, !vid.forcevbo); + else + { + if (rsurface.batchvertex3f) + rsurface.batchvertex3f_vertexbuffer = R_BufferData_Store(rsurface.batchnumvertices * sizeof(float[3]), rsurface.batchvertex3f, R_BUFFERDATA_VERTEX, &rsurface.batchvertex3f_bufferoffset, !vid.forcevbo); + if (rsurface.batchsvector3f) + rsurface.batchsvector3f_vertexbuffer = R_BufferData_Store(rsurface.batchnumvertices * sizeof(float[3]), rsurface.batchsvector3f, R_BUFFERDATA_VERTEX, &rsurface.batchsvector3f_bufferoffset, !vid.forcevbo); + if (rsurface.batchtvector3f) + rsurface.batchtvector3f_vertexbuffer = R_BufferData_Store(rsurface.batchnumvertices * sizeof(float[3]), rsurface.batchtvector3f, R_BUFFERDATA_VERTEX, &rsurface.batchtvector3f_bufferoffset, !vid.forcevbo); + if (rsurface.batchnormal3f) + rsurface.batchnormal3f_vertexbuffer = R_BufferData_Store(rsurface.batchnumvertices * sizeof(float[3]), rsurface.batchnormal3f, R_BUFFERDATA_VERTEX, &rsurface.batchnormal3f_bufferoffset, !vid.forcevbo); + if (rsurface.batchlightmapcolor4f && r_batch_dynamicbuffer.integer && vid.support.arb_vertex_buffer_object) + rsurface.batchlightmapcolor4f_vertexbuffer = R_BufferData_Store(rsurface.batchnumvertices * sizeof(float[4]), rsurface.batchlightmapcolor4f, R_BUFFERDATA_VERTEX, &rsurface.batchlightmapcolor4f_bufferoffset, !vid.forcevbo); + if (rsurface.batchtexcoordtexture2f && r_batch_dynamicbuffer.integer && vid.support.arb_vertex_buffer_object) + rsurface.batchtexcoordtexture2f_vertexbuffer = R_BufferData_Store(rsurface.batchnumvertices * sizeof(float[2]), rsurface.batchtexcoordtexture2f, R_BUFFERDATA_VERTEX, &rsurface.batchtexcoordtexture2f_bufferoffset, !vid.forcevbo); + if (rsurface.batchtexcoordlightmap2f && r_batch_dynamicbuffer.integer && vid.support.arb_vertex_buffer_object) + rsurface.batchtexcoordlightmap2f_vertexbuffer = R_BufferData_Store(rsurface.batchnumvertices * sizeof(float[2]), rsurface.batchtexcoordlightmap2f, R_BUFFERDATA_VERTEX, &rsurface.batchtexcoordlightmap2f_bufferoffset, !vid.forcevbo); + if (rsurface.batchskeletalindex4ub) + rsurface.batchskeletalindex4ub_vertexbuffer = R_BufferData_Store(rsurface.batchnumvertices * sizeof(unsigned char[4]), rsurface.batchskeletalindex4ub, R_BUFFERDATA_VERTEX, &rsurface.batchskeletalindex4ub_bufferoffset, !vid.forcevbo); + if (rsurface.batchskeletalweight4ub) + rsurface.batchskeletalweight4ub_vertexbuffer = R_BufferData_Store(rsurface.batchnumvertices * sizeof(unsigned char[4]), rsurface.batchskeletalweight4ub, R_BUFFERDATA_VERTEX, &rsurface.batchskeletalweight4ub_bufferoffset, !vid.forcevbo); + } + if (rsurface.batchelement3s) + rsurface.batchelement3s_indexbuffer = R_BufferData_Store(rsurface.batchnumtriangles * sizeof(short[3]), rsurface.batchelement3s, R_BUFFERDATA_INDEX16, &rsurface.batchelement3s_bufferoffset, !vid.forcevbo); + else if (rsurface.batchelement3i) + rsurface.batchelement3i_indexbuffer = R_BufferData_Store(rsurface.batchnumtriangles * sizeof(int[3]), rsurface.batchelement3i, R_BUFFERDATA_INDEX32, &rsurface.batchelement3i_bufferoffset, !vid.forcevbo); + } } void RSurf_DrawBatch(void) @@ -10578,10 +10658,7 @@ static void R_DrawTextureSurfaceList_Sky(int texturenumsurfaces, const msurface_ // anything despite that colormask... GL_BlendFunc(GL_ZERO, GL_ONE); RSurf_PrepareVerticesForBatch(BATCHNEED_ARRAY_VERTEX | BATCHNEED_ALLOWMULTIDRAW, texturenumsurfaces, texturesurfacelist); - if (rsurface.batchvertex3fbuffer) - R_Mesh_PrepareVertices_Vertex3f(rsurface.batchnumvertices, rsurface.batchvertex3f, rsurface.batchvertex3fbuffer); - else - R_Mesh_PrepareVertices_Vertex3f(rsurface.batchnumvertices, rsurface.batchvertex3f, rsurface.batchvertex3f_vertexbuffer); + R_Mesh_PrepareVertices_Vertex3f(rsurface.batchnumvertices, rsurface.batchvertex3f, rsurface.batchvertex3f_vertexbuffer, rsurface.batchvertex3f_bufferoffset); } else { @@ -11195,10 +11272,7 @@ static void R_DrawSurface_TransparentCallback(const entity_render_t *ent, const RSurf_SetupDepthAndCulling(); RSurf_PrepareVerticesForBatch(BATCHNEED_ARRAY_VERTEX | BATCHNEED_ALLOWMULTIDRAW, texturenumsurfaces, texturesurfacelist); R_SetupShader_DepthOrShadow(false, false, !!rsurface.batchskeletaltransform3x4); - if (rsurface.batchvertex3fbuffer) - R_Mesh_PrepareVertices_Vertex3f(rsurface.batchnumvertices, rsurface.batchvertex3f, rsurface.batchvertex3fbuffer); - else - R_Mesh_PrepareVertices_Vertex3f(rsurface.batchnumvertices, rsurface.batchvertex3f, rsurface.batchvertex3f_vertexbuffer); + R_Mesh_PrepareVertices_Vertex3f(rsurface.batchnumvertices, rsurface.batchvertex3f, rsurface.batchvertex3f_vertexbuffer, rsurface.batchvertex3f_bufferoffset); RSurf_DrawBatch(); } if (setup) @@ -11290,10 +11364,7 @@ static void R_DrawTextureSurfaceList_DepthOnly(int texturenumsurfaces, const msu return; RSurf_SetupDepthAndCulling(); RSurf_PrepareVerticesForBatch(BATCHNEED_ARRAY_VERTEX | BATCHNEED_ALLOWMULTIDRAW, texturenumsurfaces, texturesurfacelist); - if (rsurface.batchvertex3fbuffer) - R_Mesh_PrepareVertices_Vertex3f(rsurface.batchnumvertices, rsurface.batchvertex3f, rsurface.batchvertex3fbuffer); - else - R_Mesh_PrepareVertices_Vertex3f(rsurface.batchnumvertices, rsurface.batchvertex3f, rsurface.batchvertex3f_vertexbuffer); + R_Mesh_PrepareVertices_Vertex3f(rsurface.batchnumvertices, rsurface.batchvertex3f, rsurface.batchvertex3f_vertexbuffer, rsurface.batchvertex3f_bufferoffset); R_SetupShader_DepthOrShadow(false, false, !!rsurface.batchskeletaltransform3x4); RSurf_DrawBatch(); } diff --git a/gl_rsurf.c b/gl_rsurf.c index 98c36493..8a915155 100644 --- a/gl_rsurf.c +++ b/gl_rsurf.c @@ -1423,10 +1423,7 @@ void R_Q1BSP_DrawShadowMap(int side, entity_render_t *ent, const vec3_t relative --modelsurfacelistindex; GL_CullFace(rsurface.texture->currentmaterialflags & MATERIALFLAG_NOCULLFACE ? GL_NONE : r_refdef.view.cullface_back); RSurf_PrepareVerticesForBatch(BATCHNEED_ARRAY_VERTEX | BATCHNEED_ALLOWMULTIDRAW, batchnumsurfaces, batchsurfacelist); - if (rsurface.batchvertex3fbuffer) - R_Mesh_PrepareVertices_Vertex3f(rsurface.batchnumvertices, rsurface.batchvertex3f, rsurface.batchvertex3fbuffer); - else - R_Mesh_PrepareVertices_Vertex3f(rsurface.batchnumvertices, rsurface.batchvertex3f, rsurface.batchvertex3f_vertexbuffer); + R_Mesh_PrepareVertices_Vertex3f(rsurface.batchnumvertices, rsurface.batchvertex3f, rsurface.batchvertex3f_vertexbuffer, rsurface.batchvertex3f_bufferoffset); RSurf_DrawBatch(); } R_FrameData_ReturnToMark(); diff --git a/model_shared.c b/model_shared.c index 37be74af..5c87e3dd 100644 --- a/model_shared.c +++ b/model_shared.c @@ -200,12 +200,6 @@ void Mod_UnloadModel (dp_model_t *mod) used = mod->used; if (mod->mempool) { - if (mod->surfmesh.vertex3fbuffer) - R_Mesh_DestroyMeshBuffer(mod->surfmesh.vertex3fbuffer); - mod->surfmesh.vertex3fbuffer = NULL; - if (mod->surfmesh.vertexmeshbuffer) - R_Mesh_DestroyMeshBuffer(mod->surfmesh.vertexmeshbuffer); - mod->surfmesh.vertexmeshbuffer = NULL; if (mod->surfmesh.data_element3i_indexbuffer) R_Mesh_DestroyMeshBuffer(mod->surfmesh.data_element3i_indexbuffer); mod->surfmesh.data_element3i_indexbuffer = NULL; @@ -1235,14 +1229,6 @@ static void Mod_ShadowMesh_CreateVBOs(shadowmesh_t *mesh, mempool_t *mempool) } } - // upload r_vertexmesh_t array as a buffer - if (mesh->vertexmesh && !mesh->vertexmeshbuffer) - mesh->vertexmeshbuffer = R_Mesh_CreateMeshBuffer(mesh->vertexmesh, mesh->numverts * sizeof(*mesh->vertexmesh), loadmodel->name, false, false, false, false); - - // upload vertex3f array as a buffer - if (mesh->vertex3f && !mesh->vertex3fbuffer) - mesh->vertex3fbuffer = R_Mesh_CreateMeshBuffer(mesh->vertex3f, mesh->numverts * sizeof(float[3]), loadmodel->name, false, false, false, false); - // upload short indices as a buffer if (mesh->element3s && !mesh->element3s_indexbuffer) mesh->element3s_indexbuffer = R_Mesh_CreateMeshBuffer(mesh->element3s, mesh->numtriangles * sizeof(short[3]), loadmodel->name, true, false, false, true); @@ -1261,12 +1247,14 @@ static void Mod_ShadowMesh_CreateVBOs(shadowmesh_t *mesh, mempool_t *mempool) size_t size; unsigned char *mem; size = 0; + mesh->vbooffset_vertexmesh = size;if (mesh->vertexmesh ) size += mesh->numverts * sizeof(r_vertexmesh_t); mesh->vbooffset_vertex3f = size;if (mesh->vertex3f ) size += mesh->numverts * sizeof(float[3]); mesh->vbooffset_svector3f = size;if (mesh->svector3f ) size += mesh->numverts * sizeof(float[3]); mesh->vbooffset_tvector3f = size;if (mesh->tvector3f ) size += mesh->numverts * sizeof(float[3]); mesh->vbooffset_normal3f = size;if (mesh->normal3f ) size += mesh->numverts * sizeof(float[3]); mesh->vbooffset_texcoord2f = size;if (mesh->texcoord2f ) size += mesh->numverts * sizeof(float[2]); mem = (unsigned char *)Mem_Alloc(tempmempool, size); + if (mesh->vertexmesh ) memcpy(mem + mesh->vbooffset_vertexmesh , mesh->vertexmesh , mesh->numverts * sizeof(r_vertexmesh_t)); if (mesh->vertex3f ) memcpy(mem + mesh->vbooffset_vertex3f , mesh->vertex3f , mesh->numverts * sizeof(float[3])); if (mesh->svector3f ) memcpy(mem + mesh->vbooffset_svector3f , mesh->svector3f , mesh->numverts * sizeof(float[3])); if (mesh->tvector3f ) memcpy(mem + mesh->vbooffset_tvector3f , mesh->tvector3f , mesh->numverts * sizeof(float[3])); @@ -1361,10 +1349,6 @@ void Mod_ShadowMesh_Free(shadowmesh_t *mesh) shadowmesh_t *nextmesh; for (;mesh;mesh = nextmesh) { - if (mesh->vertex3fbuffer) - R_Mesh_DestroyMeshBuffer(mesh->vertex3fbuffer); - if (mesh->vertexmeshbuffer) - R_Mesh_DestroyMeshBuffer(mesh->vertexmeshbuffer); if (mesh->element3i_indexbuffer) R_Mesh_DestroyMeshBuffer(mesh->element3i_indexbuffer); if (mesh->element3s_indexbuffer) @@ -3018,12 +3002,12 @@ void Mod_BuildVBOs(void) // build r_vertexmesh_t array // (compressed interleaved array for D3D) - if (!loadmodel->surfmesh.vertexmesh && vid.useinterleavedarrays) + if (!loadmodel->surfmesh.data_vertexmesh && vid.useinterleavedarrays) { int vertexindex; int numvertices = loadmodel->surfmesh.num_vertices; r_vertexmesh_t *vertexmesh; - loadmodel->surfmesh.vertexmesh = vertexmesh = (r_vertexmesh_t*)Mem_Alloc(loadmodel->mempool, numvertices * sizeof(*loadmodel->surfmesh.vertexmesh)); + loadmodel->surfmesh.data_vertexmesh = vertexmesh = (r_vertexmesh_t*)Mem_Alloc(loadmodel->mempool, numvertices * sizeof(r_vertexmesh_t)); for (vertexindex = 0;vertexindex < numvertices;vertexindex++, vertexmesh++) { VectorCopy(loadmodel->surfmesh.data_vertex3f + 3*vertexindex, vertexmesh->vertex3f); @@ -3042,14 +3026,6 @@ void Mod_BuildVBOs(void) } } - // upload r_vertexmesh_t array as a buffer - if (loadmodel->surfmesh.vertexmesh && !loadmodel->surfmesh.vertexmeshbuffer) - loadmodel->surfmesh.vertexmeshbuffer = R_Mesh_CreateMeshBuffer(loadmodel->surfmesh.vertexmesh, loadmodel->surfmesh.num_vertices * sizeof(*loadmodel->surfmesh.vertexmesh), loadmodel->name, false, false, false, false); - - // upload vertex3f array as a buffer - if (loadmodel->surfmesh.data_vertex3f && !loadmodel->surfmesh.vertex3fbuffer) - loadmodel->surfmesh.vertex3fbuffer = R_Mesh_CreateMeshBuffer(loadmodel->surfmesh.data_vertex3f, loadmodel->surfmesh.num_vertices * sizeof(float[3]), loadmodel->name, false, false, false, false); - // upload short indices as a buffer if (loadmodel->surfmesh.data_element3s && !loadmodel->surfmesh.data_element3s_indexbuffer) loadmodel->surfmesh.data_element3s_indexbuffer = R_Mesh_CreateMeshBuffer(loadmodel->surfmesh.data_element3s, loadmodel->surfmesh.num_triangles * sizeof(short[3]), loadmodel->name, true, false, false, true); @@ -3069,6 +3045,7 @@ void Mod_BuildVBOs(void) size_t size; unsigned char *mem; size = 0; + loadmodel->surfmesh.vbooffset_vertexmesh = size;if (loadmodel->surfmesh.data_vertexmesh ) size += loadmodel->surfmesh.num_vertices * sizeof(r_vertexmesh_t); loadmodel->surfmesh.vbooffset_vertex3f = size;if (loadmodel->surfmesh.data_vertex3f ) size += loadmodel->surfmesh.num_vertices * sizeof(float[3]); loadmodel->surfmesh.vbooffset_svector3f = size;if (loadmodel->surfmesh.data_svector3f ) size += loadmodel->surfmesh.num_vertices * sizeof(float[3]); loadmodel->surfmesh.vbooffset_tvector3f = size;if (loadmodel->surfmesh.data_tvector3f ) size += loadmodel->surfmesh.num_vertices * sizeof(float[3]); @@ -3079,6 +3056,7 @@ void Mod_BuildVBOs(void) loadmodel->surfmesh.vbooffset_skeletalindex4ub = size;if (loadmodel->surfmesh.data_skeletalindex4ub ) size += loadmodel->surfmesh.num_vertices * sizeof(unsigned char[4]); loadmodel->surfmesh.vbooffset_skeletalweight4ub = size;if (loadmodel->surfmesh.data_skeletalweight4ub ) size += loadmodel->surfmesh.num_vertices * sizeof(unsigned char[4]); mem = (unsigned char *)Mem_Alloc(tempmempool, size); + if (loadmodel->surfmesh.data_vertexmesh ) memcpy(mem + loadmodel->surfmesh.vbooffset_vertexmesh , loadmodel->surfmesh.data_vertexmesh , loadmodel->surfmesh.num_vertices * sizeof(r_vertexmesh_t)); if (loadmodel->surfmesh.data_vertex3f ) memcpy(mem + loadmodel->surfmesh.vbooffset_vertex3f , loadmodel->surfmesh.data_vertex3f , loadmodel->surfmesh.num_vertices * sizeof(float[3])); if (loadmodel->surfmesh.data_svector3f ) memcpy(mem + loadmodel->surfmesh.vbooffset_svector3f , loadmodel->surfmesh.data_svector3f , loadmodel->surfmesh.num_vertices * sizeof(float[3])); if (loadmodel->surfmesh.data_tvector3f ) memcpy(mem + loadmodel->surfmesh.vbooffset_tvector3f , loadmodel->surfmesh.data_tvector3f , loadmodel->surfmesh.num_vertices * sizeof(float[3])); @@ -4062,15 +4040,6 @@ static void Mod_GenerateLightmaps_UnweldTriangles(dp_model_t *model) if (model->surfmesh.num_vertices > 65536) model->surfmesh.data_element3s = NULL; - if (model->surfmesh.vertexmesh) - Mem_Free(model->surfmesh.vertexmesh); - model->surfmesh.vertexmesh = NULL; - if (model->surfmesh.vertex3fbuffer) - R_Mesh_DestroyMeshBuffer(model->surfmesh.vertex3fbuffer); - model->surfmesh.vertex3fbuffer = NULL; - if (model->surfmesh.vertexmeshbuffer) - R_Mesh_DestroyMeshBuffer(model->surfmesh.vertexmeshbuffer); - model->surfmesh.vertexmeshbuffer = NULL; if (model->surfmesh.data_element3i_indexbuffer) R_Mesh_DestroyMeshBuffer(model->surfmesh.data_element3i_indexbuffer); model->surfmesh.data_element3i_indexbuffer = NULL; diff --git a/model_shared.h b/model_shared.h index 1604c5fb..dd5d5e07 100644 --- a/model_shared.h +++ b/model_shared.h @@ -163,17 +163,19 @@ typedef struct surfmesh_s unsigned char *data_skeletalindex4ub; unsigned char *data_skeletalweight4ub; int *data_lightmapoffsets; // index into surface's lightmap samples for vertex lighting + r_vertexmesh_t *data_vertexmesh; // interleaved arrays for D3D // vertex buffer object (stores geometry in video memory) r_meshbuffer_t *vbo_vertexbuffer; - size_t vbooffset_vertex3f; - size_t vbooffset_svector3f; - size_t vbooffset_tvector3f; - size_t vbooffset_normal3f; - size_t vbooffset_texcoordtexture2f; - size_t vbooffset_texcoordlightmap2f; - size_t vbooffset_lightmapcolor4f; - size_t vbooffset_skeletalindex4ub; - size_t vbooffset_skeletalweight4ub; + int vbooffset_vertex3f; + int vbooffset_svector3f; + int vbooffset_tvector3f; + int vbooffset_normal3f; + int vbooffset_texcoordtexture2f; + int vbooffset_texcoordlightmap2f; + int vbooffset_lightmapcolor4f; + int vbooffset_skeletalindex4ub; + int vbooffset_skeletalweight4ub; + int vbooffset_vertexmesh; // morph blending, these are zero if model is skeletal or static int num_morphframes; struct md3vertex_s *data_morphmd3vertex; @@ -190,9 +192,7 @@ typedef struct surfmesh_s qboolean isanimated; // vertex and index buffers for rendering - r_vertexmesh_t *vertexmesh; - r_meshbuffer_t *vertex3fbuffer; - r_meshbuffer_t *vertexmeshbuffer; + r_meshbuffer_t *vertexmesh_vertexbuffer; } surfmesh_t; @@ -224,10 +224,13 @@ typedef struct shadowmesh_s // used always int *element3i; r_meshbuffer_t *element3i_indexbuffer; - size_t element3i_bufferoffset; + int element3i_bufferoffset; unsigned short *element3s; r_meshbuffer_t *element3s_indexbuffer; - size_t element3s_bufferoffset; + int element3s_bufferoffset; + // vertex/index buffers for rendering + // (created by Mod_ShadowMesh_Finish if possible) + r_vertexmesh_t *vertexmesh; // usually NULL // used for shadow mapping cubemap side partitioning int sideoffsets[6], sidetotals[6]; // used for shadow mesh (NULL on light mesh) @@ -236,16 +239,12 @@ typedef struct shadowmesh_s // while building meshes shadowmeshvertexhash_t **vertexhashtable, *vertexhashentries; r_meshbuffer_t *vbo_vertexbuffer; - size_t vbooffset_vertex3f; - size_t vbooffset_svector3f; - size_t vbooffset_tvector3f; - size_t vbooffset_normal3f; - size_t vbooffset_texcoord2f; - // vertex/index buffers for rendering - // (created by Mod_ShadowMesh_Finish if possible) - r_vertexmesh_t *vertexmesh; // usually NULL - r_meshbuffer_t *vertex3fbuffer; - r_meshbuffer_t *vertexmeshbuffer; // usually NULL + int vbooffset_vertex3f; + int vbooffset_svector3f; + int vbooffset_tvector3f; + int vbooffset_normal3f; + int vbooffset_texcoord2f; + int vbooffset_vertexmesh; } shadowmesh_t; diff --git a/r_shadow.c b/r_shadow.c index 1327d397..6fe3e0e9 100644 --- a/r_shadow.c +++ b/r_shadow.c @@ -1384,7 +1384,7 @@ void R_Shadow_VolumeFromList(int numverts, int numtris, const float *invertex3f, else if (r_shadow_rendermode == R_SHADOW_RENDERMODE_VISIBLEVOLUMES) { tris = R_Shadow_ConstructShadowVolume_ZFail(numverts, numtris, elements, neighbors, invertex3f, &outverts, shadowelements, shadowvertex3f, projectorigin, projectdirection, projectdistance, nummarktris, marktris); - R_Mesh_PrepareVertices_Vertex3f(outverts, shadowvertex3f, NULL); + R_Mesh_PrepareVertices_Vertex3f(outverts, shadowvertex3f, NULL, 0); R_Mesh_Draw(0, outverts, 0, tris, shadowelements, NULL, 0, NULL, NULL, 0); } else @@ -1418,7 +1418,7 @@ void R_Shadow_VolumeFromList(int numverts, int numtris, const float *invertex3f, GL_CullFace(r_refdef.view.cullface_back); R_SetStencil(true, 255, GL_KEEP, GL_INCR, GL_KEEP, GL_ALWAYS, 128, 255); } - R_Mesh_PrepareVertices_Vertex3f(outverts, shadowvertex3f, NULL); + R_Mesh_PrepareVertices_Vertex3f(outverts, shadowvertex3f, NULL, 0); R_Mesh_Draw(0, outverts, 0, tris, shadowelements, NULL, 0, NULL, NULL, 0); } } @@ -2321,7 +2321,7 @@ void R_Shadow_RenderMode_DrawDeferredLight(qboolean stenciltest, qboolean shadow GL_DepthTest(true); GL_DepthFunc(GL_GREATER); GL_CullFace(r_refdef.view.cullface_back); - R_Mesh_PrepareVertices_Vertex3f(8, vertex3f, NULL); + R_Mesh_PrepareVertices_Vertex3f(8, vertex3f, NULL, 0); R_Mesh_Draw(0, 8, 0, 12, NULL, NULL, 0, bboxelements, NULL, 0); } @@ -3765,10 +3765,7 @@ static void R_Shadow_DrawWorldShadow_ShadowMap(int numsurfaces, int *surfacelist if (!mesh->sidetotals[r_shadow_shadowmapside]) continue; r_refdef.stats[r_stat_lights_shadowtriangles] += mesh->sidetotals[r_shadow_shadowmapside]; - if (mesh->vertex3fbuffer) - R_Mesh_PrepareVertices_Vertex3f(mesh->numverts, mesh->vertex3f, mesh->vertex3fbuffer); - else - R_Mesh_PrepareVertices_Vertex3f(mesh->numverts, mesh->vertex3f, mesh->vbo_vertexbuffer); + R_Mesh_PrepareVertices_Vertex3f(mesh->numverts, mesh->vertex3f, mesh->vbo_vertexbuffer, mesh->vbooffset_vertex3f); R_Mesh_Draw(0, mesh->numverts, mesh->sideoffsets[r_shadow_shadowmapside], mesh->sidetotals[r_shadow_shadowmapside], mesh->element3i, mesh->element3i_indexbuffer, mesh->element3i_bufferoffset, mesh->element3s, mesh->element3s_indexbuffer, mesh->element3s_bufferoffset); } CHECKGLERROR @@ -3805,10 +3802,7 @@ static void R_Shadow_DrawWorldShadow_ShadowVolume(int numsurfaces, int *surfacel for (;mesh;mesh = mesh->next) { r_refdef.stats[r_stat_lights_shadowtriangles] += mesh->numtriangles; - if (mesh->vertex3fbuffer) - R_Mesh_PrepareVertices_Vertex3f(mesh->numverts, mesh->vertex3f, mesh->vertex3fbuffer); - else - R_Mesh_PrepareVertices_Vertex3f(mesh->numverts, mesh->vertex3f, mesh->vbo_vertexbuffer); + R_Mesh_PrepareVertices_Vertex3f(mesh->numverts, mesh->vertex3f, mesh->vbo_vertexbuffer, mesh->vbooffset_vertex3f); if (r_shadow_rendermode == R_SHADOW_RENDERMODE_ZPASS_STENCIL) { // increment stencil if frontface is infront of depthbuffer @@ -5111,13 +5105,13 @@ static void R_BeginCoronaQuery(rtlight_t *rtlight, float scale, qboolean usequer qglBeginQueryARB(GL_SAMPLES_PASSED_ARB, rtlight->corona_queryindex_allpixels); GL_DepthFunc(GL_ALWAYS); R_CalcSprite_Vertex3f(vertex3f, centerorigin, r_refdef.view.right, r_refdef.view.up, scale, -scale, -scale, scale); - R_Mesh_PrepareVertices_Vertex3f(4, vertex3f, NULL); + R_Mesh_PrepareVertices_Vertex3f(4, vertex3f, NULL, 0); R_Mesh_Draw(0, 4, 0, 2, polygonelement3i, NULL, 0, polygonelement3s, NULL, 0); qglEndQueryARB(GL_SAMPLES_PASSED_ARB); GL_DepthFunc(GL_LEQUAL); qglBeginQueryARB(GL_SAMPLES_PASSED_ARB, rtlight->corona_queryindex_visiblepixels); R_CalcSprite_Vertex3f(vertex3f, rtlight->shadoworigin, r_refdef.view.right, r_refdef.view.up, scale, -scale, -scale, scale); - R_Mesh_PrepareVertices_Vertex3f(4, vertex3f, NULL); + R_Mesh_PrepareVertices_Vertex3f(4, vertex3f, NULL, 0); R_Mesh_Draw(0, 4, 0, 2, polygonelement3i, NULL, 0, polygonelement3s, NULL, 0); qglEndQueryARB(GL_SAMPLES_PASSED_ARB); CHECKGLERROR diff --git a/render.h b/render.h index 3fbdcde1..538ab505 100644 --- a/render.h +++ b/render.h @@ -287,40 +287,40 @@ typedef struct rsurfacestate_s int entityskeletaltransform3x4size; float *modelvertex3f; const r_meshbuffer_t *modelvertex3f_vertexbuffer; - size_t modelvertex3f_bufferoffset; + int modelvertex3f_bufferoffset; float *modelsvector3f; const r_meshbuffer_t *modelsvector3f_vertexbuffer; - size_t modelsvector3f_bufferoffset; + int modelsvector3f_bufferoffset; float *modeltvector3f; const r_meshbuffer_t *modeltvector3f_vertexbuffer; - size_t modeltvector3f_bufferoffset; + int modeltvector3f_bufferoffset; float *modelnormal3f; const r_meshbuffer_t *modelnormal3f_vertexbuffer; - size_t modelnormal3f_bufferoffset; + int modelnormal3f_bufferoffset; float *modellightmapcolor4f; const r_meshbuffer_t *modellightmapcolor4f_vertexbuffer; - size_t modellightmapcolor4f_bufferoffset; + int modellightmapcolor4f_bufferoffset; float *modeltexcoordtexture2f; const r_meshbuffer_t *modeltexcoordtexture2f_vertexbuffer; - size_t modeltexcoordtexture2f_bufferoffset; + int modeltexcoordtexture2f_bufferoffset; float *modeltexcoordlightmap2f; const r_meshbuffer_t *modeltexcoordlightmap2f_vertexbuffer; - size_t modeltexcoordlightmap2f_bufferoffset; + int modeltexcoordlightmap2f_bufferoffset; unsigned char *modelskeletalindex4ub; const r_meshbuffer_t *modelskeletalindex4ub_vertexbuffer; - size_t modelskeletalindex4ub_bufferoffset; + int modelskeletalindex4ub_bufferoffset; unsigned char *modelskeletalweight4ub; const r_meshbuffer_t *modelskeletalweight4ub_vertexbuffer; - size_t modelskeletalweight4ub_bufferoffset; + int modelskeletalweight4ub_bufferoffset; r_vertexmesh_t *modelvertexmesh; - const r_meshbuffer_t *modelvertexmeshbuffer; - const r_meshbuffer_t *modelvertex3fbuffer; + const r_meshbuffer_t *modelvertexmesh_vertexbuffer; + int modelvertexmesh_bufferoffset; int *modelelement3i; const r_meshbuffer_t *modelelement3i_indexbuffer; - size_t modelelement3i_bufferoffset; + int modelelement3i_bufferoffset; unsigned short *modelelement3s; const r_meshbuffer_t *modelelement3s_indexbuffer; - size_t modelelement3s_bufferoffset; + int modelelement3s_bufferoffset; int *modellightmapoffsets; int modelnumvertices; int modelnumtriangles; @@ -340,41 +340,41 @@ typedef struct rsurfacestate_s int batchfirsttriangle; int batchnumtriangles; r_vertexmesh_t *batchvertexmesh; - const r_meshbuffer_t *batchvertexmeshbuffer; - const r_meshbuffer_t *batchvertex3fbuffer; + const r_meshbuffer_t *batchvertexmesh_vertexbuffer; + int batchvertexmesh_bufferoffset; float *batchvertex3f; const r_meshbuffer_t *batchvertex3f_vertexbuffer; - size_t batchvertex3f_bufferoffset; + int batchvertex3f_bufferoffset; float *batchsvector3f; const r_meshbuffer_t *batchsvector3f_vertexbuffer; - size_t batchsvector3f_bufferoffset; + int batchsvector3f_bufferoffset; float *batchtvector3f; const r_meshbuffer_t *batchtvector3f_vertexbuffer; - size_t batchtvector3f_bufferoffset; + int batchtvector3f_bufferoffset; float *batchnormal3f; const r_meshbuffer_t *batchnormal3f_vertexbuffer; - size_t batchnormal3f_bufferoffset; + int batchnormal3f_bufferoffset; float *batchlightmapcolor4f; const r_meshbuffer_t *batchlightmapcolor4f_vertexbuffer; - size_t batchlightmapcolor4f_bufferoffset; + int batchlightmapcolor4f_bufferoffset; float *batchtexcoordtexture2f; const r_meshbuffer_t *batchtexcoordtexture2f_vertexbuffer; - size_t batchtexcoordtexture2f_bufferoffset; + int batchtexcoordtexture2f_bufferoffset; float *batchtexcoordlightmap2f; const r_meshbuffer_t *batchtexcoordlightmap2f_vertexbuffer; - size_t batchtexcoordlightmap2f_bufferoffset; + int batchtexcoordlightmap2f_bufferoffset; unsigned char *batchskeletalindex4ub; const r_meshbuffer_t *batchskeletalindex4ub_vertexbuffer; - size_t batchskeletalindex4ub_bufferoffset; + int batchskeletalindex4ub_bufferoffset; unsigned char *batchskeletalweight4ub; const r_meshbuffer_t *batchskeletalweight4ub_vertexbuffer; - size_t batchskeletalweight4ub_bufferoffset; + int batchskeletalweight4ub_bufferoffset; int *batchelement3i; const r_meshbuffer_t *batchelement3i_indexbuffer; - size_t batchelement3i_bufferoffset; + int batchelement3i_bufferoffset; unsigned short *batchelement3s; const r_meshbuffer_t *batchelement3s_indexbuffer; - size_t batchelement3s_bufferoffset; + int batchelement3s_bufferoffset; int batchskeletalnumtransforms; float *batchskeletaltransform3x4; const r_meshbuffer_t *batchskeletaltransform3x4buffer; // uniform buffer @@ -383,7 +383,7 @@ typedef struct rsurfacestate_s // rendering pass processing arrays in GL11 and GL13 paths float *passcolor4f; const r_meshbuffer_t *passcolor4f_vertexbuffer; - size_t passcolor4f_bufferoffset; + int passcolor4f_bufferoffset; // some important fields from the entity int ent_skinnum; -- 2.39.2