Skip to content

Commit 1bb5e9e

Browse files
illwieckzslipher
andcommitted
screenSpace: make it work when GL_EXT_gpu_shader4 is missing
Sadly I do not have the artistic talent to render a new coordinate system for the ASCII art square so I had to delete it :-( --slipher Co-Authored-By: slipher <[email protected]>
1 parent 9a48f79 commit 1bb5e9e

File tree

3 files changed

+39
-22
lines changed

3 files changed

+39
-22
lines changed

src/engine/renderer/glsl_source/screenSpace_vp.glsl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,16 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3434

3535
/* screenSpace_vp.glsl */
3636

37+
#if defined(HAVE_EXT_gpu_shader4)
3738
const vec2 vertices[3] = vec2[3] ( vec2( -1.0f, -1.0f ), vec2( 3.0f, -1.0f ), vec2( -1.0f, 3.0f ) );
3839

3940
void main() {
4041
gl_Position = vec4( vertices[gl_VertexID], 0.0f, 1.0f );
4142
}
43+
#else
44+
IN vec3 attr_Position;
45+
46+
void main() {
47+
gl_Position = vec4( attr_Position, 1.0f );
48+
}
49+
#endif

src/engine/renderer/tr_surface.cpp

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -531,13 +531,21 @@ void Tess_AddCubeWithNormals( const vec3_t position, const vec3_t minSize, const
531531
void Tess_InstantScreenSpaceQuad() {
532532
GLIMP_LOGCOMMENT( "--- Tess_InstantScreenSpaceQuad ---" );
533533

534-
tr.skipVBO = true;
535-
536-
Tess_Begin( Tess_StageIteratorDummy, nullptr, true, -1, 0 );
537-
rb_surfaceTable[Util::ordinal( *( tr.genericTriangle->surface ) )]( tr.genericTriangle->surface );
538-
Tess_DrawElements();
539-
540-
tr.skipVBO = false;
534+
if ( glConfig2.gpuShader4Available )
535+
{
536+
tr.skipVBO = true;
537+
Tess_Begin( Tess_StageIteratorDummy, nullptr, true, -1, 0 );
538+
rb_surfaceTable[Util::ordinal( *( tr.genericTriangle->surface ) )]( tr.genericTriangle->surface );
539+
Tess_DrawElements();
540+
tr.skipVBO = false;
541+
}
542+
else
543+
{
544+
Tess_Begin( Tess_StageIteratorDummy, nullptr, true, -1, 0 );
545+
rb_surfaceTable[Util::ordinal( *( tr.genericQuad->surface ) )]( tr.genericQuad->surface );
546+
GL_VertexAttribsState( ATTR_POSITION );
547+
Tess_DrawElements();
548+
}
541549

542550
GL_CheckErrors();
543551

@@ -550,12 +558,15 @@ void Tess_InstantQuad( u_ModelViewProjectionMatrix &shader, const float x, const
550558

551559
Tess_Begin( Tess_StageIteratorDummy, nullptr, true, -1, 0 );
552560

561+
/* We don't use x, y, width, height directly to make it compatible
562+
with R_InitGenericVBOs() in tr_vbo.cpp.
563+
See: https://github.com/DaemonEngine/Daemon/pull/1739 */
553564
matrix_t modelViewMatrix;
554565
MatrixCopy( matrixIdentity, modelViewMatrix );
555-
modelViewMatrix[12] = x;
556-
modelViewMatrix[13] = y;
557-
modelViewMatrix[0] = width;
558-
modelViewMatrix[5] = height;
566+
modelViewMatrix[12] = 0.5f * width + x;
567+
modelViewMatrix[13] = 0.5f * height + y;
568+
modelViewMatrix[0] = 0.5f * width;
569+
modelViewMatrix[5] = 0.5f * height;
559570
GL_LoadModelViewMatrix( modelViewMatrix );
560571
shader.SetUniform_ModelViewProjectionMatrix(
561572
glState.modelViewProjectionMatrix[ glState.stackIndex ] );

src/engine/renderer/tr_vbo.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -556,24 +556,22 @@ void R_BindNullIBO()
556556
}
557557

558558
static void R_InitGenericVBOs() {
559+
/* Those values are chosen to specify a full-screen rectangle for
560+
screen-space shaders without a projection matrix. The values here
561+
don't influence the triangle but this is a fallback for when the
562+
gl_VertexID-based triangle can't be used (when GL_EXT_gpu_shader4
563+
is missing).
564+
See: https://github.com/DaemonEngine/Daemon/pull/1739 */
559565
// Min and max coordinates of the quad
560-
static const vec3_t min = { 0.0f, 0.0f, 0.0f };
566+
static const vec3_t min = { -1.0f, -1.0f, 0.0f };
561567
static const vec3_t max = { 1.0f, 1.0f, 0.0f };
562568
{
563569
/*
564570
Quad is a static mesh with 4 vertices and 2 triangles
565571
566-
z
567-
^
568-
| 1------2
569-
| y | |
570-
| / | |
571-
| / | |
572-
|/ 0------3
573-
0---------->x
574572
Verts:
575-
0: 0.0 0.0 0.0
576-
1: 0.0 1.0 0.0
573+
0: -1.0 0.0 0.0
574+
1: -1.0 1.0 0.0
577575
2: 1.0 1.0 0.0
578576
3: 1.0 0.0 0.0
579577
Surfs:

0 commit comments

Comments
 (0)