mirror of
https://github.com/RaySollium99/libpicofe.git
synced 2025-09-03 06:17:44 -04:00
make gl layer reinitializable
This commit is contained in:
parent
e3ea3015f0
commit
c722861112
3 changed files with 27 additions and 15 deletions
30
gl.c
30
gl.c
|
@ -10,10 +10,15 @@ static EGLDisplay edpy;
|
|||
static EGLSurface esfc;
|
||||
static EGLContext ectxt;
|
||||
|
||||
static GLuint texture_name;
|
||||
|
||||
/* for external flips */
|
||||
void *gl_es_display;
|
||||
void *gl_es_surface;
|
||||
|
||||
static int tex_w, tex_h;
|
||||
static void *tex_mem;
|
||||
|
||||
static int gl_have_error(const char *name)
|
||||
{
|
||||
GLenum e = glGetError();
|
||||
|
@ -34,11 +39,9 @@ static int gles_have_error(const char *name)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int gl_init(void *display, void *window, int *quirks)
|
||||
int gl_init(void *display, void *window, int *quirks, int w, int h)
|
||||
{
|
||||
EGLConfig ecfg = NULL;
|
||||
GLuint texture_name = 0;
|
||||
void *tmp_texture_mem = NULL;
|
||||
EGLint num_config;
|
||||
int retval = -1;
|
||||
int ret;
|
||||
|
@ -53,8 +56,10 @@ int gl_init(void *display, void *window, int *quirks)
|
|||
goto out;
|
||||
}
|
||||
|
||||
tmp_texture_mem = calloc(1, 1024 * 512 * 2);
|
||||
if (tmp_texture_mem == NULL) {
|
||||
for (tex_w = 1; tex_w < w; tex_w *= 2);
|
||||
for (tex_h = 1; tex_h < h; tex_h *= 2);
|
||||
tex_mem = realloc(tex_mem, tex_w * tex_h * 2);
|
||||
if (tex_mem == NULL) {
|
||||
fprintf(stderr, "OOM\n");
|
||||
goto out;
|
||||
}
|
||||
|
@ -99,12 +104,15 @@ int gl_init(void *display, void *window, int *quirks)
|
|||
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
if (texture_name)
|
||||
glDeleteTextures(1, &texture_name);
|
||||
|
||||
glGenTextures(1, &texture_name);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, texture_name);
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1024, 512, 0, GL_RGB,
|
||||
GL_UNSIGNED_SHORT_5_6_5, tmp_texture_mem);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tex_w, tex_h, 0, GL_RGB,
|
||||
GL_UNSIGNED_SHORT_5_6_5, tex_mem);
|
||||
if (gl_have_error("glTexImage2D"))
|
||||
goto out;
|
||||
|
||||
|
@ -127,7 +135,6 @@ int gl_init(void *display, void *window, int *quirks)
|
|||
gl_es_surface = (void *)esfc;
|
||||
retval = 0;
|
||||
out:
|
||||
free(tmp_texture_mem);
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
@ -156,8 +163,8 @@ int gl_flip(const void *fb, int w, int h)
|
|||
|
||||
if (fb != NULL) {
|
||||
if (w != old_w || h != old_h) {
|
||||
float f_w = (float)w / 1024.0f;
|
||||
float f_h = (float)h / 512.0f;
|
||||
float f_w = (float)w / tex_w;
|
||||
float f_h = (float)h / tex_h;
|
||||
texture[1*2 + 0] = f_w;
|
||||
texture[2*2 + 1] = f_h;
|
||||
texture[3*2 + 0] = f_w;
|
||||
|
@ -199,5 +206,8 @@ void gl_finish(void)
|
|||
gl_es_display = (void *)edpy;
|
||||
gl_es_surface = (void *)esfc;
|
||||
|
||||
if (tex_mem) free(tex_mem);
|
||||
tex_mem = NULL;
|
||||
|
||||
gl_platform_finish();
|
||||
}
|
||||
|
|
4
gl.h
4
gl.h
|
@ -3,7 +3,7 @@
|
|||
|
||||
#ifdef HAVE_GLES
|
||||
|
||||
int gl_init(void *display, void *window, int *quirks);
|
||||
int gl_init(void *display, void *window, int *quirks, int w, int h);
|
||||
void gl_announce(void);
|
||||
int gl_flip(const void *fb, int w, int h);
|
||||
void gl_finish(void);
|
||||
|
@ -14,7 +14,7 @@ extern void *gl_es_surface;
|
|||
|
||||
#else
|
||||
|
||||
static __inline int gl_init(void *display, void *window, int *quirks)
|
||||
static __inline int gl_init(void *display, void *window, int *quirks, int w, int h)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -117,7 +117,8 @@ int plat_sdl_change_video_mode(int w, int h, int force)
|
|||
}
|
||||
}
|
||||
else if (plat_target.vout_method == vout_mode_gl) {
|
||||
plat_sdl_gl_active = (gl_init(display, window, &gl_quirks) == 0);
|
||||
int sw = plat_sdl_screen->w, sh = plat_sdl_screen->h;
|
||||
plat_sdl_gl_active = (gl_init(display, window, &gl_quirks, sw, sh) == 0);
|
||||
if (!plat_sdl_gl_active) {
|
||||
fprintf(stderr, "warning: could not init GL.\n");
|
||||
plat_target.vout_method = 0;
|
||||
|
@ -185,8 +186,9 @@ void plat_sdl_event_handler(void *event_)
|
|||
}
|
||||
else if (plat_sdl_gl_active) {
|
||||
if (gl_quirks & GL_QUIRK_ACTIVATE_RECREATE) {
|
||||
int sw = plat_sdl_screen->w, sh = plat_sdl_screen->h;
|
||||
gl_finish();
|
||||
plat_sdl_gl_active = (gl_init(display, window, &gl_quirks) == 0);
|
||||
plat_sdl_gl_active = (gl_init(display, window, &gl_quirks, sw, sh) == 0);
|
||||
}
|
||||
gl_flip(NULL, 0, 0);
|
||||
}
|
||||
|
@ -311,7 +313,7 @@ int plat_sdl_init(void)
|
|||
if (env)
|
||||
try_gl = atoi(env);
|
||||
if (try_gl)
|
||||
ret = gl_init(display, window, &gl_quirks);
|
||||
ret = gl_init(display, window, &gl_quirks, g_menuscreen_w, g_menuscreen_h);
|
||||
if (ret == 0) {
|
||||
gl_announce();
|
||||
gl_works = 1;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue