Skip to content

Commit

Permalink
GLES2: Fixes for mirror and portal issues
Browse files Browse the repository at this point in the history
  • Loading branch information
pbdot committed Dec 3, 2023
1 parent 752bd4e commit 79ec81e
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 6 deletions.
4 changes: 2 additions & 2 deletions libraries/gl4es/include/GL/gl.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
#ifndef __gl_h_
#define __gl_h_

// edge: Adding _WIN32 here for static library
#if defined(__EMSCRIPTEN__) || defined(__APPLE__) || defined(_WIN32)
// edge: Adding _WIN32 and EDGE_GL_ES2
#if defined(__EMSCRIPTEN__) || defined(__APPLE__) || defined(_WIN32) || defined(EDGE_GL_ES2)
#define USE_MGL_NAMESPACE 1
#define GL_GLEXT_PROTOTYPES 1
#define MANGLE(x) gl4es_gl##x
Expand Down
3 changes: 3 additions & 0 deletions libraries/gl4es/include/gl4esinit.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
extern "C" {
#endif

// EDGE-Classic for working around any issue needing to flush the GL4ES render list
void gl4es_flush();

// set driver GetProcAddress implementation. required for hardext detection with NOEGL or when loader is disabled
void set_getprocaddress(void *(APIENTRY_GL4ES *new_proc_address)(const char *));
// reguired with NOEGL
Expand Down
16 changes: 12 additions & 4 deletions libraries/gl4es/src/gl/planes.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,23 @@
#include "matrix.h"
#include "matvec.h"

static GLfloat planebuffer[6][4];

void APIENTRY_GL4ES gl4es_glClipPlanef(GLenum plane, const GLfloat *equation)
{
/*
When glClipPlane is called,
equation is transformed by the inverse of the modelview matrix and stored in the resulting eye coordinates.
Subsequent changes to the modelview matrix have no effect on the stored plane-equation components.
If the dot product of the eye coordinates of a vertex with the stored plane equation components is positive or zero,
When glClipPlane is called,
equation is transformed by the inverse of the modelview matrix and stored in the resulting eye coordinates.
Subsequent changes to the modelview matrix have no effect on the stored plane-equation components.
If the dot product of the eye coordinates of a vertex with the stored plane equation components is positive or zero,
the vertex is in with respect to that clipping plane. Otherwise, it is out.
*/

// EDGE-CLASSIC: fix bad memory access, though this isn't perfect as could potentionally be overwritten, so if clip plane issues need to check here
int planeidx = plane - GL_CLIP_PLANE0;
memcpy(planebuffer[planeidx], equation, sizeof(GLfloat) * 4);
equation = planebuffer[planeidx];

PUSH_IF_COMPILING(glClipPlanef); //TODO: fix that, equation is an array and should be copied before beeing put in the stack
if((plane<GL_CLIP_PLANE0) || (plane>=GL_CLIP_PLANE0+hardext.maxplanes)) {
errorShim(GL_INVALID_ENUM);
Expand Down
21 changes: 21 additions & 0 deletions source_files/edge/r_render.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2061,6 +2061,11 @@ static void RGL_WalkMirror(drawsub_c *dsub, seg_t *seg, angle_t left, angle_t ri

dsub->mirrors.push_back(mir);

#if defined(EDGE_GL_ES2)
// GL4ES mirror fix for renderlist
gl4es_flush();
#endif

// push mirror (translation matrix)
MIR_Push(mir);

Expand All @@ -2085,6 +2090,12 @@ static void RGL_WalkMirror(drawsub_c *dsub, seg_t *seg, angle_t left, angle_t ri

// pop mirror
MIR_Pop();

#if defined(EDGE_GL_ES2)
// GL4ES mirror fix for renderlist
gl4es_flush();
#endif

}

//
Expand Down Expand Up @@ -3005,6 +3016,11 @@ static void RGL_DrawMirror(drawmirror_c *mir)

RGL_FinishUnits();

#if defined(EDGE_GL_ES2)
// GL4ES mirror fix for renderlist
gl4es_flush();
#endif

MIR_Push(mir);
{
RGL_DrawSubList(mir->drawsubs, true);
Expand All @@ -3016,6 +3032,11 @@ static void RGL_DrawMirror(drawmirror_c *mir)
else
DrawMirrorPolygon(mir);

#if defined(EDGE_GL_ES2)
// GL4ES mirror fix for renderlist
gl4es_flush();
#endif

solid_mode = true;
RGL_StartUnits(solid_mode);
}
Expand Down
5 changes: 5 additions & 0 deletions source_files/edge/r_sky.cc
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,11 @@ void RGL_FinishSky(void)
if (!r_dumbsky.d)
glDepthFunc(GL_GREATER);

#if defined(EDGE_GL_ES2)
// On ES2 the clip planes seem to maybe be inverting z values, this fixes that
glDepthFunc(GL_ALWAYS);
#endif

if (custom_sky_box)
RGL_DrawSkyBox();
else
Expand Down

0 comments on commit 79ec81e

Please sign in to comment.