This commit is contained in:
TheBrokenRail 2022-06-30 19:53:32 -04:00
parent 699d83c61b
commit e506dbb1bb
9 changed files with 272 additions and 21 deletions

View File

@ -1,7 +1,7 @@
project(media-layer-stubs) project(media-layer-stubs)
# Stubs Only Needed For ARM # Stubs Only Needed For ARM
if(MCPI_USE_GLES1_COMPATIBILITY_LAYER AND BUILD_NATIVE_COMPONENTS AND NOT MCPI_HEADLESS_MODE) if(BUILD_NATIVE_COMPONENTS AND NOT MCPI_HEADLESS_MODE)
# GLESv1_CM Compatibility Layer # GLESv1_CM Compatibility Layer
set(GLES1_LINK_MODE "SHARED") set(GLES1_LINK_MODE "SHARED")
if(MCPI_USE_MEDIA_LAYER_PROXY) if(MCPI_USE_MEDIA_LAYER_PROXY)
@ -9,10 +9,15 @@ if(MCPI_USE_GLES1_COMPATIBILITY_LAYER AND BUILD_NATIVE_COMPONENTS AND NOT MCPI_H
# (This is so it doesn't interfere with the Media Layer Proxy Server's libGLESv1_CM.so.1 symlink.) # (This is so it doesn't interfere with the Media Layer Proxy Server's libGLESv1_CM.so.1 symlink.)
set(GLES1_LINK_MODE "OBJECT") set(GLES1_LINK_MODE "OBJECT")
endif() endif()
add_library(GLESv1_CM "${GLES1_LINK_MODE}" src/compatibility-layer/state.c src/compatibility-layer/passthrough.c src/compatibility-layer/matrix.c src/compatibility-layer/draw.c) if(MCPI_USE_GLES1_COMPATIBILITY_LAYER)
set(GLES_SRC src/compatibility-layer/state.c src/compatibility-layer/passthrough.c src/compatibility-layer/matrix.c src/compatibility-layer/draw.c src/compatibility-layer/buffer.cpp)
else()
set(GLES_SRC src/passthrough.c)
endif()
add_library(GLESv1_CM "${GLES1_LINK_MODE}" ${GLES_SRC})
target_link_libraries(GLESv1_CM PRIVATE glfw PUBLIC reborn-util PRIVATE dl PRIVATE m) target_link_libraries(GLESv1_CM PRIVATE glfw PUBLIC reborn-util PRIVATE dl PRIVATE m)
# Install # Install
if(NOT MCPI_USE_MEDIA_LAYER_PROXY) if(GLES1_LINK_MODE STREQUAL "SHARED")
install(TARGETS GLESv1_CM DESTINATION "${MCPI_LIB_DIR}") install(TARGETS GLESv1_CM DESTINATION "${MCPI_LIB_DIR}")
endif() endif()
else() else()

View File

@ -0,0 +1,34 @@
#include <unordered_map>
#include <GLES/gl.h>
#include "../passthrough.h"
// Store Buffers
static std::unordered_map<GLuint, GLuint> buffers_map;
// Get Buffer
GL_FUNC(glGenBuffers, void, (GLsizei n, GLuint *buffers));
static GLuint get_real_buffer(GLuint fake_buffer) {
if (buffers_map.count(fake_buffer) > 0) {
return buffers_map[fake_buffer];
} else {
GLuint new_buffer;
real_glGenBuffers()(1, &new_buffer);
buffers_map[fake_buffer] = new_buffer;
return get_real_buffer(fake_buffer);
}
}
// Convert Fake Buffers To Real Buffers When Calling GL
GL_FUNC(glBindBuffer, void, (GLenum target, GLuint buffer));
void glBindBuffer(GLenum target, GLuint buffer) {
real_glBindBuffer()(target, get_real_buffer(buffer));
}
GL_FUNC(glDeleteBuffers, void, (GLsizei n, const GLuint *buffers));
void glDeleteBuffers(GLsizei n, const GLuint *buffers) {
for (int i = 0; i < n; i++) {
if (buffers_map.count(buffers[i]) > 0) {
real_glDeleteBuffers()(1, &buffers_map[i]);
}
}
}

View File

@ -1,5 +1,5 @@
#include "state.h" #include "state.h"
#include "passthrough.h" #include "../passthrough.h"
#include <GLES/gl.h> #include <GLES/gl.h>

View File

@ -4,7 +4,6 @@
#include <libreborn/libreborn.h> #include <libreborn/libreborn.h>
#include "state.h" #include "state.h"
#include "passthrough.h"
// Matrix Common // Matrix Common
static void matrix_copy(matrix_t *src, matrix_t *dst) { static void matrix_copy(matrix_t *src, matrix_t *dst) {

View File

@ -1,6 +1,6 @@
#include <GLES/gl.h> #include <GLES/gl.h>
#include "passthrough.h" #include "../passthrough.h"
// Simple v1.1 -> v2.0 Passthrough Functions // Simple v1.1 -> v2.0 Passthrough Functions
GL_FUNC(glLineWidth, void, (GLfloat width)); GL_FUNC(glLineWidth, void, (GLfloat width));
@ -43,10 +43,6 @@ GL_FUNC(glDepthFunc, void, (GLenum func));
void glDepthFunc(GLenum func) { void glDepthFunc(GLenum func) {
real_glDepthFunc()(func); real_glDepthFunc()(func);
} }
GL_FUNC(glBindBuffer, void, (GLenum target, GLuint buffer));
void glBindBuffer(GLenum target, GLuint buffer) {
real_glBindBuffer()(target, buffer);
}
GL_FUNC(glClearColor, void, (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)); GL_FUNC(glClearColor, void, (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha));
void glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha) { void glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha) {
real_glClearColor()(red, green, blue, alpha); real_glClearColor()(red, green, blue, alpha);
@ -61,10 +57,6 @@ void glHint(GLenum target, GLenum mode) {
real_glHint()(target, mode); real_glHint()(target, mode);
} }
} }
GL_FUNC(glDeleteBuffers, void, (GLsizei n, const GLuint *buffers));
void glDeleteBuffers(GLsizei n, const GLuint *buffers) {
real_glDeleteBuffers()(n, buffers);
}
GL_FUNC(glColorMask, void, (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)); GL_FUNC(glColorMask, void, (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha));
void glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha) { void glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha) {
real_glColorMask()(red, green, blue, alpha); real_glColorMask()(red, green, blue, alpha);

View File

@ -1,7 +1,7 @@
#include <libreborn/libreborn.h> #include <libreborn/libreborn.h>
#include "state.h" #include "state.h"
#include "passthrough.h" #include "../passthrough.h"
// GL State // GL State
gl_state_t gl_state = { gl_state_t gl_state = {

View File

@ -0,0 +1,204 @@
#include <GLES/gl.h>
#include "passthrough.h"
GL_FUNC(glFogfv, void, (GLenum pname, const GLfloat *params));
void glFogfv(GLenum pname, const GLfloat *params) {
real_glFogfv()(pname, params);
}
GL_FUNC(glVertexPointer, void, (GLint size, GLenum type, GLsizei stride, const void *pointer));
void glVertexPointer(GLint size, GLenum type, GLsizei stride, const void *pointer) {
real_glVertexPointer()(size, type, stride, pointer);
}
GL_FUNC(glLineWidth, void, (GLfloat width));
void glLineWidth(GLfloat width) {
real_glLineWidth()(width);
}
GL_FUNC(glBlendFunc, void, (GLenum sfactor, GLenum dfactor));
void glBlendFunc(GLenum sfactor, GLenum dfactor) {
real_glBlendFunc()(sfactor, dfactor);
}
GL_FUNC(glDrawArrays, void, (GLenum mode, GLint first, GLsizei count));
void glDrawArrays(GLenum mode, GLint first, GLsizei count) {
real_glDrawArrays()(mode, first, count);
}
GL_FUNC(glColor4f, void, (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha));
void glColor4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) {
real_glColor4f()(red, green, blue, alpha);
}
GL_FUNC(glClear, void, (GLbitfield mask));
void glClear(GLbitfield mask) {
real_glClear()(mask);
}
GL_FUNC(glBufferData, void, (GLenum target, GLsizeiptr size, const void *data, GLenum usage));
void glBufferData(GLenum target, GLsizeiptr size, const void *data, GLenum usage) {
real_glBufferData()(target, size, data, usage);
}
GL_FUNC(glFogx, void, (GLenum pname, GLfixed param));
void glFogx(GLenum pname, GLfixed param) {
real_glFogx()(pname, param);
}
GL_FUNC(glFogf, void, (GLenum pname, GLfloat param));
void glFogf(GLenum pname, GLfloat param) {
real_glFogf()(pname, param);
}
GL_FUNC(glMatrixMode, void, (GLenum mode));
void glMatrixMode(GLenum mode) {
real_glMatrixMode()(mode);
}
GL_FUNC(glColorPointer, void, (GLint size, GLenum type, GLsizei stride, const void *pointer));
void glColorPointer(GLint size, GLenum type, GLsizei stride, const void *pointer) {
real_glColorPointer()(size, type, stride, pointer);
}
GL_FUNC(glScissor, void, (GLint x, GLint y, GLsizei width, GLsizei height));
void glScissor(GLint x, GLint y, GLsizei width, GLsizei height) {
real_glScissor()(x, y, width, height);
}
GL_FUNC(glTexParameteri, void, (GLenum target, GLenum pname, GLint param));
void glTexParameteri(GLenum target, GLenum pname, GLint param) {
real_glTexParameteri()(target, pname, param);
}
GL_FUNC(glTexImage2D, void, (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void *pixels));
void glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void *pixels) {
real_glTexImage2D()(target, level, internalformat, width, height, border, format, type, pixels);
}
GL_FUNC(glEnable, void, (GLenum cap));
void glEnable(GLenum cap) {
real_glEnable()(cap);
}
GL_FUNC(glEnableClientState, void, (GLenum array));
void glEnableClientState(GLenum array) {
real_glEnableClientState()(array);
}
GL_FUNC(glPolygonOffset, void, (GLfloat factor, GLfloat units));
void glPolygonOffset(GLfloat factor, GLfloat units) {
real_glPolygonOffset()(factor, units);
}
GL_FUNC(glDisableClientState, void, (GLenum array));
void glDisableClientState(GLenum array) {
real_glDisableClientState()(array);
}
GL_FUNC(glDepthRangef, void, (GLclampf near, GLclampf far));
void glDepthRangef(GLclampf near, GLclampf far) {
real_glDepthRangef()(near, far);
}
GL_FUNC(glDepthFunc, void, (GLenum func));
void glDepthFunc(GLenum func) {
real_glDepthFunc()(func);
}
GL_FUNC(glBindBuffer, void, (GLenum target, GLuint buffer));
void glBindBuffer(GLenum target, GLuint buffer) {
real_glBindBuffer()(target, buffer);
}
GL_FUNC(glClearColor, void, (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha));
void glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha) {
real_glClearColor()(red, green, blue, alpha);
}
GL_FUNC(glPopMatrix, void, ());
void glPopMatrix() {
real_glPopMatrix()();
}
GL_FUNC(glLoadIdentity, void, ());
void glLoadIdentity() {
real_glLoadIdentity()();
}
GL_FUNC(glScalef, void, (GLfloat x, GLfloat y, GLfloat z));
void glScalef(GLfloat x, GLfloat y, GLfloat z) {
real_glScalef()(x, y, z);
}
GL_FUNC(glPushMatrix, void, ());
void glPushMatrix() {
real_glPushMatrix()();
}
GL_FUNC(glDepthMask, void, (GLboolean flag));
void glDepthMask(GLboolean flag) {
real_glDepthMask()(flag);
}
GL_FUNC(glHint, void, (GLenum target, GLenum mode));
void glHint(GLenum target, GLenum mode) {
real_glHint()(target, mode);
}
GL_FUNC(glMultMatrixf, void, (const GLfloat *m));
void glMultMatrixf(const GLfloat *m) {
real_glMultMatrixf()(m);
}
GL_FUNC(glTexCoordPointer, void, (GLint size, GLenum type, GLsizei stride, const void *pointer));
void glTexCoordPointer(GLint size, GLenum type, GLsizei stride, const void *pointer) {
real_glTexCoordPointer()(size, type, stride, pointer);
}
GL_FUNC(glDeleteBuffers, void, (GLsizei n, const GLuint *buffers));
void glDeleteBuffers(GLsizei n, const GLuint *buffers) {
real_glDeleteBuffers()(n, buffers);
}
GL_FUNC(glColorMask, void, (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha));
void glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha) {
real_glColorMask()(red, green, blue, alpha);
}
GL_FUNC(glTexSubImage2D, void, (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *pixels));
void glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *pixels) {
real_glTexSubImage2D()(target, level, xoffset, yoffset, width, height, format, type, pixels);
}
GL_FUNC(glGenTextures, void, (GLsizei n, GLuint *textures));
void glGenTextures(GLsizei n, GLuint *textures) {
real_glGenTextures()(n, textures);
}
GL_FUNC(glDeleteTextures, void, (GLsizei n, const GLuint *textures));
void glDeleteTextures(GLsizei n, const GLuint *textures) {
real_glDeleteTextures()(n, textures);
}
GL_FUNC(glAlphaFunc, void, (GLenum func, GLclampf ref));
void glAlphaFunc(GLenum func, GLclampf ref) {
real_glAlphaFunc()(func, ref);
}
GL_FUNC(glGetFloatv, void, (GLenum pname, GLfloat *params));
void glGetFloatv(GLenum pname, GLfloat *params) {
real_glGetFloatv()(pname, params);
}
GL_FUNC(glBindTexture, void, (GLenum target, GLuint texture));
void glBindTexture(GLenum target, GLuint texture) {
real_glBindTexture()(target, texture);
}
GL_FUNC(glTranslatef, void, (GLfloat x, GLfloat y, GLfloat z));
void glTranslatef(GLfloat x, GLfloat y, GLfloat z) {
real_glTranslatef()(x, y, z);
}
GL_FUNC(glShadeModel, void, (GLenum mode));
void glShadeModel(GLenum mode) {
real_glShadeModel()(mode);
}
GL_FUNC(glOrthof, void, (GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat near, GLfloat far));
void glOrthof(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat near, GLfloat far) {
real_glOrthof()(left, right, bottom, top, near, far);
}
GL_FUNC(glDisable, void, (GLenum cap));
void glDisable(GLenum cap) {
real_glDisable()(cap);
}
GL_FUNC(glCullFace, void, (GLenum mode));
void glCullFace(GLenum mode) {
real_glCullFace()(mode);
}
GL_FUNC(glRotatef, void, (GLfloat angle, GLfloat x, GLfloat y, GLfloat z));
void glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z) {
real_glRotatef()(angle, x, y, z);
}
GL_FUNC(glViewport, void, (GLint x, GLint y, GLsizei width, GLsizei height));
void glViewport(GLint x, GLint y, GLsizei width, GLsizei height) {
real_glViewport()(x, y, width, height);
}
GL_FUNC(glNormal3f, void, (GLfloat nx, GLfloat ny, GLfloat nz));
void glNormal3f(GLfloat nx, GLfloat ny, GLfloat nz) {
real_glNormal3f()(nx, ny, nz);
}
GL_FUNC(glIsEnabled, GLboolean, (GLenum cap));
GLboolean glIsEnabled(GLenum cap) {
return real_glIsEnabled()(cap);
}
GL_FUNC(glGetIntegerv, void, (GLenum pname, GLint *data));
void glGetIntegerv(GLenum pname, GLint *data) {
real_glGetIntegerv()(pname, data);
}
GL_FUNC(glReadPixels, void, (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void *data));
void glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void *data) {
real_glReadPixels()(x, y, width, height, format, type, data);
}

