Skip to content

Commit 1227a0e

Browse files
committed
Vertex buffers object handling
1 parent a460c80 commit 1227a0e

27 files changed

+1678
-338
lines changed

MSVC/build/ogl.vcxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,10 @@
276276
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|x64'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
277277
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|x64'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
278278
</ClCompile>
279+
<ClCompile Include="..\..\src\ogl\Vertex_Chunk.cxx" />
280+
<ClCompile Include="..\..\src\ogl\VBO_Element.cxx" />
281+
<ClCompile Include="..\..\src\ogl\VBO_Handler.cxx" />
282+
<ClCompile Include="..\..\src\ogl\VBO_Vertex.cxx" />
279283
</ItemGroup>
280284
<ItemGroup>
281285
<ClInclude Include="..\..\include\bzfgl.h" />
@@ -288,6 +292,10 @@
288292
<ClInclude Include="..\..\include\OpenGLTexture.h" />
289293
<ClInclude Include="..\..\include\OpenGLUtils.h" />
290294
<ClInclude Include="..\..\include\RenderNode.h" />
295+
<ClInclude Include="..\..\include\Vertex_Chunk.h" />
296+
<ClInclude Include="..\..\src\ogl\VBO_Element.h" />
297+
<ClInclude Include="..\..\src\ogl\VBO_Handler.h" />
298+
<ClInclude Include="..\..\src\ogl\VBO_Vertex.h" />
291299
</ItemGroup>
292300
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
293301
<ImportGroup Label="ExtensionTargets">

MSVC/build/ogl.vcxproj.filters

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@
2525
<ClCompile Include="..\..\src\ogl\OpenGLFramebuffer.cxx">
2626
<Filter>Source Files</Filter>
2727
</ClCompile>
28+
<ClCompile Include="..\..\src\ogl\Vertex_Chunk.cxx">
29+
<Filter>Source Files</Filter>
30+
</ClCompile>
31+
<ClCompile Include="..\..\src\ogl\VBO_Element.cxx">
32+
<Filter>Source Files</Filter>
33+
</ClCompile>
34+
<ClCompile Include="..\..\src\ogl\VBO_Handler.cxx">
35+
<Filter>Source Files</Filter>
36+
</ClCompile>
37+
<ClCompile Include="..\..\src\ogl\VBO_Vertex.cxx">
38+
<Filter>Source Files</Filter>
39+
</ClCompile>
2840
</ItemGroup>
2941
<ItemGroup>
3042
<ClInclude Include="..\..\include\RenderNode.h">
@@ -57,6 +69,18 @@
5769
<ClInclude Include="..\..\include\OpenGLFramebuffer.h">
5870
<Filter>Header Files</Filter>
5971
</ClInclude>
72+
<ClInclude Include="..\..\include\Vertex_Chunk.h">
73+
<Filter>Header Files</Filter>
74+
</ClInclude>
75+
<ClInclude Include="..\..\src\ogl\VBO_Element.h">
76+
<Filter>Header Files</Filter>
77+
</ClInclude>
78+
<ClInclude Include="..\..\src\ogl\VBO_Handler.h">
79+
<Filter>Header Files</Filter>
80+
</ClInclude>
81+
<ClInclude Include="..\..\src\ogl\VBO_Vertex.h">
82+
<Filter>Header Files</Filter>
83+
</ClInclude>
6084
</ItemGroup>
6185
<ItemGroup>
6286
<Filter Include="Header Files">

include/Element_Chunk.h

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/* bzflag
2+
* Copyright (c) 2019-2019 Tim Riker
3+
*
4+
* This package is free software; you can redistribute it and/or
5+
* modify it under the terms of the license found in the file
6+
* named COPYING that should have accompanied this file.
7+
*
8+
* THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
9+
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
10+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
11+
*/
12+
13+
#pragma once
14+
15+
// 1st
16+
#include "common.h"
17+
18+
// system interface headers
19+
#include <glm/fwd.hpp>
20+
#include <vector>
21+
22+
// Common headers
23+
#include "bzfgl.h"
24+
25+
// forward declaration
26+
class VBO_Element;
27+
28+
class Element_Chunk
29+
{
30+
public:
31+
Element_Chunk();
32+
Element_Chunk(unsigned int size);
33+
~Element_Chunk();
34+
35+
Element_Chunk(Element_Chunk&& other);
36+
Element_Chunk& operator=(Element_Chunk&& data);
37+
38+
// These are for the case the caller provides a pointer to the first element
39+
void elementData(const GLuint elements[], int size = -1);
40+
41+
void glDrawElements(GLenum mode, unsigned int size, unsigned int offset);
42+
43+
private:
44+
static VBO_Element *vbo;
45+
static unsigned int refer;
46+
47+
int index;
48+
unsigned int indexSize;
49+
};
50+
51+
// Local Variables: ***
52+
// mode: C++ ***
53+
// tab-width: 4 ***
54+
// c-basic-offset: 4 ***
55+
// indent-tabs-mode: nil ***
56+
// End: ***
57+
// ex: shiftwidth=4 tabstop=4

