- enable use of vertex buffer for sprite rendering.

This commit is contained in:
Christoph Oelckers 2014-05-12 20:23:54 +02:00
parent 9c659b948c
commit b514a815f4
4 changed files with 67 additions and 47 deletions

View File

@ -26,6 +26,14 @@ struct FFlatVertex
float u,v; // texture coordinates float u,v; // texture coordinates
void SetFlatVertex(vertex_t *vt, const secplane_t &plane); void SetFlatVertex(vertex_t *vt, const secplane_t &plane);
void Set(float xx, float zz, float yy, float uu, float vv)
{
x = xx;
z = zz;
y = yy;
u = uu;
v = vv;
}
}; };
#define VTO ((FFlatVertex*)NULL) #define VTO ((FFlatVertex*)NULL)

View File

@ -528,7 +528,7 @@ void ADynamicLight::CollectWithinRadius(subsector_t *subSec, float radius)
touching_subsectors = AddLightNode(&subSec->lighthead[additive], subSec, this, touching_subsectors); touching_subsectors = AddLightNode(&subSec->lighthead[additive], subSec, this, touching_subsectors);
if (subSec->sector->validcount != ::validcount) if (subSec->sector->validcount != ::validcount)
{ {
touching_sector = AddLightNode(&subSec->sector->lighthead[additive], subSec->sector, this, touching_sector); touching_sector = AddLightNode(&subSec->render_sector->lighthead[additive], subSec->sector, this, touching_sector);
subSec->sector->validcount = ::validcount; subSec->sector->validcount = ::validcount;
} }

View File

@ -52,6 +52,7 @@
#include "gl/system/gl_cvars.h" #include "gl/system/gl_cvars.h"
#include "gl/renderer/gl_lightdata.h" #include "gl/renderer/gl_lightdata.h"
#include "gl/renderer/gl_renderstate.h" #include "gl/renderer/gl_renderstate.h"
#include "gl/renderer/gl_renderer.h"
#include "gl/data/gl_data.h" #include "gl/data/gl_data.h"
#include "gl/dynlights/gl_glow.h" #include "gl/dynlights/gl_glow.h"
#include "gl/scene/gl_drawinfo.h" #include "gl/scene/gl_drawinfo.h"
@ -60,6 +61,7 @@
#include "gl/shaders/gl_shader.h" #include "gl/shaders/gl_shader.h"
#include "gl/textures/gl_material.h" #include "gl/textures/gl_material.h"
#include "gl/utility/gl_clock.h" #include "gl/utility/gl_clock.h"
#include "gl/data/gl_vertexbuffer.h"
CVAR(Bool, gl_usecolorblending, true, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) CVAR(Bool, gl_usecolorblending, true, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
CVAR(Bool, gl_spritebrightfog, false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG); CVAR(Bool, gl_spritebrightfog, false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG);
@ -265,33 +267,10 @@ void GLSprite::Draw(int pass)
v4 = Vector(x2, z2, y2); v4 = Vector(x2, z2, y2);
} }
glBegin(GL_TRIANGLE_STRIP); FFlatVertex *ptr;
if (gltexture) unsigned int offset, count;
if (!gl_usevbo)
{ {
glTexCoord2f(ul, vt); glVertex3fv(&v1[0]);
glTexCoord2f(ur, vt); glVertex3fv(&v2[0]);
glTexCoord2f(ul, vb); glVertex3fv(&v3[0]);
glTexCoord2f(ur, vb); glVertex3fv(&v4[0]);
}
else // Particle
{
glVertex3fv(&v1[0]);
glVertex3fv(&v2[0]);
glVertex3fv(&v3[0]);
glVertex3fv(&v4[0]);
}
glEnd();
if (foglayer)
{
// If we get here we know that we have colored fog and no fixed colormap.
gl_SetFog(foglevel, rel, &Colormap, additivefog);
gl_RenderState.SetFixedColormap(CM_FOGLAYER);
gl_RenderState.BlendEquation(GL_FUNC_ADD);
gl_RenderState.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
gl_RenderState.Apply();
glBegin(GL_TRIANGLE_STRIP); glBegin(GL_TRIANGLE_STRIP);
if (gltexture) if (gltexture)
{ {
@ -307,7 +286,56 @@ void GLSprite::Draw(int pass)
glVertex3fv(&v3[0]); glVertex3fv(&v3[0]);
glVertex3fv(&v4[0]); glVertex3fv(&v4[0]);
} }
glEnd(); glEnd();
}
else
{
ptr = GLRenderer->mVBO->GetBuffer();
ptr->Set(v1[0], v1[1], v1[2], ul, vt);
ptr++;
ptr->Set(v2[0], v2[1], v2[2], ur, vt);
ptr++;
ptr->Set(v3[0], v3[1], v3[2], ul, vb);
ptr++;
ptr->Set(v4[0], v4[1], v4[2], ur, vb);
ptr++;
count = GLRenderer->mVBO->GetCount(ptr, &offset);
glDrawArrays(GL_TRIANGLE_STRIP, offset, count);
}
if (foglayer)
{
// If we get here we know that we have colored fog and no fixed colormap.
gl_SetFog(foglevel, rel, &Colormap, additivefog);
gl_RenderState.SetFixedColormap(CM_FOGLAYER);
gl_RenderState.BlendEquation(GL_FUNC_ADD);
gl_RenderState.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
gl_RenderState.Apply();
if (!gl_usevbo)
{
glBegin(GL_TRIANGLE_STRIP);
if (gltexture)
{
glTexCoord2f(ul, vt); glVertex3fv(&v1[0]);
glTexCoord2f(ur, vt); glVertex3fv(&v2[0]);
glTexCoord2f(ul, vb); glVertex3fv(&v3[0]);
glTexCoord2f(ur, vb); glVertex3fv(&v4[0]);
}
else // Particle
{
glVertex3fv(&v1[0]);
glVertex3fv(&v2[0]);
glVertex3fv(&v3[0]);
glVertex3fv(&v4[0]);
}
glEnd();
}
else
{
glDrawArrays(GL_TRIANGLE_STRIP, offset, count);
}
gl_RenderState.SetFixedColormap(CM_DEFAULT); gl_RenderState.SetFixedColormap(CM_DEFAULT);
} }
} }

