diff options
Diffstat (limited to 'drivers')
59 files changed, 2273 insertions, 1780 deletions
diff --git a/drivers/SCsub b/drivers/SCsub index 41c20d81ad..cc7bcbc640 100644 --- a/drivers/SCsub +++ b/drivers/SCsub @@ -1,41 +1,42 @@ #!/usr/bin/env python -Import('env') +Import("env") env.drivers_sources = [] # OS drivers -SConscript('unix/SCsub') -SConscript('windows/SCsub') +SConscript("unix/SCsub") +SConscript("windows/SCsub") # Sounds drivers -SConscript('alsa/SCsub') -SConscript('coreaudio/SCsub') -SConscript('pulseaudio/SCsub') -if (env["platform"] == "windows"): +SConscript("alsa/SCsub") +SConscript("coreaudio/SCsub") +SConscript("pulseaudio/SCsub") +if env["platform"] == "windows": SConscript("wasapi/SCsub") -if env['xaudio2']: +if env["xaudio2"]: SConscript("xaudio2/SCsub") # Midi drivers -SConscript('alsamidi/SCsub') -SConscript('coremidi/SCsub') -SConscript('winmidi/SCsub') +SConscript("alsamidi/SCsub") +SConscript("coremidi/SCsub") +SConscript("winmidi/SCsub") # Graphics drivers -if (env["platform"] != "server" and env["platform"] != "javascript"): -# SConscript('gles2/SCsub') - SConscript('vulkan/SCsub') - SConscript('gl_context/SCsub') +if env["platform"] != "server" and env["platform"] != "javascript": + # SConscript('gles2/SCsub') + SConscript("vulkan/SCsub") + SConscript("gl_context/SCsub") else: - SConscript('dummy/SCsub') + SConscript("dummy/SCsub") # Core dependencies SConscript("png/SCsub") SConscript("spirv-reflect/SCsub") -if env['vsproj']: +if env["vsproj"]: import os + path = os.getcwd() # Change directory so the path resolves correctly in the function call. os.chdir("..") diff --git a/drivers/alsa/SCsub b/drivers/alsa/SCsub index 28b315ae66..91e1140b75 100644 --- a/drivers/alsa/SCsub +++ b/drivers/alsa/SCsub @@ -1,5 +1,5 @@ #!/usr/bin/env python -Import('env') +Import("env") env.add_source_files(env.drivers_sources, "*.cpp") diff --git a/drivers/alsa/audio_driver_alsa.cpp b/drivers/alsa/audio_driver_alsa.cpp index 400ce31bf7..48e694dd3a 100644 --- a/drivers/alsa/audio_driver_alsa.cpp +++ b/drivers/alsa/audio_driver_alsa.cpp @@ -60,7 +60,7 @@ Error AudioDriverALSA::init_device() { fprintf(stderr, "ALSA ERR: %s\n", snd_strerror(status)); \ if (pcm_handle) { \ snd_pcm_close(pcm_handle); \ - pcm_handle = NULL; \ + pcm_handle = nullptr; \ } \ ERR_FAIL_COND_V(m_cond, ERR_CANT_OPEN); \ } @@ -98,7 +98,7 @@ Error AudioDriverALSA::init_device() { status = snd_pcm_hw_params_set_channels(pcm_handle, hwparams, 2); CHECK_FAIL(status < 0); - status = snd_pcm_hw_params_set_rate_near(pcm_handle, hwparams, &mix_rate, NULL); + status = snd_pcm_hw_params_set_rate_near(pcm_handle, hwparams, &mix_rate, nullptr); CHECK_FAIL(status < 0); // In ALSA the period size seems to be the one that will determine the actual latency @@ -113,12 +113,12 @@ Error AudioDriverALSA::init_device() { status = snd_pcm_hw_params_set_buffer_size_near(pcm_handle, hwparams, &buffer_size); CHECK_FAIL(status < 0); - status = snd_pcm_hw_params_set_period_size_near(pcm_handle, hwparams, &period_size, NULL); + status = snd_pcm_hw_params_set_period_size_near(pcm_handle, hwparams, &period_size, nullptr); CHECK_FAIL(status < 0); print_verbose("Audio buffer frames: " + itos(period_size) + " calculated latency: " + itos(period_size * 1000 / mix_rate) + "ms"); - status = snd_pcm_hw_params_set_periods_near(pcm_handle, hwparams, &periods, NULL); + status = snd_pcm_hw_params_set_periods_near(pcm_handle, hwparams, &periods, nullptr); CHECK_FAIL(status < 0); status = snd_pcm_hw_params(pcm_handle, hwparams); @@ -262,11 +262,11 @@ Array AudioDriverALSA::get_device_list() { if (snd_device_name_hint(-1, "pcm", &hints) < 0) return list; - for (void **n = hints; *n != NULL; n++) { + for (void **n = hints; *n != nullptr; n++) { char *name = snd_device_name_get_hint(*n, "NAME"); char *desc = snd_device_name_get_hint(*n, "DESC"); - if (name != NULL && !strncmp(name, "plughw", 6)) { + if (name != nullptr && !strncmp(name, "plughw", 6)) { if (desc) { list.push_back(String(name) + ";" + String(desc)); } else { @@ -274,9 +274,9 @@ Array AudioDriverALSA::get_device_list() { } } - if (desc != NULL) + if (desc != nullptr) free(desc); - if (name != NULL) + if (name != nullptr) free(name); } snd_device_name_free_hint(hints); @@ -314,7 +314,7 @@ void AudioDriverALSA::finish_device() { if (pcm_handle) { snd_pcm_close(pcm_handle); - pcm_handle = NULL; + pcm_handle = nullptr; } } @@ -325,15 +325,15 @@ void AudioDriverALSA::finish() { Thread::wait_to_finish(thread); memdelete(thread); - thread = NULL; + thread = nullptr; } finish_device(); } AudioDriverALSA::AudioDriverALSA() : - thread(NULL), - pcm_handle(NULL), + thread(nullptr), + pcm_handle(nullptr), device_name("Default"), new_device("Default") { } diff --git a/drivers/alsamidi/SCsub b/drivers/alsamidi/SCsub index 4c24925192..4e1b5f2a36 100644 --- a/drivers/alsamidi/SCsub +++ b/drivers/alsamidi/SCsub @@ -1,6 +1,6 @@ #!/usr/bin/env python -Import('env') +Import("env") # Driver source files env.add_source_files(env.drivers_sources, "*.cpp") diff --git a/drivers/alsamidi/midi_driver_alsamidi.cpp b/drivers/alsamidi/midi_driver_alsamidi.cpp index 0cecf1de3e..e3e54ea267 100644 --- a/drivers/alsamidi/midi_driver_alsamidi.cpp +++ b/drivers/alsamidi/midi_driver_alsamidi.cpp @@ -132,18 +132,18 @@ Error MIDIDriverALSAMidi::open() { return ERR_CANT_OPEN; int i = 0; - for (void **n = hints; *n != NULL; n++) { + for (void **n = hints; *n != nullptr; n++) { char *name = snd_device_name_get_hint(*n, "NAME"); - if (name != NULL) { + if (name != nullptr) { snd_rawmidi_t *midi_in; - int ret = snd_rawmidi_open(&midi_in, NULL, name, SND_RAWMIDI_NONBLOCK); + int ret = snd_rawmidi_open(&midi_in, nullptr, name, SND_RAWMIDI_NONBLOCK); if (ret >= 0) { connected_inputs.insert(i++, midi_in); } } - if (name != NULL) + if (name != nullptr) free(name); } snd_device_name_free_hint(hints); @@ -161,7 +161,7 @@ void MIDIDriverALSAMidi::close() { Thread::wait_to_finish(thread); memdelete(thread); - thread = NULL; + thread = nullptr; } for (int i = 0; i < connected_inputs.size(); i++) { @@ -202,7 +202,7 @@ PackedStringArray MIDIDriverALSAMidi::get_connected_inputs() { MIDIDriverALSAMidi::MIDIDriverALSAMidi() { - thread = NULL; + thread = nullptr; exit_thread = false; } diff --git a/drivers/coreaudio/SCsub b/drivers/coreaudio/SCsub index 4c24925192..4e1b5f2a36 100644 --- a/drivers/coreaudio/SCsub +++ b/drivers/coreaudio/SCsub @@ -1,6 +1,6 @@ #!/usr/bin/env python -Import('env') +Import("env") # Driver source files env.add_source_files(env.drivers_sources, "*.cpp") diff --git a/drivers/coreaudio/audio_driver_coreaudio.cpp b/drivers/coreaudio/audio_driver_coreaudio.cpp index 1e95bcf5d9..21c3649445 100644 --- a/drivers/coreaudio/audio_driver_coreaudio.cpp +++ b/drivers/coreaudio/audio_driver_coreaudio.cpp @@ -79,8 +79,8 @@ Error AudioDriverCoreAudio::init() { #endif desc.componentManufacturer = kAudioUnitManufacturer_Apple; - AudioComponent comp = AudioComponentFindNext(NULL, &desc); - ERR_FAIL_COND_V(comp == NULL, FAILED); + AudioComponent comp = AudioComponentFindNext(nullptr, &desc); + ERR_FAIL_COND_V(comp == nullptr, FAILED); OSStatus result = AudioComponentInstanceNew(comp, &audio_unit); ERR_FAIL_COND_V(result != noErr, FAILED); @@ -335,7 +335,7 @@ void AudioDriverCoreAudio::finish() { ERR_PRINT("AudioComponentInstanceDispose failed"); } - audio_unit = NULL; + audio_unit = nullptr; unlock(); } } @@ -351,8 +351,8 @@ Error AudioDriverCoreAudio::capture_init() { #endif desc.componentManufacturer = kAudioUnitManufacturer_Apple; - AudioComponent comp = AudioComponentFindNext(NULL, &desc); - ERR_FAIL_COND_V(comp == NULL, FAILED); + AudioComponent comp = AudioComponentFindNext(nullptr, &desc); + ERR_FAIL_COND_V(comp == nullptr, FAILED); OSStatus result = AudioComponentInstanceNew(comp, &input_unit); ERR_FAIL_COND_V(result != noErr, FAILED); @@ -380,7 +380,7 @@ Error AudioDriverCoreAudio::capture_init() { size = sizeof(AudioDeviceID); AudioObjectPropertyAddress property = { kAudioHardwarePropertyDefaultInputDevice, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMaster }; - result = AudioObjectGetPropertyData(kAudioObjectSystemObject, &property, 0, NULL, &size, &deviceId); + result = AudioObjectGetPropertyData(kAudioObjectSystemObject, &property, 0, nullptr, &size, &deviceId); ERR_FAIL_COND_V(result != noErr, FAILED); result = AudioUnitSetProperty(input_unit, kAudioOutputUnitProperty_CurrentDevice, kAudioUnitScope_Global, 0, &deviceId, sizeof(AudioDeviceID)); @@ -469,7 +469,7 @@ void AudioDriverCoreAudio::capture_finish() { ERR_PRINT("AudioComponentInstanceDispose failed"); } - input_unit = NULL; + input_unit = nullptr; unlock(); } } @@ -513,18 +513,18 @@ Array AudioDriverCoreAudio::_get_device_list(bool capture) { prop.mElement = kAudioObjectPropertyElementMaster; UInt32 size = 0; - AudioObjectGetPropertyDataSize(kAudioObjectSystemObject, &prop, 0, NULL, &size); + AudioObjectGetPropertyDataSize(kAudioObjectSystemObject, &prop, 0, nullptr, &size); AudioDeviceID *audioDevices = (AudioDeviceID *)malloc(size); - AudioObjectGetPropertyData(kAudioObjectSystemObject, &prop, 0, NULL, &size, audioDevices); + AudioObjectGetPropertyData(kAudioObjectSystemObject, &prop, 0, nullptr, &size, audioDevices); UInt32 deviceCount = size / sizeof(AudioDeviceID); for (UInt32 i = 0; i < deviceCount; i++) { prop.mScope = capture ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput; prop.mSelector = kAudioDevicePropertyStreamConfiguration; - AudioObjectGetPropertyDataSize(audioDevices[i], &prop, 0, NULL, &size); + AudioObjectGetPropertyDataSize(audioDevices[i], &prop, 0, nullptr, &size); AudioBufferList *bufferList = (AudioBufferList *)malloc(size); - AudioObjectGetPropertyData(audioDevices[i], &prop, 0, NULL, &size, bufferList); + AudioObjectGetPropertyData(audioDevices[i], &prop, 0, nullptr, &size, bufferList); UInt32 channelCount = 0; for (UInt32 j = 0; j < bufferList->mNumberBuffers; j++) @@ -538,7 +538,7 @@ Array AudioDriverCoreAudio::_get_device_list(bool capture) { size = sizeof(CFStringRef); prop.mSelector = kAudioObjectPropertyName; - AudioObjectGetPropertyData(audioDevices[i], &prop, 0, NULL, &size, &cfname); + AudioObjectGetPropertyData(audioDevices[i], &prop, 0, nullptr, &size, &cfname); CFIndex length = CFStringGetLength(cfname); CFIndex maxSize = CFStringGetMaximumSizeForEncoding(length, kCFStringEncodingUTF8) + 1; @@ -569,18 +569,18 @@ void AudioDriverCoreAudio::_set_device(const String &device, bool capture) { prop.mElement = kAudioObjectPropertyElementMaster; UInt32 size = 0; - AudioObjectGetPropertyDataSize(kAudioObjectSystemObject, &prop, 0, NULL, &size); + AudioObjectGetPropertyDataSize(kAudioObjectSystemObject, &prop, 0, nullptr, &size); AudioDeviceID *audioDevices = (AudioDeviceID *)malloc(size); - AudioObjectGetPropertyData(kAudioObjectSystemObject, &prop, 0, NULL, &size, audioDevices); + AudioObjectGetPropertyData(kAudioObjectSystemObject, &prop, 0, nullptr, &size, audioDevices); UInt32 deviceCount = size / sizeof(AudioDeviceID); for (UInt32 i = 0; i < deviceCount && !found; i++) { prop.mScope = capture ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput; prop.mSelector = kAudioDevicePropertyStreamConfiguration; - AudioObjectGetPropertyDataSize(audioDevices[i], &prop, 0, NULL, &size); + AudioObjectGetPropertyDataSize(audioDevices[i], &prop, 0, nullptr, &size); AudioBufferList *bufferList = (AudioBufferList *)malloc(size); - AudioObjectGetPropertyData(audioDevices[i], &prop, 0, NULL, &size, bufferList); + AudioObjectGetPropertyData(audioDevices[i], &prop, 0, nullptr, &size, bufferList); UInt32 channelCount = 0; for (UInt32 j = 0; j < bufferList->mNumberBuffers; j++) @@ -594,7 +594,7 @@ void AudioDriverCoreAudio::_set_device(const String &device, bool capture) { size = sizeof(CFStringRef); prop.mSelector = kAudioObjectPropertyName; - AudioObjectGetPropertyData(audioDevices[i], &prop, 0, NULL, &size, &cfname); + AudioObjectGetPropertyData(audioDevices[i], &prop, 0, nullptr, &size, &cfname); CFIndex length = CFStringGetLength(cfname); CFIndex maxSize = CFStringGetMaximumSizeForEncoding(length, kCFStringEncodingUTF8) + 1; @@ -620,7 +620,7 @@ void AudioDriverCoreAudio::_set_device(const String &device, bool capture) { UInt32 elem = capture ? kAudioHardwarePropertyDefaultInputDevice : kAudioHardwarePropertyDefaultOutputDevice; AudioObjectPropertyAddress property = { elem, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMaster }; - OSStatus result = AudioObjectGetPropertyData(kAudioObjectSystemObject, &property, 0, NULL, &size, &deviceId); + OSStatus result = AudioObjectGetPropertyData(kAudioObjectSystemObject, &property, 0, nullptr, &size, &deviceId); ERR_FAIL_COND(result != noErr); found = true; @@ -677,8 +677,8 @@ String AudioDriverCoreAudio::capture_get_device() { #endif AudioDriverCoreAudio::AudioDriverCoreAudio() : - audio_unit(NULL), - input_unit(NULL), + audio_unit(nullptr), + input_unit(nullptr), active(false), device_name("Default"), capture_device_name("Default"), diff --git a/drivers/coremidi/SCsub b/drivers/coremidi/SCsub index 4c24925192..4e1b5f2a36 100644 --- a/drivers/coremidi/SCsub +++ b/drivers/coremidi/SCsub @@ -1,6 +1,6 @@ #!/usr/bin/env python -Import('env') +Import("env") # Driver source files env.add_source_files(env.drivers_sources, "*.cpp") diff --git a/drivers/coremidi/midi_driver_coremidi.cpp b/drivers/coremidi/midi_driver_coremidi.cpp index d807896e61..2cd322813b 100644 --- a/drivers/coremidi/midi_driver_coremidi.cpp +++ b/drivers/coremidi/midi_driver_coremidi.cpp @@ -47,8 +47,8 @@ void MIDIDriverCoreMidi::read(const MIDIPacketList *packet_list, void *read_proc Error MIDIDriverCoreMidi::open() { - CFStringRef name = CFStringCreateWithCString(NULL, "Godot", kCFStringEncodingASCII); - OSStatus result = MIDIClientCreate(name, NULL, NULL, &client); + CFStringRef name = CFStringCreateWithCString(nullptr, "Godot", kCFStringEncodingASCII); + OSStatus result = MIDIClientCreate(name, nullptr, nullptr, &client); CFRelease(name); if (result != noErr) { ERR_PRINT("MIDIClientCreate failed, code: " + itos(result)); @@ -99,7 +99,7 @@ PackedStringArray MIDIDriverCoreMidi::get_connected_inputs() { for (int i = 0; i < connected_sources.size(); i++) { MIDIEndpointRef source = connected_sources[i]; - CFStringRef ref = NULL; + CFStringRef ref = nullptr; char name[256]; MIDIObjectGetStringProperty(source, kMIDIPropertyDisplayName, &ref); diff --git a/drivers/dummy/SCsub b/drivers/dummy/SCsub index 28b315ae66..91e1140b75 100644 --- a/drivers/dummy/SCsub +++ b/drivers/dummy/SCsub @@ -1,5 +1,5 @@ #!/usr/bin/env python -Import('env') +Import("env") env.add_source_files(env.drivers_sources, "*.cpp") diff --git a/drivers/dummy/rasterizer_dummy.h b/drivers/dummy/rasterizer_dummy.h index b446828128..0bcfed2dcf 100644 --- a/drivers/dummy/rasterizer_dummy.h +++ b/drivers/dummy/rasterizer_dummy.h @@ -35,8 +35,8 @@ #include "core/rid_owner.h" #include "core/self_list.h" #include "scene/resources/mesh.h" -#include "servers/visual/rasterizer.h" -#include "servers/visual_server.h" +#include "servers/rendering/rasterizer.h" +#include "servers/rendering_server.h" class RasterizerSceneDummy : public RasterizerScene { public: @@ -55,7 +55,7 @@ public: RID sky_create() { return RID(); } void sky_set_radiance_size(RID p_sky, int p_radiance_size) {} - void sky_set_mode(RID p_sky, VS::SkyMode p_samples) {} + void sky_set_mode(RID p_sky, RS::SkyMode p_samples) {} void sky_set_texture(RID p_sky, RID p_panorama) {} void sky_set_texture(RID p_sky, RID p_cube_map, int p_radiance_size) {} void sky_set_material(RID p_sky, RID p_material) {} @@ -64,28 +64,28 @@ public: RID environment_create() { return RID(); } - void environment_set_background(RID p_env, VS::EnvironmentBG p_bg) {} + void environment_set_background(RID p_env, RS::EnvironmentBG p_bg) {} void environment_set_sky(RID p_env, RID p_sky) {} void environment_set_sky_custom_fov(RID p_env, float p_scale) {} void environment_set_sky_orientation(RID p_env, const Basis &p_orientation) {} void environment_set_bg_color(RID p_env, const Color &p_color) {} void environment_set_bg_energy(RID p_env, float p_energy) {} void environment_set_canvas_max_layer(RID p_env, int p_max_layer) {} - void environment_set_ambient_light(RID p_env, const Color &p_color, VS::EnvironmentAmbientSource p_ambient = VS::ENV_AMBIENT_SOURCE_BG, float p_energy = 1.0, float p_sky_contribution = 0.0, VS::EnvironmentReflectionSource p_reflection_source = VS::ENV_REFLECTION_SOURCE_BG, const Color &p_ao_color = Color()) {} + void environment_set_ambient_light(RID p_env, const Color &p_color, RS::EnvironmentAmbientSource p_ambient = RS::ENV_AMBIENT_SOURCE_BG, float p_energy = 1.0, float p_sky_contribution = 0.0, RS::EnvironmentReflectionSource p_reflection_source = RS::ENV_REFLECTION_SOURCE_BG, const Color &p_ao_color = Color()) {} // FIXME: Disabled during Vulkan refactoring, should be ported. #if 0 void environment_set_camera_feed_id(RID p_env, int p_camera_feed_id) {} #endif - void environment_set_glow(RID p_env, bool p_enable, int p_level_flags, float p_intensity, float p_strength, float p_mix, float p_bloom_threshold, VS::EnvironmentGlowBlendMode p_blend_mode, float p_hdr_bleed_threshold, float p_hdr_bleed_scale, float p_hdr_luminance_cap, bool p_bicubic_upscale) {} + void environment_set_glow(RID p_env, bool p_enable, int p_level_flags, float p_intensity, float p_strength, float p_mix, float p_bloom_threshold, RS::EnvironmentGlowBlendMode p_blend_mode, float p_hdr_bleed_threshold, float p_hdr_bleed_scale, float p_hdr_luminance_cap) {} void environment_set_fog(RID p_env, bool p_enable, float p_begin, float p_end, RID p_gradient_texture) {} void environment_set_ssr(RID p_env, bool p_enable, int p_max_steps, float p_fade_int, float p_fade_out, float p_depth_tolerance, bool p_roughness) {} - virtual void environment_set_ssao(RID p_env, bool p_enable, float p_radius, float p_intensity, float p_bias, float p_light_affect, float p_ao_channel_affect, VS::EnvironmentSSAOBlur p_blur, float p_bilateral_sharpness) {} - virtual void environment_set_ssao_quality(VS::EnvironmentSSAOQuality p_quality, bool p_half_size) {} + virtual void environment_set_ssao(RID p_env, bool p_enable, float p_radius, float p_intensity, float p_bias, float p_light_affect, float p_ao_channel_affect, RS::EnvironmentSSAOBlur p_blur, float p_bilateral_sharpness) {} + virtual void environment_set_ssao_quality(RS::EnvironmentSSAOQuality p_quality, bool p_half_size) {} - void environment_set_tonemap(RID p_env, VS::EnvironmentToneMapper p_tone_mapper, float p_exposure, float p_white, bool p_auto_exposure, float p_min_luminance, float p_max_luminance, float p_auto_exp_speed, float p_auto_exp_scale) {} + void environment_set_tonemap(RID p_env, RS::EnvironmentToneMapper p_tone_mapper, float p_exposure, float p_white, bool p_auto_exposure, float p_min_luminance, float p_max_luminance, float p_auto_exp_speed, float p_auto_exp_scale) {} void environment_set_adjustment(RID p_env, bool p_enable, float p_brightness, float p_contrast, float p_saturation, RID p_ramp) {} @@ -94,13 +94,13 @@ public: void environment_set_fog_height(RID p_env, bool p_enable, float p_min_height, float p_max_height, float p_height_curve) {} bool is_environment(RID p_env) const { return false; } - VS::EnvironmentBG environment_get_background(RID p_env) const { return VS::ENV_BG_KEEP; } + RS::EnvironmentBG environment_get_background(RID p_env) const { return RS::ENV_BG_KEEP; } int environment_get_canvas_max_layer(RID p_env) const { return 0; } virtual RID camera_effects_create() { return RID(); } - virtual void camera_effects_set_dof_blur_quality(VS::DOFBlurQuality p_quality, bool p_use_jitter) {} - virtual void camera_effects_set_dof_blur_bokeh_shape(VS::DOFBokehShape p_shape) {} + virtual void camera_effects_set_dof_blur_quality(RS::DOFBlurQuality p_quality, bool p_use_jitter) {} + virtual void camera_effects_set_dof_blur_bokeh_shape(RS::DOFBokehShape p_shape) {} virtual void camera_effects_set_dof_blur(RID p_camera_effects, bool p_far_enable, float p_far_distance, float p_far_transition, bool p_near_enable, float p_near_distance, float p_near_transition, float p_amount) {} virtual void camera_effects_set_custom_exposure(RID p_camera_effects, bool p_enable, float p_exposure) {} @@ -133,10 +133,10 @@ public: void set_scene_pass(uint64_t p_pass) {} virtual void set_time(double p_time, double p_step) {} - void set_debug_draw_mode(VS::ViewportDebugDraw p_debug_draw) {} + void set_debug_draw_mode(RS::ViewportDebugDraw p_debug_draw) {} virtual RID render_buffers_create() { return RID(); } - virtual void render_buffers_configure(RID p_render_buffers, RID p_render_target, int p_width, int p_height, VS::ViewportMSAA p_msaa) {} + virtual void render_buffers_configure(RID p_render_buffers, RID p_render_target, int p_width, int p_height, RS::ViewportMSAA p_msaa) {} virtual void screen_space_roughness_limiter_set_active(bool p_enable, float p_curve) {} virtual bool screen_space_roughness_limiter_is_active() const { return false; } @@ -162,7 +162,7 @@ public: struct DummySurface { uint32_t format; - VS::PrimitiveType primitive; + RS::PrimitiveType primitive; Vector<uint8_t> array; int vertex_count; Vector<uint8_t> index_array; @@ -175,14 +175,14 @@ public: struct DummyMesh { Vector<DummySurface> surfaces; int blend_shape_count; - VS::BlendShapeMode blend_shape_mode; + RS::BlendShapeMode blend_shape_mode; }; mutable RID_PtrOwner<DummyTexture> texture_owner; mutable RID_PtrOwner<DummyMesh> mesh_owner; virtual RID texture_2d_create(const Ref<Image> &p_image) { return RID(); } - virtual RID texture_2d_layered_create(const Vector<Ref<Image>> &p_layers, VS::TextureLayeredType p_layered_type) { return RID(); } + virtual RID texture_2d_layered_create(const Vector<Ref<Image>> &p_layers, RS::TextureLayeredType p_layered_type) { return RID(); } virtual RID texture_3d_create(const Vector<Ref<Image>> &p_slices) { return RID(); } virtual RID texture_proxy_create(RID p_base) { return RID(); } @@ -209,11 +209,11 @@ public: virtual void texture_set_path(RID p_texture, const String &p_path) {} virtual String texture_get_path(RID p_texture) const { return String(); } - virtual void texture_set_detect_3d_callback(RID p_texture, VS::TextureDetectCallback p_callback, void *p_userdata) {} - virtual void texture_set_detect_normal_callback(RID p_texture, VS::TextureDetectCallback p_callback, void *p_userdata) {} - virtual void texture_set_detect_roughness_callback(RID p_texture, VS::TextureDetectRoughnessCallback p_callback, void *p_userdata) {} + virtual void texture_set_detect_3d_callback(RID p_texture, RS::TextureDetectCallback p_callback, void *p_userdata) {} + virtual void texture_set_detect_normal_callback(RID p_texture, RS::TextureDetectCallback p_callback, void *p_userdata) {} + virtual void texture_set_detect_roughness_callback(RID p_texture, RS::TextureDetectRoughnessCallback p_callback, void *p_userdata) {} - virtual void texture_debug_usage(List<VS::TextureInfo> *r_info) {} + virtual void texture_debug_usage(List<RS::TextureInfo> *r_info) {} virtual void texture_set_force_redraw_if_visible(RID p_texture, bool p_enable) {} virtual Size2 texture_size_with_proxy(RID p_proxy) { return Size2(); } @@ -225,7 +225,7 @@ public: return texture_owner.make_rid(texture); } - void texture_allocate(RID p_texture, int p_width, int p_height, int p_depth_3d, Image::Format p_format, VisualServer::TextureType p_type = VS::TEXTURE_TYPE_2D, uint32_t p_flags = VS::TEXTURE_FLAGS_DEFAULT) { + void texture_allocate(RID p_texture, int p_width, int p_height, int p_depth_3d, Image::Format p_format, RenderingServer::TextureType p_type = RS::TEXTURE_TYPE_2D, uint32_t p_flags = RS::TEXTURE_FLAGS_DEFAULT) { DummyTexture *t = texture_owner.getornull(p_texture); ERR_FAIL_COND(!t); t->width = p_width; @@ -278,7 +278,7 @@ public: return t->format; } - VisualServer::TextureType texture_get_type(RID p_texture) const { return VS::TEXTURE_TYPE_2D; } + RenderingServer::TextureType texture_get_type(RID p_texture) const { return RS::TEXTURE_TYPE_2D; } uint32_t texture_get_texid(RID p_texture) const { return 0; } uint32_t texture_get_width(RID p_texture) const { return 0; } uint32_t texture_get_height(RID p_texture) const { return 0; } @@ -299,13 +299,13 @@ public: void texture_set_shrink_all_x2_on_set_data(bool p_enable) {} - void texture_debug_usage(List<VS::TextureInfo> *r_info) {} + void texture_debug_usage(List<RS::TextureInfo> *r_info) {} RID texture_create_radiance_cubemap(RID p_source, int p_resolution = -1) const { return RID(); } - void texture_set_detect_3d_callback(RID p_texture, VisualServer::TextureDetectCallback p_callback, void *p_userdata) {} - void texture_set_detect_srgb_callback(RID p_texture, VisualServer::TextureDetectCallback p_callback, void *p_userdata) {} - void texture_set_detect_normal_callback(RID p_texture, VisualServer::TextureDetectCallback p_callback, void *p_userdata) {} + void texture_set_detect_3d_callback(RID p_texture, RenderingServer::TextureDetectCallback p_callback, void *p_userdata) {} + void texture_set_detect_srgb_callback(RID p_texture, RenderingServer::TextureDetectCallback p_callback, void *p_userdata) {} + void texture_set_detect_normal_callback(RID p_texture, RenderingServer::TextureDetectCallback p_callback, void *p_userdata) {} void textures_keep_original(bool p_enable) {} @@ -353,14 +353,14 @@ public: DummyMesh *mesh = memnew(DummyMesh); ERR_FAIL_COND_V(!mesh, RID()); mesh->blend_shape_count = 0; - mesh->blend_shape_mode = VS::BLEND_SHAPE_MODE_NORMALIZED; + mesh->blend_shape_mode = RS::BLEND_SHAPE_MODE_NORMALIZED; return mesh_owner.make_rid(mesh); } - void mesh_add_surface(RID p_mesh, const VS::SurfaceData &p_surface) {} + void mesh_add_surface(RID p_mesh, const RS::SurfaceData &p_surface) {} #if 0 - void mesh_add_surface(RID p_mesh, uint32_t p_format, VS::PrimitiveType p_primitive, const Vector<uint8_t> &p_array, int p_vertex_count, const Vector<uint8_t> &p_index_array, int p_index_count, const AABB &p_aabb, const Vector<Vector<uint8_t> > &p_blend_shapes = Vector<Vector<uint8_t> >(), const Vector<AABB> &p_bone_aabbs = Vector<AABB>()) { + void mesh_add_surface(RID p_mesh, uint32_t p_format, RS::PrimitiveType p_primitive, const Vector<uint8_t> &p_array, int p_vertex_count, const Vector<uint8_t> &p_index_array, int p_index_count, const AABB &p_aabb, const Vector<Vector<uint8_t> > &p_blend_shapes = Vector<Vector<uint8_t> >(), const Vector<AABB> &p_bone_aabbs = Vector<AABB>()) { DummyMesh *m = mesh_owner.getornull(p_mesh); ERR_FAIL_COND(!m); @@ -390,14 +390,14 @@ public: return m->blend_shape_count; } - void mesh_set_blend_shape_mode(RID p_mesh, VS::BlendShapeMode p_mode) { + void mesh_set_blend_shape_mode(RID p_mesh, RS::BlendShapeMode p_mode) { DummyMesh *m = mesh_owner.getornull(p_mesh); ERR_FAIL_COND(!m); m->blend_shape_mode = p_mode; } - VS::BlendShapeMode mesh_get_blend_shape_mode(RID p_mesh) const { + RS::BlendShapeMode mesh_get_blend_shape_mode(RID p_mesh) const { DummyMesh *m = mesh_owner.getornull(p_mesh); - ERR_FAIL_COND_V(!m, VS::BLEND_SHAPE_MODE_NORMALIZED); + ERR_FAIL_COND_V(!m, RS::BLEND_SHAPE_MODE_NORMALIZED); return m->blend_shape_mode; } @@ -439,9 +439,9 @@ public: return m->surfaces[p_surface].format; } - VS::PrimitiveType mesh_surface_get_primitive_type(RID p_mesh, int p_surface) const { + RS::PrimitiveType mesh_surface_get_primitive_type(RID p_mesh, int p_surface) const { DummyMesh *m = mesh_owner.getornull(p_mesh); - ERR_FAIL_COND_V(!m, VS::PRIMITIVE_POINTS); + ERR_FAIL_COND_V(!m, RS::PRIMITIVE_POINTS); return m->surfaces[p_surface].primitive; } @@ -474,7 +474,7 @@ public: } #endif - VS::SurfaceData mesh_get_surface(RID p_mesh, int p_surface) const { return VS::SurfaceData(); } + RS::SurfaceData mesh_get_surface(RID p_mesh, int p_surface) const { return RS::SurfaceData(); } int mesh_get_surface_count(RID p_mesh) const { DummyMesh *m = mesh_owner.getornull(p_mesh); ERR_FAIL_COND_V(!m, 0); @@ -491,7 +491,7 @@ public: virtual RID multimesh_create() { return RID(); } - virtual void multimesh_allocate(RID p_multimesh, int p_instances, VS::MultimeshTransformFormat p_transform_format, bool p_use_colors = false, bool p_use_custom_data = false) {} + virtual void multimesh_allocate(RID p_multimesh, int p_instances, RS::MultimeshTransformFormat p_transform_format, bool p_use_colors = false, bool p_use_custom_data = false) {} int multimesh_get_instance_count(RID p_multimesh) const { return 0; } void multimesh_set_mesh(RID p_multimesh, RID p_mesh) {} @@ -516,7 +516,7 @@ public: /* IMMEDIATE API */ RID immediate_create() { return RID(); } - void immediate_begin(RID p_immediate, VS::PrimitiveType p_rimitive, RID p_texture = RID()) {} + void immediate_begin(RID p_immediate, RS::PrimitiveType p_rimitive, RID p_texture = RID()) {} void immediate_vertex(RID p_immediate, const Vector3 &p_vertex) {} void immediate_normal(RID p_immediate, const Vector3 &p_normal) {} void immediate_tangent(RID p_immediate, const Plane &p_tangent) {} @@ -543,14 +543,14 @@ public: /* Light API */ - RID light_create(VS::LightType p_type) { return RID(); } + RID light_create(RS::LightType p_type) { return RID(); } - RID directional_light_create() { return light_create(VS::LIGHT_DIRECTIONAL); } - RID omni_light_create() { return light_create(VS::LIGHT_OMNI); } - RID spot_light_create() { return light_create(VS::LIGHT_SPOT); } + RID directional_light_create() { return light_create(RS::LIGHT_DIRECTIONAL); } + RID omni_light_create() { return light_create(RS::LIGHT_OMNI); } + RID spot_light_create() { return light_create(RS::LIGHT_SPOT); } void light_set_color(RID p_light, const Color &p_color) {} - void light_set_param(RID p_light, VS::LightParam p_param, float p_value) {} + void light_set_param(RID p_light, RS::LightParam p_param, float p_value) {} void light_set_shadow(RID p_light, bool p_enabled) {} void light_set_shadow_color(RID p_light, const Color &p_color) {} void light_set_projector(RID p_light, RID p_texture) {} @@ -559,22 +559,22 @@ public: void light_set_reverse_cull_face_mode(RID p_light, bool p_enabled) {} void light_set_use_gi(RID p_light, bool p_enabled) {} - void light_omni_set_shadow_mode(RID p_light, VS::LightOmniShadowMode p_mode) {} + void light_omni_set_shadow_mode(RID p_light, RS::LightOmniShadowMode p_mode) {} - void light_directional_set_shadow_mode(RID p_light, VS::LightDirectionalShadowMode p_mode) {} + void light_directional_set_shadow_mode(RID p_light, RS::LightDirectionalShadowMode p_mode) {} void light_directional_set_blend_splits(RID p_light, bool p_enable) {} bool light_directional_get_blend_splits(RID p_light) const { return false; } - void light_directional_set_shadow_depth_range_mode(RID p_light, VS::LightDirectionalShadowDepthRangeMode p_range_mode) {} - VS::LightDirectionalShadowDepthRangeMode light_directional_get_shadow_depth_range_mode(RID p_light) const { return VS::LIGHT_DIRECTIONAL_SHADOW_DEPTH_RANGE_STABLE; } + void light_directional_set_shadow_depth_range_mode(RID p_light, RS::LightDirectionalShadowDepthRangeMode p_range_mode) {} + RS::LightDirectionalShadowDepthRangeMode light_directional_get_shadow_depth_range_mode(RID p_light) const { return RS::LIGHT_DIRECTIONAL_SHADOW_DEPTH_RANGE_STABLE; } - VS::LightDirectionalShadowMode light_directional_get_shadow_mode(RID p_light) { return VS::LIGHT_DIRECTIONAL_SHADOW_ORTHOGONAL; } - VS::LightOmniShadowMode light_omni_get_shadow_mode(RID p_light) { return VS::LIGHT_OMNI_SHADOW_DUAL_PARABOLOID; } + RS::LightDirectionalShadowMode light_directional_get_shadow_mode(RID p_light) { return RS::LIGHT_DIRECTIONAL_SHADOW_ORTHOGONAL; } + RS::LightOmniShadowMode light_omni_get_shadow_mode(RID p_light) { return RS::LIGHT_OMNI_SHADOW_DUAL_PARABOLOID; } bool light_has_shadow(RID p_light) const { return false; } - VS::LightType light_get_type(RID p_light) const { return VS::LIGHT_OMNI; } + RS::LightType light_get_type(RID p_light) const { return RS::LIGHT_OMNI; } AABB light_get_aabb(RID p_light) const { return AABB(); } - float light_get_param(RID p_light, VS::LightParam p_param) { return 0.0; } + float light_get_param(RID p_light, RS::LightParam p_param) { return 0.0; } Color light_get_color(RID p_light) { return Color(); } bool light_get_use_gi(RID p_light) { return false; } uint64_t light_get_version(RID p_light) const { return 0; } @@ -583,7 +583,7 @@ public: RID reflection_probe_create() { return RID(); } - void reflection_probe_set_update_mode(RID p_probe, VS::ReflectionProbeUpdateMode p_mode) {} + void reflection_probe_set_update_mode(RID p_probe, RS::ReflectionProbeUpdateMode p_mode) {} void reflection_probe_set_intensity(RID p_probe, float p_intensity) {} void reflection_probe_set_interior_ambient(RID p_probe, const Color &p_ambient) {} void reflection_probe_set_interior_ambient_energy(RID p_probe, float p_energy) {} @@ -598,7 +598,7 @@ public: void reflection_probe_set_resolution(RID p_probe, int p_resolution) {} AABB reflection_probe_get_aabb(RID p_probe) const { return AABB(); } - VS::ReflectionProbeUpdateMode reflection_probe_get_update_mode(RID p_probe) const { return VisualServer::REFLECTION_PROBE_UPDATE_ONCE; } + RS::ReflectionProbeUpdateMode reflection_probe_get_update_mode(RID p_probe) const { return RenderingServer::REFLECTION_PROBE_UPDATE_ONCE; } uint32_t reflection_probe_get_cull_mask(RID p_probe) const { return 0; } Vector3 reflection_probe_get_extents(RID p_probe) const { return Vector3(); } Vector3 reflection_probe_get_origin_offset(RID p_probe) const { return Vector3(); } @@ -719,7 +719,7 @@ public: float lightmap_capture_get_energy(RID p_capture) const { return 0.0; } const Vector<LightmapCaptureOctree> *lightmap_capture_get_octree_ptr(RID p_capture) const { const LightmapCapture *capture = lightmap_capture_data_owner.getornull(p_capture); - ERR_FAIL_COND_V(!capture, NULL); + ERR_FAIL_COND_V(!capture, nullptr); return &capture->octree; } @@ -742,7 +742,7 @@ public: void particles_set_fractional_delta(RID p_particles, bool p_enable) {} void particles_restart(RID p_particles) {} - void particles_set_draw_order(RID p_particles, VS::ParticlesDrawOrder p_order) {} + void particles_set_draw_order(RID p_particles, RS::ParticlesDrawOrder p_order) {} void particles_set_draw_passes(RID p_particles, int p_count) {} void particles_set_draw_pass_mesh(RID p_particles, int p_pass, RID p_mesh) {} @@ -776,12 +776,12 @@ public: virtual void render_target_disable_clear_request(RID p_render_target) {} virtual void render_target_do_clear_request(RID p_render_target) {} - VS::InstanceType get_base_type(RID p_rid) const { + RS::InstanceType get_base_type(RID p_rid) const { if (mesh_owner.owns(p_rid)) { - return VS::INSTANCE_MESH; + return RS::INSTANCE_MESH; } - return VS::INSTANCE_NONE; + return RS::INSTANCE_NONE; } bool free(RID p_rid) { @@ -803,9 +803,9 @@ public: void render_info_begin_capture() {} void render_info_end_capture() {} - int get_captured_render_info(VS::RenderInfo p_info) { return 0; } + int get_captured_render_info(RS::RenderInfo p_info) { return 0; } - int get_render_info(VS::RenderInfo p_info) { return 0; } + int get_render_info(RS::RenderInfo p_info) { return 0; } String get_video_adapter_name() const { return String(); } String get_video_adapter_vendor() const { return String(); } @@ -825,7 +825,7 @@ public: class RasterizerCanvasDummy : public RasterizerCanvas { public: - virtual TextureBindingID request_texture_binding(RID p_texture, RID p_normalmap, RID p_specular, VS::CanvasItemTextureFilter p_filter, VS::CanvasItemTextureRepeat p_repeat, RID p_multimesh) { return 0; } + virtual TextureBindingID request_texture_binding(RID p_texture, RID p_normalmap, RID p_specular, RS::CanvasItemTextureFilter p_filter, RS::CanvasItemTextureRepeat p_repeat, RID p_multimesh) { return 0; } virtual void free_texture_binding(TextureBindingID p_binding) {} virtual PolygonID request_polygon(const Vector<int> &p_indices, const Vector<Point2> &p_points, const Vector<Color> &p_colors, const Vector<Point2> &p_uvs = Vector<Point2>(), const Vector<int> &p_bones = Vector<int>(), const Vector<float> &p_weights = Vector<float>()) { return 0; } @@ -841,7 +841,7 @@ public: virtual RID occluder_polygon_create() { return RID(); } virtual void occluder_polygon_set_shape_as_lines(RID p_occluder, const Vector<Vector2> &p_lines) {} - virtual void occluder_polygon_set_cull_mode(RID p_occluder, VS::CanvasOccluderPolygonCullMode p_mode) {} + virtual void occluder_polygon_set_cull_mode(RID p_occluder, RS::CanvasOccluderPolygonCullMode p_mode) {} void draw_window_margins(int *p_margins, RID *p_margin_textures) {} diff --git a/drivers/dummy/texture_loader_dummy.cpp b/drivers/dummy/texture_loader_dummy.cpp index 95876f5c7d..ddd2943720 100644 --- a/drivers/dummy/texture_loader_dummy.cpp +++ b/drivers/dummy/texture_loader_dummy.cpp @@ -35,7 +35,7 @@ #include <string.h> -RES ResourceFormatDummyTexture::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress) { +RES ResourceFormatDummyTexture::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) { unsigned int width = 8; unsigned int height = 8; @@ -67,10 +67,19 @@ RES ResourceFormatDummyTexture::load(const String &p_path, const String &p_origi } void ResourceFormatDummyTexture::get_recognized_extensions(List<String> *p_extensions) const { - p_extensions->push_back("png"); - p_extensions->push_back("hdr"); + p_extensions->push_back("bmp"); + p_extensions->push_back("dds"); + p_extensions->push_back("exr"); + p_extensions->push_back("jpeg"); p_extensions->push_back("jpg"); + p_extensions->push_back("hdr"); + p_extensions->push_back("pkm"); + p_extensions->push_back("png"); + p_extensions->push_back("pvr"); + p_extensions->push_back("svg"); + p_extensions->push_back("svgz"); p_extensions->push_back("tga"); + p_extensions->push_back("webp"); } bool ResourceFormatDummyTexture::handles_type(const String &p_type) const { @@ -79,7 +88,22 @@ bool ResourceFormatDummyTexture::handles_type(const String &p_type) const { String ResourceFormatDummyTexture::get_resource_type(const String &p_path) const { String extension = p_path.get_extension().to_lower(); - if (extension == "png" || extension == "hdr" || extension == "jpg" || extension == "tga") + if ( + extension == "bmp" || + extension == "dds" || + extension == "exr" || + extension == "jpeg" || + extension == "jpg" || + extension == "hdr" || + extension == "pkm" || + extension == "png" || + extension == "pvr" || + extension == "svg" || + extension == "svgz" || + extension == "tga" || + extension == "webp") { return "ImageTexture"; + } + return ""; } diff --git a/drivers/dummy/texture_loader_dummy.h b/drivers/dummy/texture_loader_dummy.h index e5ae945706..ef9f3b13b6 100644 --- a/drivers/dummy/texture_loader_dummy.h +++ b/drivers/dummy/texture_loader_dummy.h @@ -36,7 +36,7 @@ class ResourceFormatDummyTexture : public ResourceFormatLoader { public: - virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = NULL, bool p_use_sub_threads = false, float *r_progress = nullptr); + virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, bool p_no_cache = false); virtual void get_recognized_extensions(List<String> *p_extensions) const; virtual bool handles_type(const String &p_type) const; virtual String get_resource_type(const String &p_path) const; diff --git a/drivers/gl_context/SCsub b/drivers/gl_context/SCsub index b9f0ea2254..ddeec6f4c6 100644 --- a/drivers/gl_context/SCsub +++ b/drivers/gl_context/SCsub @@ -1,8 +1,8 @@ #!/usr/bin/env python -Import('env') +Import("env") -if (env["platform"] in ["haiku", "osx", "windows", "x11"]): +if env["platform"] in ["haiku", "osx", "windows", "linuxbsd"]: # Thirdparty source files thirdparty_dir = "#thirdparty/glad/" thirdparty_sources = [ @@ -12,8 +12,8 @@ if (env["platform"] in ["haiku", "osx", "windows", "x11"]): env.Prepend(CPPPATH=[thirdparty_dir]) - env.Append(CPPDEFINES=['GLAD_ENABLED']) - env.Append(CPPDEFINES=['GLES_OVER_GL']) + env.Append(CPPDEFINES=["GLAD_ENABLED"]) + env.Append(CPPDEFINES=["GLES_OVER_GL"]) env_thirdparty = env.Clone() env_thirdparty.disable_warnings() diff --git a/drivers/gles2/SCsub b/drivers/gles2/SCsub index 9923e52c73..987ddcd16e 100644 --- a/drivers/gles2/SCsub +++ b/drivers/gles2/SCsub @@ -1,6 +1,6 @@ #!/usr/bin/env python -Import('env') +Import("env") env.add_source_files(env.drivers_sources, "*.cpp") diff --git a/drivers/gles2/rasterizer_canvas_gles2.cpp b/drivers/gles2/rasterizer_canvas_gles2.cpp index 24927c4bb8..069eeaba6c 100644 --- a/drivers/gles2/rasterizer_canvas_gles2.cpp +++ b/drivers/gles2/rasterizer_canvas_gles2.cpp @@ -33,7 +33,7 @@ #include "core/os/os.h" #include "core/project_settings.h" #include "rasterizer_scene_gles2.h" -#include "servers/visual/visual_server_raster.h" +#include "servers/rendering/rendering_server_raster.h" #ifndef GLES_OVER_GL #define glClearDepth glClearDepthf @@ -85,7 +85,7 @@ void RasterizerCanvasGLES2::_set_uniforms() { state.canvas_shader.set_uniform(CanvasShaderGLES2::LIGHT_COLOR, light->color * light->energy); state.canvas_shader.set_uniform(CanvasShaderGLES2::LIGHT_POS, light->light_shader_pos); state.canvas_shader.set_uniform(CanvasShaderGLES2::LIGHT_HEIGHT, light->height); - state.canvas_shader.set_uniform(CanvasShaderGLES2::LIGHT_OUTSIDE_ALPHA, light->mode == VS::CANVAS_LIGHT_MODE_MASK ? 1.0 : 0.0); + state.canvas_shader.set_uniform(CanvasShaderGLES2::LIGHT_OUTSIDE_ALPHA, light->mode == RS::CANVAS_LIGHT_MODE_MASK ? 1.0 : 0.0); if (state.using_shadow) { RasterizerStorageGLES2::CanvasLightShadow *cls = storage->canvas_light_shadow_owner.getornull(light->shadow_buffer); @@ -124,7 +124,7 @@ void RasterizerCanvasGLES2::canvas_begin() { viewport_width = storage->frame.current_rt->width; viewport_height = storage->frame.current_rt->height; viewport_x = storage->frame.current_rt->x; - viewport_y = OS::get_singleton()->get_window_size().height - viewport_height - storage->frame.current_rt->y; + viewport_y = DisplayServer::get_singleton()->window_get_size().height - viewport_height - storage->frame.current_rt->y; glScissor(viewport_x, viewport_y, viewport_width, viewport_height); glViewport(viewport_x, viewport_y, viewport_width, viewport_height); glEnable(GL_SCISSOR_TEST); @@ -152,8 +152,8 @@ void RasterizerCanvasGLES2::canvas_begin() { glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, storage->resources.white_tex); - glVertexAttrib4f(VS::ARRAY_COLOR, 1, 1, 1, 1); - glDisableVertexAttribArray(VS::ARRAY_COLOR); + glVertexAttrib4f(RS::ARRAY_COLOR, 1, 1, 1, 1); + glDisableVertexAttribArray(RS::ARRAY_COLOR); // set up default uniforms @@ -168,7 +168,7 @@ void RasterizerCanvasGLES2::canvas_begin() { canvas_transform.translate(-(storage->frame.current_rt->width / 2.0f), -(storage->frame.current_rt->height / 2.0f), 0.0f); canvas_transform.scale(Vector3(2.0f / storage->frame.current_rt->width, csy * -2.0f / storage->frame.current_rt->height, 1.0f)); } else { - Vector2 ssize = OS::get_singleton()->get_window_size(); + Vector2 ssize = DisplayServer::get_singleton()->window_get_size(); canvas_transform.translate(-(ssize.width / 2.0f), -(ssize.height / 2.0f), 0.0f); canvas_transform.scale(Vector3(2.0f / ssize.width, -2.0f / ssize.height, 1.0f)); } @@ -188,14 +188,14 @@ void RasterizerCanvasGLES2::canvas_end() { glBindBuffer(GL_ARRAY_BUFFER, 0); - for (int i = 0; i < VS::ARRAY_MAX; i++) { + for (int i = 0; i < RS::ARRAY_MAX; i++) { glDisableVertexAttribArray(i); } if (storage->frame.current_rt && storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_DIRECT_TO_SCREEN]) { //reset viewport to full window size - int viewport_width = OS::get_singleton()->get_window_size().width; - int viewport_height = OS::get_singleton()->get_window_size().height; + int viewport_width = DisplayServer::get_singleton()->window_get_size().width; + int viewport_height = DisplayServer::get_singleton()->window_get_size().height; glViewport(0, 0, viewport_width, viewport_height); glScissor(0, 0, viewport_width, viewport_height); } @@ -208,7 +208,7 @@ void RasterizerCanvasGLES2::canvas_end() { RasterizerStorageGLES2::Texture *RasterizerCanvasGLES2::_bind_canvas_texture(const RID &p_texture, const RID &p_normal_map) { - RasterizerStorageGLES2::Texture *tex_return = NULL; + RasterizerStorageGLES2::Texture *tex_return = nullptr; if (p_texture.is_valid()) { @@ -216,7 +216,7 @@ RasterizerStorageGLES2::Texture *RasterizerCanvasGLES2::_bind_canvas_texture(con if (!texture) { state.current_tex = RID(); - state.current_tex_ptr = NULL; + state.current_tex_ptr = nullptr; glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 1); glBindTexture(GL_TEXTURE_2D, storage->resources.white_tex); @@ -224,7 +224,7 @@ RasterizerStorageGLES2::Texture *RasterizerCanvasGLES2::_bind_canvas_texture(con } else { if (texture->redraw_if_visible) { - VisualServerRaster::redraw_request(); + RenderingServerRaster::redraw_request(); } texture = texture->get_ptr(); @@ -243,7 +243,7 @@ RasterizerStorageGLES2::Texture *RasterizerCanvasGLES2::_bind_canvas_texture(con } } else { state.current_tex = RID(); - state.current_tex_ptr = NULL; + state.current_tex_ptr = nullptr; glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 1); glBindTexture(GL_TEXTURE_2D, storage->resources.white_tex); @@ -266,7 +266,7 @@ RasterizerStorageGLES2::Texture *RasterizerCanvasGLES2::_bind_canvas_texture(con } else { if (normal_map->redraw_if_visible) { //check before proxy, because this is usually used with proxies - VisualServerRaster::redraw_request(); + RenderingServerRaster::redraw_request(); } normal_map = normal_map->get_ptr(); @@ -293,59 +293,59 @@ void RasterizerCanvasGLES2::_draw_polygon(const int *p_indices, int p_index_coun glBindBuffer(GL_ARRAY_BUFFER, data.polygon_buffer); #ifndef GLES_OVER_GL // Orphan the buffer to avoid CPU/GPU sync points caused by glBufferSubData - glBufferData(GL_ARRAY_BUFFER, data.polygon_buffer_size, NULL, GL_DYNAMIC_DRAW); + glBufferData(GL_ARRAY_BUFFER, data.polygon_buffer_size, nullptr, GL_DYNAMIC_DRAW); #endif uint32_t buffer_ofs = 0; glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(Vector2) * p_vertex_count, p_vertices); - glEnableVertexAttribArray(VS::ARRAY_VERTEX); - glVertexAttribPointer(VS::ARRAY_VERTEX, 2, GL_FLOAT, GL_FALSE, sizeof(Vector2), NULL); + glEnableVertexAttribArray(RS::ARRAY_VERTEX); + glVertexAttribPointer(RS::ARRAY_VERTEX, 2, GL_FLOAT, GL_FALSE, sizeof(Vector2), nullptr); buffer_ofs += sizeof(Vector2) * p_vertex_count; if (p_singlecolor) { - glDisableVertexAttribArray(VS::ARRAY_COLOR); + glDisableVertexAttribArray(RS::ARRAY_COLOR); Color m = *p_colors; - glVertexAttrib4f(VS::ARRAY_COLOR, m.r, m.g, m.b, m.a); + glVertexAttrib4f(RS::ARRAY_COLOR, m.r, m.g, m.b, m.a); } else if (!p_colors) { - glDisableVertexAttribArray(VS::ARRAY_COLOR); - glVertexAttrib4f(VS::ARRAY_COLOR, 1, 1, 1, 1); + glDisableVertexAttribArray(RS::ARRAY_COLOR); + glVertexAttrib4f(RS::ARRAY_COLOR, 1, 1, 1, 1); } else { glBufferSubData(GL_ARRAY_BUFFER, buffer_ofs, sizeof(Color) * p_vertex_count, p_colors); - glEnableVertexAttribArray(VS::ARRAY_COLOR); - glVertexAttribPointer(VS::ARRAY_COLOR, 4, GL_FLOAT, GL_FALSE, sizeof(Color), CAST_INT_TO_UCHAR_PTR(buffer_ofs)); + glEnableVertexAttribArray(RS::ARRAY_COLOR); + glVertexAttribPointer(RS::ARRAY_COLOR, 4, GL_FLOAT, GL_FALSE, sizeof(Color), CAST_INT_TO_UCHAR_PTR(buffer_ofs)); buffer_ofs += sizeof(Color) * p_vertex_count; } if (p_uvs) { glBufferSubData(GL_ARRAY_BUFFER, buffer_ofs, sizeof(Vector2) * p_vertex_count, p_uvs); - glEnableVertexAttribArray(VS::ARRAY_TEX_UV); - glVertexAttribPointer(VS::ARRAY_TEX_UV, 2, GL_FLOAT, GL_FALSE, sizeof(Vector2), CAST_INT_TO_UCHAR_PTR(buffer_ofs)); + glEnableVertexAttribArray(RS::ARRAY_TEX_UV); + glVertexAttribPointer(RS::ARRAY_TEX_UV, 2, GL_FLOAT, GL_FALSE, sizeof(Vector2), CAST_INT_TO_UCHAR_PTR(buffer_ofs)); buffer_ofs += sizeof(Vector2) * p_vertex_count; } else { - glDisableVertexAttribArray(VS::ARRAY_TEX_UV); + glDisableVertexAttribArray(RS::ARRAY_TEX_UV); } if (p_weights && p_bones) { glBufferSubData(GL_ARRAY_BUFFER, buffer_ofs, sizeof(float) * 4 * p_vertex_count, p_weights); - glEnableVertexAttribArray(VS::ARRAY_WEIGHTS); - glVertexAttribPointer(VS::ARRAY_WEIGHTS, 4, GL_FLOAT, GL_FALSE, sizeof(float) * 4, CAST_INT_TO_UCHAR_PTR(buffer_ofs)); + glEnableVertexAttribArray(RS::ARRAY_WEIGHTS); + glVertexAttribPointer(RS::ARRAY_WEIGHTS, 4, GL_FLOAT, GL_FALSE, sizeof(float) * 4, CAST_INT_TO_UCHAR_PTR(buffer_ofs)); buffer_ofs += sizeof(float) * 4 * p_vertex_count; glBufferSubData(GL_ARRAY_BUFFER, buffer_ofs, sizeof(int) * 4 * p_vertex_count, p_bones); - glEnableVertexAttribArray(VS::ARRAY_BONES); - glVertexAttribPointer(VS::ARRAY_BONES, 4, GL_UNSIGNED_INT, GL_FALSE, sizeof(int) * 4, CAST_INT_TO_UCHAR_PTR(buffer_ofs)); + glEnableVertexAttribArray(RS::ARRAY_BONES); + glVertexAttribPointer(RS::ARRAY_BONES, 4, GL_UNSIGNED_INT, GL_FALSE, sizeof(int) * 4, CAST_INT_TO_UCHAR_PTR(buffer_ofs)); buffer_ofs += sizeof(int) * 4 * p_vertex_count; } else { - glDisableVertexAttribArray(VS::ARRAY_WEIGHTS); - glDisableVertexAttribArray(VS::ARRAY_BONES); + glDisableVertexAttribArray(RS::ARRAY_WEIGHTS); + glDisableVertexAttribArray(RS::ARRAY_BONES); } glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, data.polygon_index_buffer); #ifndef GLES_OVER_GL // Orphan the buffer to avoid CPU/GPU sync points caused by glBufferSubData - glBufferData(GL_ELEMENT_ARRAY_BUFFER, data.polygon_index_buffer_size, NULL, GL_DYNAMIC_DRAW); + glBufferData(GL_ELEMENT_ARRAY_BUFFER, data.polygon_index_buffer_size, nullptr, GL_DYNAMIC_DRAW); #endif if (storage->config.support_32_bits_indices) { //should check for @@ -369,36 +369,36 @@ void RasterizerCanvasGLES2::_draw_generic(GLuint p_primitive, int p_vertex_count glBindBuffer(GL_ARRAY_BUFFER, data.polygon_buffer); #ifndef GLES_OVER_GL // Orphan the buffer to avoid CPU/GPU sync points caused by glBufferSubData - glBufferData(GL_ARRAY_BUFFER, data.polygon_buffer_size, NULL, GL_DYNAMIC_DRAW); + glBufferData(GL_ARRAY_BUFFER, data.polygon_buffer_size, nullptr, GL_DYNAMIC_DRAW); #endif uint32_t buffer_ofs = 0; glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(Vector2) * p_vertex_count, p_vertices); - glEnableVertexAttribArray(VS::ARRAY_VERTEX); - glVertexAttribPointer(VS::ARRAY_VERTEX, 2, GL_FLOAT, GL_FALSE, sizeof(Vector2), NULL); + glEnableVertexAttribArray(RS::ARRAY_VERTEX); + glVertexAttribPointer(RS::ARRAY_VERTEX, 2, GL_FLOAT, GL_FALSE, sizeof(Vector2), nullptr); buffer_ofs += sizeof(Vector2) * p_vertex_count; if (p_singlecolor) { - glDisableVertexAttribArray(VS::ARRAY_COLOR); + glDisableVertexAttribArray(RS::ARRAY_COLOR); Color m = *p_colors; - glVertexAttrib4f(VS::ARRAY_COLOR, m.r, m.g, m.b, m.a); + glVertexAttrib4f(RS::ARRAY_COLOR, m.r, m.g, m.b, m.a); } else if (!p_colors) { - glDisableVertexAttribArray(VS::ARRAY_COLOR); - glVertexAttrib4f(VS::ARRAY_COLOR, 1, 1, 1, 1); + glDisableVertexAttribArray(RS::ARRAY_COLOR); + glVertexAttrib4f(RS::ARRAY_COLOR, 1, 1, 1, 1); } else { glBufferSubData(GL_ARRAY_BUFFER, buffer_ofs, sizeof(Color) * p_vertex_count, p_colors); - glEnableVertexAttribArray(VS::ARRAY_COLOR); - glVertexAttribPointer(VS::ARRAY_COLOR, 4, GL_FLOAT, GL_FALSE, sizeof(Color), CAST_INT_TO_UCHAR_PTR(buffer_ofs)); + glEnableVertexAttribArray(RS::ARRAY_COLOR); + glVertexAttribPointer(RS::ARRAY_COLOR, 4, GL_FLOAT, GL_FALSE, sizeof(Color), CAST_INT_TO_UCHAR_PTR(buffer_ofs)); buffer_ofs += sizeof(Color) * p_vertex_count; } if (p_uvs) { glBufferSubData(GL_ARRAY_BUFFER, buffer_ofs, sizeof(Vector2) * p_vertex_count, p_uvs); - glEnableVertexAttribArray(VS::ARRAY_TEX_UV); - glVertexAttribPointer(VS::ARRAY_TEX_UV, 2, GL_FLOAT, GL_FALSE, sizeof(Vector2), CAST_INT_TO_UCHAR_PTR(buffer_ofs)); + glEnableVertexAttribArray(RS::ARRAY_TEX_UV); + glVertexAttribPointer(RS::ARRAY_TEX_UV, 2, GL_FLOAT, GL_FALSE, sizeof(Vector2), CAST_INT_TO_UCHAR_PTR(buffer_ofs)); } else { - glDisableVertexAttribArray(VS::ARRAY_TEX_UV); + glDisableVertexAttribArray(RS::ARRAY_TEX_UV); } glDrawArrays(p_primitive, 0, p_vertex_count); @@ -411,43 +411,43 @@ void RasterizerCanvasGLES2::_draw_generic_indices(GLuint p_primitive, const int glBindBuffer(GL_ARRAY_BUFFER, data.polygon_buffer); #ifndef GLES_OVER_GL // Orphan the buffer to avoid CPU/GPU sync points caused by glBufferSubData - glBufferData(GL_ARRAY_BUFFER, data.polygon_buffer_size, NULL, GL_DYNAMIC_DRAW); + glBufferData(GL_ARRAY_BUFFER, data.polygon_buffer_size, nullptr, GL_DYNAMIC_DRAW); #endif uint32_t buffer_ofs = 0; glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(Vector2) * p_vertex_count, p_vertices); - glEnableVertexAttribArray(VS::ARRAY_VERTEX); - glVertexAttribPointer(VS::ARRAY_VERTEX, 2, GL_FLOAT, GL_FALSE, sizeof(Vector2), NULL); + glEnableVertexAttribArray(RS::ARRAY_VERTEX); + glVertexAttribPointer(RS::ARRAY_VERTEX, 2, GL_FLOAT, GL_FALSE, sizeof(Vector2), nullptr); buffer_ofs += sizeof(Vector2) * p_vertex_count; if (p_singlecolor) { - glDisableVertexAttribArray(VS::ARRAY_COLOR); + glDisableVertexAttribArray(RS::ARRAY_COLOR); Color m = *p_colors; - glVertexAttrib4f(VS::ARRAY_COLOR, m.r, m.g, m.b, m.a); + glVertexAttrib4f(RS::ARRAY_COLOR, m.r, m.g, m.b, m.a); } else if (!p_colors) { - glDisableVertexAttribArray(VS::ARRAY_COLOR); - glVertexAttrib4f(VS::ARRAY_COLOR, 1, 1, 1, 1); + glDisableVertexAttribArray(RS::ARRAY_COLOR); + glVertexAttrib4f(RS::ARRAY_COLOR, 1, 1, 1, 1); } else { glBufferSubData(GL_ARRAY_BUFFER, buffer_ofs, sizeof(Color) * p_vertex_count, p_colors); - glEnableVertexAttribArray(VS::ARRAY_COLOR); - glVertexAttribPointer(VS::ARRAY_COLOR, 4, GL_FLOAT, GL_FALSE, sizeof(Color), CAST_INT_TO_UCHAR_PTR(buffer_ofs)); + glEnableVertexAttribArray(RS::ARRAY_COLOR); + glVertexAttribPointer(RS::ARRAY_COLOR, 4, GL_FLOAT, GL_FALSE, sizeof(Color), CAST_INT_TO_UCHAR_PTR(buffer_ofs)); buffer_ofs += sizeof(Color) * p_vertex_count; } if (p_uvs) { glBufferSubData(GL_ARRAY_BUFFER, buffer_ofs, sizeof(Vector2) * p_vertex_count, p_uvs); - glEnableVertexAttribArray(VS::ARRAY_TEX_UV); - glVertexAttribPointer(VS::ARRAY_TEX_UV, 2, GL_FLOAT, GL_FALSE, sizeof(Vector2), CAST_INT_TO_UCHAR_PTR(buffer_ofs)); + glEnableVertexAttribArray(RS::ARRAY_TEX_UV); + glVertexAttribPointer(RS::ARRAY_TEX_UV, 2, GL_FLOAT, GL_FALSE, sizeof(Vector2), CAST_INT_TO_UCHAR_PTR(buffer_ofs)); buffer_ofs += sizeof(Vector2) * p_vertex_count; } else { - glDisableVertexAttribArray(VS::ARRAY_TEX_UV); + glDisableVertexAttribArray(RS::ARRAY_TEX_UV); } glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, data.polygon_index_buffer); #ifndef GLES_OVER_GL // Orphan the buffer to avoid CPU/GPU sync points caused by glBufferSubData - glBufferData(GL_ELEMENT_ARRAY_BUFFER, data.polygon_index_buffer_size, NULL, GL_DYNAMIC_DRAW); + glBufferData(GL_ELEMENT_ARRAY_BUFFER, data.polygon_index_buffer_size, nullptr, GL_DYNAMIC_DRAW); #endif if (storage->config.support_32_bits_indices) { //should check for @@ -510,20 +510,20 @@ void RasterizerCanvasGLES2::_draw_gui_primitive(int p_points, const Vector2 *p_v glBindBuffer(GL_ARRAY_BUFFER, data.polygon_buffer); #ifndef GLES_OVER_GL // Orphan the buffer to avoid CPU/GPU sync points caused by glBufferSubData - glBufferData(GL_ARRAY_BUFFER, data.polygon_buffer_size, NULL, GL_DYNAMIC_DRAW); + glBufferData(GL_ARRAY_BUFFER, data.polygon_buffer_size, nullptr, GL_DYNAMIC_DRAW); #endif glBufferSubData(GL_ARRAY_BUFFER, 0, p_points * stride * 4 * sizeof(float), buffer_data); - glVertexAttribPointer(VS::ARRAY_VERTEX, 2, GL_FLOAT, GL_FALSE, stride * sizeof(float), NULL); + glVertexAttribPointer(RS::ARRAY_VERTEX, 2, GL_FLOAT, GL_FALSE, stride * sizeof(float), nullptr); if (p_colors) { - glVertexAttribPointer(VS::ARRAY_COLOR, 4, GL_FLOAT, GL_FALSE, stride * sizeof(float), CAST_INT_TO_UCHAR_PTR(color_offset * sizeof(float))); - glEnableVertexAttribArray(VS::ARRAY_COLOR); + glVertexAttribPointer(RS::ARRAY_COLOR, 4, GL_FLOAT, GL_FALSE, stride * sizeof(float), CAST_INT_TO_UCHAR_PTR(color_offset * sizeof(float))); + glEnableVertexAttribArray(RS::ARRAY_COLOR); } if (p_uvs) { - glVertexAttribPointer(VS::ARRAY_TEX_UV, 2, GL_FLOAT, GL_FALSE, stride * sizeof(float), CAST_INT_TO_UCHAR_PTR(uv_offset * sizeof(float))); - glEnableVertexAttribArray(VS::ARRAY_TEX_UV); + glVertexAttribPointer(RS::ARRAY_TEX_UV, 2, GL_FLOAT, GL_FALSE, stride * sizeof(float), CAST_INT_TO_UCHAR_PTR(uv_offset * sizeof(float))); + glEnableVertexAttribArray(RS::ARRAY_TEX_UV); } glDrawArrays(prim[p_points], 0, p_points); @@ -564,8 +564,8 @@ void RasterizerCanvasGLES2::_canvas_item_render_commands(Item *p_item, Item *cur _bind_canvas_texture(RID(), RID()); - glDisableVertexAttribArray(VS::ARRAY_COLOR); - glVertexAttrib4fv(VS::ARRAY_COLOR, line->color.components); + glDisableVertexAttribArray(RS::ARRAY_COLOR); + glVertexAttrib4fv(RS::ARRAY_COLOR, line->color.components); state.canvas_shader.set_uniform(CanvasShaderGLES2::MODELVIEW_MATRIX, state.uniforms.modelview_matrix); @@ -579,7 +579,7 @@ void RasterizerCanvasGLES2::_canvas_item_render_commands(Item *p_item, Item *cur if (line->antialiased) glEnable(GL_LINE_SMOOTH); #endif - _draw_gui_primitive(2, verts, NULL, NULL); + _draw_gui_primitive(2, verts, nullptr, nullptr); #ifdef GLES_OVER_GL if (line->antialiased) @@ -595,7 +595,7 @@ void RasterizerCanvasGLES2::_canvas_item_render_commands(Item *p_item, Item *cur line->to - t }; - _draw_gui_primitive(4, verts, NULL, NULL); + _draw_gui_primitive(4, verts, nullptr, nullptr); #ifdef GLES_OVER_GL if (line->antialiased) { glEnable(GL_LINE_SMOOTH); @@ -604,7 +604,7 @@ void RasterizerCanvasGLES2::_canvas_item_render_commands(Item *p_item, Item *cur verts[j], verts[(j + 1) % 4], }; - _draw_gui_primitive(2, vertsl, NULL, NULL); + _draw_gui_primitive(2, vertsl, nullptr, nullptr); } glDisable(GL_LINE_SMOOTH); } @@ -616,8 +616,8 @@ void RasterizerCanvasGLES2::_canvas_item_render_commands(Item *p_item, Item *cur Item::CommandRect *r = static_cast<Item::CommandRect *>(command); - glDisableVertexAttribArray(VS::ARRAY_COLOR); - glVertexAttrib4fv(VS::ARRAY_COLOR, r->modulate.components); + glDisableVertexAttribArray(RS::ARRAY_COLOR); + glVertexAttrib4fv(RS::ARRAY_COLOR, r->modulate.components); bool can_tile = true; if (r->texture.is_valid() && r->flags & CANVAS_RECT_TILE && !storage->config.support_npot_repeat_mipmap) { @@ -696,13 +696,13 @@ void RasterizerCanvasGLES2::_canvas_item_render_commands(Item *p_item, Item *cur bool untile = false; - if (can_tile && r->flags & CANVAS_RECT_TILE && !(texture->flags & VS::TEXTURE_FLAG_REPEAT)) { + if (can_tile && r->flags & CANVAS_RECT_TILE && !(texture->flags & RS::TEXTURE_FLAG_REPEAT)) { glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); untile = true; } - _draw_gui_primitive(4, points, NULL, uvs); + _draw_gui_primitive(4, points, nullptr, uvs); if (untile) { glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); @@ -717,7 +717,7 @@ void RasterizerCanvasGLES2::_canvas_item_render_commands(Item *p_item, Item *cur }; state.canvas_shader.set_uniform(CanvasShaderGLES2::COLOR_TEXPIXEL_SIZE, Vector2()); - _draw_gui_primitive(4, points, NULL, uvs); + _draw_gui_primitive(4, points, nullptr, uvs); } } else { @@ -753,7 +753,7 @@ void RasterizerCanvasGLES2::_canvas_item_render_commands(Item *p_item, Item *cur bool untile = false; - if (can_tile && r->flags & CANVAS_RECT_TILE && !(tex->flags & VS::TEXTURE_FLAG_REPEAT)) { + if (can_tile && r->flags & CANVAS_RECT_TILE && !(tex->flags & RS::TEXTURE_FLAG_REPEAT)) { glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); untile = true; @@ -816,8 +816,8 @@ void RasterizerCanvasGLES2::_canvas_item_render_commands(Item *p_item, Item *cur state.canvas_shader.use_material((void *)p_material); } - glDisableVertexAttribArray(VS::ARRAY_COLOR); - glVertexAttrib4fv(VS::ARRAY_COLOR, np->color.components); + glDisableVertexAttribArray(RS::ARRAY_COLOR); + glVertexAttrib4fv(RS::ARRAY_COLOR, np->color.components); RasterizerStorageGLES2::Texture *tex = _bind_canvas_texture(np->texture, np->normal_map); @@ -968,13 +968,13 @@ void RasterizerCanvasGLES2::_canvas_item_render_commands(Item *p_item, Item *cur glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, data.ninepatch_elements); - glEnableVertexAttribArray(VS::ARRAY_VERTEX); - glEnableVertexAttribArray(VS::ARRAY_TEX_UV); + glEnableVertexAttribArray(RS::ARRAY_VERTEX); + glEnableVertexAttribArray(RS::ARRAY_TEX_UV); - glVertexAttribPointer(VS::ARRAY_VERTEX, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), NULL); - glVertexAttribPointer(VS::ARRAY_TEX_UV, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), CAST_INT_TO_UCHAR_PTR((sizeof(float) * 2))); + glVertexAttribPointer(RS::ARRAY_VERTEX, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), nullptr); + glVertexAttribPointer(RS::ARRAY_TEX_UV, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), CAST_INT_TO_UCHAR_PTR((sizeof(float) * 2))); - glDrawElements(GL_TRIANGLES, 18 * 3 - (np->draw_center ? 0 : 6), GL_UNSIGNED_BYTE, NULL); + glDrawElements(GL_TRIANGLES, 18 * 3 - (np->draw_center ? 0 : 6), GL_UNSIGNED_BYTE, nullptr); glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); @@ -1008,7 +1008,7 @@ void RasterizerCanvasGLES2::_canvas_item_render_commands(Item *p_item, Item *cur _bind_canvas_texture(RID(), RID()); - _draw_polygon(indices, num_points * 3, num_points + 1, points, NULL, &circle->color, true); + _draw_polygon(indices, num_points * 3, num_points + 1, points, nullptr, &circle->color, true); } break; case Item::Command::TYPE_POLYGON: { @@ -1072,18 +1072,18 @@ void RasterizerCanvasGLES2::_canvas_item_render_commands(Item *p_item, Item *cur glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, s->index_id); } - for (int k = 0; k < VS::ARRAY_MAX - 1; k++) { + for (int k = 0; k < RS::ARRAY_MAX - 1; k++) { if (s->attribs[k].enabled) { glEnableVertexAttribArray(k); glVertexAttribPointer(s->attribs[k].index, s->attribs[k].size, s->attribs[k].type, s->attribs[k].normalized, s->attribs[k].stride, CAST_INT_TO_UCHAR_PTR(s->attribs[k].offset)); } else { glDisableVertexAttribArray(k); switch (k) { - case VS::ARRAY_NORMAL: { - glVertexAttrib4f(VS::ARRAY_NORMAL, 0.0, 0.0, 1, 1); + case RS::ARRAY_NORMAL: { + glVertexAttrib4f(RS::ARRAY_NORMAL, 0.0, 0.0, 1, 1); } break; - case VS::ARRAY_COLOR: { - glVertexAttrib4f(VS::ARRAY_COLOR, 1, 1, 1, 1); + case RS::ARRAY_COLOR: { + glVertexAttrib4f(RS::ARRAY_COLOR, 1, 1, 1, 1); } break; default: { @@ -1099,7 +1099,7 @@ void RasterizerCanvasGLES2::_canvas_item_render_commands(Item *p_item, Item *cur } } - for (int j = 1; j < VS::ARRAY_MAX - 1; j++) { + for (int j = 1; j < RS::ARRAY_MAX - 1; j++) { glDisableVertexAttribArray(j); } } @@ -1118,7 +1118,7 @@ void RasterizerCanvasGLES2::_canvas_item_render_commands(Item *p_item, Item *cur if (!mesh_data) break; - state.canvas_shader.set_conditional(CanvasShaderGLES2::USE_INSTANCE_CUSTOM, multi_mesh->custom_data_format != VS::MULTIMESH_CUSTOM_DATA_NONE); + state.canvas_shader.set_conditional(CanvasShaderGLES2::USE_INSTANCE_CUSTOM, multi_mesh->custom_data_format != RS::MULTIMESH_CUSTOM_DATA_NONE); state.canvas_shader.set_conditional(CanvasShaderGLES2::USE_INSTANCING, true); state.canvas_shader.set_conditional(CanvasShaderGLES2::USE_TEXTURE_RECT, false); @@ -1162,18 +1162,18 @@ void RasterizerCanvasGLES2::_canvas_item_render_commands(Item *p_item, Item *cur glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, s->index_id); } - for (int k = 0; k < VS::ARRAY_MAX - 1; k++) { + for (int k = 0; k < RS::ARRAY_MAX - 1; k++) { if (s->attribs[k].enabled) { glEnableVertexAttribArray(k); glVertexAttribPointer(s->attribs[k].index, s->attribs[k].size, s->attribs[k].type, s->attribs[k].normalized, s->attribs[k].stride, CAST_INT_TO_UCHAR_PTR(s->attribs[k].offset)); } else { glDisableVertexAttribArray(k); switch (k) { - case VS::ARRAY_NORMAL: { - glVertexAttrib4f(VS::ARRAY_NORMAL, 0.0, 0.0, 1, 1); + case RS::ARRAY_NORMAL: { + glVertexAttrib4f(RS::ARRAY_NORMAL, 0.0, 0.0, 1, 1); } break; - case VS::ARRAY_COLOR: { - glVertexAttrib4f(VS::ARRAY_COLOR, 1, 1, 1, 1); + case RS::ARRAY_COLOR: { + glVertexAttrib4f(RS::ARRAY_COLOR, 1, 1, 1, 1); } break; default: { @@ -1189,7 +1189,7 @@ void RasterizerCanvasGLES2::_canvas_item_render_commands(Item *p_item, Item *cur glVertexAttrib4fv(INSTANCE_ATTRIB_BASE + 0, &buffer[0]); glVertexAttrib4fv(INSTANCE_ATTRIB_BASE + 1, &buffer[4]); - if (multi_mesh->transform_format == VS::MULTIMESH_TRANSFORM_3D) { + if (multi_mesh->transform_format == RS::MULTIMESH_TRANSFORM_3D) { glVertexAttrib4fv(INSTANCE_ATTRIB_BASE + 2, &buffer[8]); } else { glVertexAttrib4f(INSTANCE_ATTRIB_BASE + 2, 0.0, 0.0, 1.0, 0.0); @@ -1197,7 +1197,7 @@ void RasterizerCanvasGLES2::_canvas_item_render_commands(Item *p_item, Item *cur } if (multi_mesh->color_floats) { - if (multi_mesh->color_format == VS::MULTIMESH_COLOR_8BIT) { + if (multi_mesh->color_format == RS::MULTIMESH_COLOR_8BIT) { uint8_t *color_data = (uint8_t *)(buffer + color_ofs); glVertexAttrib4f(INSTANCE_ATTRIB_BASE + 3, color_data[0] / 255.0, color_data[1] / 255.0, color_data[2] / 255.0, color_data[3] / 255.0); } else { @@ -1208,7 +1208,7 @@ void RasterizerCanvasGLES2::_canvas_item_render_commands(Item *p_item, Item *cur } if (multi_mesh->custom_data_floats) { - if (multi_mesh->custom_data_format == VS::MULTIMESH_CUSTOM_DATA_8BIT) { + if (multi_mesh->custom_data_format == RS::MULTIMESH_CUSTOM_DATA_8BIT) { uint8_t *custom_data = (uint8_t *)(buffer + custom_data_ofs); glVertexAttrib4f(INSTANCE_ATTRIB_BASE + 4, custom_data[0] / 255.0, custom_data[1] / 255.0, custom_data[2] / 255.0, custom_data[3] / 255.0); } else { @@ -1241,13 +1241,13 @@ void RasterizerCanvasGLES2::_canvas_item_render_commands(Item *p_item, Item *cur _bind_canvas_texture(RID(), RID()); if (pline->triangles.size()) { - _draw_generic(GL_TRIANGLE_STRIP, pline->triangles.size(), pline->triangles.ptr(), NULL, pline->triangle_colors.ptr(), pline->triangle_colors.size() == 1); + _draw_generic(GL_TRIANGLE_STRIP, pline->triangles.size(), pline->triangles.ptr(), nullptr, pline->triangle_colors.ptr(), pline->triangle_colors.size() == 1); #ifdef GLES_OVER_GL glEnable(GL_LINE_SMOOTH); if (pline->multiline) { //needs to be different } else { - _draw_generic(GL_LINE_LOOP, pline->lines.size(), pline->lines.ptr(), NULL, pline->line_colors.ptr(), pline->line_colors.size() == 1); + _draw_generic(GL_LINE_LOOP, pline->lines.size(), pline->lines.ptr(), nullptr, pline->line_colors.ptr(), pline->line_colors.size() == 1); } glDisable(GL_LINE_SMOOTH); #endif @@ -1265,12 +1265,12 @@ void RasterizerCanvasGLES2::_canvas_item_render_commands(Item *p_item, Item *cur while (todo) { int to_draw = MIN(max_per_call, todo); - _draw_generic(GL_LINES, to_draw * 2, &pline->lines.ptr()[offset], NULL, pline->line_colors.size() == 1 ? pline->line_colors.ptr() : &pline->line_colors.ptr()[offset], pline->line_colors.size() == 1); + _draw_generic(GL_LINES, to_draw * 2, &pline->lines.ptr()[offset], nullptr, pline->line_colors.size() == 1 ? pline->line_colors.ptr() : &pline->line_colors.ptr()[offset], pline->line_colors.size() == 1); todo -= to_draw; offset += to_draw * 2; } } else { - _draw_generic(GL_LINES, pline->lines.size(), pline->lines.ptr(), NULL, pline->line_colors.ptr(), pline->line_colors.size() == 1); + _draw_generic(GL_LINES, pline->lines.size(), pline->lines.ptr(), nullptr, pline->line_colors.ptr(), pline->line_colors.size() == 1); } #ifdef GLES_OVER_GL @@ -1301,9 +1301,9 @@ void RasterizerCanvasGLES2::_canvas_item_render_commands(Item *p_item, Item *cur if (primitive->colors.size() == 1 && primitive->points.size() > 1) { Color c = primitive->colors[0]; - glVertexAttrib4f(VS::ARRAY_COLOR, c.r, c.g, c.b, c.a); + glVertexAttrib4f(RS::ARRAY_COLOR, c.r, c.g, c.b, c.a); } else if (primitive->colors.empty()) { - glVertexAttrib4f(VS::ARRAY_COLOR, 1, 1, 1, 1); + glVertexAttrib4f(RS::ARRAY_COLOR, 1, 1, 1, 1); } _draw_gui_primitive(primitive->points.size(), primitive->points.ptr(), primitive->colors.ptr(), primitive->uvs.ptr()); @@ -1402,7 +1402,7 @@ void RasterizerCanvasGLES2::_copy_screen(const Rect2 &p_rect) { 2, 3, 0 }; - _draw_polygon(indexpos, 6, 4, vertpos, uvpos, NULL, false); + _draw_polygon(indexpos, 6, 4, vertpos, uvpos, nullptr, false); storage->shaders.copy.set_conditional(CopyShaderGLES2::USE_COPY_SECTION, false); storage->shaders.copy.set_conditional(CopyShaderGLES2::USE_NO_ALPHA, false); @@ -1426,16 +1426,16 @@ void RasterizerCanvasGLES2::_copy_texscreen(const Rect2 &p_rect) { void RasterizerCanvasGLES2::canvas_render_items(Item *p_item_list, int p_z, const Color &p_modulate, Light *p_light, const Transform2D &p_base_transform) { - Item *current_clip = NULL; + Item *current_clip = nullptr; - RasterizerStorageGLES2::Shader *shader_cache = NULL; + RasterizerStorageGLES2::Shader *shader_cache = nullptr; bool rebind_shader = true; bool prev_use_skeleton = false; state.canvas_shader.set_conditional(CanvasShaderGLES2::USE_SKELETON, false); state.current_tex = RID(); - state.current_tex_ptr = NULL; + state.current_tex_ptr = nullptr; state.current_normal = RID(); state.canvas_texscreen_used = false; @@ -1475,14 +1475,14 @@ void RasterizerCanvasGLES2::canvas_render_items(Item *p_item_list, int p_z, cons } } - RasterizerStorageGLES2::Skeleton *skeleton = NULL; + RasterizerStorageGLES2::Skeleton *skeleton = nullptr; { //skeleton handling if (ci->skeleton.is_valid() && storage->skeleton_owner.owns(ci->skeleton)) { skeleton = storage->skeleton_owner.getornull(ci->skeleton); if (!skeleton->use_2d) { - skeleton = NULL; + skeleton = nullptr; } else { state.skeleton_transform = p_base_transform * skeleton->base_transform_2d; state.skeleton_transform_inverse = state.skeleton_transform.affine_inverse(); @@ -1490,7 +1490,7 @@ void RasterizerCanvasGLES2::canvas_render_items(Item *p_item_list, int p_z, cons } } - bool use_skeleton = skeleton != NULL; + bool use_skeleton = skeleton != nullptr; if (prev_use_skeleton != use_skeleton) { rebind_shader = true; state.canvas_shader.set_conditional(CanvasShaderGLES2::USE_SKELETON, use_skeleton); @@ -1513,13 +1513,13 @@ void RasterizerCanvasGLES2::canvas_render_items(Item *p_item_list, int p_z, cons if (material != canvas_last_material || rebind_shader) { - RasterizerStorageGLES2::Shader *shader_ptr = NULL; + RasterizerStorageGLES2::Shader *shader_ptr = nullptr; if (material_ptr) { shader_ptr = material_ptr->shader; - if (shader_ptr && shader_ptr->mode != VS::SHADER_CANVAS_ITEM) { - shader_ptr = NULL; // not a canvas item shader, don't use. + if (shader_ptr && shader_ptr->mode != RS::SHADER_CANVAS_ITEM) { + shader_ptr = nullptr; // not a canvas item shader, don't use. } } @@ -1542,7 +1542,7 @@ void RasterizerCanvasGLES2::canvas_render_items(Item *p_item_list, int p_z, cons if (shader_ptr != shader_cache) { if (shader_ptr->canvas_item.uses_time) { - VisualServerRaster::redraw_request(); + RenderingServerRaster::redraw_request(); } state.canvas_shader.set_custom_shader(shader_ptr->custom_code_id); @@ -1582,7 +1582,7 @@ void RasterizerCanvasGLES2::canvas_render_items(Item *p_item_list, int p_z, cons } if (t->redraw_if_visible) { - VisualServerRaster::redraw_request(); + RenderingServerRaster::redraw_request(); } t = t->get_ptr(); @@ -1674,7 +1674,7 @@ void RasterizerCanvasGLES2::canvas_render_items(Item *p_item_list, int p_z, cons _set_uniforms(); if (unshaded || (state.uniforms.final_modulate.a > 0.001 && (!shader_cache || shader_cache->canvas_item.light_mode != RasterizerStorageGLES2::Shader::CanvasItem::LIGHT_MODE_LIGHT_ONLY) && !ci->light_masked)) - _canvas_item_render_commands(p_item_list, NULL, reclip, material_ptr); + _canvas_item_render_commands(p_item_list, nullptr, reclip, material_ptr); rebind_shader = true; // hacked in for now. @@ -1682,7 +1682,7 @@ void RasterizerCanvasGLES2::canvas_render_items(Item *p_item_list, int p_z, cons Light *light = p_light; bool light_used = false; - VS::CanvasLightMode mode = VS::CANVAS_LIGHT_MODE_ADD; + RS::CanvasLightMode mode = RS::CANVAS_LIGHT_MODE_ADD; state.uniforms.final_modulate = ci->final_modulate; // remove the canvas modulate while (light) { @@ -1697,17 +1697,17 @@ void RasterizerCanvasGLES2::canvas_render_items(Item *p_item_list, int p_z, cons switch (mode) { - case VS::CANVAS_LIGHT_MODE_ADD: { + case RS::CANVAS_LIGHT_MODE_ADD: { glBlendEquation(GL_FUNC_ADD); glBlendFunc(GL_SRC_ALPHA, GL_ONE); } break; - case VS::CANVAS_LIGHT_MODE_SUB: { + case RS::CANVAS_LIGHT_MODE_SUB: { glBlendEquation(GL_FUNC_REVERSE_SUBTRACT); glBlendFunc(GL_SRC_ALPHA, GL_ONE); } break; - case VS::CANVAS_LIGHT_MODE_MIX: - case VS::CANVAS_LIGHT_MODE_MASK: { + case RS::CANVAS_LIGHT_MODE_MIX: + case RS::CANVAS_LIGHT_MODE_MASK: { glBlendEquation(GL_FUNC_ADD); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); @@ -1726,12 +1726,12 @@ void RasterizerCanvasGLES2::canvas_render_items(Item *p_item_list, int p_z, cons state.canvas_shader.set_conditional(CanvasShaderGLES2::USE_SHADOWS, has_shadow); if (has_shadow) { state.canvas_shader.set_conditional(CanvasShaderGLES2::SHADOW_USE_GRADIENT, light->shadow_gradient_length > 0); - state.canvas_shader.set_conditional(CanvasShaderGLES2::SHADOW_FILTER_NEAREST, light->shadow_filter == VS::CANVAS_LIGHT_FILTER_NONE); - state.canvas_shader.set_conditional(CanvasShaderGLES2::SHADOW_FILTER_PCF3, light->shadow_filter == VS::CANVAS_LIGHT_FILTER_PCF3); - state.canvas_shader.set_conditional(CanvasShaderGLES2::SHADOW_FILTER_PCF5, light->shadow_filter == VS::CANVAS_LIGHT_FILTER_PCF5); - state.canvas_shader.set_conditional(CanvasShaderGLES2::SHADOW_FILTER_PCF7, light->shadow_filter == VS::CANVAS_LIGHT_FILTER_PCF7); - state.canvas_shader.set_conditional(CanvasShaderGLES2::SHADOW_FILTER_PCF9, light->shadow_filter == VS::CANVAS_LIGHT_FILTER_PCF9); - state.canvas_shader.set_conditional(CanvasShaderGLES2::SHADOW_FILTER_PCF13, light->shadow_filter == VS::CANVAS_LIGHT_FILTER_PCF13); + state.canvas_shader.set_conditional(CanvasShaderGLES2::SHADOW_FILTER_NEAREST, light->shadow_filter == RS::CANVAS_LIGHT_FILTER_NONE); + state.canvas_shader.set_conditional(CanvasShaderGLES2::SHADOW_FILTER_PCF3, light->shadow_filter == RS::CANVAS_LIGHT_FILTER_PCF3); + state.canvas_shader.set_conditional(CanvasShaderGLES2::SHADOW_FILTER_PCF5, light->shadow_filter == RS::CANVAS_LIGHT_FILTER_PCF5); + state.canvas_shader.set_conditional(CanvasShaderGLES2::SHADOW_FILTER_PCF7, light->shadow_filter == RS::CANVAS_LIGHT_FILTER_PCF7); + state.canvas_shader.set_conditional(CanvasShaderGLES2::SHADOW_FILTER_PCF9, light->shadow_filter == RS::CANVAS_LIGHT_FILTER_PCF9); + state.canvas_shader.set_conditional(CanvasShaderGLES2::SHADOW_FILTER_PCF13, light->shadow_filter == RS::CANVAS_LIGHT_FILTER_PCF13); } state.canvas_shader.bind(); @@ -1753,9 +1753,9 @@ void RasterizerCanvasGLES2::canvas_render_items(Item *p_item_list, int p_z, cons } glActiveTexture(GL_TEXTURE0); - _canvas_item_render_commands(p_item_list, NULL, reclip, material_ptr); //redraw using light + _canvas_item_render_commands(p_item_list, nullptr, reclip, material_ptr); //redraw using light - state.using_light = NULL; + state.using_light = nullptr; } light = light->next_ptr; @@ -1846,7 +1846,7 @@ void RasterizerCanvasGLES2::canvas_light_shadow_buffer_update(RID p_buffer, cons glClearColor(1, 1, 1, 1); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - VS::CanvasOccluderPolygonCullMode cull = VS::CANVAS_OCCLUDER_POLYGON_CULL_DISABLED; + RS::CanvasOccluderPolygonCullMode cull = RS::CANVAS_OCCLUDER_POLYGON_CULL_DISABLED; for (int i = 0; i < 4; i++) { @@ -1903,31 +1903,31 @@ void RasterizerCanvasGLES2::canvas_light_shadow_buffer_update(RID p_buffer, cons state.canvas_shadow_shader.set_uniform(CanvasShadowShaderGLES2::WORLD_MATRIX, instance->xform_cache); - VS::CanvasOccluderPolygonCullMode transformed_cull_cache = instance->cull_cache; + RS::CanvasOccluderPolygonCullMode transformed_cull_cache = instance->cull_cache; - if (transformed_cull_cache != VS::CANVAS_OCCLUDER_POLYGON_CULL_DISABLED && + if (transformed_cull_cache != RS::CANVAS_OCCLUDER_POLYGON_CULL_DISABLED && (p_light_xform.basis_determinant() * instance->xform_cache.basis_determinant()) < 0) { transformed_cull_cache = - transformed_cull_cache == VS::CANVAS_OCCLUDER_POLYGON_CULL_CLOCKWISE ? - VS::CANVAS_OCCLUDER_POLYGON_CULL_COUNTER_CLOCKWISE : - VS::CANVAS_OCCLUDER_POLYGON_CULL_CLOCKWISE; + transformed_cull_cache == RS::CANVAS_OCCLUDER_POLYGON_CULL_CLOCKWISE ? + RS::CANVAS_OCCLUDER_POLYGON_CULL_COUNTER_CLOCKWISE : + RS::CANVAS_OCCLUDER_POLYGON_CULL_CLOCKWISE; } if (cull != transformed_cull_cache) { cull = transformed_cull_cache; switch (cull) { - case VS::CANVAS_OCCLUDER_POLYGON_CULL_DISABLED: { + case RS::CANVAS_OCCLUDER_POLYGON_CULL_DISABLED: { glDisable(GL_CULL_FACE); } break; - case VS::CANVAS_OCCLUDER_POLYGON_CULL_CLOCKWISE: { + case RS::CANVAS_OCCLUDER_POLYGON_CULL_CLOCKWISE: { glEnable(GL_CULL_FACE); glCullFace(GL_FRONT); } break; - case VS::CANVAS_OCCLUDER_POLYGON_CULL_COUNTER_CLOCKWISE: { + case RS::CANVAS_OCCLUDER_POLYGON_CULL_COUNTER_CLOCKWISE: { glEnable(GL_CULL_FACE); glCullFace(GL_BACK); @@ -1937,8 +1937,8 @@ void RasterizerCanvasGLES2::canvas_light_shadow_buffer_update(RID p_buffer, cons } glBindBuffer(GL_ARRAY_BUFFER, cc->vertex_id); - glEnableVertexAttribArray(VS::ARRAY_VERTEX); - glVertexAttribPointer(VS::ARRAY_VERTEX, 3, GL_FLOAT, false, 0, 0); + glEnableVertexAttribArray(RS::ARRAY_VERTEX); + glVertexAttribPointer(RS::ARRAY_VERTEX, 3, GL_FLOAT, false, 0, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, cc->index_id); glDrawElements(GL_TRIANGLES, cc->len * 3, GL_UNSIGNED_SHORT, 0); @@ -1979,8 +1979,8 @@ void RasterizerCanvasGLES2::reset_canvas() { void RasterizerCanvasGLES2::_bind_quad_buffer() { glBindBuffer(GL_ARRAY_BUFFER, data.canvas_quad_vertices); - glEnableVertexAttribArray(VS::ARRAY_VERTEX); - glVertexAttribPointer(VS::ARRAY_VERTEX, 2, GL_FLOAT, GL_FALSE, 0, NULL); + glEnableVertexAttribArray(RS::ARRAY_VERTEX); + glVertexAttribPointer(RS::ARRAY_VERTEX, 2, GL_FLOAT, GL_FALSE, 0, nullptr); } void RasterizerCanvasGLES2::draw_generic_textured_rect(const Rect2 &p_rect, const Rect2 &p_src) { @@ -1995,7 +1995,7 @@ void RasterizerCanvasGLES2::draw_lens_distortion_rect(const Rect2 &p_rect, float if (storage->frame.current_rt) { half_size = Vector2(storage->frame.current_rt->width, storage->frame.current_rt->height); } else { - half_size = OS::get_singleton()->get_window_size(); + half_size = DisplayServer::get_singleton()->window_get_size(); } half_size *= 0.5; Vector2 offset((p_rect.position.x - half_size.x) / half_size.x, (p_rect.position.y - half_size.y) / half_size.y); @@ -2022,14 +2022,14 @@ void RasterizerCanvasGLES2::draw_lens_distortion_rect(const Rect2 &p_rect, float // and cleanup glBindBuffer(GL_ARRAY_BUFFER, 0); - for (int i = 0; i < VS::ARRAY_MAX; i++) { + for (int i = 0; i < RS::ARRAY_MAX; i++) { glDisableVertexAttribArray(i); } } void RasterizerCanvasGLES2::draw_window_margins(int *black_margin, RID *black_image) { - Vector2 window_size = OS::get_singleton()->get_window_size(); + Vector2 window_size = DisplayServer::get_singleton()->window_get_size(); int window_h = window_size.height; int window_w = window_size.width; @@ -2117,7 +2117,7 @@ void RasterizerCanvasGLES2::initialize() { poly_size = MAX(poly_size, (2 + 2 + 4) * 4 * sizeof(float)); glGenBuffers(1, &data.polygon_buffer); glBindBuffer(GL_ARRAY_BUFFER, data.polygon_buffer); - glBufferData(GL_ARRAY_BUFFER, poly_size, NULL, GL_DYNAMIC_DRAW); + glBufferData(GL_ARRAY_BUFFER, poly_size, nullptr, GL_DYNAMIC_DRAW); data.polygon_buffer_size = poly_size; @@ -2128,7 +2128,7 @@ void RasterizerCanvasGLES2::initialize() { index_size *= 1024; // kb glGenBuffers(1, &data.polygon_index_buffer); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, data.polygon_index_buffer); - glBufferData(GL_ELEMENT_ARRAY_BUFFER, index_size, NULL, GL_DYNAMIC_DRAW); + glBufferData(GL_ELEMENT_ARRAY_BUFFER, index_size, nullptr, GL_DYNAMIC_DRAW); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); data.polygon_index_buffer_size = index_size; @@ -2140,7 +2140,7 @@ void RasterizerCanvasGLES2::initialize() { glGenBuffers(1, &data.ninepatch_vertices); glBindBuffer(GL_ARRAY_BUFFER, data.ninepatch_vertices); - glBufferData(GL_ARRAY_BUFFER, sizeof(float) * (16 + 16) * 2, NULL, GL_DYNAMIC_DRAW); + glBufferData(GL_ARRAY_BUFFER, sizeof(float) * (16 + 16) * 2, nullptr, GL_DYNAMIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, 0); @@ -2210,7 +2210,7 @@ void RasterizerCanvasGLES2::initialize() { state.canvas_shader.set_conditional(CanvasShaderGLES2::USE_PIXEL_SNAP, GLOBAL_DEF("rendering/quality/2d/use_pixel_snap", false)); - state.using_light = NULL; + state.using_light = nullptr; state.using_transparent_rt = false; state.using_skeleton = false; } diff --git a/drivers/gles2/rasterizer_canvas_gles2.h b/drivers/gles2/rasterizer_canvas_gles2.h index f6ae6a60c0..2d6355e948 100644 --- a/drivers/gles2/rasterizer_canvas_gles2.h +++ b/drivers/gles2/rasterizer_canvas_gles2.h @@ -32,7 +32,7 @@ #define RASTERIZERCANVASGLES2_H #include "rasterizer_storage_gles2.h" -#include "servers/visual/rasterizer.h" +#include "servers/rendering/rasterizer.h" #include "shaders/canvas.glsl.gen.h" #include "shaders/lens_distorted.glsl.gen.h" @@ -116,7 +116,7 @@ public: virtual void canvas_end(); _FORCE_INLINE_ void _draw_gui_primitive(int p_points, const Vector2 *p_vertices, const Color *p_colors, const Vector2 *p_uvs); - _FORCE_INLINE_ void _draw_polygon(const int *p_indices, int p_index_count, int p_vertex_count, const Vector2 *p_vertices, const Vector2 *p_uvs, const Color *p_colors, bool p_singlecolor, const float *p_weights = NULL, const int *p_bones = NULL); + _FORCE_INLINE_ void _draw_polygon(const int *p_indices, int p_index_count, int p_vertex_count, const Vector2 *p_vertices, const Vector2 *p_uvs, const Color *p_colors, bool p_singlecolor, const float *p_weights = nullptr, const int *p_bones = nullptr); _FORCE_INLINE_ void _draw_generic(GLuint p_primitive, int p_vertex_count, const Vector2 *p_vertices, const Vector2 *p_uvs, const Color *p_colors, bool p_singlecolor); _FORCE_INLINE_ void _draw_generic_indices(GLuint p_primitive, const int *p_indices, int p_index_count, int p_vertex_count, const Vector2 *p_vertices, const Vector2 *p_uvs, const Color *p_colors, bool p_singlecolor); diff --git a/drivers/gles2/rasterizer_gles2.cpp b/drivers/gles2/rasterizer_gles2.cpp index 02b956fd44..37b729d568 100644 --- a/drivers/gles2/rasterizer_gles2.cpp +++ b/drivers/gles2/rasterizer_gles2.cpp @@ -221,7 +221,7 @@ void RasterizerGLES2::initialize() { if (OS::get_singleton()->is_stdout_verbose()) { if (GLAD_GL_ARB_debug_output) { glEnable(_EXT_DEBUG_OUTPUT_SYNCHRONOUS_ARB); - glDebugMessageCallbackARB(_gl_debug_print, NULL); + glDebugMessageCallbackARB(_gl_debug_print, nullptr); glEnable(_EXT_DEBUG_OUTPUT); } else { print_line("OpenGL debugging not supported!"); @@ -233,12 +233,12 @@ void RasterizerGLES2::initialize() { #ifdef CAN_DEBUG #ifdef GLES_OVER_GL if (OS::get_singleton()->is_stdout_verbose() && GLAD_GL_ARB_debug_output) { - glDebugMessageControlARB(_EXT_DEBUG_SOURCE_API_ARB, _EXT_DEBUG_TYPE_ERROR_ARB, _EXT_DEBUG_SEVERITY_HIGH_ARB, 0, NULL, GL_TRUE); - glDebugMessageControlARB(_EXT_DEBUG_SOURCE_API_ARB, _EXT_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB, _EXT_DEBUG_SEVERITY_HIGH_ARB, 0, NULL, GL_TRUE); - glDebugMessageControlARB(_EXT_DEBUG_SOURCE_API_ARB, _EXT_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB, _EXT_DEBUG_SEVERITY_HIGH_ARB, 0, NULL, GL_TRUE); - glDebugMessageControlARB(_EXT_DEBUG_SOURCE_API_ARB, _EXT_DEBUG_TYPE_PORTABILITY_ARB, _EXT_DEBUG_SEVERITY_HIGH_ARB, 0, NULL, GL_TRUE); - glDebugMessageControlARB(_EXT_DEBUG_SOURCE_API_ARB, _EXT_DEBUG_TYPE_PERFORMANCE_ARB, _EXT_DEBUG_SEVERITY_HIGH_ARB, 0, NULL, GL_TRUE); - glDebugMessageControlARB(_EXT_DEBUG_SOURCE_API_ARB, _EXT_DEBUG_TYPE_OTHER_ARB, _EXT_DEBUG_SEVERITY_HIGH_ARB, 0, NULL, GL_TRUE); + glDebugMessageControlARB(_EXT_DEBUG_SOURCE_API_ARB, _EXT_DEBUG_TYPE_ERROR_ARB, _EXT_DEBUG_SEVERITY_HIGH_ARB, 0, nullptr, GL_TRUE); + glDebugMessageControlARB(_EXT_DEBUG_SOURCE_API_ARB, _EXT_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB, _EXT_DEBUG_SEVERITY_HIGH_ARB, 0, nullptr, GL_TRUE); + glDebugMessageControlARB(_EXT_DEBUG_SOURCE_API_ARB, _EXT_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB, _EXT_DEBUG_SEVERITY_HIGH_ARB, 0, nullptr, GL_TRUE); + glDebugMessageControlARB(_EXT_DEBUG_SOURCE_API_ARB, _EXT_DEBUG_TYPE_PORTABILITY_ARB, _EXT_DEBUG_SEVERITY_HIGH_ARB, 0, nullptr, GL_TRUE); + glDebugMessageControlARB(_EXT_DEBUG_SOURCE_API_ARB, _EXT_DEBUG_TYPE_PERFORMANCE_ARB, _EXT_DEBUG_SEVERITY_HIGH_ARB, 0, nullptr, GL_TRUE); + glDebugMessageControlARB(_EXT_DEBUG_SOURCE_API_ARB, _EXT_DEBUG_TYPE_OTHER_ARB, _EXT_DEBUG_SEVERITY_HIGH_ARB, 0, nullptr, GL_TRUE); /* glDebugMessageInsertARB( GL_DEBUG_SOURCE_API_ARB, GL_DEBUG_TYPE_OTHER_ARB, 1, @@ -256,14 +256,14 @@ void RasterizerGLES2::initialize() { print_line("godot: ENABLING GL DEBUG"); glEnable(_EXT_DEBUG_OUTPUT_SYNCHRONOUS_ARB); - callback(_gl_debug_print, NULL); + callback(_gl_debug_print, nullptr); glEnable(_EXT_DEBUG_OUTPUT); } } #endif // GLES_OVER_GL #endif // CAN_DEBUG - print_line("OpenGL ES 2.0 Renderer: " + VisualServer::get_singleton()->get_video_adapter_name()); + print_line("OpenGL ES 2.0 Renderer: " + RenderingServer::get_singleton()->get_video_adapter_name()); storage->initialize(); canvas->initialize(); scene->initialize(); @@ -316,15 +316,15 @@ void RasterizerGLES2::set_current_render_target(RID p_render_target) { glViewport(0, 0, rt->width, rt->height); } else { - storage->frame.current_rt = NULL; + storage->frame.current_rt = nullptr; storage->frame.clear_request = false; - glViewport(0, 0, OS::get_singleton()->get_window_size().width, OS::get_singleton()->get_window_size().height); + glViewport(0, 0, DisplayServer::get_singleton()->window_get_size().width, DisplayServer::get_singleton()->window_get_size().height); glBindFramebuffer(GL_FRAMEBUFFER, RasterizerStorageGLES2::system_fbo); } } void RasterizerGLES2::restore_render_target(bool p_3d_was_drawn) { - ERR_FAIL_COND(storage->frame.current_rt == NULL); + ERR_FAIL_COND(storage->frame.current_rt == nullptr); RasterizerStorageGLES2::RenderTarget *rt = storage->frame.current_rt; glBindFramebuffer(GL_FRAMEBUFFER, rt->fbo); glViewport(0, 0, rt->width, rt->height); @@ -359,7 +359,7 @@ void RasterizerGLES2::set_boot_image(const Ref<Image> &p_image, const Color &p_c canvas->canvas_begin(); RID texture = storage->texture_create(); - storage->texture_allocate(texture, p_image->get_width(), p_image->get_height(), 0, p_image->get_format(), VS::TEXTURE_TYPE_2D, p_use_filter ? VS::TEXTURE_FLAG_FILTER : 0); + storage->texture_allocate(texture, p_image->get_width(), p_image->get_height(), 0, p_image->get_format(), RS::TEXTURE_TYPE_2D, p_use_filter ? RS::TEXTURE_FLAG_FILTER : 0); storage->texture_set_data(texture, p_image); Rect2 imgrect(0, 0, p_image->get_width(), p_image->get_height()); diff --git a/drivers/gles2/rasterizer_gles2.h b/drivers/gles2/rasterizer_gles2.h index 9a5501f13d..027a634ae8 100644 --- a/drivers/gles2/rasterizer_gles2.h +++ b/drivers/gles2/rasterizer_gles2.h @@ -34,7 +34,7 @@ #include "rasterizer_canvas_gles2.h" #include "rasterizer_scene_gles2.h" #include "rasterizer_storage_gles2.h" -#include "servers/visual/rasterizer.h" +#include "servers/rendering/rasterizer.h" class RasterizerGLES2 : public Rasterizer { diff --git a/drivers/gles2/rasterizer_scene_gles2.cpp b/drivers/gles2/rasterizer_scene_gles2.cpp index c433886545..bdf0559f58 100644 --- a/drivers/gles2/rasterizer_scene_gles2.cpp +++ b/drivers/gles2/rasterizer_scene_gles2.cpp @@ -37,7 +37,7 @@ #include "core/vmap.h" #include "rasterizer_canvas_gles2.h" #include "servers/camera/camera_feed.h" -#include "servers/visual/visual_server_raster.h" +#include "servers/rendering/rendering_server_raster.h" #ifndef GLES_OVER_GL #define glClearDepth glClearDepthf @@ -142,7 +142,7 @@ void RasterizerSceneGLES2::shadow_atlas_set_size(RID p_atlas, int p_size) { glGenTextures(1, &shadow_atlas->color); glBindTexture(GL_TEXTURE_2D, shadow_atlas->color); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, shadow_atlas->size, shadow_atlas->size, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, shadow_atlas->size, shadow_atlas->size, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); @@ -152,7 +152,7 @@ void RasterizerSceneGLES2::shadow_atlas_set_size(RID p_atlas, int p_size) { //just depth texture glGenTextures(1, &shadow_atlas->depth); glBindTexture(GL_TEXTURE_2D, shadow_atlas->depth); - glTexImage2D(GL_TEXTURE_2D, 0, storage->config.depth_internalformat, shadow_atlas->size, shadow_atlas->size, 0, GL_DEPTH_COMPONENT, storage->config.depth_type, NULL); + glTexImage2D(GL_TEXTURE_2D, 0, storage->config.depth_internalformat, shadow_atlas->size, shadow_atlas->size, 0, GL_DEPTH_COMPONENT, storage->config.depth_type, nullptr); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); @@ -456,10 +456,10 @@ int RasterizerSceneGLES2::get_directional_light_shadow_size(RID p_light_intance) ERR_FAIL_COND_V(!light_instance, 0); switch (light_instance->light_ptr->directional_shadow_mode) { - case VS::LIGHT_DIRECTIONAL_SHADOW_ORTHOGONAL: + case RS::LIGHT_DIRECTIONAL_SHADOW_ORTHOGONAL: break; //none - case VS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_2_SPLITS: - case VS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_4_SPLITS: + case RS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_2_SPLITS: + case RS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_4_SPLITS: shadow_size /= 2; break; } @@ -525,7 +525,7 @@ bool RasterizerSceneGLES2::reflection_probe_instance_needs_redraw(RID p_instance const ReflectionProbeInstance *rpi = reflection_probe_instance_owner.getornull(p_instance); ERR_FAIL_COND_V(!rpi, false); - bool need_redraw = rpi->probe_ptr->resolution != rpi->current_resolution || rpi->dirty || rpi->probe_ptr->update_mode == VS::REFLECTION_PROBE_UPDATE_ALWAYS; + bool need_redraw = rpi->probe_ptr->resolution != rpi->current_resolution || rpi->dirty || rpi->probe_ptr->update_mode == RS::REFLECTION_PROBE_UPDATE_ALWAYS; rpi->dirty = false; return need_redraw; } @@ -566,7 +566,7 @@ bool RasterizerSceneGLES2::reflection_probe_instance_begin_render(RID p_instance // Mobile hardware (PowerVR specially) prefers this approach, // the previous approach with manual lod levels kills the game. for (int i = 0; i < 6; i++) { - glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, internal_format, size, size, 0, format, type, NULL); + glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, internal_format, size, size, 0, format, type, nullptr); } glGenerateMipmap(GL_TEXTURE_CUBE_MAP); @@ -575,7 +575,7 @@ bool RasterizerSceneGLES2::reflection_probe_instance_begin_render(RID p_instance for (int i = 0; i < 6; i++) { glBindFramebuffer(GL_FRAMEBUFFER, rpi->fbo[i]); glBindTexture(GL_TEXTURE_2D, rpi->color[i]); - glTexImage2D(GL_TEXTURE_2D, 0, internal_format, size, size, 0, format, type, NULL); + glTexImage2D(GL_TEXTURE_2D, 0, internal_format, size, size, 0, format, type, nullptr); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, rpi->color[i], 0); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rpi->depth); GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); @@ -610,7 +610,7 @@ bool RasterizerSceneGLES2::reflection_probe_instance_postprocess_step(RID p_inst glDisable(GL_BLEND); glDepthMask(GL_FALSE); - for (int i = 0; i < VS::ARRAY_MAX - 1; i++) { + for (int i = 0; i < RS::ARRAY_MAX - 1; i++) { glDisableVertexAttribArray(i); } } @@ -646,7 +646,7 @@ bool RasterizerSceneGLES2::reflection_probe_instance_postprocess_step(RID p_inst glActiveTexture(GL_TEXTURE3); glBindTexture(GL_TEXTURE_2D, storage->resources.mipmap_blur_color); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, size, size, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, size, size, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, storage->resources.mipmap_blur_color, 0); glViewport(0, 0, size, size); glActiveTexture(GL_TEXTURE0); @@ -690,7 +690,7 @@ RID RasterizerSceneGLES2::environment_create() { return environment_owner.make_rid(env); } -void RasterizerSceneGLES2::environment_set_background(RID p_env, VS::EnvironmentBG p_bg) { +void RasterizerSceneGLES2::environment_set_background(RID p_env, RS::EnvironmentBG p_bg) { Environment *env = environment_owner.getornull(p_env); ERR_FAIL_COND(!env); @@ -755,7 +755,7 @@ void RasterizerSceneGLES2::environment_set_camera_feed_id(RID p_env, int p_camer env->camera_feed_id = p_camera_feed_id; } -void RasterizerSceneGLES2::environment_set_dof_blur_far(RID p_env, bool p_enable, float p_distance, float p_transition, float p_amount, VS::EnvironmentDOFBlurQuality p_quality) { +void RasterizerSceneGLES2::environment_set_dof_blur_far(RID p_env, bool p_enable, float p_distance, float p_transition, float p_amount, RS::EnvironmentDOFBlurQuality p_quality) { Environment *env = environment_owner.getornull(p_env); ERR_FAIL_COND(!env); @@ -767,7 +767,7 @@ void RasterizerSceneGLES2::environment_set_dof_blur_far(RID p_env, bool p_enable env->dof_blur_far_quality = p_quality; } -void RasterizerSceneGLES2::environment_set_dof_blur_near(RID p_env, bool p_enable, float p_distance, float p_transition, float p_amount, VS::EnvironmentDOFBlurQuality p_quality) { +void RasterizerSceneGLES2::environment_set_dof_blur_near(RID p_env, bool p_enable, float p_distance, float p_transition, float p_amount, RS::EnvironmentDOFBlurQuality p_quality) { Environment *env = environment_owner.getornull(p_env); ERR_FAIL_COND(!env); @@ -779,7 +779,7 @@ void RasterizerSceneGLES2::environment_set_dof_blur_near(RID p_env, bool p_enabl env->dof_blur_near_quality = p_quality; } -void RasterizerSceneGLES2::environment_set_glow(RID p_env, bool p_enable, int p_level_flags, float p_intensity, float p_strength, float p_bloom_threshold, VS::EnvironmentGlowBlendMode p_blend_mode, float p_hdr_bleed_threshold, float p_hdr_bleed_scale, float p_hdr_luminance_cap, bool p_bicubic_upscale) { +void RasterizerSceneGLES2::environment_set_glow(RID p_env, bool p_enable, int p_level_flags, float p_intensity, float p_strength, float p_bloom_threshold, RS::EnvironmentGlowBlendMode p_blend_mode, float p_hdr_bleed_threshold, float p_hdr_bleed_scale, float p_hdr_luminance_cap, bool p_bicubic_upscale) { Environment *env = environment_owner.getornull(p_env); ERR_FAIL_COND(!env); @@ -806,12 +806,12 @@ void RasterizerSceneGLES2::environment_set_ssr(RID p_env, bool p_enable, int p_m ERR_FAIL_COND(!env); } -void RasterizerSceneGLES2::environment_set_ssao(RID p_env, bool p_enable, float p_radius, float p_intensity, float p_radius2, float p_intensity2, float p_bias, float p_light_affect, float p_ao_channel_affect, const Color &p_color, VS::EnvironmentSSAOQuality p_quality, VisualServer::EnvironmentSSAOBlur p_blur, float p_bilateral_sharpness) { +void RasterizerSceneGLES2::environment_set_ssao(RID p_env, bool p_enable, float p_radius, float p_intensity, float p_radius2, float p_intensity2, float p_bias, float p_light_affect, float p_ao_channel_affect, const Color &p_color, RS::EnvironmentSSAOQuality p_quality, RenderingServer::EnvironmentSSAOBlur p_blur, float p_bilateral_sharpness) { Environment *env = environment_owner.getornull(p_env); ERR_FAIL_COND(!env); } -void RasterizerSceneGLES2::environment_set_tonemap(RID p_env, VS::EnvironmentToneMapper p_tone_mapper, float p_exposure, float p_white, bool p_auto_exposure, float p_min_luminance, float p_max_luminance, float p_auto_exp_speed, float p_auto_exp_scale) { +void RasterizerSceneGLES2::environment_set_tonemap(RID p_env, RS::EnvironmentToneMapper p_tone_mapper, float p_exposure, float p_white, bool p_auto_exposure, float p_min_luminance, float p_max_luminance, float p_auto_exp_speed, float p_auto_exp_scale) { Environment *env = environment_owner.getornull(p_env); ERR_FAIL_COND(!env); } @@ -866,9 +866,9 @@ bool RasterizerSceneGLES2::is_environment(RID p_env) { return environment_owner.owns(p_env); } -VS::EnvironmentBG RasterizerSceneGLES2::environment_get_background(RID p_env) { +RS::EnvironmentBG RasterizerSceneGLES2::environment_get_background(RID p_env) { const Environment *env = environment_owner.getornull(p_env); - ERR_FAIL_COND_V(!env, VS::ENV_BG_MAX); + ERR_FAIL_COND_V(!env, RS::ENV_BG_MAX); return env->bg_mode; } @@ -914,7 +914,7 @@ void RasterizerSceneGLES2::light_instance_set_shadow_transform(RID p_light_insta LightInstance *light_instance = light_instance_owner.getornull(p_light_instance); ERR_FAIL_COND(!light_instance); - if (light_instance->light_ptr->type != VS::LIGHT_DIRECTIONAL) { + if (light_instance->light_ptr->type != RS::LIGHT_DIRECTIONAL) { p_pass = 0; } @@ -956,7 +956,7 @@ void RasterizerSceneGLES2::gi_probe_instance_set_bounds(RID p_probe, const Vecto void RasterizerSceneGLES2::_add_geometry(RasterizerStorageGLES2::Geometry *p_geometry, InstanceBase *p_instance, RasterizerStorageGLES2::GeometryOwner *p_owner, int p_material, bool p_depth_pass, bool p_shadow_pass) { - RasterizerStorageGLES2::Material *material = NULL; + RasterizerStorageGLES2::Material *material = nullptr; RID material_src; if (p_instance->material_override.is_valid()) { @@ -971,7 +971,7 @@ void RasterizerSceneGLES2::_add_geometry(RasterizerStorageGLES2::Geometry *p_geo material = storage->material_owner.getornull(material_src); if (!material->shader || !material->shader->valid) { - material = NULL; + material = nullptr; } } @@ -1022,7 +1022,7 @@ 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) { + if (p_instance->cast_shadows == RS::SHADOW_CASTING_SETTING_DOUBLE_SIDED) { 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 { @@ -1048,7 +1048,7 @@ void RasterizerSceneGLES2::_add_geometry_with_material(RasterizerStorageGLES2::G e->use_accum = false; e->light_index = RenderList::MAX_LIGHTS; e->use_accum_ptr = &e->use_accum; - e->instancing = (e->instance->base_type == VS::INSTANCE_MULTIMESH) ? 1 : 0; + e->instancing = (e->instance->base_type == RS::INSTANCE_MULTIMESH) ? 1 : 0; e->front_facing = false; if (e->geometry->last_pass != render_pass) { @@ -1162,7 +1162,7 @@ void RasterizerSceneGLES2::_add_geometry_with_material(RasterizerStorageGLES2::G //directional sort key e->light_type1 = 1; - e->light_type2 = li->light_ptr->type == VisualServer::LIGHT_OMNI ? 0 : 1; + e->light_type2 = li->light_ptr->type == RenderingServer::LIGHT_OMNI ? 0 : 1; e->light_index = li->light_index; copy = true; @@ -1181,7 +1181,7 @@ void RasterizerSceneGLES2::_add_geometry_with_material(RasterizerStorageGLES2::G // do not add anything here, as lights are duplicated elements.. if (p_material->shader->spatial.uses_time) { - VisualServerRaster::redraw_request(); + RenderingServerRaster::redraw_request(); } } @@ -1224,7 +1224,7 @@ void RasterizerSceneGLES2::_fill_render_list(InstanceBase **p_cull_result, int p switch (instance->base_type) { - case VS::INSTANCE_MESH: { + case RS::INSTANCE_MESH: { RasterizerStorageGLES2::Mesh *mesh = storage->mesh_owner.getornull(instance->base); ERR_CONTINUE(!mesh); @@ -1236,12 +1236,12 @@ void RasterizerSceneGLES2::_fill_render_list(InstanceBase **p_cull_result, int p RasterizerStorageGLES2::Surface *surface = mesh->surfaces[j]; - _add_geometry(surface, instance, NULL, material_index, p_depth_pass, p_shadow_pass); + _add_geometry(surface, instance, nullptr, material_index, p_depth_pass, p_shadow_pass); } } break; - case VS::INSTANCE_MULTIMESH: { + case RS::INSTANCE_MULTIMESH: { RasterizerStorageGLES2::MultiMesh *multi_mesh = storage->multimesh_owner.getornull(instance->base); ERR_CONTINUE(!multi_mesh); @@ -1260,11 +1260,11 @@ void RasterizerSceneGLES2::_fill_render_list(InstanceBase **p_cull_result, int p } } break; - case VS::INSTANCE_IMMEDIATE: { + case RS::INSTANCE_IMMEDIATE: { RasterizerStorageGLES2::Immediate *im = storage->immediate_owner.getornull(instance->base); ERR_CONTINUE(!im); - _add_geometry(im, instance, NULL, -1, p_depth_pass, p_shadow_pass); + _add_geometry(im, instance, nullptr, -1, p_depth_pass, p_shadow_pass); } break; @@ -1426,7 +1426,7 @@ bool RasterizerSceneGLES2::_setup_material(RasterizerStorageGLES2::Material *p_m } if (t->redraw_if_visible) { //must check before proxy because this is often used with proxies - VisualServerRaster::redraw_request(); + RenderingServerRaster::redraw_request(); } t = t->get_ptr(); @@ -1459,7 +1459,7 @@ void RasterizerSceneGLES2::_setup_geometry(RenderList::Element *p_element, Raste switch (p_element->instance->base_type) { - case VS::INSTANCE_MESH: { + case RS::INSTANCE_MESH: { RasterizerStorageGLES2::Surface *s = static_cast<RasterizerStorageGLES2::Surface *>(p_element->geometry); glBindBuffer(GL_ARRAY_BUFFER, s->vertex_id); @@ -1468,18 +1468,18 @@ void RasterizerSceneGLES2::_setup_geometry(RenderList::Element *p_element, Raste glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, s->index_id); } - for (int i = 0; i < VS::ARRAY_MAX - 1; i++) { + for (int i = 0; i < RS::ARRAY_MAX - 1; i++) { if (s->attribs[i].enabled) { glEnableVertexAttribArray(i); glVertexAttribPointer(s->attribs[i].index, s->attribs[i].size, s->attribs[i].type, s->attribs[i].normalized, s->attribs[i].stride, CAST_INT_TO_UCHAR_PTR(s->attribs[i].offset)); } else { glDisableVertexAttribArray(i); switch (i) { - case VS::ARRAY_NORMAL: { - glVertexAttrib4f(VS::ARRAY_NORMAL, 0.0, 0.0, 1, 1); + case RS::ARRAY_NORMAL: { + glVertexAttrib4f(RS::ARRAY_NORMAL, 0.0, 0.0, 1, 1); } break; - case VS::ARRAY_COLOR: { - glVertexAttrib4f(VS::ARRAY_COLOR, 1, 1, 1, 1); + case RS::ARRAY_COLOR: { + glVertexAttrib4f(RS::ARRAY_COLOR, 1, 1, 1, 1); } break; default: { @@ -1502,7 +1502,7 @@ void RasterizerSceneGLES2::_setup_geometry(RenderList::Element *p_element, Raste Vector<float> &transform_buffer = storage->resources.skeleton_transform_cpu_buffer; - if (!s->attribs[VS::ARRAY_BONES].enabled || !s->attribs[VS::ARRAY_WEIGHTS].enabled) { + if (!s->attribs[RS::ARRAY_BONES].enabled || !s->attribs[RS::ARRAY_WEIGHTS].enabled) { break; // the whole instance has a skeleton, but this surface is not affected by it. } @@ -1511,10 +1511,10 @@ void RasterizerSceneGLES2::_setup_geometry(RenderList::Element *p_element, Raste transform_buffer.resize(s->array_len * 12); } - const size_t bones_offset = s->attribs[VS::ARRAY_BONES].offset; - const size_t bones_stride = s->attribs[VS::ARRAY_BONES].stride; - const size_t bone_weight_offset = s->attribs[VS::ARRAY_WEIGHTS].offset; - const size_t bone_weight_stride = s->attribs[VS::ARRAY_WEIGHTS].stride; + const size_t bones_offset = s->attribs[RS::ARRAY_BONES].offset; + const size_t bones_stride = s->attribs[RS::ARRAY_BONES].stride; + const size_t bone_weight_offset = s->attribs[RS::ARRAY_WEIGHTS].offset; + const size_t bone_weight_stride = s->attribs[RS::ARRAY_WEIGHTS].stride; { float *write = transform_buffer.ptrw(); @@ -1530,7 +1530,7 @@ void RasterizerSceneGLES2::_setup_geometry(RenderList::Element *p_element, Raste size_t bones[4]; float bone_weight[4]; - if (s->attribs[VS::ARRAY_BONES].type == GL_UNSIGNED_BYTE) { + if (s->attribs[RS::ARRAY_BONES].type == GL_UNSIGNED_BYTE) { // read as byte const uint8_t *bones_ptr = vertex_data + bones_offset + (i * bones_stride); bones[0] = bones_ptr[0]; @@ -1546,7 +1546,7 @@ void RasterizerSceneGLES2::_setup_geometry(RenderList::Element *p_element, Raste bones[3] = bones_ptr[3]; } - if (s->attribs[VS::ARRAY_WEIGHTS].type == GL_FLOAT) { + if (s->attribs[RS::ARRAY_WEIGHTS].type == GL_FLOAT) { // read as float const float *weight_ptr = (const float *)(vertex_data + bone_weight_offset + (i * bone_weight_stride)); bone_weight[0] = weight_ptr[0]; @@ -1621,7 +1621,7 @@ void RasterizerSceneGLES2::_setup_geometry(RenderList::Element *p_element, Raste } break; - case VS::INSTANCE_MULTIMESH: { + case RS::INSTANCE_MULTIMESH: { RasterizerStorageGLES2::Surface *s = static_cast<RasterizerStorageGLES2::Surface *>(p_element->geometry); glBindBuffer(GL_ARRAY_BUFFER, s->vertex_id); @@ -1630,18 +1630,18 @@ void RasterizerSceneGLES2::_setup_geometry(RenderList::Element *p_element, Raste glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, s->index_id); } - for (int i = 0; i < VS::ARRAY_MAX - 1; i++) { + for (int i = 0; i < RS::ARRAY_MAX - 1; i++) { if (s->attribs[i].enabled) { glEnableVertexAttribArray(i); glVertexAttribPointer(s->attribs[i].index, s->attribs[i].size, s->attribs[i].type, s->attribs[i].normalized, s->attribs[i].stride, CAST_INT_TO_UCHAR_PTR(s->attribs[i].offset)); } else { glDisableVertexAttribArray(i); switch (i) { - case VS::ARRAY_NORMAL: { - glVertexAttrib4f(VS::ARRAY_NORMAL, 0.0, 0.0, 1, 1); + case RS::ARRAY_NORMAL: { + glVertexAttrib4f(RS::ARRAY_NORMAL, 0.0, 0.0, 1, 1); } break; - case VS::ARRAY_COLOR: { - glVertexAttrib4f(VS::ARRAY_COLOR, 1, 1, 1, 1); + case RS::ARRAY_COLOR: { + glVertexAttrib4f(RS::ARRAY_COLOR, 1, 1, 1, 1); } break; default: { @@ -1662,7 +1662,7 @@ void RasterizerSceneGLES2::_setup_geometry(RenderList::Element *p_element, Raste } break; - case VS::INSTANCE_IMMEDIATE: { + case RS::INSTANCE_IMMEDIATE: { } break; default: { @@ -1674,7 +1674,7 @@ void RasterizerSceneGLES2::_render_geometry(RenderList::Element *p_element) { switch (p_element->instance->base_type) { - case VS::INSTANCE_MESH: { + case RS::INSTANCE_MESH: { RasterizerStorageGLES2::Surface *s = static_cast<RasterizerStorageGLES2::Surface *>(p_element->geometry); @@ -1688,22 +1688,22 @@ void RasterizerSceneGLES2::_render_geometry(RenderList::Element *p_element) { storage->info.render.vertices_count += s->array_len; } /* - if (p_element->instance->skeleton.is_valid() && s->attribs[VS::ARRAY_BONES].enabled && s->attribs[VS::ARRAY_WEIGHTS].enabled) { + if (p_element->instance->skeleton.is_valid() && s->attribs[RS::ARRAY_BONES].enabled && s->attribs[RS::ARRAY_WEIGHTS].enabled) { //clean up after skeleton glBindBuffer(GL_ARRAY_BUFFER, storage->resources.skeleton_transform_buffer); - glDisableVertexAttribArray(VS::ARRAY_MAX + 0); - glDisableVertexAttribArray(VS::ARRAY_MAX + 1); - glDisableVertexAttribArray(VS::ARRAY_MAX + 2); + glDisableVertexAttribArray(RS::ARRAY_MAX + 0); + glDisableVertexAttribArray(RS::ARRAY_MAX + 1); + glDisableVertexAttribArray(RS::ARRAY_MAX + 2); - glVertexAttrib4f(VS::ARRAY_MAX + 0, 1, 0, 0, 0); - glVertexAttrib4f(VS::ARRAY_MAX + 1, 0, 1, 0, 0); - glVertexAttrib4f(VS::ARRAY_MAX + 2, 0, 0, 1, 0); + glVertexAttrib4f(RS::ARRAY_MAX + 0, 1, 0, 0, 0); + glVertexAttrib4f(RS::ARRAY_MAX + 1, 0, 1, 0, 0); + glVertexAttrib4f(RS::ARRAY_MAX + 2, 0, 0, 1, 0); } */ } break; - case VS::INSTANCE_MULTIMESH: { + case RS::INSTANCE_MULTIMESH: { RasterizerStorageGLES2::MultiMesh *multi_mesh = static_cast<RasterizerStorageGLES2::MultiMesh *>(p_element->owner); RasterizerStorageGLES2::Surface *s = static_cast<RasterizerStorageGLES2::Surface *>(p_element->geometry); @@ -1734,7 +1734,7 @@ void RasterizerSceneGLES2::_render_geometry(RenderList::Element *p_element) { } if (multi_mesh->color_floats) { - if (multi_mesh->color_format == VS::MULTIMESH_COLOR_8BIT) { + if (multi_mesh->color_format == RS::MULTIMESH_COLOR_8BIT) { uint8_t *color_data = (uint8_t *)(buffer + color_ofs); glVertexAttrib4f(INSTANCE_ATTRIB_BASE + 3, color_data[0] / 255.0, color_data[1] / 255.0, color_data[2] / 255.0, color_data[3] / 255.0); } else { @@ -1745,7 +1745,7 @@ void RasterizerSceneGLES2::_render_geometry(RenderList::Element *p_element) { } if (multi_mesh->custom_data_floats) { - if (multi_mesh->custom_data_format == VS::MULTIMESH_CUSTOM_DATA_8BIT) { + if (multi_mesh->custom_data_format == RS::MULTIMESH_CUSTOM_DATA_8BIT) { uint8_t *custom_data = (uint8_t *)(buffer + custom_data_ofs); glVertexAttrib4f(INSTANCE_ATTRIB_BASE + 4, custom_data[0] / 255.0, custom_data[1] / 255.0, custom_data[2] / 255.0, custom_data[3] / 255.0); } else { @@ -1764,7 +1764,7 @@ void RasterizerSceneGLES2::_render_geometry(RenderList::Element *p_element) { } break; - case VS::INSTANCE_IMMEDIATE: { + case RS::INSTANCE_IMMEDIATE: { const RasterizerStorageGLES2::Immediate *im = static_cast<const RasterizerStorageGLES2::Immediate *>(p_element->geometry); if (im->building) { @@ -1792,7 +1792,7 @@ void RasterizerSceneGLES2::_render_geometry(RenderList::Element *p_element) { RasterizerStorageGLES2::Texture *t = storage->texture_owner.getornull(c.texture); if (t->redraw_if_visible) { - VisualServerRaster::redraw_request(); + RenderingServerRaster::redraw_request(); } t = t->get_ptr(); @@ -1816,53 +1816,53 @@ void RasterizerSceneGLES2::_render_geometry(RenderList::Element *p_element) { } if (!c.normals.empty()) { - glEnableVertexAttribArray(VS::ARRAY_NORMAL); + glEnableVertexAttribArray(RS::ARRAY_NORMAL); glBufferSubData(GL_ARRAY_BUFFER, buf_ofs, sizeof(Vector3) * vertices, c.normals.ptr()); - glVertexAttribPointer(VS::ARRAY_NORMAL, 3, GL_FLOAT, GL_FALSE, sizeof(Vector3), CAST_INT_TO_UCHAR_PTR(buf_ofs)); + glVertexAttribPointer(RS::ARRAY_NORMAL, 3, GL_FLOAT, GL_FALSE, sizeof(Vector3), CAST_INT_TO_UCHAR_PTR(buf_ofs)); buf_ofs += sizeof(Vector3) * vertices; } else { - glDisableVertexAttribArray(VS::ARRAY_NORMAL); + glDisableVertexAttribArray(RS::ARRAY_NORMAL); } if (!c.tangents.empty()) { - glEnableVertexAttribArray(VS::ARRAY_TANGENT); + glEnableVertexAttribArray(RS::ARRAY_TANGENT); glBufferSubData(GL_ARRAY_BUFFER, buf_ofs, sizeof(Plane) * vertices, c.tangents.ptr()); - glVertexAttribPointer(VS::ARRAY_TANGENT, 4, GL_FLOAT, GL_FALSE, sizeof(Plane), CAST_INT_TO_UCHAR_PTR(buf_ofs)); + glVertexAttribPointer(RS::ARRAY_TANGENT, 4, GL_FLOAT, GL_FALSE, sizeof(Plane), CAST_INT_TO_UCHAR_PTR(buf_ofs)); buf_ofs += sizeof(Plane) * vertices; } else { - glDisableVertexAttribArray(VS::ARRAY_TANGENT); + glDisableVertexAttribArray(RS::ARRAY_TANGENT); } if (!c.colors.empty()) { - glEnableVertexAttribArray(VS::ARRAY_COLOR); + glEnableVertexAttribArray(RS::ARRAY_COLOR); glBufferSubData(GL_ARRAY_BUFFER, buf_ofs, sizeof(Color) * vertices, c.colors.ptr()); - glVertexAttribPointer(VS::ARRAY_COLOR, 4, GL_FLOAT, GL_FALSE, sizeof(Color), CAST_INT_TO_UCHAR_PTR(buf_ofs)); + glVertexAttribPointer(RS::ARRAY_COLOR, 4, GL_FLOAT, GL_FALSE, sizeof(Color), CAST_INT_TO_UCHAR_PTR(buf_ofs)); buf_ofs += sizeof(Color) * vertices; } else { - glDisableVertexAttribArray(VS::ARRAY_COLOR); + glDisableVertexAttribArray(RS::ARRAY_COLOR); } if (!c.uvs.empty()) { - glEnableVertexAttribArray(VS::ARRAY_TEX_UV); + glEnableVertexAttribArray(RS::ARRAY_TEX_UV); glBufferSubData(GL_ARRAY_BUFFER, buf_ofs, sizeof(Vector2) * vertices, c.uvs.ptr()); - glVertexAttribPointer(VS::ARRAY_TEX_UV, 2, GL_FLOAT, GL_FALSE, sizeof(Vector2), CAST_INT_TO_UCHAR_PTR(buf_ofs)); + glVertexAttribPointer(RS::ARRAY_TEX_UV, 2, GL_FLOAT, GL_FALSE, sizeof(Vector2), CAST_INT_TO_UCHAR_PTR(buf_ofs)); buf_ofs += sizeof(Vector2) * vertices; } else { - glDisableVertexAttribArray(VS::ARRAY_TEX_UV); + glDisableVertexAttribArray(RS::ARRAY_TEX_UV); } if (!c.uv2s.empty()) { - glEnableVertexAttribArray(VS::ARRAY_TEX_UV2); + glEnableVertexAttribArray(RS::ARRAY_TEX_UV2); glBufferSubData(GL_ARRAY_BUFFER, buf_ofs, sizeof(Vector2) * vertices, c.uv2s.ptr()); - glVertexAttribPointer(VS::ARRAY_TEX_UV2, 2, GL_FLOAT, GL_FALSE, sizeof(Vector2), CAST_INT_TO_UCHAR_PTR(buf_ofs)); + glVertexAttribPointer(RS::ARRAY_TEX_UV2, 2, GL_FLOAT, GL_FALSE, sizeof(Vector2), CAST_INT_TO_UCHAR_PTR(buf_ofs)); buf_ofs += sizeof(Vector2) * vertices; } else { - glDisableVertexAttribArray(VS::ARRAY_TEX_UV2); + glDisableVertexAttribArray(RS::ARRAY_TEX_UV2); } - glEnableVertexAttribArray(VS::ARRAY_VERTEX); + glEnableVertexAttribArray(RS::ARRAY_VERTEX); glBufferSubData(GL_ARRAY_BUFFER, buf_ofs, sizeof(Vector3) * vertices, c.vertices.ptr()); - glVertexAttribPointer(VS::ARRAY_VERTEX, 3, GL_FLOAT, GL_FALSE, sizeof(Vector3), CAST_INT_TO_UCHAR_PTR(buf_ofs)); + glVertexAttribPointer(RS::ARRAY_VERTEX, 3, GL_FLOAT, GL_FALSE, sizeof(Vector3), CAST_INT_TO_UCHAR_PTR(buf_ofs)); glDrawArrays(gl_primitive[c.primitive], 0, c.vertices.size()); } @@ -1901,18 +1901,18 @@ void RasterizerSceneGLES2::_setup_light_type(LightInstance *p_light, ShadowAtlas state.scene_shader.set_conditional(SceneShaderGLES2::USE_LIGHTING, true); switch (p_light->light_ptr->type) { - case VS::LIGHT_DIRECTIONAL: { + case RS::LIGHT_DIRECTIONAL: { state.scene_shader.set_conditional(SceneShaderGLES2::LIGHT_MODE_DIRECTIONAL, true); switch (p_light->light_ptr->directional_shadow_mode) { - case VS::LIGHT_DIRECTIONAL_SHADOW_ORTHOGONAL: { + case RS::LIGHT_DIRECTIONAL_SHADOW_ORTHOGONAL: { //no need } break; - case VS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_2_SPLITS: { + case RS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_2_SPLITS: { state.scene_shader.set_conditional(SceneShaderGLES2::LIGHT_USE_PSSM2, true); } break; - case VS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_4_SPLITS: { + case RS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_4_SPLITS: { state.scene_shader.set_conditional(SceneShaderGLES2::LIGHT_USE_PSSM4, true); } break; } @@ -1931,7 +1931,7 @@ void RasterizerSceneGLES2::_setup_light_type(LightInstance *p_light, ShadowAtlas } } break; - case VS::LIGHT_OMNI: { + case RS::LIGHT_OMNI: { state.scene_shader.set_conditional(SceneShaderGLES2::LIGHT_MODE_OMNI, true); if (!state.render_no_shadows && shadow_atlas && p_light->light_ptr->shadow) { @@ -1946,7 +1946,7 @@ void RasterizerSceneGLES2::_setup_light_type(LightInstance *p_light, ShadowAtlas state.scene_shader.set_conditional(SceneShaderGLES2::SHADOW_MODE_PCF_13, shadow_filter_mode == SHADOW_FILTER_PCF13); } } break; - case VS::LIGHT_SPOT: { + case RS::LIGHT_SPOT: { state.scene_shader.set_conditional(SceneShaderGLES2::LIGHT_MODE_SPOT, true); if (!state.render_no_shadows && shadow_atlas && p_light->light_ptr->shadow) { @@ -1969,8 +1969,8 @@ void RasterizerSceneGLES2::_setup_light(LightInstance *light, ShadowAtlas *shado RasterizerStorageGLES2::Light *light_ptr = light->light_ptr; //common parameters - float energy = light_ptr->param[VS::LIGHT_PARAM_ENERGY]; - float specular = light_ptr->param[VS::LIGHT_PARAM_SPECULAR]; + float energy = light_ptr->param[RS::LIGHT_PARAM_ENERGY]; + float specular = light_ptr->param[RS::LIGHT_PARAM_SPECULAR]; float sign = (light_ptr->negative && !accum_pass) ? -1 : 1; //inverse color for base pass lights only state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_SPECULAR, specular); @@ -1982,7 +1982,7 @@ void RasterizerSceneGLES2::_setup_light(LightInstance *light, ShadowAtlas *shado //specific parameters switch (light_ptr->type) { - case VS::LIGHT_DIRECTIONAL: { + case RS::LIGHT_DIRECTIONAL: { //not using inverse for performance, view should be normalized anyway Vector3 direction = p_view_transform.basis.xform_inv(light->transform.basis.xform(Vector3(0, 0, -1))).normalized(); state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_DIRECTION, direction); @@ -1995,15 +1995,15 @@ void RasterizerSceneGLES2::_setup_light(LightInstance *light, ShadowAtlas *shado Color split_offsets; switch (light_ptr->directional_shadow_mode) { - case VS::LIGHT_DIRECTIONAL_SHADOW_ORTHOGONAL: { + case RS::LIGHT_DIRECTIONAL_SHADOW_ORTHOGONAL: { shadow_count = 1; } break; - case VS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_2_SPLITS: { + case RS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_2_SPLITS: { shadow_count = 2; } break; - case VS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_4_SPLITS: { + case RS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_4_SPLITS: { shadow_count = 4; } break; } @@ -2015,7 +2015,7 @@ void RasterizerSceneGLES2::_setup_light(LightInstance *light, ShadowAtlas *shado uint32_t width = light->directional_rect.size.x; uint32_t height = light->directional_rect.size.y; - if (light_ptr->directional_shadow_mode == VS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_4_SPLITS) { + if (light_ptr->directional_shadow_mode == RS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_4_SPLITS) { width /= 2; height /= 2; @@ -2029,7 +2029,7 @@ void RasterizerSceneGLES2::_setup_light(LightInstance *light, ShadowAtlas *shado y += height; } - } else if (light_ptr->directional_shadow_mode == VS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_2_SPLITS) { + } else if (light_ptr->directional_shadow_mode == RS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_2_SPLITS) { height /= 2; @@ -2067,16 +2067,16 @@ void RasterizerSceneGLES2::_setup_light(LightInstance *light, ShadowAtlas *shado state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_SHADOW_MATRIX4, matrices[3]); } } break; - case VS::LIGHT_OMNI: { + case RS::LIGHT_OMNI: { Vector3 position = p_view_transform.xform_inv(light->transform.origin); state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_POSITION, position); - float range = light_ptr->param[VS::LIGHT_PARAM_RANGE]; + float range = light_ptr->param[RS::LIGHT_PARAM_RANGE]; state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_RANGE, range); - float attenuation = light_ptr->param[VS::LIGHT_PARAM_ATTENUATION]; + float attenuation = light_ptr->param[RS::LIGHT_PARAM_ATTENUATION]; state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_ATTENUATION, attenuation); if (!state.render_no_shadows && light_ptr->shadow && shadow_atlas && shadow_atlas->shadow_owners.has(light->self)) { @@ -2101,7 +2101,7 @@ void RasterizerSceneGLES2::_setup_light(LightInstance *light, ShadowAtlas *shado uint32_t width = shadow_size; uint32_t height = shadow_size; - if (light->light_ptr->omni_shadow_detail == VS::LIGHT_OMNI_SHADOW_DETAIL_HORIZONTAL) { + if (light->light_ptr->omni_shadow_detail == RS::LIGHT_OMNI_SHADOW_DETAIL_HORIZONTAL) { height /= 2; } else { width /= 2; @@ -2121,7 +2121,7 @@ void RasterizerSceneGLES2::_setup_light(LightInstance *light, ShadowAtlas *shado } } break; - case VS::LIGHT_SPOT: { + case RS::LIGHT_SPOT: { Vector3 position = p_view_transform.xform_inv(light->transform.origin); @@ -2129,10 +2129,10 @@ void RasterizerSceneGLES2::_setup_light(LightInstance *light, ShadowAtlas *shado Vector3 direction = p_view_transform.inverse().basis.xform(light->transform.basis.xform(Vector3(0, 0, -1))).normalized(); state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_DIRECTION, direction); - float attenuation = light_ptr->param[VS::LIGHT_PARAM_ATTENUATION]; - float range = light_ptr->param[VS::LIGHT_PARAM_RANGE]; - float spot_attenuation = light_ptr->param[VS::LIGHT_PARAM_SPOT_ATTENUATION]; - float angle = light_ptr->param[VS::LIGHT_PARAM_SPOT_ANGLE]; + float attenuation = light_ptr->param[RS::LIGHT_PARAM_ATTENUATION]; + float range = light_ptr->param[RS::LIGHT_PARAM_RANGE]; + float spot_attenuation = light_ptr->param[RS::LIGHT_PARAM_SPOT_ATTENUATION]; + float angle = light_ptr->param[RS::LIGHT_PARAM_SPOT_ANGLE]; angle = Math::cos(Math::deg2rad(angle)); state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_ATTENUATION, attenuation); state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_SPOT_ATTENUATION, spot_attenuation); @@ -2259,19 +2259,19 @@ void RasterizerSceneGLES2::_render_render_list(RenderList::Element **p_elements, bool prev_instancing = false; bool prev_depth_prepass = false; state.scene_shader.set_conditional(SceneShaderGLES2::SHADELESS, false); - RasterizerStorageGLES2::Material *prev_material = NULL; - RasterizerStorageGLES2::Geometry *prev_geometry = NULL; - RasterizerStorageGLES2::Skeleton *prev_skeleton = NULL; - RasterizerStorageGLES2::GeometryOwner *prev_owner = NULL; + RasterizerStorageGLES2::Material *prev_material = nullptr; + RasterizerStorageGLES2::Geometry *prev_geometry = nullptr; + RasterizerStorageGLES2::Skeleton *prev_skeleton = nullptr; + RasterizerStorageGLES2::GeometryOwner *prev_owner = nullptr; Transform view_transform_inverse = p_view_transform.inverse(); CameraMatrix projection_inverse = p_projection.inverse(); bool prev_base_pass = false; - LightInstance *prev_light = NULL; + LightInstance *prev_light = nullptr; bool prev_vertex_lit = false; - ReflectionProbeInstance *prev_refprobe_1 = NULL; - ReflectionProbeInstance *prev_refprobe_2 = NULL; + ReflectionProbeInstance *prev_refprobe_1 = nullptr; + ReflectionProbeInstance *prev_refprobe_2 = nullptr; int prev_blend_mode = -2; //will always catch the first go @@ -2299,7 +2299,7 @@ void RasterizerSceneGLES2::_render_render_list(RenderList::Element **p_elements, using_fog = true; } - RasterizerStorageGLES2::Texture *prev_lightmap = NULL; + RasterizerStorageGLES2::Texture *prev_lightmap = nullptr; float lightmap_energy = 1.0; bool prev_use_lightmap_capture = false; @@ -2313,10 +2313,10 @@ void RasterizerSceneGLES2::_render_render_list(RenderList::Element **p_elements, bool rebind = false; bool accum_pass = *e->use_accum_ptr; *e->use_accum_ptr = true; //set to accum for next time this is found - LightInstance *light = NULL; - ReflectionProbeInstance *refprobe_1 = NULL; - ReflectionProbeInstance *refprobe_2 = NULL; - RasterizerStorageGLES2::Texture *lightmap = NULL; + LightInstance *light = nullptr; + ReflectionProbeInstance *refprobe_1 = nullptr; + ReflectionProbeInstance *refprobe_2 = nullptr; + RasterizerStorageGLES2::Texture *lightmap = nullptr; bool use_lightmap_capture = false; bool rebind_light = false; bool rebind_reflection = false; @@ -2432,13 +2432,13 @@ void RasterizerSceneGLES2::_render_render_list(RenderList::Element **p_elements, } if (refprobe_1 != prev_refprobe_1 || refprobe_2 != prev_refprobe_2) { - state.scene_shader.set_conditional(SceneShaderGLES2::USE_REFLECTION_PROBE1, refprobe_1 != NULL); - state.scene_shader.set_conditional(SceneShaderGLES2::USE_REFLECTION_PROBE2, refprobe_2 != NULL); - if (refprobe_1 != NULL && refprobe_1 != prev_refprobe_1) { + state.scene_shader.set_conditional(SceneShaderGLES2::USE_REFLECTION_PROBE1, refprobe_1 != nullptr); + state.scene_shader.set_conditional(SceneShaderGLES2::USE_REFLECTION_PROBE2, refprobe_2 != nullptr); + if (refprobe_1 != nullptr && refprobe_1 != prev_refprobe_1) { glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 5); glBindTexture(GL_TEXTURE_CUBE_MAP, refprobe_1->cubemap); } - if (refprobe_2 != NULL && refprobe_2 != prev_refprobe_2) { + if (refprobe_2 != nullptr && refprobe_2 != prev_refprobe_2) { glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 6); glBindTexture(GL_TEXTURE_CUBE_MAP, refprobe_2->cubemap); } @@ -2467,8 +2467,8 @@ void RasterizerSceneGLES2::_render_render_list(RenderList::Element **p_elements, } if (lightmap != prev_lightmap) { - state.scene_shader.set_conditional(SceneShaderGLES2::USE_LIGHTMAP, lightmap != NULL); - if (lightmap != NULL) { + state.scene_shader.set_conditional(SceneShaderGLES2::USE_LIGHTMAP, lightmap != nullptr); + if (lightmap != nullptr) { glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 4); glBindTexture(GL_TEXTURE_2D, lightmap->tex_id); } @@ -2490,7 +2490,7 @@ void RasterizerSceneGLES2::_render_render_list(RenderList::Element **p_elements, rebind = true; } - bool instancing = e->instance->base_type == VS::INSTANCE_MULTIMESH; + bool instancing = e->instance->base_type == RS::INSTANCE_MULTIMESH; if (instancing != prev_instancing) { @@ -2501,16 +2501,16 @@ void RasterizerSceneGLES2::_render_render_list(RenderList::Element **p_elements, RasterizerStorageGLES2::Skeleton *skeleton = storage->skeleton_owner.getornull(e->instance->skeleton); if (skeleton != prev_skeleton) { - - if (skeleton) { - state.scene_shader.set_conditional(SceneShaderGLES2::USE_SKELETON, true); - state.scene_shader.set_conditional(SceneShaderGLES2::USE_SKELETON_SOFTWARE, storage->config.use_skeleton_software); - } else { - state.scene_shader.set_conditional(SceneShaderGLES2::USE_SKELETON, false); - state.scene_shader.set_conditional(SceneShaderGLES2::USE_SKELETON_SOFTWARE, false); + if ((prev_skeleton == nullptr) != (skeleton == nullptr)) { + if (skeleton) { + state.scene_shader.set_conditional(SceneShaderGLES2::USE_SKELETON, true); + state.scene_shader.set_conditional(SceneShaderGLES2::USE_SKELETON_SOFTWARE, storage->config.use_skeleton_software); + } else { + state.scene_shader.set_conditional(SceneShaderGLES2::USE_SKELETON, false); + state.scene_shader.set_conditional(SceneShaderGLES2::USE_SKELETON_SOFTWARE, false); + } + rebind = true; } - - rebind = true; } if (e->owner != prev_owner || e->geometry != prev_geometry || skeleton != prev_skeleton) { @@ -2641,7 +2641,7 @@ void RasterizerSceneGLES2::_render_render_list(RenderList::Element **p_elements, prev_use_lightmap_capture = use_lightmap_capture; } - _setup_light_type(NULL, NULL); //clear light stuff + _setup_light_type(nullptr, nullptr); //clear light stuff state.scene_shader.set_conditional(SceneShaderGLES2::USE_SKELETON, false); state.scene_shader.set_conditional(SceneShaderGLES2::SHADELESS, false); state.scene_shader.set_conditional(SceneShaderGLES2::BASE_PASS, false); @@ -2726,10 +2726,10 @@ void RasterizerSceneGLES2::_draw_sky(RasterizerStorageGLES2::Sky *p_sky, const C glBufferData(GL_ARRAY_BUFFER, sizeof(Vector3) * 8, vertices, GL_DYNAMIC_DRAW); // bind sky vertex array.... - glVertexAttribPointer(VS::ARRAY_VERTEX, 3, GL_FLOAT, GL_FALSE, sizeof(Vector3) * 2, 0); - glVertexAttribPointer(VS::ARRAY_TEX_UV, 3, GL_FLOAT, GL_FALSE, sizeof(Vector3) * 2, CAST_INT_TO_UCHAR_PTR(sizeof(Vector3))); - glEnableVertexAttribArray(VS::ARRAY_VERTEX); - glEnableVertexAttribArray(VS::ARRAY_TEX_UV); + glVertexAttribPointer(RS::ARRAY_VERTEX, 3, GL_FLOAT, GL_FALSE, sizeof(Vector3) * 2, 0); + glVertexAttribPointer(RS::ARRAY_TEX_UV, 3, GL_FLOAT, GL_FALSE, sizeof(Vector3) * 2, CAST_INT_TO_UCHAR_PTR(sizeof(Vector3))); + glEnableVertexAttribArray(RS::ARRAY_VERTEX); + glEnableVertexAttribArray(RS::ARRAY_TEX_UV); storage->shaders.copy.set_conditional(CopyShaderGLES2::USE_ASYM_PANO, asymmetrical); storage->shaders.copy.set_conditional(CopyShaderGLES2::USE_PANORAMA, !asymmetrical); @@ -2752,8 +2752,8 @@ void RasterizerSceneGLES2::_draw_sky(RasterizerStorageGLES2::Sky *p_sky, const C glDrawArrays(GL_TRIANGLE_FAN, 0, 4); - glDisableVertexAttribArray(VS::ARRAY_VERTEX); - glDisableVertexAttribArray(VS::ARRAY_TEX_UV); + glDisableVertexAttribArray(RS::ARRAY_VERTEX); + glDisableVertexAttribArray(RS::ARRAY_TEX_UV); glBindBuffer(GL_ARRAY_BUFFER, 0); storage->shaders.copy.set_conditional(CopyShaderGLES2::USE_ASYM_PANO, false); @@ -2845,9 +2845,9 @@ void RasterizerSceneGLES2::_post_process(Environment *env, const CameraMatrix &p state.effect_blur_shader.set_conditional(EffectBlurShaderGLES2::USE_ORTHOGONAL_PROJECTION, p_cam_projection.is_orthogonal()); state.effect_blur_shader.set_conditional(EffectBlurShaderGLES2::DOF_FAR_BLUR, true); - state.effect_blur_shader.set_conditional(EffectBlurShaderGLES2::DOF_QUALITY_LOW, env->dof_blur_far_quality == VS::ENV_DOF_BLUR_QUALITY_LOW); - state.effect_blur_shader.set_conditional(EffectBlurShaderGLES2::DOF_QUALITY_MEDIUM, env->dof_blur_far_quality == VS::ENV_DOF_BLUR_QUALITY_MEDIUM); - state.effect_blur_shader.set_conditional(EffectBlurShaderGLES2::DOF_QUALITY_HIGH, env->dof_blur_far_quality == VS::ENV_DOF_BLUR_QUALITY_HIGH); + state.effect_blur_shader.set_conditional(EffectBlurShaderGLES2::DOF_QUALITY_LOW, env->dof_blur_far_quality == RS::ENV_DOF_BLUR_QUALITY_LOW); + state.effect_blur_shader.set_conditional(EffectBlurShaderGLES2::DOF_QUALITY_MEDIUM, env->dof_blur_far_quality == RS::ENV_DOF_BLUR_QUALITY_MEDIUM); + state.effect_blur_shader.set_conditional(EffectBlurShaderGLES2::DOF_QUALITY_HIGH, env->dof_blur_far_quality == RS::ENV_DOF_BLUR_QUALITY_HIGH); state.effect_blur_shader.bind(); int qsteps[3] = { 4, 10, 20 }; @@ -2901,7 +2901,7 @@ void RasterizerSceneGLES2::_post_process(Environment *env, const CameraMatrix &p if (!storage->frame.current_rt->used_dof_blur_near) { glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->color); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, storage->frame.current_rt->width, storage->frame.current_rt->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, storage->frame.current_rt->width, storage->frame.current_rt->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); } int vp_h = storage->frame.current_rt->height; @@ -2911,9 +2911,9 @@ void RasterizerSceneGLES2::_post_process(Environment *env, const CameraMatrix &p state.effect_blur_shader.set_conditional(EffectBlurShaderGLES2::DOF_NEAR_BLUR, true); state.effect_blur_shader.set_conditional(EffectBlurShaderGLES2::DOF_NEAR_FIRST_TAP, true); - state.effect_blur_shader.set_conditional(EffectBlurShaderGLES2::DOF_QUALITY_LOW, env->dof_blur_near_quality == VS::ENV_DOF_BLUR_QUALITY_LOW); - state.effect_blur_shader.set_conditional(EffectBlurShaderGLES2::DOF_QUALITY_MEDIUM, env->dof_blur_near_quality == VS::ENV_DOF_BLUR_QUALITY_MEDIUM); - state.effect_blur_shader.set_conditional(EffectBlurShaderGLES2::DOF_QUALITY_HIGH, env->dof_blur_near_quality == VS::ENV_DOF_BLUR_QUALITY_HIGH); + state.effect_blur_shader.set_conditional(EffectBlurShaderGLES2::DOF_QUALITY_LOW, env->dof_blur_near_quality == RS::ENV_DOF_BLUR_QUALITY_LOW); + state.effect_blur_shader.set_conditional(EffectBlurShaderGLES2::DOF_QUALITY_MEDIUM, env->dof_blur_near_quality == RS::ENV_DOF_BLUR_QUALITY_MEDIUM); + state.effect_blur_shader.set_conditional(EffectBlurShaderGLES2::DOF_QUALITY_HIGH, env->dof_blur_near_quality == RS::ENV_DOF_BLUR_QUALITY_HIGH); state.effect_blur_shader.bind(); int qsteps[3] = { 4, 10, 20 }; @@ -3003,7 +3003,7 @@ void RasterizerSceneGLES2::_post_process(Environment *env, const CameraMatrix &p if (env->glow_enabled) { - for (int i = 0; i < VS::MAX_GLOW_LEVELS; i++) { + for (int i = 0; i < RS::MAX_GLOW_LEVELS; i++) { if (env->glow_levels & (1 << i)) { if (i >= storage->frame.current_rt->mip_maps[1].sizes.size()) { @@ -3156,9 +3156,9 @@ void RasterizerSceneGLES2::_post_process(Environment *env, const CameraMatrix &p } } - state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_SCREEN, env->glow_blend_mode == VS::ENV_GLOW_BLEND_MODE_SCREEN); - state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_SOFTLIGHT, env->glow_blend_mode == VS::ENV_GLOW_BLEND_MODE_SOFTLIGHT); - state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_REPLACE, env->glow_blend_mode == VS::ENV_GLOW_BLEND_MODE_REPLACE); + state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_SCREEN, env->glow_blend_mode == RS::ENV_GLOW_BLEND_MODE_SCREEN); + state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_SOFTLIGHT, env->glow_blend_mode == RS::ENV_GLOW_BLEND_MODE_SOFTLIGHT); + state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_REPLACE, env->glow_blend_mode == RS::ENV_GLOW_BLEND_MODE_REPLACE); } //Adjustments @@ -3216,7 +3216,7 @@ void RasterizerSceneGLES2::render_scene(const Transform &p_cam_transform, const storage->info.render.object_count += p_cull_count; GLuint current_fb = 0; - Environment *env = NULL; + Environment *env = nullptr; int viewport_width, viewport_height; int viewport_x = 0; @@ -3261,7 +3261,7 @@ void RasterizerSceneGLES2::render_scene(const Transform &p_cam_transform, const viewport_x = storage->frame.current_rt->x; if (storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_DIRECT_TO_SCREEN]) { - viewport_y = OS::get_singleton()->get_window_size().height - viewport_height - storage->frame.current_rt->y; + viewport_y = DisplayServer::get_singleton()->window_get_size().height - viewport_height - storage->frame.current_rt->y; } else { viewport_y = storage->frame.current_rt->y; } @@ -3288,7 +3288,7 @@ void RasterizerSceneGLES2::render_scene(const Transform &p_cam_transform, const LightInstance *light = light_instance_owner.getornull(light_rid); - if (light->light_ptr->type == VS::LIGHT_DIRECTIONAL) { + if (light->light_ptr->type == RS::LIGHT_DIRECTIONAL) { render_directional_lights++; //as going in reverse, directional lights are always first anyway } @@ -3300,7 +3300,7 @@ void RasterizerSceneGLES2::render_scene(const Transform &p_cam_transform, const } } else { - render_light_instances = NULL; + render_light_instances = nullptr; render_directional_lights = 0; render_light_instance_count = 0; } @@ -3318,11 +3318,11 @@ void RasterizerSceneGLES2::render_scene(const Transform &p_cam_transform, const } } else { - reflection_probe_instances = NULL; + reflection_probe_instances = nullptr; reflection_probe_count = 0; } - if (env && env->bg_mode == VS::ENV_BG_CANVAS) { + if (env && env->bg_mode == RS::ENV_BG_CANVAS) { // If using canvas background, copy 2d to screen copy texture // TODO: When GLES2 renders to current_rt->mip_maps[], this copy will no longer be needed _copy_texture_to_buffer(storage->frame.current_rt->color, storage->frame.current_rt->copy_screen_effect.fbo); @@ -3358,22 +3358,22 @@ void RasterizerSceneGLES2::render_scene(const Transform &p_cam_transform, const if (storage->frame.current_rt && storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_TRANSPARENT]) { clear_color = Color(0, 0, 0, 0); storage->frame.clear_request = false; - } else if (!env || env->bg_mode == VS::ENV_BG_CLEAR_COLOR || env->bg_mode == VS::ENV_BG_SKY) { + } else if (!env || env->bg_mode == RS::ENV_BG_CLEAR_COLOR || env->bg_mode == RS::ENV_BG_SKY) { if (storage->frame.clear_request) { clear_color = storage->frame.clear_request_color; storage->frame.clear_request = false; } - } else if (env->bg_mode == VS::ENV_BG_CANVAS || env->bg_mode == VS::ENV_BG_COLOR || env->bg_mode == VS::ENV_BG_COLOR_SKY) { + } else if (env->bg_mode == RS::ENV_BG_CANVAS || env->bg_mode == RS::ENV_BG_COLOR || env->bg_mode == RS::ENV_BG_COLOR_SKY) { clear_color = env->bg_color; storage->frame.clear_request = false; - } else if (env->bg_mode == VS::ENV_BG_CAMERA_FEED) { + } else if (env->bg_mode == RS::ENV_BG_CAMERA_FEED) { feed = CameraServer::get_singleton()->get_feed_by_id(env->camera_feed_id); storage->frame.clear_request = false; } else { storage->frame.clear_request = false; } - if (!env || env->bg_mode != VS::ENV_BG_KEEP) { + if (!env || env->bg_mode != RS::ENV_BG_KEEP) { glClearColor(clear_color.r, clear_color.g, clear_color.b, clear_color.a); glClear(GL_COLOR_BUFFER_BIT); } @@ -3385,26 +3385,26 @@ void RasterizerSceneGLES2::render_scene(const Transform &p_cam_transform, const glDisable(GL_SCISSOR_TEST); } - glVertexAttrib4f(VS::ARRAY_COLOR, 1, 1, 1, 1); + glVertexAttrib4f(RS::ARRAY_COLOR, 1, 1, 1, 1); glBlendEquation(GL_FUNC_ADD); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // render sky - RasterizerStorageGLES2::Sky *sky = NULL; + RasterizerStorageGLES2::Sky *sky = nullptr; GLuint env_radiance_tex = 0; if (env) { switch (env->bg_mode) { - case VS::ENV_BG_COLOR_SKY: - case VS::ENV_BG_SKY: { + case RS::ENV_BG_COLOR_SKY: + case RS::ENV_BG_SKY: { sky = storage->sky_owner.getornull(env->sky); if (sky) { env_radiance_tex = sky->radiance; } } break; - case VS::ENV_BG_CAMERA_FEED: { + case RS::ENV_BG_CAMERA_FEED: { if (feed.is_valid() && (feed->get_base_width() > 0) && (feed->get_base_height() > 0)) { // copy our camera feed to our background @@ -3419,12 +3419,12 @@ void RasterizerSceneGLES2::render_scene(const Transform &p_cam_transform, const if (feed->get_datatype() == CameraFeed::FEED_RGB) { RID camera_RGBA = feed->get_texture(CameraServer::FEED_RGBA_IMAGE); - VS::get_singleton()->texture_bind(camera_RGBA, 0); + RS::get_singleton()->texture_bind(camera_RGBA, 0); } else if (feed->get_datatype() == CameraFeed::FEED_YCBCR) { RID camera_YCbCr = feed->get_texture(CameraServer::FEED_YCBCR_IMAGE); - VS::get_singleton()->texture_bind(camera_YCbCr, 0); + RS::get_singleton()->texture_bind(camera_YCbCr, 0); storage->shaders.copy.set_conditional(CopyShaderGLES2::YCBCR_TO_RGB, true); @@ -3432,8 +3432,8 @@ void RasterizerSceneGLES2::render_scene(const Transform &p_cam_transform, const RID camera_Y = feed->get_texture(CameraServer::FEED_Y_IMAGE); RID camera_CbCr = feed->get_texture(CameraServer::FEED_CBCR_IMAGE); - VS::get_singleton()->texture_bind(camera_Y, 0); - VS::get_singleton()->texture_bind(camera_CbCr, 1); + RS::get_singleton()->texture_bind(camera_Y, 0); + RS::get_singleton()->texture_bind(camera_CbCr, 1); storage->shaders.copy.set_conditional(CopyShaderGLES2::SEP_CBCR_TEXTURE, true); storage->shaders.copy.set_conditional(CopyShaderGLES2::YCBCR_TO_RGB, true); @@ -3444,8 +3444,8 @@ void RasterizerSceneGLES2::render_scene(const Transform &p_cam_transform, const storage->bind_quad_array(); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); - glDisableVertexAttribArray(VS::ARRAY_VERTEX); - glDisableVertexAttribArray(VS::ARRAY_TEX_UV); + glDisableVertexAttribArray(RS::ARRAY_VERTEX); + glDisableVertexAttribArray(RS::ARRAY_TEX_UV); glBindBuffer(GL_ARRAY_BUFFER, 0); // turn off everything used @@ -3464,7 +3464,7 @@ void RasterizerSceneGLES2::render_scene(const Transform &p_cam_transform, const clear_color = Color(0.0, 1.0, 0.0, 1.0); } } break; - case VS::ENV_BG_CANVAS: { + case RS::ENV_BG_CANVAS: { // use screen copy as background _copy_texture_to_buffer(storage->frame.current_rt->copy_screen_effect.color, current_fb); } break; @@ -3484,7 +3484,7 @@ void RasterizerSceneGLES2::render_scene(const Transform &p_cam_transform, const _render_render_list(render_list.elements, render_list.element_count, cam_transform, p_cam_projection, p_shadow_atlas, env, env_radiance_tex, 0.0, 0.0, reverse_cull, false, false); // then draw the sky after - if (env && env->bg_mode == VS::ENV_BG_SKY && (!storage->frame.current_rt || !storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_TRANSPARENT])) { + if (env && env->bg_mode == RS::ENV_BG_SKY && (!storage->frame.current_rt || !storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_TRANSPARENT])) { if (sky && sky->panorama.is_valid()) { _draw_sky(sky, p_cam_projection, cam_transform, false, env->sky_custom_fov, env->bg_energy, env->sky_orientation); @@ -3616,7 +3616,7 @@ void RasterizerSceneGLES2::render_shadow(RID p_light, RID p_shadow_atlas, int p_ // TODO directional light - if (light->type == VS::LIGHT_DIRECTIONAL) { + if (light->type == RS::LIGHT_DIRECTIONAL) { // set pssm stuff // TODO set this only when changed @@ -3651,7 +3651,7 @@ void RasterizerSceneGLES2::render_shadow(RID p_light, RID p_shadow_atlas, int p_ width = light_instance->directional_rect.size.width; height = light_instance->directional_rect.size.height; - if (light->directional_shadow_mode == VS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_4_SPLITS) { + if (light->directional_shadow_mode == RS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_4_SPLITS) { width /= 2; height /= 2; @@ -3665,7 +3665,7 @@ void RasterizerSceneGLES2::render_shadow(RID p_light, RID p_shadow_atlas, int p_ y += height; } - } else if (light->directional_shadow_mode == VS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_2_SPLITS) { + } else if (light->directional_shadow_mode == RS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_2_SPLITS) { height /= 2; @@ -3676,10 +3676,10 @@ void RasterizerSceneGLES2::render_shadow(RID p_light, RID p_shadow_atlas, int p_ } } - float bias_mult = Math::lerp(1.0f, light_instance->shadow_transform[p_pass].bias_scale, light->param[VS::LIGHT_PARAM_SHADOW_BIAS_SPLIT_SCALE]); - zfar = light->param[VS::LIGHT_PARAM_RANGE]; - bias = light->param[VS::LIGHT_PARAM_SHADOW_BIAS] * bias_mult; - normal_bias = light->param[VS::LIGHT_PARAM_SHADOW_NORMAL_BIAS] * bias_mult; + float bias_mult = Math::lerp(1.0f, light_instance->shadow_transform[p_pass].bias_scale, light->param[RS::LIGHT_PARAM_SHADOW_BIAS_SPLIT_SCALE]); + zfar = light->param[RS::LIGHT_PARAM_RANGE]; + bias = light->param[RS::LIGHT_PARAM_SHADOW_BIAS] * bias_mult; + normal_bias = light->param[RS::LIGHT_PARAM_SHADOW_NORMAL_BIAS] * bias_mult; fbo = directional_shadow.fbo; } else { @@ -3708,9 +3708,9 @@ void RasterizerSceneGLES2::render_shadow(RID p_light, RID p_shadow_atlas, int p_ width = shadow_size; height = shadow_size; - if (light->type == VS::LIGHT_OMNI) { + if (light->type == RS::LIGHT_OMNI) { // cubemap only - if (light->omni_shadow_mode == VS::LIGHT_OMNI_SHADOW_CUBE && storage->config.support_shadow_cubemaps) { + if (light->omni_shadow_mode == RS::LIGHT_OMNI_SHADOW_CUBE && storage->config.support_shadow_cubemaps) { int cubemap_index = shadow_cubemaps.size() - 1; // find an appropriate cubemap to render to @@ -3727,7 +3727,7 @@ void RasterizerSceneGLES2::render_shadow(RID p_light, RID p_shadow_atlas, int p_ light_transform = light_instance->shadow_transform[0].transform; custom_vp_size = shadow_cubemaps[cubemap_index].size; - zfar = light->param[VS::LIGHT_PARAM_RANGE]; + zfar = light->param[RS::LIGHT_PARAM_RANGE]; current_cubemap = cubemap_index; } else { @@ -3736,7 +3736,7 @@ void RasterizerSceneGLES2::render_shadow(RID p_light, RID p_shadow_atlas, int p_ light_projection = light_instance->shadow_transform[0].camera; light_transform = light_instance->shadow_transform[0].transform; - if (light->omni_shadow_detail == VS::LIGHT_OMNI_SHADOW_DETAIL_HORIZONTAL) { + if (light->omni_shadow_detail == RS::LIGHT_OMNI_SHADOW_DETAIL_HORIZONTAL) { height /= 2; y += p_pass * height; @@ -3747,22 +3747,22 @@ void RasterizerSceneGLES2::render_shadow(RID p_light, RID p_shadow_atlas, int p_ state.dual_parbolloid_direction = p_pass == 0 ? 1.0 : -1.0; flip_facing = (p_pass == 1); - zfar = light->param[VS::LIGHT_PARAM_RANGE]; - bias = light->param[VS::LIGHT_PARAM_SHADOW_BIAS]; + zfar = light->param[RS::LIGHT_PARAM_RANGE]; + bias = light->param[RS::LIGHT_PARAM_SHADOW_BIAS]; state.dual_parbolloid_zfar = zfar; state.scene_shader.set_conditional(SceneShaderGLES2::RENDER_DEPTH_DUAL_PARABOLOID, true); } - } else if (light->type == VS::LIGHT_SPOT) { + } else if (light->type == RS::LIGHT_SPOT) { light_projection = light_instance->shadow_transform[0].camera; light_transform = light_instance->shadow_transform[0].transform; flip_facing = false; - zfar = light->param[VS::LIGHT_PARAM_RANGE]; - bias = light->param[VS::LIGHT_PARAM_SHADOW_BIAS]; - normal_bias = light->param[VS::LIGHT_PARAM_SHADOW_NORMAL_BIAS]; + zfar = light->param[RS::LIGHT_PARAM_RANGE]; + bias = light->param[RS::LIGHT_PARAM_SHADOW_BIAS]; + normal_bias = light->param[RS::LIGHT_PARAM_SHADOW_NORMAL_BIAS]; } } @@ -3806,13 +3806,13 @@ void RasterizerSceneGLES2::render_shadow(RID p_light, RID p_shadow_atlas, int p_ state.scene_shader.set_conditional(SceneShaderGLES2::RENDER_DEPTH, true); - _render_render_list(render_list.elements, render_list.element_count, light_transform, light_projection, RID(), NULL, 0, bias, normal_bias, flip_facing, false, true); + _render_render_list(render_list.elements, render_list.element_count, light_transform, light_projection, RID(), nullptr, 0, bias, normal_bias, flip_facing, false, true); state.scene_shader.set_conditional(SceneShaderGLES2::RENDER_DEPTH, false); state.scene_shader.set_conditional(SceneShaderGLES2::RENDER_DEPTH_DUAL_PARABOLOID, false); // convert cubemap to dual paraboloid if needed - if (light->type == VS::LIGHT_OMNI && (light->omni_shadow_mode == VS::LIGHT_OMNI_SHADOW_CUBE && storage->config.support_shadow_cubemaps) && p_pass == 5) { + if (light->type == RS::LIGHT_OMNI && (light->omni_shadow_mode == RS::LIGHT_OMNI_SHADOW_CUBE && storage->config.support_shadow_cubemaps) && p_pass == 5) { ShadowAtlas *shadow_atlas = shadow_atlas_owner.getornull(p_shadow_atlas); glBindFramebuffer(GL_FRAMEBUFFER, shadow_atlas->fbo); @@ -3827,14 +3827,14 @@ void RasterizerSceneGLES2::render_shadow(RID p_light, RID p_shadow_atlas, int p_ state.cube_to_dp_shader.set_uniform(CubeToDpShaderGLES2::Z_FLIP, i == 1); state.cube_to_dp_shader.set_uniform(CubeToDpShaderGLES2::Z_NEAR, light_projection.get_z_near()); state.cube_to_dp_shader.set_uniform(CubeToDpShaderGLES2::Z_FAR, light_projection.get_z_far()); - state.cube_to_dp_shader.set_uniform(CubeToDpShaderGLES2::BIAS, light->param[VS::LIGHT_PARAM_SHADOW_BIAS]); + state.cube_to_dp_shader.set_uniform(CubeToDpShaderGLES2::BIAS, light->param[RS::LIGHT_PARAM_SHADOW_BIAS]); uint32_t local_width = width; uint32_t local_height = height; uint32_t local_x = x; uint32_t local_y = y; - if (light->omni_shadow_detail == VS::LIGHT_OMNI_SHADOW_DETAIL_HORIZONTAL) { + if (light->omni_shadow_detail == RS::LIGHT_OMNI_SHADOW_DETAIL_HORIZONTAL) { local_height /= 2; local_y += i * local_height; } else { @@ -3922,7 +3922,7 @@ bool RasterizerSceneGLES2::free(RID p_rid) { return true; } -void RasterizerSceneGLES2::set_debug_draw_mode(VS::ViewportDebugDraw p_debug_draw) { +void RasterizerSceneGLES2::set_debug_draw_mode(RS::ViewportDebugDraw p_debug_draw) { } void RasterizerSceneGLES2::initialize() { @@ -3977,7 +3977,7 @@ void RasterizerSceneGLES2::initialize() { { glGenBuffers(1, &state.sky_verts); glBindBuffer(GL_ARRAY_BUFFER, state.sky_verts); - glBufferData(GL_ARRAY_BUFFER, sizeof(Vector3) * 8, NULL, GL_DYNAMIC_DRAW); + glBufferData(GL_ARRAY_BUFFER, sizeof(Vector3) * 8, nullptr, GL_DYNAMIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, 0); } @@ -3987,7 +3987,7 @@ void RasterizerSceneGLES2::initialize() { glGenBuffers(1, &state.immediate_buffer); glBindBuffer(GL_ARRAY_BUFFER, state.immediate_buffer); - glBufferData(GL_ARRAY_BUFFER, immediate_buffer_size * 1024, NULL, GL_DYNAMIC_DRAW); + glBufferData(GL_ARRAY_BUFFER, immediate_buffer_size * 1024, nullptr, GL_DYNAMIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, 0); } @@ -4010,7 +4010,7 @@ void RasterizerSceneGLES2::initialize() { for (int i = 0; i < 6; i++) { - glTexImage2D(_cube_side_enum[i], 0, storage->config.depth_internalformat, cube_size, cube_size, 0, GL_DEPTH_COMPONENT, storage->config.depth_type, NULL); + glTexImage2D(_cube_side_enum[i], 0, storage->config.depth_internalformat, cube_size, cube_size, 0, GL_DEPTH_COMPONENT, storage->config.depth_type, nullptr); } glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST); @@ -4045,12 +4045,12 @@ void RasterizerSceneGLES2::initialize() { //maximum compatibility, renderbuffer and RGBA shadow glGenRenderbuffers(1, &directional_shadow.depth); glBindRenderbuffer(GL_RENDERBUFFER, directional_shadow.depth); - glRenderbufferStorage(GL_RENDERBUFFER, storage->config.depth_internalformat, directional_shadow.size, directional_shadow.size); + glRenderbufferStorage(GL_RENDERBUFFER, storage->config.depth_buffer_internalformat, directional_shadow.size, directional_shadow.size); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, directional_shadow.depth); glGenTextures(1, &directional_shadow.color); glBindTexture(GL_TEXTURE_2D, directional_shadow.color); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, directional_shadow.size, directional_shadow.size, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, directional_shadow.size, directional_shadow.size, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); @@ -4061,7 +4061,7 @@ void RasterizerSceneGLES2::initialize() { glGenTextures(1, &directional_shadow.depth); glBindTexture(GL_TEXTURE_2D, directional_shadow.depth); - glTexImage2D(GL_TEXTURE_2D, 0, storage->config.depth_internalformat, directional_shadow.size, directional_shadow.size, 0, GL_DEPTH_COMPONENT, storage->config.depth_type, NULL); + glTexImage2D(GL_TEXTURE_2D, 0, storage->config.depth_internalformat, directional_shadow.size, directional_shadow.size, 0, GL_DEPTH_COMPONENT, storage->config.depth_type, nullptr); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); diff --git a/drivers/gles2/rasterizer_scene_gles2.h b/drivers/gles2/rasterizer_scene_gles2.h index 174cdd8e2e..56c0e632c2 100644 --- a/drivers/gles2/rasterizer_scene_gles2.h +++ b/drivers/gles2/rasterizer_scene_gles2.h @@ -236,7 +236,7 @@ public: /* ENVIRONMENT API */ struct Environment { - VS::EnvironmentBG bg_mode; + RS::EnvironmentBG bg_mode; RID sky; float sky_custom_fov; @@ -259,7 +259,7 @@ public: float glow_intensity; float glow_strength; float glow_bloom; - VS::EnvironmentGlowBlendMode glow_blend_mode; + RS::EnvironmentGlowBlendMode glow_blend_mode; float glow_hdr_bleed_threshold; float glow_hdr_bleed_scale; float glow_hdr_luminance_cap; @@ -269,13 +269,13 @@ public: float dof_blur_far_distance; float dof_blur_far_transition; float dof_blur_far_amount; - VS::EnvironmentDOFBlurQuality dof_blur_far_quality; + RS::EnvironmentDOFBlurQuality dof_blur_far_quality; bool dof_blur_near_enabled; float dof_blur_near_distance; float dof_blur_near_transition; float dof_blur_near_amount; - VS::EnvironmentDOFBlurQuality dof_blur_near_quality; + RS::EnvironmentDOFBlurQuality dof_blur_near_quality; bool adjustments_enabled; float adjustments_brightness; @@ -300,7 +300,7 @@ public: float fog_height_curve; Environment() : - bg_mode(VS::ENV_BG_CLEAR_COLOR), + bg_mode(RS::ENV_BG_CLEAR_COLOR), sky_custom_fov(0.0), bg_energy(1.0), sky_ambient(0), @@ -313,7 +313,7 @@ public: glow_intensity(0.8), glow_strength(1.0), glow_bloom(0.0), - glow_blend_mode(VS::ENV_GLOW_BLEND_MODE_SOFTLIGHT), + glow_blend_mode(RS::ENV_GLOW_BLEND_MODE_SOFTLIGHT), glow_hdr_bleed_threshold(1.0), glow_hdr_bleed_scale(2.0), glow_hdr_luminance_cap(12.0), @@ -322,12 +322,12 @@ public: dof_blur_far_distance(10), dof_blur_far_transition(5), dof_blur_far_amount(0.1), - dof_blur_far_quality(VS::ENV_DOF_BLUR_QUALITY_MEDIUM), + dof_blur_far_quality(RS::ENV_DOF_BLUR_QUALITY_MEDIUM), dof_blur_near_enabled(false), dof_blur_near_distance(2), dof_blur_near_transition(1), dof_blur_near_amount(0.1), - dof_blur_near_quality(VS::ENV_DOF_BLUR_QUALITY_MEDIUM), + dof_blur_near_quality(RS::ENV_DOF_BLUR_QUALITY_MEDIUM), adjustments_enabled(false), adjustments_brightness(1.0), adjustments_contrast(1.0), @@ -353,7 +353,7 @@ public: virtual RID environment_create(); - virtual void environment_set_background(RID p_env, VS::EnvironmentBG p_bg); + virtual void environment_set_background(RID p_env, RS::EnvironmentBG p_bg); virtual void environment_set_sky(RID p_env, RID p_sky); virtual void environment_set_sky_custom_fov(RID p_env, float p_scale); virtual void environment_set_sky_orientation(RID p_env, const Basis &p_orientation); @@ -363,15 +363,15 @@ public: virtual void environment_set_ambient_light(RID p_env, const Color &p_color, float p_energy = 1.0, float p_sky_contribution = 0.0); virtual void environment_set_camera_feed_id(RID p_env, int p_camera_feed_id); - virtual void environment_set_dof_blur_near(RID p_env, bool p_enable, float p_distance, float p_transition, float p_amount, VS::EnvironmentDOFBlurQuality p_quality); - virtual void environment_set_dof_blur_far(RID p_env, bool p_enable, float p_distance, float p_transition, float p_amount, VS::EnvironmentDOFBlurQuality p_quality); - virtual void environment_set_glow(RID p_env, bool p_enable, int p_level_flags, float p_intensity, float p_strength, float p_bloom_threshold, VS::EnvironmentGlowBlendMode p_blend_mode, float p_hdr_bleed_threshold, float p_hdr_bleed_scale, float p_hdr_luminance_cap, bool p_bicubic_upscale); + virtual void environment_set_dof_blur_near(RID p_env, bool p_enable, float p_distance, float p_transition, float p_amount, RS::EnvironmentDOFBlurQuality p_quality); + virtual void environment_set_dof_blur_far(RID p_env, bool p_enable, float p_distance, float p_transition, float p_amount, RS::EnvironmentDOFBlurQuality p_quality); + virtual void environment_set_glow(RID p_env, bool p_enable, int p_level_flags, float p_intensity, float p_strength, float p_bloom_threshold, RS::EnvironmentGlowBlendMode p_blend_mode, float p_hdr_bleed_threshold, float p_hdr_bleed_scale, float p_hdr_luminance_cap, bool p_bicubic_upscale); virtual void environment_set_fog(RID p_env, bool p_enable, float p_begin, float p_end, RID p_gradient_texture); virtual void environment_set_ssr(RID p_env, bool p_enable, int p_max_steps, float p_fade_in, float p_fade_out, float p_depth_tolerance, bool p_roughness); - virtual void environment_set_ssao(RID p_env, bool p_enable, float p_radius, float p_intensity, float p_radius2, float p_intensity2, float p_bias, float p_light_affect, float p_ao_channel_affect, const Color &p_color, VS::EnvironmentSSAOQuality p_quality, VS::EnvironmentSSAOBlur p_blur, float p_bilateral_sharpness); + virtual void environment_set_ssao(RID p_env, bool p_enable, float p_radius, float p_intensity, float p_radius2, float p_intensity2, float p_bias, float p_light_affect, float p_ao_channel_affect, const Color &p_color, RS::EnvironmentSSAOQuality p_quality, RS::EnvironmentSSAOBlur p_blur, float p_bilateral_sharpness); - virtual void environment_set_tonemap(RID p_env, VS::EnvironmentToneMapper p_tone_mapper, float p_exposure, float p_white, bool p_auto_exposure, float p_min_luminance, float p_max_luminance, float p_auto_exp_speed, float p_auto_exp_scale); + virtual void environment_set_tonemap(RID p_env, RS::EnvironmentToneMapper p_tone_mapper, float p_exposure, float p_white, bool p_auto_exposure, float p_min_luminance, float p_max_luminance, float p_auto_exp_speed, float p_auto_exp_scale); virtual void environment_set_adjustment(RID p_env, bool p_enable, float p_brightness, float p_contrast, float p_saturation, RID p_ramp); @@ -381,7 +381,7 @@ public: virtual bool is_environment(RID p_env); - virtual VS::EnvironmentBG environment_get_background(RID p_env); + virtual RS::EnvironmentBG environment_get_background(RID p_env); virtual int environment_get_canvas_max_layer(RID p_env); /* LIGHT INSTANCE */ @@ -575,7 +575,7 @@ public: _FORCE_INLINE_ Element *add_element() { if (element_count + alpha_element_count >= max_elements) - return NULL; + return nullptr; elements[element_count] = &base_elements[element_count]; return elements[element_count++]; @@ -583,7 +583,7 @@ public: _FORCE_INLINE_ Element *add_alpha_element() { if (element_count + alpha_element_count >= max_elements) { - return NULL; + return nullptr; } int idx = max_elements - alpha_element_count - 1; @@ -650,7 +650,7 @@ public: virtual bool free(RID p_rid); virtual void set_scene_pass(uint64_t p_pass); - virtual void set_debug_draw_mode(VS::ViewportDebugDraw p_debug_draw); + virtual void set_debug_draw_mode(RS::ViewportDebugDraw p_debug_draw); void iteration(); void initialize(); diff --git a/drivers/gles2/rasterizer_storage_gles2.cpp b/drivers/gles2/rasterizer_storage_gles2.cpp index f76c7da8e1..b8c7815f6a 100644 --- a/drivers/gles2/rasterizer_storage_gles2.cpp +++ b/drivers/gles2/rasterizer_storage_gles2.cpp @@ -34,7 +34,7 @@ #include "core/project_settings.h" #include "rasterizer_canvas_gles2.h" #include "rasterizer_scene_gles2.h" -#include "servers/visual/shader_language.h" +#include "servers/rendering/shader_language.h" GLuint RasterizerStorageGLES2::system_fbo = 0; @@ -127,11 +127,11 @@ PFNGLCOMPRESSEDTEXSUBIMAGE3DOESPROC glCompressedTexSubImage3DOES; void RasterizerStorageGLES2::bind_quad_array() const { glBindBuffer(GL_ARRAY_BUFFER, resources.quadie); - glVertexAttribPointer(VS::ARRAY_VERTEX, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 4, 0); - glVertexAttribPointer(VS::ARRAY_TEX_UV, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 4, CAST_INT_TO_UCHAR_PTR(8)); + glVertexAttribPointer(RS::ARRAY_VERTEX, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 4, 0); + glVertexAttribPointer(RS::ARRAY_TEX_UV, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 4, CAST_INT_TO_UCHAR_PTR(8)); - glEnableVertexAttribArray(VS::ARRAY_VERTEX); - glEnableVertexAttribArray(VS::ARRAY_TEX_UV); + glEnableVertexAttribArray(RS::ARRAY_VERTEX); + glEnableVertexAttribArray(RS::ARRAY_TEX_UV); } Ref<Image> RasterizerStorageGLES2::_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 { @@ -549,15 +549,15 @@ RID RasterizerStorageGLES2::texture_create() { return texture_owner.make_rid(texture); } -void RasterizerStorageGLES2::texture_allocate(RID p_texture, int p_width, int p_height, int p_depth_3d, Image::Format p_format, VisualServer::TextureType p_type, uint32_t p_flags) { +void RasterizerStorageGLES2::texture_allocate(RID p_texture, int p_width, int p_height, int p_depth_3d, Image::Format p_format, RenderingServer::TextureType p_type, uint32_t p_flags) { GLenum format; GLenum internal_format; GLenum type; bool compressed = false; - if (p_flags & VS::TEXTURE_FLAG_USED_FOR_STREAMING) { - p_flags &= ~VS::TEXTURE_FLAG_MIPMAPS; // no mipies for video + if (p_flags & RS::TEXTURE_FLAG_USED_FOR_STREAMING) { + p_flags &= ~RS::TEXTURE_FLAG_MIPMAPS; // no mipies for video } Texture *texture = texture_owner.getornull(p_texture); @@ -570,15 +570,15 @@ void RasterizerStorageGLES2::texture_allocate(RID p_texture, int p_width, int p_ texture->type = p_type; switch (p_type) { - case VS::TEXTURE_TYPE_2D: { + case RS::TEXTURE_TYPE_2D: { texture->target = GL_TEXTURE_2D; texture->images.resize(1); } break; - case VS::TEXTURE_TYPE_CUBEMAP: { + case RS::TEXTURE_TYPE_CUBEMAP: { texture->target = GL_TEXTURE_CUBE_MAP; texture->images.resize(6); } break; - case VS::TEXTURE_TYPE_2D_ARRAY: { + case RS::TEXTURE_TYPE_2D_ARRAY: { if (config.texture_array_supported) { texture->target = GL_TEXTURE_2D_ARRAY; texture->images.resize(p_depth_3d); @@ -587,7 +587,7 @@ void RasterizerStorageGLES2::texture_allocate(RID p_texture, int p_width, int p_ return; } } break; - case VS::TEXTURE_TYPE_3D: { + case RS::TEXTURE_TYPE_3D: { if (config.texture_3d_supported) { texture->target = GL_TEXTURE_3D; texture->images.resize(p_depth_3d); @@ -611,12 +611,12 @@ void RasterizerStorageGLES2::texture_allocate(RID p_texture, int p_width, int p_ bool is_po2 = p_width == po2_width && p_height == po2_height; - if (!is_po2 && (p_flags & VS::TEXTURE_FLAG_REPEAT || p_flags & VS::TEXTURE_FLAG_MIPMAPS)) { + if (!is_po2 && (p_flags & RS::TEXTURE_FLAG_REPEAT || p_flags & RS::TEXTURE_FLAG_MIPMAPS)) { - if (p_flags & VS::TEXTURE_FLAG_USED_FOR_STREAMING) { + if (p_flags & RS::TEXTURE_FLAG_USED_FOR_STREAMING) { //not supported ERR_PRINT("Streaming texture for non power of 2 or has mipmaps on this hardware: " + texture->path + "'. Mipmaps and repeat disabled."); - texture->flags &= ~(VS::TEXTURE_FLAG_REPEAT | VS::TEXTURE_FLAG_MIPMAPS); + texture->flags &= ~(RS::TEXTURE_FLAG_REPEAT | RS::TEXTURE_FLAG_MIPMAPS); } else { texture->alloc_height = po2_height; texture->alloc_width = po2_width; @@ -640,7 +640,7 @@ void RasterizerStorageGLES2::texture_allocate(RID p_texture, int p_width, int p_ glBindTexture(texture->target, texture->tex_id); #if defined(GLES_OVER_GL) || defined(ANDROID_ENABLED) - if ((p_type == VS::TEXTURE_TYPE_3D && config.texture_3d_supported) || (p_type == VS::TEXTURE_TYPE_2D_ARRAY && config.texture_array_supported)) { + if ((p_type == RS::TEXTURE_TYPE_3D && config.texture_3d_supported) || (p_type == RS::TEXTURE_TYPE_2D_ARRAY && config.texture_array_supported)) { int width = p_width; int height = p_height; @@ -648,23 +648,23 @@ void RasterizerStorageGLES2::texture_allocate(RID p_texture, int p_width, int p_ int mipmaps = 0; - while (width > 0 || height > 0 || (p_type == VS::TEXTURE_TYPE_3D && depth > 0)) { + while (width > 0 || height > 0 || (p_type == RS::TEXTURE_TYPE_3D && depth > 0)) { width = MAX(1, width); height = MAX(1, height); depth = MAX(1, depth); - glTexImage3D(texture->target, mipmaps, internal_format, width, height, depth, 0, format, type, NULL); + glTexImage3D(texture->target, mipmaps, internal_format, width, height, depth, 0, format, type, nullptr); width /= 2; height /= 2; - if (p_type == VS::TEXTURE_TYPE_3D) { + if (p_type == RS::TEXTURE_TYPE_3D) { depth /= 2; } mipmaps++; - if (!(p_flags & VS::TEXTURE_FLAG_MIPMAPS)) + if (!(p_flags & RS::TEXTURE_FLAG_MIPMAPS)) break; } #ifdef GLES_OVER_GL @@ -674,9 +674,9 @@ void RasterizerStorageGLES2::texture_allocate(RID p_texture, int p_width, int p_ } else #endif - if (p_flags & VS::TEXTURE_FLAG_USED_FOR_STREAMING) { + if (p_flags & RS::TEXTURE_FLAG_USED_FOR_STREAMING) { //prealloc if video - glTexImage2D(texture->target, 0, internal_format, texture->alloc_width, texture->alloc_height, 0, format, type, NULL); + glTexImage2D(texture->target, 0, internal_format, texture->alloc_width, texture->alloc_height, 0, format, type, nullptr); } texture->active = true; @@ -686,7 +686,7 @@ void RasterizerStorageGLES2::texture_set_data(RID p_texture, const Ref<Image> &p Texture *texture = texture_owner.getornull(p_texture); ERR_FAIL_COND(!texture); - if ((texture->type == VS::TEXTURE_TYPE_2D_ARRAY && !config.texture_array_supported) || (texture->type == VS::TEXTURE_TYPE_3D && !config.texture_3d_supported)) { + if ((texture->type == RS::TEXTURE_TYPE_2D_ARRAY && !config.texture_array_supported) || (texture->type == RS::TEXTURE_TYPE_3D && !config.texture_3d_supported)) { return; } ERR_FAIL_COND(!texture->active); @@ -699,7 +699,7 @@ void RasterizerStorageGLES2::texture_set_data(RID p_texture, const Ref<Image> &p GLenum internal_format; bool compressed = false; - if (config.keep_original_textures && !(texture->flags & VS::TEXTURE_FLAG_USED_FOR_STREAMING)) { + if (config.keep_original_textures && !(texture->flags & RS::TEXTURE_FLAG_USED_FOR_STREAMING)) { texture->images.write[p_layer] = p_image; } @@ -717,7 +717,7 @@ void RasterizerStorageGLES2::texture_set_data(RID p_texture, const Ref<Image> &p img->resize_to_po2(false); } - if (config.shrink_textures_x2 && (p_image->has_mipmaps() || !p_image->is_compressed()) && !(texture->flags & VS::TEXTURE_FLAG_USED_FOR_STREAMING)) { + if (config.shrink_textures_x2 && (p_image->has_mipmaps() || !p_image->is_compressed()) && !(texture->flags & RS::TEXTURE_FLAG_USED_FOR_STREAMING)) { texture->alloc_height = MAX(1, texture->alloc_height / 2); texture->alloc_width = MAX(1, texture->alloc_width / 2); @@ -734,17 +734,17 @@ void RasterizerStorageGLES2::texture_set_data(RID p_texture, const Ref<Image> &p GLenum blit_target = GL_TEXTURE_2D; switch (texture->type) { - case VS::TEXTURE_TYPE_2D: { + case RS::TEXTURE_TYPE_2D: { blit_target = GL_TEXTURE_2D; } break; - case VS::TEXTURE_TYPE_CUBEMAP: { + case RS::TEXTURE_TYPE_CUBEMAP: { ERR_FAIL_INDEX(p_layer, 6); blit_target = _cube_side_enum[p_layer]; } break; - case VS::TEXTURE_TYPE_2D_ARRAY: { + case RS::TEXTURE_TYPE_2D_ARRAY: { blit_target = GL_TEXTURE_2D_ARRAY; } break; - case VS::TEXTURE_TYPE_3D: { + case RS::TEXTURE_TYPE_3D: { blit_target = GL_TEXTURE_3D; } break; } @@ -758,17 +758,17 @@ void RasterizerStorageGLES2::texture_set_data(RID p_texture, const Ref<Image> &p texture->ignore_mipmaps = compressed && !img->has_mipmaps(); - if ((texture->flags & VS::TEXTURE_FLAG_MIPMAPS) && !texture->ignore_mipmaps) + if ((texture->flags & RS::TEXTURE_FLAG_MIPMAPS) && !texture->ignore_mipmaps) glTexParameteri(texture->target, GL_TEXTURE_MIN_FILTER, config.use_fast_texture_filter ? GL_LINEAR_MIPMAP_NEAREST : GL_LINEAR_MIPMAP_LINEAR); else { - if (texture->flags & VS::TEXTURE_FLAG_FILTER) { + if (texture->flags & RS::TEXTURE_FLAG_FILTER) { glTexParameteri(texture->target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); } else { glTexParameteri(texture->target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); } } - if (texture->flags & VS::TEXTURE_FLAG_FILTER) { + if (texture->flags & RS::TEXTURE_FLAG_FILTER) { glTexParameteri(texture->target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // Linear Filtering @@ -777,9 +777,9 @@ void RasterizerStorageGLES2::texture_set_data(RID p_texture, const Ref<Image> &p glTexParameteri(texture->target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); // raw Filtering } - if (((texture->flags & VS::TEXTURE_FLAG_REPEAT) || (texture->flags & VS::TEXTURE_FLAG_MIRRORED_REPEAT)) && texture->target != GL_TEXTURE_CUBE_MAP) { + if (((texture->flags & RS::TEXTURE_FLAG_REPEAT) || (texture->flags & RS::TEXTURE_FLAG_MIRRORED_REPEAT)) && texture->target != GL_TEXTURE_CUBE_MAP) { - if (texture->flags & VS::TEXTURE_FLAG_MIRRORED_REPEAT) { + if (texture->flags & RS::TEXTURE_FLAG_MIRRORED_REPEAT) { glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT); } else { @@ -793,7 +793,7 @@ void RasterizerStorageGLES2::texture_set_data(RID p_texture, const Ref<Image> &p glTexParameterf(texture->target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); } - int mipmaps = ((texture->flags & VS::TEXTURE_FLAG_MIPMAPS) && img->has_mipmaps()) ? img->get_mipmap_count() + 1 : 1; + int mipmaps = ((texture->flags & RS::TEXTURE_FLAG_MIPMAPS) && img->has_mipmaps()) ? img->get_mipmap_count() + 1 : 1; int w = img->get_width(); int h = img->get_height(); @@ -804,7 +804,7 @@ void RasterizerStorageGLES2::texture_set_data(RID p_texture, const Ref<Image> &p int size, ofs; img->get_mipmap_offset_and_size(i, ofs, size); - if (texture->type == VS::TEXTURE_TYPE_2D || texture->type == VS::TEXTURE_TYPE_CUBEMAP) { + if (texture->type == RS::TEXTURE_TYPE_2D || texture->type == RS::TEXTURE_TYPE_CUBEMAP) { if (compressed) { glPixelStorei(GL_UNPACK_ALIGNMENT, 4); @@ -816,7 +816,7 @@ void RasterizerStorageGLES2::texture_set_data(RID p_texture, const Ref<Image> &p } else { glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - if (texture->flags & VS::TEXTURE_FLAG_USED_FOR_STREAMING) { + if (texture->flags & RS::TEXTURE_FLAG_USED_FOR_STREAMING) { glTexSubImage2D(blit_target, i, 0, 0, w, h, format, type, &read[ofs]); } else { glTexImage2D(blit_target, i, internal_format, w, h, 0, format, type, &read[ofs]); @@ -854,7 +854,7 @@ void RasterizerStorageGLES2::texture_set_data(RID p_texture, const Ref<Image> &p texture->stored_cube_sides |= (1 << p_layer); - if ((texture->flags & VS::TEXTURE_FLAG_MIPMAPS) && mipmaps == 1 && !texture->ignore_mipmaps && (texture->type != VS::TEXTURE_TYPE_CUBEMAP || texture->stored_cube_sides == (1 << 6) - 1)) { + if ((texture->flags & RS::TEXTURE_FLAG_MIPMAPS) && mipmaps == 1 && !texture->ignore_mipmaps && (texture->type != RS::TEXTURE_TYPE_CUBEMAP || texture->stored_cube_sides == (1 << 6) - 1)) { //generate mipmaps if they were requested and the image does not contain them glGenerateMipmap(texture->target); } @@ -875,7 +875,7 @@ Ref<Image> RasterizerStorageGLES2::texture_get_data(RID p_texture, int p_layer) ERR_FAIL_COND_V(!texture->active, Ref<Image>()); ERR_FAIL_COND_V(texture->data_size == 0 && !texture->render_target, Ref<Image>()); - if (texture->type == VS::TEXTURE_TYPE_CUBEMAP && p_layer < 6 && p_layer >= 0 && !texture->images[p_layer].is_null()) { + if (texture->type == RS::TEXTURE_TYPE_CUBEMAP && p_layer < 6 && p_layer >= 0 && !texture->images[p_layer].is_null()) { return texture->images[p_layer]; } @@ -946,7 +946,7 @@ Ref<Image> RasterizerStorageGLES2::texture_get_data(RID p_texture, int p_layer) glBindFramebuffer(GL_FRAMEBUFFER, temp_framebuffer); glBindTexture(GL_TEXTURE_2D, temp_color_texture); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture->alloc_width, texture->alloc_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture->alloc_width, texture->alloc_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); @@ -997,16 +997,16 @@ void RasterizerStorageGLES2::texture_set_flags(RID p_texture, uint32_t p_flags) Texture *texture = texture_owner.getornull(p_texture); ERR_FAIL_COND(!texture); - bool had_mipmaps = texture->flags & VS::TEXTURE_FLAG_MIPMAPS; + bool had_mipmaps = texture->flags & RS::TEXTURE_FLAG_MIPMAPS; texture->flags = p_flags; glActiveTexture(GL_TEXTURE0); glBindTexture(texture->target, texture->tex_id); - if (((texture->flags & VS::TEXTURE_FLAG_REPEAT) || (texture->flags & VS::TEXTURE_FLAG_MIRRORED_REPEAT)) && texture->target != GL_TEXTURE_CUBE_MAP) { + if (((texture->flags & RS::TEXTURE_FLAG_REPEAT) || (texture->flags & RS::TEXTURE_FLAG_MIRRORED_REPEAT)) && texture->target != GL_TEXTURE_CUBE_MAP) { - if (texture->flags & VS::TEXTURE_FLAG_MIRRORED_REPEAT) { + if (texture->flags & RS::TEXTURE_FLAG_MIRRORED_REPEAT) { glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT); } else { @@ -1019,21 +1019,21 @@ void RasterizerStorageGLES2::texture_set_flags(RID p_texture, uint32_t p_flags) glTexParameterf(texture->target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); } - if ((texture->flags & VS::TEXTURE_FLAG_MIPMAPS) && !texture->ignore_mipmaps) { + if ((texture->flags & RS::TEXTURE_FLAG_MIPMAPS) && !texture->ignore_mipmaps) { if (!had_mipmaps && texture->mipmaps == 1) { glGenerateMipmap(texture->target); } glTexParameteri(texture->target, GL_TEXTURE_MIN_FILTER, config.use_fast_texture_filter ? GL_LINEAR_MIPMAP_NEAREST : GL_LINEAR_MIPMAP_LINEAR); } else { - if (texture->flags & VS::TEXTURE_FLAG_FILTER) { + if (texture->flags & RS::TEXTURE_FLAG_FILTER) { glTexParameteri(texture->target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); } else { glTexParameteri(texture->target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); } } - if (texture->flags & VS::TEXTURE_FLAG_FILTER) { + if (texture->flags & RS::TEXTURE_FLAG_FILTER) { glTexParameteri(texture->target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // Linear Filtering @@ -1059,10 +1059,10 @@ Image::Format RasterizerStorageGLES2::texture_get_format(RID p_texture) const { return texture->format; } -VisualServer::TextureType RasterizerStorageGLES2::texture_get_type(RID p_texture) const { +RenderingServer::TextureType RasterizerStorageGLES2::texture_get_type(RID p_texture) const { Texture *texture = texture_owner.getornull(p_texture); - ERR_FAIL_COND_V(!texture, VS::TEXTURE_TYPE_2D); + ERR_FAIL_COND_V(!texture, RS::TEXTURE_TYPE_2D); return texture->type; } @@ -1135,7 +1135,7 @@ String RasterizerStorageGLES2::texture_get_path(RID p_texture) const { return texture->path; } -void RasterizerStorageGLES2::texture_debug_usage(List<VS::TextureInfo> *r_info) { +void RasterizerStorageGLES2::texture_debug_usage(List<RS::TextureInfo> *r_info) { List<RID> textures; texture_owner.get_owned_list(&textures); @@ -1144,7 +1144,7 @@ void RasterizerStorageGLES2::texture_debug_usage(List<VS::TextureInfo> *r_info) Texture *t = texture_owner.getornull(E->get()); if (!t) continue; - VS::TextureInfo tinfo; + RS::TextureInfo tinfo; tinfo.path = t->path; tinfo.format = t->format; tinfo.width = t->alloc_width; @@ -1180,7 +1180,7 @@ void RasterizerStorageGLES2::texture_set_proxy(RID p_texture, RID p_proxy) { if (texture->proxy) { texture->proxy->proxy_owners.erase(texture); - texture->proxy = NULL; + texture->proxy = nullptr; } if (p_proxy.is_valid()) { @@ -1200,7 +1200,7 @@ void RasterizerStorageGLES2::texture_set_force_redraw_if_visible(RID p_texture, texture->redraw_if_visible = p_enable; } -void RasterizerStorageGLES2::texture_set_detect_3d_callback(RID p_texture, VisualServer::TextureDetectCallback p_callback, void *p_userdata) { +void RasterizerStorageGLES2::texture_set_detect_3d_callback(RID p_texture, RenderingServer::TextureDetectCallback p_callback, void *p_userdata) { Texture *texture = texture_owner.getornull(p_texture); ERR_FAIL_COND(!texture); @@ -1208,7 +1208,7 @@ void RasterizerStorageGLES2::texture_set_detect_3d_callback(RID p_texture, Visua texture->detect_3d_ud = p_userdata; } -void RasterizerStorageGLES2::texture_set_detect_srgb_callback(RID p_texture, VisualServer::TextureDetectCallback p_callback, void *p_userdata) { +void RasterizerStorageGLES2::texture_set_detect_srgb_callback(RID p_texture, RenderingServer::TextureDetectCallback p_callback, void *p_userdata) { Texture *texture = texture_owner.getornull(p_texture); ERR_FAIL_COND(!texture); @@ -1216,7 +1216,7 @@ void RasterizerStorageGLES2::texture_set_detect_srgb_callback(RID p_texture, Vis texture->detect_srgb_ud = p_userdata; } -void RasterizerStorageGLES2::texture_set_detect_normal_callback(RID p_texture, VisualServer::TextureDetectCallback p_callback, void *p_userdata) { +void RasterizerStorageGLES2::texture_set_detect_normal_callback(RID p_texture, RenderingServer::TextureDetectCallback p_callback, void *p_userdata) { Texture *texture = texture_owner.getornull(p_texture); ERR_FAIL_COND(!texture); @@ -1265,7 +1265,7 @@ void RasterizerStorageGLES2::sky_set_texture(RID p_sky, RID p_panorama, int p_ra glDisable(GL_SCISSOR_TEST); glDisable(GL_BLEND); - for (int i = 0; i < VS::ARRAY_MAX - 1; i++) { + for (int i = 0; i < RS::ARRAY_MAX - 1; i++) { glDisableVertexAttribArray(i); } } @@ -1301,7 +1301,7 @@ void RasterizerStorageGLES2::sky_set_texture(RID p_sky, RID p_panorama, int p_ra // Mobile hardware (PowerVR specially) prefers this approach, // the previous approach with manual lod levels kills the game. for (int i = 0; i < 6; i++) { - glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, internal_format, size, size, 0, format, type, NULL); + glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, internal_format, size, size, 0, format, type, nullptr); } glGenerateMipmap(GL_TEXTURE_CUBE_MAP); @@ -1330,7 +1330,7 @@ void RasterizerStorageGLES2::sky_set_texture(RID p_sky, RID p_panorama, int p_ra //make framebuffer size the texture size, need to use a separate texture for compatibility glActiveTexture(GL_TEXTURE3); glBindTexture(GL_TEXTURE_2D, resources.mipmap_blur_color); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, size, size, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, size, size, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, resources.mipmap_blur_color, 0); if (lod == 1) { @@ -1397,7 +1397,7 @@ void RasterizerStorageGLES2::sky_set_texture(RID p_sky, RID p_panorama, int p_ra RID RasterizerStorageGLES2::shader_create() { Shader *shader = memnew(Shader); - shader->mode = VS::SHADER_SPATIAL; + shader->mode = RS::SHADER_SPATIAL; shader->shader = &scene->state.scene_shader; RID rid = shader_owner.make_rid(shader); _shader_make_dirty(shader); @@ -1421,16 +1421,16 @@ void RasterizerStorageGLES2::shader_set_code(RID p_shader, const String &p_code) shader->code = p_code; String mode_string = ShaderLanguage::get_shader_type(p_code); - VS::ShaderMode mode; + RS::ShaderMode mode; if (mode_string == "canvas_item") - mode = VS::SHADER_CANVAS_ITEM; + mode = RS::SHADER_CANVAS_ITEM; else if (mode_string == "particles") - mode = VS::SHADER_PARTICLES; + mode = RS::SHADER_PARTICLES; else if (mode_string == "sky") - mode = VS::SHADER_SKY; + mode = RS::SHADER_SKY; else - mode = VS::SHADER_SPATIAL; + mode = RS::SHADER_SPATIAL; if (shader->custom_code_id && mode != shader->mode) { shader->shader->free_custom_shader(shader->custom_code_id); @@ -1440,10 +1440,10 @@ void RasterizerStorageGLES2::shader_set_code(RID p_shader, const String &p_code) shader->mode = mode; // TODO handle all shader types - if (mode == VS::SHADER_CANVAS_ITEM) { + if (mode == RS::SHADER_CANVAS_ITEM) { shader->shader = &canvas->state.canvas_shader; - } else if (mode == VS::SHADER_SPATIAL) { + } else if (mode == RS::SHADER_SPATIAL) { shader->shader = &scene->state.scene_shader; } else { return; @@ -1477,11 +1477,11 @@ void RasterizerStorageGLES2::_update_shader(Shader *p_shader) const { } ShaderCompilerGLES2::GeneratedCode gen_code; - ShaderCompilerGLES2::IdentifierActions *actions = NULL; + ShaderCompilerGLES2::IdentifierActions *actions = nullptr; switch (p_shader->mode) { - case VS::SHADER_CANVAS_ITEM: { + case RS::SHADER_CANVAS_ITEM: { p_shader->canvas_item.light_mode = Shader::CanvasItem::LIGHT_MODE_NORMAL; p_shader->canvas_item.blend_mode = Shader::CanvasItem::BLEND_MODE_MIX; @@ -1508,7 +1508,7 @@ void RasterizerStorageGLES2::_update_shader(Shader *p_shader) const { actions->uniforms = &p_shader->uniforms; } break; - case VS::SHADER_SPATIAL: { + case RS::SHADER_SPATIAL: { p_shader->spatial.blend_mode = Shader::Spatial::BLEND_MODE_MIX; p_shader->spatial.depth_draw_mode = Shader::Spatial::DEPTH_DRAW_OPAQUE; p_shader->spatial.cull_mode = Shader::Spatial::CULL_MODE_BACK; @@ -1949,8 +1949,8 @@ void RasterizerStorageGLES2::material_remove_instance_owner(RID p_material, Rast } void RasterizerStorageGLES2::material_set_render_priority(RID p_material, int priority) { - ERR_FAIL_COND(priority < VS::MATERIAL_RENDER_PRIORITY_MIN); - ERR_FAIL_COND(priority > VS::MATERIAL_RENDER_PRIORITY_MAX); + ERR_FAIL_COND(priority < RS::MATERIAL_RENDER_PRIORITY_MIN); + ERR_FAIL_COND(priority > RS::MATERIAL_RENDER_PRIORITY_MAX); Material *material = material_owner.getornull(p_material); ERR_FAIL_COND(!material); @@ -1975,7 +1975,7 @@ void RasterizerStorageGLES2::_update_material(Material *p_material) { bool can_cast_shadow = false; bool is_animated = false; - if (p_material->shader && p_material->shader->mode == VS::SHADER_SPATIAL) { + if (p_material->shader && p_material->shader->mode == RS::SHADER_SPATIAL) { if (p_material->shader->spatial.blend_mode == Shader::Spatial::BLEND_MODE_MIX && (!p_material->shader->spatial.uses_alpha || p_material->shader->spatial.depth_draw_mode == Shader::Spatial::DEPTH_DRAW_ALPHA_PREPASS)) { @@ -2087,14 +2087,14 @@ static Vector<uint8_t> _unpack_half_floats(const Vector<uint8_t> &array, uint32_ uint32_t p_format = format; - static int src_size[VS::ARRAY_MAX]; - static int dst_size[VS::ARRAY_MAX]; - static int to_convert[VS::ARRAY_MAX]; + static int src_size[RS::ARRAY_MAX]; + static int dst_size[RS::ARRAY_MAX]; + static int to_convert[RS::ARRAY_MAX]; int src_stride = 0; int dst_stride = 0; - for (int i = 0; i < VS::ARRAY_MAX; i++) { + for (int i = 0; i < RS::ARRAY_MAX; i++) { to_convert[i] = 0; if (!(p_format & (1 << i))) { @@ -2105,11 +2105,11 @@ static Vector<uint8_t> _unpack_half_floats(const Vector<uint8_t> &array, uint32_ switch (i) { - case VS::ARRAY_VERTEX: { + case RS::ARRAY_VERTEX: { - if (p_format & VS::ARRAY_COMPRESS_VERTEX) { + if (p_format & RS::ARRAY_COMPRESS_VERTEX) { - if (p_format & VS::ARRAY_FLAG_USE_2D_VERTICES) { + if (p_format & RS::ARRAY_FLAG_USE_2D_VERTICES) { src_size[i] = 4; dst_size[i] = 8; to_convert[i] = 2; @@ -2119,10 +2119,10 @@ static Vector<uint8_t> _unpack_half_floats(const Vector<uint8_t> &array, uint32_ to_convert[i] = 3; } - format &= ~VS::ARRAY_COMPRESS_VERTEX; + format &= ~RS::ARRAY_COMPRESS_VERTEX; } else { - if (p_format & VS::ARRAY_FLAG_USE_2D_VERTICES) { + if (p_format & RS::ARRAY_FLAG_USE_2D_VERTICES) { src_size[i] = 8; dst_size[i] = 8; } else { @@ -2132,9 +2132,9 @@ static Vector<uint8_t> _unpack_half_floats(const Vector<uint8_t> &array, uint32_ } } break; - case VS::ARRAY_NORMAL: { + case RS::ARRAY_NORMAL: { - if (p_format & VS::ARRAY_COMPRESS_NORMAL) { + if (p_format & RS::ARRAY_COMPRESS_NORMAL) { src_size[i] = 4; dst_size[i] = 4; } else { @@ -2143,9 +2143,9 @@ static Vector<uint8_t> _unpack_half_floats(const Vector<uint8_t> &array, uint32_ } } break; - case VS::ARRAY_TANGENT: { + case RS::ARRAY_TANGENT: { - if (p_format & VS::ARRAY_COMPRESS_TANGENT) { + if (p_format & RS::ARRAY_COMPRESS_TANGENT) { src_size[i] = 4; dst_size[i] = 4; } else { @@ -2154,9 +2154,9 @@ static Vector<uint8_t> _unpack_half_floats(const Vector<uint8_t> &array, uint32_ } } break; - case VS::ARRAY_COLOR: { + case RS::ARRAY_COLOR: { - if (p_format & VS::ARRAY_COMPRESS_COLOR) { + if (p_format & RS::ARRAY_COMPRESS_COLOR) { src_size[i] = 4; dst_size[i] = 4; } else { @@ -2165,12 +2165,12 @@ static Vector<uint8_t> _unpack_half_floats(const Vector<uint8_t> &array, uint32_ } } break; - case VS::ARRAY_TEX_UV: { + case RS::ARRAY_TEX_UV: { - if (p_format & VS::ARRAY_COMPRESS_TEX_UV) { + if (p_format & RS::ARRAY_COMPRESS_TEX_UV) { src_size[i] = 4; to_convert[i] = 2; - format &= ~VS::ARRAY_COMPRESS_TEX_UV; + format &= ~RS::ARRAY_COMPRESS_TEX_UV; } else { src_size[i] = 8; } @@ -2178,12 +2178,12 @@ static Vector<uint8_t> _unpack_half_floats(const Vector<uint8_t> &array, uint32_ dst_size[i] = 8; } break; - case VS::ARRAY_TEX_UV2: { + case RS::ARRAY_TEX_UV2: { - if (p_format & VS::ARRAY_COMPRESS_TEX_UV2) { + if (p_format & RS::ARRAY_COMPRESS_TEX_UV2) { src_size[i] = 4; to_convert[i] = 2; - format &= ~VS::ARRAY_COMPRESS_TEX_UV2; + format &= ~RS::ARRAY_COMPRESS_TEX_UV2; } else { src_size[i] = 8; } @@ -2191,9 +2191,9 @@ static Vector<uint8_t> _unpack_half_floats(const Vector<uint8_t> &array, uint32_ dst_size[i] = 8; } break; - case VS::ARRAY_BONES: { + case RS::ARRAY_BONES: { - if (p_format & VS::ARRAY_FLAG_USE_16_BIT_BONES) { + if (p_format & RS::ARRAY_FLAG_USE_16_BIT_BONES) { src_size[i] = 8; dst_size[i] = 8; } else { @@ -2202,9 +2202,9 @@ static Vector<uint8_t> _unpack_half_floats(const Vector<uint8_t> &array, uint32_ } } break; - case VS::ARRAY_WEIGHTS: { + case RS::ARRAY_WEIGHTS: { - if (p_format & VS::ARRAY_COMPRESS_WEIGHTS) { + if (p_format & RS::ARRAY_COMPRESS_WEIGHTS) { src_size[i] = 8; dst_size[i] = 8; } else { @@ -2213,7 +2213,7 @@ static Vector<uint8_t> _unpack_half_floats(const Vector<uint8_t> &array, uint32_ } } break; - case VS::ARRAY_INDEX: { + case RS::ARRAY_INDEX: { src_size[i] = 0; dst_size[i] = 0; @@ -2234,7 +2234,7 @@ static Vector<uint8_t> _unpack_half_floats(const Vector<uint8_t> &array, uint32_ int src_offset = 0; int dst_offset = 0; - for (int i = 0; i < VS::ARRAY_MAX; i++) { + for (int i = 0; i < RS::ARRAY_MAX; i++) { if (src_size[i] == 0) { continue; //no go @@ -2272,27 +2272,27 @@ static Vector<uint8_t> _unpack_half_floats(const Vector<uint8_t> &array, uint32_ return ret; } -void RasterizerStorageGLES2::mesh_add_surface(RID p_mesh, uint32_t p_format, VS::PrimitiveType p_primitive, const Vector<uint8_t> &p_array, int p_vertex_count, const Vector<uint8_t> &p_index_array, int p_index_count, const AABB &p_aabb, const Vector<Vector<uint8_t>> &p_blend_shapes, const Vector<AABB> &p_bone_aabbs) { +void RasterizerStorageGLES2::mesh_add_surface(RID p_mesh, uint32_t p_format, RS::PrimitiveType p_primitive, const Vector<uint8_t> &p_array, int p_vertex_count, const Vector<uint8_t> &p_index_array, int p_index_count, const AABB &p_aabb, const Vector<Vector<uint8_t>> &p_blend_shapes, const Vector<AABB> &p_bone_aabbs) { Mesh *mesh = mesh_owner.getornull(p_mesh); ERR_FAIL_COND(!mesh); - ERR_FAIL_COND(!(p_format & VS::ARRAY_FORMAT_VERTEX)); + ERR_FAIL_COND(!(p_format & RS::ARRAY_FORMAT_VERTEX)); //must have index and bones, both. { - uint32_t bones_weight = VS::ARRAY_FORMAT_BONES | VS::ARRAY_FORMAT_WEIGHTS; + uint32_t bones_weight = RS::ARRAY_FORMAT_BONES | RS::ARRAY_FORMAT_WEIGHTS; ERR_FAIL_COND_MSG((p_format & bones_weight) && (p_format & bones_weight) != bones_weight, "Array must have both bones and weights in format or none."); } //bool has_morph = p_blend_shapes.size(); - Surface::Attrib attribs[VS::ARRAY_MAX]; + Surface::Attrib attribs[RS::ARRAY_MAX]; int stride = 0; bool uses_half_float = false; - for (int i = 0; i < VS::ARRAY_MAX; i++) { + for (int i = 0; i < RS::ARRAY_MAX; i++) { attribs[i].index = i; @@ -2308,15 +2308,15 @@ void RasterizerStorageGLES2::mesh_add_surface(RID p_mesh, uint32_t p_format, VS: switch (i) { - case VS::ARRAY_VERTEX: { + case RS::ARRAY_VERTEX: { - if (p_format & VS::ARRAY_FLAG_USE_2D_VERTICES) { + if (p_format & RS::ARRAY_FLAG_USE_2D_VERTICES) { attribs[i].size = 2; } else { - attribs[i].size = (p_format & VS::ARRAY_COMPRESS_VERTEX) ? 4 : 3; + attribs[i].size = (p_format & RS::ARRAY_COMPRESS_VERTEX) ? 4 : 3; } - if (p_format & VS::ARRAY_COMPRESS_VERTEX) { + if (p_format & RS::ARRAY_COMPRESS_VERTEX) { attribs[i].type = _GL_HALF_FLOAT_OES; stride += attribs[i].size * 2; uses_half_float = true; @@ -2328,11 +2328,11 @@ void RasterizerStorageGLES2::mesh_add_surface(RID p_mesh, uint32_t p_format, VS: attribs[i].normalized = GL_FALSE; } break; - case VS::ARRAY_NORMAL: { + case RS::ARRAY_NORMAL: { attribs[i].size = 3; - if (p_format & VS::ARRAY_COMPRESS_NORMAL) { + if (p_format & RS::ARRAY_COMPRESS_NORMAL) { attribs[i].type = GL_BYTE; stride += 4; //pad extra byte attribs[i].normalized = GL_TRUE; @@ -2343,11 +2343,11 @@ void RasterizerStorageGLES2::mesh_add_surface(RID p_mesh, uint32_t p_format, VS: } } break; - case VS::ARRAY_TANGENT: { + case RS::ARRAY_TANGENT: { attribs[i].size = 4; - if (p_format & VS::ARRAY_COMPRESS_TANGENT) { + if (p_format & RS::ARRAY_COMPRESS_TANGENT) { attribs[i].type = GL_BYTE; stride += 4; attribs[i].normalized = GL_TRUE; @@ -2358,11 +2358,11 @@ void RasterizerStorageGLES2::mesh_add_surface(RID p_mesh, uint32_t p_format, VS: } } break; - case VS::ARRAY_COLOR: { + case RS::ARRAY_COLOR: { attribs[i].size = 4; - if (p_format & VS::ARRAY_COMPRESS_COLOR) { + if (p_format & RS::ARRAY_COMPRESS_COLOR) { attribs[i].type = GL_UNSIGNED_BYTE; stride += 4; attribs[i].normalized = GL_TRUE; @@ -2373,11 +2373,11 @@ void RasterizerStorageGLES2::mesh_add_surface(RID p_mesh, uint32_t p_format, VS: } } break; - case VS::ARRAY_TEX_UV: { + case RS::ARRAY_TEX_UV: { attribs[i].size = 2; - if (p_format & VS::ARRAY_COMPRESS_TEX_UV) { + if (p_format & RS::ARRAY_COMPRESS_TEX_UV) { attribs[i].type = _GL_HALF_FLOAT_OES; stride += 4; uses_half_float = true; @@ -2389,11 +2389,11 @@ void RasterizerStorageGLES2::mesh_add_surface(RID p_mesh, uint32_t p_format, VS: attribs[i].normalized = GL_FALSE; } break; - case VS::ARRAY_TEX_UV2: { + case RS::ARRAY_TEX_UV2: { attribs[i].size = 2; - if (p_format & VS::ARRAY_COMPRESS_TEX_UV2) { + if (p_format & RS::ARRAY_COMPRESS_TEX_UV2) { attribs[i].type = _GL_HALF_FLOAT_OES; stride += 4; uses_half_float = true; @@ -2404,11 +2404,11 @@ void RasterizerStorageGLES2::mesh_add_surface(RID p_mesh, uint32_t p_format, VS: attribs[i].normalized = GL_FALSE; } break; - case VS::ARRAY_BONES: { + case RS::ARRAY_BONES: { attribs[i].size = 4; - if (p_format & VS::ARRAY_FLAG_USE_16_BIT_BONES) { + if (p_format & RS::ARRAY_FLAG_USE_16_BIT_BONES) { attribs[i].type = GL_UNSIGNED_SHORT; stride += 8; } else { @@ -2420,11 +2420,11 @@ void RasterizerStorageGLES2::mesh_add_surface(RID p_mesh, uint32_t p_format, VS: attribs[i].integer = true; } break; - case VS::ARRAY_WEIGHTS: { + case RS::ARRAY_WEIGHTS: { attribs[i].size = 4; - if (p_format & VS::ARRAY_COMPRESS_WEIGHTS) { + if (p_format & RS::ARRAY_COMPRESS_WEIGHTS) { attribs[i].type = GL_UNSIGNED_SHORT; stride += 8; @@ -2436,7 +2436,7 @@ void RasterizerStorageGLES2::mesh_add_surface(RID p_mesh, uint32_t p_format, VS: } } break; - case VS::ARRAY_INDEX: { + case RS::ARRAY_INDEX: { attribs[i].size = 1; @@ -2454,7 +2454,7 @@ void RasterizerStorageGLES2::mesh_add_surface(RID p_mesh, uint32_t p_format, VS: } } - for (int i = 0; i < VS::ARRAY_MAX - 1; i++) { + for (int i = 0; i < RS::ARRAY_MAX - 1; i++) { attribs[i].stride = stride; } @@ -2500,9 +2500,9 @@ void RasterizerStorageGLES2::mesh_add_surface(RID p_mesh, uint32_t p_format, VS: return; //do not go any further, above function used unpacked stuff will be used instead. } - if (p_format & VS::ARRAY_FORMAT_INDEX) { + if (p_format & RS::ARRAY_FORMAT_INDEX) { - index_array_size = attribs[VS::ARRAY_INDEX].stride * p_index_count; + index_array_size = attribs[RS::ARRAY_INDEX].stride * p_index_count; } ERR_FAIL_COND(p_index_array.size() != index_array_size); @@ -2545,7 +2545,7 @@ void RasterizerStorageGLES2::mesh_add_surface(RID p_mesh, uint32_t p_format, VS: surface->skeleton_bone_used.write[i] = !(surface->skeleton_bone_aabb[i].size.x < 0 || surface->skeleton_bone_aabb[i].size.y < 0 || surface->skeleton_bone_aabb[i].size.z < 0); } - for (int i = 0; i < VS::ARRAY_MAX; i++) { + for (int i = 0; i < RS::ARRAY_MAX; i++) { surface->attribs[i] = attribs[i]; } @@ -2555,11 +2555,11 @@ void RasterizerStorageGLES2::mesh_add_surface(RID p_mesh, uint32_t p_format, VS: glGenBuffers(1, &surface->vertex_id); glBindBuffer(GL_ARRAY_BUFFER, surface->vertex_id); - glBufferData(GL_ARRAY_BUFFER, array_size, vr.ptr(), (p_format & VS::ARRAY_FLAG_USE_DYNAMIC_UPDATE) ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW); + glBufferData(GL_ARRAY_BUFFER, array_size, vr.ptr(), (p_format & RS::ARRAY_FLAG_USE_DYNAMIC_UPDATE) ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, 0); - if (p_format & VS::ARRAY_FORMAT_INDEX) { + if (p_format & RS::ARRAY_FORMAT_INDEX) { const uint8_t *ir = p_index_array.ptr(); glGenBuffers(1, &surface->index_id); @@ -2616,16 +2616,16 @@ int RasterizerStorageGLES2::mesh_get_blend_shape_count(RID p_mesh) const { return mesh->blend_shape_count; } -void RasterizerStorageGLES2::mesh_set_blend_shape_mode(RID p_mesh, VS::BlendShapeMode p_mode) { +void RasterizerStorageGLES2::mesh_set_blend_shape_mode(RID p_mesh, RS::BlendShapeMode p_mode) { Mesh *mesh = mesh_owner.getornull(p_mesh); ERR_FAIL_COND(!mesh); mesh->blend_shape_mode = p_mode; } -VS::BlendShapeMode RasterizerStorageGLES2::mesh_get_blend_shape_mode(RID p_mesh) const { +RS::BlendShapeMode RasterizerStorageGLES2::mesh_get_blend_shape_mode(RID p_mesh) const { const Mesh *mesh = mesh_owner.getornull(p_mesh); - ERR_FAIL_COND_V(!mesh, VS::BLEND_SHAPE_MODE_NORMALIZED); + ERR_FAIL_COND_V(!mesh, RS::BLEND_SHAPE_MODE_NORMALIZED); return mesh->blend_shape_mode; } @@ -2723,10 +2723,10 @@ uint32_t RasterizerStorageGLES2::mesh_surface_get_format(RID p_mesh, int p_surfa return mesh->surfaces[p_surface]->format; } -VS::PrimitiveType RasterizerStorageGLES2::mesh_surface_get_primitive_type(RID p_mesh, int p_surface) const { +RS::PrimitiveType RasterizerStorageGLES2::mesh_surface_get_primitive_type(RID p_mesh, int p_surface) const { const Mesh *mesh = mesh_owner.getornull(p_mesh); - ERR_FAIL_COND_V(!mesh, VS::PRIMITIVE_MAX); - ERR_FAIL_INDEX_V(p_surface, mesh->surfaces.size(), VS::PRIMITIVE_MAX); + ERR_FAIL_COND_V(!mesh, RS::PRIMITIVE_MAX); + ERR_FAIL_INDEX_V(p_surface, mesh->surfaces.size(), RS::PRIMITIVE_MAX); return mesh->surfaces[p_surface]->primitive; } @@ -2815,7 +2815,7 @@ AABB RasterizerStorageGLES2::mesh_get_aabb(RID p_mesh, RID p_skeleton) const { if (mesh->custom_aabb != AABB()) return mesh->custom_aabb; - Skeleton *sk = NULL; + Skeleton *sk = nullptr; if (p_skeleton.is_valid()) { sk = skeleton_owner.getornull(p_skeleton); } @@ -2827,7 +2827,7 @@ AABB RasterizerStorageGLES2::mesh_get_aabb(RID p_mesh, RID p_skeleton) const { for (int i = 0; i < mesh->surfaces.size(); i++) { AABB laabb; - if ((mesh->surfaces[i]->format & VS::ARRAY_FORMAT_BONES) && mesh->surfaces[i]->skeleton_bone_aabb.size()) { + if ((mesh->surfaces[i]->format & RS::ARRAY_FORMAT_BONES) && mesh->surfaces[i]->skeleton_bone_aabb.size()) { int bs = mesh->surfaces[i]->skeleton_bone_aabb.size(); const AABB *skbones = mesh->surfaces[i]->skeleton_bone_aabb.ptr(); @@ -2939,7 +2939,7 @@ RID RasterizerStorageGLES2::multimesh_create() { return multimesh_owner.make_rid(multimesh); } -void RasterizerStorageGLES2::multimesh_allocate(RID p_multimesh, int p_instances, VS::MultimeshTransformFormat p_transform_format, VS::MultimeshColorFormat p_color_format, VS::MultimeshCustomDataFormat p_data) { +void RasterizerStorageGLES2::multimesh_allocate(RID p_multimesh, int p_instances, RS::MultimeshTransformFormat p_transform_format, RS::MultimeshColorFormat p_color_format, RS::MultimeshCustomDataFormat p_data) { MultiMesh *multimesh = multimesh_owner.getornull(p_multimesh); ERR_FAIL_COND(!multimesh); @@ -2957,23 +2957,23 @@ void RasterizerStorageGLES2::multimesh_allocate(RID p_multimesh, int p_instances multimesh->data.resize(0); } - if (multimesh->transform_format == VS::MULTIMESH_TRANSFORM_2D) { + if (multimesh->transform_format == RS::MULTIMESH_TRANSFORM_2D) { multimesh->xform_floats = 8; } else { multimesh->xform_floats = 12; } - if (multimesh->color_format == VS::MULTIMESH_COLOR_8BIT) { + if (multimesh->color_format == RS::MULTIMESH_COLOR_8BIT) { multimesh->color_floats = 1; - } else if (multimesh->color_format == VS::MULTIMESH_COLOR_FLOAT) { + } else if (multimesh->color_format == RS::MULTIMESH_COLOR_FLOAT) { multimesh->color_floats = 4; } else { multimesh->color_floats = 0; } - if (multimesh->custom_data_format == VS::MULTIMESH_CUSTOM_DATA_8BIT) { + if (multimesh->custom_data_format == RS::MULTIMESH_CUSTOM_DATA_8BIT) { multimesh->custom_data_floats = 1; - } else if (multimesh->custom_data_format == VS::MULTIMESH_CUSTOM_DATA_FLOAT) { + } else if (multimesh->custom_data_format == RS::MULTIMESH_CUSTOM_DATA_FLOAT) { multimesh->custom_data_floats = 4; } else { multimesh->custom_data_floats = 0; @@ -2987,7 +2987,7 @@ void RasterizerStorageGLES2::multimesh_allocate(RID p_multimesh, int p_instances int color_from = 0; int custom_data_from = 0; - if (multimesh->transform_format == VS::MULTIMESH_TRANSFORM_2D) { + if (multimesh->transform_format == RS::MULTIMESH_TRANSFORM_2D) { multimesh->data.write[i + 0] = 1.0; multimesh->data.write[i + 1] = 0.0; multimesh->data.write[i + 2] = 0.0; @@ -3015,7 +3015,7 @@ void RasterizerStorageGLES2::multimesh_allocate(RID p_multimesh, int p_instances custom_data_from = 12; } - if (multimesh->color_format == VS::MULTIMESH_COLOR_8BIT) { + if (multimesh->color_format == RS::MULTIMESH_COLOR_8BIT) { union { uint32_t colu; float colf; @@ -3024,7 +3024,7 @@ void RasterizerStorageGLES2::multimesh_allocate(RID p_multimesh, int p_instances cu.colu = 0xFFFFFFFF; multimesh->data.write[i + color_from + 0] = cu.colf; custom_data_from = color_from + 1; - } else if (multimesh->color_format == VS::MULTIMESH_COLOR_FLOAT) { + } else if (multimesh->color_format == RS::MULTIMESH_COLOR_FLOAT) { multimesh->data.write[i + color_from + 0] = 1.0; multimesh->data.write[i + color_from + 1] = 1.0; multimesh->data.write[i + color_from + 2] = 1.0; @@ -3032,7 +3032,7 @@ void RasterizerStorageGLES2::multimesh_allocate(RID p_multimesh, int p_instances custom_data_from = color_from + 4; } - if (multimesh->custom_data_format == VS::MULTIMESH_CUSTOM_DATA_8BIT) { + if (multimesh->custom_data_format == RS::MULTIMESH_CUSTOM_DATA_8BIT) { union { uint32_t colu; float colf; @@ -3040,7 +3040,7 @@ void RasterizerStorageGLES2::multimesh_allocate(RID p_multimesh, int p_instances cu.colu = 0; multimesh->data.write[i + custom_data_from + 0] = cu.colf; - } else if (multimesh->custom_data_format == VS::MULTIMESH_CUSTOM_DATA_FLOAT) { + } else if (multimesh->custom_data_format == RS::MULTIMESH_CUSTOM_DATA_FLOAT) { multimesh->data.write[i + custom_data_from + 0] = 0.0; multimesh->data.write[i + custom_data_from + 1] = 0.0; multimesh->data.write[i + custom_data_from + 2] = 0.0; @@ -3094,7 +3094,7 @@ void RasterizerStorageGLES2::multimesh_instance_set_transform(RID p_multimesh, i MultiMesh *multimesh = multimesh_owner.getornull(p_multimesh); ERR_FAIL_COND(!multimesh); ERR_FAIL_INDEX(p_index, multimesh->size); - ERR_FAIL_COND(multimesh->transform_format == VS::MULTIMESH_TRANSFORM_2D); + ERR_FAIL_COND(multimesh->transform_format == RS::MULTIMESH_TRANSFORM_2D); int stride = multimesh->color_floats + multimesh->custom_data_floats + multimesh->xform_floats; @@ -3125,7 +3125,7 @@ void RasterizerStorageGLES2::multimesh_instance_set_transform_2d(RID p_multimesh MultiMesh *multimesh = multimesh_owner.getornull(p_multimesh); ERR_FAIL_COND(!multimesh); ERR_FAIL_INDEX(p_index, multimesh->size); - ERR_FAIL_COND(multimesh->transform_format == VS::MULTIMESH_TRANSFORM_3D); + ERR_FAIL_COND(multimesh->transform_format == RS::MULTIMESH_TRANSFORM_3D); int stride = multimesh->color_floats + multimesh->xform_floats + multimesh->custom_data_floats; float *dataptr = &multimesh->data.write[stride * p_index]; @@ -3151,13 +3151,13 @@ void RasterizerStorageGLES2::multimesh_instance_set_color(RID p_multimesh, int p MultiMesh *multimesh = multimesh_owner.getornull(p_multimesh); ERR_FAIL_COND(!multimesh); ERR_FAIL_INDEX(p_index, multimesh->size); - ERR_FAIL_COND(multimesh->color_format == VS::MULTIMESH_COLOR_NONE); - ERR_FAIL_INDEX(multimesh->color_format, VS::MULTIMESH_COLOR_MAX); + ERR_FAIL_COND(multimesh->color_format == RS::MULTIMESH_COLOR_NONE); + ERR_FAIL_INDEX(multimesh->color_format, RS::MULTIMESH_COLOR_MAX); int stride = multimesh->color_floats + multimesh->xform_floats + multimesh->custom_data_floats; float *dataptr = &multimesh->data.write[stride * p_index + multimesh->xform_floats]; - if (multimesh->color_format == VS::MULTIMESH_COLOR_8BIT) { + if (multimesh->color_format == RS::MULTIMESH_COLOR_8BIT) { uint8_t *data8 = (uint8_t *)dataptr; data8[0] = CLAMP(p_color.r * 255.0, 0, 255); @@ -3165,7 +3165,7 @@ void RasterizerStorageGLES2::multimesh_instance_set_color(RID p_multimesh, int p data8[2] = CLAMP(p_color.b * 255.0, 0, 255); data8[3] = CLAMP(p_color.a * 255.0, 0, 255); - } else if (multimesh->color_format == VS::MULTIMESH_COLOR_FLOAT) { + } else if (multimesh->color_format == RS::MULTIMESH_COLOR_FLOAT) { dataptr[0] = p_color.r; dataptr[1] = p_color.g; dataptr[2] = p_color.b; @@ -3184,13 +3184,13 @@ void RasterizerStorageGLES2::multimesh_instance_set_custom_data(RID p_multimesh, MultiMesh *multimesh = multimesh_owner.getornull(p_multimesh); ERR_FAIL_COND(!multimesh); ERR_FAIL_INDEX(p_index, multimesh->size); - ERR_FAIL_COND(multimesh->custom_data_format == VS::MULTIMESH_CUSTOM_DATA_NONE); - ERR_FAIL_INDEX(multimesh->custom_data_format, VS::MULTIMESH_CUSTOM_DATA_MAX); + ERR_FAIL_COND(multimesh->custom_data_format == RS::MULTIMESH_CUSTOM_DATA_NONE); + ERR_FAIL_INDEX(multimesh->custom_data_format, RS::MULTIMESH_CUSTOM_DATA_MAX); int stride = multimesh->color_floats + multimesh->xform_floats + multimesh->custom_data_floats; float *dataptr = &multimesh->data.write[stride * p_index + multimesh->xform_floats + multimesh->color_floats]; - if (multimesh->custom_data_format == VS::MULTIMESH_CUSTOM_DATA_8BIT) { + if (multimesh->custom_data_format == RS::MULTIMESH_CUSTOM_DATA_8BIT) { uint8_t *data8 = (uint8_t *)dataptr; data8[0] = CLAMP(p_custom_data.r * 255.0, 0, 255); @@ -3198,7 +3198,7 @@ void RasterizerStorageGLES2::multimesh_instance_set_custom_data(RID p_multimesh, data8[2] = CLAMP(p_custom_data.b * 255.0, 0, 255); data8[3] = CLAMP(p_custom_data.a * 255.0, 0, 255); - } else if (multimesh->custom_data_format == VS::MULTIMESH_CUSTOM_DATA_FLOAT) { + } else if (multimesh->custom_data_format == RS::MULTIMESH_CUSTOM_DATA_FLOAT) { dataptr[0] = p_custom_data.r; dataptr[1] = p_custom_data.g; dataptr[2] = p_custom_data.b; @@ -3224,7 +3224,7 @@ Transform RasterizerStorageGLES2::multimesh_instance_get_transform(RID p_multime MultiMesh *multimesh = multimesh_owner.getornull(p_multimesh); ERR_FAIL_COND_V(!multimesh, Transform()); ERR_FAIL_INDEX_V(p_index, multimesh->size, Transform()); - ERR_FAIL_COND_V(multimesh->transform_format == VS::MULTIMESH_TRANSFORM_2D, Transform()); + ERR_FAIL_COND_V(multimesh->transform_format == RS::MULTIMESH_TRANSFORM_2D, Transform()); int stride = multimesh->color_floats + multimesh->xform_floats + multimesh->custom_data_floats; float *dataptr = &multimesh->data.write[stride * p_index]; @@ -3251,7 +3251,7 @@ Transform2D RasterizerStorageGLES2::multimesh_instance_get_transform_2d(RID p_mu MultiMesh *multimesh = multimesh_owner.getornull(p_multimesh); ERR_FAIL_COND_V(!multimesh, Transform2D()); ERR_FAIL_INDEX_V(p_index, multimesh->size, Transform2D()); - ERR_FAIL_COND_V(multimesh->transform_format == VS::MULTIMESH_TRANSFORM_3D, Transform2D()); + ERR_FAIL_COND_V(multimesh->transform_format == RS::MULTIMESH_TRANSFORM_3D, Transform2D()); int stride = multimesh->color_floats + multimesh->xform_floats + multimesh->custom_data_floats; float *dataptr = &multimesh->data.write[stride * p_index]; @@ -3272,13 +3272,13 @@ Color RasterizerStorageGLES2::multimesh_instance_get_color(RID p_multimesh, int MultiMesh *multimesh = multimesh_owner.getornull(p_multimesh); ERR_FAIL_COND_V(!multimesh, Color()); ERR_FAIL_INDEX_V(p_index, multimesh->size, Color()); - ERR_FAIL_COND_V(multimesh->color_format == VS::MULTIMESH_COLOR_NONE, Color()); - ERR_FAIL_INDEX_V(multimesh->color_format, VS::MULTIMESH_COLOR_MAX, Color()); + ERR_FAIL_COND_V(multimesh->color_format == RS::MULTIMESH_COLOR_NONE, Color()); + ERR_FAIL_INDEX_V(multimesh->color_format, RS::MULTIMESH_COLOR_MAX, Color()); int stride = multimesh->color_floats + multimesh->xform_floats + multimesh->custom_data_floats; float *dataptr = &multimesh->data.write[stride * p_index + multimesh->xform_floats]; - if (multimesh->color_format == VS::MULTIMESH_COLOR_8BIT) { + if (multimesh->color_format == RS::MULTIMESH_COLOR_8BIT) { union { uint32_t colu; float colf; @@ -3288,7 +3288,7 @@ Color RasterizerStorageGLES2::multimesh_instance_get_color(RID p_multimesh, int return Color::hex(BSWAP32(cu.colu)); - } else if (multimesh->color_format == VS::MULTIMESH_COLOR_FLOAT) { + } else if (multimesh->color_format == RS::MULTIMESH_COLOR_FLOAT) { Color c; c.r = dataptr[0]; c.g = dataptr[1]; @@ -3305,13 +3305,13 @@ Color RasterizerStorageGLES2::multimesh_instance_get_custom_data(RID p_multimesh MultiMesh *multimesh = multimesh_owner.getornull(p_multimesh); ERR_FAIL_COND_V(!multimesh, Color()); ERR_FAIL_INDEX_V(p_index, multimesh->size, Color()); - ERR_FAIL_COND_V(multimesh->custom_data_format == VS::MULTIMESH_CUSTOM_DATA_NONE, Color()); - ERR_FAIL_INDEX_V(multimesh->custom_data_format, VS::MULTIMESH_CUSTOM_DATA_MAX, Color()); + ERR_FAIL_COND_V(multimesh->custom_data_format == RS::MULTIMESH_CUSTOM_DATA_NONE, Color()); + ERR_FAIL_INDEX_V(multimesh->custom_data_format, RS::MULTIMESH_CUSTOM_DATA_MAX, Color()); int stride = multimesh->color_floats + multimesh->xform_floats + multimesh->custom_data_floats; float *dataptr = &multimesh->data.write[stride * p_index + multimesh->xform_floats + multimesh->color_floats]; - if (multimesh->custom_data_format == VS::MULTIMESH_CUSTOM_DATA_8BIT) { + if (multimesh->custom_data_format == RS::MULTIMESH_CUSTOM_DATA_8BIT) { union { uint32_t colu; float colf; @@ -3321,7 +3321,7 @@ Color RasterizerStorageGLES2::multimesh_instance_get_custom_data(RID p_multimesh return Color::hex(BSWAP32(cu.colu)); - } else if (multimesh->custom_data_format == VS::MULTIMESH_CUSTOM_DATA_FLOAT) { + } else if (multimesh->custom_data_format == RS::MULTIMESH_CUSTOM_DATA_FLOAT) { Color c; c.r = dataptr[0]; c.g = dataptr[1]; @@ -3400,7 +3400,7 @@ void RasterizerStorageGLES2::update_dirty_multimeshes() { AABB aabb; - if (multimesh->transform_format == VS::MULTIMESH_TRANSFORM_2D) { + if (multimesh->transform_format == RS::MULTIMESH_TRANSFORM_2D) { for (int i = 0; i < count; i += stride) { @@ -3472,7 +3472,7 @@ RID RasterizerStorageGLES2::immediate_create() { return immediate_owner.make_rid(im); } -void RasterizerStorageGLES2::immediate_begin(RID p_immediate, VS::PrimitiveType p_primitive, RID p_texture) { +void RasterizerStorageGLES2::immediate_begin(RID p_immediate, RS::PrimitiveType p_primitive, RID p_texture) { Immediate *im = immediate_owner.getornull(p_immediate); ERR_FAIL_COND(!im); ERR_FAIL_COND(im->building); @@ -3499,17 +3499,17 @@ void RasterizerStorageGLES2::immediate_vertex(RID p_immediate, const Vector3 &p_ im->aabb.expand_to(p_vertex); } - if (im->mask & VS::ARRAY_FORMAT_NORMAL) + if (im->mask & RS::ARRAY_FORMAT_NORMAL) c->normals.push_back(chunk_normal); - if (im->mask & VS::ARRAY_FORMAT_TANGENT) + if (im->mask & RS::ARRAY_FORMAT_TANGENT) c->tangents.push_back(chunk_tangent); - if (im->mask & VS::ARRAY_FORMAT_COLOR) + if (im->mask & RS::ARRAY_FORMAT_COLOR) c->colors.push_back(chunk_color); - if (im->mask & VS::ARRAY_FORMAT_TEX_UV) + if (im->mask & RS::ARRAY_FORMAT_TEX_UV) c->uvs.push_back(chunk_uv); - if (im->mask & VS::ARRAY_FORMAT_TEX_UV2) + if (im->mask & RS::ARRAY_FORMAT_TEX_UV2) c->uv2s.push_back(chunk_uv2); - im->mask |= VS::ARRAY_FORMAT_VERTEX; + im->mask |= RS::ARRAY_FORMAT_VERTEX; c->vertices.push_back(p_vertex); } @@ -3518,7 +3518,7 @@ void RasterizerStorageGLES2::immediate_normal(RID p_immediate, const Vector3 &p_ ERR_FAIL_COND(!im); ERR_FAIL_COND(!im->building); - im->mask |= VS::ARRAY_FORMAT_NORMAL; + im->mask |= RS::ARRAY_FORMAT_NORMAL; chunk_normal = p_normal; } @@ -3527,7 +3527,7 @@ void RasterizerStorageGLES2::immediate_tangent(RID p_immediate, const Plane &p_t ERR_FAIL_COND(!im); ERR_FAIL_COND(!im->building); - im->mask |= VS::ARRAY_FORMAT_TANGENT; + im->mask |= RS::ARRAY_FORMAT_TANGENT; chunk_tangent = p_tangent; } @@ -3536,7 +3536,7 @@ void RasterizerStorageGLES2::immediate_color(RID p_immediate, const Color &p_col ERR_FAIL_COND(!im); ERR_FAIL_COND(!im->building); - im->mask |= VS::ARRAY_FORMAT_COLOR; + im->mask |= RS::ARRAY_FORMAT_COLOR; chunk_color = p_color; } @@ -3545,7 +3545,7 @@ void RasterizerStorageGLES2::immediate_uv(RID p_immediate, const Vector2 &tex_uv ERR_FAIL_COND(!im); ERR_FAIL_COND(!im->building); - im->mask |= VS::ARRAY_FORMAT_TEX_UV; + im->mask |= RS::ARRAY_FORMAT_TEX_UV; chunk_uv = tex_uv; } @@ -3554,7 +3554,7 @@ void RasterizerStorageGLES2::immediate_uv2(RID p_immediate, const Vector2 &tex_u ERR_FAIL_COND(!im); ERR_FAIL_COND(!im->building); - im->mask |= VS::ARRAY_FORMAT_TEX_UV2; + im->mask |= RS::ARRAY_FORMAT_TEX_UV2; chunk_uv2 = tex_uv; } @@ -3626,9 +3626,9 @@ void RasterizerStorageGLES2::skeleton_allocate(RID p_skeleton, int p_bones, bool glBindTexture(GL_TEXTURE_2D, skeleton->tex_id); #ifdef GLES_OVER_GL - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, p_bones * (skeleton->use_2d ? 2 : 3), 1, 0, GL_RGBA, GL_FLOAT, NULL); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, p_bones * (skeleton->use_2d ? 2 : 3), 1, 0, GL_RGBA, GL_FLOAT, nullptr); #else - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, p_bones * (skeleton->use_2d ? 2 : 3), 1, 0, GL_RGBA, GL_FLOAT, NULL); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, p_bones * (skeleton->use_2d ? 2 : 3), 1, 0, GL_RGBA, GL_FLOAT, nullptr); #endif glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); @@ -3812,34 +3812,34 @@ void RasterizerStorageGLES2::update_dirty_skeletons() { /* Light API */ -RID RasterizerStorageGLES2::light_create(VS::LightType p_type) { +RID RasterizerStorageGLES2::light_create(RS::LightType p_type) { Light *light = memnew(Light); light->type = p_type; - light->param[VS::LIGHT_PARAM_ENERGY] = 1.0; - light->param[VS::LIGHT_PARAM_INDIRECT_ENERGY] = 1.0; - light->param[VS::LIGHT_PARAM_SPECULAR] = 0.5; - light->param[VS::LIGHT_PARAM_RANGE] = 1.0; - light->param[VS::LIGHT_PARAM_SPOT_ANGLE] = 45; - light->param[VS::LIGHT_PARAM_CONTACT_SHADOW_SIZE] = 45; - light->param[VS::LIGHT_PARAM_SHADOW_MAX_DISTANCE] = 0; - light->param[VS::LIGHT_PARAM_SHADOW_SPLIT_1_OFFSET] = 0.1; - light->param[VS::LIGHT_PARAM_SHADOW_SPLIT_2_OFFSET] = 0.3; - light->param[VS::LIGHT_PARAM_SHADOW_SPLIT_3_OFFSET] = 0.6; - light->param[VS::LIGHT_PARAM_SHADOW_NORMAL_BIAS] = 0.1; - light->param[VS::LIGHT_PARAM_SHADOW_BIAS_SPLIT_SCALE] = 0.1; + light->param[RS::LIGHT_PARAM_ENERGY] = 1.0; + light->param[RS::LIGHT_PARAM_INDIRECT_ENERGY] = 1.0; + light->param[RS::LIGHT_PARAM_SPECULAR] = 0.5; + light->param[RS::LIGHT_PARAM_RANGE] = 1.0; + light->param[RS::LIGHT_PARAM_SPOT_ANGLE] = 45; + light->param[RS::LIGHT_PARAM_CONTACT_SHADOW_SIZE] = 45; + light->param[RS::LIGHT_PARAM_SHADOW_MAX_DISTANCE] = 0; + light->param[RS::LIGHT_PARAM_SHADOW_SPLIT_1_OFFSET] = 0.1; + light->param[RS::LIGHT_PARAM_SHADOW_SPLIT_2_OFFSET] = 0.3; + light->param[RS::LIGHT_PARAM_SHADOW_SPLIT_3_OFFSET] = 0.6; + light->param[RS::LIGHT_PARAM_SHADOW_NORMAL_BIAS] = 0.1; + light->param[RS::LIGHT_PARAM_SHADOW_BIAS_SPLIT_SCALE] = 0.1; light->color = Color(1, 1, 1, 1); light->shadow = false; light->negative = false; light->cull_mask = 0xFFFFFFFF; - light->directional_shadow_mode = VS::LIGHT_DIRECTIONAL_SHADOW_ORTHOGONAL; - light->omni_shadow_mode = VS::LIGHT_OMNI_SHADOW_DUAL_PARABOLOID; - light->omni_shadow_detail = VS::LIGHT_OMNI_SHADOW_DETAIL_VERTICAL; + light->directional_shadow_mode = RS::LIGHT_DIRECTIONAL_SHADOW_ORTHOGONAL; + light->omni_shadow_mode = RS::LIGHT_OMNI_SHADOW_DUAL_PARABOLOID; + light->omni_shadow_detail = RS::LIGHT_OMNI_SHADOW_DETAIL_VERTICAL; light->directional_blend_splits = false; - light->directional_range_mode = VS::LIGHT_DIRECTIONAL_SHADOW_DEPTH_RANGE_STABLE; + light->directional_range_mode = RS::LIGHT_DIRECTIONAL_SHADOW_DEPTH_RANGE_STABLE; light->reverse_cull = false; light->use_gi = true; light->version = 0; @@ -3854,20 +3854,20 @@ void RasterizerStorageGLES2::light_set_color(RID p_light, const Color &p_color) light->color = p_color; } -void RasterizerStorageGLES2::light_set_param(RID p_light, VS::LightParam p_param, float p_value) { +void RasterizerStorageGLES2::light_set_param(RID p_light, RS::LightParam p_param, float p_value) { Light *light = light_owner.getornull(p_light); ERR_FAIL_COND(!light); - ERR_FAIL_INDEX(p_param, VS::LIGHT_PARAM_MAX); + ERR_FAIL_INDEX(p_param, RS::LIGHT_PARAM_MAX); switch (p_param) { - case VS::LIGHT_PARAM_RANGE: - case VS::LIGHT_PARAM_SPOT_ANGLE: - case VS::LIGHT_PARAM_SHADOW_MAX_DISTANCE: - case VS::LIGHT_PARAM_SHADOW_SPLIT_1_OFFSET: - case VS::LIGHT_PARAM_SHADOW_SPLIT_2_OFFSET: - case VS::LIGHT_PARAM_SHADOW_SPLIT_3_OFFSET: - case VS::LIGHT_PARAM_SHADOW_NORMAL_BIAS: - case VS::LIGHT_PARAM_SHADOW_BIAS: { + case RS::LIGHT_PARAM_RANGE: + case RS::LIGHT_PARAM_SPOT_ANGLE: + case RS::LIGHT_PARAM_SHADOW_MAX_DISTANCE: + case RS::LIGHT_PARAM_SHADOW_SPLIT_1_OFFSET: + case RS::LIGHT_PARAM_SHADOW_SPLIT_2_OFFSET: + case RS::LIGHT_PARAM_SHADOW_SPLIT_3_OFFSET: + case RS::LIGHT_PARAM_SHADOW_NORMAL_BIAS: + case RS::LIGHT_PARAM_SHADOW_BIAS: { light->version++; light->instance_change_notify(true, false); } break; @@ -3939,7 +3939,7 @@ void RasterizerStorageGLES2::light_set_use_gi(RID p_light, bool p_enabled) { light->instance_change_notify(true, false); } -void RasterizerStorageGLES2::light_omni_set_shadow_mode(RID p_light, VS::LightOmniShadowMode p_mode) { +void RasterizerStorageGLES2::light_omni_set_shadow_mode(RID p_light, RS::LightOmniShadowMode p_mode) { Light *light = light_owner.getornull(p_light); ERR_FAIL_COND(!light); @@ -3949,14 +3949,14 @@ void RasterizerStorageGLES2::light_omni_set_shadow_mode(RID p_light, VS::LightOm light->instance_change_notify(true, false); } -VS::LightOmniShadowMode RasterizerStorageGLES2::light_omni_get_shadow_mode(RID p_light) { +RS::LightOmniShadowMode RasterizerStorageGLES2::light_omni_get_shadow_mode(RID p_light) { Light *light = light_owner.getornull(p_light); - ERR_FAIL_COND_V(!light, VS::LIGHT_OMNI_SHADOW_CUBE); + ERR_FAIL_COND_V(!light, RS::LIGHT_OMNI_SHADOW_CUBE); return light->omni_shadow_mode; } -void RasterizerStorageGLES2::light_omni_set_shadow_detail(RID p_light, VS::LightOmniShadowDetail p_detail) { +void RasterizerStorageGLES2::light_omni_set_shadow_detail(RID p_light, RS::LightOmniShadowDetail p_detail) { Light *light = light_owner.getornull(p_light); ERR_FAIL_COND(!light); @@ -3966,7 +3966,7 @@ void RasterizerStorageGLES2::light_omni_set_shadow_detail(RID p_light, VS::Light light->instance_change_notify(true, false); } -void RasterizerStorageGLES2::light_directional_set_shadow_mode(RID p_light, VS::LightDirectionalShadowMode p_mode) { +void RasterizerStorageGLES2::light_directional_set_shadow_mode(RID p_light, RS::LightDirectionalShadowMode p_mode) { Light *light = light_owner.getornull(p_light); ERR_FAIL_COND(!light); @@ -3992,37 +3992,37 @@ bool RasterizerStorageGLES2::light_directional_get_blend_splits(RID p_light) con return light->directional_blend_splits; } -VS::LightDirectionalShadowMode RasterizerStorageGLES2::light_directional_get_shadow_mode(RID p_light) { +RS::LightDirectionalShadowMode RasterizerStorageGLES2::light_directional_get_shadow_mode(RID p_light) { Light *light = light_owner.getornull(p_light); - ERR_FAIL_COND_V(!light, VS::LIGHT_DIRECTIONAL_SHADOW_ORTHOGONAL); + ERR_FAIL_COND_V(!light, RS::LIGHT_DIRECTIONAL_SHADOW_ORTHOGONAL); return light->directional_shadow_mode; } -void RasterizerStorageGLES2::light_directional_set_shadow_depth_range_mode(RID p_light, VS::LightDirectionalShadowDepthRangeMode p_range_mode) { +void RasterizerStorageGLES2::light_directional_set_shadow_depth_range_mode(RID p_light, RS::LightDirectionalShadowDepthRangeMode p_range_mode) { Light *light = light_owner.getornull(p_light); ERR_FAIL_COND(!light); light->directional_range_mode = p_range_mode; } -VS::LightDirectionalShadowDepthRangeMode RasterizerStorageGLES2::light_directional_get_shadow_depth_range_mode(RID p_light) const { +RS::LightDirectionalShadowDepthRangeMode RasterizerStorageGLES2::light_directional_get_shadow_depth_range_mode(RID p_light) const { Light *light = light_owner.getornull(p_light); - ERR_FAIL_COND_V(!light, VS::LIGHT_DIRECTIONAL_SHADOW_DEPTH_RANGE_STABLE); + ERR_FAIL_COND_V(!light, RS::LIGHT_DIRECTIONAL_SHADOW_DEPTH_RANGE_STABLE); return light->directional_range_mode; } -VS::LightType RasterizerStorageGLES2::light_get_type(RID p_light) const { +RS::LightType RasterizerStorageGLES2::light_get_type(RID p_light) const { Light *light = light_owner.getornull(p_light); - ERR_FAIL_COND_V(!light, VS::LIGHT_DIRECTIONAL); + ERR_FAIL_COND_V(!light, RS::LIGHT_DIRECTIONAL); return light->type; } -float RasterizerStorageGLES2::light_get_param(RID p_light, VS::LightParam p_param) { +float RasterizerStorageGLES2::light_get_param(RID p_light, RS::LightParam p_param) { Light *light = light_owner.getornull(p_light); ERR_FAIL_COND_V(!light, 0.0); - ERR_FAIL_INDEX_V(p_param, VS::LIGHT_PARAM_MAX, 0.0); + ERR_FAIL_INDEX_V(p_param, RS::LIGHT_PARAM_MAX, 0.0); return light->param[p_param]; } @@ -4061,18 +4061,18 @@ AABB RasterizerStorageGLES2::light_get_aabb(RID p_light) const { switch (light->type) { - case VS::LIGHT_SPOT: { - float len = light->param[VS::LIGHT_PARAM_RANGE]; - float size = Math::tan(Math::deg2rad(light->param[VS::LIGHT_PARAM_SPOT_ANGLE])) * len; + case RS::LIGHT_SPOT: { + float len = light->param[RS::LIGHT_PARAM_RANGE]; + float size = Math::tan(Math::deg2rad(light->param[RS::LIGHT_PARAM_SPOT_ANGLE])) * len; return AABB(Vector3(-size, -size, -len), Vector3(size * 2, size * 2, len)); }; - case VS::LIGHT_OMNI: { - float r = light->param[VS::LIGHT_PARAM_RANGE]; + case RS::LIGHT_OMNI: { + float r = light->param[RS::LIGHT_PARAM_RANGE]; return AABB(-Vector3(r, r, r), Vector3(r, r, r) * 2); }; - case VS::LIGHT_DIRECTIONAL: { + case RS::LIGHT_DIRECTIONAL: { return AABB(); }; } @@ -4097,13 +4097,13 @@ RID RasterizerStorageGLES2::reflection_probe_create() { reflection_probe->box_projection = false; reflection_probe->enable_shadows = false; reflection_probe->cull_mask = (1 << 20) - 1; - reflection_probe->update_mode = VS::REFLECTION_PROBE_UPDATE_ONCE; + reflection_probe->update_mode = RS::REFLECTION_PROBE_UPDATE_ONCE; reflection_probe->resolution = 128; return reflection_probe_owner.make_rid(reflection_probe); } -void RasterizerStorageGLES2::reflection_probe_set_update_mode(RID p_probe, VS::ReflectionProbeUpdateMode p_mode) { +void RasterizerStorageGLES2::reflection_probe_set_update_mode(RID p_probe, RS::ReflectionProbeUpdateMode p_mode) { ReflectionProbe *reflection_probe = reflection_probe_owner.getornull(p_probe); ERR_FAIL_COND(!reflection_probe); @@ -4220,10 +4220,10 @@ AABB RasterizerStorageGLES2::reflection_probe_get_aabb(RID p_probe) const { return aabb; } -VS::ReflectionProbeUpdateMode RasterizerStorageGLES2::reflection_probe_get_update_mode(RID p_probe) const { +RS::ReflectionProbeUpdateMode RasterizerStorageGLES2::reflection_probe_get_update_mode(RID p_probe) const { const ReflectionProbe *reflection_probe = reflection_probe_owner.getornull(p_probe); - ERR_FAIL_COND_V(!reflection_probe, VS::REFLECTION_PROBE_UPDATE_ALWAYS); + ERR_FAIL_COND_V(!reflection_probe, RS::REFLECTION_PROBE_UPDATE_ALWAYS); return reflection_probe->update_mode; } @@ -4465,7 +4465,7 @@ float RasterizerStorageGLES2::lightmap_capture_get_energy(RID p_capture) const { const Vector<RasterizerStorage::LightmapCaptureOctree> *RasterizerStorageGLES2::lightmap_capture_get_octree_ptr(RID p_capture) const { const LightmapCapture *capture = lightmap_capture_data_owner.getornull(p_capture); - ERR_FAIL_COND_V(!capture, NULL); + ERR_FAIL_COND_V(!capture, nullptr); return &capture->octree; } @@ -4518,7 +4518,7 @@ void RasterizerStorageGLES2::particles_set_fractional_delta(RID p_particles, boo void RasterizerStorageGLES2::particles_set_process_material(RID p_particles, RID p_material) { } -void RasterizerStorageGLES2::particles_set_draw_order(RID p_particles, VS::ParticlesDrawOrder p_order) { +void RasterizerStorageGLES2::particles_set_draw_order(RID p_particles, RS::ParticlesDrawOrder p_order) { } void RasterizerStorageGLES2::particles_set_draw_passes(RID p_particles, int p_passes) { @@ -4579,37 +4579,37 @@ void RasterizerStorageGLES2::instance_remove_skeleton(RID p_skeleton, Rasterizer void RasterizerStorageGLES2::instance_add_dependency(RID p_base, RasterizerScene::InstanceBase *p_instance) { - Instantiable *inst = NULL; + Instantiable *inst = nullptr; switch (p_instance->base_type) { - case VS::INSTANCE_MESH: { + case RS::INSTANCE_MESH: { inst = mesh_owner.getornull(p_base); ERR_FAIL_COND(!inst); } break; - case VS::INSTANCE_MULTIMESH: { + case RS::INSTANCE_MULTIMESH: { inst = multimesh_owner.getornull(p_base); ERR_FAIL_COND(!inst); } break; - case VS::INSTANCE_IMMEDIATE: { + case RS::INSTANCE_IMMEDIATE: { inst = immediate_owner.getornull(p_base); ERR_FAIL_COND(!inst); } break; - /*case VS::INSTANCE_PARTICLES: { + /*case RS::INSTANCE_PARTICLES: { inst = particles_owner.getornull(p_base); ERR_FAIL_COND(!inst); } break;*/ - case VS::INSTANCE_REFLECTION_PROBE: { + case RS::INSTANCE_REFLECTION_PROBE: { inst = reflection_probe_owner.getornull(p_base); ERR_FAIL_COND(!inst); } break; - case VS::INSTANCE_LIGHT: { + case RS::INSTANCE_LIGHT: { inst = light_owner.getornull(p_base); ERR_FAIL_COND(!inst); } break; - /*case VS::INSTANCE_GI_PROBE: { + /*case RS::INSTANCE_GI_PROBE: { inst = gi_probe_owner.getornull(p_base); ERR_FAIL_COND(!inst); } break;*/ - case VS::INSTANCE_LIGHTMAP_CAPTURE: { + case RS::INSTANCE_LIGHTMAP_CAPTURE: { inst = lightmap_capture_data_owner.getornull(p_base); ERR_FAIL_COND(!inst); } break; @@ -4623,38 +4623,38 @@ void RasterizerStorageGLES2::instance_add_dependency(RID p_base, RasterizerScene void RasterizerStorageGLES2::instance_remove_dependency(RID p_base, RasterizerScene::InstanceBase *p_instance) { - Instantiable *inst = NULL; + Instantiable *inst = nullptr; switch (p_instance->base_type) { - case VS::INSTANCE_MESH: { + case RS::INSTANCE_MESH: { inst = mesh_owner.getornull(p_base); ERR_FAIL_COND(!inst); } break; - case VS::INSTANCE_MULTIMESH: { + case RS::INSTANCE_MULTIMESH: { inst = multimesh_owner.getornull(p_base); ERR_FAIL_COND(!inst); } break; - case VS::INSTANCE_IMMEDIATE: { + case RS::INSTANCE_IMMEDIATE: { inst = immediate_owner.getornull(p_base); ERR_FAIL_COND(!inst); } break; - /*case VS::INSTANCE_PARTICLES: { + /*case RS::INSTANCE_PARTICLES: { inst = particles_owner.getornull(p_base); ERR_FAIL_COND(!inst); } break;*/ - case VS::INSTANCE_REFLECTION_PROBE: { + case RS::INSTANCE_REFLECTION_PROBE: { inst = reflection_probe_owner.getornull(p_base); ERR_FAIL_COND(!inst); } break; - case VS::INSTANCE_LIGHT: { + case RS::INSTANCE_LIGHT: { inst = light_owner.getornull(p_base); ERR_FAIL_COND(!inst); } break; - /*case VS::INSTANCE_GI_PROBE: { + /*case RS::INSTANCE_GI_PROBE: { inst = gi_probe_owner.getornull(p_base); ERR_FAIL_COND(!inst); } break; */ - case VS::INSTANCE_LIGHTMAP_CAPTURE: { + case RS::INSTANCE_LIGHTMAP_CAPTURE: { inst = lightmap_capture_data_owner.getornull(p_base); ERR_FAIL_COND(!inst); } break; @@ -4721,9 +4721,9 @@ void RasterizerStorageGLES2::_render_target_allocate(RenderTarget *rt) { glGenTextures(1, &rt->color); glBindTexture(GL_TEXTURE_2D, rt->color); - glTexImage2D(GL_TEXTURE_2D, 0, color_internal_format, rt->width, rt->height, 0, color_format, color_type, NULL); + glTexImage2D(GL_TEXTURE_2D, 0, color_internal_format, rt->width, rt->height, 0, color_format, color_type, nullptr); - if (texture->flags & VS::TEXTURE_FLAG_FILTER) { + if (texture->flags & RS::TEXTURE_FLAG_FILTER) { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); @@ -4744,7 +4744,7 @@ void RasterizerStorageGLES2::_render_target_allocate(RenderTarget *rt) { glGenTextures(1, &rt->depth); glBindTexture(GL_TEXTURE_2D, rt->depth); - glTexImage2D(GL_TEXTURE_2D, 0, config.depth_internalformat, rt->width, rt->height, 0, GL_DEPTH_COMPONENT, config.depth_type, NULL); + glTexImage2D(GL_TEXTURE_2D, 0, config.depth_internalformat, rt->width, rt->height, 0, GL_DEPTH_COMPONENT, config.depth_type, nullptr); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); @@ -4805,7 +4805,7 @@ void RasterizerStorageGLES2::_render_target_allocate(RenderTarget *rt) { /* For MSAA */ #ifndef JAVASCRIPT_ENABLED - if (rt->msaa >= VS::VIEWPORT_MSAA_2X && rt->msaa <= VS::VIEWPORT_MSAA_16X && config.multisample_supported) { + if (rt->msaa >= RS::VIEWPORT_MSAA_2X && rt->msaa <= RS::VIEWPORT_MSAA_16X && config.multisample_supported) { rt->multisample_active = true; @@ -4841,7 +4841,7 @@ void RasterizerStorageGLES2::_render_target_allocate(RenderTarget *rt) { glGenTextures(1, &rt->multisample_color); glBindTexture(GL_TEXTURE_2D, rt->multisample_color); - glTexImage2D(GL_TEXTURE_2D, 0, color_internal_format, rt->width, rt->height, 0, color_format, color_type, NULL); + glTexImage2D(GL_TEXTURE_2D, 0, color_internal_format, rt->width, rt->height, 0, color_format, color_type, nullptr); // multisample buffer is same size as front buffer, so just use nearest glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); @@ -4894,9 +4894,9 @@ void RasterizerStorageGLES2::_render_target_allocate(RenderTarget *rt) { glBindTexture(GL_TEXTURE_2D, rt->copy_screen_effect.color); if (rt->flags[RasterizerStorage::RENDER_TARGET_TRANSPARENT]) { - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, rt->width, rt->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, rt->width, rt->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); } else { - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, rt->width, rt->height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, rt->width, rt->height, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr); } glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); @@ -4961,7 +4961,7 @@ void RasterizerStorageGLES2::_render_target_allocate(RenderTarget *rt) { glBindTexture(GL_TEXTURE_2D, rt->mip_maps[i].color); for (int l = 0; l < level + 1; l++) { - glTexImage2D(GL_TEXTURE_2D, l, color_internal_format, width, height, 0, color_format, color_type, NULL); + glTexImage2D(GL_TEXTURE_2D, l, color_internal_format, width, height, 0, color_format, color_type, nullptr); width = MAX(1, (width / 2)); height = MAX(1, (height / 2)); } @@ -4975,7 +4975,7 @@ void RasterizerStorageGLES2::_render_target_allocate(RenderTarget *rt) { for (int l = 0; l < level + 1; l++) { glGenTextures(1, &rt->mip_maps[i].sizes.write[l].color); glBindTexture(GL_TEXTURE_2D, rt->mip_maps[i].sizes[l].color); - glTexImage2D(GL_TEXTURE_2D, 0, color_internal_format, width, height, 0, color_format, color_type, NULL); + glTexImage2D(GL_TEXTURE_2D, 0, color_internal_format, width, height, 0, color_format, color_type, nullptr); width = MAX(1, (width / 2)); height = MAX(1, (height / 2)); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); @@ -5134,7 +5134,7 @@ RID RasterizerStorageGLES2::render_target_create() { Texture *t = memnew(Texture); - t->type = VS::TEXTURE_TYPE_2D; + t->type = RS::TEXTURE_TYPE_2D; t->flags = 0; t->width = 0; t->height = 0; @@ -5235,7 +5235,7 @@ void RasterizerStorageGLES2::render_target_set_external_texture(RID p_render_tar // allocate a texture t = memnew(Texture); - t->type = VS::TEXTURE_TYPE_2D; + t->type = RS::TEXTURE_TYPE_2D; t->flags = 0; t->width = 0; t->height = 0; @@ -5278,7 +5278,7 @@ void RasterizerStorageGLES2::render_target_set_external_texture(RID p_render_tar // Switch our texture on our frame buffer #if ANDROID_ENABLED - if (rt->msaa >= VS::VIEWPORT_MSAA_EXT_2X && rt->msaa <= VS::VIEWPORT_MSAA_EXT_4X) { + if (rt->msaa >= RS::VIEWPORT_MSAA_EXT_2X && rt->msaa <= RS::VIEWPORT_MSAA_EXT_4X) { // This code only applies to the Oculus Go and Oculus Quest. Due to the the tiled nature // of the GPU we can do a single render pass by rendering directly into our texture chains // texture and apply MSAA as we render. @@ -5287,7 +5287,7 @@ void RasterizerStorageGLES2::render_target_set_external_texture(RID p_render_tar // the normal MSAA modes need to be used to enable our two pass approach static const int msaa_value[] = { 2, 4 }; - int msaa = msaa_value[rt->msaa - VS::VIEWPORT_MSAA_EXT_2X]; + int msaa = msaa_value[rt->msaa - RS::VIEWPORT_MSAA_EXT_2X]; if (rt->external.depth == 0) { // create a multisample depth buffer, we're not reusing Godots because Godot's didn't get created.. @@ -5370,7 +5370,7 @@ void RasterizerStorageGLES2::render_target_set_as_unused(RID p_render_target) { rt->used_in_frame = false; } -void RasterizerStorageGLES2::render_target_set_msaa(RID p_render_target, VS::ViewportMSAA p_msaa) { +void RasterizerStorageGLES2::render_target_set_msaa(RID p_render_target, RS::ViewportMSAA p_msaa) { RenderTarget *rt = render_target_owner.getornull(p_render_target); ERR_FAIL_COND(!rt); @@ -5412,12 +5412,12 @@ RID RasterizerStorageGLES2::canvas_light_shadow_buffer_create(int p_width) { glGenTextures(1, &cls->distance); glBindTexture(GL_TEXTURE_2D, cls->distance); if (config.use_rgba_2d_shadows) { - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, cls->size, cls->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, cls->size, cls->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); } else { #ifdef GLES_OVER_GL - glTexImage2D(GL_TEXTURE_2D, 0, GL_R32F, cls->size, cls->height, 0, _RED_OES, GL_FLOAT, NULL); + glTexImage2D(GL_TEXTURE_2D, 0, GL_R32F, cls->size, cls->height, 0, _RED_OES, GL_FLOAT, nullptr); #else - glTexImage2D(GL_TEXTURE_2D, 0, GL_FLOAT, cls->size, cls->height, 0, _RED_OES, GL_FLOAT, NULL); + glTexImage2D(GL_TEXTURE_2D, 0, GL_FLOAT, cls->size, cls->height, 0, _RED_OES, GL_FLOAT, nullptr); #endif } @@ -5544,22 +5544,22 @@ void RasterizerStorageGLES2::canvas_light_occluder_set_polylines(RID p_occluder, } } -VS::InstanceType RasterizerStorageGLES2::get_base_type(RID p_rid) const { +RS::InstanceType RasterizerStorageGLES2::get_base_type(RID p_rid) const { if (mesh_owner.owns(p_rid)) { - return VS::INSTANCE_MESH; + return RS::INSTANCE_MESH; } else if (light_owner.owns(p_rid)) { - return VS::INSTANCE_LIGHT; + return RS::INSTANCE_LIGHT; } else if (multimesh_owner.owns(p_rid)) { - return VS::INSTANCE_MULTIMESH; + return RS::INSTANCE_MULTIMESH; } else if (immediate_owner.owns(p_rid)) { - return VS::INSTANCE_IMMEDIATE; + return RS::INSTANCE_IMMEDIATE; } else if (reflection_probe_owner.owns(p_rid)) { - return VS::INSTANCE_REFLECTION_PROBE; + return RS::INSTANCE_REFLECTION_PROBE; } else if (lightmap_capture_data_owner.owns(p_rid)) { - return VS::INSTANCE_LIGHTMAP_CAPTURE; + return RS::INSTANCE_LIGHTMAP_CAPTURE; } else { - return VS::INSTANCE_NONE; + return RS::INSTANCE_NONE; } } @@ -5611,7 +5611,7 @@ bool RasterizerStorageGLES2::free(RID p_rid) { while (shader->materials.first()) { Material *m = shader->materials.first()->self(); - m->shader = NULL; + m->shader = nullptr; _material_make_dirty(m); shader->materials.remove(shader->materials.first()); @@ -5710,7 +5710,7 @@ bool RasterizerStorageGLES2::free(RID p_rid) { } } - multimesh_allocate(p_rid, 0, VS::MULTIMESH_TRANSFORM_3D, VS::MULTIMESH_COLOR_NONE); + multimesh_allocate(p_rid, 0, RS::MULTIMESH_TRANSFORM_3D, RS::MULTIMESH_COLOR_NONE); update_dirty_multimeshes(); @@ -5817,25 +5817,25 @@ void RasterizerStorageGLES2::render_info_end_capture() { info.snap.vertices_count = info.render.vertices_count - info.snap.vertices_count; } -int RasterizerStorageGLES2::get_captured_render_info(VS::RenderInfo p_info) { +int RasterizerStorageGLES2::get_captured_render_info(RS::RenderInfo p_info) { switch (p_info) { - case VS::INFO_OBJECTS_IN_FRAME: { + case RS::INFO_OBJECTS_IN_FRAME: { return info.snap.object_count; } break; - case VS::INFO_VERTICES_IN_FRAME: { + case RS::INFO_VERTICES_IN_FRAME: { return info.snap.vertices_count; } break; - case VS::INFO_MATERIAL_CHANGES_IN_FRAME: { + case RS::INFO_MATERIAL_CHANGES_IN_FRAME: { return info.snap.material_switch_count; } break; - case VS::INFO_SHADER_CHANGES_IN_FRAME: { + case RS::INFO_SHADER_CHANGES_IN_FRAME: { return info.snap.shader_rebind_count; } break; - case VS::INFO_SURFACE_CHANGES_IN_FRAME: { + case RS::INFO_SURFACE_CHANGES_IN_FRAME: { return info.snap.surface_switch_count; } break; - case VS::INFO_DRAW_CALLS_IN_FRAME: { + case RS::INFO_DRAW_CALLS_IN_FRAME: { return info.snap.draw_call_count; } break; default: { @@ -5844,27 +5844,27 @@ int RasterizerStorageGLES2::get_captured_render_info(VS::RenderInfo p_info) { } } -int RasterizerStorageGLES2::get_render_info(VS::RenderInfo p_info) { +int RasterizerStorageGLES2::get_render_info(RS::RenderInfo p_info) { switch (p_info) { - case VS::INFO_OBJECTS_IN_FRAME: + case RS::INFO_OBJECTS_IN_FRAME: return info.render_final.object_count; - case VS::INFO_VERTICES_IN_FRAME: + case RS::INFO_VERTICES_IN_FRAME: return info.render_final.vertices_count; - case VS::INFO_MATERIAL_CHANGES_IN_FRAME: + case RS::INFO_MATERIAL_CHANGES_IN_FRAME: return info.render_final.material_switch_count; - case VS::INFO_SHADER_CHANGES_IN_FRAME: + case RS::INFO_SHADER_CHANGES_IN_FRAME: return info.render_final.shader_rebind_count; - case VS::INFO_SURFACE_CHANGES_IN_FRAME: + case RS::INFO_SURFACE_CHANGES_IN_FRAME: return info.render_final.surface_switch_count; - case VS::INFO_DRAW_CALLS_IN_FRAME: + case RS::INFO_DRAW_CALLS_IN_FRAME: return info.render_final.draw_call_count; - case VS::INFO_USAGE_VIDEO_MEM_TOTAL: + case RS::INFO_USAGE_VIDEO_MEM_TOTAL: return 0; //no idea - case VS::INFO_VIDEO_MEM_USED: + case RS::INFO_VIDEO_MEM_USED: return info.vertex_mem + info.texture_mem; - case VS::INFO_TEXTURE_MEM_USED: + case RS::INFO_TEXTURE_MEM_USED: return info.texture_mem; - case VS::INFO_VERTEX_MEM_USED: + case RS::INFO_VERTEX_MEM_USED: return info.vertex_mem; default: return 0; //no idea either @@ -5942,7 +5942,7 @@ void RasterizerStorageGLES2::initialize() { #ifdef IPHONE_ENABLED // appears that IPhone doesn't need to dlopen TODO: test this rigorously before removing - //void *gles2_lib = dlopen(NULL, RTLD_LAZY); + //void *gles2_lib = dlopen(nullptr, RTLD_LAZY); //glRenderbufferStorageMultisampleAPPLE = dlsym(gles2_lib, "glRenderbufferStorageMultisampleAPPLE"); //glResolveMultisampleFramebufferAPPLE = dlsym(gles2_lib, "glResolveMultisampleFramebufferAPPLE"); #elif ANDROID_ENABLED @@ -6014,7 +6014,7 @@ void RasterizerStorageGLES2::initialize() { GLuint depth; glGenTextures(1, &depth); glBindTexture(GL_TEXTURE_2D, depth); - glTexImage2D(GL_TEXTURE_2D, 0, config.depth_internalformat, 32, 32, 0, GL_DEPTH_COMPONENT, config.depth_type, NULL); + glTexImage2D(GL_TEXTURE_2D, 0, config.depth_internalformat, 32, 32, 0, GL_DEPTH_COMPONENT, config.depth_type, nullptr); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); @@ -6046,7 +6046,7 @@ void RasterizerStorageGLES2::initialize() { glGenTextures(1, &depth); glBindTexture(GL_TEXTURE_2D, depth); - glTexImage2D(GL_TEXTURE_2D, 0, config.depth_internalformat, 32, 32, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, NULL); + glTexImage2D(GL_TEXTURE_2D, 0, config.depth_internalformat, 32, 32, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, nullptr); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); @@ -6074,7 +6074,7 @@ void RasterizerStorageGLES2::initialize() { frame.count = 0; frame.delta = 0; - frame.current_rt = NULL; + frame.current_rt = nullptr; frame.clear_request = false; glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &config.max_vertex_texture_image_units); @@ -6190,7 +6190,7 @@ void RasterizerStorageGLES2::initialize() { glGenTextures(1, &resources.white_tex_array); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D_ARRAY, resources.white_tex_array); - glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 8, 8, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); + glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 8, 8, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr); glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 0, 8, 8, 1, GL_RGB, GL_UNSIGNED_BYTE, whitetexdata); glGenerateMipmap(GL_TEXTURE_2D_ARRAY); glBindTexture(GL_TEXTURE_2D, 0); @@ -6252,7 +6252,7 @@ void RasterizerStorageGLES2::initialize() { #endif config.force_vertex_shading = GLOBAL_GET("rendering/quality/shading/force_vertex_shading"); - config.use_fast_texture_filter = GLOBAL_GET("rendering/quality/filters/use_nearest_mipmap_filter"); + config.use_fast_texture_filter = GLOBAL_GET("rendering/quality/texture_filters/use_nearest_mipmap_filter"); } void RasterizerStorageGLES2::finalize() { diff --git a/drivers/gles2/rasterizer_storage_gles2.h b/drivers/gles2/rasterizer_storage_gles2.h index 86965730e0..29651936fb 100644 --- a/drivers/gles2/rasterizer_storage_gles2.h +++ b/drivers/gles2/rasterizer_storage_gles2.h @@ -32,8 +32,8 @@ #define RASTERIZERSTORAGEGLES2_H #include "core/self_list.h" -#include "servers/visual/rasterizer.h" -#include "servers/visual/shader_language.h" +#include "servers/rendering/rasterizer.h" +#include "servers/rendering/shader_language.h" #include "shader_compiler_gles2.h" #include "shader_gles2.h" @@ -249,7 +249,7 @@ public: int width, height, depth; int alloc_width, alloc_height; Image::Format format; - VS::TextureType type; + RS::TextureType type; GLenum target; GLenum gl_format_cache; @@ -279,24 +279,24 @@ public: bool redraw_if_visible; - VisualServer::TextureDetectCallback detect_3d; + RenderingServer::TextureDetectCallback detect_3d; void *detect_3d_ud; - VisualServer::TextureDetectCallback detect_srgb; + RenderingServer::TextureDetectCallback detect_srgb; void *detect_srgb_ud; - VisualServer::TextureDetectCallback detect_normal; + RenderingServer::TextureDetectCallback detect_normal; void *detect_normal_ud; Texture() : - proxy(NULL), + proxy(nullptr), flags(0), width(0), height(0), alloc_width(0), alloc_height(0), format(Image::FORMAT_L8), - type(VS::TEXTURE_TYPE_2D), + type(RS::TEXTURE_TYPE_2D), target(0), data_size(0), total_data_size(0), @@ -307,14 +307,14 @@ public: active(false), tex_id(0), stored_cube_sides(0), - render_target(NULL), + render_target(nullptr), redraw_if_visible(false), - detect_3d(NULL), - detect_3d_ud(NULL), - detect_srgb(NULL), - detect_srgb_ud(NULL), - detect_normal(NULL), - detect_normal_ud(NULL) { + detect_3d(nullptr), + detect_3d_ud(nullptr), + detect_srgb(nullptr), + detect_srgb_ud(nullptr), + detect_normal(nullptr), + detect_normal_ud(nullptr) { } _ALWAYS_INLINE_ Texture *get_ptr() { @@ -331,7 +331,7 @@ public: } for (Set<Texture *>::Element *E = proxy_owners.front(); E; E = E->next()) { - E->get()->proxy = NULL; + E->get()->proxy = nullptr; } if (proxy) { @@ -345,14 +345,14 @@ public: 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; virtual RID texture_create(); - virtual void texture_allocate(RID p_texture, int p_width, int p_height, int p_depth_3d, Image::Format p_format, VS::TextureType p_type, uint32_t p_flags = VS::TEXTURE_FLAGS_DEFAULT); + virtual void texture_allocate(RID p_texture, int p_width, int p_height, int p_depth_3d, Image::Format p_format, RS::TextureType p_type, uint32_t p_flags = RS::TEXTURE_FLAGS_DEFAULT); virtual void texture_set_data(RID p_texture, const Ref<Image> &p_image, int p_layer = 0); virtual 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_layer = 0); virtual Ref<Image> texture_get_data(RID p_texture, int p_layer = 0) const; virtual void texture_set_flags(RID p_texture, uint32_t p_flags); virtual uint32_t texture_get_flags(RID p_texture) const; virtual Image::Format texture_get_format(RID p_texture) const; - virtual VS::TextureType texture_get_type(RID p_texture) const; + virtual RS::TextureType texture_get_type(RID p_texture) const; virtual uint32_t texture_get_texid(RID p_texture) const; virtual uint32_t texture_get_width(RID p_texture) const; virtual uint32_t texture_get_height(RID p_texture) const; @@ -365,7 +365,7 @@ public: virtual void texture_set_shrink_all_x2_on_set_data(bool p_enable); - virtual void texture_debug_usage(List<VS::TextureInfo> *r_info); + virtual void texture_debug_usage(List<RS::TextureInfo> *r_info); virtual RID texture_create_radiance_cubemap(RID p_source, int p_resolution = -1) const; @@ -374,9 +374,9 @@ public: virtual void texture_set_proxy(RID p_texture, RID p_proxy); virtual Size2 texture_size_with_proxy(RID p_texture) const; - virtual void texture_set_detect_3d_callback(RID p_texture, VisualServer::TextureDetectCallback p_callback, void *p_userdata); - virtual void texture_set_detect_srgb_callback(RID p_texture, VisualServer::TextureDetectCallback p_callback, void *p_userdata); - virtual void texture_set_detect_normal_callback(RID p_texture, VisualServer::TextureDetectCallback p_callback, void *p_userdata); + virtual void texture_set_detect_3d_callback(RID p_texture, RenderingServer::TextureDetectCallback p_callback, void *p_userdata); + virtual void texture_set_detect_srgb_callback(RID p_texture, RenderingServer::TextureDetectCallback p_callback, void *p_userdata); + virtual void texture_set_detect_normal_callback(RID p_texture, RenderingServer::TextureDetectCallback p_callback, void *p_userdata); virtual void texture_set_force_redraw_if_visible(RID p_texture, bool p_enable); @@ -402,7 +402,7 @@ public: RID self; - VS::ShaderMode mode; + RS::ShaderMode mode; ShaderGLES2 *shader; String code; SelfList<Material>::List materials; @@ -508,7 +508,7 @@ public: Shader() : dirty_list(this) { - shader = NULL; + shader = nullptr; valid = false; custom_code_id = 0; version = 1; @@ -561,7 +561,7 @@ public: dirty_list(this) { can_cast_shadow_cache = false; is_animated_cache = false; - shader = NULL; + shader = nullptr; line_width = 1.0; last_pass = 0; render_priority = 0; @@ -617,7 +617,7 @@ public: uint32_t offset; }; - Attrib attribs[VS::ARRAY_MAX]; + Attrib attribs[RS::ARRAY_MAX]; Mesh *mesh; uint32_t format; @@ -641,7 +641,7 @@ public: int array_byte_size; int index_array_byte_size; - VS::PrimitiveType primitive; + RS::PrimitiveType primitive; Vector<AABB> skeleton_bone_aabb; Vector<bool> skeleton_bone_used; @@ -655,12 +655,12 @@ public: int total_data_size; Surface() : - mesh(NULL), + mesh(nullptr), array_len(0), index_array_len(0), array_byte_size(0), index_array_byte_size(0), - primitive(VS::PRIMITIVE_POINTS), + primitive(RS::PRIMITIVE_POINTS), active(false), total_data_size(0) { } @@ -675,7 +675,7 @@ public: Vector<Surface *> surfaces; int blend_shape_count; - VS::BlendShapeMode blend_shape_mode; + RS::BlendShapeMode blend_shape_mode; AABB custom_aabb; @@ -694,7 +694,7 @@ public: Mesh() : blend_shape_count(0), - blend_shape_mode(VS::BLEND_SHAPE_MODE_NORMALIZED) { + blend_shape_mode(RS::BLEND_SHAPE_MODE_NORMALIZED) { } }; @@ -702,13 +702,13 @@ public: virtual RID mesh_create(); - virtual void mesh_add_surface(RID p_mesh, uint32_t p_format, VS::PrimitiveType p_primitive, const Vector<uint8_t> &p_array, int p_vertex_count, const Vector<uint8_t> &p_index_array, int p_index_count, const AABB &p_aabb, const Vector<Vector<uint8_t>> &p_blend_shapes = Vector<Vector<uint8_t>>(), const Vector<AABB> &p_bone_aabbs = Vector<AABB>()); + virtual void mesh_add_surface(RID p_mesh, uint32_t p_format, RS::PrimitiveType p_primitive, const Vector<uint8_t> &p_array, int p_vertex_count, const Vector<uint8_t> &p_index_array, int p_index_count, const AABB &p_aabb, const Vector<Vector<uint8_t>> &p_blend_shapes = Vector<Vector<uint8_t>>(), const Vector<AABB> &p_bone_aabbs = Vector<AABB>()); virtual void mesh_set_blend_shape_count(RID p_mesh, int p_amount); virtual int mesh_get_blend_shape_count(RID p_mesh) const; - virtual void mesh_set_blend_shape_mode(RID p_mesh, VS::BlendShapeMode p_mode); - virtual VS::BlendShapeMode mesh_get_blend_shape_mode(RID p_mesh) const; + virtual void mesh_set_blend_shape_mode(RID p_mesh, RS::BlendShapeMode p_mode); + virtual RS::BlendShapeMode mesh_get_blend_shape_mode(RID p_mesh) const; virtual void mesh_surface_update_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data); @@ -722,7 +722,7 @@ public: virtual Vector<uint8_t> mesh_surface_get_index_array(RID p_mesh, int p_surface) const; virtual uint32_t mesh_surface_get_format(RID p_mesh, int p_surface) const; - virtual VS::PrimitiveType mesh_surface_get_primitive_type(RID p_mesh, int p_surface) const; + virtual RS::PrimitiveType mesh_surface_get_primitive_type(RID p_mesh, int p_surface) const; virtual AABB mesh_surface_get_aabb(RID p_mesh, int p_surface) const; virtual Vector<Vector<uint8_t>> mesh_surface_get_blend_shapes(RID p_mesh, int p_surface) const; @@ -744,9 +744,9 @@ public: RID mesh; int size; - VS::MultimeshTransformFormat transform_format; - VS::MultimeshColorFormat color_format; - VS::MultimeshCustomDataFormat custom_data_format; + RS::MultimeshTransformFormat transform_format; + RS::MultimeshColorFormat color_format; + RS::MultimeshCustomDataFormat custom_data_format; Vector<float> data; @@ -766,9 +766,9 @@ public: MultiMesh() : size(0), - transform_format(VS::MULTIMESH_TRANSFORM_2D), - color_format(VS::MULTIMESH_COLOR_NONE), - custom_data_format(VS::MULTIMESH_CUSTOM_DATA_NONE), + transform_format(RS::MULTIMESH_TRANSFORM_2D), + color_format(RS::MULTIMESH_COLOR_NONE), + custom_data_format(RS::MULTIMESH_CUSTOM_DATA_NONE), update_list(this), mesh_list(this), visible_instances(-1), @@ -786,7 +786,7 @@ public: virtual RID multimesh_create(); - virtual void multimesh_allocate(RID p_multimesh, int p_instances, VS::MultimeshTransformFormat p_transform_format, VS::MultimeshColorFormat p_color_format, VS::MultimeshCustomDataFormat p_data = VS::MULTIMESH_CUSTOM_DATA_NONE); + virtual void multimesh_allocate(RID p_multimesh, int p_instances, RS::MultimeshTransformFormat p_transform_format, RS::MultimeshColorFormat p_color_format, RS::MultimeshCustomDataFormat p_data = RS::MULTIMESH_CUSTOM_DATA_NONE); virtual int multimesh_get_instance_count(RID p_multimesh) const; virtual void multimesh_set_mesh(RID p_multimesh, RID p_mesh); @@ -817,7 +817,7 @@ public: struct Chunk { RID texture; - VS::PrimitiveType primitive; + RS::PrimitiveType primitive; Vector<Vector3> vertices; Vector<Vector3> normals; Vector<Plane> tangents; @@ -846,7 +846,7 @@ public: 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()); + virtual void immediate_begin(RID p_immediate, RS::PrimitiveType p_primitive, RID p_texture = RID()); virtual void immediate_vertex(RID p_immediate, const Vector3 &p_vertex); virtual void immediate_normal(RID p_immediate, const Vector3 &p_normal); virtual void immediate_tangent(RID p_immediate, const Plane &p_tangent); @@ -906,8 +906,8 @@ public: /* Light API */ struct Light : Instantiable { - VS::LightType type; - float param[VS::LIGHT_PARAM_MAX]; + RS::LightType type; + float param[RS::LIGHT_PARAM_MAX]; Color color; Color shadow_color; @@ -921,11 +921,11 @@ public: uint32_t cull_mask; - VS::LightOmniShadowMode omni_shadow_mode; - VS::LightOmniShadowDetail omni_shadow_detail; + RS::LightOmniShadowMode omni_shadow_mode; + RS::LightOmniShadowDetail omni_shadow_detail; - VS::LightDirectionalShadowMode directional_shadow_mode; - VS::LightDirectionalShadowDepthRangeMode directional_range_mode; + RS::LightDirectionalShadowMode directional_shadow_mode; + RS::LightDirectionalShadowDepthRangeMode directional_range_mode; bool directional_blend_splits; @@ -934,10 +934,10 @@ public: mutable RID_PtrOwner<Light> light_owner; - virtual RID light_create(VS::LightType p_type); + virtual RID light_create(RS::LightType p_type); virtual void light_set_color(RID p_light, const Color &p_color); - virtual void light_set_param(RID p_light, VS::LightParam p_param, float p_value); + virtual void light_set_param(RID p_light, RS::LightParam p_param, float p_value); virtual void light_set_shadow(RID p_light, bool p_enabled); virtual void light_set_shadow_color(RID p_light, const Color &p_color); virtual void light_set_projector(RID p_light, RID p_texture); @@ -946,23 +946,23 @@ public: virtual void light_set_reverse_cull_face_mode(RID p_light, bool p_enabled); virtual void light_set_use_gi(RID p_light, bool p_enabled); - virtual void light_omni_set_shadow_mode(RID p_light, VS::LightOmniShadowMode p_mode); - virtual void light_omni_set_shadow_detail(RID p_light, VS::LightOmniShadowDetail p_detail); + virtual void light_omni_set_shadow_mode(RID p_light, RS::LightOmniShadowMode p_mode); + virtual void light_omni_set_shadow_detail(RID p_light, RS::LightOmniShadowDetail p_detail); - virtual void light_directional_set_shadow_mode(RID p_light, VS::LightDirectionalShadowMode p_mode); + virtual void light_directional_set_shadow_mode(RID p_light, RS::LightDirectionalShadowMode p_mode); virtual void light_directional_set_blend_splits(RID p_light, bool p_enable); virtual bool light_directional_get_blend_splits(RID p_light) const; - virtual VS::LightDirectionalShadowMode light_directional_get_shadow_mode(RID p_light); - virtual VS::LightOmniShadowMode light_omni_get_shadow_mode(RID p_light); + virtual RS::LightDirectionalShadowMode light_directional_get_shadow_mode(RID p_light); + virtual RS::LightOmniShadowMode light_omni_get_shadow_mode(RID p_light); - virtual void light_directional_set_shadow_depth_range_mode(RID p_light, VS::LightDirectionalShadowDepthRangeMode p_range_mode); - virtual VS::LightDirectionalShadowDepthRangeMode light_directional_get_shadow_depth_range_mode(RID p_light) const; + virtual void light_directional_set_shadow_depth_range_mode(RID p_light, RS::LightDirectionalShadowDepthRangeMode p_range_mode); + virtual RS::LightDirectionalShadowDepthRangeMode light_directional_get_shadow_depth_range_mode(RID p_light) const; virtual bool light_has_shadow(RID p_light) const; - virtual VS::LightType light_get_type(RID p_light) const; - virtual float light_get_param(RID p_light, VS::LightParam p_param); + virtual RS::LightType light_get_type(RID p_light) const; + virtual float light_get_param(RID p_light, RS::LightParam p_param); virtual Color light_get_color(RID p_light); virtual bool light_get_use_gi(RID p_light); @@ -973,7 +973,7 @@ public: struct ReflectionProbe : Instantiable { - VS::ReflectionProbeUpdateMode update_mode; + RS::ReflectionProbeUpdateMode update_mode; float intensity; Color interior_ambient; float interior_ambient_energy; @@ -992,7 +992,7 @@ public: virtual RID reflection_probe_create(); - virtual void reflection_probe_set_update_mode(RID p_probe, VS::ReflectionProbeUpdateMode p_mode); + virtual void reflection_probe_set_update_mode(RID p_probe, RS::ReflectionProbeUpdateMode p_mode); virtual void reflection_probe_set_intensity(RID p_probe, float p_intensity); virtual void reflection_probe_set_interior_ambient(RID p_probe, const Color &p_ambient); virtual void reflection_probe_set_interior_ambient_energy(RID p_probe, float p_energy); @@ -1007,7 +1007,7 @@ public: virtual void reflection_probe_set_resolution(RID p_probe, int p_resolution); virtual AABB reflection_probe_get_aabb(RID p_probe) const; - virtual VS::ReflectionProbeUpdateMode reflection_probe_get_update_mode(RID p_probe) const; + virtual RS::ReflectionProbeUpdateMode reflection_probe_get_update_mode(RID p_probe) const; virtual uint32_t reflection_probe_get_cull_mask(RID p_probe) const; virtual int reflection_probe_get_resolution(RID p_probe) const; @@ -1111,7 +1111,7 @@ public: virtual void particles_set_fractional_delta(RID p_particles, bool p_enable); virtual void particles_restart(RID p_particles); - virtual void particles_set_draw_order(RID p_particles, VS::ParticlesDrawOrder p_order); + virtual void particles_set_draw_order(RID p_particles, RS::ParticlesDrawOrder p_order); virtual void particles_set_draw_passes(RID p_particles, int p_passes); virtual void particles_set_draw_pass_mesh(RID p_particles, int p_pass, RID p_mesh); @@ -1203,7 +1203,7 @@ public: bool flags[RENDER_TARGET_FLAG_MAX]; bool used_in_frame; - VS::ViewportMSAA msaa; + RS::ViewportMSAA msaa; RID texture; @@ -1223,7 +1223,7 @@ public: width(0), height(0), used_in_frame(false), - msaa(VS::VIEWPORT_MSAA_DISABLED), + msaa(RS::VIEWPORT_MSAA_DISABLED), used_dof_blur_near(false), mip_maps_allocated(false) { for (int i = 0; i < RENDER_TARGET_FLAG_MAX; ++i) { @@ -1247,7 +1247,7 @@ 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_set_as_unused(RID p_render_target); - virtual void render_target_set_msaa(RID p_render_target, VS::ViewportMSAA p_msaa); + virtual void render_target_set_msaa(RID p_render_target, RS::ViewportMSAA p_msaa); /* CANVAS SHADOW */ @@ -1279,7 +1279,7 @@ public: virtual RID canvas_light_occluder_create(); virtual void canvas_light_occluder_set_polylines(RID p_occluder, const Vector<Vector2> &p_lines); - virtual VS::InstanceType get_base_type(RID p_rid) const; + virtual RS::InstanceType get_base_type(RID p_rid) const; virtual bool free(RID p_rid); @@ -1309,9 +1309,9 @@ public: virtual void render_info_begin_capture(); virtual void render_info_end_capture(); - virtual int get_captured_render_info(VS::RenderInfo p_info); + virtual int get_captured_render_info(RS::RenderInfo p_info); - virtual int get_render_info(VS::RenderInfo p_info); + virtual int get_render_info(RS::RenderInfo p_info); virtual String get_video_adapter_name() const; virtual String get_video_adapter_vendor() const; diff --git a/drivers/gles2/shader_compiler_gles2.cpp b/drivers/gles2/shader_compiler_gles2.cpp index 620fcdbdca..699d6e1484 100644 --- a/drivers/gles2/shader_compiler_gles2.cpp +++ b/drivers/gles2/shader_compiler_gles2.cpp @@ -226,7 +226,7 @@ void ShaderCompilerGLES2::_dump_function_deps(SL::ShaderNode *p_node, const Stri _dump_function_deps(p_node, E->get(), p_func_code, r_to_add, r_added); - SL::FunctionNode *fnode = NULL; + SL::FunctionNode *fnode = nullptr; for (int i = 0; i < p_node->functions.size(); i++) { if (p_node->functions[i].name == E->get()) { @@ -639,12 +639,12 @@ String ShaderCompilerGLES2::_dump_node_code(SL::Node *p_node, int p_level, Gener code += _mkid(arr_node->name); } - if (arr_node->call_expression != NULL) { + if (arr_node->call_expression != nullptr) { code += "."; code += _dump_node_code(arr_node->call_expression, p_level, r_gen_code, p_actions, p_default_actions, p_assigning); } - if (arr_node->index_expression != NULL) { + if (arr_node->index_expression != nullptr) { code += "["; code += _dump_node_code(arr_node->index_expression, p_level, r_gen_code, p_actions, p_default_actions, p_assigning); code += "]"; @@ -923,7 +923,7 @@ String ShaderCompilerGLES2::_dump_node_code(SL::Node *p_node, int p_level, Gener code += _dump_node_code(member_node->owner, p_level, r_gen_code, p_actions, p_default_actions, p_assigning); code += "."; code += member_node->name; - if (member_node->index_expression != NULL) { + if (member_node->index_expression != nullptr) { code += "["; code += _dump_node_code(member_node->index_expression, p_level, r_gen_code, p_actions, p_default_actions, p_assigning); code += "]"; @@ -934,7 +934,7 @@ String ShaderCompilerGLES2::_dump_node_code(SL::Node *p_node, int p_level, Gener return code.as_string(); } -Error ShaderCompilerGLES2::compile(VS::ShaderMode p_mode, const String &p_code, IdentifierActions *p_actions, const String &p_path, GeneratedCode &r_gen_code) { +Error ShaderCompilerGLES2::compile(RS::ShaderMode p_mode, const String &p_code, IdentifierActions *p_actions, const String &p_path, GeneratedCode &r_gen_code) { Error err = parser.compile(p_code, ShaderTypes::get_singleton()->get_functions(p_mode), ShaderTypes::get_singleton()->get_modes(p_mode), ShaderTypes::get_singleton()->get_types()); @@ -945,7 +945,7 @@ Error ShaderCompilerGLES2::compile(VS::ShaderMode p_mode, const String &p_code, print_line(itos(i + 1) + " " + shader[i]); } - _err_print_error(NULL, p_path.utf8().get_data(), parser.get_error_line(), parser.get_error_text().utf8().get_data(), ERR_HANDLER_SHADER); + _err_print_error(nullptr, p_path.utf8().get_data(), parser.get_error_line(), parser.get_error_text().utf8().get_data(), ERR_HANDLER_SHADER); return err; } @@ -975,210 +975,210 @@ ShaderCompilerGLES2::ShaderCompilerGLES2() { /** CANVAS ITEM SHADER **/ - actions[VS::SHADER_CANVAS_ITEM].renames["VERTEX"] = "outvec.xy"; - actions[VS::SHADER_CANVAS_ITEM].renames["UV"] = "uv"; - actions[VS::SHADER_CANVAS_ITEM].renames["POINT_SIZE"] = "point_size"; - - actions[VS::SHADER_CANVAS_ITEM].renames["WORLD_MATRIX"] = "modelview_matrix"; - actions[VS::SHADER_CANVAS_ITEM].renames["PROJECTION_MATRIX"] = "projection_matrix"; - actions[VS::SHADER_CANVAS_ITEM].renames["EXTRA_MATRIX"] = "extra_matrix_instance"; - actions[VS::SHADER_CANVAS_ITEM].renames["TIME"] = "time"; - actions[VS::SHADER_CANVAS_ITEM].renames["AT_LIGHT_PASS"] = "at_light_pass"; - actions[VS::SHADER_CANVAS_ITEM].renames["INSTANCE_CUSTOM"] = "instance_custom"; - - actions[VS::SHADER_CANVAS_ITEM].renames["COLOR"] = "color"; - actions[VS::SHADER_CANVAS_ITEM].renames["NORMAL"] = "normal"; - actions[VS::SHADER_CANVAS_ITEM].renames["NORMALMAP"] = "normal_map"; - actions[VS::SHADER_CANVAS_ITEM].renames["NORMALMAP_DEPTH"] = "normal_depth"; - actions[VS::SHADER_CANVAS_ITEM].renames["TEXTURE"] = "color_texture"; - actions[VS::SHADER_CANVAS_ITEM].renames["TEXTURE_PIXEL_SIZE"] = "color_texpixel_size"; - actions[VS::SHADER_CANVAS_ITEM].renames["NORMAL_TEXTURE"] = "normal_texture"; - actions[VS::SHADER_CANVAS_ITEM].renames["SCREEN_UV"] = "screen_uv"; - actions[VS::SHADER_CANVAS_ITEM].renames["SCREEN_TEXTURE"] = "screen_texture"; - actions[VS::SHADER_CANVAS_ITEM].renames["SCREEN_PIXEL_SIZE"] = "screen_pixel_size"; - actions[VS::SHADER_CANVAS_ITEM].renames["FRAGCOORD"] = "gl_FragCoord"; - actions[VS::SHADER_CANVAS_ITEM].renames["POINT_COORD"] = "gl_PointCoord"; - - actions[VS::SHADER_CANVAS_ITEM].renames["LIGHT_VEC"] = "light_vec"; - actions[VS::SHADER_CANVAS_ITEM].renames["LIGHT_HEIGHT"] = "light_height"; - actions[VS::SHADER_CANVAS_ITEM].renames["LIGHT_COLOR"] = "light_color"; - actions[VS::SHADER_CANVAS_ITEM].renames["LIGHT_UV"] = "light_uv"; - actions[VS::SHADER_CANVAS_ITEM].renames["LIGHT"] = "light"; - actions[VS::SHADER_CANVAS_ITEM].renames["SHADOW_COLOR"] = "shadow_color"; - actions[VS::SHADER_CANVAS_ITEM].renames["SHADOW_VEC"] = "shadow_vec"; - - actions[VS::SHADER_CANVAS_ITEM].usage_defines["COLOR"] = "#define COLOR_USED\n"; - actions[VS::SHADER_CANVAS_ITEM].usage_defines["SCREEN_TEXTURE"] = "#define SCREEN_TEXTURE_USED\n"; - actions[VS::SHADER_CANVAS_ITEM].usage_defines["SCREEN_UV"] = "#define SCREEN_UV_USED\n"; - actions[VS::SHADER_CANVAS_ITEM].usage_defines["SCREEN_PIXEL_SIZE"] = "@SCREEN_UV"; - actions[VS::SHADER_CANVAS_ITEM].usage_defines["NORMAL"] = "#define NORMAL_USED\n"; - actions[VS::SHADER_CANVAS_ITEM].usage_defines["NORMALMAP"] = "#define NORMALMAP_USED\n"; - actions[VS::SHADER_CANVAS_ITEM].usage_defines["LIGHT"] = "#define USE_LIGHT_SHADER_CODE\n"; - actions[VS::SHADER_CANVAS_ITEM].render_mode_defines["skip_vertex_transform"] = "#define SKIP_TRANSFORM_USED\n"; - actions[VS::SHADER_CANVAS_ITEM].usage_defines["SHADOW_VEC"] = "#define SHADOW_VEC_USED\n"; + actions[RS::SHADER_CANVAS_ITEM].renames["VERTEX"] = "outvec.xy"; + actions[RS::SHADER_CANVAS_ITEM].renames["UV"] = "uv"; + actions[RS::SHADER_CANVAS_ITEM].renames["POINT_SIZE"] = "point_size"; + + actions[RS::SHADER_CANVAS_ITEM].renames["WORLD_MATRIX"] = "modelview_matrix"; + actions[RS::SHADER_CANVAS_ITEM].renames["PROJECTION_MATRIX"] = "projection_matrix"; + actions[RS::SHADER_CANVAS_ITEM].renames["EXTRA_MATRIX"] = "extra_matrix_instance"; + actions[RS::SHADER_CANVAS_ITEM].renames["TIME"] = "time"; + actions[RS::SHADER_CANVAS_ITEM].renames["AT_LIGHT_PASS"] = "at_light_pass"; + actions[RS::SHADER_CANVAS_ITEM].renames["INSTANCE_CUSTOM"] = "instance_custom"; + + actions[RS::SHADER_CANVAS_ITEM].renames["COLOR"] = "color"; + actions[RS::SHADER_CANVAS_ITEM].renames["NORMAL"] = "normal"; + actions[RS::SHADER_CANVAS_ITEM].renames["NORMALMAP"] = "normal_map"; + actions[RS::SHADER_CANVAS_ITEM].renames["NORMALMAP_DEPTH"] = "normal_depth"; + actions[RS::SHADER_CANVAS_ITEM].renames["TEXTURE"] = "color_texture"; + actions[RS::SHADER_CANVAS_ITEM].renames["TEXTURE_PIXEL_SIZE"] = "color_texpixel_size"; + actions[RS::SHADER_CANVAS_ITEM].renames["NORMAL_TEXTURE"] = "normal_texture"; + actions[RS::SHADER_CANVAS_ITEM].renames["SCREEN_UV"] = "screen_uv"; + actions[RS::SHADER_CANVAS_ITEM].renames["SCREEN_TEXTURE"] = "screen_texture"; + actions[RS::SHADER_CANVAS_ITEM].renames["SCREEN_PIXEL_SIZE"] = "screen_pixel_size"; + actions[RS::SHADER_CANVAS_ITEM].renames["FRAGCOORD"] = "gl_FragCoord"; + actions[RS::SHADER_CANVAS_ITEM].renames["POINT_COORD"] = "gl_PointCoord"; + + actions[RS::SHADER_CANVAS_ITEM].renames["LIGHT_VEC"] = "light_vec"; + actions[RS::SHADER_CANVAS_ITEM].renames["LIGHT_HEIGHT"] = "light_height"; + actions[RS::SHADER_CANVAS_ITEM].renames["LIGHT_COLOR"] = "light_color"; + actions[RS::SHADER_CANVAS_ITEM].renames["LIGHT_UV"] = "light_uv"; + actions[RS::SHADER_CANVAS_ITEM].renames["LIGHT"] = "light"; + actions[RS::SHADER_CANVAS_ITEM].renames["SHADOW_COLOR"] = "shadow_color"; + actions[RS::SHADER_CANVAS_ITEM].renames["SHADOW_VEC"] = "shadow_vec"; + + actions[RS::SHADER_CANVAS_ITEM].usage_defines["COLOR"] = "#define COLOR_USED\n"; + actions[RS::SHADER_CANVAS_ITEM].usage_defines["SCREEN_TEXTURE"] = "#define SCREEN_TEXTURE_USED\n"; + actions[RS::SHADER_CANVAS_ITEM].usage_defines["SCREEN_UV"] = "#define SCREEN_UV_USED\n"; + actions[RS::SHADER_CANVAS_ITEM].usage_defines["SCREEN_PIXEL_SIZE"] = "@SCREEN_UV"; + actions[RS::SHADER_CANVAS_ITEM].usage_defines["NORMAL"] = "#define NORMAL_USED\n"; + actions[RS::SHADER_CANVAS_ITEM].usage_defines["NORMALMAP"] = "#define NORMALMAP_USED\n"; + actions[RS::SHADER_CANVAS_ITEM].usage_defines["LIGHT"] = "#define USE_LIGHT_SHADER_CODE\n"; + actions[RS::SHADER_CANVAS_ITEM].render_mode_defines["skip_vertex_transform"] = "#define SKIP_TRANSFORM_USED\n"; + actions[RS::SHADER_CANVAS_ITEM].usage_defines["SHADOW_VEC"] = "#define SHADOW_VEC_USED\n"; // Ported from GLES3 - actions[VS::SHADER_CANVAS_ITEM].usage_defines["sinh"] = "#define SINH_USED\n"; - actions[VS::SHADER_CANVAS_ITEM].usage_defines["cosh"] = "#define COSH_USED\n"; - actions[VS::SHADER_CANVAS_ITEM].usage_defines["tanh"] = "#define TANH_USED\n"; - actions[VS::SHADER_CANVAS_ITEM].usage_defines["asinh"] = "#define ASINH_USED\n"; - actions[VS::SHADER_CANVAS_ITEM].usage_defines["acosh"] = "#define ACOSH_USED\n"; - actions[VS::SHADER_CANVAS_ITEM].usage_defines["atanh"] = "#define ATANH_USED\n"; - actions[VS::SHADER_CANVAS_ITEM].usage_defines["determinant"] = "#define DETERMINANT_USED\n"; - actions[VS::SHADER_CANVAS_ITEM].usage_defines["transpose"] = "#define TRANSPOSE_USED\n"; - actions[VS::SHADER_CANVAS_ITEM].usage_defines["outerProduct"] = "#define OUTER_PRODUCT_USED\n"; - actions[VS::SHADER_CANVAS_ITEM].usage_defines["round"] = "#define ROUND_USED\n"; - actions[VS::SHADER_CANVAS_ITEM].usage_defines["roundEven"] = "#define ROUND_EVEN_USED\n"; - actions[VS::SHADER_CANVAS_ITEM].usage_defines["inverse"] = "#define INVERSE_USED\n"; - actions[VS::SHADER_CANVAS_ITEM].usage_defines["isinf"] = "#define IS_INF_USED\n"; - actions[VS::SHADER_CANVAS_ITEM].usage_defines["isnan"] = "#define IS_NAN_USED\n"; - actions[VS::SHADER_CANVAS_ITEM].usage_defines["trunc"] = "#define TRUNC_USED\n"; + actions[RS::SHADER_CANVAS_ITEM].usage_defines["sinh"] = "#define SINH_USED\n"; + actions[RS::SHADER_CANVAS_ITEM].usage_defines["cosh"] = "#define COSH_USED\n"; + actions[RS::SHADER_CANVAS_ITEM].usage_defines["tanh"] = "#define TANH_USED\n"; + actions[RS::SHADER_CANVAS_ITEM].usage_defines["asinh"] = "#define ASINH_USED\n"; + actions[RS::SHADER_CANVAS_ITEM].usage_defines["acosh"] = "#define ACOSH_USED\n"; + actions[RS::SHADER_CANVAS_ITEM].usage_defines["atanh"] = "#define ATANH_USED\n"; + actions[RS::SHADER_CANVAS_ITEM].usage_defines["determinant"] = "#define DETERMINANT_USED\n"; + actions[RS::SHADER_CANVAS_ITEM].usage_defines["transpose"] = "#define TRANSPOSE_USED\n"; + actions[RS::SHADER_CANVAS_ITEM].usage_defines["outerProduct"] = "#define OUTER_PRODUCT_USED\n"; + actions[RS::SHADER_CANVAS_ITEM].usage_defines["round"] = "#define ROUND_USED\n"; + actions[RS::SHADER_CANVAS_ITEM].usage_defines["roundEven"] = "#define ROUND_EVEN_USED\n"; + actions[RS::SHADER_CANVAS_ITEM].usage_defines["inverse"] = "#define INVERSE_USED\n"; + actions[RS::SHADER_CANVAS_ITEM].usage_defines["isinf"] = "#define IS_INF_USED\n"; + actions[RS::SHADER_CANVAS_ITEM].usage_defines["isnan"] = "#define IS_NAN_USED\n"; + actions[RS::SHADER_CANVAS_ITEM].usage_defines["trunc"] = "#define TRUNC_USED\n"; /** SPATIAL SHADER **/ - actions[VS::SHADER_SPATIAL].renames["WORLD_MATRIX"] = "world_transform"; - actions[VS::SHADER_SPATIAL].renames["INV_CAMERA_MATRIX"] = "camera_inverse_matrix"; - actions[VS::SHADER_SPATIAL].renames["CAMERA_MATRIX"] = "camera_matrix"; - actions[VS::SHADER_SPATIAL].renames["PROJECTION_MATRIX"] = "projection_matrix"; - actions[VS::SHADER_SPATIAL].renames["INV_PROJECTION_MATRIX"] = "projection_inverse_matrix"; - actions[VS::SHADER_SPATIAL].renames["MODELVIEW_MATRIX"] = "modelview"; - - actions[VS::SHADER_SPATIAL].renames["VERTEX"] = "vertex.xyz"; - actions[VS::SHADER_SPATIAL].renames["NORMAL"] = "normal"; - actions[VS::SHADER_SPATIAL].renames["TANGENT"] = "tangent"; - actions[VS::SHADER_SPATIAL].renames["BINORMAL"] = "binormal"; - actions[VS::SHADER_SPATIAL].renames["POSITION"] = "position"; - actions[VS::SHADER_SPATIAL].renames["UV"] = "uv_interp"; - actions[VS::SHADER_SPATIAL].renames["UV2"] = "uv2_interp"; - actions[VS::SHADER_SPATIAL].renames["COLOR"] = "color_interp"; - actions[VS::SHADER_SPATIAL].renames["POINT_SIZE"] = "point_size"; + actions[RS::SHADER_SPATIAL].renames["WORLD_MATRIX"] = "world_transform"; + actions[RS::SHADER_SPATIAL].renames["INV_CAMERA_MATRIX"] = "camera_inverse_matrix"; + actions[RS::SHADER_SPATIAL].renames["CAMERA_MATRIX"] = "camera_matrix"; + actions[RS::SHADER_SPATIAL].renames["PROJECTION_MATRIX"] = "projection_matrix"; + actions[RS::SHADER_SPATIAL].renames["INV_PROJECTION_MATRIX"] = "projection_inverse_matrix"; + actions[RS::SHADER_SPATIAL].renames["MODELVIEW_MATRIX"] = "modelview"; + + actions[RS::SHADER_SPATIAL].renames["VERTEX"] = "vertex.xyz"; + actions[RS::SHADER_SPATIAL].renames["NORMAL"] = "normal"; + actions[RS::SHADER_SPATIAL].renames["TANGENT"] = "tangent"; + actions[RS::SHADER_SPATIAL].renames["BINORMAL"] = "binormal"; + actions[RS::SHADER_SPATIAL].renames["POSITION"] = "position"; + actions[RS::SHADER_SPATIAL].renames["UV"] = "uv_interp"; + actions[RS::SHADER_SPATIAL].renames["UV2"] = "uv2_interp"; + actions[RS::SHADER_SPATIAL].renames["COLOR"] = "color_interp"; + actions[RS::SHADER_SPATIAL].renames["POINT_SIZE"] = "point_size"; // gl_InstanceID is not available in OpenGL ES 2.0 - actions[VS::SHADER_SPATIAL].renames["INSTANCE_ID"] = "0"; + actions[RS::SHADER_SPATIAL].renames["INSTANCE_ID"] = "0"; //builtins - actions[VS::SHADER_SPATIAL].renames["TIME"] = "time"; - actions[VS::SHADER_SPATIAL].renames["VIEWPORT_SIZE"] = "viewport_size"; - - actions[VS::SHADER_SPATIAL].renames["FRAGCOORD"] = "gl_FragCoord"; - actions[VS::SHADER_SPATIAL].renames["FRONT_FACING"] = "gl_FrontFacing"; - actions[VS::SHADER_SPATIAL].renames["NORMALMAP"] = "normalmap"; - actions[VS::SHADER_SPATIAL].renames["NORMALMAP_DEPTH"] = "normaldepth"; - actions[VS::SHADER_SPATIAL].renames["ALBEDO"] = "albedo"; - actions[VS::SHADER_SPATIAL].renames["ALPHA"] = "alpha"; - actions[VS::SHADER_SPATIAL].renames["METALLIC"] = "metallic"; - actions[VS::SHADER_SPATIAL].renames["SPECULAR"] = "specular"; - actions[VS::SHADER_SPATIAL].renames["ROUGHNESS"] = "roughness"; - actions[VS::SHADER_SPATIAL].renames["RIM"] = "rim"; - actions[VS::SHADER_SPATIAL].renames["RIM_TINT"] = "rim_tint"; - actions[VS::SHADER_SPATIAL].renames["CLEARCOAT"] = "clearcoat"; - actions[VS::SHADER_SPATIAL].renames["CLEARCOAT_GLOSS"] = "clearcoat_gloss"; - actions[VS::SHADER_SPATIAL].renames["ANISOTROPY"] = "anisotropy"; - actions[VS::SHADER_SPATIAL].renames["ANISOTROPY_FLOW"] = "anisotropy_flow"; - actions[VS::SHADER_SPATIAL].renames["SSS_STRENGTH"] = "sss_strength"; - actions[VS::SHADER_SPATIAL].renames["TRANSMISSION"] = "transmission"; - actions[VS::SHADER_SPATIAL].renames["AO"] = "ao"; - actions[VS::SHADER_SPATIAL].renames["AO_LIGHT_AFFECT"] = "ao_light_affect"; - actions[VS::SHADER_SPATIAL].renames["EMISSION"] = "emission"; - actions[VS::SHADER_SPATIAL].renames["POINT_COORD"] = "gl_PointCoord"; - actions[VS::SHADER_SPATIAL].renames["INSTANCE_CUSTOM"] = "instance_custom"; - actions[VS::SHADER_SPATIAL].renames["SCREEN_UV"] = "screen_uv"; - actions[VS::SHADER_SPATIAL].renames["SCREEN_TEXTURE"] = "screen_texture"; - actions[VS::SHADER_SPATIAL].renames["DEPTH_TEXTURE"] = "depth_texture"; + actions[RS::SHADER_SPATIAL].renames["TIME"] = "time"; + actions[RS::SHADER_SPATIAL].renames["VIEWPORT_SIZE"] = "viewport_size"; + + actions[RS::SHADER_SPATIAL].renames["FRAGCOORD"] = "gl_FragCoord"; + actions[RS::SHADER_SPATIAL].renames["FRONT_FACING"] = "gl_FrontFacing"; + actions[RS::SHADER_SPATIAL].renames["NORMALMAP"] = "normalmap"; + actions[RS::SHADER_SPATIAL].renames["NORMALMAP_DEPTH"] = "normaldepth"; + actions[RS::SHADER_SPATIAL].renames["ALBEDO"] = "albedo"; + actions[RS::SHADER_SPATIAL].renames["ALPHA"] = "alpha"; + actions[RS::SHADER_SPATIAL].renames["METALLIC"] = "metallic"; + actions[RS::SHADER_SPATIAL].renames["SPECULAR"] = "specular"; + actions[RS::SHADER_SPATIAL].renames["ROUGHNESS"] = "roughness"; + actions[RS::SHADER_SPATIAL].renames["RIM"] = "rim"; + actions[RS::SHADER_SPATIAL].renames["RIM_TINT"] = "rim_tint"; + actions[RS::SHADER_SPATIAL].renames["CLEARCOAT"] = "clearcoat"; + actions[RS::SHADER_SPATIAL].renames["CLEARCOAT_GLOSS"] = "clearcoat_gloss"; + actions[RS::SHADER_SPATIAL].renames["ANISOTROPY"] = "anisotropy"; + actions[RS::SHADER_SPATIAL].renames["ANISOTROPY_FLOW"] = "anisotropy_flow"; + actions[RS::SHADER_SPATIAL].renames["SSS_STRENGTH"] = "sss_strength"; + actions[RS::SHADER_SPATIAL].renames["TRANSMISSION"] = "transmission"; + actions[RS::SHADER_SPATIAL].renames["AO"] = "ao"; + actions[RS::SHADER_SPATIAL].renames["AO_LIGHT_AFFECT"] = "ao_light_affect"; + actions[RS::SHADER_SPATIAL].renames["EMISSION"] = "emission"; + actions[RS::SHADER_SPATIAL].renames["POINT_COORD"] = "gl_PointCoord"; + actions[RS::SHADER_SPATIAL].renames["INSTANCE_CUSTOM"] = "instance_custom"; + actions[RS::SHADER_SPATIAL].renames["SCREEN_UV"] = "screen_uv"; + actions[RS::SHADER_SPATIAL].renames["SCREEN_TEXTURE"] = "screen_texture"; + actions[RS::SHADER_SPATIAL].renames["DEPTH_TEXTURE"] = "depth_texture"; // Defined in GLES3, but not available in GLES2 - //actions[VS::SHADER_SPATIAL].renames["DEPTH"] = "gl_FragDepth"; - actions[VS::SHADER_SPATIAL].renames["ALPHA_SCISSOR"] = "alpha_scissor"; - actions[VS::SHADER_SPATIAL].renames["OUTPUT_IS_SRGB"] = "SHADER_IS_SRGB"; + //actions[RS::SHADER_SPATIAL].renames["DEPTH"] = "gl_FragDepth"; + actions[RS::SHADER_SPATIAL].renames["ALPHA_SCISSOR"] = "alpha_scissor"; + actions[RS::SHADER_SPATIAL].renames["OUTPUT_IS_SRGB"] = "SHADER_IS_SRGB"; //for light - actions[VS::SHADER_SPATIAL].renames["VIEW"] = "view"; - actions[VS::SHADER_SPATIAL].renames["LIGHT_COLOR"] = "light_color"; - actions[VS::SHADER_SPATIAL].renames["LIGHT"] = "light"; - actions[VS::SHADER_SPATIAL].renames["ATTENUATION"] = "attenuation"; - actions[VS::SHADER_SPATIAL].renames["DIFFUSE_LIGHT"] = "diffuse_light"; - actions[VS::SHADER_SPATIAL].renames["SPECULAR_LIGHT"] = "specular_light"; - - actions[VS::SHADER_SPATIAL].usage_defines["TANGENT"] = "#define ENABLE_TANGENT_INTERP\n"; - actions[VS::SHADER_SPATIAL].usage_defines["BINORMAL"] = "@TANGENT"; - actions[VS::SHADER_SPATIAL].usage_defines["RIM"] = "#define LIGHT_USE_RIM\n"; - actions[VS::SHADER_SPATIAL].usage_defines["RIM_TINT"] = "@RIM"; - actions[VS::SHADER_SPATIAL].usage_defines["CLEARCOAT"] = "#define LIGHT_USE_CLEARCOAT\n"; - actions[VS::SHADER_SPATIAL].usage_defines["CLEARCOAT_GLOSS"] = "@CLEARCOAT"; - actions[VS::SHADER_SPATIAL].usage_defines["ANISOTROPY"] = "#define LIGHT_USE_ANISOTROPY\n"; - actions[VS::SHADER_SPATIAL].usage_defines["ANISOTROPY_FLOW"] = "@ANISOTROPY"; - actions[VS::SHADER_SPATIAL].usage_defines["AO"] = "#define ENABLE_AO\n"; - actions[VS::SHADER_SPATIAL].usage_defines["AO_LIGHT_AFFECT"] = "#define ENABLE_AO\n"; - actions[VS::SHADER_SPATIAL].usage_defines["UV"] = "#define ENABLE_UV_INTERP\n"; - actions[VS::SHADER_SPATIAL].usage_defines["UV2"] = "#define ENABLE_UV2_INTERP\n"; - actions[VS::SHADER_SPATIAL].usage_defines["NORMALMAP"] = "#define ENABLE_NORMALMAP\n"; - actions[VS::SHADER_SPATIAL].usage_defines["NORMALMAP_DEPTH"] = "@NORMALMAP"; - actions[VS::SHADER_SPATIAL].usage_defines["COLOR"] = "#define ENABLE_COLOR_INTERP\n"; - actions[VS::SHADER_SPATIAL].usage_defines["INSTANCE_CUSTOM"] = "#define ENABLE_INSTANCE_CUSTOM\n"; - actions[VS::SHADER_SPATIAL].usage_defines["ALPHA_SCISSOR"] = "#define ALPHA_SCISSOR_USED\n"; - actions[VS::SHADER_SPATIAL].usage_defines["POSITION"] = "#define OVERRIDE_POSITION\n"; - - actions[VS::SHADER_SPATIAL].usage_defines["SSS_STRENGTH"] = "#define ENABLE_SSS\n"; - actions[VS::SHADER_SPATIAL].usage_defines["TRANSMISSION"] = "#define TRANSMISSION_USED\n"; - actions[VS::SHADER_SPATIAL].usage_defines["SCREEN_TEXTURE"] = "#define SCREEN_TEXTURE_USED\n"; - actions[VS::SHADER_SPATIAL].usage_defines["DEPTH_TEXTURE"] = "#define DEPTH_TEXTURE_USED\n"; - actions[VS::SHADER_SPATIAL].usage_defines["SCREEN_UV"] = "#define SCREEN_UV_USED\n"; - - actions[VS::SHADER_SPATIAL].usage_defines["DIFFUSE_LIGHT"] = "#define USE_LIGHT_SHADER_CODE\n"; - actions[VS::SHADER_SPATIAL].usage_defines["SPECULAR_LIGHT"] = "#define USE_LIGHT_SHADER_CODE\n"; + actions[RS::SHADER_SPATIAL].renames["VIEW"] = "view"; + actions[RS::SHADER_SPATIAL].renames["LIGHT_COLOR"] = "light_color"; + actions[RS::SHADER_SPATIAL].renames["LIGHT"] = "light"; + actions[RS::SHADER_SPATIAL].renames["ATTENUATION"] = "attenuation"; + actions[RS::SHADER_SPATIAL].renames["DIFFUSE_LIGHT"] = "diffuse_light"; + actions[RS::SHADER_SPATIAL].renames["SPECULAR_LIGHT"] = "specular_light"; + + actions[RS::SHADER_SPATIAL].usage_defines["TANGENT"] = "#define ENABLE_TANGENT_INTERP\n"; + actions[RS::SHADER_SPATIAL].usage_defines["BINORMAL"] = "@TANGENT"; + actions[RS::SHADER_SPATIAL].usage_defines["RIM"] = "#define LIGHT_USE_RIM\n"; + actions[RS::SHADER_SPATIAL].usage_defines["RIM_TINT"] = "@RIM"; + actions[RS::SHADER_SPATIAL].usage_defines["CLEARCOAT"] = "#define LIGHT_USE_CLEARCOAT\n"; + actions[RS::SHADER_SPATIAL].usage_defines["CLEARCOAT_GLOSS"] = "@CLEARCOAT"; + actions[RS::SHADER_SPATIAL].usage_defines["ANISOTROPY"] = "#define LIGHT_USE_ANISOTROPY\n"; + actions[RS::SHADER_SPATIAL].usage_defines["ANISOTROPY_FLOW"] = "@ANISOTROPY"; + actions[RS::SHADER_SPATIAL].usage_defines["AO"] = "#define ENABLE_AO\n"; + actions[RS::SHADER_SPATIAL].usage_defines["AO_LIGHT_AFFECT"] = "#define ENABLE_AO\n"; + actions[RS::SHADER_SPATIAL].usage_defines["UV"] = "#define ENABLE_UV_INTERP\n"; + actions[RS::SHADER_SPATIAL].usage_defines["UV2"] = "#define ENABLE_UV2_INTERP\n"; + actions[RS::SHADER_SPATIAL].usage_defines["NORMALMAP"] = "#define ENABLE_NORMALMAP\n"; + actions[RS::SHADER_SPATIAL].usage_defines["NORMALMAP_DEPTH"] = "@NORMALMAP"; + actions[RS::SHADER_SPATIAL].usage_defines["COLOR"] = "#define ENABLE_COLOR_INTERP\n"; + actions[RS::SHADER_SPATIAL].usage_defines["INSTANCE_CUSTOM"] = "#define ENABLE_INSTANCE_CUSTOM\n"; + actions[RS::SHADER_SPATIAL].usage_defines["ALPHA_SCISSOR"] = "#define ALPHA_SCISSOR_USED\n"; + actions[RS::SHADER_SPATIAL].usage_defines["POSITION"] = "#define OVERRIDE_POSITION\n"; + + actions[RS::SHADER_SPATIAL].usage_defines["SSS_STRENGTH"] = "#define ENABLE_SSS\n"; + actions[RS::SHADER_SPATIAL].usage_defines["TRANSMISSION"] = "#define TRANSMISSION_USED\n"; + actions[RS::SHADER_SPATIAL].usage_defines["SCREEN_TEXTURE"] = "#define SCREEN_TEXTURE_USED\n"; + actions[RS::SHADER_SPATIAL].usage_defines["DEPTH_TEXTURE"] = "#define DEPTH_TEXTURE_USED\n"; + actions[RS::SHADER_SPATIAL].usage_defines["SCREEN_UV"] = "#define SCREEN_UV_USED\n"; + + actions[RS::SHADER_SPATIAL].usage_defines["DIFFUSE_LIGHT"] = "#define USE_LIGHT_SHADER_CODE\n"; + actions[RS::SHADER_SPATIAL].usage_defines["SPECULAR_LIGHT"] = "#define USE_LIGHT_SHADER_CODE\n"; // Ported from GLES3 - actions[VS::SHADER_SPATIAL].usage_defines["sinh"] = "#define SINH_USED\n"; - actions[VS::SHADER_SPATIAL].usage_defines["cosh"] = "#define COSH_USED\n"; - actions[VS::SHADER_SPATIAL].usage_defines["tanh"] = "#define TANH_USED\n"; - actions[VS::SHADER_SPATIAL].usage_defines["asinh"] = "#define ASINH_USED\n"; - actions[VS::SHADER_SPATIAL].usage_defines["acosh"] = "#define ACOSH_USED\n"; - actions[VS::SHADER_SPATIAL].usage_defines["atanh"] = "#define ATANH_USED\n"; - actions[VS::SHADER_SPATIAL].usage_defines["determinant"] = "#define DETERMINANT_USED\n"; - actions[VS::SHADER_SPATIAL].usage_defines["transpose"] = "#define TRANSPOSE_USED\n"; - actions[VS::SHADER_SPATIAL].usage_defines["outerProduct"] = "#define OUTER_PRODUCT_USED\n"; - actions[VS::SHADER_SPATIAL].usage_defines["round"] = "#define ROUND_USED\n"; - actions[VS::SHADER_SPATIAL].usage_defines["roundEven"] = "#define ROUND_EVEN_USED\n"; - actions[VS::SHADER_SPATIAL].usage_defines["inverse"] = "#define INVERSE_USED\n"; - actions[VS::SHADER_SPATIAL].usage_defines["isinf"] = "#define IS_INF_USED\n"; - actions[VS::SHADER_SPATIAL].usage_defines["isnan"] = "#define IS_NAN_USED\n"; - actions[VS::SHADER_SPATIAL].usage_defines["trunc"] = "#define TRUNC_USED\n"; - - actions[VS::SHADER_SPATIAL].render_mode_defines["skip_vertex_transform"] = "#define SKIP_TRANSFORM_USED\n"; - actions[VS::SHADER_SPATIAL].render_mode_defines["world_vertex_coords"] = "#define VERTEX_WORLD_COORDS_USED\n"; + actions[RS::SHADER_SPATIAL].usage_defines["sinh"] = "#define SINH_USED\n"; + actions[RS::SHADER_SPATIAL].usage_defines["cosh"] = "#define COSH_USED\n"; + actions[RS::SHADER_SPATIAL].usage_defines["tanh"] = "#define TANH_USED\n"; + actions[RS::SHADER_SPATIAL].usage_defines["asinh"] = "#define ASINH_USED\n"; + actions[RS::SHADER_SPATIAL].usage_defines["acosh"] = "#define ACOSH_USED\n"; + actions[RS::SHADER_SPATIAL].usage_defines["atanh"] = "#define ATANH_USED\n"; + actions[RS::SHADER_SPATIAL].usage_defines["determinant"] = "#define DETERMINANT_USED\n"; + actions[RS::SHADER_SPATIAL].usage_defines["transpose"] = "#define TRANSPOSE_USED\n"; + actions[RS::SHADER_SPATIAL].usage_defines["outerProduct"] = "#define OUTER_PRODUCT_USED\n"; + actions[RS::SHADER_SPATIAL].usage_defines["round"] = "#define ROUND_USED\n"; + actions[RS::SHADER_SPATIAL].usage_defines["roundEven"] = "#define ROUND_EVEN_USED\n"; + actions[RS::SHADER_SPATIAL].usage_defines["inverse"] = "#define INVERSE_USED\n"; + actions[RS::SHADER_SPATIAL].usage_defines["isinf"] = "#define IS_INF_USED\n"; + actions[RS::SHADER_SPATIAL].usage_defines["isnan"] = "#define IS_NAN_USED\n"; + actions[RS::SHADER_SPATIAL].usage_defines["trunc"] = "#define TRUNC_USED\n"; + + actions[RS::SHADER_SPATIAL].render_mode_defines["skip_vertex_transform"] = "#define SKIP_TRANSFORM_USED\n"; + actions[RS::SHADER_SPATIAL].render_mode_defines["world_vertex_coords"] = "#define VERTEX_WORLD_COORDS_USED\n"; // Defined in GLES3, could be implemented in GLES2 too if there's a need for it - //actions[VS::SHADER_SPATIAL].render_mode_defines["ensure_correct_normals"] = "#define ENSURE_CORRECT_NORMALS\n"; + //actions[RS::SHADER_SPATIAL].render_mode_defines["ensure_correct_normals"] = "#define ENSURE_CORRECT_NORMALS\n"; // Defined in GLES3, might not be possible in GLES2 as gl_FrontFacing is not available - //actions[VS::SHADER_SPATIAL].render_mode_defines["cull_front"] = "#define DO_SIDE_CHECK\n"; - //actions[VS::SHADER_SPATIAL].render_mode_defines["cull_disabled"] = "#define DO_SIDE_CHECK\n"; + //actions[RS::SHADER_SPATIAL].render_mode_defines["cull_front"] = "#define DO_SIDE_CHECK\n"; + //actions[RS::SHADER_SPATIAL].render_mode_defines["cull_disabled"] = "#define DO_SIDE_CHECK\n"; bool force_lambert = GLOBAL_GET("rendering/quality/shading/force_lambert_over_burley"); if (!force_lambert) { - actions[VS::SHADER_SPATIAL].render_mode_defines["diffuse_burley"] = "#define DIFFUSE_BURLEY\n"; + actions[RS::SHADER_SPATIAL].render_mode_defines["diffuse_burley"] = "#define DIFFUSE_BURLEY\n"; } - actions[VS::SHADER_SPATIAL].render_mode_defines["diffuse_oren_nayar"] = "#define DIFFUSE_OREN_NAYAR\n"; - actions[VS::SHADER_SPATIAL].render_mode_defines["diffuse_lambert_wrap"] = "#define DIFFUSE_LAMBERT_WRAP\n"; - actions[VS::SHADER_SPATIAL].render_mode_defines["diffuse_toon"] = "#define DIFFUSE_TOON\n"; + actions[RS::SHADER_SPATIAL].render_mode_defines["diffuse_oren_nayar"] = "#define DIFFUSE_OREN_NAYAR\n"; + actions[RS::SHADER_SPATIAL].render_mode_defines["diffuse_lambert_wrap"] = "#define DIFFUSE_LAMBERT_WRAP\n"; + actions[RS::SHADER_SPATIAL].render_mode_defines["diffuse_toon"] = "#define DIFFUSE_TOON\n"; bool force_blinn = GLOBAL_GET("rendering/quality/shading/force_blinn_over_ggx"); if (!force_blinn) { - actions[VS::SHADER_SPATIAL].render_mode_defines["specular_schlick_ggx"] = "#define SPECULAR_SCHLICK_GGX\n"; + actions[RS::SHADER_SPATIAL].render_mode_defines["specular_schlick_ggx"] = "#define SPECULAR_SCHLICK_GGX\n"; } else { - actions[VS::SHADER_SPATIAL].render_mode_defines["specular_schlick_ggx"] = "#define SPECULAR_BLINN\n"; + actions[RS::SHADER_SPATIAL].render_mode_defines["specular_schlick_ggx"] = "#define SPECULAR_BLINN\n"; } - actions[VS::SHADER_SPATIAL].render_mode_defines["specular_blinn"] = "#define SPECULAR_BLINN\n"; - actions[VS::SHADER_SPATIAL].render_mode_defines["specular_phong"] = "#define SPECULAR_PHONG\n"; - actions[VS::SHADER_SPATIAL].render_mode_defines["specular_toon"] = "#define SPECULAR_TOON\n"; - actions[VS::SHADER_SPATIAL].render_mode_defines["specular_disabled"] = "#define SPECULAR_DISABLED\n"; - actions[VS::SHADER_SPATIAL].render_mode_defines["shadows_disabled"] = "#define SHADOWS_DISABLED\n"; - actions[VS::SHADER_SPATIAL].render_mode_defines["ambient_light_disabled"] = "#define AMBIENT_LIGHT_DISABLED\n"; - actions[VS::SHADER_SPATIAL].render_mode_defines["shadow_to_opacity"] = "#define USE_SHADOW_TO_OPACITY\n"; + actions[RS::SHADER_SPATIAL].render_mode_defines["specular_blinn"] = "#define SPECULAR_BLINN\n"; + actions[RS::SHADER_SPATIAL].render_mode_defines["specular_phong"] = "#define SPECULAR_PHONG\n"; + actions[RS::SHADER_SPATIAL].render_mode_defines["specular_toon"] = "#define SPECULAR_TOON\n"; + actions[RS::SHADER_SPATIAL].render_mode_defines["specular_disabled"] = "#define SPECULAR_DISABLED\n"; + actions[RS::SHADER_SPATIAL].render_mode_defines["shadows_disabled"] = "#define SHADOWS_DISABLED\n"; + actions[RS::SHADER_SPATIAL].render_mode_defines["ambient_light_disabled"] = "#define AMBIENT_LIGHT_DISABLED\n"; + actions[RS::SHADER_SPATIAL].render_mode_defines["shadow_to_opacity"] = "#define USE_SHADOW_TO_OPACITY\n"; // No defines for particle shaders in GLES2, there are no GPU particles diff --git a/drivers/gles2/shader_compiler_gles2.h b/drivers/gles2/shader_compiler_gles2.h index dd10a27c0d..757dcdd4f2 100644 --- a/drivers/gles2/shader_compiler_gles2.h +++ b/drivers/gles2/shader_compiler_gles2.h @@ -33,9 +33,9 @@ #include "core/pair.h" #include "core/string_builder.h" -#include "servers/visual/shader_language.h" -#include "servers/visual/shader_types.h" -#include "servers/visual_server.h" +#include "servers/rendering/shader_language.h" +#include "servers/rendering/shader_types.h" +#include "servers/rendering_server.h" class ShaderCompilerGLES2 { public: @@ -91,10 +91,10 @@ private: Set<StringName> used_rmode_defines; Set<StringName> internal_functions; - DefaultIdentifierActions actions[VS::SHADER_MAX]; + DefaultIdentifierActions actions[RS::SHADER_MAX]; public: - Error compile(VS::ShaderMode p_mode, const String &p_code, IdentifierActions *p_actions, const String &p_path, GeneratedCode &r_gen_code); + Error compile(RS::ShaderMode p_mode, const String &p_code, IdentifierActions *p_actions, const String &p_path, GeneratedCode &r_gen_code); ShaderCompilerGLES2(); }; diff --git a/drivers/gles2/shader_gles2.cpp b/drivers/gles2/shader_gles2.cpp index f03f1ffa4f..2c335c6c5a 100644 --- a/drivers/gles2/shader_gles2.cpp +++ b/drivers/gles2/shader_gles2.cpp @@ -55,7 +55,7 @@ #endif -ShaderGLES2 *ShaderGLES2::active = NULL; +ShaderGLES2 *ShaderGLES2::active = nullptr; //#define DEBUG_SHADER @@ -103,10 +103,10 @@ bool ShaderGLES2::bind() { } void ShaderGLES2::unbind() { - version = NULL; + version = nullptr; glUseProgram(0); uniforms_dirty = true; - active = NULL; + active = nullptr; } static void _display_error_with_code(const String &p_error, const Vector<const char *> &p_code) { @@ -196,19 +196,19 @@ ShaderGLES2::Version *ShaderGLES2::get_current_version() { CharString code_string2; CharString code_globals; - CustomCode *cc = NULL; + CustomCode *cc = nullptr; if (conditional_version.code_version > 0) { cc = custom_code_map.getptr(conditional_version.code_version); - ERR_FAIL_COND_V(!cc, NULL); + ERR_FAIL_COND_V(!cc, nullptr); v.code_version = cc->version; } // program v.id = glCreateProgram(); - ERR_FAIL_COND_V(v.id == 0, NULL); + ERR_FAIL_COND_V(v.id == 0, nullptr); if (cc) { for (int i = 0; i < cc->custom_defines.size(); i++) { @@ -244,7 +244,7 @@ ShaderGLES2::Version *ShaderGLES2::get_current_version() { #endif v.vert_id = glCreateShader(GL_VERTEX_SHADER); - glShaderSource(v.vert_id, strings.size(), &strings[0], NULL); + glShaderSource(v.vert_id, strings.size(), &strings[0], nullptr); glCompileShader(v.vert_id); GLint status; @@ -281,7 +281,7 @@ ShaderGLES2::Version *ShaderGLES2::get_current_version() { v.id = 0; } - ERR_FAIL_V(NULL); + ERR_FAIL_V(nullptr); } strings.resize(string_base_size); @@ -320,7 +320,7 @@ ShaderGLES2::Version *ShaderGLES2::get_current_version() { #endif v.frag_id = glCreateShader(GL_FRAGMENT_SHADER); - glShaderSource(v.frag_id, strings.size(), &strings[0], NULL); + glShaderSource(v.frag_id, strings.size(), &strings[0], nullptr); glCompileShader(v.frag_id); glGetShaderiv(v.frag_id, GL_COMPILE_STATUS, &status); @@ -357,7 +357,7 @@ ShaderGLES2::Version *ShaderGLES2::get_current_version() { v.id = 0; } - ERR_FAIL_V(NULL); + ERR_FAIL_V(nullptr); } glAttachShader(v.id, v.frag_id); @@ -384,7 +384,7 @@ ShaderGLES2::Version *ShaderGLES2::get_current_version() { v.id = 0; ERR_PRINT("No OpenGL program link log. What the frick?"); - ERR_FAIL_V(NULL); + ERR_FAIL_V(nullptr); } if (iloglen == 0) { @@ -407,7 +407,7 @@ ShaderGLES2::Version *ShaderGLES2::get_current_version() { glDeleteProgram(v.id); v.id = 0; - ERR_FAIL_V(NULL); + ERR_FAIL_V(nullptr); } // get uniform locations @@ -553,7 +553,7 @@ void ShaderGLES2::setup( } void ShaderGLES2::finish() { - const VersionKey *V = NULL; + const VersionKey *V = nullptr; while ((V = version_map.next(V))) { Version &v = version_map[*V]; @@ -565,7 +565,7 @@ void ShaderGLES2::finish() { } void ShaderGLES2::clear_caches() { - const VersionKey *V = NULL; + const VersionKey *V = nullptr; while ((V = version_map.next(V))) { Version &v = version_map[*V]; @@ -578,7 +578,7 @@ void ShaderGLES2::clear_caches() { version_map.clear(); custom_code_map.clear(); - version = NULL; + version = nullptr; last_custom_code = 1; uniforms_dirty = true; } @@ -1093,7 +1093,7 @@ void ShaderGLES2::use_material(void *p_material) { } ShaderGLES2::ShaderGLES2() { - version = NULL; + version = nullptr; last_custom_code = 1; uniforms_dirty = true; } diff --git a/drivers/gles2/shader_gles2.h b/drivers/gles2/shader_gles2.h index d5e8159479..d20d5bc585 100644 --- a/drivers/gles2/shader_gles2.h +++ b/drivers/gles2/shader_gles2.h @@ -44,7 +44,7 @@ #include "core/math/camera_matrix.h" #include "core/pair.h" #include "core/variant.h" -#include "servers/visual/shader_language.h" +#include "servers/rendering/shader_language.h" #include <stdio.h> @@ -121,7 +121,7 @@ private: id = 0; vert_id = 0; frag_id = 0; - uniform_location = NULL; + uniform_location = nullptr; code_version = 0; ok = false; } diff --git a/drivers/gles2/shaders/SCsub b/drivers/gles2/shaders/SCsub index d7ae0243e6..bcd6ea79fb 100644 --- a/drivers/gles2/shaders/SCsub +++ b/drivers/gles2/shaders/SCsub @@ -1,23 +1,23 @@ #!/usr/bin/env python -Import('env') +Import("env") -if 'GLES2_GLSL' in env['BUILDERS']: - env.GLES2_GLSL('copy.glsl'); -# env.GLES2_GLSL('resolve.glsl'); - env.GLES2_GLSL('canvas.glsl'); - env.GLES2_GLSL('canvas_shadow.glsl'); - env.GLES2_GLSL('scene.glsl'); - env.GLES2_GLSL('cubemap_filter.glsl'); - env.GLES2_GLSL('cube_to_dp.glsl'); -# env.GLES2_GLSL('blend_shape.glsl'); -# env.GLES2_GLSL('screen_space_reflection.glsl'); - env.GLES2_GLSL('effect_blur.glsl'); -# env.GLES2_GLSL('subsurf_scattering.glsl'); -# env.GLES2_GLSL('ssao.glsl'); -# env.GLES2_GLSL('ssao_minify.glsl'); -# env.GLES2_GLSL('ssao_blur.glsl'); -# env.GLES2_GLSL('exposure.glsl'); - env.GLES2_GLSL('tonemap.glsl'); -# env.GLES2_GLSL('particles.glsl'); - env.GLES2_GLSL('lens_distorted.glsl'); +if "GLES2_GLSL" in env["BUILDERS"]: + env.GLES2_GLSL("copy.glsl") + # env.GLES2_GLSL('resolve.glsl'); + env.GLES2_GLSL("canvas.glsl") + env.GLES2_GLSL("canvas_shadow.glsl") + env.GLES2_GLSL("scene.glsl") + env.GLES2_GLSL("cubemap_filter.glsl") + env.GLES2_GLSL("cube_to_dp.glsl") + # env.GLES2_GLSL('blend_shape.glsl'); + # env.GLES2_GLSL('screen_space_reflection.glsl'); + env.GLES2_GLSL("effect_blur.glsl") + # env.GLES2_GLSL('subsurf_scattering.glsl'); + # env.GLES2_GLSL('ssao.glsl'); + # env.GLES2_GLSL('ssao_minify.glsl'); + # env.GLES2_GLSL('ssao_blur.glsl'); + # env.GLES2_GLSL('exposure.glsl'); + env.GLES2_GLSL("tonemap.glsl") + # env.GLES2_GLSL('particles.glsl'); + env.GLES2_GLSL("lens_distorted.glsl") diff --git a/drivers/gles2/shaders/blend_shape.glsl b/drivers/gles2/shaders/blend_shape.glsl index a1e954e33d..0d0b3e24e4 100644 --- a/drivers/gles2/shaders/blend_shape.glsl +++ b/drivers/gles2/shaders/blend_shape.glsl @@ -2,7 +2,7 @@ [vertex] /* -from VisualServer: +from RenderingServer: ARRAY_VERTEX=0, ARRAY_NORMAL=1, diff --git a/drivers/png/SCsub b/drivers/png/SCsub index 87b54cecaf..db08be0c47 100644 --- a/drivers/png/SCsub +++ b/drivers/png/SCsub @@ -1,11 +1,11 @@ #!/usr/bin/env python -Import('env') +Import("env") env_png = env.Clone() # Thirdparty source files -if env['builtin_libpng']: +if env["builtin_libpng"]: thirdparty_dir = "#thirdparty/libpng/" thirdparty_sources = [ "png.c", @@ -32,6 +32,7 @@ if env['builtin_libpng']: # Currently .ASM filter_neon.S does not compile on NT. import os + use_neon = "neon_enabled" in env and env["neon_enabled"] and os.name != "nt" if use_neon: env_png.Append(CPPDEFINES=[("PNG_ARM_NEON_OPT", 2)]) @@ -45,7 +46,7 @@ if env['builtin_libpng']: if use_neon: env_neon = env_thirdparty.Clone() if "S_compiler" in env: - env_neon['CC'] = env['S_compiler'] + env_neon["CC"] = env["S_compiler"] neon_sources = [] neon_sources.append(env_neon.Object(thirdparty_dir + "/arm/arm_init.c")) neon_sources.append(env_neon.Object(thirdparty_dir + "/arm/filter_neon_intrinsics.c")) @@ -56,4 +57,4 @@ if env['builtin_libpng']: # Godot source files env_png.add_source_files(env.drivers_sources, "*.cpp") -Export('env') +Export("env") diff --git a/drivers/png/png_driver_common.cpp b/drivers/png/png_driver_common.cpp index efd488fd5c..f17abcb54c 100644 --- a/drivers/png/png_driver_common.cpp +++ b/drivers/png/png_driver_common.cpp @@ -110,7 +110,7 @@ Error png_to_image(const uint8_t *p_source, size_t p_size, Ref<Image> p_image) { uint8_t *writer = buffer.ptrw(); // read image data to buffer and release libpng resources - success = png_image_finish_read(&png_img, NULL, writer, stride, NULL); + success = png_image_finish_read(&png_img, nullptr, writer, stride, nullptr); ERR_FAIL_COND_V_MSG(check_error(png_img), ERR_FILE_CORRUPT, png_img.message); ERR_FAIL_COND_V(!success, ERR_FILE_CORRUPT); @@ -175,7 +175,7 @@ Error image_to_png(const Ref<Image> &p_image, Vector<uint8_t> &p_buffer) { uint8_t *writer = p_buffer.ptrw(); success = png_image_write_to_memory(&png_img, &writer[buffer_offset], - &compressed_size, 0, reader, 0, NULL); + &compressed_size, 0, reader, 0, nullptr); ERR_FAIL_COND_V_MSG(check_error(png_img), FAILED, png_img.message); } if (!success) { @@ -189,7 +189,7 @@ Error image_to_png(const Ref<Image> &p_image, Vector<uint8_t> &p_buffer) { uint8_t *writer = p_buffer.ptrw(); success = png_image_write_to_memory(&png_img, &writer[buffer_offset], - &compressed_size, 0, reader, 0, NULL); + &compressed_size, 0, reader, 0, nullptr); ERR_FAIL_COND_V_MSG(check_error(png_img), FAILED, png_img.message); ERR_FAIL_COND_V(!success, FAILED); } diff --git a/drivers/pulseaudio/SCsub b/drivers/pulseaudio/SCsub index 28b315ae66..91e1140b75 100644 --- a/drivers/pulseaudio/SCsub +++ b/drivers/pulseaudio/SCsub @@ -1,5 +1,5 @@ #!/usr/bin/env python -Import('env') +Import("env") env.add_source_files(env.drivers_sources, "*.cpp") diff --git a/drivers/pulseaudio/audio_driver_pulseaudio.cpp b/drivers/pulseaudio/audio_driver_pulseaudio.cpp index ee9278fb8f..8a47f6cf96 100644 --- a/drivers/pulseaudio/audio_driver_pulseaudio.cpp +++ b/drivers/pulseaudio/audio_driver_pulseaudio.cpp @@ -98,7 +98,7 @@ void AudioDriverPulseAudio::detect_channels(bool capture) { pa_operation *pa_op = pa_context_get_server_info(pa_ctx, &AudioDriverPulseAudio::pa_server_info_cb, (void *)this); if (pa_op) { while (pa_status == 0) { - int ret = pa_mainloop_iterate(pa_ml, 1, NULL); + int ret = pa_mainloop_iterate(pa_ml, 1, nullptr); if (ret < 0) { ERR_PRINT("pa_mainloop_iterate error"); } @@ -128,7 +128,7 @@ void AudioDriverPulseAudio::detect_channels(bool capture) { if (pa_op) { while (pa_status == 0) { - int ret = pa_mainloop_iterate(pa_ml, 1, NULL); + int ret = pa_mainloop_iterate(pa_ml, 1, nullptr); if (ret < 0) { ERR_PRINT("pa_mainloop_iterate error"); } @@ -203,7 +203,7 @@ Error AudioDriverPulseAudio::init_device() { pa_map.map[7] = PA_CHANNEL_POSITION_SIDE_RIGHT; pa_str = pa_stream_new(pa_ctx, "Sound", &spec, &pa_map); - if (pa_str == NULL) { + if (pa_str == nullptr) { ERR_PRINT("PulseAudio: pa_stream_new error: " + String(pa_strerror(pa_context_errno(pa_ctx)))); ERR_FAIL_V(ERR_CANT_OPEN); } @@ -220,9 +220,9 @@ Error AudioDriverPulseAudio::init_device() { attr.maxlength = (uint32_t)-1; attr.minreq = (uint32_t)-1; - const char *dev = device_name == "Default" ? NULL : device_name.utf8().get_data(); + const char *dev = device_name == "Default" ? nullptr : device_name.utf8().get_data(); pa_stream_flags flags = pa_stream_flags(PA_STREAM_INTERPOLATE_TIMING | PA_STREAM_ADJUST_LATENCY | PA_STREAM_AUTO_TIMING_UPDATE); - int error_code = pa_stream_connect_playback(pa_str, dev, &attr, flags, NULL, NULL); + int error_code = pa_stream_connect_playback(pa_str, dev, &attr, flags, nullptr, nullptr); ERR_FAIL_COND_V(error_code < 0, ERR_CANT_OPEN); samples_in.resize(buffer_frames * channels); @@ -244,31 +244,31 @@ Error AudioDriverPulseAudio::init() { mix_rate = GLOBAL_DEF_RST("audio/mix_rate", DEFAULT_MIX_RATE); pa_ml = pa_mainloop_new(); - ERR_FAIL_COND_V(pa_ml == NULL, ERR_CANT_OPEN); + ERR_FAIL_COND_V(pa_ml == nullptr, ERR_CANT_OPEN); pa_ctx = pa_context_new(pa_mainloop_get_api(pa_ml), "Godot"); - ERR_FAIL_COND_V(pa_ctx == NULL, ERR_CANT_OPEN); + ERR_FAIL_COND_V(pa_ctx == nullptr, ERR_CANT_OPEN); pa_ready = 0; pa_context_set_state_callback(pa_ctx, pa_state_cb, (void *)this); - int ret = pa_context_connect(pa_ctx, NULL, PA_CONTEXT_NOFLAGS, NULL); + int ret = pa_context_connect(pa_ctx, nullptr, PA_CONTEXT_NOFLAGS, nullptr); if (ret < 0) { if (pa_ctx) { pa_context_unref(pa_ctx); - pa_ctx = NULL; + pa_ctx = nullptr; } if (pa_ml) { pa_mainloop_free(pa_ml); - pa_ml = NULL; + pa_ml = nullptr; } return ERR_CANT_OPEN; } while (pa_ready == 0) { - ret = pa_mainloop_iterate(pa_ml, 1, NULL); + ret = pa_mainloop_iterate(pa_ml, 1, nullptr); if (ret < 0) { ERR_PRINT("pa_mainloop_iterate error"); } @@ -278,12 +278,12 @@ Error AudioDriverPulseAudio::init() { if (pa_ctx) { pa_context_disconnect(pa_ctx); pa_context_unref(pa_ctx); - pa_ctx = NULL; + pa_ctx = nullptr; } if (pa_ml) { pa_mainloop_free(pa_ml); - pa_ml = NULL; + pa_ml = nullptr; } return ERR_CANT_OPEN; @@ -377,7 +377,7 @@ void AudioDriverPulseAudio::thread_func(void *p_udata) { int ret; do { - ret = pa_mainloop_iterate(ad->pa_ml, 0, NULL); + ret = pa_mainloop_iterate(ad->pa_ml, 0, nullptr); } while (ret > 0); if (avail_bytes > 0 && pa_stream_get_state(ad->pa_str) == PA_STREAM_READY) { @@ -385,7 +385,7 @@ void AudioDriverPulseAudio::thread_func(void *p_udata) { if (bytes > 0) { size_t bytes_to_write = MIN(bytes, avail_bytes); const void *ptr = ad->samples_out.ptr(); - ret = pa_stream_write(ad->pa_str, (char *)ptr + write_ofs, bytes_to_write, NULL, 0LL, PA_SEEK_RELATIVE); + ret = pa_stream_write(ad->pa_str, (char *)ptr + write_ofs, bytes_to_write, nullptr, 0LL, PA_SEEK_RELATIVE); if (ret != 0) { ERR_PRINT("PulseAudio: pa_stream_write error: " + String(pa_strerror(ret))); } else { @@ -432,7 +432,7 @@ void AudioDriverPulseAudio::thread_func(void *p_udata) { pa_operation *pa_op = pa_context_get_server_info(ad->pa_ctx, &AudioDriverPulseAudio::pa_server_info_cb, (void *)ad); if (pa_op) { while (ad->pa_status == 0) { - ret = pa_mainloop_iterate(ad->pa_ml, 1, NULL); + ret = pa_mainloop_iterate(ad->pa_ml, 1, nullptr); if (ret < 0) { ERR_PRINT("pa_mainloop_iterate error"); } @@ -463,7 +463,7 @@ void AudioDriverPulseAudio::thread_func(void *p_udata) { if (ad->pa_rec_str && pa_stream_get_state(ad->pa_rec_str) == PA_STREAM_READY) { size_t bytes = pa_stream_readable_size(ad->pa_rec_str); if (bytes > 0) { - const void *ptr = NULL; + const void *ptr = nullptr; size_t maxbytes = ad->input_buffer.size() * sizeof(int16_t); bytes = MIN(bytes, maxbytes); @@ -555,7 +555,7 @@ Array AudioDriverPulseAudio::get_device_list() { pa_devices.clear(); pa_devices.push_back("Default"); - if (pa_ctx == NULL) { + if (pa_ctx == nullptr) { return pa_devices; } @@ -566,7 +566,7 @@ Array AudioDriverPulseAudio::get_device_list() { pa_operation *pa_op = pa_context_get_sink_info_list(pa_ctx, pa_sinklist_cb, (void *)this); if (pa_op) { while (pa_status == 0) { - int ret = pa_mainloop_iterate(pa_ml, 1, NULL); + int ret = pa_mainloop_iterate(pa_ml, 1, nullptr); if (ret < 0) { ERR_PRINT("pa_mainloop_iterate error"); } @@ -613,7 +613,7 @@ void AudioDriverPulseAudio::finish_device() { if (pa_str) { pa_stream_disconnect(pa_str); pa_stream_unref(pa_str); - pa_str = NULL; + pa_str = nullptr; } } @@ -630,17 +630,17 @@ void AudioDriverPulseAudio::finish() { if (pa_ctx) { pa_context_disconnect(pa_ctx); pa_context_unref(pa_ctx); - pa_ctx = NULL; + pa_ctx = nullptr; } if (pa_ml) { pa_mainloop_free(pa_ml); - pa_ml = NULL; + pa_ml = nullptr; } memdelete(thread); - thread = NULL; + thread = nullptr; } Error AudioDriverPulseAudio::capture_init_device() { @@ -680,12 +680,12 @@ Error AudioDriverPulseAudio::capture_init_device() { attr.fragsize = input_buffer_size * sizeof(int16_t); pa_rec_str = pa_stream_new(pa_ctx, "Record", &spec, &pa_rec_map); - if (pa_rec_str == NULL) { + if (pa_rec_str == nullptr) { ERR_PRINT("PulseAudio: pa_stream_new error: " + String(pa_strerror(pa_context_errno(pa_ctx)))); ERR_FAIL_V(ERR_CANT_OPEN); } - const char *dev = capture_device_name == "Default" ? NULL : capture_device_name.utf8().get_data(); + const char *dev = capture_device_name == "Default" ? nullptr : capture_device_name.utf8().get_data(); pa_stream_flags flags = pa_stream_flags(PA_STREAM_INTERPOLATE_TIMING | PA_STREAM_ADJUST_LATENCY | PA_STREAM_AUTO_TIMING_UPDATE); int error_code = pa_stream_connect_record(pa_rec_str, dev, &attr, flags); if (error_code < 0) { @@ -709,7 +709,7 @@ void AudioDriverPulseAudio::capture_finish_device() { ERR_PRINT("PulseAudio: pa_stream_disconnect error: " + String(pa_strerror(ret))); } pa_stream_unref(pa_rec_str); - pa_rec_str = NULL; + pa_rec_str = nullptr; } } @@ -757,7 +757,7 @@ Array AudioDriverPulseAudio::capture_get_device_list() { pa_rec_devices.clear(); pa_rec_devices.push_back("Default"); - if (pa_ctx == NULL) { + if (pa_ctx == nullptr) { return pa_rec_devices; } @@ -768,7 +768,7 @@ Array AudioDriverPulseAudio::capture_get_device_list() { pa_operation *pa_op = pa_context_get_source_info_list(pa_ctx, pa_sourcelist_cb, (void *)this); if (pa_op) { while (pa_status == 0) { - int ret = pa_mainloop_iterate(pa_ml, 1, NULL); + int ret = pa_mainloop_iterate(pa_ml, 1, nullptr); if (ret < 0) { ERR_PRINT("pa_mainloop_iterate error"); } @@ -794,11 +794,11 @@ String AudioDriverPulseAudio::capture_get_device() { } AudioDriverPulseAudio::AudioDriverPulseAudio() : - thread(NULL), - pa_ml(NULL), - pa_ctx(NULL), - pa_str(NULL), - pa_rec_str(NULL), + thread(nullptr), + pa_ml(nullptr), + pa_ctx(nullptr), + pa_str(nullptr), + pa_rec_str(nullptr), device_name("Default"), new_device("Default"), default_device(""), diff --git a/drivers/spirv-reflect/SCsub b/drivers/spirv-reflect/SCsub index 8ff27da114..d0ffaf068d 100644 --- a/drivers/spirv-reflect/SCsub +++ b/drivers/spirv-reflect/SCsub @@ -1,17 +1,17 @@ #!/usr/bin/env python -Import('env') +Import("env") env_spirv_reflect = env.Clone() env_spirv_reflect.disable_warnings() thirdparty_dir = "#thirdparty/spirv-reflect/" thirdparty_sources = [ - "spirv_reflect.c" + "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') +Export("env") diff --git a/drivers/unix/SCsub b/drivers/unix/SCsub index 4888f56099..91ef613546 100644 --- a/drivers/unix/SCsub +++ b/drivers/unix/SCsub @@ -1,7 +1,7 @@ #!/usr/bin/env python -Import('env') +Import("env") env.add_source_files(env.drivers_sources, "*.cpp") -env["check_c_headers"] = [ [ "mntent.h", "HAVE_MNTENT" ] ] +env["check_c_headers"] = [["mntent.h", "HAVE_MNTENT"]] diff --git a/drivers/unix/dir_access_unix.cpp b/drivers/unix/dir_access_unix.cpp index 715bc56003..00103684c7 100644 --- a/drivers/unix/dir_access_unix.cpp +++ b/drivers/unix/dir_access_unix.cpp @@ -129,7 +129,7 @@ String DirAccessUnix::get_next() { dirent *entry = readdir(dir_stream); - if (entry == NULL) { + if (entry == nullptr) { list_dir_end(); return ""; } @@ -173,7 +173,7 @@ void DirAccessUnix::list_dir_end() { if (dir_stream) closedir(dir_stream); - dir_stream = 0; + dir_stream = nullptr; _cisdir = false; } @@ -207,7 +207,7 @@ static void _get_drives(List<String> *list) { char strings[4096]; while (getmntent_r(mtab, &mnt, strings, sizeof(strings))) { - if (mnt.mnt_dir != NULL && _filter_drive(&mnt)) { + if (mnt.mnt_dir != nullptr && _filter_drive(&mnt)) { // Avoid duplicates if (!list->find(mnt.mnt_dir)) { list->push_back(mnt.mnt_dir); @@ -306,7 +306,7 @@ Error DirAccessUnix::change_dir(String p_dir) { // prev_dir is the directory we are changing out of String prev_dir; char real_current_dir_name[2048]; - ERR_FAIL_COND_V(getcwd(real_current_dir_name, 2048) == NULL, ERR_BUG); + ERR_FAIL_COND_V(getcwd(real_current_dir_name, 2048) == nullptr, ERR_BUG); if (prev_dir.parse_utf8(real_current_dir_name)) prev_dir = real_current_dir_name; //no utf8, maybe latin? @@ -327,7 +327,7 @@ Error DirAccessUnix::change_dir(String p_dir) { String base = _get_root_path(); if (base != String() && !try_dir.begins_with(base)) { - ERR_FAIL_COND_V(getcwd(real_current_dir_name, 2048) == NULL, ERR_BUG); + ERR_FAIL_COND_V(getcwd(real_current_dir_name, 2048) == nullptr, ERR_BUG); String new_dir; new_dir.parse_utf8(real_current_dir_name); @@ -410,14 +410,14 @@ String DirAccessUnix::get_filesystem_type() const { DirAccessUnix::DirAccessUnix() { - dir_stream = 0; + dir_stream = nullptr; _cisdir = false; /* determine drive count */ // set current directory to an absolute path of the current directory char real_current_dir_name[2048]; - ERR_FAIL_COND(getcwd(real_current_dir_name, 2048) == NULL); + ERR_FAIL_COND(getcwd(real_current_dir_name, 2048) == nullptr); if (current_dir.parse_utf8(real_current_dir_name)) current_dir = real_current_dir_name; diff --git a/drivers/unix/file_access_unix.cpp b/drivers/unix/file_access_unix.cpp index 91164dc3f9..4aa408a1f0 100644 --- a/drivers/unix/file_access_unix.cpp +++ b/drivers/unix/file_access_unix.cpp @@ -76,7 +76,7 @@ Error FileAccessUnix::_open(const String &p_path, int p_mode_flags) { if (f) fclose(f); - f = NULL; + f = nullptr; path_src = p_path; path = fix_path(p_path); @@ -119,7 +119,7 @@ Error FileAccessUnix::_open(const String &p_path, int p_mode_flags) { f = fopen(path.utf8().get_data(), mode_string); - if (f == NULL) { + if (f == nullptr) { switch (errno) { case ENOENT: { last_error = ERR_FILE_NOT_FOUND; @@ -155,7 +155,7 @@ void FileAccessUnix::close() { return; fclose(f); - f = NULL; + f = nullptr; if (close_notification_func) { close_notification_func(path, flags); @@ -175,7 +175,7 @@ void FileAccessUnix::close() { bool FileAccessUnix::is_open() const { - return (f != NULL); + return (f != nullptr); } String FileAccessUnix::get_path() const { @@ -352,10 +352,10 @@ FileAccess *FileAccessUnix::create_libc() { return memnew(FileAccessUnix); } -CloseNotificationFunc FileAccessUnix::close_notification_func = NULL; +CloseNotificationFunc FileAccessUnix::close_notification_func = nullptr; FileAccessUnix::FileAccessUnix() : - f(NULL), + f(nullptr), flags(0), last_error(OK) { } diff --git a/drivers/unix/ip_unix.cpp b/drivers/unix/ip_unix.cpp index 08c099f771..5e3dedfc2f 100644 --- a/drivers/unix/ip_unix.cpp +++ b/drivers/unix/ip_unix.cpp @@ -107,13 +107,13 @@ IP_Address IP_Unix::_resolve_hostname(const String &p_hostname, Type p_type) { }; hints.ai_flags &= ~AI_NUMERICHOST; - int s = getaddrinfo(p_hostname.utf8().get_data(), NULL, &hints, &result); + int s = getaddrinfo(p_hostname.utf8().get_data(), nullptr, &hints, &result); if (s != 0) { ERR_PRINT("getaddrinfo failed! Cannot resolve hostname."); return IP_Address(); }; - if (result == NULL || result->ai_addr == NULL) { + if (result == nullptr || result->ai_addr == nullptr) { ERR_PRINT("Invalid response from getaddrinfo"); if (result) freeaddrinfo(result); @@ -175,7 +175,7 @@ void IP_Unix::get_local_interfaces(Map<String, Interface_Info> *r_interfaces) co addrs = (IP_ADAPTER_ADDRESSES *)memalloc(buf_size); int err = GetAdaptersAddresses(AF_UNSPEC, GAA_FLAG_SKIP_ANYCAST | GAA_FLAG_SKIP_MULTICAST | GAA_FLAG_SKIP_DNS_SERVER | GAA_FLAG_SKIP_FRIENDLY_NAME, - NULL, addrs, &buf_size); + nullptr, addrs, &buf_size); if (err == NO_ERROR) { break; }; @@ -189,7 +189,7 @@ void IP_Unix::get_local_interfaces(Map<String, Interface_Info> *r_interfaces) co IP_ADAPTER_ADDRESSES *adapter = addrs; - while (adapter != NULL) { + while (adapter != nullptr) { Interface_Info info; info.name = adapter->AdapterName; @@ -197,7 +197,7 @@ void IP_Unix::get_local_interfaces(Map<String, Interface_Info> *r_interfaces) co info.index = String::num_uint64(adapter->IfIndex); IP_ADAPTER_UNICAST_ADDRESS *address = adapter->FirstUnicastAddress; - while (address != NULL) { + while (address != nullptr) { int family = address->Address.lpSockaddr->sa_family; if (family != AF_INET && family != AF_INET6) continue; @@ -219,13 +219,13 @@ void IP_Unix::get_local_interfaces(Map<String, Interface_Info> *r_interfaces) co void IP_Unix::get_local_interfaces(Map<String, Interface_Info> *r_interfaces) const { - struct ifaddrs *ifAddrStruct = NULL; - struct ifaddrs *ifa = NULL; + struct ifaddrs *ifAddrStruct = nullptr; + struct ifaddrs *ifa = nullptr; int family; getifaddrs(&ifAddrStruct); - for (ifa = ifAddrStruct; ifa != NULL; ifa = ifa->ifa_next) { + for (ifa = ifAddrStruct; ifa != nullptr; ifa = ifa->ifa_next) { if (!ifa->ifa_addr) continue; @@ -248,7 +248,7 @@ void IP_Unix::get_local_interfaces(Map<String, Interface_Info> *r_interfaces) co info.ip_addresses.push_front(_sockaddr2ip(ifa->ifa_addr)); } - if (ifAddrStruct != NULL) freeifaddrs(ifAddrStruct); + if (ifAddrStruct != nullptr) freeifaddrs(ifAddrStruct); } #endif diff --git a/drivers/unix/net_socket_posix.cpp b/drivers/unix/net_socket_posix.cpp index 4adeeb1d9b..7c6543c3a2 100644 --- a/drivers/unix/net_socket_posix.cpp +++ b/drivers/unix/net_socket_posix.cpp @@ -86,7 +86,7 @@ #define SOCK_CLOSE closesocket // connect is broken on windows under certain conditions, reasons unknown: // See https://github.com/godotengine/webrtc-native/issues/6 -#define SOCK_CONNECT(p_sock, p_addr, p_addr_len) ::WSAConnect(p_sock, p_addr, p_addr_len, NULL, NULL, NULL, NULL) +#define SOCK_CONNECT(p_sock, p_addr, p_addr_len) ::WSAConnect(p_sock, p_addr, p_addr_len, nullptr, nullptr, nullptr, nullptr) // Workaround missing flag in MinGW #if defined(__MINGW32__) && !defined(SIO_UDP_NETRESET) @@ -155,7 +155,7 @@ NetSocket *NetSocketPosix::_create_func() { void NetSocketPosix::make_default() { #if defined(WINDOWS_ENABLED) - if (_create == NULL) { + if (_create == nullptr) { WSADATA data; WSAStartup(MAKEWORD(2, 2), &data); } @@ -165,10 +165,10 @@ void NetSocketPosix::make_default() { void NetSocketPosix::cleanup() { #if defined(WINDOWS_ENABLED) - if (_create != NULL) { + if (_create != nullptr) { WSACleanup(); } - _create = NULL; + _create = nullptr; #endif } @@ -446,15 +446,15 @@ Error NetSocketPosix::poll(PollType p_type, int p_timeout) const { #if defined(WINDOWS_ENABLED) bool ready = false; fd_set rd, wr, ex; - fd_set *rdp = NULL; - fd_set *wrp = NULL; + fd_set *rdp = nullptr; + fd_set *wrp = nullptr; FD_ZERO(&rd); FD_ZERO(&wr); FD_ZERO(&ex); FD_SET(_sock, &ex); struct timeval timeout = { p_timeout, 0 }; - // For blocking operation, pass NULL timeout pointer to select. - struct timeval *tp = NULL; + // For blocking operation, pass nullptr timeout pointer to select. + struct timeval *tp = nullptr; if (p_timeout >= 0) { // If timeout is non-negative, we want to specify the timeout instead. tp = &timeout; diff --git a/drivers/unix/os_unix.cpp b/drivers/unix/os_unix.cpp index 458488f3e9..53c60951b7 100644 --- a/drivers/unix/os_unix.cpp +++ b/drivers/unix/os_unix.cpp @@ -41,7 +41,7 @@ #include "drivers/unix/net_socket_posix.h" #include "drivers/unix/rw_lock_posix.h" #include "drivers/unix/thread_posix.h" -#include "servers/visual_server.h" +#include "servers/rendering_server.h" #ifdef __APPLE__ #include <mach-o/dyld.h> @@ -109,7 +109,7 @@ void OS_Unix::initialize_debugging() { struct sigaction action; memset(&action, 0, sizeof(action)); action.sa_handler = handle_interrupt; - sigaction(SIGINT, &action, NULL); + sigaction(SIGINT, &action, nullptr); } } @@ -172,24 +172,24 @@ String OS_Unix::get_name() const { uint64_t OS_Unix::get_unix_time() const { - return time(NULL); + return time(nullptr); }; uint64_t OS_Unix::get_system_time_secs() const { struct timeval tv_now; - gettimeofday(&tv_now, NULL); + gettimeofday(&tv_now, nullptr); return uint64_t(tv_now.tv_sec); } uint64_t OS_Unix::get_system_time_msecs() const { struct timeval tv_now; - gettimeofday(&tv_now, NULL); + gettimeofday(&tv_now, nullptr); return uint64_t(tv_now.tv_sec) * 1000 + uint64_t(tv_now.tv_usec) / 1000; } OS::Date OS_Unix::get_date(bool utc) const { - time_t t = time(NULL); + time_t t = time(nullptr); struct tm *lt; if (utc) lt = gmtime(&t); @@ -209,7 +209,7 @@ OS::Date OS_Unix::get_date(bool utc) const { } OS::Time OS_Unix::get_time(bool utc) const { - time_t t = time(NULL); + time_t t = time(nullptr); struct tm *lt; if (utc) lt = gmtime(&t); @@ -224,7 +224,7 @@ OS::Time OS_Unix::get_time(bool utc) const { } OS::TimeZoneInfo OS_Unix::get_time_zone_info() const { - time_t t = time(NULL); + time_t t = time(nullptr); struct tm *lt = localtime(&t); char name[16]; strftime(name, 16, "%Z", lt); @@ -379,7 +379,7 @@ int OS_Unix::get_process_id() const { bool OS_Unix::has_environment(const String &p_var) const { - return getenv(p_var.utf8().get_data()) != NULL; + return getenv(p_var.utf8().get_data()) != nullptr; } String OS_Unix::get_locale() const { @@ -433,7 +433,7 @@ Error OS_Unix::get_dynamic_library_symbol_handle(void *p_library_handle, const S p_symbol_handle = dlsym(p_library_handle, p_name.utf8().get_data()); error = dlerror(); - if (error != NULL) { + if (error != nullptr) { ERR_FAIL_COND_V_MSG(!p_optional, ERR_CANT_RESOLVE, "Can't resolve symbol " + p_name + ". Error: " + error + "."); return ERR_CANT_RESOLVE; @@ -511,7 +511,7 @@ String OS_Unix::get_executable_path() const { int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 }; char buf[MAXPATHLEN]; size_t len = sizeof(buf); - if (sysctl(mib, 4, buf, &len, NULL, 0) != 0) { + if (sysctl(mib, 4, buf, &len, nullptr, 0) != 0) { WARN_PRINT("Couldn't get executable path from sysctl"); return OS::get_executable_path(); } diff --git a/drivers/unix/os_unix.h b/drivers/unix/os_unix.h index c381890834..90679ddf1d 100644 --- a/drivers/unix/os_unix.h +++ b/drivers/unix/os_unix.h @@ -85,7 +85,7 @@ public: virtual void delay_usec(uint32_t p_usec) const; virtual uint64_t get_ticks_usec() const; - virtual Error execute(const String &p_path, const List<String> &p_arguments, bool p_blocking = true, ProcessID *r_child_id = NULL, String *r_pipe = NULL, int *r_exitcode = NULL, bool read_stderr = false, Mutex *p_pipe_mutex = NULL); + virtual Error execute(const String &p_path, const List<String> &p_arguments, bool p_blocking = true, ProcessID *r_child_id = nullptr, String *r_pipe = nullptr, int *r_exitcode = nullptr, bool read_stderr = false, Mutex *p_pipe_mutex = nullptr); virtual Error kill(const ProcessID &p_pid); virtual int get_process_id() const; diff --git a/drivers/unix/rw_lock_posix.cpp b/drivers/unix/rw_lock_posix.cpp index bb3eebd267..f219a0905c 100644 --- a/drivers/unix/rw_lock_posix.cpp +++ b/drivers/unix/rw_lock_posix.cpp @@ -91,7 +91,7 @@ void RWLockPosix::make_default() { RWLockPosix::RWLockPosix() { //rwlock=PTHREAD_RWLOCK_INITIALIZER; fails on OSX - pthread_rwlock_init(&rwlock, NULL); + pthread_rwlock_init(&rwlock, nullptr); } RWLockPosix::~RWLockPosix() { diff --git a/drivers/unix/thread_posix.cpp b/drivers/unix/thread_posix.cpp index 21f49a7e38..c227aec6d6 100644 --- a/drivers/unix/thread_posix.cpp +++ b/drivers/unix/thread_posix.cpp @@ -75,7 +75,7 @@ void *ThreadPosix::thread_callback(void *userdata) { ScriptServer::thread_exit(); - return NULL; + return nullptr; } Thread *ThreadPosix::create_func_posix(ThreadCreateCallback p_callback, void *p_user, const Settings &) { @@ -108,7 +108,7 @@ void ThreadPosix::wait_to_finish_func_posix(Thread *p_thread) { ERR_FAIL_COND(!tp); ERR_FAIL_COND(tp->pthread == 0); - pthread_join(tp->pthread, NULL); + pthread_join(tp->pthread, nullptr); tp->pthread = 0; } diff --git a/drivers/vulkan/SCsub b/drivers/vulkan/SCsub index 85a5ae8d26..91d0e42f80 100644 --- a/drivers/vulkan/SCsub +++ b/drivers/vulkan/SCsub @@ -1,10 +1,28 @@ #!/usr/bin/env python -Import('env') +Import("env") env.add_source_files(env.drivers_sources, "*.cpp") -if env['builtin_vulkan']: +if env["platform"] == "android": + # Use NDK Vulkan headers + thirdparty_dir = env["ANDROID_NDK_ROOT"] + "/sources/third_party/vulkan/src" + thirdparty_includes = [ + thirdparty_dir, + thirdparty_dir + "/include", + thirdparty_dir + "/layers", + thirdparty_dir + "/layers/generated", + ] + env.Prepend(CPPPATH=thirdparty_includes) + + # Build Vulkan memory allocator + env_thirdparty = env.Clone() + env_thirdparty.disable_warnings() + + thirdparty_dir = "#thirdparty/vulkan" + vma_sources = [thirdparty_dir + "/android/vk_mem_alloc.cpp"] + env_thirdparty.add_source_files(env.drivers_sources, vma_sources) +elif env["builtin_vulkan"]: # Use bundled Vulkan headers thirdparty_dir = "#thirdparty/vulkan" env.Prepend(CPPPATH=[thirdparty_dir, thirdparty_dir + "/include", thirdparty_dir + "/loader"]) @@ -27,48 +45,56 @@ if env['builtin_vulkan']: ] vma_sources = [thirdparty_dir + "/vk_mem_alloc.cpp"] - if env['platform'] == "windows": + 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'] == "iphone": - env_thirdparty.AppendUnique(CPPDEFINES=[ - 'VK_USE_PLATFORM_IOS_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' - ]) + 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"] == "iphone": + env_thirdparty.AppendUnique( + CPPDEFINES=[ + "VK_USE_PLATFORM_IOS_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"] == "linuxbsd": + 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", + ] + ) import platform - if (platform.system() == "Linux"): + + if platform.system() == "Linux": # In glibc since 2.17 and musl libc since 1.1.24. Used by loader.c. - env_thirdparty.AppendUnique(CPPDEFINES=['HAVE_SECURE_GETENV']) + env_thirdparty.AppendUnique(CPPDEFINES=["HAVE_SECURE_GETENV"]) loader_sources = [thirdparty_dir + "/loader/" + file for file in loader_sources] env_thirdparty.add_source_files(env.drivers_sources, loader_sources) diff --git a/drivers/vulkan/rendering_device_vulkan.cpp b/drivers/vulkan/rendering_device_vulkan.cpp index 76541c3cd5..23e9227a39 100644 --- a/drivers/vulkan/rendering_device_vulkan.cpp +++ b/drivers/vulkan/rendering_device_vulkan.cpp @@ -29,6 +29,7 @@ /*************************************************************************/ #include "rendering_device_vulkan.h" + #include "core/hashfuncs.h" #include "core/os/file_access.h" #include "core/os/os.h" @@ -1234,13 +1235,13 @@ const VkImageType RenderingDeviceVulkan::vulkan_image_type[RenderingDevice::TEXT Error RenderingDeviceVulkan::_buffer_allocate(Buffer *p_buffer, uint32_t p_size, uint32_t p_usage, VmaMemoryUsage p_mapping) { VkBufferCreateInfo bufferInfo; bufferInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; - bufferInfo.pNext = NULL; + bufferInfo.pNext = nullptr; bufferInfo.flags = 0; bufferInfo.size = p_size; bufferInfo.usage = p_usage; bufferInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE; bufferInfo.queueFamilyIndexCount = 0; - bufferInfo.pQueueFamilyIndices = 0; + bufferInfo.pQueueFamilyIndices = nullptr; VmaAllocationCreateInfo allocInfo; allocInfo.flags = 0; @@ -1248,10 +1249,10 @@ Error RenderingDeviceVulkan::_buffer_allocate(Buffer *p_buffer, uint32_t p_size, allocInfo.requiredFlags = 0; allocInfo.preferredFlags = 0; allocInfo.memoryTypeBits = 0; - allocInfo.pool = NULL; - allocInfo.pUserData = NULL; + allocInfo.pool = nullptr; + allocInfo.pUserData = nullptr; - VkResult err = vmaCreateBuffer(allocator, &bufferInfo, &allocInfo, &p_buffer->buffer, &p_buffer->allocation, NULL); + VkResult err = vmaCreateBuffer(allocator, &bufferInfo, &allocInfo, &p_buffer->buffer, &p_buffer->allocation, nullptr); ERR_FAIL_COND_V_MSG(err, ERR_CANT_CREATE, "Can't create buffer of size: " + itos(p_size) + ", error " + itos(err) + "."); p_buffer->size = p_size; p_buffer->buffer_info.buffer = p_buffer->buffer; @@ -1265,8 +1266,8 @@ Error RenderingDeviceVulkan::_buffer_free(Buffer *p_buffer) { ERR_FAIL_COND_V(p_buffer->size == 0, ERR_INVALID_PARAMETER); vmaDestroyBuffer(allocator, p_buffer->buffer, p_buffer->allocation); - p_buffer->buffer = NULL; - p_buffer->allocation = NULL; + p_buffer->buffer = VK_NULL_HANDLE; + p_buffer->allocation = nullptr; p_buffer->size = 0; return OK; @@ -1276,13 +1277,13 @@ Error RenderingDeviceVulkan::_insert_staging_block() { VkBufferCreateInfo bufferInfo; bufferInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; - bufferInfo.pNext = NULL; + bufferInfo.pNext = nullptr; bufferInfo.flags = 0; bufferInfo.size = staging_buffer_block_size; bufferInfo.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT; bufferInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE; bufferInfo.queueFamilyIndexCount = 0; - bufferInfo.pQueueFamilyIndices = 0; + bufferInfo.pQueueFamilyIndices = nullptr; VmaAllocationCreateInfo allocInfo; allocInfo.flags = 0; @@ -1290,12 +1291,12 @@ Error RenderingDeviceVulkan::_insert_staging_block() { allocInfo.requiredFlags = 0; allocInfo.preferredFlags = 0; allocInfo.memoryTypeBits = 0; - allocInfo.pool = NULL; - allocInfo.pUserData = NULL; + allocInfo.pool = nullptr; + allocInfo.pUserData = nullptr; StagingBufferBlock block; - VkResult err = vmaCreateBuffer(allocator, &bufferInfo, &allocInfo, &block.buffer, &block.allocation, NULL); + VkResult err = vmaCreateBuffer(allocator, &bufferInfo, &allocInfo, &block.buffer, &block.allocation, nullptr); ERR_FAIL_COND_V_MSG(err, ERR_CANT_CREATE, "vmaCreateBuffer failed with error " + itos(err) + "."); block.frame_used = 0; @@ -1459,7 +1460,7 @@ Error RenderingDeviceVulkan::_buffer_update(Buffer *p_buffer, size_t p_offset, c //map staging buffer (It's CPU and coherent) - void *data_ptr = NULL; + void *data_ptr = nullptr; { VkResult vkerr = vmaMapMemory(allocator, staging_buffer_blocks[staging_buffer_current].allocation, &data_ptr); ERR_FAIL_COND_V_MSG(vkerr, ERR_CANT_CREATE, "vmaMapMemory failed with error " + itos(vkerr) + "."); @@ -1492,11 +1493,11 @@ void RenderingDeviceVulkan::_memory_barrier(VkPipelineStageFlags p_src_stage_mas VkMemoryBarrier mem_barrier; mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER; - mem_barrier.pNext = NULL; + mem_barrier.pNext = nullptr; mem_barrier.srcAccessMask = p_src_access; mem_barrier.dstAccessMask = p_dst_sccess; - vkCmdPipelineBarrier(p_sync_with_draw ? frames[frame].draw_command_buffer : frames[frame].setup_command_buffer, p_src_stage_mask, p_dst_stage_mask, 0, 1, &mem_barrier, 0, NULL, 0, NULL); + vkCmdPipelineBarrier(p_sync_with_draw ? frames[frame].draw_command_buffer : frames[frame].setup_command_buffer, p_src_stage_mask, p_dst_stage_mask, 0, 1, &mem_barrier, 0, nullptr, 0, nullptr); } void RenderingDeviceVulkan::_full_barrier(bool p_sync_with_draw) { @@ -1539,7 +1540,7 @@ void RenderingDeviceVulkan::_buffer_memory_barrier(VkBuffer buffer, uint64_t p_f VkBufferMemoryBarrier buffer_mem_barrier; buffer_mem_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER; - buffer_mem_barrier.pNext = NULL; + buffer_mem_barrier.pNext = nullptr; buffer_mem_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; buffer_mem_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; buffer_mem_barrier.srcAccessMask = p_src_access; @@ -1548,7 +1549,7 @@ void RenderingDeviceVulkan::_buffer_memory_barrier(VkBuffer buffer, uint64_t p_f buffer_mem_barrier.offset = p_from; buffer_mem_barrier.size = p_size; - vkCmdPipelineBarrier(p_sync_with_draw ? frames[frame].draw_command_buffer : frames[frame].setup_command_buffer, p_src_stage_mask, p_dst_stage_mask, 0, 0, NULL, 1, &buffer_mem_barrier, 0, NULL); + vkCmdPipelineBarrier(p_sync_with_draw ? frames[frame].draw_command_buffer : frames[frame].setup_command_buffer, p_src_stage_mask, p_dst_stage_mask, 0, 0, nullptr, 1, &buffer_mem_barrier, 0, nullptr); } /*****************/ @@ -1561,20 +1562,30 @@ RID RenderingDeviceVulkan::texture_create(const TextureFormat &p_format, const T VkImageCreateInfo image_create_info; image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; - image_create_info.pNext = NULL; + image_create_info.pNext = nullptr; image_create_info.flags = 0; - VkImageFormatListCreateInfoKHR format_list_create_info; - Vector<VkFormat> allowed_formats; +#ifndef _MSC_VER +#warning TODO check for support via RenderingDevice to enable on mobile when possible +#endif + +#ifndef ANDROID_ENABLED + // vkCreateImage fails with format list on Android (VK_ERROR_OUT_OF_HOST_MEMORY) + VkImageFormatListCreateInfoKHR format_list_create_info; //keep out of the if, needed for creation + Vector<VkFormat> allowed_formats; //keep out of the if, needed for creation +#endif if (p_format.shareable_formats.size()) { image_create_info.flags |= VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT; + +#ifndef ANDROID_ENABLED + for (int i = 0; i < p_format.shareable_formats.size(); i++) { allowed_formats.push_back(vulkan_formats[p_format.shareable_formats[i]]); } format_list_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_FORMAT_LIST_CREATE_INFO_KHR; - format_list_create_info.pNext = NULL; + format_list_create_info.pNext = nullptr; format_list_create_info.viewFormatCount = allowed_formats.size(); format_list_create_info.pViewFormats = allowed_formats.ptr(); image_create_info.pNext = &format_list_create_info; @@ -1583,7 +1594,9 @@ RID RenderingDeviceVulkan::texture_create(const TextureFormat &p_format, const T "If supplied a list of shareable formats, the current format must be present in the list"); ERR_FAIL_COND_V_MSG(p_view.format_override != DATA_FORMAT_MAX && p_format.shareable_formats.find(p_view.format_override) == -1, RID(), "If supplied a list of shareable formats, the current view format override must be present in the list"); +#endif } + if (p_format.type == TEXTURE_TYPE_CUBE || p_format.type == TEXTURE_TYPE_CUBE_ARRAY) { image_create_info.flags |= VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT; } @@ -1665,7 +1678,7 @@ RID RenderingDeviceVulkan::texture_create(const TextureFormat &p_format, const T image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; image_create_info.queueFamilyIndexCount = 0; - image_create_info.pQueueFamilyIndices = NULL; + image_create_info.pQueueFamilyIndices = nullptr; image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; uint32_t required_mipmaps = get_image_required_mipmaps(image_create_info.extent.width, image_create_info.extent.height, image_create_info.extent.depth); @@ -1744,8 +1757,8 @@ RID RenderingDeviceVulkan::texture_create(const TextureFormat &p_format, const T allocInfo.requiredFlags = 0; allocInfo.preferredFlags = 0; allocInfo.memoryTypeBits = 0; - allocInfo.pool = NULL; - allocInfo.pUserData = NULL; + allocInfo.pool = nullptr; + allocInfo.pUserData = nullptr; Texture texture; @@ -1759,6 +1772,8 @@ RID RenderingDeviceVulkan::texture_create(const TextureFormat &p_format, const T texture.depth = image_create_info.extent.depth; texture.layers = image_create_info.arrayLayers; texture.mipmaps = image_create_info.mipLevels; + texture.base_mipmap = 0; + texture.base_layer = 0; texture.usage_flags = p_format.usage_bits; texture.samples = p_format.samples; texture.allowed_shared_formats = p_format.shareable_formats; @@ -1806,7 +1821,7 @@ RID RenderingDeviceVulkan::texture_create(const TextureFormat &p_format, const T VkImageViewCreateInfo image_view_create_info; image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; - image_view_create_info.pNext = NULL; + image_view_create_info.pNext = nullptr; image_view_create_info.flags = 0; image_view_create_info.image = texture.image; @@ -1852,7 +1867,7 @@ RID RenderingDeviceVulkan::texture_create(const TextureFormat &p_format, const T image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; } - err = vkCreateImageView(device, &image_view_create_info, NULL, &texture.view); + err = vkCreateImageView(device, &image_view_create_info, nullptr, &texture.view); if (err) { vmaDestroyImage(allocator, texture.image, texture.allocation); @@ -1863,7 +1878,7 @@ RID RenderingDeviceVulkan::texture_create(const TextureFormat &p_format, const T { VkImageMemoryBarrier image_memory_barrier; image_memory_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; - image_memory_barrier.pNext = NULL; + image_memory_barrier.pNext = nullptr; image_memory_barrier.srcAccessMask = 0; image_memory_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; image_memory_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED; @@ -1877,7 +1892,7 @@ RID RenderingDeviceVulkan::texture_create(const TextureFormat &p_format, const T image_memory_barrier.subresourceRange.baseArrayLayer = 0; image_memory_barrier.subresourceRange.layerCount = image_create_info.arrayLayers; - vkCmdPipelineBarrier(frames[frame].setup_command_buffer, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, 0, 0, NULL, 0, NULL, 1, &image_memory_barrier); + vkCmdPipelineBarrier(frames[frame].setup_command_buffer, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &image_memory_barrier); } RID id = texture_owner.make_rid(texture); @@ -1910,7 +1925,7 @@ RID RenderingDeviceVulkan::texture_create_shared(const TextureView &p_view, RID VkImageViewCreateInfo image_view_create_info; image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; - image_view_create_info.pNext = NULL; + image_view_create_info.pNext = nullptr; image_view_create_info.flags = 0; image_view_create_info.image = texture.image; @@ -1961,7 +1976,7 @@ RID RenderingDeviceVulkan::texture_create_shared(const TextureView &p_view, RID image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; } - VkResult err = vkCreateImageView(device, &image_view_create_info, NULL, &texture.view); + VkResult err = vkCreateImageView(device, &image_view_create_info, nullptr, &texture.view); ERR_FAIL_COND_V_MSG(err, RID(), "vkCreateImageView failed with error " + itos(err) + "."); texture.owner = p_with_texture; @@ -1999,10 +2014,12 @@ RID RenderingDeviceVulkan::texture_create_shared_from_slice(const TextureView &p get_image_format_required_size(texture.format, texture.width, texture.height, texture.depth, p_mipmap + 1, &texture.width, &texture.height); texture.mipmaps = 1; texture.layers = p_slice_type == TEXTURE_SLICE_CUBEMAP ? 6 : 1; + texture.base_mipmap = p_mipmap; + texture.base_layer = p_layer; VkImageViewCreateInfo image_view_create_info; image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; - image_view_create_info.pNext = NULL; + image_view_create_info.pNext = nullptr; image_view_create_info.flags = 0; image_view_create_info.image = texture.image; @@ -2059,7 +2076,7 @@ RID RenderingDeviceVulkan::texture_create_shared_from_slice(const TextureView &p image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; } - VkResult err = vkCreateImageView(device, &image_view_create_info, NULL, &texture.view); + VkResult err = vkCreateImageView(device, &image_view_create_info, nullptr, &texture.view); ERR_FAIL_COND_V_MSG(err, RID(), "vkCreateImageView failed with error " + itos(err) + "."); texture.owner = p_with_texture; @@ -2121,7 +2138,7 @@ Error RenderingDeviceVulkan::texture_update(RID p_texture, uint32_t p_layer, con { VkImageMemoryBarrier image_memory_barrier; image_memory_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; - image_memory_barrier.pNext = NULL; + image_memory_barrier.pNext = nullptr; image_memory_barrier.srcAccessMask = 0; image_memory_barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT; image_memory_barrier.oldLayout = texture->layout; @@ -2136,7 +2153,7 @@ Error RenderingDeviceVulkan::texture_update(RID p_texture, uint32_t p_layer, con image_memory_barrier.subresourceRange.baseArrayLayer = p_layer; image_memory_barrier.subresourceRange.layerCount = 1; - vkCmdPipelineBarrier(command_buffer, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, NULL, 0, NULL, 1, &image_memory_barrier); + vkCmdPipelineBarrier(command_buffer, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, nullptr, 0, nullptr, 1, &image_memory_barrier); } uint32_t mipmap_offset = 0; @@ -2169,7 +2186,7 @@ Error RenderingDeviceVulkan::texture_update(RID p_texture, uint32_t p_layer, con uint8_t *write_ptr; { //map - void *data_ptr = NULL; + void *data_ptr = nullptr; VkResult vkerr = vmaMapMemory(allocator, staging_buffer_blocks[staging_buffer_current].allocation, &data_ptr); ERR_FAIL_COND_V_MSG(vkerr, ERR_CANT_CREATE, "vmaMapMemory failed with error " + itos(vkerr) + "."); write_ptr = (uint8_t *)data_ptr; @@ -2258,7 +2275,7 @@ Error RenderingDeviceVulkan::texture_update(RID p_texture, uint32_t p_layer, con { VkImageMemoryBarrier image_memory_barrier; image_memory_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; - image_memory_barrier.pNext = NULL; + image_memory_barrier.pNext = nullptr; image_memory_barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT; image_memory_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; image_memory_barrier.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL; @@ -2272,7 +2289,7 @@ Error RenderingDeviceVulkan::texture_update(RID p_texture, uint32_t p_layer, con image_memory_barrier.subresourceRange.baseArrayLayer = p_layer; image_memory_barrier.subresourceRange.layerCount = 1; - vkCmdPipelineBarrier(command_buffer, VK_ACCESS_TRANSFER_WRITE_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, 0, 0, NULL, 0, NULL, 1, &image_memory_barrier); + vkCmdPipelineBarrier(command_buffer, VK_ACCESS_TRANSFER_WRITE_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &image_memory_barrier); } return OK; @@ -2380,7 +2397,7 @@ Vector<uint8_t> RenderingDeviceVulkan::texture_get_data(RID p_texture, uint32_t { //Source image barrier VkImageMemoryBarrier image_memory_barrier; image_memory_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; - image_memory_barrier.pNext = NULL; + image_memory_barrier.pNext = nullptr; image_memory_barrier.srcAccessMask = 0; image_memory_barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT; image_memory_barrier.oldLayout = tex->layout; @@ -2395,7 +2412,7 @@ Vector<uint8_t> RenderingDeviceVulkan::texture_get_data(RID p_texture, uint32_t image_memory_barrier.subresourceRange.baseArrayLayer = p_layer; image_memory_barrier.subresourceRange.layerCount = 1; - vkCmdPipelineBarrier(command_buffer, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, NULL, 0, NULL, 1, &image_memory_barrier); + vkCmdPipelineBarrier(command_buffer, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, nullptr, 0, nullptr, 1, &image_memory_barrier); } uint32_t computed_w = tex->width; @@ -2437,7 +2454,7 @@ Vector<uint8_t> RenderingDeviceVulkan::texture_get_data(RID p_texture, uint32_t { //restore src VkImageMemoryBarrier image_memory_barrier; image_memory_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; - image_memory_barrier.pNext = NULL; + image_memory_barrier.pNext = nullptr; image_memory_barrier.srcAccessMask = VK_ACCESS_TRANSFER_READ_BIT; image_memory_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; image_memory_barrier.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; @@ -2451,7 +2468,7 @@ Vector<uint8_t> RenderingDeviceVulkan::texture_get_data(RID p_texture, uint32_t image_memory_barrier.subresourceRange.baseArrayLayer = p_layer; image_memory_barrier.subresourceRange.layerCount = 1; - vkCmdPipelineBarrier(command_buffer, VK_ACCESS_TRANSFER_WRITE_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, 0, 0, NULL, 0, NULL, 1, &image_memory_barrier); + vkCmdPipelineBarrier(command_buffer, VK_ACCESS_TRANSFER_WRITE_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &image_memory_barrier); } _flush(true); @@ -2546,7 +2563,7 @@ Error RenderingDeviceVulkan::texture_copy(RID p_from_texture, RID p_to_texture, { //Source VkImageMemoryBarrier image_memory_barrier; image_memory_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; - image_memory_barrier.pNext = NULL; + image_memory_barrier.pNext = nullptr; image_memory_barrier.srcAccessMask = 0; image_memory_barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT; image_memory_barrier.oldLayout = src_tex->layout; @@ -2561,12 +2578,12 @@ Error RenderingDeviceVulkan::texture_copy(RID p_from_texture, RID p_to_texture, image_memory_barrier.subresourceRange.baseArrayLayer = p_src_layer; image_memory_barrier.subresourceRange.layerCount = 1; - vkCmdPipelineBarrier(command_buffer, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, NULL, 0, NULL, 1, &image_memory_barrier); + vkCmdPipelineBarrier(command_buffer, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, nullptr, 0, nullptr, 1, &image_memory_barrier); } { //Dest VkImageMemoryBarrier image_memory_barrier; image_memory_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; - image_memory_barrier.pNext = NULL; + image_memory_barrier.pNext = nullptr; image_memory_barrier.srcAccessMask = 0; image_memory_barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT; image_memory_barrier.oldLayout = dst_tex->layout; @@ -2581,7 +2598,7 @@ Error RenderingDeviceVulkan::texture_copy(RID p_from_texture, RID p_to_texture, image_memory_barrier.subresourceRange.baseArrayLayer = p_dst_layer; image_memory_barrier.subresourceRange.layerCount = 1; - vkCmdPipelineBarrier(command_buffer, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, NULL, 0, NULL, 1, &image_memory_barrier); + vkCmdPipelineBarrier(command_buffer, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, nullptr, 0, nullptr, 1, &image_memory_barrier); } //COPY @@ -2617,7 +2634,7 @@ Error RenderingDeviceVulkan::texture_copy(RID p_from_texture, RID p_to_texture, { //restore src VkImageMemoryBarrier image_memory_barrier; image_memory_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; - image_memory_barrier.pNext = NULL; + image_memory_barrier.pNext = nullptr; image_memory_barrier.srcAccessMask = VK_ACCESS_TRANSFER_READ_BIT; image_memory_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT; image_memory_barrier.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; @@ -2631,14 +2648,14 @@ Error RenderingDeviceVulkan::texture_copy(RID p_from_texture, RID p_to_texture, image_memory_barrier.subresourceRange.baseArrayLayer = p_src_layer; image_memory_barrier.subresourceRange.layerCount = 1; - vkCmdPipelineBarrier(command_buffer, VK_ACCESS_TRANSFER_WRITE_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, 0, 0, NULL, 0, NULL, 1, &image_memory_barrier); + vkCmdPipelineBarrier(command_buffer, VK_ACCESS_TRANSFER_WRITE_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &image_memory_barrier); } { //make dst readable VkImageMemoryBarrier image_memory_barrier; image_memory_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; - image_memory_barrier.pNext = NULL; + image_memory_barrier.pNext = nullptr; image_memory_barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT; image_memory_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT; image_memory_barrier.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL; @@ -2653,7 +2670,160 @@ Error RenderingDeviceVulkan::texture_copy(RID p_from_texture, RID p_to_texture, image_memory_barrier.subresourceRange.baseArrayLayer = p_src_layer; image_memory_barrier.subresourceRange.layerCount = 1; - vkCmdPipelineBarrier(command_buffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, 0, 0, NULL, 0, NULL, 1, &image_memory_barrier); + vkCmdPipelineBarrier(command_buffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &image_memory_barrier); + } + } + + return OK; +} +Error RenderingDeviceVulkan::texture_resolve_multisample(RID p_from_texture, RID p_to_texture, bool p_sync_with_draw) { + _THREAD_SAFE_METHOD_ + + Texture *src_tex = texture_owner.getornull(p_from_texture); + ERR_FAIL_COND_V(!src_tex, ERR_INVALID_PARAMETER); + + ERR_FAIL_COND_V_MSG(p_sync_with_draw && src_tex->bound, ERR_INVALID_PARAMETER, + "Source texture can't be copied while a render pass that uses it is being created. Ensure render pass is finalized (and that it was created with RENDER_PASS_CONTENTS_FINISH) to unbind this texture."); + ERR_FAIL_COND_V_MSG(!(src_tex->usage_flags & TEXTURE_USAGE_CAN_COPY_FROM_BIT), ERR_INVALID_PARAMETER, + "Source texture requires the TEXTURE_USAGE_CAN_COPY_FROM_BIT in order to be retrieved."); + + ERR_FAIL_COND_V_MSG(src_tex->type != TEXTURE_TYPE_2D, ERR_INVALID_PARAMETER, "Source texture must be 2D (or a slice of a 3D/Cube texture)"); + ERR_FAIL_COND_V_MSG(src_tex->samples == TEXTURE_SAMPLES_1, ERR_INVALID_PARAMETER, "Source texture must be multisampled."); + + Texture *dst_tex = texture_owner.getornull(p_to_texture); + ERR_FAIL_COND_V(!dst_tex, ERR_INVALID_PARAMETER); + + ERR_FAIL_COND_V_MSG(p_sync_with_draw && dst_tex->bound, ERR_INVALID_PARAMETER, + "Destination texture can't be copied while a render pass that uses it is being created. Ensure render pass is finalized (and that it was created with RENDER_PASS_CONTENTS_FINISH) to unbind this texture."); + ERR_FAIL_COND_V_MSG(!(dst_tex->usage_flags & TEXTURE_USAGE_CAN_COPY_TO_BIT), ERR_INVALID_PARAMETER, + "Destination texture requires the TEXTURE_USAGE_CAN_COPY_TO_BIT in order to be retrieved."); + + ERR_FAIL_COND_V_MSG(dst_tex->type != TEXTURE_TYPE_2D, ERR_INVALID_PARAMETER, "Destination texture must be 2D (or a slice of a 3D/Cube texture)."); + ERR_FAIL_COND_V_MSG(dst_tex->samples != TEXTURE_SAMPLES_1, ERR_INVALID_PARAMETER, "Destination texture must not be multisampled."); + + ERR_FAIL_COND_V_MSG(src_tex->format != dst_tex->format, ERR_INVALID_PARAMETER, "Source and Destionation textures must be the same format."); + ERR_FAIL_COND_V_MSG(src_tex->width != dst_tex->width && src_tex->height != dst_tex->height && src_tex->depth != dst_tex->depth, ERR_INVALID_PARAMETER, "Source and Destionation textures must have the same dimensions."); + + ERR_FAIL_COND_V_MSG(src_tex->read_aspect_mask != dst_tex->read_aspect_mask, ERR_INVALID_PARAMETER, + "Source and destination texture must be of the same type (color or depth)."); + + VkCommandBuffer command_buffer = p_sync_with_draw ? frames[frame].draw_command_buffer : frames[frame].setup_command_buffer; + + { + + //PRE Copy the image + + { //Source + VkImageMemoryBarrier image_memory_barrier; + image_memory_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; + image_memory_barrier.pNext = nullptr; + image_memory_barrier.srcAccessMask = 0; + image_memory_barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT; + image_memory_barrier.oldLayout = src_tex->layout; + image_memory_barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; + + image_memory_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; + image_memory_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; + image_memory_barrier.image = src_tex->image; + image_memory_barrier.subresourceRange.aspectMask = src_tex->barrier_aspect_mask; + image_memory_barrier.subresourceRange.baseMipLevel = src_tex->base_mipmap; + image_memory_barrier.subresourceRange.levelCount = 1; + image_memory_barrier.subresourceRange.baseArrayLayer = src_tex->base_layer; + image_memory_barrier.subresourceRange.layerCount = 1; + + vkCmdPipelineBarrier(command_buffer, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, nullptr, 0, nullptr, 1, &image_memory_barrier); + } + { //Dest + VkImageMemoryBarrier image_memory_barrier; + image_memory_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; + image_memory_barrier.pNext = nullptr; + image_memory_barrier.srcAccessMask = 0; + image_memory_barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT; + image_memory_barrier.oldLayout = dst_tex->layout; + image_memory_barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL; + + image_memory_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; + image_memory_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; + image_memory_barrier.image = dst_tex->image; + image_memory_barrier.subresourceRange.aspectMask = dst_tex->read_aspect_mask; + image_memory_barrier.subresourceRange.baseMipLevel = dst_tex->base_mipmap; + image_memory_barrier.subresourceRange.levelCount = 1; + image_memory_barrier.subresourceRange.baseArrayLayer = dst_tex->base_layer; + image_memory_barrier.subresourceRange.layerCount = 1; + + vkCmdPipelineBarrier(command_buffer, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, nullptr, 0, nullptr, 1, &image_memory_barrier); + } + + //COPY + + { + + VkImageResolve image_copy_region; + image_copy_region.srcSubresource.aspectMask = src_tex->read_aspect_mask; + image_copy_region.srcSubresource.baseArrayLayer = src_tex->base_layer; + image_copy_region.srcSubresource.layerCount = 1; + image_copy_region.srcSubresource.mipLevel = src_tex->base_mipmap; + image_copy_region.srcOffset.x = 0; + image_copy_region.srcOffset.y = 0; + image_copy_region.srcOffset.z = 0; + + image_copy_region.dstSubresource.aspectMask = dst_tex->read_aspect_mask; + image_copy_region.dstSubresource.baseArrayLayer = dst_tex->base_layer; + image_copy_region.dstSubresource.layerCount = 1; + image_copy_region.dstSubresource.mipLevel = dst_tex->base_mipmap; + image_copy_region.dstOffset.x = 0; + image_copy_region.dstOffset.y = 0; + image_copy_region.dstOffset.z = 0; + + image_copy_region.extent.width = src_tex->width; + image_copy_region.extent.height = src_tex->height; + image_copy_region.extent.depth = src_tex->depth; + + vkCmdResolveImage(command_buffer, src_tex->image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, dst_tex->image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &image_copy_region); + } + + // RESTORE LAYOUT for SRC and DST + + { //restore src + VkImageMemoryBarrier image_memory_barrier; + image_memory_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; + image_memory_barrier.pNext = nullptr; + image_memory_barrier.srcAccessMask = VK_ACCESS_TRANSFER_READ_BIT; + image_memory_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT; + image_memory_barrier.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; + image_memory_barrier.newLayout = src_tex->layout; + image_memory_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; + image_memory_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; + image_memory_barrier.image = src_tex->image; + image_memory_barrier.subresourceRange.aspectMask = src_tex->barrier_aspect_mask; + image_memory_barrier.subresourceRange.baseMipLevel = src_tex->base_mipmap; + image_memory_barrier.subresourceRange.levelCount = 1; + image_memory_barrier.subresourceRange.baseArrayLayer = src_tex->base_layer; + image_memory_barrier.subresourceRange.layerCount = 1; + + vkCmdPipelineBarrier(command_buffer, VK_ACCESS_TRANSFER_WRITE_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &image_memory_barrier); + } + + { //make dst readable + + VkImageMemoryBarrier image_memory_barrier; + image_memory_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; + image_memory_barrier.pNext = nullptr; + image_memory_barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT; + image_memory_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT; + image_memory_barrier.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL; + image_memory_barrier.newLayout = dst_tex->layout; + + image_memory_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; + image_memory_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; + image_memory_barrier.image = dst_tex->image; + image_memory_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; + image_memory_barrier.subresourceRange.baseMipLevel = dst_tex->base_mipmap; + image_memory_barrier.subresourceRange.levelCount = 1; + image_memory_barrier.subresourceRange.baseArrayLayer = dst_tex->base_layer; + image_memory_barrier.subresourceRange.layerCount = 1; + + vkCmdPipelineBarrier(command_buffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &image_memory_barrier); } } @@ -2691,7 +2861,7 @@ Error RenderingDeviceVulkan::texture_clear(RID p_texture, const Color &p_color, if (src_tex->layout != VK_IMAGE_LAYOUT_GENERAL) { //storage may be in general state VkImageMemoryBarrier image_memory_barrier; image_memory_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; - image_memory_barrier.pNext = NULL; + image_memory_barrier.pNext = nullptr; image_memory_barrier.srcAccessMask = 0; image_memory_barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT; image_memory_barrier.oldLayout = src_tex->layout; @@ -2701,13 +2871,13 @@ Error RenderingDeviceVulkan::texture_clear(RID p_texture, const Color &p_color, image_memory_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; image_memory_barrier.image = src_tex->image; image_memory_barrier.subresourceRange.aspectMask = src_tex->read_aspect_mask; - image_memory_barrier.subresourceRange.baseMipLevel = p_base_mipmap; + image_memory_barrier.subresourceRange.baseMipLevel = src_tex->base_mipmap + p_base_mipmap; image_memory_barrier.subresourceRange.levelCount = p_mipmaps; - image_memory_barrier.subresourceRange.baseArrayLayer = p_base_layer; + image_memory_barrier.subresourceRange.baseArrayLayer = src_tex->base_layer + p_base_layer; image_memory_barrier.subresourceRange.layerCount = p_layers; layout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL; - vkCmdPipelineBarrier(command_buffer, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, NULL, 0, NULL, 1, &image_memory_barrier); + vkCmdPipelineBarrier(command_buffer, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, nullptr, 0, nullptr, 1, &image_memory_barrier); } VkClearColorValue clear_color; @@ -2718,9 +2888,9 @@ Error RenderingDeviceVulkan::texture_clear(RID p_texture, const Color &p_color, VkImageSubresourceRange range; range.aspectMask = src_tex->read_aspect_mask; - range.baseArrayLayer = p_base_layer; + range.baseArrayLayer = src_tex->base_layer + p_base_layer; range.layerCount = p_layers; - range.baseMipLevel = p_base_mipmap; + range.baseMipLevel = src_tex->base_mipmap + p_base_mipmap; range.levelCount = p_mipmaps; vkCmdClearColorImage(command_buffer, src_tex->image, layout, &clear_color, 1, &range); @@ -2729,7 +2899,7 @@ Error RenderingDeviceVulkan::texture_clear(RID p_texture, const Color &p_color, VkImageMemoryBarrier image_memory_barrier; image_memory_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; - image_memory_barrier.pNext = NULL; + image_memory_barrier.pNext = nullptr; image_memory_barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT; image_memory_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; image_memory_barrier.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL; @@ -2739,12 +2909,12 @@ Error RenderingDeviceVulkan::texture_clear(RID p_texture, const Color &p_color, image_memory_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; image_memory_barrier.image = src_tex->image; image_memory_barrier.subresourceRange.aspectMask = src_tex->read_aspect_mask; - image_memory_barrier.subresourceRange.baseMipLevel = p_base_mipmap; + image_memory_barrier.subresourceRange.baseMipLevel = src_tex->base_mipmap + p_base_mipmap; image_memory_barrier.subresourceRange.levelCount = p_mipmaps; - image_memory_barrier.subresourceRange.baseArrayLayer = p_base_layer; + image_memory_barrier.subresourceRange.baseArrayLayer = src_tex->base_layer + p_base_layer; image_memory_barrier.subresourceRange.layerCount = p_layers; - vkCmdPipelineBarrier(command_buffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, 0, 0, NULL, 0, NULL, 1, &image_memory_barrier); + vkCmdPipelineBarrier(command_buffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &image_memory_barrier); } return OK; @@ -2839,6 +3009,21 @@ VkRenderPass RenderingDeviceVulkan::_render_pass_create(const Vector<AttachmentF description.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; //don't care what is there } } break; + case INITIAL_ACTION_DROP: { + if (p_format[i].usage_flags & TEXTURE_USAGE_COLOR_ATTACHMENT_BIT) { + description.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; + description.initialLayout = is_sampled ? VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL : (is_storage ? VK_IMAGE_LAYOUT_GENERAL : VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL); + description.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; + } else if (p_format[i].usage_flags & TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) { + description.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; + description.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; //don't care what is there + description.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; + } else { + description.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; + description.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; + description.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; //don't care what is there + } + } break; case INITIAL_ACTION_CONTINUE: { if (p_format[i].usage_flags & TEXTURE_USAGE_COLOR_ATTACHMENT_BIT) { description.loadOp = VK_ATTACHMENT_LOAD_OP_LOAD; @@ -2944,27 +3129,27 @@ VkRenderPass RenderingDeviceVulkan::_render_pass_create(const Vector<AttachmentF subpass.flags = 0; subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS; subpass.inputAttachmentCount = 0; //unsupported for now - subpass.pInputAttachments = NULL; + subpass.pInputAttachments = nullptr; subpass.colorAttachmentCount = color_references.size(); subpass.pColorAttachments = color_references.ptr(); subpass.pDepthStencilAttachment = depth_stencil_references.ptr(); subpass.pResolveAttachments = resolve_references.ptr(); subpass.preserveAttachmentCount = 0; - subpass.pPreserveAttachments = NULL; + subpass.pPreserveAttachments = nullptr; VkRenderPassCreateInfo render_pass_create_info; render_pass_create_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; - render_pass_create_info.pNext = NULL; + render_pass_create_info.pNext = nullptr; render_pass_create_info.flags = 0; render_pass_create_info.attachmentCount = attachments.size(); render_pass_create_info.pAttachments = attachments.ptr(); render_pass_create_info.subpassCount = 1; render_pass_create_info.pSubpasses = &subpass; render_pass_create_info.dependencyCount = 0; - render_pass_create_info.pDependencies = NULL; + render_pass_create_info.pDependencies = nullptr; VkRenderPass render_pass; - VkResult res = vkCreateRenderPass(device, &render_pass_create_info, NULL, &render_pass); + VkResult res = vkCreateRenderPass(device, &render_pass_create_info, nullptr, &render_pass); ERR_FAIL_COND_V_MSG(res, VK_NULL_HANDLE, "vkCreateRenderPass failed with error " + itos(res) + "."); if (r_color_attachment_count) { @@ -3083,7 +3268,7 @@ RID RenderingDeviceVulkan::sampler_create(const SamplerState &p_state) { VkSamplerCreateInfo sampler_create_info; sampler_create_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; - sampler_create_info.pNext = NULL; + sampler_create_info.pNext = nullptr; sampler_create_info.flags = 0; sampler_create_info.magFilter = p_state.mag_filter == SAMPLER_FILTER_LINEAR ? VK_FILTER_LINEAR : VK_FILTER_NEAREST; sampler_create_info.minFilter = p_state.min_filter == SAMPLER_FILTER_LINEAR ? VK_FILTER_LINEAR : VK_FILTER_NEAREST; @@ -3113,7 +3298,7 @@ RID RenderingDeviceVulkan::sampler_create(const SamplerState &p_state) { sampler_create_info.unnormalizedCoordinates = p_state.unnormalized_uvw; VkSampler sampler; - VkResult res = vkCreateSampler(device, &sampler_create_info, NULL, &sampler); + VkResult res = vkCreateSampler(device, &sampler_create_info, nullptr, &sampler); ERR_FAIL_COND_V_MSG(res, RID(), "vkCreateSampler failed with error " + itos(res) + "."); return sampler_owner.make_rid(sampler); @@ -3142,7 +3327,7 @@ RID RenderingDeviceVulkan::vertex_buffer_create(uint32_t p_size_bytes, const Vec } // Internally reference counted, this ID is warranted to be unique for the same description, but needs to be freed as many times as it was allocated -RenderingDevice::VertexFormatID RenderingDeviceVulkan::vertex_format_create(const Vector<VertexDescription> &p_vertex_formats) { +RenderingDevice::VertexFormatID RenderingDeviceVulkan::vertex_format_create(const Vector<VertexAttribute> &p_vertex_formats) { _THREAD_SAFE_METHOD_ @@ -3178,7 +3363,7 @@ RenderingDevice::VertexFormatID RenderingDeviceVulkan::vertex_format_create(cons } vdcache.create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; - vdcache.create_info.pNext = NULL; + vdcache.create_info.pNext = nullptr; vdcache.create_info.flags = 0; vdcache.create_info.vertexAttributeDescriptionCount = p_vertex_formats.size(); @@ -3217,7 +3402,7 @@ RID RenderingDeviceVulkan::vertex_array_create(uint32_t p_vertex_count, VertexFo //validate with buffer { - const VertexDescription &atf = vd.vertex_formats[i]; + const VertexAttribute &atf = vd.vertex_formats[i]; uint32_t element_size = get_format_vertex_size(atf.format); ERR_FAIL_COND_V(element_size == 0, RID()); //should never happens since this was prevalidated @@ -3546,7 +3731,7 @@ bool RenderingDeviceVulkan::_uniform_add_binding(Vector<Vector<VkDescriptorSetLa } layout_binding.binding = binding; layout_binding.stageFlags = shader_stage_masks[p_stage]; - layout_binding.pImmutableSamplers = NULL; //no support for this yet + layout_binding.pImmutableSamplers = nullptr; //no support for this yet info.stages = 1 << p_stage; info.binding = binding; @@ -3600,7 +3785,7 @@ RID RenderingDeviceVulkan::shader_create(const Vector<ShaderStageData> &p_stages "Reflection of SPIR-V shader stage '" + String(shader_stage_names[p_stages[i].shader_stage]) + "' failed parsing shader."); uint32_t binding_count = 0; - result = spvReflectEnumerateDescriptorBindings(&module, &binding_count, NULL); + result = spvReflectEnumerateDescriptorBindings(&module, &binding_count, nullptr); ERR_FAIL_COND_V_MSG(result != SPV_REFLECT_RESULT_SUCCESS, RID(), "Reflection of SPIR-V shader stage '" + String(shader_stage_names[p_stages[i].shader_stage]) + "' failed enumerating descriptor bindings."); @@ -3742,7 +3927,7 @@ RID RenderingDeviceVulkan::shader_create(const Vector<ShaderStageData> &p_stages layout_binding.binding = info.binding; layout_binding.stageFlags = shader_stage_masks[stage]; - layout_binding.pImmutableSamplers = NULL; //no support for this yet + layout_binding.pImmutableSamplers = nullptr; //no support for this yet info.stages = 1 << stage; info.binding = info.binding; @@ -3760,7 +3945,7 @@ RID RenderingDeviceVulkan::shader_create(const Vector<ShaderStageData> &p_stages if (stage == SHADER_STAGE_VERTEX) { uint32_t iv_count = 0; - result = spvReflectEnumerateInputVariables(&module, &iv_count, NULL); + result = spvReflectEnumerateInputVariables(&module, &iv_count, nullptr); ERR_FAIL_COND_V_MSG(result != SPV_REFLECT_RESULT_SUCCESS, RID(), "Reflection of SPIR-V shader stage '" + String(shader_stage_names[p_stages[i].shader_stage]) + "' failed enumerating input variables."); @@ -3783,7 +3968,7 @@ RID RenderingDeviceVulkan::shader_create(const Vector<ShaderStageData> &p_stages if (stage == SHADER_STAGE_FRAGMENT) { uint32_t ov_count = 0; - result = spvReflectEnumerateOutputVariables(&module, &ov_count, NULL); + result = spvReflectEnumerateOutputVariables(&module, &ov_count, nullptr); ERR_FAIL_COND_V_MSG(result != SPV_REFLECT_RESULT_SUCCESS, RID(), "Reflection of SPIR-V shader stage '" + String(shader_stage_names[p_stages[i].shader_stage]) + "' failed enumerating output variables."); @@ -3803,7 +3988,7 @@ RID RenderingDeviceVulkan::shader_create(const Vector<ShaderStageData> &p_stages } } uint32_t pc_count = 0; - result = spvReflectEnumeratePushConstantBlocks(&module, &pc_count, NULL); + result = spvReflectEnumeratePushConstantBlocks(&module, &pc_count, nullptr); ERR_FAIL_COND_V_MSG(result != SPV_REFLECT_RESULT_SUCCESS, RID(), "Reflection of SPIR-V shader stage '" + String(shader_stage_names[p_stages[i].shader_stage]) + "' failed enumerating push constants."); @@ -3817,7 +4002,7 @@ RID RenderingDeviceVulkan::shader_create(const Vector<ShaderStageData> &p_stages ERR_FAIL_COND_V_MSG(result != SPV_REFLECT_RESULT_SUCCESS, RID(), "Reflection of SPIR-V shader stage '" + String(shader_stage_names[p_stages[i].shader_stage]) + "' failed obtaining push constants."); #if 0 - if (pconstants[0] == NULL) { + if (pconstants[0] == nullptr) { FileAccess *f = FileAccess::open("res://popo.spv", FileAccess::WRITE); f->store_buffer((const uint8_t *)&SpirV[0], SpirV.size() * sizeof(uint32_t)); memdelete(f); @@ -3857,7 +4042,7 @@ RID RenderingDeviceVulkan::shader_create(const Vector<ShaderStageData> &p_stages for (int i = 0; i < p_stages.size(); i++) { VkShaderModuleCreateInfo shader_module_create_info; shader_module_create_info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; - shader_module_create_info.pNext = NULL; + shader_module_create_info.pNext = nullptr; shader_module_create_info.flags = 0; shader_module_create_info.codeSize = p_stages[i].spir_v.size(); const uint8_t *r = p_stages[i].spir_v.ptr(); @@ -3865,7 +4050,7 @@ RID RenderingDeviceVulkan::shader_create(const Vector<ShaderStageData> &p_stages shader_module_create_info.pCode = (const uint32_t *)r; VkShaderModule module; - VkResult res = vkCreateShaderModule(device, &shader_module_create_info, NULL, &module); + VkResult res = vkCreateShaderModule(device, &shader_module_create_info, nullptr, &module); if (res) { success = false; error_text = "Error (" + itos(res) + ") creating shader module for stage: " + String(shader_stage_names[p_stages[i].shader_stage]); @@ -3882,12 +4067,12 @@ RID RenderingDeviceVulkan::shader_create(const Vector<ShaderStageData> &p_stages VkPipelineShaderStageCreateInfo shader_stage; shader_stage.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; - shader_stage.pNext = NULL; + shader_stage.pNext = nullptr; shader_stage.flags = 0; shader_stage.stage = shader_stage_bits[p_stages[i].shader_stage]; shader_stage.module = module; shader_stage.pName = "main"; - shader_stage.pSpecializationInfo = NULL; + shader_stage.pSpecializationInfo = nullptr; shader.pipeline_stages.push_back(shader_stage); } @@ -3900,13 +4085,13 @@ RID RenderingDeviceVulkan::shader_create(const Vector<ShaderStageData> &p_stages //empty ones are fine if they were not used according to spec (binding count will be 0) VkDescriptorSetLayoutCreateInfo layout_create_info; layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; - layout_create_info.pNext = NULL; + layout_create_info.pNext = nullptr; layout_create_info.flags = 0; layout_create_info.bindingCount = set_bindings[i].size(); layout_create_info.pBindings = set_bindings[i].ptr(); VkDescriptorSetLayout layout; - VkResult res = vkCreateDescriptorSetLayout(device, &layout_create_info, NULL, &layout); + VkResult res = vkCreateDescriptorSetLayout(device, &layout_create_info, nullptr, &layout); if (res) { error_text = "Error (" + itos(res) + ") creating descriptor set layout for set " + itos(i); success = false; @@ -3943,7 +4128,7 @@ RID RenderingDeviceVulkan::shader_create(const Vector<ShaderStageData> &p_stages //create pipeline layout VkPipelineLayoutCreateInfo pipeline_layout_create_info; pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; - pipeline_layout_create_info.pNext = NULL; + pipeline_layout_create_info.pNext = nullptr; pipeline_layout_create_info.flags = 0; pipeline_layout_create_info.setLayoutCount = shader.sets.size(); @@ -3965,10 +4150,10 @@ RID RenderingDeviceVulkan::shader_create(const Vector<ShaderStageData> &p_stages pipeline_layout_create_info.pPushConstantRanges = &push_constant_range; } else { pipeline_layout_create_info.pushConstantRangeCount = 0; - pipeline_layout_create_info.pPushConstantRanges = NULL; + pipeline_layout_create_info.pPushConstantRanges = nullptr; } - VkResult err = vkCreatePipelineLayout(device, &pipeline_layout_create_info, NULL, &shader.pipeline_layout); + VkResult err = vkCreatePipelineLayout(device, &pipeline_layout_create_info, nullptr, &shader.pipeline_layout); if (err) { error_text = "Error (" + itos(err) + ") creating pipeline layout."; @@ -3979,11 +4164,11 @@ RID RenderingDeviceVulkan::shader_create(const Vector<ShaderStageData> &p_stages if (!success) { //clean up if failed for (int i = 0; i < shader.pipeline_stages.size(); i++) { - vkDestroyShaderModule(device, shader.pipeline_stages[i].module, NULL); + vkDestroyShaderModule(device, shader.pipeline_stages[i].module, nullptr); } for (int i = 0; i < shader.sets.size(); i++) { - vkDestroyDescriptorSetLayout(device, shader.sets[i].descriptor_set_layout, NULL); + vkDestroyDescriptorSetLayout(device, shader.sets[i].descriptor_set_layout, nullptr); } ERR_FAIL_V_MSG(RID(), error_text); @@ -4064,7 +4249,7 @@ RID RenderingDeviceVulkan::texture_buffer_create(uint32_t p_size_elements, DataF VkBufferViewCreateInfo view_create_info; view_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO; - view_create_info.pNext = NULL; + view_create_info.pNext = nullptr; view_create_info.flags = 0; view_create_info.buffer = texture_buffer.buffer.buffer; view_create_info.format = vulkan_formats[p_format]; @@ -4073,7 +4258,7 @@ RID RenderingDeviceVulkan::texture_buffer_create(uint32_t p_size_elements, DataF texture_buffer.view = VK_NULL_HANDLE; - VkResult res = vkCreateBufferView(device, &view_create_info, NULL, &texture_buffer.view); + VkResult res = vkCreateBufferView(device, &view_create_info, nullptr, &texture_buffer.view); if (res) { _buffer_free(&texture_buffer.buffer); ERR_FAIL_V_MSG(RID(), "Unable to create buffer view, error " + itos(res) + "."); @@ -4088,7 +4273,7 @@ RenderingDeviceVulkan::DescriptorPool *RenderingDeviceVulkan::_descriptor_pool_a descriptor_pools[p_key] = Set<DescriptorPool *>(); } - DescriptorPool *pool = NULL; + DescriptorPool *pool = nullptr; for (Set<DescriptorPool *>::Element *E = descriptor_pools[p_key].front(); E; E = E->next()) { if (E->get()->usage < max_descriptors_per_pool) { @@ -4104,7 +4289,7 @@ RenderingDeviceVulkan::DescriptorPool *RenderingDeviceVulkan::_descriptor_pool_a VkDescriptorPoolCreateInfo descriptor_pool_create_info; descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; - descriptor_pool_create_info.pNext = NULL; + descriptor_pool_create_info.pNext = nullptr; descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT; // can't think how somebody may NOT need this flag.. descriptor_pool_create_info.maxSets = max_descriptors_per_pool; Vector<VkDescriptorPoolSize> sizes; @@ -4169,10 +4354,10 @@ RenderingDeviceVulkan::DescriptorPool *RenderingDeviceVulkan::_descriptor_pool_a descriptor_pool_create_info.poolSizeCount = sizes.size(); descriptor_pool_create_info.pPoolSizes = sizes.ptr(); - VkResult res = vkCreateDescriptorPool(device, &descriptor_pool_create_info, NULL, &pool->pool); + VkResult res = vkCreateDescriptorPool(device, &descriptor_pool_create_info, nullptr, &pool->pool); if (res) { memdelete(pool); - ERR_FAIL_COND_V_MSG(res, NULL, "vkCreateDescriptorPool failed with error " + itos(res) + "."); + ERR_FAIL_COND_V_MSG(res, nullptr, "vkCreateDescriptorPool failed with error " + itos(res) + "."); } descriptor_pools[p_key].insert(pool); } @@ -4189,7 +4374,7 @@ void RenderingDeviceVulkan::_descriptor_pool_free(const DescriptorPoolKey &p_key ERR_FAIL_COND(p_pool->usage == 0); p_pool->usage--; if (p_pool->usage == 0) { - vkDestroyDescriptorPool(device, p_pool->pool, NULL); + vkDestroyDescriptorPool(device, p_pool->pool, nullptr); descriptor_pools[p_key].erase(p_pool); memdelete(p_pool); if (descriptor_pools[p_key].empty()) { @@ -4249,8 +4434,8 @@ RID RenderingDeviceVulkan::uniform_set_create(const Vector<Uniform> &p_uniforms, VkWriteDescriptorSet write; //common header write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; - write.pNext = NULL; - write.dstSet = NULL; //will assign afterwards when everything is valid + write.pNext = nullptr; + write.dstSet = VK_NULL_HANDLE; //will assign afterwards when everything is valid write.dstBinding = set_uniform.binding; uint32_t type_size = 1; @@ -4282,8 +4467,8 @@ RID RenderingDeviceVulkan::uniform_set_create(const Vector<Uniform> &p_uniforms, write.descriptorCount = uniform.ids.size(); write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; write.pImageInfo = image_infos.push_back(image_info)->get().ptr(); - write.pBufferInfo = NULL; - write.pTexelBufferView = NULL; + write.pBufferInfo = nullptr; + write.pTexelBufferView = nullptr; type_size = uniform.ids.size(); @@ -4318,6 +4503,10 @@ RID RenderingDeviceVulkan::uniform_set_create(const Vector<Uniform> &p_uniforms, attachable_textures.push_back(texture->owner.is_valid() ? texture->owner : uniform.ids[j + 1]); } + if (texture->usage_flags & TEXTURE_USAGE_STORAGE_BIT) { + //can also be used as storage, add to mutable sampled + mutable_sampled_textures.push_back(texture); + } if (texture->owner.is_valid()) { texture = texture_owner.getornull(texture->owner); ERR_FAIL_COND_V(!texture, RID()); //bug, should never happen @@ -4326,19 +4515,14 @@ RID RenderingDeviceVulkan::uniform_set_create(const Vector<Uniform> &p_uniforms, img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; image_info.push_back(img_info); - - if (texture->usage_flags & TEXTURE_USAGE_STORAGE_BIT) { - //can also be used as storage, add to mutable sampled - mutable_sampled_textures.push_back(texture); - } } write.dstArrayElement = 0; write.descriptorCount = uniform.ids.size() / 2; write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; write.pImageInfo = image_infos.push_back(image_info)->get().ptr(); - write.pBufferInfo = NULL; - write.pTexelBufferView = NULL; + write.pBufferInfo = nullptr; + write.pTexelBufferView = nullptr; type_size = uniform.ids.size() / 2; @@ -4363,13 +4547,18 @@ RID RenderingDeviceVulkan::uniform_set_create(const Vector<Uniform> &p_uniforms, "Texture (binding: " + itos(uniform.binding) + ", index " + itos(j) + ") needs the TEXTURE_USAGE_SAMPLING_BIT usage flag set in order to be used as uniform."); VkDescriptorImageInfo img_info; - img_info.sampler = NULL; + img_info.sampler = VK_NULL_HANDLE; img_info.imageView = texture->view; if (texture->usage_flags & (TEXTURE_USAGE_COLOR_ATTACHMENT_BIT | TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | TEXTURE_USAGE_RESOLVE_ATTACHMENT_BIT)) { attachable_textures.push_back(texture->owner.is_valid() ? texture->owner : uniform.ids[j]); } + if (texture->usage_flags & TEXTURE_USAGE_STORAGE_BIT) { + //can also be used as storage, add to mutable sampled + mutable_sampled_textures.push_back(texture); + } + if (texture->owner.is_valid()) { texture = texture_owner.getornull(texture->owner); ERR_FAIL_COND_V(!texture, RID()); //bug, should never happen @@ -4378,19 +4567,14 @@ RID RenderingDeviceVulkan::uniform_set_create(const Vector<Uniform> &p_uniforms, img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; image_info.push_back(img_info); - - if (texture->usage_flags & TEXTURE_USAGE_STORAGE_BIT) { - //can also be used as storage, add to mutable sampled - mutable_sampled_textures.push_back(texture); - } } write.dstArrayElement = 0; write.descriptorCount = uniform.ids.size(); write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; write.pImageInfo = image_infos.push_back(image_info)->get().ptr(); - write.pBufferInfo = NULL; - write.pTexelBufferView = NULL; + write.pBufferInfo = nullptr; + write.pTexelBufferView = nullptr; type_size = uniform.ids.size(); } break; @@ -4416,9 +4600,14 @@ RID RenderingDeviceVulkan::uniform_set_create(const Vector<Uniform> &p_uniforms, "Image (binding: " + itos(uniform.binding) + ", index " + itos(j) + ") needs the TEXTURE_USAGE_STORAGE_BIT usage flag set in order to be used as uniform."); VkDescriptorImageInfo img_info; - img_info.sampler = NULL; + img_info.sampler = VK_NULL_HANDLE; img_info.imageView = texture->view; + if (texture->usage_flags & TEXTURE_USAGE_SAMPLING_BIT) { + //can also be used as storage, add to mutable sampled + mutable_storage_textures.push_back(texture); + } + if (texture->owner.is_valid()) { texture = texture_owner.getornull(texture->owner); ERR_FAIL_COND_V(!texture, RID()); //bug, should never happen @@ -4427,19 +4616,14 @@ RID RenderingDeviceVulkan::uniform_set_create(const Vector<Uniform> &p_uniforms, img_info.imageLayout = VK_IMAGE_LAYOUT_GENERAL; image_info.push_back(img_info); - - if (texture->usage_flags & TEXTURE_USAGE_SAMPLING_BIT) { - //can also be used as storage, add to mutable sampled - mutable_storage_textures.push_back(texture); - } } write.dstArrayElement = 0; write.descriptorCount = uniform.ids.size(); write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; write.pImageInfo = image_infos.push_back(image_info)->get().ptr(); - write.pBufferInfo = NULL; - write.pTexelBufferView = NULL; + write.pBufferInfo = nullptr; + write.pTexelBufferView = nullptr; type_size = uniform.ids.size(); @@ -4467,7 +4651,7 @@ RID RenderingDeviceVulkan::uniform_set_create(const Vector<Uniform> &p_uniforms, write.dstArrayElement = 0; write.descriptorCount = uniform.ids.size(); write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER; - write.pImageInfo = NULL; + write.pImageInfo = nullptr; write.pBufferInfo = buffer_infos.push_back(buffer_info)->get().ptr(); write.pTexelBufferView = buffer_views.push_back(buffer_view)->get().ptr(); @@ -4533,9 +4717,9 @@ RID RenderingDeviceVulkan::uniform_set_create(const Vector<Uniform> &p_uniforms, write.dstArrayElement = 0; write.descriptorCount = 1; write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; - write.pImageInfo = NULL; + write.pImageInfo = nullptr; write.pBufferInfo = &buffer->buffer_info; - write.pTexelBufferView = NULL; + write.pTexelBufferView = nullptr; } break; case UNIFORM_TYPE_STORAGE_BUFFER: { @@ -4552,9 +4736,9 @@ RID RenderingDeviceVulkan::uniform_set_create(const Vector<Uniform> &p_uniforms, write.dstArrayElement = 0; write.descriptorCount = 1; write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER; - write.pImageInfo = NULL; + write.pImageInfo = nullptr; write.pBufferInfo = &buffer->buffer_info; - write.pTexelBufferView = NULL; + write.pTexelBufferView = nullptr; } break; case UNIFORM_TYPE_INPUT_ATTACHMENT: { @@ -4578,7 +4762,7 @@ RID RenderingDeviceVulkan::uniform_set_create(const Vector<Uniform> &p_uniforms, VkDescriptorSetAllocateInfo descriptor_set_allocate_info; descriptor_set_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; - descriptor_set_allocate_info.pNext = NULL; + descriptor_set_allocate_info.pNext = nullptr; descriptor_set_allocate_info.descriptorPool = pool->pool; descriptor_set_allocate_info.descriptorSetCount = 1; descriptor_set_allocate_info.pSetLayouts = &shader->sets[p_shader_set].descriptor_set_layout; @@ -4619,7 +4803,7 @@ RID RenderingDeviceVulkan::uniform_set_create(const Vector<Uniform> &p_uniforms, for (int i = 0; i < writes.size(); i++) { writes.write[i].dstSet = descriptor_set; } - vkUpdateDescriptorSets(device, writes.size(), writes.ptr(), 0, NULL); + vkUpdateDescriptorSets(device, writes.size(), writes.ptr(), 0, nullptr); } return id; @@ -4638,7 +4822,7 @@ Error RenderingDeviceVulkan::buffer_update(RID p_buffer, uint32_t p_offset, uint VkPipelineStageFlags dst_stage_mask; VkAccessFlags dst_access; - Buffer *buffer = NULL; + Buffer *buffer = nullptr; if (vertex_buffer_owner.owns(p_buffer)) { dst_stage_mask = VK_PIPELINE_STAGE_VERTEX_INPUT_BIT; dst_access = VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT; @@ -4684,7 +4868,7 @@ Vector<uint8_t> RenderingDeviceVulkan::buffer_get_data(RID p_buffer) { _THREAD_SAFE_METHOD_ - Buffer *buffer = NULL; + Buffer *buffer = nullptr; if (vertex_buffer_owner.owns(p_buffer)) { buffer = vertex_buffer_owner.getornull(p_buffer); } else if (index_buffer_owner.owns(p_buffer)) { @@ -4783,12 +4967,12 @@ RID RenderingDeviceVulkan::render_pipeline_create(RID p_shader, FramebufferForma } else { //does not use vertices pipeline_vertex_input_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; - pipeline_vertex_input_state_create_info.pNext = NULL; + pipeline_vertex_input_state_create_info.pNext = nullptr; pipeline_vertex_input_state_create_info.flags = 0; pipeline_vertex_input_state_create_info.vertexBindingDescriptionCount = 0; - pipeline_vertex_input_state_create_info.pVertexBindingDescriptions = NULL; + pipeline_vertex_input_state_create_info.pVertexBindingDescriptions = nullptr; pipeline_vertex_input_state_create_info.vertexAttributeDescriptionCount = 0; - pipeline_vertex_input_state_create_info.pVertexAttributeDescriptions = NULL; + pipeline_vertex_input_state_create_info.pVertexAttributeDescriptions = nullptr; ERR_FAIL_COND_V_MSG(shader->vertex_input_mask != 0, RID(), "Shader contains vertex inputs, but no vertex input description was provided for pipeline creation."); @@ -4799,7 +4983,7 @@ RID RenderingDeviceVulkan::render_pipeline_create(RID p_shader, FramebufferForma VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info; input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; - input_assembly_create_info.pNext = NULL; + input_assembly_create_info.pNext = nullptr; input_assembly_create_info.flags = 0; static const VkPrimitiveTopology topology_list[RENDER_PRIMITIVE_MAX] = { @@ -4822,24 +5006,24 @@ RID RenderingDeviceVulkan::render_pipeline_create(RID p_shader, FramebufferForma //tesselation VkPipelineTessellationStateCreateInfo tesselation_create_info; tesselation_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO; - tesselation_create_info.pNext = NULL; + tesselation_create_info.pNext = nullptr; tesselation_create_info.flags = 0; ERR_FAIL_COND_V(p_rasterization_state.patch_control_points < 1 || p_rasterization_state.patch_control_points > limits.maxTessellationPatchSize, RID()); tesselation_create_info.patchControlPoints = p_rasterization_state.patch_control_points; VkPipelineViewportStateCreateInfo viewport_state_create_info; viewport_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; - viewport_state_create_info.pNext = NULL; + viewport_state_create_info.pNext = nullptr; viewport_state_create_info.flags = 0; viewport_state_create_info.viewportCount = 1; //if VR extensions are supported at some point, this will have to be customizable in the framebuffer format - viewport_state_create_info.pViewports = NULL; + viewport_state_create_info.pViewports = nullptr; viewport_state_create_info.scissorCount = 1; - viewport_state_create_info.pScissors = NULL; + viewport_state_create_info.pScissors = nullptr; //rasterization VkPipelineRasterizationStateCreateInfo rasterization_state_create_info; rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; - rasterization_state_create_info.pNext = NULL; + rasterization_state_create_info.pNext = nullptr; rasterization_state_create_info.flags = 0; rasterization_state_create_info.depthClampEnable = p_rasterization_state.enable_depth_clamp; rasterization_state_create_info.rasterizerDiscardEnable = p_rasterization_state.discard_primitives; @@ -4862,7 +5046,7 @@ RID RenderingDeviceVulkan::render_pipeline_create(RID p_shader, FramebufferForma //multisample VkPipelineMultisampleStateCreateInfo multisample_state_create_info; multisample_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; - multisample_state_create_info.pNext = NULL; + multisample_state_create_info.pNext = nullptr; multisample_state_create_info.flags = 0; multisample_state_create_info.rasterizationSamples = rasterization_sample_count[p_multisample_state.sample_count]; @@ -4882,7 +5066,7 @@ RID RenderingDeviceVulkan::render_pipeline_create(RID p_shader, FramebufferForma } multisample_state_create_info.pSampleMask = sample_mask.ptr(); } else { - multisample_state_create_info.pSampleMask = NULL; + multisample_state_create_info.pSampleMask = nullptr; } multisample_state_create_info.alphaToCoverageEnable = p_multisample_state.enable_alpha_to_coverage; @@ -4892,7 +5076,7 @@ RID RenderingDeviceVulkan::render_pipeline_create(RID p_shader, FramebufferForma VkPipelineDepthStencilStateCreateInfo depth_stencil_state_create_info; depth_stencil_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO; - depth_stencil_state_create_info.pNext = NULL; + depth_stencil_state_create_info.pNext = nullptr; depth_stencil_state_create_info.flags = 0; depth_stencil_state_create_info.depthTestEnable = p_depth_stencil_state.enable_depth_test; depth_stencil_state_create_info.depthWriteEnable = p_depth_stencil_state.enable_depth_write; @@ -4901,29 +5085,29 @@ RID RenderingDeviceVulkan::render_pipeline_create(RID p_shader, FramebufferForma depth_stencil_state_create_info.depthBoundsTestEnable = p_depth_stencil_state.enable_depth_range; depth_stencil_state_create_info.stencilTestEnable = p_depth_stencil_state.enable_stencil; - ERR_FAIL_INDEX_V(p_depth_stencil_state.stencil_operation_front.fail, STENCIL_OP_MAX, RID()); - depth_stencil_state_create_info.front.failOp = stencil_operations[p_depth_stencil_state.stencil_operation_front.fail]; - ERR_FAIL_INDEX_V(p_depth_stencil_state.stencil_operation_front.pass, STENCIL_OP_MAX, RID()); - depth_stencil_state_create_info.front.passOp = stencil_operations[p_depth_stencil_state.stencil_operation_front.pass]; - ERR_FAIL_INDEX_V(p_depth_stencil_state.stencil_operation_front.depth_fail, STENCIL_OP_MAX, RID()); - depth_stencil_state_create_info.front.depthFailOp = stencil_operations[p_depth_stencil_state.stencil_operation_front.depth_fail]; - ERR_FAIL_INDEX_V(p_depth_stencil_state.stencil_operation_front.compare, COMPARE_OP_MAX, RID()); - depth_stencil_state_create_info.front.compareOp = compare_operators[p_depth_stencil_state.stencil_operation_front.compare]; - depth_stencil_state_create_info.front.compareMask = p_depth_stencil_state.stencil_operation_front.compare_mask; - depth_stencil_state_create_info.front.writeMask = p_depth_stencil_state.stencil_operation_front.write_mask; - depth_stencil_state_create_info.front.reference = p_depth_stencil_state.stencil_operation_front.reference; - - ERR_FAIL_INDEX_V(p_depth_stencil_state.stencil_operation_back.fail, STENCIL_OP_MAX, RID()); - depth_stencil_state_create_info.back.failOp = stencil_operations[p_depth_stencil_state.stencil_operation_back.fail]; - ERR_FAIL_INDEX_V(p_depth_stencil_state.stencil_operation_back.pass, STENCIL_OP_MAX, RID()); - depth_stencil_state_create_info.back.passOp = stencil_operations[p_depth_stencil_state.stencil_operation_back.pass]; - ERR_FAIL_INDEX_V(p_depth_stencil_state.stencil_operation_back.depth_fail, STENCIL_OP_MAX, RID()); - depth_stencil_state_create_info.back.depthFailOp = stencil_operations[p_depth_stencil_state.stencil_operation_back.depth_fail]; - ERR_FAIL_INDEX_V(p_depth_stencil_state.stencil_operation_back.compare, COMPARE_OP_MAX, RID()); - depth_stencil_state_create_info.back.compareOp = compare_operators[p_depth_stencil_state.stencil_operation_back.compare]; - depth_stencil_state_create_info.back.compareMask = p_depth_stencil_state.stencil_operation_back.compare_mask; - depth_stencil_state_create_info.back.writeMask = p_depth_stencil_state.stencil_operation_back.write_mask; - depth_stencil_state_create_info.back.reference = p_depth_stencil_state.stencil_operation_back.reference; + ERR_FAIL_INDEX_V(p_depth_stencil_state.front_op.fail, STENCIL_OP_MAX, RID()); + depth_stencil_state_create_info.front.failOp = stencil_operations[p_depth_stencil_state.front_op.fail]; + ERR_FAIL_INDEX_V(p_depth_stencil_state.front_op.pass, STENCIL_OP_MAX, RID()); + depth_stencil_state_create_info.front.passOp = stencil_operations[p_depth_stencil_state.front_op.pass]; + ERR_FAIL_INDEX_V(p_depth_stencil_state.front_op.depth_fail, STENCIL_OP_MAX, RID()); + depth_stencil_state_create_info.front.depthFailOp = stencil_operations[p_depth_stencil_state.front_op.depth_fail]; + ERR_FAIL_INDEX_V(p_depth_stencil_state.front_op.compare, COMPARE_OP_MAX, RID()); + depth_stencil_state_create_info.front.compareOp = compare_operators[p_depth_stencil_state.front_op.compare]; + depth_stencil_state_create_info.front.compareMask = p_depth_stencil_state.front_op.compare_mask; + depth_stencil_state_create_info.front.writeMask = p_depth_stencil_state.front_op.write_mask; + depth_stencil_state_create_info.front.reference = p_depth_stencil_state.front_op.reference; + + ERR_FAIL_INDEX_V(p_depth_stencil_state.back_op.fail, STENCIL_OP_MAX, RID()); + depth_stencil_state_create_info.back.failOp = stencil_operations[p_depth_stencil_state.back_op.fail]; + ERR_FAIL_INDEX_V(p_depth_stencil_state.back_op.pass, STENCIL_OP_MAX, RID()); + depth_stencil_state_create_info.back.passOp = stencil_operations[p_depth_stencil_state.back_op.pass]; + ERR_FAIL_INDEX_V(p_depth_stencil_state.back_op.depth_fail, STENCIL_OP_MAX, RID()); + depth_stencil_state_create_info.back.depthFailOp = stencil_operations[p_depth_stencil_state.back_op.depth_fail]; + ERR_FAIL_INDEX_V(p_depth_stencil_state.back_op.compare, COMPARE_OP_MAX, RID()); + depth_stencil_state_create_info.back.compareOp = compare_operators[p_depth_stencil_state.back_op.compare]; + depth_stencil_state_create_info.back.compareMask = p_depth_stencil_state.back_op.compare_mask; + depth_stencil_state_create_info.back.writeMask = p_depth_stencil_state.back_op.write_mask; + depth_stencil_state_create_info.back.reference = p_depth_stencil_state.back_op.reference; depth_stencil_state_create_info.minDepthBounds = p_depth_stencil_state.depth_range_min; depth_stencil_state_create_info.maxDepthBounds = p_depth_stencil_state.depth_range_max; @@ -4931,7 +5115,7 @@ RID RenderingDeviceVulkan::render_pipeline_create(RID p_shader, FramebufferForma //blend state VkPipelineColorBlendStateCreateInfo color_blend_state_create_info; color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; - color_blend_state_create_info.pNext = NULL; + color_blend_state_create_info.pNext = nullptr; color_blend_state_create_info.flags = 0; color_blend_state_create_info.logicOpEnable = p_blend_state.enable_logic_op; ERR_FAIL_INDEX_V(p_blend_state.logic_op, LOGIC_OP_MAX, RID()); @@ -4988,7 +5172,7 @@ RID RenderingDeviceVulkan::render_pipeline_create(RID p_shader, FramebufferForma VkPipelineDynamicStateCreateInfo dynamic_state_create_info; dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; - dynamic_state_create_info.pNext = NULL; + dynamic_state_create_info.pNext = nullptr; dynamic_state_create_info.flags = 0; Vector<VkDynamicState> dynamic_states; //vulkan is weird.. @@ -5030,7 +5214,7 @@ RID RenderingDeviceVulkan::render_pipeline_create(RID p_shader, FramebufferForma VkGraphicsPipelineCreateInfo graphics_pipeline_create_info; graphics_pipeline_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; - graphics_pipeline_create_info.pNext = NULL; + graphics_pipeline_create_info.pNext = nullptr; graphics_pipeline_create_info.flags = 0; graphics_pipeline_create_info.stageCount = shader->pipeline_stages.size(); @@ -5048,11 +5232,11 @@ RID RenderingDeviceVulkan::render_pipeline_create(RID p_shader, FramebufferForma graphics_pipeline_create_info.renderPass = fb_format.render_pass; graphics_pipeline_create_info.subpass = 0; - graphics_pipeline_create_info.basePipelineHandle = NULL; + graphics_pipeline_create_info.basePipelineHandle = VK_NULL_HANDLE; graphics_pipeline_create_info.basePipelineIndex = 0; RenderPipeline pipeline; - VkResult err = vkCreateGraphicsPipelines(device, NULL, 1, &graphics_pipeline_create_info, NULL, &pipeline.pipeline); + VkResult err = vkCreateGraphicsPipelines(device, VK_NULL_HANDLE, 1, &graphics_pipeline_create_info, nullptr, &pipeline.pipeline); ERR_FAIL_COND_V_MSG(err, RID(), "vkCreateGraphicsPipelines failed with error " + itos(err) + "."); pipeline.set_formats = shader->set_formats; @@ -5116,16 +5300,16 @@ RID RenderingDeviceVulkan::compute_pipeline_create(RID p_shader) { VkComputePipelineCreateInfo compute_pipeline_create_info; compute_pipeline_create_info.sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO; - compute_pipeline_create_info.pNext = NULL; + compute_pipeline_create_info.pNext = nullptr; compute_pipeline_create_info.flags = 0; compute_pipeline_create_info.stage = shader->pipeline_stages[0]; compute_pipeline_create_info.layout = shader->pipeline_layout; - compute_pipeline_create_info.basePipelineHandle = NULL; + compute_pipeline_create_info.basePipelineHandle = VK_NULL_HANDLE; compute_pipeline_create_info.basePipelineIndex = 0; ComputePipeline pipeline; - VkResult err = vkCreateComputePipelines(device, NULL, 1, &compute_pipeline_create_info, NULL, &pipeline.pipeline); + VkResult err = vkCreateComputePipelines(device, VK_NULL_HANDLE, 1, &compute_pipeline_create_info, nullptr, &pipeline.pipeline); ERR_FAIL_COND_V_MSG(err, RID(), "vkCreateComputePipelines failed with error " + itos(err) + "."); pipeline.set_formats = shader->set_formats; @@ -5150,19 +5334,21 @@ bool RenderingDeviceVulkan::compute_pipeline_is_valid(RID p_pipeline) { /**** SCREEN ****/ /****************/ -int RenderingDeviceVulkan::screen_get_width(int p_screen) const { +int RenderingDeviceVulkan::screen_get_width(DisplayServer::WindowID p_screen) const { _THREAD_SAFE_METHOD_ - + ERR_FAIL_COND_V_MSG(local_device.is_valid(), -1, "Local devices have no screen"); return context->window_get_width(p_screen); } -int RenderingDeviceVulkan::screen_get_height(int p_screen) const { +int RenderingDeviceVulkan::screen_get_height(DisplayServer::WindowID p_screen) const { _THREAD_SAFE_METHOD_ + ERR_FAIL_COND_V_MSG(local_device.is_valid(), -1, "Local devices have no screen"); return context->window_get_height(p_screen); } RenderingDevice::FramebufferFormatID RenderingDeviceVulkan::screen_get_framebuffer_format() const { _THREAD_SAFE_METHOD_ + ERR_FAIL_COND_V_MSG(local_device.is_valid(), INVALID_ID, "Local devices have no screen"); //very hacky, but not used often per frame so I guess ok VkFormat vkformat = context->get_screen_format(); @@ -5189,12 +5375,13 @@ RenderingDevice::FramebufferFormatID RenderingDeviceVulkan::screen_get_framebuff /**** DRAW LIST ****/ /*******************/ -RenderingDevice::DrawListID RenderingDeviceVulkan::draw_list_begin_for_screen(int p_screen, const Color &p_clear_color) { +RenderingDevice::DrawListID RenderingDeviceVulkan::draw_list_begin_for_screen(DisplayServer::WindowID p_screen, const Color &p_clear_color) { _THREAD_SAFE_METHOD_ + ERR_FAIL_COND_V_MSG(local_device.is_valid(), INVALID_ID, "Local devices have no screen"); - ERR_FAIL_COND_V_MSG(draw_list != NULL, INVALID_ID, "Only one draw list can be active at the same time."); - ERR_FAIL_COND_V_MSG(compute_list != NULL, INVALID_ID, "Only one draw/compute list can be active at the same time."); + ERR_FAIL_COND_V_MSG(draw_list != nullptr, INVALID_ID, "Only one draw list can be active at the same time."); + ERR_FAIL_COND_V_MSG(compute_list != nullptr, INVALID_ID, "Only one draw/compute list can be active at the same time."); VkCommandBuffer command_buffer = frames[frame].draw_command_buffer; draw_list = memnew(DrawList); @@ -5207,7 +5394,7 @@ RenderingDevice::DrawListID RenderingDeviceVulkan::draw_list_begin_for_screen(in VkRenderPassBeginInfo render_pass_begin; render_pass_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; - render_pass_begin.pNext = NULL; + render_pass_begin.pNext = nullptr; render_pass_begin.renderPass = context->window_get_render_pass(p_screen); render_pass_begin.framebuffer = context->window_get_framebuffer(p_screen); @@ -5268,7 +5455,7 @@ Error RenderingDeviceVulkan::_draw_list_setup_framebuffer(Framebuffer *p_framebu VkFramebufferCreateInfo framebuffer_create_info; framebuffer_create_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; - framebuffer_create_info.pNext = NULL; + framebuffer_create_info.pNext = nullptr; framebuffer_create_info.flags = 0; framebuffer_create_info.renderPass = version.render_pass; Vector<VkImageView> attachments; @@ -5285,7 +5472,7 @@ Error RenderingDeviceVulkan::_draw_list_setup_framebuffer(Framebuffer *p_framebu framebuffer_create_info.height = p_framebuffer->size.height; framebuffer_create_info.layers = 1; - VkResult err = vkCreateFramebuffer(device, &framebuffer_create_info, NULL, &version.framebuffer); + VkResult err = vkCreateFramebuffer(device, &framebuffer_create_info, nullptr, &version.framebuffer); ERR_FAIL_COND_V_MSG(err, ERR_CANT_CREATE, "vkCreateFramebuffer failed with error " + itos(err) + "."); p_framebuffer->framebuffers.insert(vk, version); @@ -5301,7 +5488,7 @@ Error RenderingDeviceVulkan::_draw_list_render_pass_begin(Framebuffer *framebuff VkRenderPassBeginInfo render_pass_begin; render_pass_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; - render_pass_begin.pNext = NULL; + render_pass_begin.pNext = nullptr; render_pass_begin.renderPass = render_pass; render_pass_begin.framebuffer = vkframebuffer; @@ -5404,8 +5591,8 @@ RenderingDevice::DrawListID RenderingDeviceVulkan::draw_list_begin(RID p_framebu _THREAD_SAFE_METHOD_ - ERR_FAIL_COND_V_MSG(draw_list != NULL, INVALID_ID, "Only one draw list can be active at the same time."); - ERR_FAIL_COND_V_MSG(compute_list != NULL, INVALID_ID, "Only one draw/compute list can be active at the same time."); + ERR_FAIL_COND_V_MSG(draw_list != nullptr, INVALID_ID, "Only one draw list can be active at the same time."); + ERR_FAIL_COND_V_MSG(compute_list != nullptr, INVALID_ID, "Only one draw/compute list can be active at the same time."); Framebuffer *framebuffer = framebuffer_owner.getornull(p_framebuffer); ERR_FAIL_COND_V(!framebuffer, INVALID_ID); @@ -5542,11 +5729,11 @@ Error RenderingDeviceVulkan::draw_list_begin_split(RID p_framebuffer, uint32_t p VkCommandPoolCreateInfo cmd_pool_info; cmd_pool_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; - cmd_pool_info.pNext = NULL; + cmd_pool_info.pNext = nullptr; cmd_pool_info.queueFamilyIndex = context->get_graphics_queue(); cmd_pool_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; - VkResult res = vkCreateCommandPool(device, &cmd_pool_info, NULL, &split_draw_list_allocators.write[i].command_pool); + VkResult res = vkCreateCommandPool(device, &cmd_pool_info, nullptr, &split_draw_list_allocators.write[i].command_pool); ERR_FAIL_COND_V_MSG(res, ERR_CANT_CREATE, "vkCreateCommandPool failed with error " + itos(res) + "."); for (int j = 0; j < frame_count; j++) { @@ -5556,7 +5743,7 @@ Error RenderingDeviceVulkan::draw_list_begin_split(RID p_framebuffer, uint32_t p VkCommandBufferAllocateInfo cmdbuf; //no command buffer exists, create it. cmdbuf.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; - cmdbuf.pNext = NULL; + cmdbuf.pNext = nullptr; cmdbuf.commandPool = split_draw_list_allocators[i].command_pool; cmdbuf.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY; cmdbuf.commandBufferCount = 1; @@ -5593,7 +5780,7 @@ Error RenderingDeviceVulkan::draw_list_begin_split(RID p_framebuffer, uint32_t p VkCommandBufferInheritanceInfo inheritance_info; inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO; - inheritance_info.pNext = NULL; + inheritance_info.pNext = nullptr; inheritance_info.renderPass = render_pass; inheritance_info.subpass = 0; inheritance_info.framebuffer = vkframebuffer; @@ -5603,21 +5790,21 @@ Error RenderingDeviceVulkan::draw_list_begin_split(RID p_framebuffer, uint32_t p VkCommandBufferBeginInfo cmdbuf_begin; cmdbuf_begin.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; - cmdbuf_begin.pNext = NULL; + cmdbuf_begin.pNext = nullptr; cmdbuf_begin.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT; cmdbuf_begin.pInheritanceInfo = &inheritance_info; VkResult res = vkResetCommandBuffer(command_buffer, 0); if (res) { memdelete_arr(draw_list); - draw_list = NULL; + draw_list = nullptr; ERR_FAIL_V_MSG(ERR_CANT_CREATE, "vkResetCommandBuffer failed with error " + itos(res) + "."); } res = vkBeginCommandBuffer(command_buffer, &cmdbuf_begin); if (res) { memdelete_arr(draw_list); - draw_list = NULL; + draw_list = nullptr; ERR_FAIL_V_MSG(ERR_CANT_CREATE, "vkBeginCommandBuffer failed with error " + itos(res) + "."); } @@ -5658,30 +5845,30 @@ Error RenderingDeviceVulkan::draw_list_begin_split(RID p_framebuffer, uint32_t p RenderingDeviceVulkan::DrawList *RenderingDeviceVulkan::_get_draw_list_ptr(DrawListID p_id) { if (p_id < 0) { - return NULL; + return nullptr; } if (!draw_list) { - return NULL; + return nullptr; } else if (p_id == ID_TYPE_DRAW_LIST) { if (draw_list_split) { - return NULL; + return nullptr; } return draw_list; } else if (p_id >> DrawListID(ID_BASE_SHIFT) == ID_TYPE_SPLIT_DRAW_LIST) { if (!draw_list_split) { - return NULL; + return nullptr; } uint64_t index = p_id & ((DrawListID(1) << DrawListID(ID_BASE_SHIFT)) - 1); //mask if (index >= draw_list_count) { - return NULL; + return nullptr; } return &draw_list[index]; } else { - return NULL; + return nullptr; } } @@ -5856,7 +6043,7 @@ void RenderingDeviceVulkan::draw_list_set_line_width(DrawListID p_list, float p_ vkCmdSetLineWidth(dl->command_buffer, p_width); } -void RenderingDeviceVulkan::draw_list_set_push_constant(DrawListID p_list, void *p_data, uint32_t p_data_size) { +void RenderingDeviceVulkan::draw_list_set_push_constant(DrawListID p_list, const void *p_data, uint32_t p_data_size) { DrawList *dl = _get_draw_list_ptr(p_list); ERR_FAIL_COND(!dl); @@ -5927,7 +6114,7 @@ void RenderingDeviceVulkan::draw_list_draw(DrawListID p_list, bool p_use_indices #endif if (!dl->state.sets[i].bound) { //All good, see if this requires re-binding - vkCmdBindDescriptorSets(dl->command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, dl->state.pipeline_layout, i, 1, &dl->state.sets[i].descriptor_set, 0, NULL); + vkCmdBindDescriptorSets(dl->command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, dl->state.pipeline_layout, i, 1, &dl->state.sets[i].descriptor_set, 0, nullptr); dl->state.sets[i].bound = true; } } @@ -6046,13 +6233,13 @@ void RenderingDeviceVulkan::draw_list_end() { vkCmdExecuteCommands(frames[frame].draw_command_buffer, draw_list_count, command_buffers); vkCmdEndRenderPass(frames[frame].draw_command_buffer); memdelete_arr(draw_list); - draw_list = NULL; + draw_list = nullptr; } else { //just end the list vkCmdEndRenderPass(draw_list->command_buffer); memdelete(draw_list); - draw_list = NULL; + draw_list = nullptr; } for (int i = 0; i < draw_list_bound_textures.size(); i++) { @@ -6085,8 +6272,8 @@ void RenderingDeviceVulkan::draw_list_end() { RenderingDevice::ComputeListID RenderingDeviceVulkan::compute_list_begin() { - ERR_FAIL_COND_V_MSG(draw_list != NULL, INVALID_ID, "Only one draw list can be active at the same time."); - ERR_FAIL_COND_V_MSG(compute_list != NULL, INVALID_ID, "Only one draw/compute list can be active at the same time."); + ERR_FAIL_COND_V_MSG(draw_list != nullptr, INVALID_ID, "Only one draw list can be active at the same time."); + ERR_FAIL_COND_V_MSG(compute_list != nullptr, INVALID_ID, "Only one draw/compute list can be active at the same time."); compute_list = memnew(ComputeList); compute_list->command_buffer = frames[frame].draw_command_buffer; @@ -6189,7 +6376,7 @@ void RenderingDeviceVulkan::compute_list_bind_uniform_set(ComputeListID p_list, VkImageMemoryBarrier image_memory_barrier; image_memory_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; - image_memory_barrier.pNext = NULL; + image_memory_barrier.pNext = nullptr; image_memory_barrier.srcAccessMask = VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT; image_memory_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT; image_memory_barrier.oldLayout = textures_to_sampled[i]->layout; @@ -6199,12 +6386,12 @@ void RenderingDeviceVulkan::compute_list_bind_uniform_set(ComputeListID p_list, image_memory_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; image_memory_barrier.image = textures_to_sampled[i]->image; image_memory_barrier.subresourceRange.aspectMask = textures_to_sampled[i]->read_aspect_mask; - image_memory_barrier.subresourceRange.baseMipLevel = 0; + image_memory_barrier.subresourceRange.baseMipLevel = textures_to_sampled[i]->base_mipmap; image_memory_barrier.subresourceRange.levelCount = textures_to_sampled[i]->mipmaps; - image_memory_barrier.subresourceRange.baseArrayLayer = 0; + image_memory_barrier.subresourceRange.baseArrayLayer = textures_to_sampled[i]->base_layer; image_memory_barrier.subresourceRange.layerCount = textures_to_sampled[i]->layers; - vkCmdPipelineBarrier(cl->command_buffer, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, 0, 0, NULL, 0, NULL, 1, &image_memory_barrier); + vkCmdPipelineBarrier(cl->command_buffer, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &image_memory_barrier); textures_to_sampled[i]->layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; @@ -6220,7 +6407,7 @@ void RenderingDeviceVulkan::compute_list_bind_uniform_set(ComputeListID p_list, VkImageMemoryBarrier image_memory_barrier; image_memory_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; - image_memory_barrier.pNext = NULL; + image_memory_barrier.pNext = nullptr; image_memory_barrier.srcAccessMask = VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT; image_memory_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT; image_memory_barrier.oldLayout = textures_to_storage[i]->layout; @@ -6230,12 +6417,12 @@ void RenderingDeviceVulkan::compute_list_bind_uniform_set(ComputeListID p_list, image_memory_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; image_memory_barrier.image = textures_to_storage[i]->image; image_memory_barrier.subresourceRange.aspectMask = textures_to_storage[i]->read_aspect_mask; - image_memory_barrier.subresourceRange.baseMipLevel = 0; + image_memory_barrier.subresourceRange.baseMipLevel = textures_to_storage[i]->base_mipmap; image_memory_barrier.subresourceRange.levelCount = textures_to_storage[i]->mipmaps; - image_memory_barrier.subresourceRange.baseArrayLayer = 0; + image_memory_barrier.subresourceRange.baseArrayLayer = textures_to_storage[i]->base_layer; image_memory_barrier.subresourceRange.layerCount = textures_to_storage[i]->layers; - vkCmdPipelineBarrier(cl->command_buffer, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT | VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, 0, 0, NULL, 0, NULL, 1, &image_memory_barrier); + vkCmdPipelineBarrier(cl->command_buffer, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT | VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &image_memory_barrier); textures_to_storage[i]->layout = VK_IMAGE_LAYOUT_GENERAL; @@ -6259,7 +6446,7 @@ void RenderingDeviceVulkan::compute_list_bind_uniform_set(ComputeListID p_list, #endif } -void RenderingDeviceVulkan::compute_list_set_push_constant(ComputeListID p_list, void *p_data, uint32_t p_data_size) { +void RenderingDeviceVulkan::compute_list_set_push_constant(ComputeListID p_list, const void *p_data, uint32_t p_data_size) { ERR_FAIL_COND(p_list != ID_TYPE_COMPUTE_LIST); ERR_FAIL_COND(!compute_list); @@ -6329,7 +6516,7 @@ void RenderingDeviceVulkan::compute_list_dispatch(ComputeListID p_list, uint32_t #endif if (!cl->state.sets[i].bound) { //All good, see if this requires re-binding - vkCmdBindDescriptorSets(cl->command_buffer, VK_PIPELINE_BIND_POINT_COMPUTE, cl->state.pipeline_layout, i, 1, &cl->state.sets[i].descriptor_set, 0, NULL); + vkCmdBindDescriptorSets(cl->command_buffer, VK_PIPELINE_BIND_POINT_COMPUTE, cl->state.pipeline_layout, i, 1, &cl->state.sets[i].descriptor_set, 0, nullptr); cl->state.sets[i].bound = true; } } @@ -6352,7 +6539,7 @@ void RenderingDeviceVulkan::compute_list_end() { VkImageMemoryBarrier image_memory_barrier; image_memory_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; - image_memory_barrier.pNext = NULL; + image_memory_barrier.pNext = nullptr; image_memory_barrier.srcAccessMask = VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT; image_memory_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; image_memory_barrier.oldLayout = E->get()->layout; @@ -6362,18 +6549,18 @@ void RenderingDeviceVulkan::compute_list_end() { image_memory_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; image_memory_barrier.image = E->get()->image; image_memory_barrier.subresourceRange.aspectMask = E->get()->read_aspect_mask; - image_memory_barrier.subresourceRange.baseMipLevel = 0; + image_memory_barrier.subresourceRange.baseMipLevel = E->get()->base_mipmap; image_memory_barrier.subresourceRange.levelCount = E->get()->mipmaps; - image_memory_barrier.subresourceRange.baseArrayLayer = 0; + image_memory_barrier.subresourceRange.baseArrayLayer = E->get()->base_layer; image_memory_barrier.subresourceRange.layerCount = E->get()->layers; - vkCmdPipelineBarrier(compute_list->command_buffer, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, 0, 0, NULL, 0, NULL, 1, &image_memory_barrier); + vkCmdPipelineBarrier(compute_list->command_buffer, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &image_memory_barrier); E->get()->layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; } memdelete(compute_list); - compute_list = NULL; + compute_list = nullptr; #ifdef FORCE_FULL_BARRIER _full_barrier(true); #else @@ -6389,7 +6576,7 @@ void RenderingDeviceVulkan::draw_list_render_secondary_to_framebuffer(ID p_frame VkRenderPassBeginInfo render_pass_begin; render_pass_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; - render_pass_begin.pNext = NULL; + render_pass_begin.pNext = nullptr; render_pass_begin.renderPass = context->get_render_pass(); render_pass_begin.framebuffer = context->get_frame_framebuffer(frame); @@ -6511,75 +6698,104 @@ void RenderingDeviceVulkan::free(RID p_id) { _free_dependencies(p_id); //recursively erase dependencies first, to avoid potential API problems _free_internal(p_id); } -void RenderingDeviceVulkan::swap_buffers() { - _THREAD_SAFE_METHOD_ +void RenderingDeviceVulkan::_finalize_command_bufers() { - { //finalize frame + if (draw_list) { + ERR_PRINT("Found open draw list at the end of the frame, this should never happen (further drawing will likely not work)."); + } - if (draw_list) { - ERR_PRINT("Found open draw list at the end of the frame, this should never happen (further drawing will likely not work)."); - } + if (compute_list) { + ERR_PRINT("Found open compute list at the end of the frame, this should never happen (further compute will likely not work)."); + } - if (compute_list) { - ERR_PRINT("Found open compute list at the end of the frame, this should never happen (further compute will likely not work)."); - } + { //complete the setup buffer (that needs to be processed before anything else) + vkEndCommandBuffer(frames[frame].setup_command_buffer); + vkEndCommandBuffer(frames[frame].draw_command_buffer); + } +} + +void RenderingDeviceVulkan::_begin_frame() { + + //erase pending resources + _free_pending_resources(frame); + + //create setup command buffer and set as the setup buffer + + { + VkCommandBufferBeginInfo cmdbuf_begin; + cmdbuf_begin.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; + cmdbuf_begin.pNext = nullptr; + cmdbuf_begin.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; + cmdbuf_begin.pInheritanceInfo = nullptr; + + VkResult err = vkResetCommandBuffer(frames[frame].setup_command_buffer, 0); + ERR_FAIL_COND_MSG(err, "vkResetCommandBuffer failed with error " + itos(err) + "."); - { //complete the setup buffer (that needs to be processed before anything else) - vkEndCommandBuffer(frames[frame].setup_command_buffer); - vkEndCommandBuffer(frames[frame].draw_command_buffer); + err = vkBeginCommandBuffer(frames[frame].setup_command_buffer, &cmdbuf_begin); + ERR_FAIL_COND_MSG(err, "vkBeginCommandBuffer failed with error " + itos(err) + "."); + err = vkBeginCommandBuffer(frames[frame].draw_command_buffer, &cmdbuf_begin); + ERR_FAIL_COND_MSG(err, "vkBeginCommandBuffer failed with error " + itos(err) + "."); + + if (local_device.is_null()) { + context->append_command_buffer(frames[frame].draw_command_buffer); + context->set_setup_buffer(frames[frame].setup_command_buffer); //append now so it's added before everything else } - screen_prepared = false; } - //swap buffers - context->swap_buffers(); + //advance current frame + frames_drawn++; + //advance staging buffer if used + if (staging_buffer_used) { + staging_buffer_current = (staging_buffer_current + 1) % staging_buffer_blocks.size(); + staging_buffer_used = false; + } - { //advance frame + if (frames[frame].timestamp_count) { + vkGetQueryPoolResults(device, frames[frame].timestamp_pool, 0, frames[frame].timestamp_count, sizeof(uint64_t) * max_timestamp_query_elements, frames[frame].timestamp_result_values, sizeof(uint64_t), VK_QUERY_RESULT_64_BIT); + SWAP(frames[frame].timestamp_names, frames[frame].timestamp_result_names); + SWAP(frames[frame].timestamp_cpu_values, frames[frame].timestamp_cpu_result_values); + } - frame = (frame + 1) % frame_count; + frames[frame].timestamp_result_count = frames[frame].timestamp_count; + frames[frame].timestamp_count = 0; + frames[frame].index = Engine::get_singleton()->get_frames_drawn(); +} - //erase pending resources - _free_pending_resources(frame); +void RenderingDeviceVulkan::swap_buffers() { - //create setup command buffer and set as the setup buffer + ERR_FAIL_COND_MSG(local_device.is_valid(), "Local devices can't swap buffers."); + _THREAD_SAFE_METHOD_ - { - VkCommandBufferBeginInfo cmdbuf_begin; - cmdbuf_begin.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; - cmdbuf_begin.pNext = NULL; - cmdbuf_begin.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; - cmdbuf_begin.pInheritanceInfo = NULL; + _finalize_command_bufers(); - VkResult err = vkResetCommandBuffer(frames[frame].setup_command_buffer, 0); - ERR_FAIL_COND_MSG(err, "vkResetCommandBuffer failed with error " + itos(err) + "."); + screen_prepared = false; + //swap buffers + context->swap_buffers(); - err = vkBeginCommandBuffer(frames[frame].setup_command_buffer, &cmdbuf_begin); - ERR_FAIL_COND_MSG(err, "vkBeginCommandBuffer failed with error " + itos(err) + "."); - context->set_setup_buffer(frames[frame].setup_command_buffer); //append now so it's added before everything else - err = vkBeginCommandBuffer(frames[frame].draw_command_buffer, &cmdbuf_begin); - ERR_FAIL_COND_MSG(err, "vkBeginCommandBuffer failed with error " + itos(err) + "."); - context->append_command_buffer(frames[frame].draw_command_buffer); - } + frame = (frame + 1) % frame_count; - //advance current frame - frames_drawn++; - //advance staging buffer if used - if (staging_buffer_used) { - staging_buffer_current = (staging_buffer_current + 1) % staging_buffer_blocks.size(); - staging_buffer_used = false; - } + _begin_frame(); +} - if (frames[frame].timestamp_count) { - vkGetQueryPoolResults(device, frames[frame].timestamp_pool, 0, frames[frame].timestamp_count, sizeof(uint64_t) * max_timestamp_query_elements, frames[frame].timestamp_result_values, sizeof(uint64_t), VK_QUERY_RESULT_64_BIT); - SWAP(frames[frame].timestamp_names, frames[frame].timestamp_result_names); - SWAP(frames[frame].timestamp_cpu_values, frames[frame].timestamp_cpu_result_values); - } +void RenderingDeviceVulkan::submit() { + ERR_FAIL_COND_MSG(local_device.is_null(), "Only local devices can submit and sync."); + ERR_FAIL_COND_MSG(local_device_processing, "device already submitted, call sync to wait until done."); - frames[frame].timestamp_result_count = frames[frame].timestamp_count; - frames[frame].timestamp_count = 0; - frames[frame].index = Engine::get_singleton()->get_frames_drawn(); - } + _finalize_command_bufers(); + + VkCommandBuffer command_buffers[2] = { frames[frame].setup_command_buffer, frames[frame].draw_command_buffer }; + context->local_device_push_command_buffers(local_device, command_buffers, 2); + local_device_processing = true; +} + +void RenderingDeviceVulkan::sync() { + + ERR_FAIL_COND_MSG(local_device.is_null(), "Only local devices can submit and sync."); + ERR_FAIL_COND_MSG(!local_device_processing, "sync can only be called after a submit"); + + context->local_device_sync(local_device); + _begin_frame(); } void RenderingDeviceVulkan::_free_pending_resources(int p_frame) { @@ -6588,7 +6804,7 @@ void RenderingDeviceVulkan::_free_pending_resources(int p_frame) { while (frames[p_frame].render_pipelines_to_dispose_of.front()) { RenderPipeline *pipeline = &frames[p_frame].render_pipelines_to_dispose_of.front()->get(); - vkDestroyPipeline(device, pipeline->pipeline, NULL); + vkDestroyPipeline(device, pipeline->pipeline, nullptr); frames[p_frame].render_pipelines_to_dispose_of.pop_front(); } @@ -6596,7 +6812,7 @@ void RenderingDeviceVulkan::_free_pending_resources(int p_frame) { while (frames[p_frame].compute_pipelines_to_dispose_of.front()) { ComputePipeline *pipeline = &frames[p_frame].compute_pipelines_to_dispose_of.front()->get(); - vkDestroyPipeline(device, pipeline->pipeline, NULL); + vkDestroyPipeline(device, pipeline->pipeline, nullptr); frames[p_frame].compute_pipelines_to_dispose_of.pop_front(); } @@ -6615,7 +6831,7 @@ void RenderingDeviceVulkan::_free_pending_resources(int p_frame) { while (frames[p_frame].buffer_views_to_dispose_of.front()) { VkBufferView buffer_view = frames[p_frame].buffer_views_to_dispose_of.front()->get(); - vkDestroyBufferView(device, buffer_view, NULL); + vkDestroyBufferView(device, buffer_view, nullptr); frames[p_frame].buffer_views_to_dispose_of.pop_front(); } @@ -6626,15 +6842,15 @@ void RenderingDeviceVulkan::_free_pending_resources(int p_frame) { //descriptor set layout for each set for (int i = 0; i < shader->sets.size(); i++) { - vkDestroyDescriptorSetLayout(device, shader->sets[i].descriptor_set_layout, NULL); + vkDestroyDescriptorSetLayout(device, shader->sets[i].descriptor_set_layout, nullptr); } //pipeline layout - vkDestroyPipelineLayout(device, shader->pipeline_layout, NULL); + vkDestroyPipelineLayout(device, shader->pipeline_layout, nullptr); //shaders themselves for (int i = 0; i < shader->pipeline_stages.size(); i++) { - vkDestroyShaderModule(device, shader->pipeline_stages[i].module, NULL); + vkDestroyShaderModule(device, shader->pipeline_stages[i].module, nullptr); } frames[p_frame].shaders_to_dispose_of.pop_front(); @@ -6644,7 +6860,7 @@ void RenderingDeviceVulkan::_free_pending_resources(int p_frame) { while (frames[p_frame].samplers_to_dispose_of.front()) { VkSampler sampler = frames[p_frame].samplers_to_dispose_of.front()->get(); - vkDestroySampler(device, sampler, NULL); + vkDestroySampler(device, sampler, nullptr); frames[p_frame].samplers_to_dispose_of.pop_front(); } @@ -6655,8 +6871,8 @@ void RenderingDeviceVulkan::_free_pending_resources(int p_frame) { for (Map<Framebuffer::VersionKey, Framebuffer::Version>::Element *E = framebuffer->framebuffers.front(); E; E = E->next()) { //first framebuffer, then render pass because it depends on it - vkDestroyFramebuffer(device, E->get().framebuffer, NULL); - vkDestroyRenderPass(device, E->get().render_pass, NULL); + vkDestroyFramebuffer(device, E->get().framebuffer, nullptr); + vkDestroyRenderPass(device, E->get().render_pass, nullptr); } frames[p_frame].framebuffers_to_dispose_of.pop_front(); @@ -6669,7 +6885,7 @@ void RenderingDeviceVulkan::_free_pending_resources(int p_frame) { if (texture->bound) { WARN_PRINT("Deleted a texture while it was bound.."); } - vkDestroyImageView(device, texture->view, NULL); + vkDestroyImageView(device, texture->view, nullptr); if (texture->owner.is_null()) { //actually owns the image and the allocation too vmaDestroyImage(allocator, texture->image, texture->allocation); @@ -6698,43 +6914,71 @@ uint32_t RenderingDeviceVulkan::get_frame_delay() const { void RenderingDeviceVulkan::_flush(bool p_current_frame) { + if (local_device.is_valid() && !p_current_frame) { + return; //flushign previous frames has no effect with local device + } //not doing this crashes RADV (undefined behavior) if (p_current_frame) { vkEndCommandBuffer(frames[frame].setup_command_buffer); vkEndCommandBuffer(frames[frame].draw_command_buffer); } - context->flush(p_current_frame, p_current_frame); - //re-create the setup command - if (p_current_frame) { + + if (local_device.is_valid()) { + + VkCommandBuffer command_buffers[2] = { frames[frame].setup_command_buffer, frames[frame].draw_command_buffer }; + context->local_device_push_command_buffers(local_device, command_buffers, 2); + context->local_device_sync(local_device); + VkCommandBufferBeginInfo cmdbuf_begin; cmdbuf_begin.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; - cmdbuf_begin.pNext = NULL; + cmdbuf_begin.pNext = nullptr; cmdbuf_begin.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; - cmdbuf_begin.pInheritanceInfo = NULL; + cmdbuf_begin.pInheritanceInfo = nullptr; VkResult err = vkBeginCommandBuffer(frames[frame].setup_command_buffer, &cmdbuf_begin); ERR_FAIL_COND_MSG(err, "vkBeginCommandBuffer failed with error " + itos(err) + "."); - context->set_setup_buffer(frames[frame].setup_command_buffer); //append now so it's added before everything else - } + err = vkBeginCommandBuffer(frames[frame].draw_command_buffer, &cmdbuf_begin); + ERR_FAIL_COND_MSG(err, "vkBeginCommandBuffer failed with error " + itos(err) + "."); - if (p_current_frame) { - VkCommandBufferBeginInfo cmdbuf_begin; - cmdbuf_begin.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; - cmdbuf_begin.pNext = NULL; - cmdbuf_begin.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; - cmdbuf_begin.pInheritanceInfo = NULL; + } else { + context->flush(p_current_frame, p_current_frame); + //re-create the setup command + if (p_current_frame) { + VkCommandBufferBeginInfo cmdbuf_begin; + cmdbuf_begin.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; + cmdbuf_begin.pNext = nullptr; + cmdbuf_begin.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; + cmdbuf_begin.pInheritanceInfo = nullptr; - VkResult err = vkBeginCommandBuffer(frames[frame].draw_command_buffer, &cmdbuf_begin); - ERR_FAIL_COND_MSG(err, "vkBeginCommandBuffer failed with error " + itos(err) + "."); - context->append_command_buffer(frames[frame].draw_command_buffer); + VkResult err = vkBeginCommandBuffer(frames[frame].setup_command_buffer, &cmdbuf_begin); + ERR_FAIL_COND_MSG(err, "vkBeginCommandBuffer failed with error " + itos(err) + "."); + context->set_setup_buffer(frames[frame].setup_command_buffer); //append now so it's added before everything else + } + + if (p_current_frame) { + VkCommandBufferBeginInfo cmdbuf_begin; + cmdbuf_begin.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; + cmdbuf_begin.pNext = nullptr; + cmdbuf_begin.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; + cmdbuf_begin.pInheritanceInfo = nullptr; + + VkResult err = vkBeginCommandBuffer(frames[frame].draw_command_buffer, &cmdbuf_begin); + ERR_FAIL_COND_MSG(err, "vkBeginCommandBuffer failed with error " + itos(err) + "."); + context->append_command_buffer(frames[frame].draw_command_buffer); + } } } -void RenderingDeviceVulkan::initialize(VulkanContext *p_context) { +void RenderingDeviceVulkan::initialize(VulkanContext *p_context, bool p_local_device) { context = p_context; device = p_context->get_device(); - frame_count = p_context->get_swapchain_image_count() + 1; //always need one extra to ensure it's unused at any time, without having to use a fence for this. + if (p_local_device) { + frame_count = 1; + local_device = p_context->local_device_create(); + } else { + frame_count = p_context->get_swapchain_image_count() + 1; //always need one extra to ensure it's unused at any time, without having to use a fence for this. + } limits = p_context->get_device_limits(); max_timestamp_query_elements = 256; @@ -6757,11 +7001,11 @@ void RenderingDeviceVulkan::initialize(VulkanContext *p_context) { { //create command pool, one per frame is recommended VkCommandPoolCreateInfo cmd_pool_info; cmd_pool_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; - cmd_pool_info.pNext = NULL; + cmd_pool_info.pNext = nullptr; cmd_pool_info.queueFamilyIndex = p_context->get_graphics_queue(); cmd_pool_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; - VkResult res = vkCreateCommandPool(device, &cmd_pool_info, NULL, &frames[i].command_pool); + VkResult res = vkCreateCommandPool(device, &cmd_pool_info, nullptr, &frames[i].command_pool); ERR_FAIL_COND_MSG(res, "vkCreateCommandPool failed with error " + itos(res) + "."); } @@ -6770,7 +7014,7 @@ void RenderingDeviceVulkan::initialize(VulkanContext *p_context) { VkCommandBufferAllocateInfo cmdbuf; //no command buffer exists, create it. cmdbuf.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; - cmdbuf.pNext = NULL; + cmdbuf.pNext = nullptr; cmdbuf.commandPool = frames[i].command_pool; cmdbuf.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; cmdbuf.commandBufferCount = 1; @@ -6787,12 +7031,12 @@ void RenderingDeviceVulkan::initialize(VulkanContext *p_context) { VkQueryPoolCreateInfo query_pool_create_info; query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO; query_pool_create_info.flags = 0; - query_pool_create_info.pNext = NULL; + query_pool_create_info.pNext = nullptr; query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP; query_pool_create_info.queryCount = max_timestamp_query_elements; query_pool_create_info.pipelineStatistics = 0; - vkCreateQueryPool(device, &query_pool_create_info, NULL, &frames[i].timestamp_pool); + vkCreateQueryPool(device, &query_pool_create_info, nullptr, &frames[i].timestamp_pool); frames[i].timestamp_names = memnew_arr(String, max_timestamp_query_elements); frames[i].timestamp_cpu_values = memnew_arr(uint64_t, max_timestamp_query_elements); @@ -6809,17 +7053,19 @@ void RenderingDeviceVulkan::initialize(VulkanContext *p_context) { //setting up things can be done in the meantime until swap_buffers(), which is called before advance. VkCommandBufferBeginInfo cmdbuf_begin; cmdbuf_begin.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; - cmdbuf_begin.pNext = NULL; + cmdbuf_begin.pNext = nullptr; cmdbuf_begin.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; - cmdbuf_begin.pInheritanceInfo = NULL; + cmdbuf_begin.pInheritanceInfo = nullptr; VkResult err = vkBeginCommandBuffer(frames[0].setup_command_buffer, &cmdbuf_begin); ERR_FAIL_COND_MSG(err, "vkBeginCommandBuffer failed with error " + itos(err) + "."); - context->set_setup_buffer(frames[0].setup_command_buffer); //append now so it's added before everything else err = vkBeginCommandBuffer(frames[0].draw_command_buffer, &cmdbuf_begin); ERR_FAIL_COND_MSG(err, "vkBeginCommandBuffer failed with error " + itos(err) + "."); - context->append_command_buffer(frames[0].draw_command_buffer); + if (local_device.is_null()) { + context->set_setup_buffer(frames[0].setup_command_buffer); //append now so it's added before everything else + context->append_command_buffer(frames[0].draw_command_buffer); + } } staging_buffer_block_size = GLOBAL_DEF("rendering/vulkan/staging_buffer/block_size_kb", 256); @@ -6853,11 +7099,11 @@ void RenderingDeviceVulkan::initialize(VulkanContext *p_context) { //check to make sure DescriptorPoolKey is good static_assert(sizeof(uint64_t) * 3 >= UNIFORM_TYPE_MAX * sizeof(uint16_t)); - draw_list = NULL; + draw_list = nullptr; draw_list_count = 0; draw_list_split = false; - compute_list = NULL; + compute_list = nullptr; } template <class T> @@ -6880,7 +7126,7 @@ void RenderingDeviceVulkan::capture_timestamp(const String &p_name, bool p_sync_ VkMemoryBarrier memoryBarrier; memoryBarrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER; - memoryBarrier.pNext = NULL; + memoryBarrier.pNext = nullptr; memoryBarrier.srcAccessMask = VK_ACCESS_INDIRECT_COMMAND_READ_BIT | VK_ACCESS_INDEX_READ_BIT | VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT | @@ -6912,7 +7158,7 @@ void RenderingDeviceVulkan::capture_timestamp(const String &p_name, bool p_sync_ VK_ACCESS_HOST_READ_BIT | VK_ACCESS_HOST_WRITE_BIT; - vkCmdPipelineBarrier(p_sync_to_draw ? frames[frame].draw_command_buffer : frames[frame].setup_command_buffer, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 1, &memoryBarrier, 0, NULL, 0, NULL); + vkCmdPipelineBarrier(p_sync_to_draw ? frames[frame].draw_command_buffer : frames[frame].setup_command_buffer, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 1, &memoryBarrier, 0, nullptr, 0, nullptr); } vkCmdWriteTimestamp(p_sync_to_draw ? frames[frame].draw_command_buffer : frames[frame].setup_command_buffer, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, frames[frame].timestamp_pool, frames[frame].timestamp_count); frames[frame].timestamp_names[frames[frame].timestamp_count] = p_name; @@ -6928,9 +7174,42 @@ uint64_t RenderingDeviceVulkan::get_captured_timestamps_frame() const { return frames[frame].index; } +static void mult64to128(uint64_t u, uint64_t v, uint64_t &h, uint64_t &l) { + uint64_t u1 = (u & 0xffffffff); + uint64_t v1 = (v & 0xffffffff); + uint64_t t = (u1 * v1); + uint64_t w3 = (t & 0xffffffff); + uint64_t k = (t >> 32); + + u >>= 32; + t = (u * v1) + k; + k = (t & 0xffffffff); + uint64_t w1 = (t >> 32); + + v >>= 32; + t = (u1 * v) + k; + k = (t >> 32); + + h = (u * v) + w1 + k; + l = (t << 32) + w3; +} + uint64_t RenderingDeviceVulkan::get_captured_timestamp_gpu_time(uint32_t p_index) const { ERR_FAIL_UNSIGNED_INDEX_V(p_index, frames[frame].timestamp_result_count, 0); - return frames[frame].timestamp_result_values[p_index] * limits.timestampPeriod; + + // this sucks because timestampPeriod multiplier is a float, while the timestamp is 64 bits nanosecs. + // so, in cases like nvidia which give you enormous numbers and 1 as multiplier, multiplying is next to impossible + // need to do 128 bits fixed point multiplication to get the rigth value + + uint64_t shift_bits = 16; + + uint64_t h, l; + + mult64to128(frames[frame].timestamp_result_values[p_index], uint64_t(double(limits.timestampPeriod) * double(1 << shift_bits)), h, l); + l >>= shift_bits; + l |= h << (64 - shift_bits); + + return l; } uint64_t RenderingDeviceVulkan::get_captured_timestamp_cpu_time(uint32_t p_index) const { ERR_FAIL_UNSIGNED_INDEX_V(p_index, frames[frame].timestamp_result_count, 0); @@ -7030,8 +7309,8 @@ void RenderingDeviceVulkan::finalize() { for (int i = 0; i < frame_count; i++) { int f = (frame + i) % frame_count; _free_pending_resources(f); - vkDestroyCommandPool(device, frames[i].command_pool, NULL); - vkDestroyQueryPool(device, frames[i].timestamp_pool, NULL); + vkDestroyCommandPool(device, frames[i].command_pool, nullptr); + vkDestroyQueryPool(device, frames[i].timestamp_pool, nullptr); memdelete_arr(frames[i].timestamp_names); memdelete_arr(frames[i].timestamp_cpu_values); memdelete_arr(frames[i].timestamp_result_names); @@ -7040,7 +7319,7 @@ void RenderingDeviceVulkan::finalize() { } for (int i = 0; i < split_draw_list_allocators.size(); i++) { - vkDestroyCommandPool(device, split_draw_list_allocators[i].command_pool, NULL); + vkDestroyCommandPool(device, split_draw_list_allocators[i].command_pool, nullptr); } memdelete_arr(frames); @@ -7048,6 +7327,19 @@ void RenderingDeviceVulkan::finalize() { for (int i = 0; i < staging_buffer_blocks.size(); i++) { vmaDestroyBuffer(allocator, staging_buffer_blocks[i].buffer, staging_buffer_blocks[i].allocation); } + vmaDestroyAllocator(allocator); + + while (vertex_formats.size()) { + Map<VertexFormatID, VertexDescriptionCache>::Element *temp = vertex_formats.front(); + memdelete_arr(temp->get().bindings); + memdelete_arr(temp->get().attributes); + vertex_formats.erase(temp); + } + + for (int i = 0; i < framebuffer_formats.size(); i++) { + vkDestroyRenderPass(device, framebuffer_formats[i].render_pass, nullptr); + } + framebuffer_formats.clear(); //all these should be clear at this point ERR_FAIL_COND(descriptor_pools.size()); @@ -7055,6 +7347,19 @@ void RenderingDeviceVulkan::finalize() { ERR_FAIL_COND(reverse_dependency_map.size()); } +RenderingDevice *RenderingDeviceVulkan::create_local_device() { + RenderingDeviceVulkan *rd = memnew(RenderingDeviceVulkan); + rd->initialize(context, true); + return rd; +} + RenderingDeviceVulkan::RenderingDeviceVulkan() { screen_prepared = false; } + +RenderingDeviceVulkan::~RenderingDeviceVulkan() { + if (local_device.is_valid()) { + finalize(); + context->local_device_free(local_device); + } +} diff --git a/drivers/vulkan/rendering_device_vulkan.h b/drivers/vulkan/rendering_device_vulkan.h index 4a224f0ceb..6432946fbe 100644 --- a/drivers/vulkan/rendering_device_vulkan.h +++ b/drivers/vulkan/rendering_device_vulkan.h @@ -34,11 +34,13 @@ #include "core/oa_hash_map.h" #include "core/os/thread_safe.h" #include "core/rid_owner.h" -#include "servers/visual/rendering_device.h" +#include "servers/rendering/rendering_device.h" #ifdef DEBUG_ENABLED +#ifndef _DEBUG #define _DEBUG #endif +#endif #include "vk_mem_alloc.h" #include <vulkan/vulkan.h> //todo: @@ -78,7 +80,7 @@ class RenderingDeviceVulkan : public RenderingDevice { static void get_compressed_image_format_block_dimensions(DataFormat p_format, uint32_t &r_w, uint32_t &r_h); uint32_t get_compressed_image_format_block_byte_size(DataFormat p_format); static uint32_t get_compressed_image_format_pixel_rshift(DataFormat p_format); - static uint32_t get_image_format_required_size(DataFormat p_format, uint32_t p_width, uint32_t p_height, uint32_t p_depth, uint32_t p_mipmaps, uint32_t *r_blockw = NULL, uint32_t *r_blockh = NULL, uint32_t *r_depth = NULL); + static uint32_t get_image_format_required_size(DataFormat p_format, uint32_t p_width, uint32_t p_height, uint32_t p_depth, uint32_t p_mipmaps, uint32_t *r_blockw = nullptr, uint32_t *r_blockh = nullptr, uint32_t *r_depth = nullptr); static uint32_t get_image_required_mipmaps(uint32_t p_width, uint32_t p_height, uint32_t p_depth); static bool format_has_stencil(DataFormat p_format); @@ -136,6 +138,8 @@ class RenderingDeviceVulkan : public RenderingDevice { uint32_t layers; uint32_t mipmaps; uint32_t usage_flags; + uint32_t base_mipmap; + uint32_t base_layer; Vector<DataFormat> allowed_shared_formats; @@ -207,8 +211,8 @@ class RenderingDeviceVulkan : public RenderingDevice { VkDescriptorBufferInfo buffer_info; //used for binding Buffer() { size = 0; - buffer = NULL; - allocation = NULL; + buffer = VK_NULL_HANDLE; + allocation = nullptr; } }; @@ -260,7 +264,7 @@ class RenderingDeviceVulkan : public RenderingDevice { } }; - VkRenderPass _render_pass_create(const Vector<AttachmentFormat> &p_format, InitialAction p_initial_action, FinalAction p_final_action, InitialAction p_initial_depth_action, FinalAction p_final_depthcolor_action, int *r_color_attachment_count = NULL); + VkRenderPass _render_pass_create(const Vector<AttachmentFormat> &p_format, InitialAction p_initial_action, FinalAction p_final_action, InitialAction p_initial_depth_action, FinalAction p_final_depthcolor_action, int *r_color_attachment_count = nullptr); // This is a cache and it's never freed, it ensures // IDs for a given format are always unique. @@ -328,7 +332,7 @@ class RenderingDeviceVulkan : public RenderingDevice { RID_Owner<Buffer, true> vertex_buffer_owner; struct VertexDescriptionKey { - Vector<VertexDescription> vertex_formats; + Vector<VertexAttribute> vertex_formats; bool operator==(const VertexDescriptionKey &p_key) const { int vdc = vertex_formats.size(); int vdck = p_key.vertex_formats.size(); @@ -336,11 +340,11 @@ class RenderingDeviceVulkan : public RenderingDevice { if (vdc != vdck) { return false; } else { - const VertexDescription *a_ptr = vertex_formats.ptr(); - const VertexDescription *b_ptr = p_key.vertex_formats.ptr(); + const VertexAttribute *a_ptr = vertex_formats.ptr(); + const VertexAttribute *b_ptr = p_key.vertex_formats.ptr(); for (int i = 0; i < vdc; i++) { - const VertexDescription &a = a_ptr[i]; - const VertexDescription &b = b_ptr[i]; + const VertexAttribute &a = a_ptr[i]; + const VertexAttribute &b = b_ptr[i]; if (a.location != b.location) { return false; @@ -365,9 +369,9 @@ class RenderingDeviceVulkan : public RenderingDevice { uint32_t hash() const { int vdc = vertex_formats.size(); uint32_t h = hash_djb2_one_32(vdc); - const VertexDescription *ptr = vertex_formats.ptr(); + const VertexAttribute *ptr = vertex_formats.ptr(); for (int i = 0; i < vdc; i++) { - const VertexDescription &vd = ptr[i]; + const VertexAttribute &vd = ptr[i]; h = hash_djb2_one_32(vd.location, h); h = hash_djb2_one_32(vd.offset, h); h = hash_djb2_one_32(vd.format, h); @@ -389,7 +393,7 @@ class RenderingDeviceVulkan : public RenderingDevice { HashMap<VertexDescriptionKey, VertexFormatID, VertexDescriptionHash> vertex_format_cache; struct VertexDescriptionCache { - Vector<VertexDescription> vertex_formats; + Vector<VertexAttribute> vertex_formats; VkVertexInputBindingDescription *bindings; VkVertexInputAttributeDescription *attributes; VkPipelineVertexInputStateCreateInfo create_info; @@ -948,10 +952,12 @@ class RenderingDeviceVulkan : public RenderingDevice { uint32_t max_timestamp_query_elements; - Frame *frames; //frames available, they are cycled (usually 3) + Frame *frames; //frames available, for main device they are cycled (usually 3), for local devices only 1 int frame; //current frame int frame_count; //total amount of frames uint64_t frames_drawn; + RID local_device; + bool local_device_processing = false; void _free_pending_resources(int p_frame); @@ -967,6 +973,9 @@ class RenderingDeviceVulkan : public RenderingDevice { template <class T> void _free_rids(T &p_owner, const char *p_type); + void _finalize_command_bufers(); + void _begin_frame(); + public: virtual RID texture_create(const TextureFormat &p_format, const TextureView &p_view, const Vector<Vector<uint8_t>> &p_data = Vector<Vector<uint8_t>>()); virtual RID texture_create_shared(const TextureView &p_view, RID p_with_texture); @@ -981,6 +990,7 @@ public: virtual Error texture_copy(RID p_from_texture, RID p_to_texture, const Vector3 &p_from, const Vector3 &p_to, const Vector3 &p_size, uint32_t p_src_mipmap, uint32_t p_dst_mipmap, uint32_t p_src_layer, uint32_t p_dst_layer, bool p_sync_with_draw = false); virtual Error texture_clear(RID p_texture, const Color &p_color, uint32_t p_base_mipmap, uint32_t p_mipmaps, uint32_t p_base_layer, uint32_t p_layers, bool p_sync_with_draw = false); + virtual Error texture_resolve_multisample(RID p_from_texture, RID p_to_texture, bool p_sync_with_draw = false); /*********************/ /**** FRAMEBUFFER ****/ @@ -1006,7 +1016,7 @@ public: virtual RID vertex_buffer_create(uint32_t p_size_bytes, const Vector<uint8_t> &p_data = Vector<uint8_t>()); // Internally reference counted, this ID is warranted to be unique for the same description, but needs to be freed as many times as it was allocated - virtual VertexFormatID vertex_format_create(const Vector<VertexDescription> &p_vertex_formats); + virtual VertexFormatID vertex_format_create(const Vector<VertexAttribute> &p_vertex_formats); virtual RID vertex_array_create(uint32_t p_vertex_count, VertexFormatID p_vertex_format, const Vector<RID> &p_src_buffers); virtual RID index_buffer_create(uint32_t p_size_indices, IndexBufferFormat p_format, const Vector<uint8_t> &p_data = Vector<uint8_t>(), bool p_use_restart_indices = false); @@ -1052,15 +1062,15 @@ public: /**** SCREEN ****/ /****************/ - virtual int screen_get_width(int p_screen = 0) const; - virtual int screen_get_height(int p_screen = 0) const; + virtual int screen_get_width(DisplayServer::WindowID p_screen = 0) const; + virtual int screen_get_height(DisplayServer::WindowID p_screen = 0) const; virtual FramebufferFormatID screen_get_framebuffer_format() const; /********************/ /**** DRAW LISTS ****/ /********************/ - virtual DrawListID draw_list_begin_for_screen(int p_screen = 0, const Color &p_clear_color = Color()); + virtual DrawListID draw_list_begin_for_screen(DisplayServer::WindowID p_screen = 0, const Color &p_clear_color = Color()); virtual DrawListID draw_list_begin(RID p_framebuffer, InitialAction p_initial_color_action, FinalAction p_final_color_action, InitialAction p_initial_depth_action, FinalAction p_final_depth_action, const Vector<Color> &p_clear_color_values = Vector<Color>(), float p_clear_depth = 1.0, uint32_t p_clear_stencil = 0, const Rect2 &p_region = Rect2()); virtual Error draw_list_begin_split(RID p_framebuffer, uint32_t p_splits, DrawListID *r_split_ids, InitialAction p_initial_color_action, FinalAction p_final_color_action, InitialAction p_initial_depth_action, FinalAction p_final_depth_action, const Vector<Color> &p_clear_color_values = Vector<Color>(), float p_clear_depth = 1.0, uint32_t p_clear_stencil = 0, const Rect2 &p_region = Rect2()); @@ -1070,7 +1080,7 @@ public: virtual void draw_list_bind_vertex_array(DrawListID p_list, RID p_vertex_array); virtual void draw_list_bind_index_array(DrawListID p_list, RID p_index_array); virtual void draw_list_set_line_width(DrawListID p_list, float p_width); - virtual void draw_list_set_push_constant(DrawListID p_list, void *p_data, uint32_t p_data_size); + virtual void draw_list_set_push_constant(DrawListID p_list, const void *p_data, uint32_t p_data_size); virtual void draw_list_draw(DrawListID p_list, bool p_use_indices, uint32_t p_instances = 1, uint32_t p_procedural_vertices = 0); @@ -1086,7 +1096,7 @@ public: virtual ComputeListID compute_list_begin(); virtual void compute_list_bind_compute_pipeline(ComputeListID p_list, RID p_compute_pipeline); virtual void compute_list_bind_uniform_set(ComputeListID p_list, RID p_uniform_set, uint32_t p_index); - virtual void compute_list_set_push_constant(ComputeListID p_list, void *p_data, uint32_t p_data_size); + virtual void compute_list_set_push_constant(ComputeListID p_list, const void *p_data, uint32_t p_data_size); virtual void compute_list_add_barrier(ComputeListID p_list); virtual void compute_list_dispatch(ComputeListID p_list, uint32_t p_x_groups, uint32_t p_y_groups, uint32_t p_z_groups); @@ -1116,14 +1126,20 @@ public: virtual int limit_get(Limit p_limit); virtual void prepare_screen_for_drawing(); - void initialize(VulkanContext *p_context); + void initialize(VulkanContext *p_context, bool p_local_device = false); void finalize(); - virtual void swap_buffers(); + virtual void swap_buffers(); //for main device + + virtual void submit(); //for local device + virtual void sync(); //for local device virtual uint32_t get_frame_delay() const; + virtual RenderingDevice *create_local_device(); + RenderingDeviceVulkan(); + ~RenderingDeviceVulkan(); }; #endif // RENDERING_DEVICE_VULKAN_H diff --git a/drivers/vulkan/vulkan_context.cpp b/drivers/vulkan/vulkan_context.cpp index c8ff342713..d293abdee3 100644 --- a/drivers/vulkan/vulkan_context.cpp +++ b/drivers/vulkan/vulkan_context.cpp @@ -51,20 +51,20 @@ VKAPI_ATTR VkBool32 VKAPI_CALL VulkanContext::_debug_messenger_callback( void *pUserData) { // This error needs to be ignored because the AMD allocator will mix up memory types on IGP processors. - if (strstr(pCallbackData->pMessage, "Mapping an image with layout") != NULL && - strstr(pCallbackData->pMessage, "can result in undefined behavior if this memory is used by the device") != NULL) { + if (strstr(pCallbackData->pMessage, "Mapping an image with layout") != nullptr && + strstr(pCallbackData->pMessage, "can result in undefined behavior if this memory is used by the device") != nullptr) { return VK_FALSE; } // This needs to be ignored because Validator is wrong here. - if (strstr(pCallbackData->pMessage, "SPIR-V module not valid: Pointer operand") != NULL && - strstr(pCallbackData->pMessage, "must be a memory object") != NULL) { + if (strstr(pCallbackData->pMessage, "SPIR-V module not valid: Pointer operand") != nullptr && + strstr(pCallbackData->pMessage, "must be a memory object") != nullptr) { return VK_FALSE; } // Workaround for Vulkan-Loader usability bug: https://github.com/KhronosGroup/Vulkan-Loader/issues/262. - if (strstr(pCallbackData->pMessage, "wrong ELF class: ELFCLASS32") != NULL) { + if (strstr(pCallbackData->pMessage, "wrong ELF class: ELFCLASS32") != nullptr) { return VK_FALSE; } - if (pCallbackData->pMessageIdName && strstr(pCallbackData->pMessageIdName, "UNASSIGNED-CoreValidation-DrawState-ClearCmdBeforeDraw") != NULL) { + if (pCallbackData->pMessageIdName && strstr(pCallbackData->pMessageIdName, "UNASSIGNED-CoreValidation-DrawState-ClearCmdBeforeDraw") != nullptr) { return VK_FALSE; } @@ -92,7 +92,7 @@ VKAPI_ATTR VkBool32 VKAPI_CALL VulkanContext::_debug_messenger_callback( "\n\t\tObject[" + String::num_int64(object) + "]" + " - " + string_VkObjectType(pCallbackData->pObjects[object].objectType) + ", Handle " + String::num_int64(pCallbackData->pObjects[object].objectHandle); - if (NULL != pCallbackData->pObjects[object].pObjectName && strlen(pCallbackData->pObjects[object].pObjectName) > 0) { + if (nullptr != pCallbackData->pObjects[object].pObjectName && strlen(pCallbackData->pObjects[object].pObjectName) > 0) { objects_string += ", Name \"" + String(pCallbackData->pObjects[object].pObjectName) + "\""; } } @@ -165,16 +165,17 @@ VkBool32 VulkanContext::_check_layers(uint32_t check_count, const char **check_n Error VulkanContext::_create_validation_layers() { VkResult err; + const char *instance_validation_layers_alt1[] = { "VK_LAYER_KHRONOS_validation" }; + const char *instance_validation_layers_alt2[] = { "VK_LAYER_LUNARG_standard_validation" }; + const char *instance_validation_layers_alt3[] = { "VK_LAYER_GOOGLE_threading", "VK_LAYER_LUNARG_parameter_validation", "VK_LAYER_LUNARG_object_tracker", "VK_LAYER_LUNARG_core_validation", "VK_LAYER_GOOGLE_unique_objects" }; + uint32_t instance_layer_count = 0; - uint32_t validation_layer_count = 0; - const char *instance_validation_layers_alt1[] = { "VK_LAYER_LUNARG_standard_validation" }; - const char *instance_validation_layers_alt2[] = { "VK_LAYER_GOOGLE_threading", "VK_LAYER_LUNARG_parameter_validation", - "VK_LAYER_LUNARG_object_tracker", "VK_LAYER_LUNARG_core_validation", - "VK_LAYER_GOOGLE_unique_objects" }; - VkBool32 validation_found = 0; - err = vkEnumerateInstanceLayerProperties(&instance_layer_count, NULL); + err = vkEnumerateInstanceLayerProperties(&instance_layer_count, nullptr); ERR_FAIL_COND_V(err, ERR_CANT_CREATE); - const char **instance_validation_layers = instance_validation_layers_alt1; + + VkBool32 validation_found = 0; + uint32_t validation_layer_count = 0; + const char **instance_validation_layers = nullptr; if (instance_layer_count > 0) { VkLayerProperties *instance_layers = (VkLayerProperties *)malloc(sizeof(VkLayerProperties) * instance_layer_count); err = vkEnumerateInstanceLayerProperties(&instance_layer_count, instance_layers); @@ -183,27 +184,33 @@ Error VulkanContext::_create_validation_layers() { ERR_FAIL_V(ERR_CANT_CREATE); } - validation_found = _check_layers(ARRAY_SIZE(instance_validation_layers_alt1), instance_validation_layers, - instance_layer_count, instance_layers); - if (validation_found) { - enabled_layer_count = ARRAY_SIZE(instance_validation_layers_alt1); - enabled_layers[0] = "VK_LAYER_LUNARG_standard_validation"; - validation_layer_count = 1; - } else { - // use alternative set of validation layers - instance_validation_layers = instance_validation_layers_alt2; - enabled_layer_count = ARRAY_SIZE(instance_validation_layers_alt2); - validation_found = _check_layers(ARRAY_SIZE(instance_validation_layers_alt2), instance_validation_layers, - instance_layer_count, instance_layers); + validation_layer_count = ARRAY_SIZE(instance_validation_layers_alt1); + instance_validation_layers = instance_validation_layers_alt1; + validation_found = _check_layers(validation_layer_count, instance_validation_layers, instance_layer_count, instance_layers); + + // use alternative (deprecated, removed in SDK 1.1.126.0) set of validation layers + if (!validation_found) { validation_layer_count = ARRAY_SIZE(instance_validation_layers_alt2); - for (uint32_t i = 0; i < validation_layer_count; i++) { - enabled_layers[i] = instance_validation_layers[i]; - } + instance_validation_layers = instance_validation_layers_alt2; + validation_found = _check_layers(validation_layer_count, instance_validation_layers, instance_layer_count, instance_layers); } + + // use alternative (deprecated, removed in SDK 1.1.121.1) set of validation layers + if (!validation_found) { + validation_layer_count = ARRAY_SIZE(instance_validation_layers_alt3); + instance_validation_layers = instance_validation_layers_alt3; + validation_found = _check_layers(validation_layer_count, instance_validation_layers, instance_layer_count, instance_layers); + } + free(instance_layers); } - if (!validation_found) { + if (validation_found) { + enabled_layer_count = validation_layer_count; + for (uint32_t i = 0; i < validation_layer_count; i++) { + enabled_layers[i] = instance_validation_layers[i]; + } + } else { return ERR_CANT_CREATE; } @@ -222,12 +229,12 @@ Error VulkanContext::_initialize_extensions() { VkBool32 platformSurfaceExtFound = 0; memset(extension_names, 0, sizeof(extension_names)); - err = vkEnumerateInstanceExtensionProperties(NULL, &instance_extension_count, NULL); + err = vkEnumerateInstanceExtensionProperties(nullptr, &instance_extension_count, nullptr); ERR_FAIL_COND_V(err, ERR_CANT_CREATE); if (instance_extension_count > 0) { VkExtensionProperties *instance_extensions = (VkExtensionProperties *)malloc(sizeof(VkExtensionProperties) * instance_extension_count); - err = vkEnumerateInstanceExtensionProperties(NULL, &instance_extension_count, instance_extensions); + err = vkEnumerateInstanceExtensionProperties(nullptr, &instance_extension_count, instance_extensions); if (err) { free(instance_extensions); ERR_FAIL_V(ERR_CANT_CREATE); @@ -286,7 +293,7 @@ Error VulkanContext::_create_physical_device() { CharString namecs = name.utf8(); const VkApplicationInfo app = { /*sType*/ VK_STRUCTURE_TYPE_APPLICATION_INFO, - /*pNext*/ NULL, + /*pNext*/ nullptr, /*pApplicationName*/ cs.get_data(), /*applicationVersion*/ 0, /*pEngineName*/ namecs.get_data(), @@ -295,7 +302,7 @@ Error VulkanContext::_create_physical_device() { }; VkInstanceCreateInfo inst_info = { /*sType*/ VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, - /*pNext*/ NULL, + /*pNext*/ nullptr, /*flags*/ 0, /*pApplicationInfo*/ &app, /*enabledLayerCount*/ enabled_layer_count, @@ -313,7 +320,7 @@ Error VulkanContext::_create_physical_device() { if (use_validation_layers) { // VK_EXT_debug_utils style dbg_messenger_create_info.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT; - dbg_messenger_create_info.pNext = NULL; + dbg_messenger_create_info.pNext = nullptr; dbg_messenger_create_info.flags = 0; dbg_messenger_create_info.messageSeverity = VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT; @@ -327,7 +334,7 @@ Error VulkanContext::_create_physical_device() { uint32_t gpu_count; - VkResult err = vkCreateInstance(&inst_info, NULL, &inst); + VkResult err = vkCreateInstance(&inst_info, nullptr, &inst); ERR_FAIL_COND_V_MSG(err == VK_ERROR_INCOMPATIBLE_DRIVER, ERR_CANT_CREATE, "Cannot find a compatible Vulkan installable client driver (ICD).\n\n" "vkCreateInstance Failure"); @@ -342,7 +349,7 @@ Error VulkanContext::_create_physical_device() { "vkCreateInstance Failure"); /* Make initial call to query gpu_count, then second call for gpu info*/ - err = vkEnumeratePhysicalDevices(inst, &gpu_count, NULL); + err = vkEnumeratePhysicalDevices(inst, &gpu_count, nullptr); ERR_FAIL_COND_V(err, ERR_CANT_CREATE); ERR_FAIL_COND_V_MSG(gpu_count == 0, ERR_CANT_CREATE, @@ -366,12 +373,12 @@ Error VulkanContext::_create_physical_device() { enabled_extension_count = 0; memset(extension_names, 0, sizeof(extension_names)); - err = vkEnumerateDeviceExtensionProperties(gpu, NULL, &device_extension_count, NULL); + err = vkEnumerateDeviceExtensionProperties(gpu, nullptr, &device_extension_count, nullptr); ERR_FAIL_COND_V(err, ERR_CANT_CREATE); if (device_extension_count > 0) { VkExtensionProperties *device_extensions = (VkExtensionProperties *)malloc(sizeof(VkExtensionProperties) * device_extension_count); - err = vkEnumerateDeviceExtensionProperties(gpu, NULL, &device_extension_count, device_extensions); + err = vkEnumerateDeviceExtensionProperties(gpu, nullptr, &device_extension_count, device_extensions); if (err) { free(device_extensions); ERR_FAIL_V(ERR_CANT_CREATE); @@ -449,16 +456,16 @@ Error VulkanContext::_create_physical_device() { (PFN_vkCmdInsertDebugUtilsLabelEXT)vkGetInstanceProcAddr(inst, "vkCmdInsertDebugUtilsLabelEXT"); SetDebugUtilsObjectNameEXT = (PFN_vkSetDebugUtilsObjectNameEXT)vkGetInstanceProcAddr(inst, "vkSetDebugUtilsObjectNameEXT"); - if (NULL == CreateDebugUtilsMessengerEXT || NULL == DestroyDebugUtilsMessengerEXT || - NULL == SubmitDebugUtilsMessageEXT || NULL == CmdBeginDebugUtilsLabelEXT || - NULL == CmdEndDebugUtilsLabelEXT || NULL == CmdInsertDebugUtilsLabelEXT || - NULL == SetDebugUtilsObjectNameEXT) { + if (nullptr == CreateDebugUtilsMessengerEXT || nullptr == DestroyDebugUtilsMessengerEXT || + nullptr == SubmitDebugUtilsMessageEXT || nullptr == CmdBeginDebugUtilsLabelEXT || + nullptr == CmdEndDebugUtilsLabelEXT || nullptr == CmdInsertDebugUtilsLabelEXT || + nullptr == SetDebugUtilsObjectNameEXT) { ERR_FAIL_V_MSG(ERR_CANT_CREATE, "GetProcAddr: Failed to init VK_EXT_debug_utils\n" "GetProcAddr: Failure"); } - err = CreateDebugUtilsMessengerEXT(inst, &dbg_messenger_create_info, NULL, &dbg_messenger); + err = CreateDebugUtilsMessengerEXT(inst, &dbg_messenger_create_info, nullptr, &dbg_messenger); switch (err) { case VK_SUCCESS: break; @@ -478,7 +485,7 @@ Error VulkanContext::_create_physical_device() { vkGetPhysicalDeviceProperties(gpu, &gpu_props); /* Call with NULL data to get count */ - vkGetPhysicalDeviceQueueFamilyProperties(gpu, &queue_family_count, NULL); + vkGetPhysicalDeviceQueueFamilyProperties(gpu, &queue_family_count, nullptr); ERR_FAIL_COND_V(queue_family_count == 0, ERR_CANT_CREATE); queue_props = (VkQueueFamilyProperties *)malloc(queue_family_count * sizeof(VkQueueFamilyProperties)); @@ -492,7 +499,7 @@ Error VulkanContext::_create_physical_device() { #define GET_INSTANCE_PROC_ADDR(inst, entrypoint) \ { \ fp##entrypoint = (PFN_vk##entrypoint)vkGetInstanceProcAddr(inst, "vk" #entrypoint); \ - ERR_FAIL_COND_V_MSG(fp##entrypoint == NULL, ERR_CANT_CREATE, \ + ERR_FAIL_COND_V_MSG(fp##entrypoint == nullptr, ERR_CANT_CREATE, \ "vkGetInstanceProcAddr failed to find vk" #entrypoint); \ } @@ -511,7 +518,7 @@ Error VulkanContext::_create_device() { float queue_priorities[1] = { 0.0 }; VkDeviceQueueCreateInfo queues[2]; queues[0].sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; - queues[0].pNext = NULL; + queues[0].pNext = nullptr; queues[0].queueFamilyIndex = graphics_queue_family_index; queues[0].queueCount = 1; queues[0].pQueuePriorities = queue_priorities; @@ -519,12 +526,12 @@ Error VulkanContext::_create_device() { VkDeviceCreateInfo sdevice = { /*sType*/ VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, - /*pNext*/ NULL, + /*pNext*/ nullptr, /*flags*/ 0, /*queueCreateInfoCount*/ 1, /*pQueueCreateInfos*/ queues, /*enabledLayerCount*/ 0, - /*ppEnabledLayerNames*/ NULL, + /*ppEnabledLayerNames*/ nullptr, /*enabledExtensionCount*/ enabled_extension_count, /*ppEnabledExtensionNames*/ (const char *const *)extension_names, /*pEnabledFeatures*/ &physical_device_features, // If specific features are required, pass them in here @@ -532,14 +539,14 @@ Error VulkanContext::_create_device() { }; if (separate_present_queue) { queues[1].sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; - queues[1].pNext = NULL; + queues[1].pNext = nullptr; queues[1].queueFamilyIndex = present_queue_family_index; queues[1].queueCount = 1; queues[1].pQueuePriorities = queue_priorities; queues[1].flags = 0; sdevice.queueCreateInfoCount = 2; } - err = vkCreateDevice(gpu, &sdevice, NULL, &device); + err = vkCreateDevice(gpu, &sdevice, nullptr, &device); ERR_FAIL_COND_V(err, ERR_CANT_CREATE); return OK; } @@ -593,12 +600,12 @@ Error VulkanContext::_initialize_queues(VkSurfaceKHR surface) { _create_device(); - static PFN_vkGetDeviceProcAddr g_gdpa = NULL; + static PFN_vkGetDeviceProcAddr g_gdpa = nullptr; #define GET_DEVICE_PROC_ADDR(dev, entrypoint) \ { \ if (!g_gdpa) g_gdpa = (PFN_vkGetDeviceProcAddr)vkGetInstanceProcAddr(inst, "vkGetDeviceProcAddr"); \ fp##entrypoint = (PFN_vk##entrypoint)g_gdpa(dev, "vk" #entrypoint); \ - ERR_FAIL_COND_V_MSG(fp##entrypoint == NULL, ERR_CANT_CREATE, \ + ERR_FAIL_COND_V_MSG(fp##entrypoint == nullptr, ERR_CANT_CREATE, \ "vkGetDeviceProcAddr failed to find vk" #entrypoint); \ } @@ -622,7 +629,7 @@ Error VulkanContext::_initialize_queues(VkSurfaceKHR surface) { // Get the list of VkFormat's that are supported: uint32_t formatCount; - VkResult err = fpGetPhysicalDeviceSurfaceFormatsKHR(gpu, surface, &formatCount, NULL); + VkResult err = fpGetPhysicalDeviceSurfaceFormatsKHR(gpu, surface, &formatCount, nullptr); ERR_FAIL_COND_V(err, ERR_CANT_CREATE); VkSurfaceFormatKHR *surfFormats = (VkSurfaceFormatKHR *)malloc(formatCount * sizeof(VkSurfaceFormatKHR)); err = fpGetPhysicalDeviceSurfaceFormatsKHR(gpu, surface, &formatCount, surfFormats); @@ -662,7 +669,7 @@ Error VulkanContext::_create_semaphores() { // rendering and waiting for drawing to be complete before presenting VkSemaphoreCreateInfo semaphoreCreateInfo = { /*sType*/ VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, - /*pNext*/ NULL, + /*pNext*/ nullptr, /*flags*/ 0, }; @@ -670,21 +677,21 @@ Error VulkanContext::_create_semaphores() { // ahead of the image presents VkFenceCreateInfo fence_ci = { /*sType*/ VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, - /*pNext*/ NULL, + /*pNext*/ nullptr, /*flags*/ VK_FENCE_CREATE_SIGNALED_BIT }; for (uint32_t i = 0; i < FRAME_LAG; i++) { - err = vkCreateFence(device, &fence_ci, NULL, &fences[i]); + err = vkCreateFence(device, &fence_ci, nullptr, &fences[i]); ERR_FAIL_COND_V(err, ERR_CANT_CREATE); - err = vkCreateSemaphore(device, &semaphoreCreateInfo, NULL, &image_acquired_semaphores[i]); + err = vkCreateSemaphore(device, &semaphoreCreateInfo, nullptr, &image_acquired_semaphores[i]); ERR_FAIL_COND_V(err, ERR_CANT_CREATE); - err = vkCreateSemaphore(device, &semaphoreCreateInfo, NULL, &draw_complete_semaphores[i]); + err = vkCreateSemaphore(device, &semaphoreCreateInfo, nullptr, &draw_complete_semaphores[i]); ERR_FAIL_COND_V(err, ERR_CANT_CREATE); if (separate_present_queue) { - err = vkCreateSemaphore(device, &semaphoreCreateInfo, NULL, &image_ownership_semaphores[i]); + err = vkCreateSemaphore(device, &semaphoreCreateInfo, nullptr, &image_ownership_semaphores[i]); ERR_FAIL_COND_V(err, ERR_CANT_CREATE); } } @@ -696,7 +703,9 @@ Error VulkanContext::_create_semaphores() { return OK; } -int VulkanContext::_window_create(VkSurfaceKHR p_surface, int p_width, int p_height) { +Error VulkanContext::_window_create(DisplayServer::WindowID p_window_id, VkSurfaceKHR p_surface, int p_width, int p_height) { + + ERR_FAIL_COND_V(windows.has(p_window_id), ERR_INVALID_PARAMETER); if (!queues_initialized) { // We use a single GPU, but we need a surface to initialize the @@ -710,39 +719,37 @@ int VulkanContext::_window_create(VkSurfaceKHR p_surface, int p_width, int p_hei window.width = p_width; window.height = p_height; Error err = _update_swap_chain(&window); - ERR_FAIL_COND_V(err != OK, -1); + ERR_FAIL_COND_V(err != OK, ERR_CANT_CREATE); - int id = last_window_id; - windows[id] = window; - last_window_id++; - return id; + windows[p_window_id] = window; + return OK; } -void VulkanContext::window_resize(int p_window, int p_width, int p_height) { +void VulkanContext::window_resize(DisplayServer::WindowID p_window, int p_width, int p_height) { ERR_FAIL_COND(!windows.has(p_window)); windows[p_window].width = p_width; windows[p_window].height = p_height; _update_swap_chain(&windows[p_window]); } -int VulkanContext::window_get_width(int p_window) { +int VulkanContext::window_get_width(DisplayServer::WindowID p_window) { ERR_FAIL_COND_V(!windows.has(p_window), -1); return windows[p_window].width; } -int VulkanContext::window_get_height(int p_window) { +int VulkanContext::window_get_height(DisplayServer::WindowID p_window) { ERR_FAIL_COND_V(!windows.has(p_window), -1); return windows[p_window].height; } -VkRenderPass VulkanContext::window_get_render_pass(int p_window) { +VkRenderPass VulkanContext::window_get_render_pass(DisplayServer::WindowID p_window) { ERR_FAIL_COND_V(!windows.has(p_window), VK_NULL_HANDLE); Window *w = &windows[p_window]; //vulkan use of currentbuffer return w->render_pass; } -VkFramebuffer VulkanContext::window_get_framebuffer(int p_window) { +VkFramebuffer VulkanContext::window_get_framebuffer(DisplayServer::WindowID p_window) { ERR_FAIL_COND_V(!windows.has(p_window), VK_NULL_HANDLE); ERR_FAIL_COND_V(!buffers_prepared, VK_NULL_HANDLE); Window *w = &windows[p_window]; @@ -750,10 +757,10 @@ VkFramebuffer VulkanContext::window_get_framebuffer(int p_window) { return w->swapchain_image_resources[w->current_buffer].framebuffer; } -void VulkanContext::window_destroy(int p_window_id) { +void VulkanContext::window_destroy(DisplayServer::WindowID p_window_id) { ERR_FAIL_COND(!windows.has(p_window_id)); _clean_up_swap_chain(&windows[p_window_id]); - vkDestroySurfaceKHR(inst, windows[p_window_id].surface, NULL); + vkDestroySurfaceKHR(inst, windows[p_window_id].surface, nullptr); windows.erase(p_window_id); } @@ -765,20 +772,20 @@ Error VulkanContext::_clean_up_swap_chain(Window *window) { vkDeviceWaitIdle(device); //this destroys images associated it seems - fpDestroySwapchainKHR(device, window->swapchain, NULL); + fpDestroySwapchainKHR(device, window->swapchain, nullptr); window->swapchain = VK_NULL_HANDLE; - vkDestroyRenderPass(device, window->render_pass, NULL); + vkDestroyRenderPass(device, window->render_pass, nullptr); if (window->swapchain_image_resources) { for (uint32_t i = 0; i < swapchainImageCount; i++) { - vkDestroyImageView(device, window->swapchain_image_resources[i].view, NULL); - vkDestroyFramebuffer(device, window->swapchain_image_resources[i].framebuffer, NULL); + vkDestroyImageView(device, window->swapchain_image_resources[i].view, nullptr); + vkDestroyFramebuffer(device, window->swapchain_image_resources[i].framebuffer, nullptr); } free(window->swapchain_image_resources); - window->swapchain_image_resources = NULL; + window->swapchain_image_resources = nullptr; } if (separate_present_queue) { - vkDestroyCommandPool(device, window->present_cmd_pool, NULL); + vkDestroyCommandPool(device, window->present_cmd_pool, nullptr); } return OK; } @@ -796,7 +803,7 @@ Error VulkanContext::_update_swap_chain(Window *window) { ERR_FAIL_COND_V(err, ERR_CANT_CREATE); uint32_t presentModeCount; - err = fpGetPhysicalDeviceSurfacePresentModesKHR(gpu, window->surface, &presentModeCount, NULL); + err = fpGetPhysicalDeviceSurfacePresentModesKHR(gpu, window->surface, &presentModeCount, nullptr); ERR_FAIL_COND_V(err, ERR_CANT_CREATE); VkPresentModeKHR *presentModes = (VkPresentModeKHR *)malloc(presentModeCount * sizeof(VkPresentModeKHR)); ERR_FAIL_COND_V(!presentModes, ERR_CANT_CREATE); @@ -918,7 +925,7 @@ Error VulkanContext::_update_swap_chain(Window *window) { VkSwapchainCreateInfoKHR swapchain_ci = { /*sType*/ VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR, - /*pNext*/ NULL, + /*pNext*/ nullptr, /*flags*/ 0, /*surface*/ window->surface, /*minImageCount*/ desiredNumOfSwapchainImages, @@ -932,19 +939,19 @@ Error VulkanContext::_update_swap_chain(Window *window) { /*imageUsage*/ VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, /*imageSharingMode*/ VK_SHARING_MODE_EXCLUSIVE, /*queueFamilyIndexCount*/ 0, - /*pQueueFamilyIndices*/ NULL, + /*pQueueFamilyIndices*/ nullptr, /*preTransform*/ (VkSurfaceTransformFlagBitsKHR)preTransform, /*compositeAlpha*/ compositeAlpha, /*presentMode*/ swapchainPresentMode, /*clipped*/ true, - /*oldSwapchain*/ NULL, + /*oldSwapchain*/ VK_NULL_HANDLE, }; - err = fpCreateSwapchainKHR(device, &swapchain_ci, NULL, &window->swapchain); + err = fpCreateSwapchainKHR(device, &swapchain_ci, nullptr, &window->swapchain); ERR_FAIL_COND_V(err, ERR_CANT_CREATE); uint32_t sp_image_count; - err = fpGetSwapchainImagesKHR(device, window->swapchain, &sp_image_count, NULL); + err = fpGetSwapchainImagesKHR(device, window->swapchain, &sp_image_count, nullptr); ERR_FAIL_COND_V(err, ERR_CANT_CREATE); if (swapchainImageCount == 0) { @@ -972,7 +979,7 @@ Error VulkanContext::_update_swap_chain(Window *window) { for (uint32_t i = 0; i < swapchainImageCount; i++) { VkImageViewCreateInfo color_image_view = { /*sType*/ VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, - /*pNext*/ NULL, + /*pNext*/ nullptr, /*flags*/ 0, /*image*/ swapchainImages[i], /*viewType*/ VK_IMAGE_VIEW_TYPE_2D, @@ -994,7 +1001,7 @@ Error VulkanContext::_update_swap_chain(Window *window) { color_image_view.image = window->swapchain_image_resources[i].image; - err = vkCreateImageView(device, &color_image_view, NULL, &window->swapchain_image_resources[i].view); + err = vkCreateImageView(device, &color_image_view, nullptr, &window->swapchain_image_resources[i].view); if (err) { free(swapchainImages); ERR_FAIL_V(ERR_CANT_CREATE); @@ -1028,33 +1035,33 @@ Error VulkanContext::_update_swap_chain(Window *window) { /*flags*/ 0, /*pipelineBindPoint*/ VK_PIPELINE_BIND_POINT_GRAPHICS, /*inputAttachmentCount*/ 0, - /*pInputAttachments*/ NULL, + /*pInputAttachments*/ nullptr, /*colorAttachmentCount*/ 1, /*pColorAttachments*/ &color_reference, - /*pResolveAttachments*/ NULL, - /*pDepthStencilAttachment*/ NULL, + /*pResolveAttachments*/ nullptr, + /*pDepthStencilAttachment*/ nullptr, /*preserveAttachmentCount*/ 0, - /*pPreserveAttachments*/ NULL, + /*pPreserveAttachments*/ nullptr, }; const VkRenderPassCreateInfo rp_info = { /*sTyp*/ VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, - /*pNext*/ NULL, + /*pNext*/ nullptr, /*flags*/ 0, /*attachmentCount*/ 1, /*pAttachments*/ &attachment, /*subpassCount*/ 1, /*pSubpasses*/ &subpass, /*dependencyCount*/ 0, - /*pDependencies*/ NULL, + /*pDependencies*/ nullptr, }; - err = vkCreateRenderPass(device, &rp_info, NULL, &window->render_pass); + err = vkCreateRenderPass(device, &rp_info, nullptr, &window->render_pass); ERR_FAIL_COND_V(err, ERR_CANT_CREATE); for (uint32_t i = 0; i < swapchainImageCount; i++) { const VkFramebufferCreateInfo fb_info = { /*sType*/ VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, - /*pNext*/ NULL, + /*pNext*/ nullptr, /*flags*/ 0, /*renderPass*/ window->render_pass, /*attachmentCount*/ 1, @@ -1064,7 +1071,7 @@ Error VulkanContext::_update_swap_chain(Window *window) { /*layers*/ 1, }; - err = vkCreateFramebuffer(device, &fb_info, NULL, &window->swapchain_image_resources[i].framebuffer); + err = vkCreateFramebuffer(device, &fb_info, nullptr, &window->swapchain_image_resources[i].framebuffer); ERR_FAIL_COND_V(err, ERR_CANT_CREATE); } } @@ -1074,15 +1081,15 @@ Error VulkanContext::_update_swap_chain(Window *window) { if (separate_present_queue) { const VkCommandPoolCreateInfo present_cmd_pool_info = { /*sType*/ VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, - /*pNext*/ NULL, + /*pNext*/ nullptr, /*flags*/ 0, /*queueFamilyIndex*/ present_queue_family_index, }; - err = vkCreateCommandPool(device, &present_cmd_pool_info, NULL, &window->present_cmd_pool); + err = vkCreateCommandPool(device, &present_cmd_pool_info, nullptr, &window->present_cmd_pool); ERR_FAIL_COND_V(err, ERR_CANT_CREATE); const VkCommandBufferAllocateInfo present_cmd_info = { /*sType*/ VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, - /*pNext*/ NULL, + /*pNext*/ nullptr, /*commandPool*/ window->present_cmd_pool, /*level*/ VK_COMMAND_BUFFER_LEVEL_PRIMARY, /*commandBufferCount*/ 1, @@ -1094,16 +1101,16 @@ Error VulkanContext::_update_swap_chain(Window *window) { const VkCommandBufferBeginInfo cmd_buf_info = { /*sType*/ VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, - /*pNext*/ NULL, + /*pNext*/ nullptr, /*flags*/ VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, - /*pInheritanceInfo*/ NULL, + /*pInheritanceInfo*/ nullptr, }; err = vkBeginCommandBuffer(window->swapchain_image_resources[i].graphics_to_present_cmd, &cmd_buf_info); ERR_FAIL_COND_V(err, ERR_CANT_CREATE); VkImageMemoryBarrier image_ownership_barrier = { /*sType*/ VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, - /*pNext*/ NULL, + /*pNext*/ nullptr, /*srcAccessMask*/ 0, /*dstAccessMask*/ VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, /*oldLayout*/ VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, @@ -1115,7 +1122,7 @@ Error VulkanContext::_update_swap_chain(Window *window) { }; vkCmdPipelineBarrier(window->swapchain_image_resources[i].graphics_to_present_cmd, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, - VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, 0, 0, NULL, 0, NULL, 1, &image_ownership_barrier); + VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, 0, 0, nullptr, 0, nullptr, 1, &image_ownership_barrier); err = vkEndCommandBuffer(window->swapchain_image_resources[i].graphics_to_present_cmd); ERR_FAIL_COND_V(err, ERR_CANT_CREATE); } @@ -1163,16 +1170,16 @@ void VulkanContext::flush(bool p_flush_setup, bool p_flush_pending) { //use a fence to wait for everything done VkSubmitInfo submit_info; submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; - submit_info.pNext = NULL; - submit_info.pWaitDstStageMask = NULL; + submit_info.pNext = nullptr; + submit_info.pWaitDstStageMask = nullptr; submit_info.waitSemaphoreCount = 0; - submit_info.pWaitSemaphores = NULL; + submit_info.pWaitSemaphores = nullptr; submit_info.commandBufferCount = 1; submit_info.pCommandBuffers = command_buffer_queue.ptr(); submit_info.signalSemaphoreCount = 0; - submit_info.pSignalSemaphores = NULL; + submit_info.pSignalSemaphores = nullptr; VkResult err = vkQueueSubmit(graphics_queue, 1, &submit_info, VK_NULL_HANDLE); - command_buffer_queue.write[0] = NULL; + command_buffer_queue.write[0] = nullptr; ERR_FAIL_COND(err); vkDeviceWaitIdle(device); } @@ -1183,14 +1190,14 @@ void VulkanContext::flush(bool p_flush_setup, bool p_flush_pending) { VkSubmitInfo submit_info; submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; - submit_info.pNext = NULL; - submit_info.pWaitDstStageMask = NULL; + submit_info.pNext = nullptr; + submit_info.pWaitDstStageMask = nullptr; submit_info.waitSemaphoreCount = 0; - submit_info.pWaitSemaphores = NULL; + submit_info.pWaitSemaphores = nullptr; submit_info.commandBufferCount = command_buffer_count - 1; submit_info.pCommandBuffers = command_buffer_queue.ptr() + 1; submit_info.signalSemaphoreCount = 0; - submit_info.pSignalSemaphores = NULL; + submit_info.pSignalSemaphores = nullptr; VkResult err = vkQueueSubmit(graphics_queue, 1, &submit_info, VK_NULL_HANDLE); ERR_FAIL_COND(err); vkDeviceWaitIdle(device); @@ -1274,10 +1281,10 @@ Error VulkanContext::swap_buffers() { // engine has fully released ownership to the application, and it is // okay to render to the image. - const VkCommandBuffer *commands_ptr = NULL; + const VkCommandBuffer *commands_ptr = nullptr; uint32_t commands_to_submit = 0; - if (command_buffer_queue[0] == NULL) { + if (command_buffer_queue[0] == nullptr) { //no setup command, but commands to submit, submit from the first and skip command if (command_buffer_count > 1) { commands_ptr = command_buffer_queue.ptr() + 1; @@ -1291,7 +1298,7 @@ Error VulkanContext::swap_buffers() { VkPipelineStageFlags pipe_stage_flags; VkSubmitInfo submit_info; submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; - submit_info.pNext = NULL; + submit_info.pNext = nullptr; submit_info.pWaitDstStageMask = &pipe_stage_flags; pipe_stage_flags = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT; submit_info.waitSemaphoreCount = 1; @@ -1303,7 +1310,7 @@ Error VulkanContext::swap_buffers() { err = vkQueueSubmit(graphics_queue, 1, &submit_info, fences[frame_index]); ERR_FAIL_COND_V(err, ERR_CANT_CREATE); - command_buffer_queue.write[0] = NULL; + command_buffer_queue.write[0] = nullptr; command_buffer_count = 1; if (separate_present_queue) { @@ -1339,13 +1346,13 @@ Error VulkanContext::swap_buffers() { // otherwise wait for draw complete VkPresentInfoKHR present = { /*sType*/ VK_STRUCTURE_TYPE_PRESENT_INFO_KHR, - /*pNext*/ NULL, + /*pNext*/ nullptr, /*waitSemaphoreCount*/ 1, /*pWaitSemaphores*/ (separate_present_queue) ? &image_ownership_semaphores[frame_index] : &draw_complete_semaphores[frame_index], /*swapchainCount*/ 0, - /*pSwapchain*/ NULL, - /*pImageIndices*/ NULL, - /*pResults*/ NULL, + /*pSwapchain*/ nullptr, + /*pImageIndices*/ nullptr, + /*pResults*/ nullptr, }; VkSwapchainKHR *pSwapchains = (VkSwapchainKHR *)alloca(sizeof(VkSwapchainKHR *) * windows.size()); @@ -1483,25 +1490,116 @@ VkPhysicalDeviceLimits VulkanContext::get_device_limits() const { } VulkanContext::VulkanContext() { - queue_props = NULL; + queue_props = nullptr; command_buffer_count = 0; - instance_validation_layers = NULL; + instance_validation_layers = nullptr; use_validation_layers = true; VK_KHR_incremental_present_enabled = true; VK_GOOGLE_display_timing_enabled = true; command_buffer_queue.resize(1); //first one is the setup command always - command_buffer_queue.write[0] = NULL; + command_buffer_queue.write[0] = nullptr; command_buffer_count = 1; queues_initialized = false; buffers_prepared = false; swapchainImageCount = 0; - last_window_id = 0; +} + +RID VulkanContext::local_device_create() { + LocalDevice ld; + + { //create device + VkResult err; + float queue_priorities[1] = { 0.0 }; + VkDeviceQueueCreateInfo queues[2]; + queues[0].sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; + queues[0].pNext = nullptr; + queues[0].queueFamilyIndex = graphics_queue_family_index; + queues[0].queueCount = 1; + queues[0].pQueuePriorities = queue_priorities; + queues[0].flags = 0; + + VkDeviceCreateInfo sdevice = { + /*sType =*/VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, + /*pNext */ nullptr, + /*flags */ 0, + /*queueCreateInfoCount */ 1, + /*pQueueCreateInfos */ queues, + /*enabledLayerCount */ 0, + /*ppEnabledLayerNames */ nullptr, + /*enabledExtensionCount */ enabled_extension_count, + /*ppEnabledExtensionNames */ (const char *const *)extension_names, + /*pEnabledFeatures */ &physical_device_features, // If specific features are required, pass them in here + }; + err = vkCreateDevice(gpu, &sdevice, nullptr, &ld.device); + ERR_FAIL_COND_V(err, RID()); + } + + { //create graphics queue + + vkGetDeviceQueue(ld.device, graphics_queue_family_index, 0, &ld.queue); + } + + return local_device_owner.make_rid(ld); +} + +VkDevice VulkanContext::local_device_get_vk_device(RID p_local_device) { + LocalDevice *ld = local_device_owner.getornull(p_local_device); + return ld->device; +} + +void VulkanContext::local_device_push_command_buffers(RID p_local_device, const VkCommandBuffer *p_buffers, int p_count) { + + LocalDevice *ld = local_device_owner.getornull(p_local_device); + ERR_FAIL_COND(ld->waiting); + + VkSubmitInfo submit_info; + submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; + submit_info.pNext = nullptr; + submit_info.pWaitDstStageMask = nullptr; + submit_info.waitSemaphoreCount = 0; + submit_info.pWaitSemaphores = nullptr; + submit_info.commandBufferCount = p_count; + submit_info.pCommandBuffers = p_buffers; + submit_info.signalSemaphoreCount = 0; + submit_info.pSignalSemaphores = nullptr; + + VkResult err = vkQueueSubmit(ld->queue, 1, &submit_info, VK_NULL_HANDLE); + ERR_FAIL_COND(err); + + ld->waiting = true; +} + +void VulkanContext::local_device_sync(RID p_local_device) { + + LocalDevice *ld = local_device_owner.getornull(p_local_device); + ERR_FAIL_COND(!ld->waiting); + + vkDeviceWaitIdle(ld->device); + ld->waiting = false; +} + +void VulkanContext::local_device_free(RID p_local_device) { + + LocalDevice *ld = local_device_owner.getornull(p_local_device); + vkDestroyDevice(ld->device, nullptr); + local_device_owner.free(p_local_device); } VulkanContext::~VulkanContext() { if (queue_props) { free(queue_props); } + for (uint32_t i = 0; i < FRAME_LAG; i++) { + vkDestroyFence(device, fences[i], nullptr); + vkDestroySemaphore(device, image_acquired_semaphores[i], nullptr); + vkDestroySemaphore(device, draw_complete_semaphores[i], nullptr); + if (separate_present_queue) { + vkDestroySemaphore(device, image_ownership_semaphores[i], nullptr); + } + } + DestroyDebugUtilsMessengerEXT(inst, dbg_messenger, nullptr); + vkDestroyDevice(device, nullptr); + vkDestroyInstance(inst, nullptr); } diff --git a/drivers/vulkan/vulkan_context.h b/drivers/vulkan/vulkan_context.h index 458cb6d793..51c3febb47 100644 --- a/drivers/vulkan/vulkan_context.h +++ b/drivers/vulkan/vulkan_context.h @@ -33,7 +33,10 @@ #include "core/error_list.h" #include "core/map.h" +#include "core/os/mutex.h" +#include "core/rid_owner.h" #include "core/ustring.h" +#include "servers/display_server.h" #include <vulkan/vulkan.h> class VulkanContext { @@ -44,8 +47,6 @@ class VulkanContext { FRAME_LAG = 2 }; - bool use_validation_layers; - VkInstance inst; VkSurfaceKHR surface; VkPhysicalDevice gpu; @@ -106,8 +107,15 @@ class VulkanContext { } }; - Map<int, Window> windows; - int last_window_id; + struct LocalDevice { + bool waiting = false; + VkDevice device; + VkQueue queue; + }; + + RID_Owner<LocalDevice, true> local_device_owner; + + Map<DisplayServer::WindowID, Window> windows; uint32_t swapchainImageCount; //commands @@ -173,7 +181,7 @@ 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); + virtual Error _window_create(DisplayServer::WindowID p_window_id, VkSurfaceKHR p_surface, int p_width, int p_height); VkInstance _get_instance() { return inst; @@ -181,18 +189,26 @@ protected: bool buffers_prepared; + bool use_validation_layers; + 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); + void window_resize(DisplayServer::WindowID p_window_id, int p_width, int p_height); + int window_get_width(DisplayServer::WindowID p_window = 0); + int window_get_height(DisplayServer::WindowID p_window = 0); + void window_destroy(DisplayServer::WindowID p_window_id); + VkFramebuffer window_get_framebuffer(DisplayServer::WindowID p_window = 0); + VkRenderPass window_get_render_pass(DisplayServer::WindowID p_window = 0); + + RID local_device_create(); + VkDevice local_device_get_vk_device(RID p_local_device); + void local_device_push_command_buffers(RID p_local_device, const VkCommandBuffer *p_buffers, int p_count); + void local_device_sync(RID p_local_device); + void local_device_free(RID p_local_device); VkFormat get_screen_format() const; VkPhysicalDeviceLimits get_device_limits() const; diff --git a/drivers/wasapi/SCsub b/drivers/wasapi/SCsub index 4c24925192..4e1b5f2a36 100644 --- a/drivers/wasapi/SCsub +++ b/drivers/wasapi/SCsub @@ -1,6 +1,6 @@ #!/usr/bin/env python -Import('env') +Import("env") # Driver source files env.add_source_files(env.drivers_sources, "*.cpp") diff --git a/drivers/wasapi/audio_driver_wasapi.cpp b/drivers/wasapi/audio_driver_wasapi.cpp index fa78771993..ab2976f02c 100644 --- a/drivers/wasapi/audio_driver_wasapi.cpp +++ b/drivers/wasapi/audio_driver_wasapi.cpp @@ -54,10 +54,10 @@ const IID IID_IAudioClient = __uuidof(IAudioClient); const IID IID_IAudioRenderClient = __uuidof(IAudioRenderClient); const IID IID_IAudioCaptureClient = __uuidof(IAudioCaptureClient); -#define SAFE_RELEASE(memory) \ - if ((memory) != NULL) { \ - (memory)->Release(); \ - (memory) = NULL; \ +#define SAFE_RELEASE(memory) \ + if ((memory) != nullptr) { \ + (memory)->Release(); \ + (memory) = nullptr; \ } #define REFTIMES_PER_SEC 10000000 @@ -75,11 +75,11 @@ class CMMNotificationClient : public IMMNotificationClient { public: CMMNotificationClient() : _cRef(1), - _pEnumerator(NULL) {} + _pEnumerator(nullptr) {} virtual ~CMMNotificationClient() { - if ((_pEnumerator) != NULL) { + if ((_pEnumerator) != nullptr) { (_pEnumerator)->Release(); - (_pEnumerator) = NULL; + (_pEnumerator) = nullptr; } } @@ -103,7 +103,7 @@ public: AddRef(); *ppvInterface = (IMMNotificationClient *)this; } else { - *ppvInterface = NULL; + *ppvInterface = nullptr; return E_NOINTERFACE; } return S_OK; @@ -143,23 +143,23 @@ static CMMNotificationClient notif_client; Error AudioDriverWASAPI::audio_device_init(AudioDeviceWASAPI *p_device, bool p_capture, bool reinit) { WAVEFORMATEX *pwfex; - IMMDeviceEnumerator *enumerator = NULL; - IMMDevice *device = NULL; + IMMDeviceEnumerator *enumerator = nullptr; + IMMDevice *device = nullptr; - CoInitialize(NULL); + CoInitialize(nullptr); - HRESULT hr = CoCreateInstance(CLSID_MMDeviceEnumerator, NULL, CLSCTX_ALL, IID_IMMDeviceEnumerator, (void **)&enumerator); + HRESULT hr = CoCreateInstance(CLSID_MMDeviceEnumerator, nullptr, CLSCTX_ALL, IID_IMMDeviceEnumerator, (void **)&enumerator); ERR_FAIL_COND_V(hr != S_OK, ERR_CANT_OPEN); if (p_device->device_name == "Default") { hr = enumerator->GetDefaultAudioEndpoint(p_capture ? eCapture : eRender, eConsole, &device); } else { - IMMDeviceCollection *devices = NULL; + IMMDeviceCollection *devices = nullptr; hr = enumerator->EnumAudioEndpoints(p_capture ? eCapture : eRender, DEVICE_STATE_ACTIVE, &devices); ERR_FAIL_COND_V(hr != S_OK, ERR_CANT_OPEN); - LPWSTR strId = NULL; + LPWSTR strId = nullptr; bool found = false; UINT count = 0; @@ -167,12 +167,12 @@ Error AudioDriverWASAPI::audio_device_init(AudioDeviceWASAPI *p_device, bool p_c ERR_FAIL_COND_V(hr != S_OK, ERR_CANT_OPEN); for (ULONG i = 0; i < count && !found; i++) { - IMMDevice *tmp_device = NULL; + IMMDevice *tmp_device = nullptr; hr = devices->Item(i, &tmp_device); ERR_BREAK(hr != S_OK); - IPropertyStore *props = NULL; + IPropertyStore *props = nullptr; hr = tmp_device->OpenPropertyStore(STGM_READ, &props); ERR_BREAK(hr != S_OK); @@ -202,7 +202,7 @@ Error AudioDriverWASAPI::audio_device_init(AudioDeviceWASAPI *p_device, bool p_c CoTaskMemFree(strId); } - if (device == NULL) { + if (device == nullptr) { hr = enumerator->GetDefaultAudioEndpoint(p_capture ? eCapture : eRender, eConsole, &device); } } @@ -224,7 +224,7 @@ Error AudioDriverWASAPI::audio_device_init(AudioDeviceWASAPI *p_device, bool p_c ERR_PRINT("WASAPI: RegisterEndpointNotificationCallback error"); } - hr = device->Activate(IID_IAudioClient, CLSCTX_ALL, NULL, (void **)&p_device->audio_client); + hr = device->Activate(IID_IAudioClient, CLSCTX_ALL, nullptr, (void **)&p_device->audio_client); SAFE_RELEASE(device) if (reinit) { @@ -246,7 +246,7 @@ Error AudioDriverWASAPI::audio_device_init(AudioDeviceWASAPI *p_device, bool p_c print_verbose("WASAPI: wBitsPerSample = " + itos(pwfex->wBitsPerSample)); print_verbose("WASAPI: cbSize = " + itos(pwfex->cbSize)); - WAVEFORMATEX *closest = NULL; + WAVEFORMATEX *closest = nullptr; hr = p_device->audio_client->IsFormatSupported(AUDCLNT_SHAREMODE_SHARED, pwfex, &closest); if (hr == S_FALSE) { WARN_PRINT("WASAPI: Mix format is not supported by the Device"); @@ -295,7 +295,7 @@ Error AudioDriverWASAPI::audio_device_init(AudioDeviceWASAPI *p_device, bool p_c pwfex->nAvgBytesPerSec = pwfex->nSamplesPerSec * pwfex->nChannels * (pwfex->wBitsPerSample / 8); } - hr = p_device->audio_client->Initialize(AUDCLNT_SHAREMODE_SHARED, streamflags, p_capture ? REFTIMES_PER_SEC : 0, 0, pwfex, NULL); + hr = p_device->audio_client->Initialize(AUDCLNT_SHAREMODE_SHARED, streamflags, p_capture ? REFTIMES_PER_SEC : 0, 0, pwfex, nullptr); ERR_FAIL_COND_V_MSG(hr != S_OK, ERR_CANT_OPEN, "WASAPI: Initialize failed with error 0x" + String::num_uint64(hr, 16) + "."); if (p_capture) { @@ -424,14 +424,14 @@ AudioDriver::SpeakerMode AudioDriverWASAPI::get_speaker_mode() const { Array AudioDriverWASAPI::audio_device_get_list(bool p_capture) { Array list; - IMMDeviceCollection *devices = NULL; - IMMDeviceEnumerator *enumerator = NULL; + IMMDeviceCollection *devices = nullptr; + IMMDeviceEnumerator *enumerator = nullptr; list.push_back(String("Default")); - CoInitialize(NULL); + CoInitialize(nullptr); - HRESULT hr = CoCreateInstance(CLSID_MMDeviceEnumerator, NULL, CLSCTX_ALL, IID_IMMDeviceEnumerator, (void **)&enumerator); + HRESULT hr = CoCreateInstance(CLSID_MMDeviceEnumerator, nullptr, CLSCTX_ALL, IID_IMMDeviceEnumerator, (void **)&enumerator); ERR_FAIL_COND_V(hr != S_OK, Array()); hr = enumerator->EnumAudioEndpoints(p_capture ? eCapture : eRender, DEVICE_STATE_ACTIVE, &devices); @@ -442,12 +442,12 @@ Array AudioDriverWASAPI::audio_device_get_list(bool p_capture) { ERR_FAIL_COND_V(hr != S_OK, Array()); for (ULONG i = 0; i < count; i++) { - IMMDevice *device = NULL; + IMMDevice *device = nullptr; hr = devices->Item(i, &device); ERR_BREAK(hr != S_OK); - IPropertyStore *props = NULL; + IPropertyStore *props = nullptr; hr = device->OpenPropertyStore(STGM_READ, &props); ERR_BREAK(hr != S_OK); @@ -594,7 +594,7 @@ void AudioDriverWASAPI::thread_func(void *p_udata) { // Check how much frames are available on the WASAPI buffer UINT32 write_frames = MIN(ad->buffer_frames - cur_frames, avail_frames); if (write_frames > 0) { - BYTE *buffer = NULL; + BYTE *buffer = nullptr; hr = ad->audio_output.render_client->GetBuffer(write_frames, &buffer); if (hr == S_OK) { @@ -693,7 +693,7 @@ void AudioDriverWASAPI::thread_func(void *p_udata) { HRESULT hr = ad->audio_input.capture_client->GetNextPacketSize(&packet_length); if (hr == S_OK) { while (packet_length != 0) { - hr = ad->audio_input.capture_client->GetBuffer(&data, &num_frames_available, &flags, NULL, NULL); + hr = ad->audio_input.capture_client->GetBuffer(&data, &num_frames_available, &flags, nullptr, nullptr); ERR_BREAK(hr != S_OK); // fixme: Only works for floating point atm @@ -796,7 +796,7 @@ void AudioDriverWASAPI::finish() { Thread::wait_to_finish(thread); memdelete(thread); - thread = NULL; + thread = nullptr; } finish_capture_device(); @@ -855,7 +855,7 @@ String AudioDriverWASAPI::capture_get_device() { AudioDriverWASAPI::AudioDriverWASAPI() { - thread = NULL; + thread = nullptr; samples_in.clear(); diff --git a/drivers/wasapi/audio_driver_wasapi.h b/drivers/wasapi/audio_driver_wasapi.h index 3ea61c6010..01a4666812 100644 --- a/drivers/wasapi/audio_driver_wasapi.h +++ b/drivers/wasapi/audio_driver_wasapi.h @@ -59,9 +59,9 @@ class AudioDriverWASAPI : public AudioDriver { String new_device; AudioDeviceWASAPI() : - audio_client(NULL), - render_client(NULL), - capture_client(NULL), + audio_client(nullptr), + render_client(nullptr), + capture_client(nullptr), active(false), format_tag(0), bits_per_sample(0), diff --git a/drivers/windows/SCsub b/drivers/windows/SCsub index 28b315ae66..91e1140b75 100644 --- a/drivers/windows/SCsub +++ b/drivers/windows/SCsub @@ -1,5 +1,5 @@ #!/usr/bin/env python -Import('env') +Import("env") env.add_source_files(env.drivers_sources, "*.cpp") diff --git a/drivers/windows/dir_access_windows.cpp b/drivers/windows/dir_access_windows.cpp index cf09f79832..a8618b05d7 100644 --- a/drivers/windows/dir_access_windows.cpp +++ b/drivers/windows/dir_access_windows.cpp @@ -67,7 +67,7 @@ Error DirAccessWindows::list_dir_begin() { _cishidden = false; list_dir_end(); - p->h = FindFirstFileExW((current_dir + "\\*").c_str(), FindExInfoStandard, &p->fu, FindExSearchNameMatch, NULL, 0); + p->h = FindFirstFileExW((current_dir + "\\*").c_str(), FindExInfoStandard, &p->fu, FindExSearchNameMatch, nullptr, 0); return (p->h == INVALID_HANDLE_VALUE) ? ERR_CANT_OPEN : OK; } @@ -175,7 +175,7 @@ Error DirAccessWindows::make_dir(String p_dir) { p_dir = "\\\\?\\" + p_dir; //done according to // https://msdn.microsoft.com/en-us/library/windows/desktop/aa363855(v=vs.85).aspx - success = CreateDirectoryW(p_dir.c_str(), NULL); + success = CreateDirectoryW(p_dir.c_str(), nullptr); err = GetLastError(); if (success) { @@ -206,7 +206,13 @@ String DirAccessWindows::get_current_dir(bool p_include_drive) { if (p_include_drive) { return current_dir; } else { - return current_dir.right(current_dir.find(":") + 1); + if (_get_root_string() == "") { + int p = current_dir.find(":"); + if (p != -1) { + return current_dir.right(p + 1); + } + } + return current_dir; } } @@ -269,11 +275,11 @@ Error DirAccessWindows::rename(String p_path, String p_new_path) { if (p_path.to_lower() == p_new_path.to_lower()) { WCHAR tmpfile[MAX_PATH]; - if (!GetTempFileNameW(fix_path(get_current_dir()).c_str(), NULL, 0, tmpfile)) { + if (!GetTempFileNameW(fix_path(get_current_dir()).c_str(), nullptr, 0, tmpfile)) { return FAILED; } - if (!::ReplaceFileW(tmpfile, p_path.c_str(), NULL, 0, NULL, NULL)) { + if (!::ReplaceFileW(tmpfile, p_path.c_str(), nullptr, 0, nullptr, nullptr)) { DeleteFileW(tmpfile); return FAILED; } @@ -343,7 +349,7 @@ FileType DirAccessWindows::get_file_type(const String& p_file) const { size_t DirAccessWindows::get_space_left() { uint64_t bytes = 0; - if (!GetDiskFreeSpaceEx(NULL, (PULARGE_INTEGER)&bytes, NULL, NULL)) + if (!GetDiskFreeSpaceEx(nullptr, (PULARGE_INTEGER)&bytes, nullptr, nullptr)) return 0; //this is either 0 or a value in bytes. diff --git a/drivers/windows/file_access_windows.cpp b/drivers/windows/file_access_windows.cpp index 01d2b8716f..69078b3326 100644 --- a/drivers/windows/file_access_windows.cpp +++ b/drivers/windows/file_access_windows.cpp @@ -117,7 +117,7 @@ Error FileAccessWindows::_open(const String &p_path, int p_mode_flags) { errno_t errcode = _wfopen_s(&f, path.c_str(), mode_string); - if (f == NULL) { + if (f == nullptr) { switch (errcode) { case ENOENT: { last_error = ERR_FILE_NOT_FOUND; @@ -140,7 +140,7 @@ void FileAccessWindows::close() { return; fclose(f); - f = NULL; + f = nullptr; if (save_path != "") { @@ -164,7 +164,7 @@ void FileAccessWindows::close() { rename_error = _wrename((save_path + ".tmp").c_str(), save_path.c_str()) != 0; } else { //atomic replace for existing file - rename_error = !ReplaceFileW(save_path.c_str(), (save_path + ".tmp").c_str(), NULL, 2 | 4, NULL, NULL); + rename_error = !ReplaceFileW(save_path.c_str(), (save_path + ".tmp").c_str(), nullptr, 2 | 4, nullptr, nullptr); } if (rename_error) { attempts--; @@ -196,7 +196,7 @@ String FileAccessWindows::get_path_absolute() const { bool FileAccessWindows::is_open() const { - return (f != NULL); + return (f != nullptr); } void FileAccessWindows::seek(size_t p_position) { @@ -318,7 +318,7 @@ bool FileAccessWindows::file_exists(const String &p_name) { //printf("opening file %s\n", p_fname.c_str()); String filename = fix_path(p_name); _wfopen_s(&g, filename.c_str(), L"rb"); - if (g == NULL) { + if (g == nullptr) { return false; } else { @@ -354,7 +354,7 @@ Error FileAccessWindows::_set_unix_permissions(const String &p_file, uint32_t p_ } FileAccessWindows::FileAccessWindows() : - f(NULL), + f(nullptr), flags(0), prev_op(0), last_error(OK) { diff --git a/drivers/windows/thread_windows.cpp b/drivers/windows/thread_windows.cpp index a7f34b64ca..aea2db2603 100644 --- a/drivers/windows/thread_windows.cpp +++ b/drivers/windows/thread_windows.cpp @@ -64,7 +64,7 @@ Thread *ThreadWindows::create_func_windows(ThreadCreateCallback p_callback, void ThreadWindows *tr = memnew(ThreadWindows); tr->callback = p_callback; tr->user = p_user; - tr->handle = CreateEvent(NULL, TRUE, FALSE, NULL); + tr->handle = CreateEvent(nullptr, TRUE, FALSE, nullptr); QueueUserWorkItem(thread_callback, tr, WT_EXECUTELONGFUNCTION); @@ -91,7 +91,7 @@ void ThreadWindows::make_default() { } ThreadWindows::ThreadWindows() : - handle(NULL) { + handle(nullptr) { } ThreadWindows::~ThreadWindows() { diff --git a/drivers/winmidi/SCsub b/drivers/winmidi/SCsub index 4c24925192..4e1b5f2a36 100644 --- a/drivers/winmidi/SCsub +++ b/drivers/winmidi/SCsub @@ -1,6 +1,6 @@ #!/usr/bin/env python -Import('env') +Import("env") # Driver source files env.add_source_files(env.drivers_sources, "*.cpp") diff --git a/drivers/xaudio2/SCsub b/drivers/xaudio2/SCsub index de750525ab..6778ad281e 100644 --- a/drivers/xaudio2/SCsub +++ b/drivers/xaudio2/SCsub @@ -1,7 +1,7 @@ #!/usr/bin/env python -Import('env') +Import("env") env.add_source_files(env.drivers_sources, "*.cpp") -env.Append(CPPDEFINES=['XAUDIO2_ENABLED']) -env.Append(LINKFLAGS=['xaudio2_8.lib']) +env.Append(CPPDEFINES=["XAUDIO2_ENABLED"]) +env.Append(LINKFLAGS=["xaudio2_8.lib"]) diff --git a/drivers/xaudio2/audio_driver_xaudio2.cpp b/drivers/xaudio2/audio_driver_xaudio2.cpp index 9c7cb4f0f3..120bfa2b36 100644 --- a/drivers/xaudio2/audio_driver_xaudio2.cpp +++ b/drivers/xaudio2/audio_driver_xaudio2.cpp @@ -43,7 +43,7 @@ Error AudioDriverXAudio2::init() { thread_exited = false; exit_thread = false; pcm_open = false; - samples_in = NULL; + samples_in = nullptr; mix_rate = GLOBAL_DEF_RST("audio/mix_rate", DEFAULT_MIX_RATE); // FIXME: speaker_mode seems unused in the Xaudio2 driver so far @@ -193,11 +193,11 @@ void AudioDriverXAudio2::finish() { mastering_voice->DestroyVoice(); memdelete(thread); - thread = NULL; + thread = nullptr; } AudioDriverXAudio2::AudioDriverXAudio2() : - thread(NULL), + thread(nullptr), current_buffer(0) { wave_format = { 0 }; for (int i = 0; i < AUDIO_BUFFERS; i++) { diff --git a/drivers/xaudio2/audio_driver_xaudio2.h b/drivers/xaudio2/audio_driver_xaudio2.h index 108891a288..eb4a6d6e95 100644 --- a/drivers/xaudio2/audio_driver_xaudio2.h +++ b/drivers/xaudio2/audio_driver_xaudio2.h @@ -50,7 +50,7 @@ class AudioDriverXAudio2 : public AudioDriver { HANDLE buffer_end_event; XAudio2DriverVoiceCallback() : - buffer_end_event(CreateEvent(NULL, FALSE, FALSE, NULL)) {} + buffer_end_event(CreateEvent(nullptr, FALSE, FALSE, nullptr)) {} void STDMETHODCALLTYPE OnBufferEnd(void *pBufferContext) { SetEvent(buffer_end_event); } |