include/FlagSceneNode.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,10 @@ class FlagSceneNode : public SceneNode
5555
FlagRenderNode(const FlagSceneNode*);
5656
~FlagRenderNode();
5757
void render() override;
58+
void renderShadow() override;
5859
const glm::vec3 &getPosition() const override;
5960
private:
61+
void render(bool shadow);
6062
const FlagSceneNode* sceneNode;
6163
int waveReference;
6264
};

include/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ noinst_HEADERS = \
4242
EighthDPyrSceneNode.h \
4343
EighthDimSceneNode.h \
4444
EighthDimShellNode.h \
45+
Element_Chunk.h \
4546
EmptySceneNodeGenerator.h \
4647
ErrorHandler.h \
4748
Extents.h \
@@ -123,6 +124,7 @@ noinst_HEADERS = \
123124
TextureMatrix.h \
124125
TimeKeeper.h \
125126
TriWallSceneNode.h \
127+
Vertex_Chunk.h \
126128
ViewFrustum.h \
127129
VotingBooth.h \
128130
WallObstacle.h \

include/MeshDrawInfo.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ class MeshDrawInfo
9090
const glm::vec3 *getVertices() const;
9191
const glm::vec3 *getNormals() const;
9292
const glm::vec2 *getTexcoords() const;
93+
int getCornerCount() const;
9394

9495
int getRadarCount() const;
9596
const DrawLod* getRadarLods() const;
@@ -216,6 +217,10 @@ inline const glm::vec2 *MeshDrawInfo::getTexcoords() const
216217
{
217218
return texcoords;
218219
}
220+
inline int MeshDrawInfo::getCornerCount() const
221+
{
222+
return cornerCount;
223+
}
219224
inline int MeshDrawInfo::getRadarCount() const
220225
{
221226
return radarCount;

include/MeshDrawMgr.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,28 @@
2121
// common interface headers
2222
#include "bzfgl.h"
2323
#include "MeshDrawInfo.h"
24+
#include "Vertex_Chunk.h"
25+
#include "Element_Chunk.h"
2426

2527
class MeshDrawMgr
2628
{
2729
public:
2830
MeshDrawMgr(const MeshDrawInfo* drawInfo);
29-
~MeshDrawMgr();
31+
~MeshDrawMgr() = default;
3032

3133
void executeSet(int lod, int set, bool useNormals, bool useTexcoords);
32-
void executeSetGeometry(int lod, int set);
3334

3435
private:
3536
void rawExecuteCommands(int lod, int set);
3637

3738
void makeLists();
38-
void freeLists();
39-
static void initContext(void* data);
40-
static void freeContext(void* data);
4139

4240
private:
4341
const MeshDrawInfo* drawInfo;
4442

45-
using LodList = std::vector<int>;
43+
Vertex_Chunk vboVertexChunk;
44+
45+
using LodList = std::vector<Element_Chunk>;
4646
std::vector<LodList> lodLists;
4747
};
4848

include/MeshFragSceneNode.h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
// Global headers
2525
#include "BzMaterial.h"
26+
#include "Vertex_Chunk.h"
2627

2728
//
2829
// NOTES:
@@ -68,19 +69,12 @@ class MeshFragSceneNode : public WallSceneNode
6869
const glm::vec3 &getPosition() const override;
6970

7071
private:
71-
void drawV() const; // draw with just vertices
72-
void drawVT() const; // draw with texcoords
73-
void drawVN() const; // draw with normals
74-
void drawVTN() const; // draw with texcoords and normals
72+
void drawVTN(); // draw with texcoords and normals
7573

7674
void initDisplayList();
77-
void freeDisplayList();
78-
static void initContext(void *data);
79-
static void freeContext(void *data);
80-
8175
private:
8276
int style;
83-
GLuint list;
77+
Vertex_Chunk vboChunk;
8478
MeshFragSceneNode &sceneNode;
8579
};
8680

include/Vertex_Chunk.h

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/* bzflag
2+
* Copyright (c) 2019-2019 Tim Riker
3+
*
4+
* This package is free software; you can redistribute it and/or
5+
* modify it under the terms of the license found in the file
6+
* named COPYING that should have accompanied this file.
7+
*
8+
* THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
9+
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
10+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
11+
*/
12+
13+
#pragma once
14+
15+
// 1st
16+
#include "common.h"
17+
18+
// system interface headers
19+
#include <glm/fwd.hpp>
20+
#include <vector>
21+
22+
// Common headers
23+
#include "bzfgl.h"
24+
25+
// forward declaration
26+
class VBO_Vertex;
27+
28+
class Vertex_Chunk
29+
{
30+
public:
31+
enum Component {V=0, VC, VN, VT, VTN, VTC, VTNC, VLast};
32+
33+
Vertex_Chunk();
34+
Vertex_Chunk(Component comp, unsigned int size);
35+
~Vertex_Chunk();
36+
37+
Vertex_Chunk(Vertex_Chunk&& other);
38+
Vertex_Chunk& operator=(Vertex_Chunk&& data);
39+
40+
// This method bind all the buffers, to be ready for drawing
41+
void enableArrays();
42+
// This method will select which buffer should be enabled
43+
// Vertex is always enabled
44+
void enableArrays(bool texture, bool normal, bool color);
45+
// This method will enable the vertex buffer only (used for shadows
46+
void enableVertexOnly();
47+
48+
// These write the GL buffers from an std::vector
49+
void vertexData(const std::vector<glm::vec3> vertices);
50+
void textureData(const std::vector<glm::vec2> textures);
51+
void normalData(const std::vector<glm::vec3> normals);
52+
void colorData(const std::vector<glm::vec4> colors);
53+
54+
// These are for the case the caller provides a bidimensional array
55+
void vertexData(const GLfloat vertices[][3]);
56+
void textureData(const GLfloat textures[][2]);
57+
void normalData(const GLfloat normals[][3]);
58+
void colorData(const GLfloat colors[][4]);
59+
60+
// These are for the case the caller provides a bidimensional array
61+
void vertexData(const GLfloat vertices[][3], unsigned int size);
62+
void textureData(const GLfloat textures[][2], unsigned int size);
63+
void normalData(const GLfloat normals[][3], unsigned int size);
64+
void colorData(const GLfloat colors[][4], unsigned int size);
65+
66+
// These are for the case the caller provides a pointer to the first element
67+
void vertexData(const GLfloat *vertices, int size = -1);
68+
void textureData(const GLfloat *textures, int size = -1);
69+
void normalData(const GLfloat *normals, int size = -1);
70+
void colorData(const GLfloat *colors, int size = -1);
71+
72+
// These are for the case the caller provides an array of glm::vec* elements
73+
void vertexData(const glm::vec3 vertices[]);
74+
void textureData(const glm::vec2 textures[]);
75+
void normalData(const glm::vec3 normals[]);
76+
void colorData(const glm::vec4 colors[]);
77+
78+
// These are for the case the caller provides an array of glm::vec* elements
79+
void vertexData(const glm::vec3 vertices[], int size);
80+
void textureData(const glm::vec2 textures[], int size);
81+
void normalData(const glm::vec3 normals[], int size);
82+
void colorData(const glm::vec4 colors[], int size);
83+
84+
void glDrawArrays(GLenum mode);
85+
void glDrawArrays(GLenum mode, unsigned int size, unsigned int offset = 0);
86+
87+
void draw(GLenum mode);
88+
void draw(GLenum mode, bool onlyVertex);
89+
void draw(GLenum mode, bool onlyVertex, int size);
90+
91+
unsigned int getIndex() const;
92+
private:
93+
static VBO_Vertex *vbo[VLast];
94+
static unsigned int refer[VLast];
95+
96+
VBO_Vertex *myVBO;
97+
int index;
98+
unsigned int indexSize;
99+
Component myComp;
100+
};
101+
102+
// Local Variables: ***
103+
// mode: C++ ***
104+
// tab-width: 4 ***
105+
// c-basic-offset: 4 ***
106+
// indent-tabs-mode: nil ***
107+
// End: ***
108+
// ex: shiftwidth=4 tabstop=4

src/bzflag/BackgroundRenderer.cxx

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,10 +1129,6 @@ void BackgroundRenderer::drawGroundShadows(
11291129
// disable color updates
11301130
SceneNode::setColorOverride(true);
11311131

1132-
// disable the unused arrays
1133-
glDisableClientState(GL_NORMAL_ARRAY);
1134-
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
1135-
11361132
if (BZDBCache::stencilShadows)
11371133
{
11381134
OpenGLGState::resetState();
@@ -1177,10 +1173,6 @@ void BackgroundRenderer::drawGroundShadows(
11771173

11781174
OpenGLGState::resetState();
11791175

1180-
// re-enable the arrays
1181-
glEnableClientState(GL_NORMAL_ARRAY);
1182-
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
1183-
11841176
glPopMatrix();
11851177
}
11861178

0 commit comments

Comments
 (0)