View File

@ -290,32 +290,16 @@ void GLWall::RenderWall(int textured, float * color2, ADynamicLight * light)
{ {
FFlatVertex *ptr = GLRenderer->mVBO->GetBuffer(); FFlatVertex *ptr = GLRenderer->mVBO->GetBuffer();
ptr->x = glseg.x1; ptr->Set(glseg.x1, zbottom[0], glseg.y1, tcs[0].u, tcs[0].v);
ptr->y = glseg.y1;
ptr->z = zbottom[0];
ptr->u = tcs[0].u;
ptr->v = tcs[0].v;
ptr++; ptr++;
if (split && glseg.fracleft == 0) SplitLeftEdge(tcs, ptr); if (split && glseg.fracleft == 0) SplitLeftEdge(tcs, ptr);
ptr->x = glseg.x1; ptr->Set(glseg.x1, ztop[0], glseg.y1, tcs[1].u, tcs[1].v);
ptr->y = glseg.y1;
ptr->z = ztop[0];
ptr->u = tcs[1].u;
ptr->v = tcs[1].v;
ptr++; ptr++;
if (split && !(flags & GLWF_NOSPLITUPPER)) SplitUpperEdge(tcs, ptr); if (split && !(flags & GLWF_NOSPLITUPPER)) SplitUpperEdge(tcs, ptr);
ptr->x = glseg.x2; ptr->Set(glseg.x2, ztop[1], glseg.y2, tcs[2].u, tcs[2].v);
ptr->y = glseg.y2;
ptr->z = ztop[1];
ptr->u = tcs[2].u;
ptr->v = tcs[2].v;
ptr++; ptr++;
if (split && glseg.fracright == 1) SplitRightEdge(tcs, ptr); if (split && glseg.fracright == 1) SplitRightEdge(tcs, ptr);
ptr->x = glseg.x2; ptr->Set(glseg.x2, zbottom[1], glseg.y2, tcs[3].u, tcs[3].v);
ptr->y = glseg.y2;
ptr->z = zbottom[1];
ptr->u = tcs[3].u;
ptr->v = tcs[3].v;
ptr++; ptr++;
if (split && !(flags & GLWF_NOSPLITLOWER)) SplitLowerEdge(tcs, ptr); if (split && !(flags & GLWF_NOSPLITLOWER)) SplitLowerEdge(tcs, ptr);
unsigned int offset; unsigned int offset;