- replaced builtin texture coordinate vertex attribute.

This commit is contained in:
Christoph Oelckers 2014-07-15 00:59:01 +02:00
parent 5a322742c3
commit 1b7f5a2e6a
6 changed files with 20 additions and 16 deletions

View file

@ -115,9 +115,9 @@ FFlatVertexBuffer::FFlatVertexBuffer()
glBindVertexArray(vao_id); glBindVertexArray(vao_id);
glBindBuffer(GL_ARRAY_BUFFER, vbo_id); glBindBuffer(GL_ARRAY_BUFFER, vbo_id);
glVertexPointer(3,GL_FLOAT, sizeof(FFlatVertex), &VTO->x); glVertexPointer(3,GL_FLOAT, sizeof(FFlatVertex), &VTO->x);
glTexCoordPointer(2,GL_FLOAT, sizeof(FFlatVertex), &VTO->u); glVertexAttribPointer(VATTR_TEXCOORD, 2,GL_FLOAT, false, sizeof(FFlatVertex), &VTO->u);
glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY); glEnableVertexAttribArray(VATTR_TEXCOORD);
glBindVertexArray(0); glBindVertexArray(0);
} }
@ -140,6 +140,7 @@ CVAR(Bool, gl_testbuffer, false, 0)
void FFlatVertexBuffer::ImmRenderBuffer(unsigned int primtype, unsigned int offset, unsigned int count) void FFlatVertexBuffer::ImmRenderBuffer(unsigned int primtype, unsigned int offset, unsigned int count)
{ {
#if 0
if (!gl_testbuffer) // todo: remove the immediate mode calls once the uniform array method has been tested. if (!gl_testbuffer) // todo: remove the immediate mode calls once the uniform array method has been tested.
{ {
glBegin(primtype); glBegin(primtype);
@ -151,6 +152,7 @@ void FFlatVertexBuffer::ImmRenderBuffer(unsigned int primtype, unsigned int offs
glEnd(); glEnd();
} }
else else
#endif
{ {
if (count > 20) if (count > 20)
{ {

View file

@ -117,7 +117,7 @@ FModelVertexBuffer::FModelVertexBuffer()
glBufferData(GL_ELEMENT_ARRAY_BUFFER,ibo_shadowdata.Size() * sizeof(unsigned int), &ibo_shadowdata[0], GL_STATIC_DRAW); glBufferData(GL_ELEMENT_ARRAY_BUFFER,ibo_shadowdata.Size() * sizeof(unsigned int), &ibo_shadowdata[0], GL_STATIC_DRAW);
glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY); glEnableVertexAttribArray(VATTR_TEXCOORD);
glEnableVertexAttribArray(VATTR_VERTEX2); glEnableVertexAttribArray(VATTR_VERTEX2);
glBindVertexArray(0); glBindVertexArray(0);
} }
@ -141,7 +141,7 @@ FModelVertexBuffer::~FModelVertexBuffer()
unsigned int FModelVertexBuffer::SetupFrame(unsigned int frame1, unsigned int frame2, float factor) unsigned int FModelVertexBuffer::SetupFrame(unsigned int frame1, unsigned int frame2, float factor)
{ {
glVertexPointer(3, GL_FLOAT, sizeof(FModelVertex), &VMO[frame1].x); glVertexPointer(3, GL_FLOAT, sizeof(FModelVertex), &VMO[frame1].x);
glTexCoordPointer(2, GL_FLOAT, sizeof(FModelVertex), &VMO[frame1].u); glVertexAttribPointer(VATTR_TEXCOORD, 2, GL_FLOAT, false, sizeof(FModelVertex), &VMO[frame1].u);
glVertexAttribPointer(VATTR_VERTEX2, 3, GL_FLOAT, false, sizeof(FModelVertex), &VMO[frame2].x); glVertexAttribPointer(VATTR_VERTEX2, 3, GL_FLOAT, false, sizeof(FModelVertex), &VMO[frame2].x);
return frame1; return frame1;
} }

View file

@ -81,10 +81,10 @@ FSkyVertexBuffer::FSkyVertexBuffer()
glBindVertexArray(vao_id); glBindVertexArray(vao_id);
glBindBuffer(GL_ARRAY_BUFFER, vbo_id); glBindBuffer(GL_ARRAY_BUFFER, vbo_id);
glVertexPointer(3, GL_FLOAT, sizeof(FSkyVertex), &VSO->x); glVertexPointer(3, GL_FLOAT, sizeof(FSkyVertex), &VSO->x);
glTexCoordPointer(2, GL_FLOAT, sizeof(FSkyVertex), &VSO->u); glVertexAttribPointer(VATTR_TEXCOORD, 2, GL_FLOAT, false, sizeof(FSkyVertex), &VSO->u);
glVertexAttribPointer(VATTR_COLOR, 4, GL_UNSIGNED_BYTE, true, sizeof(FSkyVertex), &VSO->color); glVertexAttribPointer(VATTR_COLOR, 4, GL_UNSIGNED_BYTE, true, sizeof(FSkyVertex), &VSO->color);
glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY); glEnableVertexAttribArray(VATTR_TEXCOORD);
glEnableVertexAttribArray(VATTR_COLOR); glEnableVertexAttribArray(VATTR_COLOR);
glBindVertexArray(0); glBindVertexArray(0);

View file

@ -157,6 +157,8 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char *
glAttachShader(hShader, hVertProg); glAttachShader(hShader, hVertProg);
glAttachShader(hShader, hFragProg); glAttachShader(hShader, hFragProg);
glBindAttribLocation(hShader, VATTR_TEXCOORD, "aTexCoord");
glBindAttribLocation(hShader, VATTR_COLOR, "aColor"); glBindAttribLocation(hShader, VATTR_COLOR, "aColor");
glBindAttribLocation(hShader, VATTR_VERTEX2, "aVertex2"); glBindAttribLocation(hShader, VATTR_VERTEX2, "aVertex2");

View file

@ -9,8 +9,10 @@ extern bool gl_shaderactive;
enum enum
{ {
VATTR_COLOR = 14, VATTR_VERTEX = 0,
VATTR_VERTEX2 = 15 VATTR_TEXCOORD = 1,
VATTR_COLOR = 2,
VATTR_VERTEX2 = 3
}; };

View file

@ -1,4 +1,5 @@
in vec2 aTexCoord;
in vec4 aColor; in vec4 aColor;
#ifndef SIMPLE // we do not need these for simple shaders #ifndef SIMPLE // we do not need these for simple shaders
in vec4 aVertex2; in vec4 aVertex2;
@ -15,26 +16,23 @@ uniform float fakeVB[100];
void main() void main()
{ {
#ifdef UNIFORM_VB
vec4 vert; vec4 vert;
vec4 tc; vec4 tc;
#ifdef UNIFORM_VB
if (gl_MultiTexCoord0.x >= 100000.0) if (gl_MultiTexCoord0.x >= 100000.0)
{ {
int fakeVI = int(gl_MultiTexCoord0.y)*5; int fakeVI = int(aTexCoord.y)*5;
vert = gl_Vertex + vec4(fakeVB[fakeVI], fakeVB[fakeVI+1], fakeVB[fakeVI+2], 0.0); vert = gl_Vertex + vec4(fakeVB[fakeVI], fakeVB[fakeVI+1], fakeVB[fakeVI+2], 0.0);
tc = vec4(fakeVB[fakeVI+3], fakeVB[fakeVI+4], 0.0, 0.0); tc = vec4(fakeVB[fakeVI+3], fakeVB[fakeVI+4], 0.0, 0.0);
} }
else else
#endif
{ {
vert = gl_Vertex; vert = gl_Vertex;
tc = gl_MultiTexCoord0; tc = vec4(aTexCoord, 0.0, 0.0);
} }
#else
#define vert gl_Vertex
#define tc gl_MultiTexCoord0
#endif
#ifndef SIMPLE #ifndef SIMPLE
vec4 worldcoord = ModelMatrix * mix(vert, aVertex2, uInterpolationFactor); vec4 worldcoord = ModelMatrix * mix(vert, aVertex2, uInterpolationFactor);