mirror of
https://github.com/MobileGL-Dev/MobileGlues.git
synced 2025-09-24 03:31:43 -04:00
[Improvement|Feat] (...): Add DEBUG, GLOBAL_DEBUG. Add mesa glsl converter.
Signed-off-by: BZLZHH <admin@bzlzhh.top>
This commit is contained in:
parent
a32be48037
commit
77ce93c80a
@ -43,6 +43,7 @@ target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE ./includes)
|
|||||||
target_link_libraries(${CMAKE_PROJECT_NAME}
|
target_link_libraries(${CMAKE_PROJECT_NAME}
|
||||||
${CMAKE_SOURCE_DIR}/libraries/arm64-v8a/libglslang.a
|
${CMAKE_SOURCE_DIR}/libraries/arm64-v8a/libglslang.a
|
||||||
${CMAKE_SOURCE_DIR}/libraries/arm64-v8a/libspirv-cross-c-shared.so
|
${CMAKE_SOURCE_DIR}/libraries/arm64-v8a/libspirv-cross-c-shared.so
|
||||||
|
${CMAKE_SOURCE_DIR}/libraries/arm64-v8a/libshaderconv.so
|
||||||
android
|
android
|
||||||
log
|
log
|
||||||
)
|
)
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
#include "buffer.h"
|
#include "buffer.h"
|
||||||
|
|
||||||
|
#define DEBUG 0
|
||||||
|
|
||||||
static GLenum get_binding_query(GLenum target) {
|
static GLenum get_binding_query(GLenum target) {
|
||||||
switch(target) {
|
switch(target) {
|
||||||
case GL_ARRAY_BUFFER: return GL_ARRAY_BUFFER_BINDING;
|
case GL_ARRAY_BUFFER: return GL_ARRAY_BUFFER_BINDING;
|
||||||
@ -15,6 +17,7 @@ static GLenum get_binding_query(GLenum target) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void* glMapBuffer(GLenum target, GLenum access) {
|
void* glMapBuffer(GLenum target, GLenum access) {
|
||||||
|
LOG()
|
||||||
if (get_binding_query(target) == 0) {
|
if (get_binding_query(target) == 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -74,6 +77,7 @@ static void force_unmap(GLenum target, GLuint original_buffer) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
GLboolean glUnmapBuffer(GLenum target) {
|
GLboolean glUnmapBuffer(GLenum target) {
|
||||||
|
LOG()
|
||||||
if (g_active_mapping.mapped_ptr == NULL ||
|
if (g_active_mapping.mapped_ptr == NULL ||
|
||||||
g_active_mapping.target != target ||
|
g_active_mapping.target != target ||
|
||||||
g_active_mapping.buffer_id == 0)
|
g_active_mapping.buffer_id == 0)
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
#include "drawing.h"
|
#include "drawing.h"
|
||||||
|
|
||||||
|
#define DEBUG 0
|
||||||
|
|
||||||
void glMultiDrawElementsBaseVertex( GLenum mode, GLsizei *counts, GLenum type, const void * const *indices, GLsizei primcount, const GLint * basevertex) {
|
void glMultiDrawElementsBaseVertex( GLenum mode, GLsizei *counts, GLenum type, const void * const *indices, GLsizei primcount, const GLint * basevertex) {
|
||||||
LOG();
|
LOG();
|
||||||
for (int i = 0; i < primcount; i++) {
|
for (int i = 0; i < primcount; i++) {
|
||||||
|
@ -6,13 +6,18 @@
|
|||||||
#define MOBILEGLUES_DRAWING_H
|
#define MOBILEGLUES_DRAWING_H
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include "../gl/log.h"
|
|
||||||
#include "../gl/gl.h"
|
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <GLES3/gl32.h>
|
#include <GLES3/gl32.h>
|
||||||
|
#include "../includes.h"
|
||||||
|
#include "gl.h"
|
||||||
|
#include "glcorearb.h"
|
||||||
|
#include "log.h"
|
||||||
|
#include "loader.h"
|
||||||
|
#include "../gles/loader.h"
|
||||||
|
#include "mg.h"
|
||||||
|
|
||||||
GLAPI GLAPIENTRY void glMultiDrawElementsBaseVertex( GLenum mode, GLsizei *counts, GLenum type, const void * const *indices, GLsizei primcount, const GLint * basevertex);
|
GLAPI GLAPIENTRY void glMultiDrawElementsBaseVertex( GLenum mode, GLsizei *counts, GLenum type, const void * const *indices, GLsizei primcount, const GLint * basevertex);
|
||||||
|
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
#include "getter.h"
|
#include "getter.h"
|
||||||
|
|
||||||
|
#define DEBUG 0
|
||||||
|
|
||||||
GLAPI GLAPIENTRY void glGetIntegerv(GLenum pname, GLint *params) {
|
GLAPI GLAPIENTRY void glGetIntegerv(GLenum pname, GLint *params) {
|
||||||
LOG();
|
LOG();
|
||||||
LOG_D("glGetIntegerv, pname: %d",pname);
|
LOG_D("glGetIntegerv, pname: %d",pname);
|
||||||
|
@ -10,6 +10,8 @@
|
|||||||
#include "../gles/loader.h"
|
#include "../gles/loader.h"
|
||||||
#include "mg.h"
|
#include "mg.h"
|
||||||
|
|
||||||
|
#define DEBUG 0
|
||||||
|
|
||||||
GLAPI GLAPIENTRY GLenum glGetError() {
|
GLAPI GLAPIENTRY GLenum glGetError() {
|
||||||
LOG();
|
LOG();
|
||||||
LOAD_GLES(glGetError, GLenum);
|
LOAD_GLES(glGetError, GLenum);
|
||||||
|
@ -10,6 +10,8 @@
|
|||||||
#include "../gles/loader.h"
|
#include "../gles/loader.h"
|
||||||
#include "mg.h"
|
#include "mg.h"
|
||||||
|
|
||||||
|
#define DEBUG false
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Miscellaneous
|
* Miscellaneous
|
||||||
*/
|
*/
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
#include <regex>
|
#include <regex>
|
||||||
#include <strstream>
|
#include <strstream>
|
||||||
|
|
||||||
#define DBG(d)
|
char* (*MesaConvertShader)(const char *src, unsigned int type, unsigned int glsl, unsigned int essl);
|
||||||
|
|
||||||
typedef std::vector<uint32_t> Spirv;
|
typedef std::vector<uint32_t> Spirv;
|
||||||
|
|
||||||
@ -311,7 +311,7 @@ std::string addPrecisionToSampler2DShadow(const std::string& glslCode) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* GLSLtoGLSLES(char* glsl_code, GLenum glsl_type, uint essl_version) {
|
char* GLSLtoGLSLES_2(char* glsl_code, GLenum glsl_type, uint essl_version) {
|
||||||
glslang::InitializeProcess();
|
glslang::InitializeProcess();
|
||||||
EShLanguage shader_language;
|
EShLanguage shader_language;
|
||||||
switch (glsl_type) {
|
switch (glsl_type) {
|
||||||
@ -343,7 +343,7 @@ char* GLSLtoGLSLES(char* glsl_code, GLenum glsl_type, uint essl_version) {
|
|||||||
std::strcpy(shader_source, shader_str.c_str());
|
std::strcpy(shader_source, shader_str.c_str());
|
||||||
|
|
||||||
}
|
}
|
||||||
DBG(SHUT_LOGD("GLSL version: %d",glsl_version);)
|
LOG_D("GLSL version: %d",glsl_version);
|
||||||
|
|
||||||
shader.setStrings(&shader_source, 1);
|
shader.setStrings(&shader_source, 1);
|
||||||
|
|
||||||
@ -360,7 +360,7 @@ char* GLSLtoGLSLES(char* glsl_code, GLenum glsl_type, uint essl_version) {
|
|||||||
LOG_D("GLSL Compiling ERROR: \n%s",shader.getInfoLog());
|
LOG_D("GLSL Compiling ERROR: \n%s",shader.getInfoLog());
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
DBG(SHUT_LOGD("GLSL Compiled.");)
|
LOG_D("GLSL Compiled.");
|
||||||
|
|
||||||
glslang::TProgram program;
|
glslang::TProgram program;
|
||||||
program.addShader(&shader);
|
program.addShader(&shader);
|
||||||
@ -369,7 +369,7 @@ char* GLSLtoGLSLES(char* glsl_code, GLenum glsl_type, uint essl_version) {
|
|||||||
LOG_D("Shader Linking ERROR: %s",program.getInfoLog());
|
LOG_D("Shader Linking ERROR: %s",program.getInfoLog());
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
DBG(SHUT_LOGD("Shader Linked." );)
|
LOG_D("Shader Linked." );
|
||||||
std::vector<unsigned int> spirv_code;
|
std::vector<unsigned int> spirv_code;
|
||||||
glslang::SpvOptions spvOptions;
|
glslang::SpvOptions spvOptions;
|
||||||
spvOptions.disableOptimizer = true;
|
spvOptions.disableOptimizer = true;
|
||||||
@ -395,14 +395,6 @@ char* GLSLtoGLSLES(char* glsl_code, GLenum glsl_type, uint essl_version) {
|
|||||||
spvc_context_create_compiler(context, SPVC_BACKEND_GLSL, ir, SPVC_CAPTURE_MODE_TAKE_OWNERSHIP, &compiler_glsl);
|
spvc_context_create_compiler(context, SPVC_BACKEND_GLSL, ir, SPVC_CAPTURE_MODE_TAKE_OWNERSHIP, &compiler_glsl);
|
||||||
spvc_compiler_create_shader_resources(compiler_glsl, &resources);
|
spvc_compiler_create_shader_resources(compiler_glsl, &resources);
|
||||||
spvc_resources_get_resource_list_for_type(resources, SPVC_RESOURCE_TYPE_UNIFORM_BUFFER, &list, &count);
|
spvc_resources_get_resource_list_for_type(resources, SPVC_RESOURCE_TYPE_UNIFORM_BUFFER, &list, &count);
|
||||||
DBG(for (i = 0; i < count; i++)
|
|
||||||
{
|
|
||||||
SHUT_LOGD("ID: %u, BaseTypeID: %u, TypeID: %u, Name: %s\n", list[i].id, list[i].base_type_id, list[i].type_id,
|
|
||||||
list[i].name);
|
|
||||||
SHUT_LOGD(" Set: %u, Binding: %u\n",
|
|
||||||
spvc_compiler_get_decoration(compiler_glsl, list[i].id, SpvDecorationDescriptorSet),
|
|
||||||
spvc_compiler_get_decoration(compiler_glsl, list[i].id, SpvDecorationBinding));
|
|
||||||
})
|
|
||||||
spvc_compiler_create_compiler_options(compiler_glsl, &options);
|
spvc_compiler_create_compiler_options(compiler_glsl, &options);
|
||||||
spvc_compiler_options_set_uint(options, SPVC_COMPILER_OPTION_GLSL_VERSION, essl_version >= 300 ? essl_version : 300);
|
spvc_compiler_options_set_uint(options, SPVC_COMPILER_OPTION_GLSL_VERSION, essl_version >= 300 ? essl_version : 300);
|
||||||
spvc_compiler_options_set_bool(options, SPVC_COMPILER_OPTION_GLSL_ES, SPVC_TRUE);
|
spvc_compiler_options_set_bool(options, SPVC_COMPILER_OPTION_GLSL_ES, SPVC_TRUE);
|
||||||
@ -419,9 +411,20 @@ char* GLSLtoGLSLES(char* glsl_code, GLenum glsl_type, uint essl_version) {
|
|||||||
char* result_essl = new char[essl.length() + 1];
|
char* result_essl = new char[essl.length() + 1];
|
||||||
std::strcpy(result_essl, essl.c_str());
|
std::strcpy(result_essl, essl.c_str());
|
||||||
|
|
||||||
DBG(SHUT_LOGD("GLSL to GLSL ES Complete: \n%s",result_essl))
|
LOG_D("Originally GLSL to GLSL ES Complete: \n%s",result_essl)
|
||||||
|
|
||||||
free(shader_source);
|
free(shader_source);
|
||||||
glslang::FinalizeProcess();
|
glslang::FinalizeProcess();
|
||||||
return result_essl;
|
return result_essl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char * GLSLtoGLSLES_1(char* glsl_code, GLenum glsl_type) {
|
||||||
|
LOG_D("input shader:\n%s\n", glsl_code)
|
||||||
|
LOG_D("use plus.\n")
|
||||||
|
//PreConvert();
|
||||||
|
char * result = MesaConvertShader(glsl_code, glsl_type == GL_VERTEX_SHADER ? 35633 : 35632, 460LL, 320);
|
||||||
|
LOG_D("result shader:\n%s\n", result)
|
||||||
|
char * ret = (char*)malloc(sizeof(char) * strlen(result) + 1);
|
||||||
|
strcpy(ret, result);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
@ -12,7 +12,8 @@
|
|||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
__attribute__((visibility("default"))) extern char *GLSLtoGLSLES(char *glsl_code, GLenum glsl_type, uint essl_version);
|
__attribute__((visibility("default"))) extern char *GLSLtoGLSLES_1(char *glsl_code, GLenum glsl_type);
|
||||||
|
__attribute__((visibility("default"))) extern char *GLSLtoGLSLES_2(char *glsl_code, GLenum glsl_type, uint essl_version);
|
||||||
__attribute__((visibility("default"))) extern int getGLSLVersion(const char* glsl_code);
|
__attribute__((visibility("default"))) extern int getGLSLVersion(const char* glsl_code);
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@ -4,21 +4,14 @@
|
|||||||
|
|
||||||
#ifndef MOBILEGLUES_LOG_H
|
#ifndef MOBILEGLUES_LOG_H
|
||||||
|
|
||||||
//#define DEBUG
|
#define GLOBAL_DEBUG 0
|
||||||
|
|
||||||
|
#define LOG() if(DEBUG||GLOBAL_DEBUG) __android_log_print(ANDROID_LOG_DEBUG, RENDERERNAME, "Use function: %s", __FUNCTION__);
|
||||||
|
#define LOG_D(...) if(DEBUG||GLOBAL_DEBUG) __android_log_print(ANDROID_LOG_DEBUG, RENDERERNAME, __VA_ARGS__);
|
||||||
|
#define LOG_W(...) if(DEBUG||GLOBAL_DEBUG) __android_log_print(ANDROID_LOG_WARN, RENDERERNAME, __VA_ARGS__);
|
||||||
|
#define LOG_E(...) if(DEBUG||GLOBAL_DEBUG) __android_log_print(ANDROID_LOG_ERROR, RENDERERNAME, __VA_ARGS__);
|
||||||
|
#define LOG_F(...) if(DEBUG||GLOBAL_DEBUG) __android_log_print(ANDROID_LOG_FATAL, RENDERERNAME, __VA_ARGS__);
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
#define LOG() __android_log_print(ANDROID_LOG_DEBUG, RENDERERNAME, "Use function: %s", __FUNCTION__);
|
|
||||||
#define LOG_D(...) __android_log_print(ANDROID_LOG_DEBUG, RENDERERNAME, __VA_ARGS__);
|
|
||||||
#define LOG_W(...) __android_log_print(ANDROID_LOG_WARN, RENDERERNAME, __VA_ARGS__);
|
|
||||||
#define LOG_E(...) __android_log_print(ANDROID_LOG_ERROR, RENDERERNAME, __VA_ARGS__);
|
|
||||||
#define LOG_F(...) __android_log_print(ANDROID_LOG_FATAL, RENDERERNAME, __VA_ARGS__);
|
|
||||||
#else
|
|
||||||
#define LOG() {}
|
|
||||||
#define LOG_D(...) {}
|
|
||||||
#define LOG_W(...) {}
|
|
||||||
#define LOG_E(...) {}
|
|
||||||
#define LOG_F(...) {}
|
|
||||||
#endif
|
|
||||||
#define LOG_V(...) __android_log_print(ANDROID_LOG_VERBOSE, RENDERERNAME, __VA_ARGS__);
|
#define LOG_V(...) __android_log_print(ANDROID_LOG_VERBOSE, RENDERERNAME, __VA_ARGS__);
|
||||||
#define LOG_I(...) __android_log_print(ANDROID_LOG_INFO, RENDERERNAME, __VA_ARGS__);
|
#define LOG_I(...) __android_log_print(ANDROID_LOG_INFO, RENDERERNAME, __VA_ARGS__);
|
||||||
|
|
||||||
|
@ -4,9 +4,15 @@
|
|||||||
|
|
||||||
#include "mg.h"
|
#include "mg.h"
|
||||||
|
|
||||||
|
#define DEBUG 0
|
||||||
|
|
||||||
hard_ext_t hard_ext;
|
hard_ext_t hard_ext;
|
||||||
gl_state_t gl_state;
|
gl_state_t gl_state;
|
||||||
|
|
||||||
|
FUNC_GL_STATE_SIZEI(proxy_width)
|
||||||
|
FUNC_GL_STATE_SIZEI(proxy_height)
|
||||||
|
FUNC_GL_STATE_ENUM(proxy_intformat)
|
||||||
|
|
||||||
GLenum pname_convert(GLenum pname){
|
GLenum pname_convert(GLenum pname){
|
||||||
switch (pname) {
|
switch (pname) {
|
||||||
//useless now
|
//useless now
|
||||||
|
@ -41,9 +41,6 @@ struct gl_state_s {
|
|||||||
};
|
};
|
||||||
typedef struct gl_state_s* gl_state_t;
|
typedef struct gl_state_s* gl_state_t;
|
||||||
extern gl_state_t gl_state;
|
extern gl_state_t gl_state;
|
||||||
FUNC_GL_STATE_SIZEI(proxy_width)
|
|
||||||
FUNC_GL_STATE_SIZEI(proxy_height)
|
|
||||||
FUNC_GL_STATE_ENUM(proxy_intformat)
|
|
||||||
|
|
||||||
GLenum pname_convert(GLenum pname);
|
GLenum pname_convert(GLenum pname);
|
||||||
GLenum map_tex_target(GLenum target);
|
GLenum map_tex_target(GLenum target);
|
||||||
|
@ -14,6 +14,8 @@
|
|||||||
#include "../includes.h"
|
#include "../includes.h"
|
||||||
#include "glsl/glsl_for_es.h"
|
#include "glsl/glsl_for_es.h"
|
||||||
|
|
||||||
|
#define DEBUG 0
|
||||||
|
|
||||||
bool can_run_essl3(int esversion, const char *glsl) {
|
bool can_run_essl3(int esversion, const char *glsl) {
|
||||||
int glsl_version;
|
int glsl_version;
|
||||||
|
|
||||||
@ -73,12 +75,7 @@ void glShaderSource(GLuint shader, GLsizei count, const GLchar *const* string, c
|
|||||||
LOG_D("%s", source);
|
LOG_D("%s", source);
|
||||||
GLint shaderType;
|
GLint shaderType;
|
||||||
glGetShaderiv(shader, GL_SHADER_TYPE, &shaderType);
|
glGetShaderiv(shader, GL_SHADER_TYPE, &shaderType);
|
||||||
if(glsl_version < 140) {
|
converted = glsl_version<140?GLSLtoGLSLES_1(source, shaderType):GLSLtoGLSLES_2(source,shaderType,320);
|
||||||
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
converted = GLSLtoGLSLES(source, shaderType, 320);
|
|
||||||
}
|
|
||||||
LOG_D("\n[INFO] [Shader] Converted Shader source: \n%s", converted);
|
LOG_D("\n[INFO] [Shader] Converted Shader source: \n%s", converted);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,6 +17,8 @@
|
|||||||
#include "glsl/glsl_for_es.h"
|
#include "glsl/glsl_for_es.h"
|
||||||
#include "mg.h"
|
#include "mg.h"
|
||||||
|
|
||||||
|
#define DEBUG 0
|
||||||
|
|
||||||
int nlevel(int size, int level) {
|
int nlevel(int size, int level) {
|
||||||
if(size) {
|
if(size) {
|
||||||
size>>=level;
|
size>>=level;
|
||||||
|
@ -15,6 +15,8 @@
|
|||||||
#include "../gl/mg.h"
|
#include "../gl/mg.h"
|
||||||
#include "../gl/buffer.h"
|
#include "../gl/buffer.h"
|
||||||
|
|
||||||
|
#define DEBUG 0
|
||||||
|
|
||||||
void *gles = NULL, *egl = NULL;
|
void *gles = NULL, *egl = NULL;
|
||||||
|
|
||||||
static const char *path_prefix[] = {
|
static const char *path_prefix[] = {
|
||||||
|
@ -12,7 +12,10 @@
|
|||||||
#include "../gl/log.h"
|
#include "../gl/log.h"
|
||||||
#include "../gl/envvars.h"
|
#include "../gl/envvars.h"
|
||||||
|
|
||||||
|
#define DEBUG 0
|
||||||
|
|
||||||
void *glXGetProcAddress(const char *name) {
|
void *glXGetProcAddress(const char *name) {
|
||||||
|
LOG()
|
||||||
void* proc = dlsym(RTLD_DEFAULT, (const char*)name);
|
void* proc = dlsym(RTLD_DEFAULT, (const char*)name);
|
||||||
|
|
||||||
if (!proc) {
|
if (!proc) {
|
||||||
@ -25,6 +28,7 @@ void *glXGetProcAddress(const char *name) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void *glXGetProcAddressARB(const char *name) {
|
void *glXGetProcAddressARB(const char *name) {
|
||||||
|
LOG()
|
||||||
void* proc = dlsym(RTLD_DEFAULT, (const char*)name);
|
void* proc = dlsym(RTLD_DEFAULT, (const char*)name);
|
||||||
|
|
||||||
if (!proc) {
|
if (!proc) {
|
||||||
|
BIN
src/main/cpp/libraries/arm64-v8a/libshaderconv.so
Normal file
BIN
src/main/cpp/libraries/arm64-v8a/libshaderconv.so
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user