diff --git a/core/command_queue_mt.h b/core/command_queue_mt.h index bae8cf7fca8..83c90a925c8 100644 --- a/core/command_queue_mt.h +++ b/core/command_queue_mt.h @@ -170,6 +170,43 @@ class CommandQueueMT { virtual void call() { (instance->*method)(p1, p2, p3, p4, p5, p6, p7, p8); } }; + template + struct Command9 : public CommandBase { + + T *instance; + M method; + typename GetSimpleTypeT::type_t p1; + typename GetSimpleTypeT::type_t p2; + typename GetSimpleTypeT::type_t p3; + typename GetSimpleTypeT::type_t p4; + typename GetSimpleTypeT::type_t p5; + typename GetSimpleTypeT::type_t p6; + typename GetSimpleTypeT::type_t p7; + typename GetSimpleTypeT::type_t p8; + typename GetSimpleTypeT::type_t p9; + + virtual void call() { (instance->*method)(p1, p2, p3, p4, p5, p6, p7, p8, p9); } + }; + + template + struct Command10 : public CommandBase { + + T *instance; + M method; + typename GetSimpleTypeT::type_t p1; + typename GetSimpleTypeT::type_t p2; + typename GetSimpleTypeT::type_t p3; + typename GetSimpleTypeT::type_t p4; + typename GetSimpleTypeT::type_t p5; + typename GetSimpleTypeT::type_t p6; + typename GetSimpleTypeT::type_t p7; + typename GetSimpleTypeT::type_t p8; + typename GetSimpleTypeT::type_t p9; + typename GetSimpleTypeT::type_t p10; + + virtual void call() { (instance->*method)(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10); } + }; + /* comands that return */ template @@ -779,6 +816,52 @@ public: if (sync) sync->post(); } + + template + void push(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8, P9 p9) { + + Command9 *cmd = allocate_and_lock >(); + + cmd->instance = p_instance; + cmd->method = p_method; + cmd->p1 = p1; + cmd->p2 = p2; + cmd->p3 = p3; + cmd->p4 = p4; + cmd->p5 = p5; + cmd->p6 = p6; + cmd->p7 = p7; + cmd->p8 = p8; + cmd->p9 = p9; + + unlock(); + + if (sync) sync->post(); + } + + template + void push(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8, P9 p9, P10 p10) { + + Command10 *cmd = allocate_and_lock >(); + + cmd->instance = p_instance; + cmd->method = p_method; + cmd->p1 = p1; + cmd->p2 = p2; + cmd->p3 = p3; + cmd->p4 = p4; + cmd->p5 = p5; + cmd->p6 = p6; + cmd->p7 = p7; + cmd->p8 = p8; + cmd->p9 = p9; + cmd->p10 = p10; + + unlock(); + + if (sync) sync->post(); + } + /*** PUSH AND RET COMMANDS ***/ template diff --git a/core/image.cpp b/core/image.cpp index 2da91c7b131..686735c9069 100644 --- a/core/image.cpp +++ b/core/image.cpp @@ -81,21 +81,21 @@ const char *Image::format_names[Image::FORMAT_MAX] = { SavePNGFunc Image::save_png_func = NULL; -void Image::_put_pixelb(int p_x, int p_y, uint32_t p_pixelsize, uint8_t *p_dst, const uint8_t *p_src) { +void Image::_put_pixelb(int p_x, int p_y, uint32_t p_pixelsize, uint8_t *p_data, const uint8_t *p_pixel) { uint32_t ofs = (p_y * width + p_x) * p_pixelsize; for (uint32_t i = 0; i < p_pixelsize; i++) { - p_dst[ofs + i] = p_src[i]; + p_data[ofs + i] = p_pixel[i]; } } -void Image::_get_pixelb(int p_x, int p_y, uint32_t p_pixelsize, const uint8_t *p_src, uint8_t *p_dst) { +void Image::_get_pixelb(int p_x, int p_y, uint32_t p_pixelsize, const uint8_t *p_data, uint8_t *p_pixel) { uint32_t ofs = (p_y * width + p_x) * p_pixelsize; for (uint32_t i = 0; i < p_pixelsize; i++) { - p_dst[i] = p_src[ofs + i]; + p_pixel[i] = p_data[ofs + i]; } } @@ -818,7 +818,7 @@ void Image::flip_y() { uint8_t down[16]; uint32_t pixel_size = get_format_pixel_size(format); - for (int y = 0; y < height; y++) { + for (int y = 0; y < height / 2; y++) { for (int x = 0; x < width; x++) { @@ -854,7 +854,7 @@ void Image::flip_x() { for (int y = 0; y < height; y++) { - for (int x = 0; x < width; x++) { + for (int x = 0; x < width / 2; x++) { _get_pixelb(x, y, pixel_size, w.ptr(), up); _get_pixelb(width - x - 1, y, pixel_size, w.ptr(), down); @@ -1457,7 +1457,7 @@ Error Image::save_png(const String &p_path) const { if (save_png_func == NULL) return ERR_UNAVAILABLE; - return save_png_func(p_path, Ref(this)); + return save_png_func(p_path, Ref((Image *)this)); } int Image::get_image_data_size(int p_width, int p_height, Format p_format, int p_mipmaps) { @@ -1599,7 +1599,7 @@ Rect2 Image::get_used_rect() const { Ref Image::get_rect(const Rect2 &p_area) const { Ref img = memnew(Image(p_area.size.x, p_area.size.y, mipmaps, format)); - img->blit_rect(Ref(this), p_area, Point2(0, 0)); + img->blit_rect(Ref((Image *)this), p_area, Point2(0, 0)); return img; } diff --git a/core/image.h b/core/image.h index 2a78870f53c..e3174a28993 100644 --- a/core/image.h +++ b/core/image.h @@ -162,8 +162,8 @@ private: static int _get_dst_image_size(int p_width, int p_height, Format p_format, int &r_mipmaps, int p_mipmaps = -1); bool _can_modify(Format p_format) const; - _FORCE_INLINE_ void _put_pixelb(int p_x, int p_y, uint32_t p_pixelsize, uint8_t *p_dst, const uint8_t *p_src); - _FORCE_INLINE_ void _get_pixelb(int p_x, int p_y, uint32_t p_pixelsize, const uint8_t *p_src, uint8_t *p_dst); + _FORCE_INLINE_ void _put_pixelb(int p_x, int p_y, uint32_t p_pixelsize, uint8_t *p_data, const uint8_t *p_pixel); + _FORCE_INLINE_ void _get_pixelb(int p_x, int p_y, uint32_t p_pixelsize, const uint8_t *p_data, uint8_t *p_pixel); void _set_data(const Dictionary &p_data); Dictionary _get_data() const; diff --git a/core/object.cpp b/core/object.cpp index 7aee936a2df..f20e93f9d7f 100644 --- a/core/object.cpp +++ b/core/object.cpp @@ -1831,10 +1831,10 @@ void postinitialize_handler(Object *p_object) { p_object->_postinitialize(); } -HashMap ObjectDB::instances; -uint32_t ObjectDB::instance_counter = 1; +HashMap ObjectDB::instances; +ObjectID ObjectDB::instance_counter = 1; HashMap ObjectDB::instance_checks; -uint32_t ObjectDB::add_instance(Object *p_object) { +ObjectID ObjectDB::add_instance(Object *p_object) { ERR_FAIL_COND_V(p_object->get_instance_ID() != 0, 0); @@ -1859,7 +1859,7 @@ void ObjectDB::remove_instance(Object *p_object) { rw_lock->write_unlock(); } -Object *ObjectDB::get_instance(uint32_t p_instance_ID) { +Object *ObjectDB::get_instance(ObjectID p_instance_ID) { rw_lock->read_lock(); Object **obj = instances.getptr(p_instance_ID); @@ -1874,7 +1874,7 @@ void ObjectDB::debug_objects(DebugFunc p_func) { rw_lock->read_lock(); - const uint32_t *K = NULL; + const ObjectID *K = NULL; while ((K = instances.next(K))) { p_func(instances[*K]); @@ -1909,7 +1909,7 @@ void ObjectDB::cleanup() { WARN_PRINT("ObjectDB Instances still exist!"); if (OS::get_singleton()->is_stdout_verbose()) { - const uint32_t *K = NULL; + const ObjectID *K = NULL; while ((K = instances.next(K))) { String node_name; diff --git a/core/object.h b/core/object.h index 3b39224af0d..83b03b92398 100644 --- a/core/object.h +++ b/core/object.h @@ -350,7 +350,7 @@ public: \ private: class ScriptInstance; -typedef uint32_t ObjectID; +typedef uint64_t ObjectID; class Object { public: @@ -423,7 +423,7 @@ private: bool _block_signals; int _predelete_ok; Set change_receptors; - uint32_t _instance_ID; + ObjectID _instance_ID; bool _predelete(); void _postinitialize(); bool _can_translate; @@ -690,16 +690,16 @@ class ObjectDB { } }; - static HashMap instances; + static HashMap instances; static HashMap instance_checks; - static uint32_t instance_counter; + static ObjectID instance_counter; friend class Object; friend void unregister_core_types(); static RWLock *rw_lock; static void cleanup(); - static uint32_t add_instance(Object *p_object); + static ObjectID add_instance(Object *p_object); static void remove_instance(Object *p_object); friend void register_core_types(); static void setup(); @@ -707,7 +707,7 @@ class ObjectDB { public: typedef void (*DebugFunc)(Object *p_obj); - static Object *get_instance(uint32_t p_instance_ID); + static Object *get_instance(ObjectID p_instance_ID); static void debug_objects(DebugFunc p_func); static int get_object_count(); diff --git a/drivers/gles3/rasterizer_scene_gles3.cpp b/drivers/gles3/rasterizer_scene_gles3.cpp index af03819a163..7152b49d277 100644 --- a/drivers/gles3/rasterizer_scene_gles3.cpp +++ b/drivers/gles3/rasterizer_scene_gles3.cpp @@ -1783,13 +1783,6 @@ void RasterizerSceneGLES3::_set_cull(bool p_front, bool p_reverse_cull) { void RasterizerSceneGLES3::_render_list(RenderList::Element **p_elements, int p_element_count, const Transform &p_view_transform, const CameraMatrix &p_projection, GLuint p_base_env, bool p_reverse_cull, bool p_alpha_pass, bool p_shadow, bool p_directional_add, bool p_directional_shadows) { - if (storage->frame.current_rt && storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_VFLIP]) { - //p_reverse_cull=!p_reverse_cull; - glFrontFace(GL_CCW); - } else { - glFrontFace(GL_CW); - } - glBindBufferBase(GL_UNIFORM_BUFFER, 0, state.scene_ubo); //bind globals ubo if (!p_shadow && !p_directional_add) { @@ -3306,19 +3299,21 @@ void RasterizerSceneGLES3::_post_process(Environment *env, const CameraMatrix &p glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); - if (!env) { - //no environment, simply return and convert to SRGB + if (!env || storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_TRANSPARENT]) { + //no environment or transparent render, simply return and convert to SRGB glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->fbo); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->effects.mip_maps[0].color); storage->shaders.copy.set_conditional(CopyShaderGLES3::LINEAR_TO_SRGB, true); - storage->shaders.copy.set_conditional(CopyShaderGLES3::DISABLE_ALPHA, true); + storage->shaders.copy.set_conditional(CopyShaderGLES3::V_FLIP, storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_VFLIP]); + storage->shaders.copy.set_conditional(CopyShaderGLES3::DISABLE_ALPHA, !storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_TRANSPARENT]); storage->shaders.copy.bind(); _copy_screen(); storage->shaders.copy.set_conditional(CopyShaderGLES3::LINEAR_TO_SRGB, false); storage->shaders.copy.set_conditional(CopyShaderGLES3::DISABLE_ALPHA, false); //compute luminance + storage->shaders.copy.set_conditional(CopyShaderGLES3::V_FLIP, false); return; } @@ -3692,6 +3687,7 @@ void RasterizerSceneGLES3::_post_process(Environment *env, const CameraMatrix &p } } + state.tonemap_shader.set_conditional(TonemapShaderGLES3::V_FLIP, storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_VFLIP]); state.tonemap_shader.bind(); state.tonemap_shader.set_uniform(TonemapShaderGLES3::EXPOSURE, env->tone_mapper_exposure); @@ -3739,6 +3735,7 @@ void RasterizerSceneGLES3::_post_process(Environment *env, const CameraMatrix &p state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_GLOW_FILTER_BICUBIC, false); state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_BCS, false); state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_COLOR_CORRECTION, false); + state.tonemap_shader.set_conditional(TonemapShaderGLES3::V_FLIP, false); } void RasterizerSceneGLES3::render_scene(const Transform &p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_ortogonal, InstanceBase **p_cull_result, int p_cull_count, RID *p_light_cull_result, int p_light_cull_count, RID *p_reflection_probe_cull_result, int p_reflection_probe_cull_count, RID p_environment, RID p_shadow_atlas, RID p_reflection_atlas, RID p_reflection_probe, int p_reflection_probe_pass) { @@ -3880,6 +3877,9 @@ void RasterizerSceneGLES3::render_scene(const Transform &p_cam_transform, const } else { use_mrt = env && (state.used_screen_texture || state.used_sss || env->ssao_enabled || env->ssr_enabled); //only enable MRT rendering if any of these is enabled + //effects disabled and transparency also prevent using MRTs + use_mrt = use_mrt && !storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_TRANSPARENT]; + use_mrt = use_mrt && !storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_NO_3D_EFFECTS]; glViewport(0, 0, storage->frame.current_rt->width, storage->frame.current_rt->height); @@ -3928,7 +3928,9 @@ void RasterizerSceneGLES3::render_scene(const Transform &p_cam_transform, const RasterizerStorageGLES3::Sky *sky = NULL; GLuint env_radiance_tex = 0; - if (!env || env->bg_mode == VS::ENV_BG_CLEAR_COLOR) { + if (storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_TRANSPARENT]) { + clear_color = Color(0, 0, 0, 0); + } else if (!env || env->bg_mode == VS::ENV_BG_CLEAR_COLOR) { if (storage->frame.clear_request) { @@ -3961,20 +3963,14 @@ void RasterizerSceneGLES3::render_scene(const Transform &p_cam_transform, const if (storage->frame.current_rt && storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_TRANSPARENT]) { glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA); + glEnable(GL_BLEND); } else { glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glDisable(GL_BLEND); } - glDisable(GL_BLEND); - render_list.sort_by_key(false); - if (storage->frame.current_rt && storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_TRANSPARENT]) { - glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA); - } else { - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - } - if (state.directional_light_count == 0) { directional_light = NULL; _render_list(render_list.elements, render_list.element_count, p_cam_transform, p_cam_projection, env_radiance_tex, false, false, false, false, shadow_atlas != NULL); @@ -3996,14 +3992,14 @@ void RasterizerSceneGLES3::render_scene(const Transform &p_cam_transform, const glDrawBuffers(1, &gldb); } - if (env && env->bg_mode == VS::ENV_BG_SKY) { + if (env && env->bg_mode == VS::ENV_BG_SKY && !storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_TRANSPARENT]) { /* if (use_mrt) { glBindFramebuffer(GL_FRAMEBUFFER,storage->frame.current_rt->buffers.fbo); //switch to alpha fbo for sky, only diffuse/ambient matters */ - _draw_sky(sky, p_cam_projection, p_cam_transform, storage->frame.current_rt && storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_VFLIP], env->sky_scale, env->bg_energy); + _draw_sky(sky, p_cam_projection, p_cam_transform, false, env->sky_scale, env->bg_energy); } //_render_list_forward(&alpha_render_list,camera_transform,camera_transform_inverse,camera_projection,false,fragment_lighting,true); diff --git a/drivers/gles3/rasterizer_storage_gles3.cpp b/drivers/gles3/rasterizer_storage_gles3.cpp index a503b6daa7e..c6e18944e75 100644 --- a/drivers/gles3/rasterizer_storage_gles3.cpp +++ b/drivers/gles3/rasterizer_storage_gles3.cpp @@ -782,7 +782,6 @@ void RasterizerStorageGLES3::texture_set_data(RID p_texture, const Ref &p int bh = h; glCompressedTexImage2D(blit_target, i, internal_format, bw, bh, 0, size, &read[ofs]); - print_line("format: " + Image::get_format_name(texture->format) + " size: " + Vector2(bw, bh) + " block: " + itos(block)); } else { glPixelStorei(GL_UNPACK_ALIGNMENT, 1); @@ -825,8 +824,7 @@ Ref RasterizerStorageGLES3::texture_get_data(RID p_texture, VS::CubeMapSi ERR_FAIL_COND_V(!texture, Ref()); ERR_FAIL_COND_V(!texture->active, Ref()); - ERR_FAIL_COND_V(texture->data_size == 0, Ref()); - ERR_FAIL_COND_V(texture->render_target, Ref()); + ERR_FAIL_COND_V(texture->data_size == 0 && !texture->render_target, Ref()); if (!texture->images[p_cube_side].is_null()) { return texture->images[p_cube_side]; @@ -5493,6 +5491,7 @@ void RasterizerStorageGLES3::_render_target_clear(RenderTarget *rt) { tex->alloc_width = 0; tex->width = 0; tex->height = 0; + tex->active = false; for (int i = 0; i < 2; i++) { for (int j = 0; j < rt->effects.mip_maps[i].sizes.size(); j++) { @@ -5589,13 +5588,14 @@ void RasterizerStorageGLES3::_render_target_allocate(RenderTarget *rt) { tex->alloc_width = rt->width; tex->height = rt->height; tex->alloc_height = rt->height; + tex->active = true; texture_set_flags(rt->texture, tex->flags); } /* BACK FBO */ - if (config.render_arch == RENDER_ARCH_DESKTOP && !rt->flags[RENDER_TARGET_NO_3D]) { + if (!rt->flags[RENDER_TARGET_NO_3D]) { static const int msaa_value[] = { 0, 2, 4, 8, 16 }; int msaa = msaa_value[rt->msaa]; @@ -5623,75 +5623,155 @@ void RasterizerStorageGLES3::_render_target_allocate(RenderTarget *rt) { glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rt->buffers.diffuse); - glGenRenderbuffers(1, &rt->buffers.specular); - glBindRenderbuffer(GL_RENDERBUFFER, rt->buffers.specular); + if (!rt->flags[RENDER_TARGET_NO_3D_EFFECTS]) { - if (msaa == 0) - glRenderbufferStorage(GL_RENDERBUFFER, color_internal_format, rt->width, rt->height); - else - glRenderbufferStorageMultisample(GL_RENDERBUFFER, msaa, color_internal_format, rt->width, rt->height); + glGenRenderbuffers(1, &rt->buffers.specular); + glBindRenderbuffer(GL_RENDERBUFFER, rt->buffers.specular); - glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_RENDERBUFFER, rt->buffers.specular); + if (msaa == 0) + glRenderbufferStorage(GL_RENDERBUFFER, color_internal_format, rt->width, rt->height); + else + glRenderbufferStorageMultisample(GL_RENDERBUFFER, msaa, color_internal_format, rt->width, rt->height); - glGenRenderbuffers(1, &rt->buffers.normal_rough); - glBindRenderbuffer(GL_RENDERBUFFER, rt->buffers.normal_rough); + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_RENDERBUFFER, rt->buffers.specular); - if (msaa == 0) - glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, rt->width, rt->height); - else - glRenderbufferStorageMultisample(GL_RENDERBUFFER, msaa, GL_RGBA8, rt->width, rt->height); + glGenRenderbuffers(1, &rt->buffers.normal_rough); + glBindRenderbuffer(GL_RENDERBUFFER, rt->buffers.normal_rough); - glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, GL_RENDERBUFFER, rt->buffers.normal_rough); + if (msaa == 0) + glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, rt->width, rt->height); + else + glRenderbufferStorageMultisample(GL_RENDERBUFFER, msaa, GL_RGBA8, rt->width, rt->height); - glGenRenderbuffers(1, &rt->buffers.sss); - glBindRenderbuffer(GL_RENDERBUFFER, rt->buffers.sss); + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, GL_RENDERBUFFER, rt->buffers.normal_rough); - if (msaa == 0) - glRenderbufferStorage(GL_RENDERBUFFER, GL_R8, rt->width, rt->height); - else - glRenderbufferStorageMultisample(GL_RENDERBUFFER, msaa, GL_R8, rt->width, rt->height); + glGenRenderbuffers(1, &rt->buffers.sss); + glBindRenderbuffer(GL_RENDERBUFFER, rt->buffers.sss); - glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT3, GL_RENDERBUFFER, rt->buffers.sss); + if (msaa == 0) + glRenderbufferStorage(GL_RENDERBUFFER, GL_R8, rt->width, rt->height); + else + glRenderbufferStorageMultisample(GL_RENDERBUFFER, msaa, GL_R8, rt->width, rt->height); - GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); - glBindFramebuffer(GL_FRAMEBUFFER, RasterizerStorageGLES3::system_fbo); + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT3, GL_RENDERBUFFER, rt->buffers.sss); - if (status != GL_FRAMEBUFFER_COMPLETE) { - printf("err status: %x\n", status); - _render_target_clear(rt); - ERR_FAIL_COND(status != GL_FRAMEBUFFER_COMPLETE); + GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); + glBindFramebuffer(GL_FRAMEBUFFER, RasterizerStorageGLES3::system_fbo); + + if (status != GL_FRAMEBUFFER_COMPLETE) { + printf("err status: %x\n", status); + _render_target_clear(rt); + ERR_FAIL_COND(status != GL_FRAMEBUFFER_COMPLETE); + } + + glBindRenderbuffer(GL_RENDERBUFFER, 0); + + // effect resolver + + glGenFramebuffers(1, &rt->buffers.effect_fbo); + glBindFramebuffer(GL_FRAMEBUFFER, rt->buffers.effect_fbo); + + glGenTextures(1, &rt->buffers.effect); + glBindTexture(GL_TEXTURE_2D, rt->buffers.effect); + glTexImage2D(GL_TEXTURE_2D, 0, color_internal_format, rt->width, rt->height, 0, + color_format, color_type, NULL); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, + GL_TEXTURE_2D, rt->buffers.effect, 0); + + if (status != GL_FRAMEBUFFER_COMPLETE) { + printf("err status: %x\n", status); + _render_target_clear(rt); + ERR_FAIL_COND(status != GL_FRAMEBUFFER_COMPLETE); + } + + glBindFramebuffer(GL_FRAMEBUFFER, RasterizerStorageGLES3::system_fbo); + + if (status != GL_FRAMEBUFFER_COMPLETE) { + _render_target_clear(rt); + ERR_FAIL_COND(status != GL_FRAMEBUFFER_COMPLETE); + } + + ///////////////// ssao + + //AO strength textures + for (int i = 0; i < 2; i++) { + + glGenFramebuffers(1, &rt->effects.ssao.blur_fbo[i]); + glBindFramebuffer(GL_FRAMEBUFFER, rt->effects.ssao.blur_fbo[i]); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, + GL_TEXTURE_2D, rt->depth, 0); + + glGenTextures(1, &rt->effects.ssao.blur_red[i]); + glBindTexture(GL_TEXTURE_2D, rt->effects.ssao.blur_red[i]); + + glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, rt->width, rt->height, 0, GL_RED, GL_UNSIGNED_BYTE, NULL); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, rt->effects.ssao.blur_red[i], 0); + + status = glCheckFramebufferStatus(GL_FRAMEBUFFER); + if (status != GL_FRAMEBUFFER_COMPLETE) { + _render_target_clear(rt); + ERR_FAIL_COND(status != GL_FRAMEBUFFER_COMPLETE); + } + } + //5 mip levels for depth texture, but base is read separately + + glGenTextures(1, &rt->effects.ssao.linear_depth); + glBindTexture(GL_TEXTURE_2D, rt->effects.ssao.linear_depth); + + int ssao_w = rt->width / 2; + int ssao_h = rt->height / 2; + + for (int i = 0; i < 4; i++) { //5, but 4 mips, base is read directly to save bw + + glTexImage2D(GL_TEXTURE_2D, i, GL_R16UI, ssao_w, ssao_h, 0, GL_RED_INTEGER, GL_UNSIGNED_SHORT, NULL); + ssao_w >>= 1; + ssao_h >>= 1; + } + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 3); + + for (int i = 0; i < 4; i++) { //5, but 4 mips, base is read directly to save bw + + GLuint fbo; + glGenFramebuffers(1, &fbo); + glBindFramebuffer(GL_FRAMEBUFFER, fbo); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, rt->effects.ssao.linear_depth, i); + rt->effects.ssao.depth_mipmap_fbos.push_back(fbo); + } + + //////Exposure + + glGenFramebuffers(1, &rt->exposure.fbo); + glBindFramebuffer(GL_FRAMEBUFFER, rt->exposure.fbo); + + glGenTextures(1, &rt->exposure.color); + glBindTexture(GL_TEXTURE_2D, rt->exposure.color); + glTexImage2D(GL_TEXTURE_2D, 0, GL_R32F, 1, 1, 0, GL_RED, GL_FLOAT, NULL); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, rt->exposure.color, 0); + + status = glCheckFramebufferStatus(GL_FRAMEBUFFER); + if (status != GL_FRAMEBUFFER_COMPLETE) { + _render_target_clear(rt); + ERR_FAIL_COND(status != GL_FRAMEBUFFER_COMPLETE); + } } + } - glBindRenderbuffer(GL_RENDERBUFFER, 0); - - // effect resolver - - glGenFramebuffers(1, &rt->buffers.effect_fbo); - glBindFramebuffer(GL_FRAMEBUFFER, rt->buffers.effect_fbo); - - glGenTextures(1, &rt->buffers.effect); - glBindTexture(GL_TEXTURE_2D, rt->buffers.effect); - glTexImage2D(GL_TEXTURE_2D, 0, color_internal_format, rt->width, rt->height, 0, - color_format, color_type, NULL); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, - GL_TEXTURE_2D, rt->buffers.effect, 0); - - if (status != GL_FRAMEBUFFER_COMPLETE) { - printf("err status: %x\n", status); - _render_target_clear(rt); - ERR_FAIL_COND(status != GL_FRAMEBUFFER_COMPLETE); - } - - glBindFramebuffer(GL_FRAMEBUFFER, RasterizerStorageGLES3::system_fbo); - - if (status != GL_FRAMEBUFFER_COMPLETE) { - _render_target_clear(rt); - ERR_FAIL_COND(status != GL_FRAMEBUFFER_COMPLETE); - } + if (!rt->flags[RENDER_TARGET_NO_SAMPLING]) { for (int i = 0; i < 2; i++) { @@ -5738,7 +5818,7 @@ void RasterizerStorageGLES3::_render_target_allocate(RenderTarget *rt) { glBindFramebuffer(GL_FRAMEBUFFER, mm.fbo); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, rt->effects.mip_maps[i].color, j); - status = glCheckFramebufferStatus(GL_FRAMEBUFFER); + GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); if (status != GL_FRAMEBUFFER_COMPLETE) { _render_target_clear(rt); ERR_FAIL_COND(status != GL_FRAMEBUFFER_COMPLETE); @@ -5758,79 +5838,6 @@ void RasterizerStorageGLES3::_render_target_allocate(RenderTarget *rt) { glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); } - ///////////////// ssao - - //AO strength textures - for (int i = 0; i < 2; i++) { - - glGenFramebuffers(1, &rt->effects.ssao.blur_fbo[i]); - glBindFramebuffer(GL_FRAMEBUFFER, rt->effects.ssao.blur_fbo[i]); - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, - GL_TEXTURE_2D, rt->depth, 0); - - glGenTextures(1, &rt->effects.ssao.blur_red[i]); - glBindTexture(GL_TEXTURE_2D, rt->effects.ssao.blur_red[i]); - - glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, rt->width, rt->height, 0, GL_RED, GL_UNSIGNED_BYTE, NULL); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, rt->effects.ssao.blur_red[i], 0); - - status = glCheckFramebufferStatus(GL_FRAMEBUFFER); - if (status != GL_FRAMEBUFFER_COMPLETE) { - _render_target_clear(rt); - ERR_FAIL_COND(status != GL_FRAMEBUFFER_COMPLETE); - } - } - //5 mip levels for depth texture, but base is read separately - - glGenTextures(1, &rt->effects.ssao.linear_depth); - glBindTexture(GL_TEXTURE_2D, rt->effects.ssao.linear_depth); - - int ssao_w = rt->width / 2; - int ssao_h = rt->height / 2; - - for (int i = 0; i < 4; i++) { //5, but 4 mips, base is read directly to save bw - - glTexImage2D(GL_TEXTURE_2D, i, GL_R16UI, ssao_w, ssao_h, 0, GL_RED_INTEGER, GL_UNSIGNED_SHORT, NULL); - ssao_w >>= 1; - ssao_h >>= 1; - } - - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 3); - - for (int i = 0; i < 4; i++) { //5, but 4 mips, base is read directly to save bw - - GLuint fbo; - glGenFramebuffers(1, &fbo); - glBindFramebuffer(GL_FRAMEBUFFER, fbo); - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, rt->effects.ssao.linear_depth, i); - rt->effects.ssao.depth_mipmap_fbos.push_back(fbo); - } - - //////Exposure - - glGenFramebuffers(1, &rt->exposure.fbo); - glBindFramebuffer(GL_FRAMEBUFFER, rt->exposure.fbo); - - glGenTextures(1, &rt->exposure.color); - glBindTexture(GL_TEXTURE_2D, rt->exposure.color); - glTexImage2D(GL_TEXTURE_2D, 0, GL_R32F, 1, 1, 0, GL_RED, GL_FLOAT, NULL); - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, rt->exposure.color, 0); - - status = glCheckFramebufferStatus(GL_FRAMEBUFFER); - if (status != GL_FRAMEBUFFER_COMPLETE) { - _render_target_clear(rt); - ERR_FAIL_COND(status != GL_FRAMEBUFFER_COMPLETE); - } } } @@ -5855,9 +5862,10 @@ RID RasterizerStorageGLES3::render_target_create() { t->srgb = false; t->total_data_size = 0; t->ignore_mipmaps = false; - t->mipmaps = 0; + t->mipmaps = 1; t->active = true; t->tex_id = 0; + t->render_target = rt; rt->texture = texture_owner.make_rid(t); @@ -5894,8 +5902,10 @@ void RasterizerStorageGLES3::render_target_set_flag(RID p_render_target, RenderT rt->flags[p_flag] = p_value; switch (p_flag) { + case RENDER_TARGET_HDR: case RENDER_TARGET_NO_3D: - case RENDER_TARGET_TRANSPARENT: { + case RENDER_TARGET_NO_SAMPLING: + case RENDER_TARGET_NO_3D_EFFECTS: { //must reset for these formats _render_target_clear(rt); _render_target_allocate(rt); @@ -6337,9 +6347,6 @@ bool RasterizerStorageGLES3::has_os_feature(const String &p_feature) const { void RasterizerStorageGLES3::initialize() { - config.render_arch = RENDER_ARCH_DESKTOP; - //config.fbo_deferred=int(Globals::get_singleton()->get("rendering/gles3/lighting_technique")); - RasterizerStorageGLES3::system_fbo = 0; //// extensions config diff --git a/drivers/gles3/rasterizer_storage_gles3.h b/drivers/gles3/rasterizer_storage_gles3.h index c8edeaefbfd..9af342301cd 100644 --- a/drivers/gles3/rasterizer_storage_gles3.h +++ b/drivers/gles3/rasterizer_storage_gles3.h @@ -61,8 +61,6 @@ public: struct Config { - RenderArchitecture render_arch; - bool shrink_textures_x2; bool use_fast_texture_filter; bool use_anisotropic_filter; @@ -1209,9 +1207,10 @@ public: flags[RENDER_TARGET_VFLIP] = false; flags[RENDER_TARGET_TRANSPARENT] = false; + flags[RENDER_TARGET_NO_3D_EFFECTS] = false; flags[RENDER_TARGET_NO_3D] = false; - flags[RENDER_TARGET_HDR] = true; flags[RENDER_TARGET_NO_SAMPLING] = false; + flags[RENDER_TARGET_HDR] = true; last_exposure_tick = 0; } diff --git a/drivers/gles3/shaders/copy.glsl b/drivers/gles3/shaders/copy.glsl index 621ae83162c..4c8648903e4 100644 --- a/drivers/gles3/shaders/copy.glsl +++ b/drivers/gles3/shaders/copy.glsl @@ -23,6 +23,10 @@ void main() { cube_interp = cube_in; #else uv_interp = uv_in; +#ifdef V_FLIP + uv_interp.y = 1.0-uv_interp.y; +#endif + #endif uv2_interp = uv2_in; gl_Position = vertex_attrib; diff --git a/drivers/gles3/shaders/scene.glsl b/drivers/gles3/shaders/scene.glsl index 8965f475d74..60efc953f99 100644 --- a/drivers/gles3/shaders/scene.glsl +++ b/drivers/gles3/shaders/scene.glsl @@ -1709,7 +1709,7 @@ FRAGMENT_SHADER_CODE sss_buffer = sss_strength; #endif -#else +#else //USE_MULTIPLE_RENDER_TARGETS #ifdef SHADELESS diff --git a/drivers/gles3/shaders/tonemap.glsl b/drivers/gles3/shaders/tonemap.glsl index b2615fa29c5..3ce2edf4e99 100644 --- a/drivers/gles3/shaders/tonemap.glsl +++ b/drivers/gles3/shaders/tonemap.glsl @@ -6,12 +6,13 @@ layout(location=4) in vec2 uv_in; out vec2 uv_interp; - - void main() { gl_Position = vertex_attrib; uv_interp = uv_in; +#ifdef V_FLIP + uv_interp.y = 1.0-uv_interp.y; +#endif } diff --git a/drivers/png/resource_saver_png.cpp b/drivers/png/resource_saver_png.cpp index 1700603489c..0d7e1d9d72b 100644 --- a/drivers/png/resource_saver_png.cpp +++ b/drivers/png/resource_saver_png.cpp @@ -55,41 +55,6 @@ Error ResourceSaverPNG::save(const String &p_path, const RES &p_resource, uint32 Error err = save_image(p_path, img); if (err == OK) { - - bool global_filter = GlobalConfig::get_singleton()->get("image_loader/filter"); - bool global_mipmaps = GlobalConfig::get_singleton()->get("image_loader/gen_mipmaps"); - bool global_repeat = GlobalConfig::get_singleton()->get("image_loader/repeat"); - - String text; - - if (global_filter != bool(texture->get_flags() & Texture::FLAG_FILTER)) { - text += bool(texture->get_flags() & Texture::FLAG_FILTER) ? "filter=true\n" : "filter=false\n"; - } - if (global_mipmaps != bool(texture->get_flags() & Texture::FLAG_MIPMAPS)) { - text += bool(texture->get_flags() & Texture::FLAG_MIPMAPS) ? "gen_mipmaps=true\n" : "gen_mipmaps=false\n"; - } - if (global_repeat != bool(texture->get_flags() & Texture::FLAG_REPEAT)) { - text += bool(texture->get_flags() & Texture::FLAG_REPEAT) ? "repeat=true\n" : "repeat=false\n"; - } - if (bool(texture->get_flags() & Texture::FLAG_ANISOTROPIC_FILTER)) { - text += "anisotropic=true\n"; - } - if (bool(texture->get_flags() & Texture::FLAG_CONVERT_TO_LINEAR)) { - text += "tolinear=true\n"; - } - if (bool(texture->get_flags() & Texture::FLAG_MIRRORED_REPEAT)) { - text += "mirroredrepeat=true\n"; - } - - if (text != "" || FileAccess::exists(p_path + ".flags")) { - - FileAccess *f = FileAccess::open(p_path + ".flags", FileAccess::WRITE); - if (f) { - - f->store_string(text); - memdelete(f); - } - } } return err; diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 30e6d4ba935..9d6c599a4e2 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -823,56 +823,54 @@ void EditorNode::_save_scene_with_preview(String p_file) { } save.step(TTR("Creating Thumbnail"), 1); //current view? - int screen = -1; - for (int i = 0; i < editor_table.size(); i++) { - if (editor_plugin_screen == editor_table[i]) { - screen = i; - break; + + Ref img; + if (is2d) { + img = scene_root->get_texture()->get_data(); + } else { + img = SpatialEditor::get_singleton()->get_editor_viewport(0)->get_viewport_node()->get_texture()->get_data(); + } + + if (img.is_valid()) { + save.step(TTR("Creating Thumbnail"), 2); + save.step(TTR("Creating Thumbnail"), 3); + + int preview_size = EditorSettings::get_singleton()->get("filesystem/file_dialog/thumbnail_size"); + preview_size *= EDSCALE; + int width, height; + if (img->get_width() > preview_size && img->get_width() >= img->get_height()) { + + width = preview_size; + height = img->get_height() * preview_size / img->get_width(); + } else if (img->get_height() > preview_size && img->get_height() >= img->get_width()) { + + height = preview_size; + width = img->get_width() * preview_size / img->get_height(); + } else { + + width = img->get_width(); + height = img->get_height(); } + + img->convert(Image::FORMAT_RGB8); + img->resize(width, height); + img->flip_y(); + + //save thumbnail directly, as thumbnailer may not update due to actual scene not changing md5 + String temp_path = EditorSettings::get_singleton()->get_settings_path().plus_file("tmp"); + String cache_base = GlobalConfig::get_singleton()->globalize_path(p_file).md5_text(); + cache_base = temp_path.plus_file("resthumb-" + cache_base); + + //does not have it, try to load a cached thumbnail + + String file = cache_base + ".png"; + + img->save_png(file); } - _editor_select(is2d ? EDITOR_2D : EDITOR_3D); - - save.step(TTR("Creating Thumbnail"), 2); - save.step(TTR("Creating Thumbnail"), 3); -#if 0 - Image img = VS::get_singleton()->viewport_texture(scree_capture(viewport); - int preview_size = EditorSettings::get_singleton()->get("filesystem/file_dialog/thumbnail_size"); - preview_size*=EDSCALE; - int width,height; - if (img.get_width() > preview_size && img.get_width() >= img.get_height()) { - - width=preview_size; - height = img.get_height() * preview_size / img.get_width(); - } else if (img.get_height() > preview_size && img.get_height() >= img.get_width()) { - - height=preview_size; - width = img.get_width() * preview_size / img.get_height(); - } else { - - width=img.get_width(); - height=img.get_height(); - } - - img.convert(Image::FORMAT_RGB8); - img.resize(width,height); - - String pfile = EditorSettings::get_singleton()->get_settings_path().plus_file("tmp/last_scene_preview.png"); - img.save_png(pfile); - Vector imgdata = FileAccess::get_file_as_array(pfile); - - //print_line("img data is "+itos(imgdata.size())); - - if (editor_data.get_edited_scene_import_metadata().is_null()) - editor_data.set_edited_scene_import_metadata(Ref( memnew( ResourceImportMetadata ) ) ); - editor_data.get_edited_scene_import_metadata()->set_option("thumbnail",imgdata); -#endif - //tamanio tel thumbnail - if (screen != -1) { - _editor_select(screen); - } save.step(TTR("Saving Scene"), 4); _save_scene(p_file); + EditorResourcePreview::get_singleton()->check_for_invalidation(p_file); } void EditorNode::_save_scene(String p_file, int idx) { @@ -6057,14 +6055,13 @@ EditorNode::EditorNode() { plugin_init_callbacks[i](); } - /*resource_preview->add_preview_generator( Ref( memnew(EditorTexturePreviewPlugin ))); - resource_preview->add_preview_generator( Ref( memnew(EditorPackedScenePreviewPlugin ))); - resource_preview->add_preview_generator( Ref( memnew(EditorMaterialPreviewPlugin ))); - resource_preview->add_preview_generator( Ref( memnew(EditorScriptPreviewPlugin ))); - resource_preview->add_preview_generator( Ref( memnew(EditorSamplePreviewPlugin ))); - resource_preview->add_preview_generator( Ref( memnew(EditorMeshPreviewPlugin ))); - resource_preview->add_preview_generator( Ref( memnew(EditorBitmapPreviewPlugin ))); -*/ + resource_preview->add_preview_generator(Ref(memnew(EditorTexturePreviewPlugin))); + resource_preview->add_preview_generator(Ref(memnew(EditorPackedScenePreviewPlugin))); + resource_preview->add_preview_generator(Ref(memnew(EditorMaterialPreviewPlugin))); + resource_preview->add_preview_generator(Ref(memnew(EditorScriptPreviewPlugin))); + //resource_preview->add_preview_generator( Ref( memnew(EditorSamplePreviewPlugin ))); + resource_preview->add_preview_generator(Ref(memnew(EditorMeshPreviewPlugin))); + resource_preview->add_preview_generator(Ref(memnew(EditorBitmapPreviewPlugin))); circle_step_msec = OS::get_singleton()->get_ticks_msec(); circle_step_frame = Engine::get_singleton()->get_frames_drawn(); diff --git a/editor/editor_resource_preview.cpp b/editor/editor_resource_preview.cpp index 0b1887e8a25..5d68de3bb68 100644 --- a/editor/editor_resource_preview.cpp +++ b/editor/editor_resource_preview.cpp @@ -190,7 +190,7 @@ void EditorResourcePreview::_thread() { } else { preview_mutex->unlock(); - Ref texture; + Ref texture; //print_line("pop from queue "+item.path); @@ -229,6 +229,7 @@ void EditorResourcePreview::_thread() { bool cache_valid = true; if (tsize != thumbnail_size) { + cache_valid = false; memdelete(f); } else if (last_modtime != modtime) { @@ -240,6 +241,7 @@ void EditorResourcePreview::_thread() { if (last_md5 != md5) { cache_valid = false; + } else { //update modified time @@ -252,14 +254,20 @@ void EditorResourcePreview::_thread() { memdelete(f); } - cache_valid = false; + //cache_valid = false; if (cache_valid) { - texture = ResourceLoader::load(cache_base + ".png", "ImageTexture", true); - if (!texture.is_valid()) { + Ref img; + img.instance(); + + if (img->load(cache_base + ".png") != OK) { //well fuck cache_valid = false; + } else { + + texture.instance(); + texture->create_from_image(img, Texture::FLAG_FILTER); } } diff --git a/editor/import/resource_importer_obj.cpp b/editor/import/resource_importer_obj.cpp index 8d0f3267f7a..342808f9e13 100644 --- a/editor/import/resource_importer_obj.cpp +++ b/editor/import/resource_importer_obj.cpp @@ -54,7 +54,7 @@ String ResourceImporterOBJ::get_save_extension() const { String ResourceImporterOBJ::get_resource_type() const { - return "Mesh"; + return "ArrayMesh"; } bool ResourceImporterOBJ::get_option_visibility(const String &p_option, const Map &p_options) const { diff --git a/editor/plugins/editor_preview_plugins.cpp b/editor/plugins/editor_preview_plugins.cpp index db8060d5915..0b08fcfce89 100644 --- a/editor/plugins/editor_preview_plugins.cpp +++ b/editor/plugins/editor_preview_plugins.cpp @@ -39,239 +39,226 @@ #include "scene/resources/bit_mask.h" #include "scene/resources/mesh.h" -#if 0 -bool EditorTexturePreviewPlugin::handles(const String& p_type) const { +bool EditorTexturePreviewPlugin::handles(const String &p_type) const { - return (ClassDB::is_type(p_type,"ImageTexture") || ClassDB::is_type(p_type, "AtlasTexture")); + return ClassDB::is_parent_class(p_type, "Texture"); } -Ref EditorTexturePreviewPlugin::generate(const RES& p_from) { +Ref EditorTexturePreviewPlugin::generate(const RES &p_from) { - Image img; + Ref img; Ref atex = p_from; if (atex.is_valid()) { - Ref tex = atex->get_atlas(); + Ref tex = atex->get_atlas(); if (!tex.is_valid()) { return Ref(); } - Image atlas = tex->get_data(); - img = atlas.get_rect(atex->get_region()); - } - else { - Ref tex = p_from; + Ref atlas = tex->get_data(); + img = atlas->get_rect(atex->get_region()); + } else { + Ref tex = p_from; img = tex->get_data(); } - if (img.empty()) + if (img.is_null() || img->empty()) return Ref(); - img.clear_mipmaps(); + img->clear_mipmaps(); int thumbnail_size = EditorSettings::get_singleton()->get("filesystem/file_dialog/thumbnail_size"); - thumbnail_size*=EDSCALE; - if (img.is_compressed()) { - if (img.decompress()!=OK) + thumbnail_size *= EDSCALE; + if (img->is_compressed()) { + if (img->decompress() != OK) return Ref(); - } else if (img.get_format()!=Image::FORMAT_RGB8 && img.get_format()!=Image::FORMAT_RGBA8) { - img.convert(Image::FORMAT_RGBA8); + } else if (img->get_format() != Image::FORMAT_RGB8 && img->get_format() != Image::FORMAT_RGBA8) { + img->convert(Image::FORMAT_RGBA8); } - int width,height; - if (img.get_width() > thumbnail_size && img.get_width() >= img.get_height()) { + int width, height; + if (img->get_width() > thumbnail_size && img->get_width() >= img->get_height()) { - width=thumbnail_size; - height = img.get_height() * thumbnail_size / img.get_width(); - } else if (img.get_height() > thumbnail_size && img.get_height() >= img.get_width()) { + width = thumbnail_size; + height = img->get_height() * thumbnail_size / img->get_width(); + } else if (img->get_height() > thumbnail_size && img->get_height() >= img->get_width()) { - height=thumbnail_size; - width = img.get_width() * thumbnail_size / img.get_height(); - } else { + height = thumbnail_size; + width = img->get_width() * thumbnail_size / img->get_height(); + } else { - width=img.get_width(); - height=img.get_height(); + width = img->get_width(); + height = img->get_height(); } - img.resize(width,height); + img->resize(width, height); - Ref ptex = Ref( memnew( ImageTexture )); + Ref ptex = Ref(memnew(ImageTexture)); - ptex->create_from_image(img,0); + ptex->create_from_image(img, 0); return ptex; - } EditorTexturePreviewPlugin::EditorTexturePreviewPlugin() { - - } //////////////////////////////////////////////////////////////////////////// -bool EditorBitmapPreviewPlugin::handles(const String& p_type) const { +bool EditorBitmapPreviewPlugin::handles(const String &p_type) const { - return ClassDB::is_type(p_type,"BitMap"); + return ClassDB::is_parent_class(p_type, "BitMap"); } -Ref EditorBitmapPreviewPlugin::generate(const RES& p_from) { +Ref EditorBitmapPreviewPlugin::generate(const RES &p_from) { - Ref bm =p_from; + Ref bm = p_from; - if (bm->get_size()==Size2()) { + if (bm->get_size() == Size2()) { return Ref(); } PoolVector data; - data.resize(bm->get_size().width*bm->get_size().height); + data.resize(bm->get_size().width * bm->get_size().height); { - PoolVector::Write w=data.write(); + PoolVector::Write w = data.write(); - for(int i=0;iget_size().width;i++) { - for(int j=0;jget_size().height;j++) { - if (bm->get_bit(Point2i(i,j))) { - w[j*bm->get_size().width+i]=255; + for (int i = 0; i < bm->get_size().width; i++) { + for (int j = 0; j < bm->get_size().height; j++) { + if (bm->get_bit(Point2i(i, j))) { + w[j * bm->get_size().width + i] = 255; } else { - w[j*bm->get_size().width+i]=0; - + w[j * bm->get_size().width + i] = 0; } } - } } - - Image img(bm->get_size().width,bm->get_size().height,0,Image::FORMAT_L8,data); + Ref img; + img.instance(); + img->create(bm->get_size().width, bm->get_size().height, 0, Image::FORMAT_L8, data); int thumbnail_size = EditorSettings::get_singleton()->get("filesystem/file_dialog/thumbnail_size"); - thumbnail_size*=EDSCALE; - if (img.is_compressed()) { - if (img.decompress()!=OK) + thumbnail_size *= EDSCALE; + if (img->is_compressed()) { + if (img->decompress() != OK) return Ref(); - } else if (img.get_format()!=Image::FORMAT_RGB8 && img.get_format()!=Image::FORMAT_RGBA8) { - img.convert(Image::FORMAT_RGBA8); + } else if (img->get_format() != Image::FORMAT_RGB8 && img->get_format() != Image::FORMAT_RGBA8) { + img->convert(Image::FORMAT_RGBA8); } - int width,height; - if (img.get_width() > thumbnail_size && img.get_width() >= img.get_height()) { + int width, height; + if (img->get_width() > thumbnail_size && img->get_width() >= img->get_height()) { - width=thumbnail_size; - height = img.get_height() * thumbnail_size / img.get_width(); - } else if (img.get_height() > thumbnail_size && img.get_height() >= img.get_width()) { + width = thumbnail_size; + height = img->get_height() * thumbnail_size / img->get_width(); + } else if (img->get_height() > thumbnail_size && img->get_height() >= img->get_width()) { - height=thumbnail_size; - width = img.get_width() * thumbnail_size / img.get_height(); - } else { + height = thumbnail_size; + width = img->get_width() * thumbnail_size / img->get_height(); + } else { - width=img.get_width(); - height=img.get_height(); + width = img->get_width(); + height = img->get_height(); } - img.resize(width,height); + img->resize(width, height); - Ref ptex = Ref( memnew( ImageTexture )); + Ref ptex = Ref(memnew(ImageTexture)); - ptex->create_from_image(img,0); + ptex->create_from_image(img, 0); return ptex; - } EditorBitmapPreviewPlugin::EditorBitmapPreviewPlugin() { - - } /////////////////////////////////////////////////////////////////////////// +bool EditorPackedScenePreviewPlugin::handles(const String &p_type) const { -Ref EditorPackedScenePreviewPlugin::_gen_from_imd(Ref p_imd) { + return ClassDB::is_parent_class(p_type, "PackedScene"); +} +Ref EditorPackedScenePreviewPlugin::generate(const RES &p_from) { - if (p_imd.is_null()) { + return generate_from_path(p_from->get_path()); +} + +Ref EditorPackedScenePreviewPlugin::generate_from_path(const String &p_path) { + + String temp_path = EditorSettings::get_singleton()->get_settings_path().plus_file("tmp"); + String cache_base = GlobalConfig::get_singleton()->globalize_path(p_path).md5_text(); + cache_base = temp_path.plus_file("resthumb-" + cache_base); + + //does not have it, try to load a cached thumbnail + + String path = cache_base + ".png"; + + if (!FileAccess::exists(path)) + return Ref(); + + Ref img; + img.instance(); + Error err = img->load(path); + if (err == OK) { + + Ref ptex = Ref(memnew(ImageTexture)); + + ptex->create_from_image(img, 0); + return ptex; + + } else { return Ref(); } - - if (!p_imd->has_option("thumbnail")) - return Ref(); - - Variant tn = p_imd->get_option("thumbnail"); - //print_line(Variant::get_type_name(tn.get_type())); - PoolVector thumbnail = tn; - - int len = thumbnail.size(); - if (len==0) - return Ref(); - - - PoolVector::Read r = thumbnail.read(); - - Image img(r.ptr(),len); - if (img.empty()) - return Ref(); - - Ref ptex = Ref( memnew( ImageTexture )); - ptex->create_from_image(img,0); - return ptex; - -} - -bool EditorPackedScenePreviewPlugin::handles(const String& p_type) const { - - return ClassDB::is_type(p_type,"PackedScene"); -} -Ref EditorPackedScenePreviewPlugin::generate(const RES& p_from) { - - Ref imd = p_from->get_import_metadata(); - return _gen_from_imd(imd); -} - -Ref EditorPackedScenePreviewPlugin::generate_from_path(const String& p_path) { - - Ref imd = ResourceLoader::load_import_metadata(p_path); - return _gen_from_imd(imd); } EditorPackedScenePreviewPlugin::EditorPackedScenePreviewPlugin() { - } ////////////////////////////////////////////////////////////////// -bool EditorMaterialPreviewPlugin::handles(const String& p_type) const { +void EditorMaterialPreviewPlugin::_preview_done(const Variant &p_udata) { - return ClassDB::is_type(p_type,"Material"); //any material + preview_done = true; } -Ref EditorMaterialPreviewPlugin::generate(const RES& p_from) { +void EditorMaterialPreviewPlugin::_bind_methods() { + + ClassDB::bind_method("_preview_done", &EditorMaterialPreviewPlugin::_preview_done); +} + +bool EditorMaterialPreviewPlugin::handles(const String &p_type) const { + + return ClassDB::is_parent_class(p_type, "Material"); //any material +} + +Ref EditorMaterialPreviewPlugin::generate(const RES &p_from) { Ref material = p_from; - ERR_FAIL_COND_V(material.is_null(),Ref()); + ERR_FAIL_COND_V(material.is_null(), Ref()); - VS::get_singleton()->mesh_surface_set_material(sphere,0,material->get_rid()); + VS::get_singleton()->mesh_surface_set_material(sphere, 0, material->get_rid()); - VS::get_singleton()->viewport_queue_screen_capture(viewport); - VS::get_singleton()->viewport_set_render_target_update_mode(viewport,VS::RENDER_TARGET_UPDATE_ONCE); //once used for capture + VS::get_singleton()->viewport_set_update_mode(viewport, VS::VIEWPORT_UPDATE_ONCE); //once used for capture //print_line("queue capture!"); - Image img; - int timeout=1000; - while(timeout) { - //print_line("try capture?"); + preview_done = false; + VS::get_singleton()->request_frame_drawn_callback(this, "_preview_done", Variant()); + + while (!preview_done) { OS::get_singleton()->delay_usec(10); - img = VS::get_singleton()->viewport_get_screen_capture(viewport); - if (!img.empty()) - break; - timeout--; } - //print_line("captured!"); - VS::get_singleton()->mesh_surface_set_material(sphere,0,RID()); + Ref img = VS::get_singleton()->VS::get_singleton()->texture_get_data(viewport_texture); + VS::get_singleton()->mesh_surface_set_material(sphere, 0, RID()); + + ERR_FAIL_COND_V(!img.is_valid(), Ref()); int thumbnail_size = EditorSettings::get_singleton()->get("filesystem/file_dialog/thumbnail_size"); - thumbnail_size*=EDSCALE; - img.resize(thumbnail_size,thumbnail_size); - - Ref ptex = Ref( memnew( ImageTexture )); - ptex->create_from_image(img,0); + thumbnail_size *= EDSCALE; + img->convert(Image::FORMAT_RGBA8); + img->resize(thumbnail_size, thumbnail_size); + Ref ptex = Ref(memnew(ImageTexture)); + ptex->create_from_image(img, 0); return ptex; } @@ -280,70 +267,68 @@ EditorMaterialPreviewPlugin::EditorMaterialPreviewPlugin() { scenario = VS::get_singleton()->scenario_create(); viewport = VS::get_singleton()->viewport_create(); - VS::get_singleton()->viewport_set_as_render_target(viewport,true); - VS::get_singleton()->viewport_set_render_target_update_mode(viewport,VS::RENDER_TARGET_UPDATE_DISABLED); - VS::get_singleton()->viewport_set_scenario(viewport,scenario); - VS::ViewportRect vr; - vr.x=0; - vr.y=0; - vr.width=128; - vr.height=128; - VS::get_singleton()->viewport_set_rect(viewport,vr); + VS::get_singleton()->viewport_set_update_mode(viewport, VS::VIEWPORT_UPDATE_DISABLED); + VS::get_singleton()->viewport_set_scenario(viewport, scenario); + VS::get_singleton()->viewport_set_size(viewport, 128, 128); + VS::get_singleton()->viewport_set_transparent_background(viewport, true); + VS::get_singleton()->viewport_set_active(viewport, true); + VS::get_singleton()->viewport_set_vflip(viewport, true); + viewport_texture = VS::get_singleton()->viewport_get_texture(viewport); camera = VS::get_singleton()->camera_create(); - VS::get_singleton()->viewport_attach_camera(viewport,camera); - VS::get_singleton()->camera_set_transform(camera,Transform(Matrix3(),Vector3(0,0,3))); - VS::get_singleton()->camera_set_perspective(camera,45,0.1,10); + VS::get_singleton()->viewport_attach_camera(viewport, camera); + VS::get_singleton()->camera_set_transform(camera, Transform(Basis(), Vector3(0, 0, 3))); + VS::get_singleton()->camera_set_perspective(camera, 45, 0.1, 10); light = VS::get_singleton()->light_create(VS::LIGHT_DIRECTIONAL); - light_instance = VS::get_singleton()->instance_create2(light,scenario); - VS::get_singleton()->instance_set_transform(light_instance,Transform().looking_at(Vector3(-1,-1,-1),Vector3(0,1,0))); + light_instance = VS::get_singleton()->instance_create2(light, scenario); + VS::get_singleton()->instance_set_transform(light_instance, Transform().looking_at(Vector3(-1, -1, -1), Vector3(0, 1, 0))); light2 = VS::get_singleton()->light_create(VS::LIGHT_DIRECTIONAL); - VS::get_singleton()->light_set_color(light2,VS::LIGHT_COLOR_DIFFUSE,Color(0.7,0.7,0.7)); - VS::get_singleton()->light_set_color(light2,VS::LIGHT_COLOR_SPECULAR,Color(0.0,0.0,0.0)); - light_instance2 = VS::get_singleton()->instance_create2(light2,scenario); + VS::get_singleton()->light_set_color(light2, Color(0.7, 0.7, 0.7)); + //VS::get_singleton()->light_set_color(light2, Color(0.7, 0.7, 0.7)); - VS::get_singleton()->instance_set_transform(light_instance2,Transform().looking_at(Vector3(0,1,0),Vector3(0,0,1))); + light_instance2 = VS::get_singleton()->instance_create2(light2, scenario); + + VS::get_singleton()->instance_set_transform(light_instance2, Transform().looking_at(Vector3(0, 1, 0), Vector3(0, 0, 1))); sphere = VS::get_singleton()->mesh_create(); - sphere_instance = VS::get_singleton()->instance_create2(sphere,scenario); + sphere_instance = VS::get_singleton()->instance_create2(sphere, scenario); - int lats=32; - int lons=32; - float radius=1.0; + int lats = 32; + int lons = 32; + float radius = 1.0; PoolVector vertices; PoolVector normals; PoolVector uvs; PoolVector tangents; - Matrix3 tt = Matrix3(Vector3(0,1,0),Math_PI*0.5); + Basis tt = Basis(Vector3(0, 1, 0), Math_PI * 0.5); - for(int i = 1; i <= lats; i++) { - double lat0 = Math_PI * (-0.5 + (double) (i - 1) / lats); - double z0 = Math::sin(lat0); - double zr0 = Math::cos(lat0); + for (int i = 1; i <= lats; i++) { + double lat0 = Math_PI * (-0.5 + (double)(i - 1) / lats); + double z0 = Math::sin(lat0); + double zr0 = Math::cos(lat0); - double lat1 = Math_PI * (-0.5 + (double) i / lats); + double lat1 = Math_PI * (-0.5 + (double)i / lats); double z1 = Math::sin(lat1); double zr1 = Math::cos(lat1); - for(int j = lons; j >= 1; j--) { + for (int j = lons; j >= 1; j--) { - double lng0 = 2 * Math_PI * (double) (j - 1) / lons; + double lng0 = 2 * Math_PI * (double)(j - 1) / lons; double x0 = Math::cos(lng0); double y0 = Math::sin(lng0); - double lng1 = 2 * Math_PI * (double) (j) / lons; + double lng1 = 2 * Math_PI * (double)(j) / lons; double x1 = Math::cos(lng1); double y1 = Math::sin(lng1); - - Vector3 v[4]={ - Vector3(x1 * zr0, z0, y1 *zr0), - Vector3(x1 * zr1, z1, y1 *zr1), - Vector3(x0 * zr1, z1, y0 *zr1), - Vector3(x0 * zr0, z0, y0 *zr0) + Vector3 v[4] = { + Vector3(x1 * zr0, z0, y1 * zr0), + Vector3(x1 * zr1, z1, y1 * zr1), + Vector3(x0 * zr1, z1, y0 * zr1), + Vector3(x0 * zr0, z0, y0 * zr0) }; #define ADD_POINT(m_idx) \ @@ -364,8 +349,6 @@ EditorMaterialPreviewPlugin::EditorMaterialPreviewPlugin() { tangents.push_back(1.0); \ } - - ADD_POINT(0); ADD_POINT(1); ADD_POINT(2); @@ -378,12 +361,11 @@ EditorMaterialPreviewPlugin::EditorMaterialPreviewPlugin() { Array arr; arr.resize(VS::ARRAY_MAX); - arr[VS::ARRAY_VERTEX]=vertices; - arr[VS::ARRAY_NORMAL]=normals; - arr[VS::ARRAY_TANGENT]=tangents; - arr[VS::ARRAY_TEX_UV]=uvs; - VS::get_singleton()->mesh_add_surface(sphere,VS::PRIMITIVE_TRIANGLES,arr); - + arr[VS::ARRAY_VERTEX] = vertices; + arr[VS::ARRAY_NORMAL] = normals; + arr[VS::ARRAY_TANGENT] = tangents; + arr[VS::ARRAY_TEX_UV] = uvs; + VS::get_singleton()->mesh_add_surface_from_arrays(sphere, VS::PRIMITIVE_TRIANGLES, arr); } EditorMaterialPreviewPlugin::~EditorMaterialPreviewPlugin() { @@ -397,30 +379,28 @@ EditorMaterialPreviewPlugin::~EditorMaterialPreviewPlugin() { VS::get_singleton()->free(light_instance2); VS::get_singleton()->free(camera); VS::get_singleton()->free(scenario); - } /////////////////////////////////////////////////////////////////////////// static bool _is_text_char(CharType c) { - return (c>='a' && c<='z') || (c>='A' && c<='Z') || (c>='0' && c<='9') || c=='_'; + return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_'; } -bool EditorScriptPreviewPlugin::handles(const String& p_type) const { +bool EditorScriptPreviewPlugin::handles(const String &p_type) const { - return ClassDB::is_type(p_type,"Script"); + return ClassDB::is_parent_class(p_type, "Script"); } -Ref EditorScriptPreviewPlugin::generate(const RES& p_from) { - +Ref EditorScriptPreviewPlugin::generate(const RES &p_from) { Ref