From 32713e60ab2c6ae1056e058b9d3a2cacca741595 Mon Sep 17 00:00:00 2001 From: marxin Date: Fri, 25 Jan 2019 11:49:06 +0100 Subject: [PATCH 1/2] Use placement new in texture_loader_pvr.cpp (#24417). Use constructor via placement new and swap colors directly. --- modules/pvr/texture_loader_pvr.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/modules/pvr/texture_loader_pvr.cpp b/modules/pvr/texture_loader_pvr.cpp index d3f2f3c272e..01e011e64c5 100644 --- a/modules/pvr/texture_loader_pvr.cpp +++ b/modules/pvr/texture_loader_pvr.cpp @@ -33,6 +33,7 @@ #include "RgbaBitmap.h" #include "core/os/file_access.h" #include +#include static void _pvrtc_decompress(Image *p_img); @@ -215,12 +216,10 @@ static void _compress_pvrtc4(Image *p_img) { int ofs, size, w, h; img->get_mipmap_offset_size_and_dimensions(i, ofs, size, w, h); Javelin::RgbaBitmap bm(w, h); - copymem(bm.GetData(), &r[ofs], size); - { + for (unsigned j = 0; j < size / 4; j++) { Javelin::ColorRgba *dp = bm.GetData(); - for (int j = 0; j < size / 4; j++) { - SWAP(dp[j].r, dp[j].b); - } + /* red and Green colors are swapped. */ + new (dp) Javelin::ColorRgba(r[ofs + 4 * j + 2], r[ofs + 4 * j + 1], r[ofs + 4 * j], r[ofs + 4 * j + 3]); } new_img->get_mipmap_offset_size_and_dimensions(i, ofs, size, w, h); From 3e4dab538656c0fb71ac0e2535a1e51c2b9ebe06 Mon Sep 17 00:00:00 2001 From: marxin Date: Fri, 25 Jan 2019 12:06:44 +0100 Subject: [PATCH 2/2] Use placement new in visual_server_scene.cpp (#24417). --- servers/visual/visual_server_scene.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/servers/visual/visual_server_scene.cpp b/servers/visual/visual_server_scene.cpp index 23ad2ec1ec0..4c8b9e03fd0 100644 --- a/servers/visual/visual_server_scene.cpp +++ b/servers/visual/visual_server_scene.cpp @@ -32,6 +32,7 @@ #include "core/os/os.h" #include "visual_server_global.h" #include "visual_server_raster.h" +#include /* CAMERA API */ RID VisualServerScene::camera_create() { @@ -1240,7 +1241,9 @@ void VisualServerScene::_update_instance_lightmap_captures(Instance *p_instance) //print_line("update captures for pos: " + p_instance->transform.origin); - zeromem(p_instance->lightmap_capture_data.ptrw(), 12 * sizeof(Color)); + for (int i = 0; i < 12; i++) + new (&p_instance->lightmap_capture_data.ptrw()[i]) Color; + //this could use some sort of blending.. for (List::Element *E = geom->lightmap_captures.front(); E; E = E->next()) { const PoolVector *octree = VSG::storage->lightmap_capture_get_octree_ptr(E->get()->base);