summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/alsa/audio_driver_alsa.cpp143
-rw-r--r--drivers/alsa/audio_driver_alsa.h13
-rw-r--r--drivers/coreaudio/audio_driver_coreaudio.cpp212
-rw-r--r--drivers/coreaudio/audio_driver_coreaudio.h20
-rw-r--r--drivers/gles2/rasterizer_canvas_gles2.cpp8
-rw-r--r--drivers/gles2/rasterizer_canvas_gles2.h4
-rw-r--r--drivers/gles2/rasterizer_gles2.cpp73
-rw-r--r--drivers/gles2/rasterizer_gles2.h4
-rw-r--r--drivers/gles2/rasterizer_scene_gles2.cpp4
-rw-r--r--drivers/gles2/rasterizer_scene_gles2.h4
-rw-r--r--drivers/gles2/rasterizer_storage_gles2.cpp4
-rw-r--r--drivers/gles2/rasterizer_storage_gles2.h4
-rw-r--r--drivers/gles2/shader_compiler_gles2.cpp10
-rw-r--r--drivers/gles2/shader_compiler_gles2.h4
-rw-r--r--drivers/gles2/shader_gles2.cpp4
-rw-r--r--drivers/gles2/shader_gles2.h4
-rw-r--r--drivers/gles3/rasterizer_canvas_gles3.cpp2
-rw-r--r--drivers/gles3/rasterizer_gles3.cpp37
-rw-r--r--drivers/gles3/rasterizer_scene_gles3.cpp24
-rw-r--r--drivers/gles3/rasterizer_scene_gles3.h1
-rw-r--r--drivers/pulseaudio/audio_driver_pulseaudio.cpp438
-rw-r--r--drivers/pulseaudio/audio_driver_pulseaudio.h29
-rw-r--r--drivers/unix/dir_access_unix.cpp2
-rw-r--r--drivers/unix/file_access_unix.cpp11
-rw-r--r--drivers/unix/file_access_unix.h4
-rw-r--r--drivers/unix/os_unix.cpp12
-rw-r--r--drivers/unix/os_unix.h6
-rw-r--r--drivers/unix/thread_posix.cpp2
-rw-r--r--drivers/unix/thread_posix.h2
-rw-r--r--drivers/wasapi/audio_driver_wasapi.cpp148
-rw-r--r--drivers/wasapi/audio_driver_wasapi.h6
-rw-r--r--drivers/windows/file_access_windows.cpp33
-rw-r--r--drivers/windows/file_access_windows.h5
33 files changed, 970 insertions, 307 deletions
diff --git a/drivers/alsa/audio_driver_alsa.cpp b/drivers/alsa/audio_driver_alsa.cpp
index 0bb03d23ea..1e17e72532 100644
--- a/drivers/alsa/audio_driver_alsa.cpp
+++ b/drivers/alsa/audio_driver_alsa.cpp
@@ -37,19 +37,20 @@
#include <errno.h>
-Error AudioDriverALSA::init() {
-
- active = false;
- thread_exited = false;
- exit_thread = false;
- pcm_open = false;
- samples_in = NULL;
- samples_out = NULL;
-
+Error AudioDriverALSA::init_device() {
mix_rate = GLOBAL_DEF("audio/mix_rate", DEFAULT_MIX_RATE);
speaker_mode = SPEAKER_MODE_STEREO;
channels = 2;
+ // If there is a specified device check that it is really present
+ if (device_name != "Default") {
+ Array list = get_device_list();
+ if (list.find(device_name) == -1) {
+ device_name = "Default";
+ new_device = "Default";
+ }
+ }
+
int status;
snd_pcm_hw_params_t *hwparams;
snd_pcm_sw_params_t *swparams;
@@ -65,7 +66,16 @@ Error AudioDriverALSA::init() {
//6 chans - "plug:surround51"
//4 chans - "plug:surround40";
- status = snd_pcm_open(&pcm_handle, "default", SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK);
+ if (device_name == "Default") {
+ status = snd_pcm_open(&pcm_handle, "default", SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK);
+ } else {
+ String device = device_name;
+ int pos = device.find(";");
+ if (pos != -1) {
+ device = device.substr(0, pos);
+ }
+ status = snd_pcm_open(&pcm_handle, device.utf8().get_data(), SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK);
+ }
ERR_FAIL_COND_V(status < 0, ERR_CANT_OPEN);
@@ -129,15 +139,28 @@ Error AudioDriverALSA::init() {
status = snd_pcm_sw_params(pcm_handle, swparams);
CHECK_FAIL(status < 0);
- samples_in = memnew_arr(int32_t, period_size * channels);
- samples_out = memnew_arr(int16_t, period_size * channels);
+ samples_in.resize(period_size * channels);
+ samples_out.resize(period_size * channels);
snd_pcm_nonblock(pcm_handle, 0);
- mutex = Mutex::create();
- thread = Thread::create(AudioDriverALSA::thread_func, this);
-
return OK;
+}
+
+Error AudioDriverALSA::init() {
+
+ active = false;
+ thread_exited = false;
+ exit_thread = false;
+ pcm_open = false;
+
+ Error err = init_device();
+ if (err == OK) {
+ mutex = Mutex::create();
+ thread = Thread::create(AudioDriverALSA::thread_func, this);
+ }
+
+ return err;
};
void AudioDriverALSA::thread_func(void *p_udata) {
@@ -152,7 +175,7 @@ void AudioDriverALSA::thread_func(void *p_udata) {
} else {
ad->lock();
- ad->audio_server_process(ad->period_size, ad->samples_in);
+ ad->audio_server_process(ad->period_size, ad->samples_in.ptrw());
ad->unlock();
@@ -167,7 +190,7 @@ void AudioDriverALSA::thread_func(void *p_udata) {
while (todo) {
if (ad->exit_thread)
break;
- uint8_t *src = (uint8_t *)ad->samples_out;
+ uint8_t *src = (uint8_t *)ad->samples_out.ptr();
int wrote = snd_pcm_writei(ad->pcm_handle, (void *)(src + (total * ad->channels)), todo);
if (wrote < 0) {
@@ -193,6 +216,26 @@ void AudioDriverALSA::thread_func(void *p_udata) {
total += wrote;
todo -= wrote;
};
+
+ // User selected a new device, finish the current one so we'll init the new device
+ if (ad->device_name != ad->new_device) {
+ ad->device_name = ad->new_device;
+ ad->finish_device();
+
+ Error err = ad->init_device();
+ if (err != OK) {
+ ERR_PRINT("ALSA: init_device error");
+ ad->device_name = "Default";
+ ad->new_device = "Default";
+
+ err = ad->init_device();
+ if (err != OK) {
+ ad->active = false;
+ ad->exit_thread = true;
+ break;
+ }
+ }
+ }
};
ad->thread_exited = true;
@@ -213,6 +256,49 @@ AudioDriver::SpeakerMode AudioDriverALSA::get_speaker_mode() const {
return speaker_mode;
};
+Array AudioDriverALSA::get_device_list() {
+
+ Array list;
+
+ list.push_back("Default");
+
+ void **hints;
+
+ if (snd_device_name_hint(-1, "pcm", &hints) < 0)
+ return list;
+
+ for (void **n = hints; *n != NULL; 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 (desc) {
+ list.push_back(String(name) + ";" + String(desc));
+ } else {
+ list.push_back(String(name));
+ }
+ }
+
+ if (desc != NULL)
+ free(desc);
+ if (name != NULL)
+ free(name);
+ }
+ snd_device_name_free_hint(hints);
+
+ return list;
+}
+
+String AudioDriverALSA::get_device() {
+
+ return device_name;
+}
+
+void AudioDriverALSA::set_device(String device) {
+
+ new_device = device;
+}
+
void AudioDriverALSA::lock() {
if (!thread || !mutex)
@@ -227,6 +313,14 @@ void AudioDriverALSA::unlock() {
mutex->unlock();
};
+void AudioDriverALSA::finish_device() {
+
+ if (pcm_open) {
+ snd_pcm_close(pcm_handle);
+ pcm_open = NULL;
+ }
+}
+
void AudioDriverALSA::finish() {
if (!thread)
@@ -235,17 +329,13 @@ void AudioDriverALSA::finish() {
exit_thread = true;
Thread::wait_to_finish(thread);
- if (pcm_open)
- snd_pcm_close(pcm_handle);
-
- if (samples_in) {
- memdelete_arr(samples_in);
- memdelete_arr(samples_out);
- };
+ finish_device();
memdelete(thread);
- if (mutex)
+ if (mutex) {
memdelete(mutex);
+ mutex = NULL;
+ }
thread = NULL;
};
@@ -254,6 +344,9 @@ AudioDriverALSA::AudioDriverALSA() {
mutex = NULL;
thread = NULL;
pcm_handle = NULL;
+
+ device_name = "Default";
+ new_device = "Default";
};
AudioDriverALSA::~AudioDriverALSA(){
diff --git a/drivers/alsa/audio_driver_alsa.h b/drivers/alsa/audio_driver_alsa.h
index 8ed60dfdc7..2878e100a2 100644
--- a/drivers/alsa/audio_driver_alsa.h
+++ b/drivers/alsa/audio_driver_alsa.h
@@ -44,8 +44,14 @@ class AudioDriverALSA : public AudioDriver {
snd_pcm_t *pcm_handle;
- int32_t *samples_in;
- int16_t *samples_out;
+ String device_name;
+ String new_device;
+
+ Vector<int32_t> samples_in;
+ Vector<int16_t> samples_out;
+
+ Error init_device();
+ void finish_device();
static void thread_func(void *p_udata);
@@ -71,6 +77,9 @@ public:
virtual void start();
virtual int get_mix_rate() const;
virtual SpeakerMode get_speaker_mode() const;
+ virtual Array get_device_list();
+ virtual String get_device();
+ virtual void set_device(String device);
virtual void lock();
virtual void unlock();
virtual void finish();
diff --git a/drivers/coreaudio/audio_driver_coreaudio.cpp b/drivers/coreaudio/audio_driver_coreaudio.cpp
index 0b39f9ebc3..c84469f26f 100644
--- a/drivers/coreaudio/audio_driver_coreaudio.cpp
+++ b/drivers/coreaudio/audio_driver_coreaudio.cpp
@@ -37,16 +37,22 @@
#define kOutputBus 0
#ifdef OSX_ENABLED
-static OSStatus outputDeviceAddressCB(AudioObjectID inObjectID, UInt32 inNumberAddresses, const AudioObjectPropertyAddress *inAddresses, void *inClientData) {
+OSStatus AudioDriverCoreAudio::output_device_address_cb(AudioObjectID inObjectID,
+ UInt32 inNumberAddresses, const AudioObjectPropertyAddress *inAddresses,
+ void *inClientData) {
AudioDriverCoreAudio *driver = (AudioDriverCoreAudio *)inClientData;
- driver->reopen();
+ // If our selected device is the Default call set_device to update the
+ // kAudioOutputUnitProperty_CurrentDevice property
+ if (driver->device_name == "Default") {
+ driver->set_device("Default");
+ }
return noErr;
}
#endif
-Error AudioDriverCoreAudio::initDevice() {
+Error AudioDriverCoreAudio::init_device() {
AudioComponentDescription desc;
zeromem(&desc, sizeof(desc));
desc.componentType = kAudioUnitType_Output;
@@ -129,7 +135,7 @@ Error AudioDriverCoreAudio::initDevice() {
return OK;
}
-Error AudioDriverCoreAudio::finishDevice() {
+Error AudioDriverCoreAudio::finish_device() {
OSStatus result;
if (active) {
@@ -153,49 +159,18 @@ Error AudioDriverCoreAudio::init() {
channels = 2;
#ifdef OSX_ENABLED
- outputDeviceAddress.mSelector = kAudioHardwarePropertyDefaultOutputDevice;
- outputDeviceAddress.mScope = kAudioObjectPropertyScopeGlobal;
- outputDeviceAddress.mElement = kAudioObjectPropertyElementMaster;
+ AudioObjectPropertyAddress prop;
+ prop.mSelector = kAudioHardwarePropertyDefaultOutputDevice;
+ prop.mScope = kAudioObjectPropertyScopeGlobal;
+ prop.mElement = kAudioObjectPropertyElementMaster;
- result = AudioObjectAddPropertyListener(kAudioObjectSystemObject, &outputDeviceAddress, &outputDeviceAddressCB, this);
+ result = AudioObjectAddPropertyListener(kAudioObjectSystemObject, &prop, &output_device_address_cb, this);
ERR_FAIL_COND_V(result != noErr, FAILED);
#endif
- return initDevice();
+ return init_device();
};
-Error AudioDriverCoreAudio::reopen() {
- bool restart = false;
-
- lock();
-
- if (active) {
- restart = true;
- }
-
- Error err = finishDevice();
- if (err != OK) {
- ERR_PRINT("finishDevice failed");
- unlock();
- return err;
- }
-
- err = initDevice();
- if (err != OK) {
- ERR_PRINT("initDevice failed");
- unlock();
- return err;
- }
-
- if (restart) {
- start();
- }
-
- unlock();
-
- return OK;
-}
-
OSStatus AudioDriverCoreAudio::output_callback(void *inRefCon,
AudioUnitRenderActionFlags *ioActionFlags,
const AudioTimeStamp *inTimeStamp,
@@ -257,6 +232,150 @@ AudioDriver::SpeakerMode AudioDriverCoreAudio::get_speaker_mode() const {
return get_speaker_mode_by_total_channels(channels);
};
+#ifdef OSX_ENABLED
+
+Array AudioDriverCoreAudio::get_device_list() {
+
+ Array list;
+
+ list.push_back("Default");
+
+ AudioObjectPropertyAddress prop;
+
+ prop.mSelector = kAudioHardwarePropertyDevices;
+ prop.mScope = kAudioObjectPropertyScopeGlobal;
+ prop.mElement = kAudioObjectPropertyElementMaster;
+
+ UInt32 size = 0;
+ AudioObjectGetPropertyDataSize(kAudioObjectSystemObject, &prop, 0, NULL, &size);
+ AudioDeviceID *audioDevices = (AudioDeviceID *)malloc(size);
+ AudioObjectGetPropertyData(kAudioObjectSystemObject, &prop, 0, NULL, &size, audioDevices);
+
+ UInt32 deviceCount = size / sizeof(AudioDeviceID);
+ for (UInt32 i = 0; i < deviceCount; i++) {
+ prop.mScope = kAudioDevicePropertyScopeOutput;
+ prop.mSelector = kAudioDevicePropertyStreamConfiguration;
+
+ AudioObjectGetPropertyDataSize(audioDevices[i], &prop, 0, NULL, &size);
+ AudioBufferList *bufferList = (AudioBufferList *)malloc(size);
+ AudioObjectGetPropertyData(audioDevices[i], &prop, 0, NULL, &size, bufferList);
+
+ UInt32 outputChannelCount = 0;
+ for (UInt32 j = 0; j < bufferList->mNumberBuffers; j++)
+ outputChannelCount += bufferList->mBuffers[j].mNumberChannels;
+
+ free(bufferList);
+
+ if (outputChannelCount >= 1) {
+ CFStringRef cfname;
+
+ size = sizeof(CFStringRef);
+ prop.mSelector = kAudioObjectPropertyName;
+
+ AudioObjectGetPropertyData(audioDevices[i], &prop, 0, NULL, &size, &cfname);
+
+ CFIndex length = CFStringGetLength(cfname);
+ CFIndex maxSize = CFStringGetMaximumSizeForEncoding(length, kCFStringEncodingUTF8) + 1;
+ char *buffer = (char *)malloc(maxSize);
+ if (CFStringGetCString(cfname, buffer, maxSize, kCFStringEncodingUTF8)) {
+ // Append the ID to the name in case we have devices with duplicate name
+ list.push_back(String(buffer) + " (" + itos(audioDevices[i]) + ")");
+ }
+
+ free(buffer);
+ }
+ }
+
+ free(audioDevices);
+
+ return list;
+}
+
+String AudioDriverCoreAudio::get_device() {
+
+ return device_name;
+}
+
+void AudioDriverCoreAudio::set_device(String device) {
+
+ device_name = device;
+ if (!active) {
+ return;
+ }
+
+ AudioDeviceID deviceId;
+ bool found = false;
+ if (device_name != "Default") {
+ AudioObjectPropertyAddress prop;
+
+ prop.mSelector = kAudioHardwarePropertyDevices;
+ prop.mScope = kAudioObjectPropertyScopeGlobal;
+ prop.mElement = kAudioObjectPropertyElementMaster;
+
+ UInt32 size = 0;
+ AudioObjectGetPropertyDataSize(kAudioObjectSystemObject, &prop, 0, NULL, &size);
+ AudioDeviceID *audioDevices = (AudioDeviceID *)malloc(size);
+ AudioObjectGetPropertyData(kAudioObjectSystemObject, &prop, 0, NULL, &size, audioDevices);
+
+ UInt32 deviceCount = size / sizeof(AudioDeviceID);
+ for (UInt32 i = 0; i < deviceCount && !found; i++) {
+ prop.mScope = kAudioDevicePropertyScopeOutput;
+ prop.mSelector = kAudioDevicePropertyStreamConfiguration;
+
+ AudioObjectGetPropertyDataSize(audioDevices[i], &prop, 0, NULL, &size);
+ AudioBufferList *bufferList = (AudioBufferList *)malloc(size);
+ AudioObjectGetPropertyData(audioDevices[i], &prop, 0, NULL, &size, bufferList);
+
+ UInt32 outputChannelCount = 0;
+ for (UInt32 j = 0; j < bufferList->mNumberBuffers; j++)
+ outputChannelCount += bufferList->mBuffers[j].mNumberChannels;
+
+ free(bufferList);
+
+ if (outputChannelCount >= 1) {
+ CFStringRef cfname;
+
+ size = sizeof(CFStringRef);
+ prop.mSelector = kAudioObjectPropertyName;
+
+ AudioObjectGetPropertyData(audioDevices[i], &prop, 0, NULL, &size, &cfname);
+
+ CFIndex length = CFStringGetLength(cfname);
+ CFIndex maxSize = CFStringGetMaximumSizeForEncoding(length, kCFStringEncodingUTF8) + 1;
+ char *buffer = (char *)malloc(maxSize);
+ if (CFStringGetCString(cfname, buffer, maxSize, kCFStringEncodingUTF8)) {
+ String name = String(buffer) + " (" + itos(audioDevices[i]) + ")";
+ if (name == device_name) {
+ deviceId = audioDevices[i];
+ found = true;
+ }
+ }
+
+ free(buffer);
+ }
+ }
+
+ free(audioDevices);
+ }
+
+ if (!found) {
+ UInt32 size = sizeof(AudioDeviceID);
+ AudioObjectPropertyAddress property = { kAudioHardwarePropertyDefaultOutputDevice, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMaster };
+
+ OSStatus result = AudioObjectGetPropertyData(kAudioObjectSystemObject, &property, 0, NULL, &size, &deviceId);
+ ERR_FAIL_COND(result != noErr);
+
+ found = true;
+ }
+
+ if (found) {
+ OSStatus result = AudioUnitSetProperty(audio_unit, kAudioOutputUnitProperty_CurrentDevice, kAudioUnitScope_Global, 0, &deviceId, sizeof(AudioDeviceID));
+ ERR_FAIL_COND(result != noErr);
+ }
+}
+
+#endif
+
void AudioDriverCoreAudio::lock() {
if (mutex)
mutex->lock();
@@ -276,10 +395,15 @@ bool AudioDriverCoreAudio::try_lock() {
void AudioDriverCoreAudio::finish() {
OSStatus result;
- finishDevice();
+ finish_device();
#ifdef OSX_ENABLED
- result = AudioObjectRemovePropertyListener(kAudioObjectSystemObject, &outputDeviceAddress, &outputDeviceAddressCB, this);
+ AudioObjectPropertyAddress prop;
+ prop.mSelector = kAudioHardwarePropertyDefaultOutputDevice;
+ prop.mScope = kAudioObjectPropertyScopeGlobal;
+ prop.mElement = kAudioObjectPropertyElementMaster;
+
+ result = AudioObjectRemovePropertyListener(kAudioObjectSystemObject, &prop, &output_device_address_cb, this);
if (result != noErr) {
ERR_PRINT("AudioObjectRemovePropertyListener failed");
}
@@ -309,6 +433,8 @@ AudioDriverCoreAudio::AudioDriverCoreAudio() {
buffer_frames = 0;
samples_in.clear();
+
+ device_name = "Default";
};
AudioDriverCoreAudio::~AudioDriverCoreAudio(){};
diff --git a/drivers/coreaudio/audio_driver_coreaudio.h b/drivers/coreaudio/audio_driver_coreaudio.h
index 51256085d8..1ef474ac19 100644
--- a/drivers/coreaudio/audio_driver_coreaudio.h
+++ b/drivers/coreaudio/audio_driver_coreaudio.h
@@ -43,12 +43,12 @@
class AudioDriverCoreAudio : public AudioDriver {
AudioComponentInstance audio_unit;
-#ifdef OSX_ENABLED
- AudioObjectPropertyAddress outputDeviceAddress;
-#endif
+
bool active;
Mutex *mutex;
+ String device_name;
+
int mix_rate;
unsigned int channels;
unsigned int buffer_frames;
@@ -56,14 +56,18 @@ class AudioDriverCoreAudio : public AudioDriver {
Vector<int32_t> samples_in;
+ static OSStatus output_device_address_cb(AudioObjectID inObjectID,
+ UInt32 inNumberAddresses, const AudioObjectPropertyAddress *inAddresses,
+ void *inClientData);
+
static OSStatus output_callback(void *inRefCon,
AudioUnitRenderActionFlags *ioActionFlags,
const AudioTimeStamp *inTimeStamp,
UInt32 inBusNumber, UInt32 inNumberFrames,
AudioBufferList *ioData);
- Error initDevice();
- Error finishDevice();
+ Error init_device();
+ Error finish_device();
public:
const char *get_name() const {
@@ -74,12 +78,16 @@ public:
virtual void start();
virtual int get_mix_rate() const;
virtual SpeakerMode get_speaker_mode() const;
+#ifdef OSX_ENABLED
+ virtual Array get_device_list();
+ virtual String get_device();
+ virtual void set_device(String device);
+#endif
virtual void lock();
virtual void unlock();
virtual void finish();
bool try_lock();
- Error reopen();
AudioDriverCoreAudio();
~AudioDriverCoreAudio();
diff --git a/drivers/gles2/rasterizer_canvas_gles2.cpp b/drivers/gles2/rasterizer_canvas_gles2.cpp
index 217f1522ee..cc8e3277b9 100644
--- a/drivers/gles2/rasterizer_canvas_gles2.cpp
+++ b/drivers/gles2/rasterizer_canvas_gles2.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
+/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -405,6 +405,8 @@ void RasterizerCanvasGLES2::_canvas_item_render_commands(Item *p_item, Item *cur
Rect2 dst_rect = Rect2(r->rect.position, r->rect.size);
+ state.canvas_shader.set_uniform(CanvasShaderGLES2::COLOR_TEXPIXEL_SIZE, texpixel_size);
+
if (dst_rect.size.width < 0) {
dst_rect.position.x += dst_rect.size.width;
dst_rect.size.width *= -1;
@@ -633,7 +635,7 @@ void RasterizerCanvasGLES2::_canvas_item_render_commands(Item *p_item, Item *cur
Item::CommandPolygon *polygon = static_cast<Item::CommandPolygon *>(command);
state.canvas_shader.set_conditional(CanvasShaderGLES2::USE_TEXTURE_RECT, false);
- state.canvas_shader.set_conditional(CanvasShaderGLES2::USE_UV_ATTRIBUTE, false);
+ state.canvas_shader.set_conditional(CanvasShaderGLES2::USE_UV_ATTRIBUTE, true);
if (state.canvas_shader.bind())
_set_uniforms();
diff --git a/drivers/gles2/rasterizer_canvas_gles2.h b/drivers/gles2/rasterizer_canvas_gles2.h
index 06dcc57df4..4eab8c6038 100644
--- a/drivers/gles2/rasterizer_canvas_gles2.h
+++ b/drivers/gles2/rasterizer_canvas_gles2.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
+/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/drivers/gles2/rasterizer_gles2.cpp b/drivers/gles2/rasterizer_gles2.cpp
index b357073ba5..9339167c8e 100644
--- a/drivers/gles2/rasterizer_gles2.cpp
+++ b/drivers/gles2/rasterizer_gles2.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
+/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -148,8 +148,8 @@ void RasterizerGLES2::initialize() {
}
// GLVersion seems to be used for both GL and GL ES, so we need different version checks for them
-#ifdef OPENGL_ENABLED // OpenGL 3.3 Core Profile required
- if (GLVersion.major < 3) {
+#ifdef OPENGL_ENABLED // OpenGL 2.1 Profile required
+ if (GLVersion.major < 2) {
#else // OpenGL ES 3.0
if (GLVersion.major < 2) {
#endif
@@ -160,32 +160,65 @@ void RasterizerGLES2::initialize() {
"Fatal error: Insufficient OpenGL / GLES driver support");
}
-#ifdef __APPLE__
-// FIXME glDebugMessageCallbackARB does not seem to work on Mac OS X and opengl 3, this may be an issue with our opengl canvas..
-#else
- if (true || OS::get_singleton()->is_stdout_verbose()) {
- glEnable(_EXT_DEBUG_OUTPUT_SYNCHRONOUS_ARB);
- glDebugMessageCallbackARB(_gl_debug_print, NULL);
- glEnable(_EXT_DEBUG_OUTPUT);
+#ifdef GLES_OVER_GL
+ //Test GL_ARB_framebuffer_object extension
+ if (!GLAD_GL_ARB_framebuffer_object) {
+ //Try older GL_EXT_framebuffer_object extension
+ if (GLAD_GL_EXT_framebuffer_object) {
+ glIsRenderbuffer = glIsRenderbufferEXT;
+ glBindRenderbuffer = glBindRenderbufferEXT;
+ glDeleteRenderbuffers = glDeleteRenderbuffersEXT;
+ glGenRenderbuffers = glGenRenderbuffersEXT;
+ glRenderbufferStorage = glRenderbufferStorageEXT;
+ glGetRenderbufferParameteriv = glGetRenderbufferParameterivEXT;
+ glIsFramebuffer = glIsFramebufferEXT;
+ glBindFramebuffer = glBindFramebufferEXT;
+ glDeleteFramebuffers = glDeleteFramebuffersEXT;
+ glGenFramebuffers = glGenFramebuffersEXT;
+ glCheckFramebufferStatus = glCheckFramebufferStatusEXT;
+ glFramebufferTexture1D = glFramebufferTexture1DEXT;
+ glFramebufferTexture2D = glFramebufferTexture2DEXT;
+ glFramebufferTexture3D = glFramebufferTexture3DEXT;
+ glFramebufferRenderbuffer = glFramebufferRenderbufferEXT;
+ glGetFramebufferAttachmentParameteriv = glGetFramebufferAttachmentParameterivEXT;
+ glGenerateMipmap = glGenerateMipmapEXT;
+ } else {
+ ERR_PRINT("Your system's graphic drivers seem not to support GL_ARB(EXT)_framebuffer_object OpenGL extension, sorry :(\n"
+ "Try a drivers update, buy a new GPU or try software rendering on Linux; Godot will now crash with a segmentation fault.");
+ OS::get_singleton()->alert("Your system's graphic drivers seem not to support GL_ARB(EXT)_framebuffer_object OpenGL extension, sorry :(\n"
+ "Godot Engine will self-destruct as soon as you acknowledge this error message.",
+ "Fatal error: Insufficient OpenGL / GLES driver support");
+ }
}
#endif
+ if (true || OS::get_singleton()->is_stdout_verbose()) {
+ if (GLAD_GL_ARB_debug_output) {
+ glEnable(_EXT_DEBUG_OUTPUT_SYNCHRONOUS_ARB);
+ glDebugMessageCallbackARB(_gl_debug_print, NULL);
+ glEnable(_EXT_DEBUG_OUTPUT);
+ } else {
+ print_line("OpenGL debugging not supported!");
+ }
+ }
#endif // GLAD_ENABLED
// For debugging
#ifdef GLES_OVER_GL
- 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);
-#endif
- /* glDebugMessageInsertARB(
+ if (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);
+ /* glDebugMessageInsertARB(
GL_DEBUG_SOURCE_API_ARB,
GL_DEBUG_TYPE_OTHER_ARB, 1,
GL_DEBUG_SEVERITY_HIGH_ARB, 5, "hello");
- */
+ */
+ }
+#endif
const GLubyte *renderer = glGetString(GL_RENDERER);
print_line("OpenGL ES 2.0 Renderer: " + String((const char *)renderer));
diff --git a/drivers/gles2/rasterizer_gles2.h b/drivers/gles2/rasterizer_gles2.h
index 3ab99109cb..8d57275449 100644
--- a/drivers/gles2/rasterizer_gles2.h
+++ b/drivers/gles2/rasterizer_gles2.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
+/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/drivers/gles2/rasterizer_scene_gles2.cpp b/drivers/gles2/rasterizer_scene_gles2.cpp
index 1f19e90f4e..bb39cbcbd5 100644
--- a/drivers/gles2/rasterizer_scene_gles2.cpp
+++ b/drivers/gles2/rasterizer_scene_gles2.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
+/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/drivers/gles2/rasterizer_scene_gles2.h b/drivers/gles2/rasterizer_scene_gles2.h
index 723accbb3b..99f034afed 100644
--- a/drivers/gles2/rasterizer_scene_gles2.h
+++ b/drivers/gles2/rasterizer_scene_gles2.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
+/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/drivers/gles2/rasterizer_storage_gles2.cpp b/drivers/gles2/rasterizer_storage_gles2.cpp
index 0f5c139f45..5bca3ee548 100644
--- a/drivers/gles2/rasterizer_storage_gles2.cpp
+++ b/drivers/gles2/rasterizer_storage_gles2.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
+/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/drivers/gles2/rasterizer_storage_gles2.h b/drivers/gles2/rasterizer_storage_gles2.h
index c3c3a391d4..9f8d8d100b 100644
--- a/drivers/gles2/rasterizer_storage_gles2.h
+++ b/drivers/gles2/rasterizer_storage_gles2.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
+/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/drivers/gles2/shader_compiler_gles2.cpp b/drivers/gles2/shader_compiler_gles2.cpp
index d2a4226905..ad6c2f850a 100644
--- a/drivers/gles2/shader_compiler_gles2.cpp
+++ b/drivers/gles2/shader_compiler_gles2.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
+/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -872,9 +872,9 @@ ShaderCompilerGLES2::ShaderCompilerGLES2() {
actions[VS::SHADER_PARTICLES].renames["EMISSION_TRANSFORM"] = "emission_transform";
actions[VS::SHADER_PARTICLES].renames["RANDOM_SEED"] = "random_seed";
- actions[VS::SHADER_SPATIAL].render_mode_defines["disable_force"] = "#define DISABLE_FORCE\n";
- actions[VS::SHADER_SPATIAL].render_mode_defines["disable_velocity"] = "#define DISABLE_VELOCITY\n";
- actions[VS::SHADER_SPATIAL].render_mode_defines["keep_data"] = "#define ENABLE_KEEP_DATA\n";
+ actions[VS::SHADER_PARTICLES].render_mode_defines["disable_force"] = "#define DISABLE_FORCE\n";
+ actions[VS::SHADER_PARTICLES].render_mode_defines["disable_velocity"] = "#define DISABLE_VELOCITY\n";
+ actions[VS::SHADER_PARTICLES].render_mode_defines["keep_data"] = "#define ENABLE_KEEP_DATA\n";
vertex_name = "vertex";
fragment_name = "fragment";
diff --git a/drivers/gles2/shader_compiler_gles2.h b/drivers/gles2/shader_compiler_gles2.h
index b9cbc216d7..804ead2172 100644
--- a/drivers/gles2/shader_compiler_gles2.h
+++ b/drivers/gles2/shader_compiler_gles2.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
+/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/drivers/gles2/shader_gles2.cpp b/drivers/gles2/shader_gles2.cpp
index 7564497d47..fa9562877d 100644
--- a/drivers/gles2/shader_gles2.cpp
+++ b/drivers/gles2/shader_gles2.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
+/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/drivers/gles2/shader_gles2.h b/drivers/gles2/shader_gles2.h
index d92c1ddb62..c3635bc201 100644
--- a/drivers/gles2/shader_gles2.h
+++ b/drivers/gles2/shader_gles2.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
+/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/drivers/gles3/rasterizer_canvas_gles3.cpp b/drivers/gles3/rasterizer_canvas_gles3.cpp
index 85fd565f5b..c33fdaa355 100644
--- a/drivers/gles3/rasterizer_canvas_gles3.cpp
+++ b/drivers/gles3/rasterizer_canvas_gles3.cpp
@@ -566,7 +566,7 @@ void RasterizerCanvasGLES3::_canvas_item_render_commands(Item *p_item, Item *cur
} else {
- _draw_generic(GL_LINES, pline->lines.size(), pline->lines.ptr(), NULL, pline->line_colors.ptr(), pline->line_colors.size() == 1);
+ _draw_generic(GL_LINE_STRIP, pline->lines.size(), pline->lines.ptr(), NULL, pline->line_colors.ptr(), pline->line_colors.size() == 1);
}
#ifdef GLES_OVER_GL
diff --git a/drivers/gles3/rasterizer_gles3.cpp b/drivers/gles3/rasterizer_gles3.cpp
index b43deab58f..ca39d9f966 100644
--- a/drivers/gles3/rasterizer_gles3.cpp
+++ b/drivers/gles3/rasterizer_gles3.cpp
@@ -160,29 +160,31 @@ void RasterizerGLES3::initialize() {
"Fatal error: Insufficient OpenGL / GLES driver support");
}
-#ifdef __APPLE__
-// FIXME glDebugMessageCallbackARB does not seem to work on Mac OS X and opengl 3, this may be an issue with our opengl canvas..
-#else
if (OS::get_singleton()->is_stdout_verbose()) {
- glEnable(_EXT_DEBUG_OUTPUT_SYNCHRONOUS_ARB);
- glDebugMessageCallbackARB(_gl_debug_print, NULL);
- glEnable(_EXT_DEBUG_OUTPUT);
+ if (GLAD_GL_ARB_debug_output) {
+ glEnable(_EXT_DEBUG_OUTPUT_SYNCHRONOUS_ARB);
+ glDebugMessageCallbackARB(_gl_debug_print, NULL);
+ glEnable(_EXT_DEBUG_OUTPUT);
+ } else {
+ print_line("OpenGL debugging not supported!");
+ }
}
-#endif
#endif // GLAD_ENABLED
/* // For debugging
- glDebugMessageControlARB(GL_DEBUG_SOURCE_API_ARB,GL_DEBUG_TYPE_ERROR_ARB,GL_DEBUG_SEVERITY_HIGH_ARB,0,NULL,GL_TRUE);
- glDebugMessageControlARB(GL_DEBUG_SOURCE_API_ARB,GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB,GL_DEBUG_SEVERITY_HIGH_ARB,0,NULL,GL_TRUE);
- glDebugMessageControlARB(GL_DEBUG_SOURCE_API_ARB,GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB,GL_DEBUG_SEVERITY_HIGH_ARB,0,NULL,GL_TRUE);
- glDebugMessageControlARB(GL_DEBUG_SOURCE_API_ARB,GL_DEBUG_TYPE_PORTABILITY_ARB,GL_DEBUG_SEVERITY_HIGH_ARB,0,NULL,GL_TRUE);
- glDebugMessageControlARB(GL_DEBUG_SOURCE_API_ARB,GL_DEBUG_TYPE_PERFORMANCE_ARB,GL_DEBUG_SEVERITY_HIGH_ARB,0,NULL,GL_TRUE);
- glDebugMessageControlARB(GL_DEBUG_SOURCE_API_ARB,GL_DEBUG_TYPE_OTHER_ARB,GL_DEBUG_SEVERITY_HIGH_ARB,0,NULL,GL_TRUE);
- glDebugMessageInsertARB(
- GL_DEBUG_SOURCE_API_ARB,
- GL_DEBUG_TYPE_OTHER_ARB, 1,
- GL_DEBUG_SEVERITY_HIGH_ARB,5, "hello");
+ if (GLAD_GL_ARB_debug_output) {
+ glDebugMessageControlARB(GL_DEBUG_SOURCE_API_ARB,GL_DEBUG_TYPE_ERROR_ARB,GL_DEBUG_SEVERITY_HIGH_ARB,0,NULL,GL_TRUE);
+ glDebugMessageControlARB(GL_DEBUG_SOURCE_API_ARB,GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB,GL_DEBUG_SEVERITY_HIGH_ARB,0,NULL,GL_TRUE);
+ glDebugMessageControlARB(GL_DEBUG_SOURCE_API_ARB,GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB,GL_DEBUG_SEVERITY_HIGH_ARB,0,NULL,GL_TRUE);
+ glDebugMessageControlARB(GL_DEBUG_SOURCE_API_ARB,GL_DEBUG_TYPE_PORTABILITY_ARB,GL_DEBUG_SEVERITY_HIGH_ARB,0,NULL,GL_TRUE);
+ glDebugMessageControlARB(GL_DEBUG_SOURCE_API_ARB,GL_DEBUG_TYPE_PERFORMANCE_ARB,GL_DEBUG_SEVERITY_HIGH_ARB,0,NULL,GL_TRUE);
+ glDebugMessageControlARB(GL_DEBUG_SOURCE_API_ARB,GL_DEBUG_TYPE_OTHER_ARB,GL_DEBUG_SEVERITY_HIGH_ARB,0,NULL,GL_TRUE);
+ glDebugMessageInsertARB(
+ GL_DEBUG_SOURCE_API_ARB,
+ GL_DEBUG_TYPE_OTHER_ARB, 1,
+ GL_DEBUG_SEVERITY_HIGH_ARB,5, "hello");
+ }
*/
const GLubyte *renderer = glGetString(GL_RENDERER);
@@ -413,4 +415,5 @@ RasterizerGLES3::~RasterizerGLES3() {
memdelete(storage);
memdelete(canvas);
+ memdelete(scene);
}
diff --git a/drivers/gles3/rasterizer_scene_gles3.cpp b/drivers/gles3/rasterizer_scene_gles3.cpp
index 5bb332816d..5b6b3d44f2 100644
--- a/drivers/gles3/rasterizer_scene_gles3.cpp
+++ b/drivers/gles3/rasterizer_scene_gles3.cpp
@@ -2085,9 +2085,9 @@ void RasterizerSceneGLES3::_render_list(RenderList::Element **p_elements, int p_
case RasterizerStorageGLES3::Shader::Spatial::BLEND_MODE_MUL: {
glBlendEquation(GL_FUNC_ADD);
if (storage->frame.current_rt && storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_TRANSPARENT]) {
- glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+ glBlendFuncSeparate(GL_DST_COLOR, GL_ZERO, GL_DST_ALPHA, GL_ZERO);
} else {
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glBlendFuncSeparate(GL_DST_COLOR, GL_ZERO, GL_ZERO, GL_ONE);
}
} break;
@@ -5118,3 +5118,23 @@ void RasterizerSceneGLES3::finalize() {
RasterizerSceneGLES3::RasterizerSceneGLES3() {
}
+
+RasterizerSceneGLES3::~RasterizerSceneGLES3() {
+
+ memdelete(default_material.get_data());
+ memdelete(default_material_twosided.get_data());
+ memdelete(default_shader.get_data());
+ memdelete(default_shader_twosided.get_data());
+
+ memdelete(default_worldcoord_material.get_data());
+ memdelete(default_worldcoord_material_twosided.get_data());
+ memdelete(default_worldcoord_shader.get_data());
+ memdelete(default_worldcoord_shader_twosided.get_data());
+
+ memdelete(default_overdraw_material.get_data());
+ memdelete(default_overdraw_shader.get_data());
+
+ memfree(state.spot_array_tmp);
+ memfree(state.omni_array_tmp);
+ memfree(state.reflection_array_tmp);
+}
diff --git a/drivers/gles3/rasterizer_scene_gles3.h b/drivers/gles3/rasterizer_scene_gles3.h
index 1b99e119ce..a6faeef473 100644
--- a/drivers/gles3/rasterizer_scene_gles3.h
+++ b/drivers/gles3/rasterizer_scene_gles3.h
@@ -852,6 +852,7 @@ public:
void initialize();
void finalize();
RasterizerSceneGLES3();
+ ~RasterizerSceneGLES3();
};
#endif // RASTERIZERSCENEGLES3_H
diff --git a/drivers/pulseaudio/audio_driver_pulseaudio.cpp b/drivers/pulseaudio/audio_driver_pulseaudio.cpp
index e90245b300..5dddb1a900 100644
--- a/drivers/pulseaudio/audio_driver_pulseaudio.cpp
+++ b/drivers/pulseaudio/audio_driver_pulseaudio.cpp
@@ -37,183 +37,215 @@
#include "os/os.h"
#include "project_settings.h"
-void pa_state_cb(pa_context *c, void *userdata) {
- pa_context_state_t state;
- int *pa_ready = (int *)userdata;
+void AudioDriverPulseAudio::pa_state_cb(pa_context *c, void *userdata) {
+ AudioDriverPulseAudio *ad = (AudioDriverPulseAudio *)userdata;
- state = pa_context_get_state(c);
- switch (state) {
- case PA_CONTEXT_FAILED:
+ switch (pa_context_get_state(c)) {
case PA_CONTEXT_TERMINATED:
- *pa_ready = 2;
+ case PA_CONTEXT_FAILED:
+ ad->pa_ready = -1;
break;
case PA_CONTEXT_READY:
- *pa_ready = 1;
+ ad->pa_ready = 1;
break;
}
}
-void sink_info_cb(pa_context *c, const pa_sink_info *l, int eol, void *userdata) {
- unsigned int *channels = (unsigned int *)userdata;
+void AudioDriverPulseAudio::pa_sink_info_cb(pa_context *c, const pa_sink_info *l, int eol, void *userdata) {
+ AudioDriverPulseAudio *ad = (AudioDriverPulseAudio *)userdata;
// If eol is set to a positive number, you're at the end of the list
if (eol > 0) {
return;
}
- *channels = l->channel_map.channels;
+ ad->pa_channels = l->channel_map.channels;
+ ad->pa_status++;
}
-void server_info_cb(pa_context *c, const pa_server_info *i, void *userdata) {
- char *default_output = (char *)userdata;
+void AudioDriverPulseAudio::pa_server_info_cb(pa_context *c, const pa_server_info *i, void *userdata) {
+ AudioDriverPulseAudio *ad = (AudioDriverPulseAudio *)userdata;
- strncpy(default_output, i->default_sink_name, 1024);
+ ad->default_device = i->default_sink_name;
+ ad->pa_status++;
}
-static unsigned int detect_channels() {
-
- pa_mainloop *pa_ml;
- pa_mainloop_api *pa_mlapi;
- pa_operation *pa_op;
- pa_context *pa_ctx;
-
- int state = 0;
- int pa_ready = 0;
-
- char default_output[1024];
- unsigned int channels = 2;
+void AudioDriverPulseAudio::detect_channels() {
- pa_ml = pa_mainloop_new();
- pa_mlapi = pa_mainloop_get_api(pa_ml);
- pa_ctx = pa_context_new(pa_mlapi, "Godot");
+ pa_channels = 2;
- int ret = pa_context_connect(pa_ctx, NULL, PA_CONTEXT_NOFLAGS, NULL);
- if (ret < 0) {
- pa_context_unref(pa_ctx);
- pa_mainloop_free(pa_ml);
-
- return 2;
- }
-
- pa_context_set_state_callback(pa_ctx, pa_state_cb, &pa_ready);
+ if (device_name == "Default") {
+ // Get the default output device name
+ pa_status = 0;
+ 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);
+ if (ret < 0) {
+ ERR_PRINT("pa_mainloop_iterate error");
+ }
+ }
- // Wait until the pa server is ready
- while (pa_ready == 0) {
- pa_mainloop_iterate(pa_ml, 1, NULL);
+ pa_operation_unref(pa_op);
+ } else {
+ ERR_PRINT("pa_context_get_server_info error");
+ }
}
- // Check if there was an error connecting to the pa server
- if (pa_ready == 2) {
- pa_context_disconnect(pa_ctx);
- pa_context_unref(pa_ctx);
- pa_mainloop_free(pa_ml);
-
- return 2;
+ char device[1024];
+ if (device_name == "Default") {
+ strcpy(device, default_device.utf8().get_data());
+ } else {
+ strcpy(device, device_name.utf8().get_data());
}
- // Get the default output device name
- pa_op = pa_context_get_server_info(pa_ctx, &server_info_cb, (void *)default_output);
+ // Now using the device name get the amount of channels
+ pa_status = 0;
+ pa_operation *pa_op = pa_context_get_sink_info_by_name(pa_ctx, device, &AudioDriverPulseAudio::pa_sink_info_cb, (void *)this);
if (pa_op) {
- while (pa_operation_get_state(pa_op) == PA_OPERATION_RUNNING) {
- ret = pa_mainloop_iterate(pa_ml, 1, NULL);
+ while (pa_status == 0) {
+ int ret = pa_mainloop_iterate(pa_ml, 1, NULL);
if (ret < 0) {
ERR_PRINT("pa_mainloop_iterate error");
}
}
pa_operation_unref(pa_op);
-
- // Now using the device name get the amount of channels
- pa_op = pa_context_get_sink_info_by_name(pa_ctx, default_output, &sink_info_cb, (void *)&channels);
- if (pa_op) {
- while (pa_operation_get_state(pa_op) == PA_OPERATION_RUNNING) {
- ret = pa_mainloop_iterate(pa_ml, 1, NULL);
- if (ret < 0) {
- ERR_PRINT("pa_mainloop_iterate error");
- }
- }
-
- pa_operation_unref(pa_op);
- } else {
- ERR_PRINT("pa_context_get_sink_info_by_name error");
- }
} else {
- ERR_PRINT("pa_context_get_server_info error");
+ ERR_PRINT("pa_context_get_sink_info_by_name error");
}
-
- pa_context_disconnect(pa_ctx);
- pa_context_unref(pa_ctx);
- pa_mainloop_free(pa_ml);
-
- return channels;
}
-Error AudioDriverPulseAudio::init() {
+Error AudioDriverPulseAudio::init_device() {
- active = false;
- thread_exited = false;
- exit_thread = false;
+ // If there is a specified device check that it is really present
+ if (device_name != "Default") {
+ Array list = get_device_list();
+ if (list.find(device_name) == -1) {
+ device_name = "Default";
+ new_device = "Default";
+ }
+ }
- mix_rate = GLOBAL_DEF("audio/mix_rate", DEFAULT_MIX_RATE);
- channels = detect_channels();
+ // Detect the amount of channels PulseAudio is using
+ // Note: If using an even amount of channels (2, 4, etc) channels and pa_channels will be equal,
+ // if not then pa_channels will have the real amount of channels PulseAudio is using and channels
+ // will have the amount of channels Godot is using (in this case it's pa_channels + 1)
+ detect_channels();
+ switch (pa_channels) {
+ case 1: // Mono
+ case 3: // Surround 2.1
+ case 5: // Surround 5.0
+ case 7: // Surround 7.0
+ channels = pa_channels + 1;
+ break;
- switch (channels) {
case 2: // Stereo
- case 4: // Surround 3.1
+ case 4: // Surround 4.0
case 6: // Surround 5.1
case 8: // Surround 7.1
+ channels = pa_channels;
break;
default:
- ERR_PRINTS("PulseAudio: Unsupported number of channels: " + itos(channels));
+ ERR_PRINTS("PulseAudio: Unsupported number of channels: " + itos(pa_channels));
ERR_FAIL_V(ERR_CANT_OPEN);
break;
}
pa_sample_spec spec;
spec.format = PA_SAMPLE_S16LE;
- spec.channels = channels;
+ spec.channels = pa_channels;
spec.rate = mix_rate;
int latency = GLOBAL_DEF("audio/output_latency", DEFAULT_OUTPUT_LATENCY);
buffer_frames = closest_power_of_2(latency * mix_rate / 1000);
- buffer_size = buffer_frames * channels;
+ pa_buffer_size = buffer_frames * pa_channels;
if (OS::get_singleton()->is_stdout_verbose()) {
- print_line("PulseAudio: detected " + itos(channels) + " channels");
+ print_line("PulseAudio: detected " + itos(pa_channels) + " channels");
print_line("PulseAudio: audio buffer frames: " + itos(buffer_frames) + " calculated latency: " + itos(buffer_frames * 1000 / mix_rate) + "ms");
}
pa_buffer_attr attr;
// set to appropriate buffer length (in bytes) from global settings
- attr.tlength = buffer_size * sizeof(int16_t);
+ attr.tlength = pa_buffer_size * sizeof(int16_t);
// set them to be automatically chosen
attr.prebuf = (uint32_t)-1;
attr.maxlength = (uint32_t)-1;
attr.minreq = (uint32_t)-1;
- int error_code;
- pulse = pa_simple_new(NULL, // default server
- "Godot", // application name
- PA_STREAM_PLAYBACK,
- NULL, // default device
- "Sound", // stream description
- &spec,
- NULL, // use default channel map
- &attr, // use buffering attributes from above
- &error_code);
-
- if (pulse == NULL) {
- fprintf(stderr, "PulseAudio ERR: %s\n", pa_strerror(error_code));
- ERR_FAIL_COND_V(pulse == NULL, ERR_CANT_OPEN);
+ pa_str = pa_stream_new(pa_ctx, "Sound", &spec, NULL);
+ ERR_FAIL_COND_V(pa_ctx == NULL, ERR_CANT_OPEN);
+
+ const char *dev = device_name == "Default" ? NULL : 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);
+ ERR_FAIL_COND_V(error_code < 0, ERR_CANT_OPEN);
+
+ samples_in.resize(buffer_frames * channels);
+ samples_out.resize(pa_buffer_size);
+
+ return OK;
+}
+
+Error AudioDriverPulseAudio::init() {
+
+ active = false;
+ thread_exited = false;
+ exit_thread = false;
+
+ mix_rate = GLOBAL_DEF("audio/mix_rate", DEFAULT_MIX_RATE);
+
+ pa_ml = pa_mainloop_new();
+ ERR_FAIL_COND_V(pa_ml == NULL, 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);
+
+ 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);
+ if (ret < 0) {
+ if (pa_ctx) {
+ pa_context_unref(pa_ctx);
+ pa_ctx = NULL;
+ }
+
+ if (pa_ml) {
+ pa_mainloop_free(pa_ml);
+ pa_ml = NULL;
+ }
+
+ return ERR_CANT_OPEN;
}
- samples_in.resize(buffer_size);
- samples_out.resize(buffer_size);
+ while (pa_ready == 0) {
+ pa_mainloop_iterate(pa_ml, 1, NULL);
+ }
- mutex = Mutex::create();
- thread = Thread::create(AudioDriverPulseAudio::thread_func, this);
+ if (pa_ready < 0) {
+ if (pa_ctx) {
+ pa_context_disconnect(pa_ctx);
+ pa_context_unref(pa_ctx);
+ pa_ctx = NULL;
+ }
+
+ if (pa_ml) {
+ pa_mainloop_free(pa_ml);
+ pa_ml = NULL;
+ }
+
+ return ERR_CANT_OPEN;
+ }
+
+ Error err = init_device();
+ if (err == OK) {
+ mutex = Mutex::create();
+ thread = Thread::create(AudioDriverPulseAudio::thread_func, this);
+ }
return OK;
}
@@ -221,9 +253,24 @@ Error AudioDriverPulseAudio::init() {
float AudioDriverPulseAudio::get_latency() {
if (latency == 0) { //only do this once since it's approximate anyway
- int error_code;
- pa_usec_t palat = pa_simple_get_latency(pulse, &error_code);
- latency = double(palat) / 1000000.0;
+ lock();
+
+ pa_usec_t palat = 0;
+ if (pa_stream_get_state(pa_str) == PA_STREAM_READY) {
+ int negative = 0;
+
+ if (pa_stream_get_latency(pa_str, &palat, &negative) >= 0) {
+ if (negative) {
+ palat = 0;
+ }
+ }
+ }
+
+ if (palat > 0) {
+ latency = double(palat) / 1000000.0;
+ }
+
+ unlock();
}
return latency;
@@ -235,7 +282,7 @@ void AudioDriverPulseAudio::thread_func(void *p_udata) {
while (!ad->exit_thread) {
if (!ad->active) {
- for (unsigned int i = 0; i < ad->buffer_size; i++) {
+ for (unsigned int i = 0; i < ad->pa_buffer_size; i++) {
ad->samples_out[i] = 0;
}
@@ -246,22 +293,77 @@ void AudioDriverPulseAudio::thread_func(void *p_udata) {
ad->unlock();
- for (unsigned int i = 0; i < ad->buffer_size; i++) {
- ad->samples_out[i] = ad->samples_in[i] >> 16;
+ if (ad->channels == ad->pa_channels) {
+ for (unsigned int i = 0; i < ad->pa_buffer_size; i++) {
+ ad->samples_out[i] = ad->samples_in[i] >> 16;
+ }
+ } else {
+ // Uneven amount of channels
+ unsigned int in_idx = 0;
+ unsigned int out_idx = 0;
+
+ for (unsigned int i = 0; i < ad->buffer_frames; i++) {
+ for (unsigned int j = 0; j < ad->pa_channels - 1; j++) {
+ ad->samples_out[out_idx++] = ad->samples_in[in_idx++] >> 16;
+ }
+ uint32_t l = ad->samples_in[in_idx++];
+ uint32_t r = ad->samples_in[in_idx++];
+ ad->samples_out[out_idx++] = (l >> 1 + r >> 1) >> 16;
+ }
}
}
- // pa_simple_write always consumes the entire buffer
-
int error_code;
- int byte_size = ad->buffer_size * sizeof(int16_t);
- if (pa_simple_write(ad->pulse, ad->samples_out.ptr(), byte_size, &error_code) < 0) {
- // can't recover here
- fprintf(stderr, "PulseAudio failed and can't recover: %s\n", pa_strerror(error_code));
- ad->active = false;
- ad->exit_thread = true;
- break;
+ int byte_size = ad->pa_buffer_size * sizeof(int16_t);
+
+ ad->lock();
+
+ int ret;
+ do {
+ ret = pa_mainloop_iterate(ad->pa_ml, 0, NULL);
+ } while (ret > 0);
+
+ if (pa_stream_get_state(ad->pa_str) == PA_STREAM_READY) {
+ const void *ptr = ad->samples_out.ptr();
+ while (byte_size > 0) {
+ size_t bytes = pa_stream_writable_size(ad->pa_str);
+ if (bytes > 0) {
+ if (bytes > byte_size) {
+ bytes = byte_size;
+ }
+
+ int ret = pa_stream_write(ad->pa_str, ptr, bytes, NULL, 0LL, PA_SEEK_RELATIVE);
+ if (ret >= 0) {
+ byte_size -= bytes;
+ ptr = (const char *)ptr + bytes;
+ }
+ } else {
+ pa_mainloop_iterate(ad->pa_ml, 1, NULL);
+ }
+ }
+ }
+
+ // User selected a new device, finish the current one so we'll init the new device
+ if (ad->device_name != ad->new_device) {
+ ad->device_name = ad->new_device;
+ ad->finish_device();
+
+ Error err = ad->init_device();
+ if (err != OK) {
+ ERR_PRINT("PulseAudio: init_device error");
+ ad->device_name = "Default";
+ ad->new_device = "Default";
+
+ err = ad->init_device();
+ if (err != OK) {
+ ad->active = false;
+ ad->exit_thread = true;
+ break;
+ }
+ }
}
+
+ ad->unlock();
}
ad->thread_exited = true;
@@ -282,6 +384,61 @@ AudioDriver::SpeakerMode AudioDriverPulseAudio::get_speaker_mode() const {
return get_speaker_mode_by_total_channels(channels);
}
+void AudioDriverPulseAudio::pa_sinklist_cb(pa_context *c, const pa_sink_info *l, int eol, void *userdata) {
+ AudioDriverPulseAudio *ad = (AudioDriverPulseAudio *)userdata;
+ int ctr = 0;
+
+ // If eol is set to a positive number, you're at the end of the list
+ if (eol > 0) {
+ return;
+ }
+
+ ad->pa_devices.push_back(l->name);
+ ad->pa_status++;
+}
+
+Array AudioDriverPulseAudio::get_device_list() {
+
+ pa_devices.clear();
+ pa_devices.push_back("Default");
+
+ if (pa_ctx == NULL) {
+ return pa_devices;
+ }
+
+ lock();
+
+ // Get the device list
+ pa_status = 0;
+ 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);
+ if (ret < 0) {
+ ERR_PRINT("pa_mainloop_iterate error");
+ }
+ }
+
+ pa_operation_unref(pa_op);
+ } else {
+ ERR_PRINT("pa_context_get_server_info error");
+ }
+
+ unlock();
+
+ return pa_devices;
+}
+
+String AudioDriverPulseAudio::get_device() {
+
+ return device_name;
+}
+
+void AudioDriverPulseAudio::set_device(String device) {
+
+ new_device = device;
+}
+
void AudioDriverPulseAudio::lock() {
if (!thread || !mutex)
@@ -296,6 +453,15 @@ void AudioDriverPulseAudio::unlock() {
mutex->unlock();
}
+void AudioDriverPulseAudio::finish_device() {
+
+ if (pa_str) {
+ pa_stream_disconnect(pa_str);
+ pa_stream_unref(pa_str);
+ pa_str = NULL;
+ }
+}
+
void AudioDriverPulseAudio::finish() {
if (!thread)
@@ -304,9 +470,17 @@ void AudioDriverPulseAudio::finish() {
exit_thread = true;
Thread::wait_to_finish(thread);
- if (pulse) {
- pa_simple_free(pulse);
- pulse = NULL;
+ finish_device();
+
+ if (pa_ctx) {
+ pa_context_disconnect(pa_ctx);
+ pa_context_unref(pa_ctx);
+ pa_ctx = NULL;
+ }
+
+ if (pa_ml) {
+ pa_mainloop_free(pa_ml);
+ pa_ml = NULL;
}
memdelete(thread);
@@ -320,25 +494,33 @@ void AudioDriverPulseAudio::finish() {
AudioDriverPulseAudio::AudioDriverPulseAudio() {
+ pa_ml = NULL;
+ pa_ctx = NULL;
+ pa_str = NULL;
+
mutex = NULL;
thread = NULL;
- pulse = NULL;
+
+ device_name = "Default";
+ new_device = "Default";
+ default_device = "";
samples_in.clear();
samples_out.clear();
mix_rate = 0;
- buffer_size = 0;
+ buffer_frames = 0;
+ pa_buffer_size = 0;
channels = 0;
+ pa_channels = 0;
+ pa_ready = 0;
+ pa_status = 0;
active = false;
thread_exited = false;
exit_thread = false;
latency = 0;
- buffer_frames = 0;
- buffer_size = 0;
- channels = 0;
}
AudioDriverPulseAudio::~AudioDriverPulseAudio() {
diff --git a/drivers/pulseaudio/audio_driver_pulseaudio.h b/drivers/pulseaudio/audio_driver_pulseaudio.h
index 3bd1146f53..934031e2a5 100644
--- a/drivers/pulseaudio/audio_driver_pulseaudio.h
+++ b/drivers/pulseaudio/audio_driver_pulseaudio.h
@@ -37,22 +37,32 @@
#include "core/os/thread.h"
#include "servers/audio_server.h"
-#include <pulse/simple.h>
+#include <pulse/pulseaudio.h>
class AudioDriverPulseAudio : public AudioDriver {
Thread *thread;
Mutex *mutex;
- pa_simple *pulse;
+ pa_mainloop *pa_ml;
+ pa_context *pa_ctx;
+ pa_stream *pa_str;
+
+ String device_name;
+ String new_device;
+ String default_device;
Vector<int32_t> samples_in;
Vector<int16_t> samples_out;
unsigned int mix_rate;
unsigned int buffer_frames;
- unsigned int buffer_size;
+ unsigned int pa_buffer_size;
int channels;
+ int pa_channels;
+ int pa_ready;
+ int pa_status;
+ Array pa_devices;
bool active;
bool thread_exited;
@@ -60,6 +70,16 @@ class AudioDriverPulseAudio : public AudioDriver {
float latency;
+ static void pa_state_cb(pa_context *c, void *userdata);
+ static void pa_sink_info_cb(pa_context *c, const pa_sink_info *l, int eol, void *userdata);
+ static void pa_server_info_cb(pa_context *c, const pa_server_info *i, void *userdata);
+ static void pa_sinklist_cb(pa_context *c, const pa_sink_info *l, int eol, void *userdata);
+
+ Error init_device();
+ void finish_device();
+
+ void detect_channels();
+
static void thread_func(void *p_udata);
public:
@@ -71,6 +91,9 @@ public:
virtual void start();
virtual int get_mix_rate() const;
virtual SpeakerMode get_speaker_mode() const;
+ virtual Array get_device_list();
+ virtual String get_device();
+ virtual void set_device(String device);
virtual void lock();
virtual void unlock();
virtual void finish();
diff --git a/drivers/unix/dir_access_unix.cpp b/drivers/unix/dir_access_unix.cpp
index 3944431516..5a4be6df4f 100644
--- a/drivers/unix/dir_access_unix.cpp
+++ b/drivers/unix/dir_access_unix.cpp
@@ -244,7 +244,7 @@ static void _get_drives(List<String> *list) {
// Parse only file:// links
if (strncmp(string, "file://", 7) == 0) {
// Strip any unwanted edges on the strings and push_back if it's not a duplicate
- String fpath = String(string + 7).strip_edges();
+ String fpath = String(string + 7).strip_edges().split_spaces()[0].percent_decode();
if (!list->find(fpath)) {
list->push_back(fpath);
}
diff --git a/drivers/unix/file_access_unix.cpp b/drivers/unix/file_access_unix.cpp
index 5b093a5885..a7a3eef935 100644
--- a/drivers/unix/file_access_unix.cpp
+++ b/drivers/unix/file_access_unix.cpp
@@ -69,6 +69,7 @@ Error FileAccessUnix::_open(const String &p_path, int p_mode_flags) {
fclose(f);
f = NULL;
+ path_src = p_path;
path = fix_path(p_path);
//printf("opening %ls, %i\n", path.c_str(), Memory::get_static_mem_usage());
@@ -152,6 +153,16 @@ bool FileAccessUnix::is_open() const {
return (f != NULL);
}
+String FileAccessUnix::get_path() const {
+
+ return path_src;
+}
+
+String FileAccessUnix::get_path_absolute() const {
+
+ return path;
+}
+
void FileAccessUnix::seek(size_t p_position) {
ERR_FAIL_COND(!f);
diff --git a/drivers/unix/file_access_unix.h b/drivers/unix/file_access_unix.h
index dbb1c9f3b5..88bb39fbd1 100644
--- a/drivers/unix/file_access_unix.h
+++ b/drivers/unix/file_access_unix.h
@@ -51,6 +51,7 @@ class FileAccessUnix : public FileAccess {
mutable Error last_error;
String save_path;
String path;
+ String path_src;
static FileAccess *create_libc();
@@ -61,6 +62,9 @@ public:
virtual void close(); ///< close a file
virtual bool is_open() const; ///< true when file is open
+ virtual String get_path() const; /// returns the path for the current open file
+ virtual String get_path_absolute() const; /// returns the absolute path for the current open file
+
virtual void seek(size_t p_position); ///< seek to a given position
virtual void seek_end(int64_t p_position = 0); ///< seek from the end of file
virtual size_t get_position() const; ///< get position in the file
diff --git a/drivers/unix/os_unix.cpp b/drivers/unix/os_unix.cpp
index aa01f22673..31c8e4ade9 100644
--- a/drivers/unix/os_unix.cpp
+++ b/drivers/unix/os_unix.cpp
@@ -73,15 +73,6 @@ void OS_Unix::debug_break() {
assert(false);
};
-int OS_Unix::get_audio_driver_count() const {
-
- return 1;
-}
-const char *OS_Unix::get_audio_driver_name(int p_driver) const {
-
- return "dummy";
-}
-
int OS_Unix::unix_initialize_audio(int p_audio_driver) {
return 0;
@@ -98,10 +89,11 @@ void handle_sigchld(int sig) {
void OS_Unix::initialize_core() {
-#ifdef NO_PTHREADS
+#ifdef NO_THREADS
ThreadDummy::make_default();
SemaphoreDummy::make_default();
MutexDummy::make_default();
+ RWLockDummy::make_default();
#else
ThreadPosix::make_default();
SemaphorePosix::make_default();
diff --git a/drivers/unix/os_unix.h b/drivers/unix/os_unix.h
index a7c9015330..db0fe1e00b 100644
--- a/drivers/unix/os_unix.h
+++ b/drivers/unix/os_unix.h
@@ -48,12 +48,6 @@ protected:
// UNIX only handles the core functions.
// inheriting platforms under unix (eg. X11) should handle the rest
- //virtual int get_video_driver_count() const;
- //virtual const char * get_video_driver_name(int p_driver) const;
-
- virtual int get_audio_driver_count() const;
- virtual const char *get_audio_driver_name(int p_driver) const;
-
virtual void initialize_core();
virtual int unix_initialize_audio(int p_audio_driver);
//virtual Error initialize(int p_video_driver,int p_audio_driver);
diff --git a/drivers/unix/thread_posix.cpp b/drivers/unix/thread_posix.cpp
index f079ae2ae2..a73b40a6f2 100644
--- a/drivers/unix/thread_posix.cpp
+++ b/drivers/unix/thread_posix.cpp
@@ -31,7 +31,7 @@
#include "thread_posix.h"
#include "script_language.h"
-#if defined(UNIX_ENABLED) || defined(PTHREAD_ENABLED)
+#if (defined(UNIX_ENABLED) || defined(PTHREAD_ENABLED)) && !defined(NO_THREADS)
#ifdef PTHREAD_BSD_SET_NAME
#include <pthread_np.h>
diff --git a/drivers/unix/thread_posix.h b/drivers/unix/thread_posix.h
index 15c9265e6d..ea2de61bd5 100644
--- a/drivers/unix/thread_posix.h
+++ b/drivers/unix/thread_posix.h
@@ -35,7 +35,7 @@
@author Juan Linietsky <reduzio@gmail.com>
*/
-#if defined(UNIX_ENABLED) || defined(PTHREAD_ENABLED)
+#if (defined(UNIX_ENABLED) || defined(PTHREAD_ENABLED)) && !defined(NO_THREADS)
#include "os/thread.h"
#include <pthread.h>
diff --git a/drivers/wasapi/audio_driver_wasapi.cpp b/drivers/wasapi/audio_driver_wasapi.cpp
index 36acfb10d1..966b69a67e 100644
--- a/drivers/wasapi/audio_driver_wasapi.cpp
+++ b/drivers/wasapi/audio_driver_wasapi.cpp
@@ -35,6 +35,8 @@
#include "os/os.h"
#include "project_settings.h"
+#include <functiondiscoverykeys.h>
+
const CLSID CLSID_MMDeviceEnumerator = __uuidof(MMDeviceEnumerator);
const IID IID_IMMDeviceEnumerator = __uuidof(IMMDeviceEnumerator);
const IID IID_IAudioClient = __uuidof(IAudioClient);
@@ -121,7 +123,61 @@ Error AudioDriverWASAPI::init_device(bool reinit) {
HRESULT hr = CoCreateInstance(CLSID_MMDeviceEnumerator, NULL, CLSCTX_ALL, IID_IMMDeviceEnumerator, (void **)&enumerator);
ERR_FAIL_COND_V(hr != S_OK, ERR_CANT_OPEN);
- hr = enumerator->GetDefaultAudioEndpoint(eRender, eConsole, &device);
+ if (device_name == "Default") {
+ hr = enumerator->GetDefaultAudioEndpoint(eRender, eConsole, &device);
+ } else {
+ IMMDeviceCollection *devices = NULL;
+
+ hr = enumerator->EnumAudioEndpoints(eRender, DEVICE_STATE_ACTIVE, &devices);
+ ERR_FAIL_COND_V(hr != S_OK, ERR_CANT_OPEN);
+
+ LPWSTR strId = NULL;
+ bool found = false;
+
+ UINT count = 0;
+ hr = devices->GetCount(&count);
+ ERR_FAIL_COND_V(hr != S_OK, ERR_CANT_OPEN);
+
+ for (ULONG i = 0; i < count && !found; i++) {
+ IMMDevice *device = NULL;
+
+ hr = devices->Item(i, &device);
+ ERR_BREAK(hr != S_OK);
+
+ IPropertyStore *props = NULL;
+ hr = device->OpenPropertyStore(STGM_READ, &props);
+ ERR_BREAK(hr != S_OK);
+
+ PROPVARIANT propvar;
+ PropVariantInit(&propvar);
+
+ hr = props->GetValue(PKEY_Device_FriendlyName, &propvar);
+ ERR_BREAK(hr != S_OK);
+
+ if (device_name == String(propvar.pwszVal)) {
+ hr = device->GetId(&strId);
+ ERR_BREAK(hr != S_OK);
+
+ found = true;
+ }
+
+ PropVariantClear(&propvar);
+ props->Release();
+ device->Release();
+ }
+
+ if (found) {
+ hr = enumerator->GetDevice(strId, &device);
+ }
+
+ if (strId) {
+ CoTaskMemFree(strId);
+ }
+
+ if (device == NULL) {
+ hr = enumerator->GetDefaultAudioEndpoint(eRender, eConsole, &device);
+ }
+ }
if (reinit) {
// In case we're trying to re-initialize the device prevent throwing this error on the console,
// otherwise if there is currently no device available this will spam the console.
@@ -151,7 +207,6 @@ Error AudioDriverWASAPI::init_device(bool reinit) {
// Since we're using WASAPI Shared Mode we can't control any of these, we just tag along
wasapi_channels = pwfex->nChannels;
- mix_rate = pwfex->nSamplesPerSec;
format_tag = pwfex->wFormatTag;
bits_per_sample = pwfex->wBitsPerSample;
@@ -187,7 +242,14 @@ Error AudioDriverWASAPI::init_device(bool reinit) {
}
}
- hr = audio_client->Initialize(AUDCLNT_SHAREMODE_SHARED, AUDCLNT_STREAMFLAGS_EVENTCALLBACK, 0, 0, pwfex, NULL);
+ DWORD streamflags = AUDCLNT_STREAMFLAGS_EVENTCALLBACK;
+ if (mix_rate != pwfex->nSamplesPerSec) {
+ streamflags |= AUDCLNT_STREAMFLAGS_RATEADJUST;
+ pwfex->nSamplesPerSec = mix_rate;
+ pwfex->nAvgBytesPerSec = pwfex->nSamplesPerSec * pwfex->nChannels * (pwfex->wBitsPerSample / 8);
+ }
+
+ hr = audio_client->Initialize(AUDCLNT_SHAREMODE_SHARED, streamflags, 0, 0, pwfex, NULL);
ERR_FAIL_COND_V(hr != S_OK, ERR_CANT_OPEN);
event = CreateEvent(NULL, FALSE, FALSE, NULL);
@@ -223,10 +285,11 @@ Error AudioDriverWASAPI::finish_device() {
if (audio_client) {
if (active) {
audio_client->Stop();
- audio_client->Release();
- audio_client = NULL;
active = false;
}
+
+ audio_client->Release();
+ audio_client = NULL;
}
if (render_client) {
@@ -244,6 +307,8 @@ Error AudioDriverWASAPI::finish_device() {
Error AudioDriverWASAPI::init() {
+ mix_rate = GLOBAL_DEF("audio/mix_rate", DEFAULT_MIX_RATE);
+
Error err = init_device();
if (err != OK) {
ERR_PRINT("WASAPI: init_device error");
@@ -285,6 +350,64 @@ AudioDriver::SpeakerMode AudioDriverWASAPI::get_speaker_mode() const {
return get_speaker_mode_by_total_channels(channels);
}
+Array AudioDriverWASAPI::get_device_list() {
+
+ Array list;
+ IMMDeviceCollection *devices = NULL;
+ IMMDeviceEnumerator *enumerator = NULL;
+
+ list.push_back(String("Default"));
+
+ CoInitialize(NULL);
+
+ HRESULT hr = CoCreateInstance(CLSID_MMDeviceEnumerator, NULL, CLSCTX_ALL, IID_IMMDeviceEnumerator, (void **)&enumerator);
+ ERR_FAIL_COND_V(hr != S_OK, Array());
+
+ hr = enumerator->EnumAudioEndpoints(eRender, DEVICE_STATE_ACTIVE, &devices);
+ ERR_FAIL_COND_V(hr != S_OK, Array());
+
+ UINT count = 0;
+ hr = devices->GetCount(&count);
+ ERR_FAIL_COND_V(hr != S_OK, Array());
+
+ for (ULONG i = 0; i < count; i++) {
+ IMMDevice *device = NULL;
+
+ hr = devices->Item(i, &device);
+ ERR_BREAK(hr != S_OK);
+
+ IPropertyStore *props = NULL;
+ hr = device->OpenPropertyStore(STGM_READ, &props);
+ ERR_BREAK(hr != S_OK);
+
+ PROPVARIANT propvar;
+ PropVariantInit(&propvar);
+
+ hr = props->GetValue(PKEY_Device_FriendlyName, &propvar);
+ ERR_BREAK(hr != S_OK);
+
+ list.push_back(String(propvar.pwszVal));
+
+ PropVariantClear(&propvar);
+ props->Release();
+ device->Release();
+ }
+
+ devices->Release();
+ enumerator->Release();
+ return list;
+}
+
+String AudioDriverWASAPI::get_device() {
+
+ return device_name;
+}
+
+void AudioDriverWASAPI::set_device(String device) {
+
+ new_device = device;
+}
+
void AudioDriverWASAPI::write_sample(AudioDriverWASAPI *ad, BYTE *buffer, int i, int32_t sample) {
if (ad->format_tag == WAVE_FORMAT_PCM) {
switch (ad->bits_per_sample) {
@@ -400,7 +523,8 @@ void AudioDriverWASAPI::thread_func(void *p_udata) {
}
}
- if (default_device_changed) {
+ // If we're using the Default device and it changed finish it so we'll re-init the device
+ if (ad->device_name == "Default" && default_device_changed) {
Error err = ad->finish_device();
if (err != OK) {
ERR_PRINT("WASAPI: finish_device error");
@@ -409,6 +533,15 @@ void AudioDriverWASAPI::thread_func(void *p_udata) {
default_device_changed = false;
}
+ // User selected a new device, finish the current one so we'll init the new device
+ if (ad->device_name != ad->new_device) {
+ ad->device_name = ad->new_device;
+ Error err = ad->finish_device();
+ if (err != OK) {
+ ERR_PRINT("WASAPI: finish_device error");
+ }
+ }
+
if (!ad->audio_client) {
Error err = ad->init_device(true);
if (err == OK) {
@@ -483,6 +616,9 @@ AudioDriverWASAPI::AudioDriverWASAPI() {
thread_exited = false;
exit_thread = false;
active = false;
+
+ device_name = "Default";
+ new_device = "Default";
}
#endif
diff --git a/drivers/wasapi/audio_driver_wasapi.h b/drivers/wasapi/audio_driver_wasapi.h
index 2b19f0cca1..c97f4c288c 100644
--- a/drivers/wasapi/audio_driver_wasapi.h
+++ b/drivers/wasapi/audio_driver_wasapi.h
@@ -49,6 +49,9 @@ class AudioDriverWASAPI : public AudioDriver {
Mutex *mutex;
Thread *thread;
+ String device_name;
+ String new_device;
+
WORD format_tag;
WORD bits_per_sample;
@@ -80,6 +83,9 @@ public:
virtual void start();
virtual int get_mix_rate() const;
virtual SpeakerMode get_speaker_mode() const;
+ virtual Array get_device_list();
+ virtual String get_device();
+ virtual void set_device(String device);
virtual void lock();
virtual void unlock();
virtual void finish();
diff --git a/drivers/windows/file_access_windows.cpp b/drivers/windows/file_access_windows.cpp
index 072790876f..23c8ea2ec7 100644
--- a/drivers/windows/file_access_windows.cpp
+++ b/drivers/windows/file_access_windows.cpp
@@ -57,7 +57,8 @@ void FileAccessWindows::check_errors() const {
Error FileAccessWindows::_open(const String &p_path, int p_mode_flags) {
- String filename = fix_path(p_path);
+ path_src = p_path;
+ path = fix_path(p_path);
if (f)
close();
@@ -78,19 +79,19 @@ Error FileAccessWindows::_open(const String &p_path, int p_mode_flags) {
backend supports utf8 encoding */
struct _stat st;
- if (_wstat(filename.c_str(), &st) == 0) {
+ if (_wstat(path.c_str(), &st) == 0) {
if (!S_ISREG(st.st_mode))
return ERR_FILE_CANT_OPEN;
};
if (is_backup_save_enabled() && p_mode_flags & WRITE && !(p_mode_flags & READ)) {
- save_path = filename;
- filename = filename + ".tmp";
+ save_path = path;
+ path = path + ".tmp";
//print_line("saving instead to "+path);
}
- f = _wfopen(filename.c_str(), mode_string);
+ f = _wfopen(path.c_str(), mode_string);
if (f == NULL) {
last_error = ERR_FILE_CANT_OPEN;
@@ -138,22 +139,36 @@ void FileAccessWindows::close() {
//atomic replace for existing file
rename_error = !ReplaceFileW(save_path.c_str(), (save_path + ".tmp").c_str(), NULL, 2 | 4, NULL, NULL);
}
- if (rename_error && close_fail_notify) {
- close_fail_notify(save_path);
- }
if (rename_error) {
attempts--;
OS::get_singleton()->delay_usec(1000000); //wait 100msec and try again
}
}
- save_path = "";
if (rename_error) {
+ if (close_fail_notify) {
+ close_fail_notify(save_path);
+ }
+
ERR_EXPLAIN("Safe save failed. This may be a permissions problem, but also may happen because you are running a paranoid antivirus. If this is the case, please switch to Windows Defender or disable the 'safe save' option in editor settings. This makes it work, but increases the risk of file corruption in a crash.");
}
+
+ save_path = "";
+
ERR_FAIL_COND(rename_error);
}
}
+
+String FileAccessWindows::get_path() const {
+
+ return path_src;
+}
+
+String FileAccessWindows::get_path_absolute() const {
+
+ return path;
+}
+
bool FileAccessWindows::is_open() const {
return (f != NULL);
diff --git a/drivers/windows/file_access_windows.h b/drivers/windows/file_access_windows.h
index 26bd08b7af..0462c1e942 100644
--- a/drivers/windows/file_access_windows.h
+++ b/drivers/windows/file_access_windows.h
@@ -46,6 +46,8 @@ class FileAccessWindows : public FileAccess {
int flags;
void check_errors() const;
mutable Error last_error;
+ String path;
+ String path_src;
String save_path;
public:
@@ -53,6 +55,9 @@ public:
virtual void close(); ///< close a file
virtual bool is_open() const; ///< true when file is open
+ virtual String get_path() const; /// returns the path for the current open file
+ virtual String get_path_absolute() const; /// returns the absolute path for the current open file
+
virtual void seek(size_t p_position); ///< seek to a given position
virtual void seek_end(int64_t p_position = 0); ///< seek from the end of file
virtual size_t get_position() const; ///< get position in the file