Merge pull request #36098 from godotengine/vulkan

Add initial Vulkan support, master branch goes UNSTABLE
This commit is contained in:
Rémi Verschelde 2020-02-11 16:01:55 +01:00 committed by GitHub
commit 1eb424ec95
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
739 changed files with 334595 additions and 12010 deletions

View file

@ -4,7 +4,6 @@ language: cpp
dist: xenial
stages:
- check
- build
env:
@ -21,7 +20,7 @@ cache:
matrix:
include:
- name: Static checks (clang-format) + Documentation checks
stage: check
stage: build
env: STATIC_CHECKS=yes
os: linux
compiler: gcc
@ -34,7 +33,7 @@ matrix:
- name: Linux editor (debug, GCC 9, with Mono)
stage: build
env: PLATFORM=x11 TOOLS=yes TARGET=debug CACHE_NAME=${PLATFORM}-tools-mono-gcc-9 MATRIX_EVAL="CC=gcc-9 && CXX=g++-9" EXTRA_ARGS="module_mono_enabled=yes mono_glue=no warnings=extra werror=yes"
env: PLATFORM=x11 TOOLS=yes TARGET=debug CACHE_NAME=${PLATFORM}-tools-mono-gcc-9 MATRIX_EVAL="CC=gcc-9 && CXX=g++-9" EXTRA_ARGS="module_mono_enabled=yes mono_glue=no warnings=extra"
os: linux
compiler: gcc-9
addons:
@ -49,7 +48,7 @@ matrix:
- name: Linux export template (release, Clang)
stage: build
env: PLATFORM=x11 TOOLS=no TARGET=release CACHE_NAME=${PLATFORM}-clang EXTRA_ARGS="warnings=extra werror=yes"
env: PLATFORM=x11 TOOLS=no TARGET=release CACHE_NAME=${PLATFORM}-clang EXTRA_ARGS="warnings=extra"
os: linux
compiler: clang
addons:
@ -57,19 +56,21 @@ matrix:
packages:
- *linux_deps
- name: Android export template (release_debug, Clang)
stage: build
env: PLATFORM=android TOOLS=no TARGET=release_debug CACHE_NAME=${PLATFORM}-clang EXTRA_ARGS="warnings=extra werror=yes"
os: linux
compiler: clang
addons:
apt:
packages:
- openjdk-8-jdk
# TODO: Android support
# - name: Android export template (release_debug, Clang)
# stage: build
# env: PLATFORM=android TOOLS=no TARGET=release_debug CACHE_NAME=${PLATFORM}-clang EXTRA_ARGS="warnings=extra werror=yes"
# os: linux
# compiler: clang
# addons:
# apt:
# packages:
# - openjdk-8-jdk
- name: macOS editor (debug, Clang)
stage: build
env: PLATFORM=osx TOOLS=yes TARGET=debug CACHE_NAME=${PLATFORM}-tools-clang EXTRA_ARGS="warnings=extra werror=yes"
env: PLATFORM=osx TOOLS=yes TARGET=debug CACHE_NAME=${PLATFORM}-tools-clang EXTRA_ARGS="warnings=extra" # werror=yes
os: osx
compiler: clang
addons:
@ -77,28 +78,32 @@ matrix:
packages:
- scons
- name: iOS export template (debug, Clang)
stage: build
env: PLATFORM=iphone TOOLS=no TARGET=debug CACHE_NAME=${PLATFORM}-clang
os: osx
compiler: clang
addons:
homebrew:
packages:
- scons
# TODO: iOS MoltenVK support
- name: Linux headless editor (release_debug, GCC 9, testing project exporting and script running)
stage: build
env: PLATFORM=server TOOLS=yes TARGET=release_debug CACHE_NAME=${PLATFORM}-tools-gcc-9 MATRIX_EVAL="CC=gcc-9 && CXX=g++-9" EXTRA_ARGS="warnings=extra werror=yes" TEST_PROJECT=yes
os: linux
compiler: gcc-9
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- *gcc9_deps
- *linux_deps
# - name: iOS export template (debug, Clang)
# stage: build
# env: PLATFORM=iphone TOOLS=no TARGET=debug CACHE_NAME=${PLATFORM}-clang
# os: osx
# compiler: clang
# addons:
# homebrew:
# packages:
# - scons
# TODO: Dummy/Offscreen rasterizer
# - name: Linux headless editor (release_debug, GCC 9, testing project exporting and script running)
# stage: build
# env: PLATFORM=server TOOLS=yes TARGET=release_debug CACHE_NAME=${PLATFORM}-tools-gcc-9 MATRIX_EVAL="CC=gcc-9 && CXX=g++-9" EXTRA_ARGS="warnings=extra werror=yes" TEST_PROJECT=yes
# os: linux
# compiler: gcc-9
# addons:
# apt:
# sources:
# - ubuntu-toolchain-r-test
# packages:
# - *gcc9_deps
# - *linux_deps
- name: Linux export template (release_debug, GCC 5, without 3D support)
stage: build

View file

@ -115,6 +115,11 @@ Comment: Open Asset Import Library (assimp)
Copyright: 2006-2016, assimp team
License: BSD-3-clause
Files: ./thirdparty/basis_universal/
Comment: Basis Universal
Copyright: 2019, Binomial LLC.
License: Apache-2.0
Files: ./thirdparty/bullet/
Comment: Bullet Continuous Collision Detection and Physics Library
Copyright: 2003-2013, Erwin Coumans
@ -167,6 +172,12 @@ Comment: glad
Copyright: 2013-2019, David Herberth
License: Expat
Files: ./thirdparty/glslang/
Comment: glslang
Copyright: 2015-2018 Google, Inc.
2002, NVIDIA Corporation.
License: glslang
Files: ./thirdparty/jpeg_compressor/
Comment: jpeg-compressor
Copyright: 2012, Rich Geldreich
@ -354,6 +365,19 @@ Copyright: 2011, Khaled Mamou
2003-2009, Erwin Coumans
License: BSD-3-clause
Files: ./thirdparty/vulkan/
Comment: Vulkan Ecosystem Components (Vulkan ICD loader and headers)
Copyright: 2014-2019, The Khronos Group Inc.
2014-2019, Valve Corporation
2014-2019, LunarG, Inc.
2015-2019, Google Inc.
License: Apache-2.0
Files: ./thirdparty/vulkan/vk_mem_alloc.h
Comment: Vulkan Memory Allocator
Copyright: 2017-2019, Advanced Micro Devices, Inc.
License: Expat
Files: ./thirdparty/wslay/
Comment: Wslay
Copyright: 2011-2015, Tatsuhiro Tsujikawa
@ -882,6 +906,112 @@ License: Expat
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
License: glslang
Here, glslang proper means core GLSL parsing, HLSL parsing, and SPIR-V code
generation. Glslang proper requires use of two licenses, one that covers
non-preprocessing and an additional one that covers preprocessing.
.
Bison was removed long ago. You can build glslang from the source grammar,
using tools of your choice, without using bison or any bison files.
.
Other parts, outside of glslang proper, include:
.
- gl_types.h, only needed for OpenGL-like reflection, and can be left out of
a parse and codegen project. See it for its license.
.
- update_glslang_sources.py, which is not part of the project proper and does
not need to be used.
.
- the SPIR-V "remapper", which is optional, but has the same license as
glslang proper
.
- Google tests and SPIR-V tools, and anything in the external subdirectory
are external and optional; see them for their respective licenses.
.
--------------------------------------------------------------------------------
.
The core of glslang-proper, minus the preprocessor is licenced as follows:
.
Copyright (C) 2015-2018 Google, Inc.
Copyright (C) <various other dates and companies>
.
All rights reserved.
.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
.
Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
.
Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
.
Neither the name of 3Dlabs Inc. Ltd. nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
.
--------------------------------------------------------------------------------
.
The preprocessor has the core license stated above, plus an additional licence:
.
Copyright (c) 2002, NVIDIA Corporation.
.
NVIDIA Corporation("NVIDIA") supplies this software to you in
consideration of your agreement to the following terms, and your use,
installation, modification or redistribution of this NVIDIA software
constitutes acceptance of these terms. If you do not agree with these
terms, please do not use, install, modify or redistribute this NVIDIA
software.
.
In consideration of your agreement to abide by the following terms, and
subject to these terms, NVIDIA grants you a personal, non-exclusive
license, under NVIDIA's copyrights in this original NVIDIA software (the
"NVIDIA Software"), to use, reproduce, modify and redistribute the
NVIDIA Software, with or without modifications, in source and/or binary
forms; provided that if you redistribute the NVIDIA Software, you must
retain the copyright notice of NVIDIA, this notice and the following
text and disclaimers in all such redistributions of the NVIDIA Software.
Neither the name, trademarks, service marks nor logos of NVIDIA
Corporation may be used to endorse or promote products derived from the
NVIDIA Software without specific prior written permission from NVIDIA.
Except as expressly stated in this notice, no other rights or licenses
express or implied, are granted by NVIDIA herein, including but not
limited to any patent rights that may be infringed by your derivative
works or by other works in which the NVIDIA Software may be
incorporated. No hardware is licensed hereunder.
.
THE NVIDIA SOFTWARE IS BEING PROVIDED ON AN "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED,
INCLUDING WITHOUT LIMITATION, WARRANTIES OR CONDITIONS OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
ITS USE AND OPERATION EITHER ALONE OR IN COMBINATION WITH OTHER
PRODUCTS.
.
IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT,
INCIDENTAL, EXEMPLARY, CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, LOST PROFITS; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) OR ARISING IN ANY WAY
OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE
NVIDIA SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT,
TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF
NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
License: FTL
The FreeType Project LICENSE
----------------------------

View file

@ -111,6 +111,7 @@ opts.Add('p', "Platform (alias for 'platform')", '')
opts.Add('platform', "Target platform (%s)" % ('|'.join(platform_list), ), '')
opts.Add(EnumVariable('target', "Compilation target", 'debug', ('debug', 'release_debug', 'release')))
opts.Add(EnumVariable('optimize', "Optimization type", 'speed', ('speed', 'size')))
opts.Add(BoolVariable('tools', "Build the tools (a.k.a. the Godot editor)", True))
opts.Add(BoolVariable('use_lto', 'Use link-time optimization', False))
opts.Add(BoolVariable('use_precise_math_checks', 'Math checks use very precise epsilon (useful to debug the engine)', False))
@ -139,6 +140,7 @@ opts.Add(BoolVariable('builtin_bullet', "Use the built-in Bullet library", True)
opts.Add(BoolVariable('builtin_certs', "Bundle default SSL certificates to be used if you don't specify an override in the project settings", True))
opts.Add(BoolVariable('builtin_enet', "Use the built-in ENet library", True))
opts.Add(BoolVariable('builtin_freetype', "Use the built-in FreeType library", True))
opts.Add(BoolVariable('builtin_glslang', "Use the built-in glslang library", True))
opts.Add(BoolVariable('builtin_libogg', "Use the built-in libogg library", True))
opts.Add(BoolVariable('builtin_libpng', "Use the built-in libpng library", True))
opts.Add(BoolVariable('builtin_libtheora', "Use the built-in libtheora library", True))
@ -154,6 +156,7 @@ opts.Add(BoolVariable('builtin_pcre2_with_jit', "Use JIT compiler for the built-
opts.Add(BoolVariable('builtin_recast', "Use the built-in Recast library", True))
opts.Add(BoolVariable('builtin_rvo2', "Use the built-in RVO2 library", True))
opts.Add(BoolVariable('builtin_squish', "Use the built-in squish library", True))
opts.Add(BoolVariable('builtin_vulkan', "Use the built-in Vulkan loader library and headers", True))
opts.Add(BoolVariable('builtin_xatlas', "Use the built-in xatlas library", True))
opts.Add(BoolVariable('builtin_zlib', "Use the built-in zlib library", True))
opts.Add(BoolVariable('builtin_zstd', "Use the built-in Zstd library", True))
@ -497,6 +500,7 @@ if selected_platform in platform_list:
if (not env["platform"] == "server"): # FIXME: detect GLES3
env.Append(BUILDERS = { 'GLES3_GLSL' : env.Builder(action=run_in_subprocess(gles_builders.build_gles3_headers), suffix='glsl.gen.h', src_suffix='.glsl')})
env.Append(BUILDERS = { 'GLES2_GLSL' : env.Builder(action=run_in_subprocess(gles_builders.build_gles2_headers), suffix='glsl.gen.h', src_suffix='.glsl')})
env.Append(BUILDERS = { 'RD_GLSL' : env.Builder(action=run_in_subprocess(gles_builders.build_rd_headers), suffix='glsl.gen.h', src_suffix='.glsl')})
scons_cache_path = os.environ.get("SCONS_CACHE")
if scons_cache_path != None:

View file

@ -2612,7 +2612,7 @@ void _Semaphore::_bind_methods() {
_Semaphore::_Semaphore() {
semaphore = Semaphore::create();
semaphore = SemaphoreOld::create();
}
_Semaphore::~_Semaphore() {

View file

@ -106,6 +106,7 @@ public:
enum VideoDriver {
VIDEO_DRIVER_GLES3,
VIDEO_DRIVER_GLES2,
VIDEO_DRIVER_VULKAN,
};
enum PowerState {
@ -642,7 +643,7 @@ public:
class _Semaphore : public Reference {
GDCLASS(_Semaphore, Reference);
Semaphore *semaphore;
SemaphoreOld *semaphore;
static void _bind_methods();

View file

@ -335,6 +335,19 @@ StringName ClassDB::get_parent_class_nocheck(const StringName &p_class) {
return ti->inherits;
}
StringName ClassDB::get_compatibility_remapped_class(const StringName &p_class) {
if (classes.has(p_class)) {
return p_class;
}
if (compat_classes.has(p_class)) {
return compat_classes[p_class];
}
return p_class;
}
StringName ClassDB::get_parent_class(const StringName &p_class) {
OBJTYPE_RLOCK;

View file

@ -218,6 +218,7 @@ public:
static void get_direct_inheriters_from_class(const StringName &p_class, List<StringName> *p_classes);
static StringName get_parent_class_nocheck(const StringName &p_class);
static StringName get_parent_class(const StringName &p_class);
static StringName get_compatibility_remapped_class(const StringName &p_class);
static bool class_exists(const StringName &p_class);
static bool is_parent_class(const StringName &p_class, const StringName &p_inherits);
static bool can_instance(const StringName &p_class);

View file

@ -529,14 +529,6 @@ Color Color::operator+(const Color &p_color) const {
a + p_color.a);
}
void Color::operator+=(const Color &p_color) {
r = r + p_color.r;
g = g + p_color.g;
b = b + p_color.b;
a = a + p_color.a;
}
Color Color::operator-(const Color &p_color) const {
return Color(

View file

@ -70,7 +70,12 @@ struct Color {
}
Color operator+(const Color &p_color) const;
void operator+=(const Color &p_color);
_FORCE_INLINE_ void operator+=(const Color &p_color) {
r = r + p_color.r;
g = g + p_color.g;
b = b + p_color.b;
a = a + p_color.a;
}
Color operator-() const;
Color operator-(const Color &p_color) const;

View file

@ -111,11 +111,11 @@ CommandQueueMT::CommandQueueMT(bool p_sync) {
for (int i = 0; i < SYNC_SEMAPHORES; i++) {
sync_sems[i].sem = Semaphore::create();
sync_sems[i].sem = SemaphoreOld::create();
sync_sems[i].in_use = false;
}
if (p_sync)
sync = Semaphore::create();
sync = SemaphoreOld::create();
else
sync = NULL;
}

View file

@ -52,9 +52,17 @@
#define _COMMA_11 ,
#define _COMMA_12 ,
#define _COMMA_13 ,
#define _COMMA_14 ,
#define _COMMA_15 ,
// 1-based comma separated list of ITEMs
#define COMMA_SEP_LIST(ITEM, LENGTH) _COMMA_SEP_LIST_##LENGTH(ITEM)
#define _COMMA_SEP_LIST_15(ITEM) \
_COMMA_SEP_LIST_14(ITEM) \
, ITEM(15)
#define _COMMA_SEP_LIST_14(ITEM) \
_COMMA_SEP_LIST_13(ITEM) \
, ITEM(14)
#define _COMMA_SEP_LIST_13(ITEM) \
_COMMA_SEP_LIST_12(ITEM) \
, ITEM(13)
@ -98,6 +106,12 @@
// 1-based semicolon separated list of ITEMs
#define SEMIC_SEP_LIST(ITEM, LENGTH) _SEMIC_SEP_LIST_##LENGTH(ITEM)
#define _SEMIC_SEP_LIST_15(ITEM) \
_SEMIC_SEP_LIST_14(ITEM); \
ITEM(15)
#define _SEMIC_SEP_LIST_14(ITEM) \
_SEMIC_SEP_LIST_13(ITEM); \
ITEM(14)
#define _SEMIC_SEP_LIST_13(ITEM) \
_SEMIC_SEP_LIST_12(ITEM); \
ITEM(13)
@ -141,6 +155,12 @@
// 1-based space separated list of ITEMs
#define SPACE_SEP_LIST(ITEM, LENGTH) _SPACE_SEP_LIST_##LENGTH(ITEM)
#define _SPACE_SEP_LIST_15(ITEM) \
_SPACE_SEP_LIST_14(ITEM) \
ITEM(15)
#define _SPACE_SEP_LIST_14(ITEM) \
_SPACE_SEP_LIST_13(ITEM) \
ITEM(14)
#define _SPACE_SEP_LIST_13(ITEM) \
_SPACE_SEP_LIST_12(ITEM) \
ITEM(13)
@ -271,13 +291,13 @@
ss->in_use = false; \
}
#define MAX_CMD_PARAMS 13
#define MAX_CMD_PARAMS 15
class CommandQueueMT {
struct SyncSemaphore {
Semaphore *sem;
SemaphoreOld *sem;
bool in_use;
};
@ -298,15 +318,15 @@ class CommandQueueMT {
};
DECL_CMD(0)
SPACE_SEP_LIST(DECL_CMD, 13)
SPACE_SEP_LIST(DECL_CMD, 15)
/* comands that return */
DECL_CMD_RET(0)
SPACE_SEP_LIST(DECL_CMD_RET, 13)
SPACE_SEP_LIST(DECL_CMD_RET, 15)
/* commands that don't return but sync */
DECL_CMD_SYNC(0)
SPACE_SEP_LIST(DECL_CMD_SYNC, 13)
SPACE_SEP_LIST(DECL_CMD_SYNC, 15)
/***** BASE *******/
@ -322,7 +342,7 @@ class CommandQueueMT {
uint32_t dealloc_ptr;
SyncSemaphore sync_sems[SYNC_SEMAPHORES];
Mutex *mutex;
Semaphore *sync;
SemaphoreOld *sync;
template <class T>
T *allocate() {
@ -443,15 +463,15 @@ class CommandQueueMT {
public:
/* NORMAL PUSH COMMANDS */
DECL_PUSH(0)
SPACE_SEP_LIST(DECL_PUSH, 13)
SPACE_SEP_LIST(DECL_PUSH, 15)
/* PUSH AND RET COMMANDS */
DECL_PUSH_AND_RET(0)
SPACE_SEP_LIST(DECL_PUSH_AND_RET, 13)
SPACE_SEP_LIST(DECL_PUSH_AND_RET, 15)
/* PUSH AND RET SYNC COMMANDS*/
DECL_PUSH_AND_SYNC(0)
SPACE_SEP_LIST(DECL_PUSH_AND_SYNC, 13)
SPACE_SEP_LIST(DECL_PUSH_AND_SYNC, 15)
void wait_and_flush_one() {
ERR_FAIL_COND(!sync);

View file

@ -214,6 +214,9 @@ Engine *Engine::get_singleton() {
return singleton;
}
bool Engine::is_abort_on_gpu_errors_enabled() const {
return abort_on_gpu_errors;
}
Engine::Engine() {
singleton = this;
@ -232,4 +235,5 @@ Engine::Engine() {
_frame_ticks = 0;
_frame_step = 0;
editor_hint = false;
abort_on_gpu_errors = false;
}

View file

@ -64,6 +64,7 @@ private:
bool _pixel_snap;
uint64_t _physics_frames;
float _physics_interpolation_fraction;
bool abort_on_gpu_errors;
uint64_t _idle_frames;
bool _in_physics;
@ -126,6 +127,8 @@ public:
Dictionary get_license_info() const;
String get_license_text() const;
bool is_abort_on_gpu_errors_enabled() const;
Engine();
virtual ~Engine() {}
};

View file

@ -79,12 +79,16 @@ const char *Image::format_names[Image::FORMAT_MAX] = {
"ETC2_RGB8",
"ETC2_RGBA8",
"ETC2_RGB8A1",
"ETC2_RA_AS_RG",
"FORMAT_DXT5_RA_AS_RG",
};
SavePNGFunc Image::save_png_func = NULL;
SaveEXRFunc Image::save_exr_func = NULL;
SavePNGBufferFunc Image::save_png_buffer_func = NULL;
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;
@ -115,7 +119,7 @@ int Image::get_format_pixel_size(Format p_format) {
case FORMAT_RGB8: return 3;
case FORMAT_RGBA8: return 4;
case FORMAT_RGBA4444: return 2;
case FORMAT_RGBA5551: return 2;
case FORMAT_RGB565: return 2;
case FORMAT_RF:
return 4; //float
case FORMAT_RGF: return 8;
@ -159,6 +163,8 @@ int Image::get_format_pixel_size(Format p_format) {
case FORMAT_ETC2_RGB8: return 1;
case FORMAT_ETC2_RGBA8: return 1;
case FORMAT_ETC2_RGB8A1: return 1;
case FORMAT_ETC2_RA_AS_RG: return 1;
case FORMAT_DXT5_RA_AS_RG: return 1;
case FORMAT_MAX: {
}
}
@ -207,7 +213,9 @@ void Image::get_format_min_pixel_size(Format p_format, int &r_w, int &r_h) {
case FORMAT_ETC2_RG11S:
case FORMAT_ETC2_RGB8:
case FORMAT_ETC2_RGBA8:
case FORMAT_ETC2_RGB8A1: {
case FORMAT_ETC2_RGB8A1:
case FORMAT_ETC2_RA_AS_RG:
case FORMAT_DXT5_RA_AS_RG: {
r_w = 4;
r_h = 4;
@ -268,7 +276,11 @@ int Image::get_format_block_size(Format p_format) {
case FORMAT_ETC2_RG11S:
case FORMAT_ETC2_RGB8:
case FORMAT_ETC2_RGBA8:
case FORMAT_ETC2_RGB8A1: {
case FORMAT_ETC2_RGB8A1:
case FORMAT_ETC2_RA_AS_RG: //used to make basis universal happy
case FORMAT_DXT5_RA_AS_RG: //used to make basis universal happy
{
return 4;
}
@ -318,6 +330,17 @@ int Image::get_mipmap_offset(int p_mipmap) const {
return ofs;
}
int Image::get_mipmap_byte_size(int p_mipmap) const {
ERR_FAIL_INDEX_V(p_mipmap, get_mipmap_count() + 1, -1);
int ofs, w, h;
_get_mipmap_offset_and_size(p_mipmap, ofs, w, h);
int ofs2;
_get_mipmap_offset_and_size(p_mipmap + 1, ofs2, w, h);
return ofs2 - ofs;
}
void Image::get_mipmap_offset_and_size(int p_mipmap, int &r_ofs, int &r_size) const {
int ofs, w, h;
@ -891,6 +914,7 @@ void Image::resize(int p_width, int p_height, Interpolation p_interpolation) {
ERR_FAIL_COND_MSG(p_height <= 0, "Image height must be greater than 0.");
ERR_FAIL_COND_MSG(p_width > MAX_WIDTH, "Image width cannot be greater than " + itos(MAX_WIDTH) + ".");
ERR_FAIL_COND_MSG(p_height > MAX_HEIGHT, "Image height cannot be greater than " + itos(MAX_HEIGHT) + ".");
ERR_FAIL_COND_MSG(p_width * p_height > MAX_PIXELS, "Too many pixels for image, maximum is " + itos(MAX_PIXELS));
if (p_width == width && p_height == height)
return;
@ -1215,7 +1239,7 @@ void Image::flip_x() {
}
}
int Image::_get_dst_image_size(int p_width, int p_height, Format p_format, int &r_mipmaps, int p_mipmaps) {
int Image::_get_dst_image_size(int p_width, int p_height, Format p_format, int &r_mipmaps, int p_mipmaps, int *r_mm_width, int *r_mm_height) {
int size = 0;
int w = p_width;
@ -1242,6 +1266,13 @@ int Image::_get_dst_image_size(int p_width, int p_height, Format p_format, int &
size += s;
if (r_mm_width) {
*r_mm_width = bw;
}
if (r_mm_height) {
*r_mm_height = bh;
}
if (p_mipmaps >= 0 && mm == p_mipmaps)
break;
@ -1547,6 +1578,206 @@ Error Image::generate_mipmaps(bool p_renormalize) {
return OK;
}
Error Image::generate_mipmap_roughness(RoughnessChannel p_roughness_channel, const Ref<Image> &p_normal_map) {
Vector<double> normal_sat_vec; //summed area table
double *normal_sat = nullptr; //summed area table for normalmap
int normal_w = 0, normal_h = 0;
ERR_FAIL_COND_V_MSG(p_normal_map.is_null() || p_normal_map->empty(), ERR_INVALID_PARAMETER, "Must provide a valid normalmap for roughness mipmaps");
Ref<Image> nm = p_normal_map->duplicate();
if (nm->is_compressed()) {
nm->decompress();
}
normal_w = nm->get_width();
normal_h = nm->get_height();
normal_sat_vec.resize(normal_w * normal_h * 3);
normal_sat = normal_sat_vec.ptrw();
//create summed area table
nm->lock();
for (int y = 0; y < normal_h; y++) {
double line_sum[3] = { 0, 0, 0 };
for (int x = 0; x < normal_w; x++) {
double normal[3];
Color color = nm->get_pixel(x, y);
normal[0] = color.r * 2.0 - 1.0;
normal[1] = color.g * 2.0 - 1.0;
normal[2] = Math::sqrt(MAX(0.0, 1.0 - (normal[0] * normal[0] + normal[1] * normal[1]))); //reconstruct if missing
line_sum[0] += normal[0];
line_sum[1] += normal[1];
line_sum[2] += normal[2];
uint32_t ofs = (y * normal_w + x) * 3;
normal_sat[ofs + 0] = line_sum[0];
normal_sat[ofs + 1] = line_sum[1];
normal_sat[ofs + 2] = line_sum[2];
if (y > 0) {
uint32_t prev_ofs = ((y - 1) * normal_w + x) * 3;
normal_sat[ofs + 0] += normal_sat[prev_ofs + 0];
normal_sat[ofs + 1] += normal_sat[prev_ofs + 1];
normal_sat[ofs + 2] += normal_sat[prev_ofs + 2];
}
}
}
#if 0
{
Vector3 beg(normal_sat_vec[0], normal_sat_vec[1], normal_sat_vec[2]);
Vector3 end(normal_sat_vec[normal_sat_vec.size() - 3], normal_sat_vec[normal_sat_vec.size() - 2], normal_sat_vec[normal_sat_vec.size() - 1]);
Vector3 avg = (end - beg) / (normal_w * normal_h);
print_line("average: " + avg);
}
#endif
int mmcount;
_get_dst_image_size(width, height, format, mmcount);
lock();
uint8_t *base_ptr = write_lock.ptr();
for (int i = 1; i <= mmcount; i++) {
int ofs, w, h;
_get_mipmap_offset_and_size(i, ofs, w, h);
uint8_t *ptr = &base_ptr[ofs];
for (int x = 0; x < w; x++) {
for (int y = 0; y < h; y++) {
int from_x = x * normal_w / w;
int from_y = y * normal_h / h;
int to_x = (x + 1) * normal_w / w;
int to_y = (y + 1) * normal_h / h;
to_x = MIN(to_x - 1, normal_w);
to_y = MIN(to_y - 1, normal_h);
int size_x = (to_x - from_x) + 1;
int size_y = (to_y - from_y) + 1;
//summed area table version (much faster)
double avg[3] = { 0, 0, 0 };
if (from_x > 0 && from_y > 0) {
uint32_t tofs = ((from_y - 1) * normal_w + (from_x - 1)) * 3;
avg[0] += normal_sat[tofs + 0];
avg[1] += normal_sat[tofs + 1];
avg[2] += normal_sat[tofs + 2];
}
if (from_y > 0) {
uint32_t tofs = ((from_y - 1) * normal_w + to_x) * 3;
avg[0] -= normal_sat[tofs + 0];
avg[1] -= normal_sat[tofs + 1];
avg[2] -= normal_sat[tofs + 2];
}
if (from_x > 0) {
uint32_t tofs = (to_y * normal_w + (from_x - 1)) * 3;
avg[0] -= normal_sat[tofs + 0];
avg[1] -= normal_sat[tofs + 1];
avg[2] -= normal_sat[tofs + 2];
}
uint32_t tofs = (to_y * normal_w + to_x) * 3;
avg[0] += normal_sat[tofs + 0];
avg[1] += normal_sat[tofs + 1];
avg[2] += normal_sat[tofs + 2];
double div = double(size_x * size_y);
Vector3 vec(avg[0] / div, avg[1] / div, avg[2] / div);
float r = vec.length();
int pixel_ofs = y * w + x;
Color c = _get_color_at_ofs(ptr, pixel_ofs);
float roughness;
switch (p_roughness_channel) {
case ROUGHNESS_CHANNEL_R: {
roughness = c.r;
} break;
case ROUGHNESS_CHANNEL_G: {
roughness = c.g;
} break;
case ROUGHNESS_CHANNEL_B: {
roughness = c.b;
} break;
case ROUGHNESS_CHANNEL_L: {
roughness = c.gray();
} break;
case ROUGHNESS_CHANNEL_A: {
roughness = c.a;
} break;
}
float variance = 0;
if (r < 1.0f) {
float r2 = r * r;
float kappa = (3.0f * r - r * r2) / (1.0f - r2);
variance = 0.25f / kappa;
}
float threshold = 0.4;
roughness = Math::sqrt(roughness * roughness + MIN(3.0f * variance, threshold * threshold));
switch (p_roughness_channel) {
case ROUGHNESS_CHANNEL_R: {
c.r = roughness;
} break;
case ROUGHNESS_CHANNEL_G: {
c.g = roughness;
} break;
case ROUGHNESS_CHANNEL_B: {
c.b = roughness;
} break;
case ROUGHNESS_CHANNEL_L: {
c.r = roughness;
c.g = roughness;
c.b = roughness;
} break;
case ROUGHNESS_CHANNEL_A: {
c.a = roughness;
} break;
}
_set_color_at_ofs(ptr, pixel_ofs, c);
}
}
#if 0
{
int size = get_mipmap_byte_size(i);
print_line("size for mimpap " + itos(i) + ": " + itos(size));
PoolVector<uint8_t> imgdata;
imgdata.resize(size);
PoolVector<uint8_t>::Write wr = imgdata.write();
copymem(wr.ptr(), ptr, size);
wr = PoolVector<uint8_t>::Write();
Ref<Image> im;
im.instance();
im->create(w, h, false, format, imgdata);
im->save_png("res://mipmap_" + itos(i) + ".png");
}
#endif
}
unlock();
nm->unlock();
return OK;
}
void Image::clear_mipmaps() {
if (!mipmaps)
@ -1576,6 +1807,7 @@ void Image::create(int p_width, int p_height, bool p_use_mipmaps, Format p_forma
ERR_FAIL_INDEX(p_width - 1, MAX_WIDTH);
ERR_FAIL_INDEX(p_height - 1, MAX_HEIGHT);
ERR_FAIL_COND_MSG(p_width * p_height > MAX_PIXELS, "Too many pixels for image, maximum is " + itos(MAX_PIXELS));
int mm = 0;
int size = _get_dst_image_size(p_width, p_height, p_format, mm, p_use_mipmaps ? -1 : 0);
@ -1595,6 +1827,7 @@ void Image::create(int p_width, int p_height, bool p_use_mipmaps, Format p_forma
ERR_FAIL_INDEX(p_width - 1, MAX_WIDTH);
ERR_FAIL_INDEX(p_height - 1, MAX_HEIGHT);
ERR_FAIL_COND_MSG(p_width * p_height > MAX_PIXELS, "Too many pixels for image, maximum is " + itos(MAX_PIXELS));
int mm;
int size = _get_dst_image_size(p_width, p_height, p_format, mm, p_use_mipmaps ? -1 : 0);
@ -1893,6 +2126,14 @@ Error Image::save_png(const String &p_path) const {
return save_png_func(p_path, Ref<Image>((Image *)this));
}
PoolVector<uint8_t> Image::save_png_to_buffer() const {
if (save_png_buffer_func == NULL) {
return PoolVector<uint8_t>();
}
return save_png_buffer_func(Ref<Image>((Image *)this));
}
Error Image::save_exr(const String &p_path, bool p_grayscale) const {
if (save_exr_func == NULL)
@ -1914,6 +2155,13 @@ int Image::get_image_required_mipmaps(int p_width, int p_height, Format p_format
return mm;
}
Size2i Image::get_image_mipmap_size(int p_width, int p_height, Format p_format, int p_mipmap) {
int mm;
Size2i ret;
_get_dst_image_size(p_width, p_height, p_format, mm, p_mipmap, &ret.x, &ret.y);
return ret;
}
int Image::get_image_mipmap_offset(int p_width, int p_height, Format p_format, int p_mipmap) {
if (p_mipmap <= 0) {
@ -1923,13 +2171,24 @@ int Image::get_image_mipmap_offset(int p_width, int p_height, Format p_format, i
return _get_dst_image_size(p_width, p_height, p_format, mm, p_mipmap - 1);
}
int Image::get_image_mipmap_offset_and_dimensions(int p_width, int p_height, Format p_format, int p_mipmap, int &r_w, int &r_h) {
if (p_mipmap <= 0) {
r_w = p_width;
r_h = p_height;
return 0;
}
int mm;
return _get_dst_image_size(p_width, p_height, p_format, mm, p_mipmap - 1, &r_w, &r_h);
}
bool Image::is_compressed() const {
return format > FORMAT_RGBE9995;
}
Error Image::decompress() {
if (format >= FORMAT_DXT1 && format <= FORMAT_RGTC_RG && _image_decompress_bc)
if (((format >= FORMAT_DXT1 && format <= FORMAT_RGTC_RG) || (format == FORMAT_DXT5_RA_AS_RG)) && _image_decompress_bc)
_image_decompress_bc(this);
else if (format >= FORMAT_BPTC_RGBA && format <= FORMAT_BPTC_RGBFU && _image_decompress_bptc)
_image_decompress_bptc(this);
@ -1937,7 +2196,7 @@ Error Image::decompress() {
_image_decompress_pvrtc(this);
else if (format == FORMAT_ETC && _image_decompress_etc1)
_image_decompress_etc1(this);
else if (format >= FORMAT_ETC2_R11 && format <= FORMAT_ETC2_RGB8A1 && _image_decompress_etc2)
else if (format >= FORMAT_ETC2_R11 && format <= FORMAT_ETC2_RA_AS_RG && _image_decompress_etc2)
_image_decompress_etc2(this);
else
return ERR_UNAVAILABLE;
@ -1946,12 +2205,16 @@ Error Image::decompress() {
Error Image::compress(CompressMode p_mode, CompressSource p_source, float p_lossy_quality) {
return compress_from_channels(p_mode, detect_used_channels(p_source), p_lossy_quality);
}
Error Image::compress_from_channels(CompressMode p_mode, UsedChannels p_channels, float p_lossy_quality) {
switch (p_mode) {
case COMPRESS_S3TC: {
ERR_FAIL_COND_V(!_image_compress_bc_func, ERR_UNAVAILABLE);
_image_compress_bc_func(this, p_lossy_quality, p_source);
_image_compress_bc_func(this, p_lossy_quality, p_channels);
} break;
case COMPRESS_PVRTC2: {
@ -1971,12 +2234,12 @@ Error Image::compress(CompressMode p_mode, CompressSource p_source, float p_loss
case COMPRESS_ETC2: {
ERR_FAIL_COND_V(!_image_compress_etc2_func, ERR_UNAVAILABLE);
_image_compress_etc2_func(this, p_lossy_quality, p_source);
_image_compress_etc2_func(this, p_lossy_quality, p_channels);
} break;
case COMPRESS_BPTC: {
ERR_FAIL_COND_V(!_image_compress_bptc_func, ERR_UNAVAILABLE);
_image_compress_bptc_func(this, p_lossy_quality, p_source);
_image_compress_bptc_func(this, p_lossy_quality, p_channels);
} break;
}
@ -2015,7 +2278,7 @@ Image::Image(int p_width, int p_height, bool p_mipmaps, Format p_format, const P
Rect2 Image::get_used_rect() const {
if (format != FORMAT_LA8 && format != FORMAT_RGBA8 && format != FORMAT_RGBAF && format != FORMAT_RGBAH && format != FORMAT_RGBA4444 && format != FORMAT_RGBA5551)
if (format != FORMAT_LA8 && format != FORMAT_RGBA8 && format != FORMAT_RGBAF && format != FORMAT_RGBAH && format != FORMAT_RGBA4444 && format != FORMAT_RGB565)
return Rect2(Point2(), Size2(width, height));
int len = data.size();
@ -2317,12 +2580,12 @@ ImageMemLoadFunc Image::_png_mem_loader_func = NULL;
ImageMemLoadFunc Image::_jpg_mem_loader_func = NULL;
ImageMemLoadFunc Image::_webp_mem_loader_func = NULL;
void (*Image::_image_compress_bc_func)(Image *, float, Image::CompressSource) = NULL;
void (*Image::_image_compress_bptc_func)(Image *, float, Image::CompressSource) = NULL;
void (*Image::_image_compress_bc_func)(Image *, float, Image::UsedChannels) = NULL;
void (*Image::_image_compress_bptc_func)(Image *, float, Image::UsedChannels) = NULL;
void (*Image::_image_compress_pvrtc2_func)(Image *) = NULL;
void (*Image::_image_compress_pvrtc4_func)(Image *) = NULL;
void (*Image::_image_compress_etc1_func)(Image *, float) = NULL;
void (*Image::_image_compress_etc2_func)(Image *, float, Image::CompressSource) = NULL;
void (*Image::_image_compress_etc2_func)(Image *, float, Image::UsedChannels) = NULL;
void (*Image::_image_decompress_pvrtc)(Image *) = NULL;
void (*Image::_image_decompress_bc)(Image *) = NULL;
void (*Image::_image_decompress_bptc)(Image *) = NULL;
@ -2333,6 +2596,8 @@ PoolVector<uint8_t> (*Image::lossy_packer)(const Ref<Image> &, float) = NULL;
Ref<Image> (*Image::lossy_unpacker)(const PoolVector<uint8_t> &) = NULL;
PoolVector<uint8_t> (*Image::lossless_packer)(const Ref<Image> &) = NULL;
Ref<Image> (*Image::lossless_unpacker)(const PoolVector<uint8_t> &) = NULL;
PoolVector<uint8_t> (*Image::basis_universal_packer)(const Ref<Image> &, Image::UsedChannels) = NULL;
Ref<Image> (*Image::basis_universal_unpacker)(const PoolVector<uint8_t> &) = NULL;
void Image::_set_data(const Dictionary &p_data) {
@ -2386,18 +2651,7 @@ Color Image::get_pixelv(const Point2 &p_src) const {
return get_pixel(p_src.x, p_src.y);
}
Color Image::get_pixel(int p_x, int p_y) const {
uint8_t *ptr = write_lock.ptr();
#ifdef DEBUG_ENABLED
ERR_FAIL_COND_V_MSG(!ptr, Color(), "Image must be locked with 'lock()' before using get_pixel().");
ERR_FAIL_INDEX_V(p_x, width, Color());
ERR_FAIL_INDEX_V(p_y, height, Color());
#endif
uint32_t ofs = p_y * width + p_x;
Color Image::_get_color_at_ofs(uint8_t *ptr, uint32_t ofs) const {
switch (format) {
case FORMAT_L8: {
@ -2441,14 +2695,13 @@ Color Image::get_pixel(int p_x, int p_y) const {
float a = (u & 0xF) / 15.0;
return Color(r, g, b, a);
}
case FORMAT_RGBA5551: {
case FORMAT_RGB565: {
uint16_t u = ((uint16_t *)ptr)[ofs];
float r = ((u >> 11) & 0x1F) / 15.0;
float g = ((u >> 6) & 0x1F) / 15.0;
float b = ((u >> 1) & 0x1F) / 15.0;
float a = (u & 0x1) / 1.0;
return Color(r, g, b, a);
float r = (u & 0x1F) / 31.0;
float g = ((u >> 5) & 0x3F) / 63.0;
float b = ((u >> 11) & 0x1F) / 31.0;
return Color(r, g, b, 1.0);
}
case FORMAT_RF: {
@ -2511,23 +2764,7 @@ Color Image::get_pixel(int p_x, int p_y) const {
}
}
void Image::set_pixelv(const Point2 &p_dst, const Color &p_color) {
set_pixel(p_dst.x, p_dst.y, p_color);
}
void Image::set_pixel(int p_x, int p_y, const Color &p_color) {
uint8_t *ptr = write_lock.ptr();
#ifdef DEBUG_ENABLED
ERR_FAIL_COND_MSG(!ptr, "Image must be locked with 'lock()' before using set_pixel().");
ERR_FAIL_INDEX(p_x, width);
ERR_FAIL_INDEX(p_y, height);
#endif
uint32_t ofs = p_y * width + p_x;
void Image::_set_color_at_ofs(uint8_t *ptr, uint32_t ofs, const Color &p_color) {
switch (format) {
case FORMAT_L8: {
ptr[ofs] = uint8_t(CLAMP(p_color.get_v() * 255.0, 0, 255));
@ -2569,14 +2806,13 @@ void Image::set_pixel(int p_x, int p_y, const Color &p_color) {
((uint16_t *)ptr)[ofs] = rgba;
} break;
case FORMAT_RGBA5551: {
case FORMAT_RGB565: {
uint16_t rgba = 0;
rgba = uint16_t(CLAMP(p_color.r * 31.0, 0, 31)) << 11;
rgba |= uint16_t(CLAMP(p_color.g * 31.0, 0, 31)) << 6;
rgba |= uint16_t(CLAMP(p_color.b * 31.0, 0, 31)) << 1;
rgba |= uint16_t(p_color.a > 0.5 ? 1 : 0);
rgba = uint16_t(CLAMP(p_color.r * 31.0, 0, 31));
rgba |= uint16_t(CLAMP(p_color.g * 63.0, 0, 33)) << 5;
rgba |= uint16_t(CLAMP(p_color.b * 31.0, 0, 31)) << 11;
((uint16_t *)ptr)[ofs] = rgba;
@ -2636,10 +2872,44 @@ void Image::set_pixel(int p_x, int p_y, const Color &p_color) {
}
}
Image::DetectChannels Image::get_detected_channels() {
Color Image::get_pixel(int p_x, int p_y) const {
ERR_FAIL_COND_V(data.size() == 0, DETECTED_RGBA);
ERR_FAIL_COND_V(is_compressed(), DETECTED_RGBA);
uint8_t *ptr = write_lock.ptr();
#ifdef DEBUG_ENABLED
ERR_FAIL_COND_V_MSG(!ptr, Color(), "Image must be locked with 'lock()' before using get_pixel().");
ERR_FAIL_INDEX_V(p_x, width, Color());
ERR_FAIL_INDEX_V(p_y, height, Color());
#endif
uint32_t ofs = p_y * width + p_x;
return _get_color_at_ofs(ptr, ofs);
}
void Image::set_pixelv(const Point2 &p_dst, const Color &p_color) {
set_pixel(p_dst.x, p_dst.y, p_color);
}
void Image::set_pixel(int p_x, int p_y, const Color &p_color) {
uint8_t *ptr = write_lock.ptr();
#ifdef DEBUG_ENABLED
ERR_FAIL_COND_MSG(!ptr, "Image must be locked with 'lock()' before using set_pixel().");
ERR_FAIL_INDEX(p_x, width);
ERR_FAIL_INDEX(p_y, height);
#endif
uint32_t ofs = p_y * width + p_x;
_set_color_at_ofs(ptr, ofs, p_color);
}
Image::UsedChannels Image::detect_used_channels(CompressSource p_source) {
ERR_FAIL_COND_V(data.size() == 0, USED_CHANNELS_RGBA);
ERR_FAIL_COND_V(is_compressed(), USED_CHANNELS_RGBA);
bool r = false, g = false, b = false, a = false, c = false;
lock();
for (int i = 0; i < width; i++) {
@ -2664,31 +2934,42 @@ Image::DetectChannels Image::get_detected_channels() {
unlock();
UsedChannels used_channels;
if (!c && !a)
return DETECTED_L;
if (!c && a)
return DETECTED_LA;
used_channels = USED_CHANNELS_L;
else if (!c && a)
used_channels = USED_CHANNELS_LA;
else if (r && !g && !b && !a)
used_channels = USED_CHANNELS_R;
else if (r && g && !b && !a)
used_channels = USED_CHANNELS_RG;
else if (r && g && b && !a)
used_channels = USED_CHANNELS_RGB;
else
used_channels = USED_CHANNELS_RGBA;
if (r && !g && !b && !a)
return DETECTED_R;
if (p_source == COMPRESS_SOURCE_SRGB && (used_channels == USED_CHANNELS_R || used_channels == USED_CHANNELS_RG)) {
//R and RG do not support SRGB
used_channels = USED_CHANNELS_RGB;
}
if (r && g && !b && !a)
return DETECTED_RG;
if (p_source == COMPRESS_SOURCE_NORMAL) {
//use RG channels only for normal
used_channels = USED_CHANNELS_RG;
}
if (r && g && b && !a)
return DETECTED_RGB;
return DETECTED_RGBA;
return used_channels;
}
void Image::optimize_channels() {
switch (get_detected_channels()) {
case DETECTED_L: convert(FORMAT_L8); break;
case DETECTED_LA: convert(FORMAT_LA8); break;
case DETECTED_R: convert(FORMAT_R8); break;
case DETECTED_RG: convert(FORMAT_RG8); break;
case DETECTED_RGB: convert(FORMAT_RGB8); break;
case DETECTED_RGBA: convert(FORMAT_RGBA8); break;
switch (detect_used_channels()) {
case USED_CHANNELS_L: convert(FORMAT_L8); break;
case USED_CHANNELS_LA: convert(FORMAT_LA8); break;
case USED_CHANNELS_R: convert(FORMAT_R8); break;
case USED_CHANNELS_RG: convert(FORMAT_RG8); break;
case USED_CHANNELS_RGB: convert(FORMAT_RGB8); break;
case USED_CHANNELS_RGBA: convert(FORMAT_RGBA8); break;
}
}
@ -2728,7 +3009,9 @@ void Image::_bind_methods() {
ClassDB::bind_method(D_METHOD("detect_alpha"), &Image::detect_alpha);
ClassDB::bind_method(D_METHOD("is_invisible"), &Image::is_invisible);
ClassDB::bind_method(D_METHOD("compress", "mode", "source", "lossy_quality"), &Image::compress);
ClassDB::bind_method(D_METHOD("detect_used_channels", "source"), &Image::detect_used_channels, DEFVAL(COMPRESS_SOURCE_GENERIC));
ClassDB::bind_method(D_METHOD("compress", "mode", "source", "lossy_quality"), &Image::compress, DEFVAL(COMPRESS_SOURCE_GENERIC), DEFVAL(0.7));
ClassDB::bind_method(D_METHOD("compress_from_channels", "mode", "channels", "lossy_quality"), &Image::compress, DEFVAL(0.7));
ClassDB::bind_method(D_METHOD("decompress"), &Image::decompress);
ClassDB::bind_method(D_METHOD("is_compressed"), &Image::is_compressed);
@ -2776,7 +3059,7 @@ void Image::_bind_methods() {
BIND_ENUM_CONSTANT(FORMAT_RGB8);
BIND_ENUM_CONSTANT(FORMAT_RGBA8);
BIND_ENUM_CONSTANT(FORMAT_RGBA4444);
BIND_ENUM_CONSTANT(FORMAT_RGBA5551);
BIND_ENUM_CONSTANT(FORMAT_RGB565);
BIND_ENUM_CONSTANT(FORMAT_RF); //float
BIND_ENUM_CONSTANT(FORMAT_RGF);
BIND_ENUM_CONSTANT(FORMAT_RGBF);
@ -2806,6 +3089,8 @@ void Image::_bind_methods() {
BIND_ENUM_CONSTANT(FORMAT_ETC2_RGB8);
BIND_ENUM_CONSTANT(FORMAT_ETC2_RGBA8);
BIND_ENUM_CONSTANT(FORMAT_ETC2_RGB8A1);
BIND_ENUM_CONSTANT(FORMAT_ETC2_RA_AS_RG);
BIND_ENUM_CONSTANT(FORMAT_DXT5_RA_AS_RG);
BIND_ENUM_CONSTANT(FORMAT_MAX);
BIND_ENUM_CONSTANT(INTERPOLATE_NEAREST);
@ -2824,17 +3109,24 @@ void Image::_bind_methods() {
BIND_ENUM_CONSTANT(COMPRESS_ETC);
BIND_ENUM_CONSTANT(COMPRESS_ETC2);
BIND_ENUM_CONSTANT(USED_CHANNELS_L);
BIND_ENUM_CONSTANT(USED_CHANNELS_LA);
BIND_ENUM_CONSTANT(USED_CHANNELS_R);
BIND_ENUM_CONSTANT(USED_CHANNELS_RG);
BIND_ENUM_CONSTANT(USED_CHANNELS_RGB);
BIND_ENUM_CONSTANT(USED_CHANNELS_RGBA);
BIND_ENUM_CONSTANT(COMPRESS_SOURCE_GENERIC);
BIND_ENUM_CONSTANT(COMPRESS_SOURCE_SRGB);
BIND_ENUM_CONSTANT(COMPRESS_SOURCE_NORMAL);
}
void Image::set_compress_bc_func(void (*p_compress_func)(Image *, float, CompressSource)) {
void Image::set_compress_bc_func(void (*p_compress_func)(Image *, float, UsedChannels)) {
_image_compress_bc_func = p_compress_func;
}
void Image::set_compress_bptc_func(void (*p_compress_func)(Image *, float, CompressSource)) {
void Image::set_compress_bptc_func(void (*p_compress_func)(Image *, float, UsedChannels)) {
_image_compress_bptc_func = p_compress_func;
}
@ -2890,6 +3182,29 @@ Ref<Image> Image::rgbe_to_srgb() {
return new_image;
}
Ref<Image> Image::get_image_from_mipmap(int p_mipamp) const {
int ofs, size, w, h;
get_mipmap_offset_size_and_dimensions(p_mipamp, ofs, size, w, h);
PoolVector<uint8_t> new_data;
new_data.resize(size);
{
PoolVector<uint8_t>::Write wr = new_data.write();
PoolVector<uint8_t>::Read rd = data.read();
copymem(wr.ptr(), rd.ptr() + ofs, size);
}
Ref<Image> image;
image.instance();
image->width = w;
image->height = h;
image->format = format;
image->data = new_data;
image->mipmaps = false;
return image;
}
void Image::bumpmap_to_normalmap(float bump_scale) {
ERR_FAIL_COND(!_can_modify(format));
convert(Image::FORMAT_RF);
@ -3078,6 +3393,31 @@ Error Image::load_webp_from_buffer(const PoolVector<uint8_t> &p_array) {
return _load_from_buffer(p_array, _webp_mem_loader_func);
}
void Image::convert_rg_to_ra_rgba8() {
ERR_FAIL_COND(format != FORMAT_RGBA8);
ERR_FAIL_COND(!data.size());
int s = data.size();
PoolVector<uint8_t>::Write w = data.write();
for (int i = 0; i < s; i += 4) {
w[i + 3] = w[i + 1];
w[i + 1] = 0;
w[i + 2] = 0;
}
}
void Image::convert_ra_rgba8_to_rg() {
ERR_FAIL_COND(format != FORMAT_RGBA8);
ERR_FAIL_COND(!data.size());
int s = data.size();
PoolVector<uint8_t>::Write w = data.write();
for (int i = 0; i < s; i += 4) {
w[i + 1] = w[i + 3];
w[i + 2] = 0;
w[i + 3] = 255;
}
}
Error Image::_load_from_buffer(const PoolVector<uint8_t> &p_array, ImageMemLoadFunc p_loader) {
int buffer_size = p_array.size();

View file

@ -47,6 +47,7 @@
class Image;
typedef Error (*SavePNGFunc)(const String &p_path, const Ref<Image> &p_img);
typedef PoolVector<uint8_t> (*SavePNGBufferFunc)(const Ref<Image> &p_img);
typedef Ref<Image> (*ImageMemLoadFunc)(const uint8_t *p_png, int p_size);
typedef Error (*SaveEXRFunc)(const String &p_path, const Ref<Image> &p_img, bool p_grayscale);
@ -57,10 +58,12 @@ class Image : public Resource {
public:
static SavePNGFunc save_png_func;
static SaveEXRFunc save_exr_func;
static SavePNGBufferFunc save_png_buffer_func;
enum {
MAX_WIDTH = 16384, // force a limit somehow
MAX_HEIGHT = 16384 // force a limit somehow
MAX_WIDTH = (1 << 24), // force a limit somehow
MAX_HEIGHT = (1 << 24), // force a limit somehow
MAX_PIXELS = 268435456
};
enum Format {
@ -72,7 +75,7 @@ public:
FORMAT_RGB8,
FORMAT_RGBA8,
FORMAT_RGBA4444,
FORMAT_RGBA5551,
FORMAT_RGB565,
FORMAT_RF, //float
FORMAT_RGF,
FORMAT_RGBF,
@ -102,6 +105,8 @@ public:
FORMAT_ETC2_RGB8,
FORMAT_ETC2_RGBA8,
FORMAT_ETC2_RGB8A1,
FORMAT_ETC2_RA_AS_RG, //used to make basis universal happy
FORMAT_DXT5_RA_AS_RG, //used to make basis universal happy
FORMAT_MAX
};
@ -117,25 +122,27 @@ public:
/* INTERPOLATE GAUSS */
};
enum CompressSource {
COMPRESS_SOURCE_GENERIC,
COMPRESS_SOURCE_SRGB,
COMPRESS_SOURCE_NORMAL,
COMPRESS_SOURCE_LAYERED,
//this is used for compression
enum UsedChannels {
USED_CHANNELS_L,
USED_CHANNELS_LA,
USED_CHANNELS_R,
USED_CHANNELS_RG,
USED_CHANNELS_RGB,
USED_CHANNELS_RGBA,
};
//some functions provided by something else
static ImageMemLoadFunc _png_mem_loader_func;
static ImageMemLoadFunc _jpg_mem_loader_func;
static ImageMemLoadFunc _webp_mem_loader_func;
static void (*_image_compress_bc_func)(Image *, float, CompressSource p_source);
static void (*_image_compress_bptc_func)(Image *, float p_lossy_quality, CompressSource p_source);
static void (*_image_compress_bc_func)(Image *, float, UsedChannels p_channels);
static void (*_image_compress_bptc_func)(Image *, float p_lossy_quality, UsedChannels p_channels);
static void (*_image_compress_pvrtc2_func)(Image *);
static void (*_image_compress_pvrtc4_func)(Image *);
static void (*_image_compress_etc1_func)(Image *, float);
static void (*_image_compress_etc2_func)(Image *, float, CompressSource p_source);
static void (*_image_compress_etc2_func)(Image *, float, UsedChannels p_channels);
static void (*_image_decompress_pvrtc)(Image *);
static void (*_image_decompress_bc)(Image *);
@ -147,9 +154,14 @@ public:
static Ref<Image> (*lossy_unpacker)(const PoolVector<uint8_t> &p_buffer);
static PoolVector<uint8_t> (*lossless_packer)(const Ref<Image> &p_image);
static Ref<Image> (*lossless_unpacker)(const PoolVector<uint8_t> &p_buffer);
static PoolVector<uint8_t> (*basis_universal_packer)(const Ref<Image> &p_image, UsedChannels p_channels);
static Ref<Image> (*basis_universal_unpacker)(const PoolVector<uint8_t> &p_buffer);
PoolVector<uint8_t>::Write write_lock;
_FORCE_INLINE_ Color _get_color_at_ofs(uint8_t *ptr, uint32_t ofs) const;
_FORCE_INLINE_ void _set_color_at_ofs(uint8_t *ptr, uint32_t ofs, const Color &p_color);
protected:
static void _bind_methods();
@ -177,7 +189,7 @@ private:
_FORCE_INLINE_ void _get_mipmap_offset_and_size(int p_mipmap, int &r_offset, int &r_width, int &r_height) const; //get where the mipmap begins in data
static int _get_dst_image_size(int p_width, int p_height, Format p_format, int &r_mipmaps, int p_mipmaps = -1);
static int _get_dst_image_size(int p_width, int p_height, Format p_format, int &r_mipmaps, int p_mipmaps = -1, int *r_mm_width = NULL, int *r_mm_height = NULL);
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_data, const uint8_t *p_pixel);
@ -214,6 +226,7 @@ public:
*/
Format get_format() const;
int get_mipmap_byte_size(int p_mipmap) const; //get where the mipmap begins in data
int get_mipmap_offset(int p_mipmap) const; //get where the mipmap begins in data
void get_mipmap_offset_and_size(int p_mipmap, int &r_ofs, int &r_size) const; //get where the mipmap begins in data
void get_mipmap_offset_size_and_dimensions(int p_mipmap, int &r_ofs, int &r_size, int &w, int &h) const; //get where the mipmap begins in data
@ -240,6 +253,16 @@ public:
*/
Error generate_mipmaps(bool p_renormalize = false);
enum RoughnessChannel {
ROUGHNESS_CHANNEL_R,
ROUGHNESS_CHANNEL_G,
ROUGHNESS_CHANNEL_B,
ROUGHNESS_CHANNEL_A,
ROUGHNESS_CHANNEL_L,
};
Error generate_mipmap_roughness(RoughnessChannel p_roughness_channel, const Ref<Image> &p_normal_map);
void clear_mipmaps();
void normalize(); //for normal maps
@ -259,6 +282,7 @@ public:
Error load(const String &p_path);
Error save_png(const String &p_path) const;
PoolVector<uint8_t> save_png_to_buffer() const;
Error save_exr(const String &p_path, bool p_grayscale) const;
/**
@ -290,7 +314,9 @@ public:
static int get_image_data_size(int p_width, int p_height, Format p_format, bool p_mipmaps = false);
static int get_image_required_mipmaps(int p_width, int p_height, Format p_format);
static Size2i get_image_mipmap_size(int p_width, int p_height, Format p_format, int p_mipmap);
static int get_image_mipmap_offset(int p_width, int p_height, Format p_format, int p_mipmap);
static int get_image_mipmap_offset_and_dimensions(int p_width, int p_height, Format p_format, int p_mipmap, int &r_w, int &r_h);
enum CompressMode {
COMPRESS_S3TC,
@ -300,8 +326,14 @@ public:
COMPRESS_ETC2,
COMPRESS_BPTC
};
enum CompressSource {
COMPRESS_SOURCE_GENERIC,
COMPRESS_SOURCE_SRGB,
COMPRESS_SOURCE_NORMAL
};
Error compress(CompressMode p_mode = COMPRESS_S3TC, CompressSource p_source = COMPRESS_SOURCE_GENERIC, float p_lossy_quality = 0.7);
Error compress(CompressMode p_mode, CompressSource p_source = COMPRESS_SOURCE_GENERIC, float p_lossy_quality = 0.7);
Error compress_from_channels(CompressMode p_mode, UsedChannels p_channels, float p_lossy_quality = 0.7);
Error decompress();
bool is_compressed() const;
@ -310,6 +342,7 @@ public:
void srgb_to_linear();
void normalmap_to_xy();
Ref<Image> rgbe_to_srgb();
Ref<Image> get_image_from_mipmap(int p_mipamp) const;
void bumpmap_to_normalmap(float bump_scale = 1.0);
void blit_rect(const Ref<Image> &p_src, const Rect2 &p_src_rect, const Point2 &p_dest);
@ -321,14 +354,17 @@ public:
Rect2 get_used_rect() const;
Ref<Image> get_rect(const Rect2 &p_area) const;
static void set_compress_bc_func(void (*p_compress_func)(Image *, float, CompressSource));
static void set_compress_bptc_func(void (*p_compress_func)(Image *, float, CompressSource));
static void set_compress_bc_func(void (*p_compress_func)(Image *, float, UsedChannels));
static void set_compress_bptc_func(void (*p_compress_func)(Image *, float, UsedChannels));
static String get_format_name(Format p_format);
Error load_png_from_buffer(const PoolVector<uint8_t> &p_array);
Error load_jpg_from_buffer(const PoolVector<uint8_t> &p_array);
Error load_webp_from_buffer(const PoolVector<uint8_t> &p_array);
void convert_rg_to_ra_rgba8();
void convert_ra_rgba8_to_rg();
Image(const uint8_t *p_mem_png_jpg, int p_len = -1);
Image(const char **p_xpm);
@ -337,17 +373,7 @@ public:
void lock();
void unlock();
//this is used for compression
enum DetectChannels {
DETECTED_L,
DETECTED_LA,
DETECTED_R,
DETECTED_RG,
DETECTED_RGB,
DETECTED_RGBA,
};
DetectChannels get_detected_channels();
UsedChannels detect_used_channels(CompressSource p_source = COMPRESS_SOURCE_GENERIC);
void optimize_channels();
Color get_pixelv(const Point2 &p_src) const;
@ -371,6 +397,8 @@ VARIANT_ENUM_CAST(Image::Format)
VARIANT_ENUM_CAST(Image::Interpolation)
VARIANT_ENUM_CAST(Image::CompressMode)
VARIANT_ENUM_CAST(Image::CompressSource)
VARIANT_ENUM_CAST(Image::UsedChannels)
VARIANT_ENUM_CAST(Image::AlphaMode)
VARIANT_ENUM_CAST(Image::RoughnessChannel)
#endif

View file

@ -86,9 +86,10 @@ void ConfigFile::set_value(const String &p_section, const String &p_key, const V
Variant ConfigFile::get_value(const String &p_section, const String &p_key, Variant p_default) const {
if (!values.has(p_section) || !values[p_section].has(p_key)) {
ERR_FAIL_COND_V_MSG(p_default.get_type() == Variant::NIL, p_default, "Couldn't find the given section/key and no default was given.");
ERR_FAIL_COND_V_MSG(p_default.get_type() == Variant::NIL, Variant(), "Couldn't find the given section '" + p_section + "', key '" + p_key + "' and no default was given.");
return p_default;
}
return values[p_section][p_key];
}

View file

@ -231,7 +231,7 @@ FileAccessNetworkClient::FileAccessNetworkClient() {
singleton = this;
last_id = 0;
client.instance();
sem = Semaphore::create();
sem = SemaphoreOld::create();
lockcount = 0;
}
@ -522,8 +522,8 @@ FileAccessNetwork::FileAccessNetwork() {
eof_flag = false;
opened = false;
pos = 0;
sem = Semaphore::create();
page_sem = Semaphore::create();
sem = SemaphoreOld::create();
page_sem = SemaphoreOld::create();
buffer_mutex = Mutex::create();
FileAccessNetworkClient *nc = FileAccessNetworkClient::singleton;
nc->lock_mutex();

View file

@ -49,7 +49,7 @@ class FileAccessNetworkClient {
List<BlockRequest> block_requests;
Semaphore *sem;
SemaphoreOld *sem;
Thread *thread;
bool quit;
Mutex *mutex;
@ -85,8 +85,8 @@ public:
class FileAccessNetwork : public FileAccess {
Semaphore *sem;
Semaphore *page_sem;
SemaphoreOld *sem;
SemaphoreOld *page_sem;
Mutex *buffer_mutex;
bool opened;
size_t total_size;

View file

@ -71,7 +71,7 @@ struct _IP_ResolverPrivate {
}
Mutex *mutex;
Semaphore *sem;
SemaphoreOld *sem;
Thread *thread;
//Semaphore* semaphore;
@ -319,7 +319,7 @@ IP::IP() {
#ifndef NO_THREADS
resolver->sem = Semaphore::create();
resolver->sem = SemaphoreOld::create();
if (resolver->sem) {
resolver->thread_abort = false;

View file

@ -1255,7 +1255,7 @@ String ResourceFormatLoaderBinary::get_resource_type(const String &p_path) const
ria->res_path = ria->local_path;
//ria->set_local_path( Globals::get_singleton()->localize_path(p_path) );
String r = ria->recognize(f);
return r;
return ClassDB::get_compatibility_remapped_class(r);
}
///////////////////////////////////////////////////////////

View file

@ -404,6 +404,7 @@ RES ResourceLoader::load(const String &p_path, const String &p_type_hint, bool p
if (!p_no_cache) {
_remove_from_loading_map(local_path);
}
print_verbose("Failed loading resource: " + path);
return RES();
}
if (!p_no_cache)
@ -728,8 +729,9 @@ String ResourceLoader::get_resource_type(const String &p_path) {
for (int i = 0; i < loader_count; i++) {
String result = loader[i]->get_resource_type(local_path);
if (result != "")
if (result != "") {
return result;
}
}
return "";

View file

@ -342,7 +342,7 @@ def make_version(template, nargs, argmax, const, ret):
def run(target, source, env):
versions = 13
versions = 15
versions_ext = 6
text = ""
text_ext = ""

View file

@ -244,6 +244,18 @@ void Basis::scale_local(const Vector3 &p_scale) {
*this = scaled_local(p_scale);
}
float Basis::get_uniform_scale() const {
return (elements[0].length() + elements[1].length() + elements[2].length()) / 3.0;
}
void Basis::make_scale_uniform() {
float l = (elements[0].length() + elements[1].length() + elements[2].length()) / 3.0;
for (int i = 0; i < 3; i++) {
elements[i].normalize();
elements[i] *= l;
}
}
Basis Basis::scaled_local(const Vector3 &p_scale) const {
Basis b;
b.set_diagonal(p_scale);

View file

@ -108,6 +108,9 @@ public:
void scale_local(const Vector3 &p_scale);
Basis scaled_local(const Vector3 &p_scale) const;
void make_scale_uniform();
float get_uniform_scale() const;
Vector3 get_scale() const;
Vector3 get_scale_abs() const;
Vector3 get_scale_local() const;

View file

@ -276,6 +276,36 @@ Vector2 CameraMatrix::get_viewport_half_extents() const {
return Vector2(res.x, res.y);
}
void CameraMatrix::get_far_plane_size(real_t &r_width, real_t &r_height) const {
const real_t *matrix = (const real_t *)this->matrix;
///////--- Far Plane ---///////
Plane far_plane = Plane(matrix[3] - matrix[2],
matrix[7] - matrix[6],
matrix[11] - matrix[10],
-matrix[15] + matrix[14]);
far_plane.normalize();
///////--- Right Plane ---///////
Plane right_plane = Plane(matrix[3] - matrix[0],
matrix[7] - matrix[4],
matrix[11] - matrix[8],
-matrix[15] + matrix[12]);
right_plane.normalize();
Plane top_plane = Plane(matrix[3] - matrix[1],
matrix[7] - matrix[5],
matrix[11] - matrix[9],
-matrix[15] + matrix[13]);
top_plane.normalize();
Vector3 res;
far_plane.intersect_3(right_plane, top_plane, &res);
r_width = res.x;
r_height = res.y;
}
bool CameraMatrix::get_endpoints(const Transform &p_transform, Vector3 *p_8points) const {
Vector<Plane> planes = get_projection_planes(Transform());
@ -485,6 +515,12 @@ void CameraMatrix::invert() {
}
}
void CameraMatrix::flip_y() {
for (int i = 0; i < 4; i++) {
matrix[1][i] = -matrix[1][i];
}
}
CameraMatrix::CameraMatrix() {
set_identity();
@ -506,6 +542,28 @@ CameraMatrix CameraMatrix::operator*(const CameraMatrix &p_matrix) const {
return new_matrix;
}
void CameraMatrix::set_depth_correction(bool p_flip_y) {
real_t *m = &matrix[0][0];
m[0] = 1;
m[1] = 0.0;
m[2] = 0.0;
m[3] = 0.0;
m[4] = 0.0;
m[5] = p_flip_y ? -1 : 1;
m[6] = 0.0;
m[7] = 0.0;
m[8] = 0.0;
m[9] = 0.0;
m[10] = 0.5;
m[11] = 0.0;
m[12] = 0.0;
m[13] = 0.0;
m[14] = 0.5;
m[15] = 1.0;
}
void CameraMatrix::set_light_bias() {
real_t *m = &matrix[0][0];

View file

@ -50,6 +50,7 @@ struct CameraMatrix {
void set_identity();
void set_zero();
void set_light_bias();
void set_depth_correction(bool p_flip_y = true);
void set_light_atlas_rect(const Rect2 &p_rect);
void set_perspective(real_t p_fovy_degrees, real_t p_aspect, real_t p_z_near, real_t p_z_far, bool p_flip_fov = false);
void set_perspective(real_t p_fovy_degrees, real_t p_aspect, real_t p_z_near, real_t p_z_far, bool p_flip_fov, int p_eye, real_t p_intraocular_dist, real_t p_convergence_dist);
@ -74,6 +75,7 @@ struct CameraMatrix {
bool get_endpoints(const Transform &p_transform, Vector3 *p_8points) const;
Vector2 get_viewport_half_extents() const;
void get_far_plane_size(real_t &r_width, real_t &r_height) const;
void invert();
CameraMatrix inverse() const;
@ -90,6 +92,23 @@ struct CameraMatrix {
int get_pixels_per_meter(int p_for_pixel_width) const;
operator Transform() const;
void flip_y();
bool operator==(const CameraMatrix &p_cam) const {
for (uint32_t i = 0; i < 4; i++) {
for (uint32_t j = 0; j < 4; j++) {
if (matrix[i][j] != p_cam.matrix[i][j]) {
return false;
}
}
}
return true;
}
bool operator!=(const CameraMatrix &p_cam) const {
return !(*this == p_cam);
}
CameraMatrix();
CameraMatrix(const Transform &p_transform);
~CameraMatrix();

View file

@ -103,7 +103,7 @@ Vector3 Vector3::cubic_interpolaten(const Vector3 &p_b, const Vector3 &p_pre_a,
Vector3 out;
out = 0.5 * ((p1 * 2.0) +
(-p0 + p2) * t +
(2.0 * p0 - 5.0 * p1 + 4 * p2 - p3) * t2 +
(2.0 * p0 - 5.0 * p1 + 4.0 * p2 - p3) * t2 +
(-p0 + 3.0 * p1 - 3.0 * p2 + p3) * t3);
return out;
}
@ -122,7 +122,7 @@ Vector3 Vector3::cubic_interpolate(const Vector3 &p_b, const Vector3 &p_pre_a, c
Vector3 out;
out = 0.5 * ((p1 * 2.0) +
(-p0 + p2) * t +
(2.0 * p0 - 5.0 * p1 + 4 * p2 - p3) * t2 +
(2.0 * p0 - 5.0 * p1 + 4.0 * p2 - p3) * t2 +
(-p0 + 3.0 * p1 - 3.0 * p2 + p3) * t3);
return out;
}

View file

@ -32,6 +32,7 @@
#define VECTOR3_H
#include "core/math/math_funcs.h"
#include "core/math/vector3i.h"
#include "core/ustring.h"
class Basis;
@ -147,6 +148,15 @@ struct Vector3 {
_FORCE_INLINE_ bool operator>=(const Vector3 &p_v) const;
operator String() const;
_FORCE_INLINE_ operator Vector3i() const {
return Vector3i(x, y, z);
}
_FORCE_INLINE_ Vector3(const Vector3i &p_ivec) {
x = p_ivec.x;
y = p_ivec.y;
z = p_ivec.z;
}
_FORCE_INLINE_ Vector3(real_t p_x, real_t p_y, real_t p_z) {
x = p_x;

55
core/math/vector3i.cpp Normal file
View file

@ -0,0 +1,55 @@
/*************************************************************************/
/* vector3i.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "vector3i.h"
void Vector3i::set_axis(int p_axis, int32_t p_value) {
ERR_FAIL_INDEX(p_axis, 3);
coord[p_axis] = p_value;
}
int32_t Vector3i::get_axis(int p_axis) const {
ERR_FAIL_INDEX_V(p_axis, 3, 0);
return operator[](p_axis);
}
int Vector3i::min_axis() const {
return x < y ? (x < z ? 0 : 2) : (y < z ? 1 : 2);
}
int Vector3i::max_axis() const {
return x < y ? (y < z ? 2 : 1) : (x < z ? 2 : 0);
}
Vector3i::operator String() const {
return (itos(x) + ", " + itos(y) + ", " + itos(z));
}

272
core/math/vector3i.h Normal file
View file

@ -0,0 +1,272 @@
/*************************************************************************/
/* vector3i.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#ifndef VECTOR3I_H
#define VECTOR3I_H
#include "core/typedefs.h"
#include "core/ustring.h"
struct Vector3i {
enum Axis {
AXIS_X,
AXIS_Y,
AXIS_Z,
};
union {
struct {
int32_t x;
int32_t y;
int32_t z;
};
int32_t coord[3];
};
_FORCE_INLINE_ const int32_t &operator[](int p_axis) const {
return coord[p_axis];
}
_FORCE_INLINE_ int32_t &operator[](int p_axis) {
return coord[p_axis];
}
void set_axis(int p_axis, int32_t p_value);
int32_t get_axis(int p_axis) const;
int min_axis() const;
int max_axis() const;
_FORCE_INLINE_ void zero();
_FORCE_INLINE_ Vector3i abs() const;
_FORCE_INLINE_ Vector3i sign() const;
/* Operators */
_FORCE_INLINE_ Vector3i &operator+=(const Vector3i &p_v);
_FORCE_INLINE_ Vector3i operator+(const Vector3i &p_v) const;
_FORCE_INLINE_ Vector3i &operator-=(const Vector3i &p_v);
_FORCE_INLINE_ Vector3i operator-(const Vector3i &p_v) const;
_FORCE_INLINE_ Vector3i &operator*=(const Vector3i &p_v);
_FORCE_INLINE_ Vector3i operator*(const Vector3i &p_v) const;
_FORCE_INLINE_ Vector3i &operator/=(const Vector3i &p_v);
_FORCE_INLINE_ Vector3i operator/(const Vector3i &p_v) const;
_FORCE_INLINE_ Vector3i &operator*=(int32_t p_scalar);
_FORCE_INLINE_ Vector3i operator*(int32_t p_scalar) const;
_FORCE_INLINE_ Vector3i &operator/=(int32_t p_scalar);
_FORCE_INLINE_ Vector3i operator/(int32_t p_scalar) const;
_FORCE_INLINE_ Vector3i operator-() const;
_FORCE_INLINE_ bool operator==(const Vector3i &p_v) const;
_FORCE_INLINE_ bool operator!=(const Vector3i &p_v) const;
_FORCE_INLINE_ bool operator<(const Vector3i &p_v) const;
_FORCE_INLINE_ bool operator<=(const Vector3i &p_v) const;
_FORCE_INLINE_ bool operator>(const Vector3i &p_v) const;
_FORCE_INLINE_ bool operator>=(const Vector3i &p_v) const;
operator String() const;
_FORCE_INLINE_ Vector3i(int32_t p_x, int32_t p_y, int32_t p_z) {
x = p_x;
y = p_y;
z = p_z;
}
_FORCE_INLINE_ Vector3i() { x = y = z = 0; }
};
Vector3i Vector3i::abs() const {
return Vector3i(ABS(x), ABS(y), ABS(z));
}
Vector3i Vector3i::sign() const {
return Vector3i(SGN(x), SGN(y), SGN(z));
}
/* Operators */
Vector3i &Vector3i::operator+=(const Vector3i &p_v) {
x += p_v.x;
y += p_v.y;
z += p_v.z;
return *this;
}
Vector3i Vector3i::operator+(const Vector3i &p_v) const {
return Vector3i(x + p_v.x, y + p_v.y, z + p_v.z);
}
Vector3i &Vector3i::operator-=(const Vector3i &p_v) {
x -= p_v.x;
y -= p_v.y;
z -= p_v.z;
return *this;
}
Vector3i Vector3i::operator-(const Vector3i &p_v) const {
return Vector3i(x - p_v.x, y - p_v.y, z - p_v.z);
}
Vector3i &Vector3i::operator*=(const Vector3i &p_v) {
x *= p_v.x;
y *= p_v.y;
z *= p_v.z;
return *this;
}
Vector3i Vector3i::operator*(const Vector3i &p_v) const {
return Vector3i(x * p_v.x, y * p_v.y, z * p_v.z);
}
Vector3i &Vector3i::operator/=(const Vector3i &p_v) {
x /= p_v.x;
y /= p_v.y;
z /= p_v.z;
return *this;
}
Vector3i Vector3i::operator/(const Vector3i &p_v) const {
return Vector3i(x / p_v.x, y / p_v.y, z / p_v.z);
}
Vector3i &Vector3i::operator*=(int32_t p_scalar) {
x *= p_scalar;
y *= p_scalar;
z *= p_scalar;
return *this;
}
_FORCE_INLINE_ Vector3i operator*(int32_t p_scalar, const Vector3i &p_vec) {
return p_vec * p_scalar;
}
Vector3i Vector3i::operator*(int32_t p_scalar) const {
return Vector3i(x * p_scalar, y * p_scalar, z * p_scalar);
}
Vector3i &Vector3i::operator/=(int32_t p_scalar) {
x /= p_scalar;
y /= p_scalar;
z /= p_scalar;
return *this;
}
Vector3i Vector3i::operator/(int32_t p_scalar) const {
return Vector3i(x / p_scalar, y / p_scalar, z / p_scalar);
}
Vector3i Vector3i::operator-() const {
return Vector3i(-x, -y, -z);
}
bool Vector3i::operator==(const Vector3i &p_v) const {
return (x == p_v.x && y == p_v.y && z == p_v.z);
}
bool Vector3i::operator!=(const Vector3i &p_v) const {
return (x != p_v.x || y != p_v.y || z != p_v.z);
}
bool Vector3i::operator<(const Vector3i &p_v) const {
if (x == p_v.x) {
if (y == p_v.y)
return z < p_v.z;
else
return y < p_v.y;
} else {
return x < p_v.x;
}
}
bool Vector3i::operator>(const Vector3i &p_v) const {
if (x == p_v.x) {
if (y == p_v.y)
return z > p_v.z;
else
return y > p_v.y;
} else {
return x > p_v.x;
}
}
bool Vector3i::operator<=(const Vector3i &p_v) const {
if (x == p_v.x) {
if (y == p_v.y)
return z <= p_v.z;
else
return y < p_v.y;
} else {
return x < p_v.x;
}
}
bool Vector3i::operator>=(const Vector3i &p_v) const {
if (x == p_v.x) {
if (y == p_v.y)
return z >= p_v.z;
else
return y > p_v.y;
} else {
return x > p_v.x;
}
}
void Vector3i::zero() {
x = y = z = 0;
}
#endif // VECTOR3I_H

View file

@ -240,6 +240,22 @@ public:
return false;
}
/**
* returns true if the value was found, false otherwise.
*
* if r_data is not NULL then the value will be written to the object
* it points to.
*/
TValue *lookup_ptr(const TKey &p_key) const {
uint32_t pos = 0;
bool exists = _lookup_pos(p_key, pos);
if (exists) {
return &values[pos];
}
return NULL;
}
_FORCE_INLINE_ bool has(const TKey &p_key) const {
uint32_t _pos = 0;
return _lookup_pos(p_key, _pos);

View file

@ -691,9 +691,9 @@ const char *OS::get_video_driver_name(int p_driver) const {
switch (p_driver) {
case VIDEO_DRIVER_GLES2:
return "GLES2";
case VIDEO_DRIVER_GLES3:
case VIDEO_DRIVER_VULKAN:
default:
return "GLES3";
return "Vulkan";
}
}

View file

@ -181,7 +181,7 @@ public:
virtual void get_fullscreen_mode_list(List<VideoMode> *p_list, int p_screen = 0) const = 0;
enum VideoDriver {
VIDEO_DRIVER_GLES3,
VIDEO_DRIVER_VULKAN,
VIDEO_DRIVER_GLES2,
VIDEO_DRIVER_MAX,
};

View file

@ -32,14 +32,14 @@
#include "core/error_macros.h"
Semaphore *(*Semaphore::create_func)() = 0;
SemaphoreOld *(*SemaphoreOld::create_func)() = 0;
Semaphore *Semaphore::create() {
SemaphoreOld *SemaphoreOld::create() {
ERR_FAIL_COND_V(!create_func, 0);
return create_func();
}
Semaphore::~Semaphore() {
SemaphoreOld::~SemaphoreOld() {
}

View file

@ -32,19 +32,53 @@
#define SEMAPHORE_H
#include "core/error_list.h"
#include "core/typedefs.h"
#include <condition_variable>
#include <mutex>
class Semaphore {
private:
std::mutex mutex_;
std::condition_variable condition_;
unsigned long count_ = 0; // Initialized as locked.
public:
_ALWAYS_INLINE_ void post() {
std::lock_guard<decltype(mutex_)> lock(mutex_);
++count_;
condition_.notify_one();
}
_ALWAYS_INLINE_ void wait() {
std::unique_lock<decltype(mutex_)> lock(mutex_);
while (!count_) // Handle spurious wake-ups.
condition_.wait(lock);
--count_;
}
_ALWAYS_INLINE_ bool try_wait() {
std::lock_guard<decltype(mutex_)> lock(mutex_);
if (count_) {
--count_;
return true;
}
return false;
}
};
class SemaphoreOld {
protected:
static Semaphore *(*create_func)();
static SemaphoreOld *(*create_func)();
public:
virtual Error wait() = 0; ///< wait until semaphore has positive value, then decrement and pass
virtual Error post() = 0; ///< unlock the semaphore, incrementing the value
virtual int get() const = 0; ///< get semaphore value
static Semaphore *create(); ///< Create a mutex
static SemaphoreOld *create(); ///< Create a mutex
virtual ~Semaphore();
virtual ~SemaphoreOld();
};
#endif

View file

@ -48,12 +48,12 @@ void MutexDummy::make_default() {
Mutex::create_func = &MutexDummy::create;
};
Semaphore *SemaphoreDummy::create() {
SemaphoreOld *SemaphoreDummy::create() {
return memnew(SemaphoreDummy);
};
void SemaphoreDummy::make_default() {
Semaphore::create_func = &SemaphoreDummy::create;
SemaphoreOld::create_func = &SemaphoreDummy::create;
};
RWLock *RWLockDummy::create() {

View file

@ -58,9 +58,9 @@ public:
static void make_default();
};
class SemaphoreDummy : public Semaphore {
class SemaphoreDummy : public SemaphoreOld {
static Semaphore *create();
static SemaphoreOld *create();
public:
virtual Error wait() { return OK; };

View file

@ -32,172 +32,46 @@
#define RID_H
#include "core/list.h"
#include "core/oa_hash_map.h"
#include "core/os/memory.h"
#include "core/safe_refcount.h"
#include "core/set.h"
#include "core/typedefs.h"
class RID_OwnerBase;
class RID_Data {
friend class RID_OwnerBase;
#ifndef DEBUG_ENABLED
RID_OwnerBase *_owner;
#endif
uint32_t _id;
public:
_FORCE_INLINE_ uint32_t get_id() const { return _id; }
virtual ~RID_Data();
};
class RID_AllocBase;
class RID {
friend class RID_OwnerBase;
mutable RID_Data *_data;
friend class RID_AllocBase;
uint64_t _id;
public:
_FORCE_INLINE_ RID_Data *get_data() const { return _data; }
_FORCE_INLINE_ bool operator==(const RID &p_rid) const {
return _data == p_rid._data;
return _id == p_rid._id;
}
_FORCE_INLINE_ bool operator<(const RID &p_rid) const {
return _data < p_rid._data;
return _id < p_rid._id;
}
_FORCE_INLINE_ bool operator<=(const RID &p_rid) const {
return _data <= p_rid._data;
return _id <= p_rid._id;
}
_FORCE_INLINE_ bool operator>(const RID &p_rid) const {
return _data > p_rid._data;
return _id > p_rid._id;
}
_FORCE_INLINE_ bool operator!=(const RID &p_rid) const {
return _data != p_rid._data;
return _id != p_rid._id;
}
_FORCE_INLINE_ bool is_valid() const { return _data != NULL; }
_FORCE_INLINE_ bool is_valid() const { return _id != 0; }
_FORCE_INLINE_ bool is_null() const { return _id == 0; }
_FORCE_INLINE_ uint32_t get_id() const { return _data ? _data->get_id() : 0; }
_FORCE_INLINE_ uint64_t get_id() const { return _id; }
_FORCE_INLINE_ RID() {
_data = NULL;
}
};
class RID_OwnerBase {
protected:
static SafeRefCount refcount;
_FORCE_INLINE_ void _set_data(RID &p_rid, RID_Data *p_data) {
p_rid._data = p_data;
refcount.ref();
p_data->_id = refcount.get();
#ifndef DEBUG_ENABLED
p_data->_owner = this;
#endif
}
#ifndef DEBUG_ENABLED
_FORCE_INLINE_ bool _is_owner(const RID &p_rid) const {
return this == p_rid._data->_owner;
}
_FORCE_INLINE_ void _remove_owner(RID &p_rid) {
p_rid._data->_owner = NULL;
}
#endif
public:
virtual void get_owned_list(List<RID> *p_owned) = 0;
static void init_rid();
virtual ~RID_OwnerBase() {}
};
template <class T>
class RID_Owner : public RID_OwnerBase {
public:
#ifdef DEBUG_ENABLED
mutable Set<RID_Data *> id_map;
#endif
public:
_FORCE_INLINE_ RID make_rid(T *p_data) {
RID rid;
_set_data(rid, p_data);
#ifdef DEBUG_ENABLED
id_map.insert(p_data);
#endif
return rid;
}
_FORCE_INLINE_ T *get(const RID &p_rid) {
#ifdef DEBUG_ENABLED
ERR_FAIL_COND_V(!p_rid.is_valid(), NULL);
ERR_FAIL_COND_V(!id_map.has(p_rid.get_data()), NULL);
#endif
return static_cast<T *>(p_rid.get_data());
}
_FORCE_INLINE_ T *getornull(const RID &p_rid) {
#ifdef DEBUG_ENABLED
if (p_rid.get_data()) {
ERR_FAIL_COND_V(!id_map.has(p_rid.get_data()), NULL);
}
#endif
return static_cast<T *>(p_rid.get_data());
}
_FORCE_INLINE_ T *getptr(const RID &p_rid) {
return static_cast<T *>(p_rid.get_data());
}
_FORCE_INLINE_ bool owns(const RID &p_rid) const {
if (p_rid.get_data() == NULL)
return false;
#ifdef DEBUG_ENABLED
return id_map.has(p_rid.get_data());
#else
return _is_owner(p_rid);
#endif
}
void free(RID p_rid) {
#ifdef DEBUG_ENABLED
id_map.erase(p_rid.get_data());
#else
_remove_owner(p_rid);
#endif
}
void get_owned_list(List<RID> *p_owned) {
#ifdef DEBUG_ENABLED
for (typename Set<RID_Data *>::Element *E = id_map.front(); E; E = E->next()) {
RID r;
_set_data(r, static_cast<T *>(E->get()));
p_owned->push_back(r);
}
#endif
_id = 0;
}
};

View file

@ -1,5 +1,5 @@
/*************************************************************************/
/* rid.cpp */
/* rid_owner.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@ -28,14 +28,6 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "rid.h"
#include "rid_owner.h"
RID_Data::~RID_Data() {
}
SafeRefCount RID_OwnerBase::refcount;
void RID_OwnerBase::init_rid() {
refcount.init();
}
volatile uint64_t RID_AllocBase::base_id = 1;

406
core/rid_owner.h Normal file
View file

@ -0,0 +1,406 @@
/*************************************************************************/
/* rid_owner.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#ifndef RID_OWNER_H
#define RID_OWNER_H
#include "core/print_string.h"
#include "core/rid.h"
#include "core/spin_lock.h"
#include <stdio.h>
#include <typeinfo>
class RID_AllocBase {
static volatile uint64_t base_id;
protected:
static RID _make_from_id(uint64_t p_id) {
RID rid;
rid._id = p_id;
return rid;
}
static uint64_t _gen_id() {
return atomic_increment(&base_id);
}
static RID _gen_rid() {
return _make_from_id(_gen_id());
}
public:
virtual ~RID_AllocBase() {}
};
template <class T, bool THREAD_SAFE = false>
class RID_Alloc : public RID_AllocBase {
T **chunks;
uint32_t **free_list_chunks;
uint32_t **validator_chunks;
uint32_t elements_in_chunk;
uint32_t max_alloc;
uint32_t alloc_count;
const char *description;
SpinLock spin_lock;
public:
RID make_rid(const T &p_value) {
if (THREAD_SAFE) {
spin_lock.lock();
}
if (alloc_count == max_alloc) {
//allocate a new chunk
uint32_t chunk_count = alloc_count == 0 ? 0 : (max_alloc / elements_in_chunk);
//grow chunks
chunks = (T **)memrealloc(chunks, sizeof(T *) * (chunk_count + 1));
chunks[chunk_count] = (T *)memalloc(sizeof(T) * elements_in_chunk); //but don't initialize
//grow validators
validator_chunks = (uint32_t **)memrealloc(validator_chunks, sizeof(uint32_t *) * (chunk_count + 1));
validator_chunks[chunk_count] = (uint32_t *)memalloc(sizeof(uint32_t) * elements_in_chunk);
//grow free lists
free_list_chunks = (uint32_t **)memrealloc(free_list_chunks, sizeof(uint32_t *) * (chunk_count + 1));
free_list_chunks[chunk_count] = (uint32_t *)memalloc(sizeof(uint32_t) * elements_in_chunk);
//initialize
for (uint32_t i = 0; i < elements_in_chunk; i++) {
//dont initialize chunk
validator_chunks[chunk_count][i] = 0xFFFFFFFF;
free_list_chunks[chunk_count][i] = alloc_count + i;
}
max_alloc += elements_in_chunk;
}
uint32_t free_index = free_list_chunks[alloc_count / elements_in_chunk][alloc_count % elements_in_chunk];
uint32_t free_chunk = free_index / elements_in_chunk;
uint32_t free_element = free_index % elements_in_chunk;
T *ptr = &chunks[free_chunk][free_element];
memnew_placement(ptr, T(p_value));
uint32_t validator = (uint32_t)(_gen_id() & 0xFFFFFFFF);
uint64_t id = validator;
id <<= 32;
id |= free_index;
validator_chunks[free_chunk][free_element] = validator;
alloc_count++;
if (THREAD_SAFE) {
spin_lock.unlock();
}
return _make_from_id(id);
}
_FORCE_INLINE_ T *getornull(const RID &p_rid) {
if (THREAD_SAFE) {
spin_lock.lock();
}
uint64_t id = p_rid.get_id();
uint32_t idx = uint32_t(id & 0xFFFFFFFF);
if (unlikely(idx >= max_alloc)) {
if (THREAD_SAFE) {
spin_lock.unlock();
}
return NULL;
}
uint32_t idx_chunk = idx / elements_in_chunk;
uint32_t idx_element = idx % elements_in_chunk;
uint32_t validator = uint32_t(id >> 32);
if (unlikely(validator_chunks[idx_chunk][idx_element] != validator)) {
if (THREAD_SAFE) {
spin_lock.unlock();
}
return NULL;
}
T *ptr = &chunks[idx_chunk][idx_element];
if (THREAD_SAFE) {
spin_lock.unlock();
}
return ptr;
}
_FORCE_INLINE_ bool owns(const RID &p_rid) {
if (THREAD_SAFE) {
spin_lock.lock();
}
uint64_t id = p_rid.get_id();
uint32_t idx = uint32_t(id & 0xFFFFFFFF);
if (unlikely(idx >= max_alloc)) {
if (THREAD_SAFE) {
spin_lock.unlock();
}
return false;
}
uint32_t idx_chunk = idx / elements_in_chunk;
uint32_t idx_element = idx % elements_in_chunk;
uint32_t validator = uint32_t(id >> 32);
bool owned = validator_chunks[idx_chunk][idx_element] == validator;
if (THREAD_SAFE) {
spin_lock.unlock();
}
return owned;
}
_FORCE_INLINE_ void free(const RID &p_rid) {
if (THREAD_SAFE) {
spin_lock.lock();
}
uint64_t id = p_rid.get_id();
uint32_t idx = uint32_t(id & 0xFFFFFFFF);
if (unlikely(idx >= max_alloc)) {
if (THREAD_SAFE) {
spin_lock.unlock();
}
ERR_FAIL();
}
uint32_t idx_chunk = idx / elements_in_chunk;
uint32_t idx_element = idx % elements_in_chunk;
uint32_t validator = uint32_t(id >> 32);
if (unlikely(validator_chunks[idx_chunk][idx_element] != validator)) {
if (THREAD_SAFE) {
spin_lock.unlock();
}
ERR_FAIL();
}
chunks[idx_chunk][idx_element].~T();
validator_chunks[idx_chunk][idx_element] = 0xFFFFFFFF; // go invalid
alloc_count--;
free_list_chunks[alloc_count / elements_in_chunk][alloc_count % elements_in_chunk] = idx;
if (THREAD_SAFE) {
spin_lock.unlock();
}
}
_FORCE_INLINE_ uint32_t get_rid_count() const {
return alloc_count;
}
_FORCE_INLINE_ T *get_ptr_by_index(uint32_t p_index) {
ERR_FAIL_INDEX_V(p_index, alloc_count, NULL);
if (THREAD_SAFE) {
spin_lock.lock();
}
uint64_t idx = free_list_chunks[p_index / elements_in_chunk][p_index % elements_in_chunk];
T *ptr = &chunks[idx / elements_in_chunk][idx % elements_in_chunk];
if (THREAD_SAFE) {
spin_lock.unlock();
}
return ptr;
}
_FORCE_INLINE_ RID get_rid_by_index(uint32_t p_index) {
ERR_FAIL_INDEX_V(p_index, alloc_count, RID());
if (THREAD_SAFE) {
spin_lock.lock();
}
uint64_t idx = free_list_chunks[p_index / elements_in_chunk][p_index % elements_in_chunk];
uint64_t validator = validator_chunks[idx / elements_in_chunk][idx % elements_in_chunk];
RID rid = _make_from_id((validator << 32) | idx);
if (THREAD_SAFE) {
spin_lock.unlock();
}
return rid;
}
void get_owned_list(List<RID> *p_owned) {
if (THREAD_SAFE) {
spin_lock.lock();
}
for (size_t i = 0; i < max_alloc; i++) {
uint64_t validator = validator_chunks[i / elements_in_chunk][i % elements_in_chunk];
if (validator != 0xFFFFFFFF) {
p_owned->push_back(_make_from_id((validator << 32) | i));
}
}
if (THREAD_SAFE) {
spin_lock.unlock();
}
}
void set_description(const char *p_descrption) {
description = p_descrption;
}
RID_Alloc(uint32_t p_target_chunk_byte_size = 4096) {
chunks = NULL;
free_list_chunks = NULL;
validator_chunks = NULL;
elements_in_chunk = sizeof(T) > p_target_chunk_byte_size ? 1 : (p_target_chunk_byte_size / sizeof(T));
max_alloc = 0;
alloc_count = 0;
description = NULL;
}
~RID_Alloc() {
if (alloc_count) {
if (description) {
print_error("ERROR: " + itos(alloc_count) + " RID allocations of type '" + description + "' were leaked at exit.");
} else {
print_error("ERROR: " + itos(alloc_count) + " RID allocations of type '" + typeid(T).name() + "' were leaked at exit.");
}
for (size_t i = 0; i < max_alloc; i++) {
uint64_t validator = validator_chunks[i / elements_in_chunk][i % elements_in_chunk];
if (validator != 0xFFFFFFFF) {
chunks[i / elements_in_chunk][i % elements_in_chunk].~T();
}
}
}
uint32_t chunk_count = max_alloc / elements_in_chunk;
for (uint32_t i = 0; i < chunk_count; i++) {
memfree(chunks[i]);
memfree(validator_chunks[i]);
memfree(free_list_chunks[i]);
}
if (chunks) {
memfree(chunks);
memfree(free_list_chunks);
memfree(validator_chunks);
}
}
};
template <class T, bool THREAD_SAFE = false>
class RID_PtrOwner {
RID_Alloc<T *, THREAD_SAFE> alloc;
public:
_FORCE_INLINE_ RID make_rid(T *p_ptr) {
return alloc.make_rid(p_ptr);
}
_FORCE_INLINE_ T *getornull(const RID &p_rid) {
T **ptr = alloc.getornull(p_rid);
if (unlikely(!ptr)) {
return NULL;
}
return *ptr;
}
_FORCE_INLINE_ bool owns(const RID &p_rid) {
return alloc.owns(p_rid);
}
_FORCE_INLINE_ void free(const RID &p_rid) {
alloc.free(p_rid);
}
_FORCE_INLINE_ void get_owned_list(List<RID> *p_owned) {
return alloc.get_owned_list(p_owned);
}
void set_description(const char *p_descrption) {
alloc.set_description(p_descrption);
}
RID_PtrOwner(uint32_t p_target_chunk_byte_size = 4096) :
alloc(p_target_chunk_byte_size) {}
};
template <class T, bool THREAD_SAFE = false>
class RID_Owner {
RID_Alloc<T, THREAD_SAFE> alloc;
public:
_FORCE_INLINE_ RID make_rid(const T &p_ptr) {
return alloc.make_rid(p_ptr);
}
_FORCE_INLINE_ T *getornull(const RID &p_rid) {
return alloc.getornull(p_rid);
}
_FORCE_INLINE_ bool owns(const RID &p_rid) {
return alloc.owns(p_rid);
}
_FORCE_INLINE_ void free(const RID &p_rid) {
alloc.free(p_rid);
}
_FORCE_INLINE_ uint32_t get_rid_count() const {
return alloc.get_rid_count();
}
_FORCE_INLINE_ RID get_rid_by_index(uint32_t p_index) {
return alloc.get_rid_by_index(p_index);
}
_FORCE_INLINE_ T *get_ptr_by_index(uint32_t p_index) {
return alloc.get_ptr_by_index(p_index);
}
_FORCE_INLINE_ void get_owned_list(List<RID> *p_owned) {
return alloc.get_owned_list(p_owned);
}
void set_description(const char *p_descrption) {
alloc.set_description(p_descrption);
}
RID_Owner(uint32_t p_target_chunk_byte_size = 4096) :
alloc(p_target_chunk_byte_size) {}
};
#endif // RID_OWNER_H

50
core/spin_lock.h Normal file
View file

@ -0,0 +1,50 @@
/*************************************************************************/
/* spin_lock.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#ifndef SPIN_LOCK_H
#define SPIN_LOCK_H
#include "core/typedefs.h"
#include <atomic>
class SpinLock {
std::atomic_flag locked = ATOMIC_FLAG_INIT;
public:
_ALWAYS_INLINE_ void lock() {
while (locked.test_and_set(std::memory_order_acquire)) {
;
}
}
_ALWAYS_INLINE_ void unlock() {
locked.clear(std::memory_order_release);
}
};
#endif // SPIN_LOCK_H

83
core/thread_work_pool.cpp Normal file
View file

@ -0,0 +1,83 @@
/*************************************************************************/
/* thread_work_pool.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "thread_work_pool.h"
#include "core/os/os.h"
void ThreadWorkPool::_thread_function(ThreadData *p_thread) {
while (true) {
p_thread->start.wait();
if (p_thread->exit.load()) {
break;
}
p_thread->work->work();
p_thread->completed.post();
}
}
void ThreadWorkPool::init(int p_thread_count) {
ERR_FAIL_COND(threads != nullptr);
if (p_thread_count < 0) {
p_thread_count = OS::get_singleton()->get_processor_count();
}
thread_count = p_thread_count;
threads = memnew_arr(ThreadData, thread_count);
for (uint32_t i = 0; i < thread_count; i++) {
threads[i].exit.store(false);
threads[i].thread = memnew(std::thread(ThreadWorkPool::_thread_function, &threads[i]));
}
}
void ThreadWorkPool::finish() {
if (threads == nullptr) {
return;
}
for (uint32_t i = 0; i < thread_count; i++) {
threads[i].exit.store(true);
threads[i].start.post();
}
for (uint32_t i = 0; i < thread_count; i++) {
threads[i].thread->join();
memdelete(threads[i].thread);
}
memdelete_arr(threads);
threads = nullptr;
}
ThreadWorkPool::~ThreadWorkPool() {
finish();
}

108
core/thread_work_pool.h Normal file
View file

@ -0,0 +1,108 @@
/*************************************************************************/
/* thread_work_pool.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#ifndef THREAD_WORK_POOL_H
#define THREAD_WORK_POOL_H
#include "core/os/memory.h"
#include "core/os/semaphore.h"
#include <atomic>
#include <thread>
class ThreadWorkPool {
std::atomic<uint32_t> index;
struct BaseWork {
std::atomic<uint32_t> *index;
uint32_t max_elements;
virtual void work() = 0;
};
template <class C, class M, class U>
struct Work : public BaseWork {
C *instance;
M method;
U userdata;
virtual void work() {
while (true) {
uint32_t work_index = index->fetch_add(1, std::memory_order_relaxed);
if (work_index >= max_elements) {
break;
}
(instance->*method)(work_index, userdata);
}
}
};
struct ThreadData {
std::thread *thread;
Semaphore start;
Semaphore completed;
std::atomic<bool> exit;
BaseWork *work;
};
ThreadData *threads = nullptr;
uint32_t thread_count = 0;
static void _thread_function(ThreadData *p_thread);
public:
template <class C, class M, class U>
void do_work(uint32_t p_elements, C *p_instance, M p_method, U p_userdata) {
ERR_FAIL_COND(!threads); //never initialized
index.store(0);
Work<C, M, U> *w = memnew((Work<C, M, U>));
w->instance = p_instance;
w->userdata = p_userdata;
w->method = p_method;
w->index = &index;
w->max_elements = p_elements;
for (uint32_t i = 0; i < thread_count; i++) {
threads[i].work = w;
threads[i].start.post();
}
for (uint32_t i = 0; i < thread_count; i++) {
threads[i].completed.wait();
threads[i].work = nullptr;
}
}
void init(int p_thread_count = -1);
void finish();
~ThreadWorkPool();
};
#endif // THREAD_POOL_H

View file

@ -646,6 +646,17 @@ String String::camelcase_to_underscore(bool lowercase) const {
return lowercase ? new_string.to_lower() : new_string;
}
String String::get_with_code_lines() const {
Vector<String> lines = split("\n");
String ret;
for (int i = 0; i < lines.size(); i++) {
if (i > 0) {
ret += "\n";
}
ret += itos(i + 1) + " " + lines[i];
}
return ret;
}
int String::get_slice_count(String p_splitter) const {
if (empty())

View file

@ -258,6 +258,7 @@ public:
String capitalize() const;
String camelcase_to_underscore(bool lowercase = true) const;
String get_with_code_lines() const;
int get_slice_count(String p_splitter) const;
String get_slice(String p_splitter, int p_slice) const;
String get_slicec(CharType p_splitter, int p_slice) const;

View file

@ -432,8 +432,6 @@
</argument>
<argument index="10" name="antialiased" type="bool" default="false">
</argument>
<argument index="11" name="antialiasing_use_indices" type="bool" default="false">
</argument>
<description>
Adds a triangle array to the [CanvasItem]'s draw commands.
</description>

View file

@ -24,14 +24,16 @@ SConscript('winmidi/SCsub')
# Graphics drivers
if (env["platform"] != "server"):
SConscript('gles3/SCsub')
SConscript('gles2/SCsub')
# SConscript('gles3/SCsub')
# SConscript('gles2/SCsub')
SConscript('vulkan/SCsub')
SConscript('gl_context/SCsub')
else:
SConscript('dummy/SCsub')
# Core dependencies
SConscript("png/SCsub")
SConscript("spirv-reflect/SCsub")
if env['vsproj']:
import os

View file

@ -32,6 +32,7 @@
#define RASTERIZER_DUMMY_H
#include "core/math/camera_matrix.h"
#include "core/rid_owner.h"
#include "core/self_list.h"
#include "scene/resources/mesh.h"
#include "servers/visual/rasterizer.h"
@ -121,7 +122,7 @@ public:
class RasterizerStorageDummy : public RasterizerStorage {
public:
/* TEXTURE API */
struct DummyTexture : public RID_Data {
struct DummyTexture {
int width;
int height;
uint32_t flags;
@ -142,14 +143,14 @@ public:
Vector<AABB> bone_aabbs;
};
struct DummyMesh : public RID_Data {
struct DummyMesh {
Vector<DummySurface> surfaces;
int blend_shape_count;
VS::BlendShapeMode blend_shape_mode;
};
mutable RID_Owner<DummyTexture> texture_owner;
mutable RID_Owner<DummyMesh> mesh_owner;
mutable RID_PtrOwner<DummyTexture> texture_owner;
mutable RID_PtrOwner<DummyMesh> mesh_owner;
RID texture_create() {
@ -178,7 +179,7 @@ public:
}
void texture_set_data_partial(RID p_texture, const Ref<Image> &p_image, int src_x, int src_y, int src_w, int src_h, int dst_x, int dst_y, int p_dst_mip, int p_level) {
DummyTexture *t = texture_owner.get(p_texture);
DummyTexture *t = texture_owner.getornull(p_texture);
ERR_FAIL_COND(!t);
ERR_FAIL_COND_MSG(p_image.is_null(), "It's not a reference to a valid Image object.");
@ -588,7 +589,7 @@ public:
void gi_probe_dynamic_data_update(RID p_gi_probe_data, int p_depth_slice, int p_slice_count, int p_mipmap, const void *p_data) {}
/* LIGHTMAP CAPTURE */
struct Instantiable : public RID_Data {
struct Instantiable {
SelfList<RasterizerScene::InstanceBase>::List instance_list;
@ -630,7 +631,7 @@ public:
}
};
mutable RID_Owner<LightmapCapture> lightmap_capture_data_owner;
mutable RID_PtrOwner<LightmapCapture> lightmap_capture_data_owner;
void lightmap_capture_set_bounds(RID p_capture, const AABB &p_bounds) {}
AABB lightmap_capture_get_bounds(RID p_capture) const { return AABB(); }
void lightmap_capture_set_octree(RID p_capture, const PoolVector<uint8_t> &p_octree) {}
@ -700,7 +701,7 @@ public:
void render_target_set_external_texture(RID p_render_target, unsigned int p_texture_id) {}
void render_target_set_flag(RID p_render_target, RenderTargetFlags p_flag, bool p_value) {}
bool render_target_was_used(RID p_render_target) { return false; }
void render_target_clear_used(RID p_render_target) {}
void render_target_set_as_unused(RID p_render_target) {}
void render_target_set_msaa(RID p_render_target, VS::ViewportMSAA p_msaa) {}
/* CANVAS SHADOW */
@ -724,7 +725,7 @@ public:
if (texture_owner.owns(p_rid)) {
// delete the texture
DummyTexture *texture = texture_owner.get(p_rid);
DummyTexture *texture = texture_owner.getornull(p_rid);
texture_owner.free(p_rid);
memdelete(texture);
}
@ -793,7 +794,7 @@ public:
void clear_render_target(const Color &p_color) {}
void blit_render_target_to_screen(RID p_render_target, const Rect2 &p_screen_rect, int p_screen = 0) {}
void output_lens_distorted_to_screen(RID p_render_target, const Rect2 &p_screen_rect, float p_k1, float p_k2, const Vector2 &p_eye_center, float p_oversample) {}
void end_frame(bool p_swap_buffers) {}
void end_frame(bool p_swap_buffers) { OS::get_singleton()->swap_buffers(); }
void finalize() {}
static Error is_viable() {

View file

@ -74,7 +74,7 @@ void ResourceFormatDummyTexture::get_recognized_extensions(List<String> *p_exten
}
bool ResourceFormatDummyTexture::handles_type(const String &p_type) const {
return ClassDB::is_parent_class(p_type, "Texture");
return ClassDB::is_parent_class(p_type, "Texture2D");
}
String ResourceFormatDummyTexture::get_resource_type(const String &p_path) const {

View file

@ -88,7 +88,7 @@ void RasterizerCanvasGLES2::_set_uniforms() {
state.canvas_shader.set_uniform(CanvasShaderGLES2::LIGHT_OUTSIDE_ALPHA, light->mode == VS::CANVAS_LIGHT_MODE_MASK ? 1.0 : 0.0);
if (state.using_shadow) {
RasterizerStorageGLES2::CanvasLightShadow *cls = storage->canvas_light_shadow_owner.get(light->shadow_buffer);
RasterizerStorageGLES2::CanvasLightShadow *cls = storage->canvas_light_shadow_owner.getornull(light->shadow_buffer);
glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 5);
glBindTexture(GL_TEXTURE_2D, cls->distance);
state.canvas_shader.set_uniform(CanvasShaderGLES2::SHADOW_MATRIX, light->shadow_matrix_cache);
@ -1033,11 +1033,11 @@ void RasterizerCanvasGLES2::_canvas_item_render_commands(Item *p_item, Item *cur
#ifdef GLES_OVER_GL
if (polygon->antialiased) {
glEnable(GL_LINE_SMOOTH);
if (polygon->antialiasing_use_indices) {
_draw_generic_indices(GL_LINE_STRIP, polygon->indices.ptr(), polygon->count, polygon->points.size(), polygon->points.ptr(), polygon->uvs.ptr(), polygon->colors.ptr(), polygon->colors.size() == 1);
} else {
_draw_generic(GL_LINE_LOOP, polygon->points.size(), polygon->points.ptr(), polygon->uvs.ptr(), polygon->colors.ptr(), polygon->colors.size() == 1);
}
// FIXME: Removed during Vulkan rebase.
//if (polygon->antialiasing_use_indices) {
// _draw_generic_indices(GL_LINE_STRIP, polygon->indices.ptr(), polygon->count, polygon->points.size(), polygon->points.ptr(), polygon->uvs.ptr(), polygon->colors.ptr(), polygon->colors.size() == 1);
//} else
_draw_generic(GL_LINE_LOOP, polygon->points.size(), polygon->points.ptr(), polygon->uvs.ptr(), polygon->colors.ptr(), polygon->colors.size() == 1);
glDisable(GL_LINE_SMOOTH);
}
#endif
@ -1480,7 +1480,7 @@ void RasterizerCanvasGLES2::canvas_render_items(Item *p_item_list, int p_z, cons
{
//skeleton handling
if (ci->skeleton.is_valid() && storage->skeleton_owner.owns(ci->skeleton)) {
skeleton = storage->skeleton_owner.get(ci->skeleton);
skeleton = storage->skeleton_owner.getornull(ci->skeleton);
if (!skeleton->use_2d) {
skeleton = NULL;
} else {
@ -1825,7 +1825,7 @@ void RasterizerCanvasGLES2::canvas_debug_viewport_shadows(Light *p_lights_with_s
void RasterizerCanvasGLES2::canvas_light_shadow_buffer_update(RID p_buffer, const Transform2D &p_light_xform, int p_light_mask, float p_near, float p_far, LightOccluderInstance *p_occluders, CameraMatrix *p_xform_cache) {
RasterizerStorageGLES2::CanvasLightShadow *cls = storage->canvas_light_shadow_owner.get(p_buffer);
RasterizerStorageGLES2::CanvasLightShadow *cls = storage->canvas_light_shadow_owner.getornull(p_buffer);
ERR_FAIL_COND(!cls);
glDisable(GL_BLEND);

View file

@ -384,7 +384,7 @@ void RasterizerGLES2::set_boot_image(const Ref<Image> &p_image, const Color &p_c
screenrect.position += ((Size2(window_w, window_h) - screenrect.size) / 2.0).floor();
}
RasterizerStorageGLES2::Texture *t = storage->texture_owner.get(texture);
RasterizerStorageGLES2::Texture *t = storage->texture_owner.getornull(texture);
glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 1);
glBindTexture(GL_TEXTURE_2D, t->tex_id);
canvas->draw_generic_textured_rect(screenrect, Rect2(0, 0, 1, 1));

View file

@ -370,7 +370,7 @@ bool RasterizerSceneGLES2::shadow_atlas_update_light(RID p_atlas, RID p_light_in
// it is take but invalid, so we can take it
shadow_atlas->shadow_owners.erase(sh->owner);
LightInstance *sli = light_instance_owner.get(sh->owner);
LightInstance *sli = light_instance_owner.getornull(sh->owner);
sli->shadow_atlases.erase(p_atlas);
}
@ -412,7 +412,7 @@ bool RasterizerSceneGLES2::shadow_atlas_update_light(RID p_atlas, RID p_light_in
// it is take but invalid, so we can take it
shadow_atlas->shadow_owners.erase(sh->owner);
LightInstance *sli = light_instance_owner.get(sh->owner);
LightInstance *sli = light_instance_owner.getornull(sh->owner);
sli->shadow_atlases.erase(p_atlas);
}
@ -976,7 +976,7 @@ void RasterizerSceneGLES2::_add_geometry(RasterizerStorageGLES2::Geometry *p_geo
}
if (!material) {
material = storage->material_owner.getptr(default_material);
material = storage->material_owner.getornull(default_material);
}
ERR_FAIL_COND(!material);
@ -1023,10 +1023,10 @@ void RasterizerSceneGLES2::_add_geometry_with_material(RasterizerStorageGLES2::G
if (!p_material->shader->spatial.uses_alpha_scissor && !p_material->shader->spatial.writes_modelview_or_projection && !p_material->shader->spatial.uses_vertex && !p_material->shader->spatial.uses_discard && p_material->shader->spatial.depth_draw_mode != RasterizerStorageGLES2::Shader::Spatial::DEPTH_DRAW_ALPHA_PREPASS) {
//shader does not use discard and does not write a vertex position, use generic material
if (p_instance->cast_shadows == VS::SHADOW_CASTING_SETTING_DOUBLE_SIDED) {
p_material = storage->material_owner.getptr(!p_shadow_pass && p_material->shader->spatial.uses_world_coordinates ? default_worldcoord_material_twosided : default_material_twosided);
p_material = storage->material_owner.getornull(!p_shadow_pass && p_material->shader->spatial.uses_world_coordinates ? default_worldcoord_material_twosided : default_material_twosided);
mirror = false;
} else {
p_material = storage->material_owner.getptr(!p_shadow_pass && p_material->shader->spatial.uses_world_coordinates ? default_worldcoord_material : default_material);
p_material = storage->material_owner.getornull(!p_shadow_pass && p_material->shader->spatial.uses_world_coordinates ? default_worldcoord_material : default_material);
}
}
@ -1242,13 +1242,13 @@ void RasterizerSceneGLES2::_fill_render_list(InstanceBase **p_cull_result, int p
} break;
case VS::INSTANCE_MULTIMESH: {
RasterizerStorageGLES2::MultiMesh *multi_mesh = storage->multimesh_owner.getptr(instance->base);
RasterizerStorageGLES2::MultiMesh *multi_mesh = storage->multimesh_owner.getornull(instance->base);
ERR_CONTINUE(!multi_mesh);
if (multi_mesh->size == 0 || multi_mesh->visible_instances == 0)
continue;
RasterizerStorageGLES2::Mesh *mesh = storage->mesh_owner.getptr(multi_mesh->mesh);
RasterizerStorageGLES2::Mesh *mesh = storage->mesh_owner.getornull(multi_mesh->mesh);
if (!mesh)
continue;
@ -1261,7 +1261,7 @@ void RasterizerSceneGLES2::_fill_render_list(InstanceBase **p_cull_result, int p
} break;
case VS::INSTANCE_IMMEDIATE: {
RasterizerStorageGLES2::Immediate *im = storage->immediate_owner.getptr(instance->base);
RasterizerStorageGLES2::Immediate *im = storage->immediate_owner.getornull(instance->base);
ERR_CONTINUE(!im);
_add_geometry(im, instance, NULL, -1, p_depth_pass, p_shadow_pass);
@ -1789,7 +1789,7 @@ void RasterizerSceneGLES2::_render_geometry(RenderList::Element *p_element) {
storage->info.render.vertices_count += vertices;
if (c.texture.is_valid() && storage->texture_owner.owns(c.texture)) {
RasterizerStorageGLES2::Texture *t = storage->texture_owner.get(c.texture);
RasterizerStorageGLES2::Texture *t = storage->texture_owner.getornull(c.texture);
if (t->redraw_if_visible) {
VisualServerRaster::redraw_request();
@ -3874,11 +3874,11 @@ bool RasterizerSceneGLES2::free(RID p_rid) {
if (light_instance_owner.owns(p_rid)) {
LightInstance *light_instance = light_instance_owner.getptr(p_rid);
LightInstance *light_instance = light_instance_owner.getornull(p_rid);
//remove from shadow atlases..
for (Set<RID>::Element *E = light_instance->shadow_atlases.front(); E; E = E->next()) {
ShadowAtlas *shadow_atlas = shadow_atlas_owner.get(E->get());
ShadowAtlas *shadow_atlas = shadow_atlas_owner.getornull(E->get());
ERR_CONTINUE(!shadow_atlas->shadow_owners.has(p_rid));
uint32_t key = shadow_atlas->shadow_owners[p_rid];
uint32_t q = (key >> ShadowAtlas::QUADRANT_SHIFT) & 0x3;
@ -3893,13 +3893,13 @@ bool RasterizerSceneGLES2::free(RID p_rid) {
} else if (shadow_atlas_owner.owns(p_rid)) {
ShadowAtlas *shadow_atlas = shadow_atlas_owner.get(p_rid);
ShadowAtlas *shadow_atlas = shadow_atlas_owner.getornull(p_rid);
shadow_atlas_set_size(p_rid, 0);
shadow_atlas_owner.free(p_rid);
memdelete(shadow_atlas);
} else if (reflection_probe_instance_owner.owns(p_rid)) {
ReflectionProbeInstance *reflection_instance = reflection_probe_instance_owner.get(p_rid);
ReflectionProbeInstance *reflection_instance = reflection_probe_instance_owner.getornull(p_rid);
for (int i = 0; i < 6; i++) {
glDeleteFramebuffers(1, &reflection_instance->fbo[i]);

View file

@ -225,7 +225,7 @@ public:
uint64_t shadow_atlas_realloc_tolerance_msec;
struct ShadowAtlas : public RID_Data {
struct ShadowAtlas {
enum {
QUADRANT_SHIFT = 27,
SHADOW_INDEX_MASK = (1 << QUADRANT_SHIFT) - 1,
@ -273,7 +273,7 @@ public:
Vector<ShadowCubeMap> shadow_cubemaps;
RID_Owner<ShadowAtlas> shadow_atlas_owner;
RID_PtrOwner<ShadowAtlas> shadow_atlas_owner;
RID shadow_atlas_create();
void shadow_atlas_set_size(RID p_atlas, int p_size);
@ -304,7 +304,7 @@ public:
/* REFLECTION PROBE INSTANCE */
struct ReflectionProbeInstance : public RID_Data {
struct ReflectionProbeInstance {
RasterizerStorageGLES2::ReflectionProbe *probe_ptr;
RID probe;
@ -330,7 +330,7 @@ public:
Transform transform;
};
mutable RID_Owner<ReflectionProbeInstance> reflection_probe_instance_owner;
mutable RID_PtrOwner<ReflectionProbeInstance> reflection_probe_instance_owner;
ReflectionProbeInstance **reflection_probe_instances;
int reflection_probe_count;
@ -345,7 +345,7 @@ public:
/* ENVIRONMENT API */
struct Environment : public RID_Data {
struct Environment {
VS::EnvironmentBG bg_mode;
RID sky;
@ -459,7 +459,7 @@ public:
}
};
mutable RID_Owner<Environment> environment_owner;
mutable RID_PtrOwner<Environment> environment_owner;
virtual RID environment_create();
@ -496,7 +496,7 @@ public:
/* LIGHT INSTANCE */
struct LightInstance : public RID_Data {
struct LightInstance {
struct ShadowTransform {
CameraMatrix camera;
@ -530,7 +530,7 @@ public:
Set<RID> shadow_atlases; // atlases where this light is registered
};
mutable RID_Owner<LightInstance> light_instance_owner;
mutable RID_PtrOwner<LightInstance> light_instance_owner;
virtual RID light_instance_create(RID p_light);
virtual void light_instance_set_transform(RID p_light_instance, const Transform &p_transform);

View file

@ -194,7 +194,7 @@ Ref<Image> RasterizerStorageGLES2::_get_gl_image_and_format(const Ref<Image> &p_
r_gl_type = GL_UNSIGNED_SHORT_4_4_4_4;
} break;
case Image::FORMAT_RGBA5551: {
case Image::FORMAT_RGB565: {
r_gl_internal_format = GL_RGB5_A1;
r_gl_format = GL_RGBA;
@ -1184,7 +1184,7 @@ void RasterizerStorageGLES2::texture_set_proxy(RID p_texture, RID p_proxy) {
}
if (p_proxy.is_valid()) {
Texture *proxy = texture_owner.get(p_proxy);
Texture *proxy = texture_owner.getornull(p_proxy);
ERR_FAIL_COND(!proxy);
ERR_FAIL_COND(proxy == texture);
proxy->proxy_owners.insert(texture);
@ -1201,7 +1201,7 @@ void RasterizerStorageGLES2::texture_set_force_redraw_if_visible(RID p_texture,
}
void RasterizerStorageGLES2::texture_set_detect_3d_callback(RID p_texture, VisualServer::TextureDetectCallback p_callback, void *p_userdata) {
Texture *texture = texture_owner.get(p_texture);
Texture *texture = texture_owner.getornull(p_texture);
ERR_FAIL_COND(!texture);
texture->detect_3d = p_callback;
@ -1209,7 +1209,7 @@ void RasterizerStorageGLES2::texture_set_detect_3d_callback(RID p_texture, Visua
}
void RasterizerStorageGLES2::texture_set_detect_srgb_callback(RID p_texture, VisualServer::TextureDetectCallback p_callback, void *p_userdata) {
Texture *texture = texture_owner.get(p_texture);
Texture *texture = texture_owner.getornull(p_texture);
ERR_FAIL_COND(!texture);
texture->detect_srgb = p_callback;
@ -1217,7 +1217,7 @@ void RasterizerStorageGLES2::texture_set_detect_srgb_callback(RID p_texture, Vis
}
void RasterizerStorageGLES2::texture_set_detect_normal_callback(RID p_texture, VisualServer::TextureDetectCallback p_callback, void *p_userdata) {
Texture *texture = texture_owner.get(p_texture);
Texture *texture = texture_owner.getornull(p_texture);
ERR_FAIL_COND(!texture);
texture->detect_normal = p_callback;
@ -1456,7 +1456,7 @@ void RasterizerStorageGLES2::shader_set_code(RID p_shader, const String &p_code)
String RasterizerStorageGLES2::shader_get_code(RID p_shader) const {
const Shader *shader = shader_owner.get(p_shader);
const Shader *shader = shader_owner.getornull(p_shader);
ERR_FAIL_COND_V(!shader, "");
return shader->code;
@ -1610,7 +1610,7 @@ void RasterizerStorageGLES2::update_dirty_shaders() {
void RasterizerStorageGLES2::shader_get_param_list(RID p_shader, List<PropertyInfo> *p_param_list) const {
Shader *shader = shader_owner.get(p_shader);
Shader *shader = shader_owner.getornull(p_shader);
ERR_FAIL_COND(!shader);
if (shader->dirty_list.in_list()) {
@ -1721,7 +1721,7 @@ void RasterizerStorageGLES2::shader_get_param_list(RID p_shader, List<PropertyIn
case ShaderLanguage::TYPE_USAMPLER2D: {
pi.type = Variant::OBJECT;
pi.hint = PROPERTY_HINT_RESOURCE_TYPE;
pi.hint_string = "Texture";
pi.hint_string = "Texture2D";
} break;
case ShaderLanguage::TYPE_SAMPLERCUBE: {
@ -1754,7 +1754,7 @@ void RasterizerStorageGLES2::shader_get_param_list(RID p_shader, List<PropertyIn
void RasterizerStorageGLES2::shader_set_default_texture_param(RID p_shader, const StringName &p_name, RID p_texture) {
Shader *shader = shader_owner.get(p_shader);
Shader *shader = shader_owner.getornull(p_shader);
ERR_FAIL_COND(!shader);
ERR_FAIL_COND(p_texture.is_valid() && !texture_owner.owns(p_texture));
@ -1769,7 +1769,7 @@ void RasterizerStorageGLES2::shader_set_default_texture_param(RID p_shader, cons
RID RasterizerStorageGLES2::shader_get_default_texture_param(RID p_shader, const StringName &p_name) const {
const Shader *shader = shader_owner.get(p_shader);
const Shader *shader = shader_owner.getornull(p_shader);
ERR_FAIL_COND_V(!shader, RID());
const Map<StringName, RID>::Element *E = shader->default_textures.find(p_name);
@ -1800,7 +1800,7 @@ RID RasterizerStorageGLES2::material_create() {
void RasterizerStorageGLES2::material_set_shader(RID p_material, RID p_shader) {
Material *material = material_owner.get(p_material);
Material *material = material_owner.getornull(p_material);
ERR_FAIL_COND(!material);
Shader *shader = shader_owner.getornull(p_shader);
@ -1821,7 +1821,7 @@ void RasterizerStorageGLES2::material_set_shader(RID p_material, RID p_shader) {
RID RasterizerStorageGLES2::material_get_shader(RID p_material) const {
const Material *material = material_owner.get(p_material);
const Material *material = material_owner.getornull(p_material);
ERR_FAIL_COND_V(!material, RID());
if (material->shader) {
@ -1833,7 +1833,7 @@ RID RasterizerStorageGLES2::material_get_shader(RID p_material) const {
void RasterizerStorageGLES2::material_set_param(RID p_material, const StringName &p_param, const Variant &p_value) {
Material *material = material_owner.get(p_material);
Material *material = material_owner.getornull(p_material);
ERR_FAIL_COND(!material);
if (p_value.get_type() == Variant::NIL) {
@ -1847,7 +1847,7 @@ void RasterizerStorageGLES2::material_set_param(RID p_material, const StringName
Variant RasterizerStorageGLES2::material_get_param(RID p_material, const StringName &p_param) const {
const Material *material = material_owner.get(p_material);
const Material *material = material_owner.getornull(p_material);
ERR_FAIL_COND_V(!material, RID());
if (material->params.has(p_param)) {
@ -1858,7 +1858,7 @@ Variant RasterizerStorageGLES2::material_get_param(RID p_material, const StringN
}
Variant RasterizerStorageGLES2::material_get_param_default(RID p_material, const StringName &p_param) const {
const Material *material = material_owner.get(p_material);
const Material *material = material_owner.getornull(p_material);
ERR_FAIL_COND_V(!material, Variant());
if (material->shader) {
@ -1879,14 +1879,14 @@ void RasterizerStorageGLES2::material_set_line_width(RID p_material, float p_wid
}
void RasterizerStorageGLES2::material_set_next_pass(RID p_material, RID p_next_material) {
Material *material = material_owner.get(p_material);
Material *material = material_owner.getornull(p_material);
ERR_FAIL_COND(!material);
material->next_pass = p_next_material;
}
bool RasterizerStorageGLES2::material_is_animated(RID p_material) {
Material *material = material_owner.get(p_material);
Material *material = material_owner.getornull(p_material);
ERR_FAIL_COND_V(!material, false);
if (material->dirty_list.in_list()) {
_update_material(material);
@ -1900,7 +1900,7 @@ bool RasterizerStorageGLES2::material_is_animated(RID p_material) {
}
bool RasterizerStorageGLES2::material_casts_shadows(RID p_material) {
Material *material = material_owner.get(p_material);
Material *material = material_owner.getornull(p_material);
ERR_FAIL_COND_V(!material, false);
if (material->dirty_list.in_list()) {
_update_material(material);
@ -1947,7 +1947,7 @@ void RasterizerStorageGLES2::material_set_render_priority(RID p_material, int pr
ERR_FAIL_COND(priority < VS::MATERIAL_RENDER_PRIORITY_MIN);
ERR_FAIL_COND(priority > VS::MATERIAL_RENDER_PRIORITY_MAX);
Material *material = material_owner.get(p_material);
Material *material = material_owner.getornull(p_material);
ERR_FAIL_COND(!material);
material->render_priority = priority;
@ -2804,7 +2804,7 @@ AABB RasterizerStorageGLES2::mesh_get_custom_aabb(RID p_mesh) const {
}
AABB RasterizerStorageGLES2::mesh_get_aabb(RID p_mesh, RID p_skeleton) const {
Mesh *mesh = mesh_owner.get(p_mesh);
Mesh *mesh = mesh_owner.getornull(p_mesh);
ERR_FAIL_COND_V(!mesh, AABB());
if (mesh->custom_aabb != AABB())
@ -2812,7 +2812,7 @@ AABB RasterizerStorageGLES2::mesh_get_aabb(RID p_mesh, RID p_skeleton) const {
Skeleton *sk = NULL;
if (p_skeleton.is_valid()) {
sk = skeleton_owner.get(p_skeleton);
sk = skeleton_owner.getornull(p_skeleton);
}
AABB aabb;
@ -3468,7 +3468,7 @@ RID RasterizerStorageGLES2::immediate_create() {
}
void RasterizerStorageGLES2::immediate_begin(RID p_immediate, VS::PrimitiveType p_primitive, RID p_texture) {
Immediate *im = immediate_owner.get(p_immediate);
Immediate *im = immediate_owner.getornull(p_immediate);
ERR_FAIL_COND(!im);
ERR_FAIL_COND(im->building);
@ -3481,7 +3481,7 @@ void RasterizerStorageGLES2::immediate_begin(RID p_immediate, VS::PrimitiveType
}
void RasterizerStorageGLES2::immediate_vertex(RID p_immediate, const Vector3 &p_vertex) {
Immediate *im = immediate_owner.get(p_immediate);
Immediate *im = immediate_owner.getornull(p_immediate);
ERR_FAIL_COND(!im);
ERR_FAIL_COND(!im->building);
@ -3509,7 +3509,7 @@ void RasterizerStorageGLES2::immediate_vertex(RID p_immediate, const Vector3 &p_
}
void RasterizerStorageGLES2::immediate_normal(RID p_immediate, const Vector3 &p_normal) {
Immediate *im = immediate_owner.get(p_immediate);
Immediate *im = immediate_owner.getornull(p_immediate);
ERR_FAIL_COND(!im);
ERR_FAIL_COND(!im->building);
@ -3518,7 +3518,7 @@ void RasterizerStorageGLES2::immediate_normal(RID p_immediate, const Vector3 &p_
}
void RasterizerStorageGLES2::immediate_tangent(RID p_immediate, const Plane &p_tangent) {
Immediate *im = immediate_owner.get(p_immediate);
Immediate *im = immediate_owner.getornull(p_immediate);
ERR_FAIL_COND(!im);
ERR_FAIL_COND(!im->building);
@ -3527,7 +3527,7 @@ void RasterizerStorageGLES2::immediate_tangent(RID p_immediate, const Plane &p_t
}
void RasterizerStorageGLES2::immediate_color(RID p_immediate, const Color &p_color) {
Immediate *im = immediate_owner.get(p_immediate);
Immediate *im = immediate_owner.getornull(p_immediate);
ERR_FAIL_COND(!im);
ERR_FAIL_COND(!im->building);
@ -3536,7 +3536,7 @@ void RasterizerStorageGLES2::immediate_color(RID p_immediate, const Color &p_col
}
void RasterizerStorageGLES2::immediate_uv(RID p_immediate, const Vector2 &tex_uv) {
Immediate *im = immediate_owner.get(p_immediate);
Immediate *im = immediate_owner.getornull(p_immediate);
ERR_FAIL_COND(!im);
ERR_FAIL_COND(!im->building);
@ -3545,7 +3545,7 @@ void RasterizerStorageGLES2::immediate_uv(RID p_immediate, const Vector2 &tex_uv
}
void RasterizerStorageGLES2::immediate_uv2(RID p_immediate, const Vector2 &tex_uv) {
Immediate *im = immediate_owner.get(p_immediate);
Immediate *im = immediate_owner.getornull(p_immediate);
ERR_FAIL_COND(!im);
ERR_FAIL_COND(!im->building);
@ -3554,7 +3554,7 @@ void RasterizerStorageGLES2::immediate_uv2(RID p_immediate, const Vector2 &tex_u
}
void RasterizerStorageGLES2::immediate_end(RID p_immediate) {
Immediate *im = immediate_owner.get(p_immediate);
Immediate *im = immediate_owner.getornull(p_immediate);
ERR_FAIL_COND(!im);
ERR_FAIL_COND(!im->building);
@ -3563,7 +3563,7 @@ void RasterizerStorageGLES2::immediate_end(RID p_immediate) {
}
void RasterizerStorageGLES2::immediate_clear(RID p_immediate) {
Immediate *im = immediate_owner.get(p_immediate);
Immediate *im = immediate_owner.getornull(p_immediate);
ERR_FAIL_COND(!im);
ERR_FAIL_COND(im->building);
@ -3572,13 +3572,13 @@ void RasterizerStorageGLES2::immediate_clear(RID p_immediate) {
}
AABB RasterizerStorageGLES2::immediate_get_aabb(RID p_immediate) const {
Immediate *im = immediate_owner.get(p_immediate);
Immediate *im = immediate_owner.getornull(p_immediate);
ERR_FAIL_COND_V(!im, AABB());
return im->aabb;
}
void RasterizerStorageGLES2::immediate_set_material(RID p_immediate, RID p_material) {
Immediate *im = immediate_owner.get(p_immediate);
Immediate *im = immediate_owner.getornull(p_immediate);
ERR_FAIL_COND(!im);
im->material = p_material;
@ -3586,7 +3586,7 @@ void RasterizerStorageGLES2::immediate_set_material(RID p_immediate, RID p_mater
}
RID RasterizerStorageGLES2::immediate_get_material(RID p_immediate) const {
const Immediate *im = immediate_owner.get(p_immediate);
const Immediate *im = immediate_owner.getornull(p_immediate);
ERR_FAIL_COND_V(!im, RID());
return im->material;
}
@ -5057,7 +5057,7 @@ void RasterizerStorageGLES2::_render_target_clear(RenderTarget *rt) {
glDeleteFramebuffers(1, &rt->external.fbo);
// clean up our texture
Texture *t = texture_owner.get(rt->external.texture);
Texture *t = texture_owner.getornull(rt->external.texture);
t->alloc_height = 0;
t->alloc_width = 0;
t->width = 0;
@ -5079,7 +5079,7 @@ void RasterizerStorageGLES2::_render_target_clear(RenderTarget *rt) {
rt->depth = 0;
}
Texture *tex = texture_owner.get(rt->texture);
Texture *tex = texture_owner.getornull(rt->texture);
tex->alloc_height = 0;
tex->alloc_width = 0;
tex->width = 0;
@ -5206,7 +5206,7 @@ void RasterizerStorageGLES2::render_target_set_external_texture(RID p_render_tar
}
// clean up our texture
Texture *t = texture_owner.get(rt->external.texture);
Texture *t = texture_owner.getornull(rt->external.texture);
t->alloc_height = 0;
t->alloc_width = 0;
t->width = 0;
@ -5258,7 +5258,7 @@ void RasterizerStorageGLES2::render_target_set_external_texture(RID p_render_tar
glBindFramebuffer(GL_FRAMEBUFFER, rt->external.fbo);
// find our texture
t = texture_owner.get(rt->external.texture);
t = texture_owner.getornull(rt->external.texture);
}
// set our texture
@ -5358,7 +5358,7 @@ bool RasterizerStorageGLES2::render_target_was_used(RID p_render_target) {
return rt->used_in_frame;
}
void RasterizerStorageGLES2::render_target_clear_used(RID p_render_target) {
void RasterizerStorageGLES2::render_target_set_as_unused(RID p_render_target) {
RenderTarget *rt = render_target_owner.getornull(p_render_target);
ERR_FAIL_COND(!rt);
@ -5448,7 +5448,7 @@ RID RasterizerStorageGLES2::canvas_light_occluder_create() {
void RasterizerStorageGLES2::canvas_light_occluder_set_polylines(RID p_occluder, const PoolVector<Vector2> &p_lines) {
CanvasOccluder *co = canvas_occluder_owner.get(p_occluder);
CanvasOccluder *co = canvas_occluder_owner.getornull(p_occluder);
ERR_FAIL_COND(!co);
co->lines = p_lines;
@ -5565,7 +5565,7 @@ bool RasterizerStorageGLES2::free(RID p_rid) {
RenderTarget *rt = render_target_owner.getornull(p_rid);
_render_target_clear(rt);
Texture *t = texture_owner.get(rt->texture);
Texture *t = texture_owner.getornull(rt->texture);
texture_owner.free(rt->texture);
memdelete(t);
render_target_owner.free(p_rid);
@ -5574,7 +5574,7 @@ bool RasterizerStorageGLES2::free(RID p_rid) {
return true;
} else if (texture_owner.owns(p_rid)) {
Texture *t = texture_owner.get(p_rid);
Texture *t = texture_owner.getornull(p_rid);
// can't free a render target texture
ERR_FAIL_COND_V(t->render_target, true);
@ -5585,7 +5585,7 @@ bool RasterizerStorageGLES2::free(RID p_rid) {
return true;
} else if (sky_owner.owns(p_rid)) {
Sky *sky = sky_owner.get(p_rid);
Sky *sky = sky_owner.getornull(p_rid);
sky_set_texture(p_rid, RID(), 256);
sky_owner.free(p_rid);
memdelete(sky);
@ -5593,7 +5593,7 @@ bool RasterizerStorageGLES2::free(RID p_rid) {
return true;
} else if (shader_owner.owns(p_rid)) {
Shader *shader = shader_owner.get(p_rid);
Shader *shader = shader_owner.getornull(p_rid);
if (shader->shader && shader->custom_code_id) {
shader->shader->free_custom_shader(shader->custom_code_id);
@ -5618,7 +5618,7 @@ bool RasterizerStorageGLES2::free(RID p_rid) {
return true;
} else if (material_owner.owns(p_rid)) {
Material *m = material_owner.get(p_rid);
Material *m = material_owner.getornull(p_rid);
if (m->shader) {
m->shader->materials.remove(&m->list);
@ -5650,7 +5650,7 @@ bool RasterizerStorageGLES2::free(RID p_rid) {
return true;
} else if (skeleton_owner.owns(p_rid)) {
Skeleton *s = skeleton_owner.get(p_rid);
Skeleton *s = skeleton_owner.getornull(p_rid);
if (s->update_list.in_list()) {
skeleton_update_list.remove(&s->update_list);
@ -5672,7 +5672,7 @@ bool RasterizerStorageGLES2::free(RID p_rid) {
return true;
} else if (mesh_owner.owns(p_rid)) {
Mesh *mesh = mesh_owner.get(p_rid);
Mesh *mesh = mesh_owner.getornull(p_rid);
mesh->instance_remove_deps();
mesh_clear(p_rid);
@ -5695,7 +5695,7 @@ bool RasterizerStorageGLES2::free(RID p_rid) {
return true;
} else if (multimesh_owner.owns(p_rid)) {
MultiMesh *multimesh = multimesh_owner.get(p_rid);
MultiMesh *multimesh = multimesh_owner.getornull(p_rid);
multimesh->instance_remove_deps();
if (multimesh->mesh.is_valid()) {
@ -5714,7 +5714,7 @@ bool RasterizerStorageGLES2::free(RID p_rid) {
return true;
} else if (immediate_owner.owns(p_rid)) {
Immediate *im = immediate_owner.get(p_rid);
Immediate *im = immediate_owner.getornull(p_rid);
im->instance_remove_deps();
immediate_owner.free(p_rid);
@ -5723,7 +5723,7 @@ bool RasterizerStorageGLES2::free(RID p_rid) {
return true;
} else if (light_owner.owns(p_rid)) {
Light *light = light_owner.get(p_rid);
Light *light = light_owner.getornull(p_rid);
light->instance_remove_deps();
light_owner.free(p_rid);
@ -5733,7 +5733,7 @@ bool RasterizerStorageGLES2::free(RID p_rid) {
} else if (reflection_probe_owner.owns(p_rid)) {
// delete the texture
ReflectionProbe *reflection_probe = reflection_probe_owner.get(p_rid);
ReflectionProbe *reflection_probe = reflection_probe_owner.getornull(p_rid);
reflection_probe->instance_remove_deps();
reflection_probe_owner.free(p_rid);
@ -5743,7 +5743,7 @@ bool RasterizerStorageGLES2::free(RID p_rid) {
} else if (lightmap_capture_data_owner.owns(p_rid)) {
// delete the texture
LightmapCapture *lightmap_capture = lightmap_capture_data_owner.get(p_rid);
LightmapCapture *lightmap_capture = lightmap_capture_data_owner.getornull(p_rid);
lightmap_capture->instance_remove_deps();
lightmap_capture_data_owner.free(p_rid);
@ -5752,7 +5752,7 @@ bool RasterizerStorageGLES2::free(RID p_rid) {
} else if (canvas_occluder_owner.owns(p_rid)) {
CanvasOccluder *co = canvas_occluder_owner.get(p_rid);
CanvasOccluder *co = canvas_occluder_owner.getornull(p_rid);
if (co->index_id)
glDeleteBuffers(1, &co->index_id);
if (co->vertex_id)
@ -5765,7 +5765,7 @@ bool RasterizerStorageGLES2::free(RID p_rid) {
} else if (canvas_light_shadow_owner.owns(p_rid)) {
CanvasLightShadow *cls = canvas_light_shadow_owner.get(p_rid);
CanvasLightShadow *cls = canvas_light_shadow_owner.getornull(p_rid);
glDeleteFramebuffers(1, &cls->fbo);
glDeleteRenderbuffers(1, &cls->depth);
glDeleteTextures(1, &cls->distance);

View file

@ -38,6 +38,7 @@
#include "shader_compiler_gles2.h"
#include "shader_gles2.h"
#include "core/rid_owner.h"
#include "shaders/copy.glsl.gen.h"
#include "shaders/cubemap_filter.glsl.gen.h"
/*
@ -179,7 +180,7 @@ public:
//////////////////////////////////DATA///////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
struct Instantiable : public RID_Data {
struct Instantiable {
SelfList<RasterizerScene::InstanceBase>::List instance_list;
_FORCE_INLINE_ void instance_change_notify(bool p_aabb, bool p_materials) {
@ -239,7 +240,7 @@ public:
struct RenderTarget;
struct Texture : RID_Data {
struct Texture {
Texture *proxy;
Set<Texture *> proxy_owners;
@ -340,7 +341,7 @@ public:
}
};
mutable RID_Owner<Texture> texture_owner;
mutable RID_PtrOwner<Texture2D> texture_owner;
Ref<Image> _get_gl_image_and_format(const Ref<Image> &p_image, Image::Format p_format, uint32_t p_flags, Image::Format &r_real_format, GLenum &r_gl_format, GLenum &r_gl_internal_format, GLenum &r_gl_type, bool &r_compressed, bool p_force_decompress) const;
@ -382,14 +383,14 @@ public:
/* SKY API */
struct Sky : public RID_Data {
struct Sky {
RID panorama;
GLuint radiance;
int radiance_size;
};
mutable RID_Owner<Sky> sky_owner;
mutable RID_PtrOwner<Sky> sky_owner;
virtual RID sky_create();
virtual void sky_set_texture(RID p_sky, RID p_panorama, int p_radiance_size);
@ -398,7 +399,7 @@ public:
struct Material;
struct Shader : public RID_Data {
struct Shader {
RID self;
@ -516,7 +517,7 @@ public:
}
};
mutable RID_Owner<Shader> shader_owner;
mutable RID_PtrOwner<Shader> shader_owner;
mutable SelfList<Shader>::List _shader_dirty_list;
void _shader_make_dirty(Shader *p_shader);
@ -535,7 +536,7 @@ public:
/* COMMON MATERIAL API */
struct Material : public RID_Data {
struct Material {
Shader *shader;
Map<StringName, Variant> params;
@ -576,7 +577,7 @@ public:
void _update_material(Material *p_material);
mutable RID_Owner<Material> material_owner;
mutable RID_PtrOwner<Material> material_owner;
virtual RID material_create();
@ -698,7 +699,7 @@ public:
}
};
mutable RID_Owner<Mesh> mesh_owner;
mutable RID_PtrOwner<Mesh> mesh_owner;
virtual RID mesh_create();
@ -780,7 +781,7 @@ public:
}
};
mutable RID_Owner<MultiMesh> multimesh_owner;
mutable RID_PtrOwner<MultiMesh> multimesh_owner;
SelfList<MultiMesh>::List multimesh_update_list;
@ -843,7 +844,7 @@ public:
Vector2 chunk_uv;
Vector2 chunk_uv2;
mutable RID_Owner<Immediate> immediate_owner;
mutable RID_PtrOwner<Immediate> immediate_owner;
virtual RID immediate_create();
virtual void immediate_begin(RID p_immediate, VS::PrimitiveType p_primitive, RID p_texture = RID());
@ -861,7 +862,7 @@ public:
/* SKELETON API */
struct Skeleton : RID_Data {
struct Skeleton {
bool use_2d;
@ -886,7 +887,7 @@ public:
}
};
mutable RID_Owner<Skeleton> skeleton_owner;
mutable RID_PtrOwner<Skeleton> skeleton_owner;
SelfList<Skeleton>::List skeleton_update_list;
@ -932,7 +933,7 @@ public:
uint64_t version;
};
mutable RID_Owner<Light> light_owner;
mutable RID_PtrOwner<Light> light_owner;
virtual RID light_create(VS::LightType p_type);
@ -988,7 +989,7 @@ public:
int resolution;
};
mutable RID_Owner<ReflectionProbe> reflection_probe_owner;
mutable RID_PtrOwner<ReflectionProbe> reflection_probe_owner;
virtual RID reflection_probe_create();
@ -1074,7 +1075,7 @@ public:
}
};
mutable RID_Owner<LightmapCapture> lightmap_capture_data_owner;
mutable RID_PtrOwner<LightmapCapture> lightmap_capture_data_owner;
virtual RID lightmap_capture_create();
virtual void lightmap_capture_set_bounds(RID p_capture, const AABB &p_bounds);
@ -1137,7 +1138,7 @@ public:
/* RENDER TARGET */
struct RenderTarget : public RID_Data {
struct RenderTarget {
GLuint fbo;
GLuint color;
GLuint depth;
@ -1233,7 +1234,7 @@ public:
}
};
mutable RID_Owner<RenderTarget> render_target_owner;
mutable RID_PtrOwner<RenderTarget> render_target_owner;
void _render_target_clear(RenderTarget *rt);
void _render_target_allocate(RenderTarget *rt);
@ -1246,12 +1247,12 @@ public:
virtual void render_target_set_flag(RID p_render_target, RenderTargetFlags p_flag, bool p_value);
virtual bool render_target_was_used(RID p_render_target);
virtual void render_target_clear_used(RID p_render_target);
virtual void render_target_set_as_unused(RID p_render_target);
virtual void render_target_set_msaa(RID p_render_target, VS::ViewportMSAA p_msaa);
/* CANVAS SHADOW */
struct CanvasLightShadow : public RID_Data {
struct CanvasLightShadow {
int size;
int height;
@ -1260,13 +1261,13 @@ public:
GLuint distance; //for older devices
};
RID_Owner<CanvasLightShadow> canvas_light_shadow_owner;
RID_PtrOwner<CanvasLightShadow> canvas_light_shadow_owner;
virtual RID canvas_light_shadow_buffer_create(int p_width);
/* LIGHT SHADOW MAPPING */
struct CanvasOccluder : public RID_Data {
struct CanvasOccluder {
GLuint vertex_id; // 0 means, unconfigured
GLuint index_id; // 0 means, unconfigured
@ -1274,7 +1275,7 @@ public:
int len;
};
RID_Owner<CanvasOccluder> canvas_occluder_owner;
RID_PtrOwner<CanvasOccluder> canvas_occluder_owner;
virtual RID canvas_light_occluder_create();
virtual void canvas_light_occluder_set_polylines(RID p_occluder, const PoolVector<Vector2> &p_lines);

View file

@ -901,11 +901,12 @@ void RasterizerCanvasGLES3::_canvas_item_render_commands(Item *p_item, Item *cur
#ifdef GLES_OVER_GL
if (polygon->antialiased) {
glEnable(GL_LINE_SMOOTH);
if (polygon->antialiasing_use_indices) {
_draw_generic_indices(GL_LINE_STRIP, polygon->indices.ptr(), polygon->count, polygon->points.size(), polygon->points.ptr(), polygon->uvs.ptr(), polygon->colors.ptr(), polygon->colors.size() == 1);
} else {
_draw_generic(GL_LINE_LOOP, polygon->points.size(), polygon->points.ptr(), polygon->uvs.ptr(), polygon->colors.ptr(), polygon->colors.size() == 1);
}
// FIXME: Removed during Vulkan rebase.
//if (polygon->antialiasing_use_indices) {
// _draw_generic_indices(GL_LINE_STRIP, polygon->indices.ptr(), polygon->count, polygon->points.size(), polygon->points.ptr(), polygon->uvs.ptr(), polygon->colors.ptr(), polygon->colors.size() == 1);
//} else
_draw_generic(GL_LINE_LOOP, polygon->points.size(), polygon->points.ptr(), polygon->uvs.ptr(), polygon->colors.ptr(), polygon->colors.size() == 1);
glDisable(GL_LINE_SMOOTH);
}
#endif
@ -1402,7 +1403,7 @@ void RasterizerCanvasGLES3::canvas_render_items(Item *p_item_list, int p_z, cons
{
//skeleton handling
if (ci->skeleton.is_valid() && storage->skeleton_owner.owns(ci->skeleton)) {
skeleton = storage->skeleton_owner.get(ci->skeleton);
skeleton = storage->skeleton_owner.getornull(ci->skeleton);
if (!skeleton->use_2d) {
skeleton = NULL;
} else {
@ -1697,11 +1698,13 @@ void RasterizerCanvasGLES3::canvas_render_items(Item *p_item_list, int p_z, cons
}
}
glBindBufferBase(GL_UNIFORM_BUFFER, 1, static_cast<LightInternal *>(light->light_internal.get_data())->ubo);
LightInternal *light_internal = light_internal_owner.getornull(light->light_internal);
glBindBufferBase(GL_UNIFORM_BUFFER, 1, light_internal->ubo);
if (has_shadow) {
RasterizerStorageGLES3::CanvasLightShadow *cls = storage->canvas_light_shadow_owner.get(light->shadow_buffer);
RasterizerStorageGLES3::CanvasLightShadow *cls = storage->canvas_light_shadow_owner.getornull(light->shadow_buffer);
glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 2);
glBindTexture(GL_TEXTURE_2D, cls->distance);
@ -1807,7 +1810,7 @@ void RasterizerCanvasGLES3::canvas_debug_viewport_shadows(Light *p_lights_with_s
while (light) {
if (light->shadow_buffer.is_valid()) {
RasterizerStorageGLES3::CanvasLightShadow *sb = storage->canvas_light_shadow_owner.get(light->shadow_buffer);
RasterizerStorageGLES3::CanvasLightShadow *sb = storage->canvas_light_shadow_owner.getornull(light->shadow_buffer);
if (sb) {
glBindTexture(GL_TEXTURE_2D, sb->distance);
draw_generic_textured_rect(Rect2(h, ofs, w - h * 2, h), Rect2(0, 0, 1, 1));
@ -1823,7 +1826,7 @@ void RasterizerCanvasGLES3::canvas_debug_viewport_shadows(Light *p_lights_with_s
void RasterizerCanvasGLES3::canvas_light_shadow_buffer_update(RID p_buffer, const Transform2D &p_light_xform, int p_light_mask, float p_near, float p_far, LightOccluderInstance *p_occluders, CameraMatrix *p_xform_cache) {
RasterizerStorageGLES3::CanvasLightShadow *cls = storage->canvas_light_shadow_owner.get(p_buffer);
RasterizerStorageGLES3::CanvasLightShadow *cls = storage->canvas_light_shadow_owner.getornull(p_buffer);
ERR_FAIL_COND(!cls);
glDisable(GL_BLEND);

View file

@ -96,7 +96,7 @@ public:
RasterizerStorageGLES3 *storage;
struct LightInternal : public RID_Data {
struct LightInternal {
struct UBOData {
@ -117,7 +117,7 @@ public:
GLuint ubo;
};
RID_Owner<LightInternal> light_internal_owner;
RID_PtrOwner<LightInternal> light_internal_owner;
virtual RID light_internal_create();
virtual void light_internal_update(RID p_rid, Light *p_light);

View file

@ -320,7 +320,7 @@ void RasterizerGLES3::set_boot_image(const Ref<Image> &p_image, const Color &p_c
screenrect.position += ((Size2(window_w, window_h) - screenrect.size) / 2.0).floor();
}
RasterizerStorageGLES3::Texture *t = storage->texture_owner.get(texture);
RasterizerStorageGLES3::Texture *t = storage->texture_owner.getornull(texture);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, t->tex_id);
canvas->draw_generic_textured_rect(screenrect, Rect2(0, 0, 1, 1));

View file

@ -351,7 +351,7 @@ bool RasterizerSceneGLES3::shadow_atlas_update_light(RID p_atlas, RID p_light_in
if (sh->owner.is_valid()) {
//is taken, but is invalid, erasing it
shadow_atlas->shadow_owners.erase(sh->owner);
LightInstance *sli = light_instance_owner.get(sh->owner);
LightInstance *sli = light_instance_owner.getornull(sh->owner);
sli->shadow_atlases.erase(p_atlas);
}
@ -391,7 +391,7 @@ bool RasterizerSceneGLES3::shadow_atlas_update_light(RID p_atlas, RID p_light_in
if (sh->owner.is_valid()) {
//is taken, but is invalid, erasing it
shadow_atlas->shadow_owners.erase(sh->owner);
LightInstance *sli = light_instance_owner.get(sh->owner);
LightInstance *sli = light_instance_owner.getornull(sh->owner);
sli->shadow_atlases.erase(p_atlas);
}
@ -1170,7 +1170,7 @@ bool RasterizerSceneGLES3::_setup_material(RasterizerStorageGLES3::Material *p_m
GLenum target = GL_TEXTURE_2D;
GLuint tex = 0;
RasterizerStorageGLES3::Texture *t = storage->texture_owner.getptr(textures[i]);
RasterizerStorageGLES3::Texture *t = storage->texture_owner.getornull(textures[i]);
if (t) {
@ -1606,7 +1606,7 @@ void RasterizerSceneGLES3::_render_geometry(RenderList::Element *e) {
if (c.texture.is_valid() && storage->texture_owner.owns(c.texture)) {
RasterizerStorageGLES3::Texture *t = storage->texture_owner.get(c.texture);
RasterizerStorageGLES3::Texture *t = storage->texture_owner.getornull(c.texture);
if (t->redraw_if_visible) {
VisualServerRaster::redraw_request();
@ -1884,7 +1884,7 @@ void RasterizerSceneGLES3::_setup_light(RenderList::Element *e, const Transform
const RID *reflections = e->instance->reflection_probe_instances.ptr();
for (int i = 0; i < rc; i++) {
ReflectionProbeInstance *rpi = reflection_probe_instance_owner.getptr(reflections[i]);
ReflectionProbeInstance *rpi = reflection_probe_instance_owner.getornull(reflections[i]);
if (rpi->last_pass != render_pass) //not visible
continue;
@ -1903,7 +1903,7 @@ void RasterizerSceneGLES3::_setup_light(RenderList::Element *e, const Transform
if (gi_probe_count) {
const RID *ridp = e->instance->gi_probe_instances.ptr();
GIProbeInstance *gipi = gi_probe_instance_owner.getptr(ridp[0]);
GIProbeInstance *gipi = gi_probe_instance_owner.getornull(ridp[0]);
float bias_scale = e->instance->baked_light ? 1 : 0;
glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 9);
@ -1917,7 +1917,7 @@ void RasterizerSceneGLES3::_setup_light(RenderList::Element *e, const Transform
state.scene_shader.set_uniform(SceneShaderGLES3::GI_PROBE_CELL_SIZE1, gipi->cell_size_cache);
if (gi_probe_count > 1) {
GIProbeInstance *gipi2 = gi_probe_instance_owner.getptr(ridp[1]);
GIProbeInstance *gipi2 = gi_probe_instance_owner.getornull(ridp[1]);
glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 10);
glBindTexture(GL_TEXTURE_3D, gipi2->tex_cache);
@ -2286,7 +2286,7 @@ void RasterizerSceneGLES3::_add_geometry(RasterizerStorageGLES3::Geometry *p_geo
}
if (!m) {
m = storage->material_owner.getptr(default_material);
m = storage->material_owner.getornull(default_material);
}
ERR_FAIL_COND(!m);
@ -2337,11 +2337,11 @@ void RasterizerSceneGLES3::_add_geometry_with_material(RasterizerStorageGLES3::G
if (!p_material->shader->spatial.uses_alpha_scissor && !p_material->shader->spatial.writes_modelview_or_projection && !p_material->shader->spatial.uses_vertex && !p_material->shader->spatial.uses_discard && p_material->shader->spatial.depth_draw_mode != RasterizerStorageGLES3::Shader::Spatial::DEPTH_DRAW_ALPHA_PREPASS) {
//shader does not use discard and does not write a vertex position, use generic material
if (p_instance->cast_shadows == VS::SHADOW_CASTING_SETTING_DOUBLE_SIDED) {
p_material = storage->material_owner.getptr(!p_shadow_pass && p_material->shader->spatial.uses_world_coordinates ? default_worldcoord_material_twosided : default_material_twosided);
p_material = storage->material_owner.getornull(!p_shadow_pass && p_material->shader->spatial.uses_world_coordinates ? default_worldcoord_material_twosided : default_material_twosided);
no_cull = true;
mirror = false;
} else {
p_material = storage->material_owner.getptr(!p_shadow_pass && p_material->shader->spatial.uses_world_coordinates ? default_worldcoord_material : default_material);
p_material = storage->material_owner.getornull(!p_shadow_pass && p_material->shader->spatial.uses_world_coordinates ? default_worldcoord_material : default_material);
}
}
@ -2792,7 +2792,7 @@ void RasterizerSceneGLES3::_setup_lights(RID *p_light_cull_result, int p_light_c
ERR_BREAK(i >= render_list.max_lights);
LightInstance *li = light_instance_owner.getptr(p_light_cull_result[i]);
LightInstance *li = light_instance_owner.getornull(p_light_cull_result[i]);
LightDataUBO ubo_data; //used for filling
@ -3142,7 +3142,7 @@ void RasterizerSceneGLES3::_fill_render_list(InstanceBase **p_cull_result, int p
case VS::INSTANCE_MESH: {
RasterizerStorageGLES3::Mesh *mesh = storage->mesh_owner.getptr(inst->base);
RasterizerStorageGLES3::Mesh *mesh = storage->mesh_owner.getornull(inst->base);
ERR_CONTINUE(!mesh);
int ssize = mesh->surfaces.size();
@ -3159,13 +3159,13 @@ void RasterizerSceneGLES3::_fill_render_list(InstanceBase **p_cull_result, int p
} break;
case VS::INSTANCE_MULTIMESH: {
RasterizerStorageGLES3::MultiMesh *multi_mesh = storage->multimesh_owner.getptr(inst->base);
RasterizerStorageGLES3::MultiMesh *multi_mesh = storage->multimesh_owner.getornull(inst->base);
ERR_CONTINUE(!multi_mesh);
if (multi_mesh->size == 0 || multi_mesh->visible_instances == 0)
continue;
RasterizerStorageGLES3::Mesh *mesh = storage->mesh_owner.getptr(multi_mesh->mesh);
RasterizerStorageGLES3::Mesh *mesh = storage->mesh_owner.getornull(multi_mesh->mesh);
if (!mesh)
continue; //mesh not assigned
@ -3180,7 +3180,7 @@ void RasterizerSceneGLES3::_fill_render_list(InstanceBase **p_cull_result, int p
} break;
case VS::INSTANCE_IMMEDIATE: {
RasterizerStorageGLES3::Immediate *immediate = storage->immediate_owner.getptr(inst->base);
RasterizerStorageGLES3::Immediate *immediate = storage->immediate_owner.getornull(inst->base);
ERR_CONTINUE(!immediate);
_add_geometry(immediate, inst, NULL, -1, p_depth_pass, p_shadow_pass);
@ -3188,7 +3188,7 @@ void RasterizerSceneGLES3::_fill_render_list(InstanceBase **p_cull_result, int p
} break;
case VS::INSTANCE_PARTICLES: {
RasterizerStorageGLES3::Particles *particles = storage->particles_owner.getptr(inst->base);
RasterizerStorageGLES3::Particles *particles = storage->particles_owner.getornull(inst->base);
ERR_CONTINUE(!particles);
for (int j = 0; j < particles->draw_passes.size(); j++) {
@ -3196,7 +3196,7 @@ void RasterizerSceneGLES3::_fill_render_list(InstanceBase **p_cull_result, int p
RID pmesh = particles->draw_passes[j];
if (!pmesh.is_valid())
continue;
RasterizerStorageGLES3::Mesh *mesh = storage->mesh_owner.get(pmesh);
RasterizerStorageGLES3::Mesh *mesh = storage->mesh_owner.getornull(pmesh);
if (!mesh)
continue; //mesh not assigned
@ -4155,7 +4155,7 @@ void RasterizerSceneGLES3::render_scene(const Transform &p_cam_transform, const
ERR_BREAK(i >= render_list.max_lights);
LightInstance *li = light_instance_owner.getptr(p_light_cull_result[i]);
LightInstance *li = light_instance_owner.getornull(p_light_cull_result[i]);
if (li->light_ptr->param[VS::LIGHT_PARAM_CONTACT_SHADOW_SIZE] > CMP_EPSILON) {
state.used_contact_shadows = true;
}
@ -4229,7 +4229,7 @@ void RasterizerSceneGLES3::render_scene(const Transform &p_cam_transform, const
if (probe) {
ReflectionAtlas *ref_atlas = reflection_atlas_owner.getptr(probe->atlas);
ReflectionAtlas *ref_atlas = reflection_atlas_owner.getornull(probe->atlas);
ERR_FAIL_COND(!ref_atlas);
int target_size = ref_atlas->size / ref_atlas->subdiv;
@ -4914,11 +4914,11 @@ bool RasterizerSceneGLES3::free(RID p_rid) {
if (light_instance_owner.owns(p_rid)) {
LightInstance *light_instance = light_instance_owner.getptr(p_rid);
LightInstance *light_instance = light_instance_owner.getornull(p_rid);
//remove from shadow atlases..
for (Set<RID>::Element *E = light_instance->shadow_atlases.front(); E; E = E->next()) {
ShadowAtlas *shadow_atlas = shadow_atlas_owner.get(E->get());
ShadowAtlas *shadow_atlas = shadow_atlas_owner.getornull(E->get());
ERR_CONTINUE(!shadow_atlas->shadow_owners.has(p_rid));
uint32_t key = shadow_atlas->shadow_owners[p_rid];
uint32_t q = (key >> ShadowAtlas::QUADRANT_SHIFT) & 0x3;
@ -4933,19 +4933,19 @@ bool RasterizerSceneGLES3::free(RID p_rid) {
} else if (shadow_atlas_owner.owns(p_rid)) {
ShadowAtlas *shadow_atlas = shadow_atlas_owner.get(p_rid);
ShadowAtlas *shadow_atlas = shadow_atlas_owner.getornull(p_rid);
shadow_atlas_set_size(p_rid, 0);
shadow_atlas_owner.free(p_rid);
memdelete(shadow_atlas);
} else if (reflection_atlas_owner.owns(p_rid)) {
ReflectionAtlas *reflection_atlas = reflection_atlas_owner.get(p_rid);
ReflectionAtlas *reflection_atlas = reflection_atlas_owner.getornull(p_rid);
reflection_atlas_set_size(p_rid, 0);
reflection_atlas_owner.free(p_rid);
memdelete(reflection_atlas);
} else if (reflection_probe_instance_owner.owns(p_rid)) {
ReflectionProbeInstance *reflection_instance = reflection_probe_instance_owner.get(p_rid);
ReflectionProbeInstance *reflection_instance = reflection_probe_instance_owner.getornull(p_rid);
reflection_probe_release_atlas_index(p_rid);
reflection_probe_instance_owner.free(p_rid);
@ -4953,14 +4953,14 @@ bool RasterizerSceneGLES3::free(RID p_rid) {
} else if (environment_owner.owns(p_rid)) {
Environment *environment = environment_owner.get(p_rid);
Environment *environment = environment_owner.getornull(p_rid);
environment_owner.free(p_rid);
memdelete(environment);
} else if (gi_probe_instance_owner.owns(p_rid)) {
GIProbeInstance *gi_probe_instance = gi_probe_instance_owner.get(p_rid);
GIProbeInstance *gi_probe_instance = gi_probe_instance_owner.getornull(p_rid);
gi_probe_instance_owner.free(p_rid);
memdelete(gi_probe_instance);
@ -5320,6 +5320,19 @@ void RasterizerSceneGLES3::iteration() {
}
void RasterizerSceneGLES3::finalize() {
storage->free(default_material);
storage->free(default_material_twosided);
storage->free(default_shader);
storage->free(default_shader_twosided);
storage->free(default_worldcoord_material);
storage->free(default_worldcoord_material_twosided);
storage->free(default_worldcoord_shader);
storage->free(default_worldcoord_shader_twosided);
storage->free(default_overdraw_material);
storage->free(default_overdraw_shader);
}
RasterizerSceneGLES3::RasterizerSceneGLES3() {
@ -5327,19 +5340,6 @@ RasterizerSceneGLES3::RasterizerSceneGLES3() {
RasterizerSceneGLES3::~RasterizerSceneGLES3() {
memdelete(default_material.get_data());
memdelete(default_material_twosided.get_data());
memdelete(default_shader.get_data());
memdelete(default_shader_twosided.get_data());
memdelete(default_worldcoord_material.get_data());
memdelete(default_worldcoord_material_twosided.get_data());
memdelete(default_worldcoord_shader.get_data());
memdelete(default_worldcoord_shader_twosided.get_data());
memdelete(default_overdraw_material.get_data());
memdelete(default_overdraw_shader.get_data());
memfree(state.spot_array_tmp);
memfree(state.omni_array_tmp);
memfree(state.reflection_array_tmp);

View file

@ -216,7 +216,7 @@ public:
/* SHADOW ATLAS API */
struct ShadowAtlas : public RID_Data {
struct ShadowAtlas {
enum {
QUADRANT_SHIFT = 27,
@ -267,7 +267,7 @@ public:
Vector<ShadowCubeMap> shadow_cubemaps;
RID_Owner<ShadowAtlas> shadow_atlas_owner;
RID_PtrOwner<ShadowAtlas> shadow_atlas_owner;
RID shadow_atlas_create();
void shadow_atlas_set_size(RID p_atlas, int p_size);
@ -288,7 +288,7 @@ public:
/* REFLECTION PROBE ATLAS API */
struct ReflectionAtlas : public RID_Data {
struct ReflectionAtlas {
int subdiv;
int size;
@ -304,11 +304,10 @@ public:
Vector<Reflection> reflections;
};
mutable RID_Owner<ReflectionAtlas> reflection_atlas_owner;
mutable RID_PtrOwner<ReflectionAtlas> reflection_atlas_owner;
virtual RID reflection_atlas_create();
virtual void reflection_atlas_set_size(RID p_ref_atlas, int p_size);
virtual void reflection_atlas_set_subdivision(RID p_ref_atlas, int p_subdiv);
virtual void reflection_atlas_configure(RID p_ref_atlas, int p_size, int p_count);
/* REFLECTION CUBEMAPS */
@ -324,7 +323,7 @@ public:
/* REFLECTION PROBE INSTANCE */
struct ReflectionProbeInstance : public RID_Data {
struct ReflectionProbeInstance {
RasterizerStorageGLES3::ReflectionProbe *probe_ptr;
RID probe;
@ -352,7 +351,7 @@ public:
//notes: for ambientblend, use distance to edge to blend between already existing global environment
};
mutable RID_Owner<ReflectionProbeInstance> reflection_probe_instance_owner;
mutable RID_PtrOwner<ReflectionProbeInstance> reflection_probe_instance_owner;
virtual RID reflection_probe_instance_create(RID p_probe);
virtual void reflection_probe_instance_set_transform(RID p_instance, const Transform &p_transform);
@ -364,7 +363,7 @@ public:
/* ENVIRONMENT API */
struct Environment : public RID_Data {
struct Environment {
VS::EnvironmentBG bg_mode;
@ -533,7 +532,7 @@ public:
}
};
RID_Owner<Environment> environment_owner;
RID_PtrOwner<Environment> environment_owner;
virtual RID environment_create();
@ -590,7 +589,7 @@ public:
float shadow_split_offsets[4];
};
struct LightInstance : public RID_Data {
struct LightInstance {
struct ShadowTransform {
@ -630,7 +629,7 @@ public:
LightInstance() {}
};
mutable RID_Owner<LightInstance> light_instance_owner;
mutable RID_PtrOwner<LightInstance> light_instance_owner;
virtual RID light_instance_create(RID p_light);
virtual void light_instance_set_transform(RID p_light_instance, const Transform &p_transform);
@ -639,7 +638,7 @@ public:
/* REFLECTION INSTANCE */
struct GIProbeInstance : public RID_Data {
struct GIProbeInstance {
RID data;
RasterizerStorageGLES3::GIProbe *probe;
GLuint tex_cache;
@ -653,7 +652,7 @@ public:
}
};
mutable RID_Owner<GIProbeInstance> gi_probe_instance_owner;
mutable RID_PtrOwner<GIProbeInstance> gi_probe_instance_owner;
virtual RID gi_probe_instance_create();
virtual void gi_probe_instance_set_light_data(RID p_probe, RID p_base, RID p_data);

View file

@ -206,7 +206,7 @@ Ref<Image> RasterizerStorageGLES3::_get_gl_image_and_format(const Ref<Image> &p_
r_gl_type = GL_UNSIGNED_SHORT_4_4_4_4;
} break;
case Image::FORMAT_RGBA5551: {
case Image::FORMAT_RGB565: {
r_gl_internal_format = GL_RGB5_A1;
r_gl_format = GL_RGBA;
@ -647,7 +647,7 @@ void RasterizerStorageGLES3::texture_allocate(RID p_texture, int p_width, int p_
}
#endif
Texture *texture = texture_owner.get(p_texture);
Texture *texture = texture_owner.getornull(p_texture);
ERR_FAIL_COND(!texture);
texture->width = p_width;
texture->height = p_height;
@ -750,7 +750,7 @@ void RasterizerStorageGLES3::texture_allocate(RID p_texture, int p_width, int p_
void RasterizerStorageGLES3::texture_set_data(RID p_texture, const Ref<Image> &p_image, int p_layer) {
Texture *texture = texture_owner.get(p_texture);
Texture *texture = texture_owner.getornull(p_texture);
ERR_FAIL_COND(!texture);
ERR_FAIL_COND(!texture->active);
@ -978,7 +978,7 @@ void RasterizerStorageGLES3::texture_set_data(RID p_texture, const Ref<Image> &p
// TODO If we want this to be usable without pre-filling pixels with a full image, we have to call glTexImage2D() with null data.
void RasterizerStorageGLES3::texture_set_data_partial(RID p_texture, const Ref<Image> &p_image, int src_x, int src_y, int src_w, int src_h, int dst_x, int dst_y, int p_dst_mip, int p_layer) {
Texture *texture = texture_owner.get(p_texture);
Texture *texture = texture_owner.getornull(p_texture);
ERR_FAIL_COND(!texture);
ERR_FAIL_COND(!texture->active);
@ -1064,7 +1064,7 @@ void RasterizerStorageGLES3::texture_set_data_partial(RID p_texture, const Ref<I
Ref<Image> RasterizerStorageGLES3::texture_get_data(RID p_texture, int p_layer) const {
Texture *texture = texture_owner.get(p_texture);
Texture *texture = texture_owner.getornull(p_texture);
ERR_FAIL_COND_V(!texture, Ref<Image>());
ERR_FAIL_COND_V(!texture->active, Ref<Image>());
@ -1347,7 +1347,7 @@ Ref<Image> RasterizerStorageGLES3::texture_get_data(RID p_texture, int p_layer)
void RasterizerStorageGLES3::texture_set_flags(RID p_texture, uint32_t p_flags) {
Texture *texture = texture_owner.get(p_texture);
Texture *texture = texture_owner.getornull(p_texture);
ERR_FAIL_COND(!texture);
if (texture->render_target) {
@ -1423,7 +1423,7 @@ void RasterizerStorageGLES3::texture_set_flags(RID p_texture, uint32_t p_flags)
}
uint32_t RasterizerStorageGLES3::texture_get_flags(RID p_texture) const {
Texture *texture = texture_owner.get(p_texture);
Texture *texture = texture_owner.getornull(p_texture);
ERR_FAIL_COND_V(!texture, 0);
@ -1431,7 +1431,7 @@ uint32_t RasterizerStorageGLES3::texture_get_flags(RID p_texture) const {
}
Image::Format RasterizerStorageGLES3::texture_get_format(RID p_texture) const {
Texture *texture = texture_owner.get(p_texture);
Texture *texture = texture_owner.getornull(p_texture);
ERR_FAIL_COND_V(!texture, Image::FORMAT_L8);
@ -1439,7 +1439,7 @@ Image::Format RasterizerStorageGLES3::texture_get_format(RID p_texture) const {
}
VisualServer::TextureType RasterizerStorageGLES3::texture_get_type(RID p_texture) const {
Texture *texture = texture_owner.get(p_texture);
Texture *texture = texture_owner.getornull(p_texture);
ERR_FAIL_COND_V(!texture, VS::TEXTURE_TYPE_2D);
@ -1447,7 +1447,7 @@ VisualServer::TextureType RasterizerStorageGLES3::texture_get_type(RID p_texture
}
uint32_t RasterizerStorageGLES3::texture_get_texid(RID p_texture) const {
Texture *texture = texture_owner.get(p_texture);
Texture *texture = texture_owner.getornull(p_texture);
ERR_FAIL_COND_V(!texture, 0);
@ -1464,7 +1464,7 @@ void RasterizerStorageGLES3::texture_bind(RID p_texture, uint32_t p_texture_no)
}
uint32_t RasterizerStorageGLES3::texture_get_width(RID p_texture) const {
Texture *texture = texture_owner.get(p_texture);
Texture *texture = texture_owner.getornull(p_texture);
ERR_FAIL_COND_V(!texture, 0);
@ -1472,7 +1472,7 @@ uint32_t RasterizerStorageGLES3::texture_get_width(RID p_texture) const {
}
uint32_t RasterizerStorageGLES3::texture_get_height(RID p_texture) const {
Texture *texture = texture_owner.get(p_texture);
Texture *texture = texture_owner.getornull(p_texture);
ERR_FAIL_COND_V(!texture, 0);
@ -1481,7 +1481,7 @@ uint32_t RasterizerStorageGLES3::texture_get_height(RID p_texture) const {
uint32_t RasterizerStorageGLES3::texture_get_depth(RID p_texture) const {
Texture *texture = texture_owner.get(p_texture);
Texture *texture = texture_owner.getornull(p_texture);
ERR_FAIL_COND_V(!texture, 0);
@ -1490,7 +1490,7 @@ uint32_t RasterizerStorageGLES3::texture_get_depth(RID p_texture) const {
void RasterizerStorageGLES3::texture_set_size_override(RID p_texture, int p_width, int p_height, int p_depth) {
Texture *texture = texture_owner.get(p_texture);
Texture *texture = texture_owner.getornull(p_texture);
ERR_FAIL_COND(!texture);
ERR_FAIL_COND(texture->render_target);
@ -1503,7 +1503,7 @@ void RasterizerStorageGLES3::texture_set_size_override(RID p_texture, int p_widt
}
void RasterizerStorageGLES3::texture_set_path(RID p_texture, const String &p_path) {
Texture *texture = texture_owner.get(p_texture);
Texture *texture = texture_owner.getornull(p_texture);
ERR_FAIL_COND(!texture);
texture->path = p_path;
@ -1511,7 +1511,7 @@ void RasterizerStorageGLES3::texture_set_path(RID p_texture, const String &p_pat
String RasterizerStorageGLES3::texture_get_path(RID p_texture) const {
Texture *texture = texture_owner.get(p_texture);
Texture *texture = texture_owner.getornull(p_texture);
ERR_FAIL_COND_V(!texture, String());
return texture->path;
}
@ -1522,7 +1522,7 @@ void RasterizerStorageGLES3::texture_debug_usage(List<VS::TextureInfo> *r_info)
for (List<RID>::Element *E = textures.front(); E; E = E->next()) {
Texture *t = texture_owner.get(E->get());
Texture *t = texture_owner.getornull(E->get());
if (!t)
continue;
VS::TextureInfo tinfo;
@ -1548,7 +1548,7 @@ void RasterizerStorageGLES3::textures_keep_original(bool p_enable) {
void RasterizerStorageGLES3::texture_set_detect_3d_callback(RID p_texture, VisualServer::TextureDetectCallback p_callback, void *p_userdata) {
Texture *texture = texture_owner.get(p_texture);
Texture *texture = texture_owner.getornull(p_texture);
ERR_FAIL_COND(!texture);
texture->detect_3d = p_callback;
@ -1556,7 +1556,7 @@ void RasterizerStorageGLES3::texture_set_detect_3d_callback(RID p_texture, Visua
}
void RasterizerStorageGLES3::texture_set_detect_srgb_callback(RID p_texture, VisualServer::TextureDetectCallback p_callback, void *p_userdata) {
Texture *texture = texture_owner.get(p_texture);
Texture *texture = texture_owner.getornull(p_texture);
ERR_FAIL_COND(!texture);
texture->detect_srgb = p_callback;
@ -1564,7 +1564,7 @@ void RasterizerStorageGLES3::texture_set_detect_srgb_callback(RID p_texture, Vis
}
void RasterizerStorageGLES3::texture_set_detect_normal_callback(RID p_texture, VisualServer::TextureDetectCallback p_callback, void *p_userdata) {
Texture *texture = texture_owner.get(p_texture);
Texture *texture = texture_owner.getornull(p_texture);
ERR_FAIL_COND(!texture);
texture->detect_normal = p_callback;
@ -1573,7 +1573,7 @@ void RasterizerStorageGLES3::texture_set_detect_normal_callback(RID p_texture, V
RID RasterizerStorageGLES3::texture_create_radiance_cubemap(RID p_source, int p_resolution) const {
Texture *texture = texture_owner.get(p_source);
Texture *texture = texture_owner.getornull(p_source);
ERR_FAIL_COND_V(!texture, RID());
ERR_FAIL_COND_V(texture->type != VS::TEXTURE_TYPE_CUBEMAP, RID());
@ -1729,7 +1729,7 @@ Size2 RasterizerStorageGLES3::texture_size_with_proxy(RID p_texture) const {
void RasterizerStorageGLES3::texture_set_proxy(RID p_texture, RID p_proxy) {
Texture *texture = texture_owner.get(p_texture);
Texture *texture = texture_owner.getornull(p_texture);
ERR_FAIL_COND(!texture);
if (texture->proxy) {
@ -1738,7 +1738,7 @@ void RasterizerStorageGLES3::texture_set_proxy(RID p_texture, RID p_proxy) {
}
if (p_proxy.is_valid()) {
Texture *proxy = texture_owner.get(p_proxy);
Texture *proxy = texture_owner.getornull(p_proxy);
ERR_FAIL_COND(!proxy);
ERR_FAIL_COND(proxy == texture);
proxy->proxy_owners.insert(texture);
@ -1748,7 +1748,7 @@ void RasterizerStorageGLES3::texture_set_proxy(RID p_texture, RID p_proxy) {
void RasterizerStorageGLES3::texture_set_force_redraw_if_visible(RID p_texture, bool p_enable) {
Texture *texture = texture_owner.get(p_texture);
Texture *texture = texture_owner.getornull(p_texture);
ERR_FAIL_COND(!texture);
texture->redraw_if_visible = p_enable;
}
@ -1775,8 +1775,9 @@ void RasterizerStorageGLES3::sky_set_texture(RID p_sky, RID p_panorama, int p_ra
}
sky->panorama = p_panorama;
if (!sky->panorama.is_valid())
if (!sky->panorama.is_valid()) {
return; //cleared
}
Texture *texture = texture_owner.getornull(sky->panorama);
if (!texture) {
@ -2194,7 +2195,7 @@ void RasterizerStorageGLES3::_shader_make_dirty(Shader *p_shader) {
void RasterizerStorageGLES3::shader_set_code(RID p_shader, const String &p_code) {
Shader *shader = shader_owner.get(p_shader);
Shader *shader = shader_owner.getornull(p_shader);
ERR_FAIL_COND(!shader);
shader->code = p_code;
@ -2234,7 +2235,7 @@ void RasterizerStorageGLES3::shader_set_code(RID p_shader, const String &p_code)
}
String RasterizerStorageGLES3::shader_get_code(RID p_shader) const {
const Shader *shader = shader_owner.get(p_shader);
const Shader *shader = shader_owner.getornull(p_shader);
ERR_FAIL_COND_V(!shader, String());
return shader->code;
@ -2387,7 +2388,7 @@ void RasterizerStorageGLES3::update_dirty_shaders() {
void RasterizerStorageGLES3::shader_get_param_list(RID p_shader, List<PropertyInfo> *p_param_list) const {
Shader *shader = shader_owner.get(p_shader);
Shader *shader = shader_owner.getornull(p_shader);
ERR_FAIL_COND(!shader);
if (shader->dirty_list.in_list())
@ -2471,7 +2472,7 @@ void RasterizerStorageGLES3::shader_get_param_list(RID p_shader, List<PropertyIn
pi.type = Variant::OBJECT;
pi.hint = PROPERTY_HINT_RESOURCE_TYPE;
pi.hint_string = "Texture";
pi.hint_string = "Texture2D";
} break;
case ShaderLanguage::TYPE_SAMPLER2DARRAY:
case ShaderLanguage::TYPE_ISAMPLER2DARRAY:
@ -2502,7 +2503,7 @@ void RasterizerStorageGLES3::shader_get_param_list(RID p_shader, List<PropertyIn
void RasterizerStorageGLES3::shader_set_default_texture_param(RID p_shader, const StringName &p_name, RID p_texture) {
Shader *shader = shader_owner.get(p_shader);
Shader *shader = shader_owner.getornull(p_shader);
ERR_FAIL_COND(!shader);
ERR_FAIL_COND(p_texture.is_valid() && !texture_owner.owns(p_texture));
@ -2515,7 +2516,7 @@ void RasterizerStorageGLES3::shader_set_default_texture_param(RID p_shader, cons
}
RID RasterizerStorageGLES3::shader_get_default_texture_param(RID p_shader, const StringName &p_name) const {
const Shader *shader = shader_owner.get(p_shader);
const Shader *shader = shader_owner.getornull(p_shader);
ERR_FAIL_COND_V(!shader, RID());
const Map<StringName, RID>::Element *E = shader->default_textures.find(p_name);
@ -2543,7 +2544,7 @@ RID RasterizerStorageGLES3::material_create() {
void RasterizerStorageGLES3::material_set_shader(RID p_material, RID p_shader) {
Material *material = material_owner.get(p_material);
Material *material = material_owner.getornull(p_material);
ERR_FAIL_COND(!material);
Shader *shader = shader_owner.getornull(p_shader);
@ -2563,7 +2564,7 @@ void RasterizerStorageGLES3::material_set_shader(RID p_material, RID p_shader) {
RID RasterizerStorageGLES3::material_get_shader(RID p_material) const {
const Material *material = material_owner.get(p_material);
const Material *material = material_owner.getornull(p_material);
ERR_FAIL_COND_V(!material, RID());
if (material->shader)
@ -2574,7 +2575,7 @@ RID RasterizerStorageGLES3::material_get_shader(RID p_material) const {
void RasterizerStorageGLES3::material_set_param(RID p_material, const StringName &p_param, const Variant &p_value) {
Material *material = material_owner.get(p_material);
Material *material = material_owner.getornull(p_material);
ERR_FAIL_COND(!material);
if (p_value.get_type() == Variant::NIL)
@ -2586,7 +2587,7 @@ void RasterizerStorageGLES3::material_set_param(RID p_material, const StringName
}
Variant RasterizerStorageGLES3::material_get_param(RID p_material, const StringName &p_param) const {
const Material *material = material_owner.get(p_material);
const Material *material = material_owner.getornull(p_material);
ERR_FAIL_COND_V(!material, Variant());
if (material->params.has(p_param))
@ -2596,7 +2597,7 @@ Variant RasterizerStorageGLES3::material_get_param(RID p_material, const StringN
}
Variant RasterizerStorageGLES3::material_get_param_default(RID p_material, const StringName &p_param) const {
const Material *material = material_owner.get(p_material);
const Material *material = material_owner.getornull(p_material);
ERR_FAIL_COND_V(!material, Variant());
if (material->shader) {
@ -2611,7 +2612,7 @@ Variant RasterizerStorageGLES3::material_get_param_default(RID p_material, const
void RasterizerStorageGLES3::material_set_line_width(RID p_material, float p_width) {
Material *material = material_owner.get(p_material);
Material *material = material_owner.getornull(p_material);
ERR_FAIL_COND(!material);
material->line_width = p_width;
@ -2619,7 +2620,7 @@ void RasterizerStorageGLES3::material_set_line_width(RID p_material, float p_wid
void RasterizerStorageGLES3::material_set_next_pass(RID p_material, RID p_next_material) {
Material *material = material_owner.get(p_material);
Material *material = material_owner.getornull(p_material);
ERR_FAIL_COND(!material);
material->next_pass = p_next_material;
@ -2627,7 +2628,7 @@ void RasterizerStorageGLES3::material_set_next_pass(RID p_material, RID p_next_m
bool RasterizerStorageGLES3::material_is_animated(RID p_material) {
Material *material = material_owner.get(p_material);
Material *material = material_owner.getornull(p_material);
ERR_FAIL_COND_V(!material, false);
if (material->dirty_list.in_list()) {
_update_material(material);
@ -2641,7 +2642,7 @@ bool RasterizerStorageGLES3::material_is_animated(RID p_material) {
}
bool RasterizerStorageGLES3::material_casts_shadows(RID p_material) {
Material *material = material_owner.get(p_material);
Material *material = material_owner.getornull(p_material);
ERR_FAIL_COND_V(!material, false);
if (material->dirty_list.in_list()) {
_update_material(material);
@ -2658,7 +2659,7 @@ bool RasterizerStorageGLES3::material_casts_shadows(RID p_material) {
void RasterizerStorageGLES3::material_add_instance_owner(RID p_material, RasterizerScene::InstanceBase *p_instance) {
Material *material = material_owner.get(p_material);
Material *material = material_owner.getornull(p_material);
ERR_FAIL_COND(!material);
Map<RasterizerScene::InstanceBase *, int>::Element *E = material->instance_owners.find(p_instance);
@ -2671,7 +2672,7 @@ void RasterizerStorageGLES3::material_add_instance_owner(RID p_material, Rasteri
void RasterizerStorageGLES3::material_remove_instance_owner(RID p_material, RasterizerScene::InstanceBase *p_instance) {
Material *material = material_owner.get(p_material);
Material *material = material_owner.getornull(p_material);
ERR_FAIL_COND(!material);
Map<RasterizerScene::InstanceBase *, int>::Element *E = material->instance_owners.find(p_instance);
@ -2688,7 +2689,7 @@ void RasterizerStorageGLES3::material_set_render_priority(RID p_material, int pr
ERR_FAIL_COND(priority < VS::MATERIAL_RENDER_PRIORITY_MIN);
ERR_FAIL_COND(priority > VS::MATERIAL_RENDER_PRIORITY_MAX);
Material *material = material_owner.get(p_material);
Material *material = material_owner.getornull(p_material);
ERR_FAIL_COND(!material);
material->render_priority = priority;
@ -4136,7 +4137,7 @@ AABB RasterizerStorageGLES3::mesh_get_custom_aabb(RID p_mesh) const {
AABB RasterizerStorageGLES3::mesh_get_aabb(RID p_mesh, RID p_skeleton) const {
Mesh *mesh = mesh_owner.get(p_mesh);
Mesh *mesh = mesh_owner.getornull(p_mesh);
ERR_FAIL_COND_V(!mesh, AABB());
if (mesh->custom_aabb != AABB()) {
@ -4145,7 +4146,7 @@ AABB RasterizerStorageGLES3::mesh_get_aabb(RID p_mesh, RID p_skeleton) const {
Skeleton *sk = NULL;
if (p_skeleton.is_valid()) {
sk = skeleton_owner.get(p_skeleton);
sk = skeleton_owner.getornull(p_skeleton);
}
AABB aabb;
@ -5047,7 +5048,7 @@ RID RasterizerStorageGLES3::immediate_create() {
void RasterizerStorageGLES3::immediate_begin(RID p_immediate, VS::PrimitiveType p_primitive, RID p_texture) {
ERR_FAIL_INDEX(p_primitive, (int)VS::PRIMITIVE_MAX);
Immediate *im = immediate_owner.get(p_immediate);
Immediate *im = immediate_owner.getornull(p_immediate);
ERR_FAIL_COND(!im);
ERR_FAIL_COND(im->building);
@ -5060,7 +5061,7 @@ void RasterizerStorageGLES3::immediate_begin(RID p_immediate, VS::PrimitiveType
}
void RasterizerStorageGLES3::immediate_vertex(RID p_immediate, const Vector3 &p_vertex) {
Immediate *im = immediate_owner.get(p_immediate);
Immediate *im = immediate_owner.getornull(p_immediate);
ERR_FAIL_COND(!im);
ERR_FAIL_COND(!im->building);
@ -5090,7 +5091,7 @@ void RasterizerStorageGLES3::immediate_vertex(RID p_immediate, const Vector3 &p_
void RasterizerStorageGLES3::immediate_normal(RID p_immediate, const Vector3 &p_normal) {
Immediate *im = immediate_owner.get(p_immediate);
Immediate *im = immediate_owner.getornull(p_immediate);
ERR_FAIL_COND(!im);
ERR_FAIL_COND(!im->building);
@ -5099,7 +5100,7 @@ void RasterizerStorageGLES3::immediate_normal(RID p_immediate, const Vector3 &p_
}
void RasterizerStorageGLES3::immediate_tangent(RID p_immediate, const Plane &p_tangent) {
Immediate *im = immediate_owner.get(p_immediate);
Immediate *im = immediate_owner.getornull(p_immediate);
ERR_FAIL_COND(!im);
ERR_FAIL_COND(!im->building);
@ -5108,7 +5109,7 @@ void RasterizerStorageGLES3::immediate_tangent(RID p_immediate, const Plane &p_t
}
void RasterizerStorageGLES3::immediate_color(RID p_immediate, const Color &p_color) {
Immediate *im = immediate_owner.get(p_immediate);
Immediate *im = immediate_owner.getornull(p_immediate);
ERR_FAIL_COND(!im);
ERR_FAIL_COND(!im->building);
@ -5117,7 +5118,7 @@ void RasterizerStorageGLES3::immediate_color(RID p_immediate, const Color &p_col
}
void RasterizerStorageGLES3::immediate_uv(RID p_immediate, const Vector2 &tex_uv) {
Immediate *im = immediate_owner.get(p_immediate);
Immediate *im = immediate_owner.getornull(p_immediate);
ERR_FAIL_COND(!im);
ERR_FAIL_COND(!im->building);
@ -5126,7 +5127,7 @@ void RasterizerStorageGLES3::immediate_uv(RID p_immediate, const Vector2 &tex_uv
}
void RasterizerStorageGLES3::immediate_uv2(RID p_immediate, const Vector2 &tex_uv) {
Immediate *im = immediate_owner.get(p_immediate);
Immediate *im = immediate_owner.getornull(p_immediate);
ERR_FAIL_COND(!im);
ERR_FAIL_COND(!im->building);
@ -5136,7 +5137,7 @@ void RasterizerStorageGLES3::immediate_uv2(RID p_immediate, const Vector2 &tex_u
void RasterizerStorageGLES3::immediate_end(RID p_immediate) {
Immediate *im = immediate_owner.get(p_immediate);
Immediate *im = immediate_owner.getornull(p_immediate);
ERR_FAIL_COND(!im);
ERR_FAIL_COND(!im->building);
@ -5146,7 +5147,7 @@ void RasterizerStorageGLES3::immediate_end(RID p_immediate) {
}
void RasterizerStorageGLES3::immediate_clear(RID p_immediate) {
Immediate *im = immediate_owner.get(p_immediate);
Immediate *im = immediate_owner.getornull(p_immediate);
ERR_FAIL_COND(!im);
ERR_FAIL_COND(im->building);
@ -5156,14 +5157,14 @@ void RasterizerStorageGLES3::immediate_clear(RID p_immediate) {
AABB RasterizerStorageGLES3::immediate_get_aabb(RID p_immediate) const {
Immediate *im = immediate_owner.get(p_immediate);
Immediate *im = immediate_owner.getornull(p_immediate);
ERR_FAIL_COND_V(!im, AABB());
return im->aabb;
}
void RasterizerStorageGLES3::immediate_set_material(RID p_immediate, RID p_material) {
Immediate *im = immediate_owner.get(p_immediate);
Immediate *im = immediate_owner.getornull(p_immediate);
ERR_FAIL_COND(!im);
im->material = p_material;
im->instance_change_notify(false, true);
@ -5171,7 +5172,7 @@ void RasterizerStorageGLES3::immediate_set_material(RID p_immediate, RID p_mater
RID RasterizerStorageGLES3::immediate_get_material(RID p_immediate) const {
const Immediate *im = immediate_owner.get(p_immediate);
const Immediate *im = immediate_owner.getornull(p_immediate);
ERR_FAIL_COND_V(!im, RID());
return im->material;
}
@ -6999,7 +7000,7 @@ void RasterizerStorageGLES3::_render_target_clear(RenderTarget *rt) {
glDeleteFramebuffers(1, &rt->external.fbo);
// clean up our texture
Texture *t = texture_owner.get(rt->external.texture);
Texture *t = texture_owner.getornull(rt->external.texture);
t->alloc_height = 0;
t->alloc_width = 0;
t->width = 0;
@ -7011,7 +7012,7 @@ void RasterizerStorageGLES3::_render_target_clear(RenderTarget *rt) {
rt->external.fbo = 0;
}
Texture *tex = texture_owner.get(rt->texture);
Texture *tex = texture_owner.getornull(rt->texture);
tex->alloc_height = 0;
tex->alloc_width = 0;
tex->width = 0;
@ -7117,7 +7118,7 @@ void RasterizerStorageGLES3::_render_target_allocate(RenderTarget *rt) {
ERR_FAIL_COND(status != GL_FRAMEBUFFER_COMPLETE);
Texture *tex = texture_owner.get(rt->texture);
Texture *tex = texture_owner.getornull(rt->texture);
tex->format = image_format;
tex->gl_format_cache = color_format;
tex->gl_type_cache = color_type;
@ -7487,7 +7488,7 @@ void RasterizerStorageGLES3::render_target_set_external_texture(RID p_render_tar
glDeleteFramebuffers(1, &rt->external.fbo);
// clean up our texture
Texture *t = texture_owner.get(rt->external.texture);
Texture *t = texture_owner.getornull(rt->external.texture);
t->alloc_height = 0;
t->alloc_width = 0;
t->width = 0;
@ -7536,7 +7537,7 @@ void RasterizerStorageGLES3::render_target_set_external_texture(RID p_render_tar
glBindFramebuffer(GL_FRAMEBUFFER, rt->external.fbo);
// find our texture
t = texture_owner.get(rt->external.texture);
t = texture_owner.getornull(rt->external.texture);
}
// set our texture
@ -7594,7 +7595,7 @@ bool RasterizerStorageGLES3::render_target_was_used(RID p_render_target) {
return rt->used_in_frame;
}
void RasterizerStorageGLES3::render_target_clear_used(RID p_render_target) {
void RasterizerStorageGLES3::render_target_set_as_unused(RID p_render_target) {
RenderTarget *rt = render_target_owner.getornull(p_render_target);
ERR_FAIL_COND(!rt);
@ -7678,7 +7679,7 @@ RID RasterizerStorageGLES3::canvas_light_occluder_create() {
void RasterizerStorageGLES3::canvas_light_occluder_set_polylines(RID p_occluder, const PoolVector<Vector2> &p_lines) {
CanvasOccluder *co = canvas_occluder_owner.get(p_occluder);
CanvasOccluder *co = canvas_occluder_owner.getornull(p_occluder);
ERR_FAIL_COND(!co);
co->lines = p_lines;
@ -7818,7 +7819,7 @@ 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 *t = texture_owner.getornull(rt->texture);
texture_owner.free(rt->texture);
memdelete(t);
render_target_owner.free(p_rid);
@ -7826,7 +7827,7 @@ bool RasterizerStorageGLES3::free(RID p_rid) {
} else if (texture_owner.owns(p_rid)) {
// delete the texture
Texture *texture = texture_owner.get(p_rid);
Texture *texture = texture_owner.getornull(p_rid);
ERR_FAIL_COND_V(texture->render_target, true); //can't free the render target texture, dude
info.texture_mem -= texture->total_data_size;
texture_owner.free(p_rid);
@ -7834,7 +7835,7 @@ bool RasterizerStorageGLES3::free(RID p_rid) {
} else if (sky_owner.owns(p_rid)) {
// delete the sky
Sky *sky = sky_owner.get(p_rid);
Sky *sky = sky_owner.getornull(p_rid);
sky_set_texture(p_rid, RID(), 256);
sky_owner.free(p_rid);
memdelete(sky);
@ -7842,7 +7843,7 @@ bool RasterizerStorageGLES3::free(RID p_rid) {
} else if (shader_owner.owns(p_rid)) {
// delete the texture
Shader *shader = shader_owner.get(p_rid);
Shader *shader = shader_owner.getornull(p_rid);
if (shader->shader && shader->custom_code_id)
shader->shader->free_custom_shader(shader->custom_code_id);
@ -7867,7 +7868,7 @@ bool RasterizerStorageGLES3::free(RID p_rid) {
} else if (material_owner.owns(p_rid)) {
// delete the texture
Material *material = material_owner.get(p_rid);
Material *material = material_owner.getornull(p_rid);
if (material->shader) {
material->shader->materials.remove(&material->list);
@ -7902,7 +7903,7 @@ bool RasterizerStorageGLES3::free(RID p_rid) {
} else if (skeleton_owner.owns(p_rid)) {
// delete the texture
Skeleton *skeleton = skeleton_owner.get(p_rid);
Skeleton *skeleton = skeleton_owner.getornull(p_rid);
if (skeleton->update_list.in_list()) {
skeleton_update_list.remove(&skeleton->update_list);
}
@ -7920,7 +7921,7 @@ bool RasterizerStorageGLES3::free(RID p_rid) {
} else if (mesh_owner.owns(p_rid)) {
// delete the texture
Mesh *mesh = mesh_owner.get(p_rid);
Mesh *mesh = mesh_owner.getornull(p_rid);
mesh->instance_remove_deps();
mesh_clear(p_rid);
@ -7941,7 +7942,7 @@ bool RasterizerStorageGLES3::free(RID p_rid) {
} else if (multimesh_owner.owns(p_rid)) {
// delete the texture
MultiMesh *multimesh = multimesh_owner.get(p_rid);
MultiMesh *multimesh = multimesh_owner.getornull(p_rid);
multimesh->instance_remove_deps();
if (multimesh->mesh.is_valid()) {
@ -7958,7 +7959,7 @@ bool RasterizerStorageGLES3::free(RID p_rid) {
memdelete(multimesh);
} else if (immediate_owner.owns(p_rid)) {
Immediate *immediate = immediate_owner.get(p_rid);
Immediate *immediate = immediate_owner.getornull(p_rid);
immediate->instance_remove_deps();
immediate_owner.free(p_rid);
@ -7966,7 +7967,7 @@ bool RasterizerStorageGLES3::free(RID p_rid) {
} else if (light_owner.owns(p_rid)) {
// delete the texture
Light *light = light_owner.get(p_rid);
Light *light = light_owner.getornull(p_rid);
light->instance_remove_deps();
light_owner.free(p_rid);
@ -7975,7 +7976,7 @@ bool RasterizerStorageGLES3::free(RID p_rid) {
} else if (reflection_probe_owner.owns(p_rid)) {
// delete the texture
ReflectionProbe *reflection_probe = reflection_probe_owner.get(p_rid);
ReflectionProbe *reflection_probe = reflection_probe_owner.getornull(p_rid);
reflection_probe->instance_remove_deps();
reflection_probe_owner.free(p_rid);
@ -7984,7 +7985,7 @@ bool RasterizerStorageGLES3::free(RID p_rid) {
} else if (gi_probe_owner.owns(p_rid)) {
// delete the texture
GIProbe *gi_probe = gi_probe_owner.get(p_rid);
GIProbe *gi_probe = gi_probe_owner.getornull(p_rid);
gi_probe->instance_remove_deps();
gi_probe_owner.free(p_rid);
@ -7992,7 +7993,7 @@ bool RasterizerStorageGLES3::free(RID p_rid) {
} else if (gi_probe_data_owner.owns(p_rid)) {
// delete the texture
GIProbeData *gi_probe_data = gi_probe_data_owner.get(p_rid);
GIProbeData *gi_probe_data = gi_probe_data_owner.getornull(p_rid);
glDeleteTextures(1, &gi_probe_data->tex_id);
gi_probe_data_owner.free(p_rid);
@ -8000,7 +8001,7 @@ bool RasterizerStorageGLES3::free(RID p_rid) {
} else if (lightmap_capture_data_owner.owns(p_rid)) {
// delete the texture
LightmapCapture *lightmap_capture = lightmap_capture_data_owner.get(p_rid);
LightmapCapture *lightmap_capture = lightmap_capture_data_owner.getornull(p_rid);
lightmap_capture->instance_remove_deps();
lightmap_capture_data_owner.free(p_rid);
@ -8008,7 +8009,7 @@ bool RasterizerStorageGLES3::free(RID p_rid) {
} else if (canvas_occluder_owner.owns(p_rid)) {
CanvasOccluder *co = canvas_occluder_owner.get(p_rid);
CanvasOccluder *co = canvas_occluder_owner.getornull(p_rid);
if (co->index_id)
glDeleteBuffers(1, &co->index_id);
if (co->vertex_id)
@ -8021,14 +8022,14 @@ bool RasterizerStorageGLES3::free(RID p_rid) {
} else if (canvas_light_shadow_owner.owns(p_rid)) {
CanvasLightShadow *cls = canvas_light_shadow_owner.get(p_rid);
CanvasLightShadow *cls = canvas_light_shadow_owner.getornull(p_rid);
glDeleteFramebuffers(1, &cls->fbo);
glDeleteRenderbuffers(1, &cls->depth);
glDeleteTextures(1, &cls->distance);
canvas_light_shadow_owner.free(p_rid);
memdelete(cls);
} else if (particles_owner.owns(p_rid)) {
Particles *particles = particles_owner.get(p_rid);
Particles *particles = particles_owner.getornull(p_rid);
particles->instance_remove_deps();
particles_owner.free(p_rid);
memdelete(particles);

View file

@ -43,6 +43,8 @@
#include "shaders/cubemap_filter.glsl.gen.h"
#include "shaders/particles.glsl.gen.h"
#include "core/rid_owner.h"
// WebGL 2.0 has no MapBufferRange/UnmapBuffer, but offers a non-ES style BufferSubData API instead.
#ifdef __EMSCRIPTEN__
void glGetBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, GLvoid *data);
@ -179,7 +181,7 @@ public:
//////////////////////////////////DATA///////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
struct Instantiable : public RID_Data {
struct Instantiable {
SelfList<RasterizerScene::InstanceBase>::List instance_list;
@ -242,7 +244,7 @@ public:
struct RenderTarget;
struct Texture : public RID_Data {
struct Texture {
Texture *proxy;
Set<Texture *> proxy_owners;
@ -342,7 +344,7 @@ public:
}
};
mutable RID_Owner<Texture> texture_owner;
mutable RID_PtrOwner<Texture2D> texture_owner;
Ref<Image> _get_gl_image_and_format(const Ref<Image> &p_image, Image::Format p_format, uint32_t p_flags, Image::Format &r_real_format, GLenum &r_gl_format, GLenum &r_gl_internal_format, GLenum &r_gl_type, bool &r_compressed, bool &r_srgb, bool p_force_decompress) const;
@ -384,7 +386,7 @@ public:
/* SKY API */
struct Sky : public RID_Data {
struct Sky {
RID panorama;
GLuint radiance;
@ -392,7 +394,7 @@ public:
int radiance_size;
};
mutable RID_Owner<Sky> sky_owner;
mutable RID_PtrOwner<Sky> sky_owner;
virtual RID sky_create();
virtual void sky_set_texture(RID p_sky, RID p_panorama, int p_radiance_size);
@ -401,7 +403,7 @@ public:
struct Material;
struct Shader : public RID_Data {
struct Shader {
RID self;
@ -522,7 +524,7 @@ public:
mutable SelfList<Shader>::List _shader_dirty_list;
void _shader_make_dirty(Shader *p_shader);
mutable RID_Owner<Shader> shader_owner;
mutable RID_PtrOwner<Shader> shader_owner;
virtual RID shader_create();
@ -539,7 +541,7 @@ public:
/* COMMON MATERIAL API */
struct Material : public RID_Data {
struct Material {
Shader *shader;
GLuint ubo_id;
@ -582,7 +584,7 @@ public:
void _material_add_geometry(RID p_material, Geometry *p_geometry);
void _material_remove_geometry(RID p_material, Geometry *p_geometry);
mutable RID_Owner<Material> material_owner;
mutable RID_PtrOwner<Material> material_owner;
virtual RID material_create();
@ -724,7 +726,7 @@ public:
}
};
mutable RID_Owner<Mesh> mesh_owner;
mutable RID_PtrOwner<Mesh> mesh_owner;
virtual RID mesh_create();
@ -804,7 +806,7 @@ public:
}
};
mutable RID_Owner<MultiMesh> multimesh_owner;
mutable RID_PtrOwner<MultiMesh> multimesh_owner;
SelfList<MultiMesh>::List multimesh_update_list;
@ -869,7 +871,7 @@ public:
Vector2 chunk_uv;
Vector2 chunk_uv2;
mutable RID_Owner<Immediate> immediate_owner;
mutable RID_PtrOwner<Immediate> immediate_owner;
virtual RID immediate_create();
virtual void immediate_begin(RID p_immediate, VS::PrimitiveType p_primitive, RID p_texture = RID());
@ -887,7 +889,7 @@ public:
/* SKELETON API */
struct Skeleton : RID_Data {
struct Skeleton {
bool use_2d;
int size;
Vector<float> skel_texture;
@ -904,7 +906,7 @@ public:
}
};
mutable RID_Owner<Skeleton> skeleton_owner;
mutable RID_PtrOwner<Skeleton> skeleton_owner;
SelfList<Skeleton>::List skeleton_update_list;
@ -941,7 +943,7 @@ public:
uint64_t version;
};
mutable RID_Owner<Light> light_owner;
mutable RID_PtrOwner<Light> light_owner;
virtual RID light_create(VS::LightType p_type);
@ -996,7 +998,7 @@ public:
uint32_t cull_mask;
};
mutable RID_Owner<ReflectionProbe> reflection_probe_owner;
mutable RID_PtrOwner<ReflectionProbe> reflection_probe_owner;
virtual RID reflection_probe_create();
@ -1044,7 +1046,7 @@ public:
PoolVector<int> dynamic_data;
};
mutable RID_Owner<GIProbe> gi_probe_owner;
mutable RID_PtrOwner<GIProbe> gi_probe_owner;
virtual RID gi_probe_create();
@ -1083,7 +1085,7 @@ public:
virtual uint32_t gi_probe_get_version(RID p_probe);
struct GIProbeData : public RID_Data {
struct GIProbeData {
int width;
int height;
@ -1096,7 +1098,7 @@ public:
}
};
mutable RID_Owner<GIProbeData> gi_probe_data_owner;
mutable RID_PtrOwner<GIProbeData> gi_probe_data_owner;
virtual GIProbeCompression gi_probe_get_dynamic_data_get_preferred_compression() const;
virtual RID gi_probe_dynamic_data_create(int p_width, int p_height, int p_depth, GIProbeCompression p_compression);
@ -1132,7 +1134,7 @@ public:
}
};
mutable RID_Owner<LightmapCapture> lightmap_capture_data_owner;
mutable RID_PtrOwner<LightmapCapture> lightmap_capture_data_owner;
/* PARTICLES */
@ -1228,7 +1230,7 @@ public:
void update_particles();
mutable RID_Owner<Particles> particles_owner;
mutable RID_PtrOwner<Particles> particles_owner;
virtual RID particles_create();
@ -1277,7 +1279,7 @@ public:
/* RENDER TARGET */
struct RenderTarget : public RID_Data {
struct RenderTarget {
GLuint fbo;
GLuint color;
@ -1389,7 +1391,7 @@ public:
}
};
mutable RID_Owner<RenderTarget> render_target_owner;
mutable RID_PtrOwner<RenderTarget> render_target_owner;
void _render_target_clear(RenderTarget *rt);
void _render_target_allocate(RenderTarget *rt);
@ -1402,12 +1404,12 @@ public:
virtual void render_target_set_flag(RID p_render_target, RenderTargetFlags p_flag, bool p_value);
virtual bool render_target_was_used(RID p_render_target);
virtual void render_target_clear_used(RID p_render_target);
virtual void render_target_set_as_unused(RID p_render_target);
virtual void render_target_set_msaa(RID p_render_target, VS::ViewportMSAA p_msaa);
/* CANVAS SHADOW */
struct CanvasLightShadow : public RID_Data {
struct CanvasLightShadow {
int size;
int height;
@ -1416,13 +1418,13 @@ public:
GLuint distance; //for older devices
};
RID_Owner<CanvasLightShadow> canvas_light_shadow_owner;
RID_PtrOwner<CanvasLightShadow> canvas_light_shadow_owner;
virtual RID canvas_light_shadow_buffer_create(int p_width);
/* LIGHT SHADOW MAPPING */
struct CanvasOccluder : public RID_Data {
struct CanvasOccluder {
GLuint array_id; // 0 means, unconfigured
GLuint vertex_id; // 0 means, unconfigured
@ -1431,7 +1433,7 @@ public:
int len;
};
RID_Owner<CanvasOccluder> canvas_occluder_owner;
RID_PtrOwner<CanvasOccluder> canvas_occluder_owner;
virtual RID canvas_light_occluder_create();
virtual void canvas_light_occluder_set_polylines(RID p_occluder, const PoolVector<Vector2> &p_lines);

View file

@ -354,8 +354,6 @@ String ShaderCompilerGLES3::_dump_node_code(SL::Node *p_node, int p_level, Gener
}
r_gen_code.texture_uniforms.resize(max_texture_uniforms);
r_gen_code.texture_hints.resize(max_texture_uniforms);
r_gen_code.texture_types.resize(max_texture_uniforms);
Vector<int> uniform_sizes;
Vector<int> uniform_alignments;
@ -380,9 +378,15 @@ String ShaderCompilerGLES3::_dump_node_code(SL::Node *p_node, int p_level, Gener
if (SL::is_sampler_type(E->get().type)) {
r_gen_code.vertex_global += ucode;
r_gen_code.fragment_global += ucode;
r_gen_code.texture_uniforms.write[E->get().texture_order] = _mkid(E->key());
r_gen_code.texture_hints.write[E->get().texture_order] = E->get().hint;
r_gen_code.texture_types.write[E->get().texture_order] = E->get().type;
GeneratedCode::Texture texture;
texture.name = _mkid(E->key());
texture.hint = E->get().hint;
texture.type = E->get().type;
texture.filter = E->get().filter;
texture.repeat = E->get().repeat;
r_gen_code.texture_uniforms.write[E->get().texture_order] = texture;
} else {
if (!uses_uniforms) {

View file

@ -51,9 +51,15 @@ public:
struct GeneratedCode {
Vector<CharString> defines;
Vector<StringName> texture_uniforms;
Vector<ShaderLanguage::DataType> texture_types;
Vector<ShaderLanguage::ShaderNode::Uniform::Hint> texture_hints;
struct Texture {
StringName name;
ShaderLanguage::DataType type;
ShaderLanguage::ShaderNode::Uniform::Hint hint;
ShaderLanguage::ShaderNode::Uniform::Filter filter;
ShaderLanguage::ShaderNode::Uniform::Repeat repeat;
};
Vector<Texture> texture_uniforms;
Vector<uint32_t> uniform_offsets;
uint32_t uniform_total_size;

View file

@ -114,6 +114,7 @@ Error png_to_image(const uint8_t *p_source, size_t p_size, Ref<Image> p_image) {
ERR_FAIL_COND_V_MSG(check_error(png_img), ERR_FILE_CORRUPT, png_img.message);
ERR_FAIL_COND_V(!success, ERR_FILE_CORRUPT);
//print_line("png width: "+itos(png_img.width)+" height: "+itos(png_img.height));
p_image->create(png_img.width, png_img.height, 0, dest_format, buffer);
return OK;

View file

@ -71,6 +71,14 @@ Error ResourceSaverPNG::save_image(const String &p_path, const Ref<Image> &p_img
return OK;
}
PoolVector<uint8_t> ResourceSaverPNG::save_image_to_buffer(const Ref<Image> &p_img) {
PoolVector<uint8_t> buffer;
Error err = PNGDriverCommon::image_to_png(p_img, buffer);
ERR_FAIL_COND_V_MSG(err, PoolVector<uint8_t>(), "Can't convert image to PNG.");
return buffer;
}
bool ResourceSaverPNG::recognize(const RES &p_resource) const {
return (p_resource.is_valid() && p_resource->is_class("ImageTexture"));
@ -86,4 +94,5 @@ void ResourceSaverPNG::get_recognized_extensions(const RES &p_resource, List<Str
ResourceSaverPNG::ResourceSaverPNG() {
Image::save_png_func = &save_image;
Image::save_png_buffer_func = &save_image_to_buffer;
};

View file

@ -37,6 +37,7 @@
class ResourceSaverPNG : public ResourceFormatSaver {
public:
static Error save_image(const String &p_path, const Ref<Image> &p_img);
static PoolVector<uint8_t> save_image_to_buffer(const Ref<Image> &p_img);
virtual Error save(const String &p_path, const RES &p_resource, uint32_t p_flags = 0);
virtual bool recognize(const RES &p_resource) const;

View file

@ -0,0 +1,16 @@
#!/usr/bin/env python
Import('env')
env_spirv_reflect = env.Clone()
thirdparty_dir = "#thirdparty/spirv-reflect/"
thirdparty_sources = [
"spirv_reflect.c"
]
thirdparty_sources = [thirdparty_dir + file for file in thirdparty_sources]
env_spirv_reflect.add_source_files(env.drivers_sources, thirdparty_sources)
Export('env')

View file

@ -62,7 +62,7 @@ int SemaphorePosix::get() const {
return val;
}
Semaphore *SemaphorePosix::create_semaphore_posix() {
SemaphoreOld *SemaphorePosix::create_semaphore_posix() {
return memnew(SemaphorePosix);
}

View file

@ -37,11 +37,11 @@
#include <semaphore.h>
class SemaphorePosix : public Semaphore {
class SemaphorePosix : public SemaphoreOld {
mutable sem_t sem;
static Semaphore *create_semaphore_posix();
static SemaphoreOld *create_semaphore_posix();
public:
virtual Error wait();

63
drivers/vulkan/SCsub Normal file
View file

@ -0,0 +1,63 @@
#!/usr/bin/env python
Import('env')
env.add_source_files(env.drivers_sources, "*.cpp")
if env['builtin_vulkan']:
# Use bundled Vulkan headers
thirdparty_dir = "#thirdparty/vulkan"
env.Prepend(CPPPATH=[thirdparty_dir, thirdparty_dir + "/include", thirdparty_dir + "/loader"])
# Build Vulkan loader library
env_thirdparty = env.Clone()
env_thirdparty.disable_warnings()
loader_sources = [
"cJSON.c",
"debug_utils.c",
"dev_ext_trampoline.c",
"loader.c",
"murmurhash.c",
"phys_dev_ext.c",
"trampoline.c",
"unknown_ext_chain.c",
"wsi.c",
"extension_manual.c",
]
vma_sources = [thirdparty_dir + "/vk_mem_alloc.cpp"]
if env['platform'] == "windows":
loader_sources.append("dirent_on_windows.c")
loader_sources.append("dxgi_loader.c")
env_thirdparty.AppendUnique(CPPDEFINES=[
'VK_USE_PLATFORM_WIN32_KHR',
'VULKAN_NON_CMAKE_BUILD',
'WIN32_LEAN_AND_MEAN',
'API_NAME=\\"%s\\"' % 'Vulkan'
])
if not env.msvc: # Windows 7+, missing in mingw headers
env_thirdparty.AppendUnique(CPPDEFINES=[
"CM_GETIDLIST_FILTER_CLASS=0x00000200",
"CM_GETIDLIST_FILTER_PRESENT=0x00000100"
])
elif env['platform'] == "osx":
env_thirdparty.AppendUnique(CPPDEFINES=[
'VK_USE_PLATFORM_MACOS_MVK',
'VULKAN_NON_CMAKE_BUILD',
'SYSCONFDIR=\\"%s\\"' % '/etc',
'FALLBACK_DATA_DIRS=\\"%s\\"' % '/usr/local/share:/usr/share',
'FALLBACK_CONFIG_DIRS=\\"%s\\"' % '/etc/xdg'
])
elif env['platform'] == "x11":
env_thirdparty.AppendUnique(CPPDEFINES=[
'VK_USE_PLATFORM_XLIB_KHR',
'VULKAN_NON_CMAKE_BUILD',
'SYSCONFDIR=\\"%s\\"' % '/etc',
'FALLBACK_DATA_DIRS=\\"%s\\"' % '/usr/local/share:/usr/share',
'FALLBACK_CONFIG_DIRS=\\"%s\\"' % '/etc/xdg'
])
loader_sources = [thirdparty_dir + "/loader/" + file for file in loader_sources]
env_thirdparty.add_source_files(env.drivers_sources, loader_sources)
env_thirdparty.add_source_files(env.drivers_sources, vma_sources)

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,212 @@
/*************************************************************************/
/* vulkan_context.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#ifndef VULKAN_CONTEXT_H
#define VULKAN_CONTEXT_H
#include "core/error_list.h"
#include "core/map.h"
#include "core/ustring.h"
#include <vulkan/vulkan.h>
class VulkanContext {
enum {
MAX_EXTENSIONS = 128,
MAX_LAYERS = 64,
FRAME_LAG = 2
};
bool use_validation_layers;
VkInstance inst;
VkSurfaceKHR surface;
VkPhysicalDevice gpu;
VkPhysicalDeviceProperties gpu_props;
uint32_t queue_family_count;
VkQueueFamilyProperties *queue_props;
VkDevice device;
//present
bool queues_initialized;
uint32_t graphics_queue_family_index;
uint32_t present_queue_family_index;
bool separate_present_queue;
VkQueue graphics_queue;
VkQueue present_queue;
VkColorSpaceKHR color_space;
VkFormat format;
VkSemaphore image_acquired_semaphores[FRAME_LAG];
VkSemaphore draw_complete_semaphores[FRAME_LAG];
VkSemaphore image_ownership_semaphores[FRAME_LAG];
int frame_index;
VkFence fences[FRAME_LAG];
VkPhysicalDeviceMemoryProperties memory_properties;
VkPhysicalDeviceFeatures physical_device_features;
typedef struct {
VkImage image;
VkCommandBuffer graphics_to_present_cmd;
VkImageView view;
VkFramebuffer framebuffer;
} SwapchainImageResources;
struct Window {
bool is_minimzed;
VkSurfaceKHR surface;
VkSwapchainKHR swapchain;
SwapchainImageResources *swapchain_image_resources;
VkPresentModeKHR presentMode;
uint32_t current_buffer;
int width;
int height;
VkCommandPool present_cmd_pool; //for separate present queue
VkRenderPass render_pass;
Window() {
width = 0;
height = 0;
render_pass = VK_NULL_HANDLE;
current_buffer = 0;
surface = VK_NULL_HANDLE;
swapchain_image_resources = VK_NULL_HANDLE;
swapchain = VK_NULL_HANDLE;
is_minimzed = false;
presentMode = VK_PRESENT_MODE_FIFO_KHR;
}
};
Map<int, Window> windows;
int last_window_id;
uint32_t swapchainImageCount;
//commands
bool prepared;
//extensions
bool VK_KHR_incremental_present_enabled;
bool VK_GOOGLE_display_timing_enabled;
const char **instance_validation_layers;
uint32_t enabled_extension_count;
uint32_t enabled_layer_count;
const char *extension_names[MAX_EXTENSIONS];
const char *enabled_layers[MAX_LAYERS];
PFN_vkCreateDebugUtilsMessengerEXT CreateDebugUtilsMessengerEXT;
PFN_vkDestroyDebugUtilsMessengerEXT DestroyDebugUtilsMessengerEXT;
PFN_vkSubmitDebugUtilsMessageEXT SubmitDebugUtilsMessageEXT;
PFN_vkCmdBeginDebugUtilsLabelEXT CmdBeginDebugUtilsLabelEXT;
PFN_vkCmdEndDebugUtilsLabelEXT CmdEndDebugUtilsLabelEXT;
PFN_vkCmdInsertDebugUtilsLabelEXT CmdInsertDebugUtilsLabelEXT;
PFN_vkSetDebugUtilsObjectNameEXT SetDebugUtilsObjectNameEXT;
PFN_vkGetPhysicalDeviceSurfaceSupportKHR fpGetPhysicalDeviceSurfaceSupportKHR;
PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR fpGetPhysicalDeviceSurfaceCapabilitiesKHR;
PFN_vkGetPhysicalDeviceSurfaceFormatsKHR fpGetPhysicalDeviceSurfaceFormatsKHR;
PFN_vkGetPhysicalDeviceSurfacePresentModesKHR fpGetPhysicalDeviceSurfacePresentModesKHR;
PFN_vkCreateSwapchainKHR fpCreateSwapchainKHR;
PFN_vkDestroySwapchainKHR fpDestroySwapchainKHR;
PFN_vkGetSwapchainImagesKHR fpGetSwapchainImagesKHR;
PFN_vkAcquireNextImageKHR fpAcquireNextImageKHR;
PFN_vkQueuePresentKHR fpQueuePresentKHR;
PFN_vkGetRefreshCycleDurationGOOGLE fpGetRefreshCycleDurationGOOGLE;
PFN_vkGetPastPresentationTimingGOOGLE fpGetPastPresentationTimingGOOGLE;
VkDebugUtilsMessengerEXT dbg_messenger;
Error _create_validation_layers();
Error _initialize_extensions();
VkBool32 _check_layers(uint32_t check_count, const char **check_names, uint32_t layer_count, VkLayerProperties *layers);
static VKAPI_ATTR VkBool32 VKAPI_CALL _debug_messenger_callback(VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
VkDebugUtilsMessageTypeFlagsEXT messageType,
const VkDebugUtilsMessengerCallbackDataEXT *pCallbackData,
void *pUserData);
Error _create_physical_device();
Error _initialize_queues(VkSurfaceKHR surface);
Error _create_device();
Error _clean_up_swap_chain(Window *window);
Error _update_swap_chain(Window *window);
Error _create_swap_chain();
Error _create_semaphores();
Vector<VkCommandBuffer> command_buffer_queue;
int command_buffer_count;
protected:
virtual const char *_get_platform_surface_extension() const = 0;
// virtual VkResult _create_surface(VkSurfaceKHR *surface, VkInstance p_instance) = 0;
virtual int _window_create(VkSurfaceKHR p_surface, int p_width, int p_height);
VkInstance _get_instance() {
return inst;
}
bool buffers_prepared;
public:
VkDevice get_device();
VkPhysicalDevice get_physical_device();
int get_swapchain_image_count() const;
uint32_t get_graphics_queue() const;
void window_resize(int p_window_id, int p_width, int p_height);
int window_get_width(int p_window = 0);
int window_get_height(int p_window = 0);
void window_destroy(int p_window_id);
VkFramebuffer window_get_framebuffer(int p_window = 0);
VkRenderPass window_get_render_pass(int p_window = 0);
VkFormat get_screen_format() const;
VkPhysicalDeviceLimits get_device_limits() const;
void set_setup_buffer(const VkCommandBuffer &pCommandBuffer);
void append_command_buffer(const VkCommandBuffer &pCommandBuffer);
void resize_notify();
void flush(bool p_flush_setup = false, bool p_flush_pending = false);
Error prepare_buffers();
Error swap_buffers();
Error initialize();
VulkanContext();
virtual ~VulkanContext();
};
#endif // VULKAN_DEVICE_H

View file

@ -61,7 +61,7 @@ int SemaphoreWindows::get() const {
ERR_FAIL_V(-1);
}
Semaphore *SemaphoreWindows::create_semaphore_windows() {
SemaphoreOld *SemaphoreWindows::create_semaphore_windows() {
return memnew(SemaphoreWindows);
}

View file

@ -37,11 +37,11 @@
#include <windows.h>
class SemaphoreWindows : public Semaphore {
class SemaphoreWindows : public SemaphoreOld {
mutable HANDLE semaphore;
static Semaphore *create_semaphore_windows();
static SemaphoreOld *create_semaphore_windows();
public:
virtual Error wait();

View file

@ -258,7 +258,7 @@ void AnimationBezierTrackEdit::_notification(int p_what) {
draw_line(Point2(right_limit, 0), Point2(right_limit, get_size().height), linecolor);
Ref<Texture> close_icon = get_icon("Close", "EditorIcons");
Ref<Texture2D> close_icon = get_icon("Close", "EditorIcons");
close_icon_rect.position = Vector2(get_size().width - close_icon->get_width() - hsep, hsep);
close_icon_rect.size = close_icon->get_size();
@ -290,7 +290,7 @@ void AnimationBezierTrackEdit::_notification(int p_what) {
if (node) {
int ofs = 0;
Ref<Texture> icon = EditorNode::get_singleton()->get_object_icon(node, "Node");
Ref<Texture2D> icon = EditorNode::get_singleton()->get_object_icon(node, "Node");
h = MAX(h, icon->get_height());
@ -391,7 +391,7 @@ void AnimationBezierTrackEdit::_notification(int p_what) {
{ //draw OTHER curves
float scale = timeline->get_zoom_scale();
Ref<Texture> point = get_icon("KeyValue", "EditorIcons");
Ref<Texture2D> point = get_icon("KeyValue", "EditorIcons");
for (Map<int, Color>::Element *E = subtrack_colors.front(); E; E = E->next()) {
_draw_track(E->key(), E->get());

View file

@ -63,9 +63,9 @@ class AnimationBezierTrackEdit : public Control {
Vector<Rect2> view_rects;
Ref<Texture> bezier_icon;
Ref<Texture> bezier_handle_icon;
Ref<Texture> selected_icon;
Ref<Texture2D> bezier_icon;
Ref<Texture2D> bezier_handle_icon;
Ref<Texture2D> selected_icon;
Rect2 close_icon_rect;

View file

@ -1442,11 +1442,11 @@ void AnimationTimelineEdit::_anim_loop_pressed() {
int AnimationTimelineEdit::get_buttons_width() const {
Ref<Texture> interp_mode = get_icon("TrackContinuous", "EditorIcons");
Ref<Texture> interp_type = get_icon("InterpRaw", "EditorIcons");
Ref<Texture> loop_type = get_icon("InterpWrapClamp", "EditorIcons");
Ref<Texture> remove_icon = get_icon("Remove", "EditorIcons");
Ref<Texture> down_icon = get_icon("select_arrow", "Tree");
Ref<Texture2D> interp_mode = get_icon("TrackContinuous", "EditorIcons");
Ref<Texture2D> interp_type = get_icon("InterpRaw", "EditorIcons");
Ref<Texture2D> loop_type = get_icon("InterpWrapClamp", "EditorIcons");
Ref<Texture2D> remove_icon = get_icon("Remove", "EditorIcons");
Ref<Texture2D> down_icon = get_icon("select_arrow", "Tree");
int total_w = interp_mode->get_width() + interp_type->get_width() + loop_type->get_width() + remove_icon->get_width();
total_w += (down_icon->get_width() + 4 * EDSCALE) * 4;
@ -1456,7 +1456,7 @@ int AnimationTimelineEdit::get_buttons_width() const {
int AnimationTimelineEdit::get_name_limit() const {
Ref<Texture> hsize_icon = get_icon("Hsize", "EditorIcons");
Ref<Texture2D> hsize_icon = get_icon("Hsize", "EditorIcons");
int limit = MAX(name_limit, add_track->get_minimum_size().width + hsize_icon->get_width());
@ -1504,7 +1504,7 @@ void AnimationTimelineEdit::_notification(int p_what) {
if (l <= 0)
l = 0.001; //avoid crashor
Ref<Texture> hsize_icon = get_icon("Hsize", "EditorIcons");
Ref<Texture2D> hsize_icon = get_icon("Hsize", "EditorIcons");
hsize_rect = Rect2(get_name_limit() - hsize_icon->get_width() - 2 * EDSCALE, (get_size().height - hsize_icon->get_height()) / 2, hsize_icon->get_width(), hsize_icon->get_height());
draw_texture(hsize_icon, hsize_rect.position);
@ -1934,7 +1934,7 @@ void AnimationTrackEdit::_notification(int p_what) {
Ref<Font> font = get_font("font", "Label");
Color color = get_color("font_color", "Label");
Ref<Texture> type_icons[6] = {
Ref<Texture2D> type_icons[6] = {
get_icon("KeyValue", "EditorIcons"),
get_icon("KeyXform", "EditorIcons"),
get_icon("KeyCall", "EditorIcons"),
@ -1950,7 +1950,7 @@ void AnimationTrackEdit::_notification(int p_what) {
{
Ref<Texture> check = animation->track_is_enabled(track) ? get_icon("checked", "CheckBox") : get_icon("unchecked", "CheckBox");
Ref<Texture2D> check = animation->track_is_enabled(track) ? get_icon("checked", "CheckBox") : get_icon("unchecked", "CheckBox");
int ofs = in_group ? check->get_width() : 0; //not the best reference for margin but..
@ -1958,7 +1958,7 @@ void AnimationTrackEdit::_notification(int p_what) {
draw_texture(check, check_rect.position);
ofs += check->get_width() + hsep;
Ref<Texture> type_icon = type_icons[animation->track_get_type(track)];
Ref<Texture2D> type_icon = type_icons[animation->track_get_type(track)];
draw_texture(type_icon, Point2(ofs, int(get_size().height - type_icon->get_height()) / 2));
ofs += type_icon->get_width() + hsep;
@ -1987,7 +1987,7 @@ void AnimationTrackEdit::_notification(int p_what) {
}
text_color.a *= 0.7;
} else if (node) {
Ref<Texture> icon = EditorNode::get_singleton()->get_object_icon(node, "Node");
Ref<Texture2D> icon = EditorNode::get_singleton()->get_object_icon(node, "Node");
draw_texture(icon, Point2(ofs, int(get_size().height - icon->get_height()) / 2));
icon_cache = icon;
@ -2049,17 +2049,17 @@ void AnimationTrackEdit::_notification(int p_what) {
{
Ref<Texture> wrap_icon[2] = {
Ref<Texture2D> wrap_icon[2] = {
get_icon("InterpWrapClamp", "EditorIcons"),
get_icon("InterpWrapLoop", "EditorIcons"),
};
Ref<Texture> interp_icon[3] = {
Ref<Texture2D> interp_icon[3] = {
get_icon("InterpRaw", "EditorIcons"),
get_icon("InterpLinear", "EditorIcons"),
get_icon("InterpCubic", "EditorIcons")
};
Ref<Texture> cont_icon[4] = {
Ref<Texture2D> cont_icon[4] = {
get_icon("TrackContinuous", "EditorIcons"),
get_icon("TrackDiscrete", "EditorIcons"),
get_icon("TrackTrigger", "EditorIcons"),
@ -2068,7 +2068,7 @@ void AnimationTrackEdit::_notification(int p_what) {
int ofs = get_size().width - timeline->get_buttons_width();
Ref<Texture> down_icon = get_icon("select_arrow", "Tree");
Ref<Texture2D> down_icon = get_icon("select_arrow", "Tree");
draw_line(Point2(ofs, 0), Point2(ofs, get_size().height), linecolor, Math::round(EDSCALE));
@ -2084,7 +2084,7 @@ void AnimationTrackEdit::_notification(int p_what) {
update_mode = Animation::UPDATE_CONTINUOUS;
}
Ref<Texture> update_icon = cont_icon[update_mode];
Ref<Texture2D> update_icon = cont_icon[update_mode];
update_mode_rect.position.x = ofs;
update_mode_rect.position.y = int(get_size().height - update_icon->get_height()) / 2;
@ -2105,7 +2105,7 @@ void AnimationTrackEdit::_notification(int p_what) {
update_mode_rect.size.x += down_icon->get_width();
bezier_edit_rect = Rect2();
} else if (animation->track_get_type(track) == Animation::TYPE_BEZIER) {
Ref<Texture> bezier_icon = get_icon("EditBezier", "EditorIcons");
Ref<Texture2D> bezier_icon = get_icon("EditBezier", "EditorIcons");
update_mode_rect.size.x += down_icon->get_width();
bezier_edit_rect.position = update_mode_rect.position + (update_mode_rect.size - bezier_icon->get_size()) / 2;
bezier_edit_rect.size = bezier_icon->get_size();
@ -2126,7 +2126,7 @@ void AnimationTrackEdit::_notification(int p_what) {
Animation::InterpolationType interp_mode = animation->track_get_interpolation_type(track);
Ref<Texture> icon = interp_icon[interp_mode];
Ref<Texture2D> icon = interp_icon[interp_mode];
interp_mode_rect.position.x = ofs;
interp_mode_rect.position.y = int(get_size().height - icon->get_height()) / 2;
@ -2159,7 +2159,7 @@ void AnimationTrackEdit::_notification(int p_what) {
bool loop_wrap = animation->track_get_interpolation_loop_wrap(track);
Ref<Texture> icon = wrap_icon[loop_wrap ? 1 : 0];
Ref<Texture2D> icon = wrap_icon[loop_wrap ? 1 : 0];
loop_mode_rect.position.x = ofs;
loop_mode_rect.position.y = int(get_size().height - icon->get_height()) / 2;
@ -2190,7 +2190,7 @@ void AnimationTrackEdit::_notification(int p_what) {
{
//erase
Ref<Texture> icon = get_icon("Remove", "EditorIcons");
Ref<Texture2D> icon = get_icon("Remove", "EditorIcons");
remove_rect.position.x = ofs + ((get_size().width - ofs) - icon->get_width()) / 2;
remove_rect.position.y = int(get_size().height - icon->get_height()) / 2;
@ -2271,7 +2271,7 @@ void AnimationTrackEdit::draw_key(int p_index, float p_pixels_sec, int p_x, bool
if (p_x < p_clip_left || p_x > p_clip_right)
return;
Ref<Texture> icon_to_draw = p_selected ? selected_icon : type_icon;
Ref<Texture2D> icon_to_draw = p_selected ? selected_icon : type_icon;
// Override type icon for invalid value keys, unless selected.
if (!p_selected && animation->track_get_type(track) == Animation::TYPE_VALUE) {
@ -2335,12 +2335,12 @@ void AnimationTrackEdit::draw_bg(int p_clip_left, int p_clip_right) {
void AnimationTrackEdit::draw_fg(int p_clip_left, int p_clip_right) {
}
void AnimationTrackEdit::draw_texture_clipped(const Ref<Texture> &p_texture, const Vector2 &p_pos) {
void AnimationTrackEdit::draw_texture_clipped(const Ref<Texture2D> &p_texture, const Vector2 &p_pos) {
draw_texture_region_clipped(p_texture, Rect2(p_pos, p_texture->get_size()), Rect2(Point2(), p_texture->get_size()));
}
void AnimationTrackEdit::draw_texture_region_clipped(const Ref<Texture> &p_texture, const Rect2 &p_rect, const Rect2 &p_region) {
void AnimationTrackEdit::draw_texture_region_clipped(const Ref<Texture2D> &p_texture, const Rect2 &p_rect, const Rect2 &p_region) {
int clip_left = timeline->get_name_limit();
int clip_right = get_size().width - timeline->get_buttons_width();
@ -2391,7 +2391,7 @@ void AnimationTrackEdit::set_animation_and_track(const Ref<Animation> &p_animati
track = p_track;
update();
Ref<Texture> type_icons[6] = {
Ref<Texture2D> type_icons[6] = {
get_icon("KeyValue", "EditorIcons"),
get_icon("KeyXform", "EditorIcons"),
get_icon("KeyCall", "EditorIcons"),
@ -2413,7 +2413,7 @@ NodePath AnimationTrackEdit::get_path() const {
Size2 AnimationTrackEdit::get_minimum_size() const {
Ref<Texture> texture = get_icon("Object", "EditorIcons");
Ref<Texture2D> texture = get_icon("Object", "EditorIcons");
Ref<Font> font = get_font("font", "Label");
int separation = get_constant("vseparation", "ItemList");
@ -3199,7 +3199,7 @@ void AnimationTrackEditGroup::_notification(int p_what) {
}
}
void AnimationTrackEditGroup::set_type_and_name(const Ref<Texture> &p_type, const String &p_name, const NodePath &p_node) {
void AnimationTrackEditGroup::set_type_and_name(const Ref<Texture2D> &p_type, const String &p_name, const NodePath &p_node) {
icon = p_type;
node_name = p_name;
node = p_node;
@ -4214,7 +4214,7 @@ void AnimationTrackEditor::_update_tracks() {
if (!group_sort.has(base_path)) {
AnimationTrackEditGroup *g = memnew(AnimationTrackEditGroup);
Ref<Texture> icon = get_icon("Node", "EditorIcons");
Ref<Texture2D> icon = get_icon("Node", "EditorIcons");
String name = base_path;
String tooltip;
if (root && root->has_node(base_path)) {
@ -5273,7 +5273,7 @@ void AnimationTrackEditor::_edit_menu_pressed(int p_option) {
}
String text;
Ref<Texture> icon = get_icon("Node", "EditorIcons");
Ref<Texture2D> icon = get_icon("Node", "EditorIcons");
if (node) {
if (has_icon(node->get_class(), "EditorIcons")) {
icon = get_icon(node->get_class(), "EditorIcons");

View file

@ -158,8 +158,8 @@ class AnimationTrackEdit : public Control {
Rect2 remove_rect;
Rect2 bezier_edit_rect;
Ref<Texture> type_icon;
Ref<Texture> selected_icon;
Ref<Texture2D> type_icon;
Ref<Texture2D> selected_icon;
PopupMenu *menu;
@ -167,7 +167,7 @@ class AnimationTrackEdit : public Control {
void _zoom_changed();
Ref<Texture> icon_cache;
Ref<Texture2D> icon_cache;
String path_cache;
void _menu_selected(int p_index);
@ -208,8 +208,8 @@ public:
virtual void draw_fg(int p_clip_left, int p_clip_right);
//helper
void draw_texture_clipped(const Ref<Texture> &p_texture, const Vector2 &p_pos);
void draw_texture_region_clipped(const Ref<Texture> &p_texture, const Rect2 &p_rect, const Rect2 &p_region);
void draw_texture_clipped(const Ref<Texture2D> &p_texture, const Vector2 &p_pos);
void draw_texture_region_clipped(const Ref<Texture2D> &p_texture, const Rect2 &p_rect, const Rect2 &p_region);
void draw_rect_clipped(const Rect2 &p_rect, const Color &p_color, bool p_filled = true);
int get_track() const;
@ -251,7 +251,7 @@ class AnimationBezierTrackEdit;
class AnimationTrackEditGroup : public Control {
GDCLASS(AnimationTrackEditGroup, Control);
Ref<Texture> icon;
Ref<Texture2D> icon;
String node_name;
NodePath node;
Node *root;
@ -264,7 +264,7 @@ protected:
void _notification(int p_what);
public:
void set_type_and_name(const Ref<Texture> &p_type, const String &p_name, const NodePath &p_node);
void set_type_and_name(const Ref<Texture2D> &p_type, const String &p_name, const NodePath &p_node);
virtual Size2 get_minimum_size() const;
void set_timeline(AnimationTimelineEdit *p_timeline);
void set_root(Node *p_root);

View file

@ -42,12 +42,12 @@
/// BOOL ///
int AnimationTrackEditBool::get_key_height() const {
Ref<Texture> checked = get_icon("checked", "CheckBox");
Ref<Texture2D> checked = get_icon("checked", "CheckBox");
return checked->get_height();
}
Rect2 AnimationTrackEditBool::get_key_rect(int p_index, float p_pixels_sec) {
Ref<Texture> checked = get_icon("checked", "CheckBox");
Ref<Texture2D> checked = get_icon("checked", "CheckBox");
return Rect2(-checked->get_width() / 2, 0, checked->get_width(), get_size().height);
}
@ -58,7 +58,7 @@ bool AnimationTrackEditBool::is_key_selectable_by_distance() const {
void AnimationTrackEditBool::draw_key(int p_index, float p_pixels_sec, int p_x, bool p_selected, int p_clip_left, int p_clip_right) {
bool checked = get_animation()->track_get_key_value(get_track(), p_index);
Ref<Texture> icon = get_icon(checked ? "checked" : "unchecked", "CheckBox");
Ref<Texture2D> icon = get_icon(checked ? "checked" : "unchecked", "CheckBox");
Vector2 ofs(p_x - icon->get_width() / 2, int(get_size().height - icon->get_height()) / 2);
@ -360,7 +360,7 @@ Rect2 AnimationTrackEditSpriteFrame::get_key_rect(int p_index, float p_pixels_se
if (Object::cast_to<Sprite>(object) || Object::cast_to<Sprite3D>(object)) {
Ref<Texture> texture = object->call("get_texture");
Ref<Texture2D> texture = object->call("get_texture");
if (!texture.is_valid()) {
return AnimationTrackEdit::get_key_rect(p_index, p_pixels_sec);
}
@ -404,7 +404,7 @@ Rect2 AnimationTrackEditSpriteFrame::get_key_rect(int p_index, float p_pixels_se
animation = get_animation()->track_get_key_value(animation_track, animaiton_index);
}
Ref<Texture> texture = sf->get_frame(animation, frame);
Ref<Texture2D> texture = sf->get_frame(animation, frame);
if (!texture.is_valid()) {
return AnimationTrackEdit::get_key_rect(p_index, p_pixels_sec);
}
@ -434,7 +434,7 @@ void AnimationTrackEditSpriteFrame::draw_key(int p_index, float p_pixels_sec, in
return;
}
Ref<Texture> texture;
Ref<Texture2D> texture;
Rect2 region;
if (Object::cast_to<Sprite>(object) || Object::cast_to<Sprite3D>(object)) {
@ -710,13 +710,13 @@ void AnimationTrackEditSubAnim::set_node(Object *p_object) {
int AnimationTrackEditVolumeDB::get_key_height() const {
Ref<Texture> volume_texture = get_icon("ColorTrackVu", "EditorIcons");
Ref<Texture2D> volume_texture = get_icon("ColorTrackVu", "EditorIcons");
return volume_texture->get_height() * 1.2;
}
void AnimationTrackEditVolumeDB::draw_bg(int p_clip_left, int p_clip_right) {
Ref<Texture> volume_texture = get_icon("ColorTrackVu", "EditorIcons");
Ref<Texture2D> volume_texture = get_icon("ColorTrackVu", "EditorIcons");
int tex_h = volume_texture->get_height();
int y_from = (get_size().height - tex_h) / 2;
@ -728,7 +728,7 @@ void AnimationTrackEditVolumeDB::draw_bg(int p_clip_left, int p_clip_right) {
void AnimationTrackEditVolumeDB::draw_fg(int p_clip_left, int p_clip_right) {
Ref<Texture> volume_texture = get_icon("ColorTrackVu", "EditorIcons");
Ref<Texture2D> volume_texture = get_icon("ColorTrackVu", "EditorIcons");
int tex_h = volume_texture->get_height();
int y_from = (get_size().height - tex_h) / 2;
int db0 = y_from + (24 / 80.0) * tex_h;
@ -763,7 +763,7 @@ void AnimationTrackEditVolumeDB::draw_key_link(int p_index, float p_pixels_sec,
to_x = p_clip_right;
}
Ref<Texture> volume_texture = get_icon("ColorTrackVu", "EditorIcons");
Ref<Texture2D> volume_texture = get_icon("ColorTrackVu", "EditorIcons");
int tex_h = volume_texture->get_height();
int y_from = (get_size().height - tex_h) / 2;

View file

@ -35,8 +35,8 @@
class AnimationTrackEditBool : public AnimationTrackEdit {
GDCLASS(AnimationTrackEditBool, AnimationTrackEdit);
Ref<Texture> icon_checked;
Ref<Texture> icon_unchecked;
Ref<Texture2D> icon_checked;
Ref<Texture2D> icon_unchecked;
public:
virtual int get_key_height() const;

View file

@ -819,8 +819,8 @@ void CodeTextEditor::_complete_request() {
text_editor->code_complete(entries, forced);
}
Ref<Texture> CodeTextEditor::_get_completion_icon(const ScriptCodeCompletionOption &p_option) {
Ref<Texture> tex;
Ref<Texture2D> CodeTextEditor::_get_completion_icon(const ScriptCodeCompletionOption &p_option) {
Ref<Texture2D> tex;
switch (p_option.kind) {
case ScriptCodeCompletionOption::KIND_CLASS: {
if (has_icon(p_option.display, "EditorIcons")) {

View file

@ -167,7 +167,7 @@ class CodeTextEditor : public VBoxContainer {
void _update_font();
void _complete_request();
Ref<Texture> _get_completion_icon(const ScriptCodeCompletionOption &p_option);
Ref<Texture2D> _get_completion_icon(const ScriptCodeCompletionOption &p_option);
void _font_resize_timeout();
bool _add_font_size(int p_delta);

View file

@ -903,7 +903,7 @@ void ConnectionsDock::update_tree() {
while (base) {
List<MethodInfo> node_signals2;
Ref<Texture> icon;
Ref<Texture2D> icon;
String name;
if (!did_script) {

View file

@ -77,7 +77,7 @@ class CreateDialog : public ConfirmationDialog {
void _confirmed();
void _text_changed(const String &p_newtext);
Ref<Texture> _get_editor_icon(const String &p_type) const;
Ref<Texture2D> _get_editor_icon(const String &p_type) const;
void add_type(const String &p_type, HashMap<String, TreeItem *> &p_types, TreeItem *p_root, TreeItem **to_select);

View file

@ -174,7 +174,7 @@ void DependencyEditor::_update_list() {
TreeItem *root = tree->create_item();
Ref<Texture> folder = get_icon("folder", "FileDialog");
Ref<Texture2D> folder = get_icon("folder", "FileDialog");
bool broken = false;
@ -195,7 +195,7 @@ void DependencyEditor::_update_list() {
}
String name = path.get_file();
Ref<Texture> icon = EditorNode::get_singleton()->get_class_icon(type);
Ref<Texture2D> icon = EditorNode::get_singleton()->get_class_icon(type);
item->set_text(0, name);
item->set_icon(0, icon);
item->set_metadata(0, type);
@ -338,7 +338,7 @@ void DependencyEditorOwners::_fill_owners(EditorFileSystemDirectory *efsd) {
if (!found)
continue;
Ref<Texture> icon = EditorNode::get_singleton()->get_class_icon(efsd->get_file_type(i));
Ref<Texture2D> icon = EditorNode::get_singleton()->get_class_icon(efsd->get_file_type(i));
owners->add_item(efsd->get_file_path(i), icon);
}
@ -446,7 +446,7 @@ void DependencyRemoveDialog::_build_removed_dependency_tree(const Vector<Removed
}
//List this file under this dependency
Ref<Texture> icon = EditorNode::get_singleton()->get_class_icon(rd.file_type);
Ref<Texture2D> icon = EditorNode::get_singleton()->get_class_icon(rd.file_type);
TreeItem *file_item = owners->create_item(tree_items[rd.dependency]);
file_item->set_text(0, rd.file);
file_item->set_icon(0, icon);
@ -609,7 +609,7 @@ void DependencyErrorDialog::show(Mode p_mode, const String &p_for_file, const Ve
if (report[i].get_slice_count("::") > 0)
type = report[i].get_slice("::", 1);
Ref<Texture> icon = EditorNode::get_singleton()->get_class_icon(type);
Ref<Texture2D> icon = EditorNode::get_singleton()->get_class_icon(type);
TreeItem *ti = files->create_item(root);
ti->set_text(0, dep);
@ -720,7 +720,7 @@ bool OrphanResourcesDialog::_fill_owners(EditorFileSystemDirectory *efsd, HashMa
String type = efsd->get_file_type(i);
Ref<Texture> icon = EditorNode::get_singleton()->get_class_icon(type);
Ref<Texture2D> icon = EditorNode::get_singleton()->get_class_icon(type);
ti->set_icon(0, icon);
int ds = efsd->get_file_deps(i).size();
ti->set_text(1, itos(ds));

View file

@ -304,6 +304,8 @@ void DocData::generate(bool p_basic_types) {
}
}
//used to track uninitialized values using valgrind
//print_line("getting default value for " + String(name) + "." + String(E->get().name));
if (default_value_valid && default_value.get_type() != Variant::OBJECT) {
prop.default_value = default_value.get_construct_string().replace("\n", "");
}
@ -483,7 +485,7 @@ void DocData::generate(bool p_basic_types) {
PropertyDoc pd;
pd.name = E->get();
pd.type = "Texture";
pd.type = "Texture2D";
c.theme_properties.push_back(pd);
}
l.clear();

View file

@ -110,7 +110,7 @@ void EditorAssetInstaller::open(const String &p_path, int p_depth) {
ret = unzGoToNextFile(pkg);
}
Map<String, Ref<Texture> > extension_guess;
Map<String, Ref<Texture2D> > extension_guess;
{
extension_guess["png"] = get_icon("ImageTexture", "EditorIcons");
extension_guess["jpg"] = get_icon("ImageTexture", "EditorIcons");
@ -122,7 +122,7 @@ void EditorAssetInstaller::open(const String &p_path, int p_depth) {
extension_guess["vs"] = get_icon("VisualScript", "EditorIcons");
}
Ref<Texture> generic_extension = get_icon("Object", "EditorIcons");
Ref<Texture2D> generic_extension = get_icon("Object", "EditorIcons");
unzClose(pkg);

View file

@ -144,8 +144,8 @@ void EditorAudioBus::_notification(int p_what) {
if (activity_found != channel[i].prev_active) {
if (activity_found) {
channel[i].vu_l->set_over_texture(Ref<Texture>());
channel[i].vu_r->set_over_texture(Ref<Texture>());
channel[i].vu_l->set_over_texture(Ref<Texture2D>());
channel[i].vu_r->set_over_texture(Ref<Texture2D>());
} else {
channel[i].vu_l->set_over_texture(disabled_vu);
channel[i].vu_r->set_over_texture(disabled_vu);
@ -944,7 +944,7 @@ EditorAudioBus::EditorAudioBus(EditorAudioBuses *p_buses, bool p_is_master) {
if (!ClassDB::can_instance(E->get()))
continue;
Ref<Texture> icon = EditorNode::get_singleton()->get_class_icon(E->get());
Ref<Texture2D> icon = EditorNode::get_singleton()->get_class_icon(E->get());
String name = E->get().operator String().replace("AudioEffect", "");
effect_options->add_item(name);
effect_options->set_item_metadata(effect_options->get_item_count() - 1, E->get());

View file

@ -54,7 +54,7 @@ class EditorAudioBus : public PanelContainer {
GDCLASS(EditorAudioBus, PanelContainer);
Ref<Texture> disabled_vu;
Ref<Texture2D> disabled_vu;
LineEdit *track_name;
MenuButton *bus_options;
VSlider *slider;

View file

@ -479,7 +479,7 @@ EditorPlugin *EditorData::get_editor_plugin(int p_idx) {
return editor_plugins[p_idx];
}
void EditorData::add_custom_type(const String &p_type, const String &p_inherits, const Ref<Script> &p_script, const Ref<Texture> &p_icon) {
void EditorData::add_custom_type(const String &p_type, const String &p_inherits, const Ref<Script> &p_script, const Ref<Texture2D> &p_icon) {
ERR_FAIL_COND_MSG(p_script.is_null(), "It's not a reference to a valid Script object.");
CustomType ct;

View file

@ -112,7 +112,7 @@ public:
String name;
Ref<Script> script;
Ref<Texture> icon;
Ref<Texture2D> icon;
};
struct EditedScene {
@ -178,7 +178,7 @@ public:
void save_editor_global_states();
void restore_editor_global_states();
void add_custom_type(const String &p_type, const String &p_inherits, const Ref<Script> &p_script, const Ref<Texture> &p_icon);
void add_custom_type(const String &p_type, const String &p_inherits, const Ref<Script> &p_script, const Ref<Texture2D> &p_icon);
Object *instance_custom_type(const String &p_type, const String &p_inherits);
void remove_custom_type(const String &p_type);
const Map<String, Vector<CustomType> > &get_custom_types() const { return custom_types; }

View file

@ -1477,7 +1477,7 @@ String EditorExportPlatformPC::get_os_name() const {
return os_name;
}
Ref<Texture> EditorExportPlatformPC::get_logo() const {
Ref<Texture2D> EditorExportPlatformPC::get_logo() const {
return logo;
}
@ -1629,7 +1629,7 @@ void EditorExportPlatformPC::set_os_name(const String &p_name) {
os_name = p_name;
}
void EditorExportPlatformPC::set_logo(const Ref<Texture> &p_logo) {
void EditorExportPlatformPC::set_logo(const Ref<Texture2D> &p_logo) {
logo = p_logo;
}

View file

@ -236,7 +236,7 @@ public:
virtual String get_os_name() const = 0;
virtual String get_name() const = 0;
virtual Ref<Texture> get_logo() const = 0;
virtual Ref<Texture2D> get_logo() const = 0;
Error export_project_files(const Ref<EditorExportPreset> &p_preset, EditorExportSaveFunction p_func, void *p_udata, EditorExportSaveSharedObject p_so_func = NULL);
@ -259,7 +259,7 @@ public:
};
virtual Error run(const Ref<EditorExportPreset> &p_preset, int p_device, int p_debug_flags) { return OK; }
virtual Ref<Texture> get_run_icon() const { return get_logo(); }
virtual Ref<Texture2D> get_run_icon() const { return get_logo(); }
String test_etc2() const; //generic test for etc2 since most platforms use it
virtual bool can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const = 0;
@ -420,7 +420,7 @@ public:
virtual String get_name() const;
virtual String get_os_name() const;
virtual Ref<Texture> get_logo() const;
virtual Ref<Texture2D> get_logo() const;
virtual bool can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const;
virtual List<String> get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const;
@ -431,7 +431,7 @@ public:
void set_name(const String &p_name);
void set_os_name(const String &p_name);
void set_logo(const Ref<Texture> &p_logo);
void set_logo(const Ref<Texture2D> &p_logo);
void set_release_64(const String &p_file);
void set_release_32(const String &p_file);

View file

@ -78,7 +78,7 @@ void EditorFileDialog::_notification(int p_what) {
preview_wheel_index++;
if (preview_wheel_index >= 8)
preview_wheel_index = 0;
Ref<Texture> frame = get_icon("Progress" + itos(preview_wheel_index + 1), "EditorIcons");
Ref<Texture2D> frame = get_icon("Progress" + itos(preview_wheel_index + 1), "EditorIcons");
preview->set_texture(frame);
preview_wheel_timeout = 0.1;
}
@ -263,7 +263,7 @@ void EditorFileDialog::_post_popup() {
_request_single_thumbnail(get_current_dir().plus_file(get_current_file()));
if (is_visible_in_tree()) {
Ref<Texture> folder = get_icon("folder", "FileDialog");
Ref<Texture2D> folder = get_icon("folder", "FileDialog");
const Color folder_color = get_color("folder_icon_modulate", "FileDialog");
recent->clear();
@ -295,7 +295,7 @@ void EditorFileDialog::_post_popup() {
set_process_unhandled_input(true);
}
void EditorFileDialog::_thumbnail_result(const String &p_path, const Ref<Texture> &p_preview, const Ref<Texture> &p_small_preview, const Variant &p_udata) {
void EditorFileDialog::_thumbnail_result(const String &p_path, const Ref<Texture2D> &p_preview, const Ref<Texture2D> &p_small_preview, const Variant &p_udata) {
if (display_mode == DISPLAY_LIST || p_preview.is_null())
return;
@ -305,12 +305,12 @@ void EditorFileDialog::_thumbnail_result(const String &p_path, const Ref<Texture
String pname = d["path"];
if (pname == p_path) {
item_list->set_item_icon(i, p_preview);
item_list->set_item_tag_icon(i, Ref<Texture>());
item_list->set_item_tag_icon(i, Ref<Texture2D>());
}
}
}
void EditorFileDialog::_thumbnail_done(const String &p_path, const Ref<Texture> &p_preview, const Ref<Texture> &p_small_preview, const Variant &p_udata) {
void EditorFileDialog::_thumbnail_done(const String &p_path, const Ref<Texture2D> &p_preview, const Ref<Texture2D> &p_small_preview, const Variant &p_udata) {
set_process(false);
preview_waiting = false;
@ -326,7 +326,7 @@ void EditorFileDialog::_thumbnail_done(const String &p_path, const Ref<Texture>
} else {
preview_vb->hide();
preview->set_texture(Ref<Texture>());
preview->set_texture(Ref<Texture2D>());
}
}
@ -704,8 +704,8 @@ void EditorFileDialog::update_file_list() {
int thumbnail_size = EditorSettings::get_singleton()->get("filesystem/file_dialog/thumbnail_size");
thumbnail_size *= EDSCALE;
Ref<Texture> folder_thumbnail;
Ref<Texture> file_thumbnail;
Ref<Texture2D> folder_thumbnail;
Ref<Texture2D> file_thumbnail;
item_list->clear();
@ -745,7 +745,7 @@ void EditorFileDialog::update_file_list() {
dir_access->list_dir_begin();
Ref<Texture> folder = get_icon("folder", "FileDialog");
Ref<Texture2D> folder = get_icon("folder", "FileDialog");
const Color folder_color = get_color("folder_icon_modulate", "FileDialog");
List<String> files;
List<String> dirs;
@ -841,7 +841,7 @@ void EditorFileDialog::update_file_list() {
if (get_icon_func) {
Ref<Texture> icon = get_icon_func(cdir.plus_file(files.front()->get()));
Ref<Texture2D> icon = get_icon_func(cdir.plus_file(files.front()->get()));
if (display_mode == DISPLAY_THUMBNAILS) {
item_list->set_item_icon(item_list->get_item_count() - 1, file_thumbnail);
@ -1215,7 +1215,7 @@ void EditorFileDialog::_update_favorites() {
bool res = access == ACCESS_RESOURCES;
String current = get_current_dir();
Ref<Texture> folder_icon = get_icon("Folder", "EditorIcons");
Ref<Texture2D> folder_icon = get_icon("Folder", "EditorIcons");
const Color folder_color = get_color("folder_icon_modulate", "FileDialog");
favorites->clear();

View file

@ -68,7 +68,7 @@ public:
MODE_SAVE_FILE
};
typedef Ref<Texture> (*GetIconFunc)(const String &);
typedef Ref<Texture2D> (*GetIconFunc)(const String &);
typedef void (*RegisterFunc)(EditorFileDialog *);
static GetIconFunc get_icon_func;
@ -188,10 +188,10 @@ private:
virtual void _post_popup();
void _save_to_recent();
//callback function is callback(String p_path,Ref<Texture> preview,Variant udata) preview null if could not load
//callback function is callback(String p_path,Ref<Texture2D> preview,Variant udata) preview null if could not load
void _thumbnail_result(const String &p_path, const Ref<Texture> &p_preview, const Ref<Texture> &p_small_preview, const Variant &p_udata);
void _thumbnail_done(const String &p_path, const Ref<Texture> &p_preview, const Ref<Texture> &p_small_preview, const Variant &p_udata);
void _thumbnail_result(const String &p_path, const Ref<Texture2D> &p_preview, const Ref<Texture2D> &p_small_preview, const Variant &p_udata);
void _thumbnail_done(const String &p_path, const Ref<Texture2D> &p_preview, const Ref<Texture2D> &p_small_preview, const Variant &p_udata);
void _request_single_thumbnail(const String &p_path);
void _unhandled_input(const Ref<InputEvent> &p_event);

View file

@ -1374,7 +1374,7 @@ static void _add_text_to_rt(const String &p_bbcode, RichTextLabel *p_rt) {
end = bbcode.length();
String image = bbcode.substr(brk_end + 1, end - brk_end - 1);
Ref<Texture> texture = ResourceLoader::load(base_path.plus_file(image), "Texture");
Ref<Texture2D> texture = ResourceLoader::load(base_path.plus_file(image), "Texture2D");
if (texture.is_valid())
p_rt->add_image(texture);

View file

@ -483,7 +483,7 @@ TreeItem *EditorHelpSearch::Runner::_create_class_hierarchy(const ClassMatch &p_
TreeItem *EditorHelpSearch::Runner::_create_class_item(TreeItem *p_parent, const DocData::ClassDoc *p_doc, bool p_gray) {
Ref<Texture> icon = empty_icon;
Ref<Texture2D> icon = empty_icon;
if (ui_service->has_icon(p_doc->name, "EditorIcons"))
icon = ui_service->get_icon(p_doc->name, "EditorIcons");
else if (ClassDB::class_exists(p_doc->name) && ClassDB::is_parent_class(p_doc->name, "Object"))
@ -559,7 +559,7 @@ TreeItem *EditorHelpSearch::Runner::_create_theme_property_item(TreeItem *p_pare
TreeItem *EditorHelpSearch::Runner::_create_member_item(TreeItem *p_parent, const String &p_class_name, const String &p_icon, const String &p_name, const String &p_type, const String &p_metatype, const String &p_tooltip) {
Ref<Texture> icon;
Ref<Texture2D> icon;
String text;
if (search_flags & SEARCH_SHOW_HIERARCHY) {
icon = ui_service->get_icon(p_icon, "EditorIcons");

Some files were not shown because too many files have changed in this diff Show more