gl4: remove GLES usage
This commit is contained in:
parent
fc543be4f5
commit
45413644bf
|
@ -35,11 +35,7 @@
|
||||||
#define DG_DYNARR_IMPLEMENTATION
|
#define DG_DYNARR_IMPLEMENTATION
|
||||||
#include "../files/DG_dynarr.h"
|
#include "../files/DG_dynarr.h"
|
||||||
|
|
||||||
#ifdef YQ2_GL3_GLES3
|
#define REF_VERSION "Yamagi Quake II OpenGL4 Refresher"
|
||||||
#define REF_VERSION "Yamagi Quake II OpenGL ES3 Refresher"
|
|
||||||
#else
|
|
||||||
#define REF_VERSION "Yamagi Quake II OpenGL4 Refresher"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
refimport_t ri;
|
refimport_t ri;
|
||||||
|
|
||||||
|
@ -1006,15 +1002,7 @@ GL4_DrawParticles(void)
|
||||||
glDepthMask(GL_FALSE);
|
glDepthMask(GL_FALSE);
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
|
|
||||||
#ifdef YQ2_GL3_GLES
|
|
||||||
// the RPi4 GLES3 implementation doesn't draw particles if culling is
|
|
||||||
// enabled (at least with GL_FRONT which seems to be default in q2?)
|
|
||||||
glDisable(GL_CULL_FACE);
|
|
||||||
#else
|
|
||||||
// GLES doesn't have this, maybe it's always enabled? (https://gamedev.stackexchange.com/a/15528 says it works)
|
|
||||||
// luckily we don't use glPointSize() but set gl_PointSize in shader anyway
|
|
||||||
glEnable(GL_PROGRAM_POINT_SIZE);
|
glEnable(GL_PROGRAM_POINT_SIZE);
|
||||||
#endif
|
|
||||||
|
|
||||||
GL4_UseProgram(gl4state.siParticle.shaderProgram);
|
GL4_UseProgram(gl4state.siParticle.shaderProgram);
|
||||||
|
|
||||||
|
@ -1041,12 +1029,8 @@ GL4_DrawParticles(void)
|
||||||
|
|
||||||
glDisable(GL_BLEND);
|
glDisable(GL_BLEND);
|
||||||
glDepthMask(GL_TRUE);
|
glDepthMask(GL_TRUE);
|
||||||
#ifdef YQ2_GL3_GLES
|
|
||||||
if(r_cull->value != 0.0f)
|
|
||||||
glEnable(GL_CULL_FACE);
|
|
||||||
#else
|
|
||||||
glDisable(GL_PROGRAM_POINT_SIZE);
|
glDisable(GL_PROGRAM_POINT_SIZE);
|
||||||
#endif
|
|
||||||
|
|
||||||
YQ2_VLAFREE(buf);
|
YQ2_VLAFREE(buf);
|
||||||
}
|
}
|
||||||
|
@ -1880,12 +1864,6 @@ GL4_BeginFrame(float camera_separation)
|
||||||
{
|
{
|
||||||
gl_drawbuffer->modified = false;
|
gl_drawbuffer->modified = false;
|
||||||
|
|
||||||
|
|
||||||
#ifdef YQ2_GL3_GLES
|
|
||||||
// OpenGL ES3 only supports GL_NONE, GL_BACK and GL_COLOR_ATTACHMENT*
|
|
||||||
// so this doesn't make sense here, see https://docs.gl/es3/glDrawBuffers
|
|
||||||
R_Printf(PRINT_ALL, "NOTE: gl_drawbuffer not supported by OpenGL ES!\n");
|
|
||||||
#else // Desktop GL
|
|
||||||
// TODO: stereo stuff
|
// TODO: stereo stuff
|
||||||
//if ((gl4state.camera_separation == 0) || gl4state.stereo_mode != STEREO_MODE_OPENGL)
|
//if ((gl4state.camera_separation == 0) || gl4state.stereo_mode != STEREO_MODE_OPENGL)
|
||||||
{
|
{
|
||||||
|
@ -1896,7 +1874,6 @@ GL4_BeginFrame(float camera_separation)
|
||||||
}
|
}
|
||||||
glDrawBuffer(drawBuffer);
|
glDrawBuffer(drawBuffer);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* texturemode stuff */
|
/* texturemode stuff */
|
||||||
|
|
|
@ -34,22 +34,15 @@ void
|
||||||
GL4_SetDefaultState(void)
|
GL4_SetDefaultState(void)
|
||||||
{
|
{
|
||||||
glClearColor(1, 0, 0.5, 0.5);
|
glClearColor(1, 0, 0.5, 0.5);
|
||||||
#ifndef YQ2_GL3_GLES
|
|
||||||
// in GLES this is only supported with an extension:
|
|
||||||
// https://www.khronos.org/registry/OpenGL/extensions/EXT/EXT_multisample_compatibility.txt
|
|
||||||
// but apparently it's just enabled by default if set in the context?
|
|
||||||
glDisable(GL_MULTISAMPLE);
|
glDisable(GL_MULTISAMPLE);
|
||||||
#endif
|
|
||||||
glCullFace(GL_FRONT);
|
glCullFace(GL_FRONT);
|
||||||
|
|
||||||
glDisable(GL_DEPTH_TEST);
|
glDisable(GL_DEPTH_TEST);
|
||||||
glDisable(GL_CULL_FACE);
|
glDisable(GL_CULL_FACE);
|
||||||
glDisable(GL_BLEND);
|
glDisable(GL_BLEND);
|
||||||
|
|
||||||
#ifndef YQ2_GL3_GLES
|
|
||||||
// in GLES GL_FILL is the only supported mode
|
|
||||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||||
#endif
|
|
||||||
|
|
||||||
// TODO: gl1_texturealphamode?
|
// TODO: gl1_texturealphamode?
|
||||||
GL4_TextureMode(gl_texturemode->string);
|
GL4_TextureMode(gl_texturemode->string);
|
||||||
|
@ -64,13 +57,10 @@ GL4_SetDefaultState(void)
|
||||||
|
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
|
||||||
#ifndef YQ2_GL3_GLES // see above
|
|
||||||
if (gl_msaa_samples->value)
|
if (gl_msaa_samples->value)
|
||||||
{
|
{
|
||||||
glEnable(GL_MULTISAMPLE);
|
glEnable(GL_MULTISAMPLE);
|
||||||
// glHint(GL_MULTISAMPLE_FILTER_HINT_NV, GL_NICEST); TODO what is this for?
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static byte dottexture[8][8] = {
|
static byte dottexture[8][8] = {
|
||||||
|
@ -126,14 +116,7 @@ GL4_ScreenShot(void)
|
||||||
{
|
{
|
||||||
int w=vid.width, h=vid.height;
|
int w=vid.width, h=vid.height;
|
||||||
|
|
||||||
#ifdef YQ2_GL3_GLES
|
|
||||||
// My RPi4's GLES3 doesn't like GL_RGB, so use GL_RGBA with GLES
|
|
||||||
// TODO: we could convert the screenshot to RGB before writing
|
|
||||||
// so the resulting file is smaller
|
|
||||||
static const int comps = 4;
|
|
||||||
#else // Desktop GL
|
|
||||||
static const int comps = 3;
|
static const int comps = 3;
|
||||||
#endif
|
|
||||||
byte *buffer = malloc(w*h*comps);
|
byte *buffer = malloc(w*h*comps);
|
||||||
|
|
||||||
if (!buffer)
|
if (!buffer)
|
||||||
|
|
|
@ -57,12 +57,7 @@ DebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei le
|
||||||
|
|
||||||
switch (severity)
|
switch (severity)
|
||||||
{
|
{
|
||||||
#ifdef YQ2_GL3_GLES
|
#define SVRCASE(X, STR) case GL_DEBUG_SEVERITY_ ## X ## _ARB : severityStr = STR; break;
|
||||||
#define SVRCASE(X, STR) case GL_DEBUG_SEVERITY_ ## X ## _KHR : severityStr = STR; break;
|
|
||||||
#else // Desktop GL
|
|
||||||
#define SVRCASE(X, STR) case GL_DEBUG_SEVERITY_ ## X ## _ARB : severityStr = STR; break;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
case QGL_DEBUG_SEVERITY_NOTIFICATION: return;
|
case QGL_DEBUG_SEVERITY_NOTIFICATION: return;
|
||||||
SVRCASE(HIGH, "Severity: High")
|
SVRCASE(HIGH, "Severity: High")
|
||||||
SVRCASE(MEDIUM, "Severity: Medium")
|
SVRCASE(MEDIUM, "Severity: Medium")
|
||||||
|
@ -72,11 +67,7 @@ DebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei le
|
||||||
|
|
||||||
switch (source)
|
switch (source)
|
||||||
{
|
{
|
||||||
#ifdef YQ2_GL3_GLES
|
#define SRCCASE(X) case GL_DEBUG_SOURCE_ ## X ## _ARB: sourceStr = "Source: " #X; break;
|
||||||
#define SRCCASE(X) case GL_DEBUG_SOURCE_ ## X ## _KHR: sourceStr = "Source: " #X; break;
|
|
||||||
#else
|
|
||||||
#define SRCCASE(X) case GL_DEBUG_SOURCE_ ## X ## _ARB: sourceStr = "Source: " #X; break;
|
|
||||||
#endif
|
|
||||||
SRCCASE(API);
|
SRCCASE(API);
|
||||||
SRCCASE(WINDOW_SYSTEM);
|
SRCCASE(WINDOW_SYSTEM);
|
||||||
SRCCASE(SHADER_COMPILER);
|
SRCCASE(SHADER_COMPILER);
|
||||||
|
@ -88,11 +79,7 @@ DebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei le
|
||||||
|
|
||||||
switch(type)
|
switch(type)
|
||||||
{
|
{
|
||||||
#ifdef YQ2_GL3_GLES
|
#define TYPECASE(X) case GL_DEBUG_TYPE_ ## X ## _ARB: typeStr = "Type: " #X; break;
|
||||||
#define TYPECASE(X) case GL_DEBUG_TYPE_ ## X ## _KHR: typeStr = "Type: " #X; break;
|
|
||||||
#else
|
|
||||||
#define TYPECASE(X) case GL_DEBUG_TYPE_ ## X ## _ARB: typeStr = "Type: " #X; break;
|
|
||||||
#endif
|
|
||||||
TYPECASE(ERROR);
|
TYPECASE(ERROR);
|
||||||
TYPECASE(DEPRECATED_BEHAVIOR);
|
TYPECASE(DEPRECATED_BEHAVIOR);
|
||||||
TYPECASE(UNDEFINED_BEHAVIOR);
|
TYPECASE(UNDEFINED_BEHAVIOR);
|
||||||
|
@ -228,22 +215,14 @@ int GL4_PrepareForWindow(void)
|
||||||
gl4config.stencil = false;
|
gl4config.stencil = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef YQ2_GL3_GLES3
|
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
|
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
|
|
||||||
#else // Desktop GL
|
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4);
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4);
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 6);
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 6);
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
|
||||||
#endif
|
|
||||||
|
|
||||||
// Set GL context flags.
|
// Set GL context flags.
|
||||||
int contextFlags = 0;
|
int contextFlags = 0;
|
||||||
|
|
||||||
#ifndef YQ2_GL3_GLES // Desktop GL (at least RPi4 doesn't like this for GLES3)
|
|
||||||
contextFlags |= SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG;
|
contextFlags |= SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG;
|
||||||
#endif
|
|
||||||
|
|
||||||
if (gl4_debugcontext && gl4_debugcontext->value)
|
if (gl4_debugcontext && gl4_debugcontext->value)
|
||||||
{
|
{
|
||||||
|
@ -344,21 +323,13 @@ int GL4_InitContext(void* win)
|
||||||
GL4_SetVsync();
|
GL4_SetVsync();
|
||||||
|
|
||||||
// Load GL pointrs through GLAD and check context.
|
// Load GL pointrs through GLAD and check context.
|
||||||
#ifdef YQ2_GL3_GLES
|
|
||||||
if( !gladLoadGLES2Loader(SDL_GL_GetProcAddress))
|
|
||||||
#else // Desktop GL
|
|
||||||
if( !gladLoadGLLoader(SDL_GL_GetProcAddress))
|
if( !gladLoadGLLoader(SDL_GL_GetProcAddress))
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
R_Printf(PRINT_ALL, "GL4_InitContext(): ERROR: loading OpenGL function pointers failed!\n");
|
R_Printf(PRINT_ALL, "GL4_InitContext(): ERROR: loading OpenGL function pointers failed!\n");
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#ifdef YQ2_GL3_GLES3
|
|
||||||
else if (GLVersion.major < 3)
|
|
||||||
#else // Desktop GL
|
|
||||||
else if (GLVersion.major < 4 || (GLVersion.major == 4 && GLVersion.minor < 6))
|
else if (GLVersion.major < 4 || (GLVersion.major == 4 && GLVersion.minor < 6))
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
R_Printf(PRINT_ALL, "GL4_InitContext(): ERROR: glad only got GL version %d.%d!\n", GLVersion.major, GLVersion.minor);
|
R_Printf(PRINT_ALL, "GL4_InitContext(): ERROR: glad only got GL version %d.%d!\n", GLVersion.major, GLVersion.minor);
|
||||||
|
|
||||||
|
@ -369,11 +340,7 @@ int GL4_InitContext(void* win)
|
||||||
R_Printf(PRINT_ALL, "Successfully loaded OpenGL function pointers using glad, got version %d.%d!\n", GLVersion.major, GLVersion.minor);
|
R_Printf(PRINT_ALL, "Successfully loaded OpenGL function pointers using glad, got version %d.%d!\n", GLVersion.major, GLVersion.minor);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef YQ2_GL3_GLES
|
|
||||||
gl4config.debug_output = GLAD_GL_KHR_debug != 0;
|
|
||||||
#else // Desktop GL
|
|
||||||
gl4config.debug_output = GLAD_GL_ARB_debug_output != 0;
|
gl4config.debug_output = GLAD_GL_ARB_debug_output != 0;
|
||||||
#endif
|
|
||||||
gl4config.anisotropic = GLAD_GL_ARB_texture_filter_anisotropic != 0;
|
gl4config.anisotropic = GLAD_GL_ARB_texture_filter_anisotropic != 0;
|
||||||
|
|
||||||
gl4config.major_version = GLVersion.major;
|
gl4config.major_version = GLVersion.major;
|
||||||
|
@ -382,25 +349,13 @@ int GL4_InitContext(void* win)
|
||||||
// Debug context setup.
|
// Debug context setup.
|
||||||
if (gl4_debugcontext && gl4_debugcontext->value && gl4config.debug_output)
|
if (gl4_debugcontext && gl4_debugcontext->value && gl4config.debug_output)
|
||||||
{
|
{
|
||||||
#ifdef YQ2_GL3_GLES
|
|
||||||
glDebugMessageCallbackKHR(DebugCallback, NULL);
|
|
||||||
|
|
||||||
// Call GL3_DebugCallback() synchronously, i.e. directly when and
|
|
||||||
// where the error happens (so we can get the cause in a backtrace)
|
|
||||||
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_KHR);
|
|
||||||
#else // Desktop GL
|
|
||||||
glDebugMessageCallbackARB(DebugCallback, NULL);
|
glDebugMessageCallbackARB(DebugCallback, NULL);
|
||||||
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB);
|
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Window title - set here so we can display renderer name in it.
|
// Window title - set here so we can display renderer name in it.
|
||||||
char title[40] = {0};
|
char title[40] = {0};
|
||||||
#ifdef YQ2_GL3_GLES3
|
|
||||||
snprintf(title, sizeof(title), "Yamagi Quake II %s - OpenGL ES 3.0", YQ2VERSION);
|
|
||||||
#else
|
|
||||||
snprintf(title, sizeof(title), "Yamagi Quake II %s - OpenGL 4.6", YQ2VERSION);
|
snprintf(title, sizeof(title), "Yamagi Quake II %s - OpenGL 4.6", YQ2VERSION);
|
||||||
#endif
|
|
||||||
SDL_SetWindowTitle(window, title);
|
SDL_SetWindowTitle(window, title);
|
||||||
|
|
||||||
#if SDL_VERSION_ATLEAST(2, 26, 0)
|
#if SDL_VERSION_ATLEAST(2, 26, 0)
|
||||||
|
|
|
@ -36,11 +36,7 @@ CompileShader(GLenum shaderType, const char* shaderSrc, const char* shaderSrc2)
|
||||||
{
|
{
|
||||||
GLuint shader = glCreateShader(shaderType);
|
GLuint shader = glCreateShader(shaderType);
|
||||||
|
|
||||||
#ifdef YQ2_GL3_GLES3
|
|
||||||
const char* version = "#version 300 es\nprecision mediump float;\n";
|
|
||||||
#else // Desktop GL
|
|
||||||
const char* version = "#version 460\n";
|
const char* version = "#version 460\n";
|
||||||
#endif
|
|
||||||
const char* sources[3] = { version, shaderSrc, shaderSrc2 };
|
const char* sources[3] = { version, shaderSrc, shaderSrc2 };
|
||||||
int numSources = shaderSrc2 != NULL ? 3 : 2;
|
int numSources = shaderSrc2 != NULL ? 3 : 2;
|
||||||
|
|
||||||
|
|
|
@ -34,23 +34,13 @@
|
||||||
// using system headers for their parsers/indexers but glad for real build
|
// using system headers for their parsers/indexers but glad for real build
|
||||||
// (in glad glFoo is just a #define to glad_glFoo or sth, which screws up autocompletion)
|
// (in glad glFoo is just a #define to glad_glFoo or sth, which screws up autocompletion)
|
||||||
// (you may have to configure your IDE to #define IN_IDE_PARSER, but not for building!)
|
// (you may have to configure your IDE to #define IN_IDE_PARSER, but not for building!)
|
||||||
#ifdef YQ2_GL3_GLES3
|
|
||||||
#include <GLES3/gl32.h>
|
|
||||||
#else // desktop GL4
|
|
||||||
#define GL_GLEXT_PROTOTYPES 1
|
#define GL_GLEXT_PROTOTYPES 1
|
||||||
#include <GL/gl.h>
|
#include <GL/gl.h>
|
||||||
#include <GL/glext.h>
|
#include <GL/glext.h>
|
||||||
#endif
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#ifdef YQ2_GL3_GLES3
|
#include "../glad/include/glad/glad.h"
|
||||||
#include "../glad-gles3/include/glad/glad.h"
|
|
||||||
// yes, this is a bit hacky, but it works :-P
|
|
||||||
#define glDepthRange glDepthRangef
|
|
||||||
#else // desktop GL4
|
|
||||||
#include "../glad/include/glad/glad.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue