glshim updated, added latest changes by ptitSeb
This commit is contained in:
@@ -28,6 +28,7 @@ LOCAL_SRC_FILES := \
|
||||
src/gl/light.c \
|
||||
src/gl/line.c \
|
||||
src/gl/list.c \
|
||||
src/gl/loader.c \
|
||||
src/gl/pixel.c \
|
||||
src/gl/raster.c \
|
||||
src/gl/render.c \
|
||||
|
||||
@@ -276,7 +276,7 @@ GLvoid *copy_gl_pointer_tex(pointer_state_t *ptr, GLsizei width, GLsizei skip, G
|
||||
GLfloat *gl_pointer_index(pointer_state_t *p, GLint index) {
|
||||
static GLfloat buf[4];
|
||||
GLsizei size = gl_sizeof(p->type);
|
||||
GLsizei stride = p->stride ? p->stride : size * p->size;
|
||||
GLsizei stride = (p->stride ? p->stride : size) * p->size;
|
||||
uintptr_t ptr = (uintptr_t)(p->pointer) + (stride * index)
|
||||
+ (uintptr_t)((state.vao->vertex)?state.vao->vertex->data:0);
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@ glstate_t state = {.color = {1.0f, 1.0f, 1.0f, 1.0f},
|
||||
};
|
||||
*/
|
||||
glstate_t state;
|
||||
void* gles = NULL;
|
||||
|
||||
GLuint readhack = 0;
|
||||
GLint readhack_x = 0;
|
||||
@@ -134,6 +133,7 @@ const GLubyte *glGetString(GLenum name) {
|
||||
"GL_ARB_texture_env_add "
|
||||
"GL_ARB_texture_border_clamp "
|
||||
"GL_ARB_point_parameters "
|
||||
"GL_EXT_texture_env_add "
|
||||
"GL_ARB_texture_env_combine "
|
||||
"GL_ARB_texture_env_crossbar "
|
||||
"GL_ARB_texture_env_dot3 "
|
||||
@@ -1323,28 +1323,25 @@ void glArrayElement(GLint i) {
|
||||
p = &state.vao->pointers.color;
|
||||
if (state.vao->color_array) {
|
||||
v = gl_pointer_index(p, i);
|
||||
GLfloat scale = gl_max_value(p->type);
|
||||
GLfloat scale = 1.0f/gl_max_value(p->type);
|
||||
// color[3] defaults to 1.0f
|
||||
if (p->size < 4)
|
||||
v[3] = 1.0f;
|
||||
|
||||
// scale color coordinates to a 0 - 1.0 range
|
||||
for (int i = 0; i < p->size; i++) {
|
||||
v[i] /= scale;
|
||||
v[i] *= scale;
|
||||
}
|
||||
glColor4fv(v);
|
||||
}
|
||||
p = &state.vao->pointers.secondary;
|
||||
if (state.vao->secondary_array) {
|
||||
v = gl_pointer_index(p, i);
|
||||
GLfloat scale = gl_max_value(p->type);
|
||||
// color[3] defaults to 0.0f
|
||||
if (p->size < 4)
|
||||
v[3] = 0.0f;
|
||||
GLfloat scale = 1.0f/gl_max_value(p->type);
|
||||
|
||||
// scale color coordinates to a 0 - 1.0 range
|
||||
for (int i = 0; i < p->size; i++) {
|
||||
v[i] /= scale;
|
||||
v[i] *= scale;
|
||||
}
|
||||
glSecondaryColor3fv(v);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
#include <dlfcn.h>
|
||||
#if defined (BCMHOST) && !defined(ANDROID)
|
||||
#include "bcm_host.h"
|
||||
#endif
|
||||
#include <GLES/gl.h>
|
||||
#include <EGL/egl.h>
|
||||
#ifdef TEXSTREAM
|
||||
@@ -87,7 +84,7 @@ typedef EGLint (*eglWaitSyncKHR_PTR)(EGLDisplay dpy, EGLSyncKHR sync, EGLint fla
|
||||
typedef EGLSurface (*eglCreateStreamProducerSurfaceKHR_PTR)(EGLDisplay dpy, EGLConfig config, EGLStreamKHR stream, const EGLint * attrib_list);
|
||||
#endif
|
||||
|
||||
// end of defintions
|
||||
#include "loader.h"
|
||||
|
||||
#define checkError(code) \
|
||||
{int error; while ((error = glGetError())) {} \
|
||||
@@ -101,99 +98,6 @@ typedef EGLSurface (*eglCreateStreamProducerSurfaceKHR_PTR)(EGLDisplay dpy, EGLC
|
||||
|
||||
#define GLdouble double
|
||||
|
||||
// will become a reference to dlopen'd gles
|
||||
extern void *gles;
|
||||
#ifdef ANDROID
|
||||
void *egl;
|
||||
#else
|
||||
extern void *egl;
|
||||
#endif
|
||||
|
||||
#ifndef EGL_LIB
|
||||
#define EGL_LIB "libEGL.so"
|
||||
#endif
|
||||
|
||||
#ifndef GLES_LIB
|
||||
#ifdef USE_ES2
|
||||
#define GLES_LIB "libGLESv2.so"
|
||||
#else
|
||||
#if defined(BCMHOST)
|
||||
#define GLES_LIB "libGLESv1_CM.so"
|
||||
#else
|
||||
#define GLES_LIB "libGLES_CM.so"
|
||||
//#define GLES_LIB "/media/SEBEXT/sources/PVRTrace/libGLES1.so"
|
||||
#endif // BCMHOST
|
||||
#endif // USE_ES2
|
||||
#endif // GLES_LIB
|
||||
|
||||
static void load_gles_lib() {
|
||||
if (gles) {
|
||||
return;
|
||||
}
|
||||
char *override = getenv("LIBGL_GLES");
|
||||
int flags = RTLD_LOCAL | RTLD_LAZY;
|
||||
if (override) {
|
||||
if ((gles = dlopen(override, flags))) {
|
||||
printf("libGL backend: %s\n", override);
|
||||
return;
|
||||
}
|
||||
}
|
||||
gles = dlopen(GLES_LIB, RTLD_LOCAL | RTLD_LAZY);
|
||||
printf("libGL backend: %s\n", GLES_LIB);
|
||||
}
|
||||
|
||||
static void load_egl_lib() {
|
||||
if (egl) {
|
||||
return;
|
||||
}
|
||||
char *override = getenv("LIBGL_EGL");
|
||||
int flags = RTLD_LOCAL | RTLD_LAZY;
|
||||
if (override) {
|
||||
if ((egl = dlopen(override, flags))) {
|
||||
printf("libGL egl backend: %s\n", override);
|
||||
return;
|
||||
}
|
||||
}
|
||||
egl = dlopen(EGL_LIB, RTLD_LOCAL | RTLD_LAZY);
|
||||
printf("libGL egl backend: %s\n", EGL_LIB);
|
||||
}
|
||||
|
||||
#define WARN_NULL(name) if (name == NULL) printf("libGL: warning, " #name " is NULL\n");
|
||||
|
||||
#define LOAD_GLES(name) \
|
||||
static name##_PTR gles_##name; \
|
||||
if (gles_##name == NULL) { \
|
||||
if (gles == NULL) { \
|
||||
load_gles_lib(); \
|
||||
WARN_NULL(gles); \
|
||||
} \
|
||||
gles_##name = (name##_PTR)dlsym(gles, #name); \
|
||||
WARN_NULL(gles_##name); \
|
||||
}
|
||||
|
||||
#define LOAD_GLES_OES(name) \
|
||||
static name##_PTR gles_##name; \
|
||||
if (gles_##name == NULL) { \
|
||||
if (gles == NULL) { \
|
||||
load_gles_lib(); \
|
||||
WARN_NULL(gles); \
|
||||
} \
|
||||
LOAD_EGL(eglGetProcAddress) \
|
||||
gles_##name = (name##_PTR)egl_eglGetProcAddress(#name"OES"); \
|
||||
WARN_NULL(gles_##name); \
|
||||
}
|
||||
|
||||
#define LOAD_EGL(name) \
|
||||
static name##_PTR egl_##name; \
|
||||
if (egl_##name == NULL) { \
|
||||
if (egl == NULL) { \
|
||||
load_egl_lib(); \
|
||||
WARN_NULL(egl); \
|
||||
} \
|
||||
egl_##name = (name##_PTR)dlsym(egl, #name); \
|
||||
WARN_NULL(egl_##name); \
|
||||
}
|
||||
|
||||
#define GL_TYPE_CASE(name, var, magic, type, code) \
|
||||
case magic: { \
|
||||
type *name = (type *)var; \
|
||||
|
||||
88
project/jni/glshim/src/gl/loader.c
Executable file
88
project/jni/glshim/src/gl/loader.c
Executable file
@@ -0,0 +1,88 @@
|
||||
#include "loader.h"
|
||||
#include <linux/limits.h>
|
||||
|
||||
void *gles = NULL, *egl = NULL, *bcm_host = NULL, *vcos = NULL;
|
||||
|
||||
static const char *path_prefix[] = {
|
||||
"",
|
||||
"/opt/vc/lib/",
|
||||
"/usr/local/lib/",
|
||||
"/usr/lib/",
|
||||
NULL,
|
||||
};
|
||||
|
||||
static const char *lib_ext[] = {
|
||||
"so",
|
||||
"so.1",
|
||||
"so.2",
|
||||
"dylib",
|
||||
"dll",
|
||||
NULL,
|
||||
};
|
||||
|
||||
static const char *gles_lib[] = {
|
||||
#ifdef USE_ES2
|
||||
"libGLESv2_CM",
|
||||
"libGLESv2",
|
||||
#else
|
||||
"libGLESv1_CM",
|
||||
"libGLES_CM",
|
||||
#endif // USE_ES2
|
||||
NULL
|
||||
};
|
||||
|
||||
static const char *egl_lib[] = {
|
||||
"libEGL",
|
||||
NULL
|
||||
};
|
||||
|
||||
void *open_lib(const char **names, const char *override) {
|
||||
void *lib = NULL;
|
||||
|
||||
char path_name[PATH_MAX + 1];
|
||||
int flags = RTLD_LOCAL | RTLD_NOW;
|
||||
#ifdef RTLD_DEEPBIND
|
||||
flags |= RTLD_DEEPBIND;
|
||||
#endif
|
||||
if (override) {
|
||||
if ((lib = dlopen(override, flags))) {
|
||||
strncpy(path_name, override, PATH_MAX);
|
||||
printf("libGL:loaded: %s\n", path_name);
|
||||
return lib;
|
||||
} else {
|
||||
printf("LIBGL_GLES override failed: %s\n", dlerror());
|
||||
}
|
||||
}
|
||||
for (int p = 0; path_prefix[p]; p++) {
|
||||
for (int i = 0; names[i]; i++) {
|
||||
for (int e = 0; lib_ext[e]; e++) {
|
||||
snprintf(path_name, PATH_MAX, "%s%s.%s", path_prefix[p], names[i], lib_ext[e]);
|
||||
if ((lib = dlopen(path_name, flags))) {
|
||||
printf("libGL:loaded: %s\n", path_name);
|
||||
return lib;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return lib;
|
||||
}
|
||||
|
||||
void load_libs() {
|
||||
static int first = 1;
|
||||
if (! first) return;
|
||||
first = 0;
|
||||
char *gles_override = getenv("LIBGL_GLES");
|
||||
// optimistically try to load the raspberry pi libs
|
||||
if (! gles_override) {
|
||||
const char *bcm_host_name[] = {"libbcm_host", NULL};
|
||||
const char *vcos_name[] = {"libvcos", NULL};
|
||||
bcm_host = open_lib(bcm_host_name, NULL);
|
||||
vcos = open_lib(vcos_name, NULL);
|
||||
}
|
||||
gles = open_lib(gles_lib, gles_override);
|
||||
WARN_NULL(gles);
|
||||
|
||||
char *egl_override = getenv("LIBGL_EGL");
|
||||
egl = open_lib(egl_lib, egl_override);
|
||||
WARN_NULL(egl);
|
||||
}
|
||||
55
project/jni/glshim/src/gl/loader.h
Executable file
55
project/jni/glshim/src/gl/loader.h
Executable file
@@ -0,0 +1,55 @@
|
||||
#ifndef LOADER_H
|
||||
#define LOADER_H
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "const.h"
|
||||
|
||||
// will become references to dlopen'd gles and egl
|
||||
extern void *gles, *egl, *bcm_host, *vcos;
|
||||
|
||||
extern void *open_lib(const char **names, const char *override);
|
||||
extern void load_libs();
|
||||
|
||||
#ifndef WARN_NULL
|
||||
#define WARN_NULL(name) if (name == NULL) printf("libGL: warning, " #name " is NULL\n");
|
||||
#endif
|
||||
|
||||
#ifndef LOAD_RAW
|
||||
#define DEFINE_RAW(lib, name) static name##_PTR lib##_##name
|
||||
#define LOAD_RAW(lib, name, ...) \
|
||||
{ \
|
||||
static bool first = true; \
|
||||
if (first) { \
|
||||
first = false; \
|
||||
if (lib == NULL) { \
|
||||
load_libs(); \
|
||||
} \
|
||||
if (lib != NULL) { \
|
||||
lib##_##name = (name##_PTR)__VA_ARGS__; \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
#endif
|
||||
|
||||
#define LOAD_LIB(lib, name) DEFINE_RAW(lib, name); LOAD_RAW(lib, name, dlsym(lib, #name))
|
||||
|
||||
#ifndef LOAD_GLES
|
||||
#define LOAD_GLES(name) \
|
||||
LOAD_GLES_SILENT(name); \
|
||||
WARN_NULL(gles_##name);
|
||||
#endif
|
||||
|
||||
#define LOAD_GLES_SILENT(name) LOAD_LIB(gles, name)
|
||||
#define LOAD_EGL(name) LOAD_LIB(egl, name)
|
||||
#define LOAD_GLES_OES(name) \
|
||||
DEFINE_RAW(gles, name); \
|
||||
{ \
|
||||
LOAD_EGL(eglGetProcAddress); \
|
||||
LOAD_RAW(gles, name, egl_eglGetProcAddress(#name"OES")); \
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -26,7 +26,7 @@ struct sockaddr_un sun;
|
||||
int sock = -2;
|
||||
#endif
|
||||
|
||||
void* egl = NULL;
|
||||
extern void* egl;
|
||||
|
||||
|
||||
int8_t CheckEGLErrors() {
|
||||
@@ -175,43 +175,6 @@ static bool g_bcmhost = false;
|
||||
static bool g_bcm_active = false;
|
||||
void (*bcm_host_init)();
|
||||
void (*bcm_host_deinit)();
|
||||
#ifdef BCMHOST
|
||||
void *bcm_host = NULL, *vcos = NULL;
|
||||
static const char *path_prefix[] = {
|
||||
"",
|
||||
"/opt/vc/lib/",
|
||||
"/usr/local/lib/",
|
||||
"/usr/lib/",
|
||||
NULL,
|
||||
};
|
||||
|
||||
static const char *lib_ext[] = {
|
||||
"so",
|
||||
"so.1",
|
||||
"so.2",
|
||||
"dylib",
|
||||
"dll",
|
||||
NULL,
|
||||
};
|
||||
void *open_lib(const char **names) {
|
||||
void *lib = NULL;
|
||||
|
||||
char path_name[PATH_MAX + 1];
|
||||
int flags = RTLD_LOCAL | RTLD_NOW;
|
||||
for (int p = 0; path_prefix[p]; p++) {
|
||||
for (int i = 0; names[i]; i++) {
|
||||
for (int e = 0; lib_ext[e]; e++) {
|
||||
snprintf(path_name, PATH_MAX, "%s%s.%s", path_prefix[p], names[i], lib_ext[e]);
|
||||
if ((lib = dlopen(path_name, flags))) {
|
||||
printf("libGL:loaded: %s\n", path_name);
|
||||
return lib;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return lib;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int swap_interval = 1;
|
||||
#ifndef ANDROID
|
||||
@@ -317,12 +280,6 @@ static void scan_env() {
|
||||
|
||||
env(LIBGL_XREFRESH, g_xrefresh, "xrefresh will be called on cleanup");
|
||||
env(LIBGL_STACKTRACE, g_stacktrace, "stacktrace will be printed on crash");
|
||||
#ifdef BCMHOST
|
||||
// Try to load RPi specifics libs
|
||||
const char *bcm_host_name[] = {"libbcm_host", NULL};
|
||||
const char *vcos_name[] = {"libvcos", NULL};
|
||||
bcm_host = open_lib(bcm_host_name);
|
||||
vcos = open_lib(vcos_name);
|
||||
// if ok, grab the init/deinit functions
|
||||
if (bcm_host) {
|
||||
bcm_host_init = dlsym(bcm_host, "bcm_host_init");
|
||||
@@ -330,7 +287,6 @@ static void scan_env() {
|
||||
if (bcm_host_init && bcm_host_deinit)
|
||||
g_bcmhost = true;
|
||||
}
|
||||
#endif
|
||||
if (g_xrefresh || g_stacktrace || g_bcmhost) {
|
||||
// TODO: a bit gross. Maybe look at this: http://stackoverflow.com/a/13290134/293352
|
||||
signal(SIGBUS, signal_handler);
|
||||
|
||||
Reference in New Issue
Block a user