View File

@ -7,7 +7,7 @@
#define GL_FUNC(name, return_type, args) \ #define GL_FUNC(name, return_type, args) \
typedef return_type (*real_##name##_t)args; \ typedef return_type (*real_##name##_t)args; \
\ \
__attribute__((__unused__)) static real_##name##_t real_##name() { \ static real_##name##_t real_##name() { \
static real_##name##_t func = NULL; \ static real_##name##_t func = NULL; \
if (!func) { \ if (!func) { \
func = (real_##name##_t) glfwGetProcAddress(#name); \ func = (real_##name##_t) glfwGetProcAddress(#name); \

View File

@ -38,17 +38,17 @@ CALL(11, glFogfv, void, (GLenum pname, const GLfloat *params)) {
// 'pointer' Is Only Supported As An Integer, Not As An Actual Pointer // 'pointer' Is Only Supported As An Integer, Not As An Actual Pointer
#if defined(MEDIA_LAYER_PROXY_SERVER) #if defined(MEDIA_LAYER_PROXY_SERVER)
#define CALL_GL_POINTER(unique_id, name) \ #define CALL_GL_POINTER(unique_id, name) \
static int is_set_##name = 0; \
CALL(unique_id, name, void, (GLint size, GLenum type, GLsizei stride, const void *pointer)) { \ CALL(unique_id, name, void, (GLint size, GLenum type, GLsizei stride, const void *pointer)) { \
/* Check */ \ /* Check */ \
static int last_set = 0; \
static GLint last_size; \ static GLint last_size; \
static GLenum last_type; \ static GLenum last_type; \
static GLsizei last_stride; \ static GLsizei last_stride; \
static const void *last_pointer; \ static const void *last_pointer; \
if (last_set && last_size == size && last_type == type && last_stride == stride && last_pointer == pointer) { \ if (is_set_##name && last_size == size && last_type == type && last_stride == stride && last_pointer == pointer) { \
return; \ return; \
} else { \ } else { \
last_set = 1; \ is_set_##name = 1; \
last_size = size; \ last_size = size; \
last_type = type; \ last_type = type; \
last_stride = stride; \ last_stride = stride; \
@ -524,6 +524,8 @@ CALL(28, glPolygonOffset, void, (GLfloat factor, GLfloat units)) {
#endif #endif
} }
CALL_GL_POINTER(41, glTexCoordPointer)
#if defined(MEDIA_LAYER_PROXY_SERVER) #if defined(MEDIA_LAYER_PROXY_SERVER)
void glDisableClientState(GLenum array) { void glDisableClientState(GLenum array) {
// Set // Set
@ -532,6 +534,23 @@ void glDisableClientState(GLenum array) {
return; return;
} else { } else {
*enabled = 0; *enabled = 0;
// Not needed when using compatibility layer
#ifndef MCPI_USE_GLES1_COMPATIBILITY_LAYER
switch (array) {
case GL_VERTEX_ARRAY: {
is_set_glVertexPointer = 0;
break;
}
case GL_COLOR_ARRAY: {
is_set_glColorPointer = 0;
break;
}
case GL_TEXTURE_COORD_ARRAY: {
is_set_glTexCoordPointer = 0;
break;
}
}
#endif
} }
} }
#endif #endif
@ -720,8 +739,6 @@ CALL(40, glMultMatrixf, void, (const GLfloat *m)) {
#endif #endif
} }
CALL_GL_POINTER(41, glTexCoordPointer)
CALL(42, glDeleteBuffers, void, (GLsizei n, const GLuint *buffers)) { CALL(42, glDeleteBuffers, void, (GLsizei n, const GLuint *buffers)) {
#if defined(MEDIA_LAYER_PROXY_SERVER) #if defined(MEDIA_LAYER_PROXY_SERVER)
// Lock Proxy // Lock Proxy