GLES: Add disabled code to run GLES on desktop.

Helps when testing certain extensions, etc.
This commit is contained in:
Unknown W. Brackets 2018-10-28 14:29:44 -07:00
parent e301d3bbd6
commit dc54ed6855
4 changed files with 49 additions and 8 deletions

View File

@ -36,6 +36,9 @@
#include "Windows/W32Util/Misc.h"
#include "Windows/GPU/WindowsGLContext.h"
// Currently, just compile time for debugging. May be NVIDIA only.
static const int simulateGLES = false;
void WindowsGLContext::SwapBuffers() {
// We no longer call RenderManager::Swap here, it's handled by the render thread, which
// we're not on here.
@ -293,6 +296,21 @@ bool WindowsGLContext::InitFromRenderThread(std::string *error_message) {
// Alright, now for the modernity. First try a 4.4, then 4.3, context, if that fails try 3.3.
// I can't seem to find a way that lets you simply request the newest version available.
if (wglewIsSupported("WGL_ARB_create_context") == 1) {
if (simulateGLES) {
const static int simulateVersions[][2] = { {3, 2}, {3, 1}, {3, 0}, {2, 0} };
for (auto ver : simulateVersions) {
const int attribsES[] = {
WGL_CONTEXT_MAJOR_VERSION_ARB, ver[0],
WGL_CONTEXT_MINOR_VERSION_ARB, ver[1],
WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_ES2_PROFILE_BIT_EXT,
0
};
m_hrc = wglCreateContextAttribsARB(hDC, 0, attribsES);
if (m_hrc)
break;
}
}
for (int tryCore = 1; tryCore >= 0 && m_hrc == nullptr; --tryCore) {
SetGLCoreContext(tryCore == 1);

View File

@ -214,6 +214,13 @@ void CheckGLExtensions() {
}
}
#ifndef USING_GLES2
if (strstr(versionStr, "OpenGL ES") == versionStr) {
// For desktops running GLES.
gl_extensions.IsGLES = true;
}
#endif
if (!gl_extensions.IsGLES) { // For desktop GL
gl_extensions.ver[0] = parsed[0];
gl_extensions.ver[1] = parsed[1];
@ -232,7 +239,6 @@ void CheckGLExtensions() {
// Start by assuming we're at 2.0.
gl_extensions.ver[0] = 2;
#ifdef USING_GLES2
#ifdef GL_MAJOR_VERSION
// Before grabbing the values, reset the error.
glGetError();
@ -254,6 +260,7 @@ void CheckGLExtensions() {
#endif
// If the above didn't give us a version, or gave us a crazy version, fallback.
#ifdef USING_GLES2
if (gl_extensions.ver[0] < 3 || gl_extensions.ver[0] > 5) {
// Try to load GLES 3.0 only if "3.0" found in version
// This simple heuristic avoids issues on older devices where you can only call eglGetProcAddress a limited
@ -281,6 +288,9 @@ void CheckGLExtensions() {
gl_extensions.GLES3 = gl3stubInit();
}
}
#else
// If we have GLEW/similar, assume GLES3 loaded.
gl_extensions.GLES3 = gl_extensions.ver[0] >= 3;
#endif
if (gl_extensions.GLES3) {

View File

@ -376,7 +376,7 @@ void GLQueueRunner::InitCreateFramebuffer(const GLRInitStep &step) {
#ifndef USING_GLES2
if (!gl_extensions.ARB_framebuffer_object && gl_extensions.EXT_framebuffer_object) {
fbo_ext_create(step);
} else if (!gl_extensions.ARB_framebuffer_object) {
} else if (!gl_extensions.ARB_framebuffer_object && !gl_extensions.IsGLES) {
return;
}
// If GLES2, we have basic FBO support and can just proceed.
@ -577,7 +577,9 @@ void GLQueueRunner::PerformRenderPass(const GLRStep &step) {
glDisable(GL_DITHER);
glEnable(GL_SCISSOR_TEST);
#ifndef USING_GLES2
glDisable(GL_COLOR_LOGIC_OP);
if (!gl_extensions.IsGLES) {
glDisable(GL_COLOR_LOGIC_OP);
}
#endif
/*
@ -621,6 +623,7 @@ void GLQueueRunner::PerformRenderPass(const GLRStep &step) {
GLRTexture *curTex[8]{};
CHECK_GL_ERROR_IF_DEBUG();
auto &commands = step.commands;
for (const auto &c : commands) {
switch (c.cmd) {
@ -720,7 +723,11 @@ void GLQueueRunner::PerformRenderPass(const GLRStep &step) {
#if defined(USING_GLES2)
glClearDepthf(c.clear.clearZ);
#else
glClearDepth(c.clear.clearZ);
if (gl_extensions.IsGLES) {
glClearDepthf(c.clear.clearZ);
} else {
glClearDepth(c.clear.clearZ);
}
#endif
}
if (c.clear.clearMask & GL_STENCIL_BUFFER_BIT) {
@ -758,7 +765,11 @@ void GLQueueRunner::PerformRenderPass(const GLRStep &step) {
// TODO: Support FP viewports through glViewportArrays
glViewport((GLint)c.viewport.vp.x, (GLint)y, (GLsizei)c.viewport.vp.w, (GLsizei)c.viewport.vp.h);
#if !defined(USING_GLES2)
glDepthRange(c.viewport.vp.minZ, c.viewport.vp.maxZ);
if (gl_extensions.IsGLES) {
glDepthRangef(c.viewport.vp.minZ, c.viewport.vp.maxZ);
} else {
glDepthRange(c.viewport.vp.minZ, c.viewport.vp.maxZ);
}
#else
glDepthRangef(c.viewport.vp.minZ, c.viewport.vp.maxZ);
#endif
@ -998,7 +1009,7 @@ void GLQueueRunner::PerformRenderPass(const GLRStep &step) {
break;
}
#ifndef USING_GLES2
if (tex->lodBias != c.textureLod.lodBias) {
if (tex->lodBias != c.textureLod.lodBias && !gl_extensions.IsGLES) {
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_LOD_BIAS, c.textureLod.lodBias);
tex->lodBias = c.textureLod.lodBias;
}
@ -1066,7 +1077,9 @@ void GLQueueRunner::PerformRenderPass(const GLRStep &step) {
glDisable(GL_BLEND);
glDisable(GL_CULL_FACE);
#ifndef USING_GLES2
glDisable(GL_COLOR_LOGIC_OP);
if (!gl_extensions.IsGLES) {
glDisable(GL_COLOR_LOGIC_OP);
}
#endif
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
CHECK_GL_ERROR_IF_DEBUG();

View File

@ -841,7 +841,7 @@ void *GLRBuffer::Map(GLBufferStrategy strategy) {
} else if (gl_extensions.VersionGEThan(3, 0, 0)) {
// GLES3 or desktop 3.
p = glMapBufferRange(target_, 0, size_, access);
} else {
} else if (!gl_extensions.IsGLES) {
#ifndef USING_GLES2
p = glMapBuffer(target_, GL_READ_WRITE);
#endif