2013-06-23 07:49:34 +00:00
# ifndef __VERTEXBUFFER_H
# define __VERTEXBUFFER_H
# include "tarray.h"
struct vertex_t ;
struct secplane_t ;
struct subsector_t ;
struct sector_t ;
class FVertexBuffer
{
protected :
unsigned int vbo_id ;
public :
FVertexBuffer ( ) ;
virtual ~ FVertexBuffer ( ) ;
virtual void BindVBO ( ) = 0 ;
} ;
2014-05-10 19:47:07 +00:00
struct FFlatVertex
2013-06-23 07:49:34 +00:00
{
2014-05-10 19:47:07 +00:00
float x , z , y ; // world position
2013-06-23 07:49:34 +00:00
float u , v ; // texture coordinates
void SetFlatVertex ( vertex_t * vt , const secplane_t & plane ) ;
2014-05-12 18:23:54 +00:00
void Set ( float xx , float zz , float yy , float uu , float vv )
{
x = xx ;
z = zz ;
y = yy ;
u = uu ;
v = vv ;
}
2013-06-23 07:49:34 +00:00
} ;
# define VTO ((FFlatVertex*)NULL)
class FFlatVertexBuffer : public FVertexBuffer
{
FFlatVertex * map ;
2014-05-10 19:47:07 +00:00
unsigned int mIndex ;
2014-05-10 23:23:27 +00:00
unsigned int mCurIndex ;
2013-06-23 07:49:34 +00:00
void CheckPlanes ( sector_t * sector ) ;
2014-05-20 22:36:04 +00:00
const unsigned int BUFFER_SIZE = 2000000 ;
2013-06-23 07:49:34 +00:00
public :
int vbo_arg ;
2014-05-10 19:47:07 +00:00
TArray < FFlatVertex > vbo_shadowdata ; // this is kept around for updating the actual (non-readable) buffer
2013-06-23 07:49:34 +00:00
FFlatVertexBuffer ( ) ;
~ FFlatVertexBuffer ( ) ;
2014-05-10 19:47:07 +00:00
void CreateVBO ( ) ;
void BindVBO ( ) ;
void CheckUpdate ( sector_t * sector ) ;
2014-05-10 23:23:27 +00:00
FFlatVertex * GetBuffer ( )
{
return & map [ mCurIndex ] ;
}
unsigned int GetCount ( FFlatVertex * newptr , unsigned int * poffset )
{
2014-05-13 10:00:11 +00:00
unsigned int newofs = ( unsigned int ) ( newptr - map ) ;
2014-05-10 23:23:27 +00:00
unsigned int diff = newofs - mCurIndex ;
* poffset = mCurIndex ;
mCurIndex = newofs ;
2014-05-20 22:36:04 +00:00
if ( mCurIndex > = BUFFER_SIZE ) mCurIndex = mIndex ;
2014-05-10 23:23:27 +00:00
return diff ;
}
2014-05-20 20:37:38 +00:00
# ifdef __GL_PCH_H // we need the system includes for this but we cannot include them ourselves without creating #define clashes. The affected files wouldn't try to draw anyway.
void RenderCurrent ( FFlatVertex * newptr , unsigned int primtype )
{
unsigned int offset ;
unsigned int count = GetCount ( newptr , & offset ) ;
glDrawArrays ( primtype , offset , count ) ;
}
# endif
2014-05-10 23:23:27 +00:00
void Reset ( )
{
mCurIndex = mIndex ;
}
2014-05-10 19:47:07 +00:00
private :
2013-06-23 07:49:34 +00:00
int CreateSubsectorVertices ( subsector_t * sub , const secplane_t & plane , int floor ) ;
int CreateSectorVertices ( sector_t * sec , const secplane_t & plane , int floor ) ;
int CreateVertices ( int h , sector_t * sec , const secplane_t & plane , int floor ) ;
void CreateFlatVBO ( ) ;
void UpdatePlaneVertices ( sector_t * sec , int plane ) ;
} ;
# endif