Skip to content

Commit

Permalink
GL3: Square particles with cvar gl3_particle_square
Browse files Browse the repository at this point in the history
if that cvar is set to 1, particles aren't rendered as nice circles, but
as squares, like in the software renderer or in Quake1.

Also documented it in cvarlist.md and fixed some typos there
  • Loading branch information
DanielGibson committed Jun 20, 2017
1 parent 837f017 commit 23ea2ea
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 9 deletions.
8 changes: 8 additions & 0 deletions src/client/refresh/gl3/gl3_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ cvar_t *gl_drawbuffer;
cvar_t *gl_clear;
cvar_t *gl3_particle_size;
cvar_t *gl3_particle_fade_factor;
cvar_t *gl3_particle_square;

cvar_t *gl_lefthand;
cvar_t *gl_farsee;
Expand Down Expand Up @@ -208,6 +209,7 @@ GL3_Register(void)
gl_customheight = ri.Cvar_Get("gl_customheight", "768", CVAR_ARCHIVE);
gl3_particle_size = ri.Cvar_Get("gl3_particle_size", "40", CVAR_ARCHIVE);
gl3_particle_fade_factor = ri.Cvar_Get("gl3_particle_fade_factor", "1.2", CVAR_ARCHIVE);
gl3_particle_square = ri.Cvar_Get("gl3_particle_square", "0", CVAR_ARCHIVE);

gl_norefresh = ri.Cvar_Get("gl_norefresh", "0", 0);
gl_drawentities = ri.Cvar_Get("gl_drawentities", "1", 0);
Expand Down Expand Up @@ -1655,6 +1657,12 @@ GL3_BeginFrame(float camera_separation)
GL3_UpdateUBO3D();
}

if(gl3_particle_square->modified)
{
gl3_particle_square->modified = false;
GL3_RecreateShaders();
}


/* go into 2D mode */

Expand Down
46 changes: 41 additions & 5 deletions src/client/refresh/gl3/gl3_shaders.c
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,18 @@ static const char* fragmentSrcParticles = MULTILINE_STRING(
}
);

static const char* fragmentSrcParticlesSquare = MULTILINE_STRING(

// it gets attributes and uniforms from fragmentCommon3D

in vec4 passColor;

void main()
{
outColor = passColor;
}
);


#undef MULTILINE_STRING

Expand Down Expand Up @@ -977,10 +989,8 @@ static void initUBOs(void)
gl3state.currentUBO = gl3state.uniLightsUBO;
}

qboolean GL3_InitShaders(void)
static qboolean createShaders(void)
{
initUBOs();

if(!initShader2D(&gl3state.si2D, vertexSrc2D, fragmentSrc2D))
{
R_Printf(PRINT_ALL, "WARNING: Failed to create shader program for textured 2D rendering!\n");
Expand Down Expand Up @@ -1053,7 +1063,14 @@ qboolean GL3_InitShaders(void)
R_Printf(PRINT_ALL, "WARNING: Failed to create shader program for rendering flat-colored models!\n");
return false;
}
if(!initShader3D(&gl3state.siParticle, vertexSrcParticles, fragmentSrcParticles))

const char* particleFrag = fragmentSrcParticles;
if(gl3_particle_square->value != 0.0f)
{
particleFrag = fragmentSrcParticlesSquare;
}

if(!initShader3D(&gl3state.siParticle, vertexSrcParticles, particleFrag))
{
R_Printf(PRINT_ALL, "WARNING: Failed to create shader program for rendering particles!\n");
return false;
Expand All @@ -1064,21 +1081,40 @@ qboolean GL3_InitShaders(void)
return true;
}

void GL3_ShutdownShaders(void)
qboolean GL3_InitShaders(void)
{
initUBOs();

return createShaders();
}

static void deleteShaders(void)
{
const gl3ShaderInfo_t siZero = {0};
for(gl3ShaderInfo_t* si = &gl3state.si2D; si <= &gl3state.siParticle; ++si)
{
if(si->shaderProgram != 0) glDeleteProgram(si->shaderProgram);
*si = siZero;
}
}

void GL3_ShutdownShaders(void)
{
deleteShaders();

// let's (ab)use the fact that all 4 UBO handles are consecutive fields
// of the gl3state struct
glDeleteBuffers(4, &gl3state.uniCommonUBO);
gl3state.uniCommonUBO = gl3state.uni2DUBO = gl3state.uni3DUBO = gl3state.uniLightsUBO = 0;
}

qboolean GL3_RecreateShaders(void)
{
// delete and recreate the existing shaders (but not the UBOs)
deleteShaders();
return createShaders();
}

static inline void
updateUBO(GLuint ubo, GLsizeiptr size, void* data)
{
Expand Down
2 changes: 2 additions & 0 deletions src/client/refresh/gl3/header/local.h
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@ extern void GL3_ShutdownMeshes(void);

// gl3_shaders.c

extern qboolean GL3_RecreateShaders(void);
extern qboolean GL3_InitShaders(void);
extern void GL3_ShutdownShaders(void);
extern void GL3_UpdateUBOCommon(void);
Expand Down Expand Up @@ -507,6 +508,7 @@ extern cvar_t *gl_anisotropic;
extern cvar_t *gl_lightlevel;
extern cvar_t *gl3_overbrightbits;
extern cvar_t *gl3_particle_fade_factor;
extern cvar_t *gl3_particle_square;

extern cvar_t *gl_modulate;
extern cvar_t *gl_lightmap;
Expand Down
14 changes: 10 additions & 4 deletions stuff/cvarlist.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ General:

* **basedir**: Directory from which the game data is loaded. Can be used
in startup scripts, to test binaries, etc. If not set, the directory
containing the binaries is used.
containing the binaries is used.
To use this cvar, set it at startup, like `./quake2 +set basedir /path/to/quake2`

* **cl_async**: If set to `1` (the default) the client is asynchronous.
The client framerate is fixed, the renderer framerate is variable.
Expand Down Expand Up @@ -76,7 +77,7 @@ Graphics (all renderers):
with an aspect ratio of 4:3, regardless what the actual windows size
or resolution is.

* **cl_gun**: Decides weather the gun is drawn. If set to `0` the gun
* **cl_gun**: Decides whether the gun is drawn. If set to `0` the gun
is omitted. If set to `1` the gun is only drawn if the FOV is equal
or smaller than 90. This was the default with Vanilla Quake II. If set
to `2` the gun is drawn regardless of the FOV. This is the default
Expand Down Expand Up @@ -126,8 +127,8 @@ Graphics (all renderers):

* **gl_msaa_samples**: Full scene anti aliasing samples. The number of
samples depends on the GPU driver, most drivers support at least
`2`, `4` and `8` samples. If an invalid value is set the value is
reverted the highest number of samples supported. Especially on OpenGL
`2`, `4` and `8` samples. If an invalid value is set, the value is
reverted to the highest number of samples supported. Especially on OpenGL
3.2 anti aliasing is expensive and can lead to a huge performance hit,
so try setting it to a lower value if your framerate is too low.

Expand Down Expand Up @@ -192,3 +193,8 @@ Graphics (GL3 only):
* **gl3_particle_fade_factor**: "softness" of particles: higher values
look less soft. Defaults to `1.2`.
A value of `10` looks similar to the GL1 particles.

* **gl3_particle_square**: If set to `1`, particles are rendered as squares,
like in the old software renderer or Quake1. Default is `0`.


0 comments on commit 23ea2ea

Please sign in to comment.