Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change most of the remaining renderer cvars to new-style #1530

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
d923881
Allocate material memory for stages rather than surfaces
VReaperV Aug 22, 2024
8fa176b
Change u_TextureMatrix to mat3x2
VReaperV Dec 25, 2024
c7cfecb
Fix material system dynamic stages
VReaperV Dec 25, 2024
7a4d524
Use UBOs for texData when possible
VReaperV Dec 25, 2024
d3a123f
Comment out some unused args
VReaperV Dec 25, 2024
c6cecec
Fix stage variants upload
VReaperV Dec 26, 2024
21c0079
Fix drawSurf-specific data with material system
VReaperV Jan 2, 2025
5367952
Some material system cleanup
VReaperV Jan 2, 2025
d29feae
Use a UBO for materials instead of an SSBO
VReaperV Jan 2, 2025
ab23a85
Fix material system texture matrices
VReaperV Jan 2, 2025
f42e0b4
Fix dynamic lights with material system
VReaperV Jan 11, 2025
b1d7d2e
Remove a sneaky static
VReaperV Jan 23, 2025
01d1ee4
Fix lightMapData naming
VReaperV Jan 27, 2025
65e465b
Use default constructors/destructors for TextureData
VReaperV Jan 27, 2025
a941aa7
Send stage variant data through `UpdateSurfaceData*`
VReaperV Jan 27, 2025
efe9430
Change ShaderStageVariant to an enum
VReaperV Jan 27, 2025
aea7820
Fix glsl_restart with material system
VReaperV Jan 17, 2025
5edf14d
Clean-up GLBuffer interface, use DSA
VReaperV Jan 12, 2025
2a2eac6
Add GLBuffer::BufferData, minor clean-up
VReaperV Jan 17, 2025
c319055
NUKE unused GLIndirectBuffer
VReaperV Jan 17, 2025
f5ffb7f
Clean-up material system buffer bindings
VReaperV Jan 17, 2025
0741011
Fix r_forceAmbient comparison
VReaperV Jan 21, 2025
53f5c73
Use colorModulateColorGen instead of disabling vertex color
VReaperV Jan 22, 2025
0c0823a
Implement geometry cache
VReaperV Jan 20, 2025
dcf9aa1
Change GL context cvars to new-style
VReaperV Jan 27, 2025
5b50829
Change most renderer cvars to new-style
VReaperV Jan 27, 2025
1cf13ad
NUKE unused r_noLightVisCull
VReaperV Jan 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ set(RENDERERLIST
${ENGINE_DIR}/renderer/tr_fbo.cpp
${ENGINE_DIR}/renderer/tr_flares.cpp
${ENGINE_DIR}/renderer/tr_font.cpp
${ENGINE_DIR}/renderer/GeometryCache.cpp
${ENGINE_DIR}/renderer/GeometryCache.h
${ENGINE_DIR}/renderer/InternalImage.cpp
${ENGINE_DIR}/renderer/InternalImage.h
${ENGINE_DIR}/renderer/Material.cpp
Expand Down
100 changes: 100 additions & 0 deletions src/engine/renderer/GeometryCache.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
===========================================================================

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 );

uint32_t* VBOVerts = VBO.MapBufferRange( mapVerticesNumber * 8 );
memset( VBOVerts, 0, mapVerticesNumber * 8 * sizeof( uint32_t ) );
for ( const vertexAttributeSpec_t* spec = attrBegin; spec < attrEnd; spec++ ) {
vboAttributeLayout_t& attr = VAO.attrs[spec->attrIndex];

CopyVertexAttribute( attr, *spec, mapVerticesNumber, ( byte* ) VBOVerts );
}
VBO.UnmapBuffer();

uint32_t* VBOIndices = IBO.MapBufferRange( mapIndicesNumber );
memcpy( VBOIndices, indices, mapIndicesNumber * sizeof( uint32_t ) );
IBO.UnmapBuffer();

glBindVertexArray( backEnd.currentVAO );
}
70 changes: 70 additions & 0 deletions src/engine/renderer/GeometryCache.h
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
14 changes: 7 additions & 7 deletions src/engine/renderer/InternalImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,16 +139,16 @@ int R_GetImageCustomScalingStep( const image_t *image, const imageParams_t &imag
return scalingStep;
}

int materialMinDimension = r_ignoreMaterialMinDimension->integer ? 0 : imageParams.minDimension;
int materialMaxDimension = r_ignoreMaterialMaxDimension->integer ? 0 : imageParams.maxDimension;
int materialMinDimension = r_ignoreMaterialMinDimension.Get() ? 0 : imageParams.minDimension;
int materialMaxDimension = r_ignoreMaterialMaxDimension.Get() ? 0 : imageParams.maxDimension;

int minDimension;

if ( materialMinDimension <= 0 )
{
minDimension = 1;
}
else if ( r_replaceMaterialMinDimensionIfPresentWithMaxDimension->integer )
else if ( r_replaceMaterialMinDimensionIfPresentWithMaxDimension.Get() )
{
minDimension = materialMaxDimension > 0 ? materialMaxDimension : std::numeric_limits<int>::max();
}
Expand All @@ -159,16 +159,16 @@ int R_GetImageCustomScalingStep( const image_t *image, const imageParams_t &imag

int maxDimension = materialMaxDimension > 0 ? materialMaxDimension : std::numeric_limits<int>::max();

if ( r_imageMaxDimension->integer > 0 )
if ( r_imageMaxDimension.Get() > 0 )
{
maxDimension = std::min( maxDimension, r_imageMaxDimension->integer );
maxDimension = std::min( maxDimension, r_imageMaxDimension.Get() );
}

// 1st priority: scaledDimension >= minDimension
// 2nd priority: scaledDimension <= maxDimension
// 3rd priority: scalingStep >= r_picMip->integer
// 3rd priority: scalingStep >= r_picMip.Get()
// 4th priority: scalingStep as low as possible
while ( scaledDimension > maxDimension || scalingStep < r_picMip->integer )
while ( scaledDimension > maxDimension || scalingStep < r_picMip.Get() )
{
scaledDimension >>= 1;

Expand Down
Loading