Skip to content

Commit

Permalink
Vertex buffers object handling
Browse files Browse the repository at this point in the history
  • Loading branch information
atupone committed Jul 18, 2024
1 parent 25c8309 commit 3b6d698
Show file tree
Hide file tree
Showing 26 changed files with 1,673 additions and 310 deletions.
8 changes: 8 additions & 0 deletions MSVC/build/ogl.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,10 @@
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|x64'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|x64'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<ClCompile Include="..\..\src\ogl\Vertex_Chunk.cxx" />
<ClCompile Include="..\..\src\ogl\VBO_Element.cxx" />
<ClCompile Include="..\..\src\ogl\VBO_Handler.cxx" />
<ClCompile Include="..\..\src\ogl\VBO_Vertex.cxx" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\include\bzfgl.h" />
Expand All @@ -288,6 +292,10 @@
<ClInclude Include="..\..\include\OpenGLTexture.h" />
<ClInclude Include="..\..\include\OpenGLUtils.h" />
<ClInclude Include="..\..\include\RenderNode.h" />
<ClInclude Include="..\..\include\Vertex_Chunk.h" />
<ClInclude Include="..\..\src\ogl\VBO_Element.h" />
<ClInclude Include="..\..\src\ogl\VBO_Handler.h" />
<ClInclude Include="..\..\src\ogl\VBO_Vertex.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
Expand Down
24 changes: 24 additions & 0 deletions MSVC/build/ogl.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@
<ClCompile Include="..\..\src\ogl\OpenGLFramebuffer.cxx">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src\ogl\Vertex_Chunk.cxx">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src\ogl\VBO_Element.cxx">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src\ogl\VBO_Handler.cxx">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src\ogl\VBO_Vertex.cxx">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\include\RenderNode.h">
Expand Down Expand Up @@ -57,6 +69,18 @@
<ClInclude Include="..\..\include\OpenGLFramebuffer.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\include\Vertex_Chunk.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ogl\VBO_Element.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ogl\VBO_Handler.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ogl\VBO_Vertex.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Filter Include="Header Files">
Expand Down
57 changes: 57 additions & 0 deletions include/Element_Chunk.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/* bzflag
* Copyright (c) 2019-2019 Tim Riker
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the license found in the file
* named COPYING that should have accompanied this file.
*
* THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/

#pragma once

// 1st
#include "common.h"

// system interface headers
#include <glm/fwd.hpp>
#include <vector>

// Common headers
#include "bzfgl.h"

// forward declaration
class VBO_Element;

class Element_Chunk
{
public:
Element_Chunk();
Element_Chunk(unsigned int size);
~Element_Chunk();

Element_Chunk(Element_Chunk&& other);
Element_Chunk& operator=(Element_Chunk&& data);

// These are for the case the caller provides a pointer to the first element
void elementData(const GLuint elements[], int size = -1);

void glDrawElements(GLenum mode, unsigned int size, unsigned int offset);

private:
static VBO_Element *vbo;
static unsigned int refer;

int index;
unsigned int indexSize;
};

// Local Variables: ***
// mode: C++ ***
// tab-width: 4 ***
// c-basic-offset: 4 ***
// indent-tabs-mode: nil ***
// End: ***
// ex: shiftwidth=4 tabstop=4
2 changes: 2 additions & 0 deletions include/FlagSceneNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@ class FlagSceneNode : public SceneNode
FlagRenderNode(const FlagSceneNode*);
~FlagRenderNode();
void render() override;
void renderShadow() override;
const glm::vec3 &getPosition() const override;
private:
void render(bool shadow);
const FlagSceneNode* sceneNode;
int waveReference;
};
Expand Down
2 changes: 2 additions & 0 deletions include/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ noinst_HEADERS = \
EighthDPyrSceneNode.h \
EighthDimSceneNode.h \
EighthDimShellNode.h \
Element_Chunk.h \
EmptySceneNodeGenerator.h \
ErrorHandler.h \
Extents.h \
Expand Down Expand Up @@ -122,6 +123,7 @@ noinst_HEADERS = \
TextureMatrix.h \
TimeKeeper.h \
TriWallSceneNode.h \
Vertex_Chunk.h \
ViewFrustum.h \
VotingBooth.h \
WallObstacle.h \
Expand Down
5 changes: 5 additions & 0 deletions include/MeshDrawInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class MeshDrawInfo
const glm::vec3 *getVertices() const;
const glm::vec3 *getNormals() const;
const glm::vec2 *getTexcoords() const;
int getCornerCount() const;

int getRadarCount() const;
const DrawLod* getRadarLods() const;
Expand Down Expand Up @@ -216,6 +217,10 @@ inline const glm::vec2 *MeshDrawInfo::getTexcoords() const
{
return texcoords;
}
inline int MeshDrawInfo::getCornerCount() const
{
return cornerCount;
}
inline int MeshDrawInfo::getRadarCount() const
{
return radarCount;
Expand Down
11 changes: 6 additions & 5 deletions include/MeshDrawMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@
// common interface headers
#include "bzfgl.h"
#include "MeshDrawInfo.h"
#include "Vertex_Chunk.h"
#include "Element_Chunk.h"

class MeshDrawMgr
{
public:
MeshDrawMgr(const MeshDrawInfo* drawInfo);
~MeshDrawMgr();
~MeshDrawMgr() = default;

void executeSet(int lod, int set, bool useNormals, bool useTexcoords);
void executeSetGeometry(int lod, int set);
Expand All @@ -35,14 +37,13 @@ class MeshDrawMgr
void rawExecuteCommands(int lod, int set);

void makeLists();
void freeLists();
static void initContext(void* data);
static void freeContext(void* data);

private:
const MeshDrawInfo* drawInfo;

using LodList = std::vector<int>;
Vertex_Chunk vboVertexChunk;

using LodList = std::vector<Element_Chunk>;
std::vector<LodList> lodLists;
};

Expand Down
12 changes: 3 additions & 9 deletions include/MeshFragSceneNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

// Global headers
#include "BzMaterial.h"
#include "Vertex_Chunk.h"

//
// NOTES:
Expand Down Expand Up @@ -68,19 +69,12 @@ class MeshFragSceneNode : public WallSceneNode
const glm::vec3 &getPosition() const override;

private:
void drawV() const; // draw with just vertices
void drawVT() const; // draw with texcoords
void drawVN() const; // draw with normals
void drawVTN() const; // draw with texcoords and normals
void drawVTN(); // draw with texcoords and normals

void initDisplayList();
void freeDisplayList();
static void initContext(void *data);
static void freeContext(void *data);

private:
int style;
GLuint list;
Vertex_Chunk vboChunk;
MeshFragSceneNode &sceneNode;
};

Expand Down
108 changes: 108 additions & 0 deletions include/Vertex_Chunk.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/* bzflag
* Copyright (c) 2019-2019 Tim Riker
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the license found in the file
* named COPYING that should have accompanied this file.
*
* THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/

#pragma once

// 1st
#include "common.h"

// system interface headers
#include <glm/fwd.hpp>
#include <vector>

// Common headers
#include "bzfgl.h"

// forward declaration
class VBO_Vertex;

class Vertex_Chunk
{
public:
enum Component {V=0, VC, VN, VT, VTN, VTC, VTNC, VLast};

Vertex_Chunk();
Vertex_Chunk(Component comp, unsigned int size);
~Vertex_Chunk();

Vertex_Chunk(Vertex_Chunk&& other);
Vertex_Chunk& operator=(Vertex_Chunk&& data);

// This method bind all the buffers, to be ready for drawing
void enableArrays();
// This method will select which buffer should be enabled
// Vertex is always enabled
void enableArrays(bool texture, bool normal, bool color);
// This method will enable the vertex buffer only (used for shadows
void enableVertexOnly();

// These write the GL buffers from an std::vector
void vertexData(const std::vector<glm::vec3> vertices);
void textureData(const std::vector<glm::vec2> textures);
void normalData(const std::vector<glm::vec3> normals);
void colorData(const std::vector<glm::vec4> colors);

// These are for the case the caller provides a bidimensional array
void vertexData(const GLfloat vertices[][3]);
void textureData(const GLfloat textures[][2]);
void normalData(const GLfloat normals[][3]);
void colorData(const GLfloat colors[][4]);

// These are for the case the caller provides a bidimensional array
void vertexData(const GLfloat vertices[][3], unsigned int size);
void textureData(const GLfloat textures[][2], unsigned int size);
void normalData(const GLfloat normals[][3], unsigned int size);
void colorData(const GLfloat colors[][4], unsigned int size);

// These are for the case the caller provides a pointer to the first element
void vertexData(const GLfloat *vertices, int size = -1);
void textureData(const GLfloat *textures, int size = -1);
void normalData(const GLfloat *normals, int size = -1);
void colorData(const GLfloat *colors, int size = -1);

// These are for the case the caller provides an array of glm::vec* elements
void vertexData(const glm::vec3 vertices[]);
void textureData(const glm::vec2 textures[]);
void normalData(const glm::vec3 normals[]);
void colorData(const glm::vec4 colors[]);

// These are for the case the caller provides an array of glm::vec* elements
void vertexData(const glm::vec3 vertices[], int size);
void textureData(const glm::vec2 textures[], int size);
void normalData(const glm::vec3 normals[], int size);
void colorData(const glm::vec4 colors[], int size);

void glDrawArrays(GLenum mode);
void glDrawArrays(GLenum mode, unsigned int size, unsigned int offset = 0);

void draw(GLenum mode);
void draw(GLenum mode, bool onlyVertex);
void draw(GLenum mode, bool onlyVertex, int size);

unsigned int getIndex() const;
private:
static VBO_Vertex *vbo[VLast];
static unsigned int refer[VLast];

VBO_Vertex *myVBO;
int index;
unsigned int indexSize;
Component myComp;
};

// Local Variables: ***
// mode: C++ ***
// tab-width: 4 ***
// c-basic-offset: 4 ***
// indent-tabs-mode: nil ***
// End: ***
// ex: shiftwidth=4 tabstop=4
8 changes: 0 additions & 8 deletions src/bzflag/BackgroundRenderer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1125,10 +1125,6 @@ void BackgroundRenderer::drawGroundShadows(
// disable color updates
SceneNode::setColorOverride(true);

// disable the unused arrays
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);

if (BZDBCache::stencilShadows)
{
OpenGLGState::resetState();
Expand Down Expand Up @@ -1173,10 +1169,6 @@ void BackgroundRenderer::drawGroundShadows(

OpenGLGState::resetState();

// re-enable the arrays
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);

glPopMatrix();
}

Expand Down
8 changes: 0 additions & 8 deletions src/bzflag/RadarRenderer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -901,10 +901,6 @@ void RadarRenderer::renderBoxPyrMeshFast(float _range)
OpenGLGState gs = gb.getState();
gs.setState();

// disable the unused arrays
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);

// now that the texture is bound, setup the clamp mode
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);

Expand Down Expand Up @@ -939,10 +935,6 @@ void RadarRenderer::renderBoxPyrMeshFast(float _range)

OpenGLGState::resetState();

// re-enable the arrays
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);

// do this after the GState setting
if (smooth)
{
Expand Down
2 changes: 0 additions & 2 deletions src/bzflag/defaultBZDB.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,6 @@ DefaultDBItem defaultDBItems[] =
// hidden graphics rendering params
{ "useDrawInfo", "1", true, StateDatabase::ReadWrite, NULL },
{ "f2bsort", "1", true, StateDatabase::ReadWrite, NULL },
{ "meshLists", "1", true, StateDatabase::ReadWrite, NULL },
{ "flagLists", "0", true, StateDatabase::ReadWrite, NULL },
{ "lightLists", "0", true, StateDatabase::ReadWrite, NULL },
{ "noMeshClusters", "0", true, StateDatabase::ReadWrite, NULL },

Expand Down
Loading

0 comments on commit 3b6d698

Please sign in to comment.