mirror of
https://github.com/ZDoom/Raze.git
synced 2025-06-02 18:21:06 +00:00
- Backend update from GZDoom - mainly for GLES2 support.
This commit is contained in:
parent
11aea1c5d4
commit
a3d9cd9a68
66 changed files with 9558 additions and 126 deletions
188
source/common/rendering/gles/gles_system.cpp
Normal file
188
source/common/rendering/gles/gles_system.cpp
Normal file
|
@ -0,0 +1,188 @@
|
|||
|
||||
|
||||
#include "gles_system.h"
|
||||
#include "tarray.h"
|
||||
#include "v_video.h"
|
||||
#include "printf.h"
|
||||
|
||||
CVAR(Bool, gles_use_mapped_buffer, false, 0);
|
||||
CVAR(Bool, gles_force_glsl_v100, false, 0);
|
||||
CVAR(Int, gles_max_lights_per_surface, 32, 0);
|
||||
EXTERN_CVAR(Bool, gl_customshader);
|
||||
|
||||
|
||||
#if USE_GLES2
|
||||
|
||||
PFNGLMAPBUFFERRANGEEXTPROC glMapBufferRange = NULL;
|
||||
PFNGLUNMAPBUFFEROESPROC glUnmapBuffer = NULL;
|
||||
#ifdef __ANDROID__
|
||||
#include <dlfcn.h>
|
||||
|
||||
static void* LoadGLES2Proc(const char* name)
|
||||
{
|
||||
static void *glesLib = NULL;
|
||||
|
||||
if(!glesLib)
|
||||
{
|
||||
int flags = RTLD_LOCAL | RTLD_NOW;
|
||||
|
||||
glesLib = dlopen("libGLESv2_CM.so", flags);
|
||||
if(!glesLib)
|
||||
{
|
||||
glesLib = dlopen("libGLESv2.so", flags);
|
||||
}
|
||||
}
|
||||
|
||||
void * ret = NULL;
|
||||
ret = dlsym(glesLib, name);
|
||||
|
||||
if(!ret)
|
||||
{
|
||||
//LOGI("Failed to load: %s", name);
|
||||
}
|
||||
else
|
||||
{
|
||||
//LOGI("Loaded %s func OK", name);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#elif defined _WIN32
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
static HMODULE opengl32dll;
|
||||
static PROC(WINAPI* getprocaddress)(LPCSTR name);
|
||||
|
||||
static void* LoadGLES2Proc(const char* name)
|
||||
{
|
||||
|
||||
HINSTANCE hGetProcIDDLL = LoadLibraryA("libGLESv2.dll");
|
||||
|
||||
int error = GetLastError();
|
||||
|
||||
void* addr = GetProcAddress(hGetProcIDDLL, name);
|
||||
if (!addr)
|
||||
{
|
||||
//exit(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
return addr;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif // USE_GLES2
|
||||
|
||||
static TArray<FString> m_Extensions;
|
||||
|
||||
|
||||
static void CollectExtensions()
|
||||
{
|
||||
const char* supported = (char*)glGetString(GL_EXTENSIONS);
|
||||
|
||||
if (nullptr != supported)
|
||||
{
|
||||
char* extensions = new char[strlen(supported) + 1];
|
||||
strcpy(extensions, supported);
|
||||
|
||||
char* extension = strtok(extensions, " ");
|
||||
|
||||
while (extension)
|
||||
{
|
||||
m_Extensions.Push(FString(extension));
|
||||
extension = strtok(nullptr, " ");
|
||||
}
|
||||
|
||||
delete[] extensions;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static bool CheckExtension(const char* ext)
|
||||
{
|
||||
for (unsigned int i = 0; i < m_Extensions.Size(); ++i)
|
||||
{
|
||||
if (m_Extensions[i].CompareNoCase(ext) == 0) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
namespace OpenGLESRenderer
|
||||
{
|
||||
RenderContextGLES gles;
|
||||
|
||||
void InitGLES()
|
||||
{
|
||||
|
||||
#if USE_GLES2
|
||||
|
||||
if (!gladLoadGLES2Loader(&LoadGLES2Proc))
|
||||
{
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
glMapBufferRange = (PFNGLMAPBUFFERRANGEEXTPROC)LoadGLES2Proc("glMapBufferRange");
|
||||
glUnmapBuffer = (PFNGLUNMAPBUFFEROESPROC)LoadGLES2Proc("glUnmapBuffer");
|
||||
|
||||
#else
|
||||
static bool first = true;
|
||||
|
||||
if (first)
|
||||
{
|
||||
if (ogl_LoadFunctions() == ogl_LOAD_FAILED)
|
||||
{
|
||||
//I_FatalError("Failed to load OpenGL functions.");
|
||||
}
|
||||
}
|
||||
GLuint vao;
|
||||
glGenVertexArrays(1, &vao);
|
||||
glBindVertexArray(vao);
|
||||
#endif
|
||||
CollectExtensions();
|
||||
|
||||
Printf("GL_VENDOR: %s\n", glGetString(GL_VENDOR));
|
||||
Printf("GL_RENDERER: %s\n", glGetString(GL_RENDERER));
|
||||
Printf("GL_VERSION: %s\n", glGetString(GL_VERSION));
|
||||
Printf("GL_SHADING_LANGUAGE_VERSION: %s\n", glGetString(GL_SHADING_LANGUAGE_VERSION));
|
||||
Printf("GL_EXTENSIONS:\n");
|
||||
for (unsigned i = 0; i < m_Extensions.Size(); i++)
|
||||
{
|
||||
Printf(" %s\n", m_Extensions[i].GetChars());
|
||||
}
|
||||
|
||||
|
||||
gles.flags = RFL_NO_CLIP_PLANES;
|
||||
|
||||
gles.useMappedBuffers = gles_use_mapped_buffer;
|
||||
gles.forceGLSLv100 = gles_force_glsl_v100;
|
||||
gles.maxlights = gles_max_lights_per_surface;
|
||||
|
||||
gles.modelstring = (char*)glGetString(GL_RENDERER);
|
||||
gles.vendorstring = (char*)glGetString(GL_VENDOR);
|
||||
|
||||
gl_customshader = false;
|
||||
|
||||
GLint maxTextureSize[1];
|
||||
glGetIntegerv(GL_MAX_TEXTURE_SIZE, maxTextureSize);
|
||||
|
||||
gles.max_texturesize = maxTextureSize[0];
|
||||
|
||||
Printf("GL_MAX_TEXTURE_SIZE: %d\n", gles.max_texturesize);
|
||||
|
||||
#if USE_GLES2
|
||||
gles.depthStencilAvailable = CheckExtension("GL_OES_packed_depth_stencil");
|
||||
gles.npotAvailable = CheckExtension("GL_OES_texture_npot");
|
||||
#else
|
||||
gles.depthStencilAvailable = true;
|
||||
gles.npotAvailable = true;
|
||||
gles.useMappedBuffers = true;
|
||||
#endif
|
||||
|
||||
gles.numlightvectors = (gles.maxlights * LIGHT_VEC4_NUM);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue