A boatload of stuff (to be completed)

This commit is contained in:
artdeell 2024-09-17 16:42:04 +03:00 committed by artdeell
parent 4719a7aceb
commit 065544502a
12 changed files with 3907 additions and 31 deletions

View File

@ -24,6 +24,7 @@ android {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.debug
}
}
compileOptions {

View File

@ -385,7 +385,7 @@ LOCAL_CFLAGS += -DHAVE_OPENGL_ES_2
include $(BUILD_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := tinywrapper
LOCAL_MODULE := ltw
LOCAL_SRC_FILES := \
egl.c \
proc.c \

View File

@ -19,7 +19,7 @@ void basevertex_init(context_t* context) {
es3_functions.glGenBuffers(1, &renderer->indirectRenderBuffer);
GLenum error = es3_functions.glGetError();
if(error != GL_NO_ERROR) {
printf("tinywrapper: Failed to initialize indirect buffers: %x\n", error);
printf("LTW: Failed to initialize indirect buffers: %x\n", error);
return;
}
renderer->ready = true;
@ -50,13 +50,13 @@ void glDrawElementsBaseVertex(GLenum mode,
es3_functions.glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &elementbuffer);
if(elementbuffer == 0) {
// I am not bothered enough to implement this.
printf("tinywrapper: Base vertex draws without element buffer are not supported\n");
printf("LTW: Base vertex draws without element buffer are not supported\n");
return;
}
GLint typeBytes = type_bytes(type);
uintptr_t indicesPointer = (uintptr_t)indices;
if(indicesPointer % typeBytes != 0) {
printf("tinywrapper: misaligned base vertex draw not supported\n");
printf("LTW: misaligned base vertex draw not supported\n");
}
indirect_pass_t indirect_pass;
indirect_pass.count = count;
@ -85,7 +85,7 @@ void glMultiDrawElementsBaseVertex(GLenum mode,
es3_functions.glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &elementbuffer);
if(elementbuffer == 0) {
// I am not bothered enough to implement this.
printf("tinywrapper: Base vertex draws without element buffer are not supported\n");
printf("LTW: Base vertex draws without element buffer are not supported\n");
return;
}
GLint typeBytes = type_bytes(type);
@ -93,7 +93,7 @@ void glMultiDrawElementsBaseVertex(GLenum mode,
for(GLsizei i = 0; i < drawcount; i++) {
uintptr_t indicesPointer = (uintptr_t)indices[i];
if(indicesPointer % typeBytes != 0) {
printf("tinywrapper: misaligned base vertex draw not supported (draw %i)\n", i);
printf("LTW: misaligned base vertex draw not supported (draw %i)\n", i);
return;
}
indirect_pass_t* pass = &indirect_passes[i];

View File

@ -54,6 +54,31 @@ static bool init_context(context_t* tw_context) {
static void free_context(context_t* tw_context) {
unordered_map_free(tw_context->shader_map);
}
static void find_esversion(context_t* context) {
const char* version = (const char*) es3_functions.glGetString(GL_VERSION);
const size_t len = strlen(version);
if(len < 12) goto fail;
const char* versionstart = strchr(version + 9, ' ');
int esmajor = 0, esminor = 0;
sscanf(versionstart, " %i.%i ", &esmajor, &esminor);
printf("LTW: Running on OpenGL ES %i.%i\n", esmajor, esminor);
if(esmajor == 0 && esminor == 0) return;
if(esmajor < 3) {
printf("Unsupported OpenGL ES version. This will cause you problems down the line.\n");
return;
}
if(esmajor == 3) {
context->es31 = esminor >= 1;
}else if(esmajor > 3) {
context->es31 = true;
}
return;
fail:
printf("LTW: Failed to detect GL ES version");
}
void basevertex_init(context_t* context);
void buffer_copier_init(context_t* context);
static void init_incontext(context_t* tw_context) {
@ -62,6 +87,9 @@ static void init_incontext(context_t* tw_context) {
if(tw_context->max_drawbuffers > MAX_DRAWBUFFERS) {
tw_context->max_drawbuffers = MAX_DRAWBUFFERS;
}
find_esversion(tw_context);
basevertex_init(tw_context);
buffer_copier_init(tw_context);
es3_functions.glGenBuffers(1, &tw_context->multidraw_element_buffer);

View File

@ -57,6 +57,7 @@ typedef struct {
typedef struct {
EGLContext phys_context;
bool context_rdy;
bool es31;
basevertex_renderer_t basevertex;
GLuint multidraw_element_buffer;
framebuffer_copier_t framebuffer_copier;

View File

@ -1,4 +1,6 @@
// Added manually as needed
GLESFUNC(glDrawElementsIndirect,PFNGLDRAWELEMENTSINDIRECTPROC)
GLESFUNC(glMultiDrawArraysEXT,PFNGLMULTIDRAWARRAYSEXTPROC)
GLESFUNC(glMultiDrawElementsEXT,PFNGLMULTIDRAWELEMENTSEXTPROC)
GLESFUNC(glMultiDrawElementsEXT,PFNGLMULTIDRAWELEMENTSEXTPROC)
GLESFUNC(glGetTexLevelParameteriv,PFNGLGETTEXLEVELPARAMETERIVPROC)
GLESFUNC(glGetTexLevelParameterfv,PFNGLGETTEXLEVELPARAMETERIVPROC)

View File

@ -233,11 +233,11 @@ void glGetFramebufferAttachmentParameteriv(GLenum target,
case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE:
case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING:
printf("tinywrapper: parameter %x is not implemented yet\n", pname);
printf("LTW: parameter %x is not implemented yet\n", pname);
*params = 0;
break;
default:
printf("tinywrapper: parameter %x is not supported\n", pname);
printf("LTW: parameter %x is not supported\n", pname);
*params = 0;
break;
}

View File

@ -77,6 +77,8 @@ static int inline nlevel(int size, int level) {
return size;
}
static bool trigger_texlevelparameter = false;
void glGetTexLevelParameteriv(GLenum target, GLint level, GLenum pname, GLint *params) {
if(!current_context) return;
// NSLog("glGetTexLevelParameteriv(%x, %d, %x, %p)", target, level, pname, params);
@ -93,7 +95,13 @@ void glGetTexLevelParameteriv(GLenum target, GLint level, GLenum pname, GLint *p
break;
}
} else {
printf("tinywrapper: glGetTexLevelParameteriv is not supported\n");
if(trigger_texlevelparameter) return;
if(!current_context->es31) {
printf("glGetTexLevelParameter* functions are not supported on your device");
trigger_texlevelparameter = true;
return;
}
es3_functions.glGetTexLevelParameteriv(target, level, pname, params);
}
}
@ -123,9 +131,11 @@ const GLubyte* glGetString(GLenum name) {
if(!current_context) return NULL;
switch(name) {
case GL_VERSION:
return (const GLubyte*)"3.0 tinywrapper";
return (const GLubyte*)"3.0 Large Thin Wrapper";
case GL_SHADING_LANGUAGE_VERSION:
return (const GLubyte*)"1.50 tinywrapper";
return (const GLubyte*)"4.60 LTW";
case GL_VENDOR:
return (const GLubyte*)"PojavLauncherTeam & QuestCraft Developers";
default:
return es3_functions.glGetString(name);
}

View File

@ -17,7 +17,7 @@ void buffer_copier_init(context_t* context) {
es3_functions.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
GLenum error = es3_functions.glGetError();
if(error != 0) {
printf("tinywrapper: error while initializing buffer-copier: %x\n", error);
printf("LTW: error while initializing buffer-copier: %x\n", error);
return;
}
copier->ready = true;
@ -72,7 +72,8 @@ void glGetTexImage( GLenum target,
GLenum format,
GLenum type,
void * pixels) {
printf("glGetTexImage(%x, %i, %x, %x, %p)\n", target, level, format, type, pixels);
//printf("glGetTexImage(%x, %i, %x, %x, %p)\n", target, level, format, type, pixels);
printf("LTW: glGetTexImage is not supported yet\n");
}
void glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid * data) {

View File

@ -18,12 +18,12 @@ INTERNAL eglMustCastToProperFunctionPointerType (*host_eglGetProcAddress)(const
INTERNAL es3_functions_t es3_functions;
static void error_sysegl() {
__android_log_print(ANDROID_LOG_ERROR, "TinywrapperInit", "Failed to load system EGL: %s", dlerror());
__android_log_print(ANDROID_LOG_ERROR, "LTWInit", "Failed to load system EGL: %s", dlerror());
abort();
}
static void error_init(const char* functionName) {
__android_log_print(ANDROID_LOG_ERROR, "TinywrapperInit", "Failed to load function \"%s\"", functionName);
__android_log_print(ANDROID_LOG_ERROR, "LTWInit", "Failed to load function \"%s\"", functionName);
abort();
}
@ -50,10 +50,6 @@ __attribute__((used)) eglMustCastToProperFunctionPointerType glXGetProcAddress(c
return eglGetProcAddress(procname);
}
// You must also add the stubs.c file into sources for this parameter to work.
// Do not deploy in production with this enabled.
#define USE_STUBS
#ifdef USE_STUBS
static eglMustCastToProperFunctionPointerType resolve_stub(const char* procname) {
size_t procnamelen = strlen(procname);
size_t stublen = procnamelen + 5;
@ -61,10 +57,8 @@ static eglMustCastToProperFunctionPointerType resolve_stub(const char* procname)
memcpy(stub_procname, "stub_", 5);
memcpy(stub_procname + 5, procname, procnamelen);
stub_procname[stublen] = 0;
printf("Used stub: %s\n", stub_procname);
return dlsym(NULL, stub_procname);
}
#endif
eglMustCastToProperFunctionPointerType eglGetProcAddress(const char *procname) {
// EGL functions that we implement.
@ -78,7 +72,7 @@ eglMustCastToProperFunctionPointerType eglGetProcAddress(const char *procname) {
if(strncmp(procname, "gl", 2) != 0) goto fallback;
#define GLESOVERRIDE(name) \
if(!strcmp(procname, #name)) { \
printf("Overridden: %s\n", #name); \
printf("LTW: Overridden %s\n", #name); \
return (eglMustCastToProperFunctionPointerType) name; \
}
#include "es3_overrides.h"
@ -86,8 +80,6 @@ eglMustCastToProperFunctionPointerType eglGetProcAddress(const char *procname) {
eglMustCastToProperFunctionPointerType function;
fallback:
function = host_eglGetProcAddress(procname);
#ifdef USE_STUBS
if(function == NULL) function = resolve_stub(procname);
#endif
return function;
}

View File

@ -27,7 +27,7 @@ GLuint glCreateProgram(void) {
if(phys_program == 0) return phys_program;
program_info_t *prog_info = calloc(1, sizeof(program_info_t));
if(prog_info == NULL) {
printf("tinyshdrwrp: failed to allocate program_info\n");
printf("LTWShdrWp: failed to allocate program_info\n");
abort();
}
unordered_map_put(current_context->program_map, (void*)phys_program, prog_info);
@ -82,7 +82,7 @@ void glLinkProgram(GLuint program) {
}
shader_info_t *shader = unordered_map_get(current_context->shader_map, (void*)program_info->frag_shader);
if(shader == NULL) {
printf("tinywrapper: failed to patch frag data location due to missing shader info\n");
printf("LTWShdrWp: failed to patch frag data location due to missing shader info\n");
goto fallthrough;
}
size_t nsrc_size = strlen(shader->source) + 1;
@ -103,7 +103,7 @@ void glLinkProgram(GLuint program) {
GLuint patched_shader = es3_functions.glCreateShader(GL_FRAGMENT_SHADER);
if(patched_shader == 0) {
free(new_source);
printf("tinywrapper: failed to initialize patched shader\n");
printf("LTWShdrWp: failed to initialize patched shader\n");
goto fallthrough;
}
es3_functions.glShaderSource(patched_shader, 1, &const_source, NULL);
@ -116,7 +116,7 @@ void glLinkProgram(GLuint program) {
es3_functions.glGetShaderiv(patched_shader, GL_INFO_LOG_LENGTH, &logSize);
GLchar log[logSize];
es3_functions.glGetShaderInfoLog(patched_shader, logSize, NULL, log);
printf("tinywrapper: failed to compile patched fragment shader, using default. Log:\n%s\n", log);
printf("LTWShdrWp: failed to compile patched fragment shader, using default. Log:\n%s\n", log);
goto fallthrough;
}
es3_functions.glAttachShader(program, patched_shader);
@ -133,7 +133,7 @@ GLuint glCreateShader(GLenum shaderType) {
if(phys_shader == 0) return 0;
shader_info_t* info_struct = calloc(1, sizeof(shader_info_t));
if(info_struct == NULL) {
printf("tinyshdrwrp: failed to allocate shader_info\n");
printf("LTWShdrWp: failed to allocate shader_info\n");
abort();
}
info_struct->shader_type = shaderType;
@ -154,7 +154,7 @@ void glShaderSource(GLuint shader, GLsizei count, const GLchar *const*string, co
if(!current_context) return;
shader_info_t* shader_info = unordered_map_get(current_context->shader_map, (void*)shader);
if(shader_info == NULL) {
printf("tinyshdrwrp: shader_info missing for shader %u\n", shader);
printf("LTWShdrWp: shader_info missing for shader %u\n", shader);
es3_functions.glShaderSource(shader, count, string, length);
return;
}

File diff suppressed because it is too large Load Diff