WIP on tidying up OpenGL 1 backend a bit

This commit is contained in:
UnknownShadow200 2024-06-04 22:37:48 +10:00
parent ba68f4c625
commit 5b20773092
5 changed files with 72 additions and 69 deletions

View file

@ -88,26 +88,12 @@ export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
export DEPSDIR := $(CURDIR)/$(BUILD) export DEPSDIR := $(CURDIR)/$(BUILD)
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
export LD := $(CC)
#---------------------------------------------------------------------------------
# use CXX for linking C++ projects, CC for standard C
#---------------------------------------------------------------------------------
ifeq ($(strip $(CPPFILES)),)
#---------------------------------------------------------------------------------
export LD := $(CC)
#---------------------------------------------------------------------------------
else
#---------------------------------------------------------------------------------
export LD := $(CXX)
#---------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------
export OFILES_BIN := $(addsuffix .o,$(BINFILES)) export OFILES_BIN := $(addsuffix .o,$(BINFILES))
export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) export OFILES_SRC := $(CFILES:.c=.o) $(SFILES:.s=.o)
export OFILES := $(OFILES_BIN) $(OFILES_SRC) export OFILES := $(OFILES_BIN) $(OFILES_SRC)
export HFILES_BIN := $(addsuffix .h,$(subst .,_,$(BINFILES))) export HFILES_BIN := $(addsuffix .h,$(subst .,_,$(BINFILES)))

View file

@ -111,12 +111,10 @@ typedef cc_uintptr GLpointer;
GLAPI void APIENTRY glAlphaFunc(GLenum func, GLfloat ref); GLAPI void APIENTRY glAlphaFunc(GLenum func, GLfloat ref);
GLAPI void APIENTRY glBindTexture(GLenum target, GLuint texture); GLAPI void APIENTRY glBindTexture(GLenum target, GLuint texture);
GLAPI void APIENTRY glBlendFunc(GLenum sfactor, GLenum dfactor); GLAPI void APIENTRY glBlendFunc(GLenum sfactor, GLenum dfactor);
GLAPI void APIENTRY glCallList(GLuint list);
GLAPI void APIENTRY glClear(GLuint mask); GLAPI void APIENTRY glClear(GLuint mask);
GLAPI void APIENTRY glClearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); GLAPI void APIENTRY glClearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
GLAPI void APIENTRY glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha); GLAPI void APIENTRY glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha);
GLAPI void APIENTRY glColorPointer(GLint size, GLenum type, GLsizei stride, GLpointer pointer); GLAPI void APIENTRY glColorPointer(GLint size, GLenum type, GLsizei stride, GLpointer pointer);
GLAPI void APIENTRY glDeleteLists(GLuint list, GLsizei range);
GLAPI void APIENTRY glDeleteTextures(GLsizei n, const GLuint* textures); GLAPI void APIENTRY glDeleteTextures(GLsizei n, const GLuint* textures);
GLAPI void APIENTRY glDepthFunc(GLenum func); GLAPI void APIENTRY glDepthFunc(GLenum func);
GLAPI void APIENTRY glDepthMask(GLboolean flag); GLAPI void APIENTRY glDepthMask(GLboolean flag);
@ -131,7 +129,6 @@ GLAPI void APIENTRY glFogf(GLenum pname, GLfloat param);
GLAPI void APIENTRY glFogfv(GLenum pname, const GLfloat* params); GLAPI void APIENTRY glFogfv(GLenum pname, const GLfloat* params);
GLAPI void APIENTRY glFogi(GLenum pname, GLint param); GLAPI void APIENTRY glFogi(GLenum pname, GLint param);
GLAPI void APIENTRY glFogiv(GLenum pname, const GLint* params); GLAPI void APIENTRY glFogiv(GLenum pname, const GLint* params);
GLAPI GLuint APIENTRY glGenLists(GLsizei range);
GLAPI void APIENTRY glGenTextures(GLsizei n, GLuint* textures); GLAPI void APIENTRY glGenTextures(GLsizei n, GLuint* textures);
GLAPI GLenum APIENTRY glGetError(void); GLAPI GLenum APIENTRY glGetError(void);
GLAPI void APIENTRY glGetFloatv(GLenum pname, GLfloat* params); GLAPI void APIENTRY glGetFloatv(GLenum pname, GLfloat* params);
@ -141,7 +138,6 @@ GLAPI void APIENTRY glHint(GLenum target, GLenum mode);
GLAPI void APIENTRY glLoadIdentity(void); GLAPI void APIENTRY glLoadIdentity(void);
GLAPI void APIENTRY glLoadMatrixf(const GLfloat* m); GLAPI void APIENTRY glLoadMatrixf(const GLfloat* m);
GLAPI void APIENTRY glMatrixMode(GLenum mode); GLAPI void APIENTRY glMatrixMode(GLenum mode);
GLAPI void APIENTRY glNewList(GLuint list, GLenum mode);
GLAPI void APIENTRY glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid* pixels); GLAPI void APIENTRY glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid* pixels);
GLAPI void APIENTRY glTexCoordPointer(GLint size, GLenum type, GLsizei stride, GLpointer pointer); GLAPI void APIENTRY glTexCoordPointer(GLint size, GLenum type, GLsizei stride, GLpointer pointer);
GLAPI void APIENTRY glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid* pixels); GLAPI void APIENTRY glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid* pixels);
@ -151,8 +147,12 @@ GLAPI void APIENTRY glVertexPointer(GLint size, GLenum type, GLsizei stride, GLp
GLAPI void APIENTRY glViewport(GLint x, GLint y, GLsizei width, GLsizei height); GLAPI void APIENTRY glViewport(GLint x, GLint y, GLsizei width, GLsizei height);
/* === END OPENGL HEADERS === */ /* === END OPENGL HEADERS === */
#if defined CC_BUILD_GL11 #if defined CC_BUILD_GL11
GLAPI void APIENTRY glCallList(GLuint list);
GLAPI void APIENTRY glDeleteLists(GLuint list, GLsizei range);
GLAPI GLuint APIENTRY glGenLists(GLsizei range);
GLAPI void APIENTRY glNewList(GLuint list, GLenum mode);
static GLuint activeList; static GLuint activeList;
#define gl_DYNAMICLISTID 1234567891 #define gl_DYNAMICLISTID 1234567891
static void* dynamicListData; static void* dynamicListData;
@ -183,24 +183,31 @@ static GL_SetupVBRangeFunc gfx_setupVBRangeFunc;
/* call [glDrawElements] --> opengl32.dll thunk--> GL driver thunk --> GL driver implementation */ /* call [glDrawElements] --> opengl32.dll thunk--> GL driver thunk --> GL driver implementation */
/* call [_glDrawElements] --> GL driver thunk --> GL driver implementation */ /* call [_glDrawElements] --> GL driver thunk --> GL driver implementation */
static void (APIENTRY *_glColorPointer)(GLint size, GLenum type, GLsizei stride, GLpointer pointer); typedef void (APIENTRY *FP_glColorPointer)(GLint size, GLenum type, GLsizei stride, GLpointer pointer); static FP_glColorPointer _glColorPointer;
static void (APIENTRY *_glDrawElements)(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices); typedef void (APIENTRY *FP_glTexCoordPointer)(GLint size, GLenum type, GLsizei stride, GLpointer pointer); static FP_glTexCoordPointer _glTexCoordPointer;
static void (APIENTRY *_glTexCoordPointer)(GLint size, GLenum type, GLsizei stride, GLpointer pointer); typedef void (APIENTRY *FP_glVertexPointer)(GLint size, GLenum type, GLsizei stride, GLpointer pointer); static FP_glVertexPointer _glVertexPointer;
static void (APIENTRY *_glVertexPointer)(GLint size, GLenum type, GLsizei stride, GLpointer pointer);
typedef void (APIENTRY *FP_glDrawArrays)(GLenum mode, GLint first, GLsizei count); static FP_glDrawArrays _glDrawArrays;
typedef void (APIENTRY *FP_glDrawElements)(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices); static FP_glDrawElements _glDrawElements;
static const struct DynamicLibSym coreFuncs[] = { static const struct DynamicLibSym coreFuncs[] = {
DynamicLib_Sym2("glColorPointer", glColorPointer), DynamicLib_Sym2("glColorPointer", glColorPointer),
DynamicLib_Sym2("glTexCoordPointer", glTexCoordPointer), DynamicLib_Sym2("glDrawElements", glDrawElements), DynamicLib_Sym2("glTexCoordPointer", glTexCoordPointer),
DynamicLib_Sym2("glVertexPointer", glVertexPointer) DynamicLib_Sym2("glVertexPointer", glVertexPointer),
DynamicLib_Sym2("glDrawArrays", glDrawArrays),
DynamicLib_Sym2("glDrawElements", glDrawElements)
}; };
static void LoadCoreFuncs(void) { static void LoadCoreFuncs(void) {
GLContext_GetAll(coreFuncs, Array_Elems(coreFuncs)); GLContext_GetAll(coreFuncs, Array_Elems(coreFuncs));
} }
#else #else
#define _glColorPointer glColorPointer #define _glColorPointer glColorPointer
#define _glDrawElements glDrawElements
#define _glTexCoordPointer glTexCoordPointer #define _glTexCoordPointer glTexCoordPointer
#define _glVertexPointer glVertexPointer #define _glVertexPointer glVertexPointer
#define _glDrawArrays glDrawArrays
#define _glDrawElements glDrawElements
#endif #endif
@ -447,7 +454,7 @@ void Gfx_SetVertexFormat(VertexFormat fmt) {
void Gfx_DrawVb_Lines(int verticesCount) { void Gfx_DrawVb_Lines(int verticesCount) {
gfx_setupVBFunc(); gfx_setupVBFunc();
glDrawArrays(GL_LINES, 0, verticesCount); _glDrawArrays(GL_LINES, 0, verticesCount);
} }
void Gfx_DrawVb_IndexedTris_Range(int verticesCount, int startVertex) { void Gfx_DrawVb_IndexedTris_Range(int verticesCount, int startVertex) {
@ -625,71 +632,81 @@ static void GLBackend_Init(void) { MakeIndices(gl_indices, GFX_MAX_INDICES, NULL
#else #else
#if defined CC_BUILD_WIN #if defined CC_BUILD_WIN
/* On 32 bit windows, can replace the gl function drawing with these 1.1 fallbacks */ static FP_glDrawElements _realDrawElements;
/* (note that this only works on 32 bit system, as OpenGL IDs are 32 bit integers) */ static FP_glColorPointer _realColorPointer;
static FP_glTexCoordPointer _realTexCoordPointer;
static FP_glVertexPointer _realVertexPointer;
/* fake vertex buffer objects with client side pointers */ /* On Windows, can replace the GL function drawing with these 1.1 fallbacks */
typedef struct fake_buffer { cc_uint8* data; } fake_buffer; /* fake vertex buffer objects by using client side pointers instead */
static fake_buffer* cur_ib; typedef struct legacy_buffer { cc_uint8* data; } legacy_buffer;
static fake_buffer* cur_vb; static legacy_buffer* cur_ib;
#define fake_GetBuffer(target) (target == GL_ELEMENT_ARRAY_BUFFER ? &cur_ib : &cur_vb); static legacy_buffer* cur_vb;
#define legacy_GetBuffer(target) (target == GL_ELEMENT_ARRAY_BUFFER ? &cur_ib : &cur_vb);
static void APIENTRY fake_bindBuffer(GLenum target, GfxResourceID src) { static GfxResourceID GenLegacyBuffer(void) {
fake_buffer** buffer = fake_GetBuffer(target); return (GfxResourceID)Mem_TryAllocCleared(1, sizeof(legacy_buffer));
*buffer = (fake_buffer*)src;
} }
static GfxResourceID GenFakeBuffer(void) { static void DelLegacyBuffer(GfxResourceID id) {
return (GfxResourceID)Mem_TryAllocCleared(1, sizeof(fake_buffer));
}
static void DelFakeBuffer(GfxResourceID id) {
Mem_Free(id); Mem_Free(id);
} }
static void APIENTRY fake_bufferData(GLenum target, cc_uintptr size, const GLvoid* data, GLenum usage) { static void APIENTRY legacy_bindBuffer(GLenum target, GfxResourceID src) {
fake_buffer* buffer = *fake_GetBuffer(target); legacy_buffer** buffer = legacy_GetBuffer(target);
*buffer = (legacy_buffer*)src;
}
static void APIENTRY legacy_bufferData(GLenum target, cc_uintptr size, const GLvoid* data, GLenum usage) {
legacy_buffer* buffer = *legacy_GetBuffer(target);
Mem_Free(buffer->data); Mem_Free(buffer->data);
buffer->data = Mem_TryAlloc(size, 1); buffer->data = Mem_TryAlloc(size, 1);
if (data) Mem_Copy(buffer->data, data, size); if (data) Mem_Copy(buffer->data, data, size);
} }
static void APIENTRY fake_bufferSubData(GLenum target, cc_uintptr offset, cc_uintptr size, const GLvoid* data) {
fake_buffer* buffer = *fake_GetBuffer(target); static void APIENTRY legacy_bufferSubData(GLenum target, cc_uintptr offset, cc_uintptr size, const GLvoid* data) {
legacy_buffer* buffer = *legacy_GetBuffer(target);
Mem_Copy(buffer->data, data, size); Mem_Copy(buffer->data, data, size);
} }
/* wglGetProcAddress doesn't work with OpenGL 1.1 software rasteriser, so call GL functions directly */
static void APIENTRY fake_drawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices) { static void APIENTRY gl11_drawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices) {
glDrawElements(mode, count, type, (cc_uintptr)indices + cur_ib->data); _realDrawElements(mode, count, type, (cc_uintptr)indices + cur_ib->data);
} }
static void APIENTRY fake_colorPointer(GLint size, GLenum type, GLsizei stride, GLpointer offset) { static void APIENTRY gl11_colorPointer(GLint size, GLenum type, GLsizei stride, GLpointer offset) {
glColorPointer(size, type, stride, (cc_uintptr)cur_vb->data + offset); _realColorPointer(size, type, stride, (cc_uintptr)cur_vb->data + offset);
} }
static void APIENTRY fake_texCoordPointer(GLint size, GLenum type, GLsizei stride, GLpointer offset) { static void APIENTRY gl11_texCoordPointer(GLint size, GLenum type, GLsizei stride, GLpointer offset) {
glTexCoordPointer(size, type, stride, (cc_uintptr)cur_vb->data + offset); _realTexCoordPointer(size, type, stride, (cc_uintptr)cur_vb->data + offset);
} }
static void APIENTRY fake_vertexPointer(GLint size, GLenum type, GLsizei stride, GLpointer offset) { static void APIENTRY gl11_vertexPointer(GLint size, GLenum type, GLsizei stride, GLpointer offset) {
glVertexPointer(size, type, stride, (cc_uintptr)cur_vb->data + offset); _realVertexPointer(size, type, stride, (cc_uintptr)cur_vb->data + offset);
} }
static void OpenGL11Fallback(void) {
static void FallbackOpenGL(void) {
Window_ShowDialog("Performance warning", Window_ShowDialog("Performance warning",
"Your system only supports only OpenGL 1.1\n" \ "Your system only supports only OpenGL 1.1\n" \
"This is usually caused by graphics drivers not being installed\n\n" \ "This is usually caused by graphics drivers not being installed\n\n" \
"As such you will likely experience very poor performance"); "As such you will likely experience very poor performance");
customMipmapsLevels = false; customMipmapsLevels = false;
_glBindBuffer = fake_bindBuffer; _delBuffer = DelFakeBuffer; _delBuffer = DelLegacyBuffer;
_genBuffer = GenFakeBuffer; _glBufferData = fake_bufferData; _genBuffer = GenLegacyBuffer;
_glBufferSubData = fake_bufferSubData; _glBindBuffer = legacy_bindBuffer;
_glBufferData = legacy_bufferData;
_glBufferSubData = legacy_bufferSubData;
_glDrawElements = fake_drawElements; _glColorPointer = fake_colorPointer; _realDrawElements = _glDrawElements; _realColorPointer = _glColorPointer;
_glTexCoordPointer = fake_texCoordPointer; _glVertexPointer = fake_vertexPointer; _realTexCoordPointer = _glTexCoordPointer; _realVertexPointer = _glVertexPointer;
_glDrawElements = gl11_drawElements; _glColorPointer = gl11_colorPointer;
_glTexCoordPointer = gl11_texCoordPointer; _glVertexPointer = gl11_vertexPointer;
} }
#else #else
/* No point in even trying for other systems */ /* No point in even trying for other systems */
static void OpenGL11Fallback(void) { static void FallbackOpenGL(void) {
Logger_FailToStart("Only OpenGL 1.1 supported.\n\n" \ Logger_FailToStart("Only OpenGL 1.1 supported.\n\n" \
"Compile the game with CC_BUILD_GL11, or ask on the ClassiCube forums for it"); "Compile the game with CC_BUILD_GL11, or ask on the ClassiCube forums for it");
} }
@ -723,7 +740,7 @@ static void GLBackend_Init(void) {
} else if (String_CaselessContains(&extensions, &vboExt)) { } else if (String_CaselessContains(&extensions, &vboExt)) {
GLContext_GetAll(arbVboFuncs, Array_Elems(arbVboFuncs)); GLContext_GetAll(arbVboFuncs, Array_Elems(arbVboFuncs));
} else { } else {
OpenGL11Fallback(); FallbackOpenGL();
} }
} }
#endif #endif

View file

@ -402,7 +402,7 @@ static void DrawTriangle(Vertex* frag1, Vertex* frag2, Vertex* frag3) {
int A = PackedCol_A(fragColor); int A = PackedCol_A(fragColor);
if (gfx_alphaBlend) { if (gfx_alphaBlend) {
PackedCol dst = colorBuffer[index]; BitmapCol dst = colorBuffer[index];
int dstR = BitmapCol_R(dst); int dstR = BitmapCol_R(dst);
int dstG = BitmapCol_G(dst); int dstG = BitmapCol_G(dst);
int dstB = BitmapCol_B(dst); int dstB = BitmapCol_B(dst);

View file

@ -29,6 +29,9 @@ typedef struct _CRYPTOAPI_BLOB {
DWORD cbData; DWORD cbData;
BYTE* pbData; BYTE* pbData;
} DATA_BLOB; } DATA_BLOB;
static BOOL (WINAPI *_CryptProtectData )(DATA_BLOB* dataIn, PCWSTR dataDescr, PVOID entropy, PVOID reserved, PVOID promptStruct, DWORD flags, DATA_BLOB* dataOut);
static BOOL (WINAPI *_CryptUnprotectData)(DATA_BLOB* dataIn, PWSTR* dataDescr, PVOID entropy, PVOID reserved, PVOID promptStruct, DWORD flags, DATA_BLOB* dataOut);
/* === END wincrypt.h === */ /* === END wincrypt.h === */
static HANDLE heap; static HANDLE heap;
@ -999,8 +1002,6 @@ cc_bool Platform_DescribeError(cc_result res, cc_string* dst) {
/*########################################################################################################################* /*########################################################################################################################*
*-------------------------------------------------------Encryption--------------------------------------------------------* *-------------------------------------------------------Encryption--------------------------------------------------------*
*#########################################################################################################################*/ *#########################################################################################################################*/
static BOOL (WINAPI *_CryptProtectData )(DATA_BLOB* dataIn, PCWSTR dataDescr, PVOID entropy, PVOID reserved, PVOID promptStruct, DWORD flags, DATA_BLOB* dataOut);
static BOOL (WINAPI *_CryptUnprotectData)(DATA_BLOB* dataIn, PWSTR* dataDescr, PVOID entropy, PVOID reserved, PVOID promptStruct, DWORD flags, DATA_BLOB* dataOut);
static void LoadCryptFuncs(void) { static void LoadCryptFuncs(void) {
static const struct DynamicLibSym funcs[] = { static const struct DynamicLibSym funcs[] = {

View file

@ -738,6 +738,5 @@ void GLContext_SetFpsLimit(cc_bool vsync, float minFrameMs) {
} }
void GLContext_GetApiInfo(cc_string* info) { } void GLContext_GetApiInfo(cc_string* info) { }
#endif // CC_GFX_BACKEND == CC_GFX_BACKEND_GL && !CC_BUILD_EGL #endif // CC_GFX_BACKEND == CC_GFX_BACKEND_GL && !CC_BUILD_EGL
#endif // CC_WIN_BACKEND == CC_WIN_BACKEND_BEOS
#endif #endif