diff options
author | Juan Linietsky <reduzio@gmail.com> | 2016-10-05 01:26:35 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2016-10-05 01:26:35 -0300 |
commit | cf5778e51a883936ffc896231da8259e5ebabc0a (patch) | |
tree | 286f7eb7956a5c2c275276bbc9e3db5e3ff0730f /drivers | |
parent | a6e9dc615346f44b68b418483dd218d11ba4a674 (diff) |
-Added ViewportContainer, this is the only way to make viewports show up in GUI now
-2D editing now seems to work
-Added some functions and refactoring to Viewport
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/gles2/shaders/canvas.glsl | 1 | ||||
-rw-r--r-- | drivers/gles3/rasterizer_canvas_gles3.cpp | 18 | ||||
-rw-r--r-- | drivers/gles3/rasterizer_gles3.cpp | 4 | ||||
-rw-r--r-- | drivers/gles3/rasterizer_storage_gles3.cpp | 64 | ||||
-rw-r--r-- | drivers/gles3/rasterizer_storage_gles3.h | 5 |
5 files changed, 75 insertions, 17 deletions
diff --git a/drivers/gles2/shaders/canvas.glsl b/drivers/gles2/shaders/canvas.glsl index 38c579c15c..eeab42ee64 100644 --- a/drivers/gles2/shaders/canvas.glsl +++ b/drivers/gles2/shaders/canvas.glsl @@ -395,5 +395,6 @@ LIGHT_SHADER_CODE // color.rgb*=color.a; gl_FragColor = color; + } diff --git a/drivers/gles3/rasterizer_canvas_gles3.cpp b/drivers/gles3/rasterizer_canvas_gles3.cpp index f24560763f..a1e755cb4a 100644 --- a/drivers/gles3/rasterizer_canvas_gles3.cpp +++ b/drivers/gles3/rasterizer_canvas_gles3.cpp @@ -111,6 +111,15 @@ void RasterizerCanvasGLES3::light_internal_free(RID p_rid) { void RasterizerCanvasGLES3::canvas_begin(){ + if (storage->frame.current_rt && storage->frame.clear_request) { + // a clear request may be pending, so do it + + glClearColor( storage->frame.clear_request_color.r, storage->frame.clear_request_color.g, storage->frame.clear_request_color.b, storage->frame.clear_request_color.a ); + glClear(GL_COLOR_BUFFER_BIT); + storage->frame.clear_request=false; + + } + /*canvas_shader.unbind(); canvas_shader.set_custom_shader(0); canvas_shader.set_conditional(CanvasShaderGLES2::USE_MODULATE,false); @@ -504,7 +513,7 @@ void RasterizerCanvasGLES3::_canvas_item_render_commands(Item *p_item,Item *curr } if (rect->flags&CANVAS_RECT_FLIP_V) { - src_rect.size.x*=-1; + src_rect.size.y*=-1; } if (rect->flags&CANVAS_RECT_TRANSPOSE) { @@ -769,14 +778,7 @@ void RasterizerGLES2::_canvas_item_setup_shader_params(CanvasItemMaterial *mater void RasterizerCanvasGLES3::canvas_render_items(Item *p_item_list,int p_z,const Color& p_modulate,Light *p_light) { - if (storage->frame.clear_request) { - // a clear request may be pending, so do it - glClearColor( storage->frame.clear_request_color.r, storage->frame.clear_request_color.g, storage->frame.clear_request_color.b, storage->frame.clear_request_color.a ); - glClear(GL_COLOR_BUFFER_BIT); - storage->frame.clear_request=false; - - } Item *current_clip=NULL; RasterizerStorageGLES3::Shader *shader_cache=NULL; diff --git a/drivers/gles3/rasterizer_gles3.cpp b/drivers/gles3/rasterizer_gles3.cpp index ba83a572e5..27b0690645 100644 --- a/drivers/gles3/rasterizer_gles3.cpp +++ b/drivers/gles3/rasterizer_gles3.cpp @@ -141,7 +141,7 @@ void RasterizerGLES3::set_current_render_target(RID p_render_target){ storage->frame.current_rt=rt; storage->frame.clear_request=false; - glViewport(0,0,rt->width,rt->height); + glViewport(0,0,rt->width,rt->height); } else { storage->frame.current_rt=NULL; @@ -155,6 +155,7 @@ void RasterizerGLES3::restore_render_target() { ERR_FAIL_COND(storage->frame.current_rt==NULL); RasterizerStorageGLES3::RenderTarget * rt = storage->frame.current_rt; + glBindFramebuffer(GL_FRAMEBUFFER,rt->front.fbo); glViewport(0,0,rt->width,rt->height); } @@ -176,6 +177,7 @@ void RasterizerGLES3::blit_render_target_to_screen(RID p_render_target,const Rec ERR_FAIL_COND(!rt); canvas->canvas_begin(); + glDisable(GL_BLEND); glBindFramebuffer(GL_FRAMEBUFFER,storage->config.system_fbo); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D,rt->front.color); diff --git a/drivers/gles3/rasterizer_storage_gles3.cpp b/drivers/gles3/rasterizer_storage_gles3.cpp index 515db39098..b4d65080a4 100644 --- a/drivers/gles3/rasterizer_storage_gles3.cpp +++ b/drivers/gles3/rasterizer_storage_gles3.cpp @@ -1483,6 +1483,12 @@ void RasterizerStorageGLES3::_render_target_clear(RenderTarget *rt) { rt->depth=0; } + Texture *tex = texture_owner.get(rt->texture); + tex->alloc_height=0; + tex->alloc_width=0; + tex->width=0; + tex->height=0; + } void RasterizerStorageGLES3::_render_target_allocate(RenderTarget *rt){ @@ -1490,6 +1496,8 @@ void RasterizerStorageGLES3::_render_target_allocate(RenderTarget *rt){ if (rt->width<=0 || rt->height<=0) return; + glActiveTexture(GL_TEXTURE0); + glGenFramebuffers(1, &rt->front.fbo); glBindFramebuffer(GL_FRAMEBUFFER, rt->front.fbo); @@ -1512,6 +1520,7 @@ void RasterizerStorageGLES3::_render_target_allocate(RenderTarget *rt){ GLuint color_internal_format; GLuint color_format; GLuint color_type; + Image::Format image_format; if (config.fbo_format==FBO_FORMAT_16_BITS) { @@ -1520,28 +1529,33 @@ void RasterizerStorageGLES3::_render_target_allocate(RenderTarget *rt){ color_internal_format=GL_RGB5_A1; color_format=GL_RGBA; color_type=GL_UNSIGNED_SHORT_5_5_5_1; + image_format=Image::FORMAT_RGBA5551; } else { color_internal_format=GL_RGB565; color_format=GL_RGB; color_type=GL_UNSIGNED_SHORT_5_6_5; + image_format=Image::FORMAT_RGB565; } - } else if (config.fbo_format==FBO_FORMAT_32_BITS) { + } else if (config.fbo_format==FBO_FORMAT_32_BITS || (config.fbo_format==FBO_FORMAT_FLOAT && rt->flags[RENDER_TARGET_NO_3D])) { if (rt->flags[RENDER_TARGET_TRANSPARENT]) { color_internal_format=GL_RGBA8; color_format=GL_RGBA; color_type=GL_UNSIGNED_BYTE; + image_format=Image::FORMAT_RGBA8; } else { color_internal_format=GL_RGB10_A2; color_format=GL_RGBA; color_type=GL_UNSIGNED_INT_2_10_10_10_REV; + image_format=Image::FORMAT_RGBA8;//todo } } else if (config.fbo_format==FBO_FORMAT_FLOAT) { color_internal_format=GL_RGBA16F; color_format=GL_RGBA; color_type=GL_HALF_FLOAT; + image_format=Image::FORMAT_RGBAH; } glTexImage2D(GL_TEXTURE_2D, 0, color_internal_format, rt->width, rt->height, 0, color_format, color_type, NULL); @@ -1559,6 +1573,19 @@ void RasterizerStorageGLES3::_render_target_allocate(RenderTarget *rt){ ERR_FAIL_COND( status != GL_FRAMEBUFFER_COMPLETE ); } + Texture *tex = texture_owner.get(rt->texture); + tex->format=image_format; + tex->gl_format_cache=color_format; + tex->gl_type_cache=color_type; + tex->gl_internal_format_cache=color_internal_format; + tex->tex_id=rt->front.color; + tex->width=rt->width; + tex->alloc_width=rt->width; + tex->height=rt->height; + tex->alloc_height=rt->height; + + + texture_set_flags(rt->texture,tex->flags); if (!rt->flags[RENDER_TARGET_NO_SAMPLING]) { @@ -1662,6 +1689,31 @@ void RasterizerStorageGLES3::_render_target_allocate(RenderTarget *rt){ RID RasterizerStorageGLES3::render_target_create(){ RenderTarget *rt = memnew( RenderTarget ); + + Texture * t = memnew( Texture ); + + t->flags=0; + t->width=0; + t->height=0; + t->alloc_height=0; + t->alloc_width=0; + t->format=Image::FORMAT_R8; + t->target=GL_TEXTURE_2D; + t->gl_format_cache=0; + t->gl_internal_format_cache=0; + t->gl_type_cache=0; + t->data_size=0; + t->compressed=false; + t->srgb=false; + t->total_data_size=0; + t->ignore_mipmaps=false; + t->mipmaps=0; + t->active=true; + t->tex_id=0; + + + rt->texture=texture_owner.make_rid(t); + return render_target_owner.make_rid(rt); } @@ -1686,13 +1738,9 @@ RID RasterizerStorageGLES3::render_target_get_texture(RID p_render_target) const RenderTarget *rt = render_target_owner.getornull(p_render_target); ERR_FAIL_COND_V(!rt,RID()); - - return RID(); + return rt->texture; } -Image RasterizerStorageGLES3::render_target_get_image(RID p_render_target) const{ - return Image(); -} void RasterizerStorageGLES3::render_target_set_flag(RID p_render_target,RenderTargetFlags p_flag,bool p_value) { RenderTarget *rt = render_target_owner.getornull(p_render_target); @@ -1889,12 +1937,16 @@ bool RasterizerStorageGLES3::free(RID p_rid){ RenderTarget *rt = render_target_owner.getornull(p_rid); _render_target_clear(rt); + Texture *t=texture_owner.get(rt->texture); + texture_owner.free(rt->texture); + memdelete(t); render_target_owner.free(p_rid); memdelete(rt); } else if (texture_owner.owns(p_rid)) { // delete the texture Texture *texture = texture_owner.get(p_rid); + ERR_FAIL_COND_V(texture->render_target,true); //cant free the render target texture, dude info.texture_mem-=texture->total_data_size; texture_owner.free(p_rid); memdelete(texture); diff --git a/drivers/gles3/rasterizer_storage_gles3.h b/drivers/gles3/rasterizer_storage_gles3.h index eb6cd0bd92..9820fbc941 100644 --- a/drivers/gles3/rasterizer_storage_gles3.h +++ b/drivers/gles3/rasterizer_storage_gles3.h @@ -117,7 +117,6 @@ public: bool active; GLuint tex_id; - RenderTarget *render_target; Texture() { @@ -361,6 +360,8 @@ public: bool used_in_frame; + RID texture; + RenderTarget() { width=0; @@ -387,7 +388,7 @@ public: virtual RID render_target_create(); virtual void render_target_set_size(RID p_render_target,int p_width, int p_height); virtual RID render_target_get_texture(RID p_render_target) const; - virtual Image render_target_get_image(RID p_render_target) const; + virtual void render_target_set_flag(RID p_render_target,RenderTargetFlags p_flag,bool p_value); virtual bool render_target_renedered_in_frame(RID p_render_target); |