mirror of
https://github.com/ZDoom/qzdoom-gpl.git
synced 2024-11-30 23:51:05 +00:00
- use vertex array objects to manage vertex buffers.
This commit is contained in:
parent
5ee626459d
commit
9a6bc64381
4 changed files with 34 additions and 53 deletions
|
@ -58,8 +58,10 @@
|
||||||
|
|
||||||
FVertexBuffer::FVertexBuffer()
|
FVertexBuffer::FVertexBuffer()
|
||||||
{
|
{
|
||||||
vbo_id = 0;
|
vao_id = vbo_id = 0;
|
||||||
glGenBuffers(1, &vbo_id);
|
glGenBuffers(1, &vbo_id);
|
||||||
|
glGenVertexArrays(1, &vao_id);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FVertexBuffer::~FVertexBuffer()
|
FVertexBuffer::~FVertexBuffer()
|
||||||
|
@ -68,6 +70,15 @@ FVertexBuffer::~FVertexBuffer()
|
||||||
{
|
{
|
||||||
glDeleteBuffers(1, &vbo_id);
|
glDeleteBuffers(1, &vbo_id);
|
||||||
}
|
}
|
||||||
|
if (vao_id != 0)
|
||||||
|
{
|
||||||
|
glDeleteVertexArrays(1, &vao_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void FVertexBuffer::BindVBO()
|
||||||
|
{
|
||||||
|
glBindVertexArray(vao_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
@ -100,6 +111,14 @@ FFlatVertexBuffer::FFlatVertexBuffer()
|
||||||
glBufferData(GL_ARRAY_BUFFER, 20 * sizeof(FFlatVertex), fill, GL_STATIC_DRAW);
|
glBufferData(GL_ARRAY_BUFFER, 20 * sizeof(FFlatVertex), fill, GL_STATIC_DRAW);
|
||||||
}
|
}
|
||||||
mIndex = mCurIndex = 0;
|
mIndex = mCurIndex = 0;
|
||||||
|
|
||||||
|
glBindVertexArray(vao_id);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, vbo_id);
|
||||||
|
glVertexPointer(3,GL_FLOAT, sizeof(FFlatVertex), &VTO->x);
|
||||||
|
glTexCoordPointer(2,GL_FLOAT, sizeof(FFlatVertex), &VTO->u);
|
||||||
|
glEnableClientState(GL_VERTEX_ARRAY);
|
||||||
|
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||||
|
glBindVertexArray(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
FFlatVertexBuffer::~FFlatVertexBuffer()
|
FFlatVertexBuffer::~FFlatVertexBuffer()
|
||||||
|
@ -370,27 +389,6 @@ void FFlatVertexBuffer::CreateVBO()
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
void FFlatVertexBuffer::BindVBO()
|
|
||||||
{
|
|
||||||
//if (gl.flags & RFL_BUFFER_STORAGE)
|
|
||||||
{
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, vbo_id);
|
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
|
||||||
glVertexPointer(3,GL_FLOAT, sizeof(FFlatVertex), &VTO->x);
|
|
||||||
glTexCoordPointer(2,GL_FLOAT, sizeof(FFlatVertex), &VTO->u);
|
|
||||||
glEnableClientState(GL_VERTEX_ARRAY);
|
|
||||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
|
||||||
glDisableClientState(GL_COLOR_ARRAY);
|
|
||||||
glDisableVertexAttribArray(VATTR_VERTEX2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//==========================================================================
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//==========================================================================
|
|
||||||
|
|
||||||
void FFlatVertexBuffer::CheckPlanes(sector_t *sector)
|
void FFlatVertexBuffer::CheckPlanes(sector_t *sector)
|
||||||
{
|
{
|
||||||
if (gl.flags & RFL_BUFFER_STORAGE)
|
if (gl.flags & RFL_BUFFER_STORAGE)
|
||||||
|
|
|
@ -15,11 +15,12 @@ class FVertexBuffer
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
unsigned int vbo_id;
|
unsigned int vbo_id;
|
||||||
|
unsigned int vao_id;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FVertexBuffer();
|
FVertexBuffer();
|
||||||
virtual ~FVertexBuffer();
|
virtual ~FVertexBuffer();
|
||||||
virtual void BindVBO() = 0;
|
void BindVBO();
|
||||||
};
|
};
|
||||||
|
|
||||||
struct FFlatVertex
|
struct FFlatVertex
|
||||||
|
@ -60,7 +61,6 @@ public:
|
||||||
~FFlatVertexBuffer();
|
~FFlatVertexBuffer();
|
||||||
|
|
||||||
void CreateVBO();
|
void CreateVBO();
|
||||||
void BindVBO();
|
|
||||||
void CheckUpdate(sector_t *sector);
|
void CheckUpdate(sector_t *sector);
|
||||||
|
|
||||||
FFlatVertex *GetBuffer()
|
FFlatVertex *GetBuffer()
|
||||||
|
@ -162,7 +162,6 @@ public:
|
||||||
|
|
||||||
FSkyVertexBuffer();
|
FSkyVertexBuffer();
|
||||||
virtual ~FSkyVertexBuffer();
|
virtual ~FSkyVertexBuffer();
|
||||||
virtual void BindVBO();
|
|
||||||
void RenderDome(FMaterial *tex, int mode);
|
void RenderDome(FMaterial *tex, int mode);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -203,7 +202,6 @@ public:
|
||||||
FModelVertexBuffer();
|
FModelVertexBuffer();
|
||||||
~FModelVertexBuffer();
|
~FModelVertexBuffer();
|
||||||
|
|
||||||
void BindVBO();
|
|
||||||
unsigned int SetupFrame(unsigned int frame1, unsigned int frame2, float factor);
|
unsigned int SetupFrame(unsigned int frame1, unsigned int frame2, float factor);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -109,11 +109,17 @@ FModelVertexBuffer::FModelVertexBuffer()
|
||||||
Models[i]->BuildVertexBuffer(this);
|
Models[i]->BuildVertexBuffer(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glBindVertexArray(vao_id);
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, vbo_id);
|
glBindBuffer(GL_ARRAY_BUFFER, vbo_id);
|
||||||
glBufferData(GL_ARRAY_BUFFER,vbo_shadowdata.Size() * sizeof(FModelVertex), &vbo_shadowdata[0], GL_STATIC_DRAW);
|
glBufferData(GL_ARRAY_BUFFER,vbo_shadowdata.Size() * sizeof(FModelVertex), &vbo_shadowdata[0], GL_STATIC_DRAW);
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo_id);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo_id);
|
||||||
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_TEXTURE_COORD_ARRAY);
|
||||||
|
glEnableVertexAttribArray(VATTR_VERTEX2);
|
||||||
|
glBindVertexArray(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
FModelVertexBuffer::~FModelVertexBuffer()
|
FModelVertexBuffer::~FModelVertexBuffer()
|
||||||
|
@ -125,24 +131,6 @@ FModelVertexBuffer::~FModelVertexBuffer()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//===========================================================================
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//===========================================================================
|
|
||||||
|
|
||||||
void FModelVertexBuffer::BindVBO()
|
|
||||||
{
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, vbo_id);
|
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo_id);
|
|
||||||
//glVertexPointer(3, GL_FLOAT, sizeof(FModelVertex), &VMO->x);
|
|
||||||
//glTexCoordPointer(2, GL_FLOAT, sizeof(FModelVertex), &VMO->u);
|
|
||||||
glEnableClientState(GL_VERTEX_ARRAY);
|
|
||||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
|
||||||
glDisableClientState(GL_COLOR_ARRAY);
|
|
||||||
glEnableVertexAttribArray(VATTR_VERTEX2);
|
|
||||||
}
|
|
||||||
|
|
||||||
//===========================================================================
|
//===========================================================================
|
||||||
//
|
//
|
||||||
// Sets up the buffer starts for frame interpolation
|
// Sets up the buffer starts for frame interpolation
|
||||||
|
|
|
@ -77,25 +77,22 @@ extern int skyfog;
|
||||||
FSkyVertexBuffer::FSkyVertexBuffer()
|
FSkyVertexBuffer::FSkyVertexBuffer()
|
||||||
{
|
{
|
||||||
CreateDome();
|
CreateDome();
|
||||||
}
|
|
||||||
|
|
||||||
FSkyVertexBuffer::~FSkyVertexBuffer()
|
glBindVertexArray(vao_id);
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void FSkyVertexBuffer::BindVBO()
|
|
||||||
{
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, vbo_id);
|
glBindBuffer(GL_ARRAY_BUFFER, vbo_id);
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
|
||||||
glVertexPointer(3, GL_FLOAT, sizeof(FSkyVertex), &VSO->x);
|
glVertexPointer(3, GL_FLOAT, sizeof(FSkyVertex), &VSO->x);
|
||||||
glTexCoordPointer(2, GL_FLOAT, sizeof(FSkyVertex), &VSO->u);
|
glTexCoordPointer(2, GL_FLOAT, sizeof(FSkyVertex), &VSO->u);
|
||||||
glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(FSkyVertex), &VSO->color);
|
glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(FSkyVertex), &VSO->color);
|
||||||
glEnableClientState(GL_VERTEX_ARRAY);
|
glEnableClientState(GL_VERTEX_ARRAY);
|
||||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||||
glEnableClientState(GL_COLOR_ARRAY);
|
glEnableClientState(GL_COLOR_ARRAY);
|
||||||
glDisableVertexAttribArray(VATTR_VERTEX2);
|
glBindVertexArray(0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FSkyVertexBuffer::~FSkyVertexBuffer()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
|
|
Loading…
Reference in a new issue