-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The geometry cache represents 3 buffers: a VBO, IBO, and inputVBO. These buffers will replace the old separate input VBOs and IBOs when enabled. This allows binding only a VAO before rendering, rather than setting up vertex pointers with the correct offset and formats every time. Additionally, it means that there's no need to switch between different VBOs/IBOs. The `inputVBO` is currently unused, but it will be needed to make models work with the geometry cache (model animations and world transform will be processed in a compute shader). Currently this is only used by the material system, but it should be possible to make the core renderer use it as well.
- Loading branch information
Showing
13 changed files
with
305 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/* | ||
=========================================================================== | ||
Daemon BSD Source Code | ||
Copyright (c) 2025 Daemon Developers | ||
All rights reserved. | ||
This file is part of the Daemon BSD Source Code (Daemon Source Code). | ||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
* Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above copyright | ||
notice, this list of conditions and the following disclaimer in the | ||
documentation and/or other materials provided with the distribution. | ||
* Neither the name of the Daemon developers nor the | ||
names of its contributors may be used to endorse or promote products | ||
derived from this software without specific prior written permission. | ||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL DAEMON DEVELOPERS BE LIABLE FOR ANY | ||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
=========================================================================== | ||
*/ | ||
// GeometryCache.cpp | ||
|
||
#include "GeometryCache.h" | ||
|
||
#include "tr_local.h" | ||
|
||
GeometryCache geometryCache; | ||
|
||
void GeometryCache::Bind() { | ||
VAO.Bind(); | ||
} | ||
|
||
void GeometryCache::InitGLBuffers() { | ||
inputVBO.GenBuffer(); | ||
VBO.GenBuffer(); | ||
IBO.GenBuffer(); | ||
|
||
VAO.GenVAO(); | ||
} | ||
|
||
void GeometryCache::FreeGLBuffers() { | ||
inputVBO.DelBuffer(); | ||
VBO.DelBuffer(); | ||
IBO.DelBuffer(); | ||
|
||
VAO.DelVAO(); | ||
} | ||
|
||
void GeometryCache::Free() { | ||
} | ||
|
||
void GeometryCache::AllocBuffers() { | ||
VBO.BufferData( mapVerticesNumber * 8, nullptr, GL_STATIC_DRAW ); | ||
|
||
IBO.BufferData( mapIndicesNumber, nullptr, GL_STATIC_DRAW ); | ||
} | ||
|
||
void GeometryCache::AddMapGeometry( const uint32_t verticesNumber, const uint32_t indicesNumber, | ||
const vertexAttributeSpec_t* attrBegin, const vertexAttributeSpec_t* attrEnd, | ||
const glIndex_t* indices ) { | ||
mapVerticesNumber = verticesNumber; | ||
mapIndicesNumber = indicesNumber; | ||
|
||
VAO.Bind(); | ||
|
||
AllocBuffers(); | ||
|
||
VAO.SetAttrs( attrBegin, attrEnd ); | ||
|
||
VAO.SetVertexBuffer( VBO, 0 ); | ||
VAO.SetIndexBuffer( IBO ); | ||
|
||
VBO.BufferStorage( mapVerticesNumber * 8, 1, nullptr ); | ||
VBO.MapAll(); | ||
uint32_t* VBOVerts = VBO.GetData(); | ||
for ( const vertexAttributeSpec_t* spec = attrBegin; spec < attrEnd; spec++ ) { | ||
vboAttributeLayout_t& attr = VAO.attrs[spec->attrIndex]; | ||
|
||
CopyVertexAttribute( attr, *spec, mapVerticesNumber, ( byte* ) VBOVerts ); | ||
} | ||
VBO.UnmapBuffer(); | ||
|
||
IBO.BufferStorage( mapIndicesNumber, 1, nullptr ); | ||
IBO.MapAll(); | ||
uint32_t* IBOIndices = IBO.GetData(); | ||
memcpy( IBOIndices, indices, mapIndicesNumber * sizeof( uint32_t ) ); | ||
IBO.UnmapBuffer(); | ||
|
||
glBindVertexArray( backEnd.currentVAO ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
=========================================================================== | ||
Daemon BSD Source Code | ||
Copyright (c) 2025 Daemon Developers | ||
All rights reserved. | ||
This file is part of the Daemon BSD Source Code (Daemon Source Code). | ||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
* Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above copyright | ||
notice, this list of conditions and the following disclaimer in the | ||
documentation and/or other materials provided with the distribution. | ||
* Neither the name of the Daemon developers nor the | ||
names of its contributors may be used to endorse or promote products | ||
derived from this software without specific prior written permission. | ||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL DAEMON DEVELOPERS BE LIABLE FOR ANY | ||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
=========================================================================== | ||
*/ | ||
// GeometryCache.h | ||
|
||
#ifndef GEOMETRY_CACHE_H | ||
#define GEOMETRY_CACHE_H | ||
|
||
#include "gl_shader.h" | ||
#include "Material.h" | ||
|
||
class GeometryCache { | ||
public: | ||
void Bind(); | ||
|
||
void InitGLBuffers(); | ||
void FreeGLBuffers(); | ||
|
||
void Free(); | ||
|
||
void AllocBuffers(); | ||
void AddMapGeometry( const uint32_t verticesNumber, const uint32_t indicesNumber, | ||
const vertexAttributeSpec_t* attrBegin, | ||
const vertexAttributeSpec_t* attrEnd, | ||
const glIndex_t* indices ); | ||
|
||
private: | ||
uint32_t mapVerticesNumber; | ||
uint32_t mapIndicesNumber; | ||
|
||
GLVAO VAO = GLVAO( 0 ); | ||
|
||
GLBuffer inputVBO = GLBuffer( "geometryCacheInputVBO", Util::ordinal( BufferBind::GEOMETRY_CACHE_INPUT_VBO ), GL_MAP_WRITE_BIT, GL_MAP_INVALIDATE_RANGE_BIT ); | ||
GLBuffer VBO = GLBuffer( "geometryCacheVBO", Util::ordinal( BufferBind::GEOMETRY_CACHE_VBO ), GL_MAP_WRITE_BIT, GL_MAP_FLUSH_EXPLICIT_BIT ); | ||
GLBuffer IBO = GLBuffer( "geometryCacheIBO", Util::ordinal( BufferBind::UNUSED ), GL_MAP_WRITE_BIT, GL_MAP_INVALIDATE_RANGE_BIT ); | ||
}; | ||
|
||
extern GeometryCache geometryCache; | ||
|
||
#endif // GEOMETRY_CACHE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.