Skip to content

Commit 3ef8cd9

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 366c736 commit 3ef8cd9

File tree

3 files changed

+36
-22
lines changed

3 files changed

+36
-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+
/* These values make possible to use either the legacy quad rendering
562+
or the triangle one when the related GLSL code is supported.
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: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -554,24 +554,19 @@ void R_BindNullIBO()
554554
}
555555

556556
static void R_InitGenericVBOs() {
557+
/* These values make possible to use either the legacy quad rendering
558+
or the triangle one when the related GLSL code is supported.
559+
See: https://github.com/DaemonEngine/Daemon/pull/1739 */
557560
// Min and max coordinates of the quad
558-
static const vec3_t min = { 0.0f, 0.0f, 0.0f };
561+
static const vec3_t min = { -1.0f, -1.0f, 0.0f };
559562
static const vec3_t max = { 1.0f, 1.0f, 0.0f };
560563
{
561564
/*
562565
Quad is a static mesh with 4 vertices and 2 triangles
563566
564-
z
565-
^
566-
| 1------2
567-
| y | |
568-
| / | |
569-
| / | |
570-
|/ 0------3
571-
0---------->x
572567
Verts:
573-
0: 0.0 0.0 0.0
574-
1: 0.0 1.0 0.0
568+
0: -1.0 0.0 0.0
569+
1: -1.0 1.0 0.0
575570
2: 1.0 1.0 0.0
576571
3: 1.0 0.0 0.0
577572
Surfs:

0 commit comments

Comments
 (0)