mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-01-22 09:01:57 -05:00
Windows: Change OpenGL build to not rely on linking to opengl32 dll, and instead load all the functions dynamically
This commit is contained in:
parent
a0f652cb8c
commit
e93c9336dd
7 changed files with 268 additions and 222 deletions
6
.github/workflows/build_windows.yml
vendored
6
.github/workflows/build_windows.yml
vendored
|
@ -34,11 +34,11 @@ jobs:
|
|||
cp misc/windows/CCicon_32.res src/CCicon_32.res
|
||||
cd src
|
||||
i686-w64-mingw32-gcc *.c ${{ env.COMMON_FLAGS }} ${{ env.WIN32_FLAGS }} -o cc-w32-d3d9.exe $LATEST_FLAG -lwinmm -limagehlp
|
||||
i686-w64-mingw32-gcc *.c ${{ env.COMMON_FLAGS }} ${{ env.WIN32_FLAGS }} -o cc-w32-ogl.exe $LATEST_FLAG -DCC_GFX_BACKEND=CC_GFX_BACKEND_GL1 -lwinmm -limagehlp -lopengl32
|
||||
i686-w64-mingw32-gcc *.c ${{ env.COMMON_FLAGS }} ${{ env.WIN32_FLAGS }} -o cc-w32-ogl.exe $LATEST_FLAG -DCC_GFX_BACKEND=CC_GFX_BACKEND_GL1 -lwinmm -limagehlp
|
||||
i686-w64-mingw32-gcc *.c ${{ env.COMMON_FLAGS }} ${{ env.WIN32_FLAGS }} -o cc-w32-d3d11.exe $LATEST_FLAG -DCC_GFX_BACKEND=CC_GFX_BACKEND_D3D11 -lwinmm -limagehlp
|
||||
|
||||
# mingw defaults to i686, but some really old CPUs only support i586
|
||||
i686-w64-mingw32-gcc *.c ${{ env.COMMON_FLAGS }} ${{ env.WIN32_FLAGS }} -march=i586 -o cc-w9x-ogl.exe $LATEST_FLAG -DCC_GFX_BACKEND=CC_GFX_BACKEND_GL1 -DCC_BUILD_NOSTDLIB -lwinmm -limagehlp -lopengl32
|
||||
i686-w64-mingw32-gcc *.c ${{ env.COMMON_FLAGS }} ${{ env.WIN32_FLAGS }} -march=i586 -o cc-w9x-ogl.exe $LATEST_FLAG -DCC_GFX_BACKEND=CC_GFX_BACKEND_GL1 -DCC_BUILD_NOSTDLIB -lwinmm -limagehlp
|
||||
|
||||
|
||||
- uses: ./.github/actions/notify_failure
|
||||
|
@ -100,7 +100,7 @@ jobs:
|
|||
cp misc/windows/CCicon_64.res src/CCicon_64.res
|
||||
cd src
|
||||
x86_64-w64-mingw32-gcc *.c ${{ env.COMMON_FLAGS }} ${{ env.WIN64_FLAGS }} -o cc-w64-d3d9.exe $LATEST_FLAG -lwinmm -limagehlp
|
||||
x86_64-w64-mingw32-gcc *.c ${{ env.COMMON_FLAGS }} ${{ env.WIN64_FLAGS }} -o cc-w64-ogl.exe $LATEST_FLAG -DCC_GFX_BACKEND=CC_GFX_BACKEND_GL1 -lwinmm -limagehlp -lopengl32
|
||||
x86_64-w64-mingw32-gcc *.c ${{ env.COMMON_FLAGS }} ${{ env.WIN64_FLAGS }} -o cc-w64-ogl.exe $LATEST_FLAG -DCC_GFX_BACKEND=CC_GFX_BACKEND_GL1 -lwinmm -limagehlp
|
||||
x86_64-w64-mingw32-gcc *.c ${{ env.COMMON_FLAGS }} ${{ env.WIN64_FLAGS }} -o cc-w64-d3d11.exe $LATEST_FLAG -DCC_GFX_BACKEND=CC_GFX_BACKEND_D3D11 -lwinmm -limagehlp
|
||||
|
||||
|
||||
|
|
|
@ -1,64 +1,64 @@
|
|||
/* Raster state functions */
|
||||
GL_FUNC(void, glAlphaFunc)(GLenum func, GLfloat ref);
|
||||
GL_FUNC(void, glBlendFunc)(GLenum sfactor, GLenum dfactor);
|
||||
GL_FUNC(void, glClearColor)(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
|
||||
GL_FUNC(void, glColorMask)(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha);
|
||||
GL_FUNC(void, glDepthFunc)(GLenum func);
|
||||
GL_FUNC(void, glDepthMask)(GLboolean flag);
|
||||
GL_FUNC(void, glDisable)(GLenum cap);
|
||||
GL_FUNC(void, glDisableClientState)(GLenum array);
|
||||
GL_FUNC(void, glEnable)(GLenum cap);
|
||||
GL_FUNC(void, glEnableClientState)(GLenum array);
|
||||
GL_FUNC(void, glAlphaFunc, (GLenum func, GLfloat ref))
|
||||
GL_FUNC(void, glBlendFunc, (GLenum sfactor, GLenum dfactor))
|
||||
GL_FUNC(void, glClearColor, (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha))
|
||||
GL_FUNC(void, glColorMask, (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha))
|
||||
GL_FUNC(void, glDepthFunc, (GLenum func))
|
||||
GL_FUNC(void, glDepthMask, (GLboolean flag))
|
||||
GL_FUNC(void, glDisable, (GLenum cap))
|
||||
GL_FUNC(void, glDisableClientState, (GLenum array))
|
||||
GL_FUNC(void, glEnable, (GLenum cap))
|
||||
GL_FUNC(void, glEnableClientState, (GLenum array))
|
||||
|
||||
/* Fog functions */
|
||||
GL_FUNC(void, glFogf)(GLenum pname, GLfloat param);
|
||||
GL_FUNC(void, glFogfv)(GLenum pname, const GLfloat* params);
|
||||
GL_FUNC(void, glFogi)(GLenum pname, GLint param);
|
||||
GL_FUNC(void, glFogiv)(GLenum pname, const GLint* params);
|
||||
GL_FUNC(void, glFogf, (GLenum pname, GLfloat param))
|
||||
GL_FUNC(void, glFogfv, (GLenum pname, const GLfloat* params))
|
||||
GL_FUNC(void, glFogi, (GLenum pname, GLint param))
|
||||
GL_FUNC(void, glFogiv, (GLenum pname, const GLint* params))
|
||||
|
||||
/* Transform functions */
|
||||
GL_FUNC(void, glLoadIdentity)(void);
|
||||
GL_FUNC(void, glLoadMatrixf)(const GLfloat* m);
|
||||
GL_FUNC(void, glMatrixMode)(GLenum mode);
|
||||
GL_FUNC(void, glViewport)(GLint x, GLint y, GLsizei width, GLsizei height);
|
||||
GL_FUNC(void, glLoadIdentity, (void))
|
||||
GL_FUNC(void, glLoadMatrixf, (const GLfloat* m))
|
||||
GL_FUNC(void, glMatrixMode, (GLenum mode))
|
||||
GL_FUNC(void, glViewport, (GLint x, GLint y, GLsizei width, GLsizei height))
|
||||
|
||||
/* Draw functions */
|
||||
GL_FUNC(void, glDrawArrays)(GLenum mode, GLint first, GLsizei count);
|
||||
GL_FUNC(void, glDrawElements)(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices);
|
||||
GL_FUNC(void, glColorPointer)(GLint size, GLenum type, GLsizei stride, GLpointer pointer);
|
||||
GL_FUNC(void, glTexCoordPointer)(GLint size, GLenum type, GLsizei stride, GLpointer pointer);
|
||||
GL_FUNC(void, glVertexPointer)(GLint size, GLenum type, GLsizei stride, GLpointer pointer);
|
||||
GL_FUNC(void, glDrawArrays, (GLenum mode, GLint first, GLsizei count))
|
||||
GL_FUNC(void, glDrawElements, (GLenum mode, GLsizei count, GLenum type, const GLvoid* indices))
|
||||
GL_FUNC(void, glColorPointer, (GLint size, GLenum type, GLsizei stride, GLpointer pointer))
|
||||
GL_FUNC(void, glTexCoordPointer, (GLint size, GLenum type, GLsizei stride, GLpointer pointer))
|
||||
GL_FUNC(void, glVertexPointer, (GLint size, GLenum type, GLsizei stride, GLpointer pointer))
|
||||
|
||||
/* Misc functions */
|
||||
GL_FUNC(void, glClear)(GLuint mask);
|
||||
GL_FUNC(void, glHint)(GLenum target, GLenum mode);
|
||||
GL_FUNC(void, glReadPixels)(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid* pixels);
|
||||
GL_FUNC(void, glScissor)(GLint x, GLint y, GLsizei width, GLsizei height);
|
||||
GL_FUNC(void, glClear, (GLuint mask))
|
||||
GL_FUNC(void, glHint, (GLenum target, GLenum mode))
|
||||
GL_FUNC(void, glReadPixels, (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid* pixels))
|
||||
GL_FUNC(void, glScissor, (GLint x, GLint y, GLsizei width, GLsizei height))
|
||||
|
||||
/* Texture functions */
|
||||
GL_FUNC(void, glBindTexture)(GLenum target, GLuint texture);
|
||||
GL_FUNC(void, glDeleteTextures)(GLsizei n, const GLuint* textures);
|
||||
GL_FUNC(void, glGenTextures)(GLsizei n, GLuint* textures);
|
||||
GL_FUNC(void, glTexImage2D)(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid* pixels);
|
||||
GL_FUNC(void, glTexSubImage2D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid* pixels);
|
||||
GL_FUNC(void, glTexParameteri)(GLenum target, GLenum pname, GLint param);
|
||||
GL_FUNC(void, glBindTexture, (GLenum target, GLuint texture))
|
||||
GL_FUNC(void, glDeleteTextures, (GLsizei n, const GLuint* textures))
|
||||
GL_FUNC(void, glGenTextures, (GLsizei n, GLuint* textures))
|
||||
GL_FUNC(void, glTexImage2D, (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid* pixels))
|
||||
GL_FUNC(void, glTexSubImage2D, (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid* pixels))
|
||||
GL_FUNC(void, glTexParameteri, (GLenum target, GLenum pname, GLint param))
|
||||
|
||||
/* State get functions */
|
||||
GL_FUNC(GLenum, glGetError)(void);
|
||||
GL_FUNC(void, glGetFloatv)(GLenum pname, GLfloat* params);
|
||||
GL_FUNC(void, glGetIntegerv)(GLenum pname, GLint* params);
|
||||
GL_FUNC(const GLubyte*, glGetString)(GLenum name);
|
||||
GL_FUNC(GLenum, glGetError, (void))
|
||||
GL_FUNC(void, glGetFloatv, (GLenum pname, GLfloat* params))
|
||||
GL_FUNC(void, glGetIntegerv, (GLenum pname, GLint* params))
|
||||
GL_FUNC(const GLubyte*, glGetString, (GLenum name))
|
||||
|
||||
/* Legacy display list functions */
|
||||
GL_FUNC(void, glCallList)(GLuint list);
|
||||
GL_FUNC(void, glDeleteLists)(GLuint list, GLsizei range);
|
||||
GL_FUNC(GLuint, glGenLists)(GLsizei range);
|
||||
GL_FUNC(void, glNewList)(GLuint list, GLenum mode);
|
||||
GL_FUNC(void, glEndList)(void);
|
||||
GL_FUNC(void, glCallList, (GLuint list))
|
||||
GL_FUNC(void, glDeleteLists, (GLuint list, GLsizei range))
|
||||
GL_FUNC(GLuint, glGenLists, (GLsizei range))
|
||||
GL_FUNC(void, glNewList, (GLuint list, GLenum mode))
|
||||
GL_FUNC(void, glEndList, (void))
|
||||
|
||||
/* Legacy vertex draw functions */
|
||||
GL_FUNC(void, glBegin)(GLenum mode);
|
||||
GL_FUNC(void, glEnd)(void);
|
||||
GL_FUNC(void, glColor4ub)(GLubyte r, GLubyte g, GLubyte b, GLubyte a);
|
||||
GL_FUNC(void, glTexCoord2f)(float u, float v);
|
||||
GL_FUNC(void, glVertex3f)(float x, float y, float z);
|
||||
GL_FUNC(void, glBegin, (GLenum mode))
|
||||
GL_FUNC(void, glEnd, (void))
|
||||
GL_FUNC(void, glColor4ub, (GLubyte r, GLubyte g, GLubyte b, GLubyte a))
|
||||
GL_FUNC(void, glTexCoord2f, (float u, float v))
|
||||
GL_FUNC(void, glVertex3f, (float x, float y, float z))
|
64
misc/opengl/GL1Macros.h
Normal file
64
misc/opengl/GL1Macros.h
Normal file
|
@ -0,0 +1,64 @@
|
|||
/* Raster state functions */
|
||||
#define _glAlphaFunc glAlphaFunc
|
||||
#define _glBlendFunc glBlendFunc
|
||||
#define _glClearColor glClearColor
|
||||
#define _glColorMask glColorMask
|
||||
#define _glDepthFunc glDepthFunc
|
||||
#define _glDepthMask glDepthMask
|
||||
#define _glDisable glDisable
|
||||
#define _glDisableClientState glDisableClientState
|
||||
#define _glEnable glEnable
|
||||
#define _glEnableClientState glEnableClientState
|
||||
|
||||
/* Fog functions */
|
||||
#define _glFogf glFogf
|
||||
#define _glFogfv glFogfv
|
||||
#define _glFogi glFogi
|
||||
#define _glFogiv glFogiv
|
||||
|
||||
/* Transform functions */
|
||||
#define _glLoadIdentity glLoadIdentity
|
||||
#define _glLoadMatrixf glLoadMatrixf
|
||||
#define _glMatrixMode glMatrixMode
|
||||
#define _glViewport glViewport
|
||||
|
||||
/* Draw functions */
|
||||
#define _glDrawArrays glDrawArrays
|
||||
#define _glDrawElements glDrawElements
|
||||
#define _glColorPointer glColorPointer
|
||||
#define _glTexCoordPointer glTexCoordPointer
|
||||
#define _glVertexPointer glVertexPointer
|
||||
|
||||
/* Misc functions */
|
||||
#define _glClear glClear
|
||||
#define _glHint glHint
|
||||
#define _glReadPixels glReadPixels
|
||||
#define _glScissor glScissor
|
||||
|
||||
/* Texture functions */
|
||||
#define _glBindTexture glBindTexture
|
||||
#define _glDeleteTextures glDeleteTextures
|
||||
#define _glGenTextures glGenTextures
|
||||
#define _glTexImage2D glTexImage2D
|
||||
#define _glTexSubImage2D glTexSubImage2D
|
||||
#define _glTexParameteri glTexParameteri
|
||||
|
||||
/* State get functions */
|
||||
#define _glGetError glGetError
|
||||
#define _glGetFloatv glGetFloatv
|
||||
#define _glGetIntegerv glGetIntegerv
|
||||
#define _glGetString glGetString
|
||||
|
||||
/* Legacy display list functions */
|
||||
#define _glCallList glCallList
|
||||
#define _glDeleteLists glDeleteLists
|
||||
#define _glGenLists glGenLists
|
||||
#define _glNewList glNewList
|
||||
#define _glEndList glEndList
|
||||
|
||||
/* Legacy vertex draw functions */
|
||||
#define _glBegin glBegin
|
||||
#define _glEnd glEnd
|
||||
#define _glColor4ub glColor4ub
|
||||
#define _glTexCoord2f glTexCoord2f
|
||||
#define _glVertex3f glVertex3f
|
|
@ -1,36 +1,36 @@
|
|||
/* Buffer functions */
|
||||
GL_FUNC(void, glBindBuffer)(GLenum target, GLuint buffer);
|
||||
GL_FUNC(void, glDeleteBuffers)(GLsizei n, const GLuint* buffers);
|
||||
GL_FUNC(void, glGenBuffers)(GLsizei n, GLuint *buffers);
|
||||
GL_FUNC(void, glBufferData)(GLenum target, cc_uintptr size, const GLvoid* data, GLenum usage);
|
||||
GL_FUNC(void, glBufferSubData)(GLenum target, cc_uintptr offset, cc_uintptr size, const GLvoid* data);
|
||||
GL_FUNC(void, glBindBuffer, (GLenum target, GLuint buffer))
|
||||
GL_FUNC(void, glDeleteBuffers, (GLsizei n, const GLuint* buffers))
|
||||
GL_FUNC(void, glGenBuffers, (GLsizei n, GLuint *buffers))
|
||||
GL_FUNC(void, glBufferData, (GLenum target, cc_uintptr size, const GLvoid* data, GLenum usage))
|
||||
GL_FUNC(void, glBufferSubData, (GLenum target, cc_uintptr offset, cc_uintptr size, const GLvoid* data))
|
||||
|
||||
/* Shader functions */
|
||||
GL_FUNC(GLuint, glCreateShader)(GLenum type);
|
||||
GL_FUNC(void, glDeleteShader)(GLuint shader);
|
||||
GL_FUNC(void, glGetShaderiv)(GLuint shader, GLenum pname, GLint* params);
|
||||
GL_FUNC(void, glGetShaderInfoLog)(GLuint shader, GLsizei bufSize, GLsizei* length, char* infoLog);
|
||||
GL_FUNC(void, glShaderSource)(GLuint shader, GLsizei count, const char* const* string, const GLint* length);
|
||||
GL_FUNC(GLuint, glCreateShader, (GLenum type))
|
||||
GL_FUNC(void, glDeleteShader, (GLuint shader))
|
||||
GL_FUNC(void, glGetShaderiv, (GLuint shader, GLenum pname, GLint* params))
|
||||
GL_FUNC(void, glGetShaderInfoLog, (GLuint shader, GLsizei bufSize, GLsizei* length, char* infoLog))
|
||||
GL_FUNC(void, glShaderSource, (GLuint shader, GLsizei count, const char* const* string, const GLint* length))
|
||||
|
||||
GL_FUNC(void, glAttachShader)(GLuint program, GLuint shader);
|
||||
GL_FUNC(void, glBindAttribLocation)(GLuint program, GLuint index, const char* name);
|
||||
GL_FUNC(void, glCompileShader)(GLuint shader);
|
||||
GL_FUNC(void, glDetachShader)(GLuint program, GLuint shader);
|
||||
GL_FUNC(void, glLinkProgram)(GLuint program);
|
||||
GL_FUNC(void, glAttachShader, (GLuint program, GLuint shader))
|
||||
GL_FUNC(void, glBindAttribLocation, (GLuint program, GLuint index, const char* name))
|
||||
GL_FUNC(void, glCompileShader, (GLuint shader))
|
||||
GL_FUNC(void, glDetachShader, (GLuint program, GLuint shader))
|
||||
GL_FUNC(void, glLinkProgram, (GLuint program))
|
||||
|
||||
/* Program functions */
|
||||
GL_FUNC(GLuint, glCreateProgram)(void);
|
||||
GL_FUNC(void, glDeleteProgram)(GLuint program);
|
||||
GL_FUNC(void, glGetProgramiv)(GLuint program, GLenum pname, GLint* params);
|
||||
GL_FUNC(void, glGetProgramInfoLog)(GLuint program, GLsizei bufSize, GLsizei* length, char* infoLog);
|
||||
GL_FUNC(void, glUseProgram)(GLuint program);
|
||||
GL_FUNC(GLuint, glCreateProgram, (void))
|
||||
GL_FUNC(void, glDeleteProgram, (GLuint program))
|
||||
GL_FUNC(void, glGetProgramiv, (GLuint program, GLenum pname, GLint* params))
|
||||
GL_FUNC(void, glGetProgramInfoLog, (GLuint program, GLsizei bufSize, GLsizei* length, char* infoLog))
|
||||
GL_FUNC(void, glUseProgram, (GLuint program))
|
||||
|
||||
GL_FUNC(void, glDisableVertexAttribArray)(GLuint index);
|
||||
GL_FUNC(void, glEnableVertexAttribArray)(GLuint index);
|
||||
GL_FUNC(void, glVertexAttribPointer)(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void* pointer);
|
||||
GL_FUNC(void, glDisableVertexAttribArray, (GLuint index))
|
||||
GL_FUNC(void, glEnableVertexAttribArray, (GLuint index))
|
||||
GL_FUNC(void, glVertexAttribPointer, (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void* pointer))
|
||||
|
||||
GL_FUNC(GLint, glGetUniformLocation)(GLuint program, const char* name);
|
||||
GL_FUNC(void, glUniform1f)(GLint location, GLfloat v0);
|
||||
GL_FUNC(void, glUniform2f)(GLint location, GLfloat v0, GLfloat v1);
|
||||
GL_FUNC(void, glUniform3f)(GLint location, GLfloat v0, GLfloat v1, GLfloat v2);
|
||||
GL_FUNC(void, glUniformMatrix4fv)(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value);
|
||||
GL_FUNC(GLint, glGetUniformLocation, (GLuint program, const char* name))
|
||||
GL_FUNC(void, glUniform1f, (GLint location, GLfloat v0))
|
||||
GL_FUNC(void, glUniform2f, (GLint location, GLfloat v0, GLfloat v1))
|
||||
GL_FUNC(void, glUniform3f, (GLint location, GLfloat v0, GLfloat v1, GLfloat v2))
|
||||
GL_FUNC(void, glUniformMatrix4fv, (GLint location, GLsizei count, GLboolean transpose, const GLfloat* value))
|
|
@ -18,8 +18,8 @@
|
|||
*/
|
||||
#include "../misc/opengl/GLCommon.h"
|
||||
|
||||
/* e.g. GLAPI void APIENTRY glFunction(int args); */
|
||||
#define GL_FUNC(_retType, name) GLAPI _retType APIENTRY name
|
||||
/* e.g. GLAPI void APIENTRY glFunction(int value); */
|
||||
#define GL_FUNC(retType, name, args) GLAPI retType APIENTRY name args;
|
||||
#include "../misc/opengl/GL1Funcs.h"
|
||||
|
||||
#if defined CC_BUILD_GL11
|
||||
|
@ -36,14 +36,6 @@ static void (APIENTRY *_glBufferData)(GLenum target, cc_uintptr size, const GLvo
|
|||
static void (APIENTRY *_glBufferSubData)(GLenum target, cc_uintptr offset, cc_uintptr size, const GLvoid* data);
|
||||
#endif
|
||||
|
||||
static void GLContext_GetAll(const struct DynamicLibSym* syms, int count) {
|
||||
int i;
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
*syms[i].symAddr = GLContext_GetAddress(syms[i].name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#if defined CC_BUILD_GL11_FALLBACK && !defined CC_BUILD_GL11
|
||||
/* Note the following about calling OpenGL functions on Windows */
|
||||
|
@ -56,46 +48,24 @@ static void GLContext_GetAll(const struct DynamicLibSym* syms, int count) {
|
|||
/* call [glDrawElements] --> opengl32.dll thunk--> GL driver thunk --> GL driver implementation */
|
||||
/* call [_glDrawElements] --> GL driver thunk --> GL driver implementation */
|
||||
|
||||
/* e.g. typedef void (APIENTRY *FP_glFunction)(int args); */
|
||||
/* e.g. typedef void (APIENTRY *FP_glFunction)(int value); */
|
||||
#undef GL_FUNC
|
||||
#define GL_FUNC(_retType, name) typedef _retType (APIENTRY *FP_ ## name)
|
||||
#define GL_FUNC(retType, name, args) typedef retType (APIENTRY *FP_ ## name)args;
|
||||
#include "../misc/opengl/GL1Funcs.h"
|
||||
|
||||
/* e.g. static void (APIENTRY *_glFunction)(int args); */
|
||||
/* e.g. static void (APIENTRY *_glFunction)(int value); */
|
||||
#undef GL_FUNC
|
||||
#define GL_FUNC(_retType, name) static _retType (APIENTRY *_ ## name)
|
||||
#define GL_FUNC(retType, name, args) static retType (APIENTRY *_ ## name)args;
|
||||
#include "../misc/opengl/GL1Funcs.h"
|
||||
|
||||
#define GLSym(sym) { DYNAMICLIB_QUOTE(sym), (void**)&_ ## sym }
|
||||
static const struct DynamicLibSym coreFuncs[] = {
|
||||
GLSym(glColorPointer), GLSym(glTexCoordPointer), GLSym(glVertexPointer),
|
||||
|
||||
GLSym(glDrawArrays), GLSym(glDrawElements),
|
||||
|
||||
GLSym(glBindTexture), GLSym(glDeleteTextures), GLSym(glGenTextures),
|
||||
GLSym(glTexImage2D), GLSym(glTexSubImage2D),
|
||||
GLSym(glDisableClientState), GLSym(glEnableClientState)
|
||||
/* e.g. { DYNAMICLIB_QUOTE(name), (void**)&_ ## name }, */
|
||||
#undef GL_FUNC
|
||||
#define GL_FUNC(retType, name, args) { DYNAMICLIB_QUOTE(name), (void**)&_ ## name },
|
||||
#include "../misc/opengl/GL1Funcs.h"
|
||||
};
|
||||
|
||||
static void LoadCoreFuncs(void) {
|
||||
GLContext_GetAll(coreFuncs, Array_Elems(coreFuncs));
|
||||
}
|
||||
#else
|
||||
#define _glColorPointer glColorPointer
|
||||
#define _glTexCoordPointer glTexCoordPointer
|
||||
#define _glVertexPointer glVertexPointer
|
||||
|
||||
#define _glDrawArrays glDrawArrays
|
||||
#define _glDrawElements glDrawElements
|
||||
|
||||
#define _glBindTexture glBindTexture
|
||||
#define _glDeleteTextures glDeleteTextures
|
||||
#define _glGenTextures glGenTextures
|
||||
#define _glTexImage2D glTexImage2D
|
||||
#define _glTexSubImage2D glTexSubImage2D
|
||||
|
||||
#define _glDisableClientState glDisableClientState
|
||||
#define _glEnableClientState glEnableClientState
|
||||
#include "../misc/opengl/GL1Macros.h"
|
||||
#endif
|
||||
|
||||
typedef void (*GL_SetupVBFunc)(void);
|
||||
|
@ -104,6 +74,21 @@ static GL_SetupVBFunc gfx_setupVBFunc;
|
|||
static GL_SetupVBRangeFunc gfx_setupVBRangeFunc;
|
||||
#include "_GLShared.h"
|
||||
|
||||
void Gfx_Create(void) {
|
||||
GLContext_Create();
|
||||
#ifdef CC_BUILD_GL11_FALLBACK
|
||||
GLContext_GetAll(coreFuncs, Array_Elems(coreFuncs));
|
||||
#endif
|
||||
customMipmapsLevels = true;
|
||||
Gfx.BackendType = CC_GFX_BACKEND_GL1;
|
||||
|
||||
GL_InitCommon();
|
||||
GLBackend_Init();
|
||||
Gfx_RestoreState();
|
||||
GLContext_SetVSync(gfx_vsync);
|
||||
}
|
||||
|
||||
|
||||
/*########################################################################################################################*
|
||||
*-------------------------------------------------------Index buffers-----------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
|
@ -322,13 +307,13 @@ void Gfx_SetVertexFormat(VertexFormat fmt) {
|
|||
|
||||
if (fmt == VERTEX_FORMAT_TEXTURED) {
|
||||
_glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
_glEnable(GL_TEXTURE_2D);
|
||||
|
||||
gfx_setupVBFunc = GL_SetupVbTextured;
|
||||
gfx_setupVBRangeFunc = GL_SetupVbTextured_Range;
|
||||
} else {
|
||||
_glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
_glDisable(GL_TEXTURE_2D);
|
||||
|
||||
gfx_setupVBFunc = GL_SetupVbColoured;
|
||||
gfx_setupVBRangeFunc = GL_SetupVbColoured_Range;
|
||||
|
@ -386,7 +371,7 @@ static int gfx_fogMode = -1;
|
|||
|
||||
void Gfx_SetFog(cc_bool enabled) {
|
||||
gfx_fogEnabled = enabled;
|
||||
if (enabled) { glEnable(GL_FOG); } else { glDisable(GL_FOG); }
|
||||
if (enabled) { _glEnable(GL_FOG); } else { _glDisable(GL_FOG); }
|
||||
}
|
||||
|
||||
void Gfx_SetFogCol(PackedCol color) {
|
||||
|
@ -398,19 +383,19 @@ void Gfx_SetFogCol(PackedCol color) {
|
|||
rgba[2] = PackedCol_B(color) / 255.0f;
|
||||
rgba[3] = PackedCol_A(color) / 255.0f;
|
||||
|
||||
glFogfv(GL_FOG_COLOR, rgba);
|
||||
_glFogfv(GL_FOG_COLOR, rgba);
|
||||
gfx_fogColor = color;
|
||||
}
|
||||
|
||||
void Gfx_SetFogDensity(float value) {
|
||||
if (value == gfx_fogDensity) return;
|
||||
glFogf(GL_FOG_DENSITY, value);
|
||||
_glFogf(GL_FOG_DENSITY, value);
|
||||
gfx_fogDensity = value;
|
||||
}
|
||||
|
||||
void Gfx_SetFogEnd(float value) {
|
||||
if (value == gfx_fogEnd) return;
|
||||
glFogf(GL_FOG_END, value);
|
||||
_glFogf(GL_FOG_END, value);
|
||||
gfx_fogEnd = value;
|
||||
}
|
||||
|
||||
|
@ -421,38 +406,39 @@ void Gfx_SetFogMode(FogFunc func) {
|
|||
#ifdef CC_BUILD_GLES
|
||||
/* OpenGL ES doesn't support glFogi, so use glFogf instead */
|
||||
/* https://www.khronos.org/registry/OpenGL-Refpages/es1.1/xhtml/ */
|
||||
glFogf(GL_FOG_MODE, modes[func]);
|
||||
_glFogf(GL_FOG_MODE, modes[func]);
|
||||
#else
|
||||
glFogi(GL_FOG_MODE, modes[func]);
|
||||
_glFogi(GL_FOG_MODE, modes[func]);
|
||||
#endif
|
||||
gfx_fogMode = func;
|
||||
}
|
||||
|
||||
static void SetAlphaTest(cc_bool enabled) {
|
||||
if (enabled) { glEnable(GL_ALPHA_TEST); } else { glDisable(GL_ALPHA_TEST); }
|
||||
if (enabled) { _glEnable(GL_ALPHA_TEST); } else { _glDisable(GL_ALPHA_TEST); }
|
||||
}
|
||||
|
||||
void Gfx_DepthOnlyRendering(cc_bool depthOnly) {
|
||||
cc_bool enabled = !depthOnly;
|
||||
SetColorWrite(enabled & gfx_colorMask[0], enabled & gfx_colorMask[1],
|
||||
enabled & gfx_colorMask[2], enabled & gfx_colorMask[3]);
|
||||
if (enabled) { glEnable(GL_TEXTURE_2D); } else { glDisable(GL_TEXTURE_2D); }
|
||||
|
||||
if (enabled) { _glEnable(GL_TEXTURE_2D); } else { _glDisable(GL_TEXTURE_2D); }
|
||||
}
|
||||
|
||||
|
||||
/*########################################################################################################################*
|
||||
*---------------------------------------------------------Matrices--------------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
static GLenum matrix_modes[3] = { GL_PROJECTION, GL_MODELVIEW, GL_TEXTURE };
|
||||
static GLenum matrix_modes[] = { GL_PROJECTION, GL_MODELVIEW, GL_TEXTURE };
|
||||
static int lastMatrix;
|
||||
|
||||
void Gfx_LoadMatrix(MatrixType type, const struct Matrix* matrix) {
|
||||
if (type != lastMatrix) { lastMatrix = type; glMatrixMode(matrix_modes[type]); }
|
||||
if (type != lastMatrix) { lastMatrix = type; _glMatrixMode(matrix_modes[type]); }
|
||||
|
||||
if (matrix == &Matrix_Identity) {
|
||||
glLoadIdentity();
|
||||
_glLoadIdentity();
|
||||
} else {
|
||||
glLoadMatrixf((const float*)matrix);
|
||||
_glLoadMatrixf((const float*)matrix);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -481,14 +467,14 @@ static void Gfx_RestoreState(void) {
|
|||
_glEnableClientState(GL_COLOR_ARRAY);
|
||||
gfx_format = -1;
|
||||
|
||||
glHint(GL_FOG_HINT, GL_NICEST);
|
||||
glAlphaFunc(GL_GREATER, 0.5f);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glDepthFunc(GL_LEQUAL);
|
||||
_glHint(GL_FOG_HINT, GL_NICEST);
|
||||
_glAlphaFunc(GL_GREATER, 0.5f);
|
||||
_glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
_glDepthFunc(GL_LEQUAL);
|
||||
}
|
||||
|
||||
cc_bool Gfx_WarnIfNecessary(void) {
|
||||
cc_string renderer = String_FromReadonly((const char*)glGetString(GL_RENDERER));
|
||||
cc_string renderer = String_FromReadonly((const char*)_glGetString(GL_RENDERER));
|
||||
|
||||
#ifdef CC_BUILD_GL11
|
||||
Chat_AddRaw("&cYou are using the very outdated OpenGL backend.");
|
||||
|
@ -577,10 +563,10 @@ static struct GL10Texture* gl10_tex;
|
|||
static void APIENTRY gl10_bindTexture(GLenum target, GLuint texture) {
|
||||
gl10_tex = (struct GL10Texture*)texture;
|
||||
if (gl10_tex && gl10_tex->pixels) {
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, 4, gl10_tex->width, gl10_tex->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, gl10_tex->pixels);
|
||||
_glTexImage2D(GL_TEXTURE_2D, 0, 4, gl10_tex->width, gl10_tex->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, gl10_tex->pixels);
|
||||
} else {
|
||||
BitmapCol pixel = BITMAPCOLOR_WHITE;
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, 4, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &pixel);
|
||||
_glTexImage2D(GL_TEXTURE_2D, 0, 4, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &pixel);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -621,27 +607,27 @@ static cc_uint8* gl10_vb;
|
|||
static void APIENTRY gl10_drawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices) {
|
||||
/* TODO */
|
||||
int i;
|
||||
glBegin(GL_QUADS);
|
||||
_glBegin(GL_QUADS);
|
||||
count = (count * 4) / 6;
|
||||
|
||||
if (gfx_format == VERTEX_FORMAT_TEXTURED) {
|
||||
struct VertexTextured* src = (struct VertexTextured*)gl10_vb;
|
||||
for (i = 0; i < count; i++, src++)
|
||||
{
|
||||
glColor4ub(PackedCol_R(src->Col), PackedCol_G(src->Col), PackedCol_B(src->Col), PackedCol_A(src->Col));
|
||||
glTexCoord2f(src->U, src->V);
|
||||
glVertex3f(src->x, src->y, src->z);
|
||||
_glColor4ub(PackedCol_R(src->Col), PackedCol_G(src->Col), PackedCol_B(src->Col), PackedCol_A(src->Col));
|
||||
_glTexCoord2f(src->U, src->V);
|
||||
_glVertex3f(src->x, src->y, src->z);
|
||||
}
|
||||
} else {
|
||||
struct VertexColoured* src = (struct VertexColoured*)gl10_vb;
|
||||
for (i = 0; i < count; i++, src++)
|
||||
{
|
||||
glColor4ub(PackedCol_R(src->Col), PackedCol_G(src->Col), PackedCol_B(src->Col), PackedCol_A(src->Col));
|
||||
glVertex3f(src->x, src->y, src->z);
|
||||
_glColor4ub(PackedCol_R(src->Col), PackedCol_G(src->Col), PackedCol_B(src->Col), PackedCol_A(src->Col));
|
||||
_glVertex3f(src->x, src->y, src->z);
|
||||
}
|
||||
}
|
||||
|
||||
glEnd();
|
||||
_glEnd();
|
||||
}
|
||||
static void APIENTRY gl10_colorPointer(GLint size, GLenum type, GLsizei stride, GLpointer offset) {
|
||||
}
|
||||
|
@ -721,16 +707,11 @@ static void GLBackend_Init(void) {
|
|||
DynamicLib_ReqSym2("glBufferSubDataARB", glBufferSubData)
|
||||
};
|
||||
static const cc_string vboExt = String_FromConst("GL_ARB_vertex_buffer_object");
|
||||
cc_string extensions = String_FromReadonly((const char*)glGetString(GL_EXTENSIONS));
|
||||
const GLubyte* ver = glGetString(GL_VERSION);
|
||||
cc_string extensions = String_FromReadonly((const char*)_glGetString(GL_EXTENSIONS));
|
||||
const GLubyte* ver = _glGetString(GL_VERSION);
|
||||
|
||||
/* Version string is always: x.y. (and whatever afterwards) */
|
||||
int major = ver[0] - '0', minor = ver[2] - '0';
|
||||
#ifdef CC_BUILD_GL11_FALLBACK
|
||||
LoadCoreFuncs();
|
||||
#endif
|
||||
customMipmapsLevels = true;
|
||||
Gfx.BackendType = CC_GFX_BACKEND_GL1;
|
||||
|
||||
/* Supported in core since 1.5 */
|
||||
if (major > 1 || (major == 1 && minor >= 5)) {
|
||||
|
@ -742,4 +723,4 @@ static void GLBackend_Init(void) {
|
|||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
|
@ -12,39 +12,28 @@
|
|||
/* OpenGL 2.0 backend (alternative modern-ish backend) */
|
||||
#include "../misc/opengl/GLCommon.h"
|
||||
|
||||
/* e.g. GLAPI void APIENTRY glFunction(int args); */
|
||||
#define GL_FUNC(_retType, name) GLAPI _retType APIENTRY name
|
||||
/* e.g. GLAPI void APIENTRY glFunction(int value); */
|
||||
#define GL_FUNC(retType, name, args) GLAPI retType APIENTRY name args;
|
||||
#include "../misc/opengl/GL1Funcs.h"
|
||||
|
||||
/* Functions must be dynamically linked on Windows */
|
||||
#ifdef CC_BUILD_WIN
|
||||
/* e.g. static void (APIENTRY *_glFunction)(int args); */
|
||||
/* e.g. static void (APIENTRY *_glFunction)(int value); */
|
||||
#undef GL_FUNC
|
||||
#define GL_FUNC(_retType, name) static _retType (APIENTRY *name)
|
||||
#define GL_FUNC(retType, name, args) static retType (APIENTRY *name) args;
|
||||
#include "../misc/opengl/GL2Funcs.h"
|
||||
|
||||
#define GLSym(sym) { DYNAMICLIB_QUOTE(sym), (void**)&sym }
|
||||
static const struct DynamicLibSym core_funcs[] = {
|
||||
GLSym(glBindBuffer), GLSym(glDeleteBuffers), GLSym(glGenBuffers), GLSym(glBufferData), GLSym(glBufferSubData),
|
||||
|
||||
GLSym(glCreateShader), GLSym(glDeleteShader), GLSym(glGetShaderiv), GLSym(glGetShaderInfoLog), GLSym(glShaderSource),
|
||||
GLSym(glAttachShader), GLSym(glBindAttribLocation), GLSym(glCompileShader), GLSym(glDetachShader), GLSym(glLinkProgram),
|
||||
|
||||
GLSym(glCreateProgram), GLSym(glDeleteProgram), GLSym(glGetProgramiv), GLSym(glGetProgramInfoLog), GLSym(glUseProgram),
|
||||
|
||||
GLSym(glDisableVertexAttribArray), GLSym(glEnableVertexAttribArray), GLSym(glVertexAttribPointer),
|
||||
|
||||
GLSym(glGetUniformLocation), GLSym(glUniform1f), GLSym(glUniform2f), GLSym(glUniform3f), GLSym(glUniformMatrix4fv),
|
||||
/* e.g. { DYNAMICLIB_QUOTE(name), (void**)&_ ## name }, */
|
||||
#undef GL_FUNC
|
||||
#define GL_FUNC(retType, name, args) { DYNAMICLIB_QUOTE(name), (void**)&name },
|
||||
#include "../misc/opengl/GL2Funcs.h"
|
||||
};
|
||||
#else
|
||||
#include "../misc/opengl/GL2Funcs.h"
|
||||
#include "../misc/opengl/GL2Funcs.h"
|
||||
#endif
|
||||
|
||||
#define _glBindTexture glBindTexture
|
||||
#define _glDeleteTextures glDeleteTextures
|
||||
#define _glGenTextures glGenTextures
|
||||
#define _glTexImage2D glTexImage2D
|
||||
#define _glTexSubImage2D glTexSubImage2D
|
||||
#include "../misc/opengl/GL1Macros.h"
|
||||
|
||||
#include "_GLShared.h"
|
||||
static GfxResourceID white_square;
|
||||
|
@ -52,6 +41,18 @@ static int postProcess;
|
|||
enum PostProcess { POSTPROCESS_NONE, POSTPROCESS_GRAYSCALE };
|
||||
static const char* const postProcess_Names[2] = { "NONE", "GRAYSCALE" };
|
||||
|
||||
void Gfx_Create(void) {
|
||||
GLContext_Create();
|
||||
#ifdef CC_BUILD_WIN
|
||||
GLContext_GetAll(core_funcs, Array_Elems(core_funcs));
|
||||
#endif
|
||||
Gfx.BackendType = CC_GFX_BACKEND_GL2;
|
||||
|
||||
GL_InitCommon();
|
||||
Gfx_RestoreState();
|
||||
GLContext_SetVSync(gfx_vsync);
|
||||
}
|
||||
|
||||
|
||||
/*########################################################################################################################*
|
||||
*-------------------------------------------------------Index buffers-----------------------------------------------------*
|
||||
|
@ -521,20 +522,7 @@ void Gfx_DisableTextureOffset(void) {
|
|||
/*########################################################################################################################*
|
||||
*-------------------------------------------------------State setup-------------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
static void GLContext_GetAll(const struct DynamicLibSym* syms, int count) {
|
||||
int i;
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
*syms[i].symAddr = GLContext_GetAddress(syms[i].name);
|
||||
}
|
||||
}
|
||||
|
||||
static void GLBackend_Init(void) {
|
||||
#ifdef CC_BUILD_WIN
|
||||
GLContext_GetAll(core_funcs, Array_Elems(core_funcs));
|
||||
#endif
|
||||
Gfx.BackendType = CC_GFX_BACKEND_GL2;
|
||||
|
||||
#ifdef CC_BUILD_GLES
|
||||
// OpenGL ES 2.0 doesn't support custom mipmaps levels, but 3.2 does
|
||||
// Note that GL_MAJOR_VERSION and GL_MINOR_VERSION were not actually
|
||||
|
|
|
@ -27,17 +27,20 @@
|
|||
*#########################################################################################################################*/
|
||||
static void GLBackend_Init(void);
|
||||
|
||||
void Gfx_Create(void) {
|
||||
GLContext_Create();
|
||||
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &Gfx.MaxTexWidth);
|
||||
static void GLContext_GetAll(const struct DynamicLibSym* syms, int count) {
|
||||
int i;
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
*syms[i].symAddr = GLContext_GetAddress(syms[i].name);
|
||||
}
|
||||
}
|
||||
|
||||
static void GL_InitCommon(void) {
|
||||
_glGetIntegerv(GL_MAX_TEXTURE_SIZE, &Gfx.MaxTexWidth);
|
||||
Gfx.MaxTexHeight = Gfx.MaxTexWidth;
|
||||
Gfx.Created = true;
|
||||
/* necessary for android which "loses" context when window is closed */
|
||||
Gfx.LostContext = false;
|
||||
|
||||
GLBackend_Init();
|
||||
Gfx_RestoreState();
|
||||
GLContext_SetVSync(gfx_vsync);
|
||||
}
|
||||
|
||||
cc_bool Gfx_TryRestoreContext(void) {
|
||||
|
@ -49,7 +52,6 @@ void Gfx_Free(void) {
|
|||
GLContext_Free();
|
||||
}
|
||||
|
||||
#define gl_Toggle(cap) if (enabled) { glEnable(cap); } else { glDisable(cap); }
|
||||
static void* tmpData;
|
||||
static int tmpSize;
|
||||
|
||||
|
@ -122,16 +124,16 @@ GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8 flags,
|
|||
GfxResourceID texId = NULL;
|
||||
_glGenTextures(1, (GLuint*)&texId);
|
||||
_glBindTexture(GL_TEXTURE_2D, ptr_to_uint(texId));
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, (flags & TEXTURE_FLAG_BILINEAR) ? GL_LINEAR : GL_NEAREST);
|
||||
_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, (flags & TEXTURE_FLAG_BILINEAR) ? GL_LINEAR : GL_NEAREST);
|
||||
|
||||
if (mipmaps) {
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
|
||||
_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
|
||||
if (customMipmapsLevels) {
|
||||
int lvls = CalcMipmapsLevels(bmp->width, bmp->height);
|
||||
glTexParameteri(GL_TEXTURE_2D, _GL_TEXTURE_MAX_LEVEL, lvls);
|
||||
_glTexParameteri(GL_TEXTURE_2D, _GL_TEXTURE_MAX_LEVEL, lvls);
|
||||
}
|
||||
} else {
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, (flags & TEXTURE_FLAG_BILINEAR) ? GL_LINEAR : GL_NEAREST);
|
||||
_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, (flags & TEXTURE_FLAG_BILINEAR) ? GL_LINEAR : GL_NEAREST);
|
||||
}
|
||||
|
||||
if (bmp->width == rowWidth) {
|
||||
|
@ -170,13 +172,19 @@ void Gfx_DisableMipmaps(void) { }
|
|||
*-----------------------------------------------------State management----------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
static PackedCol gfx_clearColor;
|
||||
void Gfx_SetFaceCulling(cc_bool enabled) { gl_Toggle(GL_CULL_FACE); }
|
||||
static void SetAlphaBlend(cc_bool enabled) { gl_Toggle(GL_BLEND); }
|
||||
|
||||
void Gfx_SetFaceCulling(cc_bool enabled) {
|
||||
if (enabled) { _glEnable(GL_CULL_FACE); } else { _glDisable(GL_CULL_FACE); }
|
||||
}
|
||||
|
||||
static void SetAlphaBlend(cc_bool enabled) {
|
||||
if (enabled) { _glEnable(GL_BLEND); } else { _glDisable(GL_BLEND); }
|
||||
}
|
||||
void Gfx_SetAlphaArgBlend(cc_bool enabled) { }
|
||||
|
||||
static void GL_ClearColor(PackedCol color) {
|
||||
glClearColor(PackedCol_R(color) / 255.0f, PackedCol_G(color) / 255.0f,
|
||||
PackedCol_B(color) / 255.0f, PackedCol_A(color) / 255.0f);
|
||||
_glClearColor(PackedCol_R(color) / 255.0f, PackedCol_G(color) / 255.0f,
|
||||
PackedCol_B(color) / 255.0f, PackedCol_A(color) / 255.0f);
|
||||
}
|
||||
void Gfx_ClearColor(PackedCol color) {
|
||||
if (color == gfx_clearColor) return;
|
||||
|
@ -185,11 +193,16 @@ void Gfx_ClearColor(PackedCol color) {
|
|||
}
|
||||
|
||||
static void SetColorWrite(cc_bool r, cc_bool g, cc_bool b, cc_bool a) {
|
||||
glColorMask(r, g, b, a);
|
||||
_glColorMask(r, g, b, a);
|
||||
}
|
||||
|
||||
void Gfx_SetDepthWrite(cc_bool enabled) { glDepthMask(enabled); }
|
||||
void Gfx_SetDepthTest(cc_bool enabled) { gl_Toggle(GL_DEPTH_TEST); }
|
||||
void Gfx_SetDepthWrite(cc_bool enabled) {
|
||||
_glDepthMask(enabled);
|
||||
}
|
||||
|
||||
void Gfx_SetDepthTest(cc_bool enabled) {
|
||||
if (enabled) { _glEnable(GL_DEPTH_TEST); } else { _glDisable(GL_DEPTH_TEST); }
|
||||
}
|
||||
|
||||
|
||||
/*########################################################################################################################*
|
||||
|
@ -241,13 +254,13 @@ cc_result Gfx_TakeScreenshot(struct Stream* output) {
|
|||
cc_result res;
|
||||
GLint vp[4];
|
||||
|
||||
glGetIntegerv(GL_VIEWPORT, vp); /* { x, y, width, height } */
|
||||
_glGetIntegerv(GL_VIEWPORT, vp); /* { x, y, width, height } */
|
||||
bmp.width = vp[2];
|
||||
bmp.height = vp[3];
|
||||
|
||||
bmp.scan0 = (BitmapCol*)Mem_TryAlloc(bmp.width * bmp.height, BITMAPCOLOR_SIZE);
|
||||
if (!bmp.scan0) return ERR_OUT_OF_MEMORY;
|
||||
glReadPixels(0, 0, bmp.width, bmp.height, PIXEL_FORMAT, TRANSFER_FORMAT, bmp.scan0);
|
||||
_glReadPixels(0, 0, bmp.width, bmp.height, PIXEL_FORMAT, TRANSFER_FORMAT, bmp.scan0);
|
||||
|
||||
res = Png_Encode(&bmp, output, GL_GetRow, false, NULL);
|
||||
Mem_Free(bmp.scan0);
|
||||
|
@ -260,11 +273,11 @@ static void AppendVRAMStats(cc_string* info) {
|
|||
float total, cur;
|
||||
|
||||
/* NOTE: glGetString returns UTF8, but I just treat it as code page 437 */
|
||||
cc_string exts = String_FromReadonly((const char*)glGetString(GL_EXTENSIONS));
|
||||
cc_string exts = String_FromReadonly((const char*)_glGetString(GL_EXTENSIONS));
|
||||
if (!String_CaselessContains(&exts, &memExt)) return;
|
||||
|
||||
glGetIntegerv(0x9048, &totalKb);
|
||||
glGetIntegerv(0x9049, &curKb);
|
||||
_glGetIntegerv(0x9048, &totalKb);
|
||||
_glGetIntegerv(0x9049, &curKb);
|
||||
if (totalKb <= 0 || curKb <= 0) return;
|
||||
|
||||
total = totalKb / 1024.0f; cur = curKb / 1024.0f;
|
||||
|
@ -275,18 +288,18 @@ void Gfx_GetApiInfo(cc_string* info) {
|
|||
GLint depthBits = 0;
|
||||
int pointerSize = sizeof(void*) * 8;
|
||||
|
||||
glGetIntegerv(GL_DEPTH_BITS, &depthBits);
|
||||
_glGetIntegerv(GL_DEPTH_BITS, &depthBits);
|
||||
#if CC_GFX_BACKEND == CC_GFX_BACKEND_GL2
|
||||
String_Format1(info, "-- Using OpenGL Modern (%i bit) --\n", &pointerSize);
|
||||
#else
|
||||
String_Format1(info, "-- Using OpenGL (%i bit) --\n", &pointerSize);
|
||||
#endif
|
||||
String_Format1(info, "Vendor: %c\n", glGetString(GL_VENDOR));
|
||||
String_Format1(info, "Renderer: %c\n", glGetString(GL_RENDERER));
|
||||
String_Format1(info, "GL version: %c\n", glGetString(GL_VERSION));
|
||||
String_Format1(info, "Vendor: %c\n", _glGetString(GL_VENDOR));
|
||||
String_Format1(info, "Renderer: %c\n", _glGetString(GL_RENDERER));
|
||||
String_Format1(info, "GL version: %c\n", _glGetString(GL_VERSION));
|
||||
AppendVRAMStats(info);
|
||||
PrintMaxTextureInfo(info);
|
||||
String_Format1(info, "Depth buffer bits: %i\n", &depthBits);
|
||||
String_Format1(info, "Depth buffer bits: %i\n", &depthBits);
|
||||
GLContext_GetApiInfo(info);
|
||||
}
|
||||
|
||||
|
@ -301,7 +314,7 @@ void Gfx_ClearBuffers(GfxBuffers buffers) {
|
|||
if (buffers & GFX_BUFFER_COLOR) targets |= GL_COLOR_BUFFER_BIT;
|
||||
if (buffers & GFX_BUFFER_DEPTH) targets |= GL_DEPTH_BUFFER_BIT;
|
||||
|
||||
glClear(targets);
|
||||
_glClear(targets);
|
||||
}
|
||||
|
||||
void Gfx_EndFrame(void) {
|
||||
|
@ -330,12 +343,12 @@ void Gfx_OnWindowResize(void) {
|
|||
}
|
||||
|
||||
void Gfx_SetViewport(int x, int y, int w, int h) {
|
||||
glViewport(x, y, w, h);
|
||||
_glViewport(x, y, w, h);
|
||||
}
|
||||
|
||||
void Gfx_SetScissor(int x, int y, int w, int h) {
|
||||
cc_bool enabled = x != 0 || y != 0 || w != Game.Width || h != Game.Height;
|
||||
if (enabled) { glEnable(GL_SCISSOR_TEST); } else { glDisable(GL_SCISSOR_TEST); }
|
||||
if (enabled) { _glEnable(GL_SCISSOR_TEST); } else { _glDisable(GL_SCISSOR_TEST); }
|
||||
|
||||
glScissor(x, Game.Height - h - y, w, h);
|
||||
_glScissor(x, Game.Height - h - y, w, h);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue