diff options
Diffstat (limited to 'drivers/gles2/rasterizer_gles2.cpp')
-rw-r--r-- | drivers/gles2/rasterizer_gles2.cpp | 177 |
1 files changed, 122 insertions, 55 deletions
diff --git a/drivers/gles2/rasterizer_gles2.cpp b/drivers/gles2/rasterizer_gles2.cpp index d3a5f3b5bc..b473e8493f 100644 --- a/drivers/gles2/rasterizer_gles2.cpp +++ b/drivers/gles2/rasterizer_gles2.cpp @@ -1408,6 +1408,40 @@ GLuint RasterizerGLES2::_texture_get_name(RID p_tex) { return texture->tex_id; }; +void RasterizerGLES2::texture_set_path(RID p_texture,const String& p_path) { + Texture * texture = texture_owner.get(p_texture); + ERR_FAIL_COND(!texture); + + texture->path=p_path; + +} + +String RasterizerGLES2::texture_get_path(RID p_texture) const{ + + Texture * texture = texture_owner.get(p_texture); + ERR_FAIL_COND_V(!texture,String()); + return texture->path; +} +void RasterizerGLES2::texture_debug_usage(List<VS::TextureInfo> *r_info){ + + List<RID> textures; + texture_owner.get_owned_list(&textures); + + for (List<RID>::Element *E=textures.front();E;E=E->next()) { + + Texture *t = texture_owner.get(E->get()); + if (!t) + continue; + VS::TextureInfo tinfo; + tinfo.path=t->path; + tinfo.format=t->format; + tinfo.size.x=t->alloc_width; + tinfo.size.y=t->alloc_height; + tinfo.bytes=t->total_data_size; + r_info->push_back(tinfo); + } + +} /* SHADER API */ @@ -4041,6 +4075,8 @@ void RasterizerGLES2::render_target_set_size(RID p_render_target,int p_width,int glDeleteTextures(1,&rt->color); rt->fbo=0; + rt->depth=0; + rt->color=0; rt->width=0; rt->height=0; rt->texture_ptr->tex_id=0; @@ -4060,12 +4096,14 @@ void RasterizerGLES2::render_target_set_size(RID p_render_target,int p_width,int glBindFramebuffer(GL_FRAMEBUFFER, rt->fbo); //depth - glGenRenderbuffers(1, &rt->depth); - glBindRenderbuffer(GL_RENDERBUFFER, rt->depth ); + if (!low_memory_2d) { + glGenRenderbuffers(1, &rt->depth); + glBindRenderbuffer(GL_RENDERBUFFER, rt->depth ); - glRenderbufferStorage(GL_RENDERBUFFER, use_depth24?_DEPTH_COMPONENT24_OES:GL_DEPTH_COMPONENT16, rt->width,rt->height); + glRenderbufferStorage(GL_RENDERBUFFER, use_depth24?_DEPTH_COMPONENT24_OES:GL_DEPTH_COMPONENT16, rt->width,rt->height); - glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rt->depth); + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rt->depth); + } //color glGenTextures(1, &rt->color); @@ -4145,7 +4183,7 @@ void RasterizerGLES2::begin_frame() { //fragment_lighting=Globals::get_singleton()->get("rasterizer/use_fragment_lighting"); #ifdef TOOLS_ENABLED - canvas_shader.set_conditional(CanvasShaderGLES2::USE_PIXEL_SNAP,GLOBAL_DEF("rasterizer/use_pixel_snap",false)); + canvas_shader.set_conditional(CanvasShaderGLES2::USE_PIXEL_SNAP,GLOBAL_DEF("display/use_2d_pixel_snap",false)); shadow_filter=ShadowFilterTechnique(int(Globals::get_singleton()->get("rasterizer/shadow_filter"))); #endif @@ -4160,7 +4198,6 @@ void RasterizerGLES2::begin_frame() { time_delta=time-last_time; last_time=time; frame++; - clear_viewport(Color(1,0,0.5)); _rinfo.vertex_count=0; _rinfo.object_count=0; @@ -4608,6 +4645,9 @@ void RasterizerGLES2::_update_shader( Shader* p_shader) const { enablers.push_back("#define USE_TIME\n"); uses_time=true; } + if (vertex_flags.vertex_code_writes_position) { + enablers.push_back("#define VERTEX_SHADER_WRITE_POSITION\n"); + } material_shader.set_custom_shader_code(p_shader->custom_code_id,vertex_code, vertex_globals,fragment_code, light_code, fragment_globals,uniform_names,enablers); } else if (p_shader->mode==VS::SHADER_CANVAS_ITEM) { @@ -5970,6 +6010,10 @@ void RasterizerGLES2::_render(const Geometry *p_geometry,const Material *p_mater if (element_count==0) return; + if (mm->visible>=0) { + element_count=MIN(element_count,mm->visible); + } + const MultiMesh::Element *elements=&mm->elements[0]; _rinfo.vertex_count+=s->array_len*element_count; @@ -6489,80 +6533,84 @@ void RasterizerGLES2::_render_list_forward(RenderList *p_render_list,const Trans material_shader.set_conditional(MaterialShaderGLES2::ENABLE_AMBIENT_LIGHTMAP,false); material_shader.set_conditional(MaterialShaderGLES2::ENABLE_AMBIENT_DP_SAMPLER,false); - if (e->instance->sampled_light.is_valid()) { + if (material->flags[VS::MATERIAL_FLAG_UNSHADED] == false && current_debug != VS::SCENARIO_DEBUG_SHADELESS) { - SampledLight *sl = sampled_light_owner.get(e->instance->sampled_light); - if (sl) { + if (e->instance->sampled_light.is_valid()) { - baked_light=NULL; //can't mix - material_shader.set_conditional(MaterialShaderGLES2::ENABLE_AMBIENT_DP_SAMPLER,true); - glActiveTexture(GL_TEXTURE0+max_texture_units-3); - glBindTexture(GL_TEXTURE_2D,sl->texture); //bind the texture - sampled_light_dp_multiplier=sl->multiplier; - bind_dp_sampler=true; + SampledLight *sl = sampled_light_owner.get(e->instance->sampled_light); + if (sl) { + + baked_light = NULL; //can't mix + material_shader.set_conditional(MaterialShaderGLES2::ENABLE_AMBIENT_DP_SAMPLER, true); + glActiveTexture(GL_TEXTURE0 + max_texture_units - 3); + glBindTexture(GL_TEXTURE_2D, sl->texture); //bind the texture + sampled_light_dp_multiplier = sl->multiplier; + bind_dp_sampler = true; + } } - } - if (!additive && baked_light) { + if (!additive && baked_light) { - if (baked_light->mode==VS::BAKED_LIGHT_OCTREE && baked_light->octree_texture.is_valid() && e->instance->baked_light_octree_xform) { - material_shader.set_conditional(MaterialShaderGLES2::ENABLE_AMBIENT_OCTREE,true); - bind_baked_light_octree=true; - if (prev_baked_light!=baked_light) { - Texture *tex=texture_owner.get(baked_light->octree_texture); - if (tex) { + if (baked_light->mode == VS::BAKED_LIGHT_OCTREE && baked_light->octree_texture.is_valid() && e->instance->baked_light_octree_xform) { + material_shader.set_conditional(MaterialShaderGLES2::ENABLE_AMBIENT_OCTREE, true); + bind_baked_light_octree = true; + if (prev_baked_light != baked_light) { + Texture *tex = texture_owner.get(baked_light->octree_texture); + if (tex) { - glActiveTexture(GL_TEXTURE0+max_texture_units-3); - glBindTexture(tex->target,tex->tex_id); //bind the texture - } - if (baked_light->light_texture.is_valid()) { - Texture *texl=texture_owner.get(baked_light->light_texture); - if (texl) { - glActiveTexture(GL_TEXTURE0+max_texture_units-4); - glBindTexture(texl->target,texl->tex_id); //bind the light texture + glActiveTexture(GL_TEXTURE0 + max_texture_units - 3); + glBindTexture(tex->target, tex->tex_id); //bind the texture + } + if (baked_light->light_texture.is_valid()) { + Texture *texl = texture_owner.get(baked_light->light_texture); + if (texl) { + glActiveTexture(GL_TEXTURE0 + max_texture_units - 4); + glBindTexture(texl->target, texl->tex_id); //bind the light texture + } } - } + } } - } else if (baked_light->mode==VS::BAKED_LIGHT_LIGHTMAPS) { + else if (baked_light->mode == VS::BAKED_LIGHT_LIGHTMAPS) { - int lightmap_idx = e->instance->baked_lightmap_id; + int lightmap_idx = e->instance->baked_lightmap_id; - material_shader.set_conditional(MaterialShaderGLES2::ENABLE_AMBIENT_LIGHTMAP,false); - bind_baked_lightmap=false; + material_shader.set_conditional(MaterialShaderGLES2::ENABLE_AMBIENT_LIGHTMAP, false); + bind_baked_lightmap = false; - if (baked_light->lightmaps.has(lightmap_idx)) { + if (baked_light->lightmaps.has(lightmap_idx)) { - RID texid = baked_light->lightmaps[lightmap_idx]; + RID texid = baked_light->lightmaps[lightmap_idx]; - if (prev_baked_light!=baked_light || texid!=prev_baked_light_texture) { + if (prev_baked_light != baked_light || texid != prev_baked_light_texture) { - Texture *tex = texture_owner.get(texid); - if (tex) { + Texture *tex = texture_owner.get(texid); + if (tex) { - glActiveTexture(GL_TEXTURE0+max_texture_units-3); - glBindTexture(tex->target,tex->tex_id); //bind the texture + glActiveTexture(GL_TEXTURE0 + max_texture_units - 3); + glBindTexture(tex->target, tex->tex_id); //bind the texture + } + + prev_baked_light_texture = texid; } - prev_baked_light_texture=texid; - } + if (texid.is_valid()) { + material_shader.set_conditional(MaterialShaderGLES2::ENABLE_AMBIENT_LIGHTMAP, true); + bind_baked_lightmap = true; + } - if (texid.is_valid()) { - material_shader.set_conditional(MaterialShaderGLES2::ENABLE_AMBIENT_LIGHTMAP,true); - bind_baked_lightmap=true; } - } } - } - if (int(prev_baked_light!=NULL) ^ int(baked_light!=NULL)) { - rebind=true; + if (int(prev_baked_light != NULL) ^ int(baked_light != NULL)) { + rebind = true; + } } } @@ -9161,7 +9209,11 @@ void RasterizerGLES2::_canvas_item_setup_shader_params(CanvasItemMaterial *mater glBindTexture(GL_TEXTURE_2D,framebuffer.sample_color); if (framebuffer.scale==1 && !canvas_texscreen_used) { #ifdef GLEW_ENABLED - glReadBuffer(GL_COLOR_ATTACHMENT0); + if (current_rt) { + glReadBuffer(GL_COLOR_ATTACHMENT0); + } else { + glReadBuffer(GL_BACK); + } #endif glCopyTexSubImage2D(GL_TEXTURE_2D,0,x,y,x,y,viewport.width,viewport.height); // if (current_clip) { @@ -9341,7 +9393,11 @@ void RasterizerGLES2::canvas_render_items(CanvasItem *p_item_list,int p_z,const glBindTexture(GL_TEXTURE_2D,framebuffer.sample_color); #ifdef GLEW_ENABLED - glReadBuffer(GL_COLOR_ATTACHMENT0); + if (current_rt) { + glReadBuffer(GL_COLOR_ATTACHMENT0); + } else { + glReadBuffer(GL_BACK); + } #endif glCopyTexSubImage2D(GL_TEXTURE_2D,0,x,y,x,y,w,h); // if (current_clip) { @@ -10248,7 +10304,11 @@ void RasterizerGLES2::_update_framebuffer() { framebuffer.fbo=0; } +#ifdef TOOLS_ENABLED framebuffer.active=use_fbo; +#else + framebuffer.active=use_fbo && !low_memory_2d; +#endif framebuffer.width=dwidth; framebuffer.height=dheight; framebuffer.scale=scale; @@ -10804,7 +10864,7 @@ void RasterizerGLES2::init() { copy_shader.set_conditional(CopyShaderGLES2::USE_8BIT_HDR,!use_fp16_fb); canvas_shader.set_conditional(CanvasShaderGLES2::USE_DEPTH_SHADOWS,read_depth_supported); - canvas_shader.set_conditional(CanvasShaderGLES2::USE_PIXEL_SNAP,GLOBAL_DEF("rasterizer/use_pixel_snap",false)); + canvas_shader.set_conditional(CanvasShaderGLES2::USE_PIXEL_SNAP,GLOBAL_DEF("display/use_2d_pixel_snap",false)); npo2_textures_available=true; //fragment_lighting=false; @@ -11158,6 +11218,7 @@ RasterizerGLES2::RasterizerGLES2(bool p_compress_arrays,bool p_keep_ram_copy,boo use_fp16_fb=bool(GLOBAL_DEF("rasterizer/fp16_framebuffer",true)); use_shadow_mapping=true; use_fast_texture_filter=!bool(GLOBAL_DEF("rasterizer/trilinear_mipmap_filter",true)); + low_memory_2d=bool(GLOBAL_DEF("rasterizer/low_memory_2d_mode",false)); skel_default.resize(1024*4); for(int i=0;i<1024/3;i++) { @@ -11188,6 +11249,12 @@ RasterizerGLES2::RasterizerGLES2(bool p_compress_arrays,bool p_keep_ram_copy,boo tc0_idx=0; }; +void RasterizerGLES2::restore_framebuffer() { + + glBindFramebuffer(GL_FRAMEBUFFER, base_framebuffer); + +} + RasterizerGLES2::~RasterizerGLES2() { memdelete_arr(skinned_buffer); |