Skip to content

Commit

Permalink
Merge pull request #6 from SomaZ/MBII-rend2
Browse files Browse the repository at this point in the history
Latest rend2
  • Loading branch information
MaceMadunusus authored Jun 12, 2024
2 parents 281cf31 + 285e42e commit ed18cde
Show file tree
Hide file tree
Showing 16 changed files with 166 additions and 112 deletions.
36 changes: 22 additions & 14 deletions codemp/rd-rend2/tr_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1672,18 +1672,18 @@ static void R_InitBackEndFrameData()
GLuint timerQueries[MAX_GPU_TIMERS*MAX_FRAMES];
qglGenQueries(MAX_GPU_TIMERS*MAX_FRAMES, timerQueries);

GLuint ubos[MAX_FRAMES * MAX_SCENCES];
qglGenBuffers(MAX_FRAMES * MAX_SCENCES, ubos);
GLuint ubos[MAX_FRAMES * MAX_SCENES];
qglGenBuffers(MAX_FRAMES * MAX_SCENES, ubos);

for ( int i = 0; i < MAX_FRAMES; i++ )
{
gpuFrame_t *frame = backEndData->frames + i;
const GLbitfield mapBits = GL_MAP_WRITE_BIT | GL_MAP_COHERENT_BIT | GL_MAP_PERSISTENT_BIT;

for (byte j = 0; j < MAX_SCENCES; j++)
for (byte j = 0; j < MAX_SCENES; j++)
{
size_t BUFFER_SIZE = j == 0 ? FRAME_UNIFORM_BUFFER_SIZE : FRAME_SCENE_UNIFORM_BUFFER_SIZE;
frame->ubo[j] = ubos[i * MAX_SCENCES + j];
frame->ubo[j] = ubos[i * MAX_SCENES + j];
frame->uboWriteOffset[j] = 0;
frame->uboSize[j] = BUFFER_SIZE;
qglBindBuffer(GL_UNIFORM_BUFFER, frame->ubo[j]);
Expand Down Expand Up @@ -1889,7 +1889,7 @@ static void R_ShutdownBackEndFrameData()
frame->sync = NULL;
}

qglDeleteBuffers(MAX_SCENCES, frame->ubo);
qglDeleteBuffers(MAX_SCENES, frame->ubo);

if ( glRefConfig.immutableBuffers )
{
Expand All @@ -1907,6 +1907,7 @@ static void R_ShutdownBackEndFrameData()
}
}

static bool r_inited = false;
/*
===============
R_Init
Expand All @@ -1915,7 +1916,10 @@ R_Init
void R_Init( void ) {
byte *ptr;
int i;


if (r_inited)
return;

ri.Printf( PRINT_ALL, "----- R_Init -----\n" );

// clear all our internal state
Expand Down Expand Up @@ -2028,6 +2032,7 @@ void R_Init( void ) {

// print info
GfxInfo_f();
r_inited = true;
ri.Printf( PRINT_ALL, "----- finished R_Init -----\n" );
}

Expand All @@ -2053,21 +2058,23 @@ void RE_Shutdown( qboolean destroyWindow, qboolean restarting ) {
R_ShutdownWeatherSystem();

R_ShutdownFonts();
if ( tr.registered ) {

if (r_inited)
{
R_ShutDownQueries();
FBO_Shutdown();
R_DeleteTextures();
R_DestroyGPUBuffers();
GLSL_ShutdownGPUShaders();
}

if ( destroyWindow && restarting )
{
ri.Z_Free((void *)glConfig.extensions_string);
ri.Z_Free((void *)glConfigExt.originalExtensionString);
if (destroyWindow && restarting && tr.registered)
{
ri.Z_Free((void *)glConfig.extensions_string);
ri.Z_Free((void *)glConfigExt.originalExtensionString);

qglDeleteVertexArrays(1, &tr.globalVao);
SaveGhoul2InfoArray();
}
qglDeleteVertexArrays(1, &tr.globalVao);
SaveGhoul2InfoArray();
}

// shut down platform specific OpenGL stuff
Expand All @@ -2076,6 +2083,7 @@ void RE_Shutdown( qboolean destroyWindow, qboolean restarting ) {
}

tr.registered = qfalse;
r_inited = false;
backEndData = NULL;
}

Expand Down
9 changes: 3 additions & 6 deletions shared/rd-rend2/glsl/generic.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,8 @@ uniform sampler2D u_DiffuseMap;
uniform int u_AlphaTestType;
#endif
uniform int u_FogIndex;
// x = glow out, y = deluxe, z = screen shadow, w = cube
uniform vec4 u_EnableTextures;

in vec2 var_DiffuseTex;
in vec4 var_Color;
Expand Down Expand Up @@ -581,10 +583,5 @@ void main()
#endif

out_Color = vec4(color.rgb * var_Color.rgb, color.a);

#if defined(USE_GLOW_BUFFER)
out_Glow = out_Color;
#else
out_Glow = vec4(0.0);
#endif
out_Glow = mix(vec4(0.0, 0.0, 0.0, out_Color.a), out_Color, u_EnableTextures.x);
}
11 changes: 2 additions & 9 deletions shared/rd-rend2/glsl/lightall.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -409,10 +409,8 @@ uniform samplerCube u_CubeMap;
uniform sampler2D u_EnvBrdfMap;
#endif

#if defined(USE_NORMALMAP) || defined(USE_DELUXEMAP) || defined(USE_SPECULARMAP) || defined(USE_CUBEMAP)
// y = deluxe, w = cube
// x = glow out, y = deluxe, z = screen shadow, w = cube
uniform vec4 u_EnableTextures;
#endif

uniform vec4 u_NormalScale;
uniform vec4 u_SpecularScale;
Expand Down Expand Up @@ -1177,10 +1175,5 @@ void main()
#endif

out_Color.a = diffuse.a;

#if defined(USE_GLOW_BUFFER)
out_Glow = out_Color;
#else
out_Glow = vec4(0.0, 0.0, 0.0, out_Color.a);
#endif
out_Glow = mix(vec4(0.0, 0.0, 0.0, out_Color.a), out_Color, u_EnableTextures.x);
}
6 changes: 3 additions & 3 deletions shared/rd-rend2/glsl/surface_sprites.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ uniform int u_FogIndex;
uniform vec4 u_FogColorMask;
#endif

#if defined(ALPHA_TEST)
#if defined(USE_ALPHA_TEST)
uniform int u_AlphaTestType;
#endif

Expand Down Expand Up @@ -223,7 +223,7 @@ float CalcFog(in vec3 viewOrigin, in vec3 position, in Fog fog)

void main()
{
#if defined(ALPHA_TEST)
#if defined(USE_ALPHA_TEST)
float alphaTestValue = 0.5;
if (u_AlphaTestType == ALPHA_TEST_GT0)
{
Expand Down Expand Up @@ -256,7 +256,7 @@ void main()
}
#endif

#if defined(ALPHA_TEST)
#if defined(USE_ALPHA_TEST)
if (u_AlphaTestType == ALPHA_TEST_GT0)
{
if (out_Color.a == 0.0)
Expand Down
12 changes: 10 additions & 2 deletions shared/rd-rend2/tr_bsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3816,7 +3816,8 @@ static int R_CreateSurfaceSpritesVertexData(
const srfVert_t *verts = bspSurf->verts;
const glIndex_t *indexes = bspSurf->indexes;

vec4_t color = { 1.0, 1.0, 1.0, 1.0 };
#if 0
vec4_t color = { 1.0f, 1.0f, 1.0f, 1.0f };
if (stage->rgbGen == CGEN_CONST)
{
color[0] = stage->constantColor[0];
Expand All @@ -3828,6 +3829,13 @@ static int R_CreateSurfaceSpritesVertexData(
stage->rgbGen == CGEN_EXACT_VERTEX ||
stage->rgbGen == CGEN_VERTEX_LIT ||
stage->rgbGen == CGEN_EXACT_VERTEX_LIT);
#else
// Vanilla behaviour is always: color by vertex color of the emitting surface
// even just the blue component used for all three color channels to be exact
// in pseudo code: outVert.rgb = inVert.bbb;
bool vertexLit = true;
vec4_t color = { 1.0f, 1.0f, 1.0f, 1.0f };
#endif

int numSprites = 0;
for ( int i = 0, numIndexes = bspSurf->numIndexes; i < numIndexes; i += 3 )
Expand Down Expand Up @@ -4010,7 +4018,7 @@ static void R_GenerateSurfaceSprites( const world_t *world, int worldIndex )
for (int i = 0; i < tr.numShaders; i++)
{
const shader_t *shader = tr.shaders[i];
if (shader->spriteUbo != -1)
if (shader->spriteUbo != 0)
continue;

numSpriteStages += shader->numSurfaceSpriteStages;
Expand Down
4 changes: 2 additions & 2 deletions shared/rd-rend2/tr_cmds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ void RE_BeginFrame( stereoFrame_t stereoFrame ) {
qglDeleteSync( sync );
thisFrame->sync = NULL;

for (byte i = 0; i < MAX_SCENCES; i++)
for (byte i = 0; i < MAX_SCENES; i++)
{
thisFrame->uboWriteOffset[i] = 0;
}
Expand All @@ -552,7 +552,7 @@ void RE_BeginFrame( stereoFrame_t stereoFrame ) {
R_SaveScreenshot(&thisFrame->screenshotReadback);

// Resets resources
for (byte i = 0; i < MAX_SCENCES; i++)
for (byte i = 0; i < MAX_SCENES; i++)
{
qglBindBuffer(GL_UNIFORM_BUFFER, thisFrame->ubo[i]);
glState.currentGlobalUBO = thisFrame->ubo[i];
Expand Down
40 changes: 21 additions & 19 deletions shared/rd-rend2/tr_glsl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,8 @@ static size_t GLSL_GetShaderHeader(
ALPHA_TEST_GE128,
ALPHA_TEST_GE192));

Q_strcat(dest, size, "#define USE_ALPHA_TEST\n");

Q_strcat(dest, size,
va("#define MAX_G2_BONES %i\n",
MAX_G2_BONES));
Expand Down Expand Up @@ -1470,11 +1472,11 @@ static int GLSL_LoadGPUProgramGeneric(
if (i & GENERICDEF_USE_RGBAGEN)
Q_strcat(extradefines, sizeof(extradefines), "#define USE_RGBAGEN\n");

if (i & GENERICDEF_USE_GLOW_BUFFER)
Q_strcat(extradefines, sizeof(extradefines), "#define USE_GLOW_BUFFER\n");
/*if (i & GENERICDEF_USE_GLOW_BUFFER)
Q_strcat(extradefines, sizeof(extradefines), "#define USE_GLOW_BUFFER\n");*/

if (i & GENERICDEF_USE_ALPHA_TEST)
Q_strcat(extradefines, sizeof(extradefines), "#define USE_ALPHA_TEST\n");
/*if (i & GENERICDEF_USE_ALPHA_TEST)
Q_strcat(extradefines, sizeof(extradefines), "#define USE_ALPHA_TEST\n");*/

if (!GLSL_LoadGPUShader(builder, &tr.genericShader[i], "generic", attribs, NO_XFB_VARS,
extradefines, *programDesc))
Expand Down Expand Up @@ -1536,8 +1538,8 @@ static int GLSL_LoadGPUProgramFogPass(
if (i & FOGDEF_USE_FALLBACK_GLOBAL_FOG)
Q_strcat(extradefines, sizeof(extradefines), "#define USE_FALLBACK_GLOBAL_FOG\n");

if (i & FOGDEF_USE_ALPHA_TEST)
Q_strcat(extradefines, sizeof(extradefines), "#define USE_ALPHA_TEST\n");
/*if (i & FOGDEF_USE_ALPHA_TEST)
Q_strcat(extradefines, sizeof(extradefines), "#define USE_ALPHA_TEST\n");*/

if (!GLSL_LoadGPUShader(builder, &tr.fogShader[i], "fogpass", attribs, NO_XFB_VARS,
extradefines, *programDesc))
Expand All @@ -1548,7 +1550,7 @@ static int GLSL_LoadGPUProgramFogPass(
GLSL_InitUniforms(&tr.fogShader[i]);

qglUseProgram(tr.fogShader[i].program);
if (i & FOGDEF_USE_ALPHA_TEST)
//if (i & FOGDEF_USE_ALPHA_TEST)
GLSL_SetUniformInt(&tr.fogShader[i], UNIFORM_DIFFUSEMAP, 0);
qglUseProgram(0);

Expand Down Expand Up @@ -1599,8 +1601,8 @@ static int GLSL_LoadGPUProgramRefraction(
if (i & REFRACTIONDEF_USE_RGBAGEN)
Q_strcat(extradefines, sizeof(extradefines), "#define USE_RGBAGEN\n");

if (i & REFRACTIONDEF_USE_ALPHA_TEST)
Q_strcat(extradefines, sizeof(extradefines), "#define USE_ALPHA_TEST\n");
/*if (i & REFRACTIONDEF_USE_ALPHA_TEST)
Q_strcat(extradefines, sizeof(extradefines), "#define USE_ALPHA_TEST\n");*/

if (i & REFRACTIONDEF_USE_SRGB_TRANSFORM)
Q_strcat(extradefines, sizeof(extradefines), "#define USE_LINEAR_LIGHT\n");
Expand Down Expand Up @@ -1765,11 +1767,11 @@ static int GLSL_LoadGPUProgramLightAll(
attribs |= ATTR_BONE_INDEXES | ATTR_BONE_WEIGHTS;
}

if (i & LIGHTDEF_USE_ALPHA_TEST)
Q_strcat(extradefines, sizeof(extradefines), "#define USE_ALPHA_TEST\n");
/*if (i & LIGHTDEF_USE_ALPHA_TEST)
Q_strcat(extradefines, sizeof(extradefines), "#define USE_ALPHA_TEST\n");*/

if (i & LIGHTDEF_USE_GLOW_BUFFER)
Q_strcat(extradefines, sizeof(extradefines), "#define USE_GLOW_BUFFER\n");
/*if (i & LIGHTDEF_USE_GLOW_BUFFER)
Q_strcat(extradefines, sizeof(extradefines), "#define USE_GLOW_BUFFER\n");*/

if (!GLSL_LoadGPUShader(builder, &tr.lightallShader[i], "lightall", attribs, NO_XFB_VARS,
extradefines, *programDesc))
Expand Down Expand Up @@ -2234,9 +2236,9 @@ static int GLSL_LoadGPUProgramSurfaceSprites(
Q_strcat(extradefines, sizeof(extradefines),
"#define USE_FOG\n");

if ( i & SSDEF_ALPHA_TEST )
/*if ( i & SSDEF_ALPHA_TEST )
Q_strcat(extradefines, sizeof(extradefines),
"#define ALPHA_TEST\n");
"#define USE_ALPHA_TEST\n");*/

if (i & SSDEF_ADDITIVE)
Q_strcat(extradefines, sizeof(extradefines),
Expand Down Expand Up @@ -2580,8 +2582,8 @@ shaderProgram_t *GLSL_GetGenericShaderProgram(int stage)
shaderStage_t *pStage = tess.xstages[stage];
int shaderAttribs = 0;

if ( pStage->alphaTestType != ALPHA_TEST_NONE )
shaderAttribs |= GENERICDEF_USE_ALPHA_TEST;
/*if ( pStage->alphaTestType != ALPHA_TEST_NONE )
shaderAttribs |= GENERICDEF_USE_ALPHA_TEST;*/

if (backEnd.currentEntity->e.renderfx & (RF_DISINTEGRATE1 | RF_DISINTEGRATE2))
shaderAttribs |= GENERICDEF_USE_RGBAGEN;
Expand Down Expand Up @@ -2638,10 +2640,10 @@ shaderProgram_t *GLSL_GetGenericShaderProgram(int stage)
shaderAttribs |= GENERICDEF_USE_TCGEN_AND_TCMOD;
}

if (pStage->glow)
/*if (pStage->glow)
{
shaderAttribs |= GENERICDEF_USE_GLOW_BUFFER;
}
}*/

return &tr.genericShader[shaderAttribs];
}
5 changes: 4 additions & 1 deletion shared/rd-rend2/tr_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2834,7 +2834,10 @@ image_t *R_BuildSDRSpecGlossImage(shaderStage_t *stage, const char *specImageNam
}
ri.Hunk_FreeTempMemory(specPic);

return R_CreateImage(sdrName, sdrSpecPic, specWidth, specHeight, IMGTYPE_COLORALPHA, flags & ~IMGFLAG_SRGB, 0);
image_t *outImage = R_CreateImage(sdrName, sdrSpecPic, specWidth, specHeight, IMGTYPE_COLORALPHA, flags & ~IMGFLAG_SRGB, 0);
Hunk_FreeTempMemory(sdrSpecPic);

return outImage;
}

static void R_CreateNormalMap ( const char *name, byte *pic, int width, int height, int flags )
Expand Down
Loading

0 comments on commit ed18cde

Please sign in to comment.