evas.canvas3d: Remove repeated code in e3d_drawable_new function
Reviewers: cedric, Hermet, raster Subscribers: jpeg Differential Revision: https://phab.enlightenment.org/D3824
This commit is contained in:
parent
b564c1f0ae
commit
35a64ecae7
|
@ -279,6 +279,25 @@ e3d_texture_filter_get(const E3D_Texture *texture,
|
||||||
*mag = _to_e3d_texture_filter(texture->filter_mag);
|
*mag = _to_e3d_texture_filter(texture->filter_mag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _gen_texture_2d(GLuint *texture, GLenum wrap_type, GLfloat filter_type)
|
||||||
|
{
|
||||||
|
glGenTextures(1, texture);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, *texture);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap_type);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap_type);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter_type);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter_type);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _gen_depth_stensil_buffer(GLuint *buffer, GLenum format, GLenum attach,
|
||||||
|
int size_w, int size_h)
|
||||||
|
{
|
||||||
|
glGenRenderbuffers(1, buffer);
|
||||||
|
glBindRenderbuffer(GL_RENDERBUFFER, *buffer);
|
||||||
|
glRenderbufferStorage(GL_RENDERBUFFER, format, size_w, size_h);
|
||||||
|
glFramebufferRenderbuffer(GL_FRAMEBUFFER, attach, GL_RENDERBUFFER, *buffer);
|
||||||
|
}
|
||||||
|
|
||||||
E3D_Drawable *
|
E3D_Drawable *
|
||||||
e3d_drawable_new(int w, int h, int alpha, GLenum depth_format, GLenum stencil_format)
|
e3d_drawable_new(int w, int h, int alpha, GLenum depth_format, GLenum stencil_format)
|
||||||
{
|
{
|
||||||
|
@ -289,33 +308,17 @@ e3d_drawable_new(int w, int h, int alpha, GLenum depth_format, GLenum stencil_fo
|
||||||
GLuint stencil_buf = 0;
|
GLuint stencil_buf = 0;
|
||||||
Eina_Bool depth_stencil = EINA_FALSE;
|
Eina_Bool depth_stencil = EINA_FALSE;
|
||||||
|
|
||||||
glGenTextures(1, &tex);
|
_gen_texture_2d(&tex, GL_CLAMP_TO_EDGE, GL_NEAREST);
|
||||||
glBindTexture(GL_TEXTURE_2D, 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_MIN_FILTER, GL_NEAREST);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
||||||
|
|
||||||
if (alpha)
|
if (alpha)
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
||||||
else
|
else
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
|
||||||
|
|
||||||
glGenTextures(1, &texDepth);
|
_gen_texture_2d(&texDepth, GL_CLAMP_TO_EDGE, GL_NEAREST);
|
||||||
glBindTexture(GL_TEXTURE_2D, texDepth);
|
|
||||||
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_MIN_FILTER, GL_NEAREST);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
||||||
|
|
||||||
glGenFramebuffers(1, &color_pick_fb_id);
|
glGenFramebuffers(1, &color_pick_fb_id);
|
||||||
glGenTextures(1, &texcolorpick);
|
_gen_texture_2d(&texcolorpick, GL_CLAMP_TO_EDGE, GL_NEAREST);
|
||||||
glBindTexture(GL_TEXTURE_2D, texcolorpick);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
|
||||||
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, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
||||||
|
|
||||||
glGenFramebuffers(1, &fbo);
|
glGenFramebuffers(1, &fbo);
|
||||||
|
@ -325,13 +328,7 @@ e3d_drawable_new(int w, int h, int alpha, GLenum depth_format, GLenum stencil_fo
|
||||||
#ifdef GL_GLES
|
#ifdef GL_GLES
|
||||||
if (depth_format == GL_DEPTH_STENCIL_OES)
|
if (depth_format == GL_DEPTH_STENCIL_OES)
|
||||||
{
|
{
|
||||||
glGenTextures(1, &depth_stencil_buf);
|
_gen_texture_2d(&depth_stencil_buf, GL_CLAMP_TO_EDGE, GL_NEAREST);
|
||||||
glBindTexture(GL_TEXTURE_2D, depth_stencil_buf);
|
|
||||||
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_MIN_FILTER, GL_NEAREST);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
||||||
|
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_STENCIL_OES, w, h, 0,
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_STENCIL_OES, w, h, 0,
|
||||||
GL_DEPTH_STENCIL_OES, GL_UNSIGNED_INT_24_8_OES, NULL);
|
GL_DEPTH_STENCIL_OES, GL_UNSIGNED_INT_24_8_OES, NULL);
|
||||||
|
|
||||||
|
@ -345,33 +342,17 @@ e3d_drawable_new(int w, int h, int alpha, GLenum depth_format, GLenum stencil_fo
|
||||||
#else
|
#else
|
||||||
if (depth_format == GL_DEPTH24_STENCIL8)
|
if (depth_format == GL_DEPTH24_STENCIL8)
|
||||||
{
|
{
|
||||||
glGenRenderbuffers(1, &depth_stencil_buf);
|
_gen_depth_stensil_buffer(&depth_stencil_buf, GL_DEPTH24_STENCIL8,
|
||||||
glBindRenderbuffer(GL_RENDERBUFFER, depth_stencil_buf);
|
GL_DEPTH_STENCIL_ATTACHMENT, w, h);
|
||||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, w, h);
|
|
||||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT,
|
|
||||||
GL_RENDERBUFFER, depth_stencil_buf);
|
|
||||||
|
|
||||||
depth_stencil = EINA_TRUE;
|
depth_stencil = EINA_TRUE;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if ((!depth_stencil) && (depth_format))
|
if ((!depth_stencil) && (depth_format))
|
||||||
{
|
_gen_depth_stensil_buffer(&depth_buf, depth_format, GL_DEPTH_ATTACHMENT, w, h);
|
||||||
glGenRenderbuffers(1, &depth_buf);
|
|
||||||
glBindRenderbuffer(GL_RENDERBUFFER, depth_buf);
|
|
||||||
glRenderbufferStorage(GL_RENDERBUFFER, depth_format, w, h);
|
|
||||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
|
|
||||||
GL_RENDERBUFFER, depth_buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((!depth_stencil) && (stencil_format))
|
if ((!depth_stencil) && (stencil_format))
|
||||||
{
|
_gen_depth_stensil_buffer(&stencil_buf, stencil_format, GL_STENCIL_ATTACHMENT, w, h);
|
||||||
glGenRenderbuffers(1, &stencil_buf);
|
|
||||||
glBindRenderbuffer(GL_RENDERBUFFER, stencil_buf);
|
|
||||||
glRenderbufferStorage(GL_RENDERBUFFER, stencil_format, w, h);
|
|
||||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT,
|
|
||||||
GL_RENDERBUFFER, stencil_buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
|
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
Loading…
Reference in New Issue