mirror of https://github.com/ClassiCube/ClassiCube
OpenGL1: Try to fix on big endian systems
This commit is contained in:
parent
56c6e1aab9
commit
6a734b0d6d
|
|
@ -98,6 +98,28 @@ void Gfx_Create(void) {
|
|||
}
|
||||
|
||||
|
||||
/*########################################################################################################################*
|
||||
*-------------------------------------------------------Index buffers-----------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
/* Necessary to implement this way, so works on both little endian and big endian systems */
|
||||
typedef GfxResourceID (*GenGLBuffer)(void);
|
||||
typedef void (*DelGLBuffer)(GfxResourceID id);
|
||||
|
||||
static GfxResourceID defaultGenBuffer(void) {
|
||||
GLuint buf = 0;
|
||||
_glGenBuffers(1, &buf);
|
||||
return uint_to_ptr(buf);
|
||||
}
|
||||
|
||||
static void defaultDelBuffer(GfxResourceID id) {
|
||||
GLuint buf = ptr_to_uint(id);
|
||||
_glDeleteBuffers(1, &buf);
|
||||
}
|
||||
|
||||
static GenGLBuffer genBuffer = defaultGenBuffer;
|
||||
static DelGLBuffer delBuffer = defaultDelBuffer;
|
||||
|
||||
|
||||
/*########################################################################################################################*
|
||||
*-------------------------------------------------------Index buffers-----------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
|
|
@ -105,10 +127,9 @@ GfxResourceID Gfx_CreateIb2(int count, Gfx_FillIBFunc fillFunc, void* obj) {
|
|||
#ifndef GL_INDICES
|
||||
cc_uint16 gl_indices[GFX_MAX_INDICES];
|
||||
#endif
|
||||
GfxResourceID id = NULL;
|
||||
GfxResourceID id = genBuffer();
|
||||
cc_uint32 size = count * sizeof(cc_uint16);
|
||||
|
||||
_glGenBuffers(1, (GLuint*)&id);
|
||||
fillFunc(gl_indices, count, obj);
|
||||
_glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, id);
|
||||
_glBufferData(GL_ELEMENT_ARRAY_BUFFER, size, gl_indices, GL_STATIC_DRAW);
|
||||
|
|
@ -121,7 +142,7 @@ void Gfx_DeleteIb(GfxResourceID* ib) {
|
|||
GfxResourceID id = *ib;
|
||||
if (!id) return;
|
||||
|
||||
_glDeleteBuffers(1, (GLuint*)&id);
|
||||
delBuffer(id);
|
||||
*ib = 0;
|
||||
}
|
||||
|
||||
|
|
@ -130,8 +151,7 @@ void Gfx_DeleteIb(GfxResourceID* ib) {
|
|||
*------------------------------------------------------Vertex buffers-----------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
static GfxResourceID Gfx_AllocStaticVb(VertexFormat fmt, int count) {
|
||||
GfxResourceID id = NULL;
|
||||
_glGenBuffers(1, (GLuint*)&id);
|
||||
GfxResourceID id = genBuffer();
|
||||
_glBindBuffer(GL_ARRAY_BUFFER, id);
|
||||
return id;
|
||||
}
|
||||
|
|
@ -142,7 +162,7 @@ void Gfx_BindVb(GfxResourceID vb) {
|
|||
|
||||
void Gfx_DeleteVb(GfxResourceID* vb) {
|
||||
GfxResourceID id = *vb;
|
||||
if (id) _glDeleteBuffers(1, (GLuint*)&id);
|
||||
if (id) delBuffer(id);
|
||||
*vb = 0;
|
||||
}
|
||||
|
||||
|
|
@ -164,10 +184,9 @@ static cc_bool UnlockVb(GfxResourceID vb) {
|
|||
*--------------------------------------------------Dynamic vertex buffers-------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
static GfxResourceID Gfx_AllocDynamicVb(VertexFormat fmt, int maxVertices) {
|
||||
GfxResourceID id = NULL;
|
||||
GfxResourceID id = genBuffer();
|
||||
cc_uint32 size = maxVertices * strideSizes[fmt];
|
||||
|
||||
_glGenBuffers(1, (GLuint*)&id);
|
||||
_glBindBuffer(GL_ARRAY_BUFFER, id);
|
||||
_glBufferData(GL_ARRAY_BUFFER, size, NULL, GL_DYNAMIC_DRAW);
|
||||
return id;
|
||||
|
|
@ -179,7 +198,7 @@ void Gfx_BindDynamicVb(GfxResourceID vb) {
|
|||
|
||||
void Gfx_DeleteDynamicVb(GfxResourceID* vb) {
|
||||
GfxResourceID id = *vb;
|
||||
if (id) _glDeleteBuffers(1, (GLuint*)&id);
|
||||
if (id) delBuffer(id);
|
||||
*vb = 0;
|
||||
}
|
||||
|
||||
|
|
@ -482,14 +501,12 @@ static legacy_buffer* cur_ib;
|
|||
static legacy_buffer* cur_vb;
|
||||
#define legacy_GetBuffer(target) (target == GL_ELEMENT_ARRAY_BUFFER ? &cur_ib : &cur_vb);
|
||||
|
||||
static void APIENTRY legacy_genBuffer(GLsizei n, GLuint* buffer) {
|
||||
GfxResourceID* dst = (GfxResourceID*)buffer;
|
||||
*dst = Mem_TryAllocCleared(1, sizeof(legacy_buffer));
|
||||
static GfxResourceID legacy_genBuffer(void) {
|
||||
return Mem_TryAllocCleared(1, sizeof(legacy_buffer));
|
||||
}
|
||||
|
||||
static void APIENTRY legacy_deleteBuffer(GLsizei n, const GLuint* buffer) {
|
||||
GfxResourceID* dst = (GfxResourceID*)buffer;
|
||||
Mem_Free(*dst);
|
||||
static void legacy_deleteBuffer(GfxResourceID id) {
|
||||
Mem_Free(id);
|
||||
}
|
||||
|
||||
static void APIENTRY legacy_bindBuffer(GLenum target, GfxResourceID src) {
|
||||
|
|
@ -610,8 +627,8 @@ static void FallbackOpenGL(void) {
|
|||
"As such you will likely experience very poor performance");
|
||||
customMipmapsLevels = false;
|
||||
|
||||
_glGenBuffers = legacy_genBuffer;
|
||||
_glDeleteBuffers = legacy_deleteBuffer;
|
||||
genBuffer = legacy_genBuffer;
|
||||
delBuffer = legacy_deleteBuffer;
|
||||
_glBindBuffer = legacy_bindBuffer;
|
||||
_glBufferData = legacy_bufferData;
|
||||
_glBufferSubData = legacy_bufferSubData;
|
||||
|
|
|
|||
|
|
@ -549,7 +549,7 @@ static cc_result Socket_Poll(cc_socket s, int mode, cc_bool* success) {
|
|||
set1.fd_array[0] = s; set2.fd_array[0] = s;
|
||||
|
||||
/* As per https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-select */
|
||||
/* A socket will be pollable (select returns true) in following cases):
|
||||
/* A socket will be pollable (select returns true) in following cases): */
|
||||
/* - readfds: Data is available for reading, or Connection has been closed/reset/terminated. */
|
||||
/* - writefds: Non-blocking connection attempt succeeded, or data can be sent */
|
||||
/* - exceptfds: Non-blocking connection attempt failed, or OOB data is available for reading */
|
||||
|
|
|
|||
|
|
@ -743,7 +743,7 @@ static cc_result Socket_Poll(cc_socket s, int mode, cc_bool* success) {
|
|||
set1.fd_array[0] = s; set2.fd_array[0] = s;
|
||||
|
||||
/* As per https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-select */
|
||||
/* A socket will be pollable (select returns true) in following cases):
|
||||
/* A socket will be pollable (select returns true) in following cases): */
|
||||
/* - readfds: Data is available for reading, or Connection has been closed/reset/terminated. */
|
||||
/* - writefds: Non-blocking connection attempt succeeded, or data can be sent */
|
||||
/* - exceptfds: Non-blocking connection attempt failed, or OOB data is available for reading */
|
||||
|
|
|
|||
|
|
@ -526,7 +526,7 @@ static cc_result Socket_Poll(cc_socket s, int mode, cc_bool* success) {
|
|||
set1.fd_array[0] = s; set2.fd_array[0] = s;
|
||||
|
||||
/* As per https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-select */
|
||||
/* A socket will be pollable (select returns true) in following cases):
|
||||
/* A socket will be pollable (select returns true) in following cases): */
|
||||
/* - readfds: Data is available for reading, or Connection has been closed/reset/terminated. */
|
||||
/* - writefds: Non-blocking connection attempt succeeded, or data can be sent */
|
||||
/* - exceptfds: Non-blocking connection attempt failed, or OOB data is available for reading */
|
||||
|
|
|
|||
Loading…
Reference in New Issue