Skip to content

Commit 6d73965

Browse files
committed
Move VBO/vertex specification to separate headers
Avoid circular dependencies when adding GLVAOs.
1 parent 430b387 commit 6d73965

16 files changed

+249
-139
lines changed

src.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ set(RENDERERLIST
9999
${ENGINE_DIR}/renderer/GeometryOptimiser.h
100100
${ENGINE_DIR}/renderer/GLMemory.cpp
101101
${ENGINE_DIR}/renderer/GLMemory.h
102+
${ENGINE_DIR}/renderer/GLUtils.h
102103
${ENGINE_DIR}/renderer/InternalImage.cpp
103104
${ENGINE_DIR}/renderer/InternalImage.h
104105
${ENGINE_DIR}/renderer/Material.cpp
@@ -137,6 +138,8 @@ set(RENDERERLIST
137138
${ENGINE_DIR}/renderer/tr_surface.cpp
138139
${ENGINE_DIR}/renderer/tr_types.h
139140
${ENGINE_DIR}/renderer/tr_vbo.cpp
141+
${ENGINE_DIR}/renderer/VBO.h
142+
${ENGINE_DIR}/renderer/VertexSpecification.h
140143
${ENGINE_DIR}/renderer/tr_video.cpp
141144
${ENGINE_DIR}/renderer/tr_world.cpp
142145
${ENGINE_DIR}/sys/sdl_glimp.cpp

src/engine/renderer/GLMemory.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3838

3939
#include "common/Common.h"
4040
#include "GL/glew.h"
41-
#include "tr_local.h"
41+
4242
#include "BufferBind.h"
43+
#include "GLUtils.h"
44+
#include "VertexSpecification.h"
4345

4446
class GLBuffer {
4547
public:

src/engine/renderer/GLUtils.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
===========================================================================
3+
Copyright (C) 1999-2005 Id Software, Inc.
4+
Copyright (C) 2006-2011 Robert Beckebans <[email protected]>
5+
6+
This file is part of Daemon source code.
7+
8+
Daemon source code is free software; you can redistribute it
9+
and/or modify it under the terms of the GNU General Public License as
10+
published by the Free Software Foundation; either version 2 of the License,
11+
or (at your option) any later version.
12+
13+
Daemon source code is distributed in the hope that it will be
14+
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
GNU General Public License for more details.
17+
18+
You should have received a copy of the GNU General Public License
19+
along with Daemon source code; if not, write to the Free Software
20+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21+
===========================================================================
22+
*/
23+
// GLUtils.h
24+
25+
#ifndef GLUTILS_H
26+
#define GLUTILS_H
27+
28+
#include "common/Common.h"
29+
#include "GL/glew.h"
30+
31+
#include "tr_public.h"
32+
#include "tr_types.h"
33+
34+
extern glconfig_t glConfig; // outside of TR since it shouldn't be cleared during ref re-init
35+
extern glconfig2_t glConfig2;
36+
37+
void GL_CheckErrors_( const char *filename, int line );
38+
39+
#define GL_CheckErrors() do { if ( !glConfig.smpActive ) GL_CheckErrors_( __FILE__, __LINE__ ); } while ( false )
40+
41+
#endif // GLUTILS_H

src/engine/renderer/InternalImage.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3333
*/
3434
// InternalImage.cpp
3535
#include "tr_local.h"
36+
#include "GLUtils.h"
3637

3738
// Comments may include short quotes from other authors.
3839

src/engine/renderer/TextureManager.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3434
// TextureManager.cpp
3535

3636
#include "tr_local.h"
37+
#include "GLUtils.h"
3738

3839
Texture::Texture() {
3940
}

src/engine/renderer/VBO.h

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
===========================================================================
3+
Copyright (C) 1999-2005 Id Software, Inc.
4+
Copyright (C) 2006-2011 Robert Beckebans <[email protected]>
5+
6+
This file is part of Daemon source code.
7+
8+
Daemon source code is free software; you can redistribute it
9+
and/or modify it under the terms of the GNU General Public License as
10+
published by the Free Software Foundation; either version 2 of the License,
11+
or (at your option) any later version.
12+
13+
Daemon source code is distributed in the hope that it will be
14+
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
GNU General Public License for more details.
17+
18+
You should have received a copy of the GNU General Public License
19+
along with Daemon source code; if not, write to the Free Software
20+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21+
===========================================================================
22+
*/
23+
// VBO.h
24+
25+
#ifndef VBO_H
26+
#define VBO_H
27+
28+
#include "common/Common.h"
29+
#include "GL/glew.h"
30+
31+
#include "VertexSpecification.h"
32+
#include "tr_types.h"
33+
34+
struct VBO_t
35+
{
36+
char name[96]; // only for debugging with /listVBOs
37+
38+
uint32_t vertexesVBO;
39+
40+
uint32_t vertexesSize; // total amount of memory data allocated for this vbo
41+
42+
uint32_t vertexesNum;
43+
uint32_t framesNum; // number of frames for vertex animation
44+
45+
std::array<vboAttributeLayout_t, ATTR_INDEX_MAX> attribs; // info for buffer manipulation
46+
47+
vboLayout_t layout;
48+
uint32_t attribBits; // Which attributes it has. Mostly for detecting errors
49+
GLenum usage;
50+
};
51+
52+
struct IBO_t
53+
{
54+
char name[96]; // only for debugging with /listVBOs
55+
56+
uint32_t indexesVBO;
57+
uint32_t indexesSize; // amount of memory data allocated for all triangles in bytes
58+
uint32_t indexesNum;
59+
};
60+
61+
void R_CopyVertexAttribute( const vboAttributeLayout_t& attrib, const vertexAttributeSpec_t& spec,
62+
uint32_t count, byte* interleavedData );
63+
64+
VBO_t* R_CreateStaticVBO(
65+
Str::StringRef name, const vertexAttributeSpec_t* attrBegin, const vertexAttributeSpec_t* attrEnd,
66+
uint32_t numVerts, uint32_t numFrames = 0 );
67+
68+
IBO_t* R_CreateStaticIBO( const char* name, glIndex_t* indexes, int numIndexes );
69+
IBO_t* R_CreateStaticIBO2( const char* name, int numTriangles, glIndex_t* indexes );
70+
71+
void R_BindVBO( VBO_t* vbo );
72+
void R_BindNullVBO();
73+
74+
void R_BindIBO( IBO_t* ibo );
75+
void R_BindNullIBO();
76+
77+
void R_InitVBOs();
78+
void R_ShutdownVBOs();
79+
80+
#endif // GLMEMORY_H
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/*
2+
===========================================================================
3+
Copyright (C) 1999-2005 Id Software, Inc.
4+
Copyright (C) 2006-2011 Robert Beckebans <[email protected]>
5+
6+
This file is part of Daemon source code.
7+
8+
Daemon source code is free software; you can redistribute it
9+
and/or modify it under the terms of the GNU General Public License as
10+
published by the Free Software Foundation; either version 2 of the License,
11+
or (at your option) any later version.
12+
13+
Daemon source code is distributed in the hope that it will be
14+
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
GNU General Public License for more details.
17+
18+
You should have received a copy of the GNU General Public License
19+
along with Daemon source code; if not, write to the Free Software
20+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21+
===========================================================================
22+
*/
23+
// VertexSpecification.h
24+
25+
#ifndef VERTEX_SPECIFICATION_H
26+
#define VERTEX_SPECIFICATION_H
27+
28+
#include "common/Common.h"
29+
#include "GL/glew.h"
30+
31+
enum
32+
{
33+
ATTR_INDEX_POSITION = 0,
34+
ATTR_INDEX_TEXCOORD, // TODO split into 2-element texcoords and 4-element tex + lm coords
35+
ATTR_INDEX_QTANGENT,
36+
ATTR_INDEX_COLOR,
37+
38+
// GPU vertex skinning
39+
ATTR_INDEX_BONE_FACTORS,
40+
41+
// GPU vertex animations
42+
ATTR_INDEX_POSITION2,
43+
ATTR_INDEX_QTANGENT2,
44+
ATTR_INDEX_MAX
45+
};
46+
47+
// must match order of ATTR_INDEX enums
48+
static const char* const attributeNames[] =
49+
{
50+
"attr_Position",
51+
"attr_TexCoord0",
52+
"attr_QTangent",
53+
"attr_Color",
54+
"attr_BoneFactors",
55+
"attr_Position2",
56+
"attr_QTangent2"
57+
};
58+
59+
enum
60+
{
61+
ATTR_POSITION = BIT( ATTR_INDEX_POSITION ),
62+
ATTR_TEXCOORD = BIT( ATTR_INDEX_TEXCOORD ),
63+
ATTR_QTANGENT = BIT( ATTR_INDEX_QTANGENT ),
64+
ATTR_COLOR = BIT( ATTR_INDEX_COLOR ),
65+
66+
ATTR_BONE_FACTORS = BIT( ATTR_INDEX_BONE_FACTORS ),
67+
68+
// for .md3 interpolation
69+
ATTR_POSITION2 = BIT( ATTR_INDEX_POSITION2 ),
70+
ATTR_QTANGENT2 = BIT( ATTR_INDEX_QTANGENT2 ),
71+
72+
ATTR_INTERP_BITS = ATTR_POSITION2 | ATTR_QTANGENT2,
73+
};
74+
75+
struct vboAttributeLayout_t
76+
{
77+
GLint numComponents; // how many components in a single attribute for a single vertex
78+
GLenum componentType; // the input type for a single component
79+
GLboolean normalize; // convert signed integers to the floating point range [-1, 1], and unsigned integers to the range [0, 1]
80+
GLsizei stride;
81+
GLsizei ofs;
82+
GLsizei frameOffset; // for vertex animation, real offset computed as ofs + frame * frameOffset
83+
};
84+
85+
enum class vboLayout_t
86+
{
87+
VBO_LAYOUT_CUSTOM,
88+
VBO_LAYOUT_STATIC,
89+
};
90+
91+
enum
92+
{
93+
ATTR_OPTION_NORMALIZE = BIT( 0 ),
94+
ATTR_OPTION_HAS_FRAMES = BIT( 1 ),
95+
};
96+
97+
struct vertexAttributeSpec_t
98+
{
99+
int attrIndex;
100+
GLenum componentInputType;
101+
GLenum componentStorageType;
102+
const void* begin;
103+
uint32_t numComponents;
104+
uint32_t stride;
105+
int attrOptions;
106+
};
107+
108+
uint32_t R_ComponentSize( GLenum type );
109+
110+
#endif // VERTEX_SPECIFICATION_H

src/engine/renderer/gl_shader.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2525

2626
#include "tr_local.h"
2727
#include "BufferBind.h"
28+
#include "GLUtils.h"
2829
#include <stdexcept>
2930

3031
#define USE_UNIFORM_FIREWALL 1

src/engine/renderer/tr_cmds.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2222
*/
2323
// tr_cmds.c
2424
#include "tr_local.h"
25+
#include "GLUtils.h"
2526

2627
volatile bool renderThreadActive;
2728

src/engine/renderer/tr_fbo.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2222
*/
2323
// tr_fbo.c
2424
#include "tr_local.h"
25+
#include "GLUtils.h"
2526

2627
/*
2728
=============

0 commit comments

Comments
 (0)