forked from enlightenment/efl
EvasGL: Fixed a few minor bugs.
- Added (w,h) <=0 dimension check for evas_gl_surface_create() - Changed evas_gl_make_current to return error when either surface or context is NULL. Semantically, this was allowed before but it was changed to reflect eglMakeCurrent behavior. - evas_gl_make_current - detached any previously attached buffers before attaching new ones to an FBO during a make_current. - Used dynamic memory for extension string allocation for safety. SVN revision: 72926
This commit is contained in:
parent
8d72033792
commit
896d489db8
|
@ -826,3 +826,9 @@
|
||||||
|
|
||||||
* Remove uselesss software DirectDraw 16 bits engine
|
* Remove uselesss software DirectDraw 16 bits engine
|
||||||
|
|
||||||
|
2012-06-27 Sung W. Park (sung_)
|
||||||
|
|
||||||
|
* Added (w, h) <= 0 check in EvasGL surface that was never handled before.
|
||||||
|
* Handled evas_gl_make_current to return error when either surface
|
||||||
|
or context is NULL. Before, when that was the case, it just did
|
||||||
|
make_current(NULL, NULL) internally.
|
||||||
|
|
|
@ -100,6 +100,12 @@ evas_gl_surface_create(Evas_GL *evas_gl, Evas_GL_Config *config, int width, int
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( (width <= 0) || (height <= 0))
|
||||||
|
{
|
||||||
|
ERR("Invalid surface dimensions: %d, %d", width, height);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
surf = calloc(1, sizeof(Evas_GL_Surface));
|
surf = calloc(1, sizeof(Evas_GL_Surface));
|
||||||
|
|
||||||
if (!surf) return NULL;
|
if (!surf) return NULL;
|
||||||
|
@ -221,10 +227,15 @@ evas_gl_make_current(Evas_GL *evas_gl, Evas_GL_Surface *surf, Evas_GL_Context *c
|
||||||
return EINA_FALSE;
|
return EINA_FALSE;
|
||||||
MAGIC_CHECK_END();
|
MAGIC_CHECK_END();
|
||||||
|
|
||||||
if ((!surf) || (!ctx))
|
if ((surf) && (ctx))
|
||||||
|
ret = (Eina_Bool)evas_gl->evas->engine.func->gl_make_current(evas_gl->evas->engine.data.output, surf->data, ctx->data);
|
||||||
|
else if ((!surf) && (!ctx))
|
||||||
ret = (Eina_Bool)evas_gl->evas->engine.func->gl_make_current(evas_gl->evas->engine.data.output, NULL, NULL);
|
ret = (Eina_Bool)evas_gl->evas->engine.func->gl_make_current(evas_gl->evas->engine.data.output, NULL, NULL);
|
||||||
else
|
else
|
||||||
ret = (Eina_Bool)evas_gl->evas->engine.func->gl_make_current(evas_gl->evas->engine.data.output, surf->data, ctx->data);
|
{
|
||||||
|
ERR("Bad match between surface: %p and context: %p", surf, ctx);
|
||||||
|
return EINA_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,7 +77,7 @@ struct _Render_Engine_GL_Surface
|
||||||
int stencil_bits;
|
int stencil_bits;
|
||||||
|
|
||||||
int direct_fb_opt;
|
int direct_fb_opt;
|
||||||
int multiample_bits;
|
int multisample_bits;
|
||||||
|
|
||||||
// Render target Texture/Buffers
|
// Render target Texture/Buffers
|
||||||
GLint rt_msaa_samples;
|
GLint rt_msaa_samples;
|
||||||
|
@ -146,8 +146,9 @@ static Render_Engine_GL_Context *current_evgl_ctx = NULL;
|
||||||
static Render_Engine *current_engine = NULL;
|
static Render_Engine *current_engine = NULL;
|
||||||
static Evas_Object *gl_direct_img_obj = NULL;
|
static Evas_Object *gl_direct_img_obj = NULL;
|
||||||
|
|
||||||
static char _gl_ext_string[1024];
|
static int _ext_initted = 0;
|
||||||
static char _evasgl_ext_string[1024];
|
static char *_gl_ext_string = NULL;
|
||||||
|
static char *_evasgl_ext_string = NULL;
|
||||||
|
|
||||||
// Resource context/surface per Thread in TLS for evasgl use
|
// Resource context/surface per Thread in TLS for evasgl use
|
||||||
static Eina_TLS resource_key;
|
static Eina_TLS resource_key;
|
||||||
|
@ -464,7 +465,6 @@ _gl_ext_sym_init(void)
|
||||||
//----------- GLES 2.0 Extensions ------------//
|
//----------- GLES 2.0 Extensions ------------//
|
||||||
// If the symbol's not found, they get set to NULL
|
// If the symbol's not found, they get set to NULL
|
||||||
// If one of the functions in the extension exists, the extension in supported
|
// If one of the functions in the extension exists, the extension in supported
|
||||||
|
|
||||||
/* GL_OES_get_program_binary */
|
/* GL_OES_get_program_binary */
|
||||||
FINDSYM(glsym_glGetProgramBinaryOES, "glGetProgramBinary", glsym_func_void);
|
FINDSYM(glsym_glGetProgramBinaryOES, "glGetProgramBinary", glsym_func_void);
|
||||||
FINDSYM(glsym_glGetProgramBinaryOES, "glGetProgramBinaryEXT", glsym_func_void);
|
FINDSYM(glsym_glGetProgramBinaryOES, "glGetProgramBinaryEXT", glsym_func_void);
|
||||||
|
@ -614,15 +614,26 @@ _gl_ext_sym_init(void)
|
||||||
static void
|
static void
|
||||||
_gl_ext_init(Render_Engine *re)
|
_gl_ext_init(Render_Engine *re)
|
||||||
{
|
{
|
||||||
int i;
|
int i, ext_len = 0;
|
||||||
const char *glexts, *evasglexts;
|
const char *glexts, *evasglexts;
|
||||||
|
|
||||||
memset(_gl_ext_string, 0, 1024);
|
|
||||||
memset(_evasgl_ext_string, 0, 1024);
|
|
||||||
|
|
||||||
// GLES 2.0 Extensions
|
// GLES 2.0 Extensions
|
||||||
glexts = (const char*)glGetString(GL_EXTENSIONS);
|
glexts = (const char*)glGetString(GL_EXTENSIONS);
|
||||||
|
|
||||||
|
ext_len = strlen(glexts);
|
||||||
|
if (!ext_len)
|
||||||
|
{
|
||||||
|
DBG("GL Get Extension string NULL: No extensions supported");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_gl_ext_string = calloc(1, sizeof(char) * ext_len * 2);
|
||||||
|
if (!_gl_ext_string)
|
||||||
|
{
|
||||||
|
ERR("Error allocating _gl_ext_string.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
DBG("--------GLES 2.0 Extensions--------");
|
DBG("--------GLES 2.0 Extensions--------");
|
||||||
for (i = 0; _gl_ext_entries[i].name != NULL; i++)
|
for (i = 0; _gl_ext_entries[i].name != NULL; i++)
|
||||||
{
|
{
|
||||||
|
@ -649,6 +660,20 @@ _gl_ext_init(Render_Engine *re)
|
||||||
evasglexts = glXQueryExtensionsString(re->info->info.display,
|
evasglexts = glXQueryExtensionsString(re->info->info.display,
|
||||||
re->info->info.screen);
|
re->info->info.screen);
|
||||||
#endif
|
#endif
|
||||||
|
ext_len = strlen(evasglexts);
|
||||||
|
|
||||||
|
if (!ext_len)
|
||||||
|
{
|
||||||
|
DBG("GL Get Extension string NULL: No extensions supported");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_evasgl_ext_string = calloc(1, sizeof(char) * ext_len * 2);
|
||||||
|
if (!_evasgl_ext_string)
|
||||||
|
{
|
||||||
|
ERR("Error allocating _evasgl_ext_string.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
DBG("--------EvasGL Supported Extensions----------");
|
DBG("--------EvasGL Supported Extensions----------");
|
||||||
for (i = 0; _evasgl_ext_entries[i].name != NULL; i++)
|
for (i = 0; _evasgl_ext_entries[i].name != NULL; i++)
|
||||||
|
@ -899,6 +924,19 @@ _destroy_internal_glue_resources(void *data)
|
||||||
eina_tls_free(resource_key);
|
eina_tls_free(resource_key);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Free the extension strings
|
||||||
|
if (_ext_initted)
|
||||||
|
{
|
||||||
|
if (_gl_ext_string)
|
||||||
|
free(_gl_ext_string);
|
||||||
|
if (_evasgl_ext_string)
|
||||||
|
free(_evasgl_ext_string);
|
||||||
|
|
||||||
|
_gl_ext_string = NULL;
|
||||||
|
_evasgl_ext_string = NULL;
|
||||||
|
_ext_initted = 0;
|
||||||
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1111,8 +1149,13 @@ eng_setup(Evas *e, void *in)
|
||||||
eng_window_use(re->win);
|
eng_window_use(re->win);
|
||||||
|
|
||||||
re->vsync = 0;
|
re->vsync = 0;
|
||||||
|
|
||||||
|
if (!_ext_initted)
|
||||||
|
{
|
||||||
_gl_ext_sym_init();
|
_gl_ext_sym_init();
|
||||||
_gl_ext_init(re);
|
_gl_ext_init(re);
|
||||||
|
_ext_initted = 1 ;
|
||||||
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -2874,6 +2917,9 @@ _check_gl_surface_format(GLint int_fmt, GLenum fmt, GLenum attachment, GLenum at
|
||||||
GLuint fbo, tex, rb, ds_tex;
|
GLuint fbo, tex, rb, ds_tex;
|
||||||
int w, h, fb_status;
|
int w, h, fb_status;
|
||||||
|
|
||||||
|
// Initialize Variables
|
||||||
|
fbo = tex = rb = ds_tex = 0;
|
||||||
|
|
||||||
// Width/Heith for test purposes
|
// Width/Heith for test purposes
|
||||||
w = h = 2;
|
w = h = 2;
|
||||||
|
|
||||||
|
@ -2951,7 +2997,7 @@ _check_gl_surface_format(GLint int_fmt, GLenum fmt, GLenum attachment, GLenum at
|
||||||
|
|
||||||
// Delete Created Resources
|
// Delete Created Resources
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||||
glDeleteFramebuffers(1, &fbo);
|
if (fbo) glDeleteFramebuffers(1, &fbo);
|
||||||
if (tex) glDeleteTextures(1, &tex);
|
if (tex) glDeleteTextures(1, &tex);
|
||||||
if (ds_tex) glDeleteTextures(1, &ds_tex);
|
if (ds_tex) glDeleteTextures(1, &ds_tex);
|
||||||
if (rb) glDeleteRenderbuffers(1, &rb);
|
if (rb) glDeleteRenderbuffers(1, &rb);
|
||||||
|
@ -2967,6 +3013,42 @@ _check_gl_surface_format(GLint int_fmt, GLenum fmt, GLenum attachment, GLenum at
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
_print_gl_surface_info(Render_Engine_GL_Surface *sfc, int error)
|
||||||
|
{
|
||||||
|
#define PRINT_LOG(...) \
|
||||||
|
if (error) \
|
||||||
|
ERR(__VA_ARGS__); \
|
||||||
|
else \
|
||||||
|
DBG(__VA_ARGS__);
|
||||||
|
|
||||||
|
PRINT_LOG("----------Surface Info------------");
|
||||||
|
PRINT_LOG(" [Surface] %x", (unsigned int)sfc);
|
||||||
|
PRINT_LOG(" Width: %d", sfc->w);
|
||||||
|
PRINT_LOG(" Height: %d", sfc->h);
|
||||||
|
PRINT_LOG(" Direct Surface: %x", (unsigned int)sfc->direct_sfc);
|
||||||
|
PRINT_LOG(" Current Context: %x", (unsigned int)sfc->current_ctx);
|
||||||
|
PRINT_LOG(" [-------Config-------]");
|
||||||
|
PRINT_LOG(" Depth Bits : %d", sfc->depth_bits);
|
||||||
|
PRINT_LOG(" Stencil Bits : %d", sfc->stencil_bits);
|
||||||
|
PRINT_LOG(" Direct FB Opt : %d", sfc->direct_fb_opt);
|
||||||
|
PRINT_LOG(" Multisample Bits: %d", sfc->multisample_bits);
|
||||||
|
PRINT_LOG(" MSAA Samples : %d", sfc->rt_msaa_samples);
|
||||||
|
PRINT_LOG(" [-------Internal-----]");
|
||||||
|
PRINT_LOG(" RenderTarget Texture : %d", sfc->rt_tex);
|
||||||
|
PRINT_LOG(" RenderTarget Internal Format : %x", sfc->rt_internal_fmt);
|
||||||
|
PRINT_LOG(" RenderTaret Format : %x", sfc->rt_fmt);
|
||||||
|
PRINT_LOG(" RenderBuffer Depth : %x", sfc->rb_depth);
|
||||||
|
PRINT_LOG(" RenderBuffer Depth Format : %x", sfc->rb_depth_fmt);
|
||||||
|
PRINT_LOG(" RenderBuffer Stencil : %d", sfc->rb_stencil);
|
||||||
|
PRINT_LOG(" RenderBuffer Stencil Format : %x", sfc->rb_stencil_fmt);
|
||||||
|
PRINT_LOG(" RenderBuffer Depth Stencil : %x", sfc->rb_depth_stencil);
|
||||||
|
PRINT_LOG(" RenderBuffer Depth Stencil Format: %x", sfc->rb_depth_stencil_fmt);
|
||||||
|
PRINT_LOG("--------------------------------------");
|
||||||
|
|
||||||
|
#undef PRINT_LOG
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_print_gl_surface_cap(Render_Engine *re, int error)
|
_print_gl_surface_cap(Render_Engine *re, int error)
|
||||||
{
|
{
|
||||||
|
@ -3008,7 +3090,7 @@ _set_gl_surface_cap(Render_Engine *re)
|
||||||
GLuint fbo, tex, depth, stencil;
|
GLuint fbo, tex, depth, stencil;
|
||||||
int w, h;
|
int w, h;
|
||||||
|
|
||||||
int i, ret, count;
|
int i, count;
|
||||||
|
|
||||||
if (!re) return;
|
if (!re) return;
|
||||||
if (re->gl_cap_initted) return;
|
if (re->gl_cap_initted) return;
|
||||||
|
@ -3022,7 +3104,7 @@ _set_gl_surface_cap(Render_Engine *re)
|
||||||
glGetIntegerv(GL_MAX_SAMPLES_IMG, &max_samples);
|
glGetIntegerv(GL_MAX_SAMPLES_IMG, &max_samples);
|
||||||
|
|
||||||
// Check if msaa_support is supported
|
// Check if msaa_support is supported
|
||||||
if (max_samples &&
|
if ((max_samples) &&
|
||||||
(glsym_glFramebufferTexture2DMultisample) &&
|
(glsym_glFramebufferTexture2DMultisample) &&
|
||||||
(glsym_glRenderbufferStorageMultisample))
|
(glsym_glRenderbufferStorageMultisample))
|
||||||
{
|
{
|
||||||
|
@ -3190,6 +3272,7 @@ _set_internal_config(Render_Engine *re, Render_Engine_GL_Surface *sfc, Evas_GL_C
|
||||||
}
|
}
|
||||||
case EVAS_GL_STENCIL_BIT_8:
|
case EVAS_GL_STENCIL_BIT_8:
|
||||||
if ((sfc->rb_depth_fmt == re->gl_cap.depth_24_stencil_8[0]) ||
|
if ((sfc->rb_depth_fmt == re->gl_cap.depth_24_stencil_8[0]) ||
|
||||||
|
(sfc->rb_depth_fmt == re->gl_cap.depth_24[0]) ||
|
||||||
(!(re->gl_cap.stencil_8[0]) && (re->gl_cap.depth_24_stencil_8[0])))
|
(!(re->gl_cap.stencil_8[0]) && (re->gl_cap.depth_24_stencil_8[0])))
|
||||||
{
|
{
|
||||||
sfc->rb_depth_stencil_fmt = re->gl_cap.depth_24_stencil_8[0];
|
sfc->rb_depth_stencil_fmt = re->gl_cap.depth_24_stencil_8[0];
|
||||||
|
@ -3247,10 +3330,143 @@ _set_internal_config(Render_Engine *re, Render_Engine_GL_Surface *sfc, Evas_GL_C
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static int
|
||||||
|
_attach_fbo_surface(Render_Engine *data __UNUSED__,
|
||||||
|
Render_Engine_GL_Surface *sfc,
|
||||||
|
int fbo)
|
||||||
|
{
|
||||||
|
int fb_status, curr_tex, curr_rb;
|
||||||
|
|
||||||
|
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
|
||||||
|
|
||||||
|
// Detach any previously attached buffers
|
||||||
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0);
|
||||||
|
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, 0);
|
||||||
|
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, 0);
|
||||||
|
#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
|
||||||
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, 0, 0);
|
||||||
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_TEXTURE_2D, 0, 0);
|
||||||
|
#else
|
||||||
|
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, 0);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
// Render Target Texture
|
||||||
|
if (sfc->rt_tex)
|
||||||
|
{
|
||||||
|
curr_tex = 0;
|
||||||
|
glGetIntegerv(GL_TEXTURE_BINDING_2D, &curr_tex);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, sfc->rt_tex );
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||||
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, sfc->w, sfc->h, 0,
|
||||||
|
GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, curr_tex);
|
||||||
|
|
||||||
|
// Attach texture to FBO
|
||||||
|
if (sfc->rt_msaa_samples)
|
||||||
|
glsym_glFramebufferTexture2DMultisample(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, sfc->rt_tex, 0, sfc->rt_msaa_samples);
|
||||||
|
else
|
||||||
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
|
||||||
|
GL_TEXTURE_2D, sfc->rt_tex, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Depth Stencil RenderBuffer - Attach it to FBO
|
||||||
|
if (sfc->rb_depth_stencil)
|
||||||
|
{
|
||||||
|
#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
|
||||||
|
curr_tex = 0;
|
||||||
|
glGetIntegerv(GL_TEXTURE_BINDING_2D, &curr_tex);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, sfc->rb_depth_stencil);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||||
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_STENCIL_OES, sfc->w, sfc->h,
|
||||||
|
0, GL_DEPTH_STENCIL_OES, GL_UNSIGNED_INT_24_8_OES, NULL);
|
||||||
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
|
||||||
|
GL_TEXTURE_2D, sfc->rb_depth_stencil, 0);
|
||||||
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT,
|
||||||
|
GL_TEXTURE_2D, sfc->rb_depth_stencil, 0);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, curr_tex);
|
||||||
|
|
||||||
|
#else
|
||||||
|
curr_rb = 0;
|
||||||
|
glGetIntegerv(GL_RENDERBUFFER_BINDING, &curr_rb);
|
||||||
|
glBindRenderbuffer(GL_RENDERBUFFER, sfc->rb_depth_stencil);
|
||||||
|
glRenderbufferStorage(GL_RENDERBUFFER, sfc->rb_depth_stencil_fmt,
|
||||||
|
sfc->w, sfc->h);
|
||||||
|
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT,
|
||||||
|
GL_RENDERBUFFER, sfc->rb_depth_stencil);
|
||||||
|
glBindRenderbuffer(GL_RENDERBUFFER, curr_rb);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
// Depth RenderBuffer - Attach it to FBO
|
||||||
|
if (sfc->rb_depth)
|
||||||
|
{
|
||||||
|
curr_rb = 0;
|
||||||
|
glGetIntegerv(GL_RENDERBUFFER_BINDING, &curr_rb);
|
||||||
|
|
||||||
|
glBindRenderbuffer(GL_RENDERBUFFER, sfc->rb_depth);
|
||||||
|
|
||||||
|
if (sfc->rt_msaa_samples)
|
||||||
|
glsym_glRenderbufferStorageMultisample(GL_RENDERBUFFER,
|
||||||
|
sfc->rt_msaa_samples,
|
||||||
|
sfc->rb_depth_fmt,
|
||||||
|
sfc->w, sfc->h);
|
||||||
|
else
|
||||||
|
glRenderbufferStorage(GL_RENDERBUFFER, sfc->rb_depth_fmt,
|
||||||
|
sfc->w, sfc->h);
|
||||||
|
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
|
||||||
|
GL_RENDERBUFFER, sfc->rb_depth);
|
||||||
|
glBindRenderbuffer(GL_RENDERBUFFER, curr_rb);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Stencil RenderBuffer - Attach it to FBO
|
||||||
|
if (sfc->rb_stencil)
|
||||||
|
{
|
||||||
|
curr_rb = 0;
|
||||||
|
glGetIntegerv(GL_RENDERBUFFER_BINDING, &curr_rb);
|
||||||
|
|
||||||
|
glBindRenderbuffer(GL_RENDERBUFFER, sfc->rb_stencil);
|
||||||
|
|
||||||
|
if (sfc->rt_msaa_samples)
|
||||||
|
glsym_glRenderbufferStorageMultisample(GL_RENDERBUFFER,
|
||||||
|
sfc->rt_msaa_samples,
|
||||||
|
sfc->rb_stencil_fmt,
|
||||||
|
sfc->w, sfc->h);
|
||||||
|
else
|
||||||
|
glRenderbufferStorage(GL_RENDERBUFFER, sfc->rb_stencil_fmt,
|
||||||
|
sfc->w, sfc->h);
|
||||||
|
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT,
|
||||||
|
GL_RENDERBUFFER, sfc->rb_stencil);
|
||||||
|
glBindRenderbuffer(GL_RENDERBUFFER, curr_rb);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check FBO for completeness
|
||||||
|
fb_status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
|
||||||
|
if (fb_status != GL_FRAMEBUFFER_COMPLETE)
|
||||||
|
{
|
||||||
|
ERR("FBO not complete. Error Code: %x!", fb_status);
|
||||||
|
_print_gl_surface_info(sfc, 1);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
_create_rt_buffers(Render_Engine *data __UNUSED__,
|
_create_rt_buffers(Render_Engine *data __UNUSED__,
|
||||||
Render_Engine_GL_Surface *sfc)
|
Render_Engine_GL_Surface *sfc)
|
||||||
{
|
{
|
||||||
|
int ret = 0;
|
||||||
|
GLuint fbo = 0, curr_fbo = 0;
|
||||||
|
|
||||||
|
//------------------------------------//
|
||||||
// Render Target texture
|
// Render Target texture
|
||||||
if (sfc->rt_fmt)
|
if (sfc->rt_fmt)
|
||||||
{
|
{
|
||||||
|
@ -3265,9 +3481,9 @@ _create_rt_buffers(Render_Engine *data __UNUSED__,
|
||||||
#else
|
#else
|
||||||
glGenRenderbuffers(1, &sfc->rb_depth_stencil);
|
glGenRenderbuffers(1, &sfc->rb_depth_stencil);
|
||||||
#endif
|
#endif
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
// Depth RenderBuffer - Create storage here...
|
// Depth RenderBuffer - Create storage here...
|
||||||
if (sfc->rb_depth_fmt)
|
if (sfc->rb_depth_fmt)
|
||||||
glGenRenderbuffers(1, &sfc->rb_depth);
|
glGenRenderbuffers(1, &sfc->rb_depth);
|
||||||
|
@ -3276,109 +3492,30 @@ _create_rt_buffers(Render_Engine *data __UNUSED__,
|
||||||
if (sfc->rb_stencil_fmt)
|
if (sfc->rb_stencil_fmt)
|
||||||
glGenRenderbuffers(1, &sfc->rb_stencil);
|
glGenRenderbuffers(1, &sfc->rb_stencil);
|
||||||
}
|
}
|
||||||
|
//------------------------------------//
|
||||||
|
// Try attaching the given configuration
|
||||||
|
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &curr_fbo);
|
||||||
|
glGenFramebuffers(1 ,&fbo);
|
||||||
|
|
||||||
static int
|
ret = _attach_fbo_surface(NULL, sfc, fbo);
|
||||||
_attach_fbo_surface(Render_Engine *data __UNUSED__,
|
|
||||||
Render_Engine_GL_Surface *sfc,
|
if (fbo) glDeleteFramebuffers(1, &fbo);
|
||||||
Render_Engine_GL_Context *ctx)
|
glBindFramebuffer(GL_FRAMEBUFFER, curr_fbo);
|
||||||
{
|
|
||||||
int fb_status;
|
if (!ret)
|
||||||
|
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, ctx->context_fbo);
|
|
||||||
|
|
||||||
// Render Target Texture
|
|
||||||
if (sfc->rt_tex)
|
|
||||||
{
|
|
||||||
glBindTexture(GL_TEXTURE_2D, sfc->rt_tex );
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, sfc->w, sfc->h, 0,
|
|
||||||
GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
|
||||||
|
|
||||||
if (sfc->rt_msaa_samples)
|
|
||||||
glsym_glFramebufferTexture2DMultisample(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, sfc->rt_tex, 0, sfc->rt_msaa_samples);
|
|
||||||
else
|
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
|
|
||||||
GL_TEXTURE_2D, sfc->rt_tex, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Depth Stencil RenderBuffer - Attach it to FBO
|
|
||||||
if (sfc->rb_depth_stencil)
|
|
||||||
{
|
{
|
||||||
|
if (sfc->rt_tex) glDeleteTextures(1, &sfc->rt_tex);
|
||||||
|
if (sfc->rb_depth) glDeleteRenderbuffers(1, &sfc->rb_depth);
|
||||||
|
if (sfc->rb_stencil) glDeleteRenderbuffers(1, &sfc->rb_stencil);
|
||||||
#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
|
#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
|
||||||
glBindTexture(GL_TEXTURE_2D, sfc->rb_depth_stencil);
|
if (sfc->rb_depth_stencil) glDeleteTextures(1, &sfc->rb_depth_stencil);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_STENCIL_OES, sfc->w, sfc->h,
|
|
||||||
0, GL_DEPTH_STENCIL_OES, GL_UNSIGNED_INT_24_8_OES, NULL);
|
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
|
|
||||||
GL_TEXTURE_2D, sfc->rb_depth_stencil, 0);
|
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT,
|
|
||||||
GL_TEXTURE_2D, sfc->rb_depth_stencil, 0);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
glBindRenderbuffer(GL_RENDERBUFFER, sfc->rb_depth_stencil);
|
if (sfc->rb_depth_stencil) glDeleteRenderbuffers(1, &sfc->rb_depth_stencil);
|
||||||
glRenderbufferStorage(GL_RENDERBUFFER, sfc->rb_depth_stencil_fmt,
|
|
||||||
sfc->w, sfc->h);
|
|
||||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT,
|
|
||||||
GL_RENDERBUFFER, sfc->rb_depth_stencil);
|
|
||||||
glBindRenderbuffer(GL_RENDERBUFFER, 0);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
ERR("_attach_fbo_surface() failed.");
|
||||||
|
|
||||||
// Depth RenderBuffer - Attach it to FBO
|
|
||||||
if (sfc->rb_depth)
|
|
||||||
{
|
|
||||||
glBindRenderbuffer(GL_RENDERBUFFER, sfc->rb_depth);
|
|
||||||
|
|
||||||
if (sfc->rt_msaa_samples)
|
|
||||||
glsym_glRenderbufferStorageMultisample(GL_RENDERBUFFER,
|
|
||||||
sfc->rt_msaa_samples,
|
|
||||||
sfc->rb_depth_fmt,
|
|
||||||
sfc->w, sfc->h);
|
|
||||||
else
|
|
||||||
glRenderbufferStorage(GL_RENDERBUFFER, sfc->rb_depth_fmt,
|
|
||||||
sfc->w, sfc->h);
|
|
||||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
|
|
||||||
GL_RENDERBUFFER, sfc->rb_depth);
|
|
||||||
glBindRenderbuffer(GL_RENDERBUFFER, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Stencil RenderBuffer - Attach it to FBO
|
|
||||||
if (sfc->rb_stencil)
|
|
||||||
{
|
|
||||||
glBindRenderbuffer(GL_RENDERBUFFER, sfc->rb_stencil);
|
|
||||||
|
|
||||||
if (sfc->rt_msaa_samples)
|
|
||||||
glsym_glRenderbufferStorageMultisample(GL_RENDERBUFFER,
|
|
||||||
sfc->rt_msaa_samples,
|
|
||||||
sfc->rb_stencil_fmt,
|
|
||||||
sfc->w, sfc->h);
|
|
||||||
else
|
|
||||||
glRenderbufferStorage(GL_RENDERBUFFER, sfc->rb_stencil_fmt,
|
|
||||||
sfc->w, sfc->h);
|
|
||||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT,
|
|
||||||
GL_RENDERBUFFER, sfc->rb_stencil);
|
|
||||||
glBindRenderbuffer(GL_RENDERBUFFER, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check FBO for completeness
|
|
||||||
fb_status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
|
|
||||||
if (fb_status != GL_FRAMEBUFFER_COMPLETE)
|
|
||||||
{
|
|
||||||
ERR("FBO not complete!");
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3465,7 +3602,15 @@ eng_gl_surface_create(void *data, void *config, int w, int h)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create Render texture
|
// Create Render texture
|
||||||
_create_rt_buffers(re, sfc);
|
if (!_create_rt_buffers(re, sfc))
|
||||||
|
{
|
||||||
|
ERR("Unable Create Specificed Surfaces. Unsupported format!");
|
||||||
|
goto finish;
|
||||||
|
};
|
||||||
|
|
||||||
|
ret = sfc;
|
||||||
|
|
||||||
|
finish:
|
||||||
|
|
||||||
#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
|
#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
|
||||||
res = eglMakeCurrent(re->win->egl_disp, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
res = eglMakeCurrent(re->win->egl_disp, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
||||||
|
@ -3474,14 +3619,9 @@ eng_gl_surface_create(void *data, void *config, int w, int h)
|
||||||
#endif
|
#endif
|
||||||
if (!res)
|
if (!res)
|
||||||
{
|
{
|
||||||
ERR("xxxMakeCurrent() finish!");
|
ERR("xxxMakeCurrent() (NULL, NULL) Error!");
|
||||||
goto finish;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = sfc;
|
|
||||||
|
|
||||||
finish:
|
|
||||||
|
|
||||||
if (!ret)
|
if (!ret)
|
||||||
{
|
{
|
||||||
if (sfc) free(sfc);
|
if (sfc) free(sfc);
|
||||||
|
@ -3868,9 +4008,10 @@ eng_gl_make_current(void *data __UNUSED__, void *surface, void *context)
|
||||||
// Attach FBO if it hasn't been attached or if surface changed
|
// Attach FBO if it hasn't been attached or if surface changed
|
||||||
if ((!sfc->fbo_attached) || (ctx->current_sfc != sfc))
|
if ((!sfc->fbo_attached) || (ctx->current_sfc != sfc))
|
||||||
{
|
{
|
||||||
if (!_attach_fbo_surface(re, sfc, ctx))
|
if (!_attach_fbo_surface(re, sfc, ctx->context_fbo))
|
||||||
{
|
{
|
||||||
ERR("_attach_fbo_surface() failed.");
|
ERR("_attach_fbo_surface() failed.");
|
||||||
|
_print_gl_surface_info(sfc, 1);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue