summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/alsa/audio_driver_alsa.cpp100
-rw-r--r--drivers/alsa/audio_driver_alsa.h17
-rw-r--r--drivers/convex_decomp/b2d_decompose.cpp195
-rw-r--r--drivers/convex_decomp/b2d_decompose.h2
-rw-r--r--drivers/gl_context/context_gl.cpp19
-rw-r--r--drivers/gl_context/context_gl.h24
-rw-r--r--drivers/gles2/rasterizer_gles2.cpp8039
-rw-r--r--drivers/gles2/rasterizer_gles2.h894
-rw-r--r--drivers/gles2/rasterizer_instance_gles2.cpp3
-rw-r--r--drivers/gles2/rasterizer_instance_gles2.h1
-rw-r--r--drivers/gles2/shader_compiler_gles2.cpp1032
-rw-r--r--drivers/gles2/shader_compiler_gles2.h20
-rw-r--r--drivers/gles2/shader_gles2.cpp621
-rw-r--r--drivers/gles2/shader_gles2.h306
-rw-r--r--drivers/gles3/rasterizer_canvas_gles3.cpp1084
-rw-r--r--drivers/gles3/rasterizer_canvas_gles3.h28
-rw-r--r--drivers/gles3/rasterizer_gles3.cpp249
-rw-r--r--drivers/gles3/rasterizer_gles3.h11
-rw-r--r--drivers/gles3/rasterizer_scene_gles3.cpp3797
-rw-r--r--drivers/gles3/rasterizer_scene_gles3.h338
-rw-r--r--drivers/gles3/rasterizer_storage_gles3.cpp4914
-rw-r--r--drivers/gles3/rasterizer_storage_gles3.h557
-rw-r--r--drivers/gles3/shader_compiler_gles3.cpp623
-rw-r--r--drivers/gles3/shader_compiler_gles3.h29
-rw-r--r--drivers/gles3/shader_gles3.cpp628
-rw-r--r--drivers/gles3/shader_gles3.h317
-rw-r--r--drivers/png/image_loader_png.cpp212
-rw-r--r--drivers/png/image_loader_png.h14
-rw-r--r--drivers/png/resource_saver_png.cpp106
-rw-r--r--drivers/png/resource_saver_png.h10
-rw-r--r--drivers/pulseaudio/audio_driver_pulseaudio.cpp41
-rw-r--r--drivers/pulseaudio/audio_driver_pulseaudio.h28
-rw-r--r--drivers/register_driver_types.cpp18
-rw-r--r--drivers/rtaudio/audio_driver_rtaudio.cpp95
-rw-r--r--drivers/rtaudio/audio_driver_rtaudio.h13
-rw-r--r--drivers/unix/dir_access_unix.cpp144
-rw-r--r--drivers/unix/dir_access_unix.h34
-rw-r--r--drivers/unix/file_access_unix.cpp144
-rw-r--r--drivers/unix/file_access_unix.h39
-rw-r--r--drivers/unix/ip_unix.cpp113
-rw-r--r--drivers/unix/ip_unix.h6
-rw-r--r--drivers/unix/mutex_posix.cpp15
-rw-r--r--drivers/unix/mutex_posix.h17
-rw-r--r--drivers/unix/os_unix.cpp251
-rw-r--r--drivers/unix/os_unix.h53
-rw-r--r--drivers/unix/packet_peer_udp_posix.cpp118
-rw-r--r--drivers/unix/packet_peer_udp_posix.h14
-rw-r--r--drivers/unix/rw_lock_posix.cpp25
-rw-r--r--drivers/unix/rw_lock_posix.h6
-rw-r--r--drivers/unix/semaphore_posix.cpp22
-rw-r--r--drivers/unix/semaphore_posix.h8
-rw-r--r--drivers/unix/socket_helpers.h48
-rw-r--r--drivers/unix/stream_peer_tcp_posix.cpp61
-rw-r--r--drivers/unix/stream_peer_tcp_posix.h18
-rw-r--r--drivers/unix/tcp_server_posix.cpp34
-rw-r--r--drivers/unix/tcp_server_posix.h6
-rw-r--r--drivers/unix/thread_posix.cpp67
-rw-r--r--drivers/unix/thread_posix.h29
-rw-r--r--drivers/windows/dir_access_windows.cpp160
-rw-r--r--drivers/windows/dir_access_windows.h9
-rw-r--r--drivers/windows/file_access_windows.cpp132
-rw-r--r--drivers/windows/file_access_windows.h10
-rw-r--r--drivers/windows/mutex_windows.cpp46
-rw-r--r--drivers/windows/mutex_windows.h19
-rw-r--r--drivers/windows/rw_lock_windows.cpp18
-rw-r--r--drivers/windows/rw_lock_windows.h6
-rw-r--r--drivers/windows/semaphore_windows.cpp37
-rw-r--r--drivers/windows/semaphore_windows.h10
-rw-r--r--drivers/windows/shell_windows.cpp9
-rw-r--r--drivers/windows/shell_windows.h4
-rw-r--r--drivers/windows/thread_windows.cpp61
-rw-r--r--drivers/windows/thread_windows.h29
-rw-r--r--drivers/xaudio2/audio_driver_xaudio2.cpp29
-rw-r--r--drivers/xaudio2/audio_driver_xaudio2.h41
74 files changed, 12010 insertions, 14267 deletions
diff --git a/drivers/alsa/audio_driver_alsa.cpp b/drivers/alsa/audio_driver_alsa.cpp
index f2616b11b8..7e445c7c10 100644
--- a/drivers/alsa/audio_driver_alsa.cpp
+++ b/drivers/alsa/audio_driver_alsa.cpp
@@ -36,27 +36,26 @@
Error AudioDriverALSA::init() {
- active=false;
- thread_exited=false;
- exit_thread=false;
+ active = false;
+ thread_exited = false;
+ exit_thread = false;
pcm_open = false;
samples_in = NULL;
samples_out = NULL;
- mix_rate = GLOBAL_DEF("audio/mix_rate",44100);
+ mix_rate = GLOBAL_DEF("audio/mix_rate", 44100);
speaker_mode = SPEAKER_MODE_STEREO;
channels = 2;
-
- int status;
+ int status;
snd_pcm_hw_params_t *hwparams;
snd_pcm_sw_params_t *swparams;
-#define CHECK_FAIL(m_cond)\
- if (m_cond) {\
- fprintf(stderr,"ALSA ERR: %s\n",snd_strerror(status));\
- snd_pcm_close(pcm_handle);\
- ERR_FAIL_COND_V(m_cond,ERR_CANT_OPEN);\
+#define CHECK_FAIL(m_cond) \
+ if (m_cond) { \
+ fprintf(stderr, "ALSA ERR: %s\n", snd_strerror(status)); \
+ snd_pcm_close(pcm_handle); \
+ ERR_FAIL_COND_V(m_cond, ERR_CANT_OPEN); \
}
//todo, add
@@ -65,81 +64,80 @@ Error AudioDriverALSA::init() {
status = snd_pcm_open(&pcm_handle, "default", SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK);
- ERR_FAIL_COND_V( status<0, ERR_CANT_OPEN );
+ ERR_FAIL_COND_V(status < 0, ERR_CANT_OPEN);
snd_pcm_hw_params_alloca(&hwparams);
status = snd_pcm_hw_params_any(pcm_handle, hwparams);
- CHECK_FAIL( status<0 );
+ CHECK_FAIL(status < 0);
status = snd_pcm_hw_params_set_access(pcm_handle, hwparams, SND_PCM_ACCESS_RW_INTERLEAVED);
- CHECK_FAIL( status<0 );
+ CHECK_FAIL(status < 0);
//not interested in anything else
status = snd_pcm_hw_params_set_format(pcm_handle, hwparams, SND_PCM_FORMAT_S16_LE);
- CHECK_FAIL( status<0 );
+ CHECK_FAIL(status < 0);
//todo: support 4 and 6
status = snd_pcm_hw_params_set_channels(pcm_handle, hwparams, 2);
- CHECK_FAIL( status<0 );
+ CHECK_FAIL(status < 0);
status = snd_pcm_hw_params_set_rate_near(pcm_handle, hwparams, &mix_rate, NULL);
- CHECK_FAIL( status<0 );
+ CHECK_FAIL(status < 0);
- int latency = GLOBAL_DEF("audio/output_latency",25);
- buffer_size = nearest_power_of_2( latency * mix_rate / 1000 );
+ int latency = GLOBAL_DEF("audio/output_latency", 25);
+ buffer_size = nearest_power_of_2(latency * mix_rate / 1000);
// set buffer size from project settings
status = snd_pcm_hw_params_set_buffer_size_near(pcm_handle, hwparams, &buffer_size);
- CHECK_FAIL( status<0 );
+ CHECK_FAIL(status < 0);
- // make period size 1/8
+ // make period size 1/8
period_size = buffer_size >> 3;
status = snd_pcm_hw_params_set_period_size_near(pcm_handle, hwparams, &period_size, NULL);
- CHECK_FAIL( status<0 );
+ CHECK_FAIL(status < 0);
- unsigned int periods=2;
+ unsigned int periods = 2;
status = snd_pcm_hw_params_set_periods_near(pcm_handle, hwparams, &periods, NULL);
- CHECK_FAIL( status<0 );
+ CHECK_FAIL(status < 0);
- status = snd_pcm_hw_params(pcm_handle,hwparams);
- CHECK_FAIL( status<0 );
+ status = snd_pcm_hw_params(pcm_handle, hwparams);
+ CHECK_FAIL(status < 0);
//snd_pcm_hw_params_free(&hwparams);
-
snd_pcm_sw_params_alloca(&swparams);
status = snd_pcm_sw_params_current(pcm_handle, swparams);
- CHECK_FAIL( status<0 );
+ CHECK_FAIL(status < 0);
status = snd_pcm_sw_params_set_avail_min(pcm_handle, swparams, period_size);
- CHECK_FAIL( status<0 );
+ CHECK_FAIL(status < 0);
status = snd_pcm_sw_params_set_start_threshold(pcm_handle, swparams, 1);
- CHECK_FAIL( status<0 );
+ CHECK_FAIL(status < 0);
status = snd_pcm_sw_params(pcm_handle, swparams);
- CHECK_FAIL( status<0 );
+ CHECK_FAIL(status < 0);
- samples_in = memnew_arr(int32_t, period_size*channels);
- samples_out = memnew_arr(int16_t, period_size*channels);
+ samples_in = memnew_arr(int32_t, period_size * channels);
+ samples_out = memnew_arr(int16_t, period_size * channels);
snd_pcm_nonblock(pcm_handle, 0);
- mutex=Mutex::create();
+ mutex = Mutex::create();
thread = Thread::create(AudioDriverALSA::thread_func, this);
return OK;
};
-void AudioDriverALSA::thread_func(void* p_udata) {
+void AudioDriverALSA::thread_func(void *p_udata) {
- AudioDriverALSA* ad = (AudioDriverALSA*)p_udata;
+ AudioDriverALSA *ad = (AudioDriverALSA *)p_udata;
while (!ad->exit_thread) {
if (!ad->active) {
- for (unsigned int i=0; i < ad->period_size*ad->channels; i++) {
+ for (unsigned int i = 0; i < ad->period_size * ad->channels; i++) {
ad->samples_out[i] = 0;
};
} else {
@@ -149,36 +147,35 @@ void AudioDriverALSA::thread_func(void* p_udata) {
ad->unlock();
- for(unsigned int i=0;i<ad->period_size*ad->channels;i++) {
- ad->samples_out[i]=ad->samples_in[i]>>16;
+ for (unsigned int i = 0; i < ad->period_size * ad->channels; i++) {
+ ad->samples_out[i] = ad->samples_in[i] >> 16;
}
};
-
int todo = ad->period_size;
int total = 0;
while (todo) {
if (ad->exit_thread)
break;
- uint8_t* src = (uint8_t*)ad->samples_out;
- int wrote = snd_pcm_writei(ad->pcm_handle, (void*)(src + (total*ad->channels)), todo);
+ uint8_t *src = (uint8_t *)ad->samples_out;
+ int wrote = snd_pcm_writei(ad->pcm_handle, (void *)(src + (total * ad->channels)), todo);
if (wrote < 0) {
if (ad->exit_thread)
break;
- if ( wrote == -EAGAIN ) {
+ if (wrote == -EAGAIN) {
//can't write yet (though this is blocking..)
- usleep(1000);
+ usleep(1000);
continue;
}
wrote = snd_pcm_recover(ad->pcm_handle, wrote, 0);
- if ( wrote < 0 ) {
+ if (wrote < 0) {
//absolute fail
fprintf(stderr, "ALSA failed and can't recover: %s\n", snd_strerror(wrote));
- ad->active=false;
- ad->exit_thread=true;
+ ad->active = false;
+ ad->exit_thread = true;
break;
}
continue;
@@ -189,8 +186,7 @@ void AudioDriverALSA::thread_func(void* p_udata) {
};
};
- ad->thread_exited=true;
-
+ ad->thread_exited = true;
};
void AudioDriverALSA::start() {
@@ -247,11 +243,11 @@ void AudioDriverALSA::finish() {
AudioDriverALSA::AudioDriverALSA() {
mutex = NULL;
- thread=NULL;
- pcm_handle=NULL;
+ thread = NULL;
+ pcm_handle = NULL;
};
-AudioDriverALSA::~AudioDriverALSA() {
+AudioDriverALSA::~AudioDriverALSA(){
};
diff --git a/drivers/alsa/audio_driver_alsa.h b/drivers/alsa/audio_driver_alsa.h
index 6ab98312b2..e545b7a511 100644
--- a/drivers/alsa/audio_driver_alsa.h
+++ b/drivers/alsa/audio_driver_alsa.h
@@ -30,22 +30,22 @@
#ifdef ALSA_ENABLED
-#include "core/os/thread.h"
#include "core/os/mutex.h"
+#include "core/os/thread.h"
#include <alsa/asoundlib.h>
class AudioDriverALSA : public AudioDriver {
- Thread* thread;
- Mutex* mutex;
+ Thread *thread;
+ Mutex *mutex;
- snd_pcm_t* pcm_handle;
+ snd_pcm_t *pcm_handle;
- int32_t* samples_in;
- int16_t* samples_out;
+ int32_t *samples_in;
+ int16_t *samples_out;
- static void thread_func(void* p_udata);
+ static void thread_func(void *p_udata);
unsigned int mix_rate;
SpeakerMode speaker_mode;
@@ -60,8 +60,7 @@ class AudioDriverALSA : public AudioDriver {
bool pcm_open;
public:
-
- const char* get_name() const {
+ const char *get_name() const {
return "ALSA";
};
diff --git a/drivers/convex_decomp/b2d_decompose.cpp b/drivers/convex_decomp/b2d_decompose.cpp
index f84faaf586..afafda1527 100644
--- a/drivers/convex_decomp/b2d_decompose.cpp
+++ b/drivers/convex_decomp/b2d_decompose.cpp
@@ -31,132 +31,129 @@
namespace b2ConvexDecomp {
-
-void add_to_res(Vector< Vector<Vector2> >& res,const b2Polygon& p_poly) {
+void add_to_res(Vector<Vector<Vector2> > &res, const b2Polygon &p_poly) {
Vector<Vector2> arr;
- for(int i=0;i<p_poly.nVertices;i++) {
+ for (int i = 0; i < p_poly.nVertices; i++) {
- arr.push_back(Vector2(p_poly.x[i],p_poly.y[i]));
+ arr.push_back(Vector2(p_poly.x[i], p_poly.y[i]));
}
res.push_back(arr);
-
}
-static Vector< Vector<Vector2> > _b2d_decompose(const Vector<Vector2>& p_polygon) {
+static Vector<Vector<Vector2> > _b2d_decompose(const Vector<Vector2> &p_polygon) {
-
- Vector< Vector<Vector2> > res;
- if (p_polygon.size()<3)
+ Vector<Vector<Vector2> > res;
+ if (p_polygon.size() < 3)
return res;
- b2Vec2 *polys = memnew_arr(b2Vec2,p_polygon.size());
- for(int i=0;i<p_polygon.size();i++)
- polys[i]=b2Vec2(p_polygon[i].x,p_polygon[i].y);
-
+ b2Vec2 *polys = memnew_arr(b2Vec2, p_polygon.size());
+ for (int i = 0; i < p_polygon.size(); i++)
+ polys[i] = b2Vec2(p_polygon[i].x, p_polygon[i].y);
- b2Polygon *p = new b2Polygon(polys,p_polygon.size());
- b2Polygon* decomposed = new b2Polygon[p->nVertices - 2]; //maximum number of polys
+ b2Polygon *p = new b2Polygon(polys, p_polygon.size());
+ b2Polygon *decomposed = new b2Polygon[p->nVertices - 2]; //maximum number of polys
memdelete_arr(polys);
int32 nPolys = DecomposeConvex(p, decomposed, p->nVertices - 2);
- //int32 extra = 0;
+ //int32 extra = 0;
for (int32 i = 0; i < nPolys; ++i) {
- // b2FixtureDef* toAdd = &pdarray[i+extra];
- // *toAdd = *prototype;
- //Hmm, shouldn't have to do all this...
- b2Polygon curr = decomposed[i];
- //TODO ewjordan: move this triangle handling to a better place so that
- //it happens even if this convenience function is not called.
- if (curr.nVertices == 3){
- //Check here for near-parallel edges, since we can't
- //handle this in merge routine
- for (int j=0; j<3; ++j){
- int32 lower = (j == 0) ? (curr.nVertices - 1) : (j - 1);
- int32 middle = j;
- int32 upper = (j == curr.nVertices - 1) ? (0) : (j + 1);
- float32 dx0 = curr.x[middle] - curr.x[lower]; float32 dy0 = curr.y[middle] - curr.y[lower];
- float32 dx1 = curr.x[upper] - curr.x[middle]; float32 dy1 = curr.y[upper] - curr.y[middle];
- float32 norm0 = sqrtf(dx0*dx0+dy0*dy0); float32 norm1 = sqrtf(dx1*dx1+dy1*dy1);
- if ( !(norm0 > 0.0f && norm1 > 0.0f) ) {
- //Identical points, don't do anything!
- goto Skip;
- }
- dx0 /= norm0; dy0 /= norm0;
- dx1 /= norm1; dy1 /= norm1;
- float32 cross = dx0 * dy1 - dx1 * dy0;
- float32 dot = dx0*dx1 + dy0*dy1;
- if (fabs(cross) < b2_angularSlop && dot > 0) {
- //Angle too close, split the triangle across from this point.
- //This is guaranteed to result in two triangles that satify
- //the tolerance (one of the angles is 90 degrees)
- float32 dx2 = curr.x[lower] - curr.x[upper]; float32 dy2 = curr.y[lower] - curr.y[upper];
- float32 norm2 = sqrtf(dx2*dx2+dy2*dy2);
- if (norm2 == 0.0f) {
- goto Skip;
- }
- dx2 /= norm2; dy2 /= norm2;
- float32 thisArea = curr.GetArea();
- float32 thisHeight = 2.0f * thisArea / norm2;
- float32 buffer2 = dx2;
- dx2 = dy2; dy2 = -buffer2;
- //Make two new polygons
- //printf("dx2: %f, dy2: %f, thisHeight: %f, middle: %d\n",dx2,dy2,thisHeight,middle);
- float32 newX1[3] = { curr.x[middle]+dx2*thisHeight, curr.x[lower], curr.x[middle] };
- float32 newY1[3] = { curr.y[middle]+dy2*thisHeight, curr.y[lower], curr.y[middle] };
- float32 newX2[3] = { newX1[0], curr.x[middle], curr.x[upper] };
- float32 newY2[3] = { newY1[0], curr.y[middle], curr.y[upper] };
- b2Polygon p1(newX1,newY1,3);
- b2Polygon p2(newX2,newY2,3);
- if (p1.IsUsable()){
- add_to_res(res,p1);
- //++extra;
- } else if (B2_POLYGON_REPORT_ERRORS){
- printf("Didn't add unusable polygon. Dumping vertices:\n");
- p1.print();
- }
- if (p2.IsUsable()){
- add_to_res(res,p2);
-
- //p2.AddTo(pdarray[i+extra]);
-
- //bd->CreateFixture(toAdd);
- } else if (B2_POLYGON_REPORT_ERRORS){
- printf("Didn't add unusable polygon. Dumping vertices:\n");
- p2.print();
- }
- goto Skip;
- }
+ // b2FixtureDef* toAdd = &pdarray[i+extra];
+ // *toAdd = *prototype;
+ //Hmm, shouldn't have to do all this...
+ b2Polygon curr = decomposed[i];
+ //TODO ewjordan: move this triangle handling to a better place so that
+ //it happens even if this convenience function is not called.
+ if (curr.nVertices == 3) {
+ //Check here for near-parallel edges, since we can't
+ //handle this in merge routine
+ for (int j = 0; j < 3; ++j) {
+ int32 lower = (j == 0) ? (curr.nVertices - 1) : (j - 1);
+ int32 middle = j;
+ int32 upper = (j == curr.nVertices - 1) ? (0) : (j + 1);
+ float32 dx0 = curr.x[middle] - curr.x[lower];
+ float32 dy0 = curr.y[middle] - curr.y[lower];
+ float32 dx1 = curr.x[upper] - curr.x[middle];
+ float32 dy1 = curr.y[upper] - curr.y[middle];
+ float32 norm0 = sqrtf(dx0 * dx0 + dy0 * dy0);
+ float32 norm1 = sqrtf(dx1 * dx1 + dy1 * dy1);
+ if (!(norm0 > 0.0f && norm1 > 0.0f)) {
+ //Identical points, don't do anything!
+ goto Skip;
+ }
+ dx0 /= norm0;
+ dy0 /= norm0;
+ dx1 /= norm1;
+ dy1 /= norm1;
+ float32 cross = dx0 * dy1 - dx1 * dy0;
+ float32 dot = dx0 * dx1 + dy0 * dy1;
+ if (fabs(cross) < b2_angularSlop && dot > 0) {
+ //Angle too close, split the triangle across from this point.
+ //This is guaranteed to result in two triangles that satify
+ //the tolerance (one of the angles is 90 degrees)
+ float32 dx2 = curr.x[lower] - curr.x[upper];
+ float32 dy2 = curr.y[lower] - curr.y[upper];
+ float32 norm2 = sqrtf(dx2 * dx2 + dy2 * dy2);
+ if (norm2 == 0.0f) {
+ goto Skip;
}
+ dx2 /= norm2;
+ dy2 /= norm2;
+ float32 thisArea = curr.GetArea();
+ float32 thisHeight = 2.0f * thisArea / norm2;
+ float32 buffer2 = dx2;
+ dx2 = dy2;
+ dy2 = -buffer2;
+ //Make two new polygons
+ //printf("dx2: %f, dy2: %f, thisHeight: %f, middle: %d\n",dx2,dy2,thisHeight,middle);
+ float32 newX1[3] = { curr.x[middle] + dx2 * thisHeight, curr.x[lower], curr.x[middle] };
+ float32 newY1[3] = { curr.y[middle] + dy2 * thisHeight, curr.y[lower], curr.y[middle] };
+ float32 newX2[3] = { newX1[0], curr.x[middle], curr.x[upper] };
+ float32 newY2[3] = { newY1[0], curr.y[middle], curr.y[upper] };
+ b2Polygon p1(newX1, newY1, 3);
+ b2Polygon p2(newX2, newY2, 3);
+ if (p1.IsUsable()) {
+ add_to_res(res, p1);
+ //++extra;
+ } else if (B2_POLYGON_REPORT_ERRORS) {
+ printf("Didn't add unusable polygon. Dumping vertices:\n");
+ p1.print();
+ }
+ if (p2.IsUsable()) {
+ add_to_res(res, p2);
+ //p2.AddTo(pdarray[i+extra]);
+
+ //bd->CreateFixture(toAdd);
+ } else if (B2_POLYGON_REPORT_ERRORS) {
+ printf("Didn't add unusable polygon. Dumping vertices:\n");
+ p2.print();
+ }
+ goto Skip;
+ }
}
- if (decomposed[i].IsUsable()){
- add_to_res(res,decomposed[i]);
-
- //decomposed[i].AddTo(*toAdd);
- //bd->CreateFixture((const b2FixtureDef*)toAdd);
- } else if (B2_POLYGON_REPORT_ERRORS){
- printf("Didn't add unusable polygon. Dumping vertices:\n");
- decomposed[i].print();
- }
-Skip:
- ;
+ }
+ if (decomposed[i].IsUsable()) {
+ add_to_res(res, decomposed[i]);
+
+ //decomposed[i].AddTo(*toAdd);
+ //bd->CreateFixture((const b2FixtureDef*)toAdd);
+ } else if (B2_POLYGON_REPORT_ERRORS) {
+ printf("Didn't add unusable polygon. Dumping vertices:\n");
+ decomposed[i].print();
+ }
+ Skip:;
}
//delete[] pdarray;
delete[] decomposed;
delete p;
- return res;// pdarray; //needs to be deleted after body is created
-
+ return res; // pdarray; //needs to be deleted after body is created
}
-
}
-
-Vector< Vector<Vector2> > b2d_decompose(const Vector<Vector2>& p_polygon) {
+Vector<Vector<Vector2> > b2d_decompose(const Vector<Vector2> &p_polygon) {
return b2ConvexDecomp::_b2d_decompose(p_polygon);
-
-
}
diff --git a/drivers/convex_decomp/b2d_decompose.h b/drivers/convex_decomp/b2d_decompose.h
index 3a35ca140d..c3765275ef 100644
--- a/drivers/convex_decomp/b2d_decompose.h
+++ b/drivers/convex_decomp/b2d_decompose.h
@@ -31,6 +31,6 @@
#include "math_2d.h"
#include "vector.h"
-Vector< Vector<Vector2> > b2d_decompose(const Vector<Vector2>& p_polygon);
+Vector<Vector<Vector2> > b2d_decompose(const Vector<Vector2> &p_polygon);
#endif // B2D_DECOMPOSE_H
diff --git a/drivers/gl_context/context_gl.cpp b/drivers/gl_context/context_gl.cpp
index e99ec93e11..9fe7fbf2b8 100644
--- a/drivers/gl_context/context_gl.cpp
+++ b/drivers/gl_context/context_gl.cpp
@@ -28,31 +28,26 @@
/*************************************************************************/
#include "context_gl.h"
+#if defined(OPENGL_ENABLED) || defined(GLES2_ENABLED)
-#if defined(OPENGL_ENABLED) || defined(GLES2_ENABLED)
-
-
-
-ContextGL *ContextGL::singleton=NULL;
+ContextGL *ContextGL::singleton = NULL;
ContextGL *ContextGL::get_singleton() {
return singleton;
}
-
ContextGL::ContextGL() {
-
+
ERR_FAIL_COND(singleton);
-
- singleton=this;
-}
+ singleton = this;
+}
ContextGL::~ContextGL() {
- if (singleton==this)
- singleton=NULL;
+ if (singleton == this)
+ singleton = NULL;
}
#endif
diff --git a/drivers/gl_context/context_gl.h b/drivers/gl_context/context_gl.h
index 535b492297..280da1aea6 100644
--- a/drivers/gl_context/context_gl.h
+++ b/drivers/gl_context/context_gl.h
@@ -37,34 +37,28 @@
@author Juan Linietsky <reduzio@gmail.com>
*/
-
class ContextGL {
static ContextGL *singleton;
-public:
+public:
static ContextGL *get_singleton();
-
- virtual void release_current()=0;
- virtual void make_current()=0;
+ virtual void release_current() = 0;
- virtual void swap_buffers()=0;
-
- virtual Error initialize()=0;
+ virtual void make_current() = 0;
- virtual void set_use_vsync(bool p_use)=0;
- virtual bool is_using_vsync() const=0;
+ virtual void swap_buffers() = 0;
+ virtual Error initialize() = 0;
-
-
- ContextGL();
- ~ContextGL();
+ virtual void set_use_vsync(bool p_use) = 0;
+ virtual bool is_using_vsync() const = 0;
+ ContextGL();
+ ~ContextGL();
};
-
#endif
#endif
diff --git a/drivers/gles2/rasterizer_gles2.cpp b/drivers/gles2/rasterizer_gles2.cpp
index 94c5ecdec1..5deb78977a 100644
--- a/drivers/gles2/rasterizer_gles2.cpp
+++ b/drivers/gles2/rasterizer_gles2.cpp
@@ -29,34 +29,33 @@
#ifdef GLES2_ENABLED
#include "rasterizer_gles2.h"
-#include "os/os.h"
+#include "gl_context/context_gl.h"
#include "global_config.h"
-#include <stdio.h>
-#include "servers/visual/shader_language.h"
+#include "os/os.h"
#include "servers/visual/particle_system_sw.h"
-#include "gl_context/context_gl.h"
-#include <string.h>
+#include "servers/visual/shader_language.h"
+#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#ifdef GLEW_ENABLED
-#define _GL_HALF_FLOAT_OES 0x140B
+#define _GL_HALF_FLOAT_OES 0x140B
#else
-#define _GL_HALF_FLOAT_OES 0x8D61
+#define _GL_HALF_FLOAT_OES 0x8D61
#endif
-#define _GL_RGBA16F_EXT 0x881A
-#define _GL_RGB16F_EXT 0x881B
-#define _GL_RG16F_EXT 0x822F
-#define _GL_R16F_EXT 0x822D
+#define _GL_RGBA16F_EXT 0x881A
+#define _GL_RGB16F_EXT 0x881B
+#define _GL_RG16F_EXT 0x822F
+#define _GL_R16F_EXT 0x822D
#define _GL_R32F_EXT 0x822E
+#define _GL_RED_EXT 0x1903
+#define _GL_RG_EXT 0x8227
+#define _GL_R8_EXT 0x8229
+#define _GL_RG8_EXT 0x822B
-#define _GL_RED_EXT 0x1903
-#define _GL_RG_EXT 0x8227
-#define _GL_R8_EXT 0x8229
-#define _GL_RG8_EXT 0x822B
-
-#define _DEPTH_COMPONENT24_OES 0x81A6
+#define _DEPTH_COMPONENT24_OES 0x81A6
#ifdef GLEW_ENABLED
#define _glClearDepth glClearDepth
@@ -64,25 +63,25 @@
#define _glClearDepth glClearDepthf
#endif
-
#define _GL_SRGB_EXT 0x8C40
#define _GL_SRGB_ALPHA_EXT 0x8C42
-#define _GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE
-#define _GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT 0x84FF
+#define _GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE
+#define _GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT 0x84FF
//#define DEBUG_OPENGL
#ifdef DEBUG_OPENGL
-#define DEBUG_TEST_ERROR(m_section)\
-{\
- print_line("AT: "+String(m_section)); glFlush();\
- uint32_t err = glGetError();\
- if (err) {\
- print_line("OpenGL Error #"+itos(err)+" at: "+m_section);\
- }\
-}
+#define DEBUG_TEST_ERROR(m_section) \
+ { \
+ print_line("AT: " + String(m_section)); \
+ glFlush(); \
+ uint32_t err = glGetError(); \
+ if (err) { \
+ print_line("OpenGL Error #" + itos(err) + " at: " + m_section); \
+ } \
+ }
#else
@@ -90,97 +89,87 @@
#endif
-static RasterizerGLES2* _singleton = NULL;
+static RasterizerGLES2 *_singleton = NULL;
#ifdef GLES_NO_CLIENT_ARRAYS
-static float GlobalVertexBuffer[MAX_POLYGON_VERTICES * 8] = {0};
+static float GlobalVertexBuffer[MAX_POLYGON_VERTICES * 8] = { 0 };
#endif
-static const GLenum prim_type[]={GL_POINTS,GL_LINES,GL_TRIANGLES,GL_TRIANGLE_FAN};
+static const GLenum prim_type[] = { GL_POINTS, GL_LINES, GL_TRIANGLES, GL_TRIANGLE_FAN };
-_FORCE_INLINE_ static void _set_color_attrib(const Color& p_color) {
+_FORCE_INLINE_ static void _set_color_attrib(const Color &p_color) {
- GLfloat c[4]= { p_color.r, p_color.g, p_color.b, p_color.a };
- glVertexAttrib4fv( VS::ARRAY_COLOR, c );
+ GLfloat c[4] = { p_color.r, p_color.g, p_color.b, p_color.a };
+ glVertexAttrib4fv(VS::ARRAY_COLOR, c);
}
-
-
static _FORCE_INLINE_ uint16_t make_half_float(float f) {
- union {
- float fv;
- uint32_t ui;
- } ci;
- ci.fv=f;
-
- unsigned int x = ci.ui;
- unsigned int sign = (unsigned short)(x >> 31);
- unsigned int mantissa;
- unsigned int exp;
- uint16_t hf;
-
- // get mantissa
- mantissa = x & ((1 << 23) - 1);
- // get exponent bits
- exp = x & (0xFF << 23);
- if (exp >= 0x47800000)
- {
- // check if the original single precision float number is a NaN
- if (mantissa && (exp == (0xFF << 23)))
- {
- // we have a single precision NaN
- mantissa = (1 << 23) - 1;
- }
- else
- {
- // 16-bit half-float representation stores number as Inf
- mantissa = 0;
+ union {
+ float fv;
+ uint32_t ui;
+ } ci;
+ ci.fv = f;
+
+ unsigned int x = ci.ui;
+ unsigned int sign = (unsigned short)(x >> 31);
+ unsigned int mantissa;
+ unsigned int exp;
+ uint16_t hf;
+
+ // get mantissa
+ mantissa = x & ((1 << 23) - 1);
+ // get exponent bits
+ exp = x & (0xFF << 23);
+ if (exp >= 0x47800000) {
+ // check if the original single precision float number is a NaN
+ if (mantissa && (exp == (0xFF << 23))) {
+ // we have a single precision NaN
+ mantissa = (1 << 23) - 1;
+ } else {
+ // 16-bit half-float representation stores number as Inf
+ mantissa = 0;
+ }
+ hf = (((uint16_t)sign) << 15) | (uint16_t)((0x1F << 10)) |
+ (uint16_t)(mantissa >> 13);
}
- hf = (((uint16_t)sign) << 15) | (uint16_t)((0x1F << 10)) |
- (uint16_t)(mantissa >> 13);
- }
- // check if exponent is <= -15
- else if (exp <= 0x38000000)
- {
+ // check if exponent is <= -15
+ else if (exp <= 0x38000000) {
- /*// store a denorm half-float value or zero
+ /*// store a denorm half-float value or zero
exp = (0x38000000 - exp) >> 23;
mantissa >>= (14 + exp);
hf = (((uint16_t)sign) << 15) | (uint16_t)(mantissa);
*/
- hf=0; //denormals do not work for 3D, convert to zero
- }
- else
- {
- hf = (((uint16_t)sign) << 15) |
- (uint16_t)((exp - 0x38000000) >> 13) |
- (uint16_t)(mantissa >> 13);
- }
+ hf = 0; //denormals do not work for 3D, convert to zero
+ } else {
+ hf = (((uint16_t)sign) << 15) |
+ (uint16_t)((exp - 0x38000000) >> 13) |
+ (uint16_t)(mantissa >> 13);
+ }
- return hf;
+ return hf;
}
-void RasterizerGLES2::_draw_primitive(int p_points, const Vector3 *p_vertices, const Vector3 *p_normals, const Color* p_colors, const Vector3 *p_uvs,const Plane *p_tangents,int p_instanced) {
+void RasterizerGLES2::_draw_primitive(int p_points, const Vector3 *p_vertices, const Vector3 *p_normals, const Color *p_colors, const Vector3 *p_uvs, const Plane *p_tangents, int p_instanced) {
ERR_FAIL_COND(!p_vertices);
- ERR_FAIL_COND(p_points <1 || p_points>4);
+ ERR_FAIL_COND(p_points < 1 || p_points > 4);
- bool quad=false;
+ bool quad = false;
GLenum type;
- switch(p_points) {
+ switch (p_points) {
- case 1: type=GL_POINTS; break;
- case 2: type=GL_LINES; break;
- case 4: quad=true; p_points=3;
- case 3: type=GL_TRIANGLES; break;
+ case 1: type = GL_POINTS; break;
+ case 2: type = GL_LINES; break;
+ case 4: quad = true; p_points = 3;
+ case 3: type = GL_TRIANGLES; break;
};
-
- glBindBuffer(GL_ARRAY_BUFFER,0);
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0);
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
GLfloat vert_array[18];
GLfloat normal_array[18];
@@ -189,40 +178,38 @@ void RasterizerGLES2::_draw_primitive(int p_points, const Vector3 *p_vertices, c
GLfloat uv_array[18];
glEnableVertexAttribArray(VS::ARRAY_VERTEX);
- glVertexAttribPointer( VS::ARRAY_VERTEX, 3 ,GL_FLOAT, false, 0, vert_array );
+ glVertexAttribPointer(VS::ARRAY_VERTEX, 3, GL_FLOAT, false, 0, vert_array);
- for (int i=0;i<p_points;i++) {
+ for (int i = 0; i < p_points; i++) {
- vert_array[i*3+0]=p_vertices[i].x;
- vert_array[i*3+1]=p_vertices[i].y;
- vert_array[i*3+2]=p_vertices[i].z;
+ vert_array[i * 3 + 0] = p_vertices[i].x;
+ vert_array[i * 3 + 1] = p_vertices[i].y;
+ vert_array[i * 3 + 2] = p_vertices[i].z;
if (quad) {
- int idx=2+i;
- if (idx==4)
- idx=0;
- vert_array[9+i*3+0]=p_vertices[idx].x;
- vert_array[9+i*3+1]=p_vertices[idx].y;
- vert_array[9+i*3+2]=p_vertices[idx].z;
-
+ int idx = 2 + i;
+ if (idx == 4)
+ idx = 0;
+ vert_array[9 + i * 3 + 0] = p_vertices[idx].x;
+ vert_array[9 + i * 3 + 1] = p_vertices[idx].y;
+ vert_array[9 + i * 3 + 2] = p_vertices[idx].z;
}
}
if (p_normals) {
glEnableVertexAttribArray(VS::ARRAY_NORMAL);
- glVertexAttribPointer( VS::ARRAY_NORMAL, 3 ,GL_FLOAT, false, 0, normal_array );
- for (int i=0;i<p_points;i++) {
+ glVertexAttribPointer(VS::ARRAY_NORMAL, 3, GL_FLOAT, false, 0, normal_array);
+ for (int i = 0; i < p_points; i++) {
- normal_array[i*3+0]=p_normals[i].x;
- normal_array[i*3+1]=p_normals[i].y;
- normal_array[i*3+2]=p_normals[i].z;
+ normal_array[i * 3 + 0] = p_normals[i].x;
+ normal_array[i * 3 + 1] = p_normals[i].y;
+ normal_array[i * 3 + 2] = p_normals[i].z;
if (quad) {
- int idx=2+i;
- if (idx==4)
- idx=0;
- normal_array[9+i*3+0]=p_normals[idx].x;
- normal_array[9+i*3+1]=p_normals[idx].y;
- normal_array[9+i*3+2]=p_normals[idx].z;
-
+ int idx = 2 + i;
+ if (idx == 4)
+ idx = 0;
+ normal_array[9 + i * 3 + 0] = p_normals[idx].x;
+ normal_array[9 + i * 3 + 1] = p_normals[idx].y;
+ normal_array[9 + i * 3 + 2] = p_normals[idx].z;
}
}
} else {
@@ -231,22 +218,21 @@ void RasterizerGLES2::_draw_primitive(int p_points, const Vector3 *p_vertices, c
if (p_colors) {
glEnableVertexAttribArray(VS::ARRAY_COLOR);
- glVertexAttribPointer( VS::ARRAY_COLOR, 4 ,GL_FLOAT, false, 0, color_array );
- for (int i=0;i<p_points;i++) {
+ glVertexAttribPointer(VS::ARRAY_COLOR, 4, GL_FLOAT, false, 0, color_array);
+ for (int i = 0; i < p_points; i++) {
- color_array[i*4+0]=p_colors[i].r;
- color_array[i*4+1]=p_colors[i].g;
- color_array[i*4+2]=p_colors[i].b;
- color_array[i*4+3]=p_colors[i].a;
+ color_array[i * 4 + 0] = p_colors[i].r;
+ color_array[i * 4 + 1] = p_colors[i].g;
+ color_array[i * 4 + 2] = p_colors[i].b;
+ color_array[i * 4 + 3] = p_colors[i].a;
if (quad) {
- int idx=2+i;
- if (idx==4)
- idx=0;
- color_array[12+i*4+0]=p_colors[idx].r;
- color_array[12+i*4+1]=p_colors[idx].g;
- color_array[12+i*4+2]=p_colors[idx].b;
- color_array[12+i*4+3]=p_colors[idx].a;
-
+ int idx = 2 + i;
+ if (idx == 4)
+ idx = 0;
+ color_array[12 + i * 4 + 0] = p_colors[idx].r;
+ color_array[12 + i * 4 + 1] = p_colors[idx].g;
+ color_array[12 + i * 4 + 2] = p_colors[idx].b;
+ color_array[12 + i * 4 + 3] = p_colors[idx].a;
}
}
} else {
@@ -255,22 +241,21 @@ void RasterizerGLES2::_draw_primitive(int p_points, const Vector3 *p_vertices, c
if (p_tangents) {
glEnableVertexAttribArray(VS::ARRAY_TANGENT);
- glVertexAttribPointer( VS::ARRAY_TANGENT, 4 ,GL_FLOAT, false, 0, tangent_array );
- for (int i=0;i<p_points;i++) {
+ glVertexAttribPointer(VS::ARRAY_TANGENT, 4, GL_FLOAT, false, 0, tangent_array);
+ for (int i = 0; i < p_points; i++) {
- tangent_array[i*4+0]=p_tangents[i].normal.x;
- tangent_array[i*4+1]=p_tangents[i].normal.y;
- tangent_array[i*4+2]=p_tangents[i].normal.z;
- tangent_array[i*4+3]=p_tangents[i].d;
+ tangent_array[i * 4 + 0] = p_tangents[i].normal.x;
+ tangent_array[i * 4 + 1] = p_tangents[i].normal.y;
+ tangent_array[i * 4 + 2] = p_tangents[i].normal.z;
+ tangent_array[i * 4 + 3] = p_tangents[i].d;
if (quad) {
- int idx=2+i;
- if (idx==4)
- idx=0;
- tangent_array[12+i*4+0]=p_tangents[idx].normal.x;
- tangent_array[12+i*4+1]=p_tangents[idx].normal.y;
- tangent_array[12+i*4+2]=p_tangents[idx].normal.z;
- tangent_array[12+i*4+3]=p_tangents[idx].d;
-
+ int idx = 2 + i;
+ if (idx == 4)
+ idx = 0;
+ tangent_array[12 + i * 4 + 0] = p_tangents[idx].normal.x;
+ tangent_array[12 + i * 4 + 1] = p_tangents[idx].normal.y;
+ tangent_array[12 + i * 4 + 2] = p_tangents[idx].normal.z;
+ tangent_array[12 + i * 4 + 3] = p_tangents[idx].d;
}
}
} else {
@@ -280,20 +265,19 @@ void RasterizerGLES2::_draw_primitive(int p_points, const Vector3 *p_vertices, c
if (p_uvs) {
glEnableVertexAttribArray(VS::ARRAY_TEX_UV);
- glVertexAttribPointer( VS::ARRAY_TEX_UV, 3 ,GL_FLOAT, false, 0, uv_array );
- for (int i=0;i<p_points;i++) {
+ glVertexAttribPointer(VS::ARRAY_TEX_UV, 3, GL_FLOAT, false, 0, uv_array);
+ for (int i = 0; i < p_points; i++) {
- uv_array[i*3+0]=p_uvs[i].x;
- uv_array[i*3+1]=p_uvs[i].y;
- uv_array[i*3+2]=p_uvs[i].z;
+ uv_array[i * 3 + 0] = p_uvs[i].x;
+ uv_array[i * 3 + 1] = p_uvs[i].y;
+ uv_array[i * 3 + 2] = p_uvs[i].z;
if (quad) {
- int idx=2+i;
- if (idx==4)
- idx=0;
- uv_array[9+i*3+0]=p_uvs[idx].x;
- uv_array[9+i*3+1]=p_uvs[idx].y;
- uv_array[9+i*3+2]=p_uvs[idx].z;
-
+ int idx = 2 + i;
+ if (idx == 4)
+ idx = 0;
+ uv_array[9 + i * 3 + 0] = p_uvs[idx].x;
+ uv_array[9 + i * 3 + 1] = p_uvs[idx].y;
+ uv_array[9 + i * 3 + 2] = p_uvs[idx].z;
}
}
@@ -307,32 +291,28 @@ void RasterizerGLES2::_draw_primitive(int p_points, const Vector3 *p_vertices, c
else
*/
- glDrawArrays(type,0,quad?6:p_points);
-
+ glDrawArrays(type, 0, quad ? 6 : p_points);
};
-
/* TEXTURE API */
-#define _EXT_COMPRESSED_RGB_PVRTC_4BPPV1_IMG 0x8C00
-#define _EXT_COMPRESSED_RGB_PVRTC_2BPPV1_IMG 0x8C01
-#define _EXT_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG 0x8C02
-#define _EXT_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG 0x8C03
-
-#define _EXT_COMPRESSED_SRGB_PVRTC_2BPPV1_EXT 0x8A54
-#define _EXT_COMPRESSED_SRGB_PVRTC_4BPPV1_EXT 0x8A55
-#define _EXT_COMPRESSED_SRGB_ALPHA_PVRTC_2BPPV1_EXT 0x8A56
-#define _EXT_COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV1_EXT 0x8A57
+#define _EXT_COMPRESSED_RGB_PVRTC_4BPPV1_IMG 0x8C00
+#define _EXT_COMPRESSED_RGB_PVRTC_2BPPV1_IMG 0x8C01
+#define _EXT_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG 0x8C02
+#define _EXT_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG 0x8C03
+#define _EXT_COMPRESSED_SRGB_PVRTC_2BPPV1_EXT 0x8A54
+#define _EXT_COMPRESSED_SRGB_PVRTC_4BPPV1_EXT 0x8A55
+#define _EXT_COMPRESSED_SRGB_ALPHA_PVRTC_2BPPV1_EXT 0x8A56
+#define _EXT_COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV1_EXT 0x8A57
#define _EXT_COMPRESSED_RGBA_S3TC_DXT1_EXT 0x83F1
#define _EXT_COMPRESSED_RGBA_S3TC_DXT3_EXT 0x83F2
#define _EXT_COMPRESSED_RGBA_S3TC_DXT5_EXT 0x83F3
-#define _EXT_COMPRESSED_LUMINANCE_LATC1_EXT 0x8C70
-#define _EXT_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT 0x8C71
-#define _EXT_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT 0x8C72
-#define _EXT_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT 0x8C73
-
+#define _EXT_COMPRESSED_LUMINANCE_LATC1_EXT 0x8C70
+#define _EXT_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT 0x8C71
+#define _EXT_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT 0x8C72
+#define _EXT_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT 0x8C73
#define _EXT_COMPRESSED_RED_RGTC1_EXT 0x8DBB
#define _EXT_COMPRESSED_RED_RGTC1 0x8DBB
@@ -342,71 +322,65 @@ void RasterizerGLES2::_draw_primitive(int p_points, const Vector3 *p_vertices, c
#define _EXT_COMPRESSED_SIGNED_RED_RGTC1_EXT 0x8DBC
#define _EXT_COMPRESSED_RED_GREEN_RGTC2_EXT 0x8DBD
#define _EXT_COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT 0x8DBE
-#define _EXT_ETC1_RGB8_OES 0x8D64
-
-
-
-#define _EXT_SLUMINANCE_NV 0x8C46
-#define _EXT_SLUMINANCE_ALPHA_NV 0x8C44
-#define _EXT_SRGB8_NV 0x8C41
-#define _EXT_SLUMINANCE8_NV 0x8C47
-#define _EXT_SLUMINANCE8_ALPHA8_NV 0x8C45
-
+#define _EXT_ETC1_RGB8_OES 0x8D64
-#define _EXT_COMPRESSED_SRGB_S3TC_DXT1_NV 0x8C4C
-#define _EXT_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_NV 0x8C4D
-#define _EXT_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_NV 0x8C4E
-#define _EXT_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_NV 0x8C4F
+#define _EXT_SLUMINANCE_NV 0x8C46
+#define _EXT_SLUMINANCE_ALPHA_NV 0x8C44
+#define _EXT_SRGB8_NV 0x8C41
+#define _EXT_SLUMINANCE8_NV 0x8C47
+#define _EXT_SLUMINANCE8_ALPHA8_NV 0x8C45
+#define _EXT_COMPRESSED_SRGB_S3TC_DXT1_NV 0x8C4C
+#define _EXT_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_NV 0x8C4D
+#define _EXT_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_NV 0x8C4E
+#define _EXT_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_NV 0x8C4F
-
-#define _EXT_ATC_RGB_AMD 0x8C92
-#define _EXT_ATC_RGBA_EXPLICIT_ALPHA_AMD 0x8C93
-#define _EXT_ATC_RGBA_INTERPOLATED_ALPHA_AMD 0x87EE
-
+#define _EXT_ATC_RGB_AMD 0x8C92
+#define _EXT_ATC_RGBA_EXPLICIT_ALPHA_AMD 0x8C93
+#define _EXT_ATC_RGBA_INTERPOLATED_ALPHA_AMD 0x87EE
/* TEXTURE API */
-Image RasterizerGLES2::_get_gl_image_and_format(const Image& p_image, Image::Format p_format, uint32_t p_flags,GLenum& r_gl_format,GLenum& r_gl_internal_format,int &r_gl_components,bool &r_has_alpha_cache,bool &r_compressed) {
+Image RasterizerGLES2::_get_gl_image_and_format(const Image &p_image, Image::Format p_format, uint32_t p_flags, GLenum &r_gl_format, GLenum &r_gl_internal_format, int &r_gl_components, bool &r_has_alpha_cache, bool &r_compressed) {
- r_has_alpha_cache=false;
- r_compressed=false;
- r_gl_format=0;
- Image image=p_image;
+ r_has_alpha_cache = false;
+ r_compressed = false;
+ r_gl_format = 0;
+ Image image = p_image;
- switch(p_format) {
+ switch (p_format) {
case Image::FORMAT_L8: {
- r_gl_components=1;
- r_gl_format=GL_LUMINANCE;
- r_gl_internal_format=(srgb_supported && p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)?_EXT_SLUMINANCE_NV:GL_LUMINANCE;
+ r_gl_components = 1;
+ r_gl_format = GL_LUMINANCE;
+ r_gl_internal_format = (srgb_supported && p_flags & VS::TEXTURE_FLAG_CONVERT_TO_LINEAR) ? _EXT_SLUMINANCE_NV : GL_LUMINANCE;
} break;
case Image::FORMAT_INTENSITY: {
if (!image.empty())
image.convert(Image::FORMAT_RGBA8);
- r_gl_components=4;
- r_gl_format=GL_RGBA;
- r_gl_internal_format=(srgb_supported && p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)?_GL_SRGB_ALPHA_EXT:GL_RGBA;
- r_has_alpha_cache=true;
+ r_gl_components = 4;
+ r_gl_format = GL_RGBA;
+ r_gl_internal_format = (srgb_supported && p_flags & VS::TEXTURE_FLAG_CONVERT_TO_LINEAR) ? _GL_SRGB_ALPHA_EXT : GL_RGBA;
+ r_has_alpha_cache = true;
} break;
case Image::FORMAT_LA8: {
//image.convert(Image::FORMAT_RGBA8);
- r_gl_components=2;
- r_gl_format=GL_LUMINANCE_ALPHA;
- r_gl_internal_format=(srgb_supported && p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)?_EXT_SLUMINANCE_ALPHA_NV:GL_LUMINANCE_ALPHA;
- r_has_alpha_cache=true;
+ r_gl_components = 2;
+ r_gl_format = GL_LUMINANCE_ALPHA;
+ r_gl_internal_format = (srgb_supported && p_flags & VS::TEXTURE_FLAG_CONVERT_TO_LINEAR) ? _EXT_SLUMINANCE_ALPHA_NV : GL_LUMINANCE_ALPHA;
+ r_has_alpha_cache = true;
} break;
case Image::FORMAT_INDEXED: {
if (!image.empty())
image.convert(Image::FORMAT_RGB8);
- r_gl_components=3;
- r_gl_format=GL_RGB;
- r_gl_internal_format=(srgb_supported && p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)?_GL_SRGB_EXT:GL_RGB;
+ r_gl_components = 3;
+ r_gl_format = GL_RGB;
+ r_gl_internal_format = (srgb_supported && p_flags & VS::TEXTURE_FLAG_CONVERT_TO_LINEAR) ? _GL_SRGB_EXT : GL_RGB;
} break;
@@ -414,153 +388,153 @@ Image RasterizerGLES2::_get_gl_image_and_format(const Image& p_image, Image::For
if (!image.empty())
image.convert(Image::FORMAT_RGBA8);
- r_gl_components=4;
+ r_gl_components = 4;
- if (p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR) {
+ if (p_flags & VS::TEXTURE_FLAG_CONVERT_TO_LINEAR) {
if (srgb_supported) {
- r_gl_format=GL_RGBA;
- r_gl_internal_format=_GL_SRGB_ALPHA_EXT;
+ r_gl_format = GL_RGBA;
+ r_gl_internal_format = _GL_SRGB_ALPHA_EXT;
} else {
- r_gl_internal_format=GL_RGBA;
+ r_gl_internal_format = GL_RGBA;
if (!image.empty())
image.srgb_to_linear();
}
} else {
- r_gl_internal_format=GL_RGBA;
+ r_gl_internal_format = GL_RGBA;
}
- r_has_alpha_cache=true;
+ r_has_alpha_cache = true;
} break;
case Image::FORMAT_RGB8: {
- r_gl_components=3;
+ r_gl_components = 3;
- if (p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR) {
+ if (p_flags & VS::TEXTURE_FLAG_CONVERT_TO_LINEAR) {
if (srgb_supported) {
- r_gl_internal_format=_GL_SRGB_EXT;
- r_gl_format=GL_RGB;
+ r_gl_internal_format = _GL_SRGB_EXT;
+ r_gl_format = GL_RGB;
} else {
- r_gl_internal_format=GL_RGB;
+ r_gl_internal_format = GL_RGB;
if (!image.empty())
image.srgb_to_linear();
}
} else {
- r_gl_internal_format=GL_RGB;
+ r_gl_internal_format = GL_RGB;
}
} break;
case Image::FORMAT_RGBA8: {
- r_gl_components=4;
- if (p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR) {
+ r_gl_components = 4;
+ if (p_flags & VS::TEXTURE_FLAG_CONVERT_TO_LINEAR) {
if (srgb_supported) {
- r_gl_internal_format=_GL_SRGB_ALPHA_EXT;
- r_gl_format=GL_RGBA;
+ r_gl_internal_format = _GL_SRGB_ALPHA_EXT;
+ r_gl_format = GL_RGBA;
//r_gl_internal_format=GL_RGBA;
} else {
- r_gl_internal_format=GL_RGBA;
+ r_gl_internal_format = GL_RGBA;
if (!image.empty())
image.srgb_to_linear();
}
} else {
- r_gl_internal_format=GL_RGBA;
+ r_gl_internal_format = GL_RGBA;
}
- r_has_alpha_cache=true;
+ r_has_alpha_cache = true;
} break;
case Image::FORMAT_DXT1: {
- if (!s3tc_supported || (!s3tc_srgb_supported && p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)) {
+ if (!s3tc_supported || (!s3tc_srgb_supported && p_flags & VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)) {
if (!image.empty()) {
image.decompress();
}
- r_gl_components=4;
- if (p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR) {
+ r_gl_components = 4;
+ if (p_flags & VS::TEXTURE_FLAG_CONVERT_TO_LINEAR) {
if (srgb_supported) {
- r_gl_format=GL_RGBA;
- r_gl_internal_format=_GL_SRGB_ALPHA_EXT;
+ r_gl_format = GL_RGBA;
+ r_gl_internal_format = _GL_SRGB_ALPHA_EXT;
} else {
- r_gl_internal_format=GL_RGBA;
+ r_gl_internal_format = GL_RGBA;
if (!image.empty())
image.srgb_to_linear();
}
} else {
- r_gl_internal_format=GL_RGBA;
+ r_gl_internal_format = GL_RGBA;
}
- r_has_alpha_cache=true;
+ r_has_alpha_cache = true;
} else {
- r_gl_components=1; //doesn't matter much
- r_gl_internal_format=(srgb_supported && p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)?_EXT_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_NV:_EXT_COMPRESSED_RGBA_S3TC_DXT1_EXT;
- r_compressed=true;
+ r_gl_components = 1; //doesn't matter much
+ r_gl_internal_format = (srgb_supported && p_flags & VS::TEXTURE_FLAG_CONVERT_TO_LINEAR) ? _EXT_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_NV : _EXT_COMPRESSED_RGBA_S3TC_DXT1_EXT;
+ r_compressed = true;
};
} break;
case Image::FORMAT_DXT3: {
- if (!s3tc_supported || (!s3tc_srgb_supported && p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)) {
+ if (!s3tc_supported || (!s3tc_srgb_supported && p_flags & VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)) {
if (!image.empty()) {
image.decompress();
}
- r_gl_components=4;
- if (p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR) {
+ r_gl_components = 4;
+ if (p_flags & VS::TEXTURE_FLAG_CONVERT_TO_LINEAR) {
if (srgb_supported) {
- r_gl_format=GL_RGBA;
- r_gl_internal_format=_GL_SRGB_ALPHA_EXT;
+ r_gl_format = GL_RGBA;
+ r_gl_internal_format = _GL_SRGB_ALPHA_EXT;
} else {
- r_gl_internal_format=GL_RGBA;
+ r_gl_internal_format = GL_RGBA;
if (!image.empty())
image.srgb_to_linear();
}
} else {
- r_gl_internal_format=GL_RGBA;
+ r_gl_internal_format = GL_RGBA;
}
- r_has_alpha_cache=true;
+ r_has_alpha_cache = true;
} else {
- r_gl_components=1; //doesn't matter much
- r_gl_internal_format=(srgb_supported && p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)?_EXT_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_NV:_EXT_COMPRESSED_RGBA_S3TC_DXT3_EXT;
+ r_gl_components = 1; //doesn't matter much
+ r_gl_internal_format = (srgb_supported && p_flags & VS::TEXTURE_FLAG_CONVERT_TO_LINEAR) ? _EXT_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_NV : _EXT_COMPRESSED_RGBA_S3TC_DXT3_EXT;
- r_has_alpha_cache=true;
- r_compressed=true;
+ r_has_alpha_cache = true;
+ r_compressed = true;
};
} break;
case Image::FORMAT_DXT5: {
- if (!s3tc_supported || (!s3tc_srgb_supported && p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)) {
+ if (!s3tc_supported || (!s3tc_srgb_supported && p_flags & VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)) {
if (!image.empty()) {
image.decompress();
}
- r_gl_components=4;
- if (p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR) {
+ r_gl_components = 4;
+ if (p_flags & VS::TEXTURE_FLAG_CONVERT_TO_LINEAR) {
if (srgb_supported) {
- r_gl_format=GL_RGBA;
- r_gl_internal_format=_GL_SRGB_ALPHA_EXT;
+ r_gl_format = GL_RGBA;
+ r_gl_internal_format = _GL_SRGB_ALPHA_EXT;
} else {
- r_gl_internal_format=GL_RGBA;
+ r_gl_internal_format = GL_RGBA;
if (!image.empty())
image.srgb_to_linear();
}
} else {
- r_gl_internal_format=GL_RGBA;
+ r_gl_internal_format = GL_RGBA;
}
- r_has_alpha_cache=true;
+ r_has_alpha_cache = true;
} else {
- r_gl_components=1; //doesn't matter much
- r_gl_internal_format=(srgb_supported && p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)?_EXT_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_NV:_EXT_COMPRESSED_RGBA_S3TC_DXT5_EXT;
- r_has_alpha_cache=true;
- r_compressed=true;
+ r_gl_components = 1; //doesn't matter much
+ r_gl_internal_format = (srgb_supported && p_flags & VS::TEXTURE_FLAG_CONVERT_TO_LINEAR) ? _EXT_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_NV : _EXT_COMPRESSED_RGBA_S3TC_DXT5_EXT;
+ r_has_alpha_cache = true;
+ r_compressed = true;
};
} break;
@@ -571,212 +545,207 @@ Image RasterizerGLES2::_get_gl_image_and_format(const Image& p_image, Image::For
if (!image.empty()) {
image.decompress();
}
- r_gl_components=4;
- if (p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR) {
+ r_gl_components = 4;
+ if (p_flags & VS::TEXTURE_FLAG_CONVERT_TO_LINEAR) {
if (srgb_supported) {
- r_gl_format=GL_RGBA;
- r_gl_internal_format=_GL_SRGB_ALPHA_EXT;
+ r_gl_format = GL_RGBA;
+ r_gl_internal_format = _GL_SRGB_ALPHA_EXT;
} else {
- r_gl_internal_format=GL_RGBA;
+ r_gl_internal_format = GL_RGBA;
if (!image.empty())
image.srgb_to_linear();
}
} else {
- r_gl_internal_format=GL_RGBA;
+ r_gl_internal_format = GL_RGBA;
}
- r_has_alpha_cache=true;
+ r_has_alpha_cache = true;
} else {
- r_gl_internal_format=_EXT_COMPRESSED_LUMINANCE_LATC1_EXT;
- r_gl_components=1; //doesn't matter much
- r_compressed=true;
+ r_gl_internal_format = _EXT_COMPRESSED_LUMINANCE_LATC1_EXT;
+ r_gl_components = 1; //doesn't matter much
+ r_compressed = true;
};
} break;
case Image::FORMAT_ATI2: {
- if (!latc_supported ) {
+ if (!latc_supported) {
if (!image.empty()) {
image.decompress();
}
- r_gl_components=4;
- if (p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR) {
+ r_gl_components = 4;
+ if (p_flags & VS::TEXTURE_FLAG_CONVERT_TO_LINEAR) {
if (srgb_supported) {
- r_gl_format=GL_RGBA;
- r_gl_internal_format=_GL_SRGB_ALPHA_EXT;
+ r_gl_format = GL_RGBA;
+ r_gl_internal_format = _GL_SRGB_ALPHA_EXT;
} else {
- r_gl_internal_format=GL_RGBA;
+ r_gl_internal_format = GL_RGBA;
if (!image.empty())
image.srgb_to_linear();
}
} else {
- r_gl_internal_format=GL_RGBA;
+ r_gl_internal_format = GL_RGBA;
}
- r_has_alpha_cache=true;
+ r_has_alpha_cache = true;
} else {
- r_gl_internal_format=_EXT_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT;
- r_gl_components=1; //doesn't matter much
- r_compressed=true;
+ r_gl_internal_format = _EXT_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT;
+ r_gl_components = 1; //doesn't matter much
+ r_compressed = true;
};
} break;
case Image::FORMAT_PVRTC2: {
- if (!pvr_supported || (!pvr_srgb_supported && p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)) {
+ if (!pvr_supported || (!pvr_srgb_supported && p_flags & VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)) {
if (!image.empty()) {
image.decompress();
}
- r_gl_components=4;
- if (p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR) {
+ r_gl_components = 4;
+ if (p_flags & VS::TEXTURE_FLAG_CONVERT_TO_LINEAR) {
if (srgb_supported) {
- r_gl_format=GL_RGBA;
- r_gl_internal_format=_GL_SRGB_ALPHA_EXT;
+ r_gl_format = GL_RGBA;
+ r_gl_internal_format = _GL_SRGB_ALPHA_EXT;
} else {
- r_gl_internal_format=GL_RGBA;
+ r_gl_internal_format = GL_RGBA;
if (!image.empty())
image.srgb_to_linear();
}
} else {
- r_gl_internal_format=GL_RGBA;
+ r_gl_internal_format = GL_RGBA;
}
- r_has_alpha_cache=true;
-
+ r_has_alpha_cache = true;
} else {
- r_gl_internal_format=(srgb_supported && p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)?_EXT_COMPRESSED_SRGB_PVRTC_2BPPV1_EXT:_EXT_COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
- r_gl_components=1; //doesn't matter much
- r_compressed=true;
-
+ r_gl_internal_format = (srgb_supported && p_flags & VS::TEXTURE_FLAG_CONVERT_TO_LINEAR) ? _EXT_COMPRESSED_SRGB_PVRTC_2BPPV1_EXT : _EXT_COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
+ r_gl_components = 1; //doesn't matter much
+ r_compressed = true;
}
} break;
case Image::FORMAT_PVRTC2A: {
- if (!pvr_supported || (!pvr_srgb_supported && p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)) {
+ if (!pvr_supported || (!pvr_srgb_supported && p_flags & VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)) {
if (!image.empty())
image.decompress();
- r_gl_components=4;
- if (p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR) {
+ r_gl_components = 4;
+ if (p_flags & VS::TEXTURE_FLAG_CONVERT_TO_LINEAR) {
if (srgb_supported) {
- r_gl_format=GL_RGBA;
- r_gl_internal_format=_GL_SRGB_ALPHA_EXT;
+ r_gl_format = GL_RGBA;
+ r_gl_internal_format = _GL_SRGB_ALPHA_EXT;
} else {
- r_gl_internal_format=GL_RGBA;
+ r_gl_internal_format = GL_RGBA;
if (!image.empty())
image.srgb_to_linear();
}
} else {
- r_gl_internal_format=GL_RGBA;
+ r_gl_internal_format = GL_RGBA;
}
- r_has_alpha_cache=true;
-
+ r_has_alpha_cache = true;
} else {
- r_gl_internal_format=_EXT_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
- r_gl_internal_format=(srgb_supported && p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)?_EXT_COMPRESSED_SRGB_ALPHA_PVRTC_2BPPV1_EXT:_EXT_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
- r_gl_components=1; //doesn't matter much
- r_compressed=true;
-
+ r_gl_internal_format = _EXT_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
+ r_gl_internal_format = (srgb_supported && p_flags & VS::TEXTURE_FLAG_CONVERT_TO_LINEAR) ? _EXT_COMPRESSED_SRGB_ALPHA_PVRTC_2BPPV1_EXT : _EXT_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
+ r_gl_components = 1; //doesn't matter much
+ r_compressed = true;
}
} break;
case Image::FORMAT_PVRTC4: {
- if (!pvr_supported || (!pvr_srgb_supported && p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)) {
+ if (!pvr_supported || (!pvr_srgb_supported && p_flags & VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)) {
if (!image.empty())
image.decompress();
- r_gl_components=4;
- if (p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR) {
+ r_gl_components = 4;
+ if (p_flags & VS::TEXTURE_FLAG_CONVERT_TO_LINEAR) {
if (srgb_supported) {
- r_gl_format=GL_RGBA;
- r_gl_internal_format=_GL_SRGB_ALPHA_EXT;
+ r_gl_format = GL_RGBA;
+ r_gl_internal_format = _GL_SRGB_ALPHA_EXT;
} else {
- r_gl_internal_format=GL_RGBA;
+ r_gl_internal_format = GL_RGBA;
if (!image.empty())
image.srgb_to_linear();
}
} else {
- r_gl_internal_format=GL_RGBA;
+ r_gl_internal_format = GL_RGBA;
}
- r_has_alpha_cache=true;
+ r_has_alpha_cache = true;
} else {
- r_gl_internal_format=(srgb_supported && p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)?_EXT_COMPRESSED_SRGB_PVRTC_4BPPV1_EXT:_EXT_COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
- r_gl_components=1; //doesn't matter much
- r_compressed=true;
+ r_gl_internal_format = (srgb_supported && p_flags & VS::TEXTURE_FLAG_CONVERT_TO_LINEAR) ? _EXT_COMPRESSED_SRGB_PVRTC_4BPPV1_EXT : _EXT_COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
+ r_gl_components = 1; //doesn't matter much
+ r_compressed = true;
}
} break;
case Image::FORMAT_PVRTC4A: {
- if (!pvr_supported || (!pvr_srgb_supported && p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)) {
+ if (!pvr_supported || (!pvr_srgb_supported && p_flags & VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)) {
if (!image.empty())
image.decompress();
- r_gl_components=4;
- if (p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR) {
+ r_gl_components = 4;
+ if (p_flags & VS::TEXTURE_FLAG_CONVERT_TO_LINEAR) {
if (srgb_supported) {
- r_gl_format=GL_RGBA;
- r_gl_internal_format=_GL_SRGB_ALPHA_EXT;
+ r_gl_format = GL_RGBA;
+ r_gl_internal_format = _GL_SRGB_ALPHA_EXT;
} else {
- r_gl_internal_format=GL_RGBA;
+ r_gl_internal_format = GL_RGBA;
if (!image.empty())
image.srgb_to_linear();
}
} else {
- r_gl_internal_format=GL_RGBA;
+ r_gl_internal_format = GL_RGBA;
}
- r_has_alpha_cache=true;
+ r_has_alpha_cache = true;
} else {
- r_gl_internal_format=(srgb_supported && p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)?_EXT_COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV1_EXT:_EXT_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
- r_gl_components=1; //doesn't matter much
- r_compressed=true;
+ r_gl_internal_format = (srgb_supported && p_flags & VS::TEXTURE_FLAG_CONVERT_TO_LINEAR) ? _EXT_COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV1_EXT : _EXT_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
+ r_gl_components = 1; //doesn't matter much
+ r_compressed = true;
}
} break;
case Image::FORMAT_ETC: {
- if (!etc_supported || p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR) {
+ if (!etc_supported || p_flags & VS::TEXTURE_FLAG_CONVERT_TO_LINEAR) {
if (!image.empty()) {
image.decompress();
}
- r_gl_components=3;
- if (p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR) {
+ r_gl_components = 3;
+ if (p_flags & VS::TEXTURE_FLAG_CONVERT_TO_LINEAR) {
if (srgb_supported) {
- r_gl_format=GL_RGB;
- r_gl_internal_format=_GL_SRGB_EXT;
+ r_gl_format = GL_RGB;
+ r_gl_internal_format = _GL_SRGB_EXT;
} else {
- r_gl_internal_format=GL_RGB;
+ r_gl_internal_format = GL_RGB;
if (!image.empty())
image.srgb_to_linear();
}
} else {
- r_gl_internal_format=GL_RGB;
+ r_gl_internal_format = GL_RGB;
}
- r_gl_internal_format=GL_RGB;
-
+ r_gl_internal_format = GL_RGB;
} else {
- r_gl_internal_format=_EXT_ETC1_RGB8_OES;
- r_gl_components=1; //doesn't matter much
- r_compressed=true;
+ r_gl_internal_format = _EXT_ETC1_RGB8_OES;
+ r_gl_components = 1; //doesn't matter much
+ r_compressed = true;
}
} break;
@@ -787,15 +756,14 @@ Image RasterizerGLES2::_get_gl_image_and_format(const Image& p_image, Image::For
if (!image.empty()) {
image.decompress();
}
- r_gl_components=3;
- r_gl_internal_format=GL_RGB;
-
+ r_gl_components = 3;
+ r_gl_internal_format = GL_RGB;
} else {
- r_gl_internal_format=_EXT_ATC_RGB_AMD;
- r_gl_components=1; //doesn't matter much
- r_compressed=true;
+ r_gl_internal_format = _EXT_ATC_RGB_AMD;
+ r_gl_components = 1; //doesn't matter much
+ r_compressed = true;
}
} break;
@@ -806,15 +774,14 @@ Image RasterizerGLES2::_get_gl_image_and_format(const Image& p_image, Image::For
if (!image.empty()) {
image.decompress();
}
- r_gl_components=4;
- r_gl_internal_format=GL_RGBA;
-
+ r_gl_components = 4;
+ r_gl_internal_format = GL_RGBA;
} else {
- r_gl_internal_format=_EXT_ATC_RGBA_EXPLICIT_ALPHA_AMD;
- r_gl_components=1; //doesn't matter much
- r_compressed=true;
+ r_gl_internal_format = _EXT_ATC_RGBA_EXPLICIT_ALPHA_AMD;
+ r_gl_components = 1; //doesn't matter much
+ r_compressed = true;
}
} break;
@@ -825,15 +792,14 @@ Image RasterizerGLES2::_get_gl_image_and_format(const Image& p_image, Image::For
if (!image.empty()) {
image.decompress();
}
- r_gl_components=4;
- r_gl_internal_format=GL_RGBA;
-
+ r_gl_components = 4;
+ r_gl_internal_format = GL_RGBA;
} else {
- r_gl_internal_format=_EXT_ATC_RGBA_INTERPOLATED_ALPHA_AMD;
- r_gl_components=1; //doesn't matter much
- r_compressed=true;
+ r_gl_internal_format = _EXT_ATC_RGBA_INTERPOLATED_ALPHA_AMD;
+ r_gl_components = 1; //doesn't matter much
+ r_compressed = true;
}
} break;
@@ -842,8 +808,8 @@ Image RasterizerGLES2::_get_gl_image_and_format(const Image& p_image, Image::For
if (!image.empty())
image.convert(Image::FORMAT_RGB8);
- r_gl_internal_format=GL_RGB;
- r_gl_components=3;
+ r_gl_internal_format = GL_RGB;
+ r_gl_components = 3;
} break;
@@ -853,14 +819,14 @@ Image RasterizerGLES2::_get_gl_image_and_format(const Image& p_image, Image::For
}
}
- if (r_gl_format==0) {
- r_gl_format=r_gl_internal_format;
+ if (r_gl_format == 0) {
+ r_gl_format = r_gl_internal_format;
}
return image;
}
-static const GLenum _cube_side_enum[6]={
+static const GLenum _cube_side_enum[6] = {
GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
GL_TEXTURE_CUBE_MAP_POSITIVE_X,
@@ -874,16 +840,15 @@ static const GLenum _cube_side_enum[6]={
RID RasterizerGLES2::texture_create() {
Texture *texture = memnew(Texture);
- ERR_FAIL_COND_V(!texture,RID());
+ ERR_FAIL_COND_V(!texture, RID());
glGenTextures(1, &texture->tex_id);
- texture->active=false;
- texture->total_data_size=0;
-
- return texture_owner.make_rid( texture );
+ texture->active = false;
+ texture->total_data_size = 0;
+ return texture_owner.make_rid(texture);
}
-void RasterizerGLES2::texture_allocate(RID p_texture,int p_width, int p_height,Image::Format p_format,uint32_t p_flags) {
+void RasterizerGLES2::texture_allocate(RID p_texture, int p_width, int p_height, Image::Format p_format, uint32_t p_flags) {
bool has_alpha_cache;
int components;
@@ -891,26 +856,24 @@ void RasterizerGLES2::texture_allocate(RID p_texture,int p_width, int p_height,I
GLenum internal_format;
bool compressed;
- int po2_width = nearest_power_of_2(p_width);
- int po2_height = nearest_power_of_2(p_height);
+ int po2_width = nearest_power_of_2(p_width);
+ int po2_height = nearest_power_of_2(p_height);
- if (p_flags&VS::TEXTURE_FLAG_VIDEO_SURFACE) {
- p_flags&=~VS::TEXTURE_FLAG_MIPMAPS; // no mipies for video
+ if (p_flags & VS::TEXTURE_FLAG_VIDEO_SURFACE) {
+ p_flags &= ~VS::TEXTURE_FLAG_MIPMAPS; // no mipies for video
}
-
- Texture *texture = texture_owner.get( p_texture );
+ Texture *texture = texture_owner.get(p_texture);
ERR_FAIL_COND(!texture);
- texture->width=p_width;
- texture->height=p_height;
- texture->format=p_format;
- texture->flags=p_flags;
+ texture->width = p_width;
+ texture->height = p_height;
+ texture->format = p_format;
+ texture->flags = p_flags;
texture->target = (p_flags & VS::TEXTURE_FLAG_CUBEMAP) ? GL_TEXTURE_CUBE_MAP : GL_TEXTURE_2D;
- _get_gl_image_and_format(Image(),texture->format,texture->flags,format,internal_format,components,has_alpha_cache,compressed);
-
- bool scale_textures = !compressed && !(p_flags&VS::TEXTURE_FLAG_VIDEO_SURFACE) && (!npo2_textures_available || p_flags&VS::TEXTURE_FLAG_MIPMAPS);
+ _get_gl_image_and_format(Image(), texture->format, texture->flags, format, internal_format, components, has_alpha_cache, compressed);
+ bool scale_textures = !compressed && !(p_flags & VS::TEXTURE_FLAG_VIDEO_SURFACE) && (!npo2_textures_available || p_flags & VS::TEXTURE_FLAG_MIPMAPS);
if (scale_textures) {
texture->alloc_width = po2_width;
@@ -922,45 +885,40 @@ void RasterizerGLES2::texture_allocate(RID p_texture,int p_width, int p_height,I
texture->alloc_height = texture->height;
};
- if (!(p_flags&VS::TEXTURE_FLAG_VIDEO_SURFACE) && shrink_textures_x2) {
- texture->alloc_height = MAX(1,texture->alloc_height/2);
- texture->alloc_width = MAX(1,texture->alloc_width/2);
+ if (!(p_flags & VS::TEXTURE_FLAG_VIDEO_SURFACE) && shrink_textures_x2) {
+ texture->alloc_height = MAX(1, texture->alloc_height / 2);
+ texture->alloc_width = MAX(1, texture->alloc_width / 2);
}
-
- texture->gl_components_cache=components;
- texture->gl_format_cache=format;
- texture->gl_internal_format_cache=internal_format;
- texture->format_has_alpha=has_alpha_cache;
- texture->compressed=compressed;
- texture->has_alpha=false; //by default it doesn't have alpha unless something with alpha is blitteds
- texture->data_size=0;
- texture->mipmaps=0;
-
+ texture->gl_components_cache = components;
+ texture->gl_format_cache = format;
+ texture->gl_internal_format_cache = internal_format;
+ texture->format_has_alpha = has_alpha_cache;
+ texture->compressed = compressed;
+ texture->has_alpha = false; //by default it doesn't have alpha unless something with alpha is blitteds
+ texture->data_size = 0;
+ texture->mipmaps = 0;
glActiveTexture(GL_TEXTURE0);
glBindTexture(texture->target, texture->tex_id);
-
-
-
- if (p_flags&VS::TEXTURE_FLAG_VIDEO_SURFACE) {
+ if (p_flags & VS::TEXTURE_FLAG_VIDEO_SURFACE) {
//prealloc if video
- glTexImage2D(texture->target, 0, internal_format, p_width, p_height, 0, format, GL_UNSIGNED_BYTE,NULL);
+ glTexImage2D(texture->target, 0, internal_format, p_width, p_height, 0, format, GL_UNSIGNED_BYTE, NULL);
}
- texture->active=true;
+ texture->active = true;
}
-void RasterizerGLES2::texture_set_data(RID p_texture,const Image& p_image,VS::CubeMapSide p_cube_side) {
+void RasterizerGLES2::texture_set_data(RID p_texture, const Image &p_image, VS::CubeMapSide p_cube_side) {
- Texture * texture = texture_owner.get(p_texture);
+ Texture *texture = texture_owner.get(p_texture);
ERR_FAIL_COND(!texture);
ERR_FAIL_COND(!texture->active);
ERR_FAIL_COND(texture->render_target);
- ERR_FAIL_COND(texture->format != p_image.get_format() );
- ERR_FAIL_COND( p_image.empty() );
+ ERR_FAIL_COND(texture->format != p_image.get_format());
+ ERR_FAIL_COND(p_image.empty());
int components;
GLenum format;
@@ -968,85 +926,77 @@ void RasterizerGLES2::texture_set_data(RID p_texture,const Image& p_image,VS::Cu
bool alpha;
bool compressed;
- if (keep_copies && !(texture->flags&VS::TEXTURE_FLAG_VIDEO_SURFACE) && !(use_reload_hooks && texture->reloader)) {
- texture->image[p_cube_side]=p_image;
+ if (keep_copies && !(texture->flags & VS::TEXTURE_FLAG_VIDEO_SURFACE) && !(use_reload_hooks && texture->reloader)) {
+ texture->image[p_cube_side] = p_image;
}
- Image img = _get_gl_image_and_format(p_image, p_image.get_format(),texture->flags,format,internal_format,components,alpha,compressed);
+ Image img = _get_gl_image_and_format(p_image, p_image.get_format(), texture->flags, format, internal_format, components, alpha, compressed);
if (texture->alloc_width != img.get_width() || texture->alloc_height != img.get_height()) {
-
- if (texture->alloc_width == img.get_width()/2 && texture->alloc_height == img.get_height()/2) {
+ if (texture->alloc_width == img.get_width() / 2 && texture->alloc_height == img.get_height() / 2) {
img.shrink_x2();
} else if (img.get_format() <= Image::FORMAT_INDEXED_ALPHA) {
img.resize(texture->alloc_width, texture->alloc_height, Image::INTERPOLATE_BILINEAR);
-
}
};
-
-
- if (!(texture->flags&VS::TEXTURE_FLAG_VIDEO_SURFACE) && img.detect_alpha()==Image::ALPHA_BLEND) {
- texture->has_alpha=true;
+ if (!(texture->flags & VS::TEXTURE_FLAG_VIDEO_SURFACE) && img.detect_alpha() == Image::ALPHA_BLEND) {
+ texture->has_alpha = true;
}
+ GLenum blit_target = (texture->target == GL_TEXTURE_CUBE_MAP) ? _cube_side_enum[p_cube_side] : GL_TEXTURE_2D;
-
- GLenum blit_target = (texture->target == GL_TEXTURE_CUBE_MAP)?_cube_side_enum[p_cube_side]:GL_TEXTURE_2D;
-
- texture->data_size=img.get_data().size();
+ texture->data_size = img.get_data().size();
PoolVector<uint8_t>::Read read = img.get_data().read();
glActiveTexture(GL_TEXTURE0);
glBindTexture(texture->target, texture->tex_id);
- texture->ignore_mipmaps = compressed && img.get_mipmaps()==0;
+ texture->ignore_mipmaps = compressed && img.get_mipmaps() == 0;
- if (texture->flags&VS::TEXTURE_FLAG_MIPMAPS && !texture->ignore_mipmaps)
- glTexParameteri(texture->target,GL_TEXTURE_MIN_FILTER,use_fast_texture_filter?GL_LINEAR_MIPMAP_NEAREST:GL_LINEAR_MIPMAP_LINEAR);
+ if (texture->flags & VS::TEXTURE_FLAG_MIPMAPS && !texture->ignore_mipmaps)
+ glTexParameteri(texture->target, GL_TEXTURE_MIN_FILTER, use_fast_texture_filter ? GL_LINEAR_MIPMAP_NEAREST : GL_LINEAR_MIPMAP_LINEAR);
else {
- if (texture->flags&VS::TEXTURE_FLAG_FILTER) {
- glTexParameteri(texture->target,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
+ if (texture->flags & VS::TEXTURE_FLAG_FILTER) {
+ glTexParameteri(texture->target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
} else {
- glTexParameteri(texture->target,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
-
+ glTexParameteri(texture->target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
}
}
- if (texture->flags&VS::TEXTURE_FLAG_FILTER) {
+ if (texture->flags & VS::TEXTURE_FLAG_FILTER) {
- glTexParameteri(texture->target,GL_TEXTURE_MAG_FILTER,GL_LINEAR); // Linear Filtering
+ glTexParameteri(texture->target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // Linear Filtering
} else {
- glTexParameteri(texture->target,GL_TEXTURE_MAG_FILTER,GL_NEAREST); // raw Filtering
+ glTexParameteri(texture->target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); // raw Filtering
}
- bool force_clamp_to_edge = !(texture->flags&VS::TEXTURE_FLAG_MIPMAPS && !texture->ignore_mipmaps) && (nearest_power_of_2(texture->alloc_height)!=texture->alloc_height || nearest_power_of_2(texture->alloc_width)!=texture->alloc_width);
+ bool force_clamp_to_edge = !(texture->flags & VS::TEXTURE_FLAG_MIPMAPS && !texture->ignore_mipmaps) && (nearest_power_of_2(texture->alloc_height) != texture->alloc_height || nearest_power_of_2(texture->alloc_width) != texture->alloc_width);
- if (!force_clamp_to_edge && (texture->flags&VS::TEXTURE_FLAG_REPEAT || texture->flags&VS::TEXTURE_FLAG_MIRRORED_REPEAT) && texture->target != GL_TEXTURE_CUBE_MAP) {
+ if (!force_clamp_to_edge && (texture->flags & VS::TEXTURE_FLAG_REPEAT || texture->flags & VS::TEXTURE_FLAG_MIRRORED_REPEAT) && texture->target != GL_TEXTURE_CUBE_MAP) {
- if (texture->flags&VS::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{
- glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
- glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
+ if (texture->flags & VS::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 {
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
}
} else {
//glTexParameterf( texture->target, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE );
- glTexParameterf( texture->target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
- glTexParameterf( texture->target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
+ glTexParameterf(texture->target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameterf(texture->target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
}
if (use_anisotropic_filter) {
- if (texture->flags&VS::TEXTURE_FLAG_ANISOTROPIC_FILTER) {
+ if (texture->flags & VS::TEXTURE_FLAG_ANISOTROPIC_FILTER) {
glTexParameterf(texture->target, _GL_TEXTURE_MAX_ANISOTROPY_EXT, anisotropic_level);
} else {
@@ -1054,74 +1004,66 @@ void RasterizerGLES2::texture_set_data(RID p_texture,const Image& p_image,VS::Cu
}
}
- int mipmaps= (texture->flags&VS::TEXTURE_FLAG_MIPMAPS && img.get_mipmaps()>0) ? img.get_mipmaps() +1 : 1;
+ int mipmaps = (texture->flags & VS::TEXTURE_FLAG_MIPMAPS && img.get_mipmaps() > 0) ? img.get_mipmaps() + 1 : 1;
+ int w = img.get_width();
+ int h = img.get_height();
- int w=img.get_width();
- int h=img.get_height();
+ int tsize = 0;
+ for (int i = 0; i < mipmaps; i++) {
- int tsize=0;
- for(int i=0;i<mipmaps;i++) {
-
- int size,ofs;
- img.get_mipmap_offset_and_size(i,ofs,size);
+ int size, ofs;
+ img.get_mipmap_offset_and_size(i, ofs, size);
//print_line("mipmap: "+itos(i)+" size: "+itos(size)+" w: "+itos(mm_w)+", h: "+itos(mm_h));
if (texture->compressed) {
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
- glCompressedTexImage2D( blit_target, i, format,w,h,0,size,&read[ofs] );
+ glCompressedTexImage2D(blit_target, i, format, w, h, 0, size, &read[ofs]);
} else {
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
- if (texture->flags&VS::TEXTURE_FLAG_VIDEO_SURFACE) {
- glTexSubImage2D( blit_target, i, 0,0,w, h,format,GL_UNSIGNED_BYTE,&read[ofs] );
+ if (texture->flags & VS::TEXTURE_FLAG_VIDEO_SURFACE) {
+ glTexSubImage2D(blit_target, i, 0, 0, w, h, format, GL_UNSIGNED_BYTE, &read[ofs]);
} else {
- glTexImage2D(blit_target, i, internal_format, w, h, 0, format, GL_UNSIGNED_BYTE,&read[ofs]);
+ glTexImage2D(blit_target, i, internal_format, w, h, 0, format, GL_UNSIGNED_BYTE, &read[ofs]);
}
-
}
- tsize+=size;
-
- w = MAX(1,w>>1);
- h = MAX(1,h>>1);
+ tsize += size;
+ w = MAX(1, w >> 1);
+ h = MAX(1, h >> 1);
}
- _rinfo.texture_mem-=texture->total_data_size;
- texture->total_data_size=tsize;
- _rinfo.texture_mem+=texture->total_data_size;
+ _rinfo.texture_mem -= texture->total_data_size;
+ texture->total_data_size = tsize;
+ _rinfo.texture_mem += texture->total_data_size;
//printf("texture: %i x %i - size: %i - total: %i\n",texture->width,texture->height,tsize,_rinfo.texture_mem);
-
- if (texture->flags&VS::TEXTURE_FLAG_MIPMAPS && mipmaps==1 && !texture->ignore_mipmaps) {
+ if (texture->flags & VS::TEXTURE_FLAG_MIPMAPS && mipmaps == 1 && !texture->ignore_mipmaps) {
//generate mipmaps if they were requested and the image does not contain them
glGenerateMipmap(texture->target);
}
- texture->mipmaps=mipmaps;
+ texture->mipmaps = mipmaps;
-
-
- if (mipmaps>1) {
+ if (mipmaps > 1) {
//glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, mipmaps-1 ); - assumed to have all, always
}
//texture_set_flags(p_texture,texture->flags);
-
-
}
-Image RasterizerGLES2::texture_get_data(RID p_texture,VS::CubeMapSide p_cube_side) const {
+Image RasterizerGLES2::texture_get_data(RID p_texture, VS::CubeMapSide p_cube_side) const {
- Texture * texture = texture_owner.get(p_texture);
+ Texture *texture = texture_owner.get(p_texture);
- ERR_FAIL_COND_V(!texture,Image());
- ERR_FAIL_COND_V(!texture->active,Image());
- ERR_FAIL_COND_V(texture->data_size==0,Image());
- ERR_FAIL_COND_V(texture->render_target,Image());
+ ERR_FAIL_COND_V(!texture, Image());
+ ERR_FAIL_COND_V(!texture->active, Image());
+ ERR_FAIL_COND_V(texture->data_size == 0, Image());
+ ERR_FAIL_COND_V(texture->render_target, Image());
return texture->image[p_cube_side];
@@ -1275,46 +1217,42 @@ Image RasterizerGLES2::texture_get_data(RID p_texture,VS::CubeMapSide p_cube_sid
#endif
}
-void RasterizerGLES2::texture_set_flags(RID p_texture,uint32_t p_flags) {
+void RasterizerGLES2::texture_set_flags(RID p_texture, uint32_t p_flags) {
- Texture *texture = texture_owner.get( p_texture );
+ Texture *texture = texture_owner.get(p_texture);
ERR_FAIL_COND(!texture);
if (texture->render_target) {
- p_flags&=VS::TEXTURE_FLAG_FILTER;//can change only filter
+ p_flags &= VS::TEXTURE_FLAG_FILTER; //can change only filter
}
- bool had_mipmaps = texture->flags&VS::TEXTURE_FLAG_MIPMAPS;
+ bool had_mipmaps = texture->flags & VS::TEXTURE_FLAG_MIPMAPS;
glActiveTexture(GL_TEXTURE0);
glBindTexture(texture->target, texture->tex_id);
uint32_t cube = texture->flags & VS::TEXTURE_FLAG_CUBEMAP;
- texture->flags=p_flags|cube; // can't remove a cube from being a cube
-
+ texture->flags = p_flags | cube; // can't remove a cube from being a cube
- bool force_clamp_to_edge = !(p_flags&VS::TEXTURE_FLAG_MIPMAPS && !texture->ignore_mipmaps) && (nearest_power_of_2(texture->alloc_height)!=texture->alloc_height || nearest_power_of_2(texture->alloc_width)!=texture->alloc_width);
+ bool force_clamp_to_edge = !(p_flags & VS::TEXTURE_FLAG_MIPMAPS && !texture->ignore_mipmaps) && (nearest_power_of_2(texture->alloc_height) != texture->alloc_height || nearest_power_of_2(texture->alloc_width) != texture->alloc_width);
- if (!force_clamp_to_edge && (texture->flags&VS::TEXTURE_FLAG_REPEAT || texture->flags&VS::TEXTURE_FLAG_MIRRORED_REPEAT) && texture->target != GL_TEXTURE_CUBE_MAP) {
+ if (!force_clamp_to_edge && (texture->flags & VS::TEXTURE_FLAG_REPEAT || texture->flags & VS::TEXTURE_FLAG_MIRRORED_REPEAT) && texture->target != GL_TEXTURE_CUBE_MAP) {
- if (texture->flags&VS::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 {
- glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
- glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
+ if (texture->flags & VS::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 {
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
}
} else {
//glTexParameterf( texture->target, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE );
- glTexParameterf( texture->target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
- glTexParameterf( texture->target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
-
+ glTexParameterf(texture->target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameterf(texture->target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
}
-
if (use_anisotropic_filter) {
- if (texture->flags&VS::TEXTURE_FLAG_ANISOTROPIC_FILTER) {
+ if (texture->flags & VS::TEXTURE_FLAG_ANISOTROPIC_FILTER) {
glTexParameterf(texture->target, _GL_TEXTURE_MAX_ANISOTROPY_EXT, anisotropic_level);
} else {
@@ -1322,182 +1260,171 @@ void RasterizerGLES2::texture_set_flags(RID p_texture,uint32_t p_flags) {
}
}
- if (texture->flags&VS::TEXTURE_FLAG_MIPMAPS && !texture->ignore_mipmaps) {
- if (!had_mipmaps && texture->mipmaps==1) {
+ if (texture->flags & VS::TEXTURE_FLAG_MIPMAPS && !texture->ignore_mipmaps) {
+ if (!had_mipmaps && texture->mipmaps == 1) {
glGenerateMipmap(texture->target);
}
- glTexParameteri(texture->target,GL_TEXTURE_MIN_FILTER,use_fast_texture_filter?GL_LINEAR_MIPMAP_NEAREST:GL_LINEAR_MIPMAP_LINEAR);
+ glTexParameteri(texture->target, GL_TEXTURE_MIN_FILTER, use_fast_texture_filter ? GL_LINEAR_MIPMAP_NEAREST : GL_LINEAR_MIPMAP_LINEAR);
- } else{
- if (texture->flags&VS::TEXTURE_FLAG_FILTER) {
- glTexParameteri(texture->target,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
+ } else {
+ if (texture->flags & VS::TEXTURE_FLAG_FILTER) {
+ glTexParameteri(texture->target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
} else {
- glTexParameteri(texture->target,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
-
+ glTexParameteri(texture->target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
}
}
- if (texture->flags&VS::TEXTURE_FLAG_FILTER) {
+ if (texture->flags & VS::TEXTURE_FLAG_FILTER) {
- glTexParameteri(texture->target,GL_TEXTURE_MAG_FILTER,GL_LINEAR); // Linear Filtering
+ glTexParameteri(texture->target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // Linear Filtering
} else {
- glTexParameteri(texture->target,GL_TEXTURE_MAG_FILTER,GL_NEAREST); // raw Filtering
+ glTexParameteri(texture->target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); // raw Filtering
}
}
uint32_t RasterizerGLES2::texture_get_flags(RID p_texture) const {
- Texture * texture = texture_owner.get(p_texture);
+ Texture *texture = texture_owner.get(p_texture);
- ERR_FAIL_COND_V(!texture,0);
+ ERR_FAIL_COND_V(!texture, 0);
return texture->flags;
-
}
Image::Format RasterizerGLES2::texture_get_format(RID p_texture) const {
- Texture * texture = texture_owner.get(p_texture);
+ Texture *texture = texture_owner.get(p_texture);
- ERR_FAIL_COND_V(!texture,Image::FORMAT_L8);
+ ERR_FAIL_COND_V(!texture, Image::FORMAT_L8);
return texture->format;
}
uint32_t RasterizerGLES2::texture_get_width(RID p_texture) const {
- Texture * texture = texture_owner.get(p_texture);
+ Texture *texture = texture_owner.get(p_texture);
- ERR_FAIL_COND_V(!texture,0);
+ ERR_FAIL_COND_V(!texture, 0);
return texture->width;
}
uint32_t RasterizerGLES2::texture_get_height(RID p_texture) const {
- Texture * texture = texture_owner.get(p_texture);
+ Texture *texture = texture_owner.get(p_texture);
- ERR_FAIL_COND_V(!texture,0);
+ ERR_FAIL_COND_V(!texture, 0);
return texture->height;
}
bool RasterizerGLES2::texture_has_alpha(RID p_texture) const {
- Texture * texture = texture_owner.get(p_texture);
+ Texture *texture = texture_owner.get(p_texture);
- ERR_FAIL_COND_V(!texture,0);
+ ERR_FAIL_COND_V(!texture, 0);
return texture->has_alpha;
-
}
-void RasterizerGLES2::texture_set_size_override(RID p_texture,int p_width, int p_height) {
+void RasterizerGLES2::texture_set_size_override(RID p_texture, int p_width, int p_height) {
- Texture * texture = texture_owner.get(p_texture);
+ Texture *texture = texture_owner.get(p_texture);
ERR_FAIL_COND(!texture);
ERR_FAIL_COND(texture->render_target);
- ERR_FAIL_COND(p_width<=0 || p_width>16384);
- ERR_FAIL_COND(p_height<=0 || p_height>16384);
+ ERR_FAIL_COND(p_width <= 0 || p_width > 16384);
+ ERR_FAIL_COND(p_height <= 0 || p_height > 16384);
//real texture size is in alloc width and height
- texture->width=p_width;
- texture->height=p_height;
-
+ texture->width = p_width;
+ texture->height = p_height;
}
-void RasterizerGLES2::texture_set_reload_hook(RID p_texture,ObjectID p_owner,const StringName& p_function) const {
+void RasterizerGLES2::texture_set_reload_hook(RID p_texture, ObjectID p_owner, const StringName &p_function) const {
- Texture * texture = texture_owner.get(p_texture);
+ Texture *texture = texture_owner.get(p_texture);
ERR_FAIL_COND(!texture);
ERR_FAIL_COND(texture->render_target);
- texture->reloader=p_owner;
- texture->reloader_func=p_function;
+ texture->reloader = p_owner;
+ texture->reloader_func = p_function;
if (use_reload_hooks && p_owner && keep_copies) {
- for(int i=0;i<6;i++)
- texture->image[i]=Image();
+ for (int i = 0; i < 6; i++)
+ texture->image[i] = Image();
}
}
-
GLuint RasterizerGLES2::_texture_get_name(RID p_tex) {
- Texture * texture = texture_owner.get(p_tex);
+ Texture *texture = texture_owner.get(p_tex);
ERR_FAIL_COND_V(!texture, 0);
return texture->tex_id;
};
-void RasterizerGLES2::texture_set_path(RID p_texture,const String& p_path) {
- Texture * texture = texture_owner.get(p_texture);
+void RasterizerGLES2::texture_set_path(RID p_texture, const String &p_path) {
+ Texture *texture = texture_owner.get(p_texture);
ERR_FAIL_COND(!texture);
- texture->path=p_path;
-
+ texture->path = p_path;
}
-String RasterizerGLES2::texture_get_path(RID p_texture) const{
+String RasterizerGLES2::texture_get_path(RID p_texture) const {
- Texture * texture = texture_owner.get(p_texture);
- ERR_FAIL_COND_V(!texture,String());
+ Texture *texture = texture_owner.get(p_texture);
+ ERR_FAIL_COND_V(!texture, String());
return texture->path;
}
-void RasterizerGLES2::texture_debug_usage(List<VS::TextureInfo> *r_info){
+void RasterizerGLES2::texture_debug_usage(List<VS::TextureInfo> *r_info) {
List<RID> textures;
texture_owner.get_owned_list(&textures);
- for (List<RID>::Element *E=textures.front();E;E=E->next()) {
+ for (List<RID>::Element *E = textures.front(); E; E = E->next()) {
Texture *t = texture_owner.get(E->get());
if (!t)
continue;
VS::TextureInfo tinfo;
- tinfo.path=t->path;
- tinfo.format=t->format;
- tinfo.size.x=t->alloc_width;
- tinfo.size.y=t->alloc_height;
- tinfo.bytes=t->total_data_size;
+ tinfo.path = t->path;
+ tinfo.format = t->format;
+ tinfo.size.x = t->alloc_width;
+ tinfo.size.y = t->alloc_height;
+ tinfo.bytes = t->total_data_size;
r_info->push_back(tinfo);
}
-
}
void RasterizerGLES2::texture_set_shrink_all_x2_on_set_data(bool p_enable) {
- shrink_textures_x2=p_enable;
+ shrink_textures_x2 = p_enable;
}
/* SHADER API */
RID RasterizerGLES2::shader_create(VS::ShaderMode p_mode) {
- Shader *shader = memnew( Shader );
- shader->mode=p_mode;
+ Shader *shader = memnew(Shader);
+ shader->mode = p_mode;
RID rid = shader_owner.make_rid(shader);
- shader_set_mode(rid,p_mode);
+ shader_set_mode(rid, p_mode);
_shader_make_dirty(shader);
return rid;
-
}
+void RasterizerGLES2::shader_set_mode(RID p_shader, VS::ShaderMode p_mode) {
-
-void RasterizerGLES2::shader_set_mode(RID p_shader,VS::ShaderMode p_mode) {
-
- ERR_FAIL_INDEX(p_mode,3);
- Shader *shader=shader_owner.get(p_shader);
+ ERR_FAIL_INDEX(p_mode, 3);
+ Shader *shader = shader_owner.get(p_shader);
ERR_FAIL_COND(!shader);
- if (shader->custom_code_id && p_mode==shader->mode)
+ if (shader->custom_code_id && p_mode == shader->mode)
return;
-
if (shader->custom_code_id) {
- switch(shader->mode) {
+ switch (shader->mode) {
case VS::SHADER_MATERIAL: {
material_shader.free_custom_shader(shader->custom_code_id);
} break;
@@ -1506,75 +1433,68 @@ void RasterizerGLES2::shader_set_mode(RID p_shader,VS::ShaderMode p_mode) {
} break;
}
- shader->custom_code_id=0;
+ shader->custom_code_id = 0;
}
- shader->mode=p_mode;
+ shader->mode = p_mode;
- switch(shader->mode) {
+ switch (shader->mode) {
case VS::SHADER_MATERIAL: {
- shader->custom_code_id=material_shader.create_custom_shader();
+ shader->custom_code_id = material_shader.create_custom_shader();
} break;
case VS::SHADER_CANVAS_ITEM: {
- shader->custom_code_id=canvas_shader.create_custom_shader();
+ shader->custom_code_id = canvas_shader.create_custom_shader();
} break;
}
_shader_make_dirty(shader);
-
}
VS::ShaderMode RasterizerGLES2::shader_get_mode(RID p_shader) const {
- Shader *shader=shader_owner.get(p_shader);
- ERR_FAIL_COND_V(!shader,VS::SHADER_MATERIAL);
+ Shader *shader = shader_owner.get(p_shader);
+ ERR_FAIL_COND_V(!shader, VS::SHADER_MATERIAL);
return shader->mode;
}
+void RasterizerGLES2::shader_set_code(RID p_shader, const String &p_vertex, const String &p_fragment, const String &p_light, int p_vertex_ofs, int p_fragment_ofs, int p_light_ofs) {
-void RasterizerGLES2::shader_set_code(RID p_shader, const String& p_vertex, const String& p_fragment,const String& p_light,int p_vertex_ofs,int p_fragment_ofs,int p_light_ofs) {
-
-
- Shader *shader=shader_owner.get(p_shader);
+ Shader *shader = shader_owner.get(p_shader);
ERR_FAIL_COND(!shader);
#ifdef DEBUG_ENABLED
- if (shader->vertex_code==p_vertex && shader->fragment_code==p_fragment && shader->light_code==p_light)
+ if (shader->vertex_code == p_vertex && shader->fragment_code == p_fragment && shader->light_code == p_light)
return;
#endif
- shader->fragment_code=p_fragment;
- shader->vertex_code=p_vertex;
- shader->light_code=p_light;
- shader->fragment_line=p_fragment_ofs;
- shader->vertex_line=p_vertex_ofs;
- shader->light_line=p_light_ofs;
+ shader->fragment_code = p_fragment;
+ shader->vertex_code = p_vertex;
+ shader->light_code = p_light;
+ shader->fragment_line = p_fragment_ofs;
+ shader->vertex_line = p_vertex_ofs;
+ shader->light_line = p_light_ofs;
_shader_make_dirty(shader);
-
}
String RasterizerGLES2::shader_get_vertex_code(RID p_shader) const {
- Shader *shader=shader_owner.get(p_shader);
- ERR_FAIL_COND_V(!shader,String());
+ Shader *shader = shader_owner.get(p_shader);
+ ERR_FAIL_COND_V(!shader, String());
return shader->vertex_code;
-
}
String RasterizerGLES2::shader_get_fragment_code(RID p_shader) const {
- Shader *shader=shader_owner.get(p_shader);
- ERR_FAIL_COND_V(!shader,String());
+ Shader *shader = shader_owner.get(p_shader);
+ ERR_FAIL_COND_V(!shader, String());
return shader->fragment_code;
-
}
String RasterizerGLES2::shader_get_light_code(RID p_shader) const {
- Shader *shader=shader_owner.get(p_shader);
- ERR_FAIL_COND_V(!shader,String());
+ Shader *shader = shader_owner.get(p_shader);
+ ERR_FAIL_COND_V(!shader, String());
return shader->light_code;
-
}
-void RasterizerGLES2::_shader_make_dirty(Shader* p_shader) {
+void RasterizerGLES2::_shader_make_dirty(Shader *p_shader) {
if (p_shader->dirty_list.in_list())
return;
@@ -1584,30 +1504,25 @@ void RasterizerGLES2::_shader_make_dirty(Shader* p_shader) {
void RasterizerGLES2::shader_get_param_list(RID p_shader, List<PropertyInfo> *p_param_list) const {
- Shader *shader=shader_owner.get(p_shader);
+ Shader *shader = shader_owner.get(p_shader);
ERR_FAIL_COND(!shader);
-
if (shader->dirty_list.in_list())
_update_shader(shader); // ok should be not anymore dirty
+ Map<int, StringName> order;
- Map<int,StringName> order;
-
+ for (Map<StringName, ShaderLanguage::Uniform>::Element *E = shader->uniforms.front(); E; E = E->next()) {
- for(Map<StringName,ShaderLanguage::Uniform>::Element *E=shader->uniforms.front();E;E=E->next()) {
-
-
- order[E->get().order]=E->key();
+ order[E->get().order] = E->key();
}
-
- for(Map<int,StringName>::Element *E=order.front();E;E=E->next()) {
+ for (Map<int, StringName>::Element *E = order.front(); E; E = E->next()) {
PropertyInfo pi;
- ShaderLanguage::Uniform &u=shader->uniforms[E->get()];
- pi.name=E->get();
- switch(u.type) {
+ ShaderLanguage::Uniform &u = shader->uniforms[E->get()];
+ pi.name = E->get();
+ switch (u.type) {
case ShaderLanguage::TYPE_VOID:
case ShaderLanguage::TYPE_BOOL:
@@ -1617,55 +1532,52 @@ void RasterizerGLES2::shader_get_param_list(RID p_shader, List<PropertyInfo> *p_
case ShaderLanguage::TYPE_MAT3:
case ShaderLanguage::TYPE_MAT4:
case ShaderLanguage::TYPE_VEC4:
- pi.type=u.default_value.get_type();
+ pi.type = u.default_value.get_type();
break;
case ShaderLanguage::TYPE_TEXTURE:
- pi.type=Variant::_RID;
- pi.hint=PROPERTY_HINT_RESOURCE_TYPE;
- pi.hint_string="Texture";
+ pi.type = Variant::_RID;
+ pi.hint = PROPERTY_HINT_RESOURCE_TYPE;
+ pi.hint_string = "Texture";
break;
case ShaderLanguage::TYPE_CUBEMAP:
- pi.type=Variant::_RID;
- pi.hint=PROPERTY_HINT_RESOURCE_TYPE;
- pi.hint_string="CubeMap";
+ pi.type = Variant::_RID;
+ pi.hint = PROPERTY_HINT_RESOURCE_TYPE;
+ pi.hint_string = "CubeMap";
break;
};
p_param_list->push_back(pi);
-
}
-
}
-void RasterizerGLES2::shader_set_default_texture_param(RID p_shader, const StringName& p_name, RID p_texture) {
+void RasterizerGLES2::shader_set_default_texture_param(RID p_shader, const StringName &p_name, RID p_texture) {
- Shader *shader=shader_owner.get(p_shader);
+ Shader *shader = shader_owner.get(p_shader);
ERR_FAIL_COND(!shader);
ERR_FAIL_COND(p_texture.is_valid() && !texture_owner.owns(p_texture));
if (p_texture.is_valid())
- shader->default_textures[p_name]=p_texture;
+ shader->default_textures[p_name] = p_texture;
else
shader->default_textures.erase(p_name);
_shader_make_dirty(shader);
-
}
-RID RasterizerGLES2::shader_get_default_texture_param(RID p_shader, const StringName& p_name) const{
- const Shader *shader=shader_owner.get(p_shader);
- ERR_FAIL_COND_V(!shader,RID());
+RID RasterizerGLES2::shader_get_default_texture_param(RID p_shader, const StringName &p_name) const {
+ const Shader *shader = shader_owner.get(p_shader);
+ ERR_FAIL_COND_V(!shader, RID());
- const Map<StringName,RID>::Element *E=shader->default_textures.find(p_name);
+ const Map<StringName, RID>::Element *E = shader->default_textures.find(p_name);
if (!E)
return RID();
return E->get();
}
-Variant RasterizerGLES2::shader_get_default_param(RID p_shader, const StringName& p_name) {
+Variant RasterizerGLES2::shader_get_default_param(RID p_shader, const StringName &p_name) {
- Shader *shader=shader_owner.get(p_shader);
- ERR_FAIL_COND_V(!shader,Variant());
+ Shader *shader = shader_owner.get(p_shader);
+ ERR_FAIL_COND_V(!shader, Variant());
//update shader params if necesary
//make sure the shader is compiled and everything
@@ -1679,13 +1591,11 @@ Variant RasterizerGLES2::shader_get_default_param(RID p_shader, const StringName
return Variant();
}
-
/* COMMON MATERIAL API */
-
RID RasterizerGLES2::material_create() {
- RID material = material_owner.make_rid( memnew( Material ) );
+ RID material = material_owner.make_rid(memnew(Material));
return material;
}
@@ -1693,364 +1603,339 @@ void RasterizerGLES2::material_set_shader(RID p_material, RID p_shader) {
Material *material = material_owner.get(p_material);
ERR_FAIL_COND(!material);
- if (material->shader==p_shader)
+ if (material->shader == p_shader)
return;
- material->shader=p_shader;
- material->shader_version=0;
-
+ material->shader = p_shader;
+ material->shader_version = 0;
}
RID RasterizerGLES2::material_get_shader(RID p_material) const {
Material *material = material_owner.get(p_material);
- ERR_FAIL_COND_V(!material,RID());
+ ERR_FAIL_COND_V(!material, RID());
return material->shader;
}
-
-void RasterizerGLES2::material_set_param(RID p_material, const StringName& p_param, const Variant& p_value) {
+void RasterizerGLES2::material_set_param(RID p_material, const StringName &p_param, const Variant &p_value) {
Material *material = material_owner.get(p_material);
ERR_FAIL_COND(!material);
- Map<StringName,Material::UniformData>::Element *E=material->shader_params.find(p_param);
+ Map<StringName, Material::UniformData>::Element *E = material->shader_params.find(p_param);
if (E) {
- if (p_value.get_type()==Variant::NIL) {
+ if (p_value.get_type() == Variant::NIL) {
material->shader_params.erase(E);
- material->shader_version=0; //get default!
+ material->shader_version = 0; //get default!
} else {
- E->get().value=p_value;
- E->get().inuse=true;
+ E->get().value = p_value;
+ E->get().inuse = true;
}
} else {
- if (p_value.get_type()==Variant::NIL)
+ if (p_value.get_type() == Variant::NIL)
return;
Material::UniformData ud;
- ud.index=-1;
- ud.value=p_value;
- ud.istexture=p_value.get_type()==Variant::_RID; /// cache it being texture
- ud.inuse=true;
- material->shader_params[p_param]=ud; //may be got at some point, or erased
-
+ ud.index = -1;
+ ud.value = p_value;
+ ud.istexture = p_value.get_type() == Variant::_RID; /// cache it being texture
+ ud.inuse = true;
+ material->shader_params[p_param] = ud; //may be got at some point, or erased
}
}
-Variant RasterizerGLES2::material_get_param(RID p_material, const StringName& p_param) const {
+Variant RasterizerGLES2::material_get_param(RID p_material, const StringName &p_param) const {
Material *material = material_owner.get(p_material);
- ERR_FAIL_COND_V(!material,Variant());
-
+ ERR_FAIL_COND_V(!material, Variant());
if (material->shader.is_valid()) {
//update shader params if necesary
//make sure the shader is compiled and everything
//so the actual parameters can be properly retrieved!
- material->shader_cache=shader_owner.get( material->shader );
+ material->shader_cache = shader_owner.get(material->shader);
if (!material->shader_cache) {
//invalidate
- material->shader=RID();
- material->shader_cache=NULL;
+ material->shader = RID();
+ material->shader_cache = NULL;
} else {
if (material->shader_cache->dirty_list.in_list())
_update_shader(material->shader_cache);
- if (material->shader_cache->valid && material->shader_cache->version!=material->shader_version) {
+ if (material->shader_cache->valid && material->shader_cache->version != material->shader_version) {
//validate
_update_material_shader_params(material);
}
}
}
-
if (material->shader_params.has(p_param) && material->shader_params[p_param].inuse)
return material->shader_params[p_param].value;
else
return Variant();
}
-
-void RasterizerGLES2::material_set_flag(RID p_material, VS::MaterialFlag p_flag,bool p_enabled) {
+void RasterizerGLES2::material_set_flag(RID p_material, VS::MaterialFlag p_flag, bool p_enabled) {
Material *material = material_owner.get(p_material);
ERR_FAIL_COND(!material);
- ERR_FAIL_INDEX(p_flag,VS::MATERIAL_FLAG_MAX);
-
- material->flags[p_flag]=p_enabled;
+ ERR_FAIL_INDEX(p_flag, VS::MATERIAL_FLAG_MAX);
+ material->flags[p_flag] = p_enabled;
}
-bool RasterizerGLES2::material_get_flag(RID p_material,VS::MaterialFlag p_flag) const {
+bool RasterizerGLES2::material_get_flag(RID p_material, VS::MaterialFlag p_flag) const {
Material *material = material_owner.get(p_material);
- ERR_FAIL_COND_V(!material,false);
- ERR_FAIL_INDEX_V(p_flag,VS::MATERIAL_FLAG_MAX,false);
+ ERR_FAIL_COND_V(!material, false);
+ ERR_FAIL_INDEX_V(p_flag, VS::MATERIAL_FLAG_MAX, false);
return material->flags[p_flag];
-
-
}
void RasterizerGLES2::material_set_depth_draw_mode(RID p_material, VS::MaterialDepthDrawMode p_mode) {
Material *material = material_owner.get(p_material);
ERR_FAIL_COND(!material);
- material->depth_draw_mode=p_mode;
-
+ material->depth_draw_mode = p_mode;
}
VS::MaterialDepthDrawMode RasterizerGLES2::material_get_depth_draw_mode(RID p_material) const {
Material *material = material_owner.get(p_material);
- ERR_FAIL_COND_V(!material,VS::MATERIAL_DEPTH_DRAW_ALWAYS);
+ ERR_FAIL_COND_V(!material, VS::MATERIAL_DEPTH_DRAW_ALWAYS);
return material->depth_draw_mode;
-
}
-
-
-void RasterizerGLES2::material_set_blend_mode(RID p_material,VS::MaterialBlendMode p_mode) {
+void RasterizerGLES2::material_set_blend_mode(RID p_material, VS::MaterialBlendMode p_mode) {
Material *material = material_owner.get(p_material);
ERR_FAIL_COND(!material);
- material->blend_mode=p_mode;
-
+ material->blend_mode = p_mode;
}
VS::MaterialBlendMode RasterizerGLES2::material_get_blend_mode(RID p_material) const {
Material *material = material_owner.get(p_material);
- ERR_FAIL_COND_V(!material,VS::MATERIAL_BLEND_MODE_ADD);
+ ERR_FAIL_COND_V(!material, VS::MATERIAL_BLEND_MODE_ADD);
return material->blend_mode;
}
-void RasterizerGLES2::material_set_line_width(RID p_material,float p_line_width) {
+void RasterizerGLES2::material_set_line_width(RID p_material, float p_line_width) {
Material *material = material_owner.get(p_material);
ERR_FAIL_COND(!material);
- material->line_width=p_line_width;
-
+ material->line_width = p_line_width;
}
float RasterizerGLES2::material_get_line_width(RID p_material) const {
Material *material = material_owner.get(p_material);
- ERR_FAIL_COND_V(!material,0);
+ ERR_FAIL_COND_V(!material, 0);
return material->line_width;
}
-
-
/* MESH API */
RID RasterizerGLES2::mesh_create() {
-
- return mesh_owner.make_rid( memnew( Mesh ) );
+ return mesh_owner.make_rid(memnew(Mesh));
}
+void RasterizerGLES2::mesh_add_surface(RID p_mesh, VS::PrimitiveType p_primitive, const Array &p_arrays, const Array &p_blend_shapes, bool p_alpha_sort) {
-
-void RasterizerGLES2::mesh_add_surface(RID p_mesh,VS::PrimitiveType p_primitive,const Array& p_arrays,const Array& p_blend_shapes,bool p_alpha_sort) {
-
- Mesh *mesh = mesh_owner.get( p_mesh );
+ Mesh *mesh = mesh_owner.get(p_mesh);
ERR_FAIL_COND(!mesh);
- ERR_FAIL_INDEX( p_primitive, VS::PRIMITIVE_MAX );
- ERR_FAIL_COND(p_arrays.size()!=VS::ARRAY_MAX);
+ ERR_FAIL_INDEX(p_primitive, VS::PRIMITIVE_MAX);
+ ERR_FAIL_COND(p_arrays.size() != VS::ARRAY_MAX);
- uint32_t format=0;
+ uint32_t format = 0;
// validation
- int index_array_len=0;
- int array_len=0;
+ int index_array_len = 0;
+ int array_len = 0;
- for(int i=0;i<p_arrays.size();i++) {
+ for (int i = 0; i < p_arrays.size(); i++) {
- if (p_arrays[i].get_type()==Variant::NIL)
+ if (p_arrays[i].get_type() == Variant::NIL)
continue;
- format|=(1<<i);
+ format |= (1 << i);
- if (i==VS::ARRAY_VERTEX) {
+ if (i == VS::ARRAY_VERTEX) {
- array_len=Vector3Array(p_arrays[i]).size();
- ERR_FAIL_COND(array_len==0);
- } else if (i==VS::ARRAY_INDEX) {
+ array_len = Vector3Array(p_arrays[i]).size();
+ ERR_FAIL_COND(array_len == 0);
+ } else if (i == VS::ARRAY_INDEX) {
- index_array_len=IntArray(p_arrays[i]).size();
+ index_array_len = IntArray(p_arrays[i]).size();
}
}
- ERR_FAIL_COND((format&VS::ARRAY_FORMAT_VERTEX)==0); // mandatory
+ ERR_FAIL_COND((format & VS::ARRAY_FORMAT_VERTEX) == 0); // mandatory
- ERR_FAIL_COND( mesh->morph_target_count!=p_blend_shapes.size() );
+ ERR_FAIL_COND(mesh->morph_target_count != p_blend_shapes.size());
if (mesh->morph_target_count) {
//validate format for morphs
- for(int i=0;i<p_blend_shapes.size();i++) {
+ for (int i = 0; i < p_blend_shapes.size(); i++) {
- uint32_t bsformat=0;
+ uint32_t bsformat = 0;
Array arr = p_blend_shapes[i];
- for(int j=0;j<arr.size();j++) {
-
+ for (int j = 0; j < arr.size(); j++) {
- if (arr[j].get_type()!=Variant::NIL)
- bsformat|=(1<<j);
+ if (arr[j].get_type() != Variant::NIL)
+ bsformat |= (1 << j);
}
- ERR_FAIL_COND( (bsformat)!=(format&(VS::ARRAY_FORMAT_BONES-1)));
+ ERR_FAIL_COND((bsformat) != (format & (VS::ARRAY_FORMAT_BONES - 1)));
}
}
- Surface *surface = memnew( Surface );
- ERR_FAIL_COND( !surface );
+ Surface *surface = memnew(Surface);
+ ERR_FAIL_COND(!surface);
- bool use_VBO=true; //glGenBuffersARB!=NULL; // TODO detect if it's in there
- if ((!use_hw_skeleton_xform && format&VS::ARRAY_FORMAT_WEIGHTS) || mesh->morph_target_count>0) {
+ bool use_VBO = true; //glGenBuffersARB!=NULL; // TODO detect if it's in there
+ if ((!use_hw_skeleton_xform && format & VS::ARRAY_FORMAT_WEIGHTS) || mesh->morph_target_count > 0) {
- use_VBO=false;
+ use_VBO = false;
}
//surface->packed=pack_arrays && use_VBO;
- int total_elem_size=0;
+ int total_elem_size = 0;
- for (int i=0;i<VS::ARRAY_MAX;i++) {
+ for (int i = 0; i < VS::ARRAY_MAX; i++) {
-
- Surface::ArrayData&ad=surface->array[i];
- ad.size=0;
- ad.ofs=0;
- int elem_size=0;
- int elem_count=0;
- bool valid_local=true;
+ Surface::ArrayData &ad = surface->array[i];
+ ad.size = 0;
+ ad.ofs = 0;
+ int elem_size = 0;
+ int elem_count = 0;
+ bool valid_local = true;
GLenum datatype;
- bool normalize=false;
- bool bind=false;
+ bool normalize = false;
+ bool bind = false;
- if (!(format&(1<<i))) // no array
+ if (!(format & (1 << i))) // no array
continue;
-
- switch(i) {
+ switch (i) {
case VS::ARRAY_VERTEX: {
if (use_VBO && use_half_float) {
- elem_size=3*sizeof(int16_t); // vertex
- datatype=_GL_HALF_FLOAT_OES;
+ elem_size = 3 * sizeof(int16_t); // vertex
+ datatype = _GL_HALF_FLOAT_OES;
} else {
- elem_size=3*sizeof(GLfloat); // vertex
- datatype=GL_FLOAT;
+ elem_size = 3 * sizeof(GLfloat); // vertex
+ datatype = GL_FLOAT;
}
- bind=true;
- elem_count=3;
+ bind = true;
+ elem_count = 3;
} break;
case VS::ARRAY_NORMAL: {
if (use_VBO) {
- elem_size=4*sizeof(int8_t); // vertex
- datatype=GL_BYTE;
- normalize=true;
+ elem_size = 4 * sizeof(int8_t); // vertex
+ datatype = GL_BYTE;
+ normalize = true;
} else {
- elem_size=3*sizeof(GLfloat); // vertex
- datatype=GL_FLOAT;
+ elem_size = 3 * sizeof(GLfloat); // vertex
+ datatype = GL_FLOAT;
}
- bind=true;
- elem_count=3;
+ bind = true;
+ elem_count = 3;
} break;
case VS::ARRAY_TANGENT: {
if (use_VBO) {
- elem_size=4*sizeof(int8_t); // vertex
- datatype=GL_BYTE;
- normalize=true;
+ elem_size = 4 * sizeof(int8_t); // vertex
+ datatype = GL_BYTE;
+ normalize = true;
} else {
- elem_size=4*sizeof(GLfloat); // vertex
- datatype=GL_FLOAT;
+ elem_size = 4 * sizeof(GLfloat); // vertex
+ datatype = GL_FLOAT;
}
- bind=true;
- elem_count=4;
+ bind = true;
+ elem_count = 4;
} break;
case VS::ARRAY_COLOR: {
- elem_size=4*sizeof(uint8_t); /* RGBA */
- datatype=GL_UNSIGNED_BYTE;
- elem_count=4;
- bind=true;
- normalize=true;
+ elem_size = 4 * sizeof(uint8_t); /* RGBA */
+ datatype = GL_UNSIGNED_BYTE;
+ elem_count = 4;
+ bind = true;
+ normalize = true;
} break;
case VS::ARRAY_TEX_UV:
case VS::ARRAY_TEX_UV2: {
if (use_VBO && use_half_float) {
- elem_size=2*sizeof(int16_t); // vertex
- datatype=_GL_HALF_FLOAT_OES;
+ elem_size = 2 * sizeof(int16_t); // vertex
+ datatype = _GL_HALF_FLOAT_OES;
} else {
- elem_size=2*sizeof(GLfloat); // vertex
- datatype=GL_FLOAT;
+ elem_size = 2 * sizeof(GLfloat); // vertex
+ datatype = GL_FLOAT;
}
- bind=true;
- elem_count=2;
+ bind = true;
+ elem_count = 2;
} break;
case VS::ARRAY_WEIGHTS: {
if (use_VBO) {
- elem_size=VS::ARRAY_WEIGHTS_SIZE*sizeof(GLushort);
- valid_local=false;
- bind=true;
- normalize=true;
- datatype=GL_UNSIGNED_SHORT;
- elem_count=4;
+ elem_size = VS::ARRAY_WEIGHTS_SIZE * sizeof(GLushort);
+ valid_local = false;
+ bind = true;
+ normalize = true;
+ datatype = GL_UNSIGNED_SHORT;
+ elem_count = 4;
} else {
- elem_size=VS::ARRAY_WEIGHTS_SIZE*sizeof(GLfloat);
- valid_local=false;
- bind=false;
- datatype=GL_FLOAT;
- elem_count=4;
+ elem_size = VS::ARRAY_WEIGHTS_SIZE * sizeof(GLfloat);
+ valid_local = false;
+ bind = false;
+ datatype = GL_FLOAT;
+ elem_count = 4;
}
} break;
case VS::ARRAY_BONES: {
if (use_VBO) {
- elem_size=VS::ARRAY_WEIGHTS_SIZE*sizeof(GLubyte);
- valid_local=false;
- bind=true;
- datatype=GL_UNSIGNED_BYTE;
- elem_count=4;
+ elem_size = VS::ARRAY_WEIGHTS_SIZE * sizeof(GLubyte);
+ valid_local = false;
+ bind = true;
+ datatype = GL_UNSIGNED_BYTE;
+ elem_count = 4;
} else {
- elem_size=VS::ARRAY_WEIGHTS_SIZE*sizeof(GLushort);
- valid_local=false;
- bind=false;
- datatype=GL_UNSIGNED_SHORT;
- elem_count=4;
-
+ elem_size = VS::ARRAY_WEIGHTS_SIZE * sizeof(GLushort);
+ valid_local = false;
+ bind = false;
+ datatype = GL_UNSIGNED_SHORT;
+ elem_count = 4;
}
-
} break;
case VS::ARRAY_INDEX: {
- if (index_array_len<=0) {
+ if (index_array_len <= 0) {
ERR_PRINT("index_array_len==NO_INDEX_ARRAY");
break;
}
/* determine wether using 16 or 32 bits indices */
- if (array_len>(1<<16)) {
+ if (array_len > (1 << 16)) {
- elem_size=4;
- datatype=GL_UNSIGNED_INT;
+ elem_size = 4;
+ datatype = GL_UNSIGNED_INT;
} else {
- elem_size=2;
- datatype=GL_UNSIGNED_SHORT;
+ elem_size = 2;
+ datatype = GL_UNSIGNED_SHORT;
}
-/*
+ /*
if (use_VBO) {
glGenBuffers(1,&surface->index_id);
@@ -2062,47 +1947,44 @@ void RasterizerGLES2::mesh_add_surface(RID p_mesh,VS::PrimitiveType p_primitive,
surface->index_array_local = (uint8_t*)memalloc(index_array_len*elem_size);
};
*/
- surface->index_array_len=index_array_len; // only way it can exist
- ad.ofs=0;
- ad.size=elem_size;
-
+ surface->index_array_len = index_array_len; // only way it can exist
+ ad.ofs = 0;
+ ad.size = elem_size;
continue;
} break;
default: {
- ERR_FAIL( );
+ ERR_FAIL();
}
}
- ad.ofs=total_elem_size;
- ad.size=elem_size;
- ad.datatype=datatype;
- ad.normalize=normalize;
- ad.bind=bind;
- ad.count=elem_count;
- total_elem_size+=elem_size;
+ ad.ofs = total_elem_size;
+ ad.size = elem_size;
+ ad.datatype = datatype;
+ ad.normalize = normalize;
+ ad.bind = bind;
+ ad.count = elem_count;
+ total_elem_size += elem_size;
if (valid_local) {
- surface->local_stride+=elem_size;
- surface->morph_format|=(1<<i);
+ surface->local_stride += elem_size;
+ surface->morph_format |= (1 << i);
}
-
-
}
- surface->stride=total_elem_size;
- surface->array_len=array_len;
- surface->format=format;
- surface->primitive=p_primitive;
- surface->morph_target_count=mesh->morph_target_count;
- surface->configured_format=0;
- surface->mesh=mesh;
+ surface->stride = total_elem_size;
+ surface->array_len = array_len;
+ surface->format = format;
+ surface->primitive = p_primitive;
+ surface->morph_target_count = mesh->morph_target_count;
+ surface->configured_format = 0;
+ surface->mesh = mesh;
if (keep_copies) {
- surface->data=p_arrays;
- surface->morph_data=p_blend_shapes;
+ surface->data = p_arrays;
+ surface->morph_data = p_blend_shapes;
}
- uint8_t *array_ptr=NULL;
- uint8_t *index_array_ptr=NULL;
+ uint8_t *array_ptr = NULL;
+ uint8_t *index_array_ptr = NULL;
PoolVector<uint8_t> array_pre_vbo;
PoolVector<uint8_t>::Write vaw;
PoolVector<uint8_t> index_array_pre_vbo;
@@ -2111,489 +1993,443 @@ void RasterizerGLES2::mesh_add_surface(RID p_mesh,VS::PrimitiveType p_primitive,
/* create pointers */
if (use_VBO) {
- array_pre_vbo.resize(surface->array_len*surface->stride);
+ array_pre_vbo.resize(surface->array_len * surface->stride);
vaw = array_pre_vbo.write();
- array_ptr=vaw.ptr();
+ array_ptr = vaw.ptr();
if (surface->index_array_len) {
- index_array_pre_vbo.resize(surface->index_array_len*surface->array[VS::ARRAY_INDEX].size);
+ index_array_pre_vbo.resize(surface->index_array_len * surface->array[VS::ARRAY_INDEX].size);
iaw = index_array_pre_vbo.write();
- index_array_ptr=iaw.ptr();
+ index_array_ptr = iaw.ptr();
}
- _surface_set_arrays(surface,array_ptr,index_array_ptr,p_arrays,true);
+ _surface_set_arrays(surface, array_ptr, index_array_ptr, p_arrays, true);
} else {
- surface->array_local = (uint8_t*)memalloc(surface->array_len*surface->stride);
- array_ptr=(uint8_t*)surface->array_local;
+ surface->array_local = (uint8_t *)memalloc(surface->array_len * surface->stride);
+ array_ptr = (uint8_t *)surface->array_local;
if (surface->index_array_len) {
- surface->index_array_local = (uint8_t*)memalloc(index_array_len*surface->array[VS::ARRAY_INDEX].size);
- index_array_ptr=(uint8_t*)surface->index_array_local;
+ surface->index_array_local = (uint8_t *)memalloc(index_array_len * surface->array[VS::ARRAY_INDEX].size);
+ index_array_ptr = (uint8_t *)surface->index_array_local;
}
- _surface_set_arrays(surface,array_ptr,index_array_ptr,p_arrays,true);
+ _surface_set_arrays(surface, array_ptr, index_array_ptr, p_arrays, true);
if (mesh->morph_target_count) {
- surface->morph_targets_local = memnew_arr(Surface::MorphTarget,mesh->morph_target_count);
- for(int i=0;i<mesh->morph_target_count;i++) {
+ surface->morph_targets_local = memnew_arr(Surface::MorphTarget, mesh->morph_target_count);
+ for (int i = 0; i < mesh->morph_target_count; i++) {
- surface->morph_targets_local[i].array=memnew_arr(uint8_t,surface->local_stride*surface->array_len);
- surface->morph_targets_local[i].configured_format=surface->morph_format;
- _surface_set_arrays(surface,surface->morph_targets_local[i].array,NULL,p_blend_shapes[i],false);
+ surface->morph_targets_local[i].array = memnew_arr(uint8_t, surface->local_stride * surface->array_len);
+ surface->morph_targets_local[i].configured_format = surface->morph_format;
+ _surface_set_arrays(surface, surface->morph_targets_local[i].array, NULL, p_blend_shapes[i], false);
}
}
}
-
-
-
-
/* create buffers!! */
if (use_VBO) {
- glGenBuffers(1,&surface->vertex_id);
- ERR_FAIL_COND(surface->vertex_id==0);
- glBindBuffer(GL_ARRAY_BUFFER,surface->vertex_id);
- glBufferData(GL_ARRAY_BUFFER,surface->array_len*surface->stride,array_ptr,GL_STATIC_DRAW);
- glBindBuffer(GL_ARRAY_BUFFER,0); //unbind
+ glGenBuffers(1, &surface->vertex_id);
+ ERR_FAIL_COND(surface->vertex_id == 0);
+ glBindBuffer(GL_ARRAY_BUFFER, surface->vertex_id);
+ glBufferData(GL_ARRAY_BUFFER, surface->array_len * surface->stride, array_ptr, GL_STATIC_DRAW);
+ glBindBuffer(GL_ARRAY_BUFFER, 0); //unbind
if (surface->index_array_len) {
- glGenBuffers(1,&surface->index_id);
- ERR_FAIL_COND(surface->index_id==0);
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,surface->index_id);
- glBufferData(GL_ELEMENT_ARRAY_BUFFER,index_array_len*surface->array[VS::ARRAY_INDEX].size,index_array_ptr,GL_STATIC_DRAW);
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0); //unbind
-
+ glGenBuffers(1, &surface->index_id);
+ ERR_FAIL_COND(surface->index_id == 0);
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, surface->index_id);
+ glBufferData(GL_ELEMENT_ARRAY_BUFFER, index_array_len * surface->array[VS::ARRAY_INDEX].size, index_array_ptr, GL_STATIC_DRAW);
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); //unbind
}
}
mesh->surfaces.push_back(surface);
-
}
-Error RasterizerGLES2::_surface_set_arrays(Surface *p_surface, uint8_t *p_mem,uint8_t *p_index_mem,const Array& p_arrays,bool p_main) {
+Error RasterizerGLES2::_surface_set_arrays(Surface *p_surface, uint8_t *p_mem, uint8_t *p_index_mem, const Array &p_arrays, bool p_main) {
uint32_t stride = p_main ? p_surface->stride : p_surface->local_stride;
- for(int ai=0;ai<VS::ARRAY_MAX;ai++) {
- if (ai>=p_arrays.size())
+ for (int ai = 0; ai < VS::ARRAY_MAX; ai++) {
+ if (ai >= p_arrays.size())
break;
- if (p_arrays[ai].get_type()==Variant::NIL)
+ if (p_arrays[ai].get_type() == Variant::NIL)
continue;
- Surface::ArrayData &a=p_surface->array[ai];
-
- switch(ai) {
+ Surface::ArrayData &a = p_surface->array[ai];
+ switch (ai) {
case VS::ARRAY_VERTEX: {
- ERR_FAIL_COND_V( p_arrays[ai].get_type() != Variant::VECTOR3_ARRAY, ERR_INVALID_PARAMETER );
+ ERR_FAIL_COND_V(p_arrays[ai].get_type() != Variant::VECTOR3_ARRAY, ERR_INVALID_PARAMETER);
PoolVector<Vector3> array = p_arrays[ai];
- ERR_FAIL_COND_V( array.size() != p_surface->array_len, ERR_INVALID_PARAMETER );
-
+ ERR_FAIL_COND_V(array.size() != p_surface->array_len, ERR_INVALID_PARAMETER);
PoolVector<Vector3>::Read read = array.read();
- const Vector3* src=read.ptr();
+ const Vector3 *src = read.ptr();
// setting vertices means regenerating the AABB
AABB aabb;
- float scale=1;
-
-
- if (p_surface->array[VS::ARRAY_VERTEX].datatype==_GL_HALF_FLOAT_OES) {
+ float scale = 1;
- for (int i=0;i<p_surface->array_len;i++) {
+ if (p_surface->array[VS::ARRAY_VERTEX].datatype == _GL_HALF_FLOAT_OES) {
+ for (int i = 0; i < p_surface->array_len; i++) {
- uint16_t vector[3]={ make_half_float(src[i].x), make_half_float(src[i].y), make_half_float(src[i].z) };
+ uint16_t vector[3] = { make_half_float(src[i].x), make_half_float(src[i].y), make_half_float(src[i].z) };
- copymem(&p_mem[a.ofs+i*stride], vector, a.size);
+ copymem(&p_mem[a.ofs + i * stride], vector, a.size);
- if (i==0) {
+ if (i == 0) {
- aabb=AABB(src[i],Vector3());
+ aabb = AABB(src[i], Vector3());
} else {
- aabb.expand_to( src[i] );
+ aabb.expand_to(src[i]);
}
}
-
} else {
- for (int i=0;i<p_surface->array_len;i++) {
-
+ for (int i = 0; i < p_surface->array_len; i++) {
- GLfloat vector[3]={ src[i].x, src[i].y, src[i].z };
+ GLfloat vector[3] = { src[i].x, src[i].y, src[i].z };
- copymem(&p_mem[a.ofs+i*stride], vector, a.size);
+ copymem(&p_mem[a.ofs + i * stride], vector, a.size);
- if (i==0) {
+ if (i == 0) {
- aabb=AABB(src[i],Vector3());
+ aabb = AABB(src[i], Vector3());
} else {
- aabb.expand_to( src[i] );
+ aabb.expand_to(src[i]);
}
}
}
if (p_main) {
- p_surface->aabb=aabb;
- p_surface->vertex_scale=scale;
+ p_surface->aabb = aabb;
+ p_surface->vertex_scale = scale;
}
-
} break;
case VS::ARRAY_NORMAL: {
- ERR_FAIL_COND_V( p_arrays[ai].get_type() != Variant::VECTOR3_ARRAY, ERR_INVALID_PARAMETER );
+ ERR_FAIL_COND_V(p_arrays[ai].get_type() != Variant::VECTOR3_ARRAY, ERR_INVALID_PARAMETER);
PoolVector<Vector3> array = p_arrays[ai];
- ERR_FAIL_COND_V( array.size() != p_surface->array_len, ERR_INVALID_PARAMETER );
-
+ ERR_FAIL_COND_V(array.size() != p_surface->array_len, ERR_INVALID_PARAMETER);
PoolVector<Vector3>::Read read = array.read();
- const Vector3* src=read.ptr();
+ const Vector3 *src = read.ptr();
// setting vertices means regenerating the AABB
- if (p_surface->array[VS::ARRAY_NORMAL].datatype==GL_BYTE) {
+ if (p_surface->array[VS::ARRAY_NORMAL].datatype == GL_BYTE) {
- for (int i=0;i<p_surface->array_len;i++) {
+ for (int i = 0; i < p_surface->array_len; i++) {
- GLbyte vector[4]={
- CLAMP(src[i].x*127,-128,127),
- CLAMP(src[i].y*127,-128,127),
- CLAMP(src[i].z*127,-128,127),
+ GLbyte vector[4] = {
+ CLAMP(src[i].x * 127, -128, 127),
+ CLAMP(src[i].y * 127, -128, 127),
+ CLAMP(src[i].z * 127, -128, 127),
0,
};
- copymem(&p_mem[a.ofs+i*stride], vector, a.size);
-
+ copymem(&p_mem[a.ofs + i * stride], vector, a.size);
}
} else {
- for (int i=0;i<p_surface->array_len;i++) {
-
-
- GLfloat vector[3]={ src[i].x, src[i].y, src[i].z };
- copymem(&p_mem[a.ofs+i*stride], vector, a.size);
+ for (int i = 0; i < p_surface->array_len; i++) {
+ GLfloat vector[3] = { src[i].x, src[i].y, src[i].z };
+ copymem(&p_mem[a.ofs + i * stride], vector, a.size);
}
}
-
} break;
case VS::ARRAY_TANGENT: {
- ERR_FAIL_COND_V( p_arrays[ai].get_type() != Variant::REAL_ARRAY, ERR_INVALID_PARAMETER );
+ ERR_FAIL_COND_V(p_arrays[ai].get_type() != Variant::REAL_ARRAY, ERR_INVALID_PARAMETER);
PoolVector<real_t> array = p_arrays[ai];
- ERR_FAIL_COND_V( array.size() != p_surface->array_len*4, ERR_INVALID_PARAMETER );
-
+ ERR_FAIL_COND_V(array.size() != p_surface->array_len * 4, ERR_INVALID_PARAMETER);
PoolVector<real_t>::Read read = array.read();
- const real_t* src = read.ptr();
+ const real_t *src = read.ptr();
- if (p_surface->array[VS::ARRAY_TANGENT].datatype==GL_BYTE) {
+ if (p_surface->array[VS::ARRAY_TANGENT].datatype == GL_BYTE) {
- for (int i=0;i<p_surface->array_len;i++) {
+ for (int i = 0; i < p_surface->array_len; i++) {
- GLbyte xyzw[4]={
- CLAMP(src[i*4+0]*127,-128,127),
- CLAMP(src[i*4+1]*127,-128,127),
- CLAMP(src[i*4+2]*127,-128,127),
- CLAMP(src[i*4+3]*127,-128,127)
+ GLbyte xyzw[4] = {
+ CLAMP(src[i * 4 + 0] * 127, -128, 127),
+ CLAMP(src[i * 4 + 1] * 127, -128, 127),
+ CLAMP(src[i * 4 + 2] * 127, -128, 127),
+ CLAMP(src[i * 4 + 3] * 127, -128, 127)
};
- copymem(&p_mem[a.ofs+i*stride], xyzw, a.size);
-
+ copymem(&p_mem[a.ofs + i * stride], xyzw, a.size);
}
-
} else {
- for (int i=0;i<p_surface->array_len;i++) {
+ for (int i = 0; i < p_surface->array_len; i++) {
- GLfloat xyzw[4]={
- src[i*4+0],
- src[i*4+1],
- src[i*4+2],
- src[i*4+3]
+ GLfloat xyzw[4] = {
+ src[i * 4 + 0],
+ src[i * 4 + 1],
+ src[i * 4 + 2],
+ src[i * 4 + 3]
};
- copymem(&p_mem[a.ofs+i*stride], xyzw, a.size);
-
+ copymem(&p_mem[a.ofs + i * stride], xyzw, a.size);
}
}
} break;
case VS::ARRAY_COLOR: {
- ERR_FAIL_COND_V( p_arrays[ai].get_type() != Variant::COLOR_ARRAY, ERR_INVALID_PARAMETER );
-
+ ERR_FAIL_COND_V(p_arrays[ai].get_type() != Variant::COLOR_ARRAY, ERR_INVALID_PARAMETER);
PoolVector<Color> array = p_arrays[ai];
- ERR_FAIL_COND_V( array.size() != p_surface->array_len, ERR_INVALID_PARAMETER );
-
+ ERR_FAIL_COND_V(array.size() != p_surface->array_len, ERR_INVALID_PARAMETER);
PoolVector<Color>::Read read = array.read();
- const Color* src = read.ptr();
- bool alpha=false;
+ const Color *src = read.ptr();
+ bool alpha = false;
- for (int i=0;i<p_surface->array_len;i++) {
+ for (int i = 0; i < p_surface->array_len; i++) {
- if (src[i].a<0.98) // tolerate alpha a bit, for crappy exporters
- alpha=true;
+ if (src[i].a < 0.98) // tolerate alpha a bit, for crappy exporters
+ alpha = true;
uint8_t colors[4];
- for(int j=0;j<4;j++) {
+ for (int j = 0; j < 4; j++) {
- colors[j]=CLAMP( int((src[i][j])*255.0), 0,255 );
+ colors[j] = CLAMP(int((src[i][j]) * 255.0), 0, 255);
}
- copymem(&p_mem[a.ofs+i*stride], colors, a.size);
-
+ copymem(&p_mem[a.ofs + i * stride], colors, a.size);
}
if (p_main)
- p_surface->has_alpha=alpha;
+ p_surface->has_alpha = alpha;
} break;
case VS::ARRAY_TEX_UV:
case VS::ARRAY_TEX_UV2: {
- ERR_FAIL_COND_V( p_arrays[ai].get_type() != Variant::VECTOR3_ARRAY && p_arrays[ai].get_type() != Variant::VECTOR2_ARRAY, ERR_INVALID_PARAMETER );
+ ERR_FAIL_COND_V(p_arrays[ai].get_type() != Variant::VECTOR3_ARRAY && p_arrays[ai].get_type() != Variant::VECTOR2_ARRAY, ERR_INVALID_PARAMETER);
PoolVector<Vector2> array = p_arrays[ai];
- ERR_FAIL_COND_V( array.size() != p_surface->array_len , ERR_INVALID_PARAMETER);
+ ERR_FAIL_COND_V(array.size() != p_surface->array_len, ERR_INVALID_PARAMETER);
PoolVector<Vector2>::Read read = array.read();
- const Vector2 * src=read.ptr();
- float scale=1.0;
-
+ const Vector2 *src = read.ptr();
+ float scale = 1.0;
- if (p_surface->array[ai].datatype==_GL_HALF_FLOAT_OES) {
+ if (p_surface->array[ai].datatype == _GL_HALF_FLOAT_OES) {
- for (int i=0;i<p_surface->array_len;i++) {
+ for (int i = 0; i < p_surface->array_len; i++) {
- uint16_t uv[2]={ make_half_float(src[i].x) , make_half_float(src[i].y) };
- copymem(&p_mem[a.ofs+i*stride], uv, a.size);
+ uint16_t uv[2] = { make_half_float(src[i].x), make_half_float(src[i].y) };
+ copymem(&p_mem[a.ofs + i * stride], uv, a.size);
}
} else {
- for (int i=0;i<p_surface->array_len;i++) {
+ for (int i = 0; i < p_surface->array_len; i++) {
- GLfloat uv[2]={ src[i].x , src[i].y };
-
- copymem(&p_mem[a.ofs+i*stride], uv, a.size);
+ GLfloat uv[2] = { src[i].x, src[i].y };
+ copymem(&p_mem[a.ofs + i * stride], uv, a.size);
}
}
if (p_main) {
- if (ai==VS::ARRAY_TEX_UV) {
+ if (ai == VS::ARRAY_TEX_UV) {
- p_surface->uv_scale=scale;
+ p_surface->uv_scale = scale;
}
- if (ai==VS::ARRAY_TEX_UV2) {
+ if (ai == VS::ARRAY_TEX_UV2) {
- p_surface->uv2_scale=scale;
+ p_surface->uv2_scale = scale;
}
}
} break;
case VS::ARRAY_WEIGHTS: {
-
- ERR_FAIL_COND_V( p_arrays[ai].get_type() != Variant::REAL_ARRAY, ERR_INVALID_PARAMETER );
+ ERR_FAIL_COND_V(p_arrays[ai].get_type() != Variant::REAL_ARRAY, ERR_INVALID_PARAMETER);
PoolVector<real_t> array = p_arrays[ai];
- ERR_FAIL_COND_V( array.size() != p_surface->array_len*VS::ARRAY_WEIGHTS_SIZE, ERR_INVALID_PARAMETER );
-
+ ERR_FAIL_COND_V(array.size() != p_surface->array_len * VS::ARRAY_WEIGHTS_SIZE, ERR_INVALID_PARAMETER);
PoolVector<real_t>::Read read = array.read();
- const real_t * src = read.ptr();
+ const real_t *src = read.ptr();
- if (p_surface->array[VS::ARRAY_WEIGHTS].datatype==GL_UNSIGNED_SHORT) {
+ if (p_surface->array[VS::ARRAY_WEIGHTS].datatype == GL_UNSIGNED_SHORT) {
- for (int i=0;i<p_surface->array_len;i++) {
+ for (int i = 0; i < p_surface->array_len; i++) {
GLushort data[VS::ARRAY_WEIGHTS_SIZE];
- for (int j=0;j<VS::ARRAY_WEIGHTS_SIZE;j++) {
- data[j]=CLAMP(src[i*VS::ARRAY_WEIGHTS_SIZE+j]*65535,0,65535);
+ for (int j = 0; j < VS::ARRAY_WEIGHTS_SIZE; j++) {
+ data[j] = CLAMP(src[i * VS::ARRAY_WEIGHTS_SIZE + j] * 65535, 0, 65535);
}
- copymem(&p_mem[a.ofs+i*stride], data, a.size);
+ copymem(&p_mem[a.ofs + i * stride], data, a.size);
}
} else {
- for (int i=0;i<p_surface->array_len;i++) {
+ for (int i = 0; i < p_surface->array_len; i++) {
GLfloat data[VS::ARRAY_WEIGHTS_SIZE];
- for (int j=0;j<VS::ARRAY_WEIGHTS_SIZE;j++) {
- data[j]=src[i*VS::ARRAY_WEIGHTS_SIZE+j];
+ for (int j = 0; j < VS::ARRAY_WEIGHTS_SIZE; j++) {
+ data[j] = src[i * VS::ARRAY_WEIGHTS_SIZE + j];
}
- copymem(&p_mem[a.ofs+i*stride], data, a.size);
-
-
+ copymem(&p_mem[a.ofs + i * stride], data, a.size);
}
-
-
}
} break;
case VS::ARRAY_BONES: {
-
- ERR_FAIL_COND_V( p_arrays[ai].get_type() != Variant::REAL_ARRAY, ERR_INVALID_PARAMETER );
+ ERR_FAIL_COND_V(p_arrays[ai].get_type() != Variant::REAL_ARRAY, ERR_INVALID_PARAMETER);
PoolVector<int> array = p_arrays[ai];
- ERR_FAIL_COND_V( array.size() != p_surface->array_len*VS::ARRAY_WEIGHTS_SIZE, ERR_INVALID_PARAMETER );
-
+ ERR_FAIL_COND_V(array.size() != p_surface->array_len * VS::ARRAY_WEIGHTS_SIZE, ERR_INVALID_PARAMETER);
PoolVector<int>::Read read = array.read();
- const int * src = read.ptr();
+ const int *src = read.ptr();
- p_surface->max_bone=0;
+ p_surface->max_bone = 0;
+ if (p_surface->array[VS::ARRAY_BONES].datatype == GL_UNSIGNED_BYTE) {
- if (p_surface->array[VS::ARRAY_BONES].datatype==GL_UNSIGNED_BYTE) {
-
- for (int i=0;i<p_surface->array_len;i++) {
+ for (int i = 0; i < p_surface->array_len; i++) {
GLubyte data[VS::ARRAY_WEIGHTS_SIZE];
- for (int j=0;j<VS::ARRAY_WEIGHTS_SIZE;j++) {
- data[j]=CLAMP(src[i*VS::ARRAY_WEIGHTS_SIZE+j],0,255);
- p_surface->max_bone=MAX(data[j],p_surface->max_bone);
-
+ for (int j = 0; j < VS::ARRAY_WEIGHTS_SIZE; j++) {
+ data[j] = CLAMP(src[i * VS::ARRAY_WEIGHTS_SIZE + j], 0, 255);
+ p_surface->max_bone = MAX(data[j], p_surface->max_bone);
}
- copymem(&p_mem[a.ofs+i*stride], data, a.size);
-
-
+ copymem(&p_mem[a.ofs + i * stride], data, a.size);
}
} else {
- for (int i=0;i<p_surface->array_len;i++) {
+ for (int i = 0; i < p_surface->array_len; i++) {
GLushort data[VS::ARRAY_WEIGHTS_SIZE];
- for (int j=0;j<VS::ARRAY_WEIGHTS_SIZE;j++) {
- data[j]=src[i*VS::ARRAY_WEIGHTS_SIZE+j];
- p_surface->max_bone=MAX(data[j],p_surface->max_bone);
-
+ for (int j = 0; j < VS::ARRAY_WEIGHTS_SIZE; j++) {
+ data[j] = src[i * VS::ARRAY_WEIGHTS_SIZE + j];
+ p_surface->max_bone = MAX(data[j], p_surface->max_bone);
}
- copymem(&p_mem[a.ofs+i*stride], data, a.size);
-
-
+ copymem(&p_mem[a.ofs + i * stride], data, a.size);
}
}
-
} break;
case VS::ARRAY_INDEX: {
- ERR_FAIL_COND_V( p_surface->index_array_len<=0, ERR_INVALID_DATA );
- ERR_FAIL_COND_V( p_arrays[ai].get_type() != Variant::INT_ARRAY, ERR_INVALID_PARAMETER );
+ ERR_FAIL_COND_V(p_surface->index_array_len <= 0, ERR_INVALID_DATA);
+ ERR_FAIL_COND_V(p_arrays[ai].get_type() != Variant::INT_ARRAY, ERR_INVALID_PARAMETER);
PoolVector<int> indices = p_arrays[ai];
- ERR_FAIL_COND_V( indices.size() == 0, ERR_INVALID_PARAMETER );
- ERR_FAIL_COND_V( indices.size() != p_surface->index_array_len, ERR_INVALID_PARAMETER );
+ ERR_FAIL_COND_V(indices.size() == 0, ERR_INVALID_PARAMETER);
+ ERR_FAIL_COND_V(indices.size() != p_surface->index_array_len, ERR_INVALID_PARAMETER);
/* determine wether using 16 or 32 bits indices */
PoolVector<int>::Read read = indices.read();
- const int *src=read.ptr();
-
- for (int i=0;i<p_surface->index_array_len;i++) {
+ const int *src = read.ptr();
+ for (int i = 0; i < p_surface->index_array_len; i++) {
- if (a.size==2) {
- uint16_t v=src[i];
+ if (a.size == 2) {
+ uint16_t v = src[i];
- copymem(&p_index_mem[i*a.size], &v, a.size);
+ copymem(&p_index_mem[i * a.size], &v, a.size);
} else {
- uint32_t v=src[i];
+ uint32_t v = src[i];
- copymem(&p_index_mem[i*a.size], &v, a.size);
+ copymem(&p_index_mem[i * a.size], &v, a.size);
}
}
-
} break;
-
- default: { ERR_FAIL_V(ERR_INVALID_PARAMETER);}
+ default: { ERR_FAIL_V(ERR_INVALID_PARAMETER); }
}
- p_surface->configured_format|=(1<<ai);
+ p_surface->configured_format |= (1 << ai);
}
- if (p_surface->format&VS::ARRAY_FORMAT_BONES) {
+ if (p_surface->format & VS::ARRAY_FORMAT_BONES) {
//create AABBs for each detected bone
- int total_bones = p_surface->max_bone+1;
+ int total_bones = p_surface->max_bone + 1;
if (p_main) {
p_surface->skeleton_bone_aabb.resize(total_bones);
p_surface->skeleton_bone_used.resize(total_bones);
- for(int i=0;i<total_bones;i++)
- p_surface->skeleton_bone_used[i]=false;
+ for (int i = 0; i < total_bones; i++)
+ p_surface->skeleton_bone_used[i] = false;
}
PoolVector<Vector3> vertices = p_arrays[VS::ARRAY_VERTEX];
PoolVector<int> bones = p_arrays[VS::ARRAY_BONES];
PoolVector<float> weights = p_arrays[VS::ARRAY_WEIGHTS];
- bool any_valid=false;
+ bool any_valid = false;
- if (vertices.size() && bones.size()==vertices.size()*4 && weights.size()==bones.size()) {
+ if (vertices.size() && bones.size() == vertices.size() * 4 && weights.size() == bones.size()) {
//print_line("MAKING SKELETHONG");
int vs = vertices.size();
- PoolVector<Vector3>::Read rv =vertices.read();
- PoolVector<int>::Read rb=bones.read();
- PoolVector<float>::Read rw=weights.read();
+ PoolVector<Vector3>::Read rv = vertices.read();
+ PoolVector<int>::Read rb = bones.read();
+ PoolVector<float>::Read rw = weights.read();
Vector<bool> first;
first.resize(total_bones);
- for(int i=0;i<total_bones;i++) {
- first[i]=p_main;
+ for (int i = 0; i < total_bones; i++) {
+ first[i] = p_main;
}
AABB *bptr = p_surface->skeleton_bone_aabb.ptr();
- bool *fptr=first.ptr();
- bool *usedptr=p_surface->skeleton_bone_used.ptr();
+ bool *fptr = first.ptr();
+ bool *usedptr = p_surface->skeleton_bone_used.ptr();
- for(int i=0;i<vs;i++) {
+ for (int i = 0; i < vs; i++) {
Vector3 v = rv[i];
- for(int j=0;j<4;j++) {
+ for (int j = 0; j < 4; j++) {
- int idx = rb[i*4+j];
- float w = rw[i*4+j];
- if (w==0)
- continue;//break;
- ERR_FAIL_INDEX_V(idx,total_bones,ERR_INVALID_DATA);
+ int idx = rb[i * 4 + j];
+ float w = rw[i * 4 + j];
+ if (w == 0)
+ continue; //break;
+ ERR_FAIL_INDEX_V(idx, total_bones, ERR_INVALID_DATA);
if (fptr[idx]) {
- bptr[idx].pos=v;
- fptr[idx]=false;
- any_valid=true;
+ bptr[idx].pos = v;
+ fptr[idx] = false;
+ any_valid = true;
} else {
bptr[idx].expand_to(v);
}
- usedptr[idx]=true;
+ usedptr[idx] = true;
}
}
}
@@ -2608,218 +2444,202 @@ Error RasterizerGLES2::_surface_set_arrays(Surface *p_surface, uint8_t *p_mem,ui
return OK;
}
-
-
-void RasterizerGLES2::mesh_add_custom_surface(RID p_mesh,const Variant& p_dat) {
+void RasterizerGLES2::mesh_add_custom_surface(RID p_mesh, const Variant &p_dat) {
ERR_EXPLAIN("OpenGL Rasterizer does not support custom surfaces. Running on wrong platform?");
ERR_FAIL();
}
-Array RasterizerGLES2::mesh_get_surface_arrays(RID p_mesh,int p_surface) const {
+Array RasterizerGLES2::mesh_get_surface_arrays(RID p_mesh, int p_surface) const {
- Mesh *mesh = mesh_owner.get( p_mesh );
- ERR_FAIL_COND_V(!mesh,Array());
- ERR_FAIL_INDEX_V(p_surface, mesh->surfaces.size(), Array() );
+ Mesh *mesh = mesh_owner.get(p_mesh);
+ ERR_FAIL_COND_V(!mesh, Array());
+ ERR_FAIL_INDEX_V(p_surface, mesh->surfaces.size(), Array());
Surface *surface = mesh->surfaces[p_surface];
- ERR_FAIL_COND_V( !surface, Array() );
+ ERR_FAIL_COND_V(!surface, Array());
return surface->data;
-
-
}
-Array RasterizerGLES2::mesh_get_surface_morph_arrays(RID p_mesh,int p_surface) const{
+Array RasterizerGLES2::mesh_get_surface_morph_arrays(RID p_mesh, int p_surface) const {
- Mesh *mesh = mesh_owner.get( p_mesh );
- ERR_FAIL_COND_V(!mesh,Array());
- ERR_FAIL_INDEX_V(p_surface, mesh->surfaces.size(), Array() );
+ Mesh *mesh = mesh_owner.get(p_mesh);
+ ERR_FAIL_COND_V(!mesh, Array());
+ ERR_FAIL_INDEX_V(p_surface, mesh->surfaces.size(), Array());
Surface *surface = mesh->surfaces[p_surface];
- ERR_FAIL_COND_V( !surface, Array() );
+ ERR_FAIL_COND_V(!surface, Array());
return surface->morph_data;
-
}
+void RasterizerGLES2::mesh_set_morph_target_count(RID p_mesh, int p_amount) {
-void RasterizerGLES2::mesh_set_morph_target_count(RID p_mesh,int p_amount) {
-
- Mesh *mesh = mesh_owner.get( p_mesh );
+ Mesh *mesh = mesh_owner.get(p_mesh);
ERR_FAIL_COND(!mesh);
- ERR_FAIL_COND( mesh->surfaces.size()!=0 );
-
- mesh->morph_target_count=p_amount;
+ ERR_FAIL_COND(mesh->surfaces.size() != 0);
+ mesh->morph_target_count = p_amount;
}
-int RasterizerGLES2::mesh_get_morph_target_count(RID p_mesh) const{
+int RasterizerGLES2::mesh_get_morph_target_count(RID p_mesh) const {
- Mesh *mesh = mesh_owner.get( p_mesh );
- ERR_FAIL_COND_V(!mesh,-1);
+ Mesh *mesh = mesh_owner.get(p_mesh);
+ ERR_FAIL_COND_V(!mesh, -1);
return mesh->morph_target_count;
-
}
-void RasterizerGLES2::mesh_set_morph_target_mode(RID p_mesh,VS::MorphTargetMode p_mode) {
+void RasterizerGLES2::mesh_set_morph_target_mode(RID p_mesh, VS::MorphTargetMode p_mode) {
- ERR_FAIL_INDEX(p_mode,2);
- Mesh *mesh = mesh_owner.get( p_mesh );
+ ERR_FAIL_INDEX(p_mode, 2);
+ Mesh *mesh = mesh_owner.get(p_mesh);
ERR_FAIL_COND(!mesh);
- mesh->morph_target_mode=p_mode;
-
+ mesh->morph_target_mode = p_mode;
}
VS::MorphTargetMode RasterizerGLES2::mesh_get_morph_target_mode(RID p_mesh) const {
- Mesh *mesh = mesh_owner.get( p_mesh );
- ERR_FAIL_COND_V(!mesh,VS::MORPH_MODE_NORMALIZED);
+ Mesh *mesh = mesh_owner.get(p_mesh);
+ ERR_FAIL_COND_V(!mesh, VS::MORPH_MODE_NORMALIZED);
return mesh->morph_target_mode;
-
}
+void RasterizerGLES2::mesh_surface_set_material(RID p_mesh, int p_surface, RID p_material, bool p_owned) {
-
-void RasterizerGLES2::mesh_surface_set_material(RID p_mesh, int p_surface, RID p_material,bool p_owned) {
-
- Mesh *mesh = mesh_owner.get( p_mesh );
+ Mesh *mesh = mesh_owner.get(p_mesh);
ERR_FAIL_COND(!mesh);
- ERR_FAIL_INDEX(p_surface, mesh->surfaces.size() );
+ ERR_FAIL_INDEX(p_surface, mesh->surfaces.size());
Surface *surface = mesh->surfaces[p_surface];
- ERR_FAIL_COND( !surface);
+ ERR_FAIL_COND(!surface);
if (surface->material_owned && surface->material.is_valid())
free(surface->material);
- surface->material_owned=p_owned;
+ surface->material_owned = p_owned;
- surface->material=p_material;
+ surface->material = p_material;
}
RID RasterizerGLES2::mesh_surface_get_material(RID p_mesh, int p_surface) const {
- Mesh *mesh = mesh_owner.get( p_mesh );
- ERR_FAIL_COND_V(!mesh,RID());
- ERR_FAIL_INDEX_V(p_surface, mesh->surfaces.size(), RID() );
+ Mesh *mesh = mesh_owner.get(p_mesh);
+ ERR_FAIL_COND_V(!mesh, RID());
+ ERR_FAIL_INDEX_V(p_surface, mesh->surfaces.size(), RID());
Surface *surface = mesh->surfaces[p_surface];
- ERR_FAIL_COND_V( !surface, RID() );
+ ERR_FAIL_COND_V(!surface, RID());
return surface->material;
}
int RasterizerGLES2::mesh_surface_get_array_len(RID p_mesh, int p_surface) const {
- Mesh *mesh = mesh_owner.get( p_mesh );
- ERR_FAIL_COND_V(!mesh,-1);
- ERR_FAIL_INDEX_V(p_surface, mesh->surfaces.size(), -1 );
+ Mesh *mesh = mesh_owner.get(p_mesh);
+ ERR_FAIL_COND_V(!mesh, -1);
+ ERR_FAIL_INDEX_V(p_surface, mesh->surfaces.size(), -1);
Surface *surface = mesh->surfaces[p_surface];
- ERR_FAIL_COND_V( !surface, -1 );
+ ERR_FAIL_COND_V(!surface, -1);
return surface->array_len;
}
int RasterizerGLES2::mesh_surface_get_array_index_len(RID p_mesh, int p_surface) const {
- Mesh *mesh = mesh_owner.get( p_mesh );
- ERR_FAIL_COND_V(!mesh,-1);
- ERR_FAIL_INDEX_V(p_surface, mesh->surfaces.size(), -1 );
+ Mesh *mesh = mesh_owner.get(p_mesh);
+ ERR_FAIL_COND_V(!mesh, -1);
+ ERR_FAIL_INDEX_V(p_surface, mesh->surfaces.size(), -1);
Surface *surface = mesh->surfaces[p_surface];
- ERR_FAIL_COND_V( !surface, -1 );
+ ERR_FAIL_COND_V(!surface, -1);
return surface->index_array_len;
}
uint32_t RasterizerGLES2::mesh_surface_get_format(RID p_mesh, int p_surface) const {
- Mesh *mesh = mesh_owner.get( p_mesh );
- ERR_FAIL_COND_V(!mesh,0);
- ERR_FAIL_INDEX_V(p_surface, mesh->surfaces.size(), 0 );
+ Mesh *mesh = mesh_owner.get(p_mesh);
+ ERR_FAIL_COND_V(!mesh, 0);
+ ERR_FAIL_INDEX_V(p_surface, mesh->surfaces.size(), 0);
Surface *surface = mesh->surfaces[p_surface];
- ERR_FAIL_COND_V( !surface, 0 );
+ ERR_FAIL_COND_V(!surface, 0);
return surface->format;
}
VS::PrimitiveType RasterizerGLES2::mesh_surface_get_primitive_type(RID p_mesh, int p_surface) const {
- Mesh *mesh = mesh_owner.get( p_mesh );
- ERR_FAIL_COND_V(!mesh,VS::PRIMITIVE_POINTS);
- ERR_FAIL_INDEX_V(p_surface, mesh->surfaces.size(), VS::PRIMITIVE_POINTS );
+ Mesh *mesh = mesh_owner.get(p_mesh);
+ ERR_FAIL_COND_V(!mesh, VS::PRIMITIVE_POINTS);
+ ERR_FAIL_INDEX_V(p_surface, mesh->surfaces.size(), VS::PRIMITIVE_POINTS);
Surface *surface = mesh->surfaces[p_surface];
- ERR_FAIL_COND_V( !surface, VS::PRIMITIVE_POINTS );
+ ERR_FAIL_COND_V(!surface, VS::PRIMITIVE_POINTS);
return surface->primitive;
}
-void RasterizerGLES2::mesh_remove_surface(RID p_mesh,int p_index) {
+void RasterizerGLES2::mesh_remove_surface(RID p_mesh, int p_index) {
- Mesh *mesh = mesh_owner.get( p_mesh );
+ Mesh *mesh = mesh_owner.get(p_mesh);
ERR_FAIL_COND(!mesh);
- ERR_FAIL_INDEX(p_index, mesh->surfaces.size() );
+ ERR_FAIL_INDEX(p_index, mesh->surfaces.size());
Surface *surface = mesh->surfaces[p_index];
- ERR_FAIL_COND( !surface);
+ ERR_FAIL_COND(!surface);
if (surface->vertex_id)
- glDeleteBuffers(1,&surface->vertex_id);
+ glDeleteBuffers(1, &surface->vertex_id);
if (surface->index_id)
- glDeleteBuffers(1,&surface->index_id);
-
+ glDeleteBuffers(1, &surface->index_id);
if (mesh->morph_target_count) {
- for(int i=0;i<mesh->morph_target_count;i++)
+ for (int i = 0; i < mesh->morph_target_count; i++)
memfree(surface->morph_targets_local[i].array);
- memfree( surface->morph_targets_local );
+ memfree(surface->morph_targets_local);
}
- memdelete( mesh->surfaces[p_index] );
+ memdelete(mesh->surfaces[p_index]);
mesh->surfaces.remove(p_index);
-
}
int RasterizerGLES2::mesh_get_surface_count(RID p_mesh) const {
- Mesh *mesh = mesh_owner.get( p_mesh );
- ERR_FAIL_COND_V(!mesh,-1);
+ Mesh *mesh = mesh_owner.get(p_mesh);
+ ERR_FAIL_COND_V(!mesh, -1);
return mesh->surfaces.size();
}
AABB RasterizerGLES2::mesh_get_aabb(RID p_mesh, RID p_skeleton) const {
- Mesh *mesh = mesh_owner.get( p_mesh );
- ERR_FAIL_COND_V(!mesh,AABB());
+ Mesh *mesh = mesh_owner.get(p_mesh);
+ ERR_FAIL_COND_V(!mesh, AABB());
- if (mesh->custom_aabb!=AABB())
+ if (mesh->custom_aabb != AABB())
return mesh->custom_aabb;
- Skeleton *sk=NULL;
+ Skeleton *sk = NULL;
if (p_skeleton.is_valid())
- sk=skeleton_owner.get(p_skeleton);
+ sk = skeleton_owner.get(p_skeleton);
AABB aabb;
- if (sk && sk->bones.size()!=0) {
+ if (sk && sk->bones.size() != 0) {
-
- for (int i=0;i<mesh->surfaces.size();i++) {
+ 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 & VS::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();
const bool *skused = mesh->surfaces[i]->skeleton_bone_used.ptr();
int sbs = sk->bones.size();
- ERR_CONTINUE(bs>sbs);
+ ERR_CONTINUE(bs > sbs);
Skeleton::Bone *skb = sk->bones.ptr();
- bool first=true;
- for(int j=0;j<bs;j++) {
+ bool first = true;
+ for (int j = 0; j < bs; j++) {
if (!skused[j])
continue;
- AABB baabb = skb[ j ].transform_aabb ( skbones[j] );
+ AABB baabb = skb[j].transform_aabb(skbones[j]);
if (first) {
- laabb=baabb;
- first=false;
+ laabb = baabb;
+ first = false;
} else {
laabb.merge_with(baabb);
}
@@ -2827,43 +2647,40 @@ AABB RasterizerGLES2::mesh_get_aabb(RID p_mesh, RID p_skeleton) const {
} else {
- laabb=mesh->surfaces[i]->aabb;
+ laabb = mesh->surfaces[i]->aabb;
}
- if (i==0)
- aabb=laabb;
+ if (i == 0)
+ aabb = laabb;
else
aabb.merge_with(laabb);
}
} else {
- for (int i=0;i<mesh->surfaces.size();i++) {
+ for (int i = 0; i < mesh->surfaces.size(); i++) {
- if (i==0)
- aabb=mesh->surfaces[i]->aabb;
+ if (i == 0)
+ aabb = mesh->surfaces[i]->aabb;
else
aabb.merge_with(mesh->surfaces[i]->aabb);
}
-
}
return aabb;
}
+void RasterizerGLES2::mesh_set_custom_aabb(RID p_mesh, const AABB &p_aabb) {
-void RasterizerGLES2::mesh_set_custom_aabb(RID p_mesh,const AABB& p_aabb) {
-
- Mesh *mesh = mesh_owner.get( p_mesh );
+ Mesh *mesh = mesh_owner.get(p_mesh);
ERR_FAIL_COND(!mesh);
- mesh->custom_aabb=p_aabb;
-
+ mesh->custom_aabb = p_aabb;
}
AABB RasterizerGLES2::mesh_get_custom_aabb(RID p_mesh) const {
- const Mesh *mesh = mesh_owner.get( p_mesh );
- ERR_FAIL_COND_V(!mesh,AABB());
+ const Mesh *mesh = mesh_owner.get(p_mesh);
+ ERR_FAIL_COND_V(!mesh, AABB());
return mesh->custom_aabb;
}
@@ -2871,10 +2688,10 @@ AABB RasterizerGLES2::mesh_get_custom_aabb(RID p_mesh) const {
RID RasterizerGLES2::multimesh_create() {
- return multimesh_owner.make_rid( memnew( MultiMesh ));
+ return multimesh_owner.make_rid(memnew(MultiMesh));
}
-void RasterizerGLES2::multimesh_set_instance_count(RID p_multimesh,int p_count) {
+void RasterizerGLES2::multimesh_set_instance_count(RID p_multimesh, int p_count) {
MultiMesh *multimesh = multimesh_owner.get(p_multimesh);
ERR_FAIL_COND(!multimesh);
@@ -2883,40 +2700,37 @@ void RasterizerGLES2::multimesh_set_instance_count(RID p_multimesh,int p_count)
if (use_texture_instancing) {
- if (nearest_power_of_2(p_count)!=nearest_power_of_2(multimesh->elements.size())) {
+ if (nearest_power_of_2(p_count) != nearest_power_of_2(multimesh->elements.size())) {
if (multimesh->tex_id) {
- glDeleteTextures(1,&multimesh->tex_id);
- multimesh->tex_id=0;
+ glDeleteTextures(1, &multimesh->tex_id);
+ multimesh->tex_id = 0;
}
if (p_count) {
uint32_t po2 = nearest_power_of_2(p_count);
- if (po2&0xAAAAAAAA) {
+ if (po2 & 0xAAAAAAAA) {
//half width
- multimesh->tw=Math::sqrt(po2*2);
- multimesh->th=multimesh->tw/2;
+ multimesh->tw = Math::sqrt(po2 * 2);
+ multimesh->th = multimesh->tw / 2;
} else {
- multimesh->tw=Math::sqrt(po2);
- multimesh->th=multimesh->tw;
-
+ multimesh->tw = Math::sqrt(po2);
+ multimesh->th = multimesh->tw;
}
- multimesh->tw*=4;
- if (multimesh->th==0)
- multimesh->th=1;
-
-
+ multimesh->tw *= 4;
+ if (multimesh->th == 0)
+ multimesh->th = 1;
glGenTextures(1, &multimesh->tex_id);
glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D,multimesh->tex_id);
+ glBindTexture(GL_TEXTURE_2D, multimesh->tex_id);
#ifdef GLEW_ENABLED
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, multimesh->tw, multimesh->th, 0, GL_RGBA, GL_FLOAT,NULL);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, multimesh->tw, multimesh->th, 0, GL_RGBA, GL_FLOAT, NULL);
#else
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, multimesh->tw, multimesh->th, 0, GL_RGBA, GL_FLOAT,NULL);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, multimesh->tw, multimesh->th, 0, GL_RGBA, GL_FLOAT, NULL);
#endif
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
@@ -2924,186 +2738,173 @@ void RasterizerGLES2::multimesh_set_instance_count(RID p_multimesh,int p_count)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
//multimesh->pixel_size=1.0/ps;
- glBindTexture(GL_TEXTURE_2D,0);
+ glBindTexture(GL_TEXTURE_2D, 0);
}
-
}
if (!multimesh->dirty_list.in_list()) {
_multimesh_dirty_list.add(&multimesh->dirty_list);
}
-
}
multimesh->elements.resize(p_count);
-
}
int RasterizerGLES2::multimesh_get_instance_count(RID p_multimesh) const {
MultiMesh *multimesh = multimesh_owner.get(p_multimesh);
- ERR_FAIL_COND_V(!multimesh,-1);
+ ERR_FAIL_COND_V(!multimesh, -1);
return multimesh->elements.size();
}
-void RasterizerGLES2::multimesh_set_mesh(RID p_multimesh,RID p_mesh) {
+void RasterizerGLES2::multimesh_set_mesh(RID p_multimesh, RID p_mesh) {
MultiMesh *multimesh = multimesh_owner.get(p_multimesh);
ERR_FAIL_COND(!multimesh);
- multimesh->mesh=p_mesh;
-
+ multimesh->mesh = p_mesh;
}
-void RasterizerGLES2::multimesh_set_aabb(RID p_multimesh,const AABB& p_aabb) {
+void RasterizerGLES2::multimesh_set_aabb(RID p_multimesh, const AABB &p_aabb) {
MultiMesh *multimesh = multimesh_owner.get(p_multimesh);
ERR_FAIL_COND(!multimesh);
- multimesh->aabb=p_aabb;
+ multimesh->aabb = p_aabb;
}
-void RasterizerGLES2::multimesh_instance_set_transform(RID p_multimesh,int p_index,const Transform& p_transform) {
+void RasterizerGLES2::multimesh_instance_set_transform(RID p_multimesh, int p_index, const Transform &p_transform) {
MultiMesh *multimesh = multimesh_owner.get(p_multimesh);
ERR_FAIL_COND(!multimesh);
- ERR_FAIL_INDEX(p_index,multimesh->elements.size());
- MultiMesh::Element &e=multimesh->elements[p_index];
-
- e.matrix[0]=p_transform.basis.elements[0][0];
- e.matrix[1]=p_transform.basis.elements[1][0];
- e.matrix[2]=p_transform.basis.elements[2][0];
- e.matrix[3]=0;
- e.matrix[4]=p_transform.basis.elements[0][1];
- e.matrix[5]=p_transform.basis.elements[1][1];
- e.matrix[6]=p_transform.basis.elements[2][1];
- e.matrix[7]=0;
- e.matrix[8]=p_transform.basis.elements[0][2];
- e.matrix[9]=p_transform.basis.elements[1][2];
- e.matrix[10]=p_transform.basis.elements[2][2];
- e.matrix[11]=0;
- e.matrix[12]=p_transform.origin.x;
- e.matrix[13]=p_transform.origin.y;
- e.matrix[14]=p_transform.origin.z;
- e.matrix[15]=1;
+ ERR_FAIL_INDEX(p_index, multimesh->elements.size());
+ MultiMesh::Element &e = multimesh->elements[p_index];
+
+ e.matrix[0] = p_transform.basis.elements[0][0];
+ e.matrix[1] = p_transform.basis.elements[1][0];
+ e.matrix[2] = p_transform.basis.elements[2][0];
+ e.matrix[3] = 0;
+ e.matrix[4] = p_transform.basis.elements[0][1];
+ e.matrix[5] = p_transform.basis.elements[1][1];
+ e.matrix[6] = p_transform.basis.elements[2][1];
+ e.matrix[7] = 0;
+ e.matrix[8] = p_transform.basis.elements[0][2];
+ e.matrix[9] = p_transform.basis.elements[1][2];
+ e.matrix[10] = p_transform.basis.elements[2][2];
+ e.matrix[11] = 0;
+ e.matrix[12] = p_transform.origin.x;
+ e.matrix[13] = p_transform.origin.y;
+ e.matrix[14] = p_transform.origin.z;
+ e.matrix[15] = 1;
if (!multimesh->dirty_list.in_list()) {
_multimesh_dirty_list.add(&multimesh->dirty_list);
}
-
}
-void RasterizerGLES2::multimesh_instance_set_color(RID p_multimesh,int p_index,const Color& p_color) {
+void RasterizerGLES2::multimesh_instance_set_color(RID p_multimesh, int p_index, const Color &p_color) {
MultiMesh *multimesh = multimesh_owner.get(p_multimesh);
ERR_FAIL_COND(!multimesh)
- ERR_FAIL_INDEX(p_index,multimesh->elements.size());
- MultiMesh::Element &e=multimesh->elements[p_index];
- e.color[0]=CLAMP(p_color.r*255,0,255);
- e.color[1]=CLAMP(p_color.g*255,0,255);
- e.color[2]=CLAMP(p_color.b*255,0,255);
- e.color[3]=CLAMP(p_color.a*255,0,255);
+ ERR_FAIL_INDEX(p_index, multimesh->elements.size());
+ MultiMesh::Element &e = multimesh->elements[p_index];
+ e.color[0] = CLAMP(p_color.r * 255, 0, 255);
+ e.color[1] = CLAMP(p_color.g * 255, 0, 255);
+ e.color[2] = CLAMP(p_color.b * 255, 0, 255);
+ e.color[3] = CLAMP(p_color.a * 255, 0, 255);
if (!multimesh->dirty_list.in_list()) {
_multimesh_dirty_list.add(&multimesh->dirty_list);
}
-
}
RID RasterizerGLES2::multimesh_get_mesh(RID p_multimesh) const {
MultiMesh *multimesh = multimesh_owner.get(p_multimesh);
- ERR_FAIL_COND_V(!multimesh,RID());
+ ERR_FAIL_COND_V(!multimesh, RID());
return multimesh->mesh;
}
AABB RasterizerGLES2::multimesh_get_aabb(RID p_multimesh) const {
MultiMesh *multimesh = multimesh_owner.get(p_multimesh);
- ERR_FAIL_COND_V(!multimesh,AABB());
+ ERR_FAIL_COND_V(!multimesh, AABB());
return multimesh->aabb;
}
-Transform RasterizerGLES2::multimesh_instance_get_transform(RID p_multimesh,int p_index) const {
+Transform RasterizerGLES2::multimesh_instance_get_transform(RID p_multimesh, int p_index) const {
MultiMesh *multimesh = multimesh_owner.get(p_multimesh);
- ERR_FAIL_COND_V(!multimesh,Transform());
+ ERR_FAIL_COND_V(!multimesh, Transform());
- ERR_FAIL_INDEX_V(p_index,multimesh->elements.size(),Transform());
- MultiMesh::Element &e=multimesh->elements[p_index];
+ ERR_FAIL_INDEX_V(p_index, multimesh->elements.size(), Transform());
+ MultiMesh::Element &e = multimesh->elements[p_index];
Transform tr;
- tr.basis.elements[0][0]=e.matrix[0];
- tr.basis.elements[1][0]=e.matrix[1];
- tr.basis.elements[2][0]=e.matrix[2];
- tr.basis.elements[0][1]=e.matrix[4];
- tr.basis.elements[1][1]=e.matrix[5];
- tr.basis.elements[2][1]=e.matrix[6];
- tr.basis.elements[0][2]=e.matrix[8];
- tr.basis.elements[1][2]=e.matrix[9];
- tr.basis.elements[2][2]=e.matrix[10];
- tr.origin.x=e.matrix[12];
- tr.origin.y=e.matrix[13];
- tr.origin.z=e.matrix[14];
+ tr.basis.elements[0][0] = e.matrix[0];
+ tr.basis.elements[1][0] = e.matrix[1];
+ tr.basis.elements[2][0] = e.matrix[2];
+ tr.basis.elements[0][1] = e.matrix[4];
+ tr.basis.elements[1][1] = e.matrix[5];
+ tr.basis.elements[2][1] = e.matrix[6];
+ tr.basis.elements[0][2] = e.matrix[8];
+ tr.basis.elements[1][2] = e.matrix[9];
+ tr.basis.elements[2][2] = e.matrix[10];
+ tr.origin.x = e.matrix[12];
+ tr.origin.y = e.matrix[13];
+ tr.origin.z = e.matrix[14];
return tr;
}
-Color RasterizerGLES2::multimesh_instance_get_color(RID p_multimesh,int p_index) const {
+Color RasterizerGLES2::multimesh_instance_get_color(RID p_multimesh, int p_index) const {
MultiMesh *multimesh = multimesh_owner.get(p_multimesh);
- ERR_FAIL_COND_V(!multimesh,Color());
- ERR_FAIL_INDEX_V(p_index,multimesh->elements.size(),Color());
- MultiMesh::Element &e=multimesh->elements[p_index];
+ ERR_FAIL_COND_V(!multimesh, Color());
+ ERR_FAIL_INDEX_V(p_index, multimesh->elements.size(), Color());
+ MultiMesh::Element &e = multimesh->elements[p_index];
Color c;
- c.r=e.color[0]/255.0;
- c.g=e.color[1]/255.0;
- c.b=e.color[2]/255.0;
- c.a=e.color[3]/255.0;
+ c.r = e.color[0] / 255.0;
+ c.g = e.color[1] / 255.0;
+ c.b = e.color[2] / 255.0;
+ c.a = e.color[3] / 255.0;
return c;
-
}
-void RasterizerGLES2::multimesh_set_visible_instances(RID p_multimesh,int p_visible) {
+void RasterizerGLES2::multimesh_set_visible_instances(RID p_multimesh, int p_visible) {
MultiMesh *multimesh = multimesh_owner.get(p_multimesh);
ERR_FAIL_COND(!multimesh);
- multimesh->visible=p_visible;
-
+ multimesh->visible = p_visible;
}
int RasterizerGLES2::multimesh_get_visible_instances(RID p_multimesh) const {
MultiMesh *multimesh = multimesh_owner.get(p_multimesh);
- ERR_FAIL_COND_V(!multimesh,-1);
+ ERR_FAIL_COND_V(!multimesh, -1);
return multimesh->visible;
-
}
/* IMMEDIATE API */
-
RID RasterizerGLES2::immediate_create() {
- Immediate *im = memnew( Immediate );
+ Immediate *im = memnew(Immediate);
return immediate_owner.make_rid(im);
-
}
-void RasterizerGLES2::immediate_begin(RID p_immediate, VS::PrimitiveType p_rimitive, RID p_texture){
+void RasterizerGLES2::immediate_begin(RID p_immediate, VS::PrimitiveType p_rimitive, RID p_texture) {
Immediate *im = immediate_owner.get(p_immediate);
ERR_FAIL_COND(!im);
ERR_FAIL_COND(im->building);
Immediate::Chunk ic;
- ic.texture=p_texture;
- ic.primitive=p_rimitive;
+ ic.texture = p_texture;
+ ic.primitive = p_rimitive;
im->chunks.push_back(ic);
- im->mask=0;
- im->building=true;
-
-
+ im->mask = 0;
+ im->building = true;
}
-void RasterizerGLES2::immediate_vertex(RID p_immediate,const Vector3& p_vertex){
+void RasterizerGLES2::immediate_vertex(RID p_immediate, const Vector3 &p_vertex) {
Immediate *im = immediate_owner.get(p_immediate);
ERR_FAIL_COND(!im);
@@ -3111,90 +2912,81 @@ void RasterizerGLES2::immediate_vertex(RID p_immediate,const Vector3& p_vertex){
Immediate::Chunk *c = &im->chunks.back()->get();
+ if (c->vertices.empty() && im->chunks.size() == 1) {
- if (c->vertices.empty() && im->chunks.size()==1) {
-
- im->aabb.pos=p_vertex;
- im->aabb.size=Vector3();
+ im->aabb.pos = p_vertex;
+ im->aabb.size = Vector3();
} else {
im->aabb.expand_to(p_vertex);
}
- if (im->mask&VS::ARRAY_FORMAT_NORMAL)
+ if (im->mask & VS::ARRAY_FORMAT_NORMAL)
c->normals.push_back(chunk_normal);
- if (im->mask&VS::ARRAY_FORMAT_TANGENT)
+ if (im->mask & VS::ARRAY_FORMAT_TANGENT)
c->tangents.push_back(chunk_tangent);
- if (im->mask&VS::ARRAY_FORMAT_COLOR)
+ if (im->mask & VS::ARRAY_FORMAT_COLOR)
c->colors.push_back(chunk_color);
- if (im->mask&VS::ARRAY_FORMAT_TEX_UV)
+ if (im->mask & VS::ARRAY_FORMAT_TEX_UV)
c->uvs.push_back(chunk_uv);
- if (im->mask&VS::ARRAY_FORMAT_TEX_UV2)
+ if (im->mask & VS::ARRAY_FORMAT_TEX_UV2)
c->uvs2.push_back(chunk_uv2);
- im->mask|=VS::ARRAY_FORMAT_VERTEX;
+ im->mask |= VS::ARRAY_FORMAT_VERTEX;
c->vertices.push_back(p_vertex);
-
}
-
-void RasterizerGLES2::immediate_normal(RID p_immediate,const Vector3& p_normal){
+void RasterizerGLES2::immediate_normal(RID p_immediate, const Vector3 &p_normal) {
Immediate *im = immediate_owner.get(p_immediate);
ERR_FAIL_COND(!im);
ERR_FAIL_COND(!im->building);
- im->mask|=VS::ARRAY_FORMAT_NORMAL;
- chunk_normal=p_normal;
-
+ im->mask |= VS::ARRAY_FORMAT_NORMAL;
+ chunk_normal = p_normal;
}
-void RasterizerGLES2::immediate_tangent(RID p_immediate,const Plane& p_tangent){
+void RasterizerGLES2::immediate_tangent(RID p_immediate, const Plane &p_tangent) {
Immediate *im = immediate_owner.get(p_immediate);
ERR_FAIL_COND(!im);
ERR_FAIL_COND(!im->building);
- im->mask|=VS::ARRAY_FORMAT_TANGENT;
- chunk_tangent=p_tangent;
-
+ im->mask |= VS::ARRAY_FORMAT_TANGENT;
+ chunk_tangent = p_tangent;
}
-void RasterizerGLES2::immediate_color(RID p_immediate,const Color& p_color){
+void RasterizerGLES2::immediate_color(RID p_immediate, const Color &p_color) {
Immediate *im = immediate_owner.get(p_immediate);
ERR_FAIL_COND(!im);
ERR_FAIL_COND(!im->building);
- im->mask|=VS::ARRAY_FORMAT_COLOR;
- chunk_color=p_color;
-
+ im->mask |= VS::ARRAY_FORMAT_COLOR;
+ chunk_color = p_color;
}
-void RasterizerGLES2::immediate_uv(RID p_immediate,const Vector2& tex_uv){
+void RasterizerGLES2::immediate_uv(RID p_immediate, const Vector2 &tex_uv) {
Immediate *im = immediate_owner.get(p_immediate);
ERR_FAIL_COND(!im);
ERR_FAIL_COND(!im->building);
- im->mask|=VS::ARRAY_FORMAT_TEX_UV;
- chunk_uv=tex_uv;
-
+ im->mask |= VS::ARRAY_FORMAT_TEX_UV;
+ chunk_uv = tex_uv;
}
-void RasterizerGLES2::immediate_uv2(RID p_immediate,const Vector2& tex_uv){
+void RasterizerGLES2::immediate_uv2(RID p_immediate, const Vector2 &tex_uv) {
Immediate *im = immediate_owner.get(p_immediate);
ERR_FAIL_COND(!im);
ERR_FAIL_COND(!im->building);
- im->mask|=VS::ARRAY_FORMAT_TEX_UV2;
- chunk_uv2=tex_uv;
-
+ im->mask |= VS::ARRAY_FORMAT_TEX_UV2;
+ chunk_uv2 = tex_uv;
}
-void RasterizerGLES2::immediate_end(RID p_immediate){
+void RasterizerGLES2::immediate_end(RID p_immediate) {
Immediate *im = immediate_owner.get(p_immediate);
ERR_FAIL_COND(!im);
ERR_FAIL_COND(!im->building);
- im->building=false;
-
+ im->building = false;
}
void RasterizerGLES2::immediate_clear(RID p_immediate) {
@@ -3208,345 +3000,318 @@ void RasterizerGLES2::immediate_clear(RID p_immediate) {
AABB RasterizerGLES2::immediate_get_aabb(RID p_immediate) const {
Immediate *im = immediate_owner.get(p_immediate);
- ERR_FAIL_COND_V(!im,AABB());
+ ERR_FAIL_COND_V(!im, AABB());
return im->aabb;
}
-void RasterizerGLES2::immediate_set_material(RID p_immediate,RID p_material) {
+void RasterizerGLES2::immediate_set_material(RID p_immediate, RID p_material) {
Immediate *im = immediate_owner.get(p_immediate);
ERR_FAIL_COND(!im);
- im->material=p_material;
-
+ im->material = p_material;
}
RID RasterizerGLES2::immediate_get_material(RID p_immediate) const {
const Immediate *im = immediate_owner.get(p_immediate);
- ERR_FAIL_COND_V(!im,RID());
+ ERR_FAIL_COND_V(!im, RID());
return im->material;
-
}
-
/* PARTICLES API */
RID RasterizerGLES2::particles_create() {
- Particles *particles = memnew( Particles );
- ERR_FAIL_COND_V(!particles,RID());
+ Particles *particles = memnew(Particles);
+ ERR_FAIL_COND_V(!particles, RID());
return particles_owner.make_rid(particles);
}
void RasterizerGLES2::particles_set_amount(RID p_particles, int p_amount) {
- ERR_FAIL_COND(p_amount<1);
- Particles* particles = particles_owner.get( p_particles );
+ ERR_FAIL_COND(p_amount < 1);
+ Particles *particles = particles_owner.get(p_particles);
ERR_FAIL_COND(!particles);
- particles->data.amount=p_amount;
-
+ particles->data.amount = p_amount;
}
int RasterizerGLES2::particles_get_amount(RID p_particles) const {
- Particles* particles = particles_owner.get( p_particles );
- ERR_FAIL_COND_V(!particles,-1);
+ Particles *particles = particles_owner.get(p_particles);
+ ERR_FAIL_COND_V(!particles, -1);
return particles->data.amount;
-
}
void RasterizerGLES2::particles_set_emitting(RID p_particles, bool p_emitting) {
- Particles* particles = particles_owner.get( p_particles );
+ Particles *particles = particles_owner.get(p_particles);
ERR_FAIL_COND(!particles);
- particles->data.emitting=p_emitting;
-
+ particles->data.emitting = p_emitting;
}
bool RasterizerGLES2::particles_is_emitting(RID p_particles) const {
- const Particles* particles = particles_owner.get( p_particles );
- ERR_FAIL_COND_V(!particles,false);
+ const Particles *particles = particles_owner.get(p_particles);
+ ERR_FAIL_COND_V(!particles, false);
return particles->data.emitting;
-
}
-void RasterizerGLES2::particles_set_visibility_aabb(RID p_particles, const AABB& p_visibility) {
+void RasterizerGLES2::particles_set_visibility_aabb(RID p_particles, const AABB &p_visibility) {
- Particles* particles = particles_owner.get( p_particles );
+ Particles *particles = particles_owner.get(p_particles);
ERR_FAIL_COND(!particles);
- particles->data.visibility_aabb=p_visibility;
-
+ particles->data.visibility_aabb = p_visibility;
}
-void RasterizerGLES2::particles_set_emission_half_extents(RID p_particles, const Vector3& p_half_extents) {
+void RasterizerGLES2::particles_set_emission_half_extents(RID p_particles, const Vector3 &p_half_extents) {
- Particles* particles = particles_owner.get( p_particles );
+ Particles *particles = particles_owner.get(p_particles);
ERR_FAIL_COND(!particles);
- particles->data.emission_half_extents=p_half_extents;
+ particles->data.emission_half_extents = p_half_extents;
}
Vector3 RasterizerGLES2::particles_get_emission_half_extents(RID p_particles) const {
- Particles* particles = particles_owner.get( p_particles );
- ERR_FAIL_COND_V(!particles,Vector3());
+ Particles *particles = particles_owner.get(p_particles);
+ ERR_FAIL_COND_V(!particles, Vector3());
return particles->data.emission_half_extents;
}
-void RasterizerGLES2::particles_set_emission_base_velocity(RID p_particles, const Vector3& p_base_velocity) {
+void RasterizerGLES2::particles_set_emission_base_velocity(RID p_particles, const Vector3 &p_base_velocity) {
- Particles* particles = particles_owner.get( p_particles );
+ Particles *particles = particles_owner.get(p_particles);
ERR_FAIL_COND(!particles);
- particles->data.emission_base_velocity=p_base_velocity;
+ particles->data.emission_base_velocity = p_base_velocity;
}
Vector3 RasterizerGLES2::particles_get_emission_base_velocity(RID p_particles) const {
- Particles* particles = particles_owner.get( p_particles );
- ERR_FAIL_COND_V(!particles,Vector3());
+ Particles *particles = particles_owner.get(p_particles);
+ ERR_FAIL_COND_V(!particles, Vector3());
return particles->data.emission_base_velocity;
}
+void RasterizerGLES2::particles_set_emission_points(RID p_particles, const PoolVector<Vector3> &p_points) {
-void RasterizerGLES2::particles_set_emission_points(RID p_particles, const PoolVector<Vector3>& p_points) {
-
- Particles* particles = particles_owner.get( p_particles );
+ Particles *particles = particles_owner.get(p_particles);
ERR_FAIL_COND(!particles);
- particles->data.emission_points=p_points;
+ particles->data.emission_points = p_points;
}
PoolVector<Vector3> RasterizerGLES2::particles_get_emission_points(RID p_particles) const {
- Particles* particles = particles_owner.get( p_particles );
- ERR_FAIL_COND_V(!particles,PoolVector<Vector3>());
+ Particles *particles = particles_owner.get(p_particles);
+ ERR_FAIL_COND_V(!particles, PoolVector<Vector3>());
return particles->data.emission_points;
-
}
-void RasterizerGLES2::particles_set_gravity_normal(RID p_particles, const Vector3& p_normal) {
+void RasterizerGLES2::particles_set_gravity_normal(RID p_particles, const Vector3 &p_normal) {
- Particles* particles = particles_owner.get( p_particles );
+ Particles *particles = particles_owner.get(p_particles);
ERR_FAIL_COND(!particles);
- particles->data.gravity_normal=p_normal;
-
+ particles->data.gravity_normal = p_normal;
}
Vector3 RasterizerGLES2::particles_get_gravity_normal(RID p_particles) const {
- Particles* particles = particles_owner.get( p_particles );
- ERR_FAIL_COND_V(!particles,Vector3());
+ Particles *particles = particles_owner.get(p_particles);
+ ERR_FAIL_COND_V(!particles, Vector3());
return particles->data.gravity_normal;
}
-
AABB RasterizerGLES2::particles_get_visibility_aabb(RID p_particles) const {
- const Particles* particles = particles_owner.get( p_particles );
- ERR_FAIL_COND_V(!particles,AABB());
+ const Particles *particles = particles_owner.get(p_particles);
+ ERR_FAIL_COND_V(!particles, AABB());
return particles->data.visibility_aabb;
-
}
-void RasterizerGLES2::particles_set_variable(RID p_particles, VS::ParticleVariable p_variable,float p_value) {
+void RasterizerGLES2::particles_set_variable(RID p_particles, VS::ParticleVariable p_variable, float p_value) {
- ERR_FAIL_INDEX(p_variable,VS::PARTICLE_VAR_MAX);
+ ERR_FAIL_INDEX(p_variable, VS::PARTICLE_VAR_MAX);
- Particles* particles = particles_owner.get( p_particles );
+ Particles *particles = particles_owner.get(p_particles);
ERR_FAIL_COND(!particles);
- particles->data.particle_vars[p_variable]=p_value;
-
+ particles->data.particle_vars[p_variable] = p_value;
}
float RasterizerGLES2::particles_get_variable(RID p_particles, VS::ParticleVariable p_variable) const {
- const Particles* particles = particles_owner.get( p_particles );
- ERR_FAIL_COND_V(!particles,-1);
+ const Particles *particles = particles_owner.get(p_particles);
+ ERR_FAIL_COND_V(!particles, -1);
return particles->data.particle_vars[p_variable];
}
-void RasterizerGLES2::particles_set_randomness(RID p_particles, VS::ParticleVariable p_variable,float p_randomness) {
+void RasterizerGLES2::particles_set_randomness(RID p_particles, VS::ParticleVariable p_variable, float p_randomness) {
- Particles* particles = particles_owner.get( p_particles );
+ Particles *particles = particles_owner.get(p_particles);
ERR_FAIL_COND(!particles);
- particles->data.particle_randomness[p_variable]=p_randomness;
-
+ particles->data.particle_randomness[p_variable] = p_randomness;
}
float RasterizerGLES2::particles_get_randomness(RID p_particles, VS::ParticleVariable p_variable) const {
- const Particles* particles = particles_owner.get( p_particles );
- ERR_FAIL_COND_V(!particles,-1);
+ const Particles *particles = particles_owner.get(p_particles);
+ ERR_FAIL_COND_V(!particles, -1);
return particles->data.particle_randomness[p_variable];
-
}
void RasterizerGLES2::particles_set_color_phases(RID p_particles, int p_phases) {
- Particles* particles = particles_owner.get( p_particles );
+ Particles *particles = particles_owner.get(p_particles);
ERR_FAIL_COND(!particles);
- ERR_FAIL_COND( p_phases<0 || p_phases>VS::MAX_PARTICLE_COLOR_PHASES );
- particles->data.color_phase_count=p_phases;
-
+ ERR_FAIL_COND(p_phases < 0 || p_phases > VS::MAX_PARTICLE_COLOR_PHASES);
+ particles->data.color_phase_count = p_phases;
}
int RasterizerGLES2::particles_get_color_phases(RID p_particles) const {
- Particles* particles = particles_owner.get( p_particles );
- ERR_FAIL_COND_V(!particles,-1);
+ Particles *particles = particles_owner.get(p_particles);
+ ERR_FAIL_COND_V(!particles, -1);
return particles->data.color_phase_count;
}
-
void RasterizerGLES2::particles_set_color_phase_pos(RID p_particles, int p_phase, float p_pos) {
ERR_FAIL_INDEX(p_phase, VS::MAX_PARTICLE_COLOR_PHASES);
- if (p_pos<0.0)
- p_pos=0.0;
- if (p_pos>1.0)
- p_pos=1.0;
+ if (p_pos < 0.0)
+ p_pos = 0.0;
+ if (p_pos > 1.0)
+ p_pos = 1.0;
- Particles* particles = particles_owner.get( p_particles );
+ Particles *particles = particles_owner.get(p_particles);
ERR_FAIL_COND(!particles);
- particles->data.color_phases[p_phase].pos=p_pos;
-
+ particles->data.color_phases[p_phase].pos = p_pos;
}
float RasterizerGLES2::particles_get_color_phase_pos(RID p_particles, int p_phase) const {
ERR_FAIL_INDEX_V(p_phase, VS::MAX_PARTICLE_COLOR_PHASES, -1.0);
- const Particles* particles = particles_owner.get( p_particles );
- ERR_FAIL_COND_V(!particles,-1);
+ const Particles *particles = particles_owner.get(p_particles);
+ ERR_FAIL_COND_V(!particles, -1);
return particles->data.color_phases[p_phase].pos;
-
}
-void RasterizerGLES2::particles_set_color_phase_color(RID p_particles, int p_phase, const Color& p_color) {
+void RasterizerGLES2::particles_set_color_phase_color(RID p_particles, int p_phase, const Color &p_color) {
ERR_FAIL_INDEX(p_phase, VS::MAX_PARTICLE_COLOR_PHASES);
- Particles* particles = particles_owner.get( p_particles );
+ Particles *particles = particles_owner.get(p_particles);
ERR_FAIL_COND(!particles);
- particles->data.color_phases[p_phase].color=p_color;
+ particles->data.color_phases[p_phase].color = p_color;
//update alpha
- particles->has_alpha=false;
- for(int i=0;i<VS::MAX_PARTICLE_COLOR_PHASES;i++) {
- if (particles->data.color_phases[i].color.a<0.99)
- particles->has_alpha=true;
+ particles->has_alpha = false;
+ for (int i = 0; i < VS::MAX_PARTICLE_COLOR_PHASES; i++) {
+ if (particles->data.color_phases[i].color.a < 0.99)
+ particles->has_alpha = true;
}
-
}
Color RasterizerGLES2::particles_get_color_phase_color(RID p_particles, int p_phase) const {
ERR_FAIL_INDEX_V(p_phase, VS::MAX_PARTICLE_COLOR_PHASES, Color());
- const Particles* particles = particles_owner.get( p_particles );
- ERR_FAIL_COND_V(!particles,Color());
+ const Particles *particles = particles_owner.get(p_particles);
+ ERR_FAIL_COND_V(!particles, Color());
return particles->data.color_phases[p_phase].color;
-
}
void RasterizerGLES2::particles_set_attractors(RID p_particles, int p_attractors) {
- Particles* particles = particles_owner.get( p_particles );
+ Particles *particles = particles_owner.get(p_particles);
ERR_FAIL_COND(!particles);
- ERR_FAIL_COND( p_attractors<0 || p_attractors>VisualServer::MAX_PARTICLE_ATTRACTORS );
- particles->data.attractor_count=p_attractors;
-
+ ERR_FAIL_COND(p_attractors < 0 || p_attractors > VisualServer::MAX_PARTICLE_ATTRACTORS);
+ particles->data.attractor_count = p_attractors;
}
int RasterizerGLES2::particles_get_attractors(RID p_particles) const {
- Particles* particles = particles_owner.get( p_particles );
- ERR_FAIL_COND_V(!particles,-1);
+ Particles *particles = particles_owner.get(p_particles);
+ ERR_FAIL_COND_V(!particles, -1);
return particles->data.attractor_count;
}
-void RasterizerGLES2::particles_set_attractor_pos(RID p_particles, int p_attractor, const Vector3& p_pos) {
+void RasterizerGLES2::particles_set_attractor_pos(RID p_particles, int p_attractor, const Vector3 &p_pos) {
- Particles* particles = particles_owner.get( p_particles );
+ Particles *particles = particles_owner.get(p_particles);
ERR_FAIL_COND(!particles);
- ERR_FAIL_INDEX(p_attractor,particles->data.attractor_count);
- particles->data.attractors[p_attractor].pos=p_pos;
+ ERR_FAIL_INDEX(p_attractor, particles->data.attractor_count);
+ particles->data.attractors[p_attractor].pos = p_pos;
}
-Vector3 RasterizerGLES2::particles_get_attractor_pos(RID p_particles,int p_attractor) const {
+Vector3 RasterizerGLES2::particles_get_attractor_pos(RID p_particles, int p_attractor) const {
- Particles* particles = particles_owner.get( p_particles );
- ERR_FAIL_COND_V(!particles,Vector3());
- ERR_FAIL_INDEX_V(p_attractor,particles->data.attractor_count,Vector3());
+ Particles *particles = particles_owner.get(p_particles);
+ ERR_FAIL_COND_V(!particles, Vector3());
+ ERR_FAIL_INDEX_V(p_attractor, particles->data.attractor_count, Vector3());
return particles->data.attractors[p_attractor].pos;
}
void RasterizerGLES2::particles_set_attractor_strength(RID p_particles, int p_attractor, float p_force) {
- Particles* particles = particles_owner.get( p_particles );
+ Particles *particles = particles_owner.get(p_particles);
ERR_FAIL_COND(!particles);
- ERR_FAIL_INDEX(p_attractor,particles->data.attractor_count);
- particles->data.attractors[p_attractor].force=p_force;
+ ERR_FAIL_INDEX(p_attractor, particles->data.attractor_count);
+ particles->data.attractors[p_attractor].force = p_force;
}
-float RasterizerGLES2::particles_get_attractor_strength(RID p_particles,int p_attractor) const {
+float RasterizerGLES2::particles_get_attractor_strength(RID p_particles, int p_attractor) const {
- Particles* particles = particles_owner.get( p_particles );
- ERR_FAIL_COND_V(!particles,0);
- ERR_FAIL_INDEX_V(p_attractor,particles->data.attractor_count,0);
+ Particles *particles = particles_owner.get(p_particles);
+ ERR_FAIL_COND_V(!particles, 0);
+ ERR_FAIL_INDEX_V(p_attractor, particles->data.attractor_count, 0);
return particles->data.attractors[p_attractor].force;
}
-void RasterizerGLES2::particles_set_material(RID p_particles, RID p_material,bool p_owned) {
+void RasterizerGLES2::particles_set_material(RID p_particles, RID p_material, bool p_owned) {
- Particles* particles = particles_owner.get( p_particles );
+ Particles *particles = particles_owner.get(p_particles);
ERR_FAIL_COND(!particles);
if (particles->material_owned && particles->material.is_valid())
free(particles->material);
- particles->material_owned=p_owned;
-
- particles->material=p_material;
+ particles->material_owned = p_owned;
+ particles->material = p_material;
}
RID RasterizerGLES2::particles_get_material(RID p_particles) const {
- const Particles* particles = particles_owner.get( p_particles );
- ERR_FAIL_COND_V(!particles,RID());
+ const Particles *particles = particles_owner.get(p_particles);
+ ERR_FAIL_COND_V(!particles, RID());
return particles->material;
-
}
void RasterizerGLES2::particles_set_use_local_coordinates(RID p_particles, bool p_enable) {
- Particles* particles = particles_owner.get( p_particles );
+ Particles *particles = particles_owner.get(p_particles);
ERR_FAIL_COND(!particles);
- particles->data.local_coordinates=p_enable;
-
+ particles->data.local_coordinates = p_enable;
}
bool RasterizerGLES2::particles_is_using_local_coordinates(RID p_particles) const {
- const Particles* particles = particles_owner.get( p_particles );
- ERR_FAIL_COND_V(!particles,false);
+ const Particles *particles = particles_owner.get(p_particles);
+ ERR_FAIL_COND_V(!particles, false);
return particles->data.local_coordinates;
}
bool RasterizerGLES2::particles_has_height_from_velocity(RID p_particles) const {
- const Particles* particles = particles_owner.get( p_particles );
- ERR_FAIL_COND_V(!particles,false);
+ const Particles *particles = particles_owner.get(p_particles);
+ ERR_FAIL_COND_V(!particles, false);
return particles->data.height_from_velocity;
}
void RasterizerGLES2::particles_set_height_from_velocity(RID p_particles, bool p_enable) {
- Particles* particles = particles_owner.get( p_particles );
+ Particles *particles = particles_owner.get(p_particles);
ERR_FAIL_COND(!particles);
- particles->data.height_from_velocity=p_enable;
-
+ particles->data.height_from_velocity = p_enable;
}
AABB RasterizerGLES2::particles_get_aabb(RID p_particles) const {
- const Particles* particles = particles_owner.get( p_particles );
- ERR_FAIL_COND_V(!particles,AABB());
+ const Particles *particles = particles_owner.get(p_particles);
+ ERR_FAIL_COND_V(!particles, AABB());
return particles->data.visibility_aabb;
}
@@ -3554,208 +3319,201 @@ AABB RasterizerGLES2::particles_get_aabb(RID p_particles) const {
RID RasterizerGLES2::skeleton_create() {
- Skeleton *skeleton = memnew( Skeleton );
- ERR_FAIL_COND_V(!skeleton,RID());
- return skeleton_owner.make_rid( skeleton );
+ Skeleton *skeleton = memnew(Skeleton);
+ ERR_FAIL_COND_V(!skeleton, RID());
+ return skeleton_owner.make_rid(skeleton);
}
-void RasterizerGLES2::skeleton_resize(RID p_skeleton,int p_bones) {
+void RasterizerGLES2::skeleton_resize(RID p_skeleton, int p_bones) {
- Skeleton *skeleton = skeleton_owner.get( p_skeleton );
+ Skeleton *skeleton = skeleton_owner.get(p_skeleton);
ERR_FAIL_COND(!skeleton);
if (p_bones == skeleton->bones.size()) {
return;
};
if (use_hw_skeleton_xform) {
- if (nearest_power_of_2(p_bones)!=nearest_power_of_2(skeleton->bones.size())) {
+ if (nearest_power_of_2(p_bones) != nearest_power_of_2(skeleton->bones.size())) {
if (skeleton->tex_id) {
- glDeleteTextures(1,&skeleton->tex_id);
- skeleton->tex_id=0;
+ glDeleteTextures(1, &skeleton->tex_id);
+ skeleton->tex_id = 0;
}
if (p_bones) {
glGenTextures(1, &skeleton->tex_id);
glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D,skeleton->tex_id);
- int ps = nearest_power_of_2(p_bones*3);
+ glBindTexture(GL_TEXTURE_2D, skeleton->tex_id);
+ int ps = nearest_power_of_2(p_bones * 3);
#ifdef GLEW_ENABLED
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, ps, 1, 0, GL_RGBA, GL_FLOAT,skel_default.ptr());
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, ps, 1, 0, GL_RGBA, GL_FLOAT, skel_default.ptr());
#else
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, ps, 1, 0, GL_RGBA, GL_FLOAT,skel_default.ptr());
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, ps, 1, 0, GL_RGBA, GL_FLOAT, skel_default.ptr());
#endif
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- skeleton->pixel_size=1.0/ps;
+ skeleton->pixel_size = 1.0 / ps;
- glBindTexture(GL_TEXTURE_2D,0);
+ glBindTexture(GL_TEXTURE_2D, 0);
}
-
}
if (!skeleton->dirty_list.in_list()) {
_skeleton_dirty_list.add(&skeleton->dirty_list);
}
-
}
skeleton->bones.resize(p_bones);
-
}
int RasterizerGLES2::skeleton_get_bone_count(RID p_skeleton) const {
- Skeleton *skeleton = skeleton_owner.get( p_skeleton );
+ Skeleton *skeleton = skeleton_owner.get(p_skeleton);
ERR_FAIL_COND_V(!skeleton, -1);
return skeleton->bones.size();
}
-void RasterizerGLES2::skeleton_bone_set_transform(RID p_skeleton,int p_bone, const Transform& p_transform) {
+void RasterizerGLES2::skeleton_bone_set_transform(RID p_skeleton, int p_bone, const Transform &p_transform) {
- Skeleton *skeleton = skeleton_owner.get( p_skeleton );
+ Skeleton *skeleton = skeleton_owner.get(p_skeleton);
ERR_FAIL_COND(!skeleton);
- ERR_FAIL_INDEX( p_bone, skeleton->bones.size() );
+ ERR_FAIL_INDEX(p_bone, skeleton->bones.size());
Skeleton::Bone &b = skeleton->bones[p_bone];
- b.mtx[0][0]=p_transform.basis[0][0];
- b.mtx[0][1]=p_transform.basis[1][0];
- b.mtx[0][2]=p_transform.basis[2][0];
- b.mtx[1][0]=p_transform.basis[0][1];
- b.mtx[1][1]=p_transform.basis[1][1];
- b.mtx[1][2]=p_transform.basis[2][1];
- b.mtx[2][0]=p_transform.basis[0][2];
- b.mtx[2][1]=p_transform.basis[1][2];
- b.mtx[2][2]=p_transform.basis[2][2];
- b.mtx[3][0]=p_transform.origin[0];
- b.mtx[3][1]=p_transform.origin[1];
- b.mtx[3][2]=p_transform.origin[2];
+ b.mtx[0][0] = p_transform.basis[0][0];
+ b.mtx[0][1] = p_transform.basis[1][0];
+ b.mtx[0][2] = p_transform.basis[2][0];
+ b.mtx[1][0] = p_transform.basis[0][1];
+ b.mtx[1][1] = p_transform.basis[1][1];
+ b.mtx[1][2] = p_transform.basis[2][1];
+ b.mtx[2][0] = p_transform.basis[0][2];
+ b.mtx[2][1] = p_transform.basis[1][2];
+ b.mtx[2][2] = p_transform.basis[2][2];
+ b.mtx[3][0] = p_transform.origin[0];
+ b.mtx[3][1] = p_transform.origin[1];
+ b.mtx[3][2] = p_transform.origin[2];
if (skeleton->tex_id) {
if (!skeleton->dirty_list.in_list()) {
_skeleton_dirty_list.add(&skeleton->dirty_list);
}
}
-
}
-Transform RasterizerGLES2::skeleton_bone_get_transform(RID p_skeleton,int p_bone) {
+Transform RasterizerGLES2::skeleton_bone_get_transform(RID p_skeleton, int p_bone) {
- Skeleton *skeleton = skeleton_owner.get( p_skeleton );
+ Skeleton *skeleton = skeleton_owner.get(p_skeleton);
ERR_FAIL_COND_V(!skeleton, Transform());
- ERR_FAIL_INDEX_V( p_bone, skeleton->bones.size(), Transform() );
+ ERR_FAIL_INDEX_V(p_bone, skeleton->bones.size(), Transform());
const Skeleton::Bone &b = skeleton->bones[p_bone];
Transform t;
- t.basis[0][0]=b.mtx[0][0];
- t.basis[1][0]=b.mtx[0][1];
- t.basis[2][0]=b.mtx[0][2];
- t.basis[0][1]=b.mtx[1][0];
- t.basis[1][1]=b.mtx[1][1];
- t.basis[2][1]=b.mtx[1][2];
- t.basis[0][2]=b.mtx[2][0];
- t.basis[1][2]=b.mtx[2][1];
- t.basis[2][2]=b.mtx[2][2];
- t.origin[0]=b.mtx[3][0];
- t.origin[1]=b.mtx[3][1];
- t.origin[2]=b.mtx[3][2];
+ t.basis[0][0] = b.mtx[0][0];
+ t.basis[1][0] = b.mtx[0][1];
+ t.basis[2][0] = b.mtx[0][2];
+ t.basis[0][1] = b.mtx[1][0];
+ t.basis[1][1] = b.mtx[1][1];
+ t.basis[2][1] = b.mtx[1][2];
+ t.basis[0][2] = b.mtx[2][0];
+ t.basis[1][2] = b.mtx[2][1];
+ t.basis[2][2] = b.mtx[2][2];
+ t.origin[0] = b.mtx[3][0];
+ t.origin[1] = b.mtx[3][1];
+ t.origin[2] = b.mtx[3][2];
return t;
-
}
-
/* LIGHT API */
RID RasterizerGLES2::light_create(VS::LightType p_type) {
- Light *light = memnew( Light );
- light->type=p_type;
+ Light *light = memnew(Light);
+ light->type = p_type;
return light_owner.make_rid(light);
}
VS::LightType RasterizerGLES2::light_get_type(RID p_light) const {
Light *light = light_owner.get(p_light);
- ERR_FAIL_COND_V(!light,VS::LIGHT_OMNI);
+ ERR_FAIL_COND_V(!light, VS::LIGHT_OMNI);
return light->type;
}
-void RasterizerGLES2::light_set_color(RID p_light,VS::LightColor p_type, const Color& p_color) {
+void RasterizerGLES2::light_set_color(RID p_light, VS::LightColor p_type, const Color &p_color) {
Light *light = light_owner.get(p_light);
ERR_FAIL_COND(!light);
- ERR_FAIL_INDEX( p_type, 3 );
- light->colors[p_type]=p_color;
+ ERR_FAIL_INDEX(p_type, 3);
+ light->colors[p_type] = p_color;
}
-Color RasterizerGLES2::light_get_color(RID p_light,VS::LightColor p_type) const {
+Color RasterizerGLES2::light_get_color(RID p_light, VS::LightColor p_type) const {
Light *light = light_owner.get(p_light);
ERR_FAIL_COND_V(!light, Color());
- ERR_FAIL_INDEX_V( p_type, 3, Color() );
+ ERR_FAIL_INDEX_V(p_type, 3, Color());
return light->colors[p_type];
}
-void RasterizerGLES2::light_set_shadow(RID p_light,bool p_enabled) {
+void RasterizerGLES2::light_set_shadow(RID p_light, bool p_enabled) {
Light *light = light_owner.get(p_light);
ERR_FAIL_COND(!light);
- light->shadow_enabled=p_enabled;
+ light->shadow_enabled = p_enabled;
}
bool RasterizerGLES2::light_has_shadow(RID p_light) const {
Light *light = light_owner.get(p_light);
- ERR_FAIL_COND_V(!light,false);
+ ERR_FAIL_COND_V(!light, false);
return light->shadow_enabled;
}
-void RasterizerGLES2::light_set_volumetric(RID p_light,bool p_enabled) {
+void RasterizerGLES2::light_set_volumetric(RID p_light, bool p_enabled) {
Light *light = light_owner.get(p_light);
ERR_FAIL_COND(!light);
- light->volumetric_enabled=p_enabled;
-
+ light->volumetric_enabled = p_enabled;
}
bool RasterizerGLES2::light_is_volumetric(RID p_light) const {
Light *light = light_owner.get(p_light);
- ERR_FAIL_COND_V(!light,false);
+ ERR_FAIL_COND_V(!light, false);
return light->volumetric_enabled;
}
-void RasterizerGLES2::light_set_projector(RID p_light,RID p_texture) {
+void RasterizerGLES2::light_set_projector(RID p_light, RID p_texture) {
Light *light = light_owner.get(p_light);
ERR_FAIL_COND(!light);
- light->projector=p_texture;
+ light->projector = p_texture;
}
RID RasterizerGLES2::light_get_projector(RID p_light) const {
Light *light = light_owner.get(p_light);
- ERR_FAIL_COND_V(!light,RID());
+ ERR_FAIL_COND_V(!light, RID());
return light->projector;
}
void RasterizerGLES2::light_set_var(RID p_light, VS::LightParam p_var, float p_value) {
- Light * light = light_owner.get( p_light );
+ Light *light = light_owner.get(p_light);
ERR_FAIL_COND(!light);
- ERR_FAIL_INDEX( p_var, VS::LIGHT_PARAM_MAX );
+ ERR_FAIL_INDEX(p_var, VS::LIGHT_PARAM_MAX);
- light->vars[p_var]=p_value;
+ light->vars[p_var] = p_value;
}
float RasterizerGLES2::light_get_var(RID p_light, VS::LightParam p_var) const {
- Light * light = light_owner.get( p_light );
- ERR_FAIL_COND_V(!light,0);
+ Light *light = light_owner.get(p_light);
+ ERR_FAIL_COND_V(!light, 0);
- ERR_FAIL_INDEX_V( p_var, VS::LIGHT_PARAM_MAX,0 );
+ ERR_FAIL_INDEX_V(p_var, VS::LIGHT_PARAM_MAX, 0);
return light->vars[p_var];
}
-void RasterizerGLES2::light_set_operator(RID p_light,VS::LightOp p_op) {
+void RasterizerGLES2::light_set_operator(RID p_light, VS::LightOp p_op){
};
@@ -3764,71 +3522,69 @@ VS::LightOp RasterizerGLES2::light_get_operator(RID p_light) const {
return VS::LightOp();
};
-void RasterizerGLES2::light_omni_set_shadow_mode(RID p_light,VS::LightOmniShadowMode p_mode) {
+void RasterizerGLES2::light_omni_set_shadow_mode(RID p_light, VS::LightOmniShadowMode p_mode) {
- Light * light = light_owner.get( p_light );
+ Light *light = light_owner.get(p_light);
ERR_FAIL_COND(!light);
- light->omni_shadow_mode=p_mode;
+ light->omni_shadow_mode = p_mode;
}
VS::LightOmniShadowMode RasterizerGLES2::light_omni_get_shadow_mode(RID p_light) const {
- const Light * light = light_owner.get( p_light );
- ERR_FAIL_COND_V(!light,VS::LIGHT_OMNI_SHADOW_DEFAULT);
+ const Light *light = light_owner.get(p_light);
+ ERR_FAIL_COND_V(!light, VS::LIGHT_OMNI_SHADOW_DEFAULT);
return light->omni_shadow_mode;
}
-void RasterizerGLES2::light_directional_set_shadow_mode(RID p_light,VS::LightDirectionalShadowMode p_mode) {
+void RasterizerGLES2::light_directional_set_shadow_mode(RID p_light, VS::LightDirectionalShadowMode p_mode) {
- Light * light = light_owner.get( p_light );
+ Light *light = light_owner.get(p_light);
ERR_FAIL_COND(!light);
- light->directional_shadow_mode=p_mode;
+ light->directional_shadow_mode = p_mode;
}
-
VS::LightDirectionalShadowMode RasterizerGLES2::light_directional_get_shadow_mode(RID p_light) const {
- const Light * light = light_owner.get( p_light );
- ERR_FAIL_COND_V(!light,VS::LIGHT_DIRECTIONAL_SHADOW_ORTHOGONAL);
+ const Light *light = light_owner.get(p_light);
+ ERR_FAIL_COND_V(!light, VS::LIGHT_DIRECTIONAL_SHADOW_ORTHOGONAL);
return light->directional_shadow_mode;
}
-void RasterizerGLES2::light_directional_set_shadow_param(RID p_light,VS::LightDirectionalShadowParam p_param, float p_value) {
+void RasterizerGLES2::light_directional_set_shadow_param(RID p_light, VS::LightDirectionalShadowParam p_param, float p_value) {
- Light * light = light_owner.get( p_light );
+ Light *light = light_owner.get(p_light);
ERR_FAIL_COND(!light);
- light->directional_shadow_param[p_param]=p_value;
+ light->directional_shadow_param[p_param] = p_value;
}
-float RasterizerGLES2::light_directional_get_shadow_param(RID p_light,VS::LightDirectionalShadowParam p_param) const {
+float RasterizerGLES2::light_directional_get_shadow_param(RID p_light, VS::LightDirectionalShadowParam p_param) const {
- const Light * light = light_owner.get( p_light );
- ERR_FAIL_COND_V(!light,0);
+ const Light *light = light_owner.get(p_light);
+ ERR_FAIL_COND_V(!light, 0);
return light->directional_shadow_param[p_param];
}
-
AABB RasterizerGLES2::light_get_aabb(RID p_light) const {
- Light *light = light_owner.get( p_light );
- ERR_FAIL_COND_V(!light,AABB());
+ Light *light = light_owner.get(p_light);
+ ERR_FAIL_COND_V(!light, AABB());
- switch( light->type ) {
+ switch (light->type) {
case VS::LIGHT_SPOT: {
- float len=light->vars[VS::LIGHT_PARAM_RADIUS];
- float size=Math::tan(Math::deg2rad(light->vars[VS::LIGHT_PARAM_SPOT_ANGLE]))*len;
- return AABB( Vector3( -size,-size,-len ), Vector3( size*2, size*2, len ) );
+ float len = light->vars[VS::LIGHT_PARAM_RADIUS];
+ float size = Math::tan(Math::deg2rad(light->vars[VS::LIGHT_PARAM_SPOT_ANGLE])) * len;
+ return AABB(Vector3(-size, -size, -len), Vector3(size * 2, size * 2, len));
} break;
case VS::LIGHT_OMNI: {
float r = light->vars[VS::LIGHT_PARAM_RADIUS];
- return AABB( -Vector3(r,r,r), Vector3(r,r,r)*2 );
+ return AABB(-Vector3(r, r, r), Vector3(r, r, r) * 2);
} break;
case VS::LIGHT_DIRECTIONAL: {
@@ -3837,54 +3593,51 @@ AABB RasterizerGLES2::light_get_aabb(RID p_light) const {
default: {}
}
- ERR_FAIL_V( AABB() );
+ ERR_FAIL_V(AABB());
}
-
RID RasterizerGLES2::light_instance_create(RID p_light) {
- Light *light = light_owner.get( p_light );
+ Light *light = light_owner.get(p_light);
ERR_FAIL_COND_V(!light, RID());
- LightInstance *light_instance = memnew( LightInstance );
+ LightInstance *light_instance = memnew(LightInstance);
- light_instance->light=p_light;
- light_instance->base=light;
- light_instance->last_pass=0;
+ light_instance->light = p_light;
+ light_instance->base = light;
+ light_instance->last_pass = 0;
- return light_instance_owner.make_rid( light_instance );
+ return light_instance_owner.make_rid(light_instance);
}
-void RasterizerGLES2::light_instance_set_transform(RID p_light_instance,const Transform& p_transform) {
+void RasterizerGLES2::light_instance_set_transform(RID p_light_instance, const Transform &p_transform) {
- LightInstance *lighti = light_instance_owner.get( p_light_instance );
+ LightInstance *lighti = light_instance_owner.get(p_light_instance);
ERR_FAIL_COND(!lighti);
- lighti->transform=p_transform;
-
+ lighti->transform = p_transform;
}
-
Rasterizer::ShadowType RasterizerGLES2::light_instance_get_shadow_type(RID p_light_instance, bool p_far) const {
- LightInstance *lighti = light_instance_owner.get( p_light_instance );
- ERR_FAIL_COND_V(!lighti,Rasterizer::SHADOW_NONE);
+ LightInstance *lighti = light_instance_owner.get(p_light_instance);
+ ERR_FAIL_COND_V(!lighti, Rasterizer::SHADOW_NONE);
- switch(lighti->base->type) {
+ switch (lighti->base->type) {
case VS::LIGHT_DIRECTIONAL: {
- switch(lighti->base->directional_shadow_mode) {
+ switch (lighti->base->directional_shadow_mode) {
case VS::LIGHT_DIRECTIONAL_SHADOW_ORTHOGONAL: {
return SHADOW_ORTHOGONAL;
} break;
- case VS::LIGHT_DIRECTIONAL_SHADOW_PERSPECTIVE:{
+ case VS::LIGHT_DIRECTIONAL_SHADOW_PERSPECTIVE: {
return SHADOW_PSM;
} break;
case VS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_2_SPLITS:
- case VS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_4_SPLITS:{
+ case VS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_4_SPLITS: {
return SHADOW_PSSM;
} break;
}
- }break;
+ } break;
case VS::LIGHT_OMNI: return SHADOW_DUAL_PARABOLOID; break;
case VS::LIGHT_SPOT: return SHADOW_SIMPLE; break;
}
@@ -3894,13 +3647,13 @@ Rasterizer::ShadowType RasterizerGLES2::light_instance_get_shadow_type(RID p_lig
int RasterizerGLES2::light_instance_get_shadow_passes(RID p_light_instance) const {
- LightInstance *lighti = light_instance_owner.get( p_light_instance );
- ERR_FAIL_COND_V(!lighti,0);
+ LightInstance *lighti = light_instance_owner.get(p_light_instance);
+ ERR_FAIL_COND_V(!lighti, 0);
- if (lighti->base->type==VS::LIGHT_DIRECTIONAL && lighti->base->directional_shadow_mode==VS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_4_SPLITS) {
+ if (lighti->base->type == VS::LIGHT_DIRECTIONAL && lighti->base->directional_shadow_mode == VS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_4_SPLITS) {
return 4; // dp4
- } else if (lighti->base->type==VS::LIGHT_OMNI || (lighti->base->type==VS::LIGHT_DIRECTIONAL && lighti->base->directional_shadow_mode==VS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_2_SPLITS)) {
+ } else if (lighti->base->type == VS::LIGHT_OMNI || (lighti->base->type == VS::LIGHT_DIRECTIONAL && lighti->base->directional_shadow_mode == VS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_2_SPLITS)) {
return 2; // dp
} else
return 1;
@@ -3908,20 +3661,20 @@ int RasterizerGLES2::light_instance_get_shadow_passes(RID p_light_instance) cons
bool RasterizerGLES2::light_instance_get_pssm_shadow_overlap(RID p_light_instance) const {
- return shadow_filter>=SHADOW_FILTER_ESM;
+ return shadow_filter >= SHADOW_FILTER_ESM;
}
-void RasterizerGLES2::light_instance_set_shadow_transform(RID p_light_instance, int p_index, const CameraMatrix& p_camera, const Transform& p_transform, float p_split_near,float p_split_far) {
+void RasterizerGLES2::light_instance_set_shadow_transform(RID p_light_instance, int p_index, const CameraMatrix &p_camera, const Transform &p_transform, float p_split_near, float p_split_far) {
- LightInstance *lighti = light_instance_owner.get( p_light_instance );
+ LightInstance *lighti = light_instance_owner.get(p_light_instance);
ERR_FAIL_COND(!lighti);
- ERR_FAIL_COND(lighti->base->type!=VS::LIGHT_DIRECTIONAL);
+ ERR_FAIL_COND(lighti->base->type != VS::LIGHT_DIRECTIONAL);
//ERR_FAIL_INDEX(p_index,1);
- lighti->custom_projection[p_index]=p_camera;
- lighti->custom_transform[p_index]=p_transform;
- lighti->shadow_split[p_index]=1.0/p_split_far;
+ lighti->custom_projection[p_index] = p_camera;
+ lighti->custom_transform[p_index] = p_transform;
+ lighti->shadow_split[p_index] = 1.0 / p_split_far;
#if 0
if (p_index==0) {
lighti->custom_projection=p_camera;
@@ -3942,23 +3695,21 @@ void RasterizerGLES2::light_instance_set_shadow_transform(RID p_light_instance,
#endif
}
-int RasterizerGLES2::light_instance_get_shadow_size(RID p_light_instance, int p_index) const{
+int RasterizerGLES2::light_instance_get_shadow_size(RID p_light_instance, int p_index) const {
- LightInstance *lighti = light_instance_owner.get( p_light_instance );
- ERR_FAIL_COND_V(!lighti,1);
- ERR_FAIL_COND_V(!lighti->near_shadow_buffer,256);
- return lighti->near_shadow_buffer->size/2;
+ LightInstance *lighti = light_instance_owner.get(p_light_instance);
+ ERR_FAIL_COND_V(!lighti, 1);
+ ERR_FAIL_COND_V(!lighti->near_shadow_buffer, 256);
+ return lighti->near_shadow_buffer->size / 2;
}
void RasterizerGLES2::shadow_clear_near() {
-
- for(int i=0;i<near_shadow_buffers.size();i++) {
+ for (int i = 0; i < near_shadow_buffers.size(); i++) {
if (near_shadow_buffers[i].owner)
near_shadow_buffers[i].owner->clear_near_shadow_buffers();
}
-
}
bool RasterizerGLES2::shadow_allocate_near(RID p_light) {
@@ -3967,32 +3718,31 @@ bool RasterizerGLES2::shadow_allocate_near(RID p_light) {
return false;
LightInstance *li = light_instance_owner.get(p_light);
- ERR_FAIL_COND_V(!li,false);
- ERR_FAIL_COND_V( li->near_shadow_buffer, false);
+ ERR_FAIL_COND_V(!li, false);
+ ERR_FAIL_COND_V(li->near_shadow_buffer, false);
- int skip=0;
+ int skip = 0;
if (framebuffer.active) {
int sc = framebuffer.scale;
- while(sc>1) {
- sc/=2;
+ while (sc > 1) {
+ sc /= 2;
skip++;
}
}
- for(int i=0;i<near_shadow_buffers.size();i++) {
+ for (int i = 0; i < near_shadow_buffers.size(); i++) {
-
- if (skip>0) {
+ if (skip > 0) {
skip--;
continue;
}
- if (near_shadow_buffers[i].owner!=NULL)
+ if (near_shadow_buffers[i].owner != NULL)
continue;
- near_shadow_buffers[i].owner=li;
- li->near_shadow_buffer=&near_shadow_buffers[i];
+ near_shadow_buffers[i].owner = li;
+ li->near_shadow_buffer = &near_shadow_buffers[i];
return true;
}
@@ -4004,38 +3754,35 @@ bool RasterizerGLES2::shadow_allocate_far(RID p_light) {
return false;
}
-
/* PARTICLES INSTANCE */
RID RasterizerGLES2::particles_instance_create(RID p_particles) {
- ERR_FAIL_COND_V(!particles_owner.owns(p_particles),RID());
- ParticlesInstance *particles_instance = memnew( ParticlesInstance );
- ERR_FAIL_COND_V(!particles_instance, RID() );
- particles_instance->particles=p_particles;
+ ERR_FAIL_COND_V(!particles_owner.owns(p_particles), RID());
+ ParticlesInstance *particles_instance = memnew(ParticlesInstance);
+ ERR_FAIL_COND_V(!particles_instance, RID());
+ particles_instance->particles = p_particles;
return particles_instance_owner.make_rid(particles_instance);
}
-void RasterizerGLES2::particles_instance_set_transform(RID p_particles_instance,const Transform& p_transform) {
+void RasterizerGLES2::particles_instance_set_transform(RID p_particles_instance, const Transform &p_transform) {
- ParticlesInstance *particles_instance=particles_instance_owner.get(p_particles_instance);
+ ParticlesInstance *particles_instance = particles_instance_owner.get(p_particles_instance);
ERR_FAIL_COND(!particles_instance);
- particles_instance->transform=p_transform;
+ particles_instance->transform = p_transform;
}
-
-
RID RasterizerGLES2::viewport_data_create() {
- ViewportData *vd = memnew( ViewportData );
+ ViewportData *vd = memnew(ViewportData);
glActiveTexture(GL_TEXTURE0);
glGenFramebuffers(1, &vd->lum_fbo);
glBindFramebuffer(GL_FRAMEBUFFER, vd->lum_fbo);
- GLuint format_luminance = use_fp16_fb?_GL_RG_EXT:GL_RGBA;
- GLuint format_luminance_type = use_fp16_fb?(full_float_fb_supported?GL_FLOAT:_GL_HALF_FLOAT_OES):GL_UNSIGNED_BYTE;
- GLuint format_luminance_components = use_fp16_fb?_GL_RG_EXT:GL_RGBA;
+ GLuint format_luminance = use_fp16_fb ? _GL_RG_EXT : GL_RGBA;
+ GLuint format_luminance_type = use_fp16_fb ? (full_float_fb_supported ? GL_FLOAT : _GL_HALF_FLOAT_OES) : GL_UNSIGNED_BYTE;
+ GLuint format_luminance_components = use_fp16_fb ? _GL_RG_EXT : GL_RGBA;
glGenTextures(1, &vd->lum_color);
glBindTexture(GL_TEXTURE_2D, vd->lum_color);
@@ -4048,11 +3795,10 @@ RID RasterizerGLES2::viewport_data_create() {
GL_RGBA, GL_UNSIGNED_BYTE, NULL);
*/
glTexImage2D(GL_TEXTURE_2D, 0, format_luminance, 1, 1, 0,
- format_luminance_components, format_luminance_type, NULL);
+ format_luminance_components, format_luminance_type, NULL);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
- GL_TEXTURE_2D, vd->lum_color, 0);
-
+ GL_TEXTURE_2D, vd->lum_color, 0);
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
@@ -4065,54 +3811,51 @@ RID RasterizerGLES2::viewport_data_create() {
return viewport_data_owner.make_rid(vd);
}
-RID RasterizerGLES2::render_target_create(){
+RID RasterizerGLES2::render_target_create() {
- RenderTarget *rt = memnew( RenderTarget );
- rt->fbo=0;
- rt->width=0;
- rt->height=0;
- rt->last_pass=0;
+ RenderTarget *rt = memnew(RenderTarget);
+ rt->fbo = 0;
+ rt->width = 0;
+ rt->height = 0;
+ rt->last_pass = 0;
Texture *texture = memnew(Texture);
- texture->active=false;
- texture->total_data_size=0;
- texture->render_target=rt;
- texture->ignore_mipmaps=true;
- rt->texture_ptr=texture;
- rt->texture=texture_owner.make_rid( texture );
- rt->texture_ptr->active=false;
+ texture->active = false;
+ texture->total_data_size = 0;
+ texture->render_target = rt;
+ texture->ignore_mipmaps = true;
+ rt->texture_ptr = texture;
+ rt->texture = texture_owner.make_rid(texture);
+ rt->texture_ptr->active = false;
return render_target_owner.make_rid(rt);
-
}
-void RasterizerGLES2::render_target_set_size(RID p_render_target,int p_width,int p_height){
+void RasterizerGLES2::render_target_set_size(RID p_render_target, int p_width, int p_height) {
RenderTarget *rt = render_target_owner.get(p_render_target);
- if (p_width==rt->width && p_height==rt->height)
+ if (p_width == rt->width && p_height == rt->height)
return;
- if (rt->width!=0 && rt->height!=0) {
-
- glDeleteFramebuffers(1,&rt->fbo);
- glDeleteRenderbuffers(1,&rt->depth);
- glDeleteTextures(1,&rt->color);
+ if (rt->width != 0 && rt->height != 0) {
- rt->fbo=0;
- rt->depth=0;
- rt->color=0;
- rt->width=0;
- rt->height=0;
- rt->texture_ptr->tex_id=0;
- rt->texture_ptr->active=false;
+ glDeleteFramebuffers(1, &rt->fbo);
+ glDeleteRenderbuffers(1, &rt->depth);
+ glDeleteTextures(1, &rt->color);
+ rt->fbo = 0;
+ rt->depth = 0;
+ rt->color = 0;
+ rt->width = 0;
+ rt->height = 0;
+ rt->texture_ptr->tex_id = 0;
+ rt->texture_ptr->active = false;
}
- if (p_width==0 || p_height==0)
+ if (p_width == 0 || p_height == 0)
return;
-
- rt->width=p_width;
- rt->height=p_height;
+ rt->width = p_width;
+ rt->height = p_height;
//fbo
glGenFramebuffers(1, &rt->fbo);
@@ -4121,9 +3864,9 @@ void RasterizerGLES2::render_target_set_size(RID p_render_target,int p_width,int
//depth
if (!low_memory_2d) {
glGenRenderbuffers(1, &rt->depth);
- glBindRenderbuffer(GL_RENDERBUFFER, rt->depth );
+ glBindRenderbuffer(GL_RENDERBUFFER, rt->depth);
- glRenderbufferStorage(GL_RENDERBUFFER, use_depth24?_DEPTH_COMPONENT24_OES:GL_DEPTH_COMPONENT16, rt->width,rt->height);
+ glRenderbufferStorage(GL_RENDERBUFFER, use_depth24 ? _DEPTH_COMPONENT24_OES : GL_DEPTH_COMPONENT16, rt->width, rt->height);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rt->depth);
}
@@ -4131,9 +3874,9 @@ void RasterizerGLES2::render_target_set_size(RID p_render_target,int p_width,int
//color
glGenTextures(1, &rt->color);
glBindTexture(GL_TEXTURE_2D, rt->color);
- 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, NULL);
- if (rt->texture_ptr->flags&VS::TEXTURE_FLAG_FILTER) {
+ if (rt->texture_ptr->flags & VS::TEXTURE_FLAG_FILTER) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
@@ -4146,157 +3889,139 @@ void RasterizerGLES2::render_target_set_size(RID p_render_target,int p_width,int
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, rt->color, 0);
- rt->texture_ptr->tex_id=rt->color;
- rt->texture_ptr->active=true;
- rt->texture_ptr->width=p_width;
- rt->texture_ptr->height=p_height;
+ rt->texture_ptr->tex_id = rt->color;
+ rt->texture_ptr->active = true;
+ rt->texture_ptr->width = p_width;
+ rt->texture_ptr->height = p_height;
#
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if (status != GL_FRAMEBUFFER_COMPLETE) {
- glDeleteRenderbuffers(1,&rt->fbo);
- glDeleteTextures(1,&rt->depth);
- glDeleteTextures(1,&rt->color);
- rt->fbo=0;
- rt->width=0;
- rt->height=0;
- rt->color=0;
- rt->depth=0;
- rt->texture_ptr->tex_id=0;
- rt->texture_ptr->active=false;
+ glDeleteRenderbuffers(1, &rt->fbo);
+ glDeleteTextures(1, &rt->depth);
+ glDeleteTextures(1, &rt->color);
+ rt->fbo = 0;
+ rt->width = 0;
+ rt->height = 0;
+ rt->color = 0;
+ rt->depth = 0;
+ rt->texture_ptr->tex_id = 0;
+ rt->texture_ptr->active = false;
WARN_PRINT("Could not create framebuffer!!");
}
glBindFramebuffer(GL_FRAMEBUFFER, base_framebuffer);
-
}
-RID RasterizerGLES2::render_target_get_texture(RID p_render_target) const{
+RID RasterizerGLES2::render_target_get_texture(RID p_render_target) const {
const RenderTarget *rt = render_target_owner.get(p_render_target);
- ERR_FAIL_COND_V(!rt,RID());
+ ERR_FAIL_COND_V(!rt, RID());
return rt->texture;
}
-bool RasterizerGLES2::render_target_renedered_in_frame(RID p_render_target){
+bool RasterizerGLES2::render_target_renedered_in_frame(RID p_render_target) {
RenderTarget *rt = render_target_owner.get(p_render_target);
- ERR_FAIL_COND_V(!rt,false);
- return rt->last_pass==frame;
+ ERR_FAIL_COND_V(!rt, false);
+ return rt->last_pass == frame;
}
-
/* RENDER API */
/* all calls (inside begin/end shadow) are always warranted to be in the following order: */
-
-
-
-
void RasterizerGLES2::begin_frame() {
-
-
-
_update_framebuffer();
glDepthFunc(GL_LEQUAL);
glFrontFace(GL_CW);
- //fragment_lighting=Globals::get_singleton()->get("rasterizer/use_fragment_lighting");
+//fragment_lighting=Globals::get_singleton()->get("rasterizer/use_fragment_lighting");
#ifdef TOOLS_ENABLED
- canvas_shader.set_conditional(CanvasShaderGLES2::USE_PIXEL_SNAP,GLOBAL_DEF("display/use_2d_pixel_snap",false));
- shadow_filter=ShadowFilterTechnique(int(GlobalConfig::get_singleton()->get("rasterizer/shadow_filter")));
+ canvas_shader.set_conditional(CanvasShaderGLES2::USE_PIXEL_SNAP, GLOBAL_DEF("display/use_2d_pixel_snap", false));
+ shadow_filter = ShadowFilterTechnique(int(GlobalConfig::get_singleton()->get("rasterizer/shadow_filter")));
#endif
- canvas_shader.set_conditional(CanvasShaderGLES2::SHADOW_PCF5,shadow_filter==SHADOW_FILTER_PCF5);
- canvas_shader.set_conditional(CanvasShaderGLES2::SHADOW_PCF13,shadow_filter==SHADOW_FILTER_PCF13);
- canvas_shader.set_conditional(CanvasShaderGLES2::SHADOW_ESM,shadow_filter==SHADOW_FILTER_ESM);
+ canvas_shader.set_conditional(CanvasShaderGLES2::SHADOW_PCF5, shadow_filter == SHADOW_FILTER_PCF5);
+ canvas_shader.set_conditional(CanvasShaderGLES2::SHADOW_PCF13, shadow_filter == SHADOW_FILTER_PCF13);
+ canvas_shader.set_conditional(CanvasShaderGLES2::SHADOW_ESM, shadow_filter == SHADOW_FILTER_ESM);
- window_size = Size2( OS::get_singleton()->get_video_mode().width, OS::get_singleton()->get_video_mode().height );
+ window_size = Size2(OS::get_singleton()->get_video_mode().width, OS::get_singleton()->get_video_mode().height);
- double time = (OS::get_singleton()->get_ticks_usec()/1000); // get msec
- time/=1000.0; // make secs
- time_delta=time-last_time;
- last_time=time;
+ double time = (OS::get_singleton()->get_ticks_usec() / 1000); // get msec
+ time /= 1000.0; // make secs
+ time_delta = time - last_time;
+ last_time = time;
frame++;
- _rinfo.vertex_count=0;
- _rinfo.object_count=0;
- _rinfo.mat_change_count=0;
- _rinfo.shader_change_count=0;
- _rinfo.ci_draw_commands=0;
- _rinfo.surface_count=0;
- _rinfo.draw_calls=0;
-
+ _rinfo.vertex_count = 0;
+ _rinfo.object_count = 0;
+ _rinfo.mat_change_count = 0;
+ _rinfo.shader_change_count = 0;
+ _rinfo.ci_draw_commands = 0;
+ _rinfo.surface_count = 0;
+ _rinfo.draw_calls = 0;
_update_fixed_materials();
- while(_shader_dirty_list.first()) {
+ while (_shader_dirty_list.first()) {
_update_shader(_shader_dirty_list.first()->self());
}
- while(_skeleton_dirty_list.first()) {
+ while (_skeleton_dirty_list.first()) {
+ Skeleton *s = _skeleton_dirty_list.first()->self();
- Skeleton *s=_skeleton_dirty_list.first()->self();
+ float *sk_float = (float *)skinned_buffer;
+ for (int i = 0; i < s->bones.size(); i++) {
- float *sk_float = (float*)skinned_buffer;
- for(int i=0;i<s->bones.size();i++) {
-
- float *m = &sk_float[i*12];
- const Skeleton::Bone &b=s->bones[i];
- m[0]=b.mtx[0][0];
- m[1]=b.mtx[1][0];
- m[2]=b.mtx[2][0];
- m[3]=b.mtx[3][0];
-
- m[4]=b.mtx[0][1];
- m[5]=b.mtx[1][1];
- m[6]=b.mtx[2][1];
- m[7]=b.mtx[3][1];
-
- m[8]=b.mtx[0][2];
- m[9]=b.mtx[1][2];
- m[10]=b.mtx[2][2];
- m[11]=b.mtx[3][2];
+ float *m = &sk_float[i * 12];
+ const Skeleton::Bone &b = s->bones[i];
+ m[0] = b.mtx[0][0];
+ m[1] = b.mtx[1][0];
+ m[2] = b.mtx[2][0];
+ m[3] = b.mtx[3][0];
+ m[4] = b.mtx[0][1];
+ m[5] = b.mtx[1][1];
+ m[6] = b.mtx[2][1];
+ m[7] = b.mtx[3][1];
+ m[8] = b.mtx[0][2];
+ m[9] = b.mtx[1][2];
+ m[10] = b.mtx[2][2];
+ m[11] = b.mtx[3][2];
}
-
glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D,s->tex_id);
- glTexSubImage2D(GL_TEXTURE_2D,0,0,0,nearest_power_of_2(s->bones.size()*3),1,GL_RGBA,GL_FLOAT,sk_float);
- _skeleton_dirty_list.remove( _skeleton_dirty_list.first() );
+ glBindTexture(GL_TEXTURE_2D, s->tex_id);
+ glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, nearest_power_of_2(s->bones.size() * 3), 1, GL_RGBA, GL_FLOAT, sk_float);
+ _skeleton_dirty_list.remove(_skeleton_dirty_list.first());
}
- while(_multimesh_dirty_list.first()) {
+ while (_multimesh_dirty_list.first()) {
+ MultiMesh *s = _multimesh_dirty_list.first()->self();
- MultiMesh *s=_multimesh_dirty_list.first()->self();
+ float *sk_float = (float *)skinned_buffer;
+ for (int i = 0; i < s->elements.size(); i++) {
- float *sk_float = (float*)skinned_buffer;
- for(int i=0;i<s->elements.size();i++) {
-
- float *m = &sk_float[i*16];
- const float *im=s->elements[i].matrix;
- for(int j=0;j<16;j++) {
- m[j]=im[j];
+ float *m = &sk_float[i * 16];
+ const float *im = s->elements[i].matrix;
+ for (int j = 0; j < 16; j++) {
+ m[j] = im[j];
}
-
}
-
glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D,s->tex_id);
- glTexSubImage2D(GL_TEXTURE_2D,0,0,0,s->tw,s->th,GL_RGBA,GL_FLOAT,sk_float);
- _multimesh_dirty_list.remove( _multimesh_dirty_list.first() );
+ glBindTexture(GL_TEXTURE_2D, s->tex_id);
+ glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, s->tw, s->th, GL_RGBA, GL_FLOAT, sk_float);
+ _multimesh_dirty_list.remove(_multimesh_dirty_list.first());
}
-
- draw_next_frame=false;
+ draw_next_frame = false;
//material_shader.set_uniform_default(MaterialShaderGLES2::SCREENZ_SCALE, Math::fmod(time, 3600.0));
/* nehe ?*/
@@ -4304,7 +4029,7 @@ void RasterizerGLES2::begin_frame() {
//glClear(GL_COLOR_BUFFER_BIT); //should not clear if anything else cleared..
}
-void RasterizerGLES2::capture_viewport(Image* r_capture) {
+void RasterizerGLES2::capture_viewport(Image *r_capture) {
#if 0
PoolVector<uint8_t> pixels;
pixels.resize(viewport.width*viewport.height*3);
@@ -4325,9 +4050,8 @@ void RasterizerGLES2::capture_viewport(Image* r_capture) {
r_capture->create(viewport.width,viewport.height,0,Image::FORMAT_RGB8,pixels);
#else
-
PoolVector<uint8_t> pixels;
- pixels.resize(viewport.width*viewport.height*4);
+ pixels.resize(viewport.width * viewport.height * 4);
PoolVector<uint8_t>::Write w = pixels.write();
glPixelStorei(GL_PACK_ALIGNMENT, 4);
@@ -4337,186 +4061,176 @@ void RasterizerGLES2::capture_viewport(Image* r_capture) {
#ifdef GLEW_ENABLED
glReadBuffer(GL_COLOR_ATTACHMENT0);
#endif
- glReadPixels( 0, 0, viewport.width, viewport.height,GL_RGBA,GL_UNSIGNED_BYTE,w.ptr() );
+ glReadPixels(0, 0, viewport.width, viewport.height, GL_RGBA, GL_UNSIGNED_BYTE, w.ptr());
} else {
// back?
- glReadPixels( viewport.x, window_size.height-(viewport.height+viewport.y), viewport.width,viewport.height,GL_RGBA,GL_UNSIGNED_BYTE,w.ptr());
+ glReadPixels(viewport.x, window_size.height - (viewport.height + viewport.y), viewport.width, viewport.height, GL_RGBA, GL_UNSIGNED_BYTE, w.ptr());
}
- bool flip = current_rt==NULL;
+ bool flip = current_rt == NULL;
if (flip) {
- uint32_t *imgptr = (uint32_t*)w.ptr();
- for(int y=0;y<(viewport.height/2);y++) {
+ uint32_t *imgptr = (uint32_t *)w.ptr();
+ for (int y = 0; y < (viewport.height / 2); y++) {
- uint32_t *ptr1 = &imgptr[y*viewport.width];
- uint32_t *ptr2 = &imgptr[(viewport.height-y-1)*viewport.width];
+ uint32_t *ptr1 = &imgptr[y * viewport.width];
+ uint32_t *ptr2 = &imgptr[(viewport.height - y - 1) * viewport.width];
- for(int x=0;x<viewport.width;x++) {
+ for (int x = 0; x < viewport.width; x++) {
uint32_t tmp = ptr1[x];
- ptr1[x]=ptr2[x];
- ptr2[x]=tmp;
+ ptr1[x] = ptr2[x];
+ ptr2[x] = tmp;
}
}
}
- w=PoolVector<uint8_t>::Write();
- r_capture->create(viewport.width,viewport.height,0,Image::FORMAT_RGBA8,pixels);
- //r_capture->flip_y();
-
+ w = PoolVector<uint8_t>::Write();
+ r_capture->create(viewport.width, viewport.height, 0, Image::FORMAT_RGBA8, pixels);
+//r_capture->flip_y();
#endif
-
}
-
-void RasterizerGLES2::clear_viewport(const Color& p_color) {
+void RasterizerGLES2::clear_viewport(const Color &p_color) {
if (current_rt || using_canvas_bg) {
- glScissor( 0, 0, viewport.width, viewport.height );
+ glScissor(0, 0, viewport.width, viewport.height);
} else {
- glScissor( viewport.x, window_size.height-(viewport.height+viewport.y), viewport.width,viewport.height );
+ glScissor(viewport.x, window_size.height - (viewport.height + viewport.y), viewport.width, viewport.height);
}
glEnable(GL_SCISSOR_TEST);
- glClearColor(p_color.r,p_color.g,p_color.b,p_color.a);
+ glClearColor(p_color.r, p_color.g, p_color.b, p_color.a);
glClear(GL_COLOR_BUFFER_BIT); //should not clear if anything else cleared..
glDisable(GL_SCISSOR_TEST);
};
-
void RasterizerGLES2::set_render_target(RID p_render_target, bool p_transparent_bg, bool p_vflip) {
-
-
if (!p_render_target.is_valid()) {
- glBindFramebuffer(GL_FRAMEBUFFER,base_framebuffer);
- current_rt=NULL;
- current_rt_vflip=false;
+ glBindFramebuffer(GL_FRAMEBUFFER, base_framebuffer);
+ current_rt = NULL;
+ current_rt_vflip = false;
} else {
RenderTarget *rt = render_target_owner.get(p_render_target);
ERR_FAIL_COND(!rt);
- ERR_FAIL_COND(rt->fbo==0);
- glBindFramebuffer(GL_FRAMEBUFFER,rt->fbo);
- current_rt=rt;
- current_rt_transparent=p_transparent_bg;
- current_rt_vflip=!p_vflip;
+ ERR_FAIL_COND(rt->fbo == 0);
+ glBindFramebuffer(GL_FRAMEBUFFER, rt->fbo);
+ current_rt = rt;
+ current_rt_transparent = p_transparent_bg;
+ current_rt_vflip = !p_vflip;
}
-
}
-void RasterizerGLES2::set_viewport(const VS::ViewportRect& p_viewport) {
+void RasterizerGLES2::set_viewport(const VS::ViewportRect &p_viewport) {
- viewport=p_viewport;
+ viewport = p_viewport;
//viewport.width/=2;
//viewport.height/=2;
//print_line("viewport: "+itos(p_viewport.x)+","+itos(p_viewport.y)+","+itos(p_viewport.width)+","+itos(p_viewport.height));
if (current_rt) {
- glViewport( 0, 0,viewport.width, viewport.height );
+ glViewport(0, 0, viewport.width, viewport.height);
} else {
- glViewport( viewport.x, window_size.height-(viewport.height+viewport.y), viewport.width,viewport.height );
+ glViewport(viewport.x, window_size.height - (viewport.height + viewport.y), viewport.width, viewport.height);
}
}
-void RasterizerGLES2::begin_scene(RID p_viewport_data,RID p_env,VS::ScenarioDebugMode p_debug) {
-
+void RasterizerGLES2::begin_scene(RID p_viewport_data, RID p_env, VS::ScenarioDebugMode p_debug) {
- current_debug=p_debug;
+ current_debug = p_debug;
opaque_render_list.clear();
alpha_render_list.clear();
- light_instance_count=0;
+ light_instance_count = 0;
current_env = p_env.is_valid() ? environment_owner.get(p_env) : NULL;
scene_pass++;
- last_light_id=0;
- directional_light_count=0;
- lights_use_shadow=false;
- texscreen_used=false;
- current_vd=viewport_data_owner.get(p_viewport_data);
- if (current_debug==VS::SCENARIO_DEBUG_WIREFRAME) {
+ last_light_id = 0;
+ directional_light_count = 0;
+ lights_use_shadow = false;
+ texscreen_used = false;
+ current_vd = viewport_data_owner.get(p_viewport_data);
+ if (current_debug == VS::SCENARIO_DEBUG_WIREFRAME) {
#ifdef GLEW_ENABLED
- glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
+ glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
#endif
}
//set state
glCullFace(GL_FRONT);
- cull_front=true;
+ cull_front = true;
};
-void RasterizerGLES2::begin_shadow_map( RID p_light_instance, int p_shadow_pass ) {
+void RasterizerGLES2::begin_shadow_map(RID p_light_instance, int p_shadow_pass) {
ERR_FAIL_COND(shadow);
shadow = light_instance_owner.get(p_light_instance);
- shadow_pass=p_shadow_pass;
+ shadow_pass = p_shadow_pass;
ERR_FAIL_COND(!shadow);
opaque_render_list.clear();
alpha_render_list.clear();
//pre_zpass_render_list.clear();
- light_instance_count=0;
+ light_instance_count = 0;
glCullFace(GL_FRONT);
- cull_front=true;
-
+ cull_front = true;
}
-void RasterizerGLES2::set_camera(const Transform& p_world,const CameraMatrix& p_projection,bool p_ortho_hint) {
+void RasterizerGLES2::set_camera(const Transform &p_world, const CameraMatrix &p_projection, bool p_ortho_hint) {
- camera_transform=p_world;
+ camera_transform = p_world;
if (current_rt && current_rt_vflip) {
- camera_transform.basis.set_axis(1,-camera_transform.basis.get_axis(1));
+ camera_transform.basis.set_axis(1, -camera_transform.basis.get_axis(1));
}
- camera_transform_inverse=camera_transform.inverse();
- camera_projection=p_projection;
- camera_plane = Plane( camera_transform.origin, -camera_transform.basis.get_axis(2) );
- camera_z_near=camera_projection.get_z_near();
- camera_z_far=camera_projection.get_z_far();
- camera_projection.get_viewport_size(camera_vp_size.x,camera_vp_size.y);
- camera_ortho=p_ortho_hint;
+ camera_transform_inverse = camera_transform.inverse();
+ camera_projection = p_projection;
+ camera_plane = Plane(camera_transform.origin, -camera_transform.basis.get_axis(2));
+ camera_z_near = camera_projection.get_z_near();
+ camera_z_far = camera_projection.get_z_far();
+ camera_projection.get_viewport_size(camera_vp_size.x, camera_vp_size.y);
+ camera_ortho = p_ortho_hint;
}
-void RasterizerGLES2::add_light( RID p_light_instance ) {
+void RasterizerGLES2::add_light(RID p_light_instance) {
#define LIGHT_FADE_TRESHOLD 0.05
- ERR_FAIL_COND( light_instance_count >= MAX_SCENE_LIGHTS );
+ ERR_FAIL_COND(light_instance_count >= MAX_SCENE_LIGHTS);
LightInstance *li = light_instance_owner.get(p_light_instance);
ERR_FAIL_COND(!li);
-
- switch(li->base->type) {
+ switch (li->base->type) {
case VS::LIGHT_DIRECTIONAL: {
- ERR_FAIL_COND( directional_light_count >= RenderList::MAX_LIGHTS);
- directional_lights[directional_light_count++]=li;
+ ERR_FAIL_COND(directional_light_count >= RenderList::MAX_LIGHTS);
+ directional_lights[directional_light_count++] = li;
if (li->base->shadow_enabled) {
CameraMatrix bias;
bias.set_light_bias();
- int passes=light_instance_get_shadow_passes(p_light_instance);
+ int passes = light_instance_get_shadow_passes(p_light_instance);
- for(int i=0;i<passes;i++) {
- Transform modelview=Transform(camera_transform_inverse * li->custom_transform[i]).inverse();
+ for (int i = 0; i < passes; i++) {
+ Transform modelview = Transform(camera_transform_inverse * li->custom_transform[i]).inverse();
li->shadow_projection[i] = bias * li->custom_projection[i] * modelview;
}
- lights_use_shadow=true;
+ lights_use_shadow = true;
}
} break;
case VS::LIGHT_OMNI: {
if (li->base->shadow_enabled) {
li->shadow_projection[0] = Transform(camera_transform_inverse * li->transform).inverse();
- lights_use_shadow=true;
+ lights_use_shadow = true;
}
} break;
case VS::LIGHT_SPOT: {
@@ -4524,34 +4238,29 @@ void RasterizerGLES2::add_light( RID p_light_instance ) {
if (li->base->shadow_enabled) {
CameraMatrix bias;
bias.set_light_bias();
- Transform modelview=Transform(camera_transform_inverse * li->transform).inverse();
+ Transform modelview = Transform(camera_transform_inverse * li->transform).inverse();
li->shadow_projection[0] = bias * li->projection * modelview;
- lights_use_shadow=true;
+ lights_use_shadow = true;
}
} break;
-
}
-
/* make light hash */
// actually, not really a hash, but helps to sort the lights
// and avoid recompiling redudant shader versions
+ li->last_pass = scene_pass;
+ li->sort_key = light_instance_count;
- li->last_pass=scene_pass;
- li->sort_key=light_instance_count;
-
- light_instances[light_instance_count++]=li;
-
+ light_instances[light_instance_count++] = li;
}
-void RasterizerGLES2::_update_shader( Shader* p_shader) const {
+void RasterizerGLES2::_update_shader(Shader *p_shader) const {
- _shader_dirty_list.remove( &p_shader->dirty_list );
-
- p_shader->valid=false;
+ _shader_dirty_list.remove(&p_shader->dirty_list);
+ p_shader->valid = false;
p_shader->uniforms.clear();
Vector<StringName> uniform_names;
@@ -4562,18 +4271,17 @@ void RasterizerGLES2::_update_shader( Shader* p_shader) const {
ShaderCompilerGLES2::Flags fragment_flags;
ShaderCompilerGLES2::Flags light_flags;
- if (p_shader->mode==VS::SHADER_MATERIAL) {
- Error err = shader_precompiler.compile(p_shader->vertex_code,ShaderLanguage::SHADER_MATERIAL_VERTEX,vertex_code,vertex_globals,vertex_flags,&p_shader->uniforms);
+ if (p_shader->mode == VS::SHADER_MATERIAL) {
+ Error err = shader_precompiler.compile(p_shader->vertex_code, ShaderLanguage::SHADER_MATERIAL_VERTEX, vertex_code, vertex_globals, vertex_flags, &p_shader->uniforms);
if (err) {
return; //invalid
}
- } else if (p_shader->mode==VS::SHADER_CANVAS_ITEM) {
+ } else if (p_shader->mode == VS::SHADER_CANVAS_ITEM) {
- Error err = shader_precompiler.compile(p_shader->vertex_code,ShaderLanguage::SHADER_CANVAS_ITEM_VERTEX,vertex_code,vertex_globals,vertex_flags,&p_shader->uniforms);
+ Error err = shader_precompiler.compile(p_shader->vertex_code, ShaderLanguage::SHADER_CANVAS_ITEM_VERTEX, vertex_code, vertex_globals, vertex_flags, &p_shader->uniforms);
if (err) {
return; //invalid
}
-
}
//print_line("compiled vertex: "+vertex_code);
@@ -4583,60 +4291,58 @@ void RasterizerGLES2::_update_shader( Shader* p_shader) const {
String fragment_code;
String fragment_globals;
- if (p_shader->mode==VS::SHADER_MATERIAL) {
- Error err = shader_precompiler.compile(p_shader->fragment_code,ShaderLanguage::SHADER_MATERIAL_FRAGMENT,fragment_code,fragment_globals,fragment_flags,&p_shader->uniforms);
+ if (p_shader->mode == VS::SHADER_MATERIAL) {
+ Error err = shader_precompiler.compile(p_shader->fragment_code, ShaderLanguage::SHADER_MATERIAL_FRAGMENT, fragment_code, fragment_globals, fragment_flags, &p_shader->uniforms);
if (err) {
return; //invalid
}
- } else if (p_shader->mode==VS::SHADER_CANVAS_ITEM) {
- Error err = shader_precompiler.compile(p_shader->fragment_code,ShaderLanguage::SHADER_CANVAS_ITEM_FRAGMENT,fragment_code,fragment_globals,fragment_flags,&p_shader->uniforms);
+ } else if (p_shader->mode == VS::SHADER_CANVAS_ITEM) {
+ Error err = shader_precompiler.compile(p_shader->fragment_code, ShaderLanguage::SHADER_CANVAS_ITEM_FRAGMENT, fragment_code, fragment_globals, fragment_flags, &p_shader->uniforms);
if (err) {
return; //invalid
}
}
-
String light_code;
String light_globals;
- if (p_shader->mode==VS::SHADER_MATERIAL) {
+ if (p_shader->mode == VS::SHADER_MATERIAL) {
- Error err = shader_precompiler.compile(p_shader->light_code,(ShaderLanguage::SHADER_MATERIAL_LIGHT),light_code,light_globals,light_flags,&p_shader->uniforms);
+ Error err = shader_precompiler.compile(p_shader->light_code, (ShaderLanguage::SHADER_MATERIAL_LIGHT), light_code, light_globals, light_flags, &p_shader->uniforms);
if (err) {
return; //invalid
}
- } else if (p_shader->mode==VS::SHADER_CANVAS_ITEM) {
- Error err = shader_precompiler.compile(p_shader->light_code,(ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT),light_code,light_globals,light_flags,&p_shader->uniforms);
+ } else if (p_shader->mode == VS::SHADER_CANVAS_ITEM) {
+ Error err = shader_precompiler.compile(p_shader->light_code, (ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT), light_code, light_globals, light_flags, &p_shader->uniforms);
if (err) {
return; //invalid
}
}
- fragment_globals+=light_globals; //both fragment anyway
-
+ fragment_globals += light_globals; //both fragment anyway
//print_line("compiled fragment: "+fragment_code);
//("compiled fragment globals: "+fragment_globals);
//print_line("UCF: "+itos(p_shader->uniforms.size()));
- int first_tex_index=0xFFFFF;
- p_shader->first_texture=StringName();
+ int first_tex_index = 0xFFFFF;
+ p_shader->first_texture = StringName();
- for(Map<StringName,ShaderLanguage::Uniform>::Element *E=p_shader->uniforms.front();E;E=E->next()) {
+ for (Map<StringName, ShaderLanguage::Uniform>::Element *E = p_shader->uniforms.front(); E; E = E->next()) {
- uniform_names.push_back("_"+String(E->key()));
- if (E->get().type==ShaderLanguage::TYPE_TEXTURE && E->get().order<first_tex_index) {
- p_shader->first_texture=E->key();
- first_tex_index=E->get().order;
+ uniform_names.push_back("_" + String(E->key()));
+ if (E->get().type == ShaderLanguage::TYPE_TEXTURE && E->get().order < first_tex_index) {
+ p_shader->first_texture = E->key();
+ first_tex_index = E->get().order;
}
}
- bool uses_time=false;
+ bool uses_time = false;
- if (p_shader->mode==VS::SHADER_MATERIAL) {
+ if (p_shader->mode == VS::SHADER_MATERIAL) {
//print_line("setting code to id.. "+itos(p_shader->custom_code_id));
- Vector<const char*> enablers;
+ Vector<const char *> enablers;
if (fragment_flags.use_color_interp || vertex_flags.use_color_interp)
enablers.push_back("#define ENABLE_COLOR_INTERP\n");
if (fragment_flags.use_uv_interp || vertex_flags.use_uv_interp)
@@ -4669,20 +4375,20 @@ void RasterizerGLES2::_update_shader( Shader* p_shader) const {
}
if (light_flags.uses_time || fragment_flags.uses_time || vertex_flags.uses_time) {
enablers.push_back("#define USE_TIME\n");
- uses_time=true;
+ uses_time = true;
}
if (vertex_flags.vertex_code_writes_position) {
enablers.push_back("#define VERTEX_SHADER_WRITE_POSITION\n");
}
- material_shader.set_custom_shader_code(p_shader->custom_code_id,vertex_code, vertex_globals,fragment_code, light_code, fragment_globals,uniform_names,enablers);
- } else if (p_shader->mode==VS::SHADER_CANVAS_ITEM) {
+ material_shader.set_custom_shader_code(p_shader->custom_code_id, vertex_code, vertex_globals, fragment_code, light_code, fragment_globals, uniform_names, enablers);
+ } else if (p_shader->mode == VS::SHADER_CANVAS_ITEM) {
- Vector<const char*> enablers;
+ Vector<const char *> enablers;
if (light_flags.uses_time || fragment_flags.uses_time || vertex_flags.uses_time) {
enablers.push_back("#define USE_TIME\n");
- uses_time=true;
+ uses_time = true;
}
if (fragment_flags.uses_normal) {
enablers.push_back("#define NORMAL_USED\n");
@@ -4714,117 +4420,109 @@ void RasterizerGLES2::_update_shader( Shader* p_shader) const {
if (vertex_flags.uses_worldvec) {
enablers.push_back("#define USE_WORLD_VEC\n");
}
- canvas_shader.set_custom_shader_code(p_shader->custom_code_id,vertex_code, vertex_globals,fragment_code, light_code, fragment_globals,uniform_names,enablers);
+ canvas_shader.set_custom_shader_code(p_shader->custom_code_id, vertex_code, vertex_globals, fragment_code, light_code, fragment_globals, uniform_names, enablers);
//postprocess_shader.set_custom_shader_code(p_shader->custom_code_id,vertex_code, vertex_globals,fragment_code, fragment_globals,uniform_names);
}
- p_shader->valid=true;
- p_shader->has_alpha=fragment_flags.uses_alpha || fragment_flags.uses_texscreen;
- p_shader->writes_vertex=vertex_flags.vertex_code_writes_vertex;
- p_shader->uses_discard=fragment_flags.uses_discard;
- p_shader->has_texscreen=fragment_flags.uses_texscreen;
- p_shader->has_screen_uv=fragment_flags.uses_screen_uv;
- p_shader->can_zpass=!fragment_flags.uses_discard && !vertex_flags.vertex_code_writes_vertex;
- p_shader->uses_normal=fragment_flags.uses_normal || light_flags.uses_normal;
- p_shader->uses_time=uses_time;
- p_shader->uses_texpixel_size=fragment_flags.uses_texpixel_size;
+ p_shader->valid = true;
+ p_shader->has_alpha = fragment_flags.uses_alpha || fragment_flags.uses_texscreen;
+ p_shader->writes_vertex = vertex_flags.vertex_code_writes_vertex;
+ p_shader->uses_discard = fragment_flags.uses_discard;
+ p_shader->has_texscreen = fragment_flags.uses_texscreen;
+ p_shader->has_screen_uv = fragment_flags.uses_screen_uv;
+ p_shader->can_zpass = !fragment_flags.uses_discard && !vertex_flags.vertex_code_writes_vertex;
+ p_shader->uses_normal = fragment_flags.uses_normal || light_flags.uses_normal;
+ p_shader->uses_time = uses_time;
+ p_shader->uses_texpixel_size = fragment_flags.uses_texpixel_size;
p_shader->version++;
-
}
+void RasterizerGLES2::_add_geometry(const Geometry *p_geometry, const InstanceData *p_instance, const Geometry *p_geometry_cmp, const GeometryOwner *p_owner, int p_material) {
-void RasterizerGLES2::_add_geometry( const Geometry* p_geometry, const InstanceData *p_instance, const Geometry *p_geometry_cmp, const GeometryOwner *p_owner,int p_material) {
-
- Material *m=NULL;
- RID m_src=p_instance->material_override.is_valid() ? p_instance->material_override :(p_material>=0?p_instance->materials[p_material]:p_geometry->material);
+ Material *m = NULL;
+ RID m_src = p_instance->material_override.is_valid() ? p_instance->material_override : (p_material >= 0 ? p_instance->materials[p_material] : p_geometry->material);
#ifdef DEBUG_ENABLED
- if (current_debug==VS::SCENARIO_DEBUG_OVERDRAW) {
- m_src=overdraw_material;
+ if (current_debug == VS::SCENARIO_DEBUG_OVERDRAW) {
+ m_src = overdraw_material;
}
#endif
if (m_src)
- m=material_owner.get( m_src );
+ m = material_owner.get(m_src);
if (!m) {
- m=material_owner.get( default_material );
+ m = material_owner.get(default_material);
}
ERR_FAIL_COND(!m);
- if (m->last_pass!=frame) {
+ if (m->last_pass != frame) {
if (m->shader.is_valid()) {
- m->shader_cache=shader_owner.get(m->shader);
+ m->shader_cache = shader_owner.get(m->shader);
if (m->shader_cache) {
-
-
if (!m->shader_cache->valid) {
- m->shader_cache=NULL;
+ m->shader_cache = NULL;
} else {
if (m->shader_cache->has_texscreen)
- texscreen_used=true;
+ texscreen_used = true;
}
} else {
- m->shader=RID();
+ m->shader = RID();
}
} else {
- m->shader_cache=NULL;
+ m->shader_cache = NULL;
}
- m->last_pass=frame;
+ m->last_pass = frame;
}
+ RenderList *render_list = NULL;
-
- RenderList *render_list=NULL;
-
- bool has_base_alpha=(m->shader_cache && m->shader_cache->has_alpha);
- bool has_blend_alpha=m->blend_mode!=VS::MATERIAL_BLEND_MODE_MIX || m->flags[VS::MATERIAL_FLAG_ONTOP];
+ bool has_base_alpha = (m->shader_cache && m->shader_cache->has_alpha);
+ bool has_blend_alpha = m->blend_mode != VS::MATERIAL_BLEND_MODE_MIX || m->flags[VS::MATERIAL_FLAG_ONTOP];
bool has_alpha = has_base_alpha || has_blend_alpha;
-
if (shadow) {
- if (has_blend_alpha || (has_base_alpha && m->depth_draw_mode!=VS::MATERIAL_DEPTH_DRAW_OPAQUE_PRE_PASS_ALPHA))
+ if (has_blend_alpha || (has_base_alpha && m->depth_draw_mode != VS::MATERIAL_DEPTH_DRAW_OPAQUE_PRE_PASS_ALPHA))
return; //bye
- if (!m->shader_cache || (!m->shader_cache->writes_vertex && !m->shader_cache->uses_discard && m->depth_draw_mode!=VS::MATERIAL_DEPTH_DRAW_OPAQUE_PRE_PASS_ALPHA)) {
+ if (!m->shader_cache || (!m->shader_cache->writes_vertex && !m->shader_cache->uses_discard && m->depth_draw_mode != VS::MATERIAL_DEPTH_DRAW_OPAQUE_PRE_PASS_ALPHA)) {
//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)
m = shadow_mat_double_sided_ptr;
else
m = shadow_mat_ptr;
- if (m->last_pass!=frame) {
+ if (m->last_pass != frame) {
if (m->shader.is_valid()) {
- m->shader_cache=shader_owner.get(m->shader);
+ m->shader_cache = shader_owner.get(m->shader);
if (m->shader_cache) {
-
if (!m->shader_cache->valid)
- m->shader_cache=NULL;
+ m->shader_cache = NULL;
} else {
- m->shader=RID();
+ m->shader = RID();
}
} else {
- m->shader_cache=NULL;
+ m->shader_cache = NULL;
}
- m->last_pass=frame;
+ m->last_pass = frame;
}
}
render_list = &opaque_render_list;
- /* notyet
+ /* notyet
if (!m->shader_cache || m->shader_cache->can_zpass)
render_list = &alpha_render_list;
} else {
@@ -4836,56 +4534,51 @@ void RasterizerGLES2::_add_geometry( const Geometry* p_geometry, const InstanceD
render_list = &alpha_render_list;
} else {
render_list = &opaque_render_list;
-
}
}
-
RenderList::Element *e = render_list->add_element();
if (!e)
return;
- e->geometry=p_geometry;
- e->geometry_cmp=p_geometry_cmp;
- e->material=m;
- e->instance=p_instance;
+ e->geometry = p_geometry;
+ e->geometry_cmp = p_geometry_cmp;
+ e->material = m;
+ e->instance = p_instance;
if (camera_ortho) {
- e->depth=camera_plane.distance_to(p_instance->transform.origin);
+ e->depth = camera_plane.distance_to(p_instance->transform.origin);
} else {
- e->depth=camera_transform.origin.distance_to(p_instance->transform.origin);
+ e->depth = camera_transform.origin.distance_to(p_instance->transform.origin);
}
- e->owner=p_owner;
- e->light_type=0;
- e->additive=false;
- e->additive_ptr=&e->additive;
- e->sort_flags=0;
-
+ e->owner = p_owner;
+ e->light_type = 0;
+ e->additive = false;
+ e->additive_ptr = &e->additive;
+ e->sort_flags = 0;
if (p_instance->skeleton.is_valid()) {
- e->skeleton=skeleton_owner.get(p_instance->skeleton);
+ e->skeleton = skeleton_owner.get(p_instance->skeleton);
if (!e->skeleton)
- const_cast<InstanceData*>(p_instance)->skeleton=RID();
+ const_cast<InstanceData *>(p_instance)->skeleton = RID();
else
- e->sort_flags|=RenderList::SORT_FLAG_SKELETON;
+ e->sort_flags |= RenderList::SORT_FLAG_SKELETON;
} else {
- e->skeleton=NULL;
-
+ e->skeleton = NULL;
}
- if (e->geometry->type==Geometry::GEOMETRY_MULTISURFACE)
- e->sort_flags|=RenderList::SORT_FLAG_INSTANCING;
-
+ if (e->geometry->type == Geometry::GEOMETRY_MULTISURFACE)
+ e->sort_flags |= RenderList::SORT_FLAG_INSTANCING;
- e->mirror=p_instance->mirror;
+ e->mirror = p_instance->mirror;
if (m->flags[VS::MATERIAL_FLAG_INVERT_FACES])
- e->mirror=!e->mirror;
+ e->mirror = !e->mirror;
//e->light_type=0xFF; // no lights!
- e->light_type=3; //light type 3 is no light?
- e->light=0xFFFF;
+ e->light_type = 3; //light type 3 is no light?
+ e->light = 0xFFFF;
- if (!shadow && !has_blend_alpha && has_alpha && m->depth_draw_mode==VS::MATERIAL_DEPTH_DRAW_OPAQUE_PRE_PASS_ALPHA) {
+ if (!shadow && !has_blend_alpha && has_alpha && m->depth_draw_mode == VS::MATERIAL_DEPTH_DRAW_OPAQUE_PRE_PASS_ALPHA) {
//if nothing exists, add this element as opaque too
RenderList::Element *oe = opaque_render_list.add_element();
@@ -4893,108 +4586,96 @@ void RasterizerGLES2::_add_geometry( const Geometry* p_geometry, const InstanceD
if (!oe)
return;
- memcpy(oe,e,sizeof(RenderList::Element));
- oe->additive_ptr=&oe->additive;
+ memcpy(oe, e, sizeof(RenderList::Element));
+ oe->additive_ptr = &oe->additive;
}
- if (shadow || m->flags[VS::MATERIAL_FLAG_UNSHADED] || current_debug==VS::SCENARIO_DEBUG_SHADELESS) {
+ if (shadow || m->flags[VS::MATERIAL_FLAG_UNSHADED] || current_debug == VS::SCENARIO_DEBUG_SHADELESS) {
- e->light_type=0x7F; //unshaded is zero
+ e->light_type = 0x7F; //unshaded is zero
} else {
- bool duplicate=false;
+ bool duplicate = false;
-
- for(int i=0;i<directional_light_count;i++) {
+ for (int i = 0; i < directional_light_count; i++) {
uint16_t sort_key = directional_lights[i]->sort_key;
uint8_t light_type = VS::LIGHT_DIRECTIONAL;
if (directional_lights[i]->base->shadow_enabled) {
- light_type|=0x8;
- if (directional_lights[i]->base->directional_shadow_mode==VS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_2_SPLITS)
- light_type|=0x10;
- else if (directional_lights[i]->base->directional_shadow_mode==VS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_4_SPLITS)
- light_type|=0x30;
-
+ light_type |= 0x8;
+ if (directional_lights[i]->base->directional_shadow_mode == VS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_2_SPLITS)
+ light_type |= 0x10;
+ else if (directional_lights[i]->base->directional_shadow_mode == VS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_4_SPLITS)
+ light_type |= 0x30;
}
RenderList::Element *ec;
if (duplicate) {
ec = render_list->add_element();
- memcpy(ec,e,sizeof(RenderList::Element));
+ memcpy(ec, e, sizeof(RenderList::Element));
} else {
- ec=e;
- duplicate=true;
+ ec = e;
+ duplicate = true;
}
- ec->light_type=light_type;
- ec->light=sort_key;
- ec->additive_ptr=&e->additive;
-
+ ec->light_type = light_type;
+ ec->light = sort_key;
+ ec->additive_ptr = &e->additive;
}
-
const RID *liptr = p_instance->light_instances.ptr();
- int ilc=p_instance->light_instances.size();
-
-
+ int ilc = p_instance->light_instances.size();
- for(int i=0;i<ilc;i++) {
+ for (int i = 0; i < ilc; i++) {
- LightInstance *li=light_instance_owner.get( liptr[i] );
- if (!li || li->last_pass!=scene_pass) //lit by light not in visible scene
+ LightInstance *li = light_instance_owner.get(liptr[i]);
+ if (!li || li->last_pass != scene_pass) //lit by light not in visible scene
continue;
- uint8_t light_type=li->base->type|0x40; //penalty to ensure directionals always go first
+ uint8_t light_type = li->base->type | 0x40; //penalty to ensure directionals always go first
if (li->base->shadow_enabled) {
- light_type|=0x8;
+ light_type |= 0x8;
}
- uint16_t sort_key =li->sort_key;
+ uint16_t sort_key = li->sort_key;
RenderList::Element *ec;
if (duplicate) {
ec = render_list->add_element();
- memcpy(ec,e,sizeof(RenderList::Element));
+ memcpy(ec, e, sizeof(RenderList::Element));
} else {
- duplicate=true;
- ec=e;
+ duplicate = true;
+ ec = e;
}
- ec->light_type=light_type;
- ec->light=sort_key;
- ec->additive_ptr=&e->additive;
-
+ ec->light_type = light_type;
+ ec->light = sort_key;
+ ec->additive_ptr = &e->additive;
}
-
-
-
}
DEBUG_TEST_ERROR("Add Geometry");
-
}
-void RasterizerGLES2::add_mesh( const RID& p_mesh, const InstanceData *p_data) {
+void RasterizerGLES2::add_mesh(const RID &p_mesh, const InstanceData *p_data) {
Mesh *mesh = mesh_owner.get(p_mesh);
ERR_FAIL_COND(!mesh);
int ssize = mesh->surfaces.size();
- for (int i=0;i<ssize;i++) {
+ for (int i = 0; i < ssize; i++) {
int mat_idx = p_data->materials[i].is_valid() ? i : -1;
Surface *s = mesh->surfaces[i];
- _add_geometry(s,p_data,s,NULL,mat_idx);
+ _add_geometry(s, p_data, s, NULL, mat_idx);
}
- mesh->last_pass=frame;
-
+ mesh->last_pass = frame;
}
-void RasterizerGLES2::add_multimesh( const RID& p_multimesh, const InstanceData *p_data){
+void RasterizerGLES2::add_multimesh(const RID &p_multimesh, const InstanceData *p_data) {
MultiMesh *multimesh = multimesh_owner.get(p_multimesh);
ERR_FAIL_COND(!multimesh);
@@ -5008,52 +4689,46 @@ void RasterizerGLES2::add_multimesh( const RID& p_multimesh, const InstanceData
ERR_FAIL_COND(!mesh);
int surf_count = mesh->surfaces.size();
- if (multimesh->last_pass!=scene_pass) {
+ if (multimesh->last_pass != scene_pass) {
multimesh->cache_surfaces.resize(surf_count);
- for(int i=0;i<surf_count;i++) {
+ for (int i = 0; i < surf_count; i++) {
- multimesh->cache_surfaces[i].material=mesh->surfaces[i]->material;
- multimesh->cache_surfaces[i].has_alpha=mesh->surfaces[i]->has_alpha;
- multimesh->cache_surfaces[i].surface=mesh->surfaces[i];
+ multimesh->cache_surfaces[i].material = mesh->surfaces[i]->material;
+ multimesh->cache_surfaces[i].has_alpha = mesh->surfaces[i]->has_alpha;
+ multimesh->cache_surfaces[i].surface = mesh->surfaces[i];
}
- multimesh->last_pass=scene_pass;
+ multimesh->last_pass = scene_pass;
}
- for(int i=0;i<surf_count;i++) {
+ for (int i = 0; i < surf_count; i++) {
- _add_geometry(&multimesh->cache_surfaces[i],p_data,multimesh->cache_surfaces[i].surface,multimesh);
+ _add_geometry(&multimesh->cache_surfaces[i], p_data, multimesh->cache_surfaces[i].surface, multimesh);
}
-
-
}
-void RasterizerGLES2::add_immediate( const RID& p_immediate, const InstanceData *p_data) {
-
+void RasterizerGLES2::add_immediate(const RID &p_immediate, const InstanceData *p_data) {
Immediate *immediate = immediate_owner.get(p_immediate);
ERR_FAIL_COND(!immediate);
- _add_geometry(immediate,p_data,immediate,NULL);
-
+ _add_geometry(immediate, p_data, immediate, NULL);
}
-
-void RasterizerGLES2::add_particles( const RID& p_particle_instance, const InstanceData *p_data){
+void RasterizerGLES2::add_particles(const RID &p_particle_instance, const InstanceData *p_data) {
//print_line("adding particles");
ParticlesInstance *particles_instance = particles_instance_owner.get(p_particle_instance);
ERR_FAIL_COND(!particles_instance);
- Particles *p=particles_owner.get( particles_instance->particles );
+ Particles *p = particles_owner.get(particles_instance->particles);
ERR_FAIL_COND(!p);
- _add_geometry(p,p_data,p,particles_instance);
- draw_next_frame=true;
-
+ _add_geometry(p, p_data, p, particles_instance);
+ draw_next_frame = true;
}
-Color RasterizerGLES2::_convert_color(const Color& p_color) {
+Color RasterizerGLES2::_convert_color(const Color &p_color) {
if (current_env && current_env->fx_enabled[VS::ENV_FX_SRGB])
return p_color.to_linear();
@@ -5061,51 +4736,48 @@ Color RasterizerGLES2::_convert_color(const Color& p_color) {
return p_color;
}
-void RasterizerGLES2::_set_cull(bool p_front,bool p_reverse_cull) {
+void RasterizerGLES2::_set_cull(bool p_front, bool p_reverse_cull) {
bool front = p_front;
if (p_reverse_cull)
- front=!front;
+ front = !front;
- if (front!=cull_front) {
+ if (front != cull_front) {
- glCullFace(front?GL_FRONT:GL_BACK);
- cull_front=front;
+ glCullFace(front ? GL_FRONT : GL_BACK);
+ cull_front = front;
}
}
-
_FORCE_INLINE_ void RasterizerGLES2::_update_material_shader_params(Material *p_material) const {
-
- Map<StringName,Material::UniformData> old_mparams=p_material->shader_params;
- Map<StringName,Material::UniformData> &mparams=p_material->shader_params;
+ Map<StringName, Material::UniformData> old_mparams = p_material->shader_params;
+ Map<StringName, Material::UniformData> &mparams = p_material->shader_params;
mparams.clear();
- int idx=0;
- for(Map<StringName,ShaderLanguage::Uniform>::Element *E=p_material->shader_cache->uniforms.front();E;E=E->next()) {
+ int idx = 0;
+ for (Map<StringName, ShaderLanguage::Uniform>::Element *E = p_material->shader_cache->uniforms.front(); E; E = E->next()) {
Material::UniformData ud;
- bool keep=true; //keep material value
+ bool keep = true; //keep material value
- Map<StringName,Material::UniformData>::Element *OLD=old_mparams.find(E->key());
+ Map<StringName, Material::UniformData>::Element *OLD = old_mparams.find(E->key());
bool has_old = OLD;
- bool old_inuse=has_old && old_mparams[E->key()].inuse;
+ bool old_inuse = has_old && old_mparams[E->key()].inuse;
- ud.istexture=(E->get().type==ShaderLanguage::TYPE_TEXTURE || E->get().type==ShaderLanguage::TYPE_CUBEMAP);
+ ud.istexture = (E->get().type == ShaderLanguage::TYPE_TEXTURE || E->get().type == ShaderLanguage::TYPE_CUBEMAP);
if (!has_old || !old_inuse) {
- keep=false;
- }
- else if (OLD->get().value.get_type()!=E->value().default_value.get_type()) {
+ keep = false;
+ } else if (OLD->get().value.get_type() != E->value().default_value.get_type()) {
- if (OLD->get().value.get_type()==Variant::INT && E->get().type==ShaderLanguage::TYPE_FLOAT) {
+ if (OLD->get().value.get_type() == Variant::INT && E->get().type == ShaderLanguage::TYPE_FLOAT) {
//handle common mistake using shaders (feeding ints instead of float)
- OLD->get().value=float(OLD->get().value);
- keep=true;
- } else if (!ud.istexture && E->value().default_value.get_type()!=Variant::NIL) {
+ OLD->get().value = float(OLD->get().value);
+ keep = true;
+ } else if (!ud.istexture && E->value().default_value.get_type() != Variant::NIL) {
- keep=false;
+ keep = false;
}
//type changed between old and new
/* if (old_mparams[E->key()].value.get_type()==Variant::OBJECT) {
@@ -5118,17 +4790,16 @@ _FORCE_INLINE_ void RasterizerGLES2::_update_material_shader_params(Material *p_
;
}
-
if (keep) {
- ud.value=old_mparams[E->key()].value;
+ ud.value = old_mparams[E->key()].value;
//print_line("KEEP: "+String(E->key()));
} else {
if (ud.istexture && p_material->shader_cache->default_textures.has(E->key()))
- ud.value=p_material->shader_cache->default_textures[E->key()];
+ ud.value = p_material->shader_cache->default_textures[E->key()];
else
- ud.value=E->value().default_value;
- old_inuse=false; //if reverted to default, obviously did not work
+ ud.value = E->value().default_value;
+ old_inuse = false; //if reverted to default, obviously did not work
/*
print_line("NEW: "+String(E->key())+" because: hasold-"+itos(old_mparams.has(E->key())));
@@ -5137,17 +4808,15 @@ _FORCE_INLINE_ void RasterizerGLES2::_update_material_shader_params(Material *p_
*/
}
-
- ud.index=idx++;
- ud.inuse=old_inuse;
- mparams[E->key()]=ud;
+ ud.index = idx++;
+ ud.inuse = old_inuse;
+ mparams[E->key()] = ud;
}
- p_material->shader_version=p_material->shader_cache->version;
-
+ p_material->shader_version = p_material->shader_cache->version;
}
-bool RasterizerGLES2::_setup_material(const Geometry *p_geometry,const Material *p_material,bool p_no_const_light,bool p_opaque_pass) {
+bool RasterizerGLES2::_setup_material(const Geometry *p_geometry, const Material *p_material, bool p_no_const_light, bool p_opaque_pass) {
if (p_material->flags[VS::MATERIAL_FLAG_DOUBLE_SIDED]) {
glDisable(GL_CULL_FACE);
@@ -5167,56 +4836,48 @@ bool RasterizerGLES2::_setup_material(const Geometry *p_geometry,const Material
if (p_material->line_width)
glLineWidth(p_material->line_width);
-
//all goes to false by default
- material_shader.set_conditional(MaterialShaderGLES2::USE_SHADOW_PASS,shadow!=NULL);
- material_shader.set_conditional(MaterialShaderGLES2::USE_SHADOW_PCF,shadow_filter==SHADOW_FILTER_PCF5 || shadow_filter==SHADOW_FILTER_PCF13);
- material_shader.set_conditional(MaterialShaderGLES2::USE_SHADOW_PCF_HQ,shadow_filter==SHADOW_FILTER_PCF13);
- material_shader.set_conditional(MaterialShaderGLES2::USE_SHADOW_ESM,shadow_filter==SHADOW_FILTER_ESM);
- material_shader.set_conditional(MaterialShaderGLES2::USE_LIGHTMAP_ON_UV2,p_material->flags[VS::MATERIAL_FLAG_LIGHTMAP_ON_UV2]);
- material_shader.set_conditional(MaterialShaderGLES2::USE_COLOR_ATTRIB_SRGB_TO_LINEAR,p_material->flags[VS::MATERIAL_FLAG_COLOR_ARRAY_SRGB] && current_env && current_env->fx_enabled[VS::ENV_FX_SRGB]);
+ material_shader.set_conditional(MaterialShaderGLES2::USE_SHADOW_PASS, shadow != NULL);
+ material_shader.set_conditional(MaterialShaderGLES2::USE_SHADOW_PCF, shadow_filter == SHADOW_FILTER_PCF5 || shadow_filter == SHADOW_FILTER_PCF13);
+ material_shader.set_conditional(MaterialShaderGLES2::USE_SHADOW_PCF_HQ, shadow_filter == SHADOW_FILTER_PCF13);
+ material_shader.set_conditional(MaterialShaderGLES2::USE_SHADOW_ESM, shadow_filter == SHADOW_FILTER_ESM);
+ material_shader.set_conditional(MaterialShaderGLES2::USE_LIGHTMAP_ON_UV2, p_material->flags[VS::MATERIAL_FLAG_LIGHTMAP_ON_UV2]);
+ material_shader.set_conditional(MaterialShaderGLES2::USE_COLOR_ATTRIB_SRGB_TO_LINEAR, p_material->flags[VS::MATERIAL_FLAG_COLOR_ARRAY_SRGB] && current_env && current_env->fx_enabled[VS::ENV_FX_SRGB]);
- if (p_opaque_pass && p_material->depth_draw_mode==VS::MATERIAL_DEPTH_DRAW_OPAQUE_PRE_PASS_ALPHA && p_material->shader_cache && p_material->shader_cache->has_alpha) {
+ if (p_opaque_pass && p_material->depth_draw_mode == VS::MATERIAL_DEPTH_DRAW_OPAQUE_PRE_PASS_ALPHA && p_material->shader_cache && p_material->shader_cache->has_alpha) {
- material_shader.set_conditional(MaterialShaderGLES2::ENABLE_CLIP_ALPHA,true);
+ material_shader.set_conditional(MaterialShaderGLES2::ENABLE_CLIP_ALPHA, true);
} else {
- material_shader.set_conditional(MaterialShaderGLES2::ENABLE_CLIP_ALPHA,false);
-
+ material_shader.set_conditional(MaterialShaderGLES2::ENABLE_CLIP_ALPHA, false);
}
-
if (!shadow) {
- bool depth_test=!p_material->flags[VS::MATERIAL_FLAG_ONTOP];
- bool depth_write=p_material->depth_draw_mode!=VS::MATERIAL_DEPTH_DRAW_NEVER && (p_opaque_pass || p_material->depth_draw_mode==VS::MATERIAL_DEPTH_DRAW_ALWAYS);
+ bool depth_test = !p_material->flags[VS::MATERIAL_FLAG_ONTOP];
+ bool depth_write = p_material->depth_draw_mode != VS::MATERIAL_DEPTH_DRAW_NEVER && (p_opaque_pass || p_material->depth_draw_mode == VS::MATERIAL_DEPTH_DRAW_ALWAYS);
//bool depth_write=!p_material->hints[VS::MATERIAL_HINT_NO_DEPTH_DRAW] && (p_opaque_pass || !p_material->hints[VS::MATERIAL_HINT_NO_DEPTH_DRAW_FOR_ALPHA]);
- if (current_depth_mask!=depth_write) {
- current_depth_mask=depth_write;
- glDepthMask( depth_write );
-
+ if (current_depth_mask != depth_write) {
+ current_depth_mask = depth_write;
+ glDepthMask(depth_write);
}
+ if (current_depth_test != depth_test) {
- if (current_depth_test!=depth_test) {
-
-
- current_depth_test=depth_test;
- if(depth_test)
+ current_depth_test = depth_test;
+ if (depth_test)
glEnable(GL_DEPTH_TEST);
else
glDisable(GL_DEPTH_TEST);
}
-
- material_shader.set_conditional(MaterialShaderGLES2::USE_FOG,current_env && current_env->fx_enabled[VS::ENV_FX_FOG]);
+ material_shader.set_conditional(MaterialShaderGLES2::USE_FOG, current_env && current_env->fx_enabled[VS::ENV_FX_FOG]);
//glDepthMask( true );
}
-
DEBUG_TEST_ERROR("Pre Shader Bind");
- bool rebind=false;
+ bool rebind = false;
if (p_material->shader_cache && p_material->shader_cache->valid) {
@@ -5226,14 +4887,12 @@ bool RasterizerGLES2::_setup_material(const Geometry *p_geometry,const Material
material_shader.set_conditional((MaterialShaderGLES2::Conditionals)_tex_version[i],false);
*/
-
//material_shader.set_custom_shader(p_material->shader_cache->custom_code_id);
- if (p_material->shader_version!=p_material->shader_cache->version) {
+ if (p_material->shader_version != p_material->shader_cache->version) {
//shader changed somehow, must update uniforms
- _update_material_shader_params((Material*)p_material);
-
+ _update_material_shader_params((Material *)p_material);
}
material_shader.set_custom_shader(p_material->shader_cache->custom_code_id);
rebind = material_shader.bind();
@@ -5241,11 +4900,10 @@ bool RasterizerGLES2::_setup_material(const Geometry *p_geometry,const Material
DEBUG_TEST_ERROR("Shader Bind");
//set uniforms!
- int texcoord=0;
- for (Map<StringName,Material::UniformData>::Element *E=p_material->shader_params.front();E;E=E->next()) {
+ int texcoord = 0;
+ for (Map<StringName, Material::UniformData>::Element *E = p_material->shader_params.front(); E; E = E->next()) {
-
- if (E->get().index<0)
+ if (E->get().index < 0)
continue;
//print_line(String(E->key())+": "+E->get().value);
if (E->get().istexture) {
@@ -5253,61 +4911,55 @@ bool RasterizerGLES2::_setup_material(const Geometry *p_geometry,const Material
RID rid = E->get().value;
int loc = material_shader.get_custom_uniform_location(E->get().index); //should be automatic..
-
- Texture *t=NULL;
+ Texture *t = NULL;
if (rid.is_valid()) {
-
- t=texture_owner.get(rid);
+ t = texture_owner.get(rid);
if (!t) {
- E->get().value=RID(); //nullify, invalid texture
- rid=RID();
+ E->get().value = RID(); //nullify, invalid texture
+ rid = RID();
}
}
- glActiveTexture(GL_TEXTURE0+texcoord);
- glUniform1i(loc,texcoord); //TODO - this could happen automatically on compile...
+ glActiveTexture(GL_TEXTURE0 + texcoord);
+ glUniform1i(loc, texcoord); //TODO - this could happen automatically on compile...
if (t) {
if (t->render_target)
- t->render_target->last_pass=frame;
- if (E->key()==p_material->shader_cache->first_texture) {
- tc0_idx=texcoord;
- tc0_id_cache=t->tex_id;
+ t->render_target->last_pass = frame;
+ if (E->key() == p_material->shader_cache->first_texture) {
+ tc0_idx = texcoord;
+ tc0_id_cache = t->tex_id;
}
- glBindTexture(t->target,t->tex_id);
+ glBindTexture(t->target, t->tex_id);
} else
- glBindTexture(GL_TEXTURE_2D,white_tex); //no texture
+ glBindTexture(GL_TEXTURE_2D, white_tex); //no texture
texcoord++;
- } else if (E->get().value.get_type()==Variant::COLOR){
+ } else if (E->get().value.get_type() == Variant::COLOR) {
Color c = E->get().value;
- material_shader.set_custom_uniform(E->get().index,_convert_color(c));
+ material_shader.set_custom_uniform(E->get().index, _convert_color(c));
} else {
- material_shader.set_custom_uniform(E->get().index,E->get().value);
+ material_shader.set_custom_uniform(E->get().index, E->get().value);
}
-
}
-
if (p_material->shader_cache->has_texscreen && framebuffer.active) {
- material_shader.set_uniform(MaterialShaderGLES2::TEXSCREEN_SCREEN_MULT,Vector2(float(viewport.width)/framebuffer.width,float(viewport.height)/framebuffer.height));
- material_shader.set_uniform(MaterialShaderGLES2::TEXSCREEN_SCREEN_CLAMP,Color(0,0,float(viewport.width)/framebuffer.width,float(viewport.height)/framebuffer.height));
- material_shader.set_uniform(MaterialShaderGLES2::TEXSCREEN_TEX,texcoord);
- glActiveTexture(GL_TEXTURE0+texcoord);
- glBindTexture(GL_TEXTURE_2D,framebuffer.sample_color);
-
+ material_shader.set_uniform(MaterialShaderGLES2::TEXSCREEN_SCREEN_MULT, Vector2(float(viewport.width) / framebuffer.width, float(viewport.height) / framebuffer.height));
+ material_shader.set_uniform(MaterialShaderGLES2::TEXSCREEN_SCREEN_CLAMP, Color(0, 0, float(viewport.width) / framebuffer.width, float(viewport.height) / framebuffer.height));
+ material_shader.set_uniform(MaterialShaderGLES2::TEXSCREEN_TEX, texcoord);
+ glActiveTexture(GL_TEXTURE0 + texcoord);
+ glBindTexture(GL_TEXTURE_2D, framebuffer.sample_color);
}
if (p_material->shader_cache->has_screen_uv) {
- material_shader.set_uniform(MaterialShaderGLES2::SCREEN_UV_MULT,Vector2(1.0/viewport.width,1.0/viewport.height));
+ material_shader.set_uniform(MaterialShaderGLES2::SCREEN_UV_MULT, Vector2(1.0 / viewport.width, 1.0 / viewport.height));
}
DEBUG_TEST_ERROR("Material arameters");
if (p_material->shader_cache->uses_time) {
- material_shader.set_uniform(MaterialShaderGLES2::TIME,Math::fmod(last_time,shader_time_rollback));
- draw_next_frame=true;
+ material_shader.set_uniform(MaterialShaderGLES2::TIME, Math::fmod(last_time, shader_time_rollback));
+ draw_next_frame = true;
}
- //if uses TIME - draw_next_frame=true
-
+ //if uses TIME - draw_next_frame=true
} else {
@@ -5317,57 +4969,48 @@ bool RasterizerGLES2::_setup_material(const Geometry *p_geometry,const Material
DEBUG_TEST_ERROR("Shader bind2");
}
-
-
if (shadow) {
float zofs = shadow->base->vars[VS::LIGHT_PARAM_SHADOW_Z_OFFSET];
float zslope = shadow->base->vars[VS::LIGHT_PARAM_SHADOW_Z_SLOPE_SCALE];
- if (shadow_pass>=1 && shadow->base->type==VS::LIGHT_DIRECTIONAL) {
- float m = Math::pow(shadow->base->directional_shadow_param[VS::LIGHT_DIRECTIONAL_SHADOW_PARAM_PSSM_ZOFFSET_SCALE],shadow_pass);
- zofs*=m;
- zslope*=m;
- }
- material_shader.set_uniform(MaterialShaderGLES2::SHADOW_Z_OFFSET,zofs);
- material_shader.set_uniform(MaterialShaderGLES2::SHADOW_Z_SLOPE_SCALE,zslope);
- if (shadow->base->type==VS::LIGHT_OMNI)
- material_shader.set_uniform(MaterialShaderGLES2::DUAL_PARABOLOID,shadow->dp);
+ if (shadow_pass >= 1 && shadow->base->type == VS::LIGHT_DIRECTIONAL) {
+ float m = Math::pow(shadow->base->directional_shadow_param[VS::LIGHT_DIRECTIONAL_SHADOW_PARAM_PSSM_ZOFFSET_SCALE], shadow_pass);
+ zofs *= m;
+ zslope *= m;
+ }
+ material_shader.set_uniform(MaterialShaderGLES2::SHADOW_Z_OFFSET, zofs);
+ material_shader.set_uniform(MaterialShaderGLES2::SHADOW_Z_SLOPE_SCALE, zslope);
+ if (shadow->base->type == VS::LIGHT_OMNI)
+ material_shader.set_uniform(MaterialShaderGLES2::DUAL_PARABOLOID, shadow->dp);
DEBUG_TEST_ERROR("Shadow uniforms");
-
}
-
if (current_env && current_env->fx_enabled[VS::ENV_FX_FOG]) {
Color col_begin = current_env->fx_param[VS::ENV_FX_PARAM_FOG_BEGIN_COLOR];
Color col_end = current_env->fx_param[VS::ENV_FX_PARAM_FOG_END_COLOR];
- col_begin=_convert_color(col_begin);
- col_end=_convert_color(col_end);
+ col_begin = _convert_color(col_begin);
+ col_end = _convert_color(col_end);
float from = current_env->fx_param[VS::ENV_FX_PARAM_FOG_BEGIN];
float zf = camera_z_far;
float curve = current_env->fx_param[VS::ENV_FX_PARAM_FOG_ATTENUATION];
- material_shader.set_uniform(MaterialShaderGLES2::FOG_PARAMS,Vector3(from,zf,curve));
- material_shader.set_uniform(MaterialShaderGLES2::FOG_COLOR_BEGIN,Vector3(col_begin.r,col_begin.g,col_begin.b));
- material_shader.set_uniform(MaterialShaderGLES2::FOG_COLOR_END,Vector3(col_end.r,col_end.g,col_end.b));
+ material_shader.set_uniform(MaterialShaderGLES2::FOG_PARAMS, Vector3(from, zf, curve));
+ material_shader.set_uniform(MaterialShaderGLES2::FOG_COLOR_BEGIN, Vector3(col_begin.r, col_begin.g, col_begin.b));
+ material_shader.set_uniform(MaterialShaderGLES2::FOG_COLOR_END, Vector3(col_end.r, col_end.g, col_end.b));
}
-
-
//material_shader.set_uniform(MaterialShaderGLES2::TIME,Math::fmod(last_time,300.0));
//if uses TIME - draw_next_frame=true
return rebind;
-
}
-
-
void RasterizerGLES2::_setup_light(uint16_t p_light) {
if (shadow)
return;
- if (p_light==0xFFFF)
+ if (p_light == 0xFFFF)
return;
enum {
@@ -5380,7 +5023,7 @@ void RasterizerGLES2::_setup_light(uint16_t p_light) {
VL_LIGHT_MAX
};
- static const MaterialShaderGLES2::Uniforms light_uniforms[VL_LIGHT_MAX]={
+ static const MaterialShaderGLES2::Uniforms light_uniforms[VL_LIGHT_MAX] = {
MaterialShaderGLES2::LIGHT_POS,
MaterialShaderGLES2::LIGHT_DIRECTION,
MaterialShaderGLES2::LIGHT_ATTENUATION,
@@ -5389,229 +5032,213 @@ void RasterizerGLES2::_setup_light(uint16_t p_light) {
MaterialShaderGLES2::LIGHT_SPECULAR,
};
-
GLfloat light_data[VL_LIGHT_MAX][3];
- memset(light_data,0,(VL_LIGHT_MAX)*3*sizeof(GLfloat));
+ memset(light_data, 0, (VL_LIGHT_MAX)*3 * sizeof(GLfloat));
- LightInstance *li=light_instances[p_light];
- Light *l=li->base;
+ LightInstance *li = light_instances[p_light];
+ Light *l = li->base;
- Color col_diffuse=_convert_color(l->colors[VS::LIGHT_COLOR_DIFFUSE]);
- Color col_specular=_convert_color(l->colors[VS::LIGHT_COLOR_SPECULAR]);
+ Color col_diffuse = _convert_color(l->colors[VS::LIGHT_COLOR_DIFFUSE]);
+ Color col_specular = _convert_color(l->colors[VS::LIGHT_COLOR_SPECULAR]);
- for(int j=0;j<3;j++) {
- light_data[VL_LIGHT_DIFFUSE][j]=col_diffuse[j];
- light_data[VL_LIGHT_SPECULAR][j]=col_specular[j];
+ for (int j = 0; j < 3; j++) {
+ light_data[VL_LIGHT_DIFFUSE][j] = col_diffuse[j];
+ light_data[VL_LIGHT_SPECULAR][j] = col_specular[j];
}
- if (l->type!=VS::LIGHT_OMNI) {
+ if (l->type != VS::LIGHT_OMNI) {
Vector3 dir = -li->transform.get_basis().get_axis(2);
dir = camera_transform_inverse.basis.xform(dir).normalized();
- for(int j=0;j<3;j++)
- light_data[VL_LIGHT_DIR][j]=dir[j];
+ for (int j = 0; j < 3; j++)
+ light_data[VL_LIGHT_DIR][j] = dir[j];
}
-
- if (l->type!=VS::LIGHT_DIRECTIONAL) {
+ if (l->type != VS::LIGHT_DIRECTIONAL) {
Vector3 pos = li->transform.get_origin();
pos = camera_transform_inverse.xform(pos);
- for(int j=0;j<3;j++)
- light_data[VL_LIGHT_POS][j]=pos[j];
+ for (int j = 0; j < 3; j++)
+ light_data[VL_LIGHT_POS][j] = pos[j];
}
if (li->near_shadow_buffer) {
- glActiveTexture(GL_TEXTURE0+max_texture_units-1);
- glBindTexture(GL_TEXTURE_2D,li->near_shadow_buffer->depth);
-
- material_shader.set_uniform(MaterialShaderGLES2::SHADOW_MATRIX,li->shadow_projection[0]);
- material_shader.set_uniform(MaterialShaderGLES2::SHADOW_TEXEL_SIZE,Vector2(1.0,1.0)/li->near_shadow_buffer->size);
- material_shader.set_uniform(MaterialShaderGLES2::SHADOW_TEXTURE,max_texture_units-1);
- if (shadow_filter==SHADOW_FILTER_ESM)
- material_shader.set_uniform(MaterialShaderGLES2::ESM_MULTIPLIER,float(li->base->vars[VS::LIGHT_PARAM_SHADOW_ESM_MULTIPLIER]));
+ glActiveTexture(GL_TEXTURE0 + max_texture_units - 1);
+ glBindTexture(GL_TEXTURE_2D, li->near_shadow_buffer->depth);
- if (li->base->type==VS::LIGHT_DIRECTIONAL) {
+ material_shader.set_uniform(MaterialShaderGLES2::SHADOW_MATRIX, li->shadow_projection[0]);
+ material_shader.set_uniform(MaterialShaderGLES2::SHADOW_TEXEL_SIZE, Vector2(1.0, 1.0) / li->near_shadow_buffer->size);
+ material_shader.set_uniform(MaterialShaderGLES2::SHADOW_TEXTURE, max_texture_units - 1);
+ if (shadow_filter == SHADOW_FILTER_ESM)
+ material_shader.set_uniform(MaterialShaderGLES2::ESM_MULTIPLIER, float(li->base->vars[VS::LIGHT_PARAM_SHADOW_ESM_MULTIPLIER]));
- if (li->base->directional_shadow_mode==VS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_2_SPLITS) {
+ if (li->base->type == VS::LIGHT_DIRECTIONAL) {
- material_shader.set_uniform(MaterialShaderGLES2::SHADOW_MATRIX2,li->shadow_projection[1]);
- material_shader.set_uniform(MaterialShaderGLES2::LIGHT_PSSM_SPLIT,Vector3(li->shadow_split[0],li->shadow_split[1],li->shadow_split[2]));
- } else if (li->base->directional_shadow_mode==VS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_4_SPLITS) {
+ if (li->base->directional_shadow_mode == VS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_2_SPLITS) {
+ material_shader.set_uniform(MaterialShaderGLES2::SHADOW_MATRIX2, li->shadow_projection[1]);
+ material_shader.set_uniform(MaterialShaderGLES2::LIGHT_PSSM_SPLIT, Vector3(li->shadow_split[0], li->shadow_split[1], li->shadow_split[2]));
+ } else if (li->base->directional_shadow_mode == VS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_4_SPLITS) {
- material_shader.set_uniform(MaterialShaderGLES2::SHADOW_MATRIX2,li->shadow_projection[1]);
- material_shader.set_uniform(MaterialShaderGLES2::SHADOW_MATRIX3,li->shadow_projection[2]);
- material_shader.set_uniform(MaterialShaderGLES2::SHADOW_MATRIX4,li->shadow_projection[3]);
- material_shader.set_uniform(MaterialShaderGLES2::LIGHT_PSSM_SPLIT,Vector3(li->shadow_split[0],li->shadow_split[1],li->shadow_split[2]));
-
+ material_shader.set_uniform(MaterialShaderGLES2::SHADOW_MATRIX2, li->shadow_projection[1]);
+ material_shader.set_uniform(MaterialShaderGLES2::SHADOW_MATRIX3, li->shadow_projection[2]);
+ material_shader.set_uniform(MaterialShaderGLES2::SHADOW_MATRIX4, li->shadow_projection[3]);
+ material_shader.set_uniform(MaterialShaderGLES2::LIGHT_PSSM_SPLIT, Vector3(li->shadow_split[0], li->shadow_split[1], li->shadow_split[2]));
}
//print_line("shadow split: "+rtos(li->shadow_split));
}
- material_shader.set_uniform(MaterialShaderGLES2::SHADOW_DARKENING,li->base->vars[VS::LIGHT_PARAM_SHADOW_DARKENING]);
+ material_shader.set_uniform(MaterialShaderGLES2::SHADOW_DARKENING, li->base->vars[VS::LIGHT_PARAM_SHADOW_DARKENING]);
//matrix
-
}
-
light_data[VL_LIGHT_ATTENUATION][0] = l->vars[VS::LIGHT_PARAM_ENERGY];
if (l->type == VS::LIGHT_DIRECTIONAL) {
light_data[VL_LIGHT_ATTENUATION][1] = l->directional_shadow_param[VS::LIGHT_DIRECTIONAL_SHADOW_PARAM_MAX_DISTANCE];
- }
- else{
+ } else {
light_data[VL_LIGHT_ATTENUATION][1] = l->vars[VS::LIGHT_PARAM_RADIUS];
}
light_data[VL_LIGHT_ATTENUATION][2] = l->vars[VS::LIGHT_PARAM_ATTENUATION];
- light_data[VL_LIGHT_SPOT_ATTENUATION][0]=Math::cos(Math::deg2rad(l->vars[VS::LIGHT_PARAM_SPOT_ANGLE]));
- light_data[VL_LIGHT_SPOT_ATTENUATION][1]=l->vars[VS::LIGHT_PARAM_SPOT_ATTENUATION];
-
+ light_data[VL_LIGHT_SPOT_ATTENUATION][0] = Math::cos(Math::deg2rad(l->vars[VS::LIGHT_PARAM_SPOT_ANGLE]));
+ light_data[VL_LIGHT_SPOT_ATTENUATION][1] = l->vars[VS::LIGHT_PARAM_SPOT_ATTENUATION];
//int uf = material_shader.get_uniform(MaterialShaderGLES2::LIGHT_PARAMS);
- for(int i=0;i<VL_LIGHT_MAX;i++) {
- glUniform3f( material_shader.get_uniform(light_uniforms[i]),light_data[i][0],light_data[i][1],light_data[i][2]);
+ for (int i = 0; i < VL_LIGHT_MAX; i++) {
+ glUniform3f(material_shader.get_uniform(light_uniforms[i]), light_data[i][0], light_data[i][1], light_data[i][2]);
}
-
}
-
-template<bool USE_NORMAL, bool USE_TANGENT,bool INPLACE>
-void RasterizerGLES2::_skeleton_xform(const uint8_t * p_src_array, int p_src_stride, uint8_t * p_dst_array, int p_dst_stride, int p_elements,const uint8_t *p_src_bones, const uint8_t *p_src_weights, const Skeleton::Bone *p_bone_xforms) {
+template <bool USE_NORMAL, bool USE_TANGENT, bool INPLACE>
+void RasterizerGLES2::_skeleton_xform(const uint8_t *p_src_array, int p_src_stride, uint8_t *p_dst_array, int p_dst_stride, int p_elements, const uint8_t *p_src_bones, const uint8_t *p_src_weights, const Skeleton::Bone *p_bone_xforms) {
uint32_t basesize = 3;
if (USE_NORMAL)
- basesize+=3;
+ basesize += 3;
if (USE_TANGENT)
- basesize+=4;
+ basesize += 4;
- uint32_t extra=(p_dst_stride-basesize*4);
- const int dstvec_size=3+(USE_NORMAL?3:0)+(USE_TANGENT?4:0);
+ uint32_t extra = (p_dst_stride - basesize * 4);
+ const int dstvec_size = 3 + (USE_NORMAL ? 3 : 0) + (USE_TANGENT ? 4 : 0);
float dstcopy[dstvec_size];
- for(int i=0;i<p_elements;i++) {
+ for (int i = 0; i < p_elements; i++) {
- uint32_t ss = p_src_stride*i;
- uint32_t ds = p_dst_stride*i;
- const uint16_t *bi = (const uint16_t*)&p_src_bones[ss];
+ uint32_t ss = p_src_stride * i;
+ uint32_t ds = p_dst_stride * i;
+ const uint16_t *bi = (const uint16_t *)&p_src_bones[ss];
const float *bw = (const float *)&p_src_weights[ss];
- const float *src_vec=(const float *)&p_src_array[ss];
+ const float *src_vec = (const float *)&p_src_array[ss];
float *dst_vec;
if (INPLACE)
- dst_vec=dstcopy;
+ dst_vec = dstcopy;
else
- dst_vec=(float*)&p_dst_array[ds];
+ dst_vec = (float *)&p_dst_array[ds];
- dst_vec[0]=0.0;
- dst_vec[1]=0.0;
- dst_vec[2]=0.0;
+ dst_vec[0] = 0.0;
+ dst_vec[1] = 0.0;
+ dst_vec[2] = 0.0;
//conditionals simply removed by optimizer
if (USE_NORMAL) {
- dst_vec[3]=0.0;
- dst_vec[4]=0.0;
- dst_vec[5]=0.0;
+ dst_vec[3] = 0.0;
+ dst_vec[4] = 0.0;
+ dst_vec[5] = 0.0;
if (USE_TANGENT) {
- dst_vec[6]=0.0;
- dst_vec[7]=0.0;
- dst_vec[8]=0.0;
- dst_vec[9]=src_vec[9];
+ dst_vec[6] = 0.0;
+ dst_vec[7] = 0.0;
+ dst_vec[8] = 0.0;
+ dst_vec[9] = src_vec[9];
}
} else {
if (USE_TANGENT) {
- dst_vec[3]=0.0;
- dst_vec[4]=0.0;
- dst_vec[5]=0.0;
- dst_vec[6]=src_vec[6];
+ dst_vec[3] = 0.0;
+ dst_vec[4] = 0.0;
+ dst_vec[5] = 0.0;
+ dst_vec[6] = src_vec[6];
}
}
-
-#define _XFORM_BONE(m_idx)\
- if (bw[m_idx]==0)\
- goto end;\
- p_bone_xforms[bi[m_idx]].transform_add_mul3(&src_vec[0],&dst_vec[0],bw[m_idx]);\
- if (USE_NORMAL) {\
- p_bone_xforms[bi[m_idx]].transform3_add_mul3(&src_vec[3],&dst_vec[3],bw[m_idx]);\
- if (USE_TANGENT) {\
- p_bone_xforms[bi[m_idx]].transform3_add_mul3(&src_vec[6],&dst_vec[6],bw[m_idx]);\
- }\
- } else {\
- if (USE_TANGENT) {\
- p_bone_xforms[bi[m_idx]].transform3_add_mul3(&src_vec[3],&dst_vec[3],bw[m_idx]);\
- }\
- }
+#define _XFORM_BONE(m_idx) \
+ if (bw[m_idx] == 0) \
+ goto end; \
+ p_bone_xforms[bi[m_idx]].transform_add_mul3(&src_vec[0], &dst_vec[0], bw[m_idx]); \
+ if (USE_NORMAL) { \
+ p_bone_xforms[bi[m_idx]].transform3_add_mul3(&src_vec[3], &dst_vec[3], bw[m_idx]); \
+ if (USE_TANGENT) { \
+ p_bone_xforms[bi[m_idx]].transform3_add_mul3(&src_vec[6], &dst_vec[6], bw[m_idx]); \
+ } \
+ } else { \
+ if (USE_TANGENT) { \
+ p_bone_xforms[bi[m_idx]].transform3_add_mul3(&src_vec[3], &dst_vec[3], bw[m_idx]); \
+ } \
+ }
_XFORM_BONE(0);
_XFORM_BONE(1);
_XFORM_BONE(2);
_XFORM_BONE(3);
- end:
+ end:
if (INPLACE) {
- const uint8_t *esp =(const uint8_t*) dstcopy;
- uint8_t *edp =(uint8_t*)&p_dst_array[ds];
-
+ const uint8_t *esp = (const uint8_t *)dstcopy;
+ uint8_t *edp = (uint8_t *)&p_dst_array[ds];
- for(uint32_t j=0;j<dstvec_size*4;j++) {
+ for (uint32_t j = 0; j < dstvec_size * 4; j++) {
- edp[j]=esp[j];
+ edp[j] = esp[j];
}
} else {
//copy extra stuff
- const uint8_t *esp =(const uint8_t*) &src_vec[basesize];
- uint8_t *edp =(uint8_t*) &dst_vec[basesize];
+ const uint8_t *esp = (const uint8_t *)&src_vec[basesize];
+ uint8_t *edp = (uint8_t *)&dst_vec[basesize];
+ for (uint32_t j = 0; j < extra; j++) {
- for(uint32_t j=0;j<extra;j++) {
-
- edp[j]=esp[j];
+ edp[j] = esp[j];
}
}
}
}
+Error RasterizerGLES2::_setup_geometry(const Geometry *p_geometry, const Material *p_material, const Skeleton *p_skeleton, const float *p_morphs) {
-Error RasterizerGLES2::_setup_geometry(const Geometry *p_geometry, const Material* p_material, const Skeleton *p_skeleton,const float *p_morphs) {
-
-
- switch(p_geometry->type) {
+ switch (p_geometry->type) {
case Geometry::GEOMETRY_MULTISURFACE:
case Geometry::GEOMETRY_SURFACE: {
- const Surface *surf=NULL;
- if (p_geometry->type==Geometry::GEOMETRY_SURFACE)
- surf=static_cast<const Surface*>(p_geometry);
- else if (p_geometry->type==Geometry::GEOMETRY_MULTISURFACE)
- surf=static_cast<const MultiMeshSurface*>(p_geometry)->surface;
-
+ const Surface *surf = NULL;
+ if (p_geometry->type == Geometry::GEOMETRY_SURFACE)
+ surf = static_cast<const Surface *>(p_geometry);
+ else if (p_geometry->type == Geometry::GEOMETRY_MULTISURFACE)
+ surf = static_cast<const MultiMeshSurface *>(p_geometry)->surface;
if (surf->format != surf->configured_format) {
if (OS::get_singleton()->is_stdout_verbose()) {
- print_line("has format: "+itos(surf->format));
- print_line("configured format: "+itos(surf->configured_format));
+ print_line("has format: " + itos(surf->format));
+ print_line("configured format: " + itos(surf->configured_format));
}
ERR_EXPLAIN("Missing arrays (not set) in surface");
}
- ERR_FAIL_COND_V( surf->format != surf->configured_format, ERR_UNCONFIGURED );
- uint8_t *base=0;
- int stride=surf->stride;
- bool use_VBO = (surf->array_local==0);
- _setup_geometry_vinfo=surf->array_len;
+ ERR_FAIL_COND_V(surf->format != surf->configured_format, ERR_UNCONFIGURED);
+ uint8_t *base = 0;
+ int stride = surf->stride;
+ bool use_VBO = (surf->array_local == 0);
+ _setup_geometry_vinfo = surf->array_len;
- bool skeleton_valid = p_skeleton && (surf->format&VS::ARRAY_FORMAT_BONES) && (surf->format&VS::ARRAY_FORMAT_WEIGHTS) && !p_skeleton->bones.empty() && p_skeleton->bones.size() > surf->max_bone;
+ bool skeleton_valid = p_skeleton && (surf->format & VS::ARRAY_FORMAT_BONES) && (surf->format & VS::ARRAY_FORMAT_WEIGHTS) && !p_skeleton->bones.empty() && p_skeleton->bones.size() > surf->max_bone;
/*
if (surf->packed) {
float scales[4]={surf->vertex_scale,surf->uv_scale,surf->uv2_scale,0.0};
@@ -5627,174 +5254,163 @@ Error RasterizerGLES2::_setup_geometry(const Geometry *p_geometry, const Materia
base = surf->array_local;
glBindBuffer(GL_ARRAY_BUFFER, 0);
- bool can_copy_to_local=surf->local_stride * surf->array_len <= skinned_buffer_size;
+ bool can_copy_to_local = surf->local_stride * surf->array_len <= skinned_buffer_size;
if (p_morphs && surf->stride * surf->array_len > skinned_buffer_size)
- can_copy_to_local=false;
-
+ can_copy_to_local = false;
if (!can_copy_to_local)
- skeleton_valid=false;
+ skeleton_valid = false;
/* compute morphs */
if (p_morphs && surf->morph_target_count && can_copy_to_local) {
-
-
base = skinned_buffer;
- stride=surf->local_stride;
+ stride = surf->local_stride;
//copy all first
- float coef=1.0;
-
- for(int i=0;i<surf->morph_target_count;i++) {
- if (surf->mesh->morph_target_mode==VS::MORPH_MODE_NORMALIZED)
- coef-=p_morphs[i];
- ERR_FAIL_COND_V( surf->morph_format != surf->morph_targets_local[i].configured_format, ERR_INVALID_DATA );
+ float coef = 1.0;
+ for (int i = 0; i < surf->morph_target_count; i++) {
+ if (surf->mesh->morph_target_mode == VS::MORPH_MODE_NORMALIZED)
+ coef -= p_morphs[i];
+ ERR_FAIL_COND_V(surf->morph_format != surf->morph_targets_local[i].configured_format, ERR_INVALID_DATA);
}
- int16_t coeffp = CLAMP(coef*255,0,255);
+ int16_t coeffp = CLAMP(coef * 255, 0, 255);
+ for (int i = 0; i < VS::ARRAY_MAX - 1; i++) {
- for(int i=0;i<VS::ARRAY_MAX-1;i++) {
-
- const Surface::ArrayData& ad=surf->array[i];
- if (ad.size==0)
+ const Surface::ArrayData &ad = surf->array[i];
+ if (ad.size == 0)
continue;
int ofs = ad.ofs;
- int src_stride=surf->stride;
- int dst_stride=skeleton_valid?surf->stride:surf->local_stride;
+ int src_stride = surf->stride;
+ int dst_stride = skeleton_valid ? surf->stride : surf->local_stride;
int count = surf->array_len;
- if (!skeleton_valid && i>=VS::ARRAY_MAX-3)
+ if (!skeleton_valid && i >= VS::ARRAY_MAX - 3)
break;
-
- switch(i) {
+ switch (i) {
case VS::ARRAY_VERTEX:
case VS::ARRAY_NORMAL:
- case VS::ARRAY_TANGENT:
- {
+ case VS::ARRAY_TANGENT: {
- for(int k=0;k<count;k++) {
+ for (int k = 0; k < count; k++) {
- const float *src = (const float*)&surf->array_local[ofs+k*src_stride];
- float *dst = (float*)&base[ofs+k*dst_stride];
+ const float *src = (const float *)&surf->array_local[ofs + k * src_stride];
+ float *dst = (float *)&base[ofs + k * dst_stride];
- dst[0]= src[0]*coef;
- dst[1]= src[1]*coef;
- dst[2]= src[2]*coef;
+ dst[0] = src[0] * coef;
+ dst[1] = src[1] * coef;
+ dst[2] = src[2] * coef;
};
} break;
case VS::ARRAY_COLOR: {
- for(int k=0;k<count;k++) {
+ for (int k = 0; k < count; k++) {
- const uint8_t *src = (const uint8_t*)&surf->array_local[ofs+k*src_stride];
- uint8_t *dst = (uint8_t*)&base[ofs+k*dst_stride];
+ const uint8_t *src = (const uint8_t *)&surf->array_local[ofs + k * src_stride];
+ uint8_t *dst = (uint8_t *)&base[ofs + k * dst_stride];
- dst[0]= (src[0]*coeffp)>>8;
- dst[1]= (src[1]*coeffp)>>8;
- dst[2]= (src[2]*coeffp)>>8;
- dst[3]= (src[3]*coeffp)>>8;
+ dst[0] = (src[0] * coeffp) >> 8;
+ dst[1] = (src[1] * coeffp) >> 8;
+ dst[2] = (src[2] * coeffp) >> 8;
+ dst[3] = (src[3] * coeffp) >> 8;
}
} break;
case VS::ARRAY_TEX_UV:
case VS::ARRAY_TEX_UV2: {
- for(int k=0;k<count;k++) {
+ for (int k = 0; k < count; k++) {
- const float *src = (const float*)&surf->array_local[ofs+k*src_stride];
- float *dst = (float*)&base[ofs+k*dst_stride];
+ const float *src = (const float *)&surf->array_local[ofs + k * src_stride];
+ float *dst = (float *)&base[ofs + k * dst_stride];
- dst[0]= src[0]*coef;
- dst[1]= src[1]*coef;
+ dst[0] = src[0] * coef;
+ dst[1] = src[1] * coef;
}
} break;
case VS::ARRAY_BONES:
case VS::ARRAY_WEIGHTS: {
- for(int k=0;k<count;k++) {
+ for (int k = 0; k < count; k++) {
- const float *src = (const float*)&surf->array_local[ofs+k*src_stride];
- float *dst = (float*)&base[ofs+k*dst_stride];
+ const float *src = (const float *)&surf->array_local[ofs + k * src_stride];
+ float *dst = (float *)&base[ofs + k * dst_stride];
- dst[0]= src[0];
- dst[1]= src[1];
- dst[2]= src[2];
- dst[3]= src[3];
+ dst[0] = src[0];
+ dst[1] = src[1];
+ dst[2] = src[2];
+ dst[3] = src[3];
}
} break;
-
}
}
+ for (int j = 0; j < surf->morph_target_count; j++) {
- for(int j=0;j<surf->morph_target_count;j++) {
+ for (int i = 0; i < VS::ARRAY_MAX - 3; i++) {
- for(int i=0;i<VS::ARRAY_MAX-3;i++) {
-
- const Surface::ArrayData& ad=surf->array[i];
- if (ad.size==0)
+ const Surface::ArrayData &ad = surf->array[i];
+ if (ad.size == 0)
continue;
-
int ofs = ad.ofs;
- int src_stride=surf->local_stride;
- int dst_stride=skeleton_valid?surf->stride:surf->local_stride;
+ int src_stride = surf->local_stride;
+ int dst_stride = skeleton_valid ? surf->stride : surf->local_stride;
int count = surf->array_len;
- const uint8_t *morph=surf->morph_targets_local[j].array;
+ const uint8_t *morph = surf->morph_targets_local[j].array;
float w = p_morphs[j];
- int16_t wfp = CLAMP(w*255,0,255);
+ int16_t wfp = CLAMP(w * 255, 0, 255);
- switch(i) {
+ switch (i) {
case VS::ARRAY_VERTEX:
case VS::ARRAY_NORMAL:
- case VS::ARRAY_TANGENT:
- {
+ case VS::ARRAY_TANGENT: {
- for(int k=0;k<count;k++) {
+ for (int k = 0; k < count; k++) {
- const float *src_morph = (const float*)&morph[ofs+k*src_stride];
- float *dst = (float*)&base[ofs+k*dst_stride];
+ const float *src_morph = (const float *)&morph[ofs + k * src_stride];
+ float *dst = (float *)&base[ofs + k * dst_stride];
- dst[0]+= src_morph[0]*w;
- dst[1]+= src_morph[1]*w;
- dst[2]+= src_morph[2]*w;
+ dst[0] += src_morph[0] * w;
+ dst[1] += src_morph[1] * w;
+ dst[2] += src_morph[2] * w;
}
} break;
case VS::ARRAY_COLOR: {
- for(int k=0;k<count;k++) {
+ for (int k = 0; k < count; k++) {
- const uint8_t *src = (const uint8_t*)&morph[ofs+k*src_stride];
- uint8_t *dst = (uint8_t*)&base[ofs+k*dst_stride];
+ const uint8_t *src = (const uint8_t *)&morph[ofs + k * src_stride];
+ uint8_t *dst = (uint8_t *)&base[ofs + k * dst_stride];
- dst[0]= (src[0]*wfp)>>8;
- dst[1]= (src[1]*wfp)>>8;
- dst[2]= (src[2]*wfp)>>8;
- dst[3]= (src[3]*wfp)>>8;
+ dst[0] = (src[0] * wfp) >> 8;
+ dst[1] = (src[1] * wfp) >> 8;
+ dst[2] = (src[2] * wfp) >> 8;
+ dst[3] = (src[3] * wfp) >> 8;
}
} break;
case VS::ARRAY_TEX_UV:
case VS::ARRAY_TEX_UV2: {
- for(int k=0;k<count;k++) {
+ for (int k = 0; k < count; k++) {
- const float *src_morph = (const float*)&morph[ofs+k*src_stride];
- float *dst = (float*)&base[ofs+k*dst_stride];
+ const float *src_morph = (const float *)&morph[ofs + k * src_stride];
+ float *dst = (float *)&base[ofs + k * dst_stride];
- dst[0]+= src_morph[0]*w;
- dst[1]+= src_morph[1]*w;
+ dst[0] += src_morph[0] * w;
+ dst[1] += src_morph[1] * w;
}
} break;
@@ -5802,30 +5418,23 @@ Error RasterizerGLES2::_setup_geometry(const Geometry *p_geometry, const Materia
}
}
-
-
if (skeleton_valid) {
-
-
- const uint8_t *src_weights=&surf->array_local[surf->array[VS::ARRAY_WEIGHTS].ofs];
- const uint8_t *src_bones=&surf->array_local[surf->array[VS::ARRAY_BONES].ofs];
+ const uint8_t *src_weights = &surf->array_local[surf->array[VS::ARRAY_WEIGHTS].ofs];
+ const uint8_t *src_bones = &surf->array_local[surf->array[VS::ARRAY_BONES].ofs];
const Skeleton::Bone *skeleton = &p_skeleton->bones[0];
-
- if (surf->format&VS::ARRAY_FORMAT_NORMAL && surf->format&VS::ARRAY_FORMAT_TANGENT)
- _skeleton_xform<true,true,true>(base,surf->stride,base,surf->stride,surf->array_len,src_bones,src_weights,skeleton);
- else if (surf->format&(VS::ARRAY_FORMAT_NORMAL))
- _skeleton_xform<true,false,true>(base,surf->stride,base,surf->stride,surf->array_len,src_bones,src_weights,skeleton);
- else if (surf->format&(VS::ARRAY_FORMAT_TANGENT))
- _skeleton_xform<false,true,true>(base,surf->stride,base,surf->stride,surf->array_len,src_bones,src_weights,skeleton);
+ if (surf->format & VS::ARRAY_FORMAT_NORMAL && surf->format & VS::ARRAY_FORMAT_TANGENT)
+ _skeleton_xform<true, true, true>(base, surf->stride, base, surf->stride, surf->array_len, src_bones, src_weights, skeleton);
+ else if (surf->format & (VS::ARRAY_FORMAT_NORMAL))
+ _skeleton_xform<true, false, true>(base, surf->stride, base, surf->stride, surf->array_len, src_bones, src_weights, skeleton);
+ else if (surf->format & (VS::ARRAY_FORMAT_TANGENT))
+ _skeleton_xform<false, true, true>(base, surf->stride, base, surf->stride, surf->array_len, src_bones, src_weights, skeleton);
else
- _skeleton_xform<false,false,true>(base,surf->stride,base,surf->stride,surf->array_len,src_bones,src_weights,skeleton);
-
+ _skeleton_xform<false, false, true>(base, surf->stride, base, surf->stride, surf->array_len, src_bones, src_weights, skeleton);
}
- stride=skeleton_valid?surf->stride:surf->local_stride;
-
+ stride = skeleton_valid ? surf->stride : surf->local_stride;
#if 0
{
@@ -5914,45 +5523,41 @@ Error RasterizerGLES2::_setup_geometry(const Geometry *p_geometry, const Materia
base = skinned_buffer;
//copy stuff and get it ready for the skeleton
- int dst_stride = surf->stride - ( surf->array[VS::ARRAY_BONES].size + surf->array[VS::ARRAY_WEIGHTS].size );
- const uint8_t *src_weights=&surf->array_local[surf->array[VS::ARRAY_WEIGHTS].ofs];
- const uint8_t *src_bones=&surf->array_local[surf->array[VS::ARRAY_BONES].ofs];
+ int dst_stride = surf->stride - (surf->array[VS::ARRAY_BONES].size + surf->array[VS::ARRAY_WEIGHTS].size);
+ const uint8_t *src_weights = &surf->array_local[surf->array[VS::ARRAY_WEIGHTS].ofs];
+ const uint8_t *src_bones = &surf->array_local[surf->array[VS::ARRAY_BONES].ofs];
const Skeleton::Bone *skeleton = &p_skeleton->bones[0];
- if (surf->format&VS::ARRAY_FORMAT_NORMAL && surf->format&VS::ARRAY_FORMAT_TANGENT)
- _skeleton_xform<true,true,false>(surf->array_local,surf->stride,base,dst_stride,surf->array_len,src_bones,src_weights,skeleton);
- else if (surf->format&(VS::ARRAY_FORMAT_NORMAL))
- _skeleton_xform<true,false,false>(surf->array_local,surf->stride,base,dst_stride,surf->array_len,src_bones,src_weights,skeleton);
- else if (surf->format&(VS::ARRAY_FORMAT_TANGENT))
- _skeleton_xform<false,true,false>(surf->array_local,surf->stride,base,dst_stride,surf->array_len,src_bones,src_weights,skeleton);
+ if (surf->format & VS::ARRAY_FORMAT_NORMAL && surf->format & VS::ARRAY_FORMAT_TANGENT)
+ _skeleton_xform<true, true, false>(surf->array_local, surf->stride, base, dst_stride, surf->array_len, src_bones, src_weights, skeleton);
+ else if (surf->format & (VS::ARRAY_FORMAT_NORMAL))
+ _skeleton_xform<true, false, false>(surf->array_local, surf->stride, base, dst_stride, surf->array_len, src_bones, src_weights, skeleton);
+ else if (surf->format & (VS::ARRAY_FORMAT_TANGENT))
+ _skeleton_xform<false, true, false>(surf->array_local, surf->stride, base, dst_stride, surf->array_len, src_bones, src_weights, skeleton);
else
- _skeleton_xform<false,false,false>(surf->array_local,surf->stride,base,dst_stride,surf->array_len,src_bones,src_weights,skeleton);
-
+ _skeleton_xform<false, false, false>(surf->array_local, surf->stride, base, dst_stride, surf->array_len, src_bones, src_weights, skeleton);
- stride=dst_stride;
+ stride = dst_stride;
}
-
-
-
} else {
glBindBuffer(GL_ARRAY_BUFFER, surf->vertex_id);
};
- for (int i=0;i<(VS::ARRAY_MAX-1);i++) {
+ for (int i = 0; i < (VS::ARRAY_MAX - 1); i++) {
- const Surface::ArrayData& ad=surf->array[i];
+ const Surface::ArrayData &ad = surf->array[i];
/*
if (!gl_texcoord_shader[i])
continue;
*/
- if (ad.size==0 || ! ad.bind) {
+ if (ad.size == 0 || !ad.bind) {
glDisableVertexAttribArray(i);
if (i == VS::ARRAY_COLOR) {
- _set_color_attrib(Color(1, 1, 1,1));
+ _set_color_attrib(Color(1, 1, 1, 1));
};
//print_line("disable: "+itos(i));
continue; // this one is disabled.
@@ -5961,11 +5566,10 @@ Error RasterizerGLES2::_setup_geometry(const Geometry *p_geometry, const Materia
glEnableVertexAttribArray(i);
//print_line("set: "+itos(i)+" - count: "+itos(ad.count)+" datatype: "+itos(ad.datatype)+" ofs: "+itos(ad.ofs)+" stride: "+itos(stride)+" total len: "+itos(surf->array_len));
glVertexAttribPointer(i, ad.count, ad.datatype, ad.normalize, stride, &base[ad.ofs]);
-
}
#ifdef GLEW_ENABLED
-//"desktop" opengl needs this.
- if (surf->primitive==VS::PRIMITIVE_POINTS) {
+ //"desktop" opengl needs this.
+ if (surf->primitive == VS::PRIMITIVE_POINTS) {
glEnable(GL_POINT_SPRITE);
glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
@@ -5977,13 +5581,12 @@ Error RasterizerGLES2::_setup_geometry(const Geometry *p_geometry, const Materia
} break;
default: break;
-
};
return OK;
};
-static const GLenum gl_primitive[]={
+static const GLenum gl_primitive[] = {
GL_POINTS,
GL_LINES,
GL_LINE_STRIP,
@@ -5993,43 +5596,37 @@ static const GLenum gl_primitive[]={
GL_TRIANGLE_FAN
};
-
-
-void RasterizerGLES2::_render(const Geometry *p_geometry,const Material *p_material, const Skeleton* p_skeleton, const GeometryOwner *p_owner,const Transform& p_xform) {
-
+void RasterizerGLES2::_render(const Geometry *p_geometry, const Material *p_material, const Skeleton *p_skeleton, const GeometryOwner *p_owner, const Transform &p_xform) {
_rinfo.object_count++;
- switch(p_geometry->type) {
+ switch (p_geometry->type) {
case Geometry::GEOMETRY_SURFACE: {
- Surface *s = (Surface*)p_geometry;
+ Surface *s = (Surface *)p_geometry;
- _rinfo.vertex_count+=s->array_len;
+ _rinfo.vertex_count += s->array_len;
- if (s->index_array_len>0) {
+ if (s->index_array_len > 0) {
if (s->index_array_local) {
//print_line("LOCAL F: "+itos(s->format)+" C: "+itos(s->index_array_len)+" VC: "+itos(s->array_len));
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0);
- glDrawElements(gl_primitive[s->primitive], s->index_array_len, (s->array_len>(1<<16))?GL_UNSIGNED_INT:GL_UNSIGNED_SHORT, s->index_array_local);
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
+ glDrawElements(gl_primitive[s->primitive], s->index_array_len, (s->array_len > (1 << 16)) ? GL_UNSIGNED_INT : GL_UNSIGNED_SHORT, s->index_array_local);
} else {
//print_line("indices: "+itos(s->index_array_local) );
-
//print_line("VBO F: "+itos(s->format)+" C: "+itos(s->index_array_len)+" VC: "+itos(s->array_len));
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,s->index_id);
- glDrawElements(gl_primitive[s->primitive],s->index_array_len, (s->array_len>(1<<16))?GL_UNSIGNED_INT:GL_UNSIGNED_SHORT,0);
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, s->index_id);
+ glDrawElements(gl_primitive[s->primitive], s->index_array_len, (s->array_len > (1 << 16)) ? GL_UNSIGNED_INT : GL_UNSIGNED_SHORT, 0);
}
-
} else {
- glDrawArrays(gl_primitive[s->primitive],0,s->array_len);
-
+ glDrawArrays(gl_primitive[s->primitive], 0, s->array_len);
};
_rinfo.draw_calls++;
@@ -6038,145 +5635,136 @@ void RasterizerGLES2::_render(const Geometry *p_geometry,const Material *p_mater
case Geometry::GEOMETRY_MULTISURFACE: {
material_shader.bind_uniforms();
- Surface *s = static_cast<const MultiMeshSurface*>(p_geometry)->surface;
- const MultiMesh *mm = static_cast<const MultiMesh*>(p_owner);
- int element_count=mm->elements.size();
+ Surface *s = static_cast<const MultiMeshSurface *>(p_geometry)->surface;
+ const MultiMesh *mm = static_cast<const MultiMesh *>(p_owner);
+ int element_count = mm->elements.size();
- if (element_count==0)
+ if (element_count == 0)
return;
- if (mm->visible>=0) {
- element_count=MIN(element_count,mm->visible);
+ if (mm->visible >= 0) {
+ element_count = MIN(element_count, mm->visible);
}
- const MultiMesh::Element *elements=&mm->elements[0];
-
- _rinfo.vertex_count+=s->array_len*element_count;
+ const MultiMesh::Element *elements = &mm->elements[0];
- _rinfo.draw_calls+=element_count;
+ _rinfo.vertex_count += s->array_len * element_count;
+ _rinfo.draw_calls += element_count;
if (use_texture_instancing) {
//this is probably the fastest all around way if vertex texture fetch is supported
- float twd=(1.0/mm->tw)*4.0;
- float thd=1.0/mm->th;
- float parm[3]={0.0,01.0,(1.0f/mm->tw)};
- glActiveTexture(GL_TEXTURE0+max_texture_units-2);
+ float twd = (1.0 / mm->tw) * 4.0;
+ float thd = 1.0 / mm->th;
+ float parm[3] = { 0.0, 01.0, (1.0f / mm->tw) };
+ glActiveTexture(GL_TEXTURE0 + max_texture_units - 2);
glDisableVertexAttribArray(6);
- glBindTexture(GL_TEXTURE_2D,mm->tex_id);
- material_shader.set_uniform(MaterialShaderGLES2::INSTANCE_MATRICES,GL_TEXTURE0+max_texture_units-2);
-
- if (s->index_array_len>0) {
+ glBindTexture(GL_TEXTURE_2D, mm->tex_id);
+ material_shader.set_uniform(MaterialShaderGLES2::INSTANCE_MATRICES, GL_TEXTURE0 + max_texture_units - 2);
+ if (s->index_array_len > 0) {
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,s->index_id);
- for(int i=0;i<element_count;i++) {
- parm[0]=(i%(mm->tw>>2))*twd;
- parm[1]=(i/(mm->tw>>2))*thd;
- glVertexAttrib3fv(6,parm);
- glDrawElements(gl_primitive[s->primitive],s->index_array_len, (s->array_len>(1<<16))?GL_UNSIGNED_INT:GL_UNSIGNED_SHORT,0);
-
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, s->index_id);
+ for (int i = 0; i < element_count; i++) {
+ parm[0] = (i % (mm->tw >> 2)) * twd;
+ parm[1] = (i / (mm->tw >> 2)) * thd;
+ glVertexAttrib3fv(6, parm);
+ glDrawElements(gl_primitive[s->primitive], s->index_array_len, (s->array_len > (1 << 16)) ? GL_UNSIGNED_INT : GL_UNSIGNED_SHORT, 0);
}
-
} else {
- for(int i=0;i<element_count;i++) {
+ for (int i = 0; i < element_count; i++) {
//parm[0]=(i%(mm->tw>>2))*twd;
//parm[1]=(i/(mm->tw>>2))*thd;
- glVertexAttrib3fv(6,parm);
- glDrawArrays(gl_primitive[s->primitive],0,s->array_len);
+ glVertexAttrib3fv(6, parm);
+ glDrawArrays(gl_primitive[s->primitive], 0, s->array_len);
}
- };
+ };
} else if (use_attribute_instancing) {
//if not, using atributes instead of uniforms can be really fast in forward rendering architectures
- if (s->index_array_len>0) {
-
-
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,s->index_id);
- for(int i=0;i<element_count;i++) {
- glVertexAttrib4fv(8,&elements[i].matrix[0]);
- glVertexAttrib4fv(9,&elements[i].matrix[4]);
- glVertexAttrib4fv(10,&elements[i].matrix[8]);
- glVertexAttrib4fv(11,&elements[i].matrix[12]);
- glDrawElements(gl_primitive[s->primitive],s->index_array_len, (s->array_len>(1<<16))?GL_UNSIGNED_INT:GL_UNSIGNED_SHORT,0);
+ if (s->index_array_len > 0) {
+
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, s->index_id);
+ for (int i = 0; i < element_count; i++) {
+ glVertexAttrib4fv(8, &elements[i].matrix[0]);
+ glVertexAttrib4fv(9, &elements[i].matrix[4]);
+ glVertexAttrib4fv(10, &elements[i].matrix[8]);
+ glVertexAttrib4fv(11, &elements[i].matrix[12]);
+ glDrawElements(gl_primitive[s->primitive], s->index_array_len, (s->array_len > (1 << 16)) ? GL_UNSIGNED_INT : GL_UNSIGNED_SHORT, 0);
}
-
} else {
- for(int i=0;i<element_count;i++) {
- glVertexAttrib4fv(8,&elements[i].matrix[0]);
- glVertexAttrib4fv(9,&elements[i].matrix[4]);
- glVertexAttrib4fv(10,&elements[i].matrix[8]);
- glVertexAttrib4fv(11,&elements[i].matrix[12]);
- glDrawArrays(gl_primitive[s->primitive],0,s->array_len);
+ for (int i = 0; i < element_count; i++) {
+ glVertexAttrib4fv(8, &elements[i].matrix[0]);
+ glVertexAttrib4fv(9, &elements[i].matrix[4]);
+ glVertexAttrib4fv(10, &elements[i].matrix[8]);
+ glVertexAttrib4fv(11, &elements[i].matrix[12]);
+ glDrawArrays(gl_primitive[s->primitive], 0, s->array_len);
}
- };
-
+ };
} else {
//nothing to do, slow path (hope no hardware has to use it... but you never know)
- if (s->index_array_len>0) {
+ if (s->index_array_len > 0) {
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,s->index_id);
- for(int i=0;i<element_count;i++) {
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, s->index_id);
+ for (int i = 0; i < element_count; i++) {
glUniformMatrix4fv(material_shader.get_uniform_location(MaterialShaderGLES2::INSTANCE_TRANSFORM), 1, false, elements[i].matrix);
- glDrawElements(gl_primitive[s->primitive],s->index_array_len, (s->array_len>(1<<16))?GL_UNSIGNED_INT:GL_UNSIGNED_SHORT,0);
+ glDrawElements(gl_primitive[s->primitive], s->index_array_len, (s->array_len > (1 << 16)) ? GL_UNSIGNED_INT : GL_UNSIGNED_SHORT, 0);
}
-
} else {
- for(int i=0;i<element_count;i++) {
+ for (int i = 0; i < element_count; i++) {
glUniformMatrix4fv(material_shader.get_uniform_location(MaterialShaderGLES2::INSTANCE_TRANSFORM), 1, false, elements[i].matrix);
- glDrawArrays(gl_primitive[s->primitive],0,s->array_len);
+ glDrawArrays(gl_primitive[s->primitive], 0, s->array_len);
}
- };
+ };
}
- } break;
+ } break;
case Geometry::GEOMETRY_IMMEDIATE: {
- bool restore_tex=false;
- const Immediate *im = static_cast<const Immediate*>( p_geometry );
+ bool restore_tex = false;
+ const Immediate *im = static_cast<const Immediate *>(p_geometry);
if (im->building) {
return;
}
glBindBuffer(GL_ARRAY_BUFFER, 0);
- for(const List<Immediate::Chunk>::Element *E=im->chunks.front();E;E=E->next()) {
+ for (const List<Immediate::Chunk>::Element *E = im->chunks.front(); E; E = E->next()) {
- const Immediate::Chunk &c=E->get();
+ const Immediate::Chunk &c = E->get();
if (c.vertices.empty()) {
continue;
}
- for(int i=0;i<c.vertices.size();i++)
-
- if (c.texture.is_valid() && texture_owner.owns(c.texture)) {
+ for (int i = 0; i < c.vertices.size(); i++)
- const Texture *t = texture_owner.get(c.texture);
- glActiveTexture(GL_TEXTURE0+tc0_idx);
- glBindTexture(t->target,t->tex_id);
- restore_tex=true;
+ if (c.texture.is_valid() && texture_owner.owns(c.texture)) {
+ const Texture *t = texture_owner.get(c.texture);
+ glActiveTexture(GL_TEXTURE0 + tc0_idx);
+ glBindTexture(t->target, t->tex_id);
+ restore_tex = true;
- } else if (restore_tex) {
+ } else if (restore_tex) {
- glActiveTexture(GL_TEXTURE0+tc0_idx);
- glBindTexture(GL_TEXTURE_2D,tc0_id_cache);
- restore_tex=false;
- }
+ glActiveTexture(GL_TEXTURE0 + tc0_idx);
+ glBindTexture(GL_TEXTURE_2D, tc0_id_cache);
+ restore_tex = false;
+ }
if (!c.normals.empty()) {
glEnableVertexAttribArray(VS::ARRAY_NORMAL);
- glVertexAttribPointer(VS::ARRAY_NORMAL, 3, GL_FLOAT, false,sizeof(Vector3),c.normals.ptr());
+ glVertexAttribPointer(VS::ARRAY_NORMAL, 3, GL_FLOAT, false, sizeof(Vector3), c.normals.ptr());
} else {
@@ -6186,7 +5774,7 @@ void RasterizerGLES2::_render(const Geometry *p_geometry,const Material *p_mater
if (!c.tangents.empty()) {
glEnableVertexAttribArray(VS::ARRAY_TANGENT);
- glVertexAttribPointer(VS::ARRAY_TANGENT, 4, GL_FLOAT, false,sizeof(Plane),c.tangents.ptr());
+ glVertexAttribPointer(VS::ARRAY_TANGENT, 4, GL_FLOAT, false, sizeof(Plane), c.tangents.ptr());
} else {
@@ -6196,19 +5784,18 @@ void RasterizerGLES2::_render(const Geometry *p_geometry,const Material *p_mater
if (!c.colors.empty()) {
glEnableVertexAttribArray(VS::ARRAY_COLOR);
- glVertexAttribPointer(VS::ARRAY_COLOR, 4, GL_FLOAT, false,sizeof(Color),c.colors.ptr());
+ glVertexAttribPointer(VS::ARRAY_COLOR, 4, GL_FLOAT, false, sizeof(Color), c.colors.ptr());
} else {
glDisableVertexAttribArray(VS::ARRAY_COLOR);
- _set_color_attrib(Color(1, 1, 1,1));
+ _set_color_attrib(Color(1, 1, 1, 1));
}
-
if (!c.uvs.empty()) {
glEnableVertexAttribArray(VS::ARRAY_TEX_UV);
- glVertexAttribPointer(VS::ARRAY_TEX_UV, 2, GL_FLOAT, false,sizeof(Vector2),c.uvs.ptr());
+ glVertexAttribPointer(VS::ARRAY_TEX_UV, 2, GL_FLOAT, false, sizeof(Vector2), c.uvs.ptr());
} else {
@@ -6218,101 +5805,91 @@ void RasterizerGLES2::_render(const Geometry *p_geometry,const Material *p_mater
if (!c.uvs2.empty()) {
glEnableVertexAttribArray(VS::ARRAY_TEX_UV2);
- glVertexAttribPointer(VS::ARRAY_TEX_UV2, 2, GL_FLOAT, false,sizeof(Vector2),c.uvs2.ptr());
+ glVertexAttribPointer(VS::ARRAY_TEX_UV2, 2, GL_FLOAT, false, sizeof(Vector2), c.uvs2.ptr());
} else {
glDisableVertexAttribArray(VS::ARRAY_TEX_UV2);
}
-
glEnableVertexAttribArray(VS::ARRAY_VERTEX);
- glVertexAttribPointer(VS::ARRAY_VERTEX, 3, GL_FLOAT, false,sizeof(Vector3),c.vertices.ptr());
- glDrawArrays(gl_primitive[c.primitive],0,c.vertices.size());
-
-
+ glVertexAttribPointer(VS::ARRAY_VERTEX, 3, GL_FLOAT, false, sizeof(Vector3), c.vertices.ptr());
+ glDrawArrays(gl_primitive[c.primitive], 0, c.vertices.size());
}
-
if (restore_tex) {
- glActiveTexture(GL_TEXTURE0+tc0_idx);
- glBindTexture(GL_TEXTURE_2D,tc0_id_cache);
- restore_tex=false;
+ glActiveTexture(GL_TEXTURE0 + tc0_idx);
+ glBindTexture(GL_TEXTURE_2D, tc0_id_cache);
+ restore_tex = false;
}
-
} break;
case Geometry::GEOMETRY_PARTICLES: {
-
//print_line("particulinas");
- const Particles *particles = static_cast<const Particles*>( p_geometry );
+ const Particles *particles = static_cast<const Particles *>(p_geometry);
ERR_FAIL_COND(!p_owner);
- ParticlesInstance *particles_instance = (ParticlesInstance*)p_owner;
+ ParticlesInstance *particles_instance = (ParticlesInstance *)p_owner;
ParticleSystemProcessSW &pp = particles_instance->particles_process;
float td = time_delta; //MIN(time_delta,1.0/10.0);
- pp.process(&particles->data,particles_instance->transform,td);
+ pp.process(&particles->data, particles_instance->transform, td);
ERR_EXPLAIN("A parameter in the particle system is not correct.");
ERR_FAIL_COND(!pp.valid);
-
Transform camera;
if (shadow)
- camera=shadow->transform;
+ camera = shadow->transform;
else
- camera=camera_transform;
-
- particle_draw_info.prepare(&particles->data,&pp,particles_instance->transform,camera);
- _rinfo.draw_calls+=particles->data.amount;
+ camera = camera_transform;
+ particle_draw_info.prepare(&particles->data, &pp, particles_instance->transform, camera);
+ _rinfo.draw_calls += particles->data.amount;
- _rinfo.vertex_count+=4*particles->data.amount;
+ _rinfo.vertex_count += 4 * particles->data.amount;
{
- static const Vector3 points[4]={
- Vector3(-1.0,1.0,0),
- Vector3(1.0,1.0,0),
- Vector3(1.0,-1.0,0),
- Vector3(-1.0,-1.0,0)
+ static const Vector3 points[4] = {
+ Vector3(-1.0, 1.0, 0),
+ Vector3(1.0, 1.0, 0),
+ Vector3(1.0, -1.0, 0),
+ Vector3(-1.0, -1.0, 0)
};
- static const Vector3 uvs[4]={
- Vector3(0.0,0.0,0.0),
- Vector3(1.0,0.0,0.0),
- Vector3(1.0,1.0,0.0),
- Vector3(0,1.0,0.0)
+ static const Vector3 uvs[4] = {
+ Vector3(0.0, 0.0, 0.0),
+ Vector3(1.0, 0.0, 0.0),
+ Vector3(1.0, 1.0, 0.0),
+ Vector3(0, 1.0, 0.0)
};
- static const Vector3 normals[4]={
- Vector3(0,0,1),
- Vector3(0,0,1),
- Vector3(0,0,1),
- Vector3(0,0,1)
+ static const Vector3 normals[4] = {
+ Vector3(0, 0, 1),
+ Vector3(0, 0, 1),
+ Vector3(0, 0, 1),
+ Vector3(0, 0, 1)
};
- static const Plane tangents[4]={
- Plane(Vector3(1,0,0),0),
- Plane(Vector3(1,0,0),0),
- Plane(Vector3(1,0,0),0),
- Plane(Vector3(1,0,0),0)
+ static const Plane tangents[4] = {
+ Plane(Vector3(1, 0, 0), 0),
+ Plane(Vector3(1, 0, 0), 0),
+ Plane(Vector3(1, 0, 0), 0),
+ Plane(Vector3(1, 0, 0), 0)
};
- for(int i=0;i<particles->data.amount;i++) {
+ for (int i = 0; i < particles->data.amount; i++) {
- ParticleSystemDrawInfoSW::ParticleDrawInfo &pinfo=*particle_draw_info.draw_info_order[i];
+ ParticleSystemDrawInfoSW::ParticleDrawInfo &pinfo = *particle_draw_info.draw_info_order[i];
if (!pinfo.data->active)
continue;
material_shader.set_uniform(MaterialShaderGLES2::WORLD_TRANSFORM, pinfo.transform);
_set_color_attrib(pinfo.color);
- _draw_primitive(4,points,normals,NULL,uvs,tangents);
-
+ _draw_primitive(4, points, normals, NULL, uvs, tangents);
}
-
}
} break;
- default: break;
+ default: break;
};
};
@@ -6358,234 +5935,214 @@ void RasterizerGLES2::_setup_shader_params(const Material *p_material) {
}
#endif
-
}
void RasterizerGLES2::_setup_skeleton(const Skeleton *p_skeleton) {
- material_shader.set_conditional(MaterialShaderGLES2::USE_SKELETON,p_skeleton!=NULL);
+ material_shader.set_conditional(MaterialShaderGLES2::USE_SKELETON, p_skeleton != NULL);
if (p_skeleton && p_skeleton->tex_id) {
- glActiveTexture(GL_TEXTURE0+max_texture_units-2);
- glBindTexture(GL_TEXTURE_2D,p_skeleton->tex_id);
+ glActiveTexture(GL_TEXTURE0 + max_texture_units - 2);
+ glBindTexture(GL_TEXTURE_2D, p_skeleton->tex_id);
}
-
-
}
-
-void RasterizerGLES2::_render_list_forward(RenderList *p_render_list,const Transform& p_view_transform, const Transform& p_view_transform_inverse,const CameraMatrix& p_projection,bool p_reverse_cull,bool p_fragment_light,bool p_alpha_pass) {
+void RasterizerGLES2::_render_list_forward(RenderList *p_render_list, const Transform &p_view_transform, const Transform &p_view_transform_inverse, const CameraMatrix &p_projection, bool p_reverse_cull, bool p_fragment_light, bool p_alpha_pass) {
if (current_rt && current_rt_vflip) {
//p_reverse_cull=!p_reverse_cull;
glFrontFace(GL_CCW);
-
}
- const Material *prev_material=NULL;
- uint16_t prev_light=0x777E;
- const Geometry *prev_geometry_cmp=NULL;
- uint8_t prev_light_type=0xEF;
- const Skeleton *prev_skeleton =NULL;
- uint8_t prev_sort_flags=0xFF;
- const BakedLightData *prev_baked_light=NULL;
+ const Material *prev_material = NULL;
+ uint16_t prev_light = 0x777E;
+ const Geometry *prev_geometry_cmp = NULL;
+ uint8_t prev_light_type = 0xEF;
+ const Skeleton *prev_skeleton = NULL;
+ uint8_t prev_sort_flags = 0xFF;
+ const BakedLightData *prev_baked_light = NULL;
RID prev_baked_light_texture;
- const float *prev_morph_values=NULL;
- int prev_receive_shadows_state=-1;
+ const float *prev_morph_values = NULL;
+ int prev_receive_shadows_state = -1;
- material_shader.set_conditional(MaterialShaderGLES2::USE_VERTEX_LIGHTING,!shadow && !p_fragment_light);
- material_shader.set_conditional(MaterialShaderGLES2::USE_FRAGMENT_LIGHTING,!shadow && p_fragment_light);
- material_shader.set_conditional(MaterialShaderGLES2::USE_SKELETON,false);
+ material_shader.set_conditional(MaterialShaderGLES2::USE_VERTEX_LIGHTING, !shadow && !p_fragment_light);
+ material_shader.set_conditional(MaterialShaderGLES2::USE_FRAGMENT_LIGHTING, !shadow && p_fragment_light);
+ material_shader.set_conditional(MaterialShaderGLES2::USE_SKELETON, false);
if (shadow) {
- material_shader.set_conditional(MaterialShaderGLES2::LIGHT_TYPE_DIRECTIONAL,false);
- material_shader.set_conditional(MaterialShaderGLES2::LIGHT_TYPE_OMNI,false);
- material_shader.set_conditional(MaterialShaderGLES2::LIGHT_TYPE_SPOT,false);
- material_shader.set_conditional(MaterialShaderGLES2::LIGHT_USE_SHADOW,false);
- material_shader.set_conditional(MaterialShaderGLES2::LIGHT_USE_PSSM,false);
- material_shader.set_conditional(MaterialShaderGLES2::LIGHT_USE_PSSM4,false);
- material_shader.set_conditional(MaterialShaderGLES2::SHADELESS,false);
- material_shader.set_conditional(MaterialShaderGLES2::ENABLE_AMBIENT_OCTREE,false);
- material_shader.set_conditional(MaterialShaderGLES2::ENABLE_AMBIENT_LIGHTMAP,false);
+ material_shader.set_conditional(MaterialShaderGLES2::LIGHT_TYPE_DIRECTIONAL, false);
+ material_shader.set_conditional(MaterialShaderGLES2::LIGHT_TYPE_OMNI, false);
+ material_shader.set_conditional(MaterialShaderGLES2::LIGHT_TYPE_SPOT, false);
+ material_shader.set_conditional(MaterialShaderGLES2::LIGHT_USE_SHADOW, false);
+ material_shader.set_conditional(MaterialShaderGLES2::LIGHT_USE_PSSM, false);
+ material_shader.set_conditional(MaterialShaderGLES2::LIGHT_USE_PSSM4, false);
+ material_shader.set_conditional(MaterialShaderGLES2::SHADELESS, false);
+ material_shader.set_conditional(MaterialShaderGLES2::ENABLE_AMBIENT_OCTREE, false);
+ material_shader.set_conditional(MaterialShaderGLES2::ENABLE_AMBIENT_LIGHTMAP, false);
//material_shader.set_conditional(MaterialShaderGLES2::ENABLE_AMBIENT_TEXTURE,false);
-
}
-
-
bool stores_glow = !shadow && (current_env && current_env->fx_enabled[VS::ENV_FX_GLOW]) && !p_alpha_pass;
- float sampled_light_dp_multiplier=1.0;
+ float sampled_light_dp_multiplier = 1.0;
- bool prev_blend=false;
+ bool prev_blend = false;
glDisable(GL_BLEND);
- for (int i=0;i<p_render_list->element_count;i++) {
+ for (int i = 0; i < p_render_list->element_count; i++) {
RenderList::Element *e = p_render_list->elements[i];
const Material *material = e->material;
uint16_t light = e->light;
uint8_t light_type = e->light_type;
- uint8_t sort_flags= e->sort_flags;
+ uint8_t sort_flags = e->sort_flags;
const Skeleton *skeleton = e->skeleton;
const Geometry *geometry_cmp = e->geometry_cmp;
const BakedLightData *baked_light = e->instance->baked_light;
const float *morph_values = e->instance->morph_values.ptr();
int receive_shadows_state = e->instance->receive_shadows == true ? 1 : 0;
- bool rebind=false;
- bool bind_baked_light_octree=false;
- bool bind_baked_lightmap=false;
- bool additive=false;
- bool bind_dp_sampler=false;
-
+ bool rebind = false;
+ bool bind_baked_light_octree = false;
+ bool bind_baked_lightmap = false;
+ bool additive = false;
+ bool bind_dp_sampler = false;
if (!shadow) {
if (texscreen_used && !texscreen_copied && material->shader_cache && material->shader_cache->valid && material->shader_cache->has_texscreen) {
- texscreen_copied=true;
+ texscreen_copied = true;
_copy_to_texscreen();
//force reset state
- prev_material=NULL;
- prev_light=0x777E;
- prev_geometry_cmp=NULL;
- prev_light_type=0xEF;
- prev_skeleton =NULL;
- prev_sort_flags=0xFF;
- prev_morph_values=NULL;
- prev_receive_shadows_state=-1;
+ prev_material = NULL;
+ prev_light = 0x777E;
+ prev_geometry_cmp = NULL;
+ prev_light_type = 0xEF;
+ prev_skeleton = NULL;
+ prev_sort_flags = 0xFF;
+ prev_morph_values = NULL;
+ prev_receive_shadows_state = -1;
glEnable(GL_BLEND);
glDepthMask(GL_TRUE);
glEnable(GL_DEPTH_TEST);
glDisable(GL_SCISSOR_TEST);
-
}
- if (light_type!=prev_light_type || receive_shadows_state!=prev_receive_shadows_state) {
+ if (light_type != prev_light_type || receive_shadows_state != prev_receive_shadows_state) {
- if (material->flags[VS::MATERIAL_FLAG_UNSHADED] || current_debug==VS::SCENARIO_DEBUG_SHADELESS) {
- material_shader.set_conditional(MaterialShaderGLES2::LIGHT_TYPE_DIRECTIONAL,false);
- material_shader.set_conditional(MaterialShaderGLES2::LIGHT_TYPE_OMNI,false);
- material_shader.set_conditional(MaterialShaderGLES2::LIGHT_TYPE_SPOT,false);
- material_shader.set_conditional(MaterialShaderGLES2::LIGHT_USE_SHADOW,false);
- material_shader.set_conditional(MaterialShaderGLES2::LIGHT_USE_PSSM,false);
- material_shader.set_conditional(MaterialShaderGLES2::LIGHT_USE_PSSM4,false);
- material_shader.set_conditional(MaterialShaderGLES2::SHADELESS,true);
+ if (material->flags[VS::MATERIAL_FLAG_UNSHADED] || current_debug == VS::SCENARIO_DEBUG_SHADELESS) {
+ material_shader.set_conditional(MaterialShaderGLES2::LIGHT_TYPE_DIRECTIONAL, false);
+ material_shader.set_conditional(MaterialShaderGLES2::LIGHT_TYPE_OMNI, false);
+ material_shader.set_conditional(MaterialShaderGLES2::LIGHT_TYPE_SPOT, false);
+ material_shader.set_conditional(MaterialShaderGLES2::LIGHT_USE_SHADOW, false);
+ material_shader.set_conditional(MaterialShaderGLES2::LIGHT_USE_PSSM, false);
+ material_shader.set_conditional(MaterialShaderGLES2::LIGHT_USE_PSSM4, false);
+ material_shader.set_conditional(MaterialShaderGLES2::SHADELESS, true);
} else {
- material_shader.set_conditional(MaterialShaderGLES2::LIGHT_TYPE_DIRECTIONAL,(light_type&0x3)==VS::LIGHT_DIRECTIONAL);
- material_shader.set_conditional(MaterialShaderGLES2::LIGHT_TYPE_OMNI,(light_type&0x3)==VS::LIGHT_OMNI);
- material_shader.set_conditional(MaterialShaderGLES2::LIGHT_TYPE_SPOT,(light_type&0x3)==VS::LIGHT_SPOT);
- if (receive_shadows_state==1) {
- material_shader.set_conditional(MaterialShaderGLES2::LIGHT_USE_SHADOW,(light_type&0x8));
- material_shader.set_conditional(MaterialShaderGLES2::LIGHT_USE_PSSM,(light_type&0x10));
- material_shader.set_conditional(MaterialShaderGLES2::LIGHT_USE_PSSM4,(light_type&0x20));
- }
- else {
- material_shader.set_conditional(MaterialShaderGLES2::LIGHT_USE_SHADOW,false);
- material_shader.set_conditional(MaterialShaderGLES2::LIGHT_USE_PSSM,false);
- material_shader.set_conditional(MaterialShaderGLES2::LIGHT_USE_PSSM4,false);
+ material_shader.set_conditional(MaterialShaderGLES2::LIGHT_TYPE_DIRECTIONAL, (light_type & 0x3) == VS::LIGHT_DIRECTIONAL);
+ material_shader.set_conditional(MaterialShaderGLES2::LIGHT_TYPE_OMNI, (light_type & 0x3) == VS::LIGHT_OMNI);
+ material_shader.set_conditional(MaterialShaderGLES2::LIGHT_TYPE_SPOT, (light_type & 0x3) == VS::LIGHT_SPOT);
+ if (receive_shadows_state == 1) {
+ material_shader.set_conditional(MaterialShaderGLES2::LIGHT_USE_SHADOW, (light_type & 0x8));
+ material_shader.set_conditional(MaterialShaderGLES2::LIGHT_USE_PSSM, (light_type & 0x10));
+ material_shader.set_conditional(MaterialShaderGLES2::LIGHT_USE_PSSM4, (light_type & 0x20));
+ } else {
+ material_shader.set_conditional(MaterialShaderGLES2::LIGHT_USE_SHADOW, false);
+ material_shader.set_conditional(MaterialShaderGLES2::LIGHT_USE_PSSM, false);
+ material_shader.set_conditional(MaterialShaderGLES2::LIGHT_USE_PSSM4, false);
}
- material_shader.set_conditional(MaterialShaderGLES2::SHADELESS,false);
+ material_shader.set_conditional(MaterialShaderGLES2::SHADELESS, false);
}
- rebind=true;
+ rebind = true;
}
-
if (!*e->additive_ptr) {
- additive=false;
- *e->additive_ptr=true;
+ additive = false;
+ *e->additive_ptr = true;
} else {
- additive=true;
+ additive = true;
}
-
if (stores_glow)
- material_shader.set_conditional(MaterialShaderGLES2::USE_GLOW,!additive);
-
+ material_shader.set_conditional(MaterialShaderGLES2::USE_GLOW, !additive);
- bool desired_blend=false;
- VS::MaterialBlendMode desired_blend_mode=VS::MATERIAL_BLEND_MODE_MIX;
+ bool desired_blend = false;
+ VS::MaterialBlendMode desired_blend_mode = VS::MATERIAL_BLEND_MODE_MIX;
if (additive) {
- desired_blend=true;
- desired_blend_mode=VS::MATERIAL_BLEND_MODE_ADD;
+ desired_blend = true;
+ desired_blend_mode = VS::MATERIAL_BLEND_MODE_ADD;
} else {
- desired_blend=p_alpha_pass;
- desired_blend_mode=material->blend_mode;
+ desired_blend = p_alpha_pass;
+ desired_blend_mode = material->blend_mode;
}
- if (prev_blend!=desired_blend) {
+ if (prev_blend != desired_blend) {
if (desired_blend) {
glEnable(GL_BLEND);
if (!current_rt || !current_rt_transparent)
- glColorMask(1,1,1,0);
+ glColorMask(1, 1, 1, 0);
} else {
glDisable(GL_BLEND);
- glColorMask(1,1,1,1);
-
+ glColorMask(1, 1, 1, 1);
}
- prev_blend=desired_blend;
+ prev_blend = desired_blend;
}
- if (desired_blend && desired_blend_mode!=current_blend_mode) {
-
+ if (desired_blend && desired_blend_mode != current_blend_mode) {
- switch(desired_blend_mode) {
+ switch (desired_blend_mode) {
- case VS::MATERIAL_BLEND_MODE_MIX: {
+ case VS::MATERIAL_BLEND_MODE_MIX: {
glBlendEquation(GL_FUNC_ADD);
if (current_rt && current_rt_transparent) {
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
- }
- else {
+ } else {
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
- } break;
- case VS::MATERIAL_BLEND_MODE_ADD: {
+ } break;
+ case VS::MATERIAL_BLEND_MODE_ADD: {
glBlendEquation(GL_FUNC_ADD);
- glBlendFunc(p_alpha_pass?GL_SRC_ALPHA:GL_ONE,GL_ONE);
+ glBlendFunc(p_alpha_pass ? GL_SRC_ALPHA : GL_ONE, GL_ONE);
- } break;
- case VS::MATERIAL_BLEND_MODE_SUB: {
+ } break;
+ case VS::MATERIAL_BLEND_MODE_SUB: {
glBlendEquation(GL_FUNC_REVERSE_SUBTRACT);
- glBlendFunc(GL_SRC_ALPHA,GL_ONE);
- } break;
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE);
+ } break;
case VS::MATERIAL_BLEND_MODE_MUL: {
glBlendEquation(GL_FUNC_ADD);
if (current_rt && current_rt_transparent) {
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
- }
- else {
+ } else {
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
} break;
-
}
- current_blend_mode=desired_blend_mode;
+ current_blend_mode = desired_blend_mode;
}
- material_shader.set_conditional(MaterialShaderGLES2::ENABLE_AMBIENT_OCTREE,false);
- material_shader.set_conditional(MaterialShaderGLES2::ENABLE_AMBIENT_LIGHTMAP,false);
- material_shader.set_conditional(MaterialShaderGLES2::ENABLE_AMBIENT_DP_SAMPLER,false);
+ material_shader.set_conditional(MaterialShaderGLES2::ENABLE_AMBIENT_OCTREE, false);
+ material_shader.set_conditional(MaterialShaderGLES2::ENABLE_AMBIENT_LIGHTMAP, false);
+ material_shader.set_conditional(MaterialShaderGLES2::ENABLE_AMBIENT_DP_SAMPLER, false);
material_shader.set_conditional(MaterialShaderGLES2::ENABLE_AMBIENT_COLOR, false);
-
if (material->flags[VS::MATERIAL_FLAG_UNSHADED] == false && current_debug != VS::SCENARIO_DEBUG_SHADELESS) {
if (baked_light != NULL) {
if (baked_light->realtime_color_enabled) {
float realtime_energy = baked_light->realtime_energy;
material_shader.set_conditional(MaterialShaderGLES2::ENABLE_AMBIENT_COLOR, true);
- material_shader.set_uniform(MaterialShaderGLES2::AMBIENT_COLOR, Vector3(baked_light->realtime_color.r*realtime_energy, baked_light->realtime_color.g*realtime_energy, baked_light->realtime_color.b*realtime_energy));
+ material_shader.set_uniform(MaterialShaderGLES2::AMBIENT_COLOR, Vector3(baked_light->realtime_color.r * realtime_energy, baked_light->realtime_color.g * realtime_energy, baked_light->realtime_color.b * realtime_energy));
}
}
@@ -6603,7 +6160,6 @@ void RasterizerGLES2::_render_list_forward(RenderList *p_render_list,const Trans
}
}
-
if (!additive && baked_light) {
if (baked_light->mode == VS::BAKED_LIGHT_OCTREE && baked_light->octree_texture.is_valid() && e->instance->baked_light_octree_xform) {
@@ -6623,26 +6179,20 @@ void RasterizerGLES2::_render_list_forward(RenderList *p_render_list,const Trans
glBindTexture(texl->target, texl->tex_id); //bind the light texture
}
}
-
}
- }
- else if (baked_light->mode == VS::BAKED_LIGHT_LIGHTMAPS) {
-
+ } else if (baked_light->mode == VS::BAKED_LIGHT_LIGHTMAPS) {
int lightmap_idx = e->instance->baked_lightmap_id;
material_shader.set_conditional(MaterialShaderGLES2::ENABLE_AMBIENT_LIGHTMAP, false);
bind_baked_lightmap = false;
-
if (baked_light->lightmaps.has(lightmap_idx)) {
-
RID texid = baked_light->lightmaps[lightmap_idx];
if (prev_baked_light != baked_light || texid != prev_baked_light_texture) {
-
Texture *tex = texture_owner.get(texid);
if (tex) {
@@ -6657,7 +6207,6 @@ void RasterizerGLES2::_render_list_forward(RenderList *p_render_list,const Trans
material_shader.set_conditional(MaterialShaderGLES2::ENABLE_AMBIENT_LIGHTMAP, true);
bind_baked_lightmap = true;
}
-
}
}
}
@@ -6668,33 +6217,33 @@ void RasterizerGLES2::_render_list_forward(RenderList *p_render_list,const Trans
}
}
- if (sort_flags!=prev_sort_flags) {
+ if (sort_flags != prev_sort_flags) {
- if (sort_flags&RenderList::SORT_FLAG_INSTANCING) {
- material_shader.set_conditional(MaterialShaderGLES2::USE_UNIFORM_INSTANCING,!use_texture_instancing && !use_attribute_instancing);
- material_shader.set_conditional(MaterialShaderGLES2::USE_ATTRIBUTE_INSTANCING,use_attribute_instancing);
- material_shader.set_conditional(MaterialShaderGLES2::USE_TEXTURE_INSTANCING,use_texture_instancing);
+ if (sort_flags & RenderList::SORT_FLAG_INSTANCING) {
+ material_shader.set_conditional(MaterialShaderGLES2::USE_UNIFORM_INSTANCING, !use_texture_instancing && !use_attribute_instancing);
+ material_shader.set_conditional(MaterialShaderGLES2::USE_ATTRIBUTE_INSTANCING, use_attribute_instancing);
+ material_shader.set_conditional(MaterialShaderGLES2::USE_TEXTURE_INSTANCING, use_texture_instancing);
} else {
- material_shader.set_conditional(MaterialShaderGLES2::USE_UNIFORM_INSTANCING,false);
- material_shader.set_conditional(MaterialShaderGLES2::USE_ATTRIBUTE_INSTANCING,false);
- material_shader.set_conditional(MaterialShaderGLES2::USE_TEXTURE_INSTANCING,false);
+ material_shader.set_conditional(MaterialShaderGLES2::USE_UNIFORM_INSTANCING, false);
+ material_shader.set_conditional(MaterialShaderGLES2::USE_ATTRIBUTE_INSTANCING, false);
+ material_shader.set_conditional(MaterialShaderGLES2::USE_TEXTURE_INSTANCING, false);
}
- rebind=true;
+ rebind = true;
}
- if (use_hw_skeleton_xform && (skeleton!=prev_skeleton||morph_values!=prev_morph_values)) {
+ if (use_hw_skeleton_xform && (skeleton != prev_skeleton || morph_values != prev_morph_values)) {
if (!prev_skeleton || !skeleton)
- rebind=true; //went from skeleton <-> no skeleton, needs rebind
+ rebind = true; //went from skeleton <-> no skeleton, needs rebind
- if (morph_values==NULL)
+ if (morph_values == NULL)
_setup_skeleton(skeleton);
else
_setup_skeleton(NULL);
}
- if (material!=prev_material || rebind) {
+ if (material != prev_material || rebind) {
- rebind = _setup_material(e->geometry,material,additive,!p_alpha_pass);
+ rebind = _setup_material(e->geometry, material, additive, !p_alpha_pass);
DEBUG_TEST_ERROR("Setup material");
_rinfo.mat_change_count++;
@@ -6702,74 +6251,68 @@ void RasterizerGLES2::_render_list_forward(RenderList *p_render_list,const Trans
//_setup_material_skeleton(material,skeleton);
} else {
- if (prev_skeleton!=skeleton) {
+ if (prev_skeleton != skeleton) {
//_setup_material_skeleton(material,skeleton);
};
}
+ if (geometry_cmp != prev_geometry_cmp || prev_skeleton != skeleton) {
- if (geometry_cmp!=prev_geometry_cmp || prev_skeleton!=skeleton) {
-
- _setup_geometry(e->geometry, material,e->skeleton,e->instance->morph_values.ptr());
+ _setup_geometry(e->geometry, material, e->skeleton, e->instance->morph_values.ptr());
_rinfo.surface_count++;
DEBUG_TEST_ERROR("Setup geometry");
};
- if (i==0 || light!=prev_light || rebind) {
- if (e->light!=0xFFFF) {
+ if (i == 0 || light != prev_light || rebind) {
+ if (e->light != 0xFFFF) {
_setup_light(e->light);
-
}
}
- if (bind_baked_light_octree && (baked_light!=prev_baked_light || rebind)) {
+ if (bind_baked_light_octree && (baked_light != prev_baked_light || rebind)) {
material_shader.set_uniform(MaterialShaderGLES2::AMBIENT_OCTREE_INVERSE_TRANSFORM, *e->instance->baked_light_octree_xform);
material_shader.set_uniform(MaterialShaderGLES2::AMBIENT_OCTREE_LATTICE_SIZE, baked_light->octree_lattice_size);
material_shader.set_uniform(MaterialShaderGLES2::AMBIENT_OCTREE_LATTICE_DIVIDE, baked_light->octree_lattice_divide);
material_shader.set_uniform(MaterialShaderGLES2::AMBIENT_OCTREE_STEPS, baked_light->octree_steps);
- material_shader.set_uniform(MaterialShaderGLES2::AMBIENT_OCTREE_TEX,max_texture_units-3);
+ material_shader.set_uniform(MaterialShaderGLES2::AMBIENT_OCTREE_TEX, max_texture_units - 3);
if (baked_light->light_texture.is_valid()) {
- material_shader.set_uniform(MaterialShaderGLES2::AMBIENT_OCTREE_LIGHT_TEX,max_texture_units-4);
- material_shader.set_uniform(MaterialShaderGLES2::AMBIENT_OCTREE_LIGHT_PIX_SIZE,baked_light->light_tex_pixel_size);
+ material_shader.set_uniform(MaterialShaderGLES2::AMBIENT_OCTREE_LIGHT_TEX, max_texture_units - 4);
+ material_shader.set_uniform(MaterialShaderGLES2::AMBIENT_OCTREE_LIGHT_PIX_SIZE, baked_light->light_tex_pixel_size);
} else {
- material_shader.set_uniform(MaterialShaderGLES2::AMBIENT_OCTREE_LIGHT_TEX,max_texture_units-3);
- material_shader.set_uniform(MaterialShaderGLES2::AMBIENT_OCTREE_LIGHT_PIX_SIZE,baked_light->octree_tex_pixel_size);
+ material_shader.set_uniform(MaterialShaderGLES2::AMBIENT_OCTREE_LIGHT_TEX, max_texture_units - 3);
+ material_shader.set_uniform(MaterialShaderGLES2::AMBIENT_OCTREE_LIGHT_PIX_SIZE, baked_light->octree_tex_pixel_size);
}
- material_shader.set_uniform(MaterialShaderGLES2::AMBIENT_OCTREE_MULTIPLIER,baked_light->texture_multiplier);
- material_shader.set_uniform(MaterialShaderGLES2::AMBIENT_OCTREE_PIX_SIZE,baked_light->octree_tex_pixel_size);
-
-
+ material_shader.set_uniform(MaterialShaderGLES2::AMBIENT_OCTREE_MULTIPLIER, baked_light->texture_multiplier);
+ material_shader.set_uniform(MaterialShaderGLES2::AMBIENT_OCTREE_PIX_SIZE, baked_light->octree_tex_pixel_size);
}
- if (bind_baked_lightmap && (baked_light!=prev_baked_light || rebind)) {
+ if (bind_baked_lightmap && (baked_light != prev_baked_light || rebind)) {
- material_shader.set_uniform(MaterialShaderGLES2::AMBIENT_LIGHTMAP, max_texture_units-3);
+ material_shader.set_uniform(MaterialShaderGLES2::AMBIENT_LIGHTMAP, max_texture_units - 3);
material_shader.set_uniform(MaterialShaderGLES2::AMBIENT_LIGHTMAP_MULTIPLIER, baked_light->lightmap_multiplier);
-
}
if (bind_dp_sampler) {
- material_shader.set_uniform(MaterialShaderGLES2::AMBIENT_DP_SAMPLER_MULTIPLIER,sampled_light_dp_multiplier);
- material_shader.set_uniform(MaterialShaderGLES2::AMBIENT_DP_SAMPLER,max_texture_units-3);
+ material_shader.set_uniform(MaterialShaderGLES2::AMBIENT_DP_SAMPLER_MULTIPLIER, sampled_light_dp_multiplier);
+ material_shader.set_uniform(MaterialShaderGLES2::AMBIENT_DP_SAMPLER, max_texture_units - 3);
}
- _set_cull(e->mirror,p_reverse_cull);
-
+ _set_cull(e->mirror, p_reverse_cull);
- if (i==0 || rebind) {
+ if (i == 0 || rebind) {
material_shader.set_uniform(MaterialShaderGLES2::CAMERA_INVERSE_TRANSFORM, p_view_transform_inverse);
material_shader.set_uniform(MaterialShaderGLES2::PROJECTION_TRANSFORM, p_projection);
if (!shadow) {
if (!additive && current_env && current_env->fx_enabled[VS::ENV_FX_AMBIENT_LIGHT]) {
Color ambcolor = _convert_color(current_env->fx_param[VS::ENV_FX_PARAM_AMBIENT_LIGHT_COLOR]);
- float ambnrg = current_env->fx_param[VS::ENV_FX_PARAM_AMBIENT_LIGHT_ENERGY];
- material_shader.set_uniform(MaterialShaderGLES2::AMBIENT_LIGHT,Vector3(ambcolor.r*ambnrg,ambcolor.g*ambnrg,ambcolor.b*ambnrg));
+ float ambnrg = current_env->fx_param[VS::ENV_FX_PARAM_AMBIENT_LIGHT_ENERGY];
+ material_shader.set_uniform(MaterialShaderGLES2::AMBIENT_LIGHT, Vector3(ambcolor.r * ambnrg, ambcolor.g * ambnrg, ambcolor.b * ambnrg));
} else {
- material_shader.set_uniform(MaterialShaderGLES2::AMBIENT_LIGHT,Vector3());
+ material_shader.set_uniform(MaterialShaderGLES2::AMBIENT_LIGHT, Vector3());
}
}
@@ -6785,20 +6328,20 @@ void RasterizerGLES2::_render_list_forward(RenderList *p_render_list,const Trans
if (e->instance->billboard || e->instance->billboard_y || e->instance->depth_scale) {
- Transform xf=e->instance->transform;
+ Transform xf = e->instance->transform;
if (e->instance->depth_scale) {
if (p_projection.matrix[3][3]) {
//orthogonal matrix, try to do about the same
//with viewport size
//real_t w = Math::abs( 1.0/(2.0*(p_projection.matrix[0][0])) );
- real_t h = Math::abs( 1.0/(2.0*p_projection.matrix[1][1]) );
- float sc = (h*2.0); //consistent with Y-fov
- xf.basis.scale( Vector3(sc,sc,sc));
+ real_t h = Math::abs(1.0 / (2.0 * p_projection.matrix[1][1]));
+ float sc = (h * 2.0); //consistent with Y-fov
+ xf.basis.scale(Vector3(sc, sc, sc));
} else {
//just scale by depth
real_t sc = -camera_plane.distance_to(xf.origin);
- xf.basis.scale( Vector3(sc,sc,sc));
+ xf.basis.scale(Vector3(sc, sc, sc));
}
}
@@ -6814,18 +6357,18 @@ void RasterizerGLES2::_render_list_forward(RenderList *p_render_list,const Trans
xf.basis.scale(scale);
}
-
+
if (e->instance->billboard_y) {
-
+
Vector3 scale = xf.basis.get_scale();
- Vector3 look_at = p_view_transform.get_origin();
+ Vector3 look_at = p_view_transform.get_origin();
look_at.y = 0.0;
Vector3 look_at_norm = look_at.normalized();
-
+
if (current_rt && current_rt_vflip) {
- xf.set_look_at(xf.origin,xf.origin + look_at_norm, Vector3(0.0, -1.0, 0.0));
+ xf.set_look_at(xf.origin, xf.origin + look_at_norm, Vector3(0.0, -1.0, 0.0));
} else {
- xf.set_look_at(xf.origin,xf.origin + look_at_norm, Vector3(0.0, 1.0, 0.0));
+ xf.set_look_at(xf.origin, xf.origin + look_at_norm, Vector3(0.0, 1.0, 0.0));
}
xf.basis.scale(scale);
}
@@ -6835,34 +6378,30 @@ void RasterizerGLES2::_render_list_forward(RenderList *p_render_list,const Trans
material_shader.set_uniform(MaterialShaderGLES2::WORLD_TRANSFORM, e->instance->transform);
}
- material_shader.set_uniform(MaterialShaderGLES2::NORMAL_MULT, e->mirror?-1.0:1.0);
- material_shader.set_uniform(MaterialShaderGLES2::CONST_LIGHT_MULT,additive?0.0:1.0);
-
+ material_shader.set_uniform(MaterialShaderGLES2::NORMAL_MULT, e->mirror ? -1.0 : 1.0);
+ material_shader.set_uniform(MaterialShaderGLES2::CONST_LIGHT_MULT, additive ? 0.0 : 1.0);
- _render(e->geometry, material, skeleton,e->owner,e->instance->transform);
+ _render(e->geometry, material, skeleton, e->owner, e->instance->transform);
DEBUG_TEST_ERROR("Rendering");
- prev_material=material;
- prev_skeleton=skeleton;
- prev_geometry_cmp=geometry_cmp;
- prev_light=e->light;
- prev_light_type=e->light_type;
- prev_sort_flags=sort_flags;
- prev_baked_light=baked_light;
- prev_morph_values=morph_values;
- prev_receive_shadows_state=receive_shadows_state;
+ prev_material = material;
+ prev_skeleton = skeleton;
+ prev_geometry_cmp = geometry_cmp;
+ prev_light = e->light;
+ prev_light_type = e->light_type;
+ prev_sort_flags = sort_flags;
+ prev_baked_light = baked_light;
+ prev_morph_values = morph_values;
+ prev_receive_shadows_state = receive_shadows_state;
}
//print_line("shaderchanges: "+itos(p_alpha_pass)+": "+itos(_rinfo.shader_change_count));
-
if (current_rt && current_rt_vflip) {
glFrontFace(GL_CW);
}
-
};
-
void RasterizerGLES2::_copy_to_texscreen() {
//what am i missing?
@@ -6877,153 +6416,139 @@ void RasterizerGLES2::_copy_to_texscreen() {
glBlendEquation(GL_FUNC_ADD);
if (current_rt && current_rt_transparent) {
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
- }
- else {
+ } else {
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
//glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
- glBindBuffer(GL_ARRAY_BUFFER,0);
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0);
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
- for(int i=0;i<VS::ARRAY_MAX;i++) {
+ for (int i = 0; i < VS::ARRAY_MAX; i++) {
glDisableVertexAttribArray(i);
}
glActiveTexture(GL_TEXTURE0);
-
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.sample_fbo);
glActiveTexture(GL_TEXTURE0);
- glBindTexture( GL_TEXTURE_2D, framebuffer.color );
+ glBindTexture(GL_TEXTURE_2D, framebuffer.color);
copy_shader.bind();
_copy_screen_quad();
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.fbo);
-
-
}
void RasterizerGLES2::_copy_screen_quad() {
-
- Vector2 dst_pos[4]={
+ Vector2 dst_pos[4] = {
Vector2(-1, 1),
- Vector2( 1, 1),
- Vector2( 1,-1),
- Vector2(-1,-1)
+ Vector2(1, 1),
+ Vector2(1, -1),
+ Vector2(-1, -1)
};
Size2 uvscale(
(viewport.width / float(framebuffer.scale)) / framebuffer.width,
- (viewport.height / float(framebuffer.scale)) / framebuffer.height
- );
-
- Vector2 src_uv[4]={
- Vector2( 0, 1)*uvscale,
- Vector2( 1, 1)*uvscale,
- Vector2( 1, 0)*uvscale,
- Vector2( 0, 0)*uvscale
- };
+ (viewport.height / float(framebuffer.scale)) / framebuffer.height);
- Vector2 full_uv[4]={
- Vector2( 0, 1),
- Vector2( 1, 1),
- Vector2( 1, 0),
- Vector2( 0, 0)
+ Vector2 src_uv[4] = {
+ Vector2(0, 1) * uvscale,
+ Vector2(1, 1) * uvscale,
+ Vector2(1, 0) * uvscale,
+ Vector2(0, 0) * uvscale
};
- _draw_gui_primitive2(4,dst_pos,NULL,src_uv,full_uv);
+ Vector2 full_uv[4] = {
+ Vector2(0, 1),
+ Vector2(1, 1),
+ Vector2(1, 0),
+ Vector2(0, 0)
+ };
+ _draw_gui_primitive2(4, dst_pos, NULL, src_uv, full_uv);
}
void RasterizerGLES2::_process_glow_bloom() {
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.blur[0].fbo);
glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D, framebuffer.color );
- copy_shader.set_conditional(CopyShaderGLES2::USE_GLOW_COPY,true);
+ glBindTexture(GL_TEXTURE_2D, framebuffer.color);
+ copy_shader.set_conditional(CopyShaderGLES2::USE_GLOW_COPY, true);
if (current_vd && current_env->fx_enabled[VS::ENV_FX_HDR]) {
- copy_shader.set_conditional(CopyShaderGLES2::USE_HDR,true);
-
+ copy_shader.set_conditional(CopyShaderGLES2::USE_HDR, true);
}
copy_shader.bind();
- copy_shader.set_uniform(CopyShaderGLES2::BLOOM,float(current_env->fx_param[VS::ENV_FX_PARAM_GLOW_BLOOM]));
- copy_shader.set_uniform(CopyShaderGLES2::BLOOM_TRESHOLD,float(current_env->fx_param[VS::ENV_FX_PARAM_GLOW_BLOOM_TRESHOLD]));
- glUniform1i(copy_shader.get_uniform_location(CopyShaderGLES2::SOURCE),0);
+ copy_shader.set_uniform(CopyShaderGLES2::BLOOM, float(current_env->fx_param[VS::ENV_FX_PARAM_GLOW_BLOOM]));
+ copy_shader.set_uniform(CopyShaderGLES2::BLOOM_TRESHOLD, float(current_env->fx_param[VS::ENV_FX_PARAM_GLOW_BLOOM_TRESHOLD]));
+ glUniform1i(copy_shader.get_uniform_location(CopyShaderGLES2::SOURCE), 0);
if (current_vd && current_env->fx_enabled[VS::ENV_FX_HDR]) {
glActiveTexture(GL_TEXTURE2);
- glBindTexture(GL_TEXTURE_2D, current_vd->lum_color );
- glUniform1i(copy_shader.get_uniform_location(CopyShaderGLES2::HDR_SOURCE),2);
- copy_shader.set_uniform(CopyShaderGLES2::TONEMAP_EXPOSURE,float(current_env->fx_param[VS::ENV_FX_PARAM_HDR_EXPOSURE]));
- copy_shader.set_uniform(CopyShaderGLES2::TONEMAP_WHITE,float(current_env->fx_param[VS::ENV_FX_PARAM_HDR_WHITE]));
+ glBindTexture(GL_TEXTURE_2D, current_vd->lum_color);
+ glUniform1i(copy_shader.get_uniform_location(CopyShaderGLES2::HDR_SOURCE), 2);
+ copy_shader.set_uniform(CopyShaderGLES2::TONEMAP_EXPOSURE, float(current_env->fx_param[VS::ENV_FX_PARAM_HDR_EXPOSURE]));
+ copy_shader.set_uniform(CopyShaderGLES2::TONEMAP_WHITE, float(current_env->fx_param[VS::ENV_FX_PARAM_HDR_WHITE]));
//copy_shader.set_uniform(CopyShaderGLES2::TONEMAP_WHITE,1.0);
- copy_shader.set_uniform(CopyShaderGLES2::HDR_GLOW_TRESHOLD,float(current_env->fx_param[VS::ENV_FX_PARAM_HDR_GLOW_TRESHOLD]));
- copy_shader.set_uniform(CopyShaderGLES2::HDR_GLOW_SCALE,float(current_env->fx_param[VS::ENV_FX_PARAM_HDR_GLOW_SCALE]));
+ copy_shader.set_uniform(CopyShaderGLES2::HDR_GLOW_TRESHOLD, float(current_env->fx_param[VS::ENV_FX_PARAM_HDR_GLOW_TRESHOLD]));
+ copy_shader.set_uniform(CopyShaderGLES2::HDR_GLOW_SCALE, float(current_env->fx_param[VS::ENV_FX_PARAM_HDR_GLOW_SCALE]));
glActiveTexture(GL_TEXTURE0);
}
- glViewport( 0, 0, framebuffer.blur_size, framebuffer.blur_size );
+ glViewport(0, 0, framebuffer.blur_size, framebuffer.blur_size);
_copy_screen_quad();
- copy_shader.set_conditional(CopyShaderGLES2::USE_GLOW_COPY,false);
- copy_shader.set_conditional(CopyShaderGLES2::USE_HDR,false);
+ copy_shader.set_conditional(CopyShaderGLES2::USE_GLOW_COPY, false);
+ copy_shader.set_conditional(CopyShaderGLES2::USE_HDR, false);
int passes = current_env->fx_param[VS::ENV_FX_PARAM_GLOW_BLUR_PASSES];
- Vector2 psize(1.0/framebuffer.blur_size,1.0/framebuffer.blur_size);
+ Vector2 psize(1.0 / framebuffer.blur_size, 1.0 / framebuffer.blur_size);
float pscale = current_env->fx_param[VS::ENV_FX_PARAM_GLOW_BLUR_SCALE];
float pmag = current_env->fx_param[VS::ENV_FX_PARAM_GLOW_BLUR_STRENGTH];
+ for (int i = 0; i < passes; i++) {
- for(int i=0;i<passes;i++) {
-
- static const Vector2 src_uv[4]={
- Vector2( 0, 1),
- Vector2( 1, 1),
- Vector2( 1, 0),
- Vector2( 0, 0)
+ static const Vector2 src_uv[4] = {
+ Vector2(0, 1),
+ Vector2(1, 1),
+ Vector2(1, 0),
+ Vector2(0, 0)
};
- static const Vector2 dst_pos[4]={
+ static const Vector2 dst_pos[4] = {
Vector2(-1, 1),
- Vector2( 1, 1),
- Vector2( 1,-1),
- Vector2(-1,-1)
+ Vector2(1, 1),
+ Vector2(1, -1),
+ Vector2(-1, -1)
};
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.blur[1].fbo);
- glBindTexture(GL_TEXTURE_2D, framebuffer.blur[0].color );
- copy_shader.set_conditional(CopyShaderGLES2::BLUR_V_PASS,true);
- copy_shader.set_conditional(CopyShaderGLES2::BLUR_H_PASS,false);
+ glBindTexture(GL_TEXTURE_2D, framebuffer.blur[0].color);
+ copy_shader.set_conditional(CopyShaderGLES2::BLUR_V_PASS, true);
+ copy_shader.set_conditional(CopyShaderGLES2::BLUR_H_PASS, false);
copy_shader.bind();
- copy_shader.set_uniform(CopyShaderGLES2::PIXEL_SIZE,psize);
- copy_shader.set_uniform(CopyShaderGLES2::PIXEL_SCALE,pscale);
- copy_shader.set_uniform(CopyShaderGLES2::BLUR_MAGNITUDE,pmag);
-
- _draw_gui_primitive(4,dst_pos,NULL,src_uv);
+ copy_shader.set_uniform(CopyShaderGLES2::PIXEL_SIZE, psize);
+ copy_shader.set_uniform(CopyShaderGLES2::PIXEL_SCALE, pscale);
+ copy_shader.set_uniform(CopyShaderGLES2::BLUR_MAGNITUDE, pmag);
+ _draw_gui_primitive(4, dst_pos, NULL, src_uv);
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.blur[0].fbo);
- glBindTexture(GL_TEXTURE_2D, framebuffer.blur[1].color );
- copy_shader.set_conditional(CopyShaderGLES2::BLUR_V_PASS,false);
- copy_shader.set_conditional(CopyShaderGLES2::BLUR_H_PASS,true);
+ glBindTexture(GL_TEXTURE_2D, framebuffer.blur[1].color);
+ copy_shader.set_conditional(CopyShaderGLES2::BLUR_V_PASS, false);
+ copy_shader.set_conditional(CopyShaderGLES2::BLUR_H_PASS, true);
copy_shader.bind();
- copy_shader.set_uniform(CopyShaderGLES2::PIXEL_SIZE,psize);
- copy_shader.set_uniform(CopyShaderGLES2::PIXEL_SCALE,pscale);
- copy_shader.set_uniform(CopyShaderGLES2::BLUR_MAGNITUDE,pmag);
-
- _draw_gui_primitive(4,dst_pos,NULL,src_uv);
-
+ copy_shader.set_uniform(CopyShaderGLES2::PIXEL_SIZE, psize);
+ copy_shader.set_uniform(CopyShaderGLES2::PIXEL_SCALE, pscale);
+ copy_shader.set_uniform(CopyShaderGLES2::BLUR_MAGNITUDE, pmag);
+ _draw_gui_primitive(4, dst_pos, NULL, src_uv);
}
- copy_shader.set_conditional(CopyShaderGLES2::BLUR_V_PASS,false);
- copy_shader.set_conditional(CopyShaderGLES2::BLUR_H_PASS,false);
- copy_shader.set_conditional(CopyShaderGLES2::USE_HDR,false);
+ copy_shader.set_conditional(CopyShaderGLES2::BLUR_V_PASS, false);
+ copy_shader.set_conditional(CopyShaderGLES2::BLUR_H_PASS, false);
+ copy_shader.set_conditional(CopyShaderGLES2::USE_HDR, false);
//blur it
-
-
}
void RasterizerGLES2::_process_hdr() {
@@ -7034,92 +6559,83 @@ void RasterizerGLES2::_process_hdr() {
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.luminance[0].fbo);
glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D, framebuffer.color );
- copy_shader.set_conditional(CopyShaderGLES2::USE_HDR_COPY,true);
+ glBindTexture(GL_TEXTURE_2D, framebuffer.color);
+ copy_shader.set_conditional(CopyShaderGLES2::USE_HDR_COPY, true);
copy_shader.bind();
- glUniform1i(copy_shader.get_uniform_location(CopyShaderGLES2::SOURCE),0);
- glViewport( 0, 0, framebuffer.luminance[0].size, framebuffer.luminance[0].size );
+ glUniform1i(copy_shader.get_uniform_location(CopyShaderGLES2::SOURCE), 0);
+ glViewport(0, 0, framebuffer.luminance[0].size, framebuffer.luminance[0].size);
_copy_screen_quad();
- copy_shader.set_conditional(CopyShaderGLES2::USE_HDR_COPY,false);
+ copy_shader.set_conditional(CopyShaderGLES2::USE_HDR_COPY, false);
//int passes = current_env->fx_param[VS::ENV_FX_PARAM_GLOW_BLUR_PASSES];
- copy_shader.set_conditional(CopyShaderGLES2::USE_HDR_REDUCE,true);
+ copy_shader.set_conditional(CopyShaderGLES2::USE_HDR_REDUCE, true);
copy_shader.bind();
- for(int i=1;i<framebuffer.luminance.size();i++) {
+ for (int i = 1; i < framebuffer.luminance.size(); i++) {
-
- static const Vector2 src_uv[4]={
- Vector2( 0, 1),
- Vector2( 1, 1),
- Vector2( 1, 0),
- Vector2( 0, 0)
+ static const Vector2 src_uv[4] = {
+ Vector2(0, 1),
+ Vector2(1, 1),
+ Vector2(1, 0),
+ Vector2(0, 0)
};
- static const Vector2 dst_pos[4]={
+ static const Vector2 dst_pos[4] = {
Vector2(-1, 1),
- Vector2( 1, 1),
- Vector2( 1,-1),
- Vector2(-1,-1)
+ Vector2(1, 1),
+ Vector2(1, -1),
+ Vector2(-1, -1)
};
-
- Vector2 psize(1.0/framebuffer.luminance[i-1].size,1.0/framebuffer.luminance[i-1].size);
+ Vector2 psize(1.0 / framebuffer.luminance[i - 1].size, 1.0 / framebuffer.luminance[i - 1].size);
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.luminance[i].fbo);
- glBindTexture(GL_TEXTURE_2D, framebuffer.luminance[i-1].color );
- glViewport( 0, 0, framebuffer.luminance[i].size, framebuffer.luminance[i].size );
- glUniform1i(copy_shader.get_uniform_location(CopyShaderGLES2::SOURCE),0);
+ glBindTexture(GL_TEXTURE_2D, framebuffer.luminance[i - 1].color);
+ glViewport(0, 0, framebuffer.luminance[i].size, framebuffer.luminance[i].size);
+ glUniform1i(copy_shader.get_uniform_location(CopyShaderGLES2::SOURCE), 0);
- if (framebuffer.luminance[i].size==1) {
+ if (framebuffer.luminance[i].size == 1) {
//last step
- copy_shader.set_conditional(CopyShaderGLES2::USE_HDR_STORE,true);
+ copy_shader.set_conditional(CopyShaderGLES2::USE_HDR_STORE, true);
copy_shader.bind();
glActiveTexture(GL_TEXTURE1);
- glBindTexture(GL_TEXTURE_2D, current_vd->lum_color );
- glUniform1i(copy_shader.get_uniform_location(CopyShaderGLES2::SOURCE_VD_LUM),1);
- copy_shader.set_uniform(CopyShaderGLES2::HDR_TIME_DELTA,time_delta);
- copy_shader.set_uniform(CopyShaderGLES2::HDR_EXP_ADJ_SPEED,float(current_env->fx_param[VS::ENV_FX_PARAM_HDR_EXPOSURE_ADJUST_SPEED]));
- copy_shader.set_uniform(CopyShaderGLES2::MIN_LUMINANCE,float(current_env->fx_param[VS::ENV_FX_PARAM_HDR_MIN_LUMINANCE]));
- copy_shader.set_uniform(CopyShaderGLES2::MAX_LUMINANCE,float(current_env->fx_param[VS::ENV_FX_PARAM_HDR_MAX_LUMINANCE]));
- glUniform1i(copy_shader.get_uniform_location(CopyShaderGLES2::SOURCE),0);
+ glBindTexture(GL_TEXTURE_2D, current_vd->lum_color);
+ glUniform1i(copy_shader.get_uniform_location(CopyShaderGLES2::SOURCE_VD_LUM), 1);
+ copy_shader.set_uniform(CopyShaderGLES2::HDR_TIME_DELTA, time_delta);
+ copy_shader.set_uniform(CopyShaderGLES2::HDR_EXP_ADJ_SPEED, float(current_env->fx_param[VS::ENV_FX_PARAM_HDR_EXPOSURE_ADJUST_SPEED]));
+ copy_shader.set_uniform(CopyShaderGLES2::MIN_LUMINANCE, float(current_env->fx_param[VS::ENV_FX_PARAM_HDR_MIN_LUMINANCE]));
+ copy_shader.set_uniform(CopyShaderGLES2::MAX_LUMINANCE, float(current_env->fx_param[VS::ENV_FX_PARAM_HDR_MAX_LUMINANCE]));
+ glUniform1i(copy_shader.get_uniform_location(CopyShaderGLES2::SOURCE), 0);
//swap them
- SWAP( current_vd->lum_color, framebuffer.luminance[i].color);
- SWAP( current_vd->lum_fbo, framebuffer.luminance[i].fbo);
-
+ SWAP(current_vd->lum_color, framebuffer.luminance[i].color);
+ SWAP(current_vd->lum_fbo, framebuffer.luminance[i].fbo);
}
- copy_shader.set_uniform(CopyShaderGLES2::PIXEL_SIZE,psize);
-
- _draw_gui_primitive(4,dst_pos,NULL,src_uv);
+ copy_shader.set_uniform(CopyShaderGLES2::PIXEL_SIZE, psize);
+ _draw_gui_primitive(4, dst_pos, NULL, src_uv);
}
+ copy_shader.set_conditional(CopyShaderGLES2::USE_HDR_REDUCE, false);
+ copy_shader.set_conditional(CopyShaderGLES2::USE_HDR_STORE, false);
-
- copy_shader.set_conditional(CopyShaderGLES2::USE_HDR_REDUCE,false);
- copy_shader.set_conditional(CopyShaderGLES2::USE_HDR_STORE,false);
-
- draw_next_frame=true;
-
+ draw_next_frame = true;
}
-
void RasterizerGLES2::_draw_tex_bg() {
glDepthMask(GL_TRUE);
glEnable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
glDisable(GL_BLEND);
- glColorMask(1,1,1,1);
-
+ glColorMask(1, 1, 1, 1);
RID texture;
- if (current_env->bg_mode==VS::ENV_BG_TEXTURE) {
- texture=current_env->bg_param[VS::ENV_BG_PARAM_TEXTURE];
+ if (current_env->bg_mode == VS::ENV_BG_TEXTURE) {
+ texture = current_env->bg_param[VS::ENV_BG_PARAM_TEXTURE];
} else {
- texture=current_env->bg_param[VS::ENV_BG_PARAM_CUBEMAP];
+ texture = current_env->bg_param[VS::ENV_BG_PARAM_CUBEMAP];
}
if (!texture_owner.owns(texture)) {
@@ -7131,51 +6647,48 @@ void RasterizerGLES2::_draw_tex_bg() {
glActiveTexture(GL_TEXTURE0);
glBindTexture(t->target, t->tex_id);
- copy_shader.set_conditional(CopyShaderGLES2::USE_ENERGY,true);
+ copy_shader.set_conditional(CopyShaderGLES2::USE_ENERGY, true);
- if (current_env->bg_mode==VS::ENV_BG_TEXTURE) {
- copy_shader.set_conditional(CopyShaderGLES2::USE_CUBEMAP,false);
+ if (current_env->bg_mode == VS::ENV_BG_TEXTURE) {
+ copy_shader.set_conditional(CopyShaderGLES2::USE_CUBEMAP, false);
} else {
- copy_shader.set_conditional(CopyShaderGLES2::USE_CUBEMAP,true);
+ copy_shader.set_conditional(CopyShaderGLES2::USE_CUBEMAP, true);
}
-
- copy_shader.set_conditional(CopyShaderGLES2::USE_CUSTOM_ALPHA,true);
-
+ copy_shader.set_conditional(CopyShaderGLES2::USE_CUSTOM_ALPHA, true);
copy_shader.bind();
- if (current_env->bg_mode==VS::ENV_BG_TEXTURE) {
- glUniform1i( copy_shader.get_uniform_location(CopyShaderGLES2::SOURCE),0);
+ if (current_env->bg_mode == VS::ENV_BG_TEXTURE) {
+ glUniform1i(copy_shader.get_uniform_location(CopyShaderGLES2::SOURCE), 0);
} else {
- glUniform1i( copy_shader.get_uniform_location(CopyShaderGLES2::SOURCE_CUBE),0);
+ glUniform1i(copy_shader.get_uniform_location(CopyShaderGLES2::SOURCE_CUBE), 0);
}
- float nrg =float(current_env->bg_param[VS::ENV_BG_PARAM_ENERGY]);
+ float nrg = float(current_env->bg_param[VS::ENV_BG_PARAM_ENERGY]);
if (current_env->fx_enabled[VS::ENV_FX_HDR] && !use_fp16_fb)
- nrg*=0.25; //go down a quarter for hdr
- copy_shader.set_uniform(CopyShaderGLES2::ENERGY,nrg);
- copy_shader.set_uniform(CopyShaderGLES2::CUSTOM_ALPHA,float(current_env->bg_param[VS::ENV_BG_PARAM_GLOW]));
+ nrg *= 0.25; //go down a quarter for hdr
+ copy_shader.set_uniform(CopyShaderGLES2::ENERGY, nrg);
+ copy_shader.set_uniform(CopyShaderGLES2::CUSTOM_ALPHA, float(current_env->bg_param[VS::ENV_BG_PARAM_GLOW]));
- float flip_sign = (current_env->bg_mode==VS::ENV_BG_TEXTURE && current_rt && current_rt_vflip)?-1:1;
+ float flip_sign = (current_env->bg_mode == VS::ENV_BG_TEXTURE && current_rt && current_rt_vflip) ? -1 : 1;
- Vector3 vertices[4]={
- Vector3(-1,-1*flip_sign,1),
- Vector3( 1,-1*flip_sign,1),
- Vector3( 1, 1*flip_sign,1),
- Vector3(-1, 1*flip_sign,1)
+ Vector3 vertices[4] = {
+ Vector3(-1, -1 * flip_sign, 1),
+ Vector3(1, -1 * flip_sign, 1),
+ Vector3(1, 1 * flip_sign, 1),
+ Vector3(-1, 1 * flip_sign, 1)
};
-
- Vector3 src_uv[4]={
- Vector3( 0, 1, 0),
- Vector3( 1, 1, 0),
- Vector3( 1, 0, 0),
- Vector3( 0, 0, 0)
+ Vector3 src_uv[4] = {
+ Vector3(0, 1, 0),
+ Vector3(1, 1, 0),
+ Vector3(1, 0, 0),
+ Vector3(0, 0, 0)
};
- if (current_env->bg_mode==VS::ENV_BG_TEXTURE) {
+ if (current_env->bg_mode == VS::ENV_BG_TEXTURE) {
//regular texture
//adjust aspect
@@ -7185,117 +6698,113 @@ void RasterizerGLES2::_draw_tex_bg() {
if (aspect_v > aspect_t) {
//wider than texture
- for(int i=0;i<4;i++) {
- src_uv[i].y=(src_uv[i].y-0.5)*(aspect_t/aspect_v)+0.5;
+ for (int i = 0; i < 4; i++) {
+ src_uv[i].y = (src_uv[i].y - 0.5) * (aspect_t / aspect_v) + 0.5;
}
} else {
//narrower than texture
- for(int i=0;i<4;i++) {
- src_uv[i].x=(src_uv[i].x-0.5)*(aspect_v/aspect_t)+0.5;
+ for (int i = 0; i < 4; i++) {
+ src_uv[i].x = (src_uv[i].x - 0.5) * (aspect_v / aspect_t) + 0.5;
}
}
- float scale=current_env->bg_param[VS::ENV_BG_PARAM_SCALE];
- for(int i=0;i<4;i++) {
+ float scale = current_env->bg_param[VS::ENV_BG_PARAM_SCALE];
+ for (int i = 0; i < 4; i++) {
- src_uv[i].x*=scale;
- src_uv[i].y*=scale;
+ src_uv[i].x *= scale;
+ src_uv[i].y *= scale;
}
} else {
//skybox uv vectors
- float vw,vh,zn;
- camera_projection.get_viewport_size(vw,vh);
- zn=camera_projection.get_z_near();
+ float vw, vh, zn;
+ camera_projection.get_viewport_size(vw, vh);
+ zn = camera_projection.get_z_near();
- float scale=current_env->bg_param[VS::ENV_BG_PARAM_SCALE];
+ float scale = current_env->bg_param[VS::ENV_BG_PARAM_SCALE];
- for(int i=0;i<4;i++) {
+ for (int i = 0; i < 4; i++) {
- Vector3 uv=src_uv[i];
- uv.x=(uv.x*2.0-1.0)*vw*scale;
- uv.y=-(uv.y*2.0-1.0)*vh*scale;
- uv.z=-zn;
+ Vector3 uv = src_uv[i];
+ uv.x = (uv.x * 2.0 - 1.0) * vw * scale;
+ uv.y = -(uv.y * 2.0 - 1.0) * vh * scale;
+ uv.z = -zn;
src_uv[i] = camera_transform.basis.xform(uv).normalized();
src_uv[i].z = -src_uv[i].z;
-
}
}
- _draw_primitive(4,vertices,NULL,NULL,src_uv);
+ _draw_primitive(4, vertices, NULL, NULL, src_uv);
- copy_shader.set_conditional(CopyShaderGLES2::USE_ENERGY,false);
- copy_shader.set_conditional(CopyShaderGLES2::USE_RGBE,false);
- copy_shader.set_conditional(CopyShaderGLES2::USE_CUBEMAP,false);
- copy_shader.set_conditional(CopyShaderGLES2::USE_CUSTOM_ALPHA,false);
+ copy_shader.set_conditional(CopyShaderGLES2::USE_ENERGY, false);
+ copy_shader.set_conditional(CopyShaderGLES2::USE_RGBE, false);
+ copy_shader.set_conditional(CopyShaderGLES2::USE_CUBEMAP, false);
+ copy_shader.set_conditional(CopyShaderGLES2::USE_CUSTOM_ALPHA, false);
}
void RasterizerGLES2::end_scene() {
-
-
glEnable(GL_BLEND);
glDepthMask(GL_TRUE);
glEnable(GL_DEPTH_TEST);
glDisable(GL_SCISSOR_TEST);
- bool use_fb=false;
+ bool use_fb = false;
if (framebuffer.active) {
//detect when to use the framebuffer object
- if (using_canvas_bg || texscreen_used || framebuffer.scale!=1) {
- use_fb=true;
+ if (using_canvas_bg || texscreen_used || framebuffer.scale != 1) {
+ use_fb = true;
} else if (current_env) {
- use_fb=false;
- for(int i=0;i<VS::ENV_FX_MAX;i++) {
+ use_fb = false;
+ for (int i = 0; i < VS::ENV_FX_MAX; i++) {
- if (i==VS::ENV_FX_FOG) //does not need fb
+ if (i == VS::ENV_FX_FOG) //does not need fb
continue;
if (current_env->fx_enabled[i]) {
- use_fb=true;
+ use_fb = true;
break;
}
}
}
}
-
if (use_fb) {
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.fbo);
- glViewport( 0,0,viewport.width / framebuffer.scale, viewport.height / framebuffer.scale );
- glScissor( 0,0,viewport.width / framebuffer.scale, viewport.height / framebuffer.scale );
+ glViewport(0, 0, viewport.width / framebuffer.scale, viewport.height / framebuffer.scale);
+ glScissor(0, 0, viewport.width / framebuffer.scale, viewport.height / framebuffer.scale);
- material_shader.set_conditional(MaterialShaderGLES2::USE_8BIT_HDR,!use_fp16_fb && current_env && current_env->fx_enabled[VS::ENV_FX_HDR]);
+ material_shader.set_conditional(MaterialShaderGLES2::USE_8BIT_HDR, !use_fp16_fb && current_env && current_env->fx_enabled[VS::ENV_FX_HDR]);
} else {
if (current_rt) {
- glScissor( 0,0,viewport.width,viewport.height);
+ glScissor(0, 0, viewport.width, viewport.height);
} else {
- glScissor( viewport.x, window_size.height-(viewport.height+viewport.y), viewport.width,viewport.height );
+ glScissor(viewport.x, window_size.height - (viewport.height + viewport.y), viewport.width, viewport.height);
}
}
glEnable(GL_SCISSOR_TEST);
_glClearDepth(1.0);
- bool draw_tex_background=false;
+ bool draw_tex_background = false;
- if (current_debug==VS::SCENARIO_DEBUG_OVERDRAW) {
+ if (current_debug == VS::SCENARIO_DEBUG_OVERDRAW) {
- glClearColor(0,0,0,1);
- glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
+ glClearColor(0, 0, 0, 1);
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
} else if (current_rt && current_rt_transparent) {
- glClearColor(0,0,0,0);
- glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
+ glClearColor(0, 0, 0, 0);
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
} else if (current_env) {
- switch(current_env->bg_mode) {
+ switch (current_env->bg_mode) {
case VS::ENV_BG_CANVAS:
case VS::ENV_BG_KEEP: {
@@ -7306,36 +6815,33 @@ void RasterizerGLES2::end_scene() {
case VS::ENV_BG_COLOR: {
Color bgcolor;
- if (current_env->bg_mode==VS::ENV_BG_COLOR)
+ if (current_env->bg_mode == VS::ENV_BG_COLOR)
bgcolor = current_env->bg_param[VS::ENV_BG_PARAM_COLOR];
else
bgcolor = GlobalConfig::get_singleton()->get("render/default_clear_color");
bgcolor = _convert_color(bgcolor);
float a = use_fb ? float(current_env->bg_param[VS::ENV_BG_PARAM_GLOW]) : 1.0;
- glClearColor(bgcolor.r,bgcolor.g,bgcolor.b,a);
+ glClearColor(bgcolor.r, bgcolor.g, bgcolor.b, a);
_glClearDepth(1.0);
- glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
} break;
case VS::ENV_BG_TEXTURE:
case VS::ENV_BG_CUBEMAP: {
-
glClear(GL_DEPTH_BUFFER_BIT);
- draw_tex_background=true;
+ draw_tex_background = true;
} break;
-
}
} else {
- Color c = _convert_color(Color(0.3,0.3,0.3));
- glClearColor(c.r,c.g,c.b,0.0);
- glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
+ Color c = _convert_color(Color(0.3, 0.3, 0.3));
+ glClearColor(c.r, c.g, c.b, 0.0);
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
glDisable(GL_SCISSOR_TEST);
-
//material_shader.set_uniform_camera(MaterialShaderGLES2::PROJECTION_MATRIX, camera_projection);
/*
@@ -7349,23 +6855,21 @@ void RasterizerGLES2::end_scene() {
*/
//material_shader.set_uniform_default(MaterialShaderGLES2::CAMERA_INVERSE, camera_transform_inverse);
-
- current_depth_test=true;
- current_depth_mask=true;
- texscreen_copied=false;
+ current_depth_test = true;
+ current_depth_mask = true;
+ texscreen_copied = false;
glBlendEquation(GL_FUNC_ADD);
if (current_rt && current_rt_transparent) {
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
- }
- else {
+ } else {
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
glDisable(GL_BLEND);
- current_blend_mode=VS::MATERIAL_BLEND_MODE_MIX;
+ current_blend_mode = VS::MATERIAL_BLEND_MODE_MIX;
//material_shader.set_conditional(MaterialShaderGLES2::USE_GLOW,current_env && current_env->fx_enabled[VS::ENV_FX_GLOW]);
opaque_render_list.sort_mat_light_type_flags();
- _render_list_forward(&opaque_render_list,camera_transform,camera_transform_inverse,camera_projection,false,fragment_lighting);
+ _render_list_forward(&opaque_render_list, camera_transform, camera_transform_inverse, camera_projection, false, fragment_lighting);
if (draw_tex_background) {
@@ -7378,38 +6882,35 @@ void RasterizerGLES2::end_scene() {
glBlendEquation(GL_FUNC_ADD);
if (current_rt && current_rt_transparent) {
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
- }
- else {
+ } else {
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
glDisable(GL_BLEND);
- current_blend_mode=VS::MATERIAL_BLEND_MODE_MIX;
- material_shader.set_conditional(MaterialShaderGLES2::USE_GLOW,false);
+ current_blend_mode = VS::MATERIAL_BLEND_MODE_MIX;
+ material_shader.set_conditional(MaterialShaderGLES2::USE_GLOW, false);
if (current_env && current_env->fx_enabled[VS::ENV_FX_GLOW]) {
- glColorMask(1,1,1,0); //don't touch alpha
+ glColorMask(1, 1, 1, 0); //don't touch alpha
}
alpha_render_list.sort_z();
- _render_list_forward(&alpha_render_list,camera_transform,camera_transform_inverse,camera_projection,false,fragment_lighting,true);
- glColorMask(1,1,1,1);
+ _render_list_forward(&alpha_render_list, camera_transform, camera_transform_inverse, camera_projection, false, fragment_lighting, true);
+ glColorMask(1, 1, 1, 1);
//material_shader.set_conditional( MaterialShaderGLES2::USE_FOG,false);
DEBUG_TEST_ERROR("Drawing Scene");
#ifdef GLEW_ENABLED
- glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
+ glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
#endif
if (use_fb) {
-
-
- for(int i=0;i<VS::ARRAY_MAX;i++) {
+ for (int i = 0; i < VS::ARRAY_MAX; i++) {
glDisableVertexAttribArray(i);
}
- glBindBuffer(GL_ARRAY_BUFFER,0);
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0);
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glDisable(GL_BLEND);
glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
@@ -7419,57 +6920,55 @@ void RasterizerGLES2::end_scene() {
if (current_env && current_env->fx_enabled[VS::ENV_FX_HDR]) {
int hdr_tm = current_env->fx_param[VS::ENV_FX_PARAM_HDR_TONEMAPPER];
- switch(hdr_tm) {
+ switch (hdr_tm) {
case VS::ENV_FX_HDR_TONE_MAPPER_LINEAR: {
-
} break;
case VS::ENV_FX_HDR_TONE_MAPPER_LOG: {
- copy_shader.set_conditional(CopyShaderGLES2::USE_LOG_TONEMAPPER,true);
+ copy_shader.set_conditional(CopyShaderGLES2::USE_LOG_TONEMAPPER, true);
} break;
case VS::ENV_FX_HDR_TONE_MAPPER_REINHARDT: {
- copy_shader.set_conditional(CopyShaderGLES2::USE_REINHARDT_TONEMAPPER,true);
+ copy_shader.set_conditional(CopyShaderGLES2::USE_REINHARDT_TONEMAPPER, true);
} break;
case VS::ENV_FX_HDR_TONE_MAPPER_REINHARDT_AUTOWHITE: {
- copy_shader.set_conditional(CopyShaderGLES2::USE_REINHARDT_TONEMAPPER,true);
- copy_shader.set_conditional(CopyShaderGLES2::USE_AUTOWHITE,true);
+ copy_shader.set_conditional(CopyShaderGLES2::USE_REINHARDT_TONEMAPPER, true);
+ copy_shader.set_conditional(CopyShaderGLES2::USE_AUTOWHITE, true);
} break;
}
-
_process_hdr();
}
if (current_env && current_env->fx_enabled[VS::ENV_FX_GLOW]) {
_process_glow_bloom();
- int glow_transfer_mode=current_env->fx_param[VS::ENV_FX_PARAM_GLOW_BLUR_BLEND_MODE];
- if (glow_transfer_mode==1)
- copy_shader.set_conditional(CopyShaderGLES2::USE_GLOW_SCREEN,true);
- if (glow_transfer_mode==2)
- copy_shader.set_conditional(CopyShaderGLES2::USE_GLOW_SOFTLIGHT,true);
+ int glow_transfer_mode = current_env->fx_param[VS::ENV_FX_PARAM_GLOW_BLUR_BLEND_MODE];
+ if (glow_transfer_mode == 1)
+ copy_shader.set_conditional(CopyShaderGLES2::USE_GLOW_SCREEN, true);
+ if (glow_transfer_mode == 2)
+ copy_shader.set_conditional(CopyShaderGLES2::USE_GLOW_SOFTLIGHT, true);
}
- glBindFramebuffer(GL_FRAMEBUFFER, current_rt?current_rt->fbo:base_framebuffer);
+ glBindFramebuffer(GL_FRAMEBUFFER, current_rt ? current_rt->fbo : base_framebuffer);
Size2 size;
if (current_rt) {
glBindFramebuffer(GL_FRAMEBUFFER, current_rt->fbo);
- glViewport( 0,0,viewport.width,viewport.height);
- size=Size2(viewport.width,viewport.height);
+ glViewport(0, 0, viewport.width, viewport.height);
+ size = Size2(viewport.width, viewport.height);
} else {
glBindFramebuffer(GL_FRAMEBUFFER, base_framebuffer);
- glViewport( viewport.x, window_size.height-(viewport.height+viewport.y), viewport.width,viewport.height );
- size=Size2(viewport.width,viewport.height);
+ glViewport(viewport.x, window_size.height - (viewport.height + viewport.y), viewport.width, viewport.height);
+ size = Size2(viewport.width, viewport.height);
}
//time to copy!!!
- copy_shader.set_conditional(CopyShaderGLES2::USE_BCS,current_env && current_env->fx_enabled[VS::ENV_FX_BCS]);
- copy_shader.set_conditional(CopyShaderGLES2::USE_SRGB,current_env && current_env->fx_enabled[VS::ENV_FX_SRGB]);
- copy_shader.set_conditional(CopyShaderGLES2::USE_GLOW,current_env && current_env->fx_enabled[VS::ENV_FX_GLOW]);
- copy_shader.set_conditional(CopyShaderGLES2::USE_HDR,current_env && current_env->fx_enabled[VS::ENV_FX_HDR]);
- copy_shader.set_conditional(CopyShaderGLES2::USE_NO_ALPHA,true);
- copy_shader.set_conditional(CopyShaderGLES2::USE_FXAA,current_env && current_env->fx_enabled[VS::ENV_FX_FXAA]);
+ copy_shader.set_conditional(CopyShaderGLES2::USE_BCS, current_env && current_env->fx_enabled[VS::ENV_FX_BCS]);
+ copy_shader.set_conditional(CopyShaderGLES2::USE_SRGB, current_env && current_env->fx_enabled[VS::ENV_FX_SRGB]);
+ copy_shader.set_conditional(CopyShaderGLES2::USE_GLOW, current_env && current_env->fx_enabled[VS::ENV_FX_GLOW]);
+ copy_shader.set_conditional(CopyShaderGLES2::USE_HDR, current_env && current_env->fx_enabled[VS::ENV_FX_HDR]);
+ copy_shader.set_conditional(CopyShaderGLES2::USE_NO_ALPHA, true);
+ copy_shader.set_conditional(CopyShaderGLES2::USE_FXAA, current_env && current_env->fx_enabled[VS::ENV_FX_FXAA]);
copy_shader.bind();
//copy_shader.set_uniform(CopyShaderGLES2::SOURCE,0);
@@ -7477,78 +6976,71 @@ void RasterizerGLES2::end_scene() {
if (current_env && current_env->fx_enabled[VS::ENV_FX_GLOW]) {
glActiveTexture(GL_TEXTURE1);
- glBindTexture(GL_TEXTURE_2D, framebuffer.blur[0].color );
- glUniform1i(copy_shader.get_uniform_location(CopyShaderGLES2::GLOW_SOURCE),1);
-
+ glBindTexture(GL_TEXTURE_2D, framebuffer.blur[0].color);
+ glUniform1i(copy_shader.get_uniform_location(CopyShaderGLES2::GLOW_SOURCE), 1);
}
if (current_env && current_env->fx_enabled[VS::ENV_FX_HDR]) {
glActiveTexture(GL_TEXTURE2);
- glBindTexture(GL_TEXTURE_2D, current_vd->lum_color );
- glUniform1i(copy_shader.get_uniform_location(CopyShaderGLES2::HDR_SOURCE),2);
- copy_shader.set_uniform(CopyShaderGLES2::TONEMAP_EXPOSURE,float(current_env->fx_param[VS::ENV_FX_PARAM_HDR_EXPOSURE]));
- copy_shader.set_uniform(CopyShaderGLES2::TONEMAP_WHITE,float(current_env->fx_param[VS::ENV_FX_PARAM_HDR_WHITE]));
-
+ glBindTexture(GL_TEXTURE_2D, current_vd->lum_color);
+ glUniform1i(copy_shader.get_uniform_location(CopyShaderGLES2::HDR_SOURCE), 2);
+ copy_shader.set_uniform(CopyShaderGLES2::TONEMAP_EXPOSURE, float(current_env->fx_param[VS::ENV_FX_PARAM_HDR_EXPOSURE]));
+ copy_shader.set_uniform(CopyShaderGLES2::TONEMAP_WHITE, float(current_env->fx_param[VS::ENV_FX_PARAM_HDR_WHITE]));
}
if (current_env && current_env->fx_enabled[VS::ENV_FX_FXAA])
- copy_shader.set_uniform(CopyShaderGLES2::PIXEL_SIZE,Size2(1.0/size.x,1.0/size.y));
-
+ copy_shader.set_uniform(CopyShaderGLES2::PIXEL_SIZE, Size2(1.0 / size.x, 1.0 / size.y));
if (current_env && current_env->fx_enabled[VS::ENV_FX_BCS]) {
Vector3 bcs;
- bcs.x=current_env->fx_param[VS::ENV_FX_PARAM_BCS_BRIGHTNESS];
- bcs.y=current_env->fx_param[VS::ENV_FX_PARAM_BCS_CONTRAST];
- bcs.z=current_env->fx_param[VS::ENV_FX_PARAM_BCS_SATURATION];
- copy_shader.set_uniform(CopyShaderGLES2::BCS,bcs);
+ bcs.x = current_env->fx_param[VS::ENV_FX_PARAM_BCS_BRIGHTNESS];
+ bcs.y = current_env->fx_param[VS::ENV_FX_PARAM_BCS_CONTRAST];
+ bcs.z = current_env->fx_param[VS::ENV_FX_PARAM_BCS_SATURATION];
+ copy_shader.set_uniform(CopyShaderGLES2::BCS, bcs);
}
glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D, framebuffer.color );
- glUniform1i(copy_shader.get_uniform_location(CopyShaderGLES2::SOURCE),0);
+ glBindTexture(GL_TEXTURE_2D, framebuffer.color);
+ glUniform1i(copy_shader.get_uniform_location(CopyShaderGLES2::SOURCE), 0);
_copy_screen_quad();
- copy_shader.set_conditional(CopyShaderGLES2::USE_BCS,false);
- copy_shader.set_conditional(CopyShaderGLES2::USE_SRGB,false);
- copy_shader.set_conditional(CopyShaderGLES2::USE_GLOW,false);
- copy_shader.set_conditional(CopyShaderGLES2::USE_HDR,false);
- copy_shader.set_conditional(CopyShaderGLES2::USE_NO_ALPHA,false);
- copy_shader.set_conditional(CopyShaderGLES2::USE_FXAA,false);
- copy_shader.set_conditional(CopyShaderGLES2::USE_GLOW_SCREEN,false);
- copy_shader.set_conditional(CopyShaderGLES2::USE_GLOW_SOFTLIGHT,false);
- copy_shader.set_conditional(CopyShaderGLES2::USE_REINHARDT_TONEMAPPER,false);
- copy_shader.set_conditional(CopyShaderGLES2::USE_AUTOWHITE,false);
- copy_shader.set_conditional(CopyShaderGLES2::USE_LOG_TONEMAPPER,false);
-
- material_shader.set_conditional(MaterialShaderGLES2::USE_8BIT_HDR,false);
-
-
- if (current_env && current_env->fx_enabled[VS::ENV_FX_HDR] && GLOBAL_DEF("rasterizer/debug_hdr",false)) {
+ copy_shader.set_conditional(CopyShaderGLES2::USE_BCS, false);
+ copy_shader.set_conditional(CopyShaderGLES2::USE_SRGB, false);
+ copy_shader.set_conditional(CopyShaderGLES2::USE_GLOW, false);
+ copy_shader.set_conditional(CopyShaderGLES2::USE_HDR, false);
+ copy_shader.set_conditional(CopyShaderGLES2::USE_NO_ALPHA, false);
+ copy_shader.set_conditional(CopyShaderGLES2::USE_FXAA, false);
+ copy_shader.set_conditional(CopyShaderGLES2::USE_GLOW_SCREEN, false);
+ copy_shader.set_conditional(CopyShaderGLES2::USE_GLOW_SOFTLIGHT, false);
+ copy_shader.set_conditional(CopyShaderGLES2::USE_REINHARDT_TONEMAPPER, false);
+ copy_shader.set_conditional(CopyShaderGLES2::USE_AUTOWHITE, false);
+ copy_shader.set_conditional(CopyShaderGLES2::USE_LOG_TONEMAPPER, false);
+
+ material_shader.set_conditional(MaterialShaderGLES2::USE_8BIT_HDR, false);
+
+ if (current_env && current_env->fx_enabled[VS::ENV_FX_HDR] && GLOBAL_DEF("rasterizer/debug_hdr", false)) {
_debug_luminances();
}
}
- current_env=NULL;
- current_debug=VS::SCENARIO_DEBUG_DISABLED;
- if (GLOBAL_DEF("rasterizer/debug_shadow_maps",false)) {
+ current_env = NULL;
+ current_debug = VS::SCENARIO_DEBUG_DISABLED;
+ if (GLOBAL_DEF("rasterizer/debug_shadow_maps", false)) {
_debug_shadows();
}
//_debug_luminances();
//_debug_samplers();
if (using_canvas_bg) {
- using_canvas_bg=false;
- glColorMask(1,1,1,1); //don't touch alpha
+ using_canvas_bg = false;
+ glColorMask(1, 1, 1, 1); //don't touch alpha
}
-
}
void RasterizerGLES2::end_shadow_map() {
-
-
ERR_FAIL_COND(!shadow);
glDisable(GL_BLEND);
@@ -7557,7 +7049,6 @@ void RasterizerGLES2::end_shadow_map() {
glEnable(GL_DEPTH_TEST);
glDepthMask(true);
-
ShadowBuffer *sb = shadow->near_shadow_buffer;
ERR_FAIL_COND(!sb);
@@ -7571,186 +7062,177 @@ void RasterizerGLES2::end_shadow_map() {
//glPolygonOffset( 8.0f, 16.0f);
CameraMatrix cm;
- float z_near,z_far;
+ float z_near, z_far;
Transform light_transform;
- float dp_direction=0.0;
- bool flip_facing=false;
+ float dp_direction = 0.0;
+ bool flip_facing = false;
Rect2 vp_rect;
- switch(shadow->base->type) {
+ switch (shadow->base->type) {
case VS::LIGHT_DIRECTIONAL: {
- if (shadow->base->directional_shadow_mode==VS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_4_SPLITS) {
+ if (shadow->base->directional_shadow_mode == VS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_4_SPLITS) {
cm = shadow->custom_projection[shadow_pass];
- light_transform=shadow->custom_transform[shadow_pass];
+ light_transform = shadow->custom_transform[shadow_pass];
- if (shadow_pass==0) {
+ if (shadow_pass == 0) {
- vp_rect=Rect2(0, sb->size/2, sb->size/2, sb->size/2);
- glViewport(0, sb->size/2, sb->size/2, sb->size/2);
- glScissor(0, sb->size/2, sb->size/2, sb->size/2);
- } else if (shadow_pass==1) {
+ vp_rect = Rect2(0, sb->size / 2, sb->size / 2, sb->size / 2);
+ glViewport(0, sb->size / 2, sb->size / 2, sb->size / 2);
+ glScissor(0, sb->size / 2, sb->size / 2, sb->size / 2);
+ } else if (shadow_pass == 1) {
- vp_rect=Rect2(0, 0, sb->size/2, sb->size/2);
- glViewport(0, 0, sb->size/2, sb->size/2);
- glScissor(0, 0, sb->size/2, sb->size/2);
+ vp_rect = Rect2(0, 0, sb->size / 2, sb->size / 2);
+ glViewport(0, 0, sb->size / 2, sb->size / 2);
+ glScissor(0, 0, sb->size / 2, sb->size / 2);
- } else if (shadow_pass==2) {
+ } else if (shadow_pass == 2) {
- vp_rect=Rect2(sb->size/2, sb->size/2, sb->size/2, sb->size/2);
- glViewport(sb->size/2, sb->size/2, sb->size/2, sb->size/2);
- glScissor(sb->size/2, sb->size/2, sb->size/2, sb->size/2);
- } else if (shadow_pass==3) {
-
- vp_rect=Rect2(sb->size/2, 0, sb->size/2, sb->size/2);
- glViewport(sb->size/2, 0, sb->size/2, sb->size/2);
- glScissor(sb->size/2, 0, sb->size/2, sb->size/2);
+ vp_rect = Rect2(sb->size / 2, sb->size / 2, sb->size / 2, sb->size / 2);
+ glViewport(sb->size / 2, sb->size / 2, sb->size / 2, sb->size / 2);
+ glScissor(sb->size / 2, sb->size / 2, sb->size / 2, sb->size / 2);
+ } else if (shadow_pass == 3) {
+ vp_rect = Rect2(sb->size / 2, 0, sb->size / 2, sb->size / 2);
+ glViewport(sb->size / 2, 0, sb->size / 2, sb->size / 2);
+ glScissor(sb->size / 2, 0, sb->size / 2, sb->size / 2);
}
-
-
glEnable(GL_SCISSOR_TEST);
- } else if (shadow->base->directional_shadow_mode==VS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_2_SPLITS) {
+ } else if (shadow->base->directional_shadow_mode == VS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_2_SPLITS) {
- if (shadow_pass==0) {
+ if (shadow_pass == 0) {
cm = shadow->custom_projection[0];
- light_transform=shadow->custom_transform[0];
- vp_rect=Rect2(0, sb->size/2, sb->size, sb->size/2);
- glViewport(0, sb->size/2, sb->size, sb->size/2);
- glScissor(0, sb->size/2, sb->size, sb->size/2);
+ light_transform = shadow->custom_transform[0];
+ vp_rect = Rect2(0, sb->size / 2, sb->size, sb->size / 2);
+ glViewport(0, sb->size / 2, sb->size, sb->size / 2);
+ glScissor(0, sb->size / 2, sb->size, sb->size / 2);
} else {
cm = shadow->custom_projection[1];
- light_transform=shadow->custom_transform[1];
- vp_rect=Rect2(0, 0, sb->size, sb->size/2);
- glViewport(0, 0, sb->size, sb->size/2);
- glScissor(0, 0, sb->size, sb->size/2);
-
+ light_transform = shadow->custom_transform[1];
+ vp_rect = Rect2(0, 0, sb->size, sb->size / 2);
+ glViewport(0, 0, sb->size, sb->size / 2);
+ glScissor(0, 0, sb->size, sb->size / 2);
}
glEnable(GL_SCISSOR_TEST);
} else {
cm = shadow->custom_projection[0];
- light_transform=shadow->custom_transform[0];
- vp_rect=Rect2(0, 0, sb->size, sb->size);
+ light_transform = shadow->custom_transform[0];
+ vp_rect = Rect2(0, 0, sb->size, sb->size);
glViewport(0, 0, sb->size, sb->size);
}
- z_near=cm.get_z_near();
- z_far=cm.get_z_far();
+ z_near = cm.get_z_near();
+ z_far = cm.get_z_far();
_glClearDepth(1.0f);
- glClearColor(1,1,1,1);
+ glClearColor(1, 1, 1, 1);
if (use_rgba_shadowmaps)
- glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
+ glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
else
glClear(GL_DEPTH_BUFFER_BIT);
-
glDisable(GL_SCISSOR_TEST);
} break;
case VS::LIGHT_OMNI: {
- material_shader.set_conditional(MaterialShaderGLES2::USE_DUAL_PARABOLOID,true);
- dp_direction = shadow_pass?1.0:-1.0;
+ material_shader.set_conditional(MaterialShaderGLES2::USE_DUAL_PARABOLOID, true);
+ dp_direction = shadow_pass ? 1.0 : -1.0;
flip_facing = (shadow_pass == 1);
- light_transform=shadow->transform;
- z_near=0;
- z_far=shadow->base->vars[ VS::LIGHT_PARAM_RADIUS ];
- shadow->dp.x=1.0/z_far;
- shadow->dp.y=dp_direction;
-
- if (shadow_pass==0) {
- vp_rect=Rect2(0, sb->size/2, sb->size, sb->size/2);
- glViewport(0, sb->size/2, sb->size, sb->size/2);
- glScissor(0, sb->size/2, sb->size, sb->size/2);
+ light_transform = shadow->transform;
+ z_near = 0;
+ z_far = shadow->base->vars[VS::LIGHT_PARAM_RADIUS];
+ shadow->dp.x = 1.0 / z_far;
+ shadow->dp.y = dp_direction;
+
+ if (shadow_pass == 0) {
+ vp_rect = Rect2(0, sb->size / 2, sb->size, sb->size / 2);
+ glViewport(0, sb->size / 2, sb->size, sb->size / 2);
+ glScissor(0, sb->size / 2, sb->size, sb->size / 2);
} else {
- vp_rect=Rect2(0, 0, sb->size, sb->size/2);
- glViewport(0, 0, sb->size, sb->size/2);
- glScissor(0, 0, sb->size, sb->size/2);
+ vp_rect = Rect2(0, 0, sb->size, sb->size / 2);
+ glViewport(0, 0, sb->size, sb->size / 2);
+ glScissor(0, 0, sb->size, sb->size / 2);
}
glEnable(GL_SCISSOR_TEST);
- shadow->projection=cm;
-
+ shadow->projection = cm;
- glClearColor(1,1,1,1);
+ glClearColor(1, 1, 1, 1);
_glClearDepth(1.0f);
if (use_rgba_shadowmaps)
- glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
+ glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
else
glClear(GL_DEPTH_BUFFER_BIT);
glDisable(GL_SCISSOR_TEST);
-
} break;
case VS::LIGHT_SPOT: {
- float far = shadow->base->vars[ VS::LIGHT_PARAM_RADIUS ];
- ERR_FAIL_COND( far<=0 );
- float near= far/200.0;
- if (near<0.05)
- near=0.05;
+ float far = shadow->base->vars[VS::LIGHT_PARAM_RADIUS];
+ ERR_FAIL_COND(far <= 0);
+ float near = far / 200.0;
+ if (near < 0.05)
+ near = 0.05;
- float angle = shadow->base->vars[ VS::LIGHT_PARAM_SPOT_ANGLE ];
+ float angle = shadow->base->vars[VS::LIGHT_PARAM_SPOT_ANGLE];
- cm.set_perspective( angle*2.0, 1.0, near, far );
+ cm.set_perspective(angle * 2.0, 1.0, near, far);
- shadow->projection=cm; // cache
- light_transform=shadow->transform;
- z_near=cm.get_z_near();
- z_far=cm.get_z_far();
+ shadow->projection = cm; // cache
+ light_transform = shadow->transform;
+ z_near = cm.get_z_near();
+ z_far = cm.get_z_far();
glViewport(0, 0, sb->size, sb->size);
- vp_rect=Rect2(0, 0, sb->size, sb->size);
+ vp_rect = Rect2(0, 0, sb->size, sb->size);
_glClearDepth(1.0f);
- glClearColor(1,1,1,1);
+ glClearColor(1, 1, 1, 1);
if (use_rgba_shadowmaps)
- glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
+ glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
else
glClear(GL_DEPTH_BUFFER_BIT);
-
} break;
}
Transform light_transform_inverse = light_transform.affine_inverse();
opaque_render_list.sort_mat_geom();
- _render_list_forward(&opaque_render_list,light_transform,light_transform_inverse,cm,flip_facing,false);
-
- material_shader.set_conditional(MaterialShaderGLES2::USE_DUAL_PARABOLOID,false);
+ _render_list_forward(&opaque_render_list, light_transform, light_transform_inverse, cm, flip_facing, false);
+ material_shader.set_conditional(MaterialShaderGLES2::USE_DUAL_PARABOLOID, false);
//if (!use_rgba_shadowmaps)
- if (shadow_filter==SHADOW_FILTER_ESM) {
+ if (shadow_filter == SHADOW_FILTER_ESM) {
- copy_shader.set_conditional(CopyShaderGLES2::USE_RGBA_DEPTH,use_rgba_shadowmaps);
- copy_shader.set_conditional(CopyShaderGLES2::USE_HIGHP_SOURCE,!use_rgba_shadowmaps);
+ copy_shader.set_conditional(CopyShaderGLES2::USE_RGBA_DEPTH, use_rgba_shadowmaps);
+ copy_shader.set_conditional(CopyShaderGLES2::USE_HIGHP_SOURCE, !use_rgba_shadowmaps);
- Vector2 psize(1.0/sb->size,1.0/sb->size);
+ Vector2 psize(1.0 / sb->size, 1.0 / sb->size);
float pscale = 1.0;
- int passes=shadow->base->vars[VS::LIGHT_PARAM_SHADOW_BLUR_PASSES];
+ int passes = shadow->base->vars[VS::LIGHT_PARAM_SHADOW_BLUR_PASSES];
glDisable(GL_BLEND);
glDisable(GL_CULL_FACE);
#ifdef GLEW_ENABLED
- glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
+ glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
#endif
- for(int i=0;i<VS::ARRAY_MAX;i++) {
+ for (int i = 0; i < VS::ARRAY_MAX; i++) {
glDisableVertexAttribArray(i);
}
- glBindBuffer(GL_ARRAY_BUFFER,0);
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0);
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glDisable(GL_SCISSOR_TEST);
if (!use_rgba_shadowmaps) {
@@ -7761,16 +7243,15 @@ void RasterizerGLES2::end_shadow_map() {
glDisable(GL_DEPTH_TEST);
}
- for(int i=0;i<passes;i++) {
+ for (int i = 0; i < passes; i++) {
-
- Vector2 src_sb_uv[4]={
- (vp_rect.pos+Vector2(0,vp_rect.size.y))/sb->size,
- (vp_rect.pos+vp_rect.size)/sb->size,
- (vp_rect.pos+Vector2(vp_rect.size.x,0))/sb->size,
- (vp_rect.pos)/sb->size
+ Vector2 src_sb_uv[4] = {
+ (vp_rect.pos + Vector2(0, vp_rect.size.y)) / sb->size,
+ (vp_rect.pos + vp_rect.size) / sb->size,
+ (vp_rect.pos + Vector2(vp_rect.size.x, 0)) / sb->size,
+ (vp_rect.pos) / sb->size
};
-/*
+ /*
Vector2 src_uv[4]={
Vector2( 0, 1),
Vector2( 1, 1),
@@ -7778,39 +7259,37 @@ void RasterizerGLES2::end_shadow_map() {
Vector2( 0, 0)
};
*/
- static const Vector2 dst_pos[4]={
+ static const Vector2 dst_pos[4] = {
Vector2(-1, 1),
- Vector2( 1, 1),
- Vector2( 1,-1),
- Vector2(-1,-1)
+ Vector2(1, 1),
+ Vector2(1, -1),
+ Vector2(-1, -1)
};
glBindFramebuffer(GL_FRAMEBUFFER, blur_shadow_buffer.fbo);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, sb->depth);
#ifdef GLEW_ENABLED
- //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE);
+//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE);
#endif
- copy_shader.set_conditional(CopyShaderGLES2::SHADOW_BLUR_V_PASS,true);
- copy_shader.set_conditional(CopyShaderGLES2::SHADOW_BLUR_H_PASS,false);
+ copy_shader.set_conditional(CopyShaderGLES2::SHADOW_BLUR_V_PASS, true);
+ copy_shader.set_conditional(CopyShaderGLES2::SHADOW_BLUR_H_PASS, false);
copy_shader.bind();
- copy_shader.set_uniform(CopyShaderGLES2::PIXEL_SIZE,psize);
- copy_shader.set_uniform(CopyShaderGLES2::PIXEL_SCALE,pscale);
- copy_shader.set_uniform(CopyShaderGLES2::BLUR_MAGNITUDE,1);
+ copy_shader.set_uniform(CopyShaderGLES2::PIXEL_SIZE, psize);
+ copy_shader.set_uniform(CopyShaderGLES2::PIXEL_SCALE, pscale);
+ copy_shader.set_uniform(CopyShaderGLES2::BLUR_MAGNITUDE, 1);
//copy_shader.set_uniform(CopyShaderGLES2::SOURCE,0);
- glUniform1i(copy_shader.get_uniform_location(CopyShaderGLES2::SOURCE),0);
+ glUniform1i(copy_shader.get_uniform_location(CopyShaderGLES2::SOURCE), 0);
+ _draw_gui_primitive(4, dst_pos, NULL, src_sb_uv);
- _draw_gui_primitive(4,dst_pos,NULL,src_sb_uv);
-
-
- Vector2 src_bb_uv[4]={
- (vp_rect.pos+Vector2(0,vp_rect.size.y))/blur_shadow_buffer.size,
- (vp_rect.pos+vp_rect.size)/blur_shadow_buffer.size,
- (vp_rect.pos+Vector2(vp_rect.size.x,0))/blur_shadow_buffer.size,
- (vp_rect.pos)/blur_shadow_buffer.size,
+ Vector2 src_bb_uv[4] = {
+ (vp_rect.pos + Vector2(0, vp_rect.size.y)) / blur_shadow_buffer.size,
+ (vp_rect.pos + vp_rect.size) / blur_shadow_buffer.size,
+ (vp_rect.pos + Vector2(vp_rect.size.x, 0)) / blur_shadow_buffer.size,
+ (vp_rect.pos) / blur_shadow_buffer.size,
};
glBindFramebuffer(GL_FRAMEBUFFER, sb->fbo);
@@ -7818,161 +7297,141 @@ void RasterizerGLES2::end_shadow_map() {
glBindTexture(GL_TEXTURE_2D, blur_shadow_buffer.depth);
#ifdef GLEW_ENABLED
- //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE);
+//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE);
#endif
- copy_shader.set_conditional(CopyShaderGLES2::SHADOW_BLUR_V_PASS,false);
- copy_shader.set_conditional(CopyShaderGLES2::SHADOW_BLUR_H_PASS,true);
+ copy_shader.set_conditional(CopyShaderGLES2::SHADOW_BLUR_V_PASS, false);
+ copy_shader.set_conditional(CopyShaderGLES2::SHADOW_BLUR_H_PASS, true);
copy_shader.bind();
- copy_shader.set_uniform(CopyShaderGLES2::PIXEL_SIZE,psize);
- copy_shader.set_uniform(CopyShaderGLES2::PIXEL_SCALE,pscale);
- copy_shader.set_uniform(CopyShaderGLES2::BLUR_MAGNITUDE,1);
- glUniform1i(copy_shader.get_uniform_location(CopyShaderGLES2::SOURCE),0);
-
- _draw_gui_primitive(4,dst_pos,NULL,src_bb_uv);
-
+ copy_shader.set_uniform(CopyShaderGLES2::PIXEL_SIZE, psize);
+ copy_shader.set_uniform(CopyShaderGLES2::PIXEL_SCALE, pscale);
+ copy_shader.set_uniform(CopyShaderGLES2::BLUR_MAGNITUDE, 1);
+ glUniform1i(copy_shader.get_uniform_location(CopyShaderGLES2::SOURCE), 0);
+ _draw_gui_primitive(4, dst_pos, NULL, src_bb_uv);
}
glDepthFunc(GL_LEQUAL);
- copy_shader.set_conditional(CopyShaderGLES2::USE_RGBA_DEPTH,false);
- copy_shader.set_conditional(CopyShaderGLES2::USE_HIGHP_SOURCE,false);
- copy_shader.set_conditional(CopyShaderGLES2::SHADOW_BLUR_V_PASS,false);
- copy_shader.set_conditional(CopyShaderGLES2::SHADOW_BLUR_H_PASS,false);
-
+ copy_shader.set_conditional(CopyShaderGLES2::USE_RGBA_DEPTH, false);
+ copy_shader.set_conditional(CopyShaderGLES2::USE_HIGHP_SOURCE, false);
+ copy_shader.set_conditional(CopyShaderGLES2::SHADOW_BLUR_V_PASS, false);
+ copy_shader.set_conditional(CopyShaderGLES2::SHADOW_BLUR_H_PASS, false);
}
DEBUG_TEST_ERROR("Drawing Shadow");
- shadow=NULL;
- glBindFramebuffer(GL_FRAMEBUFFER, current_rt?current_rt->fbo:base_framebuffer);
+ shadow = NULL;
+ glBindFramebuffer(GL_FRAMEBUFFER, current_rt ? current_rt->fbo : base_framebuffer);
glColorMask(1, 1, 1, 1);
//glDisable(GL_POLYGON_OFFSET_FILL);
-
}
-void RasterizerGLES2::_debug_draw_shadow(GLuint tex, const Rect2& p_rect) {
-
-
-
+void RasterizerGLES2::_debug_draw_shadow(GLuint tex, const Rect2 &p_rect) {
Transform2D modelview;
modelview.translate(p_rect.pos.x, p_rect.pos.y);
canvas_shader.set_uniform(CanvasShaderGLES2::MODELVIEW_MATRIX, modelview);
- glBindTexture(GL_TEXTURE_2D,tex);
-
- Vector3 coords[4]= {
- Vector3(p_rect.pos.x, p_rect.pos.y, 0 ),
- Vector3(p_rect.pos.x+p_rect.size.width,
- p_rect.pos.y, 0 ),
- Vector3(p_rect.pos.x+p_rect.size.width,
- p_rect.pos.y+p_rect.size.height, 0 ),
+ glBindTexture(GL_TEXTURE_2D, tex);
+
+ Vector3 coords[4] = {
+ Vector3(p_rect.pos.x, p_rect.pos.y, 0),
+ Vector3(p_rect.pos.x + p_rect.size.width,
+ p_rect.pos.y, 0),
+ Vector3(p_rect.pos.x + p_rect.size.width,
+ p_rect.pos.y + p_rect.size.height, 0),
Vector3(p_rect.pos.x,
- p_rect.pos.y+p_rect.size.height, 0 )
+ p_rect.pos.y + p_rect.size.height, 0)
};
- Vector3 texcoords[4]={
- Vector3( 0.0f,0.0f, 0),
- Vector3( 1.0f,0.0f, 0),
- Vector3( 1.0f, 1.0f, 0),
- Vector3( 0.0f, 1.0f, 0),
+ Vector3 texcoords[4] = {
+ Vector3(0.0f, 0.0f, 0),
+ Vector3(1.0f, 0.0f, 0),
+ Vector3(1.0f, 1.0f, 0),
+ Vector3(0.0f, 1.0f, 0),
};
- _draw_primitive(4,coords,0,0,texcoords);
+ _draw_primitive(4, coords, 0, 0, texcoords);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);
-
}
-void RasterizerGLES2::_debug_draw_shadows_type(Vector<ShadowBuffer>& p_shadows,Point2& ofs) {
-
+void RasterizerGLES2::_debug_draw_shadows_type(Vector<ShadowBuffer> &p_shadows, Point2 &ofs) {
- Size2 debug_size(128,128);
+ Size2 debug_size(128, 128);
//Size2 debug_size(512,512);
+ int useblur = shadow_filter == SHADOW_FILTER_ESM ? 1 : 0;
+ for (int i = 0; i < p_shadows.size() + useblur; i++) {
- int useblur=shadow_filter==SHADOW_FILTER_ESM?1:0;
- for (int i=0;i<p_shadows.size()+useblur;i++) {
+ ShadowBuffer *sb = i == p_shadows.size() ? &blur_shadow_buffer : &p_shadows[i];
- ShadowBuffer *sb=i==p_shadows.size()?&blur_shadow_buffer:&p_shadows[i];
-
- if (!sb->owner && i!=p_shadows.size())
+ if (!sb->owner && i != p_shadows.size())
continue;
- _debug_draw_shadow(sb->depth, Rect2( ofs, debug_size ));
- ofs.x+=debug_size.x;
- if ( (ofs.x+debug_size.x) > viewport.width ) {
+ _debug_draw_shadow(sb->depth, Rect2(ofs, debug_size));
+ ofs.x += debug_size.x;
+ if ((ofs.x + debug_size.x) > viewport.width) {
- ofs.x=0;
- ofs.y+=debug_size.y;
+ ofs.x = 0;
+ ofs.y += debug_size.y;
}
}
-
}
-
void RasterizerGLES2::_debug_luminances() {
- canvas_shader.set_conditional(CanvasShaderGLES2::DEBUG_ENCODED_32,!use_fp16_fb);
+ canvas_shader.set_conditional(CanvasShaderGLES2::DEBUG_ENCODED_32, !use_fp16_fb);
canvas_begin();
glDisable(GL_BLEND);
canvas_shader.bind();
- Size2 debug_size(128,128);
+ Size2 debug_size(128, 128);
Size2 ofs;
+ for (int i = 0; i <= framebuffer.luminance.size(); i++) {
- for (int i=0;i<=framebuffer.luminance.size();i++) {
-
- if (i==framebuffer.luminance.size()) {
+ if (i == framebuffer.luminance.size()) {
if (!current_vd)
break;
- _debug_draw_shadow(current_vd->lum_color, Rect2( ofs, debug_size ));
+ _debug_draw_shadow(current_vd->lum_color, Rect2(ofs, debug_size));
} else {
- _debug_draw_shadow(framebuffer.luminance[i].color, Rect2( ofs, debug_size ));
+ _debug_draw_shadow(framebuffer.luminance[i].color, Rect2(ofs, debug_size));
}
- ofs.x+=debug_size.x/2;
- if ( (ofs.x+debug_size.x) > viewport.width ) {
+ ofs.x += debug_size.x / 2;
+ if ((ofs.x + debug_size.x) > viewport.width) {
- ofs.x=0;
- ofs.y+=debug_size.y;
+ ofs.x = 0;
+ ofs.y += debug_size.y;
}
}
- canvas_shader.set_conditional(CanvasShaderGLES2::DEBUG_ENCODED_32,false);
-
+ canvas_shader.set_conditional(CanvasShaderGLES2::DEBUG_ENCODED_32, false);
}
-
void RasterizerGLES2::_debug_samplers() {
- canvas_shader.set_conditional(CanvasShaderGLES2::DEBUG_ENCODED_32,false);
+ canvas_shader.set_conditional(CanvasShaderGLES2::DEBUG_ENCODED_32, false);
canvas_begin();
glDisable(GL_BLEND);
- _set_color_attrib(Color(1,1,1,1));
+ _set_color_attrib(Color(1, 1, 1, 1));
canvas_shader.bind();
-
List<RID> samplers;
sampled_light_owner.get_owned_list(&samplers);
- Size2 debug_size(128,128);
+ Size2 debug_size(128, 128);
Size2 ofs;
+ for (List<RID>::Element *E = samplers.front(); E; E = E->next()) {
- for (List<RID>::Element *E=samplers.front();E;E=E->next()) {
-
- SampledLight *sl=sampled_light_owner.get(E->get());
+ SampledLight *sl = sampled_light_owner.get(E->get());
- _debug_draw_shadow(sl->texture, Rect2( ofs, debug_size ));
+ _debug_draw_shadow(sl->texture, Rect2(ofs, debug_size));
- ofs.x+=debug_size.x/2;
- if ( (ofs.x+debug_size.x) > viewport.width ) {
+ ofs.x += debug_size.x / 2;
+ if ((ofs.x + debug_size.x) > viewport.width) {
- ofs.x=0;
- ofs.y+=debug_size.y;
+ ofs.x = 0;
+ ofs.y += debug_size.y;
}
}
-
-
-
}
void RasterizerGLES2::_debug_shadows() {
@@ -7989,15 +7448,12 @@ void RasterizerGLES2::_debug_shadows() {
//glEnable(GL_TEXTURE_2D);
*/
-
- _debug_draw_shadows_type(near_shadow_buffers,ofs);
+ _debug_draw_shadows_type(near_shadow_buffers, ofs);
//_debug_draw_shadows_type(far_shadow_buffers,ofs);
-
}
void RasterizerGLES2::end_frame() {
-
//print_line("VTX: "+itos(_rinfo.vertex_count)+" OBJ: "+itos(_rinfo.object_count)+" MAT: "+itos(_rinfo.mat_change_count)+" SHD: "+itos(_rinfo.shader_change_count)+" CI: "+itos(_rinfo.ci_draw_commands));
//print_line("TOTAL VTX: "+itos(_rinfo.vertex_count));
@@ -8014,21 +7470,19 @@ void RasterizerGLES2::flush_frame() {
void RasterizerGLES2::begin_canvas_bg() {
if (framebuffer.active) {
- using_canvas_bg=true;
+ using_canvas_bg = true;
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.fbo);
- glViewport( 0,0,viewport.width , viewport.height );
+ glViewport(0, 0, viewport.width, viewport.height);
} else {
- using_canvas_bg=false;
+ using_canvas_bg = false;
}
-
}
void RasterizerGLES2::canvas_begin() {
-
if (using_canvas_bg) {
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.fbo);
- glColorMask(1,1,1,0); //don't touch alpha
+ glColorMask(1, 1, 1, 0); //don't touch alpha
}
glDisable(GL_CULL_FACE);
@@ -8042,47 +7496,45 @@ void RasterizerGLES2::canvas_begin() {
glBlendEquation(GL_FUNC_ADD);
if (current_rt && current_rt_transparent) {
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
- }
- else {
+ } else {
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
//glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
glLineWidth(1.0);
- glBindBuffer(GL_ARRAY_BUFFER,0);
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0);
- for(int i=0;i<VS::ARRAY_MAX;i++) {
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
+ for (int i = 0; i < VS::ARRAY_MAX; i++) {
glDisableVertexAttribArray(i);
}
glActiveTexture(GL_TEXTURE0);
- glBindTexture( GL_TEXTURE_2D, white_tex );
- canvas_tex=RID();
+ glBindTexture(GL_TEXTURE_2D, white_tex);
+ canvas_tex = RID();
//material_shader.unbind();
canvas_shader.unbind();
canvas_shader.set_custom_shader(0);
- canvas_shader.set_conditional(CanvasShaderGLES2::USE_MODULATE,false);
+ canvas_shader.set_conditional(CanvasShaderGLES2::USE_MODULATE, false);
canvas_shader.bind();
canvas_shader.set_uniform(CanvasShaderGLES2::TEXTURE, 0);
- canvas_use_modulate=false;
- _set_color_attrib(Color(1,1,1));
- canvas_transform=Transform();
+ canvas_use_modulate = false;
+ _set_color_attrib(Color(1, 1, 1));
+ canvas_transform = Transform();
canvas_transform.translate(-(viewport.width / 2.0f), -(viewport.height / 2.0f), 0.0f);
float csy = 1.0;
if (current_rt && current_rt_vflip)
csy = -1.0;
- canvas_transform.scale( Vector3( 2.0f / viewport.width, csy * -2.0f / viewport.height, 1.0f ) );
- canvas_shader.set_uniform(CanvasShaderGLES2::PROJECTION_MATRIX,canvas_transform);
- canvas_shader.set_uniform(CanvasShaderGLES2::MODELVIEW_MATRIX,Transform2D());
- canvas_shader.set_uniform(CanvasShaderGLES2::EXTRA_MATRIX,Transform2D());
-
- canvas_opacity=1.0;
- canvas_blend_mode=VS::MATERIAL_BLEND_MODE_MIX;
- canvas_texscreen_used=false;
- uses_texpixel_size=false;
+ canvas_transform.scale(Vector3(2.0f / viewport.width, csy * -2.0f / viewport.height, 1.0f));
+ canvas_shader.set_uniform(CanvasShaderGLES2::PROJECTION_MATRIX, canvas_transform);
+ canvas_shader.set_uniform(CanvasShaderGLES2::MODELVIEW_MATRIX, Transform2D());
+ canvas_shader.set_uniform(CanvasShaderGLES2::EXTRA_MATRIX, Transform2D());
- canvas_last_material=NULL;
+ canvas_opacity = 1.0;
+ canvas_blend_mode = VS::MATERIAL_BLEND_MODE_MIX;
+ canvas_texscreen_used = false;
+ uses_texpixel_size = false;
+ canvas_last_material = NULL;
}
void RasterizerGLES2::canvas_disable_blending() {
@@ -8097,56 +7549,50 @@ void RasterizerGLES2::canvas_set_opacity(float p_opacity) {
void RasterizerGLES2::canvas_set_blend_mode(VS::MaterialBlendMode p_mode) {
- if (p_mode==canvas_blend_mode)
+ if (p_mode == canvas_blend_mode)
return;
- switch(p_mode) {
+ switch (p_mode) {
- case VS::MATERIAL_BLEND_MODE_MIX: {
+ case VS::MATERIAL_BLEND_MODE_MIX: {
glBlendEquation(GL_FUNC_ADD);
if (current_rt && current_rt_transparent) {
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
- }
- else {
+ } else {
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
- } break;
- case VS::MATERIAL_BLEND_MODE_ADD: {
+ } break;
+ case VS::MATERIAL_BLEND_MODE_ADD: {
glBlendEquation(GL_FUNC_ADD);
- glBlendFunc(GL_SRC_ALPHA,GL_ONE);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE);
- } break;
- case VS::MATERIAL_BLEND_MODE_SUB: {
+ } break;
+ case VS::MATERIAL_BLEND_MODE_SUB: {
glBlendEquation(GL_FUNC_REVERSE_SUBTRACT);
- glBlendFunc(GL_SRC_ALPHA,GL_ONE);
- } break;
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE);
+ } break;
case VS::MATERIAL_BLEND_MODE_MUL: {
glBlendEquation(GL_FUNC_ADD);
- glBlendFunc(GL_DST_COLOR,GL_ZERO);
+ glBlendFunc(GL_DST_COLOR, GL_ZERO);
} break;
case VS::MATERIAL_BLEND_MODE_PREMULT_ALPHA: {
glBlendEquation(GL_FUNC_ADD);
- glBlendFunc(GL_ONE,GL_ONE_MINUS_SRC_ALPHA);
+ glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
} break;
-
}
- canvas_blend_mode=p_mode;
-
+ canvas_blend_mode = p_mode;
}
+void RasterizerGLES2::canvas_begin_rect(const Transform2D &p_transform) {
-void RasterizerGLES2::canvas_begin_rect(const Transform2D& p_transform) {
-
-
- canvas_shader.set_uniform(CanvasShaderGLES2::MODELVIEW_MATRIX,p_transform);
- canvas_shader.set_uniform(CanvasShaderGLES2::EXTRA_MATRIX,Transform2D());
-
+ canvas_shader.set_uniform(CanvasShaderGLES2::MODELVIEW_MATRIX, p_transform);
+ canvas_shader.set_uniform(CanvasShaderGLES2::EXTRA_MATRIX, Transform2D());
}
-void RasterizerGLES2::canvas_set_clip(bool p_clip, const Rect2& p_rect) {
+void RasterizerGLES2::canvas_set_clip(bool p_clip, const Rect2 &p_rect) {
if (p_clip) {
@@ -8154,19 +7600,16 @@ void RasterizerGLES2::canvas_set_clip(bool p_clip, const Rect2& p_rect) {
//glScissor(viewport.x+p_rect.pos.x,viewport.y+ (viewport.height-(p_rect.pos.y+p_rect.size.height)),
int x = p_rect.pos.x;
- int y = window_size.height-(p_rect.pos.y+p_rect.size.y);
+ int y = window_size.height - (p_rect.pos.y + p_rect.size.y);
int w = p_rect.size.x;
int h = p_rect.size.y;
- glScissor(x,y,w,h);
-
+ glScissor(x, y, w, h);
} else {
glDisable(GL_SCISSOR_TEST);
}
-
-
}
void RasterizerGLES2::canvas_end_rect() {
@@ -8174,62 +7617,57 @@ void RasterizerGLES2::canvas_end_rect() {
//glPopMatrix();
}
+RasterizerGLES2::Texture *RasterizerGLES2::_bind_canvas_texture(const RID &p_texture) {
-RasterizerGLES2::Texture* RasterizerGLES2::_bind_canvas_texture(const RID& p_texture) {
-
- if (p_texture==canvas_tex && !rebind_texpixel_size) {
+ if (p_texture == canvas_tex && !rebind_texpixel_size) {
if (canvas_tex.is_valid()) {
- Texture*texture=texture_owner.get(p_texture);
+ Texture *texture = texture_owner.get(p_texture);
return texture;
}
return NULL;
}
- rebind_texpixel_size=false;
+ rebind_texpixel_size = false;
if (p_texture.is_valid()) {
-
- Texture*texture=texture_owner.get(p_texture);
+ Texture *texture = texture_owner.get(p_texture);
if (!texture) {
- canvas_tex=RID();
- glBindTexture(GL_TEXTURE_2D,white_tex);
+ canvas_tex = RID();
+ glBindTexture(GL_TEXTURE_2D, white_tex);
return NULL;
}
if (texture->render_target)
- texture->render_target->last_pass=frame;
+ texture->render_target->last_pass = frame;
- glBindTexture(GL_TEXTURE_2D,texture->tex_id);
- canvas_tex=p_texture;
+ glBindTexture(GL_TEXTURE_2D, texture->tex_id);
+ canvas_tex = p_texture;
if (uses_texpixel_size) {
- canvas_shader.set_uniform(CanvasShaderGLES2::TEXPIXEL_SIZE,Size2(1.0/texture->width,1.0/texture->height));
+ canvas_shader.set_uniform(CanvasShaderGLES2::TEXPIXEL_SIZE, Size2(1.0 / texture->width, 1.0 / texture->height));
}
return texture;
-
} else {
-
- glBindTexture(GL_TEXTURE_2D,white_tex);
- canvas_tex=p_texture;
+ glBindTexture(GL_TEXTURE_2D, white_tex);
+ canvas_tex = p_texture;
}
-
return NULL;
}
-void RasterizerGLES2::canvas_draw_line(const Point2& p_from, const Point2& p_to,const Color& p_color,float p_width,bool p_antialiased) {
+void RasterizerGLES2::canvas_draw_line(const Point2 &p_from, const Point2 &p_to, const Color &p_color, float p_width, bool p_antialiased) {
_bind_canvas_texture(RID());
- Color c=p_color;
- c.a*=canvas_opacity;
+ Color c = p_color;
+ c.a *= canvas_opacity;
_set_color_attrib(c);
- Vector3 verts[2]={
- Vector3(p_from.x,p_from.y,0),
- Vector3(p_to.x,p_to.y,0)
+ Vector3 verts[2] = {
+ Vector3(p_from.x, p_from.y, 0),
+ Vector3(p_to.x, p_to.y, 0)
};
#ifdef GLEW_ENABLED
@@ -8237,7 +7675,7 @@ void RasterizerGLES2::canvas_draw_line(const Point2& p_from, const Point2& p_to,
glEnable(GL_LINE_SMOOTH);
#endif
glLineWidth(p_width);
- _draw_primitive(2,verts,0,0,0);
+ _draw_primitive(2, verts, 0, 0, 0);
#ifdef GLEW_ENABLED
if (p_antialiased)
@@ -8247,24 +7685,21 @@ void RasterizerGLES2::canvas_draw_line(const Point2& p_from, const Point2& p_to,
_rinfo.ci_draw_commands++;
}
-void RasterizerGLES2::_draw_gui_primitive(int p_points, const Vector2 *p_vertices, const Color* p_colors, const Vector2 *p_uvs) {
-
-
-
- static const GLenum prim[5]={GL_POINTS,GL_POINTS,GL_LINES,GL_TRIANGLES,GL_TRIANGLE_FAN};
+void RasterizerGLES2::_draw_gui_primitive(int p_points, const Vector2 *p_vertices, const Color *p_colors, const Vector2 *p_uvs) {
+ static const GLenum prim[5] = { GL_POINTS, GL_POINTS, GL_LINES, GL_TRIANGLES, GL_TRIANGLE_FAN };
//#define GLES_USE_PRIMITIVE_BUFFER
#ifndef GLES_NO_CLIENT_ARRAYS
glEnableVertexAttribArray(VS::ARRAY_VERTEX);
- glVertexAttribPointer( VS::ARRAY_VERTEX, 2 ,GL_FLOAT, false, sizeof(Vector2), p_vertices );
+ glVertexAttribPointer(VS::ARRAY_VERTEX, 2, GL_FLOAT, false, sizeof(Vector2), p_vertices);
if (p_colors) {
glEnableVertexAttribArray(VS::ARRAY_COLOR);
- glVertexAttribPointer( VS::ARRAY_COLOR, 4 ,GL_FLOAT, false, sizeof(Color), p_colors );
+ glVertexAttribPointer(VS::ARRAY_COLOR, 4, GL_FLOAT, false, sizeof(Color), p_colors);
} else {
glDisableVertexAttribArray(VS::ARRAY_COLOR);
}
@@ -8272,74 +7707,71 @@ void RasterizerGLES2::_draw_gui_primitive(int p_points, const Vector2 *p_vertice
if (p_uvs) {
glEnableVertexAttribArray(VS::ARRAY_TEX_UV);
- glVertexAttribPointer( VS::ARRAY_TEX_UV, 2 ,GL_FLOAT, false, sizeof(Vector2), p_uvs );
+ glVertexAttribPointer(VS::ARRAY_TEX_UV, 2, GL_FLOAT, false, sizeof(Vector2), p_uvs);
} else {
glDisableVertexAttribArray(VS::ARRAY_TEX_UV);
}
- glDrawArrays(prim[p_points],0,p_points);
+ glDrawArrays(prim[p_points], 0, p_points);
#else
- glBindBuffer(GL_ARRAY_BUFFER,gui_quad_buffer);
+ glBindBuffer(GL_ARRAY_BUFFER, gui_quad_buffer);
float b[32];
- int ofs=0;
+ int ofs = 0;
glEnableVertexAttribArray(VS::ARRAY_VERTEX);
- glVertexAttribPointer( VS::ARRAY_VERTEX, 2 ,GL_FLOAT, false, sizeof(float)*2, ((float*)0)+ofs );
- for(int i=0;i<p_points;i++) {
- b[ofs++]=p_vertices[i].x;
- b[ofs++]=p_vertices[i].y;
+ glVertexAttribPointer(VS::ARRAY_VERTEX, 2, GL_FLOAT, false, sizeof(float) * 2, ((float *)0) + ofs);
+ for (int i = 0; i < p_points; i++) {
+ b[ofs++] = p_vertices[i].x;
+ b[ofs++] = p_vertices[i].y;
}
if (p_colors) {
glEnableVertexAttribArray(VS::ARRAY_COLOR);
- glVertexAttribPointer( VS::ARRAY_COLOR, 4 ,GL_FLOAT, false, sizeof(float)*4, ((float*)0)+ofs );
- for(int i=0;i<p_points;i++) {
- b[ofs++]=p_colors[i].r;
- b[ofs++]=p_colors[i].g;
- b[ofs++]=p_colors[i].b;
- b[ofs++]=p_colors[i].a;
+ glVertexAttribPointer(VS::ARRAY_COLOR, 4, GL_FLOAT, false, sizeof(float) * 4, ((float *)0) + ofs);
+ for (int i = 0; i < p_points; i++) {
+ b[ofs++] = p_colors[i].r;
+ b[ofs++] = p_colors[i].g;
+ b[ofs++] = p_colors[i].b;
+ b[ofs++] = p_colors[i].a;
}
} else {
glDisableVertexAttribArray(VS::ARRAY_COLOR);
}
-
if (p_uvs) {
glEnableVertexAttribArray(VS::ARRAY_TEX_UV);
- glVertexAttribPointer( VS::ARRAY_TEX_UV, 2 ,GL_FLOAT, false, sizeof(float)*2, ((float*)0)+ofs );
- for(int i=0;i<p_points;i++) {
- b[ofs++]=p_uvs[i].x;
- b[ofs++]=p_uvs[i].y;
+ glVertexAttribPointer(VS::ARRAY_TEX_UV, 2, GL_FLOAT, false, sizeof(float) * 2, ((float *)0) + ofs);
+ for (int i = 0; i < p_points; i++) {
+ b[ofs++] = p_uvs[i].x;
+ b[ofs++] = p_uvs[i].y;
}
} else {
glDisableVertexAttribArray(VS::ARRAY_TEX_UV);
}
- glBufferSubData(GL_ARRAY_BUFFER,0,ofs*4,&b[0]);
- glDrawArrays(prim[p_points],0,p_points);
- glBindBuffer(GL_ARRAY_BUFFER,0);
-
+ glBufferSubData(GL_ARRAY_BUFFER, 0, ofs * 4, &b[0]);
+ glDrawArrays(prim[p_points], 0, p_points);
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
#endif
_rinfo.ci_draw_commands++;
}
-void RasterizerGLES2::_draw_gui_primitive2(int p_points, const Vector2 *p_vertices, const Color* p_colors, const Vector2 *p_uvs, const Vector2 *p_uvs2) {
-
+void RasterizerGLES2::_draw_gui_primitive2(int p_points, const Vector2 *p_vertices, const Color *p_colors, const Vector2 *p_uvs, const Vector2 *p_uvs2) {
- static const GLenum prim[5]={GL_POINTS,GL_POINTS,GL_LINES,GL_TRIANGLES,GL_TRIANGLE_FAN};
+ static const GLenum prim[5] = { GL_POINTS, GL_POINTS, GL_LINES, GL_TRIANGLES, GL_TRIANGLE_FAN };
glEnableVertexAttribArray(VS::ARRAY_VERTEX);
- glVertexAttribPointer( VS::ARRAY_VERTEX, 2 ,GL_FLOAT, false, sizeof(Vector2), p_vertices );
+ glVertexAttribPointer(VS::ARRAY_VERTEX, 2, GL_FLOAT, false, sizeof(Vector2), p_vertices);
if (p_colors) {
glEnableVertexAttribArray(VS::ARRAY_COLOR);
- glVertexAttribPointer( VS::ARRAY_COLOR, 4 ,GL_FLOAT, false, sizeof(Color), p_colors );
+ glVertexAttribPointer(VS::ARRAY_COLOR, 4, GL_FLOAT, false, sizeof(Color), p_colors);
} else {
glDisableVertexAttribArray(VS::ARRAY_COLOR);
}
@@ -8347,7 +7779,7 @@ void RasterizerGLES2::_draw_gui_primitive2(int p_points, const Vector2 *p_vertic
if (p_uvs) {
glEnableVertexAttribArray(VS::ARRAY_TEX_UV);
- glVertexAttribPointer( VS::ARRAY_TEX_UV, 2 ,GL_FLOAT, false, sizeof(Vector2), p_uvs );
+ glVertexAttribPointer(VS::ARRAY_TEX_UV, 2, GL_FLOAT, false, sizeof(Vector2), p_uvs);
} else {
glDisableVertexAttribArray(VS::ARRAY_TEX_UV);
}
@@ -8355,220 +7787,212 @@ void RasterizerGLES2::_draw_gui_primitive2(int p_points, const Vector2 *p_vertic
if (p_uvs2) {
glEnableVertexAttribArray(VS::ARRAY_TEX_UV2);
- glVertexAttribPointer( VS::ARRAY_TEX_UV2, 2 ,GL_FLOAT, false, sizeof(Vector2), p_uvs2 );
+ glVertexAttribPointer(VS::ARRAY_TEX_UV2, 2, GL_FLOAT, false, sizeof(Vector2), p_uvs2);
} else {
glDisableVertexAttribArray(VS::ARRAY_TEX_UV2);
}
- glDrawArrays(prim[p_points],0,p_points);
+ glDrawArrays(prim[p_points], 0, p_points);
_rinfo.ci_draw_commands++;
}
-void RasterizerGLES2::_draw_textured_quad(const Rect2& p_rect, const Rect2& p_src_region, const Size2& p_tex_size,bool p_h_flip, bool p_v_flip, bool p_transpose ) {
+void RasterizerGLES2::_draw_textured_quad(const Rect2 &p_rect, const Rect2 &p_src_region, const Size2 &p_tex_size, bool p_h_flip, bool p_v_flip, bool p_transpose) {
- Vector2 texcoords[4]= {
- Vector2( p_src_region.pos.x/p_tex_size.width,
- p_src_region.pos.y/p_tex_size.height),
+ Vector2 texcoords[4] = {
+ Vector2(p_src_region.pos.x / p_tex_size.width,
+ p_src_region.pos.y / p_tex_size.height),
- Vector2((p_src_region.pos.x+p_src_region.size.width)/p_tex_size.width,
- p_src_region.pos.y/p_tex_size.height),
+ Vector2((p_src_region.pos.x + p_src_region.size.width) / p_tex_size.width,
+ p_src_region.pos.y / p_tex_size.height),
- Vector2( (p_src_region.pos.x+p_src_region.size.width)/p_tex_size.width,
- (p_src_region.pos.y+p_src_region.size.height)/p_tex_size.height),
+ Vector2((p_src_region.pos.x + p_src_region.size.width) / p_tex_size.width,
+ (p_src_region.pos.y + p_src_region.size.height) / p_tex_size.height),
- Vector2( p_src_region.pos.x/p_tex_size.width,
- (p_src_region.pos.y+p_src_region.size.height)/p_tex_size.height)
+ Vector2(p_src_region.pos.x / p_tex_size.width,
+ (p_src_region.pos.y + p_src_region.size.height) / p_tex_size.height)
};
if (p_transpose) {
- SWAP( texcoords[1], texcoords[3] );
+ SWAP(texcoords[1], texcoords[3]);
}
if (p_h_flip) {
- SWAP( texcoords[0], texcoords[1] );
- SWAP( texcoords[2], texcoords[3] );
+ SWAP(texcoords[0], texcoords[1]);
+ SWAP(texcoords[2], texcoords[3]);
}
if (p_v_flip) {
- SWAP( texcoords[1], texcoords[2] );
- SWAP( texcoords[0], texcoords[3] );
+ SWAP(texcoords[1], texcoords[2]);
+ SWAP(texcoords[0], texcoords[3]);
}
- Vector2 coords[4]= {
- Vector2( p_rect.pos.x, p_rect.pos.y ),
- Vector2( p_rect.pos.x+p_rect.size.width, p_rect.pos.y ),
- Vector2( p_rect.pos.x+p_rect.size.width, p_rect.pos.y+p_rect.size.height ),
- Vector2( p_rect.pos.x,p_rect.pos.y+p_rect.size.height )
+ Vector2 coords[4] = {
+ Vector2(p_rect.pos.x, p_rect.pos.y),
+ Vector2(p_rect.pos.x + p_rect.size.width, p_rect.pos.y),
+ Vector2(p_rect.pos.x + p_rect.size.width, p_rect.pos.y + p_rect.size.height),
+ Vector2(p_rect.pos.x, p_rect.pos.y + p_rect.size.height)
};
- _draw_gui_primitive(4,coords,0,texcoords);
+ _draw_gui_primitive(4, coords, 0, texcoords);
_rinfo.ci_draw_commands++;
}
-void RasterizerGLES2::_draw_quad(const Rect2& p_rect) {
+void RasterizerGLES2::_draw_quad(const Rect2 &p_rect) {
- Vector2 coords[4]= {
- Vector2( p_rect.pos.x,p_rect.pos.y ),
- Vector2( p_rect.pos.x+p_rect.size.width,p_rect.pos.y ),
- Vector2( p_rect.pos.x+p_rect.size.width,p_rect.pos.y+p_rect.size.height ),
- Vector2( p_rect.pos.x,p_rect.pos.y+p_rect.size.height )
+ Vector2 coords[4] = {
+ Vector2(p_rect.pos.x, p_rect.pos.y),
+ Vector2(p_rect.pos.x + p_rect.size.width, p_rect.pos.y),
+ Vector2(p_rect.pos.x + p_rect.size.width, p_rect.pos.y + p_rect.size.height),
+ Vector2(p_rect.pos.x, p_rect.pos.y + p_rect.size.height)
};
- _draw_gui_primitive(4,coords,0,0);
+ _draw_gui_primitive(4, coords, 0, 0);
_rinfo.ci_draw_commands++;
-
}
-void RasterizerGLES2::canvas_draw_rect(const Rect2& p_rect, int p_flags, const Rect2& p_source,RID p_texture,const Color& p_modulate) {
+void RasterizerGLES2::canvas_draw_rect(const Rect2 &p_rect, int p_flags, const Rect2 &p_source, RID p_texture, const Color &p_modulate) {
Color m = p_modulate;
- m.a*=canvas_opacity;
+ m.a *= canvas_opacity;
_set_color_attrib(m);
Texture *texture = _bind_canvas_texture(p_texture);
+ if (texture) {
- if ( texture ) {
-
- bool untile=false;
+ bool untile = false;
- if (p_flags&CANVAS_RECT_TILE && !(texture->flags&VS::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;
+ if (p_flags & CANVAS_RECT_TILE && !(texture->flags & VS::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;
}
- if (!(p_flags&CANVAS_RECT_REGION)) {
+ if (!(p_flags & CANVAS_RECT_REGION)) {
- Rect2 region = Rect2(0,0,texture->width,texture->height);
- _draw_textured_quad(p_rect,region,region.size,p_flags&CANVAS_RECT_FLIP_H,p_flags&CANVAS_RECT_FLIP_V,p_flags&CANVAS_RECT_TRANSPOSE);
+ Rect2 region = Rect2(0, 0, texture->width, texture->height);
+ _draw_textured_quad(p_rect, region, region.size, p_flags & CANVAS_RECT_FLIP_H, p_flags & CANVAS_RECT_FLIP_V, p_flags & CANVAS_RECT_TRANSPOSE);
} else {
- _draw_textured_quad(p_rect, p_source, Size2(texture->width,texture->height),p_flags&CANVAS_RECT_FLIP_H,p_flags&CANVAS_RECT_FLIP_V,p_flags&CANVAS_RECT_TRANSPOSE);
-
+ _draw_textured_quad(p_rect, p_source, Size2(texture->width, texture->height), p_flags & CANVAS_RECT_FLIP_H, p_flags & CANVAS_RECT_FLIP_V, p_flags & CANVAS_RECT_TRANSPOSE);
}
if (untile) {
- glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
- glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
}
} else {
//glDisable(GL_TEXTURE_2D);
- _draw_quad( p_rect );
+ _draw_quad(p_rect);
//print_line("rect: "+p_rect);
-
}
_rinfo.ci_draw_commands++;
-
}
-void RasterizerGLES2::canvas_draw_style_box(const Rect2& p_rect, const Rect2& p_src_region, RID p_texture,const float *p_margin, bool p_draw_center,const Color& p_modulate) {
+void RasterizerGLES2::canvas_draw_style_box(const Rect2 &p_rect, const Rect2 &p_src_region, RID p_texture, const float *p_margin, bool p_draw_center, const Color &p_modulate) {
Color m = p_modulate;
- m.a*=canvas_opacity;
+ m.a *= canvas_opacity;
_set_color_attrib(m);
- Texture* texture=_bind_canvas_texture(p_texture);
+ Texture *texture = _bind_canvas_texture(p_texture);
ERR_FAIL_COND(!texture);
Rect2 region = p_src_region;
- if (region.size.width <= 0 )
- region.size.width = texture->width;
+ if (region.size.width <= 0)
+ region.size.width = texture->width;
if (region.size.height <= 0)
- region.size.height = texture->height;
+ region.size.height = texture->height;
/* CORNERS */
_draw_textured_quad( // top left
- Rect2( p_rect.pos, Size2(p_margin[MARGIN_LEFT],p_margin[MARGIN_TOP])),
- Rect2( region.pos, Size2(p_margin[MARGIN_LEFT],p_margin[MARGIN_TOP])),
- Size2( texture->width, texture->height ) );
+ Rect2(p_rect.pos, Size2(p_margin[MARGIN_LEFT], p_margin[MARGIN_TOP])),
+ Rect2(region.pos, Size2(p_margin[MARGIN_LEFT], p_margin[MARGIN_TOP])),
+ Size2(texture->width, texture->height));
_draw_textured_quad( // top right
- Rect2( Point2( p_rect.pos.x + p_rect.size.width - p_margin[MARGIN_RIGHT], p_rect.pos.y), Size2(p_margin[MARGIN_RIGHT],p_margin[MARGIN_TOP])),
- Rect2( Point2(region.pos.x+region.size.width-p_margin[MARGIN_RIGHT], region.pos.y), Size2(p_margin[MARGIN_RIGHT],p_margin[MARGIN_TOP])),
- Size2( texture->width, texture->height ) );
-
+ Rect2(Point2(p_rect.pos.x + p_rect.size.width - p_margin[MARGIN_RIGHT], p_rect.pos.y), Size2(p_margin[MARGIN_RIGHT], p_margin[MARGIN_TOP])),
+ Rect2(Point2(region.pos.x + region.size.width - p_margin[MARGIN_RIGHT], region.pos.y), Size2(p_margin[MARGIN_RIGHT], p_margin[MARGIN_TOP])),
+ Size2(texture->width, texture->height));
_draw_textured_quad( // bottom left
- Rect2( Point2(p_rect.pos.x,p_rect.pos.y + p_rect.size.height - p_margin[MARGIN_BOTTOM]), Size2(p_margin[MARGIN_LEFT],p_margin[MARGIN_BOTTOM])),
- Rect2( Point2(region.pos.x, region.pos.y+region.size.height-p_margin[MARGIN_BOTTOM]), Size2(p_margin[MARGIN_LEFT],p_margin[MARGIN_BOTTOM])),
- Size2( texture->width, texture->height ) );
+ Rect2(Point2(p_rect.pos.x, p_rect.pos.y + p_rect.size.height - p_margin[MARGIN_BOTTOM]), Size2(p_margin[MARGIN_LEFT], p_margin[MARGIN_BOTTOM])),
+ Rect2(Point2(region.pos.x, region.pos.y + region.size.height - p_margin[MARGIN_BOTTOM]), Size2(p_margin[MARGIN_LEFT], p_margin[MARGIN_BOTTOM])),
+ Size2(texture->width, texture->height));
_draw_textured_quad( // bottom right
- Rect2( Point2( p_rect.pos.x + p_rect.size.width - p_margin[MARGIN_RIGHT], p_rect.pos.y + p_rect.size.height - p_margin[MARGIN_BOTTOM]), Size2(p_margin[MARGIN_RIGHT],p_margin[MARGIN_BOTTOM])),
- Rect2( Point2(region.pos.x+region.size.width-p_margin[MARGIN_RIGHT], region.pos.y+region.size.height-p_margin[MARGIN_BOTTOM]), Size2(p_margin[MARGIN_RIGHT],p_margin[MARGIN_BOTTOM])),
- Size2( texture->width, texture->height ) );
-
- Rect2 rect_center( p_rect.pos+Point2( p_margin[MARGIN_LEFT], p_margin[MARGIN_TOP]), Size2( p_rect.size.width - p_margin[MARGIN_LEFT] - p_margin[MARGIN_RIGHT], p_rect.size.height - p_margin[MARGIN_TOP] - p_margin[MARGIN_BOTTOM] ));
+ Rect2(Point2(p_rect.pos.x + p_rect.size.width - p_margin[MARGIN_RIGHT], p_rect.pos.y + p_rect.size.height - p_margin[MARGIN_BOTTOM]), Size2(p_margin[MARGIN_RIGHT], p_margin[MARGIN_BOTTOM])),
+ Rect2(Point2(region.pos.x + region.size.width - p_margin[MARGIN_RIGHT], region.pos.y + region.size.height - p_margin[MARGIN_BOTTOM]), Size2(p_margin[MARGIN_RIGHT], p_margin[MARGIN_BOTTOM])),
+ Size2(texture->width, texture->height));
- Rect2 src_center( Point2(region.pos.x+p_margin[MARGIN_LEFT], region.pos.y+p_margin[MARGIN_TOP]), Size2(region.size.width - p_margin[MARGIN_LEFT] - p_margin[MARGIN_RIGHT], region.size.height - p_margin[MARGIN_TOP] - p_margin[MARGIN_BOTTOM] ));
+ Rect2 rect_center(p_rect.pos + Point2(p_margin[MARGIN_LEFT], p_margin[MARGIN_TOP]), Size2(p_rect.size.width - p_margin[MARGIN_LEFT] - p_margin[MARGIN_RIGHT], p_rect.size.height - p_margin[MARGIN_TOP] - p_margin[MARGIN_BOTTOM]));
+ Rect2 src_center(Point2(region.pos.x + p_margin[MARGIN_LEFT], region.pos.y + p_margin[MARGIN_TOP]), Size2(region.size.width - p_margin[MARGIN_LEFT] - p_margin[MARGIN_RIGHT], region.size.height - p_margin[MARGIN_TOP] - p_margin[MARGIN_BOTTOM]));
_draw_textured_quad( // top
- Rect2( Point2(rect_center.pos.x,p_rect.pos.y),Size2(rect_center.size.width,p_margin[MARGIN_TOP])),
- Rect2( Point2(src_center.pos.x,region.pos.y), Size2(src_center.size.width,p_margin[MARGIN_TOP])),
- Size2( texture->width, texture->height ) );
+ Rect2(Point2(rect_center.pos.x, p_rect.pos.y), Size2(rect_center.size.width, p_margin[MARGIN_TOP])),
+ Rect2(Point2(src_center.pos.x, region.pos.y), Size2(src_center.size.width, p_margin[MARGIN_TOP])),
+ Size2(texture->width, texture->height));
_draw_textured_quad( // bottom
- Rect2( Point2(rect_center.pos.x,rect_center.pos.y+rect_center.size.height),Size2(rect_center.size.width,p_margin[MARGIN_BOTTOM])),
- Rect2( Point2(src_center.pos.x,src_center.pos.y+src_center.size.height), Size2(src_center.size.width,p_margin[MARGIN_BOTTOM])),
- Size2( texture->width, texture->height ) );
+ Rect2(Point2(rect_center.pos.x, rect_center.pos.y + rect_center.size.height), Size2(rect_center.size.width, p_margin[MARGIN_BOTTOM])),
+ Rect2(Point2(src_center.pos.x, src_center.pos.y + src_center.size.height), Size2(src_center.size.width, p_margin[MARGIN_BOTTOM])),
+ Size2(texture->width, texture->height));
_draw_textured_quad( // left
- Rect2( Point2(p_rect.pos.x,rect_center.pos.y),Size2(p_margin[MARGIN_LEFT],rect_center.size.height)),
- Rect2( Point2(region.pos.x,region.pos.y+p_margin[MARGIN_TOP]), Size2(p_margin[MARGIN_LEFT],src_center.size.height)),
- Size2( texture->width, texture->height ) );
+ Rect2(Point2(p_rect.pos.x, rect_center.pos.y), Size2(p_margin[MARGIN_LEFT], rect_center.size.height)),
+ Rect2(Point2(region.pos.x, region.pos.y + p_margin[MARGIN_TOP]), Size2(p_margin[MARGIN_LEFT], src_center.size.height)),
+ Size2(texture->width, texture->height));
_draw_textured_quad( // right
- Rect2( Point2(rect_center.pos.x+rect_center.size.width,rect_center.pos.y),Size2(p_margin[MARGIN_RIGHT],rect_center.size.height)),
- Rect2( Point2(src_center.pos.x+src_center.size.width,region.pos.y+p_margin[MARGIN_TOP]), Size2(p_margin[MARGIN_RIGHT],src_center.size.height)),
- Size2( texture->width, texture->height ) );
+ Rect2(Point2(rect_center.pos.x + rect_center.size.width, rect_center.pos.y), Size2(p_margin[MARGIN_RIGHT], rect_center.size.height)),
+ Rect2(Point2(src_center.pos.x + src_center.size.width, region.pos.y + p_margin[MARGIN_TOP]), Size2(p_margin[MARGIN_RIGHT], src_center.size.height)),
+ Size2(texture->width, texture->height));
if (p_draw_center) {
_draw_textured_quad(
- rect_center,
- src_center,
- Size2( texture->width, texture->height ));
+ rect_center,
+ src_center,
+ Size2(texture->width, texture->height));
}
-
_rinfo.ci_draw_commands++;
}
-void RasterizerGLES2::canvas_draw_primitive(const Vector<Point2>& p_points, const Vector<Color>& p_colors,const Vector<Point2>& p_uvs, RID p_texture,float p_width) {
+void RasterizerGLES2::canvas_draw_primitive(const Vector<Point2> &p_points, const Vector<Color> &p_colors, const Vector<Point2> &p_uvs, RID p_texture, float p_width) {
- ERR_FAIL_COND(p_points.size()<1);
- _set_color_attrib(Color(1,1,1,canvas_opacity));
+ ERR_FAIL_COND(p_points.size() < 1);
+ _set_color_attrib(Color(1, 1, 1, canvas_opacity));
_bind_canvas_texture(p_texture);
- _draw_gui_primitive(p_points.size(),p_points.ptr(),p_colors.ptr(),p_uvs.ptr());
+ _draw_gui_primitive(p_points.size(), p_points.ptr(), p_colors.ptr(), p_uvs.ptr());
_rinfo.ci_draw_commands++;
}
-void RasterizerGLES2::canvas_draw_polygon(int p_vertex_count, const int* p_indices, const Vector2* p_vertices, const Vector2* p_uvs, const Color* p_colors,const RID& p_texture,bool p_singlecolor) {
+void RasterizerGLES2::canvas_draw_polygon(int p_vertex_count, const int *p_indices, const Vector2 *p_vertices, const Vector2 *p_uvs, const Color *p_colors, const RID &p_texture, bool p_singlecolor) {
- bool do_colors=false;
- Color m;
- if (p_singlecolor) {
- m = *p_colors;
- m.a*=canvas_opacity;
- _set_color_attrib(m);
- } else if (!p_colors) {
- m = Color(1, 1, 1, canvas_opacity);
- _set_color_attrib(m);
- } else
- do_colors=true;
+ bool do_colors = false;
+ Color m;
+ if (p_singlecolor) {
+ m = *p_colors;
+ m.a *= canvas_opacity;
+ _set_color_attrib(m);
+ } else if (!p_colors) {
+ m = Color(1, 1, 1, canvas_opacity);
+ _set_color_attrib(m);
+ } else
+ do_colors = true;
- Texture *texture = _bind_canvas_texture(p_texture);
+ Texture *texture = _bind_canvas_texture(p_texture);
#ifndef GLES_NO_CLIENT_ARRAYS
- glEnableVertexAttribArray(VS::ARRAY_VERTEX);
- glVertexAttribPointer( VS::ARRAY_VERTEX, 2 ,GL_FLOAT, false, sizeof(Vector2), p_vertices );
+ glEnableVertexAttribArray(VS::ARRAY_VERTEX);
+ glVertexAttribPointer(VS::ARRAY_VERTEX, 2, GL_FLOAT, false, sizeof(Vector2), p_vertices);
if (do_colors) {
glEnableVertexAttribArray(VS::ARRAY_COLOR);
- glVertexAttribPointer( VS::ARRAY_COLOR, 4 ,GL_FLOAT, false, sizeof(Color), p_colors );
+ glVertexAttribPointer(VS::ARRAY_COLOR, 4, GL_FLOAT, false, sizeof(Color), p_colors);
} else {
glDisableVertexAttribArray(VS::ARRAY_COLOR);
}
@@ -8576,229 +8000,213 @@ void RasterizerGLES2::canvas_draw_polygon(int p_vertex_count, const int* p_indic
if (texture && p_uvs) {
glEnableVertexAttribArray(VS::ARRAY_TEX_UV);
- glVertexAttribPointer( VS::ARRAY_TEX_UV, 2 ,GL_FLOAT, false, sizeof(Vector2), p_uvs );
+ glVertexAttribPointer(VS::ARRAY_TEX_UV, 2, GL_FLOAT, false, sizeof(Vector2), p_uvs);
} else {
glDisableVertexAttribArray(VS::ARRAY_TEX_UV);
}
if (p_indices) {
#ifdef GLEW_ENABLED
- glDrawElements(GL_TRIANGLES, p_vertex_count, GL_UNSIGNED_INT, p_indices );
+ glDrawElements(GL_TRIANGLES, p_vertex_count, GL_UNSIGNED_INT, p_indices);
#else
- static const int _max_draw_poly_indices = 16*1024; // change this size if needed!!!
+ static const int _max_draw_poly_indices = 16 * 1024; // change this size if needed!!!
ERR_FAIL_COND(p_vertex_count > _max_draw_poly_indices);
static uint16_t _draw_poly_indices[_max_draw_poly_indices];
- for (int i=0; i<p_vertex_count; i++) {
+ for (int i = 0; i < p_vertex_count; i++) {
_draw_poly_indices[i] = p_indices[i];
};
- glDrawElements(GL_TRIANGLES, p_vertex_count, GL_UNSIGNED_SHORT, _draw_poly_indices );
+ glDrawElements(GL_TRIANGLES, p_vertex_count, GL_UNSIGNED_SHORT, _draw_poly_indices);
#endif
} else {
- glDrawArrays(GL_TRIANGLES,0,p_vertex_count);
+ glDrawArrays(GL_TRIANGLES, 0, p_vertex_count);
}
-
#else //WebGL specific impl.
glBindBuffer(GL_ARRAY_BUFFER, gui_quad_buffer);
- float *b = GlobalVertexBuffer;
- int ofs = 0;
- if(p_vertex_count > MAX_POLYGON_VERTICES){
- print_line("Too many vertices to render");
- return;
- }
- glEnableVertexAttribArray(VS::ARRAY_VERTEX);
- glVertexAttribPointer( VS::ARRAY_VERTEX, 2 ,GL_FLOAT, false, sizeof(float)*2, ((float*)0)+ofs );
- for(int i=0;i<p_vertex_count;i++) {
- b[ofs++]=p_vertices[i].x;
- b[ofs++]=p_vertices[i].y;
- }
-
- if (p_colors && do_colors) {
-
- glEnableVertexAttribArray(VS::ARRAY_COLOR);
- glVertexAttribPointer( VS::ARRAY_COLOR, 4 ,GL_FLOAT, false, sizeof(float)*4, ((float*)0)+ofs );
- for(int i=0;i<p_vertex_count;i++) {
- b[ofs++]=p_colors[i].r;
- b[ofs++]=p_colors[i].g;
- b[ofs++]=p_colors[i].b;
- b[ofs++]=p_colors[i].a;
- }
-
- } else {
- glDisableVertexAttribArray(VS::ARRAY_COLOR);
- }
-
-
- if (p_uvs) {
-
- glEnableVertexAttribArray(VS::ARRAY_TEX_UV);
- glVertexAttribPointer( VS::ARRAY_TEX_UV, 2 ,GL_FLOAT, false, sizeof(float)*2, ((float*)0)+ofs );
- for(int i=0;i<p_vertex_count;i++) {
- b[ofs++]=p_uvs[i].x;
- b[ofs++]=p_uvs[i].y;
- }
-
- } else {
- glDisableVertexAttribArray(VS::ARRAY_TEX_UV);
- }
-
- glBufferSubData(GL_ARRAY_BUFFER,0,ofs*4,&b[0]);
-
- //bind the indices buffer.
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indices_buffer);
-
- static const int _max_draw_poly_indices = 16*1024; // change this size if needed!!!
- ERR_FAIL_COND(p_vertex_count > _max_draw_poly_indices);
- static uint16_t _draw_poly_indices[_max_draw_poly_indices];
- for (int i=0; i<p_vertex_count; i++) {
- _draw_poly_indices[i] = p_indices[i];
- //OS::get_singleton()->print("ind: %d ", p_indices[i]);
- };
+ float *b = GlobalVertexBuffer;
+ int ofs = 0;
+ if (p_vertex_count > MAX_POLYGON_VERTICES) {
+ print_line("Too many vertices to render");
+ return;
+ }
+ glEnableVertexAttribArray(VS::ARRAY_VERTEX);
+ glVertexAttribPointer(VS::ARRAY_VERTEX, 2, GL_FLOAT, false, sizeof(float) * 2, ((float *)0) + ofs);
+ for (int i = 0; i < p_vertex_count; i++) {
+ b[ofs++] = p_vertices[i].x;
+ b[ofs++] = p_vertices[i].y;
+ }
+
+ if (p_colors && do_colors) {
+
+ glEnableVertexAttribArray(VS::ARRAY_COLOR);
+ glVertexAttribPointer(VS::ARRAY_COLOR, 4, GL_FLOAT, false, sizeof(float) * 4, ((float *)0) + ofs);
+ for (int i = 0; i < p_vertex_count; i++) {
+ b[ofs++] = p_colors[i].r;
+ b[ofs++] = p_colors[i].g;
+ b[ofs++] = p_colors[i].b;
+ b[ofs++] = p_colors[i].a;
+ }
+
+ } else {
+ glDisableVertexAttribArray(VS::ARRAY_COLOR);
+ }
+
+ if (p_uvs) {
+
+ glEnableVertexAttribArray(VS::ARRAY_TEX_UV);
+ glVertexAttribPointer(VS::ARRAY_TEX_UV, 2, GL_FLOAT, false, sizeof(float) * 2, ((float *)0) + ofs);
+ for (int i = 0; i < p_vertex_count; i++) {
+ b[ofs++] = p_uvs[i].x;
+ b[ofs++] = p_uvs[i].y;
+ }
+
+ } else {
+ glDisableVertexAttribArray(VS::ARRAY_TEX_UV);
+ }
- //copy the data to GPU.
- glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, p_vertex_count * sizeof(uint16_t), &_draw_poly_indices[0]);
+ glBufferSubData(GL_ARRAY_BUFFER, 0, ofs * 4, &b[0]);
- //draw the triangles.
- glDrawElements(GL_TRIANGLES, p_vertex_count, GL_UNSIGNED_SHORT, 0);
+ //bind the indices buffer.
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indices_buffer);
- glBindBuffer(GL_ARRAY_BUFFER, 0);
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
+ static const int _max_draw_poly_indices = 16 * 1024; // change this size if needed!!!
+ ERR_FAIL_COND(p_vertex_count > _max_draw_poly_indices);
+ static uint16_t _draw_poly_indices[_max_draw_poly_indices];
+ for (int i = 0; i < p_vertex_count; i++) {
+ _draw_poly_indices[i] = p_indices[i];
+ //OS::get_singleton()->print("ind: %d ", p_indices[i]);
+ };
+
+ //copy the data to GPU.
+ glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, p_vertex_count * sizeof(uint16_t), &_draw_poly_indices[0]);
+
+ //draw the triangles.
+ glDrawElements(GL_TRIANGLES, p_vertex_count, GL_UNSIGNED_SHORT, 0);
+
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
#endif
_rinfo.ci_draw_commands++;
-
};
+void RasterizerGLES2::canvas_set_transform(const Transform2D &p_transform) {
-void RasterizerGLES2::canvas_set_transform(const Transform2D& p_transform) {
-
- canvas_shader.set_uniform(CanvasShaderGLES2::EXTRA_MATRIX,p_transform);
+ canvas_shader.set_uniform(CanvasShaderGLES2::EXTRA_MATRIX, p_transform);
//canvas_transform = Variant(p_transform);
}
RID RasterizerGLES2::canvas_light_occluder_create() {
- CanvasOccluder *co = memnew( CanvasOccluder );
- co->index_id=0;
- co->vertex_id=0;
- co->len=0;
+ CanvasOccluder *co = memnew(CanvasOccluder);
+ co->index_id = 0;
+ co->vertex_id = 0;
+ co->len = 0;
return canvas_occluder_owner.make_rid(co);
}
-void RasterizerGLES2::canvas_light_occluder_set_polylines(RID p_occluder, const PoolVector<Vector2>& p_lines) {
+void RasterizerGLES2::canvas_light_occluder_set_polylines(RID p_occluder, const PoolVector<Vector2> &p_lines) {
CanvasOccluder *co = canvas_occluder_owner.get(p_occluder);
ERR_FAIL_COND(!co);
- co->lines=p_lines;
+ co->lines = p_lines;
- if (p_lines.size()!=co->len) {
+ if (p_lines.size() != co->len) {
if (co->index_id)
- glDeleteBuffers(1,&co->index_id);
+ glDeleteBuffers(1, &co->index_id);
if (co->vertex_id)
- glDeleteBuffers(1,&co->vertex_id);
-
- co->index_id=0;
- co->vertex_id=0;
- co->len=0;
+ glDeleteBuffers(1, &co->vertex_id);
+ co->index_id = 0;
+ co->vertex_id = 0;
+ co->len = 0;
}
if (p_lines.size()) {
-
-
PoolVector<float> geometry;
PoolVector<uint16_t> indices;
int lc = p_lines.size();
- geometry.resize(lc*6);
- indices.resize(lc*3);
-
- PoolVector<float>::Write vw=geometry.write();
- PoolVector<uint16_t>::Write iw=indices.write();
+ geometry.resize(lc * 6);
+ indices.resize(lc * 3);
+ PoolVector<float>::Write vw = geometry.write();
+ PoolVector<uint16_t>::Write iw = indices.write();
- PoolVector<Vector2>::Read lr=p_lines.read();
+ PoolVector<Vector2>::Read lr = p_lines.read();
const int POLY_HEIGHT = 16384;
- for(int i=0;i<lc/2;i++) {
+ for (int i = 0; i < lc / 2; i++) {
- vw[i*12+0]=lr[i*2+0].x;
- vw[i*12+1]=lr[i*2+0].y;
- vw[i*12+2]=POLY_HEIGHT;
+ vw[i * 12 + 0] = lr[i * 2 + 0].x;
+ vw[i * 12 + 1] = lr[i * 2 + 0].y;
+ vw[i * 12 + 2] = POLY_HEIGHT;
- vw[i*12+3]=lr[i*2+1].x;
- vw[i*12+4]=lr[i*2+1].y;
- vw[i*12+5]=POLY_HEIGHT;
+ vw[i * 12 + 3] = lr[i * 2 + 1].x;
+ vw[i * 12 + 4] = lr[i * 2 + 1].y;
+ vw[i * 12 + 5] = POLY_HEIGHT;
- vw[i*12+6]=lr[i*2+1].x;
- vw[i*12+7]=lr[i*2+1].y;
- vw[i*12+8]=-POLY_HEIGHT;
+ vw[i * 12 + 6] = lr[i * 2 + 1].x;
+ vw[i * 12 + 7] = lr[i * 2 + 1].y;
+ vw[i * 12 + 8] = -POLY_HEIGHT;
- vw[i*12+9]=lr[i*2+0].x;
- vw[i*12+10]=lr[i*2+0].y;
- vw[i*12+11]=-POLY_HEIGHT;
+ vw[i * 12 + 9] = lr[i * 2 + 0].x;
+ vw[i * 12 + 10] = lr[i * 2 + 0].y;
+ vw[i * 12 + 11] = -POLY_HEIGHT;
- iw[i*6+0]=i*4+0;
- iw[i*6+1]=i*4+1;
- iw[i*6+2]=i*4+2;
-
- iw[i*6+3]=i*4+2;
- iw[i*6+4]=i*4+3;
- iw[i*6+5]=i*4+0;
+ iw[i * 6 + 0] = i * 4 + 0;
+ iw[i * 6 + 1] = i * 4 + 1;
+ iw[i * 6 + 2] = i * 4 + 2;
+ iw[i * 6 + 3] = i * 4 + 2;
+ iw[i * 6 + 4] = i * 4 + 3;
+ iw[i * 6 + 5] = i * 4 + 0;
}
//if same buffer len is being set, just use BufferSubData to avoid a pipeline flush
-
if (!co->vertex_id) {
- glGenBuffers(1,&co->vertex_id);
- glBindBuffer(GL_ARRAY_BUFFER,co->vertex_id);
- glBufferData(GL_ARRAY_BUFFER,lc*6*sizeof(real_t),vw.ptr(),GL_STATIC_DRAW);
+ glGenBuffers(1, &co->vertex_id);
+ glBindBuffer(GL_ARRAY_BUFFER, co->vertex_id);
+ glBufferData(GL_ARRAY_BUFFER, lc * 6 * sizeof(real_t), vw.ptr(), GL_STATIC_DRAW);
} else {
- glBindBuffer(GL_ARRAY_BUFFER,co->vertex_id);
- glBufferSubData(GL_ARRAY_BUFFER,0,lc*6*sizeof(real_t),vw.ptr());
-
+ glBindBuffer(GL_ARRAY_BUFFER, co->vertex_id);
+ glBufferSubData(GL_ARRAY_BUFFER, 0, lc * 6 * sizeof(real_t), vw.ptr());
}
- glBindBuffer(GL_ARRAY_BUFFER,0); //unbind
+ glBindBuffer(GL_ARRAY_BUFFER, 0); //unbind
if (!co->index_id) {
- glGenBuffers(1,&co->index_id);
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,co->index_id);
- glBufferData(GL_ELEMENT_ARRAY_BUFFER,lc*3*sizeof(uint16_t),iw.ptr(),GL_STATIC_DRAW);
+ glGenBuffers(1, &co->index_id);
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, co->index_id);
+ glBufferData(GL_ELEMENT_ARRAY_BUFFER, lc * 3 * sizeof(uint16_t), iw.ptr(), GL_STATIC_DRAW);
} else {
-
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,co->index_id);
- glBufferSubData(GL_ELEMENT_ARRAY_BUFFER,0,lc*3*sizeof(uint16_t),iw.ptr());
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, co->index_id);
+ glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, lc * 3 * sizeof(uint16_t), iw.ptr());
}
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0); //unbind
-
- co->len=lc;
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); //unbind
+ co->len = lc;
}
-
-
-
}
RID RasterizerGLES2::canvas_light_shadow_buffer_create(int p_width) {
- CanvasLightShadow *cls = memnew( CanvasLightShadow );
- if (p_width>max_texture_size)
- p_width=max_texture_size;
+ CanvasLightShadow *cls = memnew(CanvasLightShadow);
+ if (p_width > max_texture_size)
+ p_width = max_texture_size;
- cls->size=p_width;
+ cls->size = p_width;
glActiveTexture(GL_TEXTURE0);
glGenFramebuffers(1, &cls->fbo);
@@ -8818,14 +8226,14 @@ RID RasterizerGLES2::canvas_light_shadow_buffer_create(int p_width) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- cls->height=16;
+ cls->height = 16;
//print_line("ERROR? "+itos(glGetError()));
- if ( read_depth_supported ) {
+ if (read_depth_supported) {
// We'll use a depth texture to store the depths in the shadow map
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, cls->size, cls->height, 0,
- GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL);
+ GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL);
#ifdef GLEW_ENABLED
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
@@ -8834,7 +8242,7 @@ RID RasterizerGLES2::canvas_light_shadow_buffer_create(int p_width) {
// Attach the depth texture to FBO depth attachment point
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
- GL_TEXTURE_2D, cls->depth, 0);
+ GL_TEXTURE_2D, cls->depth, 0);
#ifdef GLEW_ENABLED
glDrawBuffer(GL_NONE);
@@ -8848,7 +8256,7 @@ RID RasterizerGLES2::canvas_light_shadow_buffer_create(int p_width) {
// Attach the RGBA texture to FBO color attachment point
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
GL_TEXTURE_2D, cls->depth, 0);
- cls->rgba=cls->depth;
+ cls->rgba = cls->depth;
// Allocate 16-bit depth buffer
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, cls->size, cls->height);
@@ -8856,12 +8264,10 @@ RID RasterizerGLES2::canvas_light_shadow_buffer_create(int p_width) {
// Attach the render buffer as depth buffer - will be ignored
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
GL_RENDERBUFFER, cls->rbo);
-
-
}
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
- //printf("errnum: %x\n",status);
+//printf("errnum: %x\n",status);
#ifdef GLEW_ENABLED
if (read_depth_supported) {
//glDrawBuffer(GL_BACK);
@@ -8869,7 +8275,7 @@ RID RasterizerGLES2::canvas_light_shadow_buffer_create(int p_width) {
#endif
glBindFramebuffer(GL_FRAMEBUFFER, base_framebuffer);
DEBUG_TEST_ERROR("2D Shadow Buffer Init");
- ERR_FAIL_COND_V( status != GL_FRAMEBUFFER_COMPLETE, RID() );
+ ERR_FAIL_COND_V(status != GL_FRAMEBUFFER_COMPLETE, RID());
#ifdef GLEW_ENABLED
if (read_depth_supported) {
@@ -8880,12 +8286,11 @@ RID RasterizerGLES2::canvas_light_shadow_buffer_create(int p_width) {
return canvas_light_shadow_owner.make_rid(cls);
}
-void RasterizerGLES2::canvas_light_shadow_buffer_update(RID p_buffer, const Transform2D& p_light_xform, int p_light_mask,float p_near, float p_far, CanvasLightOccluderInstance* p_occluders, CameraMatrix *p_xform_cache) {
+void RasterizerGLES2::canvas_light_shadow_buffer_update(RID p_buffer, const Transform2D &p_light_xform, int p_light_mask, float p_near, float p_far, CanvasLightOccluderInstance *p_occluders, CameraMatrix *p_xform_cache) {
CanvasLightShadow *cls = canvas_light_shadow_owner.get(p_buffer);
ERR_FAIL_COND(!cls);
-
glDisable(GL_BLEND);
glDisable(GL_SCISSOR_TEST);
glDisable(GL_DITHER);
@@ -8902,71 +8307,70 @@ void RasterizerGLES2::canvas_light_shadow_buffer_update(RID p_buffer, const Tran
glEnableVertexAttribArray(VS::ARRAY_VERTEX);
canvas_shadow_shader.bind();
- glViewport(0, 0, cls->size,cls->height);
+ glViewport(0, 0, cls->size, cls->height);
_glClearDepth(1.0f);
- glClearColor(1,1,1,1);
- glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
-
- VS::CanvasOccluderPolygonCullMode cull=VS::CANVAS_OCCLUDER_POLYGON_CULL_DISABLED;
+ glClearColor(1, 1, 1, 1);
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ VS::CanvasOccluderPolygonCullMode cull = VS::CANVAS_OCCLUDER_POLYGON_CULL_DISABLED;
- for(int i=0;i<4;i++) {
+ for (int i = 0; i < 4; i++) {
//make sure it remains orthogonal, makes easy to read angle later
Transform light;
- light.origin[0]=p_light_xform[2][0];
- light.origin[1]=p_light_xform[2][1];
- light.basis[0][0]=p_light_xform[0][0];
- light.basis[0][1]=p_light_xform[1][0];
- light.basis[1][0]=p_light_xform[0][1];
- light.basis[1][1]=p_light_xform[1][1];
+ light.origin[0] = p_light_xform[2][0];
+ light.origin[1] = p_light_xform[2][1];
+ light.basis[0][0] = p_light_xform[0][0];
+ light.basis[0][1] = p_light_xform[1][0];
+ light.basis[1][0] = p_light_xform[0][1];
+ light.basis[1][1] = p_light_xform[1][1];
//light.basis.scale(Vector3(to_light.elements[0].length(),to_light.elements[1].length(),1));
- / //p_near=1;
- CameraMatrix projection;
+ / //p_near=1;
+ CameraMatrix projection;
{
- real_t fov = 90;
+ real_t fov = 90;
real_t near = p_near;
real_t far = p_far;
real_t aspect = 1.0;
- real_t ymax = near * Math::tan( Math::deg2rad( fov * 0.5 ) );
- real_t ymin = - ymax;
+ real_t ymax = near * Math::tan(Math::deg2rad(fov * 0.5));
+ real_t ymin = -ymax;
real_t xmin = ymin * aspect;
real_t xmax = ymax * aspect;
- projection.set_frustum( xmin, xmax, ymin, ymax, near, far );
+ projection.set_frustum(xmin, xmax, ymin, ymax, near, far);
}
- Vector3 cam_target=Matrix3(Vector3(0,0,Math_PI*2*(i/4.0))).xform(Vector3(0,1,0));
- projection = projection * CameraMatrix(Transform().looking_at(cam_target,Vector3(0,0,-1)).affine_inverse());
+ Vector3 cam_target = Matrix3(Vector3(0, 0, Math_PI * 2 * (i / 4.0))).xform(Vector3(0, 1, 0));
+ projection = projection * CameraMatrix(Transform().looking_at(cam_target, Vector3(0, 0, -1)).affine_inverse());
- canvas_shadow_shader.set_uniform(CanvasShadowShaderGLES2::PROJECTION_MATRIX,projection);
- canvas_shadow_shader.set_uniform(CanvasShadowShaderGLES2::LIGHT_MATRIX,light);
+ canvas_shadow_shader.set_uniform(CanvasShadowShaderGLES2::PROJECTION_MATRIX, projection);
+ canvas_shadow_shader.set_uniform(CanvasShadowShaderGLES2::LIGHT_MATRIX, light);
- if (i==0)
- *p_xform_cache=projection;
+ if (i == 0)
+ *p_xform_cache = projection;
- glViewport(0, (cls->height/4)*i, cls->size,cls->height/4);
+ glViewport(0, (cls->height / 4) * i, cls->size, cls->height / 4);
- CanvasLightOccluderInstance *instance=p_occluders;
+ CanvasLightOccluderInstance *instance = p_occluders;
- while(instance) {
+ while (instance) {
CanvasOccluder *cc = canvas_occluder_owner.get(instance->polygon_buffer);
- if (!cc || cc->len==0 || !(p_light_mask&instance->light_mask)) {
+ if (!cc || cc->len == 0 || !(p_light_mask & instance->light_mask)) {
- instance=instance->next;
+ instance = instance->next;
continue;
}
- canvas_shadow_shader.set_uniform(CanvasShadowShaderGLES2::WORLD_MATRIX,instance->xform_cache);
- if (cull!=instance->cull_cache) {
+ canvas_shadow_shader.set_uniform(CanvasShadowShaderGLES2::WORLD_MATRIX, instance->xform_cache);
+ if (cull != instance->cull_cache) {
- cull=instance->cull_cache;
- switch(cull) {
+ cull = instance->cull_cache;
+ switch (cull) {
case VS::CANVAS_OCCLUDER_POLYGON_CULL_DISABLED: {
glDisable(GL_CULL_FACE);
@@ -8985,7 +8389,7 @@ void RasterizerGLES2::canvas_light_shadow_buffer_update(RID p_buffer, const Tran
} break;
}
}
-/*
+ /*
if (i==0) {
for(int i=0;i<cc->lines.size();i++) {
Vector2 p = instance->xform_cache.xform(cc->lines.get(i));
@@ -8998,24 +8402,21 @@ void RasterizerGLES2::canvas_light_shadow_buffer_update(RID p_buffer, const Tran
}
}
*/
- glBindBuffer(GL_ARRAY_BUFFER,cc->vertex_id);
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,cc->index_id);
+ glBindBuffer(GL_ARRAY_BUFFER, cc->vertex_id);
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, cc->index_id);
glVertexAttribPointer(VS::ARRAY_VERTEX, 3, GL_FLOAT, false, 0, 0);
- glDrawElements(GL_TRIANGLES,cc->len*3,GL_UNSIGNED_SHORT,0);
+ glDrawElements(GL_TRIANGLES, cc->len * 3, GL_UNSIGNED_SHORT, 0);
-
- instance=instance->next;
+ instance = instance->next;
}
-
-
}
glDisableVertexAttribArray(VS::ARRAY_VERTEX);
- glBindBuffer(GL_ARRAY_BUFFER,0);
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0);
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
- if (shadow_filter==SHADOW_FILTER_ESM) {
- //blur the buffer
+ if (shadow_filter == SHADOW_FILTER_ESM) {
+//blur the buffer
#if 0
//this is ignord, it did not make any difference..
if (read_depth_supported) {
@@ -9102,17 +8503,13 @@ void RasterizerGLES2::canvas_light_shadow_buffer_update(RID p_buffer, const Tran
#endif
}
- glBindFramebuffer(GL_FRAMEBUFFER, current_rt?current_rt->fbo:base_framebuffer);
+ glBindFramebuffer(GL_FRAMEBUFFER, current_rt ? current_rt->fbo : base_framebuffer);
glColorMask(1, 1, 1, 1);
-
-
-
}
+void RasterizerGLES2::canvas_debug_viewport_shadows(CanvasLight *p_lights_with_shadow) {
-void RasterizerGLES2::canvas_debug_viewport_shadows(CanvasLight* p_lights_with_shadow) {
-
- CanvasLight* light=p_lights_with_shadow;
+ CanvasLight *light = p_lights_with_shadow;
canvas_begin(); //reset
@@ -9121,60 +8518,56 @@ void RasterizerGLES2::canvas_debug_viewport_shadows(CanvasLight* p_lights_with_s
int ofs = h;
//print_line(" debug lights ");
- while(light) {
+ while (light) {
//print_line("debug light");
if (light->shadow_buffer.is_valid()) {
//print_line("sb is valid");
- CanvasLightShadow * sb = canvas_light_shadow_owner.get(light->shadow_buffer);
+ CanvasLightShadow *sb = canvas_light_shadow_owner.get(light->shadow_buffer);
if (sb) {
glActiveTexture(GL_TEXTURE0);
if (read_depth_supported)
- glBindTexture(GL_TEXTURE_2D,sb->depth);
+ glBindTexture(GL_TEXTURE_2D, sb->depth);
else
- glBindTexture(GL_TEXTURE_2D,sb->rgba);
- _draw_textured_quad(Rect2(h,ofs,w-h*2,h),Rect2(0,0,sb->size,10),Size2(sb->size,10),false,false);
- ofs+=h*2;
-
+ glBindTexture(GL_TEXTURE_2D, sb->rgba);
+ _draw_textured_quad(Rect2(h, ofs, w - h * 2, h), Rect2(0, 0, sb->size, 10), Size2(sb->size, 10), false, false);
+ ofs += h * 2;
}
}
- light=light->shadows_next_ptr;
+ light = light->shadows_next_ptr;
}
-
}
-void RasterizerGLES2::_canvas_normal_set_flip(const Vector2& p_flip) {
+void RasterizerGLES2::_canvas_normal_set_flip(const Vector2 &p_flip) {
- if (p_flip==normal_flip)
+ if (p_flip == normal_flip)
return;
- normal_flip=p_flip;
- canvas_shader.set_uniform(CanvasShaderGLES2::NORMAL_FLIP,normal_flip);
+ normal_flip = p_flip;
+ canvas_shader.set_uniform(CanvasShaderGLES2::NORMAL_FLIP, normal_flip);
}
+template <bool use_normalmap>
+void RasterizerGLES2::_canvas_item_render_commands(CanvasItem *p_item, CanvasItem *current_clip, bool &reclip) {
-template<bool use_normalmap>
-void RasterizerGLES2::_canvas_item_render_commands(CanvasItem *p_item,CanvasItem *current_clip,bool &reclip) {
-
- int cc=p_item->commands.size();
+ int cc = p_item->commands.size();
CanvasItem::Command **commands = p_item->commands.ptr();
+ for (int i = 0; i < cc; i++) {
- for(int i=0;i<cc;i++) {
-
- CanvasItem::Command *c=commands[i];
+ CanvasItem::Command *c = commands[i];
- switch(c->type) {
+ switch (c->type) {
case CanvasItem::Command::TYPE_LINE: {
- CanvasItem::CommandLine* line = static_cast<CanvasItem::CommandLine*>(c);
- canvas_draw_line(line->from,line->to,line->color,line->width,line->antialiased);
+ CanvasItem::CommandLine *line = static_cast<CanvasItem::CommandLine *>(c);
+ canvas_draw_line(line->from, line->to, line->color, line->width, line->antialiased);
} break;
case CanvasItem::Command::TYPE_RECT: {
- CanvasItem::CommandRect* rect = static_cast<CanvasItem::CommandRect*>(c);
- //canvas_draw_rect(rect->rect,rect->region,rect->source,rect->flags&CanvasItem::CommandRect::FLAG_TILE,rect->flags&CanvasItem::CommandRect::FLAG_FLIP_H,rect->flags&CanvasItem::CommandRect::FLAG_FLIP_V,rect->texture,rect->modulate);
+ CanvasItem::CommandRect *rect = static_cast<CanvasItem::CommandRect *>(c);
+//canvas_draw_rect(rect->rect,rect->region,rect->source,rect->flags&CanvasItem::CommandRect::FLAG_TILE,rect->flags&CanvasItem::CommandRect::FLAG_FLIP_H,rect->flags&CanvasItem::CommandRect::FLAG_FLIP_V,rect->texture,rect->modulate);
#if 0
int flags=0;
@@ -9194,84 +8587,84 @@ void RasterizerGLES2::_canvas_item_render_commands(CanvasItem *p_item,CanvasItem
}
#else
- int flags=rect->flags;
+ int flags = rect->flags;
#endif
if (use_normalmap)
- _canvas_normal_set_flip(Vector2((flags&CANVAS_RECT_FLIP_H)?-1:1,(flags&CANVAS_RECT_FLIP_V)?-1:1));
- canvas_draw_rect(rect->rect,flags,rect->source,rect->texture,rect->modulate);
+ _canvas_normal_set_flip(Vector2((flags & CANVAS_RECT_FLIP_H) ? -1 : 1, (flags & CANVAS_RECT_FLIP_V) ? -1 : 1));
+ canvas_draw_rect(rect->rect, flags, rect->source, rect->texture, rect->modulate);
} break;
case CanvasItem::Command::TYPE_STYLE: {
- CanvasItem::CommandStyle* style = static_cast<CanvasItem::CommandStyle*>(c);
+ CanvasItem::CommandStyle *style = static_cast<CanvasItem::CommandStyle *>(c);
if (use_normalmap)
- _canvas_normal_set_flip(Vector2(1,1));
- canvas_draw_style_box(style->rect,style->source,style->texture,style->margin,style->draw_center,style->color);
+ _canvas_normal_set_flip(Vector2(1, 1));
+ canvas_draw_style_box(style->rect, style->source, style->texture, style->margin, style->draw_center, style->color);
} break;
case CanvasItem::Command::TYPE_PRIMITIVE: {
if (use_normalmap)
- _canvas_normal_set_flip(Vector2(1,1));
- CanvasItem::CommandPrimitive* primitive = static_cast<CanvasItem::CommandPrimitive*>(c);
- canvas_draw_primitive(primitive->points,primitive->colors,primitive->uvs,primitive->texture,primitive->width);
+ _canvas_normal_set_flip(Vector2(1, 1));
+ CanvasItem::CommandPrimitive *primitive = static_cast<CanvasItem::CommandPrimitive *>(c);
+ canvas_draw_primitive(primitive->points, primitive->colors, primitive->uvs, primitive->texture, primitive->width);
} break;
case CanvasItem::Command::TYPE_POLYGON: {
if (use_normalmap)
- _canvas_normal_set_flip(Vector2(1,1));
- CanvasItem::CommandPolygon* polygon = static_cast<CanvasItem::CommandPolygon*>(c);
- canvas_draw_polygon(polygon->count,polygon->indices.ptr(),polygon->points.ptr(),polygon->uvs.ptr(),polygon->colors.ptr(),polygon->texture,polygon->colors.size()==1);
+ _canvas_normal_set_flip(Vector2(1, 1));
+ CanvasItem::CommandPolygon *polygon = static_cast<CanvasItem::CommandPolygon *>(c);
+ canvas_draw_polygon(polygon->count, polygon->indices.ptr(), polygon->points.ptr(), polygon->uvs.ptr(), polygon->colors.ptr(), polygon->texture, polygon->colors.size() == 1);
} break;
case CanvasItem::Command::TYPE_POLYGON_PTR: {
if (use_normalmap)
- _canvas_normal_set_flip(Vector2(1,1));
- CanvasItem::CommandPolygonPtr* polygon = static_cast<CanvasItem::CommandPolygonPtr*>(c);
- canvas_draw_polygon(polygon->count,polygon->indices,polygon->points,polygon->uvs,polygon->colors,polygon->texture,false);
+ _canvas_normal_set_flip(Vector2(1, 1));
+ CanvasItem::CommandPolygonPtr *polygon = static_cast<CanvasItem::CommandPolygonPtr *>(c);
+ canvas_draw_polygon(polygon->count, polygon->indices, polygon->points, polygon->uvs, polygon->colors, polygon->texture, false);
} break;
case CanvasItem::Command::TYPE_CIRCLE: {
- CanvasItem::CommandCircle* circle = static_cast<CanvasItem::CommandCircle*>(c);
- static const int numpoints=32;
- Vector2 points[numpoints+1];
- points[numpoints]=circle->pos;
- int indices[numpoints*3];
+ CanvasItem::CommandCircle *circle = static_cast<CanvasItem::CommandCircle *>(c);
+ static const int numpoints = 32;
+ Vector2 points[numpoints + 1];
+ points[numpoints] = circle->pos;
+ int indices[numpoints * 3];
- for(int i=0;i<numpoints;i++) {
+ for (int i = 0; i < numpoints; i++) {
- points[i]=circle->pos+Vector2( Math::sin(i*Math_PI*2.0/numpoints),Math::cos(i*Math_PI*2.0/numpoints) )*circle->radius;
- indices[i*3+0]=i;
- indices[i*3+1]=(i+1)%numpoints;
- indices[i*3+2]=numpoints;
+ points[i] = circle->pos + Vector2(Math::sin(i * Math_PI * 2.0 / numpoints), Math::cos(i * Math_PI * 2.0 / numpoints)) * circle->radius;
+ indices[i * 3 + 0] = i;
+ indices[i * 3 + 1] = (i + 1) % numpoints;
+ indices[i * 3 + 2] = numpoints;
}
- canvas_draw_polygon(numpoints*3,indices,points,NULL,&circle->color,RID(),true);
+ canvas_draw_polygon(numpoints * 3, indices, points, NULL, &circle->color, RID(), true);
//canvas_draw_circle(circle->indices.size(),circle->indices.ptr(),circle->points.ptr(),circle->uvs.ptr(),circle->colors.ptr(),circle->texture,circle->colors.size()==1);
} break;
case CanvasItem::Command::TYPE_TRANSFORM: {
- CanvasItem::CommandTransform* transform = static_cast<CanvasItem::CommandTransform*>(c);
+ CanvasItem::CommandTransform *transform = static_cast<CanvasItem::CommandTransform *>(c);
canvas_set_transform(transform->xform);
} break;
case CanvasItem::Command::TYPE_BLEND_MODE: {
- CanvasItem::CommandBlendMode* bm = static_cast<CanvasItem::CommandBlendMode*>(c);
+ CanvasItem::CommandBlendMode *bm = static_cast<CanvasItem::CommandBlendMode *>(c);
canvas_set_blend_mode(bm->blend_mode);
} break;
case CanvasItem::Command::TYPE_CLIP_IGNORE: {
- CanvasItem::CommandClipIgnore* ci = static_cast<CanvasItem::CommandClipIgnore*>(c);
+ CanvasItem::CommandClipIgnore *ci = static_cast<CanvasItem::CommandClipIgnore *>(c);
if (current_clip) {
- if (ci->ignore!=reclip) {
+ if (ci->ignore != reclip) {
if (ci->ignore) {
glDisable(GL_SCISSOR_TEST);
- reclip=true;
- } else {
+ reclip = true;
+ } else {
glEnable(GL_SCISSOR_TEST);
//glScissor(viewport.x+current_clip->final_clip_rect.pos.x,viewport.y+ (viewport.height-(current_clip->final_clip_rect.pos.y+current_clip->final_clip_rect.size.height)),
@@ -9287,51 +8680,46 @@ void RasterizerGLES2::_canvas_item_render_commands(CanvasItem *p_item,CanvasItem
y = current_clip->final_clip_rect.pos.y;
w = current_clip->final_clip_rect.size.x;
h = current_clip->final_clip_rect.size.y;
- }
- else {
+ } else {
x = current_clip->final_clip_rect.pos.x;
y = window_size.height - (current_clip->final_clip_rect.pos.y + current_clip->final_clip_rect.size.y);
w = current_clip->final_clip_rect.size.x;
h = current_clip->final_clip_rect.size.y;
}
- glScissor(x,y,w,h);
+ glScissor(x, y, w, h);
-
- reclip=false;
+ reclip = false;
}
}
}
-
-
} break;
}
}
-
}
-void RasterizerGLES2::_canvas_item_setup_shader_params(CanvasItemMaterial *material,Shader* shader) {
+void RasterizerGLES2::_canvas_item_setup_shader_params(CanvasItemMaterial *material, Shader *shader) {
if (canvas_shader.bind())
- rebind_texpixel_size=true;
+ rebind_texpixel_size = true;
- if (material->shader_version!=shader->version) {
+ if (material->shader_version != shader->version) {
//todo optimize uniforms
- material->shader_version=shader->version;
+ material->shader_version = shader->version;
}
if (shader->has_texscreen && framebuffer.active) {
int x = viewport.x;
- int y = window_size.height-(viewport.height+viewport.y);
-
- canvas_shader.set_uniform(CanvasShaderGLES2::TEXSCREEN_SCREEN_MULT,Vector2(float(viewport.width)/framebuffer.width,float(viewport.height)/framebuffer.height));
- canvas_shader.set_uniform(CanvasShaderGLES2::TEXSCREEN_SCREEN_CLAMP,Color(float(x)/framebuffer.width,float(y)/framebuffer.height,float(x+viewport.width)/framebuffer.width,float(y+viewport.height)/framebuffer.height));
- canvas_shader.set_uniform(CanvasShaderGLES2::TEXSCREEN_TEX,max_texture_units-1);
- glActiveTexture(GL_TEXTURE0+max_texture_units-1);
- glBindTexture(GL_TEXTURE_2D,framebuffer.sample_color);
- if (framebuffer.scale==1 && !canvas_texscreen_used) {
+ int y = window_size.height - (viewport.height + viewport.y);
+
+ canvas_shader.set_uniform(CanvasShaderGLES2::TEXSCREEN_SCREEN_MULT, Vector2(float(viewport.width) / framebuffer.width, float(viewport.height) / framebuffer.height));
+ canvas_shader.set_uniform(CanvasShaderGLES2::TEXSCREEN_SCREEN_CLAMP, Color(float(x) / framebuffer.width, float(y) / framebuffer.height, float(x + viewport.width) / framebuffer.width, float(y + viewport.height) / framebuffer.height));
+ canvas_shader.set_uniform(CanvasShaderGLES2::TEXSCREEN_TEX, max_texture_units - 1);
+ glActiveTexture(GL_TEXTURE0 + max_texture_units - 1);
+ glBindTexture(GL_TEXTURE_2D, framebuffer.sample_color);
+ if (framebuffer.scale == 1 && !canvas_texscreen_used) {
#ifdef GLEW_ENABLED
if (current_rt) {
glReadBuffer(GL_COLOR_ATTACHMENT0);
@@ -9340,50 +8728,47 @@ void RasterizerGLES2::_canvas_item_setup_shader_params(CanvasItemMaterial *mater
}
#endif
if (current_rt) {
- glCopyTexSubImage2D(GL_TEXTURE_2D,0,viewport.x,viewport.y,viewport.x,viewport.y,viewport.width,viewport.height);
- canvas_shader.set_uniform(CanvasShaderGLES2::TEXSCREEN_SCREEN_CLAMP,Color(float(x)/framebuffer.width,float(viewport.y)/framebuffer.height,float(x+viewport.width)/framebuffer.width,float(y+viewport.height)/framebuffer.height));
+ glCopyTexSubImage2D(GL_TEXTURE_2D, 0, viewport.x, viewport.y, viewport.x, viewport.y, viewport.width, viewport.height);
+ canvas_shader.set_uniform(CanvasShaderGLES2::TEXSCREEN_SCREEN_CLAMP, Color(float(x) / framebuffer.width, float(viewport.y) / framebuffer.height, float(x + viewport.width) / framebuffer.width, float(y + viewport.height) / framebuffer.height));
//window_size.height-(viewport.height+viewport.y)
} else {
- glCopyTexSubImage2D(GL_TEXTURE_2D,0,x,y,x,y,viewport.width,viewport.height);
+ glCopyTexSubImage2D(GL_TEXTURE_2D, 0, x, y, x, y, viewport.width, viewport.height);
}
- canvas_texscreen_used=true;
+ canvas_texscreen_used = true;
}
glActiveTexture(GL_TEXTURE0);
-
}
if (shader->has_screen_uv) {
- canvas_shader.set_uniform(CanvasShaderGLES2::SCREEN_UV_MULT,Vector2(1.0/viewport.width,1.0/viewport.height));
+ canvas_shader.set_uniform(CanvasShaderGLES2::SCREEN_UV_MULT, Vector2(1.0 / viewport.width, 1.0 / viewport.height));
}
-
- uses_texpixel_size=shader->uses_texpixel_size;
-
+ uses_texpixel_size = shader->uses_texpixel_size;
}
-void RasterizerGLES2::_canvas_item_setup_shader_uniforms(CanvasItemMaterial *material,Shader* shader) {
+void RasterizerGLES2::_canvas_item_setup_shader_uniforms(CanvasItemMaterial *material, Shader *shader) {
//this can be optimized..
- int tex_id=1;
- int idx=0;
- for(Map<StringName,ShaderLanguage::Uniform>::Element *E=shader->uniforms.front();E;E=E->next()) {
+ int tex_id = 1;
+ int idx = 0;
+ for (Map<StringName, ShaderLanguage::Uniform>::Element *E = shader->uniforms.front(); E; E = E->next()) {
- Map<StringName,Variant>::Element *F=material->shader_param.find(E->key());
+ Map<StringName, Variant>::Element *F = material->shader_param.find(E->key());
- if ((E->get().type==ShaderLanguage::TYPE_TEXTURE || E->get().type==ShaderLanguage::TYPE_CUBEMAP)) {
+ if ((E->get().type == ShaderLanguage::TYPE_TEXTURE || E->get().type == ShaderLanguage::TYPE_CUBEMAP)) {
RID rid;
if (F) {
- rid=F->get();
+ rid = F->get();
}
if (!rid.is_valid()) {
- Map<StringName,RID>::Element *DT=shader->default_textures.find(E->key());
+ Map<StringName, RID>::Element *DT = shader->default_textures.find(E->key());
if (DT) {
- rid=DT->get();
+ rid = DT->get();
}
}
@@ -9391,88 +8776,81 @@ void RasterizerGLES2::_canvas_item_setup_shader_uniforms(CanvasItemMaterial *mat
int loc = canvas_shader.get_custom_uniform_location(idx); //should be automatic..
- glActiveTexture(GL_TEXTURE0+tex_id);
- Texture *t=texture_owner.get(rid);
+ glActiveTexture(GL_TEXTURE0 + tex_id);
+ Texture *t = texture_owner.get(rid);
if (!t)
- glBindTexture(GL_TEXTURE_2D,white_tex);
+ glBindTexture(GL_TEXTURE_2D, white_tex);
else
- glBindTexture(t->target,t->tex_id);
+ glBindTexture(t->target, t->tex_id);
- glUniform1i(loc,tex_id);
+ glUniform1i(loc, tex_id);
tex_id++;
}
} else {
- Variant &v=F?F->get():E->get().default_value;
- canvas_shader.set_custom_uniform(idx,v);
+ Variant &v = F ? F->get() : E->get().default_value;
+ canvas_shader.set_custom_uniform(idx, v);
}
idx++;
}
- if (tex_id>1) {
+ if (tex_id > 1) {
glActiveTexture(GL_TEXTURE0);
}
if (shader->uses_time) {
- canvas_shader.set_uniform(CanvasShaderGLES2::TIME,Math::fmod(last_time,shader_time_rollback));
- draw_next_frame=true;
+ canvas_shader.set_uniform(CanvasShaderGLES2::TIME, Math::fmod(last_time, shader_time_rollback));
+ draw_next_frame = true;
}
- //if uses TIME - draw_next_frame=true
-
-
+ //if uses TIME - draw_next_frame=true
}
-void RasterizerGLES2::canvas_render_items(CanvasItem *p_item_list,int p_z,const Color& p_modulate,CanvasLight *p_light) {
+void RasterizerGLES2::canvas_render_items(CanvasItem *p_item_list, int p_z, const Color &p_modulate, CanvasLight *p_light) {
+ CanvasItem *current_clip = NULL;
+ Shader *shader_cache = NULL;
- CanvasItem *current_clip=NULL;
- Shader *shader_cache=NULL;
+ bool rebind_shader = true;
- bool rebind_shader=true;
+ canvas_opacity = 1.0;
+ canvas_use_modulate = p_modulate != Color(1, 1, 1, 1);
+ canvas_modulate = p_modulate;
+ canvas_shader.set_conditional(CanvasShaderGLES2::USE_MODULATE, canvas_use_modulate);
+ canvas_shader.set_conditional(CanvasShaderGLES2::USE_DISTANCE_FIELD, false);
- canvas_opacity=1.0;
- canvas_use_modulate=p_modulate!=Color(1,1,1,1);
- canvas_modulate=p_modulate;
- canvas_shader.set_conditional(CanvasShaderGLES2::USE_MODULATE,canvas_use_modulate);
- canvas_shader.set_conditional(CanvasShaderGLES2::USE_DISTANCE_FIELD,false);
+ bool reset_modulate = false;
+ bool prev_distance_field = false;
+ while (p_item_list) {
- bool reset_modulate=false;
- bool prev_distance_field=false;
-
- while(p_item_list) {
-
- CanvasItem *ci=p_item_list;
+ CanvasItem *ci = p_item_list;
if (ci->vp_render) {
if (draw_viewport_func) {
- draw_viewport_func(ci->vp_render->owner,ci->vp_render->udata,ci->vp_render->rect);
+ draw_viewport_func(ci->vp_render->owner, ci->vp_render->udata, ci->vp_render->rect);
}
memdelete(ci->vp_render);
- ci->vp_render=NULL;
- canvas_last_material=NULL;
- canvas_use_modulate=p_modulate!=Color(1,1,1,1);
- canvas_modulate=p_modulate;
- canvas_shader.set_conditional(CanvasShaderGLES2::USE_MODULATE,canvas_use_modulate);
- canvas_shader.set_conditional(CanvasShaderGLES2::USE_DISTANCE_FIELD,false);
- prev_distance_field=false;
- rebind_shader=true;
- reset_modulate=true;
-
-
+ ci->vp_render = NULL;
+ canvas_last_material = NULL;
+ canvas_use_modulate = p_modulate != Color(1, 1, 1, 1);
+ canvas_modulate = p_modulate;
+ canvas_shader.set_conditional(CanvasShaderGLES2::USE_MODULATE, canvas_use_modulate);
+ canvas_shader.set_conditional(CanvasShaderGLES2::USE_DISTANCE_FIELD, false);
+ prev_distance_field = false;
+ rebind_shader = true;
+ reset_modulate = true;
}
- if (prev_distance_field!=ci->distance_field) {
+ if (prev_distance_field != ci->distance_field) {
- canvas_shader.set_conditional(CanvasShaderGLES2::USE_DISTANCE_FIELD,ci->distance_field);
- prev_distance_field=ci->distance_field;
- rebind_shader=true;
+ canvas_shader.set_conditional(CanvasShaderGLES2::USE_DISTANCE_FIELD, ci->distance_field);
+ prev_distance_field = ci->distance_field;
+ rebind_shader = true;
}
+ if (current_clip != ci->final_clip_owner) {
- if (current_clip!=ci->final_clip_owner) {
-
- current_clip=ci->final_clip_owner;
+ current_clip = ci->final_clip_owner;
//setup clip
if (current_clip) {
@@ -9481,7 +8859,7 @@ void RasterizerGLES2::canvas_render_items(CanvasItem *p_item_list,int p_z,const
//glScissor(viewport.x+current_clip->final_clip_rect.pos.x,viewport.y+ (viewport.height-(current_clip->final_clip_rect.pos.y+current_clip->final_clip_rect.size.height)),
//current_clip->final_clip_rect.size.width,current_clip->final_clip_rect.size.height);
-/* int x = viewport.x+current_clip->final_clip_rect.pos.x;
+ /* int x = viewport.x+current_clip->final_clip_rect.pos.x;
int y = window_size.height-(viewport.y+current_clip->final_clip_rect.pos.y+current_clip->final_clip_rect.size.y);
int w = current_clip->final_clip_rect.size.x;
int h = current_clip->final_clip_rect.size.y;
@@ -9496,15 +8874,14 @@ void RasterizerGLES2::canvas_render_items(CanvasItem *p_item_list,int p_z,const
y = current_clip->final_clip_rect.pos.y;
w = current_clip->final_clip_rect.size.x;
h = current_clip->final_clip_rect.size.y;
- }
- else {
+ } else {
x = current_clip->final_clip_rect.pos.x;
y = window_size.height - (current_clip->final_clip_rect.pos.y + current_clip->final_clip_rect.size.y);
w = current_clip->final_clip_rect.size.x;
h = current_clip->final_clip_rect.size.y;
}
- glScissor(x,y,w,h);
+ glScissor(x, y, w, h);
} else {
@@ -9512,21 +8889,21 @@ void RasterizerGLES2::canvas_render_items(CanvasItem *p_item_list,int p_z,const
}
}
- if (ci->copy_back_buffer && framebuffer.active && framebuffer.scale==1) {
+ if (ci->copy_back_buffer && framebuffer.active && framebuffer.scale == 1) {
Rect2 rect;
- int x,y;
+ int x, y;
if (ci->copy_back_buffer->full) {
x = viewport.x;
- y = window_size.height-(viewport.height+viewport.y);
+ y = window_size.height - (viewport.height + viewport.y);
} else {
- x = viewport.x+ci->copy_back_buffer->screen_rect.pos.x;
- y = window_size.height-(viewport.y+ci->copy_back_buffer->screen_rect.pos.y+ci->copy_back_buffer->screen_rect.size.y);
+ x = viewport.x + ci->copy_back_buffer->screen_rect.pos.x;
+ y = window_size.height - (viewport.y + ci->copy_back_buffer->screen_rect.pos.y + ci->copy_back_buffer->screen_rect.size.y);
}
- glActiveTexture(GL_TEXTURE0+max_texture_units-1);
- glBindTexture(GL_TEXTURE_2D,framebuffer.sample_color);
+ glActiveTexture(GL_TEXTURE0 + max_texture_units - 1);
+ glBindTexture(GL_TEXTURE_2D, framebuffer.sample_color);
#ifdef GLEW_ENABLED
if (current_rt) {
@@ -9536,150 +8913,137 @@ void RasterizerGLES2::canvas_render_items(CanvasItem *p_item_list,int p_z,const
}
#endif
if (current_rt) {
- glCopyTexSubImage2D(GL_TEXTURE_2D,0,viewport.x,viewport.y,viewport.x,viewport.y,viewport.width,viewport.height);
+ glCopyTexSubImage2D(GL_TEXTURE_2D, 0, viewport.x, viewport.y, viewport.x, viewport.y, viewport.width, viewport.height);
//window_size.height-(viewport.height+viewport.y)
} else {
- glCopyTexSubImage2D(GL_TEXTURE_2D,0,x,y,x,y,viewport.width,viewport.height);
+ glCopyTexSubImage2D(GL_TEXTURE_2D, 0, x, y, x, y, viewport.width, viewport.height);
}
- canvas_texscreen_used=true;
+ canvas_texscreen_used = true;
glActiveTexture(GL_TEXTURE0);
}
-
-
-
//begin rect
- CanvasItem *material_owner = ci->material_owner?ci->material_owner:ci;
+ CanvasItem *material_owner = ci->material_owner ? ci->material_owner : ci;
CanvasItemMaterial *material = material_owner->material;
- if (material!=canvas_last_material || rebind_shader) {
+ if (material != canvas_last_material || rebind_shader) {
Shader *shader = NULL;
if (material && material->shader.is_valid()) {
shader = shader_owner.get(material->shader);
if (shader && !shader->valid) {
- shader=NULL;
+ shader = NULL;
}
}
- shader_cache=shader;
+ shader_cache = shader;
if (shader) {
canvas_shader.set_custom_shader(shader->custom_code_id);
- _canvas_item_setup_shader_params(material,shader);
+ _canvas_item_setup_shader_params(material, shader);
} else {
- shader_cache=NULL;
+ shader_cache = NULL;
canvas_shader.set_custom_shader(0);
canvas_shader.bind();
- uses_texpixel_size=false;
-
+ uses_texpixel_size = false;
}
-
- canvas_shader.set_uniform(CanvasShaderGLES2::PROJECTION_MATRIX,canvas_transform);
+ canvas_shader.set_uniform(CanvasShaderGLES2::PROJECTION_MATRIX, canvas_transform);
if (canvas_use_modulate)
- reset_modulate=true;
- canvas_last_material=material;
- rebind_shader=false;
+ reset_modulate = true;
+ canvas_last_material = material;
+ rebind_shader = false;
}
if (material && shader_cache) {
- _canvas_item_setup_shader_uniforms(material,shader_cache);
+ _canvas_item_setup_shader_uniforms(material, shader_cache);
}
- bool unshaded = (material && material->shading_mode==VS::CANVAS_ITEM_SHADING_UNSHADED) || ci->blend_mode!=VS::MATERIAL_BLEND_MODE_MIX;
+ bool unshaded = (material && material->shading_mode == VS::CANVAS_ITEM_SHADING_UNSHADED) || ci->blend_mode != VS::MATERIAL_BLEND_MODE_MIX;
if (unshaded) {
- canvas_shader.set_uniform(CanvasShaderGLES2::MODULATE,Color(1,1,1,1));
- reset_modulate=true;
+ canvas_shader.set_uniform(CanvasShaderGLES2::MODULATE, Color(1, 1, 1, 1));
+ reset_modulate = true;
} else if (reset_modulate) {
- canvas_shader.set_uniform(CanvasShaderGLES2::MODULATE,canvas_modulate);
- reset_modulate=false;
+ canvas_shader.set_uniform(CanvasShaderGLES2::MODULATE, canvas_modulate);
+ reset_modulate = false;
}
+ canvas_shader.set_uniform(CanvasShaderGLES2::MODELVIEW_MATRIX, ci->final_transform);
+ canvas_shader.set_uniform(CanvasShaderGLES2::EXTRA_MATRIX, Transform2D());
+ bool reclip = false;
- canvas_shader.set_uniform(CanvasShaderGLES2::MODELVIEW_MATRIX,ci->final_transform);
- canvas_shader.set_uniform(CanvasShaderGLES2::EXTRA_MATRIX,Transform2D());
-
-
- bool reclip=false;
-
- if (ci==p_item_list || ci->blend_mode!=canvas_blend_mode) {
+ if (ci == p_item_list || ci->blend_mode != canvas_blend_mode) {
- switch(ci->blend_mode) {
+ switch (ci->blend_mode) {
- case VS::MATERIAL_BLEND_MODE_MIX: {
+ case VS::MATERIAL_BLEND_MODE_MIX: {
glBlendEquation(GL_FUNC_ADD);
if (current_rt && current_rt_transparent) {
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
- }
- else {
+ } else {
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
- } break;
- case VS::MATERIAL_BLEND_MODE_ADD: {
+ } break;
+ case VS::MATERIAL_BLEND_MODE_ADD: {
glBlendEquation(GL_FUNC_ADD);
- glBlendFunc(GL_SRC_ALPHA,GL_ONE);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE);
- } break;
- case VS::MATERIAL_BLEND_MODE_SUB: {
+ } break;
+ case VS::MATERIAL_BLEND_MODE_SUB: {
glBlendEquation(GL_FUNC_REVERSE_SUBTRACT);
- glBlendFunc(GL_SRC_ALPHA,GL_ONE);
- } break;
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE);
+ } break;
case VS::MATERIAL_BLEND_MODE_MUL: {
glBlendEquation(GL_FUNC_ADD);
- glBlendFunc(GL_DST_COLOR,GL_ZERO);
+ glBlendFunc(GL_DST_COLOR, GL_ZERO);
} break;
case VS::MATERIAL_BLEND_MODE_PREMULT_ALPHA: {
glBlendEquation(GL_FUNC_ADD);
- glBlendFunc(GL_ONE,GL_ONE_MINUS_SRC_ALPHA);
+ glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
} break;
-
}
- canvas_blend_mode=ci->blend_mode;
+ canvas_blend_mode = ci->blend_mode;
}
canvas_opacity = ci->final_opacity;
+ if (unshaded || (p_modulate.a > 0.001 && (!material || material->shading_mode != VS::CANVAS_ITEM_SHADING_ONLY_LIGHT) && !ci->light_masked))
+ _canvas_item_render_commands<false>(ci, current_clip, reclip);
- if (unshaded || (p_modulate.a>0.001 && (!material || material->shading_mode!=VS::CANVAS_ITEM_SHADING_ONLY_LIGHT) && !ci->light_masked ))
- _canvas_item_render_commands<false>(ci,current_clip,reclip);
-
- if (canvas_blend_mode==VS::MATERIAL_BLEND_MODE_MIX && p_light && !unshaded) {
+ if (canvas_blend_mode == VS::MATERIAL_BLEND_MODE_MIX && p_light && !unshaded) {
CanvasLight *light = p_light;
- bool light_used=false;
- VS::CanvasLightMode mode=VS::CANVAS_LIGHT_MODE_ADD;
+ bool light_used = false;
+ VS::CanvasLightMode mode = VS::CANVAS_LIGHT_MODE_ADD;
+ while (light) {
- while(light) {
-
-
- if (ci->light_mask&light->item_mask && p_z>=light->z_min && p_z<=light->z_max && ci->global_rect_cache.intersects_transformed(light->xform_cache,light->rect_cache)) {
+ if (ci->light_mask & light->item_mask && p_z >= light->z_min && p_z <= light->z_max && ci->global_rect_cache.intersects_transformed(light->xform_cache, light->rect_cache)) {
//intersects this light
- if (!light_used || mode!=light->mode) {
+ if (!light_used || mode != light->mode) {
- mode=light->mode;
+ mode = light->mode;
- switch(mode) {
+ switch (mode) {
case VS::CANVAS_LIGHT_MODE_ADD: {
glBlendEquation(GL_FUNC_ADD);
- glBlendFunc(GL_SRC_ALPHA,GL_ONE);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE);
} break;
case VS::CANVAS_LIGHT_MODE_SUB: {
glBlendEquation(GL_FUNC_REVERSE_SUBTRACT);
- glBlendFunc(GL_SRC_ALPHA,GL_ONE);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE);
} break;
case VS::CANVAS_LIGHT_MODE_MIX:
case VS::CANVAS_LIGHT_MODE_MASK: {
@@ -9688,114 +9052,102 @@ void RasterizerGLES2::canvas_render_items(CanvasItem *p_item_list,int p_z,const
} break;
}
-
}
if (!light_used) {
- canvas_shader.set_conditional(CanvasShaderGLES2::USE_LIGHTING,true);
- canvas_shader.set_conditional(CanvasShaderGLES2::USE_MODULATE,false);
- light_used=true;
- normal_flip=Vector2(1,1);
-
+ canvas_shader.set_conditional(CanvasShaderGLES2::USE_LIGHTING, true);
+ canvas_shader.set_conditional(CanvasShaderGLES2::USE_MODULATE, false);
+ light_used = true;
+ normal_flip = Vector2(1, 1);
}
+ bool has_shadow = light->shadow_buffer.is_valid() && ci->light_mask & light->item_shadow_mask;
- bool has_shadow = light->shadow_buffer.is_valid() && ci->light_mask&light->item_shadow_mask;
-
- canvas_shader.set_conditional(CanvasShaderGLES2::USE_SHADOWS,has_shadow);
+ canvas_shader.set_conditional(CanvasShaderGLES2::USE_SHADOWS, has_shadow);
bool light_rebind = canvas_shader.bind();
if (light_rebind) {
if (material && shader_cache) {
- _canvas_item_setup_shader_params(material,shader_cache);
- _canvas_item_setup_shader_uniforms(material,shader_cache);
+ _canvas_item_setup_shader_params(material, shader_cache);
+ _canvas_item_setup_shader_uniforms(material, shader_cache);
}
- canvas_shader.set_uniform(CanvasShaderGLES2::MODELVIEW_MATRIX,ci->final_transform);
- canvas_shader.set_uniform(CanvasShaderGLES2::EXTRA_MATRIX,Transform2D());
- canvas_shader.set_uniform(CanvasShaderGLES2::PROJECTION_MATRIX,canvas_transform);
+ canvas_shader.set_uniform(CanvasShaderGLES2::MODELVIEW_MATRIX, ci->final_transform);
+ canvas_shader.set_uniform(CanvasShaderGLES2::EXTRA_MATRIX, Transform2D());
+ canvas_shader.set_uniform(CanvasShaderGLES2::PROJECTION_MATRIX, canvas_transform);
if (canvas_use_modulate)
- canvas_shader.set_uniform(CanvasShaderGLES2::MODULATE,canvas_modulate);
- canvas_shader.set_uniform(CanvasShaderGLES2::NORMAL_FLIP,Vector2(1,1));
- canvas_shader.set_uniform(CanvasShaderGLES2::SHADOWPIXEL_SIZE,1.0/light->shadow_buffer_size);
-
-
+ canvas_shader.set_uniform(CanvasShaderGLES2::MODULATE, canvas_modulate);
+ canvas_shader.set_uniform(CanvasShaderGLES2::NORMAL_FLIP, Vector2(1, 1));
+ canvas_shader.set_uniform(CanvasShaderGLES2::SHADOWPIXEL_SIZE, 1.0 / light->shadow_buffer_size);
}
- canvas_shader.set_uniform(CanvasShaderGLES2::LIGHT_MATRIX,light->light_shader_xform);
- canvas_shader.set_uniform(CanvasShaderGLES2::LIGHT_POS,light->light_shader_pos);
- canvas_shader.set_uniform(CanvasShaderGLES2::LIGHT_COLOR,Color(light->color.r*light->energy,light->color.g*light->energy,light->color.b*light->energy,light->color.a));
- canvas_shader.set_uniform(CanvasShaderGLES2::LIGHT_HEIGHT,light->height);
- canvas_shader.set_uniform(CanvasShaderGLES2::LIGHT_LOCAL_MATRIX,light->xform_cache.affine_inverse());
- canvas_shader.set_uniform(CanvasShaderGLES2::LIGHT_OUTSIDE_ALPHA,light->mode==VS::CANVAS_LIGHT_MODE_MASK?1.0:0.0);
+ canvas_shader.set_uniform(CanvasShaderGLES2::LIGHT_MATRIX, light->light_shader_xform);
+ canvas_shader.set_uniform(CanvasShaderGLES2::LIGHT_POS, light->light_shader_pos);
+ canvas_shader.set_uniform(CanvasShaderGLES2::LIGHT_COLOR, Color(light->color.r * light->energy, light->color.g * light->energy, light->color.b * light->energy, light->color.a));
+ canvas_shader.set_uniform(CanvasShaderGLES2::LIGHT_HEIGHT, light->height);
+ canvas_shader.set_uniform(CanvasShaderGLES2::LIGHT_LOCAL_MATRIX, light->xform_cache.affine_inverse());
+ canvas_shader.set_uniform(CanvasShaderGLES2::LIGHT_OUTSIDE_ALPHA, light->mode == VS::CANVAS_LIGHT_MODE_MASK ? 1.0 : 0.0);
if (has_shadow) {
CanvasLightShadow *cls = canvas_light_shadow_owner.get(light->shadow_buffer);
- glActiveTexture(GL_TEXTURE0+max_texture_units-3);
+ glActiveTexture(GL_TEXTURE0 + max_texture_units - 3);
if (read_depth_supported)
- glBindTexture(GL_TEXTURE_2D,cls->depth);
+ glBindTexture(GL_TEXTURE_2D, cls->depth);
else
- glBindTexture(GL_TEXTURE_2D,cls->rgba);
-
- canvas_shader.set_uniform(CanvasShaderGLES2::SHADOW_TEXTURE,max_texture_units-3);
- canvas_shader.set_uniform(CanvasShaderGLES2::SHADOW_MATRIX,light->shadow_matrix_cache);
- canvas_shader.set_uniform(CanvasShaderGLES2::SHADOW_ESM_MULTIPLIER,light->shadow_esm_mult);
- canvas_shader.set_uniform(CanvasShaderGLES2::LIGHT_SHADOW_COLOR,light->shadow_color);
+ glBindTexture(GL_TEXTURE_2D, cls->rgba);
+ canvas_shader.set_uniform(CanvasShaderGLES2::SHADOW_TEXTURE, max_texture_units - 3);
+ canvas_shader.set_uniform(CanvasShaderGLES2::SHADOW_MATRIX, light->shadow_matrix_cache);
+ canvas_shader.set_uniform(CanvasShaderGLES2::SHADOW_ESM_MULTIPLIER, light->shadow_esm_mult);
+ canvas_shader.set_uniform(CanvasShaderGLES2::LIGHT_SHADOW_COLOR, light->shadow_color);
}
-
- glActiveTexture(GL_TEXTURE0+max_texture_units-2);
- canvas_shader.set_uniform(CanvasShaderGLES2::LIGHT_TEXTURE,max_texture_units-2);
+ glActiveTexture(GL_TEXTURE0 + max_texture_units - 2);
+ canvas_shader.set_uniform(CanvasShaderGLES2::LIGHT_TEXTURE, max_texture_units - 2);
Texture *t = texture_owner.get(light->texture);
if (!t) {
- glBindTexture(GL_TEXTURE_2D,white_tex);
+ glBindTexture(GL_TEXTURE_2D, white_tex);
} else {
- glBindTexture(t->target,t->tex_id);
+ glBindTexture(t->target, t->tex_id);
}
glActiveTexture(GL_TEXTURE0);
- _canvas_item_render_commands<true>(ci,current_clip,reclip); //redraw using light
-
+ _canvas_item_render_commands<true>(ci, current_clip, reclip); //redraw using light
}
- light=light->next_ptr;
+ light = light->next_ptr;
}
if (light_used) {
-
- canvas_shader.set_conditional(CanvasShaderGLES2::USE_LIGHTING,false);
- canvas_shader.set_conditional(CanvasShaderGLES2::USE_MODULATE,canvas_use_modulate);
- canvas_shader.set_conditional(CanvasShaderGLES2::USE_SHADOWS,false);
+ canvas_shader.set_conditional(CanvasShaderGLES2::USE_LIGHTING, false);
+ canvas_shader.set_conditional(CanvasShaderGLES2::USE_MODULATE, canvas_use_modulate);
+ canvas_shader.set_conditional(CanvasShaderGLES2::USE_SHADOWS, false);
canvas_shader.bind();
if (material && shader_cache) {
- _canvas_item_setup_shader_params(material,shader_cache);
- _canvas_item_setup_shader_uniforms(material,shader_cache);
+ _canvas_item_setup_shader_params(material, shader_cache);
+ _canvas_item_setup_shader_uniforms(material, shader_cache);
}
- canvas_shader.set_uniform(CanvasShaderGLES2::MODELVIEW_MATRIX,ci->final_transform);
- canvas_shader.set_uniform(CanvasShaderGLES2::EXTRA_MATRIX,Transform2D());
+ canvas_shader.set_uniform(CanvasShaderGLES2::MODELVIEW_MATRIX, ci->final_transform);
+ canvas_shader.set_uniform(CanvasShaderGLES2::EXTRA_MATRIX, Transform2D());
if (canvas_use_modulate)
- canvas_shader.set_uniform(CanvasShaderGLES2::MODULATE,canvas_modulate);
+ canvas_shader.set_uniform(CanvasShaderGLES2::MODULATE, canvas_modulate);
glBlendEquation(GL_FUNC_ADD);
if (current_rt && current_rt_transparent) {
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
- }
- else {
+ } else {
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
}
-
-
}
if (reclip) {
@@ -9814,116 +9166,104 @@ void RasterizerGLES2::canvas_render_items(CanvasItem *p_item_list,int p_z,const
y = current_clip->final_clip_rect.pos.y;
w = current_clip->final_clip_rect.size.x;
h = current_clip->final_clip_rect.size.y;
- }
- else {
+ } else {
x = current_clip->final_clip_rect.pos.x;
y = window_size.height - (current_clip->final_clip_rect.pos.y + current_clip->final_clip_rect.size.y);
w = current_clip->final_clip_rect.size.x;
h = current_clip->final_clip_rect.size.y;
}
- glScissor(x,y,w,h);
-
-
+ glScissor(x, y, w, h);
}
-
-
- p_item_list=p_item_list->next;
+ p_item_list = p_item_list->next;
}
if (current_clip) {
glDisable(GL_SCISSOR_TEST);
}
-
}
/* ENVIRONMENT */
RID RasterizerGLES2::environment_create() {
- Environment * env = memnew( Environment );
+ Environment *env = memnew(Environment);
return environment_owner.make_rid(env);
}
-void RasterizerGLES2::environment_set_background(RID p_env,VS::EnvironmentBG p_bg) {
+void RasterizerGLES2::environment_set_background(RID p_env, VS::EnvironmentBG p_bg) {
- ERR_FAIL_INDEX(p_bg,VS::ENV_BG_MAX);
- Environment * env = environment_owner.get(p_env);
+ ERR_FAIL_INDEX(p_bg, VS::ENV_BG_MAX);
+ Environment *env = environment_owner.get(p_env);
ERR_FAIL_COND(!env);
- env->bg_mode=p_bg;
+ env->bg_mode = p_bg;
}
-VS::EnvironmentBG RasterizerGLES2::environment_get_background(RID p_env) const{
+VS::EnvironmentBG RasterizerGLES2::environment_get_background(RID p_env) const {
- const Environment * env = environment_owner.get(p_env);
- ERR_FAIL_COND_V(!env,VS::ENV_BG_MAX);
+ const Environment *env = environment_owner.get(p_env);
+ ERR_FAIL_COND_V(!env, VS::ENV_BG_MAX);
return env->bg_mode;
}
-void RasterizerGLES2::environment_set_background_param(RID p_env,VS::EnvironmentBGParam p_param, const Variant& p_value){
+void RasterizerGLES2::environment_set_background_param(RID p_env, VS::EnvironmentBGParam p_param, const Variant &p_value) {
- ERR_FAIL_INDEX(p_param,VS::ENV_BG_PARAM_MAX);
- Environment * env = environment_owner.get(p_env);
+ ERR_FAIL_INDEX(p_param, VS::ENV_BG_PARAM_MAX);
+ Environment *env = environment_owner.get(p_env);
ERR_FAIL_COND(!env);
- env->bg_param[p_param]=p_value;
-
+ env->bg_param[p_param] = p_value;
}
-Variant RasterizerGLES2::environment_get_background_param(RID p_env,VS::EnvironmentBGParam p_param) const{
+Variant RasterizerGLES2::environment_get_background_param(RID p_env, VS::EnvironmentBGParam p_param) const {
- ERR_FAIL_INDEX_V(p_param,VS::ENV_BG_PARAM_MAX,Variant());
- const Environment * env = environment_owner.get(p_env);
- ERR_FAIL_COND_V(!env,Variant());
+ ERR_FAIL_INDEX_V(p_param, VS::ENV_BG_PARAM_MAX, Variant());
+ const Environment *env = environment_owner.get(p_env);
+ ERR_FAIL_COND_V(!env, Variant());
return env->bg_param[p_param];
-
}
-void RasterizerGLES2::environment_set_enable_fx(RID p_env,VS::EnvironmentFx p_effect,bool p_enabled){
+void RasterizerGLES2::environment_set_enable_fx(RID p_env, VS::EnvironmentFx p_effect, bool p_enabled) {
- ERR_FAIL_INDEX(p_effect,VS::ENV_FX_MAX);
- Environment * env = environment_owner.get(p_env);
+ ERR_FAIL_INDEX(p_effect, VS::ENV_FX_MAX);
+ Environment *env = environment_owner.get(p_env);
ERR_FAIL_COND(!env);
- env->fx_enabled[p_effect]=p_enabled;
+ env->fx_enabled[p_effect] = p_enabled;
}
-bool RasterizerGLES2::environment_is_fx_enabled(RID p_env,VS::EnvironmentFx p_effect) const{
+bool RasterizerGLES2::environment_is_fx_enabled(RID p_env, VS::EnvironmentFx p_effect) const {
- ERR_FAIL_INDEX_V(p_effect,VS::ENV_FX_MAX,false);
- const Environment * env = environment_owner.get(p_env);
- ERR_FAIL_COND_V(!env,false);
+ ERR_FAIL_INDEX_V(p_effect, VS::ENV_FX_MAX, false);
+ const Environment *env = environment_owner.get(p_env);
+ ERR_FAIL_COND_V(!env, false);
return env->fx_enabled[p_effect];
-
}
-void RasterizerGLES2::environment_fx_set_param(RID p_env,VS::EnvironmentFxParam p_param,const Variant& p_value){
+void RasterizerGLES2::environment_fx_set_param(RID p_env, VS::EnvironmentFxParam p_param, const Variant &p_value) {
- ERR_FAIL_INDEX(p_param,VS::ENV_FX_PARAM_MAX);
- Environment * env = environment_owner.get(p_env);
+ ERR_FAIL_INDEX(p_param, VS::ENV_FX_PARAM_MAX);
+ Environment *env = environment_owner.get(p_env);
ERR_FAIL_COND(!env);
- env->fx_param[p_param]=p_value;
+ env->fx_param[p_param] = p_value;
}
-Variant RasterizerGLES2::environment_fx_get_param(RID p_env,VS::EnvironmentFxParam p_param) const{
+Variant RasterizerGLES2::environment_fx_get_param(RID p_env, VS::EnvironmentFxParam p_param) const {
- ERR_FAIL_INDEX_V(p_param,VS::ENV_FX_PARAM_MAX,Variant());
- const Environment * env = environment_owner.get(p_env);
- ERR_FAIL_COND_V(!env,Variant());
+ ERR_FAIL_INDEX_V(p_param, VS::ENV_FX_PARAM_MAX, Variant());
+ const Environment *env = environment_owner.get(p_env);
+ ERR_FAIL_COND_V(!env, Variant());
return env->fx_param[p_param];
-
}
-
-
-RID RasterizerGLES2::sampled_light_dp_create(int p_width,int p_height) {
+RID RasterizerGLES2::sampled_light_dp_create(int p_width, int p_height) {
SampledLight *slight = memnew(SampledLight);
- slight->w=p_width;
- slight->h=p_height;
- slight->multiplier=1.0;
- slight->is_float=float_linear_supported;
+ slight->w = p_width;
+ slight->h = p_height;
+ slight->multiplier = 1.0;
+ slight->is_float = float_linear_supported;
glActiveTexture(GL_TEXTURE0);
- glGenTextures(1,&slight->texture);
+ glGenTextures(1, &slight->texture);
glBindTexture(GL_TEXTURE_2D, slight->texture);
-// for debug, but glitchy
+ // for debug, but glitchy
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
@@ -9933,17 +9273,15 @@ RID RasterizerGLES2::sampled_light_dp_create(int p_width,int p_height) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
-
if (slight->is_float) {
#ifdef GLEW_ENABLED
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, p_width, p_height, 0, GL_RGBA, GL_FLOAT,NULL);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, p_width, p_height, 0, GL_RGBA, GL_FLOAT, NULL);
#else
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, p_width, p_height, 0, GL_RGBA, GL_FLOAT,NULL);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, p_width, p_height, 0, GL_RGBA, GL_FLOAT, NULL);
#endif
} else {
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, p_width, p_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
-
}
return sampled_light_owner.make_rid(slight);
@@ -9960,47 +9298,46 @@ void RasterizerGLES2::sampled_light_dp_update(RID p_sampled_light, const Color *
if (slight->is_float) {
#ifdef GLEW_ENABLED
- glTexSubImage2D(GL_TEXTURE_2D, 0,0,0,slight->w, slight->h, GL_RGBA, GL_FLOAT,p_data);
+ glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, slight->w, slight->h, GL_RGBA, GL_FLOAT, p_data);
#else
- glTexSubImage2D(GL_TEXTURE_2D, 0,0,0,slight->w, slight->h, GL_RGBA, GL_FLOAT,p_data);
+ glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, slight->w, slight->h, GL_RGBA, GL_FLOAT, p_data);
#endif
} else {
//convert to bytes
- uint8_t *tex8 = (uint8_t*)alloca(slight->w*slight->h*4);
- const float* src=(const float*)p_data;
+ uint8_t *tex8 = (uint8_t *)alloca(slight->w * slight->h * 4);
+ const float *src = (const float *)p_data;
- for(int i=0;i<slight->w*slight->h*4;i++) {
+ for (int i = 0; i < slight->w * slight->h * 4; i++) {
- tex8[i]=Math::fast_ftoi(CLAMP(src[i]*255.0,0.0,255.0));
+ tex8[i] = Math::fast_ftoi(CLAMP(src[i] * 255.0, 0.0, 255.0));
}
- glTexSubImage2D(GL_TEXTURE_2D, 0,0,0,slight->w, slight->h, GL_RGBA, GL_UNSIGNED_BYTE,p_data);
+ glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, slight->w, slight->h, GL_RGBA, GL_UNSIGNED_BYTE, p_data);
}
- slight->multiplier=p_multiplier;
-
+ slight->multiplier = p_multiplier;
}
/*MISC*/
-bool RasterizerGLES2::is_texture(const RID& p_rid) const {
+bool RasterizerGLES2::is_texture(const RID &p_rid) const {
return texture_owner.owns(p_rid);
}
-bool RasterizerGLES2::is_material(const RID& p_rid) const {
+bool RasterizerGLES2::is_material(const RID &p_rid) const {
return material_owner.owns(p_rid);
}
-bool RasterizerGLES2::is_mesh(const RID& p_rid) const {
+bool RasterizerGLES2::is_mesh(const RID &p_rid) const {
return mesh_owner.owns(p_rid);
}
-bool RasterizerGLES2::is_immediate(const RID& p_rid) const {
+bool RasterizerGLES2::is_immediate(const RID &p_rid) const {
return immediate_owner.owns(p_rid);
}
-bool RasterizerGLES2::is_multimesh(const RID& p_rid) const {
+bool RasterizerGLES2::is_multimesh(const RID &p_rid) const {
return multimesh_owner.owns(p_rid);
}
@@ -10009,44 +9346,44 @@ bool RasterizerGLES2::is_particles(const RID &p_beam) const {
return particles_owner.owns(p_beam);
}
-bool RasterizerGLES2::is_light(const RID& p_rid) const {
+bool RasterizerGLES2::is_light(const RID &p_rid) const {
return light_owner.owns(p_rid);
}
-bool RasterizerGLES2::is_light_instance(const RID& p_rid) const {
+bool RasterizerGLES2::is_light_instance(const RID &p_rid) const {
return light_instance_owner.owns(p_rid);
}
-bool RasterizerGLES2::is_particles_instance(const RID& p_rid) const {
+bool RasterizerGLES2::is_particles_instance(const RID &p_rid) const {
return particles_instance_owner.owns(p_rid);
}
-bool RasterizerGLES2::is_skeleton(const RID& p_rid) const {
+bool RasterizerGLES2::is_skeleton(const RID &p_rid) const {
return skeleton_owner.owns(p_rid);
}
-bool RasterizerGLES2::is_environment(const RID& p_rid) const {
+bool RasterizerGLES2::is_environment(const RID &p_rid) const {
return environment_owner.owns(p_rid);
}
-bool RasterizerGLES2::is_shader(const RID& p_rid) const {
+bool RasterizerGLES2::is_shader(const RID &p_rid) const {
return shader_owner.owns(p_rid);
}
-bool RasterizerGLES2::is_canvas_light_occluder(const RID& p_rid) const {
+bool RasterizerGLES2::is_canvas_light_occluder(const RID &p_rid) const {
return false;
}
-void RasterizerGLES2::free(const RID& p_rid) {
+void RasterizerGLES2::free(const RID &p_rid) {
if (texture_owner.owns(p_rid)) {
// delete the texture
Texture *texture = texture_owner.get(p_rid);
//glDeleteTextures( 1,&texture->tex_id );
- _rinfo.texture_mem-=texture->total_data_size;
+ _rinfo.texture_mem -= texture->total_data_size;
texture_owner.free(p_rid);
memdelete(texture);
@@ -10055,7 +9392,7 @@ void RasterizerGLES2::free(const RID& p_rid) {
// delete the texture
Shader *shader = shader_owner.get(p_rid);
- switch(shader->mode) {
+ switch (shader->mode) {
case VS::SHADER_MATERIAL: {
material_shader.free_custom_shader(shader->custom_code_id);
} break;
@@ -10073,7 +9410,7 @@ void RasterizerGLES2::free(const RID& p_rid) {
} else if (material_owner.owns(p_rid)) {
- Material *material = material_owner.get( p_rid );
+ Material *material = material_owner.get(p_rid);
ERR_FAIL_COND(!material);
_free_fixed_material(p_rid); //just in case
@@ -10084,7 +9421,7 @@ void RasterizerGLES2::free(const RID& p_rid) {
Mesh *mesh = mesh_owner.get(p_rid);
ERR_FAIL_COND(!mesh);
- for (int i=0;i<mesh->surfaces.size();i++) {
+ for (int i = 0; i < mesh->surfaces.size(); i++) {
Surface *surface = mesh->surfaces[i];
if (surface->array_local != 0) {
@@ -10094,22 +9431,22 @@ void RasterizerGLES2::free(const RID& p_rid) {
memfree(surface->index_array_local);
};
- if (mesh->morph_target_count>0) {
+ if (mesh->morph_target_count > 0) {
- for(int i=0;i<mesh->morph_target_count;i++) {
+ for (int i = 0; i < mesh->morph_target_count; i++) {
memdelete_arr(surface->morph_targets_local[i].array);
}
memdelete_arr(surface->morph_targets_local);
- surface->morph_targets_local=NULL;
+ surface->morph_targets_local = NULL;
}
if (surface->vertex_id)
- glDeleteBuffers(1,&surface->vertex_id);
+ glDeleteBuffers(1, &surface->vertex_id);
if (surface->index_id)
- glDeleteBuffers(1,&surface->index_id);
+ glDeleteBuffers(1, &surface->index_id);
- memdelete( surface );
+ memdelete(surface);
};
mesh->surfaces.clear();
@@ -10119,15 +9456,15 @@ void RasterizerGLES2::free(const RID& p_rid) {
} else if (multimesh_owner.owns(p_rid)) {
- MultiMesh *multimesh = multimesh_owner.get(p_rid);
- ERR_FAIL_COND(!multimesh);
+ MultiMesh *multimesh = multimesh_owner.get(p_rid);
+ ERR_FAIL_COND(!multimesh);
if (multimesh->tex_id) {
- glDeleteTextures(1,&multimesh->tex_id);
+ glDeleteTextures(1, &multimesh->tex_id);
}
- multimesh_owner.free(p_rid);
- memdelete(multimesh);
+ multimesh_owner.free(p_rid);
+ memdelete(multimesh);
} else if (immediate_owner.owns(p_rid)) {
@@ -10153,20 +9490,20 @@ void RasterizerGLES2::free(const RID& p_rid) {
} else if (skeleton_owner.owns(p_rid)) {
- Skeleton *skeleton = skeleton_owner.get( p_rid );
+ Skeleton *skeleton = skeleton_owner.get(p_rid);
ERR_FAIL_COND(!skeleton);
if (skeleton->dirty_list.in_list())
_skeleton_dirty_list.remove(&skeleton->dirty_list);
if (skeleton->tex_id) {
- glDeleteTextures(1,&skeleton->tex_id);
+ glDeleteTextures(1, &skeleton->tex_id);
}
skeleton_owner.free(p_rid);
memdelete(skeleton);
} else if (light_owner.owns(p_rid)) {
- Light *light = light_owner.get( p_rid );
+ Light *light = light_owner.get(p_rid);
ERR_FAIL_COND(!light)
light_owner.free(p_rid);
@@ -10174,53 +9511,52 @@ void RasterizerGLES2::free(const RID& p_rid) {
} else if (light_instance_owner.owns(p_rid)) {
- LightInstance *light_instance = light_instance_owner.get( p_rid );
+ LightInstance *light_instance = light_instance_owner.get(p_rid);
ERR_FAIL_COND(!light_instance);
light_instance->clear_shadow_buffers();
light_instance_owner.free(p_rid);
- memdelete( light_instance );
+ memdelete(light_instance);
} else if (environment_owner.owns(p_rid)) {
- Environment *env = environment_owner.get( p_rid );
+ Environment *env = environment_owner.get(p_rid);
ERR_FAIL_COND(!env);
environment_owner.free(p_rid);
- memdelete( env );
+ memdelete(env);
} else if (viewport_data_owner.owns(p_rid)) {
- ViewportData *viewport_data = viewport_data_owner.get( p_rid );
+ ViewportData *viewport_data = viewport_data_owner.get(p_rid);
ERR_FAIL_COND(!viewport_data);
- glDeleteFramebuffers(1,&viewport_data->lum_fbo);
- glDeleteTextures(1,&viewport_data->lum_color);
+ glDeleteFramebuffers(1, &viewport_data->lum_fbo);
+ glDeleteTextures(1, &viewport_data->lum_color);
viewport_data_owner.free(p_rid);
- memdelete( viewport_data );
+ memdelete(viewport_data);
} else if (render_target_owner.owns(p_rid)) {
- RenderTarget *render_target = render_target_owner.get( p_rid );
+ RenderTarget *render_target = render_target_owner.get(p_rid);
ERR_FAIL_COND(!render_target);
- render_target_set_size(p_rid,0,0); //clears framebuffer
+ render_target_set_size(p_rid, 0, 0); //clears framebuffer
texture_owner.free(render_target->texture);
memdelete(render_target->texture_ptr);
render_target_owner.free(p_rid);
- memdelete( render_target );
+ memdelete(render_target);
} else if (sampled_light_owner.owns(p_rid)) {
- SampledLight *sampled_light = sampled_light_owner.get( p_rid );
+ SampledLight *sampled_light = sampled_light_owner.get(p_rid);
ERR_FAIL_COND(!sampled_light);
- glDeleteTextures(1,&sampled_light->texture);
+ glDeleteTextures(1, &sampled_light->texture);
sampled_light_owner.free(p_rid);
- memdelete( sampled_light );
+ memdelete(sampled_light);
} else if (canvas_occluder_owner.owns(p_rid)) {
-
CanvasOccluder *co = canvas_occluder_owner.get(p_rid);
if (co->index_id)
- glDeleteBuffers(1,&co->index_id);
+ glDeleteBuffers(1, &co->index_id);
if (co->vertex_id)
- glDeleteBuffers(1,&co->vertex_id);
+ glDeleteBuffers(1, &co->vertex_id);
canvas_occluder_owner.free(p_rid);
memdelete(co);
@@ -10228,9 +9564,9 @@ void RasterizerGLES2::free(const RID& p_rid) {
} else if (canvas_light_shadow_owner.owns(p_rid)) {
CanvasLightShadow *cls = canvas_light_shadow_owner.get(p_rid);
- glDeleteFramebuffers(1,&cls->fbo);
- glDeleteRenderbuffers(1,&cls->rbo);
- glDeleteTextures(1,&cls->depth);
+ glDeleteFramebuffers(1, &cls->fbo);
+ glDeleteRenderbuffers(1, &cls->rbo);
+ glDeleteTextures(1, &cls->depth);
/*
if (!read_depth_supported) {
glDeleteTextures(1,&cls->rgba);
@@ -10242,11 +9578,9 @@ void RasterizerGLES2::free(const RID& p_rid) {
};
}
+bool RasterizerGLES2::ShadowBuffer::init(int p_size, bool p_use_depth) {
-
-bool RasterizerGLES2::ShadowBuffer::init(int p_size,bool p_use_depth) {
-
- size=p_size;
+ size = p_size;
// Create a framebuffer object
glGenFramebuffers(1, &fbo);
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
@@ -10266,11 +9600,11 @@ bool RasterizerGLES2::ShadowBuffer::init(int p_size,bool p_use_depth) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
//print_line("ERROR? "+itos(glGetError()));
- if ( p_use_depth ) {
+ if (p_use_depth) {
// We'll use a depth texture to store the depths in the shadow map
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, size, size, 0,
- GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL);
+ GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL);
#ifdef GLEW_ENABLED
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
@@ -10279,7 +9613,7 @@ bool RasterizerGLES2::ShadowBuffer::init(int p_size,bool p_use_depth) {
// Attach the depth texture to FBO depth attachment point
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
- GL_TEXTURE_2D, depth, 0);
+ GL_TEXTURE_2D, depth, 0);
#ifdef GLEW_ENABLED
glDrawBuffer(GL_NONE);
@@ -10294,13 +9628,11 @@ bool RasterizerGLES2::ShadowBuffer::init(int p_size,bool p_use_depth) {
GL_TEXTURE_2D, depth, 0);
// Allocate 16-bit depth buffer
- glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, size,size);
+ glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, size, size);
// Attach the render buffer as depth buffer - will be ignored
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
GL_RENDERBUFFER, rbo);
-
-
}
#if 0
@@ -10351,7 +9683,7 @@ bool RasterizerGLES2::ShadowBuffer::init(int p_size,bool p_use_depth) {
#endif
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
- //printf("errnum: %x\n",status);
+//printf("errnum: %x\n",status);
#ifdef GLEW_ENABLED
if (p_use_depth) {
//glDrawBuffer(GL_BACK);
@@ -10359,7 +9691,7 @@ bool RasterizerGLES2::ShadowBuffer::init(int p_size,bool p_use_depth) {
#endif
glBindFramebuffer(GL_FRAMEBUFFER, 0);
DEBUG_TEST_ERROR("Shadow Buffer Init");
- ERR_FAIL_COND_V( status != GL_FRAMEBUFFER_COMPLETE,false );
+ ERR_FAIL_COND_V(status != GL_FRAMEBUFFER_COMPLETE, false);
#ifdef GLEW_ENABLED
if (p_use_depth) {
@@ -10407,81 +9739,74 @@ bool RasterizerGLES2::ShadowBuffer::init(int p_size,bool p_use_depth) {
#endif
return true;
-
}
-
-
void RasterizerGLES2::_update_framebuffer() {
if (!use_framebuffers)
return;
- int scale = GLOBAL_DEF("rasterizer/framebuffer_shrink",1);
- if (scale<1)
- scale=1;
+ int scale = GLOBAL_DEF("rasterizer/framebuffer_shrink", 1);
+ if (scale < 1)
+ scale = 1;
- int dwidth = OS::get_singleton()->get_video_mode().width/scale;
- int dheight = OS::get_singleton()->get_video_mode().height/scale;
+ int dwidth = OS::get_singleton()->get_video_mode().width / scale;
+ int dheight = OS::get_singleton()->get_video_mode().height / scale;
- if (framebuffer.fbo && dwidth==framebuffer.width && dheight==framebuffer.height)
+ if (framebuffer.fbo && dwidth == framebuffer.width && dheight == framebuffer.height)
return;
+ bool use_fbo = true;
- bool use_fbo=true;
-
+ if (framebuffer.fbo != 0) {
- if (framebuffer.fbo!=0) {
-
- glDeleteFramebuffers(1,&framebuffer.fbo);
+ glDeleteFramebuffers(1, &framebuffer.fbo);
#if 0
glDeleteTextures(1,&framebuffer.depth);
#else
- glDeleteRenderbuffers(1,&framebuffer.depth);
+ glDeleteRenderbuffers(1, &framebuffer.depth);
#endif
- glDeleteTextures(1,&framebuffer.color);
-
- for(int i=0;i<framebuffer.luminance.size();i++) {
+ glDeleteTextures(1, &framebuffer.color);
- glDeleteTextures(1,&framebuffer.luminance[i].color);
- glDeleteFramebuffers(1,&framebuffer.luminance[i].fbo);
+ for (int i = 0; i < framebuffer.luminance.size(); i++) {
+ glDeleteTextures(1, &framebuffer.luminance[i].color);
+ glDeleteFramebuffers(1, &framebuffer.luminance[i].fbo);
}
- for(int i=0;i<3;i++) {
+ for (int i = 0; i < 3; i++) {
- glDeleteTextures(1,&framebuffer.blur[i].color);
- glDeleteFramebuffers(1,&framebuffer.blur[i].fbo);
+ glDeleteTextures(1, &framebuffer.blur[i].color);
+ glDeleteFramebuffers(1, &framebuffer.blur[i].fbo);
}
- glDeleteTextures(1,&framebuffer.sample_color);
- glDeleteFramebuffers(1,&framebuffer.sample_fbo);
+ glDeleteTextures(1, &framebuffer.sample_color);
+ glDeleteFramebuffers(1, &framebuffer.sample_fbo);
framebuffer.luminance.clear();
- framebuffer.blur_size=0;
- framebuffer.fbo=0;
+ framebuffer.blur_size = 0;
+ framebuffer.fbo = 0;
}
#ifdef TOOLS_ENABLED
- framebuffer.active=use_fbo;
+ framebuffer.active = use_fbo;
#else
- framebuffer.active=use_fbo && !low_memory_2d;
+ framebuffer.active = use_fbo && !low_memory_2d;
#endif
- framebuffer.width=dwidth;
- framebuffer.height=dheight;
- framebuffer.scale=scale;
+ framebuffer.width = dwidth;
+ framebuffer.height = dheight;
+ framebuffer.scale = scale;
if (!framebuffer.active)
return;
-
glGenFramebuffers(1, &framebuffer.fbo);
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.fbo);
- //print_line("generating fbo, id: "+itos(framebuffer.fbo));
- //depth
+//print_line("generating fbo, id: "+itos(framebuffer.fbo));
+//depth
- // Create a render buffer
+// Create a render buffer
#if 0
glGenTextures(1, &framebuffer.depth);
@@ -10495,9 +9820,9 @@ void RasterizerGLES2::_update_framebuffer() {
#else
glGenRenderbuffers(1, &framebuffer.depth);
- glBindRenderbuffer(GL_RENDERBUFFER, framebuffer.depth );
+ glBindRenderbuffer(GL_RENDERBUFFER, framebuffer.depth);
- glRenderbufferStorage(GL_RENDERBUFFER, use_depth24?_DEPTH_COMPONENT24_OES:GL_DEPTH_COMPONENT16, framebuffer.width,framebuffer.height);
+ glRenderbufferStorage(GL_RENDERBUFFER, use_depth24 ? _DEPTH_COMPONENT24_OES : GL_DEPTH_COMPONENT16, framebuffer.width, framebuffer.height);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, framebuffer.depth);
@@ -10506,28 +9831,25 @@ void RasterizerGLES2::_update_framebuffer() {
//GLuint format_rgba = use_fp16_fb?_GL_RGBA16F_EXT:GL_RGBA;
GLuint format_rgba = GL_RGBA;
- GLuint format_type = use_fp16_fb?_GL_HALF_FLOAT_OES:GL_UNSIGNED_BYTE;
- GLuint format_internal=GL_RGBA;
+ GLuint format_type = use_fp16_fb ? _GL_HALF_FLOAT_OES : GL_UNSIGNED_BYTE;
+ GLuint format_internal = GL_RGBA;
if (use_16bits_fbo) {
- format_type=GL_UNSIGNED_SHORT_5_6_5;
- format_rgba=GL_RGB;
- format_internal=GL_RGB;
+ format_type = GL_UNSIGNED_SHORT_5_6_5;
+ format_rgba = GL_RGB;
+ format_internal = GL_RGB;
}
/*GLuint format_luminance = use_fp16_fb?GL_RGB16F:GL_RGBA;
GLuint format_luminance_type = use_fp16_fb?(use_fu_GL_HALF_FLOAT_OES):GL_UNSIGNED_BYTE;
GLuint format_luminance_components = use_fp16_fb?GL_RGB:GL_RGBA;*/
- GLuint format_luminance = use_fp16_fb?_GL_RG_EXT:GL_RGBA;
- GLuint format_luminance_type = use_fp16_fb?(full_float_fb_supported?GL_FLOAT:_GL_HALF_FLOAT_OES):GL_UNSIGNED_BYTE;
- GLuint format_luminance_components = use_fp16_fb?_GL_RG_EXT:GL_RGBA;
-
-
-
+ GLuint format_luminance = use_fp16_fb ? _GL_RG_EXT : GL_RGBA;
+ GLuint format_luminance_type = use_fp16_fb ? (full_float_fb_supported ? GL_FLOAT : _GL_HALF_FLOAT_OES) : GL_UNSIGNED_BYTE;
+ GLuint format_luminance_components = use_fp16_fb ? _GL_RG_EXT : GL_RGBA;
glGenTextures(1, &framebuffer.color);
glBindTexture(GL_TEXTURE_2D, framebuffer.color);
- glTexImage2D(GL_TEXTURE_2D, 0, format_rgba, framebuffer.width, framebuffer.height, 0, format_internal, format_type, NULL);
+ glTexImage2D(GL_TEXTURE_2D, 0, format_rgba, framebuffer.width, framebuffer.height, 0, format_internal, format_type, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
@@ -10541,18 +9863,18 @@ void RasterizerGLES2::_update_framebuffer() {
if (status != GL_FRAMEBUFFER_COMPLETE) {
- glDeleteFramebuffers(1,&framebuffer.fbo);
+ glDeleteFramebuffers(1, &framebuffer.fbo);
#if 0
glDeleteTextures(1,&framebuffer.depth);
#else
- glDeleteRenderbuffers(1,&framebuffer.depth);
+ glDeleteRenderbuffers(1, &framebuffer.depth);
#endif
- glDeleteTextures(1,&framebuffer.color);
- framebuffer.fbo=0;
- framebuffer.active=false;
+ glDeleteTextures(1, &framebuffer.color);
+ framebuffer.fbo = 0;
+ framebuffer.active = false;
//print_line("**************** NO FAMEBUFFEEEERRRR????");
- WARN_PRINT(String("Could not create framebuffer!!, code: "+itos(status)).ascii().get_data());
+ WARN_PRINT(String("Could not create framebuffer!!, code: " + itos(status)).ascii().get_data());
}
//sample
@@ -10561,7 +9883,7 @@ void RasterizerGLES2::_update_framebuffer() {
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.sample_fbo);
glGenTextures(1, &framebuffer.sample_color);
glBindTexture(GL_TEXTURE_2D, framebuffer.sample_color);
- glTexImage2D(GL_TEXTURE_2D, 0, format_rgba, framebuffer.width, framebuffer.height, 0, format_internal, format_type, NULL);
+ glTexImage2D(GL_TEXTURE_2D, 0, format_rgba, framebuffer.width, framebuffer.height, 0, format_internal, format_type, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
@@ -10575,41 +9897,40 @@ void RasterizerGLES2::_update_framebuffer() {
if (status != GL_FRAMEBUFFER_COMPLETE) {
- glDeleteFramebuffers(1,&framebuffer.fbo);
+ glDeleteFramebuffers(1, &framebuffer.fbo);
#if 0
glDeleteTextures(1,&framebuffer.depth);
#else
- glDeleteRenderbuffers(1,&framebuffer.depth);
+ glDeleteRenderbuffers(1, &framebuffer.depth);
#endif
- glDeleteTextures(1,&framebuffer.color);
- glDeleteTextures(1,&framebuffer.sample_color);
- glDeleteFramebuffers(1,&framebuffer.sample_fbo);
- framebuffer.fbo=0;
- framebuffer.active=false;
+ glDeleteTextures(1, &framebuffer.color);
+ glDeleteTextures(1, &framebuffer.sample_color);
+ glDeleteFramebuffers(1, &framebuffer.sample_fbo);
+ framebuffer.fbo = 0;
+ framebuffer.active = false;
//print_line("**************** NO FAMEBUFFEEEERRRR????");
WARN_PRINT("Could not create framebuffer!!");
}
//blur
- int size = GLOBAL_DEF("rasterizer/blur_buffer_size",256);
+ int size = GLOBAL_DEF("rasterizer/blur_buffer_size", 256);
- if (size!=framebuffer.blur_size) {
+ if (size != framebuffer.blur_size) {
-
- for(int i=0;i<3;i++) {
+ for (int i = 0; i < 3; i++) {
if (framebuffer.blur[i].fbo) {
- glDeleteFramebuffers(1,&framebuffer.blur[i].fbo);
- glDeleteTextures(1,&framebuffer.blur[i].color);
- framebuffer.blur[i].fbo=0;
- framebuffer.blur[i].color=0;
+ glDeleteFramebuffers(1, &framebuffer.blur[i].fbo);
+ glDeleteTextures(1, &framebuffer.blur[i].color);
+ framebuffer.blur[i].fbo = 0;
+ framebuffer.blur[i].color = 0;
}
}
- framebuffer.blur_size=size;
+ framebuffer.blur_size = size;
- for(int i=0;i<3;i++) {
+ for (int i = 0; i < 3; i++) {
glGenFramebuffers(1, &framebuffer.blur[i].fbo);
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.blur[i].fbo);
@@ -10621,44 +9942,36 @@ void RasterizerGLES2::_update_framebuffer() {
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, format_rgba, size, size, 0,
- format_internal, format_type, NULL);
+ format_internal, format_type, NULL);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
- GL_TEXTURE_2D, framebuffer.blur[i].color, 0);
-
+ GL_TEXTURE_2D, framebuffer.blur[i].color, 0);
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
DEBUG_TEST_ERROR("Shadow Buffer Init");
- ERR_CONTINUE( status != GL_FRAMEBUFFER_COMPLETE );
-
-
+ ERR_CONTINUE(status != GL_FRAMEBUFFER_COMPLETE);
}
-
}
// luminance
- int base_size = GLOBAL_DEF("rasterizer/luminance_buffer_size",81);
-
- if (framebuffer.luminance.empty() || framebuffer.luminance[0].size!=base_size) {
+ int base_size = GLOBAL_DEF("rasterizer/luminance_buffer_size", 81);
+ if (framebuffer.luminance.empty() || framebuffer.luminance[0].size != base_size) {
- for(int i=0;i<framebuffer.luminance.size();i++) {
+ for (int i = 0; i < framebuffer.luminance.size(); i++) {
- glDeleteFramebuffers(1,&framebuffer.luminance[i].fbo);
- glDeleteTextures(1,&framebuffer.luminance[i].color);
+ glDeleteFramebuffers(1, &framebuffer.luminance[i].fbo);
+ glDeleteTextures(1, &framebuffer.luminance[i].color);
}
framebuffer.luminance.clear();
-
-
- while(base_size>0) {
+ while (base_size > 0) {
FrameBuffer::Luminance lb;
- lb.size=base_size;
-
+ lb.size = base_size;
glGenFramebuffers(1, &lb.fbo);
glBindFramebuffer(GL_FRAMEBUFFER, lb.fbo);
@@ -10670,32 +9983,27 @@ void RasterizerGLES2::_update_framebuffer() {
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, format_luminance, lb.size, lb.size, 0,
- format_luminance_components, format_luminance_type, NULL);
+ format_luminance_components, format_luminance_type, NULL);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
- GL_TEXTURE_2D, lb.color, 0);
-
+ GL_TEXTURE_2D, lb.color, 0);
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
- base_size/=3;
+ base_size /= 3;
DEBUG_TEST_ERROR("Shadow Buffer Init");
- ERR_CONTINUE( status != GL_FRAMEBUFFER_COMPLETE );
+ ERR_CONTINUE(status != GL_FRAMEBUFFER_COMPLETE);
framebuffer.luminance.push_back(lb);
-
}
}
-
-
-
}
void RasterizerGLES2::set_base_framebuffer(GLuint p_id, Vector2 p_size) {
- base_framebuffer=p_id;
+ base_framebuffer = p_id;
if (p_size.x != 0) {
window_size = p_size;
@@ -10755,11 +10063,9 @@ void RasterizerGLES2::_update_blur_buffer() {
}
#endif
-
bool RasterizerGLES2::_test_depth_shadow_buffer() {
-
- int size=16;
+ int size = 16;
GLuint fbo;
GLuint rbo;
@@ -10784,11 +10090,9 @@ bool RasterizerGLES2::_test_depth_shadow_buffer() {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
-
-
// We'll use a depth texture to store the depths in the shadow map
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, size, size, 0,
- GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL);
+ GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL);
#ifdef GLEW_ENABLED
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
@@ -10797,17 +10101,15 @@ bool RasterizerGLES2::_test_depth_shadow_buffer() {
// Attach the depth texture to FBO depth attachment point
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
- GL_TEXTURE_2D, depth, 0);
-
+ GL_TEXTURE_2D, depth, 0);
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
- glDeleteFramebuffers(1,&fbo);
- glDeleteRenderbuffers(1,&rbo);
- glDeleteTextures(1,&depth);
+ glDeleteFramebuffers(1, &fbo);
+ glDeleteRenderbuffers(1, &rbo);
+ glDeleteTextures(1, &depth);
return status == GL_FRAMEBUFFER_COMPLETE;
-
}
void RasterizerGLES2::init() {
@@ -10818,9 +10120,9 @@ void RasterizerGLES2::init() {
#ifdef GLEW_ENABLED
GLuint res = glewInit();
- ERR_FAIL_COND(res!=GLEW_OK);
+ ERR_FAIL_COND(res != GLEW_OK);
if (OS::get_singleton()->is_stdout_verbose()) {
- print_line(String("GLES2: Using GLEW ") + (const char*) glewGetString(GLEW_VERSION));
+ print_line(String("GLES2: Using GLEW ") + (const char *)glewGetString(GLEW_VERSION));
}
// Godot makes use of functions from ARB_framebuffer_object extension which is not implemented by all drivers.
@@ -10829,10 +10131,10 @@ void RasterizerGLES2::init() {
bool framebuffer_object_is_supported = glewIsSupported("GL_ARB_framebuffer_object");
- if ( !framebuffer_object_is_supported ) {
+ if (!framebuffer_object_is_supported) {
WARN_PRINT("GL_ARB_framebuffer_object not supported by your graphics card.");
- if ( glewIsSupported("GL_EXT_framebuffer_object") ) {
+ if (glewIsSupported("GL_EXT_framebuffer_object")) {
// falling-back to the older EXT function if present
WARN_PRINT("Falling-back to GL_EXT_framebuffer_object.");
@@ -10855,8 +10157,7 @@ void RasterizerGLES2::init() {
glGenerateMipmap = glGenerateMipmapEXT;
framebuffer_object_is_supported = true;
- }
- else {
+ } else {
ERR_PRINT("Framebuffer Object is not supported by your graphics card.");
}
}
@@ -10864,24 +10165,21 @@ void RasterizerGLES2::init() {
// Check for GL 2.1 compatibility, if not bail out
if (!(glewIsSupported("GL_VERSION_2_1") && framebuffer_object_is_supported)) {
ERR_PRINT("Your system's graphic drivers seem not to support OpenGL 2.1 / GLES 2.0, sorry :(\n"
- "Try a drivers update, buy a new GPU or try software rendering on Linux; Godot is now going to terminate.");
+ "Try a drivers update, buy a new GPU or try software rendering on Linux; Godot is now going to terminate.");
OS::get_singleton()->alert("Your system's graphic drivers seem not to support OpenGL 2.1 / GLES 2.0, sorry :(\n"
- "Godot Engine will self-destruct as soon as you acknowledge this error message.",
- "Fatal error: Insufficient OpenGL / GLES drivers");
+ "Godot Engine will self-destruct as soon as you acknowledge this error message.",
+ "Fatal error: Insufficient OpenGL / GLES drivers");
exit(1);
}
#endif
+ scene_pass = 1;
+ if (extensions.size() == 0) {
- scene_pass=1;
-
- if (extensions.size()==0) {
-
- set_extensions( (const char*)glGetString( GL_EXTENSIONS ));
+ set_extensions((const char *)glGetString(GL_EXTENSIONS));
}
-
GLint tmp = 0;
glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &tmp);
//print_line("GL_MAX_VERTEX_ATTRIBS "+itos(tmp));
@@ -10891,7 +10189,7 @@ void RasterizerGLES2::init() {
glFrontFace(GL_CW);
//glEnable(GL_TEXTURE_2D);
- default_material=create_default_material();
+ default_material = create_default_material();
material_shader.init();
canvas_shader.init();
@@ -10899,10 +10197,10 @@ void RasterizerGLES2::init() {
canvas_shadow_shader.init();
#ifdef GLEW_ENABLED
- material_shader.set_conditional(MaterialShaderGLES2::USE_GLES_OVER_GL,true);
- canvas_shader.set_conditional(CanvasShaderGLES2::USE_GLES_OVER_GL,true);
- canvas_shadow_shader.set_conditional(CanvasShadowShaderGLES2::USE_GLES_OVER_GL,true);
- copy_shader.set_conditional(CopyShaderGLES2::USE_GLES_OVER_GL,true);
+ material_shader.set_conditional(MaterialShaderGLES2::USE_GLES_OVER_GL, true);
+ canvas_shader.set_conditional(CanvasShaderGLES2::USE_GLES_OVER_GL, true);
+ canvas_shadow_shader.set_conditional(CanvasShadowShaderGLES2::USE_GLES_OVER_GL, true);
+ copy_shader.set_conditional(CopyShaderGLES2::USE_GLES_OVER_GL, true);
#endif
#ifdef ANGLE_ENABLED
@@ -10910,113 +10208,108 @@ void RasterizerGLES2::init() {
material_shader.set_conditional(MaterialShaderGLES2::DISABLE_FRONT_FACING, true);
#endif
+ shadow = NULL;
+ shadow_pass = 0;
- shadow=NULL;
- shadow_pass=0;
-
- framebuffer.fbo=0;
- framebuffer.width=0;
- framebuffer.height=0;
+ framebuffer.fbo = 0;
+ framebuffer.width = 0;
+ framebuffer.height = 0;
//framebuffer.buff16=false;
//framebuffer.blur[0].fbo=false;
//framebuffer.blur[1].fbo=false;
- framebuffer.active=false;
-
+ framebuffer.active = false;
//do a single initial clear
- glClearColor(0,0,0,1);
+ glClearColor(0, 0, 0, 1);
//glClearDepth(1.0);
- glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glGenTextures(1, &white_tex);
- unsigned char whitetexdata[8*8*3];
- for(int i=0;i<8*8*3;i++) {
- whitetexdata[i]=255;
+ unsigned char whitetexdata[8 * 8 * 3];
+ for (int i = 0; i < 8 * 8 * 3; i++) {
+ whitetexdata[i] = 255;
}
glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D,white_tex);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 8, 8, 0, GL_RGB, GL_UNSIGNED_BYTE,whitetexdata);
+ glBindTexture(GL_TEXTURE_2D, white_tex);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 8, 8, 0, GL_RGB, GL_UNSIGNED_BYTE, whitetexdata);
glGenerateMipmap(GL_TEXTURE_2D);
- glBindTexture(GL_TEXTURE_2D,0);
+ glBindTexture(GL_TEXTURE_2D, 0);
#ifdef GLEW_ENABLED
-
- pvr_supported=false;
- etc_supported=false;
- use_depth24 =true;
+ pvr_supported = false;
+ etc_supported = false;
+ use_depth24 = true;
s3tc_supported = true;
atitc_supported = false;
//use_texture_instancing=false;
//use_attribute_instancing=true;
- use_texture_instancing=false;
- use_attribute_instancing=true;
- full_float_fb_supported=true;
- srgb_supported=true;
- latc_supported=true;
- s3tc_srgb_supported=true;
- use_anisotropic_filter=true;
- float_linear_supported=true;
+ use_texture_instancing = false;
+ use_attribute_instancing = true;
+ full_float_fb_supported = true;
+ srgb_supported = true;
+ latc_supported = true;
+ s3tc_srgb_supported = true;
+ use_anisotropic_filter = true;
+ float_linear_supported = true;
GLint vtf;
- glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS,&vtf);
+ glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &vtf);
float_supported = extensions.has("GL_OES_texture_float") || extensions.has("GL_ARB_texture_float");
- use_hw_skeleton_xform=vtf>0 && float_supported;
+ use_hw_skeleton_xform = vtf > 0 && float_supported;
- read_depth_supported=_test_depth_shadow_buffer();
- use_rgba_shadowmaps=!read_depth_supported;
+ read_depth_supported = _test_depth_shadow_buffer();
+ use_rgba_shadowmaps = !read_depth_supported;
//print_line("read depth support? "+itos(read_depth_supported));
- glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT,&anisotropic_level);
- anisotropic_level=MIN(anisotropic_level,float(GLOBAL_DEF("rasterizer/anisotropic_filter_level",4.0)));
+ glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &anisotropic_level);
+ anisotropic_level = MIN(anisotropic_level, float(GLOBAL_DEF("rasterizer/anisotropic_filter_level", 4.0)));
#ifdef OSX_ENABLED
- use_rgba_shadowmaps=true;
- use_fp16_fb=false;
+ use_rgba_shadowmaps = true;
+ use_fp16_fb = false;
#else
#endif
- use_half_float=true;
+ use_half_float = true;
#else
- for (Set<String>::Element *E=extensions.front();E;E=E->next()) {
+ for (Set<String>::Element *E = extensions.front(); E; E = E->next()) {
print_line(E->get());
}
- read_depth_supported=extensions.has("GL_OES_depth_texture");
- use_rgba_shadowmaps=!read_depth_supported;
- if (shadow_filter>=SHADOW_FILTER_ESM && !extensions.has("GL_EXT_frag_depth")) {
- use_rgba_shadowmaps=true; //no other way, go back to rgba
+ read_depth_supported = extensions.has("GL_OES_depth_texture");
+ use_rgba_shadowmaps = !read_depth_supported;
+ if (shadow_filter >= SHADOW_FILTER_ESM && !extensions.has("GL_EXT_frag_depth")) {
+ use_rgba_shadowmaps = true; //no other way, go back to rgba
}
- pvr_supported=extensions.has("GL_IMG_texture_compression_pvrtc");
- pvr_srgb_supported=extensions.has("GL_EXT_pvrtc_sRGB");
- etc_supported=extensions.has("GL_OES_compressed_ETC1_RGB8_texture");
+ pvr_supported = extensions.has("GL_IMG_texture_compression_pvrtc");
+ pvr_srgb_supported = extensions.has("GL_EXT_pvrtc_sRGB");
+ etc_supported = extensions.has("GL_OES_compressed_ETC1_RGB8_texture");
use_depth24 = extensions.has("GL_OES_depth24");
s3tc_supported = extensions.has("GL_EXT_texture_compression_dxt1") || extensions.has("GL_EXT_texture_compression_s3tc") || extensions.has("WEBGL_compressed_texture_s3tc");
use_half_float = extensions.has("GL_OES_vertex_half_float");
- atitc_supported=extensions.has("GL_AMD_compressed_ATC_texture");
-
+ atitc_supported = extensions.has("GL_AMD_compressed_ATC_texture");
- srgb_supported=extensions.has("GL_EXT_sRGB");
+ srgb_supported = extensions.has("GL_EXT_sRGB");
#ifndef ANGLE_ENABLED
- s3tc_srgb_supported = s3tc_supported && extensions.has("GL_EXT_texture_compression_s3tc");
+ s3tc_srgb_supported = s3tc_supported && extensions.has("GL_EXT_texture_compression_s3tc");
#else
s3tc_srgb_supported = s3tc_supported;
#endif
latc_supported = extensions.has("GL_EXT_texture_compression_latc");
- anisotropic_level=1.0;
- use_anisotropic_filter=extensions.has("GL_EXT_texture_filter_anisotropic");
+ anisotropic_level = 1.0;
+ use_anisotropic_filter = extensions.has("GL_EXT_texture_filter_anisotropic");
if (use_anisotropic_filter) {
- glGetFloatv(_GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT,&anisotropic_level);
- anisotropic_level=MIN(anisotropic_level,float(GLOBAL_DEF("rasterizer/anisotropic_filter_level",4.0)));
+ glGetFloatv(_GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &anisotropic_level);
+ anisotropic_level = MIN(anisotropic_level, float(GLOBAL_DEF("rasterizer/anisotropic_filter_level", 4.0)));
}
-
- print_line("S3TC: "+itos(s3tc_supported)+" ATITC: "+itos(atitc_supported));
+ print_line("S3TC: " + itos(s3tc_supported) + " ATITC: " + itos(atitc_supported));
GLint vtf;
- glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS,&vtf);
+ glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &vtf);
float_supported = extensions.has("GL_OES_texture_float") || extensions.has("GL_ARB_texture_float");
- use_hw_skeleton_xform=vtf>0 && float_supported;
+ use_hw_skeleton_xform = vtf > 0 && float_supported;
float_linear_supported = extensions.has("GL_OES_texture_float_linear");
/*
@@ -11024,41 +10317,36 @@ void RasterizerGLES2::init() {
use_hw_skeleton_xform=false;
*/
GLint mva;
- glGetIntegerv(GL_MAX_VERTEX_ATTRIBS,&mva);
- if (vtf==0 && mva>8) {
+ glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &mva);
+ if (vtf == 0 && mva > 8) {
//tegra 3, mali 400
- use_attribute_instancing=true;
- use_texture_instancing=false;
- } else if (vtf>0 && extensions.has("GL_OES_texture_float")){
+ use_attribute_instancing = true;
+ use_texture_instancing = false;
+ } else if (vtf > 0 && extensions.has("GL_OES_texture_float")) {
//use_texture_instancing=true;
- use_texture_instancing=false; // i don't get it, uniforms are faster.
- use_attribute_instancing=false;
-
-
+ use_texture_instancing = false; // i don't get it, uniforms are faster.
+ use_attribute_instancing = false;
} else {
- use_texture_instancing=false;
- use_attribute_instancing=false;
+ use_texture_instancing = false;
+ use_attribute_instancing = false;
}
if (use_fp16_fb) {
- use_fp16_fb=extensions.has("GL_OES_texture_half_float") && extensions.has("GL_EXT_color_buffer_half_float") && extensions.has("GL_EXT_texture_rg");
+ use_fp16_fb = extensions.has("GL_OES_texture_half_float") && extensions.has("GL_EXT_color_buffer_half_float") && extensions.has("GL_EXT_texture_rg");
}
- full_float_fb_supported=extensions.has("GL_EXT_color_buffer_float");
+ full_float_fb_supported = extensions.has("GL_EXT_color_buffer_float");
-
- //etc_supported=false;
+//etc_supported=false;
#endif
//use_rgba_shadowmaps=true;
-
-
glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &max_texture_units);
- glGetIntegerv(GL_MAX_TEXTURE_SIZE,&max_texture_size);
+ glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size);
//read_depth_supported=false;
canvas_shadow_blur = canvas_light_shadow_buffer_create(max_texture_size);
@@ -11067,27 +10355,24 @@ void RasterizerGLES2::init() {
//shadowmaps
//don't use a shadowbuffer too big in GLES, this should be the maximum
- int max_shadow_size = GLOBAL_DEF("rasterizer/max_shadow_buffer_size",1024);
- int smsize=max_shadow_size;
- while(smsize>=16) {
+ int max_shadow_size = GLOBAL_DEF("rasterizer/max_shadow_buffer_size", 1024);
+ int smsize = max_shadow_size;
+ while (smsize >= 16) {
ShadowBuffer sb;
- bool s = sb.init(smsize,!use_rgba_shadowmaps);
+ bool s = sb.init(smsize, !use_rgba_shadowmaps);
if (s)
near_shadow_buffers.push_back(sb);
- smsize/=2;
+ smsize /= 2;
}
- blur_shadow_buffer.init(max_shadow_size,!use_rgba_shadowmaps);
-
+ blur_shadow_buffer.init(max_shadow_size, !use_rgba_shadowmaps);
//material_shader
- material_shader.set_conditional(MaterialShaderGLES2::USE_DEPTH_SHADOWS,!use_rgba_shadowmaps);
- canvas_shadow_shader.set_conditional(CanvasShadowShaderGLES2::USE_DEPTH_SHADOWS,!use_rgba_shadowmaps);
-
+ material_shader.set_conditional(MaterialShaderGLES2::USE_DEPTH_SHADOWS, !use_rgba_shadowmaps);
+ canvas_shadow_shader.set_conditional(CanvasShadowShaderGLES2::USE_DEPTH_SHADOWS, !use_rgba_shadowmaps);
}
-
shadow_material = material_create(); //empty with nothing
shadow_mat_ptr = material_owner.get(shadow_material);
@@ -11097,40 +10382,39 @@ void RasterizerGLES2::init() {
shadow_mat_double_sided_ptr->flags[VS::MATERIAL_FLAG_DOUBLE_SIDED] = true;
overdraw_material = create_overdraw_debug_material();
- copy_shader.set_conditional(CopyShaderGLES2::USE_8BIT_HDR,!use_fp16_fb);
- canvas_shader.set_conditional(CanvasShaderGLES2::USE_DEPTH_SHADOWS,read_depth_supported);
+ copy_shader.set_conditional(CopyShaderGLES2::USE_8BIT_HDR, !use_fp16_fb);
+ canvas_shader.set_conditional(CanvasShaderGLES2::USE_DEPTH_SHADOWS, read_depth_supported);
- canvas_shader.set_conditional(CanvasShaderGLES2::USE_PIXEL_SNAP,GLOBAL_DEF("display/use_2d_pixel_snap",false));
+ canvas_shader.set_conditional(CanvasShaderGLES2::USE_PIXEL_SNAP, GLOBAL_DEF("display/use_2d_pixel_snap", false));
- npo2_textures_available=true;
+ npo2_textures_available = true;
//fragment_lighting=false;
- _rinfo.texture_mem=0;
- current_env=NULL;
- current_rt=NULL;
- current_vd=NULL;
- current_debug=VS::SCENARIO_DEBUG_DISABLED;
- camera_ortho=false;
-
- glGenBuffers(1,&gui_quad_buffer);
- glBindBuffer(GL_ARRAY_BUFFER,gui_quad_buffer);
+ _rinfo.texture_mem = 0;
+ current_env = NULL;
+ current_rt = NULL;
+ current_vd = NULL;
+ current_debug = VS::SCENARIO_DEBUG_DISABLED;
+ camera_ortho = false;
+
+ glGenBuffers(1, &gui_quad_buffer);
+ glBindBuffer(GL_ARRAY_BUFFER, gui_quad_buffer);
#ifdef GLES_NO_CLIENT_ARRAYS //WebGL specific implementation.
- glBufferData(GL_ARRAY_BUFFER, 8 * MAX_POLYGON_VERTICES,NULL,GL_DYNAMIC_DRAW);
+ glBufferData(GL_ARRAY_BUFFER, 8 * MAX_POLYGON_VERTICES, NULL, GL_DYNAMIC_DRAW);
#else
- glBufferData(GL_ARRAY_BUFFER,128,NULL,GL_DYNAMIC_DRAW);
+ glBufferData(GL_ARRAY_BUFFER, 128, NULL, GL_DYNAMIC_DRAW);
#endif
- glBindBuffer(GL_ARRAY_BUFFER,0); //unbind
+ glBindBuffer(GL_ARRAY_BUFFER, 0); //unbind
-
-#ifdef GLES_NO_CLIENT_ARRAYS //webgl indices buffer
- glGenBuffers(1, &indices_buffer);
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indices_buffer);
- glBufferData(GL_ELEMENT_ARRAY_BUFFER, 16*1024, NULL, GL_DYNAMIC_DRAW);
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);// unbind
+#ifdef GLES_NO_CLIENT_ARRAYS //webgl indices buffer
+ glGenBuffers(1, &indices_buffer);
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indices_buffer);
+ glBufferData(GL_ELEMENT_ARRAY_BUFFER, 16 * 1024, NULL, GL_DYNAMIC_DRAW);
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); // unbind
#endif
- shader_time_rollback = GLOBAL_DEF("rasterizer/shader_time_rollback",300);
+ shader_time_rollback = GLOBAL_DEF("rasterizer/shader_time_rollback", 300);
- using_canvas_bg=false;
+ using_canvas_bg = false;
_update_framebuffer();
DEBUG_TEST_ERROR("Initializing");
}
@@ -11141,12 +10425,12 @@ void RasterizerGLES2::finish() {
free(shadow_material);
free(shadow_material_double_sided);
free(canvas_shadow_blur);
- free( overdraw_material );
+ free(overdraw_material);
}
int RasterizerGLES2::get_render_info(VS::RenderInfo p_info) {
- switch(p_info) {
+ switch (p_info) {
case VS::INFO_OBJECTS_IN_FRAME: {
@@ -11178,7 +10462,7 @@ int RasterizerGLES2::get_render_info(VS::RenderInfo p_info) {
} break;
case VS::INFO_VIDEO_MEM_USED: {
- return get_render_info(VS::INFO_TEXTURE_MEM_USED)+get_render_info(VS::INFO_VERTEX_MEM_USED);
+ return get_render_info(VS::INFO_TEXTURE_MEM_USED) + get_render_info(VS::INFO_VERTEX_MEM_USED);
} break;
case VS::INFO_TEXTURE_MEM_USED: {
@@ -11195,8 +10479,8 @@ int RasterizerGLES2::get_render_info(VS::RenderInfo p_info) {
void RasterizerGLES2::set_extensions(const char *p_strings) {
- Vector<String> strings = String(p_strings).split(" ",false);
- for(int i=0;i<strings.size();i++) {
+ Vector<String> strings = String(p_strings).split(" ", false);
+ for (int i = 0; i < strings.size(); i++) {
extensions.insert(strings[i]);
//print_line(strings[i]);
@@ -11210,96 +10494,88 @@ bool RasterizerGLES2::needs_to_draw_next_frame() const {
bool RasterizerGLES2::has_feature(VS::Features p_feature) const {
- switch( p_feature) {
+ switch (p_feature) {
case VS::FEATURE_SHADERS: return true;
case VS::FEATURE_NEEDS_RELOAD_HOOK: return use_reload_hooks;
default: return false;
}
}
-
void RasterizerGLES2::reload_vram() {
-
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glFrontFace(GL_CW);
-
-
//do a single initial clear
- glClearColor(0,0,0,1);
+ glClearColor(0, 0, 0, 1);
//glClearDepth(1.0);
- glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
-
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glGenTextures(1, &white_tex);
- unsigned char whitetexdata[8*8*3];
- for(int i=0;i<8*8*3;i++) {
- whitetexdata[i]=255;
+ unsigned char whitetexdata[8 * 8 * 3];
+ for (int i = 0; i < 8 * 8 * 3; i++) {
+ whitetexdata[i] = 255;
}
glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D,white_tex);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 8, 8, 0, GL_RGB, GL_UNSIGNED_BYTE,whitetexdata);
+ glBindTexture(GL_TEXTURE_2D, white_tex);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 8, 8, 0, GL_RGB, GL_UNSIGNED_BYTE, whitetexdata);
glGenerateMipmap(GL_TEXTURE_2D);
- glBindTexture(GL_TEXTURE_2D,0);
-
-
+ glBindTexture(GL_TEXTURE_2D, 0);
List<RID> textures;
texture_owner.get_owned_list(&textures);
- keep_copies=false;
- for(List<RID>::Element *E=textures.front();E;E=E->next()) {
+ keep_copies = false;
+ for (List<RID>::Element *E = textures.front(); E; E = E->next()) {
RID tid = E->get();
- Texture *t=texture_owner.get(tid);
+ Texture *t = texture_owner.get(tid);
ERR_CONTINUE(!t);
- t->tex_id=0;
- t->data_size=0;
+ t->tex_id = 0;
+ t->data_size = 0;
glGenTextures(1, &t->tex_id);
- t->active=false;
+ t->active = false;
if (t->render_target)
continue;
- texture_allocate(tid,t->width,t->height,t->format,t->flags);
- bool had_image=false;
- for(int i=0;i<6;i++) {
+ texture_allocate(tid, t->width, t->height, t->format, t->flags);
+ bool had_image = false;
+ for (int i = 0; i < 6; i++) {
if (!t->image[i].empty()) {
- texture_set_data(tid,t->image[i],VS::CubeMapSide(i));
- had_image=true;
+ texture_set_data(tid, t->image[i], VS::CubeMapSide(i));
+ had_image = true;
}
}
if (!had_image && t->reloader) {
Object *rl = ObjectDB::get_instance(t->reloader);
if (rl)
- rl->call(t->reloader_func,tid);
+ rl->call(t->reloader_func, tid);
}
}
- keep_copies=true;
+ keep_copies = true;
List<RID> render_targets;
render_target_owner.get_owned_list(&render_targets);
- for(List<RID>::Element *E=render_targets.front();E;E=E->next()) {
+ for (List<RID>::Element *E = render_targets.front(); E; E = E->next()) {
RenderTarget *rt = render_target_owner.get(E->get());
int w = rt->width;
int h = rt->height;
- rt->width=0;
- rt->height=0;
- render_target_set_size(E->get(),w,h);
+ rt->width = 0;
+ rt->height = 0;
+ render_target_set_size(E->get(), w, h);
}
-
List<RID> meshes;
mesh_owner.get_owned_list(&meshes);
- for(List<RID>::Element *E=meshes.front();E;E=E->next()) {
+ for (List<RID>::Element *E = meshes.front(); E; E = E->next()) {
Mesh *mesh = mesh_owner.get(E->get());
- Vector<Surface*> surfaces =mesh->surfaces;
+ Vector<Surface *> surfaces = mesh->surfaces;
mesh->surfaces.clear();
- for(int i=0;i<surfaces.size();i++) {
- mesh_add_surface(E->get(),surfaces[i]->primitive,surfaces[i]->data,surfaces[i]->morph_data,surfaces[i]->alpha_sort);
- mesh_surface_set_material(E->get(),i,surfaces[i]->material);
+ for (int i = 0; i < surfaces.size(); i++) {
+ mesh_add_surface(E->get(), surfaces[i]->primitive, surfaces[i]->data, surfaces[i]->morph_data, surfaces[i]->alpha_sort);
+ mesh_surface_set_material(E->get(), i, surfaces[i]->material);
if (surfaces[i]->array_local != 0) {
memfree(surfaces[i]->array_local);
@@ -11308,14 +10584,13 @@ void RasterizerGLES2::reload_vram() {
memfree(surfaces[i]->index_array_local);
};
- memdelete( surfaces[i] );
+ memdelete(surfaces[i]);
}
-
}
List<RID> skeletons;
skeleton_owner.get_owned_list(&skeletons);
- for(List<RID>::Element *E=skeletons.front();E;E=E->next()) {
+ for (List<RID>::Element *E = skeletons.front(); E; E = E->next()) {
Skeleton *sk = skeleton_owner.get(E->get());
if (!sk->tex_id)
@@ -11323,15 +10598,15 @@ void RasterizerGLES2::reload_vram() {
Vector<Skeleton::Bone> bones = sk->bones;
sk->bones.clear();
- sk->tex_id=0;
- sk->pixel_size=1.0;
- skeleton_resize(E->get(),bones.size());
- sk->bones=bones;
+ sk->tex_id = 0;
+ sk->pixel_size = 1.0;
+ skeleton_resize(E->get(), bones.size());
+ sk->bones = bones;
}
List<RID> multimeshes;
multimesh_owner.get_owned_list(&multimeshes);
- for(List<RID>::Element *E=multimeshes.front();E;E=E->next()) {
+ for (List<RID>::Element *E = multimeshes.front(); E; E = E->next()) {
MultiMesh *mm = multimesh_owner.get(E->get());
if (!mm->tex_id)
@@ -11340,162 +10615,147 @@ void RasterizerGLES2::reload_vram() {
Vector<MultiMesh::Element> elements = mm->elements;
mm->elements.clear();
- mm->tw=1;
- mm->th=1;
- mm->tex_id=0;
- mm->last_pass=0;
+ mm->tw = 1;
+ mm->th = 1;
+ mm->tex_id = 0;
+ mm->last_pass = 0;
mm->visible = -1;
- multimesh_set_instance_count(E->get(),elements.size());
- mm->elements=elements;
-
+ multimesh_set_instance_count(E->get(), elements.size());
+ mm->elements = elements;
}
+ if (framebuffer.fbo != 0) {
+ framebuffer.fbo = 0;
+ framebuffer.depth = 0;
+ framebuffer.color = 0;
-
- if (framebuffer.fbo!=0) {
-
- framebuffer.fbo=0;
- framebuffer.depth=0;
- framebuffer.color=0;
-
- for(int i=0;i<3;i++) {
- framebuffer.blur[i].fbo=0;
- framebuffer.blur[i].color=0;
+ for (int i = 0; i < 3; i++) {
+ framebuffer.blur[i].fbo = 0;
+ framebuffer.blur[i].color = 0;
}
framebuffer.luminance.clear();
-
}
- for(int i=0;i<near_shadow_buffers.size();i++) {
- near_shadow_buffers[i].init(near_shadow_buffers[i].size,!use_rgba_shadowmaps);
+ for (int i = 0; i < near_shadow_buffers.size(); i++) {
+ near_shadow_buffers[i].init(near_shadow_buffers[i].size, !use_rgba_shadowmaps);
}
- blur_shadow_buffer.init(near_shadow_buffers[0].size,!use_rgba_shadowmaps);
-
-
+ blur_shadow_buffer.init(near_shadow_buffers[0].size, !use_rgba_shadowmaps);
canvas_shader.clear_caches();
material_shader.clear_caches();
blur_shader.clear_caches();
copy_shader.clear_caches();
-
List<RID> shaders;
shader_owner.get_owned_list(&shaders);
- for(List<RID>::Element *E=shaders.front();E;E=E->next()) {
+ for (List<RID>::Element *E = shaders.front(); E; E = E->next()) {
Shader *s = shader_owner.get(E->get());
- s->custom_code_id=0;
- s->version=1;
- s->valid=false;
- shader_set_mode(E->get(),s->mode);
-
+ s->custom_code_id = 0;
+ s->version = 1;
+ s->valid = false;
+ shader_set_mode(E->get(), s->mode);
}
List<RID> materials;
material_owner.get_owned_list(&materials);
- for(List<RID>::Element *E=materials.front();E;E=E->next()) {
-
+ for (List<RID>::Element *E = materials.front(); E; E = E->next()) {
Material *m = material_owner.get(E->get());
RID shader = m->shader;
- m->shader_version=0;
- material_set_shader(E->get(),shader);
-
+ m->shader_version = 0;
+ material_set_shader(E->get(), shader);
}
-
-
-
}
void RasterizerGLES2::set_use_framebuffers(bool p_use) {
- use_framebuffers=p_use;
+ use_framebuffers = p_use;
}
-RasterizerGLES2* RasterizerGLES2::get_singleton() {
+RasterizerGLES2 *RasterizerGLES2::get_singleton() {
return _singleton;
};
-int RasterizerGLES2::RenderList::max_elements=RenderList::DEFAULT_MAX_ELEMENTS;
+int RasterizerGLES2::RenderList::max_elements = RenderList::DEFAULT_MAX_ELEMENTS;
void RasterizerGLES2::set_force_16_bits_fbo(bool p_force) {
- use_16bits_fbo=p_force;
+ use_16bits_fbo = p_force;
}
-RasterizerGLES2::RasterizerGLES2(bool p_compress_arrays,bool p_keep_ram_copy,bool p_default_fragment_lighting,bool p_use_reload_hooks) {
+RasterizerGLES2::RasterizerGLES2(bool p_compress_arrays, bool p_keep_ram_copy, bool p_default_fragment_lighting, bool p_use_reload_hooks) {
_singleton = this;
- shrink_textures_x2=false;
- RenderList::max_elements=GLOBAL_DEF("rasterizer/max_render_elements",(int)RenderList::DEFAULT_MAX_ELEMENTS);
- if (RenderList::max_elements>64000)
- RenderList::max_elements=64000;
- if (RenderList::max_elements<1024)
- RenderList::max_elements=1024;
+ shrink_textures_x2 = false;
+ RenderList::max_elements = GLOBAL_DEF("rasterizer/max_render_elements", (int)RenderList::DEFAULT_MAX_ELEMENTS);
+ if (RenderList::max_elements > 64000)
+ RenderList::max_elements = 64000;
+ if (RenderList::max_elements < 1024)
+ RenderList::max_elements = 1024;
opaque_render_list.init();
alpha_render_list.init();
- skinned_buffer_size = GLOBAL_DEF("rasterizer/skeleton_buffer_size_kb",DEFAULT_SKINNED_BUFFER_SIZE);
- if (skinned_buffer_size<256)
- skinned_buffer_size=256;
- if (skinned_buffer_size>16384)
- skinned_buffer_size=16384;
- skinned_buffer_size*=1024;
- skinned_buffer = memnew_arr( uint8_t, skinned_buffer_size );
-
- keep_copies=p_keep_ram_copy;
- use_reload_hooks=p_use_reload_hooks;
- pack_arrays=p_compress_arrays;
- p_default_fragment_lighting=false;
- fragment_lighting=GLOBAL_DEF("rasterizer/use_fragment_lighting",true);
- read_depth_supported=true; //todo check for extension
- shadow_filter=ShadowFilterTechnique((int)(GLOBAL_DEF("rasterizer/shadow_filter",SHADOW_FILTER_PCF5)));
- GlobalConfig::get_singleton()->set_custom_property_info("rasterizer/shadow_filter",PropertyInfo(Variant::INT,"rasterizer/shadow_filter",PROPERTY_HINT_ENUM,"None,PCF5,PCF13,ESM"));
- use_fp16_fb=bool(GLOBAL_DEF("rasterizer/fp16_framebuffer",true));
- use_shadow_mapping=true;
- use_fast_texture_filter=!bool(GLOBAL_DEF("rasterizer/trilinear_mipmap_filter",true));
- low_memory_2d=bool(GLOBAL_DEF("rasterizer/low_memory_2d_mode",false));
- skel_default.resize(1024*4);
- for(int i=0;i<1024/3;i++) {
-
- float * ptr = skel_default.ptr();
- ptr+=i*4*4;
- ptr[0]=1.0;
- ptr[1]=0.0;
- ptr[2]=0.0;
- ptr[3]=0.0;
-
- ptr[4]=0.0;
- ptr[5]=1.0;
- ptr[6]=0.0;
- ptr[7]=0.0;
-
- ptr[8]=0.0;
- ptr[9]=0.0;
- ptr[10]=1.0;
- ptr[12]=0.0;
- }
-
- base_framebuffer=0;
+ skinned_buffer_size = GLOBAL_DEF("rasterizer/skeleton_buffer_size_kb", DEFAULT_SKINNED_BUFFER_SIZE);
+ if (skinned_buffer_size < 256)
+ skinned_buffer_size = 256;
+ if (skinned_buffer_size > 16384)
+ skinned_buffer_size = 16384;
+ skinned_buffer_size *= 1024;
+ skinned_buffer = memnew_arr(uint8_t, skinned_buffer_size);
+
+ keep_copies = p_keep_ram_copy;
+ use_reload_hooks = p_use_reload_hooks;
+ pack_arrays = p_compress_arrays;
+ p_default_fragment_lighting = false;
+ fragment_lighting = GLOBAL_DEF("rasterizer/use_fragment_lighting", true);
+ read_depth_supported = true; //todo check for extension
+ shadow_filter = ShadowFilterTechnique((int)(GLOBAL_DEF("rasterizer/shadow_filter", SHADOW_FILTER_PCF5)));
+ GlobalConfig::get_singleton()->set_custom_property_info("rasterizer/shadow_filter", PropertyInfo(Variant::INT, "rasterizer/shadow_filter", PROPERTY_HINT_ENUM, "None,PCF5,PCF13,ESM"));
+ use_fp16_fb = bool(GLOBAL_DEF("rasterizer/fp16_framebuffer", true));
+ use_shadow_mapping = true;
+ use_fast_texture_filter = !bool(GLOBAL_DEF("rasterizer/trilinear_mipmap_filter", true));
+ low_memory_2d = bool(GLOBAL_DEF("rasterizer/low_memory_2d_mode", false));
+ skel_default.resize(1024 * 4);
+ for (int i = 0; i < 1024 / 3; i++) {
+
+ float *ptr = skel_default.ptr();
+ ptr += i * 4 * 4;
+ ptr[0] = 1.0;
+ ptr[1] = 0.0;
+ ptr[2] = 0.0;
+ ptr[3] = 0.0;
+
+ ptr[4] = 0.0;
+ ptr[5] = 1.0;
+ ptr[6] = 0.0;
+ ptr[7] = 0.0;
+
+ ptr[8] = 0.0;
+ ptr[9] = 0.0;
+ ptr[10] = 1.0;
+ ptr[12] = 0.0;
+ }
+
+ base_framebuffer = 0;
frame = 0;
- draw_next_frame=false;
- use_framebuffers=true;
- framebuffer.active=false;
- tc0_id_cache=0;
- tc0_idx=0;
- use_16bits_fbo=false;
+ draw_next_frame = false;
+ use_framebuffers = true;
+ framebuffer.active = false;
+ tc0_id_cache = 0;
+ tc0_idx = 0;
+ use_16bits_fbo = false;
};
void RasterizerGLES2::restore_framebuffer() {
glBindFramebuffer(GL_FRAMEBUFFER, base_framebuffer);
-
}
RasterizerGLES2::~RasterizerGLES2() {
@@ -11503,5 +10763,4 @@ RasterizerGLES2::~RasterizerGLES2() {
memdelete_arr(skinned_buffer);
};
-
#endif
diff --git a/drivers/gles2/rasterizer_gles2.h b/drivers/gles2/rasterizer_gles2.h
index ddcd97ec4a..81e137dffd 100644
--- a/drivers/gles2/rasterizer_gles2.h
+++ b/drivers/gles2/rasterizer_gles2.h
@@ -35,14 +35,14 @@
#ifdef GLES2_ENABLED
+#include "camera_matrix.h"
#include "image.h"
-#include "rid.h"
-#include "servers/visual_server.h"
#include "list.h"
#include "map.h"
-#include "camera_matrix.h"
-#include "sort.h"
+#include "rid.h"
#include "self_list.h"
+#include "servers/visual_server.h"
+#include "sort.h"
#include "platform_config.h"
#ifndef GLES2_INCLUDE_H
@@ -51,12 +51,12 @@
#include GLES2_INCLUDE_H
#endif
-#include "drivers/gles2/shaders/material.glsl.h"
+#include "drivers/gles2/shader_compiler_gles2.h"
+#include "drivers/gles2/shaders/blur.glsl.h"
#include "drivers/gles2/shaders/canvas.glsl.h"
#include "drivers/gles2/shaders/canvas_shadow.glsl.h"
-#include "drivers/gles2/shaders/blur.glsl.h"
#include "drivers/gles2/shaders/copy.glsl.h"
-#include "drivers/gles2/shader_compiler_gles2.h"
+#include "drivers/gles2/shaders/material.glsl.h"
#include "servers/visual/particle_system_sw.h"
/**
@@ -66,13 +66,12 @@ class RasterizerGLES2 : public Rasterizer {
enum {
- MAX_SCENE_LIGHTS=2048,
- LIGHT_SPOT_BIT=0x80,
+ MAX_SCENE_LIGHTS = 2048,
+ LIGHT_SPOT_BIT = 0x80,
DEFAULT_SKINNED_BUFFER_SIZE = 2048, // 10k vertices
MAX_HW_LIGHTS = 1,
};
-
uint8_t *skinned_buffer;
int skinned_buffer_size;
bool pvr_supported;
@@ -112,7 +111,7 @@ class RasterizerGLES2 : public Rasterizer {
Vector<float> skel_default;
- Image _get_gl_image_and_format(const Image& p_image, Image::Format p_format, uint32_t p_flags,GLenum& r_gl_format,GLenum& r_gl_internal_format,int &r_gl_components,bool &r_has_alpha_cache,bool &r_compressed);
+ Image _get_gl_image_and_format(const Image &p_image, Image::Format p_format, uint32_t p_flags, GLenum &r_gl_format, GLenum &r_gl_internal_format, int &r_gl_components, bool &r_has_alpha_cache, bool &r_compressed);
struct RenderTarget;
@@ -120,7 +119,7 @@ class RasterizerGLES2 : public Rasterizer {
String path;
uint32_t flags;
- int width,height;
+ int width, height;
int alloc_width, alloc_height;
Image::Format format;
@@ -149,30 +148,30 @@ class RasterizerGLES2 : public Rasterizer {
Texture() {
- ignore_mipmaps=false;
- render_target=NULL;
- flags=width=height=0;
- tex_id=0;
- data_size=0;
- format=Image::FORMAT_L8;
- gl_components_cache=0;
- format_has_alpha=false;
- has_alpha=false;
- active=false;
- disallow_mipmaps=false;
- compressed=false;
- total_data_size=0;
- target=GL_TEXTURE_2D;
- mipmaps=0;
-
- reloader=0;
+ ignore_mipmaps = false;
+ render_target = NULL;
+ flags = width = height = 0;
+ tex_id = 0;
+ data_size = 0;
+ format = Image::FORMAT_L8;
+ gl_components_cache = 0;
+ format_has_alpha = false;
+ has_alpha = false;
+ active = false;
+ disallow_mipmaps = false;
+ compressed = false;
+ total_data_size = 0;
+ target = GL_TEXTURE_2D;
+ mipmaps = 0;
+
+ reloader = 0;
}
~Texture() {
- if (tex_id!=0) {
+ if (tex_id != 0) {
- glDeleteTextures(1,&tex_id);
+ glDeleteTextures(1, &tex_id);
}
}
};
@@ -192,7 +191,6 @@ class RasterizerGLES2 : public Rasterizer {
uint32_t custom_code_id;
uint32_t version;
-
bool valid;
bool has_alpha;
bool can_zpass;
@@ -204,38 +202,37 @@ class RasterizerGLES2 : public Rasterizer {
bool uses_normal;
bool uses_texpixel_size;
- Map<StringName,ShaderLanguage::Uniform> uniforms;
+ Map<StringName, ShaderLanguage::Uniform> uniforms;
StringName first_texture;
- Map<StringName,RID> default_textures;
+ Map<StringName, RID> default_textures;
SelfList<Shader> dirty_list;
- Shader() : dirty_list(this) {
-
- valid=false;
- custom_code_id=0;
- has_alpha=false;
- version=1;
- vertex_line=0;
- fragment_line=0;
- light_line=0;
- can_zpass=true;
- has_texscreen=false;
- has_screen_uv=false;
- writes_vertex=false;
- uses_discard=false;
- uses_time=false;
- uses_normal=false;
+ Shader()
+ : dirty_list(this) {
+
+ valid = false;
+ custom_code_id = 0;
+ has_alpha = false;
+ version = 1;
+ vertex_line = 0;
+ fragment_line = 0;
+ light_line = 0;
+ can_zpass = true;
+ has_texscreen = false;
+ has_screen_uv = false;
+ writes_vertex = false;
+ uses_discard = false;
+ uses_time = false;
+ uses_normal = false;
}
-
-
};
mutable RID_Owner<Shader> shader_owner;
mutable SelfList<Shader>::List _shader_dirty_list;
- _FORCE_INLINE_ void _shader_make_dirty(Shader* p_shader);
- void _update_shader( Shader* p_shader) const;
+ _FORCE_INLINE_ void _shader_make_dirty(Shader *p_shader);
+ void _update_shader(Shader *p_shader) const;
struct Material {
@@ -256,37 +253,33 @@ class RasterizerGLES2 : public Rasterizer {
bool inuse;
bool istexture;
- Variant value;
+ Variant value;
int index;
};
- mutable Map<StringName,UniformData> shader_params;
+ mutable Map<StringName, UniformData> shader_params;
uint64_t last_pass;
-
Material() {
- for(int i=0;i<VS::MATERIAL_FLAG_MAX;i++)
- flags[i]=false;
- flags[VS::MATERIAL_FLAG_VISIBLE]=true;
+ for (int i = 0; i < VS::MATERIAL_FLAG_MAX; i++)
+ flags[i] = false;
+ flags[VS::MATERIAL_FLAG_VISIBLE] = true;
- line_width=1;
- has_alpha=false;
- depth_draw_mode=VS::MATERIAL_DEPTH_DRAW_OPAQUE_ONLY;
- blend_mode=VS::MATERIAL_BLEND_MODE_MIX;
+ line_width = 1;
+ has_alpha = false;
+ depth_draw_mode = VS::MATERIAL_DEPTH_DRAW_OPAQUE_ONLY;
+ blend_mode = VS::MATERIAL_BLEND_MODE_MIX;
last_pass = 0;
- shader_version=0;
- shader_cache=NULL;
-
+ shader_version = 0;
+ shader_cache = NULL;
}
};
_FORCE_INLINE_ void _update_material_shader_params(Material *p_material) const;
mutable RID_Owner<Material> material_owner;
-
-
struct Geometry {
enum Type {
@@ -302,8 +295,11 @@ class RasterizerGLES2 : public Rasterizer {
bool has_alpha;
bool material_owned;
- Geometry() { has_alpha=false; material_owned = false; }
- virtual ~Geometry() {};
+ Geometry() {
+ has_alpha = false;
+ material_owned = false;
+ }
+ virtual ~Geometry(){};
};
struct GeometryOwner {
@@ -317,11 +313,18 @@ class RasterizerGLES2 : public Rasterizer {
struct ArrayData {
- uint32_t ofs,size,datatype,count;
+ uint32_t ofs, size, datatype, count;
bool normalize;
bool bind;
- ArrayData() { ofs=0; size=0; count=0; datatype=0; normalize=0; bind=false;}
+ ArrayData() {
+ ofs = 0;
+ size = 0;
+ count = 0;
+ datatype = 0;
+ normalize = 0;
+ bind = false;
+ }
};
Mesh *mesh;
@@ -347,7 +350,7 @@ class RasterizerGLES2 : public Rasterizer {
uint8_t *array;
};
- MorphTarget* morph_targets_local;
+ MorphTarget *morph_targets_local;
int morph_target_count;
AABB aabb;
@@ -377,64 +380,60 @@ class RasterizerGLES2 : public Rasterizer {
Surface() {
+ array_len = 0;
+ local_stride = 0;
+ morph_format = 0;
+ type = GEOMETRY_SURFACE;
+ primitive = VS::PRIMITIVE_POINTS;
+ index_array_len = 0;
+ vertex_scale = 1.0;
+ uv_scale = 1.0;
+ uv2_scale = 1.0;
- array_len=0;
- local_stride=0;
- morph_format=0;
- type=GEOMETRY_SURFACE;
- primitive=VS::PRIMITIVE_POINTS;
- index_array_len=0;
- vertex_scale=1.0;
- uv_scale=1.0;
- uv2_scale=1.0;
+ alpha_sort = false;
- alpha_sort=false;
-
- format=0;
- stride=0;
- morph_targets_local=0;
- morph_target_count=0;
+ format = 0;
+ stride = 0;
+ morph_targets_local = 0;
+ morph_target_count = 0;
array_local = index_array_local = 0;
vertex_id = index_id = 0;
- active=false;
+ active = false;
//packed=false;
}
~Surface() {
-
}
};
-
struct Mesh {
bool active;
- Vector<Surface*> surfaces;
+ Vector<Surface *> surfaces;
int morph_target_count;
VS::MorphTargetMode morph_target_mode;
AABB custom_aabb;
mutable uint64_t last_pass;
Mesh() {
- morph_target_mode=VS::MORPH_MODE_NORMALIZED;
- morph_target_count=0;
- last_pass=0;
- active=false;
+ morph_target_mode = VS::MORPH_MODE_NORMALIZED;
+ morph_target_count = 0;
+ last_pass = 0;
+ active = false;
}
};
mutable RID_Owner<Mesh> mesh_owner;
- Error _surface_set_arrays(Surface *p_surface, uint8_t *p_mem,uint8_t *p_index_mem,const Array& p_arrays,bool p_main);
-
+ Error _surface_set_arrays(Surface *p_surface, uint8_t *p_mem, uint8_t *p_index_mem, const Array &p_arrays, bool p_main);
struct MultiMesh;
struct MultiMeshSurface : public Geometry {
Surface *surface;
- MultiMeshSurface() { type=GEOMETRY_MULTISURFACE; }
+ MultiMeshSurface() { type = GEOMETRY_MULTISURFACE; }
};
struct MultiMesh : public GeometryOwner {
@@ -444,28 +443,26 @@ class RasterizerGLES2 : public Rasterizer {
float matrix[16];
uint8_t color[4];
Element() {
- matrix[0]=1;
- matrix[1]=0;
- matrix[2]=0;
- matrix[3]=0;
-
- matrix[4]=0;
- matrix[5]=1;
- matrix[6]=0;
- matrix[7]=0;
-
- matrix[8]=0;
- matrix[9]=0;
- matrix[10]=1;
- matrix[11]=0;
-
- matrix[12]=0;
- matrix[13]=0;
- matrix[14]=0;
- matrix[15]=1;
+ matrix[0] = 1;
+ matrix[1] = 0;
+ matrix[2] = 0;
+ matrix[3] = 0;
+
+ matrix[4] = 0;
+ matrix[5] = 1;
+ matrix[6] = 0;
+ matrix[7] = 0;
+
+ matrix[8] = 0;
+ matrix[9] = 0;
+ matrix[10] = 1;
+ matrix[11] = 0;
+
+ matrix[12] = 0;
+ matrix[13] = 0;
+ matrix[14] = 0;
+ matrix[15] = 1;
};
-
-
};
AABB aabb;
@@ -482,12 +479,13 @@ class RasterizerGLES2 : public Rasterizer {
SelfList<MultiMesh> dirty_list;
- MultiMesh() : dirty_list(this) {
+ MultiMesh()
+ : dirty_list(this) {
- tw=1;
- th=1;
- tex_id=0;
- last_pass=0;
+ tw = 1;
+ th = 1;
+ tex_id = 0;
+ last_pass = 0;
visible = -1;
}
};
@@ -514,8 +512,10 @@ class RasterizerGLES2 : public Rasterizer {
int mask;
AABB aabb;
- Immediate() { type=GEOMETRY_IMMEDIATE; building=false;}
-
+ Immediate() {
+ type = GEOMETRY_IMMEDIATE;
+ building = false;
+ }
};
mutable RID_Owner<Immediate> immediate_owner;
@@ -525,8 +525,7 @@ class RasterizerGLES2 : public Rasterizer {
ParticleSystemSW data; // software particle system
Particles() {
- type=GEOMETRY_PARTICLES;
-
+ type = GEOMETRY_PARTICLES;
}
};
@@ -539,7 +538,7 @@ class RasterizerGLES2 : public Rasterizer {
ParticleSystemProcessSW particles_process;
Transform transform;
- ParticlesInstance() { }
+ ParticlesInstance() {}
};
mutable RID_Owner<ParticlesInstance> particles_instance_owner;
@@ -552,58 +551,52 @@ class RasterizerGLES2 : public Rasterizer {
float mtx[4][4]; //used
Bone() {
- for(int i=0;i<4;i++) {
- for(int j=0;j<4;j++) {
-
- mtx[i][j]=(i==j)?1:0;
+ for (int i = 0; i < 4; i++) {
+ for (int j = 0; j < 4; j++) {
+ mtx[i][j] = (i == j) ? 1 : 0;
}
}
-
}
- _ALWAYS_INLINE_ void transform_add_mul3(const float * p_src, float* r_dst, float p_weight) const {
+ _ALWAYS_INLINE_ void transform_add_mul3(const float *p_src, float *r_dst, float p_weight) const {
- r_dst[0]+=((mtx[0][0]*p_src[0] ) + ( mtx[1][0]*p_src[1] ) + ( mtx[2][0]*p_src[2] ) + mtx[3][0])*p_weight;
- r_dst[1]+=((mtx[0][1]*p_src[0] ) + ( mtx[1][1]*p_src[1] ) + ( mtx[2][1]*p_src[2] ) + mtx[3][1])*p_weight;
- r_dst[2]+=((mtx[0][2]*p_src[0] ) + ( mtx[1][2]*p_src[1] ) + ( mtx[2][2]*p_src[2] ) + mtx[3][2])*p_weight;
+ r_dst[0] += ((mtx[0][0] * p_src[0]) + (mtx[1][0] * p_src[1]) + (mtx[2][0] * p_src[2]) + mtx[3][0]) * p_weight;
+ r_dst[1] += ((mtx[0][1] * p_src[0]) + (mtx[1][1] * p_src[1]) + (mtx[2][1] * p_src[2]) + mtx[3][1]) * p_weight;
+ r_dst[2] += ((mtx[0][2] * p_src[0]) + (mtx[1][2] * p_src[1]) + (mtx[2][2] * p_src[2]) + mtx[3][2]) * p_weight;
}
- _ALWAYS_INLINE_ void transform3_add_mul3(const float * p_src, float* r_dst, float p_weight) const {
+ _ALWAYS_INLINE_ void transform3_add_mul3(const float *p_src, float *r_dst, float p_weight) const {
- r_dst[0]+=((mtx[0][0]*p_src[0] ) + ( mtx[1][0]*p_src[1] ) + ( mtx[2][0]*p_src[2] ) )*p_weight;
- r_dst[1]+=((mtx[0][1]*p_src[0] ) + ( mtx[1][1]*p_src[1] ) + ( mtx[2][1]*p_src[2] ) )*p_weight;
- r_dst[2]+=((mtx[0][2]*p_src[0] ) + ( mtx[1][2]*p_src[1] ) + ( mtx[2][2]*p_src[2] ) )*p_weight;
+ r_dst[0] += ((mtx[0][0] * p_src[0]) + (mtx[1][0] * p_src[1]) + (mtx[2][0] * p_src[2])) * p_weight;
+ r_dst[1] += ((mtx[0][1] * p_src[0]) + (mtx[1][1] * p_src[1]) + (mtx[2][1] * p_src[2])) * p_weight;
+ r_dst[2] += ((mtx[0][2] * p_src[0]) + (mtx[1][2] * p_src[1]) + (mtx[2][2] * p_src[2])) * p_weight;
}
- _ALWAYS_INLINE_ AABB transform_aabb(const AABB& p_aabb) const {
-
- float vertices[8][3]={
- {p_aabb.pos.x+p_aabb.size.x, p_aabb.pos.y+p_aabb.size.y, p_aabb.pos.z+p_aabb.size.z},
- {p_aabb.pos.x+p_aabb.size.x, p_aabb.pos.y+p_aabb.size.y, p_aabb.pos.z},
- {p_aabb.pos.x+p_aabb.size.x, p_aabb.pos.y, p_aabb.pos.z+p_aabb.size.z},
- {p_aabb.pos.x+p_aabb.size.x, p_aabb.pos.y, p_aabb.pos.z},
- {p_aabb.pos.x, p_aabb.pos.y+p_aabb.size.y, p_aabb.pos.z+p_aabb.size.z},
- {p_aabb.pos.x, p_aabb.pos.y+p_aabb.size.y, p_aabb.pos.z},
- {p_aabb.pos.x, p_aabb.pos.y, p_aabb.pos.z+p_aabb.size.z},
- {p_aabb.pos.x, p_aabb.pos.y, p_aabb.pos.z}
+ _ALWAYS_INLINE_ AABB transform_aabb(const AABB &p_aabb) const {
+
+ float vertices[8][3] = {
+ { p_aabb.pos.x + p_aabb.size.x, p_aabb.pos.y + p_aabb.size.y, p_aabb.pos.z + p_aabb.size.z },
+ { p_aabb.pos.x + p_aabb.size.x, p_aabb.pos.y + p_aabb.size.y, p_aabb.pos.z },
+ { p_aabb.pos.x + p_aabb.size.x, p_aabb.pos.y, p_aabb.pos.z + p_aabb.size.z },
+ { p_aabb.pos.x + p_aabb.size.x, p_aabb.pos.y, p_aabb.pos.z },
+ { p_aabb.pos.x, p_aabb.pos.y + p_aabb.size.y, p_aabb.pos.z + p_aabb.size.z },
+ { p_aabb.pos.x, p_aabb.pos.y + p_aabb.size.y, p_aabb.pos.z },
+ { p_aabb.pos.x, p_aabb.pos.y, p_aabb.pos.z + p_aabb.size.z },
+ { p_aabb.pos.x, p_aabb.pos.y, p_aabb.pos.z }
};
-
AABB ret;
-
-
- for (int i=0;i<8;i++) {
+ for (int i = 0; i < 8; i++) {
Vector3 xv(
- ((mtx[0][0]*vertices[i][0] ) + ( mtx[1][0]*vertices[i][1] ) + ( mtx[2][0]*vertices[i][2] ) + mtx[3][0] ),
- ((mtx[0][1]*vertices[i][0] ) + ( mtx[1][1]*vertices[i][1] ) + ( mtx[2][1]*vertices[i][2] ) + mtx[3][1] ),
- ((mtx[0][2]*vertices[i][0] ) + ( mtx[1][2]*vertices[i][1] ) + ( mtx[2][2]*vertices[i][2] ) + mtx[3][2] )
- );
+ ((mtx[0][0] * vertices[i][0]) + (mtx[1][0] * vertices[i][1]) + (mtx[2][0] * vertices[i][2]) + mtx[3][0]),
+ ((mtx[0][1] * vertices[i][0]) + (mtx[1][1] * vertices[i][1]) + (mtx[2][1] * vertices[i][2]) + mtx[3][1]),
+ ((mtx[0][2] * vertices[i][0]) + (mtx[1][2] * vertices[i][1]) + (mtx[2][2] * vertices[i][2]) + mtx[3][2]));
- if (i==0)
- ret.pos=xv;
+ if (i == 0)
+ ret.pos = xv;
else
ret.expand_to(xv);
}
@@ -618,16 +611,18 @@ class RasterizerGLES2 : public Rasterizer {
SelfList<Skeleton> dirty_list;
- Skeleton() : dirty_list(this) { tex_id=0; pixel_size=1.0; }
-
+ Skeleton()
+ : dirty_list(this) {
+ tex_id = 0;
+ pixel_size = 1.0;
+ }
};
mutable RID_Owner<Skeleton> skeleton_owner;
mutable SelfList<Skeleton>::List _skeleton_dirty_list;
-
- template<bool USE_NORMAL, bool USE_TANGENT,bool INPLACE>
- void _skeleton_xform(const uint8_t * p_src_array, int p_src_stride, uint8_t * p_dst_array, int p_dst_stride, int p_elements,const uint8_t *p_src_bones, const uint8_t *p_src_weights, const Skeleton::Bone *p_bone_xforms);
+ template <bool USE_NORMAL, bool USE_TANGENT, bool INPLACE>
+ void _skeleton_xform(const uint8_t *p_src_array, int p_src_stride, uint8_t *p_dst_array, int p_dst_stride, int p_elements, const uint8_t *p_src_bones, const uint8_t *p_src_weights, const Skeleton::Bone *p_bone_xforms);
struct Light {
@@ -642,36 +637,33 @@ class RasterizerGLES2 : public Rasterizer {
VS::LightDirectionalShadowMode directional_shadow_mode;
float directional_shadow_param[3];
-
Light() {
- vars[VS::LIGHT_PARAM_SPOT_ATTENUATION]=1;
- vars[VS::LIGHT_PARAM_SPOT_ANGLE]=45;
- vars[VS::LIGHT_PARAM_ATTENUATION]=1.0;
- vars[VS::LIGHT_PARAM_ENERGY]=1.0;
- vars[VS::LIGHT_PARAM_RADIUS]=1.0;
- vars[VS::LIGHT_PARAM_SHADOW_DARKENING]=0.0;
- vars[VS::LIGHT_PARAM_SHADOW_Z_OFFSET]=0.2;
- vars[VS::LIGHT_PARAM_SHADOW_Z_SLOPE_SCALE]=1.4;
- vars[VS::LIGHT_PARAM_SHADOW_ESM_MULTIPLIER]=60.0;
- vars[VS::LIGHT_PARAM_SHADOW_BLUR_PASSES]=1;
- colors[VS::LIGHT_COLOR_DIFFUSE]=Color(1,1,1);
- colors[VS::LIGHT_COLOR_SPECULAR]=Color(1,1,1);
- shadow_enabled=false;
- volumetric_enabled=false;
-
- directional_shadow_param[VS::LIGHT_DIRECTIONAL_SHADOW_PARAM_PSSM_SPLIT_WEIGHT]=0.5;
- directional_shadow_param[VS::LIGHT_DIRECTIONAL_SHADOW_PARAM_MAX_DISTANCE]=0;
- directional_shadow_param[VS::LIGHT_DIRECTIONAL_SHADOW_PARAM_PSSM_ZOFFSET_SCALE]=2.0;
- omni_shadow_mode=VS::LIGHT_OMNI_SHADOW_DEFAULT;
- directional_shadow_mode=VS::LIGHT_DIRECTIONAL_SHADOW_ORTHOGONAL;
+ vars[VS::LIGHT_PARAM_SPOT_ATTENUATION] = 1;
+ vars[VS::LIGHT_PARAM_SPOT_ANGLE] = 45;
+ vars[VS::LIGHT_PARAM_ATTENUATION] = 1.0;
+ vars[VS::LIGHT_PARAM_ENERGY] = 1.0;
+ vars[VS::LIGHT_PARAM_RADIUS] = 1.0;
+ vars[VS::LIGHT_PARAM_SHADOW_DARKENING] = 0.0;
+ vars[VS::LIGHT_PARAM_SHADOW_Z_OFFSET] = 0.2;
+ vars[VS::LIGHT_PARAM_SHADOW_Z_SLOPE_SCALE] = 1.4;
+ vars[VS::LIGHT_PARAM_SHADOW_ESM_MULTIPLIER] = 60.0;
+ vars[VS::LIGHT_PARAM_SHADOW_BLUR_PASSES] = 1;
+ colors[VS::LIGHT_COLOR_DIFFUSE] = Color(1, 1, 1);
+ colors[VS::LIGHT_COLOR_SPECULAR] = Color(1, 1, 1);
+ shadow_enabled = false;
+ volumetric_enabled = false;
+
+ directional_shadow_param[VS::LIGHT_DIRECTIONAL_SHADOW_PARAM_PSSM_SPLIT_WEIGHT] = 0.5;
+ directional_shadow_param[VS::LIGHT_DIRECTIONAL_SHADOW_PARAM_MAX_DISTANCE] = 0;
+ directional_shadow_param[VS::LIGHT_DIRECTIONAL_SHADOW_PARAM_PSSM_ZOFFSET_SCALE] = 2.0;
+ omni_shadow_mode = VS::LIGHT_OMNI_SHADOW_DEFAULT;
+ directional_shadow_mode = VS::LIGHT_DIRECTIONAL_SHADOW_ORTHOGONAL;
}
};
-
struct Environment {
-
VS::EnvironmentBG bg_mode;
Variant bg_param[VS::ENV_BG_PARAM_MAX];
bool fx_enabled[VS::ENV_FX_MAX];
@@ -679,54 +671,51 @@ class RasterizerGLES2 : public Rasterizer {
Environment() {
- bg_mode=VS::ENV_BG_DEFAULT_COLOR;
- bg_param[VS::ENV_BG_PARAM_COLOR]=Color(0,0,0);
- bg_param[VS::ENV_BG_PARAM_TEXTURE]=RID();
- bg_param[VS::ENV_BG_PARAM_CUBEMAP]=RID();
- bg_param[VS::ENV_BG_PARAM_ENERGY]=1.0;
- bg_param[VS::ENV_BG_PARAM_SCALE]=1.0;
- bg_param[VS::ENV_BG_PARAM_GLOW]=0.0;
- bg_param[VS::ENV_BG_PARAM_CANVAS_MAX_LAYER]=0;
-
- for(int i=0;i<VS::ENV_FX_MAX;i++)
- fx_enabled[i]=false;
-
- fx_param[VS::ENV_FX_PARAM_GLOW_BLUR_PASSES]=1;
- fx_param[VS::ENV_FX_PARAM_GLOW_BLUR_SCALE]=1.0;
- fx_param[VS::ENV_FX_PARAM_GLOW_BLUR_STRENGTH]=1.0;
- fx_param[VS::ENV_FX_PARAM_GLOW_BLUR_BLEND_MODE]=0;
- fx_param[VS::ENV_FX_PARAM_GLOW_BLOOM]=0.0;
- fx_param[VS::ENV_FX_PARAM_GLOW_BLOOM_TRESHOLD]=0.5;
- fx_param[VS::ENV_FX_PARAM_DOF_BLUR_PASSES]=1;
- fx_param[VS::ENV_FX_PARAM_DOF_BLUR_BEGIN]=100.0;
- fx_param[VS::ENV_FX_PARAM_DOF_BLUR_RANGE]=10.0;
- fx_param[VS::ENV_FX_PARAM_HDR_TONEMAPPER]=VS::ENV_FX_HDR_TONE_MAPPER_LINEAR;
- fx_param[VS::ENV_FX_PARAM_HDR_EXPOSURE]=0.4;
- fx_param[VS::ENV_FX_PARAM_HDR_WHITE]=1.0;
- fx_param[VS::ENV_FX_PARAM_HDR_GLOW_TRESHOLD]=0.95;
- fx_param[VS::ENV_FX_PARAM_HDR_GLOW_SCALE]=0.2;
- fx_param[VS::ENV_FX_PARAM_HDR_MIN_LUMINANCE]=0.4;
- fx_param[VS::ENV_FX_PARAM_HDR_MAX_LUMINANCE]=8.0;
- fx_param[VS::ENV_FX_PARAM_HDR_EXPOSURE_ADJUST_SPEED]=0.5;
- fx_param[VS::ENV_FX_PARAM_FOG_BEGIN]=100.0;
- fx_param[VS::ENV_FX_PARAM_FOG_ATTENUATION]=1.0;
- fx_param[VS::ENV_FX_PARAM_FOG_BEGIN_COLOR]=Color(0,0,0);
- fx_param[VS::ENV_FX_PARAM_FOG_END_COLOR]=Color(0,0,0);
- fx_param[VS::ENV_FX_PARAM_FOG_BG]=true;
- fx_param[VS::ENV_FX_PARAM_BCS_BRIGHTNESS]=1.0;
- fx_param[VS::ENV_FX_PARAM_BCS_CONTRAST]=1.0;
- fx_param[VS::ENV_FX_PARAM_BCS_SATURATION]=1.0;
-
+ bg_mode = VS::ENV_BG_DEFAULT_COLOR;
+ bg_param[VS::ENV_BG_PARAM_COLOR] = Color(0, 0, 0);
+ bg_param[VS::ENV_BG_PARAM_TEXTURE] = RID();
+ bg_param[VS::ENV_BG_PARAM_CUBEMAP] = RID();
+ bg_param[VS::ENV_BG_PARAM_ENERGY] = 1.0;
+ bg_param[VS::ENV_BG_PARAM_SCALE] = 1.0;
+ bg_param[VS::ENV_BG_PARAM_GLOW] = 0.0;
+ bg_param[VS::ENV_BG_PARAM_CANVAS_MAX_LAYER] = 0;
+
+ for (int i = 0; i < VS::ENV_FX_MAX; i++)
+ fx_enabled[i] = false;
+
+ fx_param[VS::ENV_FX_PARAM_GLOW_BLUR_PASSES] = 1;
+ fx_param[VS::ENV_FX_PARAM_GLOW_BLUR_SCALE] = 1.0;
+ fx_param[VS::ENV_FX_PARAM_GLOW_BLUR_STRENGTH] = 1.0;
+ fx_param[VS::ENV_FX_PARAM_GLOW_BLUR_BLEND_MODE] = 0;
+ fx_param[VS::ENV_FX_PARAM_GLOW_BLOOM] = 0.0;
+ fx_param[VS::ENV_FX_PARAM_GLOW_BLOOM_TRESHOLD] = 0.5;
+ fx_param[VS::ENV_FX_PARAM_DOF_BLUR_PASSES] = 1;
+ fx_param[VS::ENV_FX_PARAM_DOF_BLUR_BEGIN] = 100.0;
+ fx_param[VS::ENV_FX_PARAM_DOF_BLUR_RANGE] = 10.0;
+ fx_param[VS::ENV_FX_PARAM_HDR_TONEMAPPER] = VS::ENV_FX_HDR_TONE_MAPPER_LINEAR;
+ fx_param[VS::ENV_FX_PARAM_HDR_EXPOSURE] = 0.4;
+ fx_param[VS::ENV_FX_PARAM_HDR_WHITE] = 1.0;
+ fx_param[VS::ENV_FX_PARAM_HDR_GLOW_TRESHOLD] = 0.95;
+ fx_param[VS::ENV_FX_PARAM_HDR_GLOW_SCALE] = 0.2;
+ fx_param[VS::ENV_FX_PARAM_HDR_MIN_LUMINANCE] = 0.4;
+ fx_param[VS::ENV_FX_PARAM_HDR_MAX_LUMINANCE] = 8.0;
+ fx_param[VS::ENV_FX_PARAM_HDR_EXPOSURE_ADJUST_SPEED] = 0.5;
+ fx_param[VS::ENV_FX_PARAM_FOG_BEGIN] = 100.0;
+ fx_param[VS::ENV_FX_PARAM_FOG_ATTENUATION] = 1.0;
+ fx_param[VS::ENV_FX_PARAM_FOG_BEGIN_COLOR] = Color(0, 0, 0);
+ fx_param[VS::ENV_FX_PARAM_FOG_END_COLOR] = Color(0, 0, 0);
+ fx_param[VS::ENV_FX_PARAM_FOG_BG] = true;
+ fx_param[VS::ENV_FX_PARAM_BCS_BRIGHTNESS] = 1.0;
+ fx_param[VS::ENV_FX_PARAM_BCS_CONTRAST] = 1.0;
+ fx_param[VS::ENV_FX_PARAM_BCS_SATURATION] = 1.0;
}
-
};
mutable RID_Owner<Environment> environment_owner;
-
struct SampledLight {
- int w,h;
+ int w, h;
GLuint texture;
float multiplier;
bool is_float;
@@ -734,14 +723,16 @@ class RasterizerGLES2 : public Rasterizer {
mutable RID_Owner<SampledLight> sampled_light_owner;
-
struct ViewportData {
//1x1 fbo+texture for storing previous HDR value
GLuint lum_fbo;
GLuint lum_color;
- ViewportData() { lum_fbo=0; lum_color=0; }
+ ViewportData() {
+ lum_fbo = 0;
+ lum_color = 0;
+ }
};
mutable RID_Owner<ViewportData> viewport_data_owner;
@@ -753,15 +744,12 @@ class RasterizerGLES2 : public Rasterizer {
GLuint fbo;
GLuint color;
GLuint depth;
- int width,height;
+ int width, height;
uint64_t last_pass;
-
};
mutable RID_Owner<RenderTarget> render_target_owner;
-
-
struct ShadowBuffer;
struct LightInstance {
@@ -795,9 +783,7 @@ class RasterizerGLES2 : public Rasterizer {
CameraMatrix shadow_projection[4];
float shadow_split[4];
-
-
- ShadowBuffer* near_shadow_buffer;
+ ShadowBuffer *near_shadow_buffer;
void clear_shadow_buffers() {
@@ -807,13 +793,17 @@ class RasterizerGLES2 : public Rasterizer {
void clear_near_shadow_buffers() {
if (near_shadow_buffer) {
- near_shadow_buffer->owner=NULL;
- near_shadow_buffer=NULL;
+ near_shadow_buffer->owner = NULL;
+ near_shadow_buffer = NULL;
}
}
- LightInstance() { shadow_pass=0; last_pass=0; sort_key=0; near_shadow_buffer=NULL;}
-
+ LightInstance() {
+ shadow_pass = 0;
+ last_pass = 0;
+ sort_key = 0;
+ near_shadow_buffer = NULL;
+ }
};
mutable RID_Owner<Light> light_owner;
mutable RID_Owner<LightInstance> light_instance_owner;
@@ -841,22 +831,19 @@ class RasterizerGLES2 : public Rasterizer {
GLuint gui_quad_buffer;
GLuint indices_buffer;
-
-
struct RenderList {
enum {
- DEFAULT_MAX_ELEMENTS=4096,
- MAX_LIGHTS=4,
- SORT_FLAG_SKELETON=1,
- SORT_FLAG_INSTANCING=2,
+ DEFAULT_MAX_ELEMENTS = 4096,
+ MAX_LIGHTS = 4,
+ SORT_FLAG_SKELETON = 1,
+ SORT_FLAG_INSTANCING = 2,
};
static int max_elements;
struct Element {
-
float depth;
const InstanceData *instance;
const Skeleton *skeleton;
@@ -885,19 +872,18 @@ class RasterizerGLES2 : public Rasterizer {
};
};
-
Element *_elements;
Element **elements;
int element_count;
void clear() {
- element_count=0;
+ element_count = 0;
}
struct SortZ {
- _FORCE_INLINE_ bool operator()(const Element* A, const Element* B ) const {
+ _FORCE_INLINE_ bool operator()(const Element *A, const Element *B) const {
return A->depth > B->depth;
}
@@ -905,14 +891,13 @@ class RasterizerGLES2 : public Rasterizer {
void sort_z() {
- SortArray<Element*,SortZ> sorter;
- sorter.sort(elements,element_count);
+ SortArray<Element *, SortZ> sorter;
+ sorter.sort(elements, element_count);
}
-
struct SortMatGeom {
- _FORCE_INLINE_ bool operator()(const Element* A, const Element* B ) const {
+ _FORCE_INLINE_ bool operator()(const Element *A, const Element *B) const {
// TODO move to a single uint64 (one comparison)
if (A->material->shader_cache == B->material->shader_cache) {
if (A->material == B->material) {
@@ -931,19 +916,19 @@ class RasterizerGLES2 : public Rasterizer {
void sort_mat_geom() {
- SortArray<Element*,SortMatGeom> sorter;
- sorter.sort(elements,element_count);
+ SortArray<Element *, SortMatGeom> sorter;
+ sorter.sort(elements, element_count);
}
struct SortMatLight {
- _FORCE_INLINE_ bool operator()(const Element* A, const Element* B ) const {
+ _FORCE_INLINE_ bool operator()(const Element *A, const Element *B) const {
if (A->geometry_cmp == B->geometry_cmp) {
if (A->material == B->material) {
- return A->light<B->light;
+ return A->light < B->light;
} else {
return (A->material < B->material);
@@ -957,13 +942,13 @@ class RasterizerGLES2 : public Rasterizer {
void sort_mat_light() {
- SortArray<Element*,SortMatLight> sorter;
- sorter.sort(elements,element_count);
+ SortArray<Element *, SortMatLight> sorter;
+ sorter.sort(elements, element_count);
}
struct SortMatLightType {
- _FORCE_INLINE_ bool operator()(const Element* A, const Element* B ) const {
+ _FORCE_INLINE_ bool operator()(const Element *A, const Element *B) const {
if (A->light_type == B->light_type) {
if (A->material->shader_cache == B->material->shader_cache) {
@@ -987,13 +972,13 @@ class RasterizerGLES2 : public Rasterizer {
void sort_mat_light_type() {
- SortArray<Element*,SortMatLightType> sorter;
- sorter.sort(elements,element_count);
+ SortArray<Element *, SortMatLightType> sorter;
+ sorter.sort(elements, element_count);
}
struct SortMatLightTypeFlags {
- _FORCE_INLINE_ bool operator()(const Element* A, const Element* B ) const {
+ _FORCE_INLINE_ bool operator()(const Element *A, const Element *B) const {
if (A->sort_key == B->sort_key) {
if (A->material->shader_cache == B->material->shader_cache) {
@@ -1017,29 +1002,27 @@ class RasterizerGLES2 : public Rasterizer {
void sort_mat_light_type_flags() {
- SortArray<Element*,SortMatLightTypeFlags> sorter;
- sorter.sort(elements,element_count);
+ SortArray<Element *, SortMatLightTypeFlags> sorter;
+ sorter.sort(elements, element_count);
}
- _FORCE_INLINE_ Element* add_element() {
+ _FORCE_INLINE_ Element *add_element() {
- if (element_count>=max_elements)
+ if (element_count >= max_elements)
return NULL;
- elements[element_count]=&_elements[element_count];
+ elements[element_count] = &_elements[element_count];
return elements[element_count++];
}
void init() {
element_count = 0;
- elements=memnew_arr(Element*,max_elements);
- _elements=memnew_arr(Element,max_elements);
- for (int i=0;i<max_elements;i++)
- elements[i]=&_elements[i]; // assign elements
-
+ elements = memnew_arr(Element *, max_elements);
+ _elements = memnew_arr(Element, max_elements);
+ for (int i = 0; i < max_elements; i++)
+ elements[i] = &_elements[i]; // assign elements
}
RenderList() {
-
}
~RenderList() {
memdelete_arr(elements);
@@ -1047,14 +1030,11 @@ class RasterizerGLES2 : public Rasterizer {
}
};
-
-
RenderList opaque_render_list;
RenderList alpha_render_list;
RID default_material;
-
CameraMatrix camera_projection;
Transform camera_transform;
Transform camera_transform_inverse;
@@ -1066,12 +1046,10 @@ class RasterizerGLES2 : public Rasterizer {
bool texscreen_copied;
bool texscreen_used;
-
-
Plane camera_plane;
- void _add_geometry( const Geometry* p_geometry, const InstanceData *p_instance, const Geometry *p_geometry_cmp, const GeometryOwner *p_owner,int p_material=-1);
- void _render_list_forward(RenderList *p_render_list,const Transform& p_view_transform,const Transform& p_view_transform_inverse, const CameraMatrix& p_projection,bool p_reverse_cull=false,bool p_fragment_light=false,bool p_alpha_pass=false);
+ void _add_geometry(const Geometry *p_geometry, const InstanceData *p_instance, const Geometry *p_geometry_cmp, const GeometryOwner *p_owner, int p_material = -1);
+ void _render_list_forward(RenderList *p_render_list, const Transform &p_view_transform, const Transform &p_view_transform_inverse, const CameraMatrix &p_projection, bool p_reverse_cull = false, bool p_fragment_light = false, bool p_alpha_pass = false);
//void _setup_light(LightInstance* p_instance, int p_idx);
void _setup_light(uint16_t p_light);
@@ -1080,10 +1058,8 @@ class RasterizerGLES2 : public Rasterizer {
bool _setup_material(const Geometry *p_geometry, const Material *p_material, bool p_no_const_light, bool p_opaque_pass);
void _setup_skeleton(const Skeleton *p_skeleton);
-
- Error _setup_geometry(const Geometry *p_geometry, const Material* p_material,const Skeleton *p_skeleton, const float *p_morphs);
- void _render(const Geometry *p_geometry,const Material *p_material, const Skeleton* p_skeleton, const GeometryOwner *p_owner,const Transform& p_xform);
-
+ Error _setup_geometry(const Geometry *p_geometry, const Material *p_material, const Skeleton *p_skeleton, const float *p_morphs);
+ void _render(const Geometry *p_geometry, const Material *p_material, const Skeleton *p_skeleton, const GeometryOwner *p_owner, const Transform &p_xform);
/***********/
/* SHADOWS */
@@ -1103,8 +1079,12 @@ class RasterizerGLES2 : public Rasterizer {
#endif
LightInstance *owner;
- bool init(int p_size,bool p_use_depth);
- ShadowBuffer() { size=0; depth=0; owner=NULL; }
+ bool init(int p_size, bool p_use_depth);
+ ShadowBuffer() {
+ size = 0;
+ depth = 0;
+ owner = NULL;
+ }
};
Vector<ShadowBuffer> near_shadow_buffers;
@@ -1115,30 +1095,25 @@ class RasterizerGLES2 : public Rasterizer {
LightInstance *shadow;
int shadow_pass;
-
float shadow_near_far_split_size_ratio;
- bool _allocate_shadow_buffers(LightInstance *p_instance, Vector<ShadowBuffer>& p_buffers);
- void _debug_draw_shadow(GLuint tex, const Rect2& p_rect);
- void _debug_draw_shadows_type(Vector<ShadowBuffer>& p_shadows,Point2& ofs);
+ bool _allocate_shadow_buffers(LightInstance *p_instance, Vector<ShadowBuffer> &p_buffers);
+ void _debug_draw_shadow(GLuint tex, const Rect2 &p_rect);
+ void _debug_draw_shadows_type(Vector<ShadowBuffer> &p_shadows, Point2 &ofs);
void _debug_shadows();
void _debug_luminances();
void _debug_samplers();
-
-
/***********/
/* FBOs */
/***********/
-
struct FrameBuffer {
GLuint fbo;
GLuint color;
GLuint depth;
-
- int width,height;
+ int width, height;
int scale;
bool active;
@@ -1149,7 +1124,10 @@ class RasterizerGLES2 : public Rasterizer {
GLuint fbo;
GLuint color;
- Blur() { fbo=0; color=0; }
+ Blur() {
+ fbo = 0;
+ color = 0;
+ }
} blur[3];
struct Luminance {
@@ -1158,7 +1136,11 @@ class RasterizerGLES2 : public Rasterizer {
GLuint fbo;
GLuint color;
- Luminance() { fbo=0; color=0; size=0;}
+ Luminance() {
+ fbo = 0;
+ color = 0;
+ size = 0;
+ }
};
Vector<Luminance> luminance;
@@ -1167,7 +1149,7 @@ class RasterizerGLES2 : public Rasterizer {
GLuint sample_color;
FrameBuffer() {
- blur_size=0;
+ blur_size = 0;
}
} framebuffer;
@@ -1176,7 +1158,6 @@ class RasterizerGLES2 : public Rasterizer {
void _process_glow_and_bloom();
//void _update_blur_buffer();
-
/*********/
/* FRAME */
/*********/
@@ -1194,12 +1175,10 @@ class RasterizerGLES2 : public Rasterizer {
} _rinfo;
-
/*******************/
/* CANVAS OCCLUDER */
/*******************/
-
struct CanvasOccluder {
GLuint vertex_id; // 0 means, unconfigured
@@ -1214,7 +1193,6 @@ class RasterizerGLES2 : public Rasterizer {
/* CANVAS LIGHT SHADOW */
/***********************/
-
struct CanvasLightShadow {
int size;
@@ -1225,7 +1203,6 @@ class RasterizerGLES2 : public Rasterizer {
GLuint rgba; //for older devices
GLuint blur;
-
};
RID_Owner<CanvasLightShadow> canvas_light_shadow_owner;
@@ -1239,7 +1216,6 @@ class RasterizerGLES2 : public Rasterizer {
bool current_rt_vflip;
ViewportData *current_vd;
-
GLuint white_tex;
RID canvas_tex;
float canvas_opacity;
@@ -1251,13 +1227,11 @@ class RasterizerGLES2 : public Rasterizer {
CanvasItemMaterial *canvas_last_material;
bool canvas_texscreen_used;
Vector2 normal_flip;
- _FORCE_INLINE_ void _canvas_normal_set_flip(const Vector2& p_flip);
+ _FORCE_INLINE_ void _canvas_normal_set_flip(const Vector2 &p_flip);
-
- _FORCE_INLINE_ Texture* _bind_canvas_texture(const RID& p_texture);
+ _FORCE_INLINE_ Texture *_bind_canvas_texture(const RID &p_texture);
VS::MaterialBlendMode canvas_blend_mode;
-
int _setup_geometry_vinfo;
bool pack_arrays;
@@ -1265,8 +1239,8 @@ class RasterizerGLES2 : public Rasterizer {
bool use_reload_hooks;
bool cull_front;
bool lights_use_shadow;
- _FORCE_INLINE_ void _set_cull(bool p_front,bool p_reverse_cull=false);
- _FORCE_INLINE_ Color _convert_color(const Color& p_color);
+ _FORCE_INLINE_ void _set_cull(bool p_front, bool p_reverse_cull = false);
+ _FORCE_INLINE_ Color _convert_color(const Color &p_color);
void _process_glow_bloom();
void _process_hdr();
@@ -1285,7 +1259,6 @@ class RasterizerGLES2 : public Rasterizer {
RID overdraw_material;
float shader_time_rollback;
-
mutable MaterialShaderGLES2 material_shader;
mutable CanvasShaderGLES2 canvas_shader;
BlurShaderGLES2 blur_shader;
@@ -1294,11 +1267,11 @@ class RasterizerGLES2 : public Rasterizer {
mutable ShaderCompilerGLES2 shader_precompiler;
- void _draw_primitive(int p_points, const Vector3 *p_vertices, const Vector3 *p_normals, const Color* p_colors, const Vector3 *p_uvs,const Plane *p_tangents=NULL,int p_instanced=1);
- _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_gui_primitive2(int p_points, const Vector2 *p_vertices, const Color* p_colors, const Vector2 *p_uvs, const Vector2 *p_uvs2);
- void _draw_textured_quad(const Rect2& p_rect, const Rect2& p_src_region, const Size2& p_tex_size,bool p_h_flip=false, bool p_v_flip=false, bool p_transpose=false );
- void _draw_quad(const Rect2& p_rect);
+ void _draw_primitive(int p_points, const Vector3 *p_vertices, const Vector3 *p_normals, const Color *p_colors, const Vector3 *p_uvs, const Plane *p_tangents = NULL, int p_instanced = 1);
+ _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_gui_primitive2(int p_points, const Vector2 *p_vertices, const Color *p_colors, const Vector2 *p_uvs, const Vector2 *p_uvs2);
+ void _draw_textured_quad(const Rect2 &p_rect, const Rect2 &p_src_region, const Size2 &p_tex_size, bool p_h_flip = false, bool p_v_flip = false, bool p_transpose = false);
+ void _draw_quad(const Rect2 &p_rect);
void _copy_screen_quad();
void _copy_to_texscreen();
@@ -1313,28 +1286,28 @@ class RasterizerGLES2 : public Rasterizer {
GLuint tc0_id_cache;
GLuint tc0_idx;
- template<bool use_normalmap>
- _FORCE_INLINE_ void _canvas_item_render_commands(CanvasItem *p_item,CanvasItem *current_clip,bool &reclip);
- _FORCE_INLINE_ void _canvas_item_setup_shader_params(CanvasItemMaterial *material,Shader* p_shader);
- _FORCE_INLINE_ void _canvas_item_setup_shader_uniforms(CanvasItemMaterial *material,Shader* p_shader);
-public:
+ template <bool use_normalmap>
+ _FORCE_INLINE_ void _canvas_item_render_commands(CanvasItem *p_item, CanvasItem *current_clip, bool &reclip);
+ _FORCE_INLINE_ void _canvas_item_setup_shader_params(CanvasItemMaterial *material, Shader *p_shader);
+ _FORCE_INLINE_ void _canvas_item_setup_shader_uniforms(CanvasItemMaterial *material, Shader *p_shader);
+public:
/* TEXTURE API */
virtual RID texture_create();
- virtual void texture_allocate(RID p_texture,int p_width, int p_height,Image::Format p_format,uint32_t p_flags=VS::TEXTURE_FLAGS_DEFAULT);
- virtual void texture_set_data(RID p_texture,const Image& p_image,VS::CubeMapSide p_cube_side=VS::CUBEMAP_LEFT);
- virtual Image texture_get_data(RID p_texture,VS::CubeMapSide p_cube_side=VS::CUBEMAP_LEFT) const;
- virtual void texture_set_flags(RID p_texture,uint32_t p_flags);
+ virtual void texture_allocate(RID p_texture, int p_width, int p_height, Image::Format p_format, uint32_t p_flags = VS::TEXTURE_FLAGS_DEFAULT);
+ virtual void texture_set_data(RID p_texture, const Image &p_image, VS::CubeMapSide p_cube_side = VS::CUBEMAP_LEFT);
+ virtual Image texture_get_data(RID p_texture, VS::CubeMapSide p_cube_side = VS::CUBEMAP_LEFT) 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 uint32_t texture_get_width(RID p_texture) const;
virtual uint32_t texture_get_height(RID p_texture) const;
virtual bool texture_has_alpha(RID p_texture) const;
- virtual void texture_set_size_override(RID p_texture,int p_width, int p_height);
- virtual void texture_set_reload_hook(RID p_texture,ObjectID p_owner,const StringName& p_function) const;
+ virtual void texture_set_size_override(RID p_texture, int p_width, int p_height);
+ virtual void texture_set_reload_hook(RID p_texture, ObjectID p_owner, const StringName &p_function) const;
- virtual void texture_set_path(RID p_texture,const String& p_path);
+ virtual void texture_set_path(RID p_texture, const String &p_path);
virtual String texture_get_path(RID p_texture) const;
virtual void texture_debug_usage(List<VS::TextureInfo> *r_info);
@@ -1344,23 +1317,22 @@ public:
/* SHADER API */
- virtual RID shader_create(VS::ShaderMode p_mode=VS::SHADER_MATERIAL);
+ virtual RID shader_create(VS::ShaderMode p_mode = VS::SHADER_MATERIAL);
- virtual void shader_set_mode(RID p_shader,VS::ShaderMode p_mode);
+ virtual void shader_set_mode(RID p_shader, VS::ShaderMode p_mode);
virtual VS::ShaderMode shader_get_mode(RID p_shader) const;
- virtual void shader_set_code(RID p_shader, const String& p_vertex, const String& p_fragment,const String& p_light,int p_vertex_ofs=0,int p_fragment_ofs=0,int p_light_ofs=0);
+ virtual void shader_set_code(RID p_shader, const String &p_vertex, const String &p_fragment, const String &p_light, int p_vertex_ofs = 0, int p_fragment_ofs = 0, int p_light_ofs = 0);
virtual String shader_get_fragment_code(RID p_shader) const;
virtual String shader_get_vertex_code(RID p_shader) const;
virtual String shader_get_light_code(RID p_shader) const;
-
virtual void shader_get_param_list(RID p_shader, List<PropertyInfo> *p_param_list) const;
- virtual void shader_set_default_texture_param(RID p_shader, const StringName& p_name, RID p_texture);
- virtual RID shader_get_default_texture_param(RID p_shader, const StringName& p_name) const;
+ virtual void shader_set_default_texture_param(RID p_shader, const StringName &p_name, RID p_texture);
+ virtual RID shader_get_default_texture_param(RID p_shader, const StringName &p_name) const;
- virtual Variant shader_get_default_param(RID p_shader, const StringName& p_name);
+ virtual Variant shader_get_default_param(RID p_shader, const StringName &p_name);
/* COMMON MATERIAL API */
@@ -1369,38 +1341,37 @@ public:
virtual void material_set_shader(RID p_shader_material, RID p_shader);
virtual RID material_get_shader(RID p_shader_material) const;
- virtual void material_set_param(RID p_material, const StringName& p_param, const Variant& p_value);
- virtual Variant material_get_param(RID p_material, const StringName& p_param) const;
+ virtual void material_set_param(RID p_material, const StringName &p_param, const Variant &p_value);
+ virtual Variant material_get_param(RID p_material, const StringName &p_param) const;
- virtual void material_set_flag(RID p_material, VS::MaterialFlag p_flag,bool p_enabled);
- virtual bool material_get_flag(RID p_material,VS::MaterialFlag p_flag) const;
+ virtual void material_set_flag(RID p_material, VS::MaterialFlag p_flag, bool p_enabled);
+ virtual bool material_get_flag(RID p_material, VS::MaterialFlag p_flag) const;
virtual void material_set_depth_draw_mode(RID p_material, VS::MaterialDepthDrawMode p_mode);
virtual VS::MaterialDepthDrawMode material_get_depth_draw_mode(RID p_material) const;
- virtual void material_set_blend_mode(RID p_material,VS::MaterialBlendMode p_mode);
+ virtual void material_set_blend_mode(RID p_material, VS::MaterialBlendMode p_mode);
virtual VS::MaterialBlendMode material_get_blend_mode(RID p_material) const;
- virtual void material_set_line_width(RID p_material,float p_line_width);
+ virtual void material_set_line_width(RID p_material, float p_line_width);
virtual float material_get_line_width(RID p_material) const;
-
/* MESH API */
virtual RID mesh_create();
- virtual void mesh_add_surface(RID p_mesh,VS::PrimitiveType p_primitive,const Array& p_arrays,const Array& p_blend_shapes=Array(),bool p_alpha_sort=false);
- virtual Array mesh_get_surface_arrays(RID p_mesh,int p_surface) const;
- virtual Array mesh_get_surface_morph_arrays(RID p_mesh,int p_surface) const;
- virtual void mesh_add_custom_surface(RID p_mesh,const Variant& p_dat);
+ virtual void mesh_add_surface(RID p_mesh, VS::PrimitiveType p_primitive, const Array &p_arrays, const Array &p_blend_shapes = Array(), bool p_alpha_sort = false);
+ virtual Array mesh_get_surface_arrays(RID p_mesh, int p_surface) const;
+ virtual Array mesh_get_surface_morph_arrays(RID p_mesh, int p_surface) const;
+ virtual void mesh_add_custom_surface(RID p_mesh, const Variant &p_dat);
- virtual void mesh_set_morph_target_count(RID p_mesh,int p_amount);
+ virtual void mesh_set_morph_target_count(RID p_mesh, int p_amount);
virtual int mesh_get_morph_target_count(RID p_mesh) const;
- virtual void mesh_set_morph_target_mode(RID p_mesh,VS::MorphTargetMode p_mode);
+ virtual void mesh_set_morph_target_mode(RID p_mesh, VS::MorphTargetMode p_mode);
virtual VS::MorphTargetMode mesh_get_morph_target_mode(RID p_mesh) const;
- virtual void mesh_surface_set_material(RID p_mesh, int p_surface, RID p_material,bool p_owned=false);
+ virtual void mesh_surface_set_material(RID p_mesh, int p_surface, RID p_material, bool p_owned = false);
virtual RID mesh_surface_get_material(RID p_mesh, int p_surface) const;
virtual int mesh_surface_get_array_len(RID p_mesh, int p_surface) const;
@@ -1408,49 +1379,49 @@ public:
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 void mesh_remove_surface(RID p_mesh,int p_index);
+ virtual void mesh_remove_surface(RID p_mesh, int p_index);
virtual int mesh_get_surface_count(RID p_mesh) const;
- virtual AABB mesh_get_aabb(RID p_mesh,RID p_skeleton=RID()) const;
+ virtual AABB mesh_get_aabb(RID p_mesh, RID p_skeleton = RID()) const;
- virtual void mesh_set_custom_aabb(RID p_mesh,const AABB& p_aabb);
+ virtual void mesh_set_custom_aabb(RID p_mesh, const AABB &p_aabb);
virtual AABB mesh_get_custom_aabb(RID p_mesh) const;
/* MULTIMESH API */
virtual RID multimesh_create();
- virtual void multimesh_set_instance_count(RID p_multimesh,int p_count);
+ virtual void multimesh_set_instance_count(RID p_multimesh, int p_count);
virtual int multimesh_get_instance_count(RID p_multimesh) const;
- virtual void multimesh_set_mesh(RID p_multimesh,RID p_mesh);
- virtual void multimesh_set_aabb(RID p_multimesh,const AABB& p_aabb);
- virtual void multimesh_instance_set_transform(RID p_multimesh,int p_index,const Transform& p_transform);
- virtual void multimesh_instance_set_color(RID p_multimesh,int p_index,const Color& p_color);
+ virtual void multimesh_set_mesh(RID p_multimesh, RID p_mesh);
+ virtual void multimesh_set_aabb(RID p_multimesh, const AABB &p_aabb);
+ virtual void multimesh_instance_set_transform(RID p_multimesh, int p_index, const Transform &p_transform);
+ virtual void multimesh_instance_set_color(RID p_multimesh, int p_index, const Color &p_color);
virtual RID multimesh_get_mesh(RID p_multimesh) const;
virtual AABB multimesh_get_aabb(RID p_multimesh) const;
- virtual Transform multimesh_instance_get_transform(RID p_multimesh,int p_index) const;
- virtual Color multimesh_instance_get_color(RID p_multimesh,int p_index) const;
+ virtual Transform multimesh_instance_get_transform(RID p_multimesh, int p_index) const;
+ virtual Color multimesh_instance_get_color(RID p_multimesh, int p_index) const;
- virtual void multimesh_set_visible_instances(RID p_multimesh,int p_visible);
+ virtual void multimesh_set_visible_instances(RID p_multimesh, int p_visible);
virtual int multimesh_get_visible_instances(RID p_multimesh) const;
/* IMMEDIATE API */
virtual RID immediate_create();
- virtual void immediate_begin(RID p_immediate,VS::PrimitiveType p_rimitive,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);
- virtual void immediate_color(RID p_immediate,const Color& p_color);
- virtual void immediate_uv(RID p_immediate,const Vector2& tex_uv);
- virtual void immediate_uv2(RID p_immediate,const Vector2& tex_uv);
+ virtual void immediate_begin(RID p_immediate, VS::PrimitiveType p_rimitive, 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);
+ virtual void immediate_color(RID p_immediate, const Color &p_color);
+ virtual void immediate_uv(RID p_immediate, const Vector2 &tex_uv);
+ virtual void immediate_uv2(RID p_immediate, const Vector2 &tex_uv);
virtual void immediate_end(RID p_immediate);
virtual void immediate_clear(RID p_immediate);
virtual AABB immediate_get_aabb(RID p_immediate) const;
- virtual void immediate_set_material(RID p_immediate,RID p_material);
+ virtual void immediate_set_material(RID p_immediate, RID p_material);
virtual RID immediate_get_material(RID p_immediate) const;
/* PARTICLES API */
@@ -1463,25 +1434,25 @@ public:
virtual void particles_set_emitting(RID p_particles, bool p_emitting);
virtual bool particles_is_emitting(RID p_particles) const;
- virtual void particles_set_visibility_aabb(RID p_particles, const AABB& p_visibility);
+ virtual void particles_set_visibility_aabb(RID p_particles, const AABB &p_visibility);
virtual AABB particles_get_visibility_aabb(RID p_particles) const;
- virtual void particles_set_emission_half_extents(RID p_particles, const Vector3& p_half_extents);
+ virtual void particles_set_emission_half_extents(RID p_particles, const Vector3 &p_half_extents);
virtual Vector3 particles_get_emission_half_extents(RID p_particles) const;
- virtual void particles_set_emission_base_velocity(RID p_particles, const Vector3& p_base_velocity);
+ virtual void particles_set_emission_base_velocity(RID p_particles, const Vector3 &p_base_velocity);
virtual Vector3 particles_get_emission_base_velocity(RID p_particles) const;
- virtual void particles_set_emission_points(RID p_particles, const DVector<Vector3>& p_points);
+ virtual void particles_set_emission_points(RID p_particles, const DVector<Vector3> &p_points);
virtual DVector<Vector3> particles_get_emission_points(RID p_particles) const;
- virtual void particles_set_gravity_normal(RID p_particles, const Vector3& p_normal);
+ virtual void particles_set_gravity_normal(RID p_particles, const Vector3 &p_normal);
virtual Vector3 particles_get_gravity_normal(RID p_particles) const;
- virtual void particles_set_variable(RID p_particles, VS::ParticleVariable p_variable,float p_value);
+ virtual void particles_set_variable(RID p_particles, VS::ParticleVariable p_variable, float p_value);
virtual float particles_get_variable(RID p_particles, VS::ParticleVariable p_variable) const;
- virtual void particles_set_randomness(RID p_particles, VS::ParticleVariable p_variable,float p_randomness);
+ virtual void particles_set_randomness(RID p_particles, VS::ParticleVariable p_variable, float p_randomness);
virtual float particles_get_randomness(RID p_particles, VS::ParticleVariable p_variable) const;
virtual void particles_set_color_phase_pos(RID p_particles, int p_phase, float p_pos);
@@ -1490,19 +1461,19 @@ public:
virtual void particles_set_color_phases(RID p_particles, int p_phases);
virtual int particles_get_color_phases(RID p_particles) const;
- virtual void particles_set_color_phase_color(RID p_particles, int p_phase, const Color& p_color);
+ virtual void particles_set_color_phase_color(RID p_particles, int p_phase, const Color &p_color);
virtual Color particles_get_color_phase_color(RID p_particles, int p_phase) const;
virtual void particles_set_attractors(RID p_particles, int p_attractors);
virtual int particles_get_attractors(RID p_particles) const;
- virtual void particles_set_attractor_pos(RID p_particles, int p_attractor, const Vector3& p_pos);
- virtual Vector3 particles_get_attractor_pos(RID p_particles,int p_attractor) const;
+ virtual void particles_set_attractor_pos(RID p_particles, int p_attractor, const Vector3 &p_pos);
+ virtual Vector3 particles_get_attractor_pos(RID p_particles, int p_attractor) const;
virtual void particles_set_attractor_strength(RID p_particles, int p_attractor, float p_force);
- virtual float particles_get_attractor_strength(RID p_particles,int p_attractor) const;
+ virtual float particles_get_attractor_strength(RID p_particles, int p_attractor) const;
- virtual void particles_set_material(RID p_particles, RID p_material,bool p_owned=false);
+ virtual void particles_set_material(RID p_particles, RID p_material, bool p_owned = false);
virtual RID particles_get_material(RID p_particles) const;
virtual AABB particles_get_aabb(RID p_particles) const;
@@ -1516,68 +1487,61 @@ public:
/* SKELETON API */
virtual RID skeleton_create();
- virtual void skeleton_resize(RID p_skeleton,int p_bones);
+ virtual void skeleton_resize(RID p_skeleton, int p_bones);
virtual int skeleton_get_bone_count(RID p_skeleton) const;
- virtual void skeleton_bone_set_transform(RID p_skeleton,int p_bone, const Transform& p_transform);
- virtual Transform skeleton_bone_get_transform(RID p_skeleton,int p_bone);
-
+ virtual void skeleton_bone_set_transform(RID p_skeleton, int p_bone, const Transform &p_transform);
+ virtual Transform skeleton_bone_get_transform(RID p_skeleton, int p_bone);
/* LIGHT API */
virtual RID light_create(VS::LightType p_type);
virtual VS::LightType light_get_type(RID p_light) const;
- virtual void light_set_color(RID p_light,VS::LightColor p_type, const Color& p_color);
- virtual Color light_get_color(RID p_light,VS::LightColor p_type) const;
+ virtual void light_set_color(RID p_light, VS::LightColor p_type, const Color &p_color);
+ virtual Color light_get_color(RID p_light, VS::LightColor p_type) const;
- virtual void light_set_shadow(RID p_light,bool p_enabled);
+ virtual void light_set_shadow(RID p_light, bool p_enabled);
virtual bool light_has_shadow(RID p_light) const;
- virtual void light_set_volumetric(RID p_light,bool p_enabled);
+ virtual void light_set_volumetric(RID p_light, bool p_enabled);
virtual bool light_is_volumetric(RID p_light) const;
- virtual void light_set_projector(RID p_light,RID p_texture);
+ virtual void light_set_projector(RID p_light, RID p_texture);
virtual RID light_get_projector(RID p_light) const;
virtual void light_set_var(RID p_light, VS::LightParam p_var, float p_value);
virtual float light_get_var(RID p_light, VS::LightParam p_var) const;
- virtual void light_set_operator(RID p_light,VS::LightOp p_op);
+ virtual void light_set_operator(RID p_light, VS::LightOp p_op);
virtual VS::LightOp light_get_operator(RID p_light) const;
- virtual void light_omni_set_shadow_mode(RID p_light,VS::LightOmniShadowMode p_mode);
+ virtual void light_omni_set_shadow_mode(RID p_light, VS::LightOmniShadowMode p_mode);
virtual VS::LightOmniShadowMode light_omni_get_shadow_mode(RID p_light) const;
- virtual void light_directional_set_shadow_mode(RID p_light,VS::LightDirectionalShadowMode p_mode);
+ virtual void light_directional_set_shadow_mode(RID p_light, VS::LightDirectionalShadowMode p_mode);
virtual VS::LightDirectionalShadowMode light_directional_get_shadow_mode(RID p_light) const;
- virtual void light_directional_set_shadow_param(RID p_light,VS::LightDirectionalShadowParam p_param, float p_value);
- virtual float light_directional_get_shadow_param(RID p_light,VS::LightDirectionalShadowParam p_param) const;
-
-
+ virtual void light_directional_set_shadow_param(RID p_light, VS::LightDirectionalShadowParam p_param, float p_value);
+ virtual float light_directional_get_shadow_param(RID p_light, VS::LightDirectionalShadowParam p_param) const;
virtual AABB light_get_aabb(RID p_poly) const;
-
virtual RID light_instance_create(RID p_light);
- virtual void light_instance_set_transform(RID p_light_instance,const Transform& p_transform);
+ virtual void light_instance_set_transform(RID p_light_instance, const Transform &p_transform);
- virtual ShadowType light_instance_get_shadow_type(RID p_light_instance,bool p_far=false) const;
+ virtual ShadowType light_instance_get_shadow_type(RID p_light_instance, bool p_far = false) const;
virtual int light_instance_get_shadow_passes(RID p_light_instance) const;
virtual bool light_instance_get_pssm_shadow_overlap(RID p_light_instance) const;
- virtual void light_instance_set_shadow_transform(RID p_light_instance, int p_index, const CameraMatrix& p_camera, const Transform& p_transform, float p_split_near=0,float p_split_far=0);
- virtual int light_instance_get_shadow_size(RID p_light_instance, int p_index=0) const;
-
+ virtual void light_instance_set_shadow_transform(RID p_light_instance, int p_index, const CameraMatrix &p_camera, const Transform &p_transform, float p_split_near = 0, float p_split_far = 0);
+ virtual int light_instance_get_shadow_size(RID p_light_instance, int p_index = 0) const;
virtual void shadow_clear_near();
virtual bool shadow_allocate_near(RID p_light);
virtual bool shadow_allocate_far(RID p_light);
-
/* SHADOW */
virtual RID particles_instance_create(RID p_particles);
- virtual void particles_instance_set_transform(RID p_particles_instance,const Transform& p_transform);
-
+ virtual void particles_instance_set_transform(RID p_particles_instance, const Transform &p_transform);
/* VIEWPORT */
@@ -1588,33 +1552,30 @@ public:
virtual RID render_target_get_texture(RID p_render_target) const;
virtual bool render_target_renedered_in_frame(RID p_render_target);
-
/* RENDER API */
/* all calls (inside begin/end shadow) are always warranted to be in the following order: */
virtual void begin_frame();
+ virtual void set_viewport(const VS::ViewportRect &p_viewport);
+ virtual void set_render_target(RID p_render_target, bool p_transparent_bg = false, bool p_vflip = false);
+ virtual void clear_viewport(const Color &p_color);
+ virtual void capture_viewport(Image *r_capture);
- virtual void set_viewport(const VS::ViewportRect& p_viewport);
- virtual void set_render_target(RID p_render_target,bool p_transparent_bg=false,bool p_vflip=false);
- virtual void clear_viewport(const Color& p_color);
- virtual void capture_viewport(Image* r_capture);
-
+ virtual void begin_scene(RID p_viewport_data, RID p_env, VS::ScenarioDebugMode p_debug);
- virtual void begin_scene(RID p_viewport_data,RID p_env,VS::ScenarioDebugMode p_debug);
+ virtual void begin_shadow_map(RID p_light_instance, int p_shadow_pass);
- virtual void begin_shadow_map( RID p_light_instance, int p_shadow_pass );
+ virtual void set_camera(const Transform &p_world, const CameraMatrix &p_projection, bool p_ortho_hint);
- virtual void set_camera(const Transform& p_world,const CameraMatrix& p_projection,bool p_ortho_hint);
+ virtual void add_light(RID p_light_instance); ///< all "add_light" calls happen before add_geometry calls
- virtual void add_light( RID p_light_instance ); ///< all "add_light" calls happen before add_geometry calls
+ typedef Map<StringName, Variant> ParamOverrideMap;
- typedef Map<StringName,Variant> ParamOverrideMap;
-
- virtual void add_mesh( const RID& p_mesh, const InstanceData *p_data);
- virtual void add_multimesh( const RID& p_multimesh, const InstanceData *p_data);
- virtual void add_immediate( const RID& p_immediate, const InstanceData *p_data);
- virtual void add_particles( const RID& p_particle_instance, const InstanceData *p_data);
+ virtual void add_mesh(const RID &p_mesh, const InstanceData *p_data);
+ virtual void add_multimesh(const RID &p_multimesh, const InstanceData *p_data);
+ virtual void add_immediate(const RID &p_immediate, const InstanceData *p_data);
+ virtual void add_particles(const RID &p_particle_instance, const InstanceData *p_data);
virtual void end_scene();
virtual void end_shadow_map();
@@ -1630,69 +1591,68 @@ public:
virtual void canvas_set_opacity(float p_opacity);
virtual void canvas_set_blend_mode(VS::MaterialBlendMode p_mode);
- virtual void canvas_begin_rect(const Transform2D& p_transform);
- virtual void canvas_set_clip(bool p_clip, const Rect2& p_rect);
+ virtual void canvas_begin_rect(const Transform2D &p_transform);
+ virtual void canvas_set_clip(bool p_clip, const Rect2 &p_rect);
virtual void canvas_end_rect();
- virtual void canvas_draw_line(const Point2& p_from, const Point2& p_to,const Color& p_color,float p_width,bool p_antialiased);
- virtual void canvas_draw_rect(const Rect2& p_rect, int p_flags, const Rect2& p_source,RID p_texture,const Color& p_modulate);
- virtual void canvas_draw_style_box(const Rect2& p_rect, const Rect2& p_src_region, RID p_texture,const float *p_margins, bool p_draw_center=true,const Color& p_modulate=Color(1,1,1));
- virtual void canvas_draw_primitive(const Vector<Point2>& p_points, const Vector<Color>& p_colors,const Vector<Point2>& p_uvs, RID p_texture,float p_width);
- virtual void canvas_draw_polygon(int p_vertex_count, const int* p_indices, const Vector2* p_vertices, const Vector2* p_uvs, const Color* p_colors,const RID& p_texture,bool p_singlecolor);
- virtual void canvas_set_transform(const Transform2D& p_transform);
+ virtual void canvas_draw_line(const Point2 &p_from, const Point2 &p_to, const Color &p_color, float p_width, bool p_antialiased);
+ virtual void canvas_draw_rect(const Rect2 &p_rect, int p_flags, const Rect2 &p_source, RID p_texture, const Color &p_modulate);
+ virtual void canvas_draw_style_box(const Rect2 &p_rect, const Rect2 &p_src_region, RID p_texture, const float *p_margins, bool p_draw_center = true, const Color &p_modulate = Color(1, 1, 1));
+ virtual void canvas_draw_primitive(const Vector<Point2> &p_points, const Vector<Color> &p_colors, const Vector<Point2> &p_uvs, RID p_texture, float p_width);
+ virtual void canvas_draw_polygon(int p_vertex_count, const int *p_indices, const Vector2 *p_vertices, const Vector2 *p_uvs, const Color *p_colors, const RID &p_texture, bool p_singlecolor);
+ virtual void canvas_set_transform(const Transform2D &p_transform);
- virtual void canvas_render_items(CanvasItem *p_item_list,int p_z,const Color& p_modulate,CanvasLight *p_light);
- virtual void canvas_debug_viewport_shadows(CanvasLight* p_lights_with_shadow);
+ virtual void canvas_render_items(CanvasItem *p_item_list, int p_z, const Color &p_modulate, CanvasLight *p_light);
+ virtual void canvas_debug_viewport_shadows(CanvasLight *p_lights_with_shadow);
/* CANVAS LIGHT SHADOW */
//buffer
virtual RID canvas_light_shadow_buffer_create(int p_width);
- virtual void canvas_light_shadow_buffer_update(RID p_buffer, const Transform2D& p_light_xform, int p_light_mask,float p_near, float p_far, CanvasLightOccluderInstance* p_occluders, CameraMatrix *p_xform_cache);
+ virtual void canvas_light_shadow_buffer_update(RID p_buffer, const Transform2D &p_light_xform, int p_light_mask, float p_near, float p_far, CanvasLightOccluderInstance *p_occluders, CameraMatrix *p_xform_cache);
//occluder
virtual RID canvas_light_occluder_create();
- virtual void canvas_light_occluder_set_polylines(RID p_occluder, const DVector<Vector2>& p_lines);
+ virtual void canvas_light_occluder_set_polylines(RID p_occluder, const DVector<Vector2> &p_lines);
/* ENVIRONMENT */
-
virtual RID environment_create();
- virtual void environment_set_background(RID p_env,VS::EnvironmentBG p_bg);
+ virtual void environment_set_background(RID p_env, VS::EnvironmentBG p_bg);
virtual VS::EnvironmentBG environment_get_background(RID p_env) const;
- virtual void environment_set_background_param(RID p_env,VS::EnvironmentBGParam p_param, const Variant& p_value);
- virtual Variant environment_get_background_param(RID p_env,VS::EnvironmentBGParam p_param) const;
+ virtual void environment_set_background_param(RID p_env, VS::EnvironmentBGParam p_param, const Variant &p_value);
+ virtual Variant environment_get_background_param(RID p_env, VS::EnvironmentBGParam p_param) const;
- virtual void environment_set_enable_fx(RID p_env,VS::EnvironmentFx p_effect,bool p_enabled);
- virtual bool environment_is_fx_enabled(RID p_env,VS::EnvironmentFx p_effect) const;
+ virtual void environment_set_enable_fx(RID p_env, VS::EnvironmentFx p_effect, bool p_enabled);
+ virtual bool environment_is_fx_enabled(RID p_env, VS::EnvironmentFx p_effect) const;
- virtual void environment_fx_set_param(RID p_env,VS::EnvironmentFxParam p_param,const Variant& p_value);
- virtual Variant environment_fx_get_param(RID p_env,VS::EnvironmentFxParam p_param) const;
+ virtual void environment_fx_set_param(RID p_env, VS::EnvironmentFxParam p_param, const Variant &p_value);
+ virtual Variant environment_fx_get_param(RID p_env, VS::EnvironmentFxParam p_param) const;
/* SAMPLED LIGHT */
- virtual RID sampled_light_dp_create(int p_width,int p_height);
+ virtual RID sampled_light_dp_create(int p_width, int p_height);
virtual void sampled_light_dp_update(RID p_sampled_light, const Color *p_data, float p_multiplier);
/*MISC*/
- virtual bool is_texture(const RID& p_rid) const;
- virtual bool is_material(const RID& p_rid) const;
- virtual bool is_mesh(const RID& p_rid) const;
- virtual bool is_immediate(const RID& p_rid) const;
- virtual bool is_multimesh(const RID& p_rid) const;
+ virtual bool is_texture(const RID &p_rid) const;
+ virtual bool is_material(const RID &p_rid) const;
+ virtual bool is_mesh(const RID &p_rid) const;
+ virtual bool is_immediate(const RID &p_rid) const;
+ virtual bool is_multimesh(const RID &p_rid) const;
virtual bool is_particles(const RID &p_beam) const;
- virtual bool is_light(const RID& p_rid) const;
- virtual bool is_light_instance(const RID& p_rid) const;
- virtual bool is_particles_instance(const RID& p_rid) const;
- virtual bool is_skeleton(const RID& p_rid) const;
- virtual bool is_environment(const RID& p_rid) const;
- virtual bool is_shader(const RID& p_rid) const;
+ virtual bool is_light(const RID &p_rid) const;
+ virtual bool is_light_instance(const RID &p_rid) const;
+ virtual bool is_particles_instance(const RID &p_rid) const;
+ virtual bool is_skeleton(const RID &p_rid) const;
+ virtual bool is_environment(const RID &p_rid) const;
+ virtual bool is_shader(const RID &p_rid) const;
- virtual bool is_canvas_light_occluder(const RID& p_rid) const;
+ virtual bool is_canvas_light_occluder(const RID &p_rid) const;
- virtual void free(const RID& p_rid);
+ virtual void free(const RID &p_rid);
virtual void init();
virtual void finish();
@@ -1710,14 +1670,14 @@ public:
void reload_vram();
virtual bool has_feature(VS::Features p_feature) const;
-
+
virtual void restore_framebuffer();
- static RasterizerGLES2* get_singleton();
+ static RasterizerGLES2 *get_singleton();
virtual void set_force_16_bits_fbo(bool p_force);
- RasterizerGLES2(bool p_compress_arrays=false,bool p_keep_ram_copy=true,bool p_default_fragment_lighting=true,bool p_use_reload_hooks=false);
+ RasterizerGLES2(bool p_compress_arrays = false, bool p_keep_ram_copy = true, bool p_default_fragment_lighting = true, bool p_use_reload_hooks = false);
virtual ~RasterizerGLES2();
};
diff --git a/drivers/gles2/rasterizer_instance_gles2.cpp b/drivers/gles2/rasterizer_instance_gles2.cpp
index 647f526147..47bf6d11ff 100644
--- a/drivers/gles2/rasterizer_instance_gles2.cpp
+++ b/drivers/gles2/rasterizer_instance_gles2.cpp
@@ -33,8 +33,7 @@
Rasterizer *instance_RasterizerGLES2() {
- return memnew( RasterizerGLES2 );
+ return memnew(RasterizerGLES2);
}
-
#endif
diff --git a/drivers/gles2/rasterizer_instance_gles2.h b/drivers/gles2/rasterizer_instance_gles2.h
index 51754e0f8a..329e4e2739 100644
--- a/drivers/gles2/rasterizer_instance_gles2.h
+++ b/drivers/gles2/rasterizer_instance_gles2.h
@@ -33,7 +33,6 @@
#ifdef GLES2_ENABLED
-
Rasterizer *instance_RasterizerGLES2();
#endif
diff --git a/drivers/gles2/shader_compiler_gles2.cpp b/drivers/gles2/shader_compiler_gles2.cpp
index a5aa570e33..25decb37a2 100644
--- a/drivers/gles2/shader_compiler_gles2.cpp
+++ b/drivers/gles2/shader_compiler_gles2.cpp
@@ -38,14 +38,13 @@ typedef ShaderLanguage SL;
struct CodeGLSL2 {
String code;
-
};
static String _mktab(int p_level) {
String tb;
- for(int i=0;i<p_level;i++) {
- tb+="\t";
+ for (int i = 0; i < p_level; i++) {
+ tb += "\t";
}
return tb;
@@ -53,7 +52,7 @@ static String _mktab(int p_level) {
static String _typestr(SL::DataType p_type) {
- switch(p_type) {
+ switch (p_type) {
case SL::TYPE_VOID: return "void";
case SL::TYPE_BOOL: return "bool";
@@ -77,7 +76,7 @@ static String _mknum(float p_num) {
static String _opstr(SL::Operator p_op) {
- switch(p_op) {
+ switch (p_op) {
case SL::OP_ASSIGN: return "=";
case SL::OP_ADD: return "+";
case SL::OP_SUB: return "-";
@@ -103,7 +102,6 @@ static String _opstr(SL::Operator p_op) {
return "";
}
-
//#ifdef DEBUG_SHADER_ENABLED
#if 1
#define ENDL "\n"
@@ -111,275 +109,278 @@ static String _opstr(SL::Operator p_op) {
#define ENDL ""
#endif
-
-
-String ShaderCompilerGLES2::dump_node_code(SL::Node *p_node,int p_level,bool p_assign_left) {
+String ShaderCompilerGLES2::dump_node_code(SL::Node *p_node, int p_level, bool p_assign_left) {
String code;
- switch(p_node->type) {
+ switch (p_node->type) {
case SL::Node::TYPE_PROGRAM: {
- SL::ProgramNode *pnode=(SL::ProgramNode*)p_node;
+ SL::ProgramNode *pnode = (SL::ProgramNode *)p_node;
- code+=dump_node_code(pnode->body,p_level);
+ code += dump_node_code(pnode->body, p_level);
} break;
case SL::Node::TYPE_FUNCTION: {
} break;
case SL::Node::TYPE_BLOCK: {
- SL::BlockNode *bnode=(SL::BlockNode*)p_node;
+ SL::BlockNode *bnode = (SL::BlockNode *)p_node;
//variables
- code+="{" ENDL;
- for(Map<StringName,SL::DataType>::Element *E=bnode->variables.front();E;E=E->next()) {
+ code += "{" ENDL;
+ for (Map<StringName, SL::DataType>::Element *E = bnode->variables.front(); E; E = E->next()) {
- code+=_mktab(p_level)+_typestr(E->value())+" "+replace_string(E->key())+";" ENDL;
+ code += _mktab(p_level) + _typestr(E->value()) + " " + replace_string(E->key()) + ";" ENDL;
}
- for(int i=0;i<bnode->statements.size();i++) {
+ for (int i = 0; i < bnode->statements.size(); i++) {
- code+=_mktab(p_level)+dump_node_code(bnode->statements[i],p_level)+";" ENDL;
+ code += _mktab(p_level) + dump_node_code(bnode->statements[i], p_level) + ";" ENDL;
}
- code+="}" ENDL;
+ code += "}" ENDL;
} break;
case SL::Node::TYPE_VARIABLE: {
- SL::VariableNode *vnode=(SL::VariableNode*)p_node;
+ SL::VariableNode *vnode = (SL::VariableNode *)p_node;
- if (type==ShaderLanguage::SHADER_MATERIAL_VERTEX) {
+ if (type == ShaderLanguage::SHADER_MATERIAL_VERTEX) {
- if (vnode->name==vname_vertex && p_assign_left) {
- vertex_code_writes_vertex=true;
+ if (vnode->name == vname_vertex && p_assign_left) {
+ vertex_code_writes_vertex = true;
}
if (vnode->name == vname_position && p_assign_left) {
vertex_code_writes_position = true;
}
- if (vnode->name==vname_color_interp) {
- flags->use_color_interp=true;
+ if (vnode->name == vname_color_interp) {
+ flags->use_color_interp = true;
}
- if (vnode->name==vname_uv_interp) {
- flags->use_uv_interp=true;
+ if (vnode->name == vname_uv_interp) {
+ flags->use_uv_interp = true;
}
- if (vnode->name==vname_uv2_interp) {
- flags->use_uv2_interp=true;
+ if (vnode->name == vname_uv2_interp) {
+ flags->use_uv2_interp = true;
}
- if (vnode->name==vname_var1_interp) {
- flags->use_var1_interp=true;
+ if (vnode->name == vname_var1_interp) {
+ flags->use_var1_interp = true;
}
- if (vnode->name==vname_var2_interp) {
- flags->use_var2_interp=true;
+ if (vnode->name == vname_var2_interp) {
+ flags->use_var2_interp = true;
}
- if (vnode->name==vname_tangent_interp || vnode->name==vname_binormal_interp) {
- flags->use_tangent_interp=true;
+ if (vnode->name == vname_tangent_interp || vnode->name == vname_binormal_interp) {
+ flags->use_tangent_interp = true;
}
-
-
}
+ if (type == ShaderLanguage::SHADER_MATERIAL_FRAGMENT) {
-
- if (type==ShaderLanguage::SHADER_MATERIAL_FRAGMENT) {
-
- if (vnode->name==vname_discard) {
- uses_discard=true;
+ if (vnode->name == vname_discard) {
+ uses_discard = true;
}
- if (vnode->name==vname_normalmap) {
- uses_normalmap=true;
+ if (vnode->name == vname_normalmap) {
+ uses_normalmap = true;
}
- if (vnode->name==vname_screen_uv) {
- uses_screen_uv=true;
+ if (vnode->name == vname_screen_uv) {
+ uses_screen_uv = true;
}
- if (vnode->name==vname_diffuse_alpha && p_assign_left) {
- uses_alpha=true;
+ if (vnode->name == vname_diffuse_alpha && p_assign_left) {
+ uses_alpha = true;
}
- if (vnode->name==vname_color_interp) {
- flags->use_color_interp=true;
+ if (vnode->name == vname_color_interp) {
+ flags->use_color_interp = true;
}
- if (vnode->name==vname_uv_interp) {
- flags->use_uv_interp=true;
+ if (vnode->name == vname_uv_interp) {
+ flags->use_uv_interp = true;
}
- if (vnode->name==vname_uv2_interp) {
- flags->use_uv2_interp=true;
+ if (vnode->name == vname_uv2_interp) {
+ flags->use_uv2_interp = true;
}
- if (vnode->name==vname_var1_interp) {
- flags->use_var1_interp=true;
+ if (vnode->name == vname_var1_interp) {
+ flags->use_var1_interp = true;
}
- if (vnode->name==vname_var2_interp) {
- flags->use_var2_interp=true;
+ if (vnode->name == vname_var2_interp) {
+ flags->use_var2_interp = true;
}
- if (vnode->name==vname_tangent_interp || vnode->name==vname_binormal_interp) {
- flags->use_tangent_interp=true;
+ if (vnode->name == vname_tangent_interp || vnode->name == vname_binormal_interp) {
+ flags->use_tangent_interp = true;
}
-
}
- if (type==ShaderLanguage::SHADER_MATERIAL_LIGHT) {
+ if (type == ShaderLanguage::SHADER_MATERIAL_LIGHT) {
- if (vnode->name==vname_light) {
- uses_light=true;
+ if (vnode->name == vname_light) {
+ uses_light = true;
}
- if (vnode->name==vname_shadow) {
- uses_shadow_color=true;
+ if (vnode->name == vname_shadow) {
+ uses_shadow_color = true;
}
-
}
- if (type==ShaderLanguage::SHADER_CANVAS_ITEM_VERTEX) {
+ if (type == ShaderLanguage::SHADER_CANVAS_ITEM_VERTEX) {
- if (vnode->name==vname_var1_interp) {
- flags->use_var1_interp=true;
+ if (vnode->name == vname_var1_interp) {
+ flags->use_var1_interp = true;
}
- if (vnode->name==vname_var2_interp) {
- flags->use_var2_interp=true;
+ if (vnode->name == vname_var2_interp) {
+ flags->use_var2_interp = true;
}
- if (vnode->name==vname_world_vec) {
- uses_worldvec=true;
+ if (vnode->name == vname_world_vec) {
+ uses_worldvec = true;
}
-
}
+ if (type == ShaderLanguage::SHADER_CANVAS_ITEM_FRAGMENT) {
- if (type==ShaderLanguage::SHADER_CANVAS_ITEM_FRAGMENT) {
-
-
- if (vnode->name==vname_texpixel_size) {
- uses_texpixel_size=true;
+ if (vnode->name == vname_texpixel_size) {
+ uses_texpixel_size = true;
}
- if (vnode->name==vname_normal) {
- uses_normal=true;
+ if (vnode->name == vname_normal) {
+ uses_normal = true;
}
- if (vnode->name==vname_normalmap || vnode->name==vname_normalmap_depth) {
- uses_normalmap=true;
- uses_normal=true;
+ if (vnode->name == vname_normalmap || vnode->name == vname_normalmap_depth) {
+ uses_normalmap = true;
+ uses_normal = true;
}
- if (vnode->name==vname_screen_uv) {
- uses_screen_uv=true;
+ if (vnode->name == vname_screen_uv) {
+ uses_screen_uv = true;
}
- if (vnode->name==vname_var1_interp) {
- flags->use_var1_interp=true;
+ if (vnode->name == vname_var1_interp) {
+ flags->use_var1_interp = true;
}
- if (vnode->name==vname_var2_interp) {
- flags->use_var2_interp=true;
+ if (vnode->name == vname_var2_interp) {
+ flags->use_var2_interp = true;
}
}
- if (type==ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT) {
+ if (type == ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT) {
- if (vnode->name==vname_light) {
- uses_light=true;
+ if (vnode->name == vname_light) {
+ uses_light = true;
}
- if (vnode->name==vname_normal) {
- uses_normal=true;
+ if (vnode->name == vname_normal) {
+ uses_normal = true;
}
- if (vnode->name==vname_shadow) {
- uses_shadow_color=true;
+ if (vnode->name == vname_shadow) {
+ uses_shadow_color = true;
}
-
}
- if (vnode->name==vname_time) {
- uses_time=true;
+ if (vnode->name == vname_time) {
+ uses_time = true;
}
- code=replace_string(vnode->name);
+ code = replace_string(vnode->name);
} break;
case SL::Node::TYPE_CONSTANT: {
- SL::ConstantNode *cnode=(SL::ConstantNode*)p_node;
- switch(cnode->datatype) {
-
-
- case SL::TYPE_BOOL: code=cnode->value.operator bool()?"true":"false"; break;
- case SL::TYPE_FLOAT: code=_mknum(cnode->value); break; //force zeros, so GLSL doesn't confuse with integer.
- case SL::TYPE_VEC2: { Vector2 v = cnode->value; code="vec2("+_mknum(v.x)+", "+_mknum(v.y)+")"; } break;
- case SL::TYPE_VEC3: { Vector3 v = cnode->value; code="vec3("+_mknum(v.x)+", "+_mknum(v.y)+", "+_mknum(v.z)+")"; } break;
- case SL::TYPE_VEC4: { Plane v = cnode->value; code="vec4("+_mknum(v.normal.x)+", "+_mknum(v.normal.y)+", "+_mknum(v.normal.z)+", "+_mknum(v.d)+")"; } break;
- case SL::TYPE_MAT2: { Transform2D x = cnode->value; code="mat2( vec2("+_mknum(x[0][0])+", "+_mknum(x[0][1])+"), vec2("+_mknum(x[1][0])+", "+_mknum(x[1][1])+"))"; } break;
- case SL::TYPE_MAT3: { Basis x = cnode->value; code="mat3( vec3("+_mknum(x.get_axis(0).x)+", "+_mknum(x.get_axis(0).y)+", "+_mknum(x.get_axis(0).z)+"), vec3("+_mknum(x.get_axis(1).x)+", "+_mknum(x.get_axis(1).y)+", "+_mknum(x.get_axis(1).z)+"), vec3("+_mknum(x.get_axis(2).x)+", "+_mknum(x.get_axis(2).y)+", "+_mknum(x.get_axis(2).z)+"))"; } break;
- case SL::TYPE_MAT4: { Transform x = cnode->value; code="mat4( vec4("+_mknum(x.basis.get_axis(0).x)+", "+_mknum(x.basis.get_axis(0).y)+", "+_mknum(x.basis.get_axis(0).z)+",0.0), vec4("+_mknum(x.basis.get_axis(1).x)+", "+_mknum(x.basis.get_axis(1).y)+", "+_mknum(x.basis.get_axis(1).z)+",0.0), vec4("+_mknum(x.basis.get_axis(2).x)+", "+_mknum(x.basis.get_axis(2).y)+", "+_mknum(x.basis.get_axis(2).z)+",0.0), vec4("+_mknum(x.origin.x)+", "+_mknum(x.origin.y)+", "+_mknum(x.origin.z)+",1.0))"; } break;
- default: code="<error: "+Variant::get_type_name(cnode->value.get_type())+" ("+itos(cnode->datatype)+">";
+ SL::ConstantNode *cnode = (SL::ConstantNode *)p_node;
+ switch (cnode->datatype) {
+
+ case SL::TYPE_BOOL: code = cnode->value.operator bool() ? "true" : "false"; break;
+ case SL::TYPE_FLOAT:
+ code = _mknum(cnode->value);
+ break; //force zeros, so GLSL doesn't confuse with integer.
+ case SL::TYPE_VEC2: {
+ Vector2 v = cnode->value;
+ code = "vec2(" + _mknum(v.x) + ", " + _mknum(v.y) + ")";
+ } break;
+ case SL::TYPE_VEC3: {
+ Vector3 v = cnode->value;
+ code = "vec3(" + _mknum(v.x) + ", " + _mknum(v.y) + ", " + _mknum(v.z) + ")";
+ } break;
+ case SL::TYPE_VEC4: {
+ Plane v = cnode->value;
+ code = "vec4(" + _mknum(v.normal.x) + ", " + _mknum(v.normal.y) + ", " + _mknum(v.normal.z) + ", " + _mknum(v.d) + ")";
+ } break;
+ case SL::TYPE_MAT2: {
+ Transform2D x = cnode->value;
+ code = "mat2( vec2(" + _mknum(x[0][0]) + ", " + _mknum(x[0][1]) + "), vec2(" + _mknum(x[1][0]) + ", " + _mknum(x[1][1]) + "))";
+ } break;
+ case SL::TYPE_MAT3: {
+ Basis x = cnode->value;
+ code = "mat3( vec3(" + _mknum(x.get_axis(0).x) + ", " + _mknum(x.get_axis(0).y) + ", " + _mknum(x.get_axis(0).z) + "), vec3(" + _mknum(x.get_axis(1).x) + ", " + _mknum(x.get_axis(1).y) + ", " + _mknum(x.get_axis(1).z) + "), vec3(" + _mknum(x.get_axis(2).x) + ", " + _mknum(x.get_axis(2).y) + ", " + _mknum(x.get_axis(2).z) + "))";
+ } break;
+ case SL::TYPE_MAT4: {
+ Transform x = cnode->value;
+ code = "mat4( vec4(" + _mknum(x.basis.get_axis(0).x) + ", " + _mknum(x.basis.get_axis(0).y) + ", " + _mknum(x.basis.get_axis(0).z) + ",0.0), vec4(" + _mknum(x.basis.get_axis(1).x) + ", " + _mknum(x.basis.get_axis(1).y) + ", " + _mknum(x.basis.get_axis(1).z) + ",0.0), vec4(" + _mknum(x.basis.get_axis(2).x) + ", " + _mknum(x.basis.get_axis(2).y) + ", " + _mknum(x.basis.get_axis(2).z) + ",0.0), vec4(" + _mknum(x.origin.x) + ", " + _mknum(x.origin.y) + ", " + _mknum(x.origin.z) + ",1.0))";
+ } break;
+ default: code = "<error: " + Variant::get_type_name(cnode->value.get_type()) + " (" + itos(cnode->datatype) + ">";
}
} break;
case SL::Node::TYPE_OPERATOR: {
- SL::OperatorNode *onode=(SL::OperatorNode*)p_node;
+ SL::OperatorNode *onode = (SL::OperatorNode *)p_node;
-
- switch(onode->op) {
+ switch (onode->op) {
case SL::OP_ASSIGN_MUL: {
+ if (onode->arguments[0]->get_datatype() == SL::TYPE_VEC3 && onode->arguments[1]->get_datatype() == SL::TYPE_MAT4) {
- if (onode->arguments[0]->get_datatype()==SL::TYPE_VEC3 && onode->arguments[1]->get_datatype()==SL::TYPE_MAT4) {
-
- String mul_l=dump_node_code(onode->arguments[0],p_level,true);
- String mul_r=dump_node_code(onode->arguments[1],p_level);
- code=mul_l+"=(vec4("+mul_l+",1.0)*("+mul_r+")).xyz";
+ String mul_l = dump_node_code(onode->arguments[0], p_level, true);
+ String mul_r = dump_node_code(onode->arguments[1], p_level);
+ code = mul_l + "=(vec4(" + mul_l + ",1.0)*(" + mul_r + ")).xyz";
break;
- } else if (onode->arguments[0]->get_datatype()==SL::TYPE_MAT4 && onode->arguments[1]->get_datatype()==SL::TYPE_VEC3) {
+ } else if (onode->arguments[0]->get_datatype() == SL::TYPE_MAT4 && onode->arguments[1]->get_datatype() == SL::TYPE_VEC3) {
- String mul_l=dump_node_code(onode->arguments[0],p_level,true);
- String mul_r=dump_node_code(onode->arguments[1],p_level);
- code=mul_l+"=(("+mul_l+")*vec4("+mul_r+",1.0)).xyz";
+ String mul_l = dump_node_code(onode->arguments[0], p_level, true);
+ String mul_r = dump_node_code(onode->arguments[1], p_level);
+ code = mul_l + "=((" + mul_l + ")*vec4(" + mul_r + ",1.0)).xyz";
break;
- } else if (onode->arguments[0]->get_datatype()==SL::TYPE_VEC2 && onode->arguments[1]->get_datatype()==SL::TYPE_MAT4) {
+ } else if (onode->arguments[0]->get_datatype() == SL::TYPE_VEC2 && onode->arguments[1]->get_datatype() == SL::TYPE_MAT4) {
- String mul_l=dump_node_code(onode->arguments[0],p_level,true);
- String mul_r=dump_node_code(onode->arguments[1],p_level);
- code=mul_l+"=(vec4("+mul_l+",0.0,1.0)*("+mul_r+")).xy";
+ String mul_l = dump_node_code(onode->arguments[0], p_level, true);
+ String mul_r = dump_node_code(onode->arguments[1], p_level);
+ code = mul_l + "=(vec4(" + mul_l + ",0.0,1.0)*(" + mul_r + ")).xy";
break;
- } else if (onode->arguments[0]->get_datatype()==SL::TYPE_MAT4 && onode->arguments[1]->get_datatype()==SL::TYPE_VEC2) {
+ } else if (onode->arguments[0]->get_datatype() == SL::TYPE_MAT4 && onode->arguments[1]->get_datatype() == SL::TYPE_VEC2) {
- String mul_l=dump_node_code(onode->arguments[0],p_level,true);
- String mul_r=dump_node_code(onode->arguments[1],p_level);
- code=mul_l+"=(("+mul_l+")*vec4("+mul_r+",0.0,1.0)).xy";
+ String mul_l = dump_node_code(onode->arguments[0], p_level, true);
+ String mul_r = dump_node_code(onode->arguments[1], p_level);
+ code = mul_l + "=((" + mul_l + ")*vec4(" + mul_r + ",0.0,1.0)).xy";
break;
- } else if (onode->arguments[0]->get_datatype()==SL::TYPE_VEC2 && onode->arguments[1]->get_datatype()==SL::TYPE_MAT3) {
- String mul_l=dump_node_code(onode->arguments[0],p_level,true);
- String mul_r=dump_node_code(onode->arguments[1],p_level);
- code=mul_l+"=(("+mul_l+")*vec3("+mul_r+",1.0)).xy";
+ } else if (onode->arguments[0]->get_datatype() == SL::TYPE_VEC2 && onode->arguments[1]->get_datatype() == SL::TYPE_MAT3) {
+ String mul_l = dump_node_code(onode->arguments[0], p_level, true);
+ String mul_r = dump_node_code(onode->arguments[1], p_level);
+ code = mul_l + "=((" + mul_l + ")*vec3(" + mul_r + ",1.0)).xy";
break;
}
-
-
};
case SL::OP_ASSIGN:
case SL::OP_ASSIGN_ADD:
case SL::OP_ASSIGN_SUB:
case SL::OP_ASSIGN_DIV:
- code="("+dump_node_code(onode->arguments[0],p_level,true)+_opstr(onode->op)+dump_node_code(onode->arguments[1],p_level)+")";
+ code = "(" + dump_node_code(onode->arguments[0], p_level, true) + _opstr(onode->op) + dump_node_code(onode->arguments[1], p_level) + ")";
break;
case SL::OP_MUL:
- if (onode->arguments[0]->get_datatype()==SL::TYPE_MAT4 && onode->arguments[1]->get_datatype()==SL::TYPE_VEC3) {
+ if (onode->arguments[0]->get_datatype() == SL::TYPE_MAT4 && onode->arguments[1]->get_datatype() == SL::TYPE_VEC3) {
- code="("+dump_node_code(onode->arguments[0],p_level)+"*vec4("+dump_node_code(onode->arguments[1],p_level)+",1.0)).xyz";
+ code = "(" + dump_node_code(onode->arguments[0], p_level) + "*vec4(" + dump_node_code(onode->arguments[1], p_level) + ",1.0)).xyz";
break;
- } else if (onode->arguments[0]->get_datatype()==SL::TYPE_VEC3 && onode->arguments[1]->get_datatype()==SL::TYPE_MAT4) {
+ } else if (onode->arguments[0]->get_datatype() == SL::TYPE_VEC3 && onode->arguments[1]->get_datatype() == SL::TYPE_MAT4) {
- code="(vec4("+dump_node_code(onode->arguments[0],p_level)+",1.0)*"+dump_node_code(onode->arguments[1],p_level)+").xyz";
+ code = "(vec4(" + dump_node_code(onode->arguments[0], p_level) + ",1.0)*" + dump_node_code(onode->arguments[1], p_level) + ").xyz";
break;
- } else if (onode->arguments[0]->get_datatype()==SL::TYPE_MAT4 && onode->arguments[1]->get_datatype()==SL::TYPE_VEC2) {
+ } else if (onode->arguments[0]->get_datatype() == SL::TYPE_MAT4 && onode->arguments[1]->get_datatype() == SL::TYPE_VEC2) {
- code="("+dump_node_code(onode->arguments[0],p_level)+"*vec4("+dump_node_code(onode->arguments[1],p_level)+",0.0,1.0)).xy";
+ code = "(" + dump_node_code(onode->arguments[0], p_level) + "*vec4(" + dump_node_code(onode->arguments[1], p_level) + ",0.0,1.0)).xy";
break;
- } else if (onode->arguments[0]->get_datatype()==SL::TYPE_VEC2 && onode->arguments[1]->get_datatype()==SL::TYPE_MAT4) {
+ } else if (onode->arguments[0]->get_datatype() == SL::TYPE_VEC2 && onode->arguments[1]->get_datatype() == SL::TYPE_MAT4) {
- code="(vec4("+dump_node_code(onode->arguments[0],p_level)+",0.0,1.0)*"+dump_node_code(onode->arguments[1],p_level)+").xy";
+ code = "(vec4(" + dump_node_code(onode->arguments[0], p_level) + ",0.0,1.0)*" + dump_node_code(onode->arguments[1], p_level) + ").xy";
break;
- } else if (onode->arguments[0]->get_datatype()==SL::TYPE_MAT3 && onode->arguments[1]->get_datatype()==SL::TYPE_VEC2) {
+ } else if (onode->arguments[0]->get_datatype() == SL::TYPE_MAT3 && onode->arguments[1]->get_datatype() == SL::TYPE_VEC2) {
- code="("+dump_node_code(onode->arguments[0],p_level)+"*vec3("+dump_node_code(onode->arguments[1],p_level)+",1.0)).xy";
+ code = "(" + dump_node_code(onode->arguments[0], p_level) + "*vec3(" + dump_node_code(onode->arguments[1], p_level) + ",1.0)).xy";
break;
- } else if (onode->arguments[0]->get_datatype()==SL::TYPE_VEC2 && onode->arguments[1]->get_datatype()==SL::TYPE_MAT3) {
+ } else if (onode->arguments[0]->get_datatype() == SL::TYPE_VEC2 && onode->arguments[1]->get_datatype() == SL::TYPE_MAT3) {
- code="(vec3("+dump_node_code(onode->arguments[0],p_level)+",1.0)*"+dump_node_code(onode->arguments[1],p_level)+").xy";
+ code = "(vec3(" + dump_node_code(onode->arguments[0], p_level) + ",1.0)*" + dump_node_code(onode->arguments[1], p_level) + ").xy";
break;
}
@@ -395,19 +396,18 @@ String ShaderCompilerGLES2::dump_node_code(SL::Node *p_node,int p_level,bool p_a
case SL::OP_CMP_OR:
case SL::OP_CMP_AND:
//handle binary
- code="("+dump_node_code(onode->arguments[0],p_level)+_opstr(onode->op)+dump_node_code(onode->arguments[1],p_level)+")";
+ code = "(" + dump_node_code(onode->arguments[0], p_level) + _opstr(onode->op) + dump_node_code(onode->arguments[1], p_level) + ")";
break;
case SL::OP_NEG:
case SL::OP_NOT:
//handle unary
- code=_opstr(onode->op)+dump_node_code(onode->arguments[0],p_level);
+ code = _opstr(onode->op) + dump_node_code(onode->arguments[0], p_level);
break;
case SL::OP_CONSTRUCT:
case SL::OP_CALL: {
- String callfunc=dump_node_code(onode->arguments[0],p_level);
-
+ String callfunc = dump_node_code(onode->arguments[0], p_level);
- code=callfunc+"(";
+ code = callfunc + "(";
/*if (callfunc=="mat4") {
//fix constructor for mat4
for(int i=1;i<onode->arguments.size();i++) {
@@ -417,78 +417,80 @@ String ShaderCompilerGLES2::dump_node_code(SL::Node *p_node,int p_level,bool p_a
code+="vec4( "+dump_node_code(onode->arguments[i],p_level)+(i==4?",1.0)":",0.0)");
}
- } else*/ if (callfunc=="tex") {
+ } else*/ if (callfunc == "tex") {
- code="texture2D( "+dump_node_code(onode->arguments[1],p_level)+","+dump_node_code(onode->arguments[2],p_level)+")";
+ code = "texture2D( " + dump_node_code(onode->arguments[1], p_level) + "," + dump_node_code(onode->arguments[2], p_level) + ")";
break;
- } else if (callfunc=="texcube") {
+ } else if (callfunc == "texcube") {
- code="(textureCube( "+dump_node_code(onode->arguments[1],p_level)+",("+dump_node_code(onode->arguments[2],p_level)+")).xyz";
+ code = "(textureCube( " + dump_node_code(onode->arguments[1], p_level) + ",(" + dump_node_code(onode->arguments[2], p_level) + ")).xyz";
break;
- } else if (callfunc=="texscreen") {
+ } else if (callfunc == "texscreen") {
//create the call to sample the screen, and clamp it
- uses_texscreen=true;
- code="(texture2D( texscreen_tex, clamp(("+dump_node_code(onode->arguments[1],p_level)+").xy*texscreen_screen_mult,texscreen_screen_clamp.xy,texscreen_screen_clamp.zw))).rgb";
+ uses_texscreen = true;
+ code = "(texture2D( texscreen_tex, clamp((" + dump_node_code(onode->arguments[1], p_level) + ").xy*texscreen_screen_mult,texscreen_screen_clamp.xy,texscreen_screen_clamp.zw))).rgb";
//code="(texture2D( screen_texture, ("+dump_node_code(onode->arguments[1],p_level)+").xy).rgb";
break;
- } else if (callfunc=="texpos") {
+ } else if (callfunc == "texpos") {
//create the call to sample the screen, and clamp it
- uses_texpos=true;
- code="get_texpos("+dump_node_code(onode->arguments[1],p_level)+"";
+ uses_texpos = true;
+ code = "get_texpos(" + dump_node_code(onode->arguments[1], p_level) + "";
//code="get_texpos(gl_ProjectionMatrixInverse * texture2D( depth_texture, clamp(("+dump_node_code(onode->arguments[1],p_level)+").xy,vec2(0.0),vec2(1.0))*gl_LightSource[5].specular.zw+gl_LightSource[5].specular.xy)";
//code="(texture2D( screen_texture, ("+dump_node_code(onode->arguments[1],p_level)+").xy).rgb";
break;
- } else if (custom_h && callfunc=="cosh_custom") {
+ } else if (custom_h && callfunc == "cosh_custom") {
if (!cosh_used) {
- global_code=
- "float cosh_custom(float val)\n"\
- "{\n"\
- " float tmp = exp(val);\n"\
- " float cosH = (tmp + 1.0 / tmp) / 2.0;\n"\
- " return cosH;\n"\
- "}\n"+global_code;
- cosh_used=true;
+ global_code =
+ "float cosh_custom(float val)\n"
+ "{\n"
+ " float tmp = exp(val);\n"
+ " float cosH = (tmp + 1.0 / tmp) / 2.0;\n"
+ " return cosH;\n"
+ "}\n" +
+ global_code;
+ cosh_used = true;
}
- code="cosh_custom("+dump_node_code(onode->arguments[1],p_level)+"";
- } else if (custom_h && callfunc=="sinh_custom") {
+ code = "cosh_custom(" + dump_node_code(onode->arguments[1], p_level) + "";
+ } else if (custom_h && callfunc == "sinh_custom") {
if (!sinh_used) {
- global_code=
- "float sinh_custom(float val)\n"\
- "{\n"\
- " float tmp = exp(val);\n"\
- " float sinH = (tmp - 1.0 / tmp) / 2.0;\n"\
- " return sinH;\n"\
- "}\n"+global_code;
- sinh_used=true;
+ global_code =
+ "float sinh_custom(float val)\n"
+ "{\n"
+ " float tmp = exp(val);\n"
+ " float sinH = (tmp - 1.0 / tmp) / 2.0;\n"
+ " return sinH;\n"
+ "}\n" +
+ global_code;
+ sinh_used = true;
}
- code="sinh_custom("+dump_node_code(onode->arguments[1],p_level)+"";
- } else if (custom_h && callfunc=="tanh_custom") {
+ code = "sinh_custom(" + dump_node_code(onode->arguments[1], p_level) + "";
+ } else if (custom_h && callfunc == "tanh_custom") {
if (!tanh_used) {
- global_code=
- "float tanh_custom(float val)\n"\
- "{\n"\
- " float tmp = exp(val);\n"\
- " float tanH = (tmp - 1.0 / tmp) / (tmp + 1.0 / tmp);\n"\
- " return tanH;\n"\
- "}\n"+global_code;
- tanh_used=true;
+ global_code =
+ "float tanh_custom(float val)\n"
+ "{\n"
+ " float tmp = exp(val);\n"
+ " float tanH = (tmp - 1.0 / tmp) / (tmp + 1.0 / tmp);\n"
+ " return tanH;\n"
+ "}\n" +
+ global_code;
+ tanh_used = true;
}
- code="tanh_custom("+dump_node_code(onode->arguments[1],p_level)+"";
+ code = "tanh_custom(" + dump_node_code(onode->arguments[1], p_level) + "";
} else {
- for(int i=1;i<onode->arguments.size();i++) {
- if (i>1)
- code+=", ";
- //transform
- code+=dump_node_code(onode->arguments[i],p_level);
-
+ for (int i = 1; i < onode->arguments.size(); i++) {
+ if (i > 1)
+ code += ", ";
+ //transform
+ code += dump_node_code(onode->arguments[i], p_level);
}
}
- code+=")";
+ code += ")";
break;
} break;
default: {}
@@ -496,83 +498,81 @@ String ShaderCompilerGLES2::dump_node_code(SL::Node *p_node,int p_level,bool p_a
} break;
case SL::Node::TYPE_CONTROL_FLOW: {
- SL::ControlFlowNode *cfnode=(SL::ControlFlowNode*)p_node;
- if (cfnode->flow_op==SL::FLOW_OP_IF) {
+ SL::ControlFlowNode *cfnode = (SL::ControlFlowNode *)p_node;
+ if (cfnode->flow_op == SL::FLOW_OP_IF) {
- code+="if ("+dump_node_code(cfnode->statements[0],p_level)+") {" ENDL;
- code+=dump_node_code(cfnode->statements[1],p_level+1);
- if (cfnode->statements.size()==3) {
+ code += "if (" + dump_node_code(cfnode->statements[0], p_level) + ") {" ENDL;
+ code += dump_node_code(cfnode->statements[1], p_level + 1);
+ if (cfnode->statements.size() == 3) {
- code+="} else {" ENDL;
- code+=dump_node_code(cfnode->statements[2],p_level+1);
+ code += "} else {" ENDL;
+ code += dump_node_code(cfnode->statements[2], p_level + 1);
}
- code+="}" ENDL;
+ code += "}" ENDL;
- } else if (cfnode->flow_op==SL::FLOW_OP_RETURN) {
+ } else if (cfnode->flow_op == SL::FLOW_OP_RETURN) {
if (cfnode->statements.size()) {
- code="return "+dump_node_code(cfnode->statements[0],p_level);
+ code = "return " + dump_node_code(cfnode->statements[0], p_level);
} else {
- code="return";
+ code = "return";
}
}
} break;
case SL::Node::TYPE_MEMBER: {
- SL::MemberNode *mnode=(SL::MemberNode*)p_node;
+ SL::MemberNode *mnode = (SL::MemberNode *)p_node;
String m;
- if (mnode->basetype==SL::TYPE_MAT4) {
- if (mnode->name=="x")
- m="[0]";
- else if (mnode->name=="y")
- m="[1]";
- else if (mnode->name=="z")
- m="[2]";
- else if (mnode->name=="w")
- m="[3]";
- } else if (mnode->basetype==SL::TYPE_MAT2) {
- if (mnode->name=="x")
- m="[0]";
- else if (mnode->name=="y")
- m="[1]";
-
- } else if (mnode->basetype==SL::TYPE_MAT3) {
- if (mnode->name=="x")
- m="[0]";
- else if (mnode->name=="y")
- m="[1]";
- else if (mnode->name=="z")
- m="[2]";
+ if (mnode->basetype == SL::TYPE_MAT4) {
+ if (mnode->name == "x")
+ m = "[0]";
+ else if (mnode->name == "y")
+ m = "[1]";
+ else if (mnode->name == "z")
+ m = "[2]";
+ else if (mnode->name == "w")
+ m = "[3]";
+ } else if (mnode->basetype == SL::TYPE_MAT2) {
+ if (mnode->name == "x")
+ m = "[0]";
+ else if (mnode->name == "y")
+ m = "[1]";
+
+ } else if (mnode->basetype == SL::TYPE_MAT3) {
+ if (mnode->name == "x")
+ m = "[0]";
+ else if (mnode->name == "y")
+ m = "[1]";
+ else if (mnode->name == "z")
+ m = "[2]";
} else {
- m="."+mnode->name;
+ m = "." + mnode->name;
}
- code=dump_node_code(mnode->owner,p_level)+m;
+ code = dump_node_code(mnode->owner, p_level) + m;
} break;
}
return code;
-
}
-
Error ShaderCompilerGLES2::compile_node(SL::ProgramNode *p_program) {
// feed the local replace table and global code
- global_code="";
+ global_code = "";
// uniforms first!
- int ubase=0;
+ int ubase = 0;
if (uniforms)
- ubase=uniforms->size();
- for(Map<StringName,SL::Uniform>::Element *E=p_program->uniforms.front();E;E=E->next()) {
+ ubase = uniforms->size();
+ for (Map<StringName, SL::Uniform>::Element *E = p_program->uniforms.front(); E; E = E->next()) {
- String uline="uniform "+_typestr(E->get().type)+" _"+E->key().operator String()+";" ENDL;
+ String uline = "uniform " + _typestr(E->get().type) + " _" + E->key().operator String() + ";" ENDL;
- global_code+=uline;
+ global_code += uline;
if (uniforms) {
/*
if (uniforms->has(E->key())) {
@@ -582,138 +582,134 @@ Error ShaderCompilerGLES2::compile_node(SL::ProgramNode *p_program) {
}
*/
SL::Uniform u = E->get();
- u.order+=ubase;
- uniforms->insert(E->key(),u);
+ u.order += ubase;
+ uniforms->insert(E->key(), u);
}
}
- for(int i=0;i<p_program->functions.size();i++) {
-
+ for (int i = 0; i < p_program->functions.size(); i++) {
- SL::FunctionNode *fnode=p_program->functions[i].function;
+ SL::FunctionNode *fnode = p_program->functions[i].function;
- StringName funcname=fnode->name;
- String newfuncname=replace_string(funcname);
+ StringName funcname = fnode->name;
+ String newfuncname = replace_string(funcname);
String header;
- header=_typestr(fnode->return_type)+" "+newfuncname+"(";
- for(int i=0;i<fnode->arguments.size();i++) {
+ header = _typestr(fnode->return_type) + " " + newfuncname + "(";
+ for (int i = 0; i < fnode->arguments.size(); i++) {
- if (i>0)
- header+=", ";
- header+=_typestr(fnode->arguments[i].type)+" "+replace_string(fnode->arguments[i].name);
+ if (i > 0)
+ header += ", ";
+ header += _typestr(fnode->arguments[i].type) + " " + replace_string(fnode->arguments[i].name);
}
- header+=") {" ENDL;
- String fcode=header;
- fcode+=dump_node_code(fnode->body,1);
- fcode+="}" ENDL;
- global_code+=fcode;
-
+ header += ") {" ENDL;
+ String fcode = header;
+ fcode += dump_node_code(fnode->body, 1);
+ fcode += "}" ENDL;
+ global_code += fcode;
}
-/* for(Map<StringName,SL::DataType>::Element *E=p_program->preexisting_variables.front();E;E=E->next()) {
+ /* for(Map<StringName,SL::DataType>::Element *E=p_program->preexisting_variables.front();E;E=E->next()) {
StringName varname=E->key();
String newvarname=replace_string(varname);
global_code+="uniform "+_typestr(E->get())+" "+newvarname+";" ENDL;
}*/
- code=dump_node_code(p_program,0);
+ code = dump_node_code(p_program, 0);
#ifdef DEBUG_SHADER_ENABLED
print_line("GLOBAL CODE:\n\n");
print_line(global_code);
- global_code=global_code.replace("\n","");
+ global_code = global_code.replace("\n", "");
print_line("CODE:\n\n");
print_line(code);
- code=code.replace("\n","");
+ code = code.replace("\n", "");
#endif
return OK;
}
-Error ShaderCompilerGLES2::create_glsl_120_code(void *p_str,SL::ProgramNode *p_program) {
+Error ShaderCompilerGLES2::create_glsl_120_code(void *p_str, SL::ProgramNode *p_program) {
- ShaderCompilerGLES2 *compiler=(ShaderCompilerGLES2*)p_str;
+ ShaderCompilerGLES2 *compiler = (ShaderCompilerGLES2 *)p_str;
return compiler->compile_node(p_program);
}
+String ShaderCompilerGLES2::replace_string(const StringName &p_string) {
-String ShaderCompilerGLES2::replace_string(const StringName& p_string) {
-
- Map<StringName,StringName>::Element *E=NULL;
- E=replace_table.find(p_string);
+ Map<StringName, StringName>::Element *E = NULL;
+ E = replace_table.find(p_string);
if (E)
return E->get();
- E=mode_replace_table[type].find(p_string);
+ E = mode_replace_table[type].find(p_string);
if (E)
return E->get();
-
- return "_"+p_string.operator String();
+ return "_" + p_string.operator String();
}
-Error ShaderCompilerGLES2::compile(const String& p_code, ShaderLanguage::ShaderType p_type, String& r_code_line, String& r_globals_line, Flags& r_flags, Map<StringName,ShaderLanguage::Uniform> *r_uniforms) {
-
- uses_texscreen=false;
- uses_texpos=false;
- uses_alpha=false;
- uses_discard=false;
- uses_screen_uv=false;
- uses_light=false;
- uses_time=false;
- uses_normalmap=false;
- uses_normal=false;
- uses_texpixel_size=false;
- uses_worldvec=false;
- vertex_code_writes_vertex=false;
+Error ShaderCompilerGLES2::compile(const String &p_code, ShaderLanguage::ShaderType p_type, String &r_code_line, String &r_globals_line, Flags &r_flags, Map<StringName, ShaderLanguage::Uniform> *r_uniforms) {
+
+ uses_texscreen = false;
+ uses_texpos = false;
+ uses_alpha = false;
+ uses_discard = false;
+ uses_screen_uv = false;
+ uses_light = false;
+ uses_time = false;
+ uses_normalmap = false;
+ uses_normal = false;
+ uses_texpixel_size = false;
+ uses_worldvec = false;
+ vertex_code_writes_vertex = false;
vertex_code_writes_position = false;
- uses_shadow_color=false;
- uniforms=r_uniforms;
- flags=&r_flags;
- r_flags.use_color_interp=false;
- r_flags.use_uv_interp=false;
- r_flags.use_uv2_interp=false;
- r_flags.use_tangent_interp=false;
- r_flags.use_var1_interp=false;
- r_flags.use_var2_interp=false;
- r_flags.uses_normalmap=false;
- r_flags.uses_normal=false;
- sinh_used=false;
- tanh_used=false;
- cosh_used=false;
+ uses_shadow_color = false;
+ uniforms = r_uniforms;
+ flags = &r_flags;
+ r_flags.use_color_interp = false;
+ r_flags.use_uv_interp = false;
+ r_flags.use_uv2_interp = false;
+ r_flags.use_tangent_interp = false;
+ r_flags.use_var1_interp = false;
+ r_flags.use_var2_interp = false;
+ r_flags.uses_normalmap = false;
+ r_flags.uses_normal = false;
+ sinh_used = false;
+ tanh_used = false;
+ cosh_used = false;
String error;
- int errline,errcol;
+ int errline, errcol;
- type=p_type;
- Error err = SL::compile(p_code,p_type,create_glsl_120_code,this,&error,&errline,&errcol);
+ type = p_type;
+ Error err = SL::compile(p_code, p_type, create_glsl_120_code, this, &error, &errline, &errcol);
if (err) {
- print_line("***Error precompiling shader: "+error);
- print_line("error "+itos(errline)+":"+itos(errcol));
+ print_line("***Error precompiling shader: " + error);
+ print_line("error " + itos(errline) + ":" + itos(errcol));
return err;
}
- r_flags.uses_alpha=uses_alpha;
- r_flags.uses_texscreen=uses_texscreen;
- r_flags.uses_texpos=uses_texpos;
- r_flags.vertex_code_writes_vertex=vertex_code_writes_vertex;
- r_flags.vertex_code_writes_position=vertex_code_writes_position;
- r_flags.uses_discard=uses_discard;
- r_flags.uses_screen_uv=uses_screen_uv;
- r_flags.uses_light=uses_light;
- r_flags.uses_time=uses_time;
- r_flags.uses_normalmap=uses_normalmap;
- r_flags.uses_normal=uses_normal;
- r_flags.uses_texpixel_size=uses_texpixel_size;
- r_flags.uses_worldvec=uses_worldvec;
- r_flags.uses_shadow_color=uses_shadow_color;
- r_code_line=code;
- r_globals_line=global_code;
+ r_flags.uses_alpha = uses_alpha;
+ r_flags.uses_texscreen = uses_texscreen;
+ r_flags.uses_texpos = uses_texpos;
+ r_flags.vertex_code_writes_vertex = vertex_code_writes_vertex;
+ r_flags.vertex_code_writes_position = vertex_code_writes_position;
+ r_flags.uses_discard = uses_discard;
+ r_flags.uses_screen_uv = uses_screen_uv;
+ r_flags.uses_light = uses_light;
+ r_flags.uses_time = uses_time;
+ r_flags.uses_normalmap = uses_normalmap;
+ r_flags.uses_normal = uses_normal;
+ r_flags.uses_texpixel_size = uses_texpixel_size;
+ r_flags.uses_worldvec = uses_worldvec;
+ r_flags.uses_shadow_color = uses_shadow_color;
+ r_code_line = code;
+ r_globals_line = global_code;
return OK;
}
@@ -721,228 +717,222 @@ ShaderCompilerGLES2::ShaderCompilerGLES2() {
#ifdef GLEW_ENABLED
//use custom functions because they are not supported in GLSL120
- custom_h=true;
+ custom_h = true;
#else
- custom_h=false;
+ custom_h = false;
#endif
- replace_table["bool"]= "bool";
- replace_table["float" ]= "float";
- replace_table["vec2" ]= "vec2";
- replace_table["vec3" ]= "vec3";
- replace_table["vec4" ]= "vec4";
- replace_table["mat2" ]= "mat2";
- replace_table["mat3" ]= "mat3";
- replace_table["mat4" ]= "mat4";
- replace_table["texture" ]= "sampler2D";
- replace_table["cubemap" ]= "samplerCube";
-
- replace_table["sin"]= "sin";
- replace_table["cos" ]= "cos";
- replace_table["tan" ]= "tan";
- replace_table["asin" ]= "asin";
- replace_table["acos" ]= "acos";
- replace_table["atan" ]= "atan";
- replace_table["atan2"]= "atan";
+ replace_table["bool"] = "bool";
+ replace_table["float"] = "float";
+ replace_table["vec2"] = "vec2";
+ replace_table["vec3"] = "vec3";
+ replace_table["vec4"] = "vec4";
+ replace_table["mat2"] = "mat2";
+ replace_table["mat3"] = "mat3";
+ replace_table["mat4"] = "mat4";
+ replace_table["texture"] = "sampler2D";
+ replace_table["cubemap"] = "samplerCube";
+
+ replace_table["sin"] = "sin";
+ replace_table["cos"] = "cos";
+ replace_table["tan"] = "tan";
+ replace_table["asin"] = "asin";
+ replace_table["acos"] = "acos";
+ replace_table["atan"] = "atan";
+ replace_table["atan2"] = "atan";
if (custom_h) {
- replace_table["sinh" ]= "sinh_custom";
- replace_table["cosh" ]= "cosh_custom";
- replace_table["tanh" ]= "tanh_custom";
+ replace_table["sinh"] = "sinh_custom";
+ replace_table["cosh"] = "cosh_custom";
+ replace_table["tanh"] = "tanh_custom";
} else {
- replace_table["sinh" ]= "sinh";
- replace_table["cosh" ]= "cosh";
- replace_table["tanh" ]= "tanh";
+ replace_table["sinh"] = "sinh";
+ replace_table["cosh"] = "cosh";
+ replace_table["tanh"] = "tanh";
}
- replace_table["pow" ]= "pow";
- replace_table["exp" ]= "exp";
- replace_table["log" ]= "log";
- replace_table["sqrt"]= "sqrt";
- replace_table["abs" ]= "abs";
- replace_table["sign"]= "sign";
- replace_table["floor"]= "floor";
- replace_table["trunc"]= "trunc";
+ replace_table["pow"] = "pow";
+ replace_table["exp"] = "exp";
+ replace_table["log"] = "log";
+ replace_table["sqrt"] = "sqrt";
+ replace_table["abs"] = "abs";
+ replace_table["sign"] = "sign";
+ replace_table["floor"] = "floor";
+ replace_table["trunc"] = "trunc";
#ifdef GLEW_ENABLED
- replace_table["round"]= "roundfix";
+ replace_table["round"] = "roundfix";
#else
- replace_table["round"]= "round";
+ replace_table["round"] = "round";
#endif
- replace_table["ceil" ]= "ceil";
- replace_table["fract"]= "fract";
- replace_table["mod" ]= "mod";
- replace_table["min" ]= "min";
- replace_table["max"]= "max";
- replace_table["clamp"]= "clamp";
- replace_table["mix" ]= "mix";
- replace_table["step" ]= "step";
- replace_table["smoothstep" ]= "smoothstep";
- replace_table["length"]= "length";
- replace_table["distance"]= "distance";
- replace_table["dot" ]= "dot";
- replace_table["cross" ]="cross";
- replace_table["normalize"]= "normalize";
- replace_table["reflect"]= "reflect";
- replace_table["refract"]= "refract";
- replace_table["tex"]= "tex";
- replace_table["texa"]= "texa";
- replace_table["tex2"]= "tex2";
- replace_table["texcube"]= "textureCube";
- replace_table["texscreen"]= "texscreen";
- replace_table["texpos"]= "texpos";
-
-
+ replace_table["ceil"] = "ceil";
+ replace_table["fract"] = "fract";
+ replace_table["mod"] = "mod";
+ replace_table["min"] = "min";
+ replace_table["max"] = "max";
+ replace_table["clamp"] = "clamp";
+ replace_table["mix"] = "mix";
+ replace_table["step"] = "step";
+ replace_table["smoothstep"] = "smoothstep";
+ replace_table["length"] = "length";
+ replace_table["distance"] = "distance";
+ replace_table["dot"] = "dot";
+ replace_table["cross"] = "cross";
+ replace_table["normalize"] = "normalize";
+ replace_table["reflect"] = "reflect";
+ replace_table["refract"] = "refract";
+ replace_table["tex"] = "tex";
+ replace_table["texa"] = "texa";
+ replace_table["tex2"] = "tex2";
+ replace_table["texcube"] = "textureCube";
+ replace_table["texscreen"] = "texscreen";
+ replace_table["texpos"] = "texpos";
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["SRC_VERTEX"] = "vertex_in.xyz";
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["SRC_NORMAL"] = "normal_in";
- mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["SRC_TANGENT"]="tangent_in";
- mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["SRC_BINORMALF"]="binormalf";
-
+ mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["SRC_TANGENT"] = "tangent_in";
+ mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["SRC_BINORMALF"] = "binormalf";
+
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["POSITION"] = "gl_Position";
- mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["VERTEX"]="vertex_interp";
- mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["NORMAL"]="normal_interp";
- mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["TANGENT"]="tangent_interp";
- mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["BINORMAL"]="binormal_interp";
- mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["UV"]="uv_interp.xy";
- mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["UV2"]="uv_interp.zw";
- mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["COLOR"]="color_interp";
+ mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["VERTEX"] = "vertex_interp";
+ mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["NORMAL"] = "normal_interp";
+ mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["TANGENT"] = "tangent_interp";
+ mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["BINORMAL"] = "binormal_interp";
+ mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["UV"] = "uv_interp.xy";
+ mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["UV2"] = "uv_interp.zw";
+ mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["COLOR"] = "color_interp";
//@TODO convert to glsl stuff
- mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["SPEC_EXP"]="vertex_specular_exp";
- mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["WORLD_MATRIX"]="world_transform";
- mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["INV_CAMERA_MATRIX"]="camera_inverse_transform";
- mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["PROJECTION_MATRIX"]="projection_transform";
- mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["MODELVIEW_MATRIX"]="modelview";
- mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["POINT_SIZE"]="gl_PointSize";
- mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["VAR1"]="var1_interp";
- mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["VAR2"]="var2_interp";
+ mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["SPEC_EXP"] = "vertex_specular_exp";
+ mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["WORLD_MATRIX"] = "world_transform";
+ mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["INV_CAMERA_MATRIX"] = "camera_inverse_transform";
+ mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["PROJECTION_MATRIX"] = "projection_transform";
+ mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["MODELVIEW_MATRIX"] = "modelview";
+ mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["POINT_SIZE"] = "gl_PointSize";
+ mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["VAR1"] = "var1_interp";
+ mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["VAR2"] = "var2_interp";
//mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["SCREEN_POS"]="SCREEN_POS";
//mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["SCREEN_SIZE"]="SCREEN_SIZE";
- mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["INSTANCE_ID"]="instance_id";
- mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["TIME"]="time";
+ mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["INSTANCE_ID"] = "instance_id";
+ mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["TIME"] = "time";
- mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["VERTEX"]="vertex";
+ mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["VERTEX"] = "vertex";
//mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["POSITION"]="IN_POSITION";
- mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["NORMAL"]="normal";
- mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["TANGENT"]="tangent";
- mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["POSITION"]="gl_Position";
- mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["BINORMAL"]="binormal";
- mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["NORMALMAP"]="normalmap";
- mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["NORMALMAP_DEPTH"]="normaldepth";
- mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["VAR1"]="var1_interp";
- mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["VAR2"]="var2_interp";
- mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["UV"]="uv";
- mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["UV2"]="uv2";
- mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["SCREEN_UV"]="screen_uv";
- mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["VAR1"]="var1_interp";
- mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["VAR2"]="var2_interp";
- mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["COLOR"]="color";
- mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["DIFFUSE"]="diffuse.rgb";
- mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["DIFFUSE_ALPHA"]="diffuse";
- mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["SPECULAR"]="specular";
- mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["EMISSION"]="emission";
- mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["SHADE_PARAM"]="shade_param";
- mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["SPEC_EXP"]="specular_exp";
- mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["GLOW"]="glow";
- mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["DISCARD"]="discard_";
- mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["POINT_COORD"]="gl_PointCoord";
- mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["INV_CAMERA_MATRIX"]="camera_inverse_transform";
+ mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["NORMAL"] = "normal";
+ mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["TANGENT"] = "tangent";
+ mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["POSITION"] = "gl_Position";
+ mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["BINORMAL"] = "binormal";
+ mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["NORMALMAP"] = "normalmap";
+ mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["NORMALMAP_DEPTH"] = "normaldepth";
+ mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["VAR1"] = "var1_interp";
+ mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["VAR2"] = "var2_interp";
+ mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["UV"] = "uv";
+ mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["UV2"] = "uv2";
+ mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["SCREEN_UV"] = "screen_uv";
+ mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["VAR1"] = "var1_interp";
+ mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["VAR2"] = "var2_interp";
+ mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["COLOR"] = "color";
+ mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["DIFFUSE"] = "diffuse.rgb";
+ mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["DIFFUSE_ALPHA"] = "diffuse";
+ mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["SPECULAR"] = "specular";
+ mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["EMISSION"] = "emission";
+ mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["SHADE_PARAM"] = "shade_param";
+ mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["SPEC_EXP"] = "specular_exp";
+ mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["GLOW"] = "glow";
+ mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["DISCARD"] = "discard_";
+ mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["POINT_COORD"] = "gl_PointCoord";
+ mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["INV_CAMERA_MATRIX"] = "camera_inverse_transform";
//mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["SCREEN_POS"]="SCREEN_POS";
//mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["SCREEN_TEXEL_SIZE"]="SCREEN_TEXEL_SIZE";
- mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["TIME"]="time";
+ mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["TIME"] = "time";
//////////////
- mode_replace_table[ShaderLanguage::SHADER_MATERIAL_LIGHT]["NORMAL"]="normal";
+ mode_replace_table[ShaderLanguage::SHADER_MATERIAL_LIGHT]["NORMAL"] = "normal";
//mode_replace_table[ShaderLanguage::SHADER_MATERIAL_LIGHT]["POSITION"]="IN_POSITION";
- mode_replace_table[ShaderLanguage::SHADER_MATERIAL_LIGHT]["LIGHT_DIR"]="light_dir";
- mode_replace_table[ShaderLanguage::SHADER_MATERIAL_LIGHT]["LIGHT_DIFFUSE"]="light_diffuse";
- mode_replace_table[ShaderLanguage::SHADER_MATERIAL_LIGHT]["LIGHT_SPECULAR"]="light_specular";
- mode_replace_table[ShaderLanguage::SHADER_MATERIAL_LIGHT]["EYE_VEC"]="eye_vec";
- mode_replace_table[ShaderLanguage::SHADER_MATERIAL_LIGHT]["DIFFUSE"]="mdiffuse";
- mode_replace_table[ShaderLanguage::SHADER_MATERIAL_LIGHT]["SPECULAR"]="specular";
- mode_replace_table[ShaderLanguage::SHADER_MATERIAL_LIGHT]["SPECULAR_EXP"]="specular_exp";
- mode_replace_table[ShaderLanguage::SHADER_MATERIAL_LIGHT]["SHADE_PARAM"]="shade_param";
- mode_replace_table[ShaderLanguage::SHADER_MATERIAL_LIGHT]["LIGHT"]="light";
- mode_replace_table[ShaderLanguage::SHADER_MATERIAL_LIGHT]["POINT_COORD"]="gl_PointCoord";
- mode_replace_table[ShaderLanguage::SHADER_MATERIAL_LIGHT]["TIME"]="time";
- mode_replace_table[ShaderLanguage::SHADER_MATERIAL_LIGHT]["SHADOW"]="shadow_color";
-
- mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_VERTEX]["SRC_VERTEX"]="src_vtx";
- mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_VERTEX]["VERTEX"]="outvec.xy";
- mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_VERTEX]["WORLD_VERTEX"]="outvec.xy";
- mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_VERTEX]["UV"]="uv_interp";
- mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_VERTEX]["COLOR"]="color_interp";
- mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_VERTEX]["VAR1"]="var1_interp";
- mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_VERTEX]["VAR2"]="var2_interp";
- mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_VERTEX]["POINT_SIZE"]="gl_PointSize";
- mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_VERTEX]["WORLD_MATRIX"]="modelview_matrix";
- mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_VERTEX]["PROJECTION_MATRIX"]="projection_matrix";
- mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_VERTEX]["EXTRA_MATRIX"]="extra_matrix";
- mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_VERTEX]["TIME"]="time";
-
- mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_FRAGMENT]["POSITION"]="gl_Position";
- mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_FRAGMENT]["NORMAL"]="normal";
- mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_FRAGMENT]["NORMALMAP"]="normal_map";
- mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_FRAGMENT]["NORMALMAP_DEPTH"]="normal_depth";
- mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_FRAGMENT]["UV"]="uv_interp";
- mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_FRAGMENT]["SRC_COLOR"]="color_interp";
- mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_FRAGMENT]["COLOR"]="color";
- mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_FRAGMENT]["TEXTURE"]="texture";
- mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_FRAGMENT]["TEXTURE_PIXEL_SIZE"]="texpixel_size";
- mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_FRAGMENT]["VAR1"]="var1_interp";
- mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_FRAGMENT]["VAR2"]="var2_interp";
- mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_FRAGMENT]["SCREEN_UV"]="screen_uv";
- mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_FRAGMENT]["POINT_COORD"]="gl_PointCoord";
- mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_FRAGMENT]["TIME"]="time";
-
- mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT]["POSITION"]="gl_Position";
- mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT]["NORMAL"]="normal";
- mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT]["UV"]="uv_interp";
- mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT]["COLOR"]="color";
- mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT]["TEXTURE"]="texture";
- mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT]["TEXTURE_PIXEL_SIZE"]="texpixel_size";
- mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT]["VAR1"]="var1_interp";
- mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT]["VAR2"]="var2_interp";
- mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT]["LIGHT_VEC"]="light_vec";
- mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT]["LIGHT_HEIGHT"]="light_height";
- mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT]["LIGHT_COLOR"]="light";
- mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT]["LIGHT_SHADOW"]="light_shadow_color";
- mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT]["LIGHT_UV"]="light_uv";
- mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT]["LIGHT"]="light_out";
- mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT]["SHADOW"]="shadow_color";
- mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT]["SCREEN_UV"]="screen_uv";
- mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT]["POINT_COORD"]="gl_PointCoord";
- mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT]["TIME"]="time";
-
-
+ mode_replace_table[ShaderLanguage::SHADER_MATERIAL_LIGHT]["LIGHT_DIR"] = "light_dir";
+ mode_replace_table[ShaderLanguage::SHADER_MATERIAL_LIGHT]["LIGHT_DIFFUSE"] = "light_diffuse";
+ mode_replace_table[ShaderLanguage::SHADER_MATERIAL_LIGHT]["LIGHT_SPECULAR"] = "light_specular";
+ mode_replace_table[ShaderLanguage::SHADER_MATERIAL_LIGHT]["EYE_VEC"] = "eye_vec";
+ mode_replace_table[ShaderLanguage::SHADER_MATERIAL_LIGHT]["DIFFUSE"] = "mdiffuse";
+ mode_replace_table[ShaderLanguage::SHADER_MATERIAL_LIGHT]["SPECULAR"] = "specular";
+ mode_replace_table[ShaderLanguage::SHADER_MATERIAL_LIGHT]["SPECULAR_EXP"] = "specular_exp";
+ mode_replace_table[ShaderLanguage::SHADER_MATERIAL_LIGHT]["SHADE_PARAM"] = "shade_param";
+ mode_replace_table[ShaderLanguage::SHADER_MATERIAL_LIGHT]["LIGHT"] = "light";
+ mode_replace_table[ShaderLanguage::SHADER_MATERIAL_LIGHT]["POINT_COORD"] = "gl_PointCoord";
+ mode_replace_table[ShaderLanguage::SHADER_MATERIAL_LIGHT]["TIME"] = "time";
+ mode_replace_table[ShaderLanguage::SHADER_MATERIAL_LIGHT]["SHADOW"] = "shadow_color";
+
+ mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_VERTEX]["SRC_VERTEX"] = "src_vtx";
+ mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_VERTEX]["VERTEX"] = "outvec.xy";
+ mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_VERTEX]["WORLD_VERTEX"] = "outvec.xy";
+ mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_VERTEX]["UV"] = "uv_interp";
+ mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_VERTEX]["COLOR"] = "color_interp";
+ mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_VERTEX]["VAR1"] = "var1_interp";
+ mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_VERTEX]["VAR2"] = "var2_interp";
+ mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_VERTEX]["POINT_SIZE"] = "gl_PointSize";
+ mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_VERTEX]["WORLD_MATRIX"] = "modelview_matrix";
+ mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_VERTEX]["PROJECTION_MATRIX"] = "projection_matrix";
+ mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_VERTEX]["EXTRA_MATRIX"] = "extra_matrix";
+ mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_VERTEX]["TIME"] = "time";
+
+ mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_FRAGMENT]["POSITION"] = "gl_Position";
+ mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_FRAGMENT]["NORMAL"] = "normal";
+ mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_FRAGMENT]["NORMALMAP"] = "normal_map";
+ mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_FRAGMENT]["NORMALMAP_DEPTH"] = "normal_depth";
+ mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_FRAGMENT]["UV"] = "uv_interp";
+ mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_FRAGMENT]["SRC_COLOR"] = "color_interp";
+ mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_FRAGMENT]["COLOR"] = "color";
+ mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_FRAGMENT]["TEXTURE"] = "texture";
+ mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_FRAGMENT]["TEXTURE_PIXEL_SIZE"] = "texpixel_size";
+ mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_FRAGMENT]["VAR1"] = "var1_interp";
+ mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_FRAGMENT]["VAR2"] = "var2_interp";
+ mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_FRAGMENT]["SCREEN_UV"] = "screen_uv";
+ mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_FRAGMENT]["POINT_COORD"] = "gl_PointCoord";
+ mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_FRAGMENT]["TIME"] = "time";
+
+ mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT]["POSITION"] = "gl_Position";
+ mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT]["NORMAL"] = "normal";
+ mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT]["UV"] = "uv_interp";
+ mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT]["COLOR"] = "color";
+ mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT]["TEXTURE"] = "texture";
+ mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT]["TEXTURE_PIXEL_SIZE"] = "texpixel_size";
+ mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT]["VAR1"] = "var1_interp";
+ mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT]["VAR2"] = "var2_interp";
+ mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT]["LIGHT_VEC"] = "light_vec";
+ mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT]["LIGHT_HEIGHT"] = "light_height";
+ mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT]["LIGHT_COLOR"] = "light";
+ mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT]["LIGHT_SHADOW"] = "light_shadow_color";
+ mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT]["LIGHT_UV"] = "light_uv";
+ mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT]["LIGHT"] = "light_out";
+ mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT]["SHADOW"] = "shadow_color";
+ mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT]["SCREEN_UV"] = "screen_uv";
+ mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT]["POINT_COORD"] = "gl_PointCoord";
+ mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT]["TIME"] = "time";
//mode_replace_table[2]["SCREEN_POS"]="SCREEN_POS";
//mode_replace_table[2]["SCREEN_TEXEL_SIZE"]="SCREEN_TEXEL_SIZE";
-
- out_vertex_name="VERTEX";
-
- vname_discard="DISCARD";
- vname_screen_uv="SCREEN_UV";
- vname_diffuse_alpha="DIFFUSE_ALPHA";
- vname_color_interp="COLOR";
- vname_uv_interp="UV";
- vname_uv2_interp="UV2";
- vname_tangent_interp="TANGENT";
- vname_binormal_interp="BINORMAL";
- vname_var1_interp="VAR1";
- vname_var2_interp="VAR2";
- vname_vertex="VERTEX";
+ out_vertex_name = "VERTEX";
+
+ vname_discard = "DISCARD";
+ vname_screen_uv = "SCREEN_UV";
+ vname_diffuse_alpha = "DIFFUSE_ALPHA";
+ vname_color_interp = "COLOR";
+ vname_uv_interp = "UV";
+ vname_uv2_interp = "UV2";
+ vname_tangent_interp = "TANGENT";
+ vname_binormal_interp = "BINORMAL";
+ vname_var1_interp = "VAR1";
+ vname_var2_interp = "VAR2";
+ vname_vertex = "VERTEX";
vname_position = "POSITION";
- vname_light="LIGHT";
- vname_time="TIME";
- vname_normalmap="NORMALMAP";
- vname_normalmap_depth="NORMALMAP_DEPTH";
- vname_normal="NORMAL";
- vname_texpixel_size="TEXTURE_PIXEL_SIZE";
- vname_world_vec="WORLD_VERTEX";
- vname_shadow="SHADOW";
-
+ vname_light = "LIGHT";
+ vname_time = "TIME";
+ vname_normalmap = "NORMALMAP";
+ vname_normalmap_depth = "NORMALMAP_DEPTH";
+ vname_normal = "NORMAL";
+ vname_texpixel_size = "TEXTURE_PIXEL_SIZE";
+ vname_world_vec = "WORLD_VERTEX";
+ vname_shadow = "SHADOW";
}
diff --git a/drivers/gles2/shader_compiler_gles2.h b/drivers/gles2/shader_compiler_gles2.h
index 3c39e101ca..2565adcd5d 100644
--- a/drivers/gles2/shader_compiler_gles2.h
+++ b/drivers/gles2/shader_compiler_gles2.h
@@ -33,15 +33,15 @@
class ShaderCompilerGLES2 {
class Uniform;
+
public:
struct Flags;
-private:
+private:
ShaderLanguage::ProgramNode *program_node;
- String dump_node_code(ShaderLanguage::Node *p_node,int p_level,bool p_assign_left=false);
+ String dump_node_code(ShaderLanguage::Node *p_node, int p_level, bool p_assign_left = false);
Error compile_node(ShaderLanguage::ProgramNode *p_program);
- static Error create_glsl_120_code(void *p_str,ShaderLanguage::ProgramNode *p_program);
-
+ static Error create_glsl_120_code(void *p_str, ShaderLanguage::ProgramNode *p_program);
bool uses_light;
bool uses_texscreen;
@@ -87,7 +87,7 @@ private:
StringName vname_world_vec;
StringName vname_shadow;
- Map<StringName,ShaderLanguage::Uniform> *uniforms;
+ Map<StringName, ShaderLanguage::Uniform> *uniforms;
StringName out_vertex_name;
@@ -95,13 +95,12 @@ private:
String code;
ShaderLanguage::ShaderType type;
- String replace_string(const StringName& p_string);
+ String replace_string(const StringName &p_string);
- Map<StringName,StringName> mode_replace_table[9];
- Map<StringName,StringName> replace_table;
+ Map<StringName, StringName> mode_replace_table[9];
+ Map<StringName, StringName> replace_table;
public:
-
struct Flags {
bool uses_alpha;
@@ -126,10 +125,9 @@ public:
bool uses_shadow_color;
};
- Error compile(const String& p_code, ShaderLanguage::ShaderType p_type, String& r_code_line, String& r_globals_line, Flags& r_flags, Map<StringName,ShaderLanguage::Uniform> *r_uniforms=NULL);
+ Error compile(const String &p_code, ShaderLanguage::ShaderType p_type, String &r_code_line, String &r_globals_line, Flags &r_flags, Map<StringName, ShaderLanguage::Uniform> *r_uniforms = NULL);
ShaderCompilerGLES2();
-
};
#endif // SHADER_COMPILERL_GL_H
diff --git a/drivers/gles2/shader_gles2.cpp b/drivers/gles2/shader_gles2.cpp
index 97c31dfc1c..08b9c21d5b 100644
--- a/drivers/gles2/shader_gles2.cpp
+++ b/drivers/gles2/shader_gles2.cpp
@@ -35,22 +35,20 @@
#ifdef DEBUG_OPENGL
-#define DEBUG_TEST_ERROR(m_section)\
-{\
- uint32_t err = glGetError();\
- if (err) {\
- print_line("OpenGL Error #"+itos(err)+" at: "+m_section);\
- }\
-}
+#define DEBUG_TEST_ERROR(m_section) \
+ { \
+ uint32_t err = glGetError(); \
+ if (err) { \
+ print_line("OpenGL Error #" + itos(err) + " at: " + m_section); \
+ } \
+ }
#else
#define DEBUG_TEST_ERROR(m_section)
#endif
-ShaderGLES2 *ShaderGLES2::active=NULL;
-
-
+ShaderGLES2 *ShaderGLES2::active = NULL;
//#define DEBUG_SHADER
@@ -64,7 +62,6 @@ ShaderGLES2 *ShaderGLES2::active=NULL;
#endif
-
void ShaderGLES2::bind_uniforms() {
if (!uniforms_dirty) {
@@ -72,34 +69,33 @@ void ShaderGLES2::bind_uniforms() {
};
// upload default uniforms
- const Map<uint32_t,Variant>::Element *E =uniform_defaults.front();
+ const Map<uint32_t, Variant>::Element *E = uniform_defaults.front();
- while(E) {
- int idx=E->key();
- int location=version->uniform_location[idx];
+ while (E) {
+ int idx = E->key();
+ int location = version->uniform_location[idx];
- if (location<0) {
- E=E->next();
+ if (location < 0) {
+ E = E->next();
continue;
-
}
- const Variant &v=E->value();
+ const Variant &v = E->value();
_set_uniform_variant(location, v);
//print_line("uniform "+itos(location)+" value "+v+ " type "+Variant::get_type_name(v.get_type()));
- E=E->next();
+ E = E->next();
};
- const Map<uint32_t,CameraMatrix>::Element* C = uniform_cameras.front();
+ const Map<uint32_t, CameraMatrix>::Element *C = uniform_cameras.front();
while (C) {
int location = version->uniform_location[C->key()];
- if (location<0) {
- C=C->next();
+ if (location < 0) {
+ C = C->next();
continue;
}
- glUniformMatrix4fv(location,1,false,&(C->get().matrix[0][0]));
+ glUniformMatrix4fv(location, 1, false, &(C->get().matrix[0][0]));
C = C->next();
};
@@ -114,24 +110,24 @@ GLint ShaderGLES2::get_uniform_location(int p_idx) const {
};
bool ShaderGLES2::bind() {
-
- if (active!=this || !version || new_conditional_version.key!=conditional_version.key) {
- conditional_version=new_conditional_version;
+
+ if (active != this || !version || new_conditional_version.key != conditional_version.key) {
+ conditional_version = new_conditional_version;
version = get_current_version();
} else {
return false;
}
-
- ERR_FAIL_COND_V(!version,false);
- glUseProgram( version->id );
+ ERR_FAIL_COND_V(!version, false);
+
+ glUseProgram(version->id);
DEBUG_TEST_ERROR("Use Program");
- active=this;
+ active = this;
uniforms_dirty = true;
-/*
+ /*
* why on earth is this code here?
for (int i=0;i<texunit_pair_count;i++) {
@@ -145,184 +141,172 @@ bool ShaderGLES2::bind() {
void ShaderGLES2::unbind() {
- version=NULL;
+ version = NULL;
glUseProgram(0);
uniforms_dirty = true;
- active=NULL;
+ active = NULL;
}
+static String _fix_error_code_line(const String &p_error, int p_code_start, int p_offset) {
-static String _fix_error_code_line(const String& p_error,int p_code_start,int p_offset) {
-
- int last_find_pos=-1;
+ int last_find_pos = -1;
// NVIDIA
- String error=p_error;
- while((last_find_pos=p_error.find("(",last_find_pos+1))!=-1) {
+ String error = p_error;
+ while ((last_find_pos = p_error.find("(", last_find_pos + 1)) != -1) {
- int end_pos=last_find_pos+1;
+ int end_pos = last_find_pos + 1;
- while(true) {
+ while (true) {
- if (p_error[end_pos]>='0' && p_error[end_pos]<='9') {
+ if (p_error[end_pos] >= '0' && p_error[end_pos] <= '9') {
end_pos++;
continue;
- } else if (p_error[end_pos]==')') {
+ } else if (p_error[end_pos] == ')') {
break;
} else {
- end_pos=-1;
+ end_pos = -1;
break;
}
-
}
- if (end_pos==-1)
+ if (end_pos == -1)
continue;
- String numstr = error.substr(last_find_pos+1,(end_pos-last_find_pos)-1);
- String begin = error.substr(0,last_find_pos+1);
- String end = error.substr(end_pos,error.length());
- int num = numstr.to_int()+p_code_start-p_offset;
- error = begin+itos(num)+end;
+ String numstr = error.substr(last_find_pos + 1, (end_pos - last_find_pos) - 1);
+ String begin = error.substr(0, last_find_pos + 1);
+ String end = error.substr(end_pos, error.length());
+ int num = numstr.to_int() + p_code_start - p_offset;
+ error = begin + itos(num) + end;
}
- // ATI
- last_find_pos=-1;
- while((last_find_pos=p_error.find("ERROR: ",last_find_pos+1))!=-1) {
-
- last_find_pos+=6;
- int end_pos=last_find_pos+1;
+ // ATI
+ last_find_pos = -1;
+ while ((last_find_pos = p_error.find("ERROR: ", last_find_pos + 1)) != -1) {
- while(true) {
+ last_find_pos += 6;
+ int end_pos = last_find_pos + 1;
- if (p_error[end_pos]>='0' && p_error[end_pos]<='9') {
+ while (true) {
- end_pos++;
- continue;
- } else if (p_error[end_pos]==':') {
- break;
- } else {
+ if (p_error[end_pos] >= '0' && p_error[end_pos] <= '9') {
- end_pos=-1;
- break;
- }
+ end_pos++;
+ continue;
+ } else if (p_error[end_pos] == ':') {
+ break;
+ } else {
- }
+ end_pos = -1;
+ break;
+ }
+ }
continue;
- if (end_pos==-1)
- continue;
-
- String numstr = error.substr(last_find_pos+1,(end_pos-last_find_pos)-1);
- print_line("numstr: "+numstr);
- String begin = error.substr(0,last_find_pos+1);
- String end = error.substr(end_pos,error.length());
- int num = numstr.to_int()+p_code_start-p_offset;
- error = begin+itos(num)+end;
- }
+ if (end_pos == -1)
+ continue;
+
+ String numstr = error.substr(last_find_pos + 1, (end_pos - last_find_pos) - 1);
+ print_line("numstr: " + numstr);
+ String begin = error.substr(0, last_find_pos + 1);
+ String end = error.substr(end_pos, error.length());
+ int num = numstr.to_int() + p_code_start - p_offset;
+ error = begin + itos(num) + end;
+ }
return error;
}
-ShaderGLES2::Version* ShaderGLES2::get_current_version() {
+ShaderGLES2::Version *ShaderGLES2::get_current_version() {
- Version *_v=version_map.getptr(conditional_version);
+ Version *_v = version_map.getptr(conditional_version);
if (_v) {
- if (conditional_version.code_version!=0) {
- CustomCode *cc=custom_code_map.getptr(conditional_version.code_version);
- ERR_FAIL_COND_V(!cc,_v);
- if (cc->version==_v->code_version)
+ if (conditional_version.code_version != 0) {
+ CustomCode *cc = custom_code_map.getptr(conditional_version.code_version);
+ ERR_FAIL_COND_V(!cc, _v);
+ if (cc->version == _v->code_version)
return _v;
} else {
return _v;
}
-
}
-
-
if (!_v)
- version_map[conditional_version]=Version();
-
+ version_map[conditional_version] = Version();
Version &v = version_map[conditional_version];
if (!_v) {
- v.uniform_location = memnew_arr( GLint, uniform_count );
+ v.uniform_location = memnew_arr(GLint, uniform_count);
} else {
if (v.ok) {
//bye bye shaders
- glDeleteShader( v.vert_id );
- glDeleteShader( v.frag_id );
- glDeleteProgram( v.id );
- v.id=0;
+ glDeleteShader(v.vert_id);
+ glDeleteShader(v.frag_id);
+ glDeleteProgram(v.id);
+ v.id = 0;
}
-
}
- v.ok=false;
+ v.ok = false;
/* SETUP CONDITIONALS */
-
- Vector<const char*> strings;
+
+ Vector<const char *> strings;
#ifdef GLEW_ENABLED
strings.push_back("#version 120\n"); //ATI requieres this before anything
#endif
- int define_line_ofs=1;
+ int define_line_ofs = 1;
- for(int j=0;j<conditional_count;j++) {
-
- bool enable=((1<<j)&conditional_version.version);
- strings.push_back(enable?conditional_defines[j]:"");
+ for (int j = 0; j < conditional_count; j++) {
+
+ bool enable = ((1 << j) & conditional_version.version);
+ strings.push_back(enable ? conditional_defines[j] : "");
if (enable)
define_line_ofs++;
if (enable) {
DEBUG_PRINT(conditional_defines[j]);
}
-
}
-
+
//keep them around during the function
CharString code_string;
CharString code_string2;
CharString code_globals;
-
//print_line("code version? "+itos(conditional_version.code_version));
- CustomCode *cc=NULL;
+ CustomCode *cc = NULL;
- if ( conditional_version.code_version>0 ) {
+ if (conditional_version.code_version > 0) {
//do custom code related stuff
- ERR_FAIL_COND_V( !custom_code_map.has( conditional_version.code_version ), NULL );
- cc=&custom_code_map[conditional_version.code_version];
- v.code_version=cc->version;
- define_line_ofs+=2;
+ ERR_FAIL_COND_V(!custom_code_map.has(conditional_version.code_version), NULL);
+ cc = &custom_code_map[conditional_version.code_version];
+ v.code_version = cc->version;
+ define_line_ofs += 2;
}
-
/* CREATE PROGRAM */
-
+
v.id = glCreateProgram();
-
- ERR_FAIL_COND_V(v.id==0, NULL);
-
- /* VERTEX SHADER */
+ ERR_FAIL_COND_V(v.id == 0, NULL);
+
+ /* VERTEX SHADER */
if (cc) {
- for(int i=0;i<cc->custom_defines.size();i++) {
+ for (int i = 0; i < cc->custom_defines.size(); i++) {
strings.push_back(cc->custom_defines[i]);
- DEBUG_PRINT("CD #"+itos(i)+": "+String(cc->custom_defines[i]));
+ DEBUG_PRINT("CD #" + itos(i) + ": " + String(cc->custom_defines[i]));
}
}
- int strings_base_size=strings.size();
+ int strings_base_size = strings.size();
#if 0
if (cc) {
@@ -338,76 +322,72 @@ ShaderGLES2::Version* ShaderGLES2::get_current_version() {
}
#endif
-
strings.push_back(vertex_code0.get_data());
if (cc) {
- code_globals=cc->vertex_globals.ascii();
+ code_globals = cc->vertex_globals.ascii();
strings.push_back(code_globals.get_data());
}
strings.push_back(vertex_code1.get_data());
if (cc) {
- code_string=cc->vertex.ascii();
+ code_string = cc->vertex.ascii();
strings.push_back(code_string.get_data());
}
strings.push_back(vertex_code2.get_data());
#ifdef DEBUG_SHADER
- DEBUG_PRINT("\nVertex Code:\n\n"+String(code_string.get_data()));
- for(int i=0;i<strings.size();i++) {
+ DEBUG_PRINT("\nVertex Code:\n\n" + String(code_string.get_data()));
+ for (int i = 0; i < strings.size(); i++) {
//print_line("vert strings "+itos(i)+":"+String(strings[i]));
}
#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], NULL);
glCompileShader(v.vert_id);
-
+
GLint status;
-
- glGetShaderiv(v.vert_id,GL_COMPILE_STATUS,&status);
- if (status==GL_FALSE) {
- // error compiling
+
+ glGetShaderiv(v.vert_id, GL_COMPILE_STATUS, &status);
+ if (status == GL_FALSE) {
+ // error compiling
GLsizei iloglen;
- glGetShaderiv(v.vert_id,GL_INFO_LOG_LENGTH,&iloglen);
-
- if (iloglen<0) {
-
+ glGetShaderiv(v.vert_id, GL_INFO_LOG_LENGTH, &iloglen);
+
+ if (iloglen < 0) {
+
glDeleteShader(v.vert_id);
- glDeleteProgram( v.id );
- v.id=0;
-
+ glDeleteProgram(v.id);
+ v.id = 0;
+
ERR_PRINT("NO LOG, WTF");
} else {
- if (iloglen==0) {
+ if (iloglen == 0) {
iloglen = 4096; //buggy driver (Adreno 220+....)
}
-
- char *ilogmem = (char*)Memory::alloc_static(iloglen+1);
- ilogmem[iloglen]=0;
- glGetShaderInfoLog(v.vert_id, iloglen, &iloglen, ilogmem);
-
- String err_string=get_shader_name()+": Vertex Program Compilation Failed:\n";
-
- err_string+=ilogmem;
- err_string=_fix_error_code_line(err_string,vertex_code_start,define_line_ofs);
+ char *ilogmem = (char *)Memory::alloc_static(iloglen + 1);
+ ilogmem[iloglen] = 0;
+ glGetShaderInfoLog(v.vert_id, iloglen, &iloglen, ilogmem);
+
+ String err_string = get_shader_name() + ": Vertex Program Compilation Failed:\n";
+
+ err_string += ilogmem;
+ err_string = _fix_error_code_line(err_string, vertex_code_start, define_line_ofs);
ERR_PRINT(err_string.ascii().get_data());
Memory::free_static(ilogmem);
glDeleteShader(v.vert_id);
- glDeleteProgram( v.id );
- v.id=0;
-
+ glDeleteProgram(v.id);
+ v.id = 0;
}
-
+
ERR_FAIL_V(NULL);
- }
-
+ }
+
/* FRAGMENT SHADER */
strings.resize(strings_base_size);
@@ -426,347 +406,330 @@ ShaderGLES2::Version* ShaderGLES2::get_current_version() {
}
#endif
-
strings.push_back(fragment_code0.get_data());
if (cc) {
- code_globals=cc->fragment_globals.ascii();
+ code_globals = cc->fragment_globals.ascii();
strings.push_back(code_globals.get_data());
}
strings.push_back(fragment_code1.get_data());
if (cc) {
- code_string=cc->fragment.ascii();
+ code_string = cc->fragment.ascii();
strings.push_back(code_string.get_data());
}
strings.push_back(fragment_code2.get_data());
if (cc) {
- code_string2=cc->light.ascii();
+ code_string2 = cc->light.ascii();
strings.push_back(code_string2.get_data());
}
strings.push_back(fragment_code3.get_data());
#ifdef DEBUG_SHADER
- DEBUG_PRINT("\nFragment Code:\n\n"+String(code_string.get_data()));
- for(int i=0;i<strings.size();i++) {
+ DEBUG_PRINT("\nFragment Code:\n\n" + String(code_string.get_data()));
+ for (int i = 0; i < strings.size(); i++) {
//print_line("frag strings "+itos(i)+":"+String(strings[i]));
}
#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], NULL);
glCompileShader(v.frag_id);
-
- glGetShaderiv(v.frag_id,GL_COMPILE_STATUS,&status);
- if (status==GL_FALSE) {
- // error compiling
+
+ glGetShaderiv(v.frag_id, GL_COMPILE_STATUS, &status);
+ if (status == GL_FALSE) {
+ // error compiling
GLsizei iloglen;
- glGetShaderiv(v.frag_id,GL_INFO_LOG_LENGTH,&iloglen);
-
- if (iloglen<0) {
+ glGetShaderiv(v.frag_id, GL_INFO_LOG_LENGTH, &iloglen);
+
+ if (iloglen < 0) {
glDeleteShader(v.frag_id);
glDeleteShader(v.vert_id);
- glDeleteProgram( v.id );
- v.id=0;
+ glDeleteProgram(v.id);
+ v.id = 0;
ERR_PRINT("NO LOG, WTF");
} else {
-
- if (iloglen==0) {
+
+ if (iloglen == 0) {
iloglen = 4096; //buggy driver (Adreno 220+....)
}
- char *ilogmem = (char*)Memory::alloc_static(iloglen+1);
- ilogmem[iloglen]=0;
- glGetShaderInfoLog(v.frag_id, iloglen, &iloglen, ilogmem);
-
- String err_string=get_shader_name()+": Fragment Program Compilation Failed:\n";
-
- err_string+=ilogmem;
- err_string=_fix_error_code_line(err_string,fragment_code_start,define_line_ofs);
+ char *ilogmem = (char *)Memory::alloc_static(iloglen + 1);
+ ilogmem[iloglen] = 0;
+ glGetShaderInfoLog(v.frag_id, iloglen, &iloglen, ilogmem);
+
+ String err_string = get_shader_name() + ": Fragment Program Compilation Failed:\n";
+
+ err_string += ilogmem;
+ err_string = _fix_error_code_line(err_string, fragment_code_start, define_line_ofs);
ERR_PRINT(err_string.ascii().get_data());
Memory::free_static(ilogmem);
glDeleteShader(v.frag_id);
glDeleteShader(v.vert_id);
- glDeleteProgram( v.id );
- v.id=0;
-
+ glDeleteProgram(v.id);
+ v.id = 0;
}
-
- ERR_FAIL_V( NULL );
- }
-
- glAttachShader(v.id,v.frag_id);
- glAttachShader(v.id,v.vert_id);
+
+ ERR_FAIL_V(NULL);
+ }
+
+ glAttachShader(v.id, v.frag_id);
+ glAttachShader(v.id, v.vert_id);
// bind attributes before linking
- for (int i=0;i<attribute_pair_count;i++) {
+ for (int i = 0; i < attribute_pair_count; i++) {
- glBindAttribLocation(v.id, attribute_pairs[i].index, attribute_pairs[i].name );
+ glBindAttribLocation(v.id, attribute_pairs[i].index, attribute_pairs[i].name);
}
glLinkProgram(v.id);
-
+
glGetProgramiv(v.id, GL_LINK_STATUS, &status);
-
- if (status==GL_FALSE) {
- // error linking
+
+ if (status == GL_FALSE) {
+ // error linking
GLsizei iloglen;
- glGetProgramiv(v.id,GL_INFO_LOG_LENGTH,&iloglen);
-
- if (iloglen<0) {
-
+ glGetProgramiv(v.id, GL_INFO_LOG_LENGTH, &iloglen);
+
+ if (iloglen < 0) {
+
glDeleteShader(v.frag_id);
glDeleteShader(v.vert_id);
- glDeleteProgram( v.id );
- v.id=0;
- ERR_FAIL_COND_V(iloglen<=0, NULL);
+ glDeleteProgram(v.id);
+ v.id = 0;
+ ERR_FAIL_COND_V(iloglen <= 0, NULL);
}
- if (iloglen==0) {
+ if (iloglen == 0) {
iloglen = 4096; //buggy driver (Adreno 220+....)
}
-
- char *ilogmem = (char*)Memory::alloc_static(iloglen+1);
- ilogmem[iloglen]=0;
- glGetProgramInfoLog(v.id, iloglen, &iloglen, ilogmem);
-
- String err_string=get_shader_name()+": Program LINK FAILED:\n";
-
- err_string+=ilogmem;
- err_string=_fix_error_code_line(err_string,fragment_code_start,define_line_ofs);
+ char *ilogmem = (char *)Memory::alloc_static(iloglen + 1);
+ ilogmem[iloglen] = 0;
+ glGetProgramInfoLog(v.id, iloglen, &iloglen, ilogmem);
+
+ String err_string = get_shader_name() + ": Program LINK FAILED:\n";
+
+ err_string += ilogmem;
+ err_string = _fix_error_code_line(err_string, fragment_code_start, define_line_ofs);
ERR_PRINT(err_string.ascii().get_data());
Memory::free_static(ilogmem);
glDeleteShader(v.frag_id);
glDeleteShader(v.vert_id);
- glDeleteProgram( v.id );
- v.id=0;
-
+ glDeleteProgram(v.id);
+ v.id = 0;
+
ERR_FAIL_V(NULL);
}
-
- /* UNIFORMS */
-
- glUseProgram(v.id);
+ /* UNIFORMS */
+
+ glUseProgram(v.id);
//print_line("uniforms: ");
- for(int j=0;j<uniform_count;j++) {
-
-
- v.uniform_location[j]=glGetUniformLocation(v.id,uniform_names[j]);
+ for (int j = 0; j < uniform_count; j++) {
+
+ v.uniform_location[j] = glGetUniformLocation(v.id, uniform_names[j]);
//print_line("uniform "+String(uniform_names[j])+" location "+itos(v.uniform_location[j]));
}
-
+
// set texture uniforms
- for (int i=0;i<texunit_pair_count;i++) {
+ for (int i = 0; i < texunit_pair_count; i++) {
- GLint loc = glGetUniformLocation(v.id,texunit_pairs[i].name);
- if (loc>=0)
- glUniform1i(loc,texunit_pairs[i].index);
+ GLint loc = glGetUniformLocation(v.id, texunit_pairs[i].name);
+ if (loc >= 0)
+ glUniform1i(loc, texunit_pairs[i].index);
}
- if ( cc ) {
+ if (cc) {
v.custom_uniform_locations.resize(cc->custom_uniforms.size());
- for(int i=0;i<cc->custom_uniforms.size();i++) {
+ for (int i = 0; i < cc->custom_uniforms.size(); i++) {
- v.custom_uniform_locations[i]=glGetUniformLocation(v.id,String(cc->custom_uniforms[i]).ascii().get_data());
+ v.custom_uniform_locations[i] = glGetUniformLocation(v.id, String(cc->custom_uniforms[i]).ascii().get_data());
}
}
glUseProgram(0);
-
- v.ok=true;
+ v.ok = true;
return &v;
}
-GLint ShaderGLES2::get_uniform_location(const String& p_name) const {
+GLint ShaderGLES2::get_uniform_location(const String &p_name) const {
- ERR_FAIL_COND_V(!version,-1);
- return glGetUniformLocation(version->id,p_name.ascii().get_data());
+ ERR_FAIL_COND_V(!version, -1);
+ return glGetUniformLocation(version->id, p_name.ascii().get_data());
}
-
-void ShaderGLES2::setup(const char** p_conditional_defines, int p_conditional_count,const char** p_uniform_names,int p_uniform_count, const AttributePair* p_attribute_pairs, int p_attribute_count, const TexUnitPair *p_texunit_pairs, int p_texunit_pair_count,const char*p_vertex_code, const char *p_fragment_code,int p_vertex_code_start,int p_fragment_code_start) {
+void ShaderGLES2::setup(const char **p_conditional_defines, int p_conditional_count, const char **p_uniform_names, int p_uniform_count, const AttributePair *p_attribute_pairs, int p_attribute_count, const TexUnitPair *p_texunit_pairs, int p_texunit_pair_count, const char *p_vertex_code, const char *p_fragment_code, int p_vertex_code_start, int p_fragment_code_start) {
ERR_FAIL_COND(version);
- conditional_version.key=0;
- new_conditional_version.key=0;
- uniform_count=p_uniform_count;
- conditional_count=p_conditional_count;
- conditional_defines=p_conditional_defines;
- uniform_names=p_uniform_names;
- vertex_code=p_vertex_code;
- fragment_code=p_fragment_code;
- texunit_pairs=p_texunit_pairs;
- texunit_pair_count=p_texunit_pair_count;
- vertex_code_start=p_vertex_code_start;
- fragment_code_start=p_fragment_code_start;
- attribute_pairs=p_attribute_pairs;
- attribute_pair_count=p_attribute_count;
+ conditional_version.key = 0;
+ new_conditional_version.key = 0;
+ uniform_count = p_uniform_count;
+ conditional_count = p_conditional_count;
+ conditional_defines = p_conditional_defines;
+ uniform_names = p_uniform_names;
+ vertex_code = p_vertex_code;
+ fragment_code = p_fragment_code;
+ texunit_pairs = p_texunit_pairs;
+ texunit_pair_count = p_texunit_pair_count;
+ vertex_code_start = p_vertex_code_start;
+ fragment_code_start = p_fragment_code_start;
+ attribute_pairs = p_attribute_pairs;
+ attribute_pair_count = p_attribute_count;
//split vertex and shader code (thank you, retarded shader compiler programmers from you know what company).
{
- String globals_tag="\nVERTEX_SHADER_GLOBALS";
- String code_tag="\nVERTEX_SHADER_CODE";
- String code = vertex_code;
+ String globals_tag = "\nVERTEX_SHADER_GLOBALS";
+ String code_tag = "\nVERTEX_SHADER_CODE";
+ String code = vertex_code;
int cpos = code.find(globals_tag);
- if (cpos==-1) {
- vertex_code0=code.ascii();
+ if (cpos == -1) {
+ vertex_code0 = code.ascii();
} else {
- vertex_code0=code.substr(0,cpos).ascii();
- code = code.substr(cpos+globals_tag.length(),code.length());
+ vertex_code0 = code.substr(0, cpos).ascii();
+ code = code.substr(cpos + globals_tag.length(), code.length());
cpos = code.find(code_tag);
- if (cpos==-1) {
- vertex_code1=code.ascii();
+ if (cpos == -1) {
+ vertex_code1 = code.ascii();
} else {
- vertex_code1=code.substr(0,cpos).ascii();
- vertex_code2=code.substr(cpos+code_tag.length(),code.length()).ascii();
+ vertex_code1 = code.substr(0, cpos).ascii();
+ vertex_code2 = code.substr(cpos + code_tag.length(), code.length()).ascii();
}
}
}
{
- String globals_tag="\nFRAGMENT_SHADER_GLOBALS";
- String code_tag="\nFRAGMENT_SHADER_CODE";
- String light_code_tag="\nLIGHT_SHADER_CODE";
- String code = fragment_code;
+ String globals_tag = "\nFRAGMENT_SHADER_GLOBALS";
+ String code_tag = "\nFRAGMENT_SHADER_CODE";
+ String light_code_tag = "\nLIGHT_SHADER_CODE";
+ String code = fragment_code;
int cpos = code.find(globals_tag);
- if (cpos==-1) {
- fragment_code0=code.ascii();
+ if (cpos == -1) {
+ fragment_code0 = code.ascii();
} else {
- fragment_code0=code.substr(0,cpos).ascii();
- code = code.substr(cpos+globals_tag.length(),code.length());
+ fragment_code0 = code.substr(0, cpos).ascii();
+ code = code.substr(cpos + globals_tag.length(), code.length());
cpos = code.find(code_tag);
- if (cpos==-1) {
- fragment_code1=code.ascii();
+ if (cpos == -1) {
+ fragment_code1 = code.ascii();
} else {
- fragment_code1=code.substr(0,cpos).ascii();
- String code2 = code.substr(cpos+code_tag.length(),code.length());
+ fragment_code1 = code.substr(0, cpos).ascii();
+ String code2 = code.substr(cpos + code_tag.length(), code.length());
cpos = code2.find(light_code_tag);
- if (cpos==-1) {
- fragment_code2=code2.ascii();
+ if (cpos == -1) {
+ fragment_code2 = code2.ascii();
} else {
- fragment_code2=code2.substr(0,cpos).ascii();
- fragment_code3 = code2.substr(cpos+light_code_tag.length(),code2.length()).ascii();
+ fragment_code2 = code2.substr(0, cpos).ascii();
+ fragment_code3 = code2.substr(cpos + light_code_tag.length(), code2.length()).ascii();
}
}
}
}
-
}
void ShaderGLES2::finish() {
-
- const VersionKey *V=NULL;
- while((V=version_map.next(V))) {
-
- Version &v=version_map[*V];
- glDeleteShader( v.vert_id );
- glDeleteShader( v.frag_id );
- glDeleteProgram( v.id );
- memdelete_arr( v.uniform_location );
+ const VersionKey *V = NULL;
+ while ((V = version_map.next(V))) {
+
+ Version &v = version_map[*V];
+ glDeleteShader(v.vert_id);
+ glDeleteShader(v.frag_id);
+ glDeleteProgram(v.id);
+ memdelete_arr(v.uniform_location);
}
-
}
-
void ShaderGLES2::clear_caches() {
- const VersionKey *V=NULL;
- while((V=version_map.next(V))) {
-
- Version &v=version_map[*V];
- glDeleteShader( v.vert_id );
- glDeleteShader( v.frag_id );
- glDeleteProgram( v.id );
- memdelete_arr( v.uniform_location );
+ const VersionKey *V = NULL;
+ while ((V = version_map.next(V))) {
+
+ Version &v = version_map[*V];
+ glDeleteShader(v.vert_id);
+ glDeleteShader(v.frag_id);
+ glDeleteProgram(v.id);
+ memdelete_arr(v.uniform_location);
}
version_map.clear();
custom_code_map.clear();
- version=NULL;
- last_custom_code=1;
+ version = NULL;
+ last_custom_code = 1;
uniforms_dirty = true;
-
}
uint32_t ShaderGLES2::create_custom_shader() {
- custom_code_map[last_custom_code]=CustomCode();
- custom_code_map[last_custom_code].version=1;
+ custom_code_map[last_custom_code] = CustomCode();
+ custom_code_map[last_custom_code].version = 1;
return last_custom_code++;
}
-void ShaderGLES2::set_custom_shader_code(uint32_t p_code_id, const String& p_vertex, const String& p_vertex_globals,const String& p_fragment,const String& p_light, const String& p_fragment_globals,const Vector<StringName>& p_uniforms,const Vector<const char*> &p_custom_defines) {
+void ShaderGLES2::set_custom_shader_code(uint32_t p_code_id, const String &p_vertex, const String &p_vertex_globals, const String &p_fragment, const String &p_light, const String &p_fragment_globals, const Vector<StringName> &p_uniforms, const Vector<const char *> &p_custom_defines) {
ERR_FAIL_COND(!custom_code_map.has(p_code_id));
- CustomCode *cc=&custom_code_map[p_code_id];
-
- cc->vertex=p_vertex;
- cc->vertex_globals=p_vertex_globals;
- cc->fragment=p_fragment;
- cc->fragment_globals=p_fragment_globals;
- cc->light=p_light;
- cc->custom_uniforms=p_uniforms;
- cc->custom_defines=p_custom_defines;
+ CustomCode *cc = &custom_code_map[p_code_id];
+
+ cc->vertex = p_vertex;
+ cc->vertex_globals = p_vertex_globals;
+ cc->fragment = p_fragment;
+ cc->fragment_globals = p_fragment_globals;
+ cc->light = p_light;
+ cc->custom_uniforms = p_uniforms;
+ cc->custom_defines = p_custom_defines;
cc->version++;
}
void ShaderGLES2::set_custom_shader(uint32_t p_code_id) {
- new_conditional_version.code_version=p_code_id;
+ new_conditional_version.code_version = p_code_id;
}
void ShaderGLES2::free_custom_shader(uint32_t p_code_id) {
- /* if (! custom_code_map.has( p_code_id )) {
+ /* if (! custom_code_map.has( p_code_id )) {
print_line("no code id "+itos(p_code_id));
} else {
print_line("freed code id "+itos(p_code_id));
}*/
- ERR_FAIL_COND(! custom_code_map.has( p_code_id ));
- if (conditional_version.code_version==p_code_id)
- conditional_version.code_version=0; //bye
+ ERR_FAIL_COND(!custom_code_map.has(p_code_id));
+ if (conditional_version.code_version == p_code_id)
+ conditional_version.code_version = 0; //bye
custom_code_map.erase(p_code_id);
-
}
-
-
ShaderGLES2::ShaderGLES2() {
- version=NULL;
- last_custom_code=1;
+ version = NULL;
+ last_custom_code = 1;
uniforms_dirty = true;
}
-
ShaderGLES2::~ShaderGLES2() {
-
+
finish();
}
-
#endif
diff --git a/drivers/gles2/shader_gles2.h b/drivers/gles2/shader_gles2.h
index 004d636c1e..a292fda7fe 100644
--- a/drivers/gles2/shader_gles2.h
+++ b/drivers/gles2/shader_gles2.h
@@ -38,19 +38,17 @@
#include GLES2_INCLUDE_H
#endif
+#include "camera_matrix.h"
#include "hash_map.h"
#include "map.h"
#include "variant.h"
-#include "camera_matrix.h"
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
-
class ShaderGLES2 {
-protected:
-
+protected:
struct Enum {
uint64_t mask;
@@ -71,7 +69,7 @@ protected:
};
struct UniformPair {
- const char* name;
+ const char *name;
Variant::Type type_hint;
};
@@ -82,8 +80,8 @@ protected:
};
bool uniforms_dirty;
-private:
+private:
//@TODO Optimize to a fixed set of shader pools and use a LRU
int uniform_count;
int texunit_pair_count;
@@ -101,23 +99,25 @@ private:
String light;
uint32_t version;
Vector<StringName> custom_uniforms;
- Vector<const char*> custom_defines;
-
+ Vector<const char *> custom_defines;
};
-
struct Version {
-
+
GLuint id;
GLuint vert_id;
- GLuint frag_id;
+ GLuint frag_id;
GLint *uniform_location;
Vector<GLint> custom_uniform_locations;
uint32_t code_version;
bool ok;
- Version() { code_version=0; ok=false; uniform_location=NULL; }
+ Version() {
+ code_version = 0;
+ ok = false;
+ uniform_location = NULL;
+ }
};
-
+
Version *version;
union VersionKey {
@@ -127,34 +127,32 @@ private:
uint32_t code_version;
};
uint64_t key;
- bool operator==(const VersionKey& p_key) const { return key==p_key.key; }
- bool operator<(const VersionKey& p_key) const { return key<p_key.key; }
-
+ bool operator==(const VersionKey &p_key) const { return key == p_key.key; }
+ bool operator<(const VersionKey &p_key) const { return key < p_key.key; }
};
struct VersionKeyHash {
- static _FORCE_INLINE_ uint32_t hash( const VersionKey& p_key) { return HashMapHasherDefault::hash(p_key.key); };
+ static _FORCE_INLINE_ uint32_t hash(const VersionKey &p_key) { return HashMapHasherDefault::hash(p_key.key); };
};
//this should use a way more cachefriendly version..
- HashMap<VersionKey,Version,VersionKeyHash> version_map;
+ HashMap<VersionKey, Version, VersionKeyHash> version_map;
- HashMap<uint32_t,CustomCode> custom_code_map;
+ HashMap<uint32_t, CustomCode> custom_code_map;
uint32_t last_custom_code;
-
-
+
VersionKey conditional_version;
VersionKey new_conditional_version;
-
- virtual String get_shader_name() const=0;
-
- const char** conditional_defines;
- const char** uniform_names;
+
+ virtual String get_shader_name() const = 0;
+
+ const char **conditional_defines;
+ const char **uniform_names;
const AttributePair *attribute_pairs;
const TexUnitPair *texunit_pairs;
- const char* vertex_code;
- const char* fragment_code;
+ const char *vertex_code;
+ const char *fragment_code;
CharString fragment_code0;
CharString fragment_code1;
CharString fragment_code2;
@@ -164,204 +162,196 @@ private:
CharString vertex_code1;
CharString vertex_code2;
- Version * get_current_version();
-
+ Version *get_current_version();
+
static ShaderGLES2 *active;
- _FORCE_INLINE_ void _set_uniform_variant(GLint p_uniform,const Variant& p_value) {
+ _FORCE_INLINE_ void _set_uniform_variant(GLint p_uniform, const Variant &p_value) {
- if (p_uniform<0)
+ if (p_uniform < 0)
return; // do none
- switch(p_value.get_type()) {
+ switch (p_value.get_type()) {
- case Variant::BOOL:
- case Variant::INT:/* {
+ case Variant::BOOL:
+ case Variant::INT: /* {
int val=p_value;
glUniform1i( p_uniform, val );
} break; */
- case Variant::REAL: {
-
- real_t val=p_value;
- glUniform1f( p_uniform, val );
- } break;
- case Variant::COLOR: {
-
- Color val=p_value;
- glUniform4f( p_uniform, val.r, val.g,val.b,val.a );
- } break;
- case Variant::VECTOR2: {
-
- Vector2 val=p_value;
- glUniform2f( p_uniform, val.x,val.y );
- } break;
- case Variant::VECTOR3: {
-
- Vector3 val=p_value;
- glUniform3f( p_uniform, val.x,val.y,val.z );
- } break;
- case Variant::PLANE: {
-
- Plane val=p_value;
- glUniform4f( p_uniform, val.normal.x,val.normal.y,val.normal.z,val.d );
- } break;
- case Variant::QUAT: {
-
- Quat val=p_value;
- glUniform4f( p_uniform, val.x,val.y,val.z,val.w );
- } break;
-
- case Variant::MATRIX32: {
-
- Transform2D tr=p_value;
- GLfloat matrix[16]={ /* build a 16x16 matrix */
- tr.elements[0][0],
- tr.elements[0][1],
- 0,
- 0,
- tr.elements[1][0],
- tr.elements[1][1],
- 0,
- 0,
- 0,
- 0,
- 1,
- 0,
- tr.elements[2][0],
- tr.elements[2][1],
- 0,
- 1
- };
-
- glUniformMatrix4fv(p_uniform,1,false,matrix);
-
- } break;
- case Variant::MATRIX3:
- case Variant::TRANSFORM: {
-
- Transform tr=p_value;
- GLfloat matrix[16]={ /* build a 16x16 matrix */
- tr.basis.elements[0][0],
- tr.basis.elements[1][0],
- tr.basis.elements[2][0],
- 0,
- tr.basis.elements[0][1],
- tr.basis.elements[1][1],
- tr.basis.elements[2][1],
- 0,
- tr.basis.elements[0][2],
- tr.basis.elements[1][2],
- tr.basis.elements[2][2],
- 0,
- tr.origin.x,
- tr.origin.y,
- tr.origin.z,
- 1
- };
-
-
- glUniformMatrix4fv(p_uniform,1,false,matrix);
- } break;
- default: { ERR_FAIL(); } // do nothing
-
- }
+ case Variant::REAL: {
+
+ real_t val = p_value;
+ glUniform1f(p_uniform, val);
+ } break;
+ case Variant::COLOR: {
+
+ Color val = p_value;
+ glUniform4f(p_uniform, val.r, val.g, val.b, val.a);
+ } break;
+ case Variant::VECTOR2: {
+
+ Vector2 val = p_value;
+ glUniform2f(p_uniform, val.x, val.y);
+ } break;
+ case Variant::VECTOR3: {
+
+ Vector3 val = p_value;
+ glUniform3f(p_uniform, val.x, val.y, val.z);
+ } break;
+ case Variant::PLANE: {
+
+ Plane val = p_value;
+ glUniform4f(p_uniform, val.normal.x, val.normal.y, val.normal.z, val.d);
+ } break;
+ case Variant::QUAT: {
+
+ Quat val = p_value;
+ glUniform4f(p_uniform, val.x, val.y, val.z, val.w);
+ } break;
+
+ case Variant::MATRIX32: {
+
+ Transform2D tr = p_value;
+ GLfloat matrix[16] = { /* build a 16x16 matrix */
+ tr.elements[0][0],
+ tr.elements[0][1],
+ 0,
+ 0,
+ tr.elements[1][0],
+ tr.elements[1][1],
+ 0,
+ 0,
+ 0,
+ 0,
+ 1,
+ 0,
+ tr.elements[2][0],
+ tr.elements[2][1],
+ 0,
+ 1
+ };
+
+ glUniformMatrix4fv(p_uniform, 1, false, matrix);
+
+ } break;
+ case Variant::MATRIX3:
+ case Variant::TRANSFORM: {
+
+ Transform tr = p_value;
+ GLfloat matrix[16] = { /* build a 16x16 matrix */
+ tr.basis.elements[0][0],
+ tr.basis.elements[1][0],
+ tr.basis.elements[2][0],
+ 0,
+ tr.basis.elements[0][1],
+ tr.basis.elements[1][1],
+ tr.basis.elements[2][1],
+ 0,
+ tr.basis.elements[0][2],
+ tr.basis.elements[1][2],
+ tr.basis.elements[2][2],
+ 0,
+ tr.origin.x,
+ tr.origin.y,
+ tr.origin.z,
+ 1
+ };
+
+ glUniformMatrix4fv(p_uniform, 1, false, matrix);
+ } break;
+ default: { ERR_FAIL(); } // do nothing
+ }
}
- Map<uint32_t,Variant> uniform_defaults;
- Map<uint32_t,CameraMatrix> uniform_cameras;
-
-
-protected:
+ Map<uint32_t, Variant> uniform_defaults;
+ Map<uint32_t, CameraMatrix> uniform_cameras;
+protected:
_FORCE_INLINE_ int _get_uniform(int p_which) const;
_FORCE_INLINE_ void _set_conditional(int p_which, bool p_value);
-
- void setup(const char** p_conditional_defines, int p_conditional_count,const char** p_uniform_names,int p_uniform_count, const AttributePair* p_attribute_pairs, int p_attribute_count, const TexUnitPair *p_texunit_pairs, int p_texunit_pair_count,const char*p_vertex_code, const char *p_fragment_code,int p_vertex_code_start,int p_fragment_code_start);
-
+
+ void setup(const char **p_conditional_defines, int p_conditional_count, const char **p_uniform_names, int p_uniform_count, const AttributePair *p_attribute_pairs, int p_attribute_count, const TexUnitPair *p_texunit_pairs, int p_texunit_pair_count, const char *p_vertex_code, const char *p_fragment_code, int p_vertex_code_start, int p_fragment_code_start);
+
ShaderGLES2();
+
public:
-
enum {
- CUSTOM_SHADER_DISABLED=0
+ CUSTOM_SHADER_DISABLED = 0
};
- GLint get_uniform_location(const String& p_name) const;
+ GLint get_uniform_location(const String &p_name) const;
GLint get_uniform_location(int p_uniform) const;
-
+
static _FORCE_INLINE_ ShaderGLES2 *get_active() { return active; };
bool bind();
void unbind();
void bind_uniforms();
-
- inline GLuint get_program() const { return version?version->id:0; }
-
+ inline GLuint get_program() const { return version ? version->id : 0; }
+
void clear_caches();
uint32_t create_custom_shader();
- void set_custom_shader_code(uint32_t p_id,const String& p_vertex, const String& p_vertex_globals,const String& p_fragment,const String& p_p_light,const String& p_fragment_globals,const Vector<StringName>& p_uniforms,const Vector<const char*> &p_custom_defines);
+ void set_custom_shader_code(uint32_t p_id, const String &p_vertex, const String &p_vertex_globals, const String &p_fragment, const String &p_p_light, const String &p_fragment_globals, const Vector<StringName> &p_uniforms, const Vector<const char *> &p_custom_defines);
void set_custom_shader(uint32_t p_id);
void free_custom_shader(uint32_t p_id);
- void set_uniform_default(int p_idx, const Variant& p_value) {
+ void set_uniform_default(int p_idx, const Variant &p_value) {
- if (p_value.get_type()==Variant::NIL) {
+ if (p_value.get_type() == Variant::NIL) {
uniform_defaults.erase(p_idx);
} else {
- uniform_defaults[p_idx]=p_value;
+ uniform_defaults[p_idx] = p_value;
}
uniforms_dirty = true;
};
uint32_t get_version() const { return new_conditional_version.version; }
- void set_uniform_camera(int p_idx, const CameraMatrix& p_mat) {
+ void set_uniform_camera(int p_idx, const CameraMatrix &p_mat) {
uniform_cameras[p_idx] = p_mat;
uniforms_dirty = true;
};
- _FORCE_INLINE_ void set_custom_uniform(int p_idx, const Variant& p_value) {
+ _FORCE_INLINE_ void set_custom_uniform(int p_idx, const Variant &p_value) {
ERR_FAIL_COND(!version);
- ERR_FAIL_INDEX(p_idx,version->custom_uniform_locations.size());
- _set_uniform_variant( version->custom_uniform_locations[p_idx], p_value );
+ ERR_FAIL_INDEX(p_idx, version->custom_uniform_locations.size());
+ _set_uniform_variant(version->custom_uniform_locations[p_idx], p_value);
}
-
+
_FORCE_INLINE_ GLint get_custom_uniform_location(int p_idx) {
- ERR_FAIL_COND_V(!version,-1);
- ERR_FAIL_INDEX_V(p_idx,version->custom_uniform_locations.size(),-1);
+ ERR_FAIL_COND_V(!version, -1);
+ ERR_FAIL_INDEX_V(p_idx, version->custom_uniform_locations.size(), -1);
return version->custom_uniform_locations[p_idx];
}
- virtual void init()=0;
+ virtual void init() = 0;
void finish();
virtual ~ShaderGLES2();
-
};
-
-// called a lot, made inline
-
+// called a lot, made inline
int ShaderGLES2::_get_uniform(int p_which) const {
-
- ERR_FAIL_INDEX_V( p_which, uniform_count,-1 );
- ERR_FAIL_COND_V( !version, -1 );
+
+ ERR_FAIL_INDEX_V(p_which, uniform_count, -1);
+ ERR_FAIL_COND_V(!version, -1);
return version->uniform_location[p_which];
}
void ShaderGLES2::_set_conditional(int p_which, bool p_value) {
-
- ERR_FAIL_INDEX(p_which,conditional_count);
+
+ ERR_FAIL_INDEX(p_which, conditional_count);
if (p_value)
- new_conditional_version.version|=(1<<p_which);
+ new_conditional_version.version |= (1 << p_which);
else
- new_conditional_version.version&=~(1<<p_which);
+ new_conditional_version.version &= ~(1 << p_which);
}
#endif
diff --git a/drivers/gles3/rasterizer_canvas_gles3.cpp b/drivers/gles3/rasterizer_canvas_gles3.cpp
index 2526aad074..26d13bad89 100644
--- a/drivers/gles3/rasterizer_canvas_gles3.cpp
+++ b/drivers/gles3/rasterizer_canvas_gles3.cpp
@@ -34,60 +34,58 @@
#define glClearDepth glClearDepthf
#endif
-static _FORCE_INLINE_ void store_transform2d(const Transform2D& p_mtx, float* p_array) {
-
- p_array[ 0]=p_mtx.elements[0][0];
- p_array[ 1]=p_mtx.elements[0][1];
- p_array[ 2]=0;
- p_array[ 3]=0;
- p_array[ 4]=p_mtx.elements[1][0];
- p_array[ 5]=p_mtx.elements[1][1];
- p_array[ 6]=0;
- p_array[ 7]=0;
- p_array[ 8]=0;
- p_array[ 9]=0;
- p_array[10]=1;
- p_array[11]=0;
- p_array[12]=p_mtx.elements[2][0];
- p_array[13]=p_mtx.elements[2][1];
- p_array[14]=0;
- p_array[15]=1;
+static _FORCE_INLINE_ void store_transform2d(const Transform2D &p_mtx, float *p_array) {
+
+ p_array[0] = p_mtx.elements[0][0];
+ p_array[1] = p_mtx.elements[0][1];
+ p_array[2] = 0;
+ p_array[3] = 0;
+ p_array[4] = p_mtx.elements[1][0];
+ p_array[5] = p_mtx.elements[1][1];
+ p_array[6] = 0;
+ p_array[7] = 0;
+ p_array[8] = 0;
+ p_array[9] = 0;
+ p_array[10] = 1;
+ p_array[11] = 0;
+ p_array[12] = p_mtx.elements[2][0];
+ p_array[13] = p_mtx.elements[2][1];
+ p_array[14] = 0;
+ p_array[15] = 1;
}
-
-static _FORCE_INLINE_ void store_transform(const Transform& p_mtx, float* p_array) {
- p_array[ 0]=p_mtx.basis.elements[0][0];
- p_array[ 1]=p_mtx.basis.elements[1][0];
- p_array[ 2]=p_mtx.basis.elements[2][0];
- p_array[ 3]=0;
- p_array[ 4]=p_mtx.basis.elements[0][1];
- p_array[ 5]=p_mtx.basis.elements[1][1];
- p_array[ 6]=p_mtx.basis.elements[2][1];
- p_array[ 7]=0;
- p_array[ 8]=p_mtx.basis.elements[0][2];
- p_array[ 9]=p_mtx.basis.elements[1][2];
- p_array[10]=p_mtx.basis.elements[2][2];
- p_array[11]=0;
- p_array[12]=p_mtx.origin.x;
- p_array[13]=p_mtx.origin.y;
- p_array[14]=p_mtx.origin.z;
- p_array[15]=1;
+static _FORCE_INLINE_ void store_transform(const Transform &p_mtx, float *p_array) {
+ p_array[0] = p_mtx.basis.elements[0][0];
+ p_array[1] = p_mtx.basis.elements[1][0];
+ p_array[2] = p_mtx.basis.elements[2][0];
+ p_array[3] = 0;
+ p_array[4] = p_mtx.basis.elements[0][1];
+ p_array[5] = p_mtx.basis.elements[1][1];
+ p_array[6] = p_mtx.basis.elements[2][1];
+ p_array[7] = 0;
+ p_array[8] = p_mtx.basis.elements[0][2];
+ p_array[9] = p_mtx.basis.elements[1][2];
+ p_array[10] = p_mtx.basis.elements[2][2];
+ p_array[11] = 0;
+ p_array[12] = p_mtx.origin.x;
+ p_array[13] = p_mtx.origin.y;
+ p_array[14] = p_mtx.origin.z;
+ p_array[15] = 1;
}
-static _FORCE_INLINE_ void store_camera(const CameraMatrix& p_mtx, float* p_array) {
+static _FORCE_INLINE_ void store_camera(const CameraMatrix &p_mtx, float *p_array) {
- for (int i=0;i<4;i++) {
- for (int j=0;j<4;j++) {
+ for (int i = 0; i < 4; i++) {
+ for (int j = 0; j < 4; j++) {
- p_array[i*4+j]=p_mtx.matrix[i][j];
+ p_array[i * 4 + j] = p_mtx.matrix[i][j];
}
}
}
-
RID RasterizerCanvasGLES3::light_internal_create() {
- LightInternal * li = memnew( LightInternal );
+ LightInternal *li = memnew(LightInternal);
glGenBuffers(1, &li->ubo);
glBindBuffer(GL_UNIFORM_BUFFER, li->ubo);
@@ -97,60 +95,56 @@ RID RasterizerCanvasGLES3::light_internal_create() {
return light_internal_owner.make_rid(li);
}
-void RasterizerCanvasGLES3::light_internal_update(RID p_rid, Light* p_light) {
+void RasterizerCanvasGLES3::light_internal_update(RID p_rid, Light *p_light) {
- LightInternal * li = light_internal_owner.getornull(p_rid);
+ LightInternal *li = light_internal_owner.getornull(p_rid);
ERR_FAIL_COND(!li);
- store_transform2d(p_light->light_shader_xform,li->ubo_data.light_matrix);
- store_transform2d(p_light->xform_cache.affine_inverse(),li->ubo_data.local_matrix);
- store_camera(p_light->shadow_matrix_cache,li->ubo_data.shadow_matrix);
+ store_transform2d(p_light->light_shader_xform, li->ubo_data.light_matrix);
+ store_transform2d(p_light->xform_cache.affine_inverse(), li->ubo_data.local_matrix);
+ store_camera(p_light->shadow_matrix_cache, li->ubo_data.shadow_matrix);
- for(int i=0;i<4;i++) {
+ for (int i = 0; i < 4; i++) {
- li->ubo_data.color[i]=p_light->color[i]*p_light->energy;
- li->ubo_data.shadow_color[i]=p_light->shadow_color[i];
+ li->ubo_data.color[i] = p_light->color[i] * p_light->energy;
+ li->ubo_data.shadow_color[i] = p_light->shadow_color[i];
}
- li->ubo_data.light_pos[0]=p_light->light_shader_pos.x;
- li->ubo_data.light_pos[1]=p_light->light_shader_pos.y;
- li->ubo_data.shadowpixel_size=1.0/p_light->shadow_buffer_size;
- li->ubo_data.light_outside_alpha=p_light->mode==VS::CANVAS_LIGHT_MODE_MASK?1.0:0.0;
- li->ubo_data.light_height=p_light->height;
- if (p_light->radius_cache==0)
- li->ubo_data.shadow_gradient=0;
+ li->ubo_data.light_pos[0] = p_light->light_shader_pos.x;
+ li->ubo_data.light_pos[1] = p_light->light_shader_pos.y;
+ li->ubo_data.shadowpixel_size = 1.0 / p_light->shadow_buffer_size;
+ li->ubo_data.light_outside_alpha = p_light->mode == VS::CANVAS_LIGHT_MODE_MASK ? 1.0 : 0.0;
+ li->ubo_data.light_height = p_light->height;
+ if (p_light->radius_cache == 0)
+ li->ubo_data.shadow_gradient = 0;
else
- li->ubo_data.shadow_gradient=p_light->shadow_gradient_length/(p_light->radius_cache*1.1);
-
- li->ubo_data.shadow_distance_mult=(p_light->radius_cache*1.1);
+ li->ubo_data.shadow_gradient = p_light->shadow_gradient_length / (p_light->radius_cache * 1.1);
+ li->ubo_data.shadow_distance_mult = (p_light->radius_cache * 1.1);
glBindBuffer(GL_UNIFORM_BUFFER, li->ubo);
- glBufferSubData(GL_UNIFORM_BUFFER, 0,sizeof(LightInternal::UBOData), &li->ubo_data);
+ glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(LightInternal::UBOData), &li->ubo_data);
glBindBuffer(GL_UNIFORM_BUFFER, 0);
-
}
void RasterizerCanvasGLES3::light_internal_free(RID p_rid) {
- LightInternal * li = light_internal_owner.getornull(p_rid);
+ LightInternal *li = light_internal_owner.getornull(p_rid);
ERR_FAIL_COND(!li);
- glDeleteBuffers(1,&li->ubo);
+ glDeleteBuffers(1, &li->ubo);
light_internal_owner.free(p_rid);
memdelete(li);
-
}
-void RasterizerCanvasGLES3::canvas_begin(){
+void RasterizerCanvasGLES3::canvas_begin() {
if (storage->frame.current_rt && storage->frame.clear_request) {
// a clear request may be pending, so do it
- glClearColor( storage->frame.clear_request_color.r, storage->frame.clear_request_color.g, storage->frame.clear_request_color.b, storage->frame.clear_request_color.a );
+ glClearColor(storage->frame.clear_request_color.r, storage->frame.clear_request_color.g, storage->frame.clear_request_color.b, storage->frame.clear_request_color.a);
glClear(GL_COLOR_BUFFER_BIT);
- storage->frame.clear_request=false;
-
+ storage->frame.clear_request = false;
}
/*canvas_shader.unbind();
@@ -162,138 +156,118 @@ void RasterizerCanvasGLES3::canvas_begin(){
reset_canvas();
- state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_TEXTURE_RECT,true);
- state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_LIGHTING,false);
- state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_SHADOWS,false);
- state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_NEAREST,false);
- state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_PCF5,false);
- state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_PCF13,false);
- state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_DISTANCE_FIELD,false);
-
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_TEXTURE_RECT, true);
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_LIGHTING, false);
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_SHADOWS, false);
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_NEAREST, false);
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_PCF5, false);
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_PCF13, false);
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_DISTANCE_FIELD, false);
state.canvas_shader.set_custom_shader(0);
state.canvas_shader.bind();
- state.canvas_shader.set_uniform(CanvasShaderGLES3::FINAL_MODULATE,Color(1,1,1,1));
- state.canvas_shader.set_uniform(CanvasShaderGLES3::MODELVIEW_MATRIX,Transform2D());
- state.canvas_shader.set_uniform(CanvasShaderGLES3::EXTRA_MATRIX,Transform2D());
-
-
-
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::FINAL_MODULATE, Color(1, 1, 1, 1));
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::MODELVIEW_MATRIX, Transform2D());
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::EXTRA_MATRIX, Transform2D());
//state.canvas_shader.set_uniform(CanvasShaderGLES3::PROJECTION_MATRIX,state.vp);
//state.canvas_shader.set_uniform(CanvasShaderGLES3::MODELVIEW_MATRIX,Transform());
//state.canvas_shader.set_uniform(CanvasShaderGLES3::EXTRA_MATRIX,Transform());
- glBindBufferBase(GL_UNIFORM_BUFFER,0,state.canvas_item_ubo);
+ glBindBufferBase(GL_UNIFORM_BUFFER, 0, state.canvas_item_ubo);
glBindVertexArray(data.canvas_quad_array);
- state.using_texture_rect=true;
-
-
+ state.using_texture_rect = true;
}
-
-void RasterizerCanvasGLES3::canvas_end(){
-
+void RasterizerCanvasGLES3::canvas_end() {
glBindVertexArray(0);
- glBindBufferBase(GL_UNIFORM_BUFFER,0,0);
-
- state.using_texture_rect=false;
+ glBindBufferBase(GL_UNIFORM_BUFFER, 0, 0);
+ state.using_texture_rect = false;
}
+RasterizerStorageGLES3::Texture *RasterizerCanvasGLES3::_bind_canvas_texture(const RID &p_texture) {
-
-RasterizerStorageGLES3::Texture* RasterizerCanvasGLES3::_bind_canvas_texture(const RID& p_texture) {
-
- if (p_texture==state.current_tex) {
+ if (p_texture == state.current_tex) {
return state.current_tex_ptr;
}
if (p_texture.is_valid()) {
-
- RasterizerStorageGLES3::Texture*texture=storage->texture_owner.getornull(p_texture);
+ RasterizerStorageGLES3::Texture *texture = storage->texture_owner.getornull(p_texture);
if (!texture) {
- state.current_tex=RID();
- state.current_tex_ptr=NULL;
- glBindTexture(GL_TEXTURE_2D,storage->resources.white_tex);
+ state.current_tex = RID();
+ state.current_tex_ptr = NULL;
+ glBindTexture(GL_TEXTURE_2D, storage->resources.white_tex);
return NULL;
}
if (texture->render_target)
- texture->render_target->used_in_frame=true;
+ texture->render_target->used_in_frame = true;
- glBindTexture(GL_TEXTURE_2D,texture->tex_id);
- state.current_tex=p_texture;
- state.current_tex_ptr=texture;
+ glBindTexture(GL_TEXTURE_2D, texture->tex_id);
+ state.current_tex = p_texture;
+ state.current_tex_ptr = texture;
return texture;
-
} else {
-
- glBindTexture(GL_TEXTURE_2D,storage->resources.white_tex);
- state.current_tex=RID();
- state.current_tex_ptr=NULL;
+ glBindTexture(GL_TEXTURE_2D, storage->resources.white_tex);
+ state.current_tex = RID();
+ state.current_tex_ptr = NULL;
}
-
return NULL;
}
void RasterizerCanvasGLES3::_set_texture_rect_mode(bool p_enable) {
- if (state.using_texture_rect==p_enable)
+ if (state.using_texture_rect == p_enable)
return;
if (p_enable) {
glBindVertexArray(data.canvas_quad_array);
-
} else {
glBindVertexArray(0);
- glBindBuffer(GL_ARRAY_BUFFER,0);
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0);
-
-
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}
- state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_TEXTURE_RECT,p_enable);
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_TEXTURE_RECT, p_enable);
state.canvas_shader.bind();
- state.canvas_shader.set_uniform(CanvasShaderGLES3::FINAL_MODULATE,state.canvas_item_modulate);
- state.canvas_shader.set_uniform(CanvasShaderGLES3::MODELVIEW_MATRIX,state.final_transform);
- state.canvas_shader.set_uniform(CanvasShaderGLES3::EXTRA_MATRIX,state.extra_matrix);
-
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::FINAL_MODULATE, state.canvas_item_modulate);
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::MODELVIEW_MATRIX, state.final_transform);
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::EXTRA_MATRIX, state.extra_matrix);
- state.using_texture_rect=p_enable;
+ state.using_texture_rect = p_enable;
}
+void RasterizerCanvasGLES3::_draw_polygon(int p_vertex_count, const int *p_indices, const Vector2 *p_vertices, const Vector2 *p_uvs, const Color *p_colors, const RID &p_texture, bool p_singlecolor) {
-void RasterizerCanvasGLES3::_draw_polygon(int p_vertex_count, const int* p_indices, const Vector2* p_vertices, const Vector2* p_uvs, const Color* p_colors,const RID& p_texture,bool p_singlecolor) {
-
- bool do_colors=false;
+ bool do_colors = false;
Color m;
if (p_singlecolor) {
m = *p_colors;
- glVertexAttrib4f(VS::ARRAY_COLOR,m.r,m.g,m.b,m.a);
+ glVertexAttrib4f(VS::ARRAY_COLOR, m.r, m.g, m.b, m.a);
} else if (!p_colors) {
- glVertexAttrib4f(VS::ARRAY_COLOR,1,1,1,1);
+ glVertexAttrib4f(VS::ARRAY_COLOR, 1, 1, 1, 1);
} else
- do_colors=true;
+ do_colors = true;
RasterizerStorageGLES3::Texture *texture = _bind_canvas_texture(p_texture);
#ifndef GLES_NO_CLIENT_ARRAYS
glEnableVertexAttribArray(VS::ARRAY_VERTEX);
- glVertexAttribPointer( VS::ARRAY_VERTEX, 2 ,GL_FLOAT, false, sizeof(Vector2), p_vertices );
+ glVertexAttribPointer(VS::ARRAY_VERTEX, 2, GL_FLOAT, false, sizeof(Vector2), p_vertices);
if (do_colors) {
glEnableVertexAttribArray(VS::ARRAY_COLOR);
- glVertexAttribPointer( VS::ARRAY_COLOR, 4 ,GL_FLOAT, false, sizeof(Color), p_colors );
+ glVertexAttribPointer(VS::ARRAY_COLOR, 4, GL_FLOAT, false, sizeof(Color), p_colors);
} else {
glDisableVertexAttribArray(VS::ARRAY_COLOR);
}
@@ -301,71 +275,69 @@ void RasterizerCanvasGLES3::_draw_polygon(int p_vertex_count, const int* p_indic
if (texture && p_uvs) {
glEnableVertexAttribArray(VS::ARRAY_TEX_UV);
- glVertexAttribPointer( VS::ARRAY_TEX_UV, 2 ,GL_FLOAT, false, sizeof(Vector2), p_uvs );
+ glVertexAttribPointer(VS::ARRAY_TEX_UV, 2, GL_FLOAT, false, sizeof(Vector2), p_uvs);
} else {
glDisableVertexAttribArray(VS::ARRAY_TEX_UV);
}
if (p_indices) {
- glDrawElements(GL_TRIANGLES, p_vertex_count, GL_UNSIGNED_INT, p_indices );
+ glDrawElements(GL_TRIANGLES, p_vertex_count, GL_UNSIGNED_INT, p_indices);
} else {
- glDrawArrays(GL_TRIANGLES,0,p_vertex_count);
+ glDrawArrays(GL_TRIANGLES, 0, p_vertex_count);
}
-
#else //WebGL specific impl.
glBindBuffer(GL_ARRAY_BUFFER, gui_quad_buffer);
float *b = GlobalVertexBuffer;
int ofs = 0;
- if(p_vertex_count > MAX_POLYGON_VERTICES){
+ if (p_vertex_count > MAX_POLYGON_VERTICES) {
print_line("Too many vertices to render");
return;
}
glEnableVertexAttribArray(VS::ARRAY_VERTEX);
- glVertexAttribPointer( VS::ARRAY_VERTEX, 2 ,GL_FLOAT, false, sizeof(float)*2, ((float*)0)+ofs );
- for(int i=0;i<p_vertex_count;i++) {
- b[ofs++]=p_vertices[i].x;
- b[ofs++]=p_vertices[i].y;
+ glVertexAttribPointer(VS::ARRAY_VERTEX, 2, GL_FLOAT, false, sizeof(float) * 2, ((float *)0) + ofs);
+ for (int i = 0; i < p_vertex_count; i++) {
+ b[ofs++] = p_vertices[i].x;
+ b[ofs++] = p_vertices[i].y;
}
if (p_colors && do_colors) {
glEnableVertexAttribArray(VS::ARRAY_COLOR);
- glVertexAttribPointer( VS::ARRAY_COLOR, 4 ,GL_FLOAT, false, sizeof(float)*4, ((float*)0)+ofs );
- for(int i=0;i<p_vertex_count;i++) {
- b[ofs++]=p_colors[i].r;
- b[ofs++]=p_colors[i].g;
- b[ofs++]=p_colors[i].b;
- b[ofs++]=p_colors[i].a;
+ glVertexAttribPointer(VS::ARRAY_COLOR, 4, GL_FLOAT, false, sizeof(float) * 4, ((float *)0) + ofs);
+ for (int i = 0; i < p_vertex_count; i++) {
+ b[ofs++] = p_colors[i].r;
+ b[ofs++] = p_colors[i].g;
+ b[ofs++] = p_colors[i].b;
+ b[ofs++] = p_colors[i].a;
}
} else {
glDisableVertexAttribArray(VS::ARRAY_COLOR);
}
-
if (p_uvs) {
glEnableVertexAttribArray(VS::ARRAY_TEX_UV);
- glVertexAttribPointer( VS::ARRAY_TEX_UV, 2 ,GL_FLOAT, false, sizeof(float)*2, ((float*)0)+ofs );
- for(int i=0;i<p_vertex_count;i++) {
- b[ofs++]=p_uvs[i].x;
- b[ofs++]=p_uvs[i].y;
+ glVertexAttribPointer(VS::ARRAY_TEX_UV, 2, GL_FLOAT, false, sizeof(float) * 2, ((float *)0) + ofs);
+ for (int i = 0; i < p_vertex_count; i++) {
+ b[ofs++] = p_uvs[i].x;
+ b[ofs++] = p_uvs[i].y;
}
} else {
glDisableVertexAttribArray(VS::ARRAY_TEX_UV);
}
- glBufferSubData(GL_ARRAY_BUFFER,0,ofs*4,&b[0]);
+ glBufferSubData(GL_ARRAY_BUFFER, 0, ofs * 4, &b[0]);
//bind the indices buffer.
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indices_buffer);
- static const int _max_draw_poly_indices = 16*1024; // change this size if needed!!!
+ static const int _max_draw_poly_indices = 16 * 1024; // change this size if needed!!!
ERR_FAIL_COND(p_vertex_count > _max_draw_poly_indices);
static uint16_t _draw_poly_indices[_max_draw_poly_indices];
- for (int i=0; i<p_vertex_count; i++) {
+ for (int i = 0; i < p_vertex_count; i++) {
_draw_poly_indices[i] = p_indices[i];
//OS::get_singleton()->print("ind: %d ", p_indices[i]);
};
@@ -381,99 +353,88 @@ void RasterizerCanvasGLES3::_draw_polygon(int p_vertex_count, const int* p_indic
#endif
storage->frame.canvas_draw_commands++;
-
}
-void RasterizerCanvasGLES3::_draw_gui_primitive(int p_points, const Vector2 *p_vertices, const Color* p_colors, const Vector2 *p_uvs) {
-
-
-
- static const GLenum prim[5]={GL_POINTS,GL_POINTS,GL_LINES,GL_TRIANGLES,GL_TRIANGLE_FAN};
+void RasterizerCanvasGLES3::_draw_gui_primitive(int p_points, const Vector2 *p_vertices, const Color *p_colors, const Vector2 *p_uvs) {
+ static const GLenum prim[5] = { GL_POINTS, GL_POINTS, GL_LINES, GL_TRIANGLES, GL_TRIANGLE_FAN };
//#define GLES_USE_PRIMITIVE_BUFFER
- int version=0;
- int color_ofs=0;
- int uv_ofs=0;
- int stride=2;
+ int version = 0;
+ int color_ofs = 0;
+ int uv_ofs = 0;
+ int stride = 2;
if (p_colors) { //color
- version|=1;
- color_ofs=stride;
- stride+=4;
+ version |= 1;
+ color_ofs = stride;
+ stride += 4;
}
if (p_uvs) { //uv
- version|=2;
- uv_ofs=stride;
- stride+=2;
+ version |= 2;
+ uv_ofs = stride;
+ stride += 2;
}
+ float b[(2 + 2 + 4) * 4];
- float b[(2+2+4)*4];
-
-
- for(int i=0;i<p_points;i++) {
- b[stride*i+0]=p_vertices[i].x;
- b[stride*i+1]=p_vertices[i].y;
+ for (int i = 0; i < p_points; i++) {
+ b[stride * i + 0] = p_vertices[i].x;
+ b[stride * i + 1] = p_vertices[i].y;
}
if (p_colors) {
- for(int i=0;i<p_points;i++) {
- b[stride*i+color_ofs+0]=p_colors[i].r;
- b[stride*i+color_ofs+1]=p_colors[i].g;
- b[stride*i+color_ofs+2]=p_colors[i].b;
- b[stride*i+color_ofs+3]=p_colors[i].a;
+ for (int i = 0; i < p_points; i++) {
+ b[stride * i + color_ofs + 0] = p_colors[i].r;
+ b[stride * i + color_ofs + 1] = p_colors[i].g;
+ b[stride * i + color_ofs + 2] = p_colors[i].b;
+ b[stride * i + color_ofs + 3] = p_colors[i].a;
}
-
}
if (p_uvs) {
- for(int i=0;i<p_points;i++) {
- b[stride*i+uv_ofs+0]=p_uvs[i].x;
- b[stride*i+uv_ofs+1]=p_uvs[i].y;
+ for (int i = 0; i < p_points; i++) {
+ b[stride * i + uv_ofs + 0] = p_uvs[i].x;
+ b[stride * i + uv_ofs + 1] = p_uvs[i].y;
}
-
}
- glBindBuffer(GL_ARRAY_BUFFER,data.primitive_quad_buffer);
- glBufferSubData(GL_ARRAY_BUFFER,0,p_points*stride*4,&b[0]);
+ glBindBuffer(GL_ARRAY_BUFFER, data.primitive_quad_buffer);
+ glBufferSubData(GL_ARRAY_BUFFER, 0, p_points * stride * 4, &b[0]);
glBindVertexArray(data.primitive_quad_buffer_arrays[version]);
- glDrawArrays(prim[p_points],0,p_points);
+ glDrawArrays(prim[p_points], 0, p_points);
glBindVertexArray(0);
- glBindBuffer(GL_ARRAY_BUFFER,0);
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
storage->frame.canvas_draw_commands++;
}
-void RasterizerCanvasGLES3::_canvas_item_render_commands(Item *p_item,Item *current_clip,bool &reclip) {
+void RasterizerCanvasGLES3::_canvas_item_render_commands(Item *p_item, Item *current_clip, bool &reclip) {
- int cc=p_item->commands.size();
+ int cc = p_item->commands.size();
Item::Command **commands = p_item->commands.ptr();
+ for (int i = 0; i < cc; i++) {
- for(int i=0;i<cc;i++) {
+ Item::Command *c = commands[i];
- Item::Command *c=commands[i];
-
- switch(c->type) {
+ switch (c->type) {
case Item::Command::TYPE_LINE: {
-
- Item::CommandLine* line = static_cast<Item::CommandLine*>(c);
+ Item::CommandLine *line = static_cast<Item::CommandLine *>(c);
_set_texture_rect_mode(false);
-
_bind_canvas_texture(RID());
- glVertexAttrib4f(VS::ARRAY_COLOR,line->color.r,line->color.g,line->color.b,line->color.a);
+ glVertexAttrib4f(VS::ARRAY_COLOR, line->color.r, line->color.g, line->color.b, line->color.a);
- Vector2 verts[2]={
- Vector2(line->from.x,line->from.y),
- Vector2(line->to.x,line->to.y)
+ Vector2 verts[2] = {
+ Vector2(line->from.x, line->from.y),
+ Vector2(line->to.x, line->to.y)
};
#ifdef GLES_OVER_GL
@@ -481,72 +442,66 @@ void RasterizerCanvasGLES3::_canvas_item_render_commands(Item *p_item,Item *curr
glEnable(GL_LINE_SMOOTH);
#endif
//glLineWidth(line->width);
- _draw_gui_primitive(2,verts,NULL,NULL);
+ _draw_gui_primitive(2, verts, NULL, NULL);
#ifdef GLES_OVER_GL
if (line->antialiased)
glDisable(GL_LINE_SMOOTH);
#endif
-
} break;
case Item::Command::TYPE_RECT: {
- Item::CommandRect* rect = static_cast<Item::CommandRect*>(c);
+ Item::CommandRect *rect = static_cast<Item::CommandRect *>(c);
_set_texture_rect_mode(true);
//set color
- glVertexAttrib4f(VS::ARRAY_COLOR,rect->modulate.r,rect->modulate.g,rect->modulate.b,rect->modulate.a);
+ glVertexAttrib4f(VS::ARRAY_COLOR, rect->modulate.r, rect->modulate.g, rect->modulate.b, rect->modulate.a);
- RasterizerStorageGLES3::Texture* texture = _bind_canvas_texture(rect->texture);
+ RasterizerStorageGLES3::Texture *texture = _bind_canvas_texture(rect->texture);
- if ( texture ) {
+ if (texture) {
- bool untile=false;
+ bool untile = false;
- if (rect->flags&CANVAS_RECT_TILE && !(texture->flags&VS::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;
+ if (rect->flags & CANVAS_RECT_TILE && !(texture->flags & VS::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;
}
- Size2 texpixel_size( 1.0/texture->width, 1.0/texture->height );
- Rect2 src_rect = (rect->flags&CANVAS_RECT_REGION) ? Rect2( rect->source.pos * texpixel_size, rect->source.size * texpixel_size ) : Rect2(0,0,1,1);
+ Size2 texpixel_size(1.0 / texture->width, 1.0 / texture->height);
+ Rect2 src_rect = (rect->flags & CANVAS_RECT_REGION) ? Rect2(rect->source.pos * texpixel_size, rect->source.size * texpixel_size) : Rect2(0, 0, 1, 1);
- if (rect->flags&CANVAS_RECT_FLIP_H) {
- src_rect.size.x*=-1;
+ if (rect->flags & CANVAS_RECT_FLIP_H) {
+ src_rect.size.x *= -1;
}
- if (rect->flags&CANVAS_RECT_FLIP_V) {
- src_rect.size.y*=-1;
+ if (rect->flags & CANVAS_RECT_FLIP_V) {
+ src_rect.size.y *= -1;
}
- if (rect->flags&CANVAS_RECT_TRANSPOSE) {
+ if (rect->flags & CANVAS_RECT_TRANSPOSE) {
//err..
}
- state.canvas_shader.set_uniform(CanvasShaderGLES3::COLOR_TEXPIXEL_SIZE,texpixel_size);
-
-
- glVertexAttrib4f(1,rect->rect.pos.x,rect->rect.pos.y,rect->rect.size.x,rect->rect.size.y);
- glVertexAttrib4f(2,src_rect.pos.x,src_rect.pos.y,src_rect.size.x,src_rect.size.y);
- glDrawArrays(GL_TRIANGLE_FAN,0,4);
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::COLOR_TEXPIXEL_SIZE, texpixel_size);
+ glVertexAttrib4f(1, rect->rect.pos.x, rect->rect.pos.y, rect->rect.size.x, rect->rect.size.y);
+ glVertexAttrib4f(2, src_rect.pos.x, src_rect.pos.y, src_rect.size.x, src_rect.size.y);
+ glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
if (untile) {
- glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
- glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
}
} else {
-
- glVertexAttrib4f(1,rect->rect.pos.x,rect->rect.pos.y,rect->rect.size.x,rect->rect.size.y);
- glVertexAttrib4f(2,0,0,1,1);
- glDrawArrays(GL_TRIANGLE_FAN,0,4);
-
-
+ glVertexAttrib4f(1, rect->rect.pos.x, rect->rect.pos.y, rect->rect.size.x, rect->rect.size.y);
+ glVertexAttrib4f(2, 0, 0, 1, 1);
+ glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
}
storage->frame.canvas_draw_commands++;
@@ -555,80 +510,75 @@ void RasterizerCanvasGLES3::_canvas_item_render_commands(Item *p_item,Item *curr
case Item::Command::TYPE_NINEPATCH: {
- Item::CommandNinePatch* np = static_cast<Item::CommandNinePatch*>(c);
+ Item::CommandNinePatch *np = static_cast<Item::CommandNinePatch *>(c);
_set_texture_rect_mode(true);
- glVertexAttrib4f(VS::ARRAY_COLOR,np->color.r,np->color.g,np->color.b,np->color.a);
-
+ glVertexAttrib4f(VS::ARRAY_COLOR, np->color.r, np->color.g, np->color.b, np->color.a);
- RasterizerStorageGLES3::Texture* texture = _bind_canvas_texture(np->texture);
+ RasterizerStorageGLES3::Texture *texture = _bind_canvas_texture(np->texture);
- if ( !texture ) {
+ if (!texture) {
- glVertexAttrib4f(1,np->rect.pos.x,np->rect.pos.y,np->rect.size.x,np->rect.size.y);
- glVertexAttrib4f(2,0,0,1,1);
- glDrawArrays(GL_TRIANGLE_FAN,0,4);
+ glVertexAttrib4f(1, np->rect.pos.x, np->rect.pos.y, np->rect.size.x, np->rect.size.y);
+ glVertexAttrib4f(2, 0, 0, 1, 1);
+ glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
continue;
}
+ Size2 texpixel_size(1.0 / texture->width, 1.0 / texture->height);
- Size2 texpixel_size( 1.0/texture->width, 1.0/texture->height );
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::COLOR_TEXPIXEL_SIZE, texpixel_size);
- state.canvas_shader.set_uniform(CanvasShaderGLES3::COLOR_TEXPIXEL_SIZE,texpixel_size);
-
-#define DSTRECT(m_x,m_y,m_w,m_h) glVertexAttrib4f(1,m_x,m_y,m_w,m_h)
-#define SRCRECT(m_x,m_y,m_w,m_h) glVertexAttrib4f(2,(m_x)*texpixel_size.x,(m_y)*texpixel_size.y,(m_w)*texpixel_size.x,(m_h)*texpixel_size.y)
+#define DSTRECT(m_x, m_y, m_w, m_h) glVertexAttrib4f(1, m_x, m_y, m_w, m_h)
+#define SRCRECT(m_x, m_y, m_w, m_h) glVertexAttrib4f(2, (m_x)*texpixel_size.x, (m_y)*texpixel_size.y, (m_w)*texpixel_size.x, (m_h)*texpixel_size.y)
//top left
- DSTRECT(np->rect.pos.x,np->rect.pos.y,np->margin[MARGIN_LEFT],np->margin[MARGIN_TOP]);
- SRCRECT(0,0,np->margin[MARGIN_LEFT],np->margin[MARGIN_TOP]);
- glDrawArrays(GL_TRIANGLE_FAN,0,4);
+ DSTRECT(np->rect.pos.x, np->rect.pos.y, np->margin[MARGIN_LEFT], np->margin[MARGIN_TOP]);
+ SRCRECT(0, 0, np->margin[MARGIN_LEFT], np->margin[MARGIN_TOP]);
+ glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
//top right
- DSTRECT(np->rect.pos.x+np->rect.size.x-np->margin[MARGIN_RIGHT],np->rect.pos.y,np->margin[MARGIN_RIGHT],np->margin[MARGIN_TOP]);
- SRCRECT(texture->width-np->margin[MARGIN_RIGHT],0,np->margin[MARGIN_RIGHT],np->margin[MARGIN_TOP]);
- glDrawArrays(GL_TRIANGLE_FAN,0,4);
+ DSTRECT(np->rect.pos.x + np->rect.size.x - np->margin[MARGIN_RIGHT], np->rect.pos.y, np->margin[MARGIN_RIGHT], np->margin[MARGIN_TOP]);
+ SRCRECT(texture->width - np->margin[MARGIN_RIGHT], 0, np->margin[MARGIN_RIGHT], np->margin[MARGIN_TOP]);
+ glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
//bottom right
- DSTRECT(np->rect.pos.x+np->rect.size.x-np->margin[MARGIN_RIGHT],np->rect.pos.y+np->rect.size.y-np->margin[MARGIN_BOTTOM],np->margin[MARGIN_RIGHT],np->margin[MARGIN_BOTTOM]);
- SRCRECT(texture->width-np->margin[MARGIN_RIGHT],texture->height-np->margin[MARGIN_BOTTOM],np->margin[MARGIN_RIGHT],np->margin[MARGIN_BOTTOM]);
- glDrawArrays(GL_TRIANGLE_FAN,0,4);
+ DSTRECT(np->rect.pos.x + np->rect.size.x - np->margin[MARGIN_RIGHT], np->rect.pos.y + np->rect.size.y - np->margin[MARGIN_BOTTOM], np->margin[MARGIN_RIGHT], np->margin[MARGIN_BOTTOM]);
+ SRCRECT(texture->width - np->margin[MARGIN_RIGHT], texture->height - np->margin[MARGIN_BOTTOM], np->margin[MARGIN_RIGHT], np->margin[MARGIN_BOTTOM]);
+ glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
//bottom left
- DSTRECT(np->rect.pos.x,np->rect.pos.y+np->rect.size.y-np->margin[MARGIN_BOTTOM],np->margin[MARGIN_LEFT],np->margin[MARGIN_BOTTOM]);
- SRCRECT(0,texture->height-np->margin[MARGIN_BOTTOM],np->margin[MARGIN_LEFT],np->margin[MARGIN_BOTTOM]);
- glDrawArrays(GL_TRIANGLE_FAN,0,4);
-
+ DSTRECT(np->rect.pos.x, np->rect.pos.y + np->rect.size.y - np->margin[MARGIN_BOTTOM], np->margin[MARGIN_LEFT], np->margin[MARGIN_BOTTOM]);
+ SRCRECT(0, texture->height - np->margin[MARGIN_BOTTOM], np->margin[MARGIN_LEFT], np->margin[MARGIN_BOTTOM]);
+ glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
//top
- DSTRECT(np->rect.pos.x+np->margin[MARGIN_LEFT],np->rect.pos.y,np->rect.size.width-np->margin[MARGIN_LEFT]-np->margin[MARGIN_RIGHT],np->margin[MARGIN_TOP]);
- SRCRECT(np->margin[MARGIN_LEFT],0,texture->width-np->margin[MARGIN_LEFT]-np->margin[MARGIN_RIGHT],np->margin[MARGIN_TOP]);
- glDrawArrays(GL_TRIANGLE_FAN,0,4);
+ DSTRECT(np->rect.pos.x + np->margin[MARGIN_LEFT], np->rect.pos.y, np->rect.size.width - np->margin[MARGIN_LEFT] - np->margin[MARGIN_RIGHT], np->margin[MARGIN_TOP]);
+ SRCRECT(np->margin[MARGIN_LEFT], 0, texture->width - np->margin[MARGIN_LEFT] - np->margin[MARGIN_RIGHT], np->margin[MARGIN_TOP]);
+ glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
//bottom
- DSTRECT(np->rect.pos.x+np->margin[MARGIN_LEFT],np->rect.pos.y+np->rect.size.y-np->margin[MARGIN_BOTTOM],np->rect.size.width-np->margin[MARGIN_LEFT]-np->margin[MARGIN_RIGHT],np->margin[MARGIN_TOP]);
- SRCRECT(np->margin[MARGIN_LEFT],texture->height-np->margin[MARGIN_BOTTOM],texture->width-np->margin[MARGIN_LEFT]-np->margin[MARGIN_LEFT],np->margin[MARGIN_TOP]);
- glDrawArrays(GL_TRIANGLE_FAN,0,4);
-
+ DSTRECT(np->rect.pos.x + np->margin[MARGIN_LEFT], np->rect.pos.y + np->rect.size.y - np->margin[MARGIN_BOTTOM], np->rect.size.width - np->margin[MARGIN_LEFT] - np->margin[MARGIN_RIGHT], np->margin[MARGIN_TOP]);
+ SRCRECT(np->margin[MARGIN_LEFT], texture->height - np->margin[MARGIN_BOTTOM], texture->width - np->margin[MARGIN_LEFT] - np->margin[MARGIN_LEFT], np->margin[MARGIN_TOP]);
+ glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
//left
- DSTRECT(np->rect.pos.x,np->rect.pos.y+np->margin[MARGIN_TOP],np->margin[MARGIN_LEFT],np->rect.size.height-np->margin[MARGIN_TOP]-np->margin[MARGIN_BOTTOM]);
- SRCRECT(0,np->margin[MARGIN_TOP],np->margin[MARGIN_LEFT],texture->height-np->margin[MARGIN_TOP]-np->margin[MARGIN_BOTTOM]);
- glDrawArrays(GL_TRIANGLE_FAN,0,4);
+ DSTRECT(np->rect.pos.x, np->rect.pos.y + np->margin[MARGIN_TOP], np->margin[MARGIN_LEFT], np->rect.size.height - np->margin[MARGIN_TOP] - np->margin[MARGIN_BOTTOM]);
+ SRCRECT(0, np->margin[MARGIN_TOP], np->margin[MARGIN_LEFT], texture->height - np->margin[MARGIN_TOP] - np->margin[MARGIN_BOTTOM]);
+ glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
//right
- DSTRECT(np->rect.pos.x+np->rect.size.width-np->margin[MARGIN_RIGHT],np->rect.pos.y+np->margin[MARGIN_TOP],np->margin[MARGIN_RIGHT],np->rect.size.height-np->margin[MARGIN_TOP]-np->margin[MARGIN_BOTTOM]);
- SRCRECT(texture->width-np->margin[MARGIN_RIGHT],np->margin[MARGIN_TOP],np->margin[MARGIN_RIGHT],texture->height-np->margin[MARGIN_TOP]-np->margin[MARGIN_BOTTOM]);
- glDrawArrays(GL_TRIANGLE_FAN,0,4);
+ DSTRECT(np->rect.pos.x + np->rect.size.width - np->margin[MARGIN_RIGHT], np->rect.pos.y + np->margin[MARGIN_TOP], np->margin[MARGIN_RIGHT], np->rect.size.height - np->margin[MARGIN_TOP] - np->margin[MARGIN_BOTTOM]);
+ SRCRECT(texture->width - np->margin[MARGIN_RIGHT], np->margin[MARGIN_TOP], np->margin[MARGIN_RIGHT], texture->height - np->margin[MARGIN_TOP] - np->margin[MARGIN_BOTTOM]);
+ glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
if (np->draw_center) {
//center
- DSTRECT(np->rect.pos.x+np->margin[MARGIN_LEFT],np->rect.pos.y+np->margin[MARGIN_TOP],np->rect.size.x-np->margin[MARGIN_LEFT]-np->margin[MARGIN_RIGHT],np->rect.size.height-np->margin[MARGIN_TOP]-np->margin[MARGIN_BOTTOM]);
- SRCRECT(np->margin[MARGIN_LEFT],np->margin[MARGIN_TOP],texture->width-np->margin[MARGIN_LEFT]-np->margin[MARGIN_RIGHT],texture->height-np->margin[MARGIN_TOP]-np->margin[MARGIN_BOTTOM]);
- glDrawArrays(GL_TRIANGLE_FAN,0,4);
-
+ DSTRECT(np->rect.pos.x + np->margin[MARGIN_LEFT], np->rect.pos.y + np->margin[MARGIN_TOP], np->rect.size.x - np->margin[MARGIN_LEFT] - np->margin[MARGIN_RIGHT], np->rect.size.height - np->margin[MARGIN_TOP] - np->margin[MARGIN_BOTTOM]);
+ SRCRECT(np->margin[MARGIN_LEFT], np->margin[MARGIN_TOP], texture->width - np->margin[MARGIN_LEFT] - np->margin[MARGIN_RIGHT], texture->height - np->margin[MARGIN_TOP] - np->margin[MARGIN_BOTTOM]);
+ glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
}
#undef SRCRECT
@@ -639,41 +589,39 @@ void RasterizerCanvasGLES3::_canvas_item_render_commands(Item *p_item,Item *curr
case Item::Command::TYPE_PRIMITIVE: {
- Item::CommandPrimitive* primitive = static_cast<Item::CommandPrimitive*>(c);
+ Item::CommandPrimitive *primitive = static_cast<Item::CommandPrimitive *>(c);
_set_texture_rect_mode(false);
- ERR_CONTINUE( primitive->points.size()<1);
+ ERR_CONTINUE(primitive->points.size() < 1);
- RasterizerStorageGLES3::Texture* texture = _bind_canvas_texture(primitive->texture);
-
- if (texture ) {
- Size2 texpixel_size( 1.0/texture->width, 1.0/texture->height );
- state.canvas_shader.set_uniform(CanvasShaderGLES3::COLOR_TEXPIXEL_SIZE,texpixel_size);
+ RasterizerStorageGLES3::Texture *texture = _bind_canvas_texture(primitive->texture);
+ if (texture) {
+ Size2 texpixel_size(1.0 / texture->width, 1.0 / texture->height);
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::COLOR_TEXPIXEL_SIZE, texpixel_size);
}
- if (primitive->colors.size()==1 && primitive->points.size()>1) {
+ 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(VS::ARRAY_COLOR, c.r, c.g, c.b, c.a);
} else if (primitive->colors.empty()) {
- glVertexAttrib4f(VS::ARRAY_COLOR,1,1,1,1);
+ glVertexAttrib4f(VS::ARRAY_COLOR, 1, 1, 1, 1);
}
- _draw_gui_primitive(primitive->points.size(),primitive->points.ptr(),primitive->colors.ptr(),primitive->uvs.ptr());
+ _draw_gui_primitive(primitive->points.size(), primitive->points.ptr(), primitive->colors.ptr(), primitive->uvs.ptr());
} break;
case Item::Command::TYPE_POLYGON: {
- Item::CommandPolygon* polygon = static_cast<Item::CommandPolygon*>(c);
+ Item::CommandPolygon *polygon = static_cast<Item::CommandPolygon *>(c);
_set_texture_rect_mode(false);
- RasterizerStorageGLES3::Texture* texture = _bind_canvas_texture(polygon->texture);
-
- if (texture ) {
- Size2 texpixel_size( 1.0/texture->width, 1.0/texture->height );
- state.canvas_shader.set_uniform(CanvasShaderGLES3::COLOR_TEXPIXEL_SIZE,texpixel_size);
+ RasterizerStorageGLES3::Texture *texture = _bind_canvas_texture(polygon->texture);
+ if (texture) {
+ Size2 texpixel_size(1.0 / texture->width, 1.0 / texture->height);
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::COLOR_TEXPIXEL_SIZE, texpixel_size);
}
//_draw_polygon(polygon->count,polygon->indices.ptr(),polygon->points.ptr(),polygon->uvs.ptr(),polygon->colors.ptr(),polygon->texture,polygon->colors.size()==1);
@@ -682,59 +630,57 @@ void RasterizerCanvasGLES3::_canvas_item_render_commands(Item *p_item,Item *curr
_set_texture_rect_mode(false);
- Item::CommandCircle* circle = static_cast<Item::CommandCircle*>(c);
- static const int numpoints=32;
- Vector2 points[numpoints+1];
- points[numpoints]=circle->pos;
- int indices[numpoints*3];
+ Item::CommandCircle *circle = static_cast<Item::CommandCircle *>(c);
+ static const int numpoints = 32;
+ Vector2 points[numpoints + 1];
+ points[numpoints] = circle->pos;
+ int indices[numpoints * 3];
- for(int i=0;i<numpoints;i++) {
+ for (int i = 0; i < numpoints; i++) {
- points[i]=circle->pos+Vector2( Math::sin(i*Math_PI*2.0/numpoints),Math::cos(i*Math_PI*2.0/numpoints) )*circle->radius;
- indices[i*3+0]=i;
- indices[i*3+1]=(i+1)%numpoints;
- indices[i*3+2]=numpoints;
+ points[i] = circle->pos + Vector2(Math::sin(i * Math_PI * 2.0 / numpoints), Math::cos(i * Math_PI * 2.0 / numpoints)) * circle->radius;
+ indices[i * 3 + 0] = i;
+ indices[i * 3 + 1] = (i + 1) % numpoints;
+ indices[i * 3 + 2] = numpoints;
}
//_draw_polygon(numpoints*3,indices,points,NULL,&circle->color,RID(),true);
//canvas_draw_circle(circle->indices.size(),circle->indices.ptr(),circle->points.ptr(),circle->uvs.ptr(),circle->colors.ptr(),circle->texture,circle->colors.size()==1);
} break;
case Item::Command::TYPE_TRANSFORM: {
- Item::CommandTransform* transform = static_cast<Item::CommandTransform*>(c);
- state.extra_matrix=transform->xform;
- state.canvas_shader.set_uniform(CanvasShaderGLES3::EXTRA_MATRIX,state.extra_matrix);
+ Item::CommandTransform *transform = static_cast<Item::CommandTransform *>(c);
+ state.extra_matrix = transform->xform;
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::EXTRA_MATRIX, state.extra_matrix);
} break;
case Item::Command::TYPE_CLIP_IGNORE: {
- Item::CommandClipIgnore* ci = static_cast<Item::CommandClipIgnore*>(c);
+ Item::CommandClipIgnore *ci = static_cast<Item::CommandClipIgnore *>(c);
if (current_clip) {
- if (ci->ignore!=reclip) {
+ if (ci->ignore != reclip) {
if (ci->ignore) {
glDisable(GL_SCISSOR_TEST);
- reclip=true;
- } else {
+ reclip = true;
+ } else {
glEnable(GL_SCISSOR_TEST);
//glScissor(viewport.x+current_clip->final_clip_rect.pos.x,viewport.y+ (viewport.height-(current_clip->final_clip_rect.pos.y+current_clip->final_clip_rect.size.height)),
//current_clip->final_clip_rect.size.width,current_clip->final_clip_rect.size.height);
int x = current_clip->final_clip_rect.pos.x;
- int y = storage->frame.current_rt->height - ( current_clip->final_clip_rect.pos.y + current_clip->final_clip_rect.size.y );
+ int y = storage->frame.current_rt->height - (current_clip->final_clip_rect.pos.y + current_clip->final_clip_rect.size.y);
int w = current_clip->final_clip_rect.size.x;
int h = current_clip->final_clip_rect.size.y;
- glScissor(x,y,w,h);
+ glScissor(x, y, w, h);
- reclip=false;
+ reclip = false;
}
}
}
-
-
} break;
}
}
@@ -795,60 +741,52 @@ void RasterizerGLES2::_canvas_item_setup_shader_params(CanvasItemMaterial *mater
#endif
-void RasterizerCanvasGLES3::canvas_render_items(Item *p_item_list,int p_z,const Color& p_modulate,Light *p_light) {
-
-
+void RasterizerCanvasGLES3::canvas_render_items(Item *p_item_list, int p_z, const Color &p_modulate, Light *p_light) {
+ Item *current_clip = NULL;
+ RasterizerStorageGLES3::Shader *shader_cache = NULL;
- Item *current_clip=NULL;
- RasterizerStorageGLES3::Shader *shader_cache=NULL;
+ bool rebind_shader = true;
- bool rebind_shader=true;
+ Size2 rt_size = Size2(storage->frame.current_rt->width, storage->frame.current_rt->height);
- Size2 rt_size = Size2(storage->frame.current_rt->width,storage->frame.current_rt->height);
-
-
- state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_DISTANCE_FIELD,false);
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_DISTANCE_FIELD, false);
glBindBuffer(GL_UNIFORM_BUFFER, state.canvas_item_ubo);
glBufferData(GL_UNIFORM_BUFFER, sizeof(CanvasItemUBO), &state.canvas_item_ubo_data, GL_DYNAMIC_DRAW);
glBindBuffer(GL_UNIFORM_BUFFER, 0);
- state.current_tex=RID();
- state.current_tex_ptr=NULL;
+ state.current_tex = RID();
+ state.current_tex_ptr = NULL;
glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D,storage->resources.white_tex);
+ glBindTexture(GL_TEXTURE_2D, storage->resources.white_tex);
-
- int last_blend_mode=-1;
+ int last_blend_mode = -1;
RID canvas_last_material;
- bool prev_distance_field=false;
-
- while(p_item_list) {
+ bool prev_distance_field = false;
- Item *ci=p_item_list;
+ while (p_item_list) {
+ Item *ci = p_item_list;
- if (prev_distance_field!=ci->distance_field) {
+ if (prev_distance_field != ci->distance_field) {
- state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_DISTANCE_FIELD,ci->distance_field);
- prev_distance_field=ci->distance_field;
- rebind_shader=true;
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_DISTANCE_FIELD, ci->distance_field);
+ prev_distance_field = ci->distance_field;
+ rebind_shader = true;
}
+ if (current_clip != ci->final_clip_owner) {
- if (current_clip!=ci->final_clip_owner) {
-
- current_clip=ci->final_clip_owner;
+ current_clip = ci->final_clip_owner;
//setup clip
if (current_clip) {
glEnable(GL_SCISSOR_TEST);
- glScissor(current_clip->final_clip_rect.pos.x,(rt_size.height-(current_clip->final_clip_rect.pos.y+current_clip->final_clip_rect.size.height)),current_clip->final_clip_rect.size.width,current_clip->final_clip_rect.size.height);
-
+ glScissor(current_clip->final_clip_rect.pos.x, (rt_size.height - (current_clip->final_clip_rect.pos.y + current_clip->final_clip_rect.size.height)), current_clip->final_clip_rect.size.width, current_clip->final_clip_rect.size.height);
} else {
@@ -893,13 +831,12 @@ void RasterizerCanvasGLES3::canvas_render_items(Item *p_item_list,int p_z,const
#endif
-
//begin rect
- Item *material_owner = ci->material_owner?ci->material_owner:ci;
+ Item *material_owner = ci->material_owner ? ci->material_owner : ci;
RID material = material_owner->material;
- if (material!=canvas_last_material || rebind_shader) {
+ if (material != canvas_last_material || rebind_shader) {
RasterizerStorageGLES3::Material *material_ptr = storage->material_owner.getornull(material);
RasterizerStorageGLES3::Shader *shader_ptr = NULL;
@@ -908,46 +845,44 @@ void RasterizerCanvasGLES3::canvas_render_items(Item *p_item_list,int p_z,const
shader_ptr = material_ptr->shader;
- if (shader_ptr && shader_ptr->mode!=VS::SHADER_CANVAS_ITEM) {
- shader_ptr=NULL; //do not use non canvasitem shader
+ if (shader_ptr && shader_ptr->mode != VS::SHADER_CANVAS_ITEM) {
+ shader_ptr = NULL; //do not use non canvasitem shader
}
}
-
-
- if (shader_ptr && shader_ptr!=shader_cache) {
+ if (shader_ptr && shader_ptr != shader_cache) {
state.canvas_shader.set_custom_shader(shader_ptr->custom_code_id);
state.canvas_shader.bind();
if (material_ptr->ubo_id) {
- glBindBufferBase(GL_UNIFORM_BUFFER,2,material_ptr->ubo_id);
+ glBindBufferBase(GL_UNIFORM_BUFFER, 2, material_ptr->ubo_id);
}
int tc = material_ptr->textures.size();
- RID* textures = material_ptr->textures.ptr();
- ShaderLanguage::ShaderNode::Uniform::Hint* texture_hints = shader_ptr->texture_hints.ptr();
+ RID *textures = material_ptr->textures.ptr();
+ ShaderLanguage::ShaderNode::Uniform::Hint *texture_hints = shader_ptr->texture_hints.ptr();
- for(int i=0;i<tc;i++) {
+ for (int i = 0; i < tc; i++) {
- glActiveTexture(GL_TEXTURE1+i);
+ glActiveTexture(GL_TEXTURE1 + i);
- RasterizerStorageGLES3::Texture *t = storage->texture_owner.getornull( textures[i] );
+ RasterizerStorageGLES3::Texture *t = storage->texture_owner.getornull(textures[i]);
if (!t) {
- switch(texture_hints[i]) {
+ switch (texture_hints[i]) {
case ShaderLanguage::ShaderNode::Uniform::HINT_BLACK_ALBEDO:
case ShaderLanguage::ShaderNode::Uniform::HINT_BLACK: {
- glBindTexture(GL_TEXTURE_2D,storage->resources.black_tex);
+ glBindTexture(GL_TEXTURE_2D, storage->resources.black_tex);
} break;
case ShaderLanguage::ShaderNode::Uniform::HINT_ANISO: {
- glBindTexture(GL_TEXTURE_2D,storage->resources.aniso_tex);
+ glBindTexture(GL_TEXTURE_2D, storage->resources.aniso_tex);
} break;
case ShaderLanguage::ShaderNode::Uniform::HINT_NORMAL: {
- glBindTexture(GL_TEXTURE_2D,storage->resources.normal_tex);
+ glBindTexture(GL_TEXTURE_2D, storage->resources.normal_tex);
} break;
default: {
- glBindTexture(GL_TEXTURE_2D,storage->resources.white_tex);
+ glBindTexture(GL_TEXTURE_2D, storage->resources.white_tex);
} break;
}
@@ -958,116 +893,108 @@ void RasterizerCanvasGLES3::canvas_render_items(Item *p_item_list,int p_z,const
if (storage->config.srgb_decode_supported && t->using_srgb) {
//no srgb in 2D
- glTexParameteri(t->target,_TEXTURE_SRGB_DECODE_EXT,_SKIP_DECODE_EXT);
- t->using_srgb=false;
+ glTexParameteri(t->target, _TEXTURE_SRGB_DECODE_EXT, _SKIP_DECODE_EXT);
+ t->using_srgb = false;
}
- glBindTexture(t->target,t->tex_id);
+ glBindTexture(t->target, t->tex_id);
}
-
} else if (!shader_ptr) {
state.canvas_shader.set_custom_shader(0);
state.canvas_shader.bind();
-
}
- shader_cache=shader_ptr;
-
- canvas_last_material=material;
- rebind_shader=false;
+ shader_cache = shader_ptr;
+ canvas_last_material = material;
+ rebind_shader = false;
}
int blend_mode = shader_cache ? shader_cache->canvas_item.blend_mode : RasterizerStorageGLES3::Shader::CanvasItem::BLEND_MODE_MIX;
- bool unshaded = shader_cache && (shader_cache->canvas_item.light_mode==RasterizerStorageGLES3::Shader::CanvasItem::LIGHT_MODE_UNSHADED || blend_mode!=RasterizerStorageGLES3::Shader::CanvasItem::BLEND_MODE_MIX);
- bool reclip=false;
+ bool unshaded = shader_cache && (shader_cache->canvas_item.light_mode == RasterizerStorageGLES3::Shader::CanvasItem::LIGHT_MODE_UNSHADED || blend_mode != RasterizerStorageGLES3::Shader::CanvasItem::BLEND_MODE_MIX);
+ bool reclip = false;
- if (last_blend_mode!=blend_mode) {
+ if (last_blend_mode != blend_mode) {
- switch(blend_mode) {
+ switch (blend_mode) {
- case RasterizerStorageGLES3::Shader::CanvasItem::BLEND_MODE_MIX: {
+ case RasterizerStorageGLES3::Shader::CanvasItem::BLEND_MODE_MIX: {
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);
- }
- else {
+ } else {
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
- } break;
- case RasterizerStorageGLES3::Shader::CanvasItem::BLEND_MODE_ADD: {
+ } break;
+ case RasterizerStorageGLES3::Shader::CanvasItem::BLEND_MODE_ADD: {
glBlendEquation(GL_FUNC_ADD);
- glBlendFunc(GL_SRC_ALPHA,GL_ONE);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE);
- } break;
- case RasterizerStorageGLES3::Shader::CanvasItem::BLEND_MODE_SUB: {
+ } break;
+ case RasterizerStorageGLES3::Shader::CanvasItem::BLEND_MODE_SUB: {
glBlendEquation(GL_FUNC_REVERSE_SUBTRACT);
- glBlendFunc(GL_SRC_ALPHA,GL_ONE);
- } break;
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE);
+ } break;
case RasterizerStorageGLES3::Shader::CanvasItem::BLEND_MODE_MUL: {
glBlendEquation(GL_FUNC_ADD);
- glBlendFunc(GL_DST_COLOR,GL_ZERO);
+ glBlendFunc(GL_DST_COLOR, GL_ZERO);
} break;
case RasterizerStorageGLES3::Shader::CanvasItem::BLEND_MODE_PMALPHA: {
glBlendEquation(GL_FUNC_ADD);
- glBlendFunc(GL_ONE,GL_ONE_MINUS_SRC_ALPHA);
+ glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
} break;
-
}
- last_blend_mode=blend_mode;
+ last_blend_mode = blend_mode;
}
state.canvas_item_modulate = unshaded ? ci->final_modulate : Color(
- ci->final_modulate.r * p_modulate.r,
- ci->final_modulate.g * p_modulate.g,
- ci->final_modulate.b * p_modulate.b,
- ci->final_modulate.a * p_modulate.a );
+ ci->final_modulate.r * p_modulate.r,
+ ci->final_modulate.g * p_modulate.g,
+ ci->final_modulate.b * p_modulate.b,
+ ci->final_modulate.a * p_modulate.a);
state.final_transform = ci->final_transform;
- state.extra_matrix=Transform2D();
+ state.extra_matrix = Transform2D();
- state.canvas_shader.set_uniform(CanvasShaderGLES3::FINAL_MODULATE,state.canvas_item_modulate);
- state.canvas_shader.set_uniform(CanvasShaderGLES3::MODELVIEW_MATRIX,state.final_transform);
- state.canvas_shader.set_uniform(CanvasShaderGLES3::EXTRA_MATRIX,state.extra_matrix);
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::FINAL_MODULATE, state.canvas_item_modulate);
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::MODELVIEW_MATRIX, state.final_transform);
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::EXTRA_MATRIX, state.extra_matrix);
+ if (unshaded || (state.canvas_item_modulate.a > 0.001 && (!shader_cache || shader_cache->canvas_item.light_mode != RasterizerStorageGLES3::Shader::CanvasItem::LIGHT_MODE_LIGHT_ONLY) && !ci->light_masked))
+ _canvas_item_render_commands(ci, current_clip, reclip);
- if (unshaded || (state.canvas_item_modulate.a>0.001 && (!shader_cache || shader_cache->canvas_item.light_mode!=RasterizerStorageGLES3::Shader::CanvasItem::LIGHT_MODE_LIGHT_ONLY) && !ci->light_masked ))
- _canvas_item_render_commands(ci,current_clip,reclip);
-
- if ((blend_mode==RasterizerStorageGLES3::Shader::CanvasItem::BLEND_MODE_MIX || blend_mode==RasterizerStorageGLES3::Shader::CanvasItem::BLEND_MODE_PMALPHA) && p_light && !unshaded) {
+ if ((blend_mode == RasterizerStorageGLES3::Shader::CanvasItem::BLEND_MODE_MIX || blend_mode == RasterizerStorageGLES3::Shader::CanvasItem::BLEND_MODE_PMALPHA) && p_light && !unshaded) {
Light *light = p_light;
- bool light_used=false;
- VS::CanvasLightMode mode=VS::CANVAS_LIGHT_MODE_ADD;
- state.canvas_item_modulate=ci->final_modulate; // remove the canvas modulate
-
+ bool light_used = false;
+ VS::CanvasLightMode mode = VS::CANVAS_LIGHT_MODE_ADD;
+ state.canvas_item_modulate = ci->final_modulate; // remove the canvas modulate
- while(light) {
+ while (light) {
-
- if (ci->light_mask&light->item_mask && p_z>=light->z_min && p_z<=light->z_max && ci->global_rect_cache.intersects_transformed(light->xform_cache,light->rect_cache)) {
+ if (ci->light_mask & light->item_mask && p_z >= light->z_min && p_z <= light->z_max && ci->global_rect_cache.intersects_transformed(light->xform_cache, light->rect_cache)) {
//intersects this light
- if (!light_used || mode!=light->mode) {
+ if (!light_used || mode != light->mode) {
- mode=light->mode;
+ mode = light->mode;
- switch(mode) {
+ switch (mode) {
case VS::CANVAS_LIGHT_MODE_ADD: {
glBlendEquation(GL_FUNC_ADD);
- glBlendFunc(GL_SRC_ALPHA,GL_ONE);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE);
} break;
case VS::CANVAS_LIGHT_MODE_SUB: {
glBlendEquation(GL_FUNC_REVERSE_SUBTRACT);
- glBlendFunc(GL_SRC_ALPHA,GL_ONE);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE);
} break;
case VS::CANVAS_LIGHT_MODE_MIX:
case VS::CANVAS_LIGHT_MODE_MASK: {
@@ -1076,90 +1003,80 @@ void RasterizerCanvasGLES3::canvas_render_items(Item *p_item_list,int p_z,const
} break;
}
-
}
if (!light_used) {
- state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_LIGHTING,true);
- light_used=true;
-
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_LIGHTING, true);
+ light_used = true;
}
+ bool has_shadow = light->shadow_buffer.is_valid() && ci->light_mask & light->item_shadow_mask;
- bool has_shadow = light->shadow_buffer.is_valid() && ci->light_mask&light->item_shadow_mask;
-
-
- state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_SHADOWS,has_shadow);
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_SHADOWS, has_shadow);
if (has_shadow) {
- state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_USE_GRADIENT,light->shadow_gradient_length>0);
- switch(light->shadow_filter) {
-
- case VS::CANVAS_LIGHT_FILTER_NONE: state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_NEAREST,true); break;
- case VS::CANVAS_LIGHT_FILTER_PCF3: state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_PCF3,true); break;
- case VS::CANVAS_LIGHT_FILTER_PCF5: state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_PCF5,true); break;
- case VS::CANVAS_LIGHT_FILTER_PCF9: state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_PCF9,true); break;
- case VS::CANVAS_LIGHT_FILTER_PCF13: state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_PCF13,true); break;
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_USE_GRADIENT, light->shadow_gradient_length > 0);
+ switch (light->shadow_filter) {
+
+ case VS::CANVAS_LIGHT_FILTER_NONE: state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_NEAREST, true); break;
+ case VS::CANVAS_LIGHT_FILTER_PCF3: state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_PCF3, true); break;
+ case VS::CANVAS_LIGHT_FILTER_PCF5: state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_PCF5, true); break;
+ case VS::CANVAS_LIGHT_FILTER_PCF9: state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_PCF9, true); break;
+ case VS::CANVAS_LIGHT_FILTER_PCF13: state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_PCF13, true); break;
}
-
-
}
bool light_rebind = state.canvas_shader.bind();
if (light_rebind) {
- state.canvas_shader.set_uniform(CanvasShaderGLES3::FINAL_MODULATE,state.canvas_item_modulate);
- state.canvas_shader.set_uniform(CanvasShaderGLES3::MODELVIEW_MATRIX,state.final_transform);
- state.canvas_shader.set_uniform(CanvasShaderGLES3::EXTRA_MATRIX,Transform2D());
-
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::FINAL_MODULATE, state.canvas_item_modulate);
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::MODELVIEW_MATRIX, state.final_transform);
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::EXTRA_MATRIX, Transform2D());
}
- glBindBufferBase(GL_UNIFORM_BUFFER,1,static_cast<LightInternal*>(light->light_internal.get_data())->ubo);
+ glBindBufferBase(GL_UNIFORM_BUFFER, 1, static_cast<LightInternal *>(light->light_internal.get_data())->ubo);
if (has_shadow) {
RasterizerStorageGLES3::CanvasLightShadow *cls = storage->canvas_light_shadow_owner.get(light->shadow_buffer);
- glActiveTexture(GL_TEXTURE0+storage->config.max_texture_image_units-2);
- glBindTexture(GL_TEXTURE_2D,cls->distance);
+ glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 2);
+ glBindTexture(GL_TEXTURE_2D, cls->distance);
/*canvas_shader.set_uniform(CanvasShaderGLES3::SHADOW_MATRIX,light->shadow_matrix_cache);
canvas_shader.set_uniform(CanvasShaderGLES3::SHADOW_ESM_MULTIPLIER,light->shadow_esm_mult);
canvas_shader.set_uniform(CanvasShaderGLES3::LIGHT_SHADOW_COLOR,light->shadow_color);*/
-
}
- glActiveTexture(GL_TEXTURE0+storage->config.max_texture_image_units-1);
+ glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 1);
RasterizerStorageGLES3::Texture *t = storage->texture_owner.getornull(light->texture);
if (!t) {
- glBindTexture(GL_TEXTURE_2D,storage->resources.white_tex);
+ glBindTexture(GL_TEXTURE_2D, storage->resources.white_tex);
} else {
- glBindTexture(t->target,t->tex_id);
+ glBindTexture(t->target, t->tex_id);
}
glActiveTexture(GL_TEXTURE0);
- _canvas_item_render_commands(ci,current_clip,reclip); //redraw using light
-
+ _canvas_item_render_commands(ci, current_clip, reclip); //redraw using light
}
- light=light->next_ptr;
+ light = light->next_ptr;
}
if (light_used) {
-
- state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_LIGHTING,false);
- state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_SHADOWS,false);
- state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_NEAREST,false);
- state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_PCF3,false);
- state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_PCF5,false);
- state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_PCF9,false);
- state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_PCF13,false);
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_LIGHTING, false);
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_SHADOWS, false);
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_NEAREST, false);
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_PCF3, false);
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_PCF5, false);
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_PCF9, false);
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_PCF13, false);
state.canvas_shader.bind();
- last_blend_mode=-1;
+ last_blend_mode = -1;
/*
//this is set again, so it should not be needed anyway?
@@ -1185,69 +1102,58 @@ void RasterizerCanvasGLES3::canvas_render_items(Item *p_item_list,int p_z,const
//@TODO RESET canvas_blend_mode
*/
}
-
-
}
if (reclip) {
glEnable(GL_SCISSOR_TEST);
- glScissor(current_clip->final_clip_rect.pos.x,(rt_size.height-(current_clip->final_clip_rect.pos.y+current_clip->final_clip_rect.size.height)),current_clip->final_clip_rect.size.width,current_clip->final_clip_rect.size.height);
-
-
+ glScissor(current_clip->final_clip_rect.pos.x, (rt_size.height - (current_clip->final_clip_rect.pos.y + current_clip->final_clip_rect.size.height)), current_clip->final_clip_rect.size.width, current_clip->final_clip_rect.size.height);
}
-
-
- p_item_list=p_item_list->next;
+ p_item_list = p_item_list->next;
}
if (current_clip) {
glDisable(GL_SCISSOR_TEST);
}
-
}
-void RasterizerCanvasGLES3::canvas_debug_viewport_shadows(Light* p_lights_with_shadow){
+void RasterizerCanvasGLES3::canvas_debug_viewport_shadows(Light *p_lights_with_shadow) {
- Light* light=p_lights_with_shadow;
+ Light *light = p_lights_with_shadow;
canvas_begin(); //reset
- glVertexAttrib4f(VS::ARRAY_COLOR,1,1,1,1);
+ glVertexAttrib4f(VS::ARRAY_COLOR, 1, 1, 1, 1);
int h = 10;
int w = storage->frame.current_rt->width;
int ofs = h;
glDisable(GL_BLEND);
//print_line(" debug lights ");
- while(light) {
-
+ while (light) {
//print_line("debug light");
if (light->shadow_buffer.is_valid()) {
//print_line("sb is valid");
- RasterizerStorageGLES3::CanvasLightShadow * sb = storage->canvas_light_shadow_owner.get(light->shadow_buffer);
+ RasterizerStorageGLES3::CanvasLightShadow *sb = storage->canvas_light_shadow_owner.get(light->shadow_buffer);
if (sb) {
- glBindTexture(GL_TEXTURE_2D,sb->distance);
+ glBindTexture(GL_TEXTURE_2D, sb->distance);
//glBindTexture(GL_TEXTURE_2D,storage->resources.white_tex);
- draw_generic_textured_rect(Rect2(h,ofs,w-h*2,h),Rect2(0,0,1,1));
- ofs+=h*2;
-
+ draw_generic_textured_rect(Rect2(h, ofs, w - h * 2, h), Rect2(0, 0, 1, 1));
+ ofs += h * 2;
}
}
- light=light->shadows_next_ptr;
+ light = light->shadows_next_ptr;
}
}
-
-void RasterizerCanvasGLES3::canvas_light_shadow_buffer_update(RID p_buffer, const Transform2D& p_light_xform, int p_light_mask,float p_near, float p_far, LightOccluderInstance* p_occluders, CameraMatrix *p_xform_cache) {
+void RasterizerCanvasGLES3::canvas_light_shadow_buffer_update(RID p_buffer, const Transform2D &p_light_xform, int p_light_mask, float p_near, float p_far, LightOccluderInstance *p_occluders, CameraMatrix *p_xform_cache) {
RasterizerStorageGLES3::CanvasLightShadow *cls = storage->canvas_light_shadow_owner.get(p_buffer);
ERR_FAIL_COND(!cls);
-
glDisable(GL_BLEND);
glDisable(GL_SCISSOR_TEST);
glDisable(GL_DITHER);
@@ -1261,73 +1167,71 @@ void RasterizerCanvasGLES3::canvas_light_shadow_buffer_update(RID p_buffer, cons
glEnableVertexAttribArray(VS::ARRAY_VERTEX);
state.canvas_shadow_shader.bind();
- glViewport(0, 0, cls->size,cls->height);
+ glViewport(0, 0, cls->size, cls->height);
glClearDepth(1.0f);
- glClearColor(1,1,1,1);
- glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
+ glClearColor(1, 1, 1, 1);
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- VS::CanvasOccluderPolygonCullMode cull=VS::CANVAS_OCCLUDER_POLYGON_CULL_DISABLED;
+ VS::CanvasOccluderPolygonCullMode cull = VS::CANVAS_OCCLUDER_POLYGON_CULL_DISABLED;
-
- for(int i=0;i<4;i++) {
+ for (int i = 0; i < 4; i++) {
//make sure it remains orthogonal, makes easy to read angle later
Transform light;
- light.origin[0]=p_light_xform[2][0];
- light.origin[1]=p_light_xform[2][1];
- light.basis[0][0]=p_light_xform[0][0];
- light.basis[0][1]=p_light_xform[1][0];
- light.basis[1][0]=p_light_xform[0][1];
- light.basis[1][1]=p_light_xform[1][1];
+ light.origin[0] = p_light_xform[2][0];
+ light.origin[1] = p_light_xform[2][1];
+ light.basis[0][0] = p_light_xform[0][0];
+ light.basis[0][1] = p_light_xform[1][0];
+ light.basis[1][0] = p_light_xform[0][1];
+ light.basis[1][1] = p_light_xform[1][1];
//light.basis.scale(Vector3(to_light.elements[0].length(),to_light.elements[1].length(),1));
//p_near=1;
CameraMatrix projection;
{
- real_t fov = 90;
+ real_t fov = 90;
real_t nearp = p_near;
real_t farp = p_far;
real_t aspect = 1.0;
- real_t ymax = nearp * Math::tan( Math::deg2rad( fov * 0.5 ) );
- real_t ymin = - ymax;
+ real_t ymax = nearp * Math::tan(Math::deg2rad(fov * 0.5));
+ real_t ymin = -ymax;
real_t xmin = ymin * aspect;
real_t xmax = ymax * aspect;
- projection.set_frustum( xmin, xmax, ymin, ymax, nearp, farp );
+ projection.set_frustum(xmin, xmax, ymin, ymax, nearp, farp);
}
- Vector3 cam_target=Basis(Vector3(0,0,Math_PI*2*(i/4.0))).xform(Vector3(0,1,0));
- projection = projection * CameraMatrix(Transform().looking_at(cam_target,Vector3(0,0,-1)).affine_inverse());
-
- state.canvas_shadow_shader.set_uniform(CanvasShadowShaderGLES3::PROJECTION_MATRIX,projection);
- state.canvas_shadow_shader.set_uniform(CanvasShadowShaderGLES3::LIGHT_MATRIX,light);
- state.canvas_shadow_shader.set_uniform(CanvasShadowShaderGLES3::DISTANCE_NORM,1.0/p_far);
+ Vector3 cam_target = Basis(Vector3(0, 0, Math_PI * 2 * (i / 4.0))).xform(Vector3(0, 1, 0));
+ projection = projection * CameraMatrix(Transform().looking_at(cam_target, Vector3(0, 0, -1)).affine_inverse());
+ state.canvas_shadow_shader.set_uniform(CanvasShadowShaderGLES3::PROJECTION_MATRIX, projection);
+ state.canvas_shadow_shader.set_uniform(CanvasShadowShaderGLES3::LIGHT_MATRIX, light);
+ state.canvas_shadow_shader.set_uniform(CanvasShadowShaderGLES3::DISTANCE_NORM, 1.0 / p_far);
- if (i==0)
- *p_xform_cache=projection;
+ if (i == 0)
+ *p_xform_cache = projection;
- glViewport(0, (cls->height/4)*i, cls->size,cls->height/4);
+ glViewport(0, (cls->height / 4) * i, cls->size, cls->height / 4);
- LightOccluderInstance *instance=p_occluders;
+ LightOccluderInstance *instance = p_occluders;
- while(instance) {
+ while (instance) {
RasterizerStorageGLES3::CanvasOccluder *cc = storage->canvas_occluder_owner.get(instance->polygon_buffer);
- if (!cc || cc->len==0 || !(p_light_mask&instance->light_mask)) {
+ if (!cc || cc->len == 0 || !(p_light_mask & instance->light_mask)) {
- instance=instance->next;
+ instance = instance->next;
continue;
}
- state.canvas_shadow_shader.set_uniform(CanvasShadowShaderGLES3::WORLD_MATRIX,instance->xform_cache);
- if (cull!=instance->cull_cache) {
+ state.canvas_shadow_shader.set_uniform(CanvasShadowShaderGLES3::WORLD_MATRIX, instance->xform_cache);
+ if (cull != instance->cull_cache) {
- cull=instance->cull_cache;
- switch(cull) {
+ cull = instance->cull_cache;
+ switch (cull) {
case VS::CANVAS_OCCLUDER_POLYGON_CULL_DISABLED: {
glDisable(GL_CULL_FACE);
@@ -1346,7 +1250,7 @@ void RasterizerCanvasGLES3::canvas_light_shadow_buffer_update(RID p_buffer, cons
} break;
}
}
-/*
+ /*
if (i==0) {
for(int i=0;i<cc->lines.size();i++) {
Vector2 p = instance->xform_cache.xform(cc->lines.get(i));
@@ -1359,31 +1263,26 @@ void RasterizerCanvasGLES3::canvas_light_shadow_buffer_update(RID p_buffer, cons
}
}
*/
- glBindBuffer(GL_ARRAY_BUFFER,cc->vertex_id);
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,cc->index_id);
+ glBindBuffer(GL_ARRAY_BUFFER, cc->vertex_id);
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, cc->index_id);
glVertexAttribPointer(VS::ARRAY_VERTEX, 3, GL_FLOAT, false, 0, 0);
- glDrawElements(GL_TRIANGLES,cc->len*3,GL_UNSIGNED_SHORT,0);
+ glDrawElements(GL_TRIANGLES, cc->len * 3, GL_UNSIGNED_SHORT, 0);
-
- instance=instance->next;
+ instance = instance->next;
}
-
-
}
glDisableVertexAttribArray(VS::ARRAY_VERTEX);
- glBindBuffer(GL_ARRAY_BUFFER,0);
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0);
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}
void RasterizerCanvasGLES3::reset_canvas() {
-
if (storage->frame.current_rt) {
glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->fbo);
- glColorMask(1,1,1,1); //don't touch alpha
+ glColorMask(1, 1, 1, 1); //don't touch alpha
}
-
glBindVertexArray(0);
glDisable(GL_CULL_FACE);
glDisable(GL_DEPTH_TEST);
@@ -1392,23 +1291,21 @@ void RasterizerCanvasGLES3::reset_canvas() {
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);
- }
- else {
+ } else {
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
//glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
//glLineWidth(1.0);
- glBindBuffer(GL_ARRAY_BUFFER,0);
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0);
- for(int i=0;i<VS::ARRAY_MAX;i++) {
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
+ for (int i = 0; i < VS::ARRAY_MAX; i++) {
glDisableVertexAttribArray(i);
}
glActiveTexture(GL_TEXTURE0);
- glBindTexture( GL_TEXTURE_2D, storage->resources.white_tex );
-
+ glBindTexture(GL_TEXTURE_2D, storage->resources.white_tex);
- glVertexAttrib4f(VS::ARRAY_COLOR,1,1,1,1);
+ glVertexAttrib4f(VS::ARRAY_COLOR, 1, 1, 1, 1);
Transform canvas_transform;
@@ -1419,119 +1316,107 @@ void RasterizerCanvasGLES3::reset_canvas() {
csy = -1.0;
}
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 ) );
+ 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();
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 ) );
-
+ canvas_transform.scale(Vector3(2.0f / ssize.width, -2.0f / ssize.height, 1.0f));
}
- state.vp=canvas_transform;
+ state.vp = canvas_transform;
- store_transform(canvas_transform,state.canvas_item_ubo_data.projection_matrix);
- for(int i=0;i<4;i++) {
- state.canvas_item_ubo_data.time[i]=storage->frame.time[i];
+ store_transform(canvas_transform, state.canvas_item_ubo_data.projection_matrix);
+ for (int i = 0; i < 4; i++) {
+ state.canvas_item_ubo_data.time[i] = storage->frame.time[i];
}
glBindBuffer(GL_UNIFORM_BUFFER, state.canvas_item_ubo);
glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(CanvasItemUBO), &state.canvas_item_ubo_data);
glBindBuffer(GL_UNIFORM_BUFFER, 0);
-
- state.canvas_texscreen_used=false;
-
-
+ state.canvas_texscreen_used = false;
}
+void RasterizerCanvasGLES3::draw_generic_textured_rect(const Rect2 &p_rect, const Rect2 &p_src) {
-void RasterizerCanvasGLES3::draw_generic_textured_rect(const Rect2& p_rect, const Rect2& p_src) {
-
-
- glVertexAttrib4f(1,p_rect.pos.x,p_rect.pos.y,p_rect.size.x,p_rect.size.y);
- glVertexAttrib4f(2,p_src.pos.x,p_src.pos.y,p_src.size.x,p_src.size.y);
- glDrawArrays(GL_TRIANGLE_FAN,0,4);
+ glVertexAttrib4f(1, p_rect.pos.x, p_rect.pos.y, p_rect.size.x, p_rect.size.y);
+ glVertexAttrib4f(2, p_src.pos.x, p_src.pos.y, p_src.size.x, p_src.size.y);
+ glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
}
void RasterizerCanvasGLES3::initialize() {
-
{
//quad buffers
- glGenBuffers(1,&data.canvas_quad_vertices);
- glBindBuffer(GL_ARRAY_BUFFER,data.canvas_quad_vertices);
+ glGenBuffers(1, &data.canvas_quad_vertices);
+ glBindBuffer(GL_ARRAY_BUFFER, data.canvas_quad_vertices);
{
- const float qv[8]={
- 0,0,
- 0,1,
- 1,1,
- 1,0
+ const float qv[8] = {
+ 0, 0,
+ 0, 1,
+ 1, 1,
+ 1, 0
};
- glBufferData(GL_ARRAY_BUFFER,sizeof(float)*8,qv,GL_STATIC_DRAW);
+ glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 8, qv, GL_STATIC_DRAW);
}
- glBindBuffer(GL_ARRAY_BUFFER,0); //unbind
-
+ glBindBuffer(GL_ARRAY_BUFFER, 0); //unbind
- glGenVertexArrays(1,&data.canvas_quad_array);
+ glGenVertexArrays(1, &data.canvas_quad_array);
glBindVertexArray(data.canvas_quad_array);
- glBindBuffer(GL_ARRAY_BUFFER,data.canvas_quad_vertices);
- glVertexAttribPointer(0,2,GL_FLOAT,GL_FALSE,sizeof(float)*2,0);
+ glBindBuffer(GL_ARRAY_BUFFER, data.canvas_quad_vertices);
+ glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 2, 0);
glEnableVertexAttribArray(0);
glBindVertexArray(0);
- glBindBuffer(GL_ARRAY_BUFFER,0); //unbind
+ glBindBuffer(GL_ARRAY_BUFFER, 0); //unbind
}
{
- glGenBuffers(1,&data.primitive_quad_buffer);
- glBindBuffer(GL_ARRAY_BUFFER,data.primitive_quad_buffer);
- glBufferData(GL_ARRAY_BUFFER,(2+2+4)*4*sizeof(float),NULL,GL_DYNAMIC_DRAW); //allocate max size
- glBindBuffer(GL_ARRAY_BUFFER,0);
+ glGenBuffers(1, &data.primitive_quad_buffer);
+ glBindBuffer(GL_ARRAY_BUFFER, data.primitive_quad_buffer);
+ glBufferData(GL_ARRAY_BUFFER, (2 + 2 + 4) * 4 * sizeof(float), NULL, GL_DYNAMIC_DRAW); //allocate max size
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
-
- for(int i=0;i<4;i++) {
- glGenVertexArrays(1,&data.primitive_quad_buffer_arrays[i]);
+ for (int i = 0; i < 4; i++) {
+ glGenVertexArrays(1, &data.primitive_quad_buffer_arrays[i]);
glBindVertexArray(data.primitive_quad_buffer_arrays[i]);
- glBindBuffer(GL_ARRAY_BUFFER,data.primitive_quad_buffer);
+ glBindBuffer(GL_ARRAY_BUFFER, data.primitive_quad_buffer);
- int uv_ofs=0;
- int color_ofs=0;
- int stride=2*4;
+ int uv_ofs = 0;
+ int color_ofs = 0;
+ int stride = 2 * 4;
- if (i&1) { //color
- color_ofs=stride;
- stride+=4*4;
+ if (i & 1) { //color
+ color_ofs = stride;
+ stride += 4 * 4;
}
- if (i&2) { //uv
- uv_ofs=stride;
- stride+=2*4;
+ if (i & 2) { //uv
+ uv_ofs = stride;
+ stride += 2 * 4;
}
-
glEnableVertexAttribArray(VS::ARRAY_VERTEX);
- glVertexAttribPointer(VS::ARRAY_VERTEX,2,GL_FLOAT,GL_FALSE,stride,((uint8_t*)NULL)+0);
+ glVertexAttribPointer(VS::ARRAY_VERTEX, 2, GL_FLOAT, GL_FALSE, stride, ((uint8_t *)NULL) + 0);
- if (i&1) {
+ if (i & 1) {
glEnableVertexAttribArray(VS::ARRAY_COLOR);
- glVertexAttribPointer(VS::ARRAY_COLOR,4,GL_FLOAT,GL_FALSE,stride,((uint8_t*)NULL)+color_ofs);
+ glVertexAttribPointer(VS::ARRAY_COLOR, 4, GL_FLOAT, GL_FALSE, stride, ((uint8_t *)NULL) + color_ofs);
}
- if (i&2) {
+ if (i & 2) {
glEnableVertexAttribArray(VS::ARRAY_TEX_UV);
- glVertexAttribPointer(VS::ARRAY_TEX_UV,2,GL_FLOAT,GL_FALSE,stride,((uint8_t*)NULL)+uv_ofs);
+ glVertexAttribPointer(VS::ARRAY_TEX_UV, 2, GL_FLOAT, GL_FALSE, stride, ((uint8_t *)NULL) + uv_ofs);
}
glBindVertexArray(0);
}
}
-
- store_transform(Transform(),state.canvas_item_ubo_data.projection_matrix);
-
+ store_transform(Transform(), state.canvas_item_ubo_data.projection_matrix);
glGenBuffers(1, &state.canvas_item_ubo);
glBindBuffer(GL_UNIFORM_BUFFER, state.canvas_item_ubo);
@@ -1542,20 +1427,15 @@ void RasterizerCanvasGLES3::initialize() {
state.canvas_shader.set_base_material_tex_index(1);
state.canvas_shadow_shader.init();
- state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_RGBA_SHADOWS,storage->config.use_rgba_2d_shadows);
- state.canvas_shadow_shader.set_conditional(CanvasShadowShaderGLES3::USE_RGBA_SHADOWS,storage->config.use_rgba_2d_shadows);
-
-
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_RGBA_SHADOWS, storage->config.use_rgba_2d_shadows);
+ state.canvas_shadow_shader.set_conditional(CanvasShadowShaderGLES3::USE_RGBA_SHADOWS, storage->config.use_rgba_2d_shadows);
}
-
void RasterizerCanvasGLES3::finalize() {
- glDeleteBuffers(1,&data.canvas_quad_vertices);
- glDeleteVertexArrays(1,&data.canvas_quad_array);
+ glDeleteBuffers(1, &data.canvas_quad_vertices);
+ glDeleteVertexArrays(1, &data.canvas_quad_array);
}
-RasterizerCanvasGLES3::RasterizerCanvasGLES3()
-{
-
+RasterizerCanvasGLES3::RasterizerCanvasGLES3() {
}
diff --git a/drivers/gles3/rasterizer_canvas_gles3.h b/drivers/gles3/rasterizer_canvas_gles3.h
index 1273e5f35d..c90dcc7d65 100644
--- a/drivers/gles3/rasterizer_canvas_gles3.h
+++ b/drivers/gles3/rasterizer_canvas_gles3.h
@@ -29,19 +29,16 @@
#ifndef RASTERIZERCANVASGLES3_H
#define RASTERIZERCANVASGLES3_H
-#include "servers/visual/rasterizer.h"
#include "rasterizer_storage_gles3.h"
+#include "servers/visual/rasterizer.h"
#include "shaders/canvas_shadow.glsl.h"
-
class RasterizerCanvasGLES3 : public RasterizerCanvas {
public:
-
struct CanvasItemUBO {
float projection_matrix[16];
float time[4];
-
};
struct Data {
@@ -63,7 +60,6 @@ public:
bool using_texture_rect;
-
RID current_tex;
RasterizerStorageGLES3::Texture *current_tex_ptr;
@@ -100,31 +96,27 @@ public:
RID_Owner<LightInternal> light_internal_owner;
virtual RID light_internal_create();
- virtual void light_internal_update(RID p_rid, Light* p_light);
+ virtual void light_internal_update(RID p_rid, Light *p_light);
virtual void light_internal_free(RID p_rid);
-
virtual void canvas_begin();
virtual void canvas_end();
_FORCE_INLINE_ void _set_texture_rect_mode(bool p_enable);
- _FORCE_INLINE_ RasterizerStorageGLES3::Texture* _bind_canvas_texture(const RID& p_texture);
-
- _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(int p_vertex_count, const int* p_indices, const Vector2* p_vertices, const Vector2* p_uvs, const Color* p_colors,const RID& p_texture,bool p_singlecolor);
- _FORCE_INLINE_ void _canvas_item_render_commands(Item *p_item,Item *current_clip,bool &reclip);
+ _FORCE_INLINE_ RasterizerStorageGLES3::Texture *_bind_canvas_texture(const RID &p_texture);
+ _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(int p_vertex_count, const int *p_indices, const Vector2 *p_vertices, const Vector2 *p_uvs, const Color *p_colors, const RID &p_texture, bool p_singlecolor);
+ _FORCE_INLINE_ void _canvas_item_render_commands(Item *p_item, Item *current_clip, bool &reclip);
- virtual void canvas_render_items(Item *p_item_list,int p_z,const Color& p_modulate,Light *p_light);
- virtual void canvas_debug_viewport_shadows(Light* p_lights_with_shadow);
-
- virtual void canvas_light_shadow_buffer_update(RID p_buffer, const Transform2D& p_light_xform, int p_light_mask,float p_near, float p_far, LightOccluderInstance* p_occluders, CameraMatrix *p_xform_cache);
+ virtual void canvas_render_items(Item *p_item_list, int p_z, const Color &p_modulate, Light *p_light);
+ virtual void canvas_debug_viewport_shadows(Light *p_lights_with_shadow);
+ virtual void canvas_light_shadow_buffer_update(RID p_buffer, const Transform2D &p_light_xform, int p_light_mask, float p_near, float p_far, LightOccluderInstance *p_occluders, CameraMatrix *p_xform_cache);
virtual void reset_canvas();
- void draw_generic_textured_rect(const Rect2& p_rect, const Rect2& p_src);
-
+ void draw_generic_textured_rect(const Rect2 &p_rect, const Rect2 &p_src);
void initialize();
void finalize();
diff --git a/drivers/gles3/rasterizer_gles3.cpp b/drivers/gles3/rasterizer_gles3.cpp
index 05558a39ba..b6cb57d68a 100644
--- a/drivers/gles3/rasterizer_gles3.cpp
+++ b/drivers/gles3/rasterizer_gles3.cpp
@@ -28,9 +28,9 @@
/*************************************************************************/
#include "rasterizer_gles3.h"
-#include "os/os.h"
-#include "global_config.h"
#include "gl_context/context_gl.h"
+#include "global_config.h"
+#include "os/os.h"
#include <string.h>
RasterizerStorage *RasterizerGLES3::get_storage() {
@@ -77,63 +77,60 @@ RasterizerScene *RasterizerGLES3::get_scene() {
#define GLAPIENTRY
#endif
-static void GLAPIENTRY _gl_debug_print(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,const GLvoid *userParam)
-{
+static void GLAPIENTRY _gl_debug_print(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, const GLvoid *userParam) {
- if (type==_EXT_DEBUG_TYPE_OTHER_ARB)
+ if (type == _EXT_DEBUG_TYPE_OTHER_ARB)
return;
print_line("mesege");
char debSource[256], debType[256], debSev[256];
- if(source == _EXT_DEBUG_SOURCE_API_ARB)
- strcpy(debSource, "OpenGL");
- else if(source == _EXT_DEBUG_SOURCE_WINDOW_SYSTEM_ARB)
- strcpy(debSource, "Windows");
- else if(source == _EXT_DEBUG_SOURCE_SHADER_COMPILER_ARB)
- strcpy(debSource, "Shader Compiler");
- else if(source == _EXT_DEBUG_SOURCE_THIRD_PARTY_ARB)
- strcpy(debSource, "Third Party");
- else if(source == _EXT_DEBUG_SOURCE_APPLICATION_ARB)
- strcpy(debSource, "Application");
- else if(source == _EXT_DEBUG_SOURCE_OTHER_ARB)
- strcpy(debSource, "Other");
-
- if(type == _EXT_DEBUG_TYPE_ERROR_ARB)
- strcpy(debType, "Error");
- else if(type == _EXT_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB)
- strcpy(debType, "Deprecated behavior");
- else if(type == _EXT_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB)
- strcpy(debType, "Undefined behavior");
- else if(type == _EXT_DEBUG_TYPE_PORTABILITY_ARB)
- strcpy(debType, "Portability");
- else if(type == _EXT_DEBUG_TYPE_PERFORMANCE_ARB)
- strcpy(debType, "Performance");
- else if(type == _EXT_DEBUG_TYPE_OTHER_ARB)
- strcpy(debType, "Other");
-
- if(severity == _EXT_DEBUG_SEVERITY_HIGH_ARB)
- strcpy(debSev, "High");
- else if(severity == _EXT_DEBUG_SEVERITY_MEDIUM_ARB)
- strcpy(debSev, "Medium");
- else if(severity == _EXT_DEBUG_SEVERITY_LOW_ARB)
- strcpy(debSev, "Low");
-
- String output = String()+ "GL ERROR: Source: " + debSource + "\tType: " + debType + "\tID: " + itos(id) + "\tSeverity: " + debSev + "\tMessage: " + message;
+ if (source == _EXT_DEBUG_SOURCE_API_ARB)
+ strcpy(debSource, "OpenGL");
+ else if (source == _EXT_DEBUG_SOURCE_WINDOW_SYSTEM_ARB)
+ strcpy(debSource, "Windows");
+ else if (source == _EXT_DEBUG_SOURCE_SHADER_COMPILER_ARB)
+ strcpy(debSource, "Shader Compiler");
+ else if (source == _EXT_DEBUG_SOURCE_THIRD_PARTY_ARB)
+ strcpy(debSource, "Third Party");
+ else if (source == _EXT_DEBUG_SOURCE_APPLICATION_ARB)
+ strcpy(debSource, "Application");
+ else if (source == _EXT_DEBUG_SOURCE_OTHER_ARB)
+ strcpy(debSource, "Other");
+
+ if (type == _EXT_DEBUG_TYPE_ERROR_ARB)
+ strcpy(debType, "Error");
+ else if (type == _EXT_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB)
+ strcpy(debType, "Deprecated behavior");
+ else if (type == _EXT_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB)
+ strcpy(debType, "Undefined behavior");
+ else if (type == _EXT_DEBUG_TYPE_PORTABILITY_ARB)
+ strcpy(debType, "Portability");
+ else if (type == _EXT_DEBUG_TYPE_PERFORMANCE_ARB)
+ strcpy(debType, "Performance");
+ else if (type == _EXT_DEBUG_TYPE_OTHER_ARB)
+ strcpy(debType, "Other");
+
+ if (severity == _EXT_DEBUG_SEVERITY_HIGH_ARB)
+ strcpy(debSev, "High");
+ else if (severity == _EXT_DEBUG_SEVERITY_MEDIUM_ARB)
+ strcpy(debSev, "Medium");
+ else if (severity == _EXT_DEBUG_SEVERITY_LOW_ARB)
+ strcpy(debSev, "Low");
+
+ String output = String() + "GL ERROR: Source: " + debSource + "\tType: " + debType + "\tID: " + itos(id) + "\tSeverity: " + debSev + "\tMessage: " + message;
ERR_PRINTS(output);
-
}
-
typedef void (*DEBUGPROCARB)(GLenum source,
- GLenum type,
- GLuint id,
- GLenum severity,
- GLsizei length,
- const char* message,
- const void* userParam);
+ GLenum type,
+ GLuint id,
+ GLenum severity,
+ GLsizei length,
+ const char *message,
+ const void *userParam);
-typedef void (* DebugMessageCallbackARB) (DEBUGPROCARB callback, const void *userParam);
+typedef void (*DebugMessageCallbackARB)(DEBUGPROCARB callback, const void *userParam);
void RasterizerGLES3::initialize() {
@@ -143,30 +140,30 @@ void RasterizerGLES3::initialize() {
#ifdef GLEW_ENABLED
GLuint res = glewInit();
- ERR_FAIL_COND(res!=GLEW_OK);
+ ERR_FAIL_COND(res != GLEW_OK);
if (OS::get_singleton()->is_stdout_verbose()) {
- print_line(String("GLES2: Using GLEW ") + (const char*) glewGetString(GLEW_VERSION));
+ print_line(String("GLES2: Using GLEW ") + (const char *)glewGetString(GLEW_VERSION));
}
// Check for GL 2.1 compatibility, if not bail out
if (!glewIsSupported("GL_VERSION_3_0")) {
ERR_PRINT("Your system's graphic drivers seem not to support OpenGL 3.0+ / GLES 3.0, sorry :(\n"
- "Try a drivers update, buy a new GPU or try software rendering on Linux; Godot will now crash with a segmentation fault.");
+ "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 OpenGL 3.0+ / GLES 3.0, sorry :(\n"
- "Godot Engine will self-destruct as soon as you acknowledge this error message.",
- "Fatal error: Insufficient OpenGL / GLES drivers");
+ "Godot Engine will self-destruct as soon as you acknowledge this error message.",
+ "Fatal error: Insufficient OpenGL / GLES drivers");
// TODO: If it's even possible, we should stop the execution without segfault and memory leaks :)
}
#endif
#ifdef GLAD_ENABLED
- if(!gladLoadGL()) {
+ if (!gladLoadGL()) {
ERR_PRINT("Error initializing GLAD");
}
#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..
+// FIXME glDebugMessageCallbackARB does not seem to work on Mac OS X and opengl 3, this may be an issue with our opengl canvas..
#else
glEnable(_EXT_DEBUG_OUTPUT_SYNCHRONOUS_ARB);
glDebugMessageCallbackARB(_gl_debug_print, NULL);
@@ -175,8 +172,7 @@ void RasterizerGLES3::initialize() {
#endif
-
-/* 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_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);
@@ -194,114 +190,104 @@ void RasterizerGLES3::initialize() {
scene->initialize();
}
-void RasterizerGLES3::begin_frame(){
+void RasterizerGLES3::begin_frame() {
uint64_t tick = OS::get_singleton()->get_ticks_usec();
- double time_total = double(tick)/1000000.0;
+ double time_total = double(tick) / 1000000.0;
- storage->frame.time[0]=time_total;
- storage->frame.time[1]=Math::fmod(time_total,3600);
- storage->frame.time[2]=Math::fmod(time_total,900);
- storage->frame.time[3]=Math::fmod(time_total,60);
+ storage->frame.time[0] = time_total;
+ storage->frame.time[1] = Math::fmod(time_total, 3600);
+ storage->frame.time[2] = Math::fmod(time_total, 900);
+ storage->frame.time[3] = Math::fmod(time_total, 60);
storage->frame.count++;
- storage->frame.delta = double(tick-storage->frame.prev_tick)/1000000.0;
- if (storage->frame.prev_tick==0) {
+ storage->frame.delta = double(tick - storage->frame.prev_tick) / 1000000.0;
+ if (storage->frame.prev_tick == 0) {
//to avoid hiccups
- storage->frame.delta=0.001;
+ storage->frame.delta = 0.001;
}
- storage->frame.prev_tick=tick;
-
+ storage->frame.prev_tick = tick;
storage->update_dirty_resources();
-
- storage->info.render_object_count=0;
- storage->info.render_material_switch_count=0;
- storage->info.render_surface_switch_count=0;
- storage->info.render_shader_rebind_count=0;
- storage->info.render_vertices_count=0;
-
+ storage->info.render_object_count = 0;
+ storage->info.render_material_switch_count = 0;
+ storage->info.render_surface_switch_count = 0;
+ storage->info.render_shader_rebind_count = 0;
+ storage->info.render_vertices_count = 0;
scene->iteration();
-
-
-
-
}
-void RasterizerGLES3::set_current_render_target(RID p_render_target){
+void RasterizerGLES3::set_current_render_target(RID p_render_target) {
if (!p_render_target.is_valid() && storage->frame.current_rt && storage->frame.clear_request) {
//handle pending clear request, if the framebuffer was not cleared
- glBindFramebuffer(GL_FRAMEBUFFER,storage->frame.current_rt->fbo);
- print_line("unbind clear of: "+storage->frame.clear_request_color);
+ glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->fbo);
+ print_line("unbind clear of: " + storage->frame.clear_request_color);
glClearColor(
- storage->frame.clear_request_color.r,
- storage->frame.clear_request_color.g,
- storage->frame.clear_request_color.b,
- storage->frame.clear_request_color.a );
+ storage->frame.clear_request_color.r,
+ storage->frame.clear_request_color.g,
+ storage->frame.clear_request_color.b,
+ storage->frame.clear_request_color.a);
glClear(GL_COLOR_BUFFER_BIT);
-
}
if (p_render_target.is_valid()) {
- RasterizerStorageGLES3::RenderTarget * rt = storage->render_target_owner.getornull(p_render_target);
+ RasterizerStorageGLES3::RenderTarget *rt = storage->render_target_owner.getornull(p_render_target);
if (!rt) {
- storage->frame.current_rt=NULL;
+ storage->frame.current_rt = NULL;
}
ERR_FAIL_COND(!rt);
- storage->frame.current_rt=rt;
- storage->frame.clear_request=false;
+ storage->frame.current_rt = rt;
+ storage->frame.clear_request = false;
- glViewport(0,0,rt->width,rt->height);
+ glViewport(0, 0, rt->width, rt->height);
} else {
- storage->frame.current_rt=NULL;
- storage->frame.clear_request=false;
- glViewport(0,0,OS::get_singleton()->get_window_size().width,OS::get_singleton()->get_window_size().height);
- glBindFramebuffer(GL_FRAMEBUFFER,RasterizerStorageGLES3::system_fbo);
+ storage->frame.current_rt = NULL;
+ storage->frame.clear_request = false;
+ glViewport(0, 0, OS::get_singleton()->get_window_size().width, OS::get_singleton()->get_window_size().height);
+ glBindFramebuffer(GL_FRAMEBUFFER, RasterizerStorageGLES3::system_fbo);
}
}
void RasterizerGLES3::restore_render_target() {
- ERR_FAIL_COND(storage->frame.current_rt==NULL);
- RasterizerStorageGLES3::RenderTarget * rt = storage->frame.current_rt;
- glBindFramebuffer(GL_FRAMEBUFFER,rt->fbo);
- glViewport(0,0,rt->width,rt->height);
-
+ ERR_FAIL_COND(storage->frame.current_rt == NULL);
+ RasterizerStorageGLES3::RenderTarget *rt = storage->frame.current_rt;
+ glBindFramebuffer(GL_FRAMEBUFFER, rt->fbo);
+ glViewport(0, 0, rt->width, rt->height);
}
-void RasterizerGLES3::clear_render_target(const Color& p_color) {
+void RasterizerGLES3::clear_render_target(const Color &p_color) {
ERR_FAIL_COND(!storage->frame.current_rt);
- storage->frame.clear_request=true;
- storage->frame.clear_request_color=p_color;
-
+ storage->frame.clear_request = true;
+ storage->frame.clear_request_color = p_color;
}
-void RasterizerGLES3::blit_render_target_to_screen(RID p_render_target,const Rect2& p_screen_rect,int p_screen){
+void RasterizerGLES3::blit_render_target_to_screen(RID p_render_target, const Rect2 &p_screen_rect, int p_screen) {
- ERR_FAIL_COND( storage->frame.current_rt );
+ ERR_FAIL_COND(storage->frame.current_rt);
RasterizerStorageGLES3::RenderTarget *rt = storage->render_target_owner.getornull(p_render_target);
ERR_FAIL_COND(!rt);
canvas->canvas_begin();
glDisable(GL_BLEND);
- glBindFramebuffer(GL_FRAMEBUFFER,RasterizerStorageGLES3::system_fbo);
+ glBindFramebuffer(GL_FRAMEBUFFER, RasterizerStorageGLES3::system_fbo);
glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D,rt->color);
- canvas->draw_generic_textured_rect(p_screen_rect,Rect2(0,0,1,-1));
- glBindTexture(GL_TEXTURE_2D,0);
+ glBindTexture(GL_TEXTURE_2D, rt->color);
+ canvas->draw_generic_textured_rect(p_screen_rect, Rect2(0, 0, 1, -1));
+ glBindTexture(GL_TEXTURE_2D, 0);
canvas->canvas_end();
}
-void RasterizerGLES3::end_frame(){
+void RasterizerGLES3::end_frame() {
#if 0
canvas->canvas_begin();
@@ -335,7 +321,7 @@ void RasterizerGLES3::end_frame(){
#endif
OS::get_singleton()->swap_buffers();
-/* print_line("objects: "+itos(storage->info.render_object_count));
+ /* print_line("objects: "+itos(storage->info.render_object_count));
print_line("material chages: "+itos(storage->info.render_material_switch_count));
print_line("surface changes: "+itos(storage->info.render_surface_switch_count));
print_line("shader changes: "+itos(storage->info.render_shader_rebind_count));
@@ -343,45 +329,38 @@ void RasterizerGLES3::end_frame(){
*/
}
-void RasterizerGLES3::finalize(){
+void RasterizerGLES3::finalize() {
storage->finalize();
canvas->finalize();
}
-
Rasterizer *RasterizerGLES3::_create_current() {
- return memnew( RasterizerGLES3 );
+ return memnew(RasterizerGLES3);
}
void RasterizerGLES3::make_current() {
- _create_func=_create_current;
+ _create_func = _create_current;
}
-
void RasterizerGLES3::register_config() {
- GLOBAL_DEF("rendering/gles3/render_architecture",0);
- GlobalConfig::get_singleton()->set_custom_property_info("rendering/gles3/render_architecture",PropertyInfo(Variant::INT,"",PROPERTY_HINT_ENUM,"Desktop,Mobile"));
- GLOBAL_DEF("rendering/quality/use_nearest_mipmap_filter",false);
- GLOBAL_DEF("rendering/quality/anisotropic_filter_level",4.0);
-
+ GLOBAL_DEF("rendering/gles3/render_architecture", 0);
+ GlobalConfig::get_singleton()->set_custom_property_info("rendering/gles3/render_architecture", PropertyInfo(Variant::INT, "", PROPERTY_HINT_ENUM, "Desktop,Mobile"));
+ GLOBAL_DEF("rendering/quality/use_nearest_mipmap_filter", false);
+ GLOBAL_DEF("rendering/quality/anisotropic_filter_level", 4.0);
}
-RasterizerGLES3::RasterizerGLES3()
-{
-
- storage = memnew( RasterizerStorageGLES3 );
- canvas = memnew( RasterizerCanvasGLES3 );
- scene = memnew( RasterizerSceneGLES3 );
- canvas->storage=storage;
- storage->canvas=canvas;
- scene->storage=storage;
- storage->scene=scene;
-
-
+RasterizerGLES3::RasterizerGLES3() {
+ storage = memnew(RasterizerStorageGLES3);
+ canvas = memnew(RasterizerCanvasGLES3);
+ scene = memnew(RasterizerSceneGLES3);
+ canvas->storage = storage;
+ storage->canvas = canvas;
+ scene->storage = storage;
+ storage->scene = scene;
}
RasterizerGLES3::~RasterizerGLES3() {
diff --git a/drivers/gles3/rasterizer_gles3.h b/drivers/gles3/rasterizer_gles3.h
index 21e16b3bba..823f39ae8f 100644
--- a/drivers/gles3/rasterizer_gles3.h
+++ b/drivers/gles3/rasterizer_gles3.h
@@ -29,11 +29,10 @@
#ifndef RASTERIZERGLES3_H
#define RASTERIZERGLES3_H
-#include "servers/visual/rasterizer.h"
-#include "rasterizer_storage_gles3.h"
#include "rasterizer_canvas_gles3.h"
#include "rasterizer_scene_gles3.h"
-
+#include "rasterizer_storage_gles3.h"
+#include "servers/visual/rasterizer.h"
class RasterizerGLES3 : public Rasterizer {
@@ -44,7 +43,6 @@ class RasterizerGLES3 : public Rasterizer {
RasterizerSceneGLES3 *scene;
public:
-
virtual RasterizerStorage *get_storage();
virtual RasterizerCanvas *get_canvas();
virtual RasterizerScene *get_scene();
@@ -53,14 +51,13 @@ public:
virtual void begin_frame();
virtual void set_current_render_target(RID p_render_target);
virtual void restore_render_target();
- virtual void clear_render_target(const Color& p_color);
- virtual void blit_render_target_to_screen(RID p_render_target,const Rect2& p_screen_rect,int p_screen=0);
+ virtual void clear_render_target(const Color &p_color);
+ virtual void blit_render_target_to_screen(RID p_render_target, const Rect2 &p_screen_rect, int p_screen = 0);
virtual void end_frame();
virtual void finalize();
static void make_current();
-
static void register_config();
RasterizerGLES3();
~RasterizerGLES3();
diff --git a/drivers/gles3/rasterizer_scene_gles3.cpp b/drivers/gles3/rasterizer_scene_gles3.cpp
index f09e6ce904..b5d58ee997 100644
--- a/drivers/gles3/rasterizer_scene_gles3.cpp
+++ b/drivers/gles3/rasterizer_scene_gles3.cpp
@@ -36,7 +36,7 @@
#define glClearDepth glClearDepthf
#endif
-static const GLenum _cube_side_enum[6]={
+static const GLenum _cube_side_enum[6] = {
GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
GL_TEXTURE_CUBE_MAP_POSITIVE_X,
@@ -47,53 +47,51 @@ static const GLenum _cube_side_enum[6]={
};
-
-static _FORCE_INLINE_ void store_transform2d(const Transform2D& p_mtx, float* p_array) {
-
- p_array[ 0]=p_mtx.elements[0][0];
- p_array[ 1]=p_mtx.elements[0][1];
- p_array[ 2]=0;
- p_array[ 3]=0;
- p_array[ 4]=p_mtx.elements[1][0];
- p_array[ 5]=p_mtx.elements[1][1];
- p_array[ 6]=0;
- p_array[ 7]=0;
- p_array[ 8]=0;
- p_array[ 9]=0;
- p_array[10]=1;
- p_array[11]=0;
- p_array[12]=p_mtx.elements[2][0];
- p_array[13]=p_mtx.elements[2][1];
- p_array[14]=0;
- p_array[15]=1;
+static _FORCE_INLINE_ void store_transform2d(const Transform2D &p_mtx, float *p_array) {
+
+ p_array[0] = p_mtx.elements[0][0];
+ p_array[1] = p_mtx.elements[0][1];
+ p_array[2] = 0;
+ p_array[3] = 0;
+ p_array[4] = p_mtx.elements[1][0];
+ p_array[5] = p_mtx.elements[1][1];
+ p_array[6] = 0;
+ p_array[7] = 0;
+ p_array[8] = 0;
+ p_array[9] = 0;
+ p_array[10] = 1;
+ p_array[11] = 0;
+ p_array[12] = p_mtx.elements[2][0];
+ p_array[13] = p_mtx.elements[2][1];
+ p_array[14] = 0;
+ p_array[15] = 1;
}
-
-static _FORCE_INLINE_ void store_transform(const Transform& p_mtx, float* p_array) {
- p_array[ 0]=p_mtx.basis.elements[0][0];
- p_array[ 1]=p_mtx.basis.elements[1][0];
- p_array[ 2]=p_mtx.basis.elements[2][0];
- p_array[ 3]=0;
- p_array[ 4]=p_mtx.basis.elements[0][1];
- p_array[ 5]=p_mtx.basis.elements[1][1];
- p_array[ 6]=p_mtx.basis.elements[2][1];
- p_array[ 7]=0;
- p_array[ 8]=p_mtx.basis.elements[0][2];
- p_array[ 9]=p_mtx.basis.elements[1][2];
- p_array[10]=p_mtx.basis.elements[2][2];
- p_array[11]=0;
- p_array[12]=p_mtx.origin.x;
- p_array[13]=p_mtx.origin.y;
- p_array[14]=p_mtx.origin.z;
- p_array[15]=1;
+static _FORCE_INLINE_ void store_transform(const Transform &p_mtx, float *p_array) {
+ p_array[0] = p_mtx.basis.elements[0][0];
+ p_array[1] = p_mtx.basis.elements[1][0];
+ p_array[2] = p_mtx.basis.elements[2][0];
+ p_array[3] = 0;
+ p_array[4] = p_mtx.basis.elements[0][1];
+ p_array[5] = p_mtx.basis.elements[1][1];
+ p_array[6] = p_mtx.basis.elements[2][1];
+ p_array[7] = 0;
+ p_array[8] = p_mtx.basis.elements[0][2];
+ p_array[9] = p_mtx.basis.elements[1][2];
+ p_array[10] = p_mtx.basis.elements[2][2];
+ p_array[11] = 0;
+ p_array[12] = p_mtx.origin.x;
+ p_array[13] = p_mtx.origin.y;
+ p_array[14] = p_mtx.origin.z;
+ p_array[15] = 1;
}
-static _FORCE_INLINE_ void store_camera(const CameraMatrix& p_mtx, float* p_array) {
+static _FORCE_INLINE_ void store_camera(const CameraMatrix &p_mtx, float *p_array) {
- for (int i=0;i<4;i++) {
- for (int j=0;j<4;j++) {
+ for (int i = 0; i < 4; i++) {
+ for (int j = 0; j < 4; j++) {
- p_array[i*4+j]=p_mtx.matrix[i][j];
+ p_array[i * 4 + j] = p_mtx.matrix[i][j];
}
}
}
@@ -102,48 +100,47 @@ static _FORCE_INLINE_ void store_camera(const CameraMatrix& p_mtx, float* p_arra
RID RasterizerSceneGLES3::shadow_atlas_create() {
- ShadowAtlas *shadow_atlas = memnew( ShadowAtlas );
- shadow_atlas->fbo=0;
- shadow_atlas->depth=0;
- shadow_atlas->size=0;
- shadow_atlas->smallest_subdiv=0;
+ ShadowAtlas *shadow_atlas = memnew(ShadowAtlas);
+ shadow_atlas->fbo = 0;
+ shadow_atlas->depth = 0;
+ shadow_atlas->size = 0;
+ shadow_atlas->smallest_subdiv = 0;
- for(int i=0;i<4;i++) {
- shadow_atlas->size_order[i]=i;
+ for (int i = 0; i < 4; i++) {
+ shadow_atlas->size_order[i] = i;
}
-
return shadow_atlas_owner.make_rid(shadow_atlas);
}
-void RasterizerSceneGLES3::shadow_atlas_set_size(RID p_atlas,int p_size){
+void RasterizerSceneGLES3::shadow_atlas_set_size(RID p_atlas, int p_size) {
ShadowAtlas *shadow_atlas = shadow_atlas_owner.getornull(p_atlas);
ERR_FAIL_COND(!shadow_atlas);
- ERR_FAIL_COND(p_size<0);
+ ERR_FAIL_COND(p_size < 0);
p_size = nearest_power_of_2(p_size);
- if (p_size==shadow_atlas->size)
+ if (p_size == shadow_atlas->size)
return;
if (shadow_atlas->fbo) {
- glDeleteTextures(1,&shadow_atlas->depth);
- glDeleteFramebuffers(1,&shadow_atlas->fbo);
+ glDeleteTextures(1, &shadow_atlas->depth);
+ glDeleteFramebuffers(1, &shadow_atlas->fbo);
- shadow_atlas->depth=0;
- shadow_atlas->fbo=0;
+ shadow_atlas->depth = 0;
+ shadow_atlas->fbo = 0;
print_line("erasing atlas");
}
- for(int i=0;i<4;i++) {
+ for (int i = 0; i < 4; i++) {
//clear subdivisions
shadow_atlas->quadrants[i].shadows.resize(0);
- shadow_atlas->quadrants[i].shadows.resize( 1<<shadow_atlas->quadrants[i].subdivision );
+ shadow_atlas->quadrants[i].shadows.resize(1 << shadow_atlas->quadrants[i].subdivision);
}
//erase shadow atlas reference from lights
- for (Map<RID,uint32_t>::Element *E=shadow_atlas->shadow_owners.front();E;E=E->next()) {
+ for (Map<RID, uint32_t>::Element *E = shadow_atlas->shadow_owners.front(); E; E = E->next()) {
LightInstance *li = light_instance_owner.getornull(E->key());
ERR_CONTINUE(!li);
li->shadow_atlases.erase(p_atlas);
@@ -152,9 +149,9 @@ void RasterizerSceneGLES3::shadow_atlas_set_size(RID p_atlas,int p_size){
//clear owners
shadow_atlas->shadow_owners.clear();
- shadow_atlas->size=p_size;
+ shadow_atlas->size = p_size;
- if (shadow_atlas->size) {
+ if (shadow_atlas->size) {
glGenFramebuffers(1, &shadow_atlas->fbo);
glBindFramebuffer(GL_FRAMEBUFFER, shadow_atlas->fbo);
@@ -163,7 +160,7 @@ void RasterizerSceneGLES3::shadow_atlas_set_size(RID p_atlas,int p_size){
glGenTextures(1, &shadow_atlas->depth);
glBindTexture(GL_TEXTURE_2D, shadow_atlas->depth);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, shadow_atlas->size, shadow_atlas->size, 0,
- GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL);
+ GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
@@ -171,41 +168,37 @@ void RasterizerSceneGLES3::shadow_atlas_set_size(RID p_atlas,int p_size){
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
- GL_TEXTURE_2D, shadow_atlas->depth, 0);
+ GL_TEXTURE_2D, shadow_atlas->depth, 0);
- glViewport(0,0,shadow_atlas->size,shadow_atlas->size);
+ glViewport(0, 0, shadow_atlas->size, shadow_atlas->size);
glClearDepth(0.0f);
glClear(GL_DEPTH_BUFFER_BIT);
- glBindFramebuffer(GL_FRAMEBUFFER,0);
-
-
+ glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
}
-
-void RasterizerSceneGLES3::shadow_atlas_set_quadrant_subdivision(RID p_atlas,int p_quadrant,int p_subdivision){
+void RasterizerSceneGLES3::shadow_atlas_set_quadrant_subdivision(RID p_atlas, int p_quadrant, int p_subdivision) {
ShadowAtlas *shadow_atlas = shadow_atlas_owner.getornull(p_atlas);
ERR_FAIL_COND(!shadow_atlas);
- ERR_FAIL_INDEX(p_quadrant,4);
- ERR_FAIL_INDEX(p_subdivision,16384);
-
+ ERR_FAIL_INDEX(p_quadrant, 4);
+ ERR_FAIL_INDEX(p_subdivision, 16384);
uint32_t subdiv = nearest_power_of_2(p_subdivision);
- if (subdiv&0xaaaaaaaa) { //sqrt(subdiv) must be integer
- subdiv<<=1;
+ if (subdiv & 0xaaaaaaaa) { //sqrt(subdiv) must be integer
+ subdiv <<= 1;
}
- subdiv=int(Math::sqrt((float)subdiv));
+ subdiv = int(Math::sqrt((float)subdiv));
//obtain the number that will be x*x
- if (shadow_atlas->quadrants[p_quadrant].subdivision==subdiv)
+ if (shadow_atlas->quadrants[p_quadrant].subdivision == subdiv)
return;
//erase all data from quadrant
- for(int i=0;i<shadow_atlas->quadrants[p_quadrant].shadows.size();i++) {
+ for (int i = 0; i < shadow_atlas->quadrants[p_quadrant].shadows.size(); i++) {
if (shadow_atlas->quadrants[p_quadrant].shadows[i].owner.is_valid()) {
shadow_atlas->shadow_owners.erase(shadow_atlas->quadrants[p_quadrant].shadows[i].owner);
@@ -216,51 +209,45 @@ void RasterizerSceneGLES3::shadow_atlas_set_quadrant_subdivision(RID p_atlas,int
}
shadow_atlas->quadrants[p_quadrant].shadows.resize(0);
- shadow_atlas->quadrants[p_quadrant].shadows.resize(subdiv*subdiv);
- shadow_atlas->quadrants[p_quadrant].subdivision=subdiv;
+ shadow_atlas->quadrants[p_quadrant].shadows.resize(subdiv * subdiv);
+ shadow_atlas->quadrants[p_quadrant].subdivision = subdiv;
//cache the smallest subdiv (for faster allocation in light update)
- shadow_atlas->smallest_subdiv=1<<30;
+ shadow_atlas->smallest_subdiv = 1 << 30;
- for(int i=0;i<4;i++) {
+ for (int i = 0; i < 4; i++) {
if (shadow_atlas->quadrants[i].subdivision) {
- shadow_atlas->smallest_subdiv=MIN(shadow_atlas->smallest_subdiv,shadow_atlas->quadrants[i].subdivision);
+ shadow_atlas->smallest_subdiv = MIN(shadow_atlas->smallest_subdiv, shadow_atlas->quadrants[i].subdivision);
}
}
- if (shadow_atlas->smallest_subdiv==1<<30) {
- shadow_atlas->smallest_subdiv=0;
+ if (shadow_atlas->smallest_subdiv == 1 << 30) {
+ shadow_atlas->smallest_subdiv = 0;
}
//resort the size orders, simple bublesort for 4 elements..
- int swaps=0;
+ int swaps = 0;
do {
- swaps=0;
+ swaps = 0;
- for(int i=0;i<3;i++) {
- if (shadow_atlas->quadrants[shadow_atlas->size_order[i]].subdivision < shadow_atlas->quadrants[shadow_atlas->size_order[i+1]].subdivision) {
- SWAP(shadow_atlas->size_order[i],shadow_atlas->size_order[i+1]);
+ for (int i = 0; i < 3; i++) {
+ if (shadow_atlas->quadrants[shadow_atlas->size_order[i]].subdivision < shadow_atlas->quadrants[shadow_atlas->size_order[i + 1]].subdivision) {
+ SWAP(shadow_atlas->size_order[i], shadow_atlas->size_order[i + 1]);
swaps++;
}
}
- } while(swaps>0);
-
-
-
-
-
+ } while (swaps > 0);
}
-bool RasterizerSceneGLES3::_shadow_atlas_find_shadow(ShadowAtlas *shadow_atlas,int *p_in_quadrants,int p_quadrant_count,int p_current_subdiv,uint64_t p_tick,int &r_quadrant,int &r_shadow) {
-
+bool RasterizerSceneGLES3::_shadow_atlas_find_shadow(ShadowAtlas *shadow_atlas, int *p_in_quadrants, int p_quadrant_count, int p_current_subdiv, uint64_t p_tick, int &r_quadrant, int &r_shadow) {
- for(int i=p_quadrant_count-1;i>=0;i--) {
+ for (int i = p_quadrant_count - 1; i >= 0; i--) {
int qidx = p_in_quadrants[i];
- if (shadow_atlas->quadrants[qidx].subdivision==p_current_subdiv) {
+ if (shadow_atlas->quadrants[qidx].subdivision == p_current_subdiv) {
return false;
}
@@ -268,120 +255,113 @@ bool RasterizerSceneGLES3::_shadow_atlas_find_shadow(ShadowAtlas *shadow_atlas,i
int sc = shadow_atlas->quadrants[qidx].shadows.size();
ShadowAtlas::Quadrant::Shadow *sarr = shadow_atlas->quadrants[qidx].shadows.ptr();
- int found_free_idx=-1; //found a free one
- int found_used_idx=-1; //found existing one, must steal it
+ int found_free_idx = -1; //found a free one
+ int found_used_idx = -1; //found existing one, must steal it
uint64_t min_pass; // pass of the existing one, try to use the least recently used one (LRU fashion)
- for(int j=0;j<sc;j++) {
+ for (int j = 0; j < sc; j++) {
if (!sarr[j].owner.is_valid()) {
- found_free_idx=j;
+ found_free_idx = j;
break;
}
LightInstance *sli = light_instance_owner.getornull(sarr[j].owner);
ERR_CONTINUE(!sli);
- if (sli->last_scene_pass!=scene_pass) {
+ if (sli->last_scene_pass != scene_pass) {
//was just allocated, don't kill it so soon, wait a bit..
- if (p_tick-sarr[j].alloc_tick < shadow_atlas_realloc_tolerance_msec)
+ if (p_tick - sarr[j].alloc_tick < shadow_atlas_realloc_tolerance_msec)
continue;
- if (found_used_idx==-1 || sli->last_scene_pass<min_pass) {
- found_used_idx=j;
- min_pass=sli->last_scene_pass;
+ if (found_used_idx == -1 || sli->last_scene_pass < min_pass) {
+ found_used_idx = j;
+ min_pass = sli->last_scene_pass;
}
}
}
- if (found_free_idx==-1 && found_used_idx==-1)
+ if (found_free_idx == -1 && found_used_idx == -1)
continue; //nothing found
- if (found_free_idx==-1 && found_used_idx!=-1) {
- found_free_idx=found_used_idx;
+ if (found_free_idx == -1 && found_used_idx != -1) {
+ found_free_idx = found_used_idx;
}
- r_quadrant=qidx;
- r_shadow=found_free_idx;
+ r_quadrant = qidx;
+ r_shadow = found_free_idx;
return true;
}
return false;
-
}
-
-bool RasterizerSceneGLES3::shadow_atlas_update_light(RID p_atlas, RID p_light_intance, float p_coverage, uint64_t p_light_version){
-
+bool RasterizerSceneGLES3::shadow_atlas_update_light(RID p_atlas, RID p_light_intance, float p_coverage, uint64_t p_light_version) {
ShadowAtlas *shadow_atlas = shadow_atlas_owner.getornull(p_atlas);
- ERR_FAIL_COND_V(!shadow_atlas,false);
+ ERR_FAIL_COND_V(!shadow_atlas, false);
LightInstance *li = light_instance_owner.getornull(p_light_intance);
- ERR_FAIL_COND_V(!li,false);
+ ERR_FAIL_COND_V(!li, false);
- if (shadow_atlas->size==0 || shadow_atlas->smallest_subdiv==0) {
+ if (shadow_atlas->size == 0 || shadow_atlas->smallest_subdiv == 0) {
return false;
}
- uint32_t quad_size = shadow_atlas->size>>1;
- int desired_fit = MIN(quad_size/shadow_atlas->smallest_subdiv,nearest_power_of_2(quad_size*p_coverage));
-
+ uint32_t quad_size = shadow_atlas->size >> 1;
+ int desired_fit = MIN(quad_size / shadow_atlas->smallest_subdiv, nearest_power_of_2(quad_size * p_coverage));
int valid_quadrants[4];
- int valid_quadrant_count=0;
- int best_size=-1; //best size found
- int best_subdiv=-1; //subdiv for the best size
+ int valid_quadrant_count = 0;
+ int best_size = -1; //best size found
+ int best_subdiv = -1; //subdiv for the best size
//find the quadrants this fits into, and the best possible size it can fit into
- for(int i=0;i<4;i++) {
+ for (int i = 0; i < 4; i++) {
int q = shadow_atlas->size_order[i];
int sd = shadow_atlas->quadrants[q].subdivision;
- if (sd==0)
+ if (sd == 0)
continue; //unused
int max_fit = quad_size / sd;
- if (best_size!=-1 && max_fit>best_size)
+ if (best_size != -1 && max_fit > best_size)
break; //too large
- valid_quadrants[valid_quadrant_count++]=q;
- best_subdiv=sd;
+ valid_quadrants[valid_quadrant_count++] = q;
+ best_subdiv = sd;
- if (max_fit>=desired_fit) {
- best_size=max_fit;
+ if (max_fit >= desired_fit) {
+ best_size = max_fit;
}
}
- ERR_FAIL_COND_V(valid_quadrant_count==0,false);
+ ERR_FAIL_COND_V(valid_quadrant_count == 0, false);
uint64_t tick = OS::get_singleton()->get_ticks_msec();
-
//see if it already exists
if (shadow_atlas->shadow_owners.has(p_light_intance)) {
//it does!
uint32_t key = shadow_atlas->shadow_owners[p_light_intance];
- uint32_t q = (key>>ShadowAtlas::QUADRANT_SHIFT)&0x3;
- uint32_t s = key&ShadowAtlas::SHADOW_INDEX_MASK;
-
- bool should_realloc=shadow_atlas->quadrants[q].subdivision!=best_subdiv && (shadow_atlas->quadrants[q].shadows[s].alloc_tick-tick > shadow_atlas_realloc_tolerance_msec);
- bool should_redraw=shadow_atlas->quadrants[q].shadows[s].version!=p_light_version;
-
+ uint32_t q = (key >> ShadowAtlas::QUADRANT_SHIFT) & 0x3;
+ uint32_t s = key & ShadowAtlas::SHADOW_INDEX_MASK;
+ bool should_realloc = shadow_atlas->quadrants[q].subdivision != best_subdiv && (shadow_atlas->quadrants[q].shadows[s].alloc_tick - tick > shadow_atlas_realloc_tolerance_msec);
+ bool should_redraw = shadow_atlas->quadrants[q].shadows[s].version != p_light_version;
if (!should_realloc) {
- shadow_atlas->quadrants[q].shadows[s].version=p_light_version;
+ shadow_atlas->quadrants[q].shadows[s].version = p_light_version;
//already existing, see if it should redraw or it's just OK
return should_redraw;
}
- int new_quadrant,new_shadow;
+ int new_quadrant, new_shadow;
//find a better place
- if (_shadow_atlas_find_shadow(shadow_atlas,valid_quadrants,valid_quadrant_count,shadow_atlas->quadrants[q].subdivision,tick,new_quadrant,new_shadow)) {
+ if (_shadow_atlas_find_shadow(shadow_atlas, valid_quadrants, valid_quadrant_count, shadow_atlas->quadrants[q].subdivision, tick, new_quadrant, new_shadow)) {
//found a better place!
ShadowAtlas::Quadrant::Shadow *sh = &shadow_atlas->quadrants[new_quadrant].shadows[new_shadow];
if (sh->owner.is_valid()) {
@@ -392,18 +372,18 @@ bool RasterizerSceneGLES3::shadow_atlas_update_light(RID p_atlas, RID p_light_in
}
//erase previous
- shadow_atlas->quadrants[q].shadows[s].version=0;
- shadow_atlas->quadrants[q].shadows[s].owner=RID();
+ shadow_atlas->quadrants[q].shadows[s].version = 0;
+ shadow_atlas->quadrants[q].shadows[s].owner = RID();
- sh->owner=p_light_intance;
- sh->alloc_tick=tick;
- sh->version=p_light_version;
+ sh->owner = p_light_intance;
+ sh->alloc_tick = tick;
+ sh->version = p_light_version;
//make new key
- key=new_quadrant<<ShadowAtlas::QUADRANT_SHIFT;
- key|=new_shadow;
+ key = new_quadrant << ShadowAtlas::QUADRANT_SHIFT;
+ key |= new_shadow;
//update it in map
- shadow_atlas->shadow_owners[p_light_intance]=key;
+ shadow_atlas->shadow_owners[p_light_intance] = key;
//make it dirty, as it should redraw anyway
return true;
}
@@ -412,15 +392,15 @@ bool RasterizerSceneGLES3::shadow_atlas_update_light(RID p_atlas, RID p_light_in
//already existing, see if it should redraw or it's just OK
- shadow_atlas->quadrants[q].shadows[s].version=p_light_version;
+ shadow_atlas->quadrants[q].shadows[s].version = p_light_version;
return should_redraw;
}
- int new_quadrant,new_shadow;
+ int new_quadrant, new_shadow;
//find a better place
- if (_shadow_atlas_find_shadow(shadow_atlas,valid_quadrants,valid_quadrant_count,-1,tick,new_quadrant,new_shadow)) {
+ if (_shadow_atlas_find_shadow(shadow_atlas, valid_quadrants, valid_quadrant_count, -1, tick, new_quadrant, new_shadow)) {
//found a better place!
ShadowAtlas::Quadrant::Shadow *sh = &shadow_atlas->quadrants[new_quadrant].shadows[new_shadow];
if (sh->owner.is_valid()) {
@@ -430,15 +410,15 @@ bool RasterizerSceneGLES3::shadow_atlas_update_light(RID p_atlas, RID p_light_in
sli->shadow_atlases.erase(p_atlas);
}
- sh->owner=p_light_intance;
- sh->alloc_tick=tick;
- sh->version=p_light_version;
+ sh->owner = p_light_intance;
+ sh->alloc_tick = tick;
+ sh->version = p_light_version;
//make new key
- uint32_t key=new_quadrant<<ShadowAtlas::QUADRANT_SHIFT;
- key|=new_shadow;
+ uint32_t key = new_quadrant << ShadowAtlas::QUADRANT_SHIFT;
+ key |= new_shadow;
//update it in map
- shadow_atlas->shadow_owners[p_light_intance]=key;
+ shadow_atlas->shadow_owners[p_light_intance] = key;
//make it dirty, as it should redraw anyway
return true;
@@ -447,113 +427,106 @@ bool RasterizerSceneGLES3::shadow_atlas_update_light(RID p_atlas, RID p_light_in
//no place to allocate this light, apologies
return false;
-
-
-
-
}
void RasterizerSceneGLES3::set_directional_shadow_count(int p_count) {
- directional_shadow.light_count=p_count;
- directional_shadow.current_light=0;
+ directional_shadow.light_count = p_count;
+ directional_shadow.current_light = 0;
}
int RasterizerSceneGLES3::get_directional_light_shadow_size(RID p_light_intance) {
- ERR_FAIL_COND_V(directional_shadow.light_count==0,0);
+ ERR_FAIL_COND_V(directional_shadow.light_count == 0, 0);
int shadow_size;
- if (directional_shadow.light_count==1) {
+ if (directional_shadow.light_count == 1) {
shadow_size = directional_shadow.size;
} else {
- shadow_size = directional_shadow.size/2; //more than 4 not supported anyway
+ shadow_size = directional_shadow.size / 2; //more than 4 not supported anyway
}
LightInstance *light_instance = light_instance_owner.getornull(p_light_intance);
- ERR_FAIL_COND_V(!light_instance,0);
+ ERR_FAIL_COND_V(!light_instance, 0);
- switch(light_instance->light_ptr->directional_shadow_mode) {
- case VS::LIGHT_DIRECTIONAL_SHADOW_ORTHOGONAL: break; //none
+ switch (light_instance->light_ptr->directional_shadow_mode) {
+ case VS::LIGHT_DIRECTIONAL_SHADOW_ORTHOGONAL:
+ break; //none
case VS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_2_SPLITS:
- case VS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_4_SPLITS: shadow_size/=2; break;
+ case VS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_4_SPLITS: shadow_size /= 2; break;
}
return shadow_size;
-
}
//////////////////////////////////////////////////////
RID RasterizerSceneGLES3::reflection_atlas_create() {
- ReflectionAtlas *reflection_atlas = memnew( ReflectionAtlas );
- reflection_atlas->subdiv=0;
- reflection_atlas->color=0;
- reflection_atlas->size=0;
- for(int i=0;i<6;i++) {
- reflection_atlas->fbo[i]=0;
+ ReflectionAtlas *reflection_atlas = memnew(ReflectionAtlas);
+ reflection_atlas->subdiv = 0;
+ reflection_atlas->color = 0;
+ reflection_atlas->size = 0;
+ for (int i = 0; i < 6; i++) {
+ reflection_atlas->fbo[i] = 0;
}
return reflection_atlas_owner.make_rid(reflection_atlas);
}
-void RasterizerSceneGLES3::reflection_atlas_set_size(RID p_ref_atlas,int p_size) {
+void RasterizerSceneGLES3::reflection_atlas_set_size(RID p_ref_atlas, int p_size) {
ReflectionAtlas *reflection_atlas = reflection_atlas_owner.getornull(p_ref_atlas);
ERR_FAIL_COND(!reflection_atlas);
int size = nearest_power_of_2(p_size);
- if (size==reflection_atlas->size)
+ if (size == reflection_atlas->size)
return;
if (reflection_atlas->size) {
- for(int i=0;i<6;i++) {
- glDeleteFramebuffers(1,&reflection_atlas->fbo[i]);
- reflection_atlas->fbo[i]=0;
+ for (int i = 0; i < 6; i++) {
+ glDeleteFramebuffers(1, &reflection_atlas->fbo[i]);
+ reflection_atlas->fbo[i] = 0;
}
- glDeleteTextures(1,&reflection_atlas->color);
- reflection_atlas->color=0;
+ glDeleteTextures(1, &reflection_atlas->color);
+ reflection_atlas->color = 0;
}
- reflection_atlas->size=size;
+ reflection_atlas->size = size;
- for(int i=0;i<reflection_atlas->reflections.size();i++) {
+ for (int i = 0; i < reflection_atlas->reflections.size(); i++) {
//erase probes reference to this
if (reflection_atlas->reflections[i].owner.is_valid()) {
ReflectionProbeInstance *reflection_probe_instance = reflection_probe_instance_owner.getornull(reflection_atlas->reflections[i].owner);
- reflection_atlas->reflections[i].owner=RID();
+ reflection_atlas->reflections[i].owner = RID();
ERR_CONTINUE(!reflection_probe_instance);
- reflection_probe_instance->reflection_atlas_index=-1;
- reflection_probe_instance->atlas=RID();
- reflection_probe_instance->render_step=-1;
+ reflection_probe_instance->reflection_atlas_index = -1;
+ reflection_probe_instance->atlas = RID();
+ reflection_probe_instance->render_step = -1;
}
}
-
if (reflection_atlas->size) {
- bool use_float=true;
-
+ bool use_float = true;
- GLenum internal_format = use_float?GL_RGBA16F:GL_RGB10_A2;
+ GLenum internal_format = use_float ? GL_RGBA16F : GL_RGB10_A2;
GLenum format = GL_RGBA;
- GLenum type = use_float?GL_HALF_FLOAT:GL_UNSIGNED_INT_2_10_10_10_REV;
-
+ GLenum type = use_float ? GL_HALF_FLOAT : GL_UNSIGNED_INT_2_10_10_10_REV;
// Create a texture for storing the color
glActiveTexture(GL_TEXTURE0);
glGenTextures(1, &reflection_atlas->color);
glBindTexture(GL_TEXTURE_2D, reflection_atlas->color);
- int mmsize=reflection_atlas->size;
+ int mmsize = reflection_atlas->size;
- for(int i=0;i<6;i++) {
+ for (int i = 0; i < 6; i++) {
glTexImage2D(GL_TEXTURE_2D, i, internal_format, mmsize, mmsize, 0,
- format, type, NULL);
+ format, type, NULL);
- mmsize>>=1;
+ mmsize >>= 1;
}
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
@@ -564,194 +537,180 @@ void RasterizerSceneGLES3::reflection_atlas_set_size(RID p_ref_atlas,int p_size)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 5);
- mmsize=reflection_atlas->size;
+ mmsize = reflection_atlas->size;
- for(int i=0;i<6;i++) {
+ for (int i = 0; i < 6; i++) {
glGenFramebuffers(1, &reflection_atlas->fbo[i]);
glBindFramebuffer(GL_FRAMEBUFFER, reflection_atlas->fbo[i]);
- glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, reflection_atlas->color, i);
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, reflection_atlas->color, i);
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
- ERR_CONTINUE(status!=GL_FRAMEBUFFER_COMPLETE);
+ ERR_CONTINUE(status != GL_FRAMEBUFFER_COMPLETE);
glDisable(GL_SCISSOR_TEST);
- glViewport(0,0,mmsize,mmsize);
- glClearColor(0,0,0,0);
+ glViewport(0, 0, mmsize, mmsize);
+ glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT); //it needs to be cleared, to avoid generating garbage
- mmsize>>=1;
-
+ mmsize >>= 1;
}
-
-
}
-
-
-
}
-
-void RasterizerSceneGLES3::reflection_atlas_set_subdivision(RID p_ref_atlas,int p_subdiv) {
+void RasterizerSceneGLES3::reflection_atlas_set_subdivision(RID p_ref_atlas, int p_subdiv) {
ReflectionAtlas *reflection_atlas = reflection_atlas_owner.getornull(p_ref_atlas);
ERR_FAIL_COND(!reflection_atlas);
uint32_t subdiv = nearest_power_of_2(p_subdiv);
- if (subdiv&0xaaaaaaaa) { //sqrt(subdiv) must be integer
- subdiv<<=1;
+ if (subdiv & 0xaaaaaaaa) { //sqrt(subdiv) must be integer
+ subdiv <<= 1;
}
- subdiv=int(Math::sqrt((float)subdiv));
+ subdiv = int(Math::sqrt((float)subdiv));
- if (reflection_atlas->subdiv==subdiv)
+ if (reflection_atlas->subdiv == subdiv)
return;
-
if (subdiv) {
- for(int i=0;i<reflection_atlas->reflections.size();i++) {
+ for (int i = 0; i < reflection_atlas->reflections.size(); i++) {
//erase probes reference to this
if (reflection_atlas->reflections[i].owner.is_valid()) {
ReflectionProbeInstance *reflection_probe_instance = reflection_probe_instance_owner.getornull(reflection_atlas->reflections[i].owner);
- reflection_atlas->reflections[i].owner=RID();
+ reflection_atlas->reflections[i].owner = RID();
ERR_CONTINUE(!reflection_probe_instance);
- reflection_probe_instance->reflection_atlas_index=-1;
- reflection_probe_instance->atlas=RID();
- reflection_probe_instance->render_step=-1;
+ reflection_probe_instance->reflection_atlas_index = -1;
+ reflection_probe_instance->atlas = RID();
+ reflection_probe_instance->render_step = -1;
}
}
}
- reflection_atlas->subdiv=subdiv;
+ reflection_atlas->subdiv = subdiv;
- reflection_atlas->reflections.resize(subdiv*subdiv);
+ reflection_atlas->reflections.resize(subdiv * subdiv);
}
-
////////////////////////////////////////////////////
RID RasterizerSceneGLES3::reflection_probe_instance_create(RID p_probe) {
RasterizerStorageGLES3::ReflectionProbe *probe = storage->reflection_probe_owner.getornull(p_probe);
- ERR_FAIL_COND_V(!probe,RID());
+ ERR_FAIL_COND_V(!probe, RID());
- ReflectionProbeInstance *rpi = memnew( ReflectionProbeInstance );
+ ReflectionProbeInstance *rpi = memnew(ReflectionProbeInstance);
- rpi->probe_ptr=probe;
- rpi->self=reflection_probe_instance_owner.make_rid(rpi);
- rpi->probe=p_probe;
- rpi->reflection_atlas_index=-1;
- rpi->render_step=-1;
- rpi->last_pass=0;
+ rpi->probe_ptr = probe;
+ rpi->self = reflection_probe_instance_owner.make_rid(rpi);
+ rpi->probe = p_probe;
+ rpi->reflection_atlas_index = -1;
+ rpi->render_step = -1;
+ rpi->last_pass = 0;
return rpi->self;
}
-void RasterizerSceneGLES3::reflection_probe_instance_set_transform(RID p_instance,const Transform& p_transform) {
+void RasterizerSceneGLES3::reflection_probe_instance_set_transform(RID p_instance, const Transform &p_transform) {
ReflectionProbeInstance *rpi = reflection_probe_instance_owner.getornull(p_instance);
ERR_FAIL_COND(!rpi);
- rpi->transform=p_transform;
-
+ rpi->transform = p_transform;
}
void RasterizerSceneGLES3::reflection_probe_release_atlas_index(RID p_instance) {
ReflectionProbeInstance *rpi = reflection_probe_instance_owner.getornull(p_instance);
ERR_FAIL_COND(!rpi);
- if (rpi->reflection_atlas_index==-1)
+ if (rpi->reflection_atlas_index == -1)
return;
ReflectionAtlas *reflection_atlas = reflection_atlas_owner.getornull(rpi->atlas);
ERR_FAIL_COND(!reflection_atlas);
- ERR_FAIL_INDEX(rpi->reflection_atlas_index,reflection_atlas->reflections.size());
-
- ERR_FAIL_COND(reflection_atlas->reflections[rpi->reflection_atlas_index].owner!=rpi->self);
+ ERR_FAIL_INDEX(rpi->reflection_atlas_index, reflection_atlas->reflections.size());
- reflection_atlas->reflections[rpi->reflection_atlas_index].owner=RID();
+ ERR_FAIL_COND(reflection_atlas->reflections[rpi->reflection_atlas_index].owner != rpi->self);
- rpi->reflection_atlas_index=-1;
- rpi->atlas=RID();
- rpi->render_step=-1;
+ reflection_atlas->reflections[rpi->reflection_atlas_index].owner = RID();
+ rpi->reflection_atlas_index = -1;
+ rpi->atlas = RID();
+ rpi->render_step = -1;
}
bool RasterizerSceneGLES3::reflection_probe_instance_needs_redraw(RID p_instance) {
ReflectionProbeInstance *rpi = reflection_probe_instance_owner.getornull(p_instance);
- ERR_FAIL_COND_V(!rpi,false);
+ ERR_FAIL_COND_V(!rpi, false);
- return rpi->reflection_atlas_index==-1 || rpi->probe_ptr->update_mode==VS::REFLECTION_PROBE_UPDATE_ALWAYS;
+ return rpi->reflection_atlas_index == -1 || rpi->probe_ptr->update_mode == VS::REFLECTION_PROBE_UPDATE_ALWAYS;
}
-bool RasterizerSceneGLES3::reflection_probe_instance_has_reflection(RID p_instance){
+bool RasterizerSceneGLES3::reflection_probe_instance_has_reflection(RID p_instance) {
ReflectionProbeInstance *rpi = reflection_probe_instance_owner.getornull(p_instance);
- ERR_FAIL_COND_V(!rpi,false);
+ ERR_FAIL_COND_V(!rpi, false);
- return rpi->reflection_atlas_index!=-1;
+ return rpi->reflection_atlas_index != -1;
}
-bool RasterizerSceneGLES3::reflection_probe_instance_begin_render(RID p_instance,RID p_reflection_atlas) {
+bool RasterizerSceneGLES3::reflection_probe_instance_begin_render(RID p_instance, RID p_reflection_atlas) {
ReflectionProbeInstance *rpi = reflection_probe_instance_owner.getornull(p_instance);
- ERR_FAIL_COND_V(!rpi,false);
+ ERR_FAIL_COND_V(!rpi, false);
- rpi->render_step=0;
+ rpi->render_step = 0;
- if (rpi->reflection_atlas_index!=-1) {
+ if (rpi->reflection_atlas_index != -1) {
return true; //got one already
}
ReflectionAtlas *reflection_atlas = reflection_atlas_owner.getornull(p_reflection_atlas);
- ERR_FAIL_COND_V(!reflection_atlas,false);
-
+ ERR_FAIL_COND_V(!reflection_atlas, false);
- if (reflection_atlas->size==0 || reflection_atlas->subdiv==0) {
+ if (reflection_atlas->size == 0 || reflection_atlas->subdiv == 0) {
return false;
}
-
- int best_free=-1;
- int best_used=-1;
+ int best_free = -1;
+ int best_used = -1;
uint64_t best_used_frame;
- for(int i=0;i<reflection_atlas->reflections.size();i++) {
- if (reflection_atlas->reflections[i].owner==RID()) {
- best_free=i;
+ for (int i = 0; i < reflection_atlas->reflections.size(); i++) {
+ if (reflection_atlas->reflections[i].owner == RID()) {
+ best_free = i;
break;
}
- if (rpi->render_step<0 && reflection_atlas->reflections[i].last_frame<storage->frame.count &&
- (best_used==-1 || reflection_atlas->reflections[i].last_frame<best_used_frame)) {
- best_used=i;
- best_used_frame=reflection_atlas->reflections[i].last_frame;
+ if (rpi->render_step < 0 && reflection_atlas->reflections[i].last_frame < storage->frame.count &&
+ (best_used == -1 || reflection_atlas->reflections[i].last_frame < best_used_frame)) {
+ best_used = i;
+ best_used_frame = reflection_atlas->reflections[i].last_frame;
}
}
- if (best_free==-1 && best_used==-1) {
- return false ;// sorry, can not do. Try again next frame.
+ if (best_free == -1 && best_used == -1) {
+ return false; // sorry, can not do. Try again next frame.
}
- if (best_free==-1) {
+ if (best_free == -1) {
//find best from what is used
- best_free=best_used;
+ best_free = best_used;
ReflectionProbeInstance *victim_rpi = reflection_probe_instance_owner.getornull(reflection_atlas->reflections[best_free].owner);
- ERR_FAIL_COND_V(!victim_rpi,false);
- victim_rpi->atlas=RID();
- victim_rpi->reflection_atlas_index=-1;
-
+ ERR_FAIL_COND_V(!victim_rpi, false);
+ victim_rpi->atlas = RID();
+ victim_rpi->reflection_atlas_index = -1;
}
- reflection_atlas->reflections[best_free].owner=p_instance;
- reflection_atlas->reflections[best_free].last_frame=storage->frame.count;
+ reflection_atlas->reflections[best_free].owner = p_instance;
+ reflection_atlas->reflections[best_free].last_frame = storage->frame.count;
- rpi->reflection_atlas_index=best_free;
- rpi->atlas=p_reflection_atlas;
- rpi->render_step=0;
+ rpi->reflection_atlas_index = best_free;
+ rpi->atlas = p_reflection_atlas;
+ rpi->render_step = 0;
return true;
}
@@ -759,303 +718,274 @@ bool RasterizerSceneGLES3::reflection_probe_instance_begin_render(RID p_instance
bool RasterizerSceneGLES3::reflection_probe_instance_postprocess_step(RID p_instance) {
ReflectionProbeInstance *rpi = reflection_probe_instance_owner.getornull(p_instance);
- ERR_FAIL_COND_V(!rpi,true);
+ ERR_FAIL_COND_V(!rpi, true);
ReflectionAtlas *reflection_atlas = reflection_atlas_owner.getornull(rpi->atlas);
- ERR_FAIL_COND_V(!reflection_atlas,false);
+ ERR_FAIL_COND_V(!reflection_atlas, false);
- ERR_FAIL_COND_V(rpi->render_step>=6,true);
+ ERR_FAIL_COND_V(rpi->render_step >= 6, true);
- glBindFramebuffer(GL_FRAMEBUFFER,reflection_atlas->fbo[rpi->render_step]);
+ glBindFramebuffer(GL_FRAMEBUFFER, reflection_atlas->fbo[rpi->render_step]);
state.cube_to_dp_shader.bind();
- int target_size=reflection_atlas->size/reflection_atlas->subdiv;
+ int target_size = reflection_atlas->size / reflection_atlas->subdiv;
- int cubemap_index=reflection_cubemaps.size()-1;
+ int cubemap_index = reflection_cubemaps.size() - 1;
- for(int i=reflection_cubemaps.size()-1;i>=0;i--) {
+ for (int i = reflection_cubemaps.size() - 1; i >= 0; i--) {
//find appropriate cubemap to render to
- if (reflection_cubemaps[i].size>target_size*2)
+ if (reflection_cubemaps[i].size > target_size * 2)
break;
- cubemap_index=i;
+ cubemap_index = i;
}
glDisable(GL_BLEND);
glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_CUBE_MAP,reflection_cubemaps[cubemap_index].cubemap);
+ glBindTexture(GL_TEXTURE_CUBE_MAP, reflection_cubemaps[cubemap_index].cubemap);
glDisable(GL_CULL_FACE);
- storage->shaders.cubemap_filter.set_conditional(CubemapFilterShaderGLES3::USE_DUAL_PARABOLOID,true);
+ storage->shaders.cubemap_filter.set_conditional(CubemapFilterShaderGLES3::USE_DUAL_PARABOLOID, true);
storage->shaders.cubemap_filter.bind();
int cell_size = reflection_atlas->size / reflection_atlas->subdiv;
- for(int i=0;i<rpi->render_step;i++) {
- cell_size>>=1; //mipmaps!
+ for (int i = 0; i < rpi->render_step; i++) {
+ cell_size >>= 1; //mipmaps!
}
int x = (rpi->reflection_atlas_index % reflection_atlas->subdiv) * cell_size;
int y = (rpi->reflection_atlas_index / reflection_atlas->subdiv) * cell_size;
- int width=cell_size;
- int height=cell_size;
+ int width = cell_size;
+ int height = cell_size;
- storage->shaders.cubemap_filter.set_conditional(CubemapFilterShaderGLES3::USE_DIRECT_WRITE,rpi->render_step==0);
- storage->shaders.cubemap_filter.set_conditional(CubemapFilterShaderGLES3::LOW_QUALITY,rpi->probe_ptr->update_mode==VS::REFLECTION_PROBE_UPDATE_ALWAYS);
- for(int i=0;i<2;i++) {
+ storage->shaders.cubemap_filter.set_conditional(CubemapFilterShaderGLES3::USE_DIRECT_WRITE, rpi->render_step == 0);
+ storage->shaders.cubemap_filter.set_conditional(CubemapFilterShaderGLES3::LOW_QUALITY, rpi->probe_ptr->update_mode == VS::REFLECTION_PROBE_UPDATE_ALWAYS);
+ for (int i = 0; i < 2; i++) {
- storage->shaders.cubemap_filter.set_uniform(CubemapFilterShaderGLES3::Z_FLIP,i>0);
- storage->shaders.cubemap_filter.set_uniform(CubemapFilterShaderGLES3::ROUGHNESS,rpi->render_step/5.0);
+ storage->shaders.cubemap_filter.set_uniform(CubemapFilterShaderGLES3::Z_FLIP, i > 0);
+ storage->shaders.cubemap_filter.set_uniform(CubemapFilterShaderGLES3::ROUGHNESS, rpi->render_step / 5.0);
- uint32_t local_width=width,local_height=height;
- uint32_t local_x=x,local_y=y;
+ uint32_t local_width = width, local_height = height;
+ uint32_t local_x = x, local_y = y;
- local_height/=2;
- local_y+=i*local_height;
+ local_height /= 2;
+ local_y += i * local_height;
- glViewport(local_x,local_y,local_width,local_height);
+ glViewport(local_x, local_y, local_width, local_height);
_copy_screen();
}
- storage->shaders.cubemap_filter.set_conditional(CubemapFilterShaderGLES3::USE_DIRECT_WRITE,false);
- storage->shaders.cubemap_filter.set_conditional(CubemapFilterShaderGLES3::LOW_QUALITY,false);
-
+ storage->shaders.cubemap_filter.set_conditional(CubemapFilterShaderGLES3::USE_DIRECT_WRITE, false);
+ storage->shaders.cubemap_filter.set_conditional(CubemapFilterShaderGLES3::LOW_QUALITY, false);
rpi->render_step++;
- return rpi->render_step==6;
+ return rpi->render_step == 6;
}
/* ENVIRONMENT API */
-RID RasterizerSceneGLES3::environment_create(){
+RID RasterizerSceneGLES3::environment_create() {
-
- Environment *env = memnew( Environment );
+ Environment *env = memnew(Environment);
return environment_owner.make_rid(env);
}
-void RasterizerSceneGLES3::environment_set_background(RID p_env,VS::EnvironmentBG p_bg){
+void RasterizerSceneGLES3::environment_set_background(RID p_env, VS::EnvironmentBG p_bg) {
- Environment *env=environment_owner.getornull(p_env);
+ Environment *env = environment_owner.getornull(p_env);
ERR_FAIL_COND(!env);
- env->bg_mode=p_bg;
+ env->bg_mode = p_bg;
}
-void RasterizerSceneGLES3::environment_set_skybox(RID p_env, RID p_skybox){
+void RasterizerSceneGLES3::environment_set_skybox(RID p_env, RID p_skybox) {
- Environment *env=environment_owner.getornull(p_env);
+ Environment *env = environment_owner.getornull(p_env);
ERR_FAIL_COND(!env);
- env->skybox=p_skybox;
-
+ env->skybox = p_skybox;
}
-void RasterizerSceneGLES3::environment_set_skybox_scale(RID p_env,float p_scale) {
+void RasterizerSceneGLES3::environment_set_skybox_scale(RID p_env, float p_scale) {
- Environment *env=environment_owner.getornull(p_env);
+ Environment *env = environment_owner.getornull(p_env);
ERR_FAIL_COND(!env);
- env->skybox_scale=p_scale;
-
+ env->skybox_scale = p_scale;
}
-void RasterizerSceneGLES3::environment_set_bg_color(RID p_env,const Color& p_color){
+void RasterizerSceneGLES3::environment_set_bg_color(RID p_env, const Color &p_color) {
- Environment *env=environment_owner.getornull(p_env);
+ Environment *env = environment_owner.getornull(p_env);
ERR_FAIL_COND(!env);
- env->bg_color=p_color;
-
+ env->bg_color = p_color;
}
-void RasterizerSceneGLES3::environment_set_bg_energy(RID p_env,float p_energy) {
+void RasterizerSceneGLES3::environment_set_bg_energy(RID p_env, float p_energy) {
- Environment *env=environment_owner.getornull(p_env);
+ Environment *env = environment_owner.getornull(p_env);
ERR_FAIL_COND(!env);
- env->bg_energy=p_energy;
-
+ env->bg_energy = p_energy;
}
-void RasterizerSceneGLES3::environment_set_canvas_max_layer(RID p_env,int p_max_layer){
+void RasterizerSceneGLES3::environment_set_canvas_max_layer(RID p_env, int p_max_layer) {
- Environment *env=environment_owner.getornull(p_env);
+ Environment *env = environment_owner.getornull(p_env);
ERR_FAIL_COND(!env);
- env->canvas_max_layer=p_max_layer;
-
+ env->canvas_max_layer = p_max_layer;
}
-void RasterizerSceneGLES3::environment_set_ambient_light(RID p_env, const Color& p_color, float p_energy, float p_skybox_contribution){
+void RasterizerSceneGLES3::environment_set_ambient_light(RID p_env, const Color &p_color, float p_energy, float p_skybox_contribution) {
- Environment *env=environment_owner.getornull(p_env);
+ Environment *env = environment_owner.getornull(p_env);
ERR_FAIL_COND(!env);
- env->ambient_color=p_color;
- env->ambient_energy=p_energy;
- env->ambient_skybox_contribution=p_skybox_contribution;
-
+ env->ambient_color = p_color;
+ env->ambient_energy = p_energy;
+ env->ambient_skybox_contribution = p_skybox_contribution;
}
+void RasterizerSceneGLES3::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 RasterizerSceneGLES3::environment_set_dof_blur_far(RID p_env,bool p_enable,float p_distance,float p_transition,float p_amount,VS::EnvironmentDOFBlurQuality p_quality){
-
- Environment *env=environment_owner.getornull(p_env);
+ Environment *env = environment_owner.getornull(p_env);
ERR_FAIL_COND(!env);
- env->dof_blur_far_enabled=p_enable;
- env->dof_blur_far_distance=p_distance;
- env->dof_blur_far_transition=p_transition;
- env->dof_blur_far_amount=p_amount;
- env->dof_blur_far_quality=p_quality;
-
-
+ env->dof_blur_far_enabled = p_enable;
+ env->dof_blur_far_distance = p_distance;
+ env->dof_blur_far_transition = p_transition;
+ env->dof_blur_far_amount = p_amount;
+ env->dof_blur_far_quality = p_quality;
}
-void RasterizerSceneGLES3::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 RasterizerSceneGLES3::environment_set_dof_blur_near(RID p_env, bool p_enable, float p_distance, float p_transition, float p_amount, VS::EnvironmentDOFBlurQuality p_quality) {
- Environment *env=environment_owner.getornull(p_env);
+ Environment *env = environment_owner.getornull(p_env);
ERR_FAIL_COND(!env);
- env->dof_blur_near_enabled=p_enable;
- env->dof_blur_near_distance=p_distance;
- env->dof_blur_near_transition=p_transition;
- env->dof_blur_near_amount=p_amount;
- env->dof_blur_near_quality=p_quality;
-
-
+ env->dof_blur_near_enabled = p_enable;
+ env->dof_blur_near_distance = p_distance;
+ env->dof_blur_near_transition = p_transition;
+ env->dof_blur_near_amount = p_amount;
+ env->dof_blur_near_quality = p_quality;
}
void RasterizerSceneGLES3::environment_set_glow(RID p_env, bool p_enable, int p_level_flags, float p_intensity, float p_strength, float p_bloom_treshold, VS::EnvironmentGlowBlendMode p_blend_mode, float p_hdr_bleed_treshold, float p_hdr_bleed_scale, bool p_bicubic_upscale) {
- Environment *env=environment_owner.getornull(p_env);
+ Environment *env = environment_owner.getornull(p_env);
ERR_FAIL_COND(!env);
- env->glow_enabled=p_enable;
- env->glow_levels=p_level_flags;
- env->glow_intensity=p_intensity;
- env->glow_strength=p_strength;
- env->glow_bloom=p_bloom_treshold;
- env->glow_blend_mode=p_blend_mode;
- env->glow_hdr_bleed_treshold=p_hdr_bleed_treshold;
- env->glow_hdr_bleed_scale=p_hdr_bleed_scale;
- env->glow_bicubic_upscale=p_bicubic_upscale;
-
+ env->glow_enabled = p_enable;
+ env->glow_levels = p_level_flags;
+ env->glow_intensity = p_intensity;
+ env->glow_strength = p_strength;
+ env->glow_bloom = p_bloom_treshold;
+ env->glow_blend_mode = p_blend_mode;
+ env->glow_hdr_bleed_treshold = p_hdr_bleed_treshold;
+ env->glow_hdr_bleed_scale = p_hdr_bleed_scale;
+ env->glow_bicubic_upscale = p_bicubic_upscale;
}
-void RasterizerSceneGLES3::environment_set_fog(RID p_env,bool p_enable,float p_begin,float p_end,RID p_gradient_texture){
-
+void RasterizerSceneGLES3::environment_set_fog(RID p_env, bool p_enable, float p_begin, float p_end, RID p_gradient_texture) {
}
-void RasterizerSceneGLES3::environment_set_ssr(RID p_env,bool p_enable, int p_max_steps,float p_accel,float p_fade,float p_depth_tolerance,bool p_smooth,bool p_roughness) {
+void RasterizerSceneGLES3::environment_set_ssr(RID p_env, bool p_enable, int p_max_steps, float p_accel, float p_fade, float p_depth_tolerance, bool p_smooth, bool p_roughness) {
- Environment *env=environment_owner.getornull(p_env);
+ Environment *env = environment_owner.getornull(p_env);
ERR_FAIL_COND(!env);
- env->ssr_enabled=p_enable;
- env->ssr_max_steps=p_max_steps;
- env->ssr_accel=p_accel;
- env->ssr_fade=p_fade;
- env->ssr_depth_tolerance=p_depth_tolerance;
- env->ssr_smooth=p_smooth;
- env->ssr_roughness=p_roughness;
-
+ env->ssr_enabled = p_enable;
+ env->ssr_max_steps = p_max_steps;
+ env->ssr_accel = p_accel;
+ env->ssr_fade = p_fade;
+ env->ssr_depth_tolerance = p_depth_tolerance;
+ env->ssr_smooth = p_smooth;
+ env->ssr_roughness = p_roughness;
}
+void RasterizerSceneGLES3::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, const Color &p_color, bool p_blur) {
-void RasterizerSceneGLES3::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,const Color &p_color,bool p_blur) {
-
- Environment *env=environment_owner.getornull(p_env);
+ Environment *env = environment_owner.getornull(p_env);
ERR_FAIL_COND(!env);
- env->ssao_enabled=p_enable;
- env->ssao_radius=p_radius;
- env->ssao_intensity=p_intensity;
- env->ssao_radius2=p_radius2;
- env->ssao_intensity2=p_intensity2;
- env->ssao_bias=p_bias;
- env->ssao_light_affect=p_light_affect;
- env->ssao_color=p_color;
- env->ssao_filter=p_blur;
-
+ env->ssao_enabled = p_enable;
+ env->ssao_radius = p_radius;
+ env->ssao_intensity = p_intensity;
+ env->ssao_radius2 = p_radius2;
+ env->ssao_intensity2 = p_intensity2;
+ env->ssao_bias = p_bias;
+ env->ssao_light_affect = p_light_affect;
+ env->ssao_color = p_color;
+ env->ssao_filter = p_blur;
}
-void RasterizerSceneGLES3::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 RasterizerSceneGLES3::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) {
- Environment *env=environment_owner.getornull(p_env);
+ Environment *env = environment_owner.getornull(p_env);
ERR_FAIL_COND(!env);
-
- env->tone_mapper=p_tone_mapper;
- env->tone_mapper_exposure=p_exposure;
- env->tone_mapper_exposure_white=p_white;
- env->auto_exposure=p_auto_exposure;
- env->auto_exposure_speed=p_auto_exp_speed;
- env->auto_exposure_min=p_min_luminance;
- env->auto_exposure_max=p_max_luminance;
- env->auto_exposure_grey=p_auto_exp_scale;
-
+ env->tone_mapper = p_tone_mapper;
+ env->tone_mapper_exposure = p_exposure;
+ env->tone_mapper_exposure_white = p_white;
+ env->auto_exposure = p_auto_exposure;
+ env->auto_exposure_speed = p_auto_exp_speed;
+ env->auto_exposure_min = p_min_luminance;
+ env->auto_exposure_max = p_max_luminance;
+ env->auto_exposure_grey = p_auto_exp_scale;
}
-
-void RasterizerSceneGLES3::environment_set_adjustment(RID p_env,bool p_enable,float p_brightness,float p_contrast,float p_saturation,RID p_ramp) {
-
-
+void RasterizerSceneGLES3::environment_set_adjustment(RID p_env, bool p_enable, float p_brightness, float p_contrast, float p_saturation, RID p_ramp) {
}
-
RID RasterizerSceneGLES3::light_instance_create(RID p_light) {
+ LightInstance *light_instance = memnew(LightInstance);
- LightInstance *light_instance = memnew( LightInstance );
-
- light_instance->last_pass=0;
- light_instance->last_scene_pass=0;
- light_instance->last_scene_shadow_pass=0;
+ light_instance->last_pass = 0;
+ light_instance->last_scene_pass = 0;
+ light_instance->last_scene_shadow_pass = 0;
- light_instance->light=p_light;
- light_instance->light_ptr=storage->light_owner.getornull(p_light);
+ light_instance->light = p_light;
+ light_instance->light_ptr = storage->light_owner.getornull(p_light);
- ERR_FAIL_COND_V(!light_instance->light_ptr,RID());
+ ERR_FAIL_COND_V(!light_instance->light_ptr, RID());
- light_instance->self=light_instance_owner.make_rid(light_instance);
+ light_instance->self = light_instance_owner.make_rid(light_instance);
return light_instance->self;
}
-void RasterizerSceneGLES3::light_instance_set_transform(RID p_light_instance,const Transform& p_transform){
+void RasterizerSceneGLES3::light_instance_set_transform(RID p_light_instance, const Transform &p_transform) {
LightInstance *light_instance = light_instance_owner.getornull(p_light_instance);
ERR_FAIL_COND(!light_instance);
- light_instance->transform=p_transform;
+ light_instance->transform = p_transform;
}
-void RasterizerSceneGLES3::light_instance_set_shadow_transform(RID p_light_instance,const CameraMatrix& p_projection,const Transform& p_transform,float p_far,float p_split,int p_pass) {
+void RasterizerSceneGLES3::light_instance_set_shadow_transform(RID p_light_instance, const CameraMatrix &p_projection, const Transform &p_transform, float p_far, float p_split, int p_pass) {
LightInstance *light_instance = light_instance_owner.getornull(p_light_instance);
ERR_FAIL_COND(!light_instance);
- if (light_instance->light_ptr->type!=VS::LIGHT_DIRECTIONAL) {
- p_pass=0;
+ if (light_instance->light_ptr->type != VS::LIGHT_DIRECTIONAL) {
+ p_pass = 0;
}
- ERR_FAIL_INDEX(p_pass,4);
-
- light_instance->shadow_transform[p_pass].camera=p_projection;
- light_instance->shadow_transform[p_pass].transform=p_transform;
- light_instance->shadow_transform[p_pass].farplane=p_far;
- light_instance->shadow_transform[p_pass].split=p_split;
+ ERR_FAIL_INDEX(p_pass, 4);
+ light_instance->shadow_transform[p_pass].camera = p_projection;
+ light_instance->shadow_transform[p_pass].transform = p_transform;
+ light_instance->shadow_transform[p_pass].farplane = p_far;
+ light_instance->shadow_transform[p_pass].split = p_split;
}
-
void RasterizerSceneGLES3::light_instance_mark_visible(RID p_light_instance) {
LightInstance *light_instance = light_instance_owner.getornull(p_light_instance);
ERR_FAIL_COND(!light_instance);
- light_instance->last_scene_pass=scene_pass;
+ light_instance->last_scene_pass = scene_pass;
}
-
//////////////////////
RID RasterizerSceneGLES3::gi_probe_instance_create() {
@@ -1069,66 +999,63 @@ void RasterizerSceneGLES3::gi_probe_instance_set_light_data(RID p_probe, RID p_b
GIProbeInstance *gipi = gi_probe_instance_owner.getornull(p_probe);
ERR_FAIL_COND(!gipi);
- gipi->data=p_data;
- gipi->probe=storage->gi_probe_owner.getornull(p_base);
+ gipi->data = p_data;
+ gipi->probe = storage->gi_probe_owner.getornull(p_base);
if (p_data.is_valid()) {
RasterizerStorageGLES3::GIProbeData *gipd = storage->gi_probe_data_owner.getornull(p_data);
ERR_FAIL_COND(!gipd);
if (gipd) {
- gipi->tex_cache=gipd->tex_id;
- gipi->cell_size_cache.x=1.0/gipd->width;
- gipi->cell_size_cache.y=1.0/gipd->height;
- gipi->cell_size_cache.z=1.0/gipd->depth;
+ gipi->tex_cache = gipd->tex_id;
+ gipi->cell_size_cache.x = 1.0 / gipd->width;
+ gipi->cell_size_cache.y = 1.0 / gipd->height;
+ gipi->cell_size_cache.z = 1.0 / gipd->depth;
}
}
}
-void RasterizerSceneGLES3::gi_probe_instance_set_transform_to_data(RID p_probe,const Transform& p_xform) {
+void RasterizerSceneGLES3::gi_probe_instance_set_transform_to_data(RID p_probe, const Transform &p_xform) {
GIProbeInstance *gipi = gi_probe_instance_owner.getornull(p_probe);
ERR_FAIL_COND(!gipi);
- gipi->transform_to_data=p_xform;
-
+ gipi->transform_to_data = p_xform;
}
-void RasterizerSceneGLES3::gi_probe_instance_set_bounds(RID p_probe,const Vector3& p_bounds) {
+void RasterizerSceneGLES3::gi_probe_instance_set_bounds(RID p_probe, const Vector3 &p_bounds) {
GIProbeInstance *gipi = gi_probe_instance_owner.getornull(p_probe);
ERR_FAIL_COND(!gipi);
- gipi->bounds=p_bounds;
-
+ gipi->bounds = p_bounds;
}
////////////////////////////
////////////////////////////
////////////////////////////
-bool RasterizerSceneGLES3::_setup_material(RasterizerStorageGLES3::Material* p_material,bool p_alpha_pass) {
+bool RasterizerSceneGLES3::_setup_material(RasterizerStorageGLES3::Material *p_material, bool p_alpha_pass) {
- if (p_material->shader->spatial.cull_mode==RasterizerStorageGLES3::Shader::Spatial::CULL_MODE_DISABLED) {
+ if (p_material->shader->spatial.cull_mode == RasterizerStorageGLES3::Shader::Spatial::CULL_MODE_DISABLED) {
glDisable(GL_CULL_FACE);
} else {
glEnable(GL_CULL_FACE);
}
- if (state.current_line_width!=p_material->line_width) {
+ if (state.current_line_width != p_material->line_width) {
//glLineWidth(MAX(p_material->line_width,1.0));
- state.current_line_width=p_material->line_width;
+ state.current_line_width = p_material->line_width;
}
- if (state.current_depth_test!=(!p_material->shader->spatial.ontop)) {
+ if (state.current_depth_test != (!p_material->shader->spatial.ontop)) {
if (p_material->shader->spatial.ontop) {
glDisable(GL_DEPTH_TEST);
} else {
glEnable(GL_DEPTH_TEST);
-
}
- state.current_depth_test=!p_material->shader->spatial.ontop;
+ state.current_depth_test = !p_material->shader->spatial.ontop;
}
- if (state.current_depth_draw!=p_material->shader->spatial.depth_draw_mode) {
- switch(p_material->shader->spatial.depth_draw_mode) {
+ if (state.current_depth_draw != p_material->shader->spatial.depth_draw_mode) {
+ switch (p_material->shader->spatial.depth_draw_mode) {
case RasterizerStorageGLES3::Shader::Spatial::DEPTH_DRAW_ALPHA_PREPASS:
case RasterizerStorageGLES3::Shader::Spatial::DEPTH_DRAW_OPAQUE: {
@@ -1142,12 +1069,12 @@ bool RasterizerSceneGLES3::_setup_material(RasterizerStorageGLES3::Material* p_m
} break;
}
- state.current_depth_draw=p_material->shader->spatial.depth_draw_mode;
+ state.current_depth_draw = p_material->shader->spatial.depth_draw_mode;
}
- //glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
+//glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
- /*
+/*
if (p_material->flags[VS::MATERIAL_FLAG_WIREFRAME])
glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
else
@@ -1200,54 +1127,49 @@ bool RasterizerSceneGLES3::_setup_material(RasterizerStorageGLES3::Material* p_m
#endif
//material parameters
-
state.scene_shader.set_custom_shader(p_material->shader->custom_code_id);
bool rebind = state.scene_shader.bind();
-
if (p_material->ubo_id) {
- glBindBufferBase(GL_UNIFORM_BUFFER,1,p_material->ubo_id);
+ glBindBufferBase(GL_UNIFORM_BUFFER, 1, p_material->ubo_id);
}
-
-
int tc = p_material->textures.size();
- RID* textures = p_material->textures.ptr();
- ShaderLanguage::ShaderNode::Uniform::Hint* texture_hints = p_material->shader->texture_hints.ptr();
+ RID *textures = p_material->textures.ptr();
+ ShaderLanguage::ShaderNode::Uniform::Hint *texture_hints = p_material->shader->texture_hints.ptr();
- state.current_main_tex=0;
+ state.current_main_tex = 0;
- for(int i=0;i<tc;i++) {
+ for (int i = 0; i < tc; i++) {
- glActiveTexture(GL_TEXTURE0+i);
+ glActiveTexture(GL_TEXTURE0 + i);
GLenum target;
GLuint tex;
- RasterizerStorageGLES3::Texture *t = storage->texture_owner.getornull( textures[i] );
+ RasterizerStorageGLES3::Texture *t = storage->texture_owner.getornull(textures[i]);
if (!t) {
//check hints
- target=GL_TEXTURE_2D;
+ target = GL_TEXTURE_2D;
- switch(texture_hints[i]) {
+ switch (texture_hints[i]) {
case ShaderLanguage::ShaderNode::Uniform::HINT_BLACK_ALBEDO:
case ShaderLanguage::ShaderNode::Uniform::HINT_BLACK: {
- tex=storage->resources.black_tex;
+ tex = storage->resources.black_tex;
} break;
case ShaderLanguage::ShaderNode::Uniform::HINT_ANISO: {
- tex=storage->resources.aniso_tex;
+ tex = storage->resources.aniso_tex;
} break;
case ShaderLanguage::ShaderNode::Uniform::HINT_NORMAL: {
- tex=storage->resources.normal_tex;
+ tex = storage->resources.normal_tex;
} break;
default: {
- tex=storage->resources.white_tex;
+ tex = storage->resources.white_tex;
} break;
}
-
} else {
#ifdef TOOLS_ENABLED
@@ -1257,15 +1179,15 @@ bool RasterizerSceneGLES3::_setup_material(RasterizerStorageGLES3::Material* p_m
#endif
if (storage->config.srgb_decode_supported) {
//if SRGB decode extension is present, simply switch the texture to whathever is needed
- bool must_srgb=false;
+ bool must_srgb = false;
- if (t->srgb && (texture_hints[i]==ShaderLanguage::ShaderNode::Uniform::HINT_ALBEDO || texture_hints[i]==ShaderLanguage::ShaderNode::Uniform::HINT_BLACK_ALBEDO)) {
- must_srgb=true;
+ if (t->srgb && (texture_hints[i] == ShaderLanguage::ShaderNode::Uniform::HINT_ALBEDO || texture_hints[i] == ShaderLanguage::ShaderNode::Uniform::HINT_BLACK_ALBEDO)) {
+ must_srgb = true;
}
- if (t->using_srgb!=must_srgb) {
+ if (t->using_srgb != must_srgb) {
if (must_srgb) {
- glTexParameteri(t->target,_TEXTURE_SRGB_DECODE_EXT,_DECODE_EXT);
+ glTexParameteri(t->target, _TEXTURE_SRGB_DECODE_EXT, _DECODE_EXT);
#ifdef TOOLS_ENABLED
if (t->detect_srgb) {
t->detect_srgb(t->detect_srgb_ud);
@@ -1273,41 +1195,37 @@ bool RasterizerSceneGLES3::_setup_material(RasterizerStorageGLES3::Material* p_m
#endif
} else {
- glTexParameteri(t->target,_TEXTURE_SRGB_DECODE_EXT,_SKIP_DECODE_EXT);
+ glTexParameteri(t->target, _TEXTURE_SRGB_DECODE_EXT, _SKIP_DECODE_EXT);
}
- t->using_srgb=must_srgb;
+ t->using_srgb = must_srgb;
}
}
- target=t->target;
+ target = t->target;
tex = t->tex_id;
-
}
- glBindTexture(target,tex);
+ glBindTexture(target, tex);
- if (i==0) {
- state.current_main_tex=tex;
+ if (i == 0) {
+ state.current_main_tex = tex;
}
}
-
return rebind;
-
}
-
void RasterizerSceneGLES3::_setup_geometry(RenderList::Element *e) {
- switch(e->instance->base_type) {
+ switch (e->instance->base_type) {
case VS::INSTANCE_MESH: {
- RasterizerStorageGLES3::Surface *s = static_cast<RasterizerStorageGLES3::Surface*>(e->geometry);
+ RasterizerStorageGLES3::Surface *s = static_cast<RasterizerStorageGLES3::Surface *>(e->geometry);
if (s->blend_shapes.size() && e->instance->blend_values.size()) {
//blend shapes, use transform feedback
- storage->mesh_render_blend_shapes(s,e->instance->blend_values.ptr());
+ storage->mesh_render_blend_shapes(s, e->instance->blend_values.ptr());
//rebind shader
state.scene_shader.bind();
} else {
@@ -1319,57 +1237,56 @@ void RasterizerSceneGLES3::_setup_geometry(RenderList::Element *e) {
case VS::INSTANCE_MULTIMESH: {
- RasterizerStorageGLES3::MultiMesh *multi_mesh = static_cast<RasterizerStorageGLES3::MultiMesh*>(e->owner);
- RasterizerStorageGLES3::Surface *s = static_cast<RasterizerStorageGLES3::Surface*>(e->geometry);
+ RasterizerStorageGLES3::MultiMesh *multi_mesh = static_cast<RasterizerStorageGLES3::MultiMesh *>(e->owner);
+ RasterizerStorageGLES3::Surface *s = static_cast<RasterizerStorageGLES3::Surface *>(e->geometry);
glBindVertexArray(s->instancing_array_id); // use the instancing array ID
- glBindBuffer(GL_ARRAY_BUFFER,multi_mesh->buffer); //modify the buffer
+ glBindBuffer(GL_ARRAY_BUFFER, multi_mesh->buffer); //modify the buffer
- int stride = (multi_mesh->xform_floats+multi_mesh->color_floats)*4;
+ int stride = (multi_mesh->xform_floats + multi_mesh->color_floats) * 4;
glEnableVertexAttribArray(8);
- glVertexAttribPointer(8,4,GL_FLOAT,GL_FALSE,stride,((uint8_t*)NULL)+0);
- glVertexAttribDivisor(8,1);
+ glVertexAttribPointer(8, 4, GL_FLOAT, GL_FALSE, stride, ((uint8_t *)NULL) + 0);
+ glVertexAttribDivisor(8, 1);
glEnableVertexAttribArray(9);
- glVertexAttribPointer(9,4,GL_FLOAT,GL_FALSE,stride,((uint8_t*)NULL)+4*4);
- glVertexAttribDivisor(9,1);
+ glVertexAttribPointer(9, 4, GL_FLOAT, GL_FALSE, stride, ((uint8_t *)NULL) + 4 * 4);
+ glVertexAttribDivisor(9, 1);
int color_ofs;
- if (multi_mesh->transform_format==VS::MULTIMESH_TRANSFORM_3D) {
+ if (multi_mesh->transform_format == VS::MULTIMESH_TRANSFORM_3D) {
glEnableVertexAttribArray(10);
- glVertexAttribPointer(10,4,GL_FLOAT,GL_FALSE,stride,((uint8_t*)NULL)+8*4);
- glVertexAttribDivisor(10,1);
- color_ofs=12*4;
+ glVertexAttribPointer(10, 4, GL_FLOAT, GL_FALSE, stride, ((uint8_t *)NULL) + 8 * 4);
+ glVertexAttribDivisor(10, 1);
+ color_ofs = 12 * 4;
} else {
glDisableVertexAttribArray(10);
- glVertexAttrib4f(10,0,0,1,0);
- color_ofs=8*4;
+ glVertexAttrib4f(10, 0, 0, 1, 0);
+ color_ofs = 8 * 4;
}
- switch(multi_mesh->color_format) {
+ switch (multi_mesh->color_format) {
case VS::MULTIMESH_COLOR_NONE: {
glDisableVertexAttribArray(11);
- glVertexAttrib4f(11,1,1,1,1);
+ glVertexAttrib4f(11, 1, 1, 1, 1);
} break;
case VS::MULTIMESH_COLOR_8BIT: {
glEnableVertexAttribArray(11);
- glVertexAttribPointer(11,4,GL_UNSIGNED_BYTE,GL_TRUE,stride,((uint8_t*)NULL)+color_ofs);
- glVertexAttribDivisor(11,1);
+ glVertexAttribPointer(11, 4, GL_UNSIGNED_BYTE, GL_TRUE, stride, ((uint8_t *)NULL) + color_ofs);
+ glVertexAttribDivisor(11, 1);
} break;
case VS::MULTIMESH_COLOR_FLOAT: {
glEnableVertexAttribArray(11);
- glVertexAttribPointer(11,4,GL_FLOAT,GL_FALSE,stride,((uint8_t*)NULL)+color_ofs);
- glVertexAttribDivisor(11,1);
+ glVertexAttribPointer(11, 4, GL_FLOAT, GL_FALSE, stride, ((uint8_t *)NULL) + color_ofs);
+ glVertexAttribDivisor(11, 1);
} break;
}
} break;
}
-
}
-static const GLenum gl_primitive[]={
+static const GLenum gl_primitive[] = {
GL_POINTS,
GL_LINES,
GL_LINE_STRIP,
@@ -1379,63 +1296,53 @@ static const GLenum gl_primitive[]={
GL_TRIANGLE_FAN
};
-
-
void RasterizerSceneGLES3::_render_geometry(RenderList::Element *e) {
- switch(e->instance->base_type) {
+ switch (e->instance->base_type) {
case VS::INSTANCE_MESH: {
- RasterizerStorageGLES3::Surface *s = static_cast<RasterizerStorageGLES3::Surface*>(e->geometry);
-
- if (s->index_array_len>0) {
+ RasterizerStorageGLES3::Surface *s = static_cast<RasterizerStorageGLES3::Surface *>(e->geometry);
+ if (s->index_array_len > 0) {
- glDrawElements(gl_primitive[s->primitive],s->index_array_len, (s->array_len>=(1<<16))?GL_UNSIGNED_INT:GL_UNSIGNED_SHORT,0);
+ glDrawElements(gl_primitive[s->primitive], s->index_array_len, (s->array_len >= (1 << 16)) ? GL_UNSIGNED_INT : GL_UNSIGNED_SHORT, 0);
- storage->info.render_vertices_count+=s->index_array_len;
+ storage->info.render_vertices_count += s->index_array_len;
} else {
- glDrawArrays(gl_primitive[s->primitive],0,s->array_len);
-
- storage->info.render_vertices_count+=s->array_len;
+ glDrawArrays(gl_primitive[s->primitive], 0, s->array_len);
+ storage->info.render_vertices_count += s->array_len;
}
-
-
-
} break;
case VS::INSTANCE_MULTIMESH: {
- RasterizerStorageGLES3::MultiMesh *multi_mesh = static_cast<RasterizerStorageGLES3::MultiMesh*>(e->owner);
- RasterizerStorageGLES3::Surface *s = static_cast<RasterizerStorageGLES3::Surface*>(e->geometry);
-
- int amount = MAX(multi_mesh->size,multi_mesh->visible_instances);
-
+ RasterizerStorageGLES3::MultiMesh *multi_mesh = static_cast<RasterizerStorageGLES3::MultiMesh *>(e->owner);
+ RasterizerStorageGLES3::Surface *s = static_cast<RasterizerStorageGLES3::Surface *>(e->geometry);
+ int amount = MAX(multi_mesh->size, multi_mesh->visible_instances);
- if (s->index_array_len>0) {
+ if (s->index_array_len > 0) {
- glDrawElementsInstanced(gl_primitive[s->primitive],s->index_array_len, (s->array_len>=(1<<16))?GL_UNSIGNED_INT:GL_UNSIGNED_SHORT,0,amount);
+ glDrawElementsInstanced(gl_primitive[s->primitive], s->index_array_len, (s->array_len >= (1 << 16)) ? GL_UNSIGNED_INT : GL_UNSIGNED_SHORT, 0, amount);
- storage->info.render_vertices_count+=s->index_array_len * amount;
+ storage->info.render_vertices_count += s->index_array_len * amount;
} else {
- glDrawArraysInstanced(gl_primitive[s->primitive],0,s->array_len,amount);
-
- storage->info.render_vertices_count+=s->array_len * amount;
+ glDrawArraysInstanced(gl_primitive[s->primitive], 0, s->array_len, amount);
+ storage->info.render_vertices_count += s->array_len * amount;
}
} break;
case VS::INSTANCE_IMMEDIATE: {
- bool restore_tex=false;
- const RasterizerStorageGLES3::Immediate *im = static_cast<const RasterizerStorageGLES3::Immediate*>( e->geometry );
+ bool restore_tex = false;
+ const RasterizerStorageGLES3::Immediate *im = static_cast<const RasterizerStorageGLES3::Immediate *>(e->geometry);
if (im->building) {
return;
@@ -1444,42 +1351,38 @@ void RasterizerSceneGLES3::_render_geometry(RenderList::Element *e) {
glBindBuffer(GL_ARRAY_BUFFER, state.immediate_buffer);
glBindVertexArray(state.immediate_array);
+ for (const List<RasterizerStorageGLES3::Immediate::Chunk>::Element *E = im->chunks.front(); E; E = E->next()) {
- for(const List< RasterizerStorageGLES3::Immediate::Chunk>::Element *E=im->chunks.front();E;E=E->next()) {
-
- const RasterizerStorageGLES3::Immediate::Chunk &c=E->get();
+ const RasterizerStorageGLES3::Immediate::Chunk &c = E->get();
if (c.vertices.empty()) {
continue;
}
int vertices = c.vertices.size();
- uint32_t buf_ofs=0;
+ uint32_t buf_ofs = 0;
- storage->info.render_vertices_count+=vertices;
+ storage->info.render_vertices_count += vertices;
if (c.texture.is_valid() && storage->texture_owner.owns(c.texture)) {
const RasterizerStorageGLES3::Texture *t = storage->texture_owner.get(c.texture);
glActiveTexture(GL_TEXTURE0);
- glBindTexture(t->target,t->tex_id);
- restore_tex=true;
-
+ glBindTexture(t->target, t->tex_id);
+ restore_tex = true;
} else if (restore_tex) {
glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D,state.current_main_tex);
- restore_tex=false;
+ glBindTexture(GL_TEXTURE_2D, state.current_main_tex);
+ restore_tex = false;
}
-
-
if (!c.normals.empty()) {
glEnableVertexAttribArray(VS::ARRAY_NORMAL);
- glBufferSubData(GL_ARRAY_BUFFER,0,sizeof(Vector3)*vertices,c.normals.ptr());
- glVertexAttribPointer(VS::ARRAY_NORMAL, 3, GL_FLOAT, false,sizeof(Vector3)*vertices,((uint8_t*)NULL)+buf_ofs);
- buf_ofs+=sizeof(Vector3)*vertices;
+ glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(Vector3) * vertices, c.normals.ptr());
+ glVertexAttribPointer(VS::ARRAY_NORMAL, 3, GL_FLOAT, false, sizeof(Vector3) * vertices, ((uint8_t *)NULL) + buf_ofs);
+ buf_ofs += sizeof(Vector3) * vertices;
} else {
@@ -1489,9 +1392,9 @@ void RasterizerSceneGLES3::_render_geometry(RenderList::Element *e) {
if (!c.tangents.empty()) {
glEnableVertexAttribArray(VS::ARRAY_TANGENT);
- glBufferSubData(GL_ARRAY_BUFFER,0,sizeof(Plane)*vertices,c.tangents.ptr());
- glVertexAttribPointer(VS::ARRAY_TANGENT, 4, GL_FLOAT, false,sizeof(Plane)*vertices,((uint8_t*)NULL)+buf_ofs);
- buf_ofs+=sizeof(Plane)*vertices;
+ glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(Plane) * vertices, c.tangents.ptr());
+ glVertexAttribPointer(VS::ARRAY_TANGENT, 4, GL_FLOAT, false, sizeof(Plane) * vertices, ((uint8_t *)NULL) + buf_ofs);
+ buf_ofs += sizeof(Plane) * vertices;
} else {
@@ -1501,23 +1404,22 @@ void RasterizerSceneGLES3::_render_geometry(RenderList::Element *e) {
if (!c.colors.empty()) {
glEnableVertexAttribArray(VS::ARRAY_COLOR);
- glBufferSubData(GL_ARRAY_BUFFER,0,sizeof(Color)*vertices,c.colors.ptr());
- glVertexAttribPointer(VS::ARRAY_COLOR, 4, GL_FLOAT, false,sizeof(Color),((uint8_t*)NULL)+buf_ofs);
- buf_ofs+=sizeof(Color)*vertices;
+ glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(Color) * vertices, c.colors.ptr());
+ glVertexAttribPointer(VS::ARRAY_COLOR, 4, GL_FLOAT, false, sizeof(Color), ((uint8_t *)NULL) + buf_ofs);
+ buf_ofs += sizeof(Color) * vertices;
} else {
glDisableVertexAttribArray(VS::ARRAY_COLOR);
- glVertexAttrib4f(VS::ARRAY_COLOR,1,1,1,1);
+ glVertexAttrib4f(VS::ARRAY_COLOR, 1, 1, 1, 1);
}
-
if (!c.uvs.empty()) {
glEnableVertexAttribArray(VS::ARRAY_TEX_UV);
- glBufferSubData(GL_ARRAY_BUFFER,0,sizeof(Vector2)*vertices,c.uvs.ptr());
- glVertexAttribPointer(VS::ARRAY_TEX_UV, 2, GL_FLOAT, false,sizeof(Vector2),((uint8_t*)NULL)+buf_ofs);
- buf_ofs+=sizeof(Vector2)*vertices;
+ glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(Vector2) * vertices, c.uvs.ptr());
+ glVertexAttribPointer(VS::ARRAY_TEX_UV, 2, GL_FLOAT, false, sizeof(Vector2), ((uint8_t *)NULL) + buf_ofs);
+ buf_ofs += sizeof(Vector2) * vertices;
} else {
@@ -1527,161 +1429,151 @@ void RasterizerSceneGLES3::_render_geometry(RenderList::Element *e) {
if (!c.uvs2.empty()) {
glEnableVertexAttribArray(VS::ARRAY_TEX_UV2);
- glBufferSubData(GL_ARRAY_BUFFER,0,sizeof(Vector2)*vertices,c.uvs2.ptr());
- glVertexAttribPointer(VS::ARRAY_TEX_UV2, 2, GL_FLOAT, false,sizeof(Vector2),((uint8_t*)NULL)+buf_ofs);
- buf_ofs+=sizeof(Vector2)*vertices;
+ glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(Vector2) * vertices, c.uvs2.ptr());
+ glVertexAttribPointer(VS::ARRAY_TEX_UV2, 2, GL_FLOAT, false, sizeof(Vector2), ((uint8_t *)NULL) + buf_ofs);
+ buf_ofs += sizeof(Vector2) * vertices;
} else {
glDisableVertexAttribArray(VS::ARRAY_TEX_UV2);
}
-
glEnableVertexAttribArray(VS::ARRAY_VERTEX);
- glBufferSubData(GL_ARRAY_BUFFER,0,sizeof(Vector3)*vertices,c.vertices.ptr());
- glVertexAttribPointer(VS::ARRAY_VERTEX, 3, GL_FLOAT, false,sizeof(Vector3),((uint8_t*)NULL)+buf_ofs);
- glDrawArrays(gl_primitive[c.primitive],0,c.vertices.size());
-
-
+ glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(Vector3) * vertices, c.vertices.ptr());
+ glVertexAttribPointer(VS::ARRAY_VERTEX, 3, GL_FLOAT, false, sizeof(Vector3), ((uint8_t *)NULL) + buf_ofs);
+ glDrawArrays(gl_primitive[c.primitive], 0, c.vertices.size());
}
-
if (restore_tex) {
glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D,state.current_main_tex);
- restore_tex=false;
+ glBindTexture(GL_TEXTURE_2D, state.current_main_tex);
+ restore_tex = false;
}
} break;
-
}
-
}
-void RasterizerSceneGLES3::_setup_light(RenderList::Element *e,const Transform& p_view_transform) {
+void RasterizerSceneGLES3::_setup_light(RenderList::Element *e, const Transform &p_view_transform) {
int omni_indices[16];
- int omni_count=0;
+ int omni_count = 0;
int spot_indices[16];
- int spot_count=0;
+ int spot_count = 0;
int reflection_indices[16];
- int reflection_count=0;
+ int reflection_count = 0;
- int maxobj = MIN(16,state.max_forward_lights_per_object);
+ int maxobj = MIN(16, state.max_forward_lights_per_object);
- int lc = e->instance->light_instances.size();
+ int lc = e->instance->light_instances.size();
if (lc) {
- const RID* lights=e->instance->light_instances.ptr();
+ const RID *lights = e->instance->light_instances.ptr();
- for(int i=0;i<lc;i++) {
- LightInstance *li=light_instance_owner.getptr(lights[i]);
- if (li->last_pass!=render_pass) //not visible
+ for (int i = 0; i < lc; i++) {
+ LightInstance *li = light_instance_owner.getptr(lights[i]);
+ if (li->last_pass != render_pass) //not visible
continue;
- if (li->light_ptr->type==VS::LIGHT_OMNI) {
- if (omni_count<maxobj && e->instance->layer_mask&li->light_ptr->cull_mask) {
- omni_indices[omni_count++]=li->light_index;
+ if (li->light_ptr->type == VS::LIGHT_OMNI) {
+ if (omni_count < maxobj && e->instance->layer_mask & li->light_ptr->cull_mask) {
+ omni_indices[omni_count++] = li->light_index;
}
}
- if (li->light_ptr->type==VS::LIGHT_SPOT) {
- if (spot_count<maxobj && e->instance->layer_mask&li->light_ptr->cull_mask) {
- spot_indices[spot_count++]=li->light_index;
+ if (li->light_ptr->type == VS::LIGHT_SPOT) {
+ if (spot_count < maxobj && e->instance->layer_mask & li->light_ptr->cull_mask) {
+ spot_indices[spot_count++] = li->light_index;
}
}
}
}
- state.scene_shader.set_uniform(SceneShaderGLES3::OMNI_LIGHT_COUNT,omni_count);
+ state.scene_shader.set_uniform(SceneShaderGLES3::OMNI_LIGHT_COUNT, omni_count);
if (omni_count) {
- glUniform1iv(state.scene_shader.get_uniform(SceneShaderGLES3::OMNI_LIGHT_INDICES),omni_count,omni_indices);
+ glUniform1iv(state.scene_shader.get_uniform(SceneShaderGLES3::OMNI_LIGHT_INDICES), omni_count, omni_indices);
}
- state.scene_shader.set_uniform(SceneShaderGLES3::SPOT_LIGHT_COUNT,spot_count);
+ state.scene_shader.set_uniform(SceneShaderGLES3::SPOT_LIGHT_COUNT, spot_count);
if (spot_count) {
- glUniform1iv(state.scene_shader.get_uniform(SceneShaderGLES3::SPOT_LIGHT_INDICES),spot_count,spot_indices);
+ glUniform1iv(state.scene_shader.get_uniform(SceneShaderGLES3::SPOT_LIGHT_INDICES), spot_count, spot_indices);
}
-
int rc = e->instance->reflection_probe_instances.size();
-
if (rc) {
+ const RID *reflections = e->instance->reflection_probe_instances.ptr();
- const RID* reflections=e->instance->reflection_probe_instances.ptr();
-
- for(int i=0;i<rc;i++) {
- ReflectionProbeInstance *rpi=reflection_probe_instance_owner.getptr(reflections[i]);
- if (rpi->last_pass!=render_pass) //not visible
+ for (int i = 0; i < rc; i++) {
+ ReflectionProbeInstance *rpi = reflection_probe_instance_owner.getptr(reflections[i]);
+ if (rpi->last_pass != render_pass) //not visible
continue;
- if (reflection_count<maxobj) {
- reflection_indices[reflection_count++]=rpi->reflection_index;
+ if (reflection_count < maxobj) {
+ reflection_indices[reflection_count++] = rpi->reflection_index;
}
}
}
- state.scene_shader.set_uniform(SceneShaderGLES3::REFLECTION_COUNT,reflection_count);
+ state.scene_shader.set_uniform(SceneShaderGLES3::REFLECTION_COUNT, reflection_count);
if (reflection_count) {
- glUniform1iv(state.scene_shader.get_uniform(SceneShaderGLES3::REFLECTION_INDICES),reflection_count,reflection_indices);
+ glUniform1iv(state.scene_shader.get_uniform(SceneShaderGLES3::REFLECTION_INDICES), reflection_count, reflection_indices);
}
int gi_probe_count = e->instance->gi_probe_instances.size();
if (gi_probe_count) {
- const RID * ridp = e->instance->gi_probe_instances.ptr();
+ const RID *ridp = e->instance->gi_probe_instances.ptr();
GIProbeInstance *gipi = gi_probe_instance_owner.getptr(ridp[0]);
- glActiveTexture(GL_TEXTURE0+storage->config.max_texture_image_units-6);
- glBindTexture(GL_TEXTURE_3D,gipi->tex_cache);
+ glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 6);
+ glBindTexture(GL_TEXTURE_3D, gipi->tex_cache);
state.scene_shader.set_uniform(SceneShaderGLES3::GI_PROBE_XFORM1, gipi->transform_to_data * p_view_transform);
state.scene_shader.set_uniform(SceneShaderGLES3::GI_PROBE_BOUNDS1, gipi->bounds);
- state.scene_shader.set_uniform(SceneShaderGLES3::GI_PROBE_MULTIPLIER1, gipi->probe?gipi->probe->dynamic_range*gipi->probe->energy:0.0);
- state.scene_shader.set_uniform(SceneShaderGLES3::GI_PROBE_BIAS1, gipi->probe?gipi->probe->bias:0.0);
- state.scene_shader.set_uniform(SceneShaderGLES3::GI_PROBE_BLEND_AMBIENT1, gipi->probe?!gipi->probe->interior:false);
+ state.scene_shader.set_uniform(SceneShaderGLES3::GI_PROBE_MULTIPLIER1, gipi->probe ? gipi->probe->dynamic_range * gipi->probe->energy : 0.0);
+ state.scene_shader.set_uniform(SceneShaderGLES3::GI_PROBE_BIAS1, gipi->probe ? gipi->probe->bias : 0.0);
+ state.scene_shader.set_uniform(SceneShaderGLES3::GI_PROBE_BLEND_AMBIENT1, gipi->probe ? !gipi->probe->interior : false);
state.scene_shader.set_uniform(SceneShaderGLES3::GI_PROBE_CELL_SIZE1, gipi->cell_size_cache);
- if (gi_probe_count>1) {
+ if (gi_probe_count > 1) {
GIProbeInstance *gipi2 = gi_probe_instance_owner.getptr(ridp[1]);
- glActiveTexture(GL_TEXTURE0+storage->config.max_texture_image_units-7);
- glBindTexture(GL_TEXTURE_3D,gipi2->tex_cache);
+ glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 7);
+ glBindTexture(GL_TEXTURE_3D, gipi2->tex_cache);
state.scene_shader.set_uniform(SceneShaderGLES3::GI_PROBE_XFORM2, gipi2->transform_to_data * p_view_transform);
state.scene_shader.set_uniform(SceneShaderGLES3::GI_PROBE_BOUNDS2, gipi2->bounds);
state.scene_shader.set_uniform(SceneShaderGLES3::GI_PROBE_CELL_SIZE2, gipi2->cell_size_cache);
- state.scene_shader.set_uniform(SceneShaderGLES3::GI_PROBE_MULTIPLIER2, gipi2->probe?gipi2->probe->dynamic_range*gipi2->probe->energy:0.0);
- state.scene_shader.set_uniform(SceneShaderGLES3::GI_PROBE_BIAS2, gipi2->probe?gipi2->probe->bias:0.0);
- state.scene_shader.set_uniform(SceneShaderGLES3::GI_PROBE_BLEND_AMBIENT2, gipi2->probe?!gipi2->probe->interior:false);
- state.scene_shader.set_uniform(SceneShaderGLES3::GI_PROBE2_ENABLED, true );
+ state.scene_shader.set_uniform(SceneShaderGLES3::GI_PROBE_MULTIPLIER2, gipi2->probe ? gipi2->probe->dynamic_range * gipi2->probe->energy : 0.0);
+ state.scene_shader.set_uniform(SceneShaderGLES3::GI_PROBE_BIAS2, gipi2->probe ? gipi2->probe->bias : 0.0);
+ state.scene_shader.set_uniform(SceneShaderGLES3::GI_PROBE_BLEND_AMBIENT2, gipi2->probe ? !gipi2->probe->interior : false);
+ state.scene_shader.set_uniform(SceneShaderGLES3::GI_PROBE2_ENABLED, true);
} else {
- state.scene_shader.set_uniform(SceneShaderGLES3::GI_PROBE2_ENABLED, false );
+ state.scene_shader.set_uniform(SceneShaderGLES3::GI_PROBE2_ENABLED, false);
}
}
}
-
-void RasterizerSceneGLES3::_setup_transform(InstanceBase *p_instance,const Transform& p_view_transform,const CameraMatrix& p_projection) {
+void RasterizerSceneGLES3::_setup_transform(InstanceBase *p_instance, const Transform &p_view_transform, const CameraMatrix &p_projection) {
if (p_instance->billboard || p_instance->billboard_y || p_instance->depth_scale) {
- Transform xf=p_instance->transform;
+ Transform xf = p_instance->transform;
if (p_instance->depth_scale) {
if (p_projection.matrix[3][3]) {
//orthogonal matrix, try to do about the same
//with viewport size
//real_t w = Math::abs( 1.0/(2.0*(p_projection.matrix[0][0])) );
- real_t h = Math::abs( 1.0/(2.0*p_projection.matrix[1][1]) );
- float sc = (h*2.0); //consistent with Y-fov
- xf.basis.scale( Vector3(sc,sc,sc));
+ real_t h = Math::abs(1.0 / (2.0 * p_projection.matrix[1][1]));
+ float sc = (h * 2.0); //consistent with Y-fov
+ xf.basis.scale(Vector3(sc, sc, sc));
} else {
//just scale by depth
- real_t sc = Plane(p_view_transform.origin,-p_view_transform.get_basis().get_axis(2)).distance_to(xf.origin);
- xf.basis.scale( Vector3(sc,sc,sc));
+ real_t sc = Plane(p_view_transform.origin, -p_view_transform.get_basis().get_axis(2)).distance_to(xf.origin);
+ xf.basis.scale(Vector3(sc, sc, sc));
}
}
@@ -1701,14 +1593,14 @@ void RasterizerSceneGLES3::_setup_transform(InstanceBase *p_instance,const Trans
if (p_instance->billboard_y && storage->frame.current_rt) {
Vector3 scale = xf.basis.get_scale();
- Vector3 look_at = p_view_transform.get_origin();
+ Vector3 look_at = p_view_transform.get_origin();
look_at.y = 0.0;
Vector3 look_at_norm = look_at.normalized();
if (storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_VFLIP]) {
- xf.set_look_at(xf.origin,xf.origin + look_at_norm, Vector3(0.0, -1.0, 0.0));
+ xf.set_look_at(xf.origin, xf.origin + look_at_norm, Vector3(0.0, -1.0, 0.0));
} else {
- xf.set_look_at(xf.origin,xf.origin + look_at_norm, Vector3(0.0, 1.0, 0.0));
+ xf.set_look_at(xf.origin, xf.origin + look_at_norm, Vector3(0.0, 1.0, 0.0));
}
xf.basis.scale(scale);
}
@@ -1719,22 +1611,20 @@ void RasterizerSceneGLES3::_setup_transform(InstanceBase *p_instance,const Trans
}
}
-void RasterizerSceneGLES3::_set_cull(bool p_front,bool p_reverse_cull) {
+void RasterizerSceneGLES3::_set_cull(bool p_front, bool p_reverse_cull) {
bool front = p_front;
if (p_reverse_cull)
- front=!front;
+ front = !front;
- if (front!=state.cull_front) {
+ if (front != state.cull_front) {
- glCullFace(front?GL_FRONT:GL_BACK);
- state.cull_front=front;
+ glCullFace(front ? GL_FRONT : GL_BACK);
+ state.cull_front = front;
}
}
-
-
-void RasterizerSceneGLES3::_render_list(RenderList::Element **p_elements,int p_element_count,const Transform& p_view_transform,const CameraMatrix& p_projection,GLuint p_base_env,bool p_reverse_cull,bool p_alpha_pass,bool p_shadow,bool p_directional_add,bool p_directional_shadows) {
+void RasterizerSceneGLES3::_render_list(RenderList::Element **p_elements, int p_element_count, const Transform &p_view_transform, const CameraMatrix &p_projection, GLuint p_base_env, bool p_reverse_cull, bool p_alpha_pass, bool p_shadow, bool p_directional_add, bool p_directional_shadows) {
if (storage->frame.current_rt && storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_VFLIP]) {
//p_reverse_cull=!p_reverse_cull;
@@ -1743,287 +1633,257 @@ void RasterizerSceneGLES3::_render_list(RenderList::Element **p_elements,int p_e
glFrontFace(GL_CW);
}
- glBindBufferBase(GL_UNIFORM_BUFFER,0,state.scene_ubo); //bind globals ubo
-
+ glBindBufferBase(GL_UNIFORM_BUFFER, 0, state.scene_ubo); //bind globals ubo
if (!p_shadow && !p_directional_add) {
- glBindBufferBase(GL_UNIFORM_BUFFER,2,state.env_radiance_ubo); //bind environment radiance info
- glActiveTexture(GL_TEXTURE0+storage->config.max_texture_image_units-1);
- glBindTexture(GL_TEXTURE_2D,state.brdf_texture);
+ glBindBufferBase(GL_UNIFORM_BUFFER, 2, state.env_radiance_ubo); //bind environment radiance info
+ glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 1);
+ glBindTexture(GL_TEXTURE_2D, state.brdf_texture);
if (p_base_env) {
- glActiveTexture(GL_TEXTURE0+storage->config.max_texture_image_units-2);
- glBindTexture(GL_TEXTURE_2D,p_base_env);
- state.scene_shader.set_conditional(SceneShaderGLES3::USE_RADIANCE_MAP,true);
+ glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 2);
+ glBindTexture(GL_TEXTURE_2D, p_base_env);
+ state.scene_shader.set_conditional(SceneShaderGLES3::USE_RADIANCE_MAP, true);
} else {
- state.scene_shader.set_conditional(SceneShaderGLES3::USE_RADIANCE_MAP,false);
-
+ state.scene_shader.set_conditional(SceneShaderGLES3::USE_RADIANCE_MAP, false);
}
} else {
- state.scene_shader.set_conditional(SceneShaderGLES3::USE_RADIANCE_MAP,false);
+ state.scene_shader.set_conditional(SceneShaderGLES3::USE_RADIANCE_MAP, false);
}
-
- state.cull_front=false;
+ state.cull_front = false;
glCullFace(GL_BACK);
- state.current_depth_test=true;
+ state.current_depth_test = true;
glEnable(GL_DEPTH_TEST);
- state.scene_shader.set_conditional(SceneShaderGLES3::USE_SKELETON,false);
+ state.scene_shader.set_conditional(SceneShaderGLES3::USE_SKELETON, false);
- state.current_blend_mode=-1;
- state.current_line_width=-1;
- state.current_depth_draw=-1;
+ state.current_blend_mode = -1;
+ state.current_line_width = -1;
+ state.current_depth_draw = -1;
- RasterizerStorageGLES3::Material* prev_material=NULL;
- RasterizerStorageGLES3::Geometry* prev_geometry=NULL;
- RasterizerStorageGLES3::GeometryOwner* prev_owner=NULL;
+ RasterizerStorageGLES3::Material *prev_material = NULL;
+ RasterizerStorageGLES3::Geometry *prev_geometry = NULL;
+ RasterizerStorageGLES3::GeometryOwner *prev_owner = NULL;
VS::InstanceType prev_base_type = VS::INSTANCE_MAX;
- int current_blend_mode=-1;
+ int current_blend_mode = -1;
- int prev_shading=-1;
+ int prev_shading = -1;
RID prev_skeleton;
- state.scene_shader.set_conditional(SceneShaderGLES3::SHADELESS,true); //by default unshaded (easier to set)
+ state.scene_shader.set_conditional(SceneShaderGLES3::SHADELESS, true); //by default unshaded (easier to set)
- bool first=true;
+ bool first = true;
- storage->info.render_object_count+=p_element_count;
+ storage->info.render_object_count += p_element_count;
- for (int i=0;i<p_element_count;i++) {
+ for (int i = 0; i < p_element_count; i++) {
RenderList::Element *e = p_elements[i];
- RasterizerStorageGLES3::Material* material= e->material;
+ RasterizerStorageGLES3::Material *material = e->material;
RID skeleton = e->instance->skeleton;
+ bool rebind = first;
- bool rebind=first;
-
- int shading = (e->sort_key>>RenderList::SORT_KEY_SHADING_SHIFT)&RenderList::SORT_KEY_SHADING_MASK;
+ int shading = (e->sort_key >> RenderList::SORT_KEY_SHADING_SHIFT) & RenderList::SORT_KEY_SHADING_MASK;
if (!p_shadow) {
-
-
if (p_directional_add) {
- if (e->sort_key&RenderList::SORT_KEY_UNSHADED_FLAG || !(e->instance->layer_mask&directional_light->light_ptr->cull_mask)) {
+ if (e->sort_key & RenderList::SORT_KEY_UNSHADED_FLAG || !(e->instance->layer_mask & directional_light->light_ptr->cull_mask)) {
continue;
}
- shading&=~1; //ignore the ignore directional for base pass
+ shading &= ~1; //ignore the ignore directional for base pass
}
- if (shading!=prev_shading) {
-
- if (e->sort_key&RenderList::SORT_KEY_UNSHADED_FLAG) {
-
- state.scene_shader.set_conditional(SceneShaderGLES3::SHADELESS,true);
- state.scene_shader.set_conditional(SceneShaderGLES3::USE_FORWARD_LIGHTING,false);
- state.scene_shader.set_conditional(SceneShaderGLES3::USE_LIGHT_DIRECTIONAL,false);
- state.scene_shader.set_conditional(SceneShaderGLES3::LIGHT_DIRECTIONAL_SHADOW,false);
- state.scene_shader.set_conditional(SceneShaderGLES3::LIGHT_USE_PSSM4,false);
- state.scene_shader.set_conditional(SceneShaderGLES3::LIGHT_USE_PSSM2,false);
- state.scene_shader.set_conditional(SceneShaderGLES3::LIGHT_USE_PSSM_BLEND,false);
- state.scene_shader.set_conditional(SceneShaderGLES3::LIGHT_USE_PSSM_BLEND,false);
- state.scene_shader.set_conditional(SceneShaderGLES3::SHADOW_MODE_PCF_5,false);
- state.scene_shader.set_conditional(SceneShaderGLES3::SHADOW_MODE_PCF_13,false);
- state.scene_shader.set_conditional(SceneShaderGLES3::USE_GI_PROBES,false);
+ if (shading != prev_shading) {
+ if (e->sort_key & RenderList::SORT_KEY_UNSHADED_FLAG) {
+ state.scene_shader.set_conditional(SceneShaderGLES3::SHADELESS, true);
+ state.scene_shader.set_conditional(SceneShaderGLES3::USE_FORWARD_LIGHTING, false);
+ state.scene_shader.set_conditional(SceneShaderGLES3::USE_LIGHT_DIRECTIONAL, false);
+ state.scene_shader.set_conditional(SceneShaderGLES3::LIGHT_DIRECTIONAL_SHADOW, false);
+ state.scene_shader.set_conditional(SceneShaderGLES3::LIGHT_USE_PSSM4, false);
+ state.scene_shader.set_conditional(SceneShaderGLES3::LIGHT_USE_PSSM2, false);
+ state.scene_shader.set_conditional(SceneShaderGLES3::LIGHT_USE_PSSM_BLEND, false);
+ state.scene_shader.set_conditional(SceneShaderGLES3::LIGHT_USE_PSSM_BLEND, false);
+ state.scene_shader.set_conditional(SceneShaderGLES3::SHADOW_MODE_PCF_5, false);
+ state.scene_shader.set_conditional(SceneShaderGLES3::SHADOW_MODE_PCF_13, false);
+ state.scene_shader.set_conditional(SceneShaderGLES3::USE_GI_PROBES, false);
//state.scene_shader.set_conditional(SceneShaderGLES3::SHADELESS,true);
} else {
- state.scene_shader.set_conditional(SceneShaderGLES3::USE_GI_PROBES,e->instance->gi_probe_instances.size()>0);
-
- state.scene_shader.set_conditional(SceneShaderGLES3::SHADELESS,false);
- state.scene_shader.set_conditional(SceneShaderGLES3::USE_FORWARD_LIGHTING,!p_directional_add);
- state.scene_shader.set_conditional(SceneShaderGLES3::USE_LIGHT_DIRECTIONAL,false);
- state.scene_shader.set_conditional(SceneShaderGLES3::LIGHT_DIRECTIONAL_SHADOW,false);
- state.scene_shader.set_conditional(SceneShaderGLES3::LIGHT_USE_PSSM4,false);
- state.scene_shader.set_conditional(SceneShaderGLES3::LIGHT_USE_PSSM2,false);
- state.scene_shader.set_conditional(SceneShaderGLES3::LIGHT_USE_PSSM_BLEND,false);
- state.scene_shader.set_conditional(SceneShaderGLES3::SHADOW_MODE_PCF_5,shadow_filter_mode==SHADOW_FILTER_PCF5);
- state.scene_shader.set_conditional(SceneShaderGLES3::SHADOW_MODE_PCF_13,shadow_filter_mode==SHADOW_FILTER_PCF13);
+ state.scene_shader.set_conditional(SceneShaderGLES3::USE_GI_PROBES, e->instance->gi_probe_instances.size() > 0);
+ state.scene_shader.set_conditional(SceneShaderGLES3::SHADELESS, false);
+ state.scene_shader.set_conditional(SceneShaderGLES3::USE_FORWARD_LIGHTING, !p_directional_add);
+ state.scene_shader.set_conditional(SceneShaderGLES3::USE_LIGHT_DIRECTIONAL, false);
+ state.scene_shader.set_conditional(SceneShaderGLES3::LIGHT_DIRECTIONAL_SHADOW, false);
+ state.scene_shader.set_conditional(SceneShaderGLES3::LIGHT_USE_PSSM4, false);
+ state.scene_shader.set_conditional(SceneShaderGLES3::LIGHT_USE_PSSM2, false);
+ state.scene_shader.set_conditional(SceneShaderGLES3::LIGHT_USE_PSSM_BLEND, false);
+ state.scene_shader.set_conditional(SceneShaderGLES3::SHADOW_MODE_PCF_5, shadow_filter_mode == SHADOW_FILTER_PCF5);
+ state.scene_shader.set_conditional(SceneShaderGLES3::SHADOW_MODE_PCF_13, shadow_filter_mode == SHADOW_FILTER_PCF13);
- if (p_directional_add || (directional_light && (e->sort_key&RenderList::SORT_KEY_NO_DIRECTIONAL_FLAG)==0)) {
- state.scene_shader.set_conditional(SceneShaderGLES3::USE_LIGHT_DIRECTIONAL,true);
+ if (p_directional_add || (directional_light && (e->sort_key & RenderList::SORT_KEY_NO_DIRECTIONAL_FLAG) == 0)) {
+ state.scene_shader.set_conditional(SceneShaderGLES3::USE_LIGHT_DIRECTIONAL, true);
if (p_directional_shadows && directional_light->light_ptr->shadow) {
- state.scene_shader.set_conditional(SceneShaderGLES3::LIGHT_DIRECTIONAL_SHADOW,true);
+ state.scene_shader.set_conditional(SceneShaderGLES3::LIGHT_DIRECTIONAL_SHADOW, true);
- switch(directional_light->light_ptr->directional_shadow_mode) {
- case VS::LIGHT_DIRECTIONAL_SHADOW_ORTHOGONAL: break; //none
+ switch (directional_light->light_ptr->directional_shadow_mode) {
+ case VS::LIGHT_DIRECTIONAL_SHADOW_ORTHOGONAL:
+ break; //none
case VS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_2_SPLITS:
- state.scene_shader.set_conditional(SceneShaderGLES3::LIGHT_USE_PSSM2,true);
- state.scene_shader.set_conditional(SceneShaderGLES3::LIGHT_USE_PSSM_BLEND,directional_light->light_ptr->directional_blend_splits);
- break;
+ state.scene_shader.set_conditional(SceneShaderGLES3::LIGHT_USE_PSSM2, true);
+ state.scene_shader.set_conditional(SceneShaderGLES3::LIGHT_USE_PSSM_BLEND, directional_light->light_ptr->directional_blend_splits);
+ break;
case VS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_4_SPLITS:
- state.scene_shader.set_conditional(SceneShaderGLES3::LIGHT_USE_PSSM4,true);
- state.scene_shader.set_conditional(SceneShaderGLES3::LIGHT_USE_PSSM_BLEND,directional_light->light_ptr->directional_blend_splits);
- break;
+ state.scene_shader.set_conditional(SceneShaderGLES3::LIGHT_USE_PSSM4, true);
+ state.scene_shader.set_conditional(SceneShaderGLES3::LIGHT_USE_PSSM_BLEND, directional_light->light_ptr->directional_blend_splits);
+ break;
}
}
-
}
-
}
-
-
- rebind=true;
+ rebind = true;
}
-
if (p_alpha_pass || p_directional_add) {
int desired_blend_mode;
if (p_directional_add) {
- desired_blend_mode=RasterizerStorageGLES3::Shader::Spatial::BLEND_MODE_ADD;
+ desired_blend_mode = RasterizerStorageGLES3::Shader::Spatial::BLEND_MODE_ADD;
} else {
- desired_blend_mode=material->shader->spatial.blend_mode;
+ desired_blend_mode = material->shader->spatial.blend_mode;
}
- if (desired_blend_mode!=current_blend_mode) {
-
+ if (desired_blend_mode != current_blend_mode) {
- switch(desired_blend_mode) {
+ switch (desired_blend_mode) {
- case RasterizerStorageGLES3::Shader::Spatial::BLEND_MODE_MIX: {
+ case RasterizerStorageGLES3::Shader::Spatial::BLEND_MODE_MIX: {
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);
- }
- else {
+ } else {
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
- } break;
- case RasterizerStorageGLES3::Shader::Spatial::BLEND_MODE_ADD: {
+ } break;
+ case RasterizerStorageGLES3::Shader::Spatial::BLEND_MODE_ADD: {
glBlendEquation(GL_FUNC_ADD);
- glBlendFunc(p_alpha_pass?GL_SRC_ALPHA:GL_ONE,GL_ONE);
+ glBlendFunc(p_alpha_pass ? GL_SRC_ALPHA : GL_ONE, GL_ONE);
- } break;
- case RasterizerStorageGLES3::Shader::Spatial::BLEND_MODE_SUB: {
+ } break;
+ case RasterizerStorageGLES3::Shader::Spatial::BLEND_MODE_SUB: {
glBlendEquation(GL_FUNC_REVERSE_SUBTRACT);
- glBlendFunc(GL_SRC_ALPHA,GL_ONE);
- } break;
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE);
+ } break;
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);
- }
- else {
+ } else {
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
} break;
-
}
- current_blend_mode=desired_blend_mode;
+ current_blend_mode = desired_blend_mode;
}
-
}
-
-
}
- if (prev_skeleton!=skeleton) {
+ if (prev_skeleton != skeleton) {
if (prev_skeleton.is_valid() != skeleton.is_valid()) {
- state.scene_shader.set_conditional(SceneShaderGLES3::USE_SKELETON,skeleton.is_valid());
- rebind=true;
+ state.scene_shader.set_conditional(SceneShaderGLES3::USE_SKELETON, skeleton.is_valid());
+ rebind = true;
}
if (skeleton.is_valid()) {
RasterizerStorageGLES3::Skeleton *sk = storage->skeleton_owner.getornull(skeleton);
if (sk->size) {
- glBindBufferBase(GL_UNIFORM_BUFFER,7,sk->ubo);
+ glBindBufferBase(GL_UNIFORM_BUFFER, 7, sk->ubo);
}
}
}
- if ((prev_base_type==VS::INSTANCE_MULTIMESH) != (e->instance->base_type==VS::INSTANCE_MULTIMESH)) {
- state.scene_shader.set_conditional(SceneShaderGLES3::USE_INSTANCING,e->instance->base_type==VS::INSTANCE_MULTIMESH);
- rebind=true;
+ if ((prev_base_type == VS::INSTANCE_MULTIMESH) != (e->instance->base_type == VS::INSTANCE_MULTIMESH)) {
+ state.scene_shader.set_conditional(SceneShaderGLES3::USE_INSTANCING, e->instance->base_type == VS::INSTANCE_MULTIMESH);
+ rebind = true;
}
- if (material!=prev_material || rebind) {
+ if (material != prev_material || rebind) {
storage->info.render_material_switch_count++;
- rebind = _setup_material(material,p_alpha_pass);
+ rebind = _setup_material(material, p_alpha_pass);
if (rebind) {
storage->info.render_shader_rebind_count++;
}
}
- if (!(e->sort_key&RenderList::SORT_KEY_UNSHADED_FLAG) && !p_directional_add && !p_shadow) {
- _setup_light(e,p_view_transform);
-
+ if (!(e->sort_key & RenderList::SORT_KEY_UNSHADED_FLAG) && !p_directional_add && !p_shadow) {
+ _setup_light(e, p_view_transform);
}
-
- if (e->owner != prev_owner || prev_base_type != e->instance->base_type || prev_geometry!=e->geometry) {
-
+ if (e->owner != prev_owner || prev_base_type != e->instance->base_type || prev_geometry != e->geometry) {
_setup_geometry(e);
storage->info.render_surface_switch_count++;
-
}
- _set_cull(e->sort_key&RenderList::SORT_KEY_MIRROR_FLAG,p_reverse_cull);
+ _set_cull(e->sort_key & RenderList::SORT_KEY_MIRROR_FLAG, p_reverse_cull);
- state.scene_shader.set_uniform(SceneShaderGLES3::NORMAL_MULT, e->instance->mirror?-1.0:1.0);
+ state.scene_shader.set_uniform(SceneShaderGLES3::NORMAL_MULT, e->instance->mirror ? -1.0 : 1.0);
- _setup_transform(e->instance,p_view_transform,p_projection);
+ _setup_transform(e->instance, p_view_transform, p_projection);
_render_geometry(e);
- prev_material=material;
- prev_base_type=e->instance->base_type;
- prev_geometry=e->geometry;
- prev_owner=e->owner;
- prev_shading=shading;
- prev_skeleton=skeleton;
- first=false;
-
+ prev_material = material;
+ prev_base_type = e->instance->base_type;
+ prev_geometry = e->geometry;
+ prev_owner = e->owner;
+ prev_shading = shading;
+ prev_skeleton = skeleton;
+ first = false;
}
-
-
glFrontFace(GL_CW);
glBindVertexArray(0);
- state.scene_shader.set_conditional(SceneShaderGLES3::USE_INSTANCING,false);
- state.scene_shader.set_conditional(SceneShaderGLES3::USE_SKELETON,false);
- state.scene_shader.set_conditional(SceneShaderGLES3::USE_RADIANCE_MAP,false);
- state.scene_shader.set_conditional(SceneShaderGLES3::USE_FORWARD_LIGHTING,false);
- state.scene_shader.set_conditional(SceneShaderGLES3::USE_LIGHT_DIRECTIONAL,false);
- state.scene_shader.set_conditional(SceneShaderGLES3::LIGHT_DIRECTIONAL_SHADOW,false);
- state.scene_shader.set_conditional(SceneShaderGLES3::LIGHT_USE_PSSM4,false);
- state.scene_shader.set_conditional(SceneShaderGLES3::LIGHT_USE_PSSM2,false);
- state.scene_shader.set_conditional(SceneShaderGLES3::LIGHT_USE_PSSM_BLEND,false);
- state.scene_shader.set_conditional(SceneShaderGLES3::SHADELESS,false);
- state.scene_shader.set_conditional(SceneShaderGLES3::SHADOW_MODE_PCF_5,false);
- state.scene_shader.set_conditional(SceneShaderGLES3::SHADOW_MODE_PCF_13,false);
- state.scene_shader.set_conditional(SceneShaderGLES3::USE_GI_PROBES,false);
-
+ state.scene_shader.set_conditional(SceneShaderGLES3::USE_INSTANCING, false);
+ state.scene_shader.set_conditional(SceneShaderGLES3::USE_SKELETON, false);
+ state.scene_shader.set_conditional(SceneShaderGLES3::USE_RADIANCE_MAP, false);
+ state.scene_shader.set_conditional(SceneShaderGLES3::USE_FORWARD_LIGHTING, false);
+ state.scene_shader.set_conditional(SceneShaderGLES3::USE_LIGHT_DIRECTIONAL, false);
+ state.scene_shader.set_conditional(SceneShaderGLES3::LIGHT_DIRECTIONAL_SHADOW, false);
+ state.scene_shader.set_conditional(SceneShaderGLES3::LIGHT_USE_PSSM4, false);
+ state.scene_shader.set_conditional(SceneShaderGLES3::LIGHT_USE_PSSM2, false);
+ state.scene_shader.set_conditional(SceneShaderGLES3::LIGHT_USE_PSSM_BLEND, false);
+ state.scene_shader.set_conditional(SceneShaderGLES3::SHADELESS, false);
+ state.scene_shader.set_conditional(SceneShaderGLES3::SHADOW_MODE_PCF_5, false);
+ state.scene_shader.set_conditional(SceneShaderGLES3::SHADOW_MODE_PCF_13, false);
+ state.scene_shader.set_conditional(SceneShaderGLES3::USE_GI_PROBES, false);
}
+void RasterizerSceneGLES3::_add_geometry(RasterizerStorageGLES3::Geometry *p_geometry, InstanceBase *p_instance, RasterizerStorageGLES3::GeometryOwner *p_owner, int p_material, bool p_shadow) {
-void RasterizerSceneGLES3::_add_geometry( RasterizerStorageGLES3::Geometry* p_geometry, InstanceBase *p_instance, RasterizerStorageGLES3::GeometryOwner *p_owner,int p_material,bool p_shadow) {
-
- RasterizerStorageGLES3::Material *m=NULL;
- RID m_src=p_instance->material_override.is_valid() ? p_instance->material_override :(p_material>=0?p_instance->materials[p_material]:p_geometry->material);
-
+ RasterizerStorageGLES3::Material *m = NULL;
+ RID m_src = p_instance->material_override.is_valid() ? p_instance->material_override : (p_material >= 0 ? p_instance->materials[p_material] : p_geometry->material);
-/*
+ /*
#ifdef DEBUG_ENABLED
if (current_debug==VS::SCENARIO_DEBUG_OVERDRAW) {
m_src=overdraw_material;
@@ -2033,42 +1893,40 @@ void RasterizerSceneGLES3::_add_geometry( RasterizerStorageGLES3::Geometry* p_g
*/
if (m_src.is_valid()) {
- m=storage->material_owner.getornull( m_src );
+ m = storage->material_owner.getornull(m_src);
if (!m->shader) {
- m=NULL;
+ m = NULL;
}
}
if (!m) {
- m=storage->material_owner.getptr( default_material );
+ m = storage->material_owner.getptr(default_material);
}
ERR_FAIL_COND(!m);
-
-
- bool has_base_alpha=(m->shader->spatial.uses_alpha);
- bool has_blend_alpha=m->shader->spatial.blend_mode!=RasterizerStorageGLES3::Shader::Spatial::BLEND_MODE_MIX || m->shader->spatial.ontop;
+ bool has_base_alpha = (m->shader->spatial.uses_alpha);
+ bool has_blend_alpha = m->shader->spatial.blend_mode != RasterizerStorageGLES3::Shader::Spatial::BLEND_MODE_MIX || m->shader->spatial.ontop;
bool has_alpha = has_base_alpha || has_blend_alpha;
bool shadow = false;
bool mirror = p_instance->mirror;
- if (m->shader->spatial.cull_mode==RasterizerStorageGLES3::Shader::Spatial::CULL_MODE_FRONT) {
- mirror=!mirror;
+ if (m->shader->spatial.cull_mode == RasterizerStorageGLES3::Shader::Spatial::CULL_MODE_FRONT) {
+ mirror = !mirror;
}
if (m->shader->spatial.uses_sss) {
- state.used_sss=true;
+ state.used_sss = true;
}
if (p_shadow) {
- if (has_blend_alpha || (has_base_alpha && m->shader->spatial.depth_draw_mode!=RasterizerStorageGLES3::Shader::Spatial::DEPTH_DRAW_ALPHA_PREPASS))
+ if (has_blend_alpha || (has_base_alpha && m->shader->spatial.depth_draw_mode != RasterizerStorageGLES3::Shader::Spatial::DEPTH_DRAW_ALPHA_PREPASS))
return; //bye
- if (!m->shader->spatial.uses_vertex && !m->shader->spatial.uses_discard && m->shader->spatial.depth_draw_mode!=RasterizerStorageGLES3::Shader::Spatial::DEPTH_DRAW_ALPHA_PREPASS) {
+ if (!m->shader->spatial.uses_vertex && !m->shader->spatial.uses_discard && m->shader->spatial.depth_draw_mode != RasterizerStorageGLES3::Shader::Spatial::DEPTH_DRAW_ALPHA_PREPASS) {
//shader does not use discard and does not write a vertex position, use generic material
if (p_instance->cast_shadows == VS::SHADOW_CASTING_SETTING_DOUBLE_SIDED)
m = storage->material_owner.getptr(default_material_twosided);
@@ -2076,47 +1934,43 @@ void RasterizerSceneGLES3::_add_geometry( RasterizerStorageGLES3::Geometry* p_g
m = storage->material_owner.getptr(default_material);
}
- has_alpha=false;
-
+ has_alpha = false;
}
-
-
RenderList::Element *e = has_alpha ? render_list.add_alpha_element() : render_list.add_element();
if (!e)
return;
- e->geometry=p_geometry;
- e->material=m;
- e->instance=p_instance;
- e->owner=p_owner;
- e->sort_key=0;
+ e->geometry = p_geometry;
+ e->material = m;
+ e->instance = p_instance;
+ e->owner = p_owner;
+ e->sort_key = 0;
- if (e->geometry->last_pass!=render_pass) {
- e->geometry->last_pass=render_pass;
- e->geometry->index=current_geometry_index++;
+ if (e->geometry->last_pass != render_pass) {
+ e->geometry->last_pass = render_pass;
+ e->geometry->index = current_geometry_index++;
}
- if (!p_shadow && directional_light && (directional_light->light_ptr->cull_mask&e->instance->layer_mask)==0) {
- e->sort_key|=RenderList::SORT_KEY_NO_DIRECTIONAL_FLAG;
+ if (!p_shadow && directional_light && (directional_light->light_ptr->cull_mask & e->instance->layer_mask) == 0) {
+ e->sort_key |= RenderList::SORT_KEY_NO_DIRECTIONAL_FLAG;
}
- e->sort_key|=uint64_t(e->geometry->index)<<RenderList::SORT_KEY_GEOMETRY_INDEX_SHIFT;
- e->sort_key|=uint64_t(e->instance->base_type)<<RenderList::SORT_KEY_GEOMETRY_TYPE_SHIFT;
+ e->sort_key |= uint64_t(e->geometry->index) << RenderList::SORT_KEY_GEOMETRY_INDEX_SHIFT;
+ e->sort_key |= uint64_t(e->instance->base_type) << RenderList::SORT_KEY_GEOMETRY_TYPE_SHIFT;
if (!p_shadow) {
-
- if (e->material->last_pass!=render_pass) {
- e->material->last_pass=render_pass;
- e->material->index=current_material_index++;
+ if (e->material->last_pass != render_pass) {
+ e->material->last_pass = render_pass;
+ e->material->index = current_material_index++;
}
- e->sort_key|=uint64_t(e->material->index)<<RenderList::SORT_KEY_MATERIAL_INDEX_SHIFT;
- e->sort_key|=uint64_t(e->instance->depth_layer)<<RenderList::SORT_KEY_DEPTH_LAYER_SHIFT;
+ e->sort_key |= uint64_t(e->material->index) << RenderList::SORT_KEY_MATERIAL_INDEX_SHIFT;
+ e->sort_key |= uint64_t(e->instance->depth_layer) << RenderList::SORT_KEY_DEPTH_LAYER_SHIFT;
- if (!has_blend_alpha && has_alpha && m->shader->spatial.depth_draw_mode==RasterizerStorageGLES3::Shader::Spatial::DEPTH_DRAW_ALPHA_PREPASS) {
+ if (!has_blend_alpha && has_alpha && m->shader->spatial.depth_draw_mode == RasterizerStorageGLES3::Shader::Spatial::DEPTH_DRAW_ALPHA_PREPASS) {
//if nothing exists, add this element as opaque too
RenderList::Element *oe = render_list.add_element();
@@ -2124,11 +1978,11 @@ void RasterizerSceneGLES3::_add_geometry( RasterizerStorageGLES3::Geometry* p_g
if (!oe)
return;
- copymem(oe,e,sizeof(RenderList::Element));
+ copymem(oe, e, sizeof(RenderList::Element));
}
if (e->instance->gi_probe_instances.size()) {
- e->sort_key|=RenderList::SORT_KEY_GI_PROBES_FLAG;
+ e->sort_key |= RenderList::SORT_KEY_GI_PROBES_FLAG;
}
}
@@ -2137,20 +1991,19 @@ void RasterizerSceneGLES3::_add_geometry( RasterizerStorageGLES3::Geometry* p_g
e->sort_flags|=RenderList::SORT_FLAG_INSTANCING;
*/
-
if (mirror) {
- e->sort_key|=RenderList::SORT_KEY_MIRROR_FLAG;
+ e->sort_key |= RenderList::SORT_KEY_MIRROR_FLAG;
}
//e->light_type=0xFF; // no lights!
if (shadow || m->shader->spatial.unshaded /*|| current_debug==VS::SCENARIO_DEBUG_SHADELESS*/) {
- e->sort_key|=RenderList::SORT_KEY_UNSHADED_FLAG;
+ e->sort_key |= RenderList::SORT_KEY_UNSHADED_FLAG;
}
}
-void RasterizerSceneGLES3::_draw_skybox(RasterizerStorageGLES3::SkyBox *p_skybox,const CameraMatrix& p_projection,const Transform& p_transform,bool p_vflip,float p_scale) {
+void RasterizerSceneGLES3::_draw_skybox(RasterizerStorageGLES3::SkyBox *p_skybox, const CameraMatrix &p_projection, const Transform &p_transform, bool p_vflip, float p_scale) {
if (!p_skybox)
return;
@@ -2159,16 +2012,15 @@ void RasterizerSceneGLES3::_draw_skybox(RasterizerStorageGLES3::SkyBox *p_skybox
ERR_FAIL_COND(!tex);
glActiveTexture(GL_TEXTURE0);
- glBindTexture(tex->target,tex->tex_id);
-
+ glBindTexture(tex->target, tex->tex_id);
if (storage->config.srgb_decode_supported && tex->srgb && !tex->using_srgb) {
- glTexParameteri(tex->target,_TEXTURE_SRGB_DECODE_EXT,_DECODE_EXT);
- tex->using_srgb=true;
+ glTexParameteri(tex->target, _TEXTURE_SRGB_DECODE_EXT, _DECODE_EXT);
+ tex->using_srgb = true;
#ifdef TOOLS_ENABLED
- if (!(tex->flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)) {
- tex->flags|=VS::TEXTURE_FLAG_CONVERT_TO_LINEAR;
+ if (!(tex->flags & VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)) {
+ tex->flags |= VS::TEXTURE_FLAG_CONVERT_TO_LINEAR;
//notify that texture must be set to linear beforehand, so it works in other platforms when exported
}
#endif
@@ -2179,400 +2031,366 @@ void RasterizerSceneGLES3::_draw_skybox(RasterizerStorageGLES3::SkyBox *p_skybox
glDisable(GL_CULL_FACE);
glDisable(GL_BLEND);
glDepthFunc(GL_LEQUAL);
- glColorMask(1,1,1,1);
+ glColorMask(1, 1, 1, 1);
- float flip_sign = p_vflip?-1:1;
+ float flip_sign = p_vflip ? -1 : 1;
- Vector3 vertices[8]={
- Vector3(-1,-1*flip_sign,1),
- Vector3( 0, 1, 0),
- Vector3( 1,-1*flip_sign,1),
- Vector3( 1, 1, 0),
- Vector3( 1, 1*flip_sign,1),
- Vector3( 1, 0, 0),
- Vector3(-1, 1*flip_sign,1),
- Vector3( 0, 0, 0)
+ Vector3 vertices[8] = {
+ Vector3(-1, -1 * flip_sign, 1),
+ Vector3(0, 1, 0),
+ Vector3(1, -1 * flip_sign, 1),
+ Vector3(1, 1, 0),
+ Vector3(1, 1 * flip_sign, 1),
+ Vector3(1, 0, 0),
+ Vector3(-1, 1 * flip_sign, 1),
+ Vector3(0, 0, 0)
};
-
-
//skybox uv vectors
- float vw,vh,zn;
- p_projection.get_viewport_size(vw,vh);
- zn=p_projection.get_z_near();
+ float vw, vh, zn;
+ p_projection.get_viewport_size(vw, vh);
+ zn = p_projection.get_z_near();
- float scale=p_scale;
+ float scale = p_scale;
- for(int i=0;i<4;i++) {
+ for (int i = 0; i < 4; i++) {
- Vector3 uv=vertices[i*2+1];
- uv.x=(uv.x*2.0-1.0)*vw*scale;
- uv.y=-(uv.y*2.0-1.0)*vh*scale;
- uv.z=-zn;
- vertices[i*2+1] = p_transform.basis.xform(uv).normalized();
- vertices[i*2+1].z = -vertices[i*2+1].z;
+ Vector3 uv = vertices[i * 2 + 1];
+ uv.x = (uv.x * 2.0 - 1.0) * vw * scale;
+ uv.y = -(uv.y * 2.0 - 1.0) * vh * scale;
+ uv.z = -zn;
+ vertices[i * 2 + 1] = p_transform.basis.xform(uv).normalized();
+ vertices[i * 2 + 1].z = -vertices[i * 2 + 1].z;
}
- glBindBuffer(GL_ARRAY_BUFFER,state.skybox_verts);
- glBufferSubData(GL_ARRAY_BUFFER,0,sizeof(Vector3)*8,vertices);
- glBindBuffer(GL_ARRAY_BUFFER,0); //unbind
+ glBindBuffer(GL_ARRAY_BUFFER, state.skybox_verts);
+ glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(Vector3) * 8, vertices);
+ glBindBuffer(GL_ARRAY_BUFFER, 0); //unbind
glBindVertexArray(state.skybox_array);
- storage->shaders.copy.set_conditional(CopyShaderGLES3::USE_CUBEMAP,true);
+ storage->shaders.copy.set_conditional(CopyShaderGLES3::USE_CUBEMAP, true);
storage->shaders.copy.bind();
- glDrawArrays(GL_TRIANGLE_FAN,0,4);
+ glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
glBindVertexArray(0);
- glColorMask(1,1,1,1);
-
- storage->shaders.copy.set_conditional(CopyShaderGLES3::USE_CUBEMAP,false);
+ glColorMask(1, 1, 1, 1);
+ storage->shaders.copy.set_conditional(CopyShaderGLES3::USE_CUBEMAP, false);
}
-
-void RasterizerSceneGLES3::_setup_environment(Environment *env,const CameraMatrix& p_cam_projection,const Transform& p_cam_transform) {
-
+void RasterizerSceneGLES3::_setup_environment(Environment *env, const CameraMatrix &p_cam_projection, const Transform &p_cam_transform) {
//store camera into ubo
- store_camera(p_cam_projection,state.ubo_data.projection_matrix);
- store_transform(p_cam_transform,state.ubo_data.camera_matrix);
- store_transform(p_cam_transform.affine_inverse(),state.ubo_data.camera_inverse_matrix);
+ store_camera(p_cam_projection, state.ubo_data.projection_matrix);
+ store_transform(p_cam_transform, state.ubo_data.camera_matrix);
+ store_transform(p_cam_transform.affine_inverse(), state.ubo_data.camera_inverse_matrix);
//time global variables
- for(int i=0;i<4;i++) {
- state.ubo_data.time[i]=storage->frame.time[i];
+ for (int i = 0; i < 4; i++) {
+ state.ubo_data.time[i] = storage->frame.time[i];
}
//bg and ambient
if (env) {
- state.ubo_data.bg_energy=env->bg_energy;
- state.ubo_data.ambient_energy=env->ambient_energy;
+ state.ubo_data.bg_energy = env->bg_energy;
+ state.ubo_data.ambient_energy = env->ambient_energy;
Color linear_ambient_color = env->ambient_color.to_linear();
- state.ubo_data.ambient_light_color[0]=linear_ambient_color.r;
- state.ubo_data.ambient_light_color[1]=linear_ambient_color.g;
- state.ubo_data.ambient_light_color[2]=linear_ambient_color.b;
- state.ubo_data.ambient_light_color[3]=linear_ambient_color.a;
+ state.ubo_data.ambient_light_color[0] = linear_ambient_color.r;
+ state.ubo_data.ambient_light_color[1] = linear_ambient_color.g;
+ state.ubo_data.ambient_light_color[2] = linear_ambient_color.b;
+ state.ubo_data.ambient_light_color[3] = linear_ambient_color.a;
Color bg_color;
- switch(env->bg_mode) {
+ switch (env->bg_mode) {
case VS::ENV_BG_CLEAR_COLOR: {
- bg_color=storage->frame.clear_request_color.to_linear();
+ bg_color = storage->frame.clear_request_color.to_linear();
} break;
case VS::ENV_BG_COLOR: {
- bg_color=env->bg_color.to_linear();
+ bg_color = env->bg_color.to_linear();
} break;
default: {
- bg_color=Color(0,0,0,1);
+ bg_color = Color(0, 0, 0, 1);
} break;
}
- state.ubo_data.bg_color[0]=bg_color.r;
- state.ubo_data.bg_color[1]=bg_color.g;
- state.ubo_data.bg_color[2]=bg_color.b;
- state.ubo_data.bg_color[3]=bg_color.a;
+ state.ubo_data.bg_color[0] = bg_color.r;
+ state.ubo_data.bg_color[1] = bg_color.g;
+ state.ubo_data.bg_color[2] = bg_color.b;
+ state.ubo_data.bg_color[3] = bg_color.a;
- state.env_radiance_data.ambient_contribution=env->ambient_skybox_contribution;
- state.ubo_data.ambient_occlusion_affect_light=env->ssao_light_affect;
+ state.env_radiance_data.ambient_contribution = env->ambient_skybox_contribution;
+ state.ubo_data.ambient_occlusion_affect_light = env->ssao_light_affect;
} else {
- state.ubo_data.bg_energy=1.0;
- state.ubo_data.ambient_energy=1.0;
+ state.ubo_data.bg_energy = 1.0;
+ state.ubo_data.ambient_energy = 1.0;
//use from clear color instead, since there is no ambient
Color linear_ambient_color = storage->frame.clear_request_color.to_linear();
- state.ubo_data.ambient_light_color[0]=linear_ambient_color.r;
- state.ubo_data.ambient_light_color[1]=linear_ambient_color.g;
- state.ubo_data.ambient_light_color[2]=linear_ambient_color.b;
- state.ubo_data.ambient_light_color[3]=linear_ambient_color.a;
-
- state.ubo_data.bg_color[0]=linear_ambient_color.r;
- state.ubo_data.bg_color[1]=linear_ambient_color.g;
- state.ubo_data.bg_color[2]=linear_ambient_color.b;
- state.ubo_data.bg_color[3]=linear_ambient_color.a;
-
- state.env_radiance_data.ambient_contribution=0;
- state.ubo_data.ambient_occlusion_affect_light=0;
-
+ state.ubo_data.ambient_light_color[0] = linear_ambient_color.r;
+ state.ubo_data.ambient_light_color[1] = linear_ambient_color.g;
+ state.ubo_data.ambient_light_color[2] = linear_ambient_color.b;
+ state.ubo_data.ambient_light_color[3] = linear_ambient_color.a;
+
+ state.ubo_data.bg_color[0] = linear_ambient_color.r;
+ state.ubo_data.bg_color[1] = linear_ambient_color.g;
+ state.ubo_data.bg_color[2] = linear_ambient_color.b;
+ state.ubo_data.bg_color[3] = linear_ambient_color.a;
+
+ state.env_radiance_data.ambient_contribution = 0;
+ state.ubo_data.ambient_occlusion_affect_light = 0;
}
{
//directional shadow
- state.ubo_data.shadow_directional_pixel_size[0]=1.0/directional_shadow.size;
- state.ubo_data.shadow_directional_pixel_size[1]=1.0/directional_shadow.size;
+ state.ubo_data.shadow_directional_pixel_size[0] = 1.0 / directional_shadow.size;
+ state.ubo_data.shadow_directional_pixel_size[1] = 1.0 / directional_shadow.size;
- glActiveTexture(GL_TEXTURE0+storage->config.max_texture_image_units-4);
- glBindTexture(GL_TEXTURE_2D,directional_shadow.depth);
+ glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 4);
+ glBindTexture(GL_TEXTURE_2D, directional_shadow.depth);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LESS);
}
-
-
glBindBuffer(GL_UNIFORM_BUFFER, state.scene_ubo);
- glBufferSubData(GL_UNIFORM_BUFFER, 0,sizeof(State::SceneDataUBO), &state.ubo_data);
+ glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(State::SceneDataUBO), &state.ubo_data);
glBindBuffer(GL_UNIFORM_BUFFER, 0);
//fill up environment
- store_transform(p_cam_transform,state.env_radiance_data.transform);
-
+ store_transform(p_cam_transform, state.env_radiance_data.transform);
glBindBuffer(GL_UNIFORM_BUFFER, state.env_radiance_ubo);
- glBufferSubData(GL_UNIFORM_BUFFER, 0,sizeof(State::EnvironmentRadianceUBO), &state.env_radiance_data);
+ glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(State::EnvironmentRadianceUBO), &state.env_radiance_data);
glBindBuffer(GL_UNIFORM_BUFFER, 0);
-
}
-void RasterizerSceneGLES3::_setup_directional_light(int p_index,const Transform& p_camera_inverse_transform,bool p_use_shadows) {
+void RasterizerSceneGLES3::_setup_directional_light(int p_index, const Transform &p_camera_inverse_transform, bool p_use_shadows) {
LightInstance *li = directional_lights[p_index];
LightDataUBO ubo_data; //used for filling
- float sign = li->light_ptr->negative?-1:1;
+ float sign = li->light_ptr->negative ? -1 : 1;
Color linear_col = li->light_ptr->color.to_linear();
- ubo_data.light_color_energy[0]=linear_col.r*sign*li->light_ptr->param[VS::LIGHT_PARAM_ENERGY];
- ubo_data.light_color_energy[1]=linear_col.g*sign*li->light_ptr->param[VS::LIGHT_PARAM_ENERGY];
- ubo_data.light_color_energy[2]=linear_col.b*sign*li->light_ptr->param[VS::LIGHT_PARAM_ENERGY];
- ubo_data.light_color_energy[3]=0;
+ ubo_data.light_color_energy[0] = linear_col.r * sign * li->light_ptr->param[VS::LIGHT_PARAM_ENERGY];
+ ubo_data.light_color_energy[1] = linear_col.g * sign * li->light_ptr->param[VS::LIGHT_PARAM_ENERGY];
+ ubo_data.light_color_energy[2] = linear_col.b * sign * li->light_ptr->param[VS::LIGHT_PARAM_ENERGY];
+ ubo_data.light_color_energy[3] = 0;
//omni, keep at 0
- ubo_data.light_pos_inv_radius[0]=0.0;
- ubo_data.light_pos_inv_radius[1]=0.0;
- ubo_data.light_pos_inv_radius[2]=0.0;
- ubo_data.light_pos_inv_radius[3]=0.0;
-
- Vector3 direction = p_camera_inverse_transform.basis.xform(li->transform.basis.xform(Vector3(0,0,-1))).normalized();
- ubo_data.light_direction_attenuation[0]=direction.x;
- ubo_data.light_direction_attenuation[1]=direction.y;
- ubo_data.light_direction_attenuation[2]=direction.z;
- ubo_data.light_direction_attenuation[3]=1.0;
-
- ubo_data.light_params[0]=0;
- ubo_data.light_params[1]=li->light_ptr->param[VS::LIGHT_PARAM_SPECULAR];
- ubo_data.light_params[2]=0;
- ubo_data.light_params[3]=0;
+ ubo_data.light_pos_inv_radius[0] = 0.0;
+ ubo_data.light_pos_inv_radius[1] = 0.0;
+ ubo_data.light_pos_inv_radius[2] = 0.0;
+ ubo_data.light_pos_inv_radius[3] = 0.0;
+
+ Vector3 direction = p_camera_inverse_transform.basis.xform(li->transform.basis.xform(Vector3(0, 0, -1))).normalized();
+ ubo_data.light_direction_attenuation[0] = direction.x;
+ ubo_data.light_direction_attenuation[1] = direction.y;
+ ubo_data.light_direction_attenuation[2] = direction.z;
+ ubo_data.light_direction_attenuation[3] = 1.0;
+
+ ubo_data.light_params[0] = 0;
+ ubo_data.light_params[1] = li->light_ptr->param[VS::LIGHT_PARAM_SPECULAR];
+ ubo_data.light_params[2] = 0;
+ ubo_data.light_params[3] = 0;
Color shadow_color = li->light_ptr->shadow_color.to_linear();
- ubo_data.light_shadow_color_contact[0]=shadow_color.r;
- ubo_data.light_shadow_color_contact[1]=shadow_color.g;
- ubo_data.light_shadow_color_contact[2]=shadow_color.b;
- ubo_data.light_shadow_color_contact[3]=li->light_ptr->param[VS::LIGHT_PARAM_CONTACT_SHADOW_SIZE];
-
+ ubo_data.light_shadow_color_contact[0] = shadow_color.r;
+ ubo_data.light_shadow_color_contact[1] = shadow_color.g;
+ ubo_data.light_shadow_color_contact[2] = shadow_color.b;
+ ubo_data.light_shadow_color_contact[3] = li->light_ptr->param[VS::LIGHT_PARAM_CONTACT_SHADOW_SIZE];
if (p_use_shadows && li->light_ptr->shadow) {
- int shadow_count=0;
+ int shadow_count = 0;
- switch(li->light_ptr->directional_shadow_mode) {
+ switch (li->light_ptr->directional_shadow_mode) {
case VS::LIGHT_DIRECTIONAL_SHADOW_ORTHOGONAL: {
- shadow_count=1;
+ shadow_count = 1;
} break;
case VS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_2_SPLITS: {
- shadow_count=2;
+ shadow_count = 2;
} break;
case VS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_4_SPLITS: {
- shadow_count=4;
+ shadow_count = 4;
} break;
-
}
- for(int j=0;j<shadow_count;j++) {
+ for (int j = 0; j < shadow_count; j++) {
+ uint32_t x = li->directional_rect.pos.x;
+ uint32_t y = li->directional_rect.pos.y;
+ uint32_t width = li->directional_rect.size.x;
+ uint32_t height = li->directional_rect.size.y;
- uint32_t x=li->directional_rect.pos.x;
- uint32_t y=li->directional_rect.pos.y;
- uint32_t width=li->directional_rect.size.x;
- uint32_t height=li->directional_rect.size.y;
+ if (li->light_ptr->directional_shadow_mode == VS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_4_SPLITS) {
+ width /= 2;
+ height /= 2;
+ if (j == 0) {
- if (li->light_ptr->directional_shadow_mode==VS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_4_SPLITS) {
-
-
- width/=2;
- height/=2;
-
- if (j==0) {
-
- } else if (j==1) {
- x+=width;
- } else if (j==2) {
- y+=height;
- } else if (j==3) {
- x+=width;
- y+=height;
-
+ } else if (j == 1) {
+ x += width;
+ } else if (j == 2) {
+ y += height;
+ } else if (j == 3) {
+ x += width;
+ y += height;
}
+ } else if (li->light_ptr->directional_shadow_mode == VS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_2_SPLITS) {
+ height /= 2;
- } else if (li->light_ptr->directional_shadow_mode==VS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_2_SPLITS) {
-
- height/=2;
-
- if (j==0) {
+ if (j == 0) {
} else {
- y+=height;
+ y += height;
}
-
}
- ubo_data.shadow_split_offsets[j]=1.0/li->shadow_transform[j].split;
+ ubo_data.shadow_split_offsets[j] = 1.0 / li->shadow_transform[j].split;
Transform modelview = (p_camera_inverse_transform * li->shadow_transform[j].transform).inverse();
CameraMatrix bias;
bias.set_light_bias();
CameraMatrix rectm;
- Rect2 atlas_rect = Rect2(float(x)/directional_shadow.size,float(y)/directional_shadow.size,float(width)/directional_shadow.size,float(height)/directional_shadow.size);
+ Rect2 atlas_rect = Rect2(float(x) / directional_shadow.size, float(y) / directional_shadow.size, float(width) / directional_shadow.size, float(height) / directional_shadow.size);
rectm.set_light_atlas_rect(atlas_rect);
-
CameraMatrix shadow_mtx = rectm * bias * li->shadow_transform[j].camera * modelview;
- store_camera(shadow_mtx,&ubo_data.shadow_matrix1[16*j]);
-
- ubo_data.light_clamp[0]=atlas_rect.pos.x;
- ubo_data.light_clamp[1]=atlas_rect.pos.y;
- ubo_data.light_clamp[2]=atlas_rect.size.x;
- ubo_data.light_clamp[3]=atlas_rect.size.y;
+ store_camera(shadow_mtx, &ubo_data.shadow_matrix1[16 * j]);
+ ubo_data.light_clamp[0] = atlas_rect.pos.x;
+ ubo_data.light_clamp[1] = atlas_rect.pos.y;
+ ubo_data.light_clamp[2] = atlas_rect.size.x;
+ ubo_data.light_clamp[3] = atlas_rect.size.y;
}
-
}
glBindBuffer(GL_UNIFORM_BUFFER, state.directional_ubo);
glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(LightDataUBO), &ubo_data);
glBindBuffer(GL_UNIFORM_BUFFER, 0);
- directional_light=li;
-
- glBindBufferBase(GL_UNIFORM_BUFFER,3,state.directional_ubo);
+ directional_light = li;
+ glBindBufferBase(GL_UNIFORM_BUFFER, 3, state.directional_ubo);
}
-void RasterizerSceneGLES3::_setup_lights(RID *p_light_cull_result,int p_light_cull_count,const Transform& p_camera_inverse_transform,const CameraMatrix& p_camera_projection,RID p_shadow_atlas) {
+void RasterizerSceneGLES3::_setup_lights(RID *p_light_cull_result, int p_light_cull_count, const Transform &p_camera_inverse_transform, const CameraMatrix &p_camera_projection, RID p_shadow_atlas) {
+ state.omni_light_count = 0;
+ state.spot_light_count = 0;
+ state.directional_light_count = 0;
- state.omni_light_count=0;
- state.spot_light_count=0;
- state.directional_light_count=0;
-
- directional_light=NULL;
+ directional_light = NULL;
ShadowAtlas *shadow_atlas = shadow_atlas_owner.getornull(p_shadow_atlas);
+ for (int i = 0; i < p_light_cull_count; i++) {
- for(int i=0;i<p_light_cull_count;i++) {
-
- ERR_BREAK( i>=RenderList::MAX_LIGHTS );
+ ERR_BREAK(i >= RenderList::MAX_LIGHTS);
LightInstance *li = light_instance_owner.getptr(p_light_cull_result[i]);
LightDataUBO ubo_data; //used for filling
- switch(li->light_ptr->type) {
+ switch (li->light_ptr->type) {
case VS::LIGHT_DIRECTIONAL: {
- if (state.directional_light_count<RenderList::MAX_DIRECTIONAL_LIGHTS) {
- directional_lights[state.directional_light_count++]=li;
+ if (state.directional_light_count < RenderList::MAX_DIRECTIONAL_LIGHTS) {
+ directional_lights[state.directional_light_count++] = li;
}
-
} break;
case VS::LIGHT_OMNI: {
- float sign = li->light_ptr->negative?-1:1;
+ float sign = li->light_ptr->negative ? -1 : 1;
Color linear_col = li->light_ptr->color.to_linear();
- ubo_data.light_color_energy[0]=linear_col.r*sign*li->light_ptr->param[VS::LIGHT_PARAM_ENERGY];
- ubo_data.light_color_energy[1]=linear_col.g*sign*li->light_ptr->param[VS::LIGHT_PARAM_ENERGY];
- ubo_data.light_color_energy[2]=linear_col.b*sign*li->light_ptr->param[VS::LIGHT_PARAM_ENERGY];
- ubo_data.light_color_energy[3]=0;
-
+ ubo_data.light_color_energy[0] = linear_col.r * sign * li->light_ptr->param[VS::LIGHT_PARAM_ENERGY];
+ ubo_data.light_color_energy[1] = linear_col.g * sign * li->light_ptr->param[VS::LIGHT_PARAM_ENERGY];
+ ubo_data.light_color_energy[2] = linear_col.b * sign * li->light_ptr->param[VS::LIGHT_PARAM_ENERGY];
+ ubo_data.light_color_energy[3] = 0;
Vector3 pos = p_camera_inverse_transform.xform(li->transform.origin);
//directional, keep at 0
- ubo_data.light_pos_inv_radius[0]=pos.x;
- ubo_data.light_pos_inv_radius[1]=pos.y;
- ubo_data.light_pos_inv_radius[2]=pos.z;
- ubo_data.light_pos_inv_radius[3]=1.0/MAX(0.001,li->light_ptr->param[VS::LIGHT_PARAM_RANGE]);
+ ubo_data.light_pos_inv_radius[0] = pos.x;
+ ubo_data.light_pos_inv_radius[1] = pos.y;
+ ubo_data.light_pos_inv_radius[2] = pos.z;
+ ubo_data.light_pos_inv_radius[3] = 1.0 / MAX(0.001, li->light_ptr->param[VS::LIGHT_PARAM_RANGE]);
- ubo_data.light_direction_attenuation[0]=0;
- ubo_data.light_direction_attenuation[1]=0;
- ubo_data.light_direction_attenuation[2]=0;
- ubo_data.light_direction_attenuation[3]=li->light_ptr->param[VS::LIGHT_PARAM_ATTENUATION];
+ ubo_data.light_direction_attenuation[0] = 0;
+ ubo_data.light_direction_attenuation[1] = 0;
+ ubo_data.light_direction_attenuation[2] = 0;
+ ubo_data.light_direction_attenuation[3] = li->light_ptr->param[VS::LIGHT_PARAM_ATTENUATION];
- ubo_data.light_params[0]=0;
- ubo_data.light_params[1]=0;
- ubo_data.light_params[2]=li->light_ptr->param[VS::LIGHT_PARAM_SPECULAR];
- ubo_data.light_params[3]=0;
+ ubo_data.light_params[0] = 0;
+ ubo_data.light_params[1] = 0;
+ ubo_data.light_params[2] = li->light_ptr->param[VS::LIGHT_PARAM_SPECULAR];
+ ubo_data.light_params[3] = 0;
Color shadow_color = li->light_ptr->shadow_color.to_linear();
- ubo_data.light_shadow_color_contact[0]=shadow_color.r;
- ubo_data.light_shadow_color_contact[1]=shadow_color.g;
- ubo_data.light_shadow_color_contact[2]=shadow_color.b;
- ubo_data.light_shadow_color_contact[3]=li->light_ptr->param[VS::LIGHT_PARAM_CONTACT_SHADOW_SIZE];
+ ubo_data.light_shadow_color_contact[0] = shadow_color.r;
+ ubo_data.light_shadow_color_contact[1] = shadow_color.g;
+ ubo_data.light_shadow_color_contact[2] = shadow_color.b;
+ ubo_data.light_shadow_color_contact[3] = li->light_ptr->param[VS::LIGHT_PARAM_CONTACT_SHADOW_SIZE];
if (li->light_ptr->shadow && shadow_atlas && shadow_atlas->shadow_owners.has(li->self)) {
// fill in the shadow information
uint32_t key = shadow_atlas->shadow_owners[li->self];
- uint32_t quadrant = (key >> ShadowAtlas::QUADRANT_SHIFT)&0x3;
+ uint32_t quadrant = (key >> ShadowAtlas::QUADRANT_SHIFT) & 0x3;
uint32_t shadow = key & ShadowAtlas::SHADOW_INDEX_MASK;
- ERR_CONTINUE(shadow>=shadow_atlas->quadrants[quadrant].shadows.size());
+ ERR_CONTINUE(shadow >= shadow_atlas->quadrants[quadrant].shadows.size());
uint32_t atlas_size = shadow_atlas->size;
- uint32_t quadrant_size = atlas_size>>1;
+ uint32_t quadrant_size = atlas_size >> 1;
- uint32_t x=(quadrant&1)*quadrant_size;
- uint32_t y=(quadrant>>1)*quadrant_size;
+ uint32_t x = (quadrant & 1) * quadrant_size;
+ uint32_t y = (quadrant >> 1) * quadrant_size;
uint32_t shadow_size = (quadrant_size / shadow_atlas->quadrants[quadrant].subdivision);
- x+=(shadow % shadow_atlas->quadrants[quadrant].subdivision) * shadow_size;
- y+=(shadow / shadow_atlas->quadrants[quadrant].subdivision) * shadow_size;
-
- uint32_t width=shadow_size;
- uint32_t height=shadow_size;
+ x += (shadow % shadow_atlas->quadrants[quadrant].subdivision) * shadow_size;
+ y += (shadow / shadow_atlas->quadrants[quadrant].subdivision) * shadow_size;
+ uint32_t width = shadow_size;
+ uint32_t height = shadow_size;
- if (li->light_ptr->omni_shadow_detail==VS::LIGHT_OMNI_SHADOW_DETAIL_HORIZONTAL) {
+ if (li->light_ptr->omni_shadow_detail == VS::LIGHT_OMNI_SHADOW_DETAIL_HORIZONTAL) {
- height/=2;
+ height /= 2;
} else {
- width/=2;
-
+ width /= 2;
}
Transform proj = (p_camera_inverse_transform * li->transform).inverse();
- store_transform(proj,ubo_data.shadow_matrix1);
-
- ubo_data.light_params[3]=1.0; //means it has shadow
- ubo_data.light_clamp[0]=float(x)/atlas_size;
- ubo_data.light_clamp[1]=float(y)/atlas_size;
- ubo_data.light_clamp[2]=float(width)/atlas_size;
- ubo_data.light_clamp[3]=float(height)/atlas_size;
+ store_transform(proj, ubo_data.shadow_matrix1);
+ ubo_data.light_params[3] = 1.0; //means it has shadow
+ ubo_data.light_clamp[0] = float(x) / atlas_size;
+ ubo_data.light_clamp[1] = float(y) / atlas_size;
+ ubo_data.light_clamp[2] = float(width) / atlas_size;
+ ubo_data.light_clamp[3] = float(height) / atlas_size;
}
-
- li->light_index=state.omni_light_count;
- copymem(&state.omni_array_tmp[li->light_index*state.ubo_light_size],&ubo_data,state.ubo_light_size);
+ li->light_index = state.omni_light_count;
+ copymem(&state.omni_array_tmp[li->light_index * state.ubo_light_size], &ubo_data, state.ubo_light_size);
state.omni_light_count++;
-
-
#if 0
if (li->light_ptr->shadow_enabled) {
li->shadow_projection[0] = Transform(camera_transform_inverse * li->transform).inverse();
@@ -2582,69 +2400,69 @@ void RasterizerSceneGLES3::_setup_lights(RID *p_light_cull_result,int p_light_cu
} break;
case VS::LIGHT_SPOT: {
- float sign = li->light_ptr->negative?-1:1;
+ float sign = li->light_ptr->negative ? -1 : 1;
Color linear_col = li->light_ptr->color.to_linear();
- ubo_data.light_color_energy[0]=linear_col.r*sign*li->light_ptr->param[VS::LIGHT_PARAM_ENERGY];
- ubo_data.light_color_energy[1]=linear_col.g*sign*li->light_ptr->param[VS::LIGHT_PARAM_ENERGY];
- ubo_data.light_color_energy[2]=linear_col.b*sign*li->light_ptr->param[VS::LIGHT_PARAM_ENERGY];
- ubo_data.light_color_energy[3]=0;
+ ubo_data.light_color_energy[0] = linear_col.r * sign * li->light_ptr->param[VS::LIGHT_PARAM_ENERGY];
+ ubo_data.light_color_energy[1] = linear_col.g * sign * li->light_ptr->param[VS::LIGHT_PARAM_ENERGY];
+ ubo_data.light_color_energy[2] = linear_col.b * sign * li->light_ptr->param[VS::LIGHT_PARAM_ENERGY];
+ ubo_data.light_color_energy[3] = 0;
Vector3 pos = p_camera_inverse_transform.xform(li->transform.origin);
//directional, keep at 0
- ubo_data.light_pos_inv_radius[0]=pos.x;
- ubo_data.light_pos_inv_radius[1]=pos.y;
- ubo_data.light_pos_inv_radius[2]=pos.z;
- ubo_data.light_pos_inv_radius[3]=1.0/MAX(0.001,li->light_ptr->param[VS::LIGHT_PARAM_RANGE]);
-
- Vector3 direction = p_camera_inverse_transform.basis.xform(li->transform.basis.xform(Vector3(0,0,-1))).normalized();
- ubo_data.light_direction_attenuation[0]=direction.x;
- ubo_data.light_direction_attenuation[1]=direction.y;
- ubo_data.light_direction_attenuation[2]=direction.z;
- ubo_data.light_direction_attenuation[3]=li->light_ptr->param[VS::LIGHT_PARAM_ATTENUATION];
-
- ubo_data.light_params[0]=li->light_ptr->param[VS::LIGHT_PARAM_SPOT_ATTENUATION];
- ubo_data.light_params[1]=Math::cos(Math::deg2rad(li->light_ptr->param[VS::LIGHT_PARAM_SPOT_ANGLE]));
- ubo_data.light_params[2]=li->light_ptr->param[VS::LIGHT_PARAM_SPECULAR];
- ubo_data.light_params[3]=0;
+ ubo_data.light_pos_inv_radius[0] = pos.x;
+ ubo_data.light_pos_inv_radius[1] = pos.y;
+ ubo_data.light_pos_inv_radius[2] = pos.z;
+ ubo_data.light_pos_inv_radius[3] = 1.0 / MAX(0.001, li->light_ptr->param[VS::LIGHT_PARAM_RANGE]);
+
+ Vector3 direction = p_camera_inverse_transform.basis.xform(li->transform.basis.xform(Vector3(0, 0, -1))).normalized();
+ ubo_data.light_direction_attenuation[0] = direction.x;
+ ubo_data.light_direction_attenuation[1] = direction.y;
+ ubo_data.light_direction_attenuation[2] = direction.z;
+ ubo_data.light_direction_attenuation[3] = li->light_ptr->param[VS::LIGHT_PARAM_ATTENUATION];
+
+ ubo_data.light_params[0] = li->light_ptr->param[VS::LIGHT_PARAM_SPOT_ATTENUATION];
+ ubo_data.light_params[1] = Math::cos(Math::deg2rad(li->light_ptr->param[VS::LIGHT_PARAM_SPOT_ANGLE]));
+ ubo_data.light_params[2] = li->light_ptr->param[VS::LIGHT_PARAM_SPECULAR];
+ ubo_data.light_params[3] = 0;
Color shadow_color = li->light_ptr->shadow_color.to_linear();
- ubo_data.light_shadow_color_contact[0]=shadow_color.r;
- ubo_data.light_shadow_color_contact[1]=shadow_color.g;
- ubo_data.light_shadow_color_contact[2]=shadow_color.b;
- ubo_data.light_shadow_color_contact[3]=li->light_ptr->param[VS::LIGHT_PARAM_CONTACT_SHADOW_SIZE];
+ ubo_data.light_shadow_color_contact[0] = shadow_color.r;
+ ubo_data.light_shadow_color_contact[1] = shadow_color.g;
+ ubo_data.light_shadow_color_contact[2] = shadow_color.b;
+ ubo_data.light_shadow_color_contact[3] = li->light_ptr->param[VS::LIGHT_PARAM_CONTACT_SHADOW_SIZE];
if (li->light_ptr->shadow && shadow_atlas && shadow_atlas->shadow_owners.has(li->self)) {
// fill in the shadow information
uint32_t key = shadow_atlas->shadow_owners[li->self];
- uint32_t quadrant = (key >> ShadowAtlas::QUADRANT_SHIFT)&0x3;
+ uint32_t quadrant = (key >> ShadowAtlas::QUADRANT_SHIFT) & 0x3;
uint32_t shadow = key & ShadowAtlas::SHADOW_INDEX_MASK;
- ERR_CONTINUE(shadow>=shadow_atlas->quadrants[quadrant].shadows.size());
+ ERR_CONTINUE(shadow >= shadow_atlas->quadrants[quadrant].shadows.size());
uint32_t atlas_size = shadow_atlas->size;
- uint32_t quadrant_size = atlas_size>>1;
+ uint32_t quadrant_size = atlas_size >> 1;
- uint32_t x=(quadrant&1)*quadrant_size;
- uint32_t y=(quadrant>>1)*quadrant_size;
+ uint32_t x = (quadrant & 1) * quadrant_size;
+ uint32_t y = (quadrant >> 1) * quadrant_size;
uint32_t shadow_size = (quadrant_size / shadow_atlas->quadrants[quadrant].subdivision);
- x+=(shadow % shadow_atlas->quadrants[quadrant].subdivision) * shadow_size;
- y+=(shadow / shadow_atlas->quadrants[quadrant].subdivision) * shadow_size;
+ x += (shadow % shadow_atlas->quadrants[quadrant].subdivision) * shadow_size;
+ y += (shadow / shadow_atlas->quadrants[quadrant].subdivision) * shadow_size;
- uint32_t width=shadow_size;
- uint32_t height=shadow_size;
+ uint32_t width = shadow_size;
+ uint32_t height = shadow_size;
- Rect2 rect(float(x)/atlas_size,float(y)/atlas_size,float(width)/atlas_size,float(height)/atlas_size);
+ Rect2 rect(float(x) / atlas_size, float(y) / atlas_size, float(width) / atlas_size, float(height) / atlas_size);
- ubo_data.light_params[3]=1.0; //means it has shadow
- ubo_data.light_clamp[0]=rect.pos.x;
- ubo_data.light_clamp[1]=rect.pos.y;
- ubo_data.light_clamp[2]=rect.size.x;
- ubo_data.light_clamp[3]=rect.size.y;
+ ubo_data.light_params[3] = 1.0; //means it has shadow
+ ubo_data.light_clamp[0] = rect.pos.x;
+ ubo_data.light_clamp[1] = rect.pos.y;
+ ubo_data.light_clamp[2] = rect.size.x;
+ ubo_data.light_clamp[3] = rect.size.y;
Transform modelview = (p_camera_inverse_transform * li->transform).inverse();
@@ -2655,13 +2473,11 @@ void RasterizerSceneGLES3::_setup_lights(RID *p_light_cull_result,int p_light_cu
CameraMatrix shadow_mtx = rectm * bias * li->shadow_transform[0].camera * modelview;
- store_camera(shadow_mtx,ubo_data.shadow_matrix1);
-
-
+ store_camera(shadow_mtx, ubo_data.shadow_matrix1);
}
- li->light_index=state.spot_light_count;
- copymem(&state.spot_array_tmp[li->light_index*state.ubo_light_size],&ubo_data,state.ubo_light_size);
+ li->light_index = state.spot_light_count;
+ copymem(&state.spot_array_tmp[li->light_index * state.ubo_light_size], &ubo_data, state.ubo_light_size);
state.spot_light_count++;
#if 0
@@ -2674,225 +2490,200 @@ void RasterizerSceneGLES3::_setup_lights(RID *p_light_cull_result,int p_light_cu
}
#endif
} break;
-
}
-
- li->last_pass=render_pass;
+ li->last_pass = render_pass;
//update UBO for forward rendering, blit to texture for clustered
-
}
-
-
if (state.omni_light_count) {
glBindBuffer(GL_UNIFORM_BUFFER, state.omni_array_ubo);
- glBufferSubData(GL_UNIFORM_BUFFER, 0, state.omni_light_count*state.ubo_light_size, state.omni_array_tmp);
+ glBufferSubData(GL_UNIFORM_BUFFER, 0, state.omni_light_count * state.ubo_light_size, state.omni_array_tmp);
glBindBuffer(GL_UNIFORM_BUFFER, 0);
}
- glBindBufferBase(GL_UNIFORM_BUFFER,4,state.omni_array_ubo);
+ glBindBufferBase(GL_UNIFORM_BUFFER, 4, state.omni_array_ubo);
if (state.spot_light_count) {
glBindBuffer(GL_UNIFORM_BUFFER, state.spot_array_ubo);
- glBufferSubData(GL_UNIFORM_BUFFER, 0, state.spot_light_count*state.ubo_light_size, state.spot_array_tmp);
+ glBufferSubData(GL_UNIFORM_BUFFER, 0, state.spot_light_count * state.ubo_light_size, state.spot_array_tmp);
glBindBuffer(GL_UNIFORM_BUFFER, 0);
-
}
- glBindBufferBase(GL_UNIFORM_BUFFER,5,state.spot_array_ubo);
-
-
+ glBindBufferBase(GL_UNIFORM_BUFFER, 5, state.spot_array_ubo);
}
-void RasterizerSceneGLES3::_setup_reflections(RID *p_reflection_probe_cull_result,int p_reflection_probe_cull_count,const Transform& p_camera_inverse_transform,const CameraMatrix& p_camera_projection,RID p_reflection_atlas,Environment *p_env) {
+void RasterizerSceneGLES3::_setup_reflections(RID *p_reflection_probe_cull_result, int p_reflection_probe_cull_count, const Transform &p_camera_inverse_transform, const CameraMatrix &p_camera_projection, RID p_reflection_atlas, Environment *p_env) {
- state.reflection_probe_count=0;
+ state.reflection_probe_count = 0;
- for(int i=0;i<p_reflection_probe_cull_count;i++) {
+ for (int i = 0; i < p_reflection_probe_cull_count; i++) {
- ReflectionProbeInstance *rpi=reflection_probe_instance_owner.getornull(p_reflection_probe_cull_result[i]);
+ ReflectionProbeInstance *rpi = reflection_probe_instance_owner.getornull(p_reflection_probe_cull_result[i]);
ERR_CONTINUE(!rpi);
- ReflectionAtlas *reflection_atlas=reflection_atlas_owner.getornull(p_reflection_atlas);
+ ReflectionAtlas *reflection_atlas = reflection_atlas_owner.getornull(p_reflection_atlas);
ERR_CONTINUE(!reflection_atlas);
- ERR_CONTINUE(rpi->reflection_atlas_index<0);
-
+ ERR_CONTINUE(rpi->reflection_atlas_index < 0);
- if (state.reflection_probe_count>=state.max_ubo_reflections)
+ if (state.reflection_probe_count >= state.max_ubo_reflections)
break;
- rpi->last_pass=render_pass;
-
+ rpi->last_pass = render_pass;
ReflectionProbeDataUBO reflection_ubo;
- reflection_ubo.box_extents[0]=rpi->probe_ptr->extents.x;
- reflection_ubo.box_extents[1]=rpi->probe_ptr->extents.y;
- reflection_ubo.box_extents[2]=rpi->probe_ptr->extents.z;
- reflection_ubo.box_extents[3]=0;
+ reflection_ubo.box_extents[0] = rpi->probe_ptr->extents.x;
+ reflection_ubo.box_extents[1] = rpi->probe_ptr->extents.y;
+ reflection_ubo.box_extents[2] = rpi->probe_ptr->extents.z;
+ reflection_ubo.box_extents[3] = 0;
+ reflection_ubo.box_ofs[0] = rpi->probe_ptr->origin_offset.x;
+ reflection_ubo.box_ofs[1] = rpi->probe_ptr->origin_offset.y;
+ reflection_ubo.box_ofs[2] = rpi->probe_ptr->origin_offset.z;
+ reflection_ubo.box_ofs[3] = 0;
-
- reflection_ubo.box_ofs[0]=rpi->probe_ptr->origin_offset.x;
- reflection_ubo.box_ofs[1]=rpi->probe_ptr->origin_offset.y;
- reflection_ubo.box_ofs[2]=rpi->probe_ptr->origin_offset.z;
- reflection_ubo.box_ofs[3]=0;
-
- reflection_ubo.params[0]=rpi->probe_ptr->intensity;
- reflection_ubo.params[1]=0;
- reflection_ubo.params[2]=rpi->probe_ptr->interior?1.0:0.0;
- reflection_ubo.params[3]=rpi->probe_ptr->box_projection?1.0:0.0;
+ reflection_ubo.params[0] = rpi->probe_ptr->intensity;
+ reflection_ubo.params[1] = 0;
+ reflection_ubo.params[2] = rpi->probe_ptr->interior ? 1.0 : 0.0;
+ reflection_ubo.params[3] = rpi->probe_ptr->box_projection ? 1.0 : 0.0;
if (rpi->probe_ptr->interior) {
Color ambient_linear = rpi->probe_ptr->interior_ambient.to_linear();
- reflection_ubo.ambient[0]=ambient_linear.r*rpi->probe_ptr->interior_ambient_energy;
- reflection_ubo.ambient[1]=ambient_linear.g*rpi->probe_ptr->interior_ambient_energy;
- reflection_ubo.ambient[2]=ambient_linear.b*rpi->probe_ptr->interior_ambient_energy;
- reflection_ubo.ambient[3]=rpi->probe_ptr->interior_ambient_probe_contrib;
+ reflection_ubo.ambient[0] = ambient_linear.r * rpi->probe_ptr->interior_ambient_energy;
+ reflection_ubo.ambient[1] = ambient_linear.g * rpi->probe_ptr->interior_ambient_energy;
+ reflection_ubo.ambient[2] = ambient_linear.b * rpi->probe_ptr->interior_ambient_energy;
+ reflection_ubo.ambient[3] = rpi->probe_ptr->interior_ambient_probe_contrib;
} else {
Color ambient_linear;
- float contrib=0;
+ float contrib = 0;
if (p_env) {
- ambient_linear=p_env->ambient_color.to_linear();
- ambient_linear.r*=p_env->ambient_energy;
- ambient_linear.g*=p_env->ambient_energy;
- ambient_linear.b*=p_env->ambient_energy;
- contrib=p_env->ambient_skybox_contribution;
+ ambient_linear = p_env->ambient_color.to_linear();
+ ambient_linear.r *= p_env->ambient_energy;
+ ambient_linear.g *= p_env->ambient_energy;
+ ambient_linear.b *= p_env->ambient_energy;
+ contrib = p_env->ambient_skybox_contribution;
}
- reflection_ubo.ambient[0]=ambient_linear.r;
- reflection_ubo.ambient[1]=ambient_linear.g;
- reflection_ubo.ambient[2]=ambient_linear.b;
- reflection_ubo.ambient[3]=0;
+ reflection_ubo.ambient[0] = ambient_linear.r;
+ reflection_ubo.ambient[1] = ambient_linear.g;
+ reflection_ubo.ambient[2] = ambient_linear.b;
+ reflection_ubo.ambient[3] = 0;
}
int cell_size = reflection_atlas->size / reflection_atlas->subdiv;
int x = (rpi->reflection_atlas_index % reflection_atlas->subdiv) * cell_size;
int y = (rpi->reflection_atlas_index / reflection_atlas->subdiv) * cell_size;
- int width=cell_size;
- int height=cell_size;
+ int width = cell_size;
+ int height = cell_size;
- reflection_ubo.atlas_clamp[0]=float(x)/reflection_atlas->size;
- reflection_ubo.atlas_clamp[1]=float(y)/reflection_atlas->size;
- reflection_ubo.atlas_clamp[2]=float(width)/reflection_atlas->size;
- reflection_ubo.atlas_clamp[3]=float(height/2)/reflection_atlas->size;
+ reflection_ubo.atlas_clamp[0] = float(x) / reflection_atlas->size;
+ reflection_ubo.atlas_clamp[1] = float(y) / reflection_atlas->size;
+ reflection_ubo.atlas_clamp[2] = float(width) / reflection_atlas->size;
+ reflection_ubo.atlas_clamp[3] = float(height / 2) / reflection_atlas->size;
Transform proj = (p_camera_inverse_transform * rpi->transform).inverse();
- store_transform(proj,reflection_ubo.local_matrix);
+ store_transform(proj, reflection_ubo.local_matrix);
- rpi->reflection_index=state.reflection_probe_count;
- copymem(&state.reflection_array_tmp[rpi->reflection_index*sizeof(ReflectionProbeDataUBO)],&reflection_ubo,sizeof(ReflectionProbeDataUBO));
+ rpi->reflection_index = state.reflection_probe_count;
+ copymem(&state.reflection_array_tmp[rpi->reflection_index * sizeof(ReflectionProbeDataUBO)], &reflection_ubo, sizeof(ReflectionProbeDataUBO));
state.reflection_probe_count++;
-
}
-
if (state.reflection_probe_count) {
-
glBindBuffer(GL_UNIFORM_BUFFER, state.reflection_array_ubo);
- glBufferSubData(GL_UNIFORM_BUFFER, 0, state.reflection_probe_count*sizeof(ReflectionProbeDataUBO), state.reflection_array_tmp);
+ glBufferSubData(GL_UNIFORM_BUFFER, 0, state.reflection_probe_count * sizeof(ReflectionProbeDataUBO), state.reflection_array_tmp);
glBindBuffer(GL_UNIFORM_BUFFER, 0);
-
}
- glBindBufferBase(GL_UNIFORM_BUFFER,6,state.reflection_array_ubo);
-
+ glBindBufferBase(GL_UNIFORM_BUFFER, 6, state.reflection_array_ubo);
}
-
void RasterizerSceneGLES3::_copy_screen() {
- glBindVertexArray( storage->resources.quadie_array);
- glDrawArrays(GL_TRIANGLE_FAN,0,4);
+ glBindVertexArray(storage->resources.quadie_array);
+ glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
glBindVertexArray(0);
-
}
void RasterizerSceneGLES3::_copy_to_front_buffer(Environment *env) {
//copy to front buffer
- glBindFramebuffer(GL_FRAMEBUFFER,storage->frame.current_rt->fbo);
+ glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->fbo);
glDepthMask(GL_FALSE);
glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
glDisable(GL_BLEND);
glDepthFunc(GL_LEQUAL);
- glColorMask(1,1,1,1);
+ glColorMask(1, 1, 1, 1);
glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D,storage->frame.current_rt->buffers.diffuse);
+ glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->buffers.diffuse);
- storage->shaders.copy.set_conditional(CopyShaderGLES3::DISABLE_ALPHA,true);
+ storage->shaders.copy.set_conditional(CopyShaderGLES3::DISABLE_ALPHA, true);
if (!env) {
//no environment, simply convert from linear to srgb
- storage->shaders.copy.set_conditional(CopyShaderGLES3::LINEAR_TO_SRGB,true);
+ storage->shaders.copy.set_conditional(CopyShaderGLES3::LINEAR_TO_SRGB, true);
} else {
/* FIXME: Why are both statements equal? */
- storage->shaders.copy.set_conditional(CopyShaderGLES3::LINEAR_TO_SRGB,true);
-
+ storage->shaders.copy.set_conditional(CopyShaderGLES3::LINEAR_TO_SRGB, true);
}
storage->shaders.copy.bind();
_copy_screen();
-
//turn off everything used
- storage->shaders.copy.set_conditional(CopyShaderGLES3::LINEAR_TO_SRGB,false);
- storage->shaders.copy.set_conditional(CopyShaderGLES3::DISABLE_ALPHA,false);
-
-
+ storage->shaders.copy.set_conditional(CopyShaderGLES3::LINEAR_TO_SRGB, false);
+ storage->shaders.copy.set_conditional(CopyShaderGLES3::DISABLE_ALPHA, false);
}
void RasterizerSceneGLES3::_copy_texture_to_front_buffer(GLuint p_texture) {
//copy to front buffer
- glBindFramebuffer(GL_FRAMEBUFFER,storage->frame.current_rt->fbo);
+ glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->fbo);
glDepthMask(GL_FALSE);
glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
glDisable(GL_BLEND);
glDepthFunc(GL_LEQUAL);
- glColorMask(1,1,1,1);
+ glColorMask(1, 1, 1, 1);
glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D,p_texture);
+ glBindTexture(GL_TEXTURE_2D, p_texture);
- glViewport(0,0,storage->frame.current_rt->width*0.5,storage->frame.current_rt->height*0.5);
+ glViewport(0, 0, storage->frame.current_rt->width * 0.5, storage->frame.current_rt->height * 0.5);
- storage->shaders.copy.set_conditional(CopyShaderGLES3::DISABLE_ALPHA,true);
+ storage->shaders.copy.set_conditional(CopyShaderGLES3::DISABLE_ALPHA, true);
storage->shaders.copy.bind();
_copy_screen();
//turn off everything used
- storage->shaders.copy.set_conditional(CopyShaderGLES3::LINEAR_TO_SRGB,false);
- storage->shaders.copy.set_conditional(CopyShaderGLES3::DISABLE_ALPHA,false);
-
-
+ storage->shaders.copy.set_conditional(CopyShaderGLES3::LINEAR_TO_SRGB, false);
+ storage->shaders.copy.set_conditional(CopyShaderGLES3::DISABLE_ALPHA, false);
}
-void RasterizerSceneGLES3::_fill_render_list(InstanceBase** p_cull_result,int p_cull_count,bool p_shadow){
+void RasterizerSceneGLES3::_fill_render_list(InstanceBase **p_cull_result, int p_cull_count, bool p_shadow) {
- current_geometry_index=0;
- current_material_index=0;
- state.used_sss=false;
+ current_geometry_index = 0;
+ current_material_index = 0;
+ state.used_sss = false;
//fill list
- for(int i=0;i<p_cull_count;i++) {
+ for (int i = 0; i < p_cull_count; i++) {
InstanceBase *inst = p_cull_result[i];
- switch(inst->base_type) {
+ switch (inst->base_type) {
case VS::INSTANCE_MESH: {
@@ -2901,11 +2692,11 @@ void RasterizerSceneGLES3::_fill_render_list(InstanceBase** p_cull_result,int p_
int ssize = mesh->surfaces.size();
- for (int i=0;i<ssize;i++) {
+ for (int i = 0; i < ssize; i++) {
int mat_idx = inst->materials[i].is_valid() ? i : -1;
RasterizerStorageGLES3::Surface *s = mesh->surfaces[i];
- _add_geometry(s,inst,NULL,mat_idx,p_shadow);
+ _add_geometry(s, inst, NULL, mat_idx, p_shadow);
}
//mesh->last_pass=frame;
@@ -2916,8 +2707,7 @@ void RasterizerSceneGLES3::_fill_render_list(InstanceBase** p_cull_result,int p_
RasterizerStorageGLES3::MultiMesh *multi_mesh = storage->multimesh_owner.getptr(inst->base);
ERR_CONTINUE(!multi_mesh);
-
- if (multi_mesh->size==0 || multi_mesh->visible_instances==0)
+ if (multi_mesh->size == 0 || multi_mesh->visible_instances == 0)
continue;
RasterizerStorageGLES3::Mesh *mesh = storage->mesh_owner.getptr(multi_mesh->mesh);
@@ -2926,32 +2716,27 @@ void RasterizerSceneGLES3::_fill_render_list(InstanceBase** p_cull_result,int p_
int ssize = mesh->surfaces.size();
- for (int i=0;i<ssize;i++) {
+ for (int i = 0; i < ssize; i++) {
RasterizerStorageGLES3::Surface *s = mesh->surfaces[i];
- _add_geometry(s,inst,multi_mesh,-1,p_shadow);
+ _add_geometry(s, inst, multi_mesh, -1, p_shadow);
}
-
} break;
case VS::INSTANCE_IMMEDIATE: {
} break;
-
}
}
}
-
-void RasterizerSceneGLES3::_render_mrts(Environment *env,const CameraMatrix &p_cam_projection) {
-
+void RasterizerSceneGLES3::_render_mrts(Environment *env, const CameraMatrix &p_cam_projection) {
glDepthMask(GL_FALSE);
glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
glDisable(GL_BLEND);
-
if (env->ssao_enabled) {
//copy diffuse to front buffer
glBindFramebuffer(GL_READ_FRAMEBUFFER, storage->frame.current_rt->buffers.fbo);
@@ -2962,87 +2747,83 @@ void RasterizerSceneGLES3::_render_mrts(Environment *env,const CameraMatrix &p_c
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
-
//copy from depth, convert to linear
GLint ss[2];
- ss[0]=storage->frame.current_rt->width;
- ss[1]=storage->frame.current_rt->height;
+ ss[0] = storage->frame.current_rt->width;
+ ss[1] = storage->frame.current_rt->height;
- for(int i=0;i<storage->frame.current_rt->effects.ssao.depth_mipmap_fbos.size();i++) {
+ for (int i = 0; i < storage->frame.current_rt->effects.ssao.depth_mipmap_fbos.size(); i++) {
- state.ssao_minify_shader.set_conditional(SsaoMinifyShaderGLES3::MINIFY_START,i==0);
+ state.ssao_minify_shader.set_conditional(SsaoMinifyShaderGLES3::MINIFY_START, i == 0);
state.ssao_minify_shader.bind();
- state.ssao_minify_shader.set_uniform(SsaoMinifyShaderGLES3::CAMERA_Z_FAR,p_cam_projection.get_z_far());
- state.ssao_minify_shader.set_uniform(SsaoMinifyShaderGLES3::CAMERA_Z_NEAR,p_cam_projection.get_z_near());
- state.ssao_minify_shader.set_uniform(SsaoMinifyShaderGLES3::SOURCE_MIPMAP,MAX(0,i-1));
- glUniform2iv(state.ssao_minify_shader.get_uniform(SsaoMinifyShaderGLES3::FROM_SIZE),1,ss);
- ss[0]>>=1;
- ss[1]>>=1;
+ state.ssao_minify_shader.set_uniform(SsaoMinifyShaderGLES3::CAMERA_Z_FAR, p_cam_projection.get_z_far());
+ state.ssao_minify_shader.set_uniform(SsaoMinifyShaderGLES3::CAMERA_Z_NEAR, p_cam_projection.get_z_near());
+ state.ssao_minify_shader.set_uniform(SsaoMinifyShaderGLES3::SOURCE_MIPMAP, MAX(0, i - 1));
+ glUniform2iv(state.ssao_minify_shader.get_uniform(SsaoMinifyShaderGLES3::FROM_SIZE), 1, ss);
+ ss[0] >>= 1;
+ ss[1] >>= 1;
glActiveTexture(GL_TEXTURE0);
- if (i==0) {
- glBindTexture(GL_TEXTURE_2D,storage->frame.current_rt->depth);
+ if (i == 0) {
+ glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->depth);
} else {
- glBindTexture(GL_TEXTURE_2D,storage->frame.current_rt->effects.ssao.linear_depth);
+ glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->effects.ssao.linear_depth);
}
- glBindFramebuffer(GL_FRAMEBUFFER,storage->frame.current_rt->effects.ssao.depth_mipmap_fbos[i]); //copy to front first
- glViewport(0,0,ss[0],ss[1]);
+ glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->effects.ssao.depth_mipmap_fbos[i]); //copy to front first
+ glViewport(0, 0, ss[0], ss[1]);
_copy_screen();
-
}
- ss[0]=storage->frame.current_rt->width;
- ss[1]=storage->frame.current_rt->height;
-
- glViewport(0,0,ss[0],ss[1]);
+ ss[0] = storage->frame.current_rt->width;
+ ss[1] = storage->frame.current_rt->height;
+ glViewport(0, 0, ss[0], ss[1]);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_GREATER);
// do SSAO!
- state.ssao_shader.set_conditional(SsaoShaderGLES3::ENABLE_RADIUS2,env->ssao_radius2>0.001);
+ state.ssao_shader.set_conditional(SsaoShaderGLES3::ENABLE_RADIUS2, env->ssao_radius2 > 0.001);
state.ssao_shader.bind();
- state.ssao_shader.set_uniform(SsaoShaderGLES3::CAMERA_Z_FAR,p_cam_projection.get_z_far());
- state.ssao_shader.set_uniform(SsaoShaderGLES3::CAMERA_Z_NEAR,p_cam_projection.get_z_near());
- glUniform2iv(state.ssao_shader.get_uniform(SsaoShaderGLES3::SCREEN_SIZE),1,ss);
+ state.ssao_shader.set_uniform(SsaoShaderGLES3::CAMERA_Z_FAR, p_cam_projection.get_z_far());
+ state.ssao_shader.set_uniform(SsaoShaderGLES3::CAMERA_Z_NEAR, p_cam_projection.get_z_near());
+ glUniform2iv(state.ssao_shader.get_uniform(SsaoShaderGLES3::SCREEN_SIZE), 1, ss);
float radius = env->ssao_radius;
- state.ssao_shader.set_uniform(SsaoShaderGLES3::RADIUS,radius);
+ state.ssao_shader.set_uniform(SsaoShaderGLES3::RADIUS, radius);
float intensity = env->ssao_intensity;
- state.ssao_shader.set_uniform(SsaoShaderGLES3::INTENSITY_DIV_R6,intensity / pow(radius, 6.0f));
+ state.ssao_shader.set_uniform(SsaoShaderGLES3::INTENSITY_DIV_R6, intensity / pow(radius, 6.0f));
- if (env->ssao_radius2>0.001) {
+ if (env->ssao_radius2 > 0.001) {
float radius2 = env->ssao_radius2;
- state.ssao_shader.set_uniform(SsaoShaderGLES3::RADIUS2,radius2);
+ state.ssao_shader.set_uniform(SsaoShaderGLES3::RADIUS2, radius2);
float intensity2 = env->ssao_intensity2;
- state.ssao_shader.set_uniform(SsaoShaderGLES3::INTENSITY_DIV_R62,intensity2 / pow(radius2, 6.0f));
-
+ state.ssao_shader.set_uniform(SsaoShaderGLES3::INTENSITY_DIV_R62, intensity2 / pow(radius2, 6.0f));
}
- float proj_info[4]={
- -2.0f / (ss[0]*p_cam_projection.matrix[0][0]),
- -2.0f / (ss[1]*p_cam_projection.matrix[1][1]),
- ( 1.0f - p_cam_projection.matrix[0][2]) / p_cam_projection.matrix[0][0],
- ( 1.0f + p_cam_projection.matrix[1][2]) / p_cam_projection.matrix[1][1]
+ float proj_info[4] = {
+ -2.0f / (ss[0] * p_cam_projection.matrix[0][0]),
+ -2.0f / (ss[1] * p_cam_projection.matrix[1][1]),
+ (1.0f - p_cam_projection.matrix[0][2]) / p_cam_projection.matrix[0][0],
+ (1.0f + p_cam_projection.matrix[1][2]) / p_cam_projection.matrix[1][1]
};
- glUniform4fv(state.ssao_shader.get_uniform(SsaoShaderGLES3::PROJ_INFO),1,proj_info);
+ glUniform4fv(state.ssao_shader.get_uniform(SsaoShaderGLES3::PROJ_INFO), 1, proj_info);
float pixels_per_meter = float(p_cam_projection.get_pixels_per_meter(ss[0]));
- state.ssao_shader.set_uniform(SsaoShaderGLES3::PROJ_SCALE,pixels_per_meter);
- state.ssao_shader.set_uniform(SsaoShaderGLES3::BIAS,env->ssao_bias);
+ state.ssao_shader.set_uniform(SsaoShaderGLES3::PROJ_SCALE, pixels_per_meter);
+ state.ssao_shader.set_uniform(SsaoShaderGLES3::BIAS, env->ssao_bias);
glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D,storage->frame.current_rt->depth);
+ glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->depth);
glActiveTexture(GL_TEXTURE1);
- glBindTexture(GL_TEXTURE_2D,storage->frame.current_rt->effects.ssao.linear_depth);
+ glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->effects.ssao.linear_depth);
glActiveTexture(GL_TEXTURE2);
- glBindTexture(GL_TEXTURE_2D,storage->frame.current_rt->buffers.effect);
+ glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->buffers.effect);
- glBindFramebuffer(GL_FRAMEBUFFER,storage->frame.current_rt->effects.ssao.blur_fbo[0]); //copy to front first
- Color white(1,1,1,1);
- glClearBufferfv(GL_COLOR,0,white.components); // specular
+ glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->effects.ssao.blur_fbo[0]); //copy to front first
+ Color white(1, 1, 1, 1);
+ glClearBufferfv(GL_COLOR, 0, white.components); // specular
_copy_screen();
@@ -3051,22 +2832,21 @@ void RasterizerSceneGLES3::_render_mrts(Environment *env,const CameraMatrix &p_c
state.ssao_blur_shader.bind();
if (env->ssao_filter) {
- for(int i=0;i<2;i++) {
+ for (int i = 0; i < 2; i++) {
- state.ssao_blur_shader.set_uniform(SsaoBlurShaderGLES3::CAMERA_Z_FAR,p_cam_projection.get_z_far());
- state.ssao_blur_shader.set_uniform(SsaoBlurShaderGLES3::CAMERA_Z_NEAR,p_cam_projection.get_z_near());
- GLint axis[2]={i,1-i};
- glUniform2iv(state.ssao_blur_shader.get_uniform(SsaoBlurShaderGLES3::AXIS),1,axis);
+ state.ssao_blur_shader.set_uniform(SsaoBlurShaderGLES3::CAMERA_Z_FAR, p_cam_projection.get_z_far());
+ state.ssao_blur_shader.set_uniform(SsaoBlurShaderGLES3::CAMERA_Z_NEAR, p_cam_projection.get_z_near());
+ GLint axis[2] = { i, 1 - i };
+ glUniform2iv(state.ssao_blur_shader.get_uniform(SsaoBlurShaderGLES3::AXIS), 1, axis);
glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D,storage->frame.current_rt->effects.ssao.blur_red[i]);
+ glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->effects.ssao.blur_red[i]);
glActiveTexture(GL_TEXTURE1);
- glBindTexture(GL_TEXTURE_2D,storage->frame.current_rt->depth);
- glBindFramebuffer(GL_FRAMEBUFFER,storage->frame.current_rt->effects.ssao.blur_fbo[1-i]);
- if (i==0) {
- glClearBufferfv(GL_COLOR,0,white.components); // specular
+ glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->depth);
+ glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->effects.ssao.blur_fbo[1 - i]);
+ if (i == 0) {
+ glClearBufferfv(GL_COLOR, 0, white.components); // specular
}
_copy_screen();
-
}
}
@@ -3075,16 +2855,16 @@ void RasterizerSceneGLES3::_render_mrts(Environment *env,const CameraMatrix &p_c
// just copy diffuse while applying SSAO
- state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::SSAO_MERGE,true);
+ state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::SSAO_MERGE, true);
state.effect_blur_shader.bind();
- state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::SSAO_COLOR,env->ssao_color);
+ state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::SSAO_COLOR, env->ssao_color);
glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D,storage->frame.current_rt->color); //previous level, since mipmaps[0] starts one level bigger
+ glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->color); //previous level, since mipmaps[0] starts one level bigger
glActiveTexture(GL_TEXTURE1);
- glBindTexture(GL_TEXTURE_2D,storage->frame.current_rt->effects.ssao.blur_red[0]); //previous level, since mipmaps[0] starts one level bigger
- glBindFramebuffer(GL_FRAMEBUFFER,storage->frame.current_rt->effects.mip_maps[0].sizes[0].fbo); // copy to base level
+ glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->effects.ssao.blur_red[0]); //previous level, since mipmaps[0] starts one level bigger
+ glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->effects.mip_maps[0].sizes[0].fbo); // copy to base level
_copy_screen();
- state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::SSAO_MERGE,false);
+ state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::SSAO_MERGE, false);
} else {
@@ -3096,137 +2876,124 @@ void RasterizerSceneGLES3::_render_mrts(Environment *env,const CameraMatrix &p_c
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
-
}
-
- if (state.used_sss) {//sss enabled
+ if (state.used_sss) { //sss enabled
//copy diffuse while performing sss
//copy normal and roughness to effect buffer
glBindFramebuffer(GL_READ_FRAMEBUFFER, storage->frame.current_rt->buffers.fbo);
glReadBuffer(GL_COLOR_ATTACHMENT3);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, storage->frame.current_rt->buffers.effect_fbo);
- glBlitFramebuffer(0, 0, storage->frame.current_rt->width, storage->frame.current_rt->height, 0, 0, storage->frame.current_rt->width, storage->frame.current_rt->height, GL_COLOR_BUFFER_BIT , GL_NEAREST);
+ glBlitFramebuffer(0, 0, storage->frame.current_rt->width, storage->frame.current_rt->height, 0, 0, storage->frame.current_rt->width, storage->frame.current_rt->height, GL_COLOR_BUFFER_BIT, GL_NEAREST);
- state.sss_shader.set_conditional(SubsurfScatteringShaderGLES3::USE_11_SAMPLES,subsurface_scatter_quality==SSS_QUALITY_LOW);
- state.sss_shader.set_conditional(SubsurfScatteringShaderGLES3::USE_17_SAMPLES,subsurface_scatter_quality==SSS_QUALITY_MEDIUM);
- state.sss_shader.set_conditional(SubsurfScatteringShaderGLES3::USE_25_SAMPLES,subsurface_scatter_quality==SSS_QUALITY_HIGH);
- state.sss_shader.set_conditional(SubsurfScatteringShaderGLES3::ENABLE_FOLLOW_SURFACE,subsurface_scatter_follow_surface);
+ state.sss_shader.set_conditional(SubsurfScatteringShaderGLES3::USE_11_SAMPLES, subsurface_scatter_quality == SSS_QUALITY_LOW);
+ state.sss_shader.set_conditional(SubsurfScatteringShaderGLES3::USE_17_SAMPLES, subsurface_scatter_quality == SSS_QUALITY_MEDIUM);
+ state.sss_shader.set_conditional(SubsurfScatteringShaderGLES3::USE_25_SAMPLES, subsurface_scatter_quality == SSS_QUALITY_HIGH);
+ state.sss_shader.set_conditional(SubsurfScatteringShaderGLES3::ENABLE_FOLLOW_SURFACE, subsurface_scatter_follow_surface);
state.sss_shader.bind();
- state.sss_shader.set_uniform(SubsurfScatteringShaderGLES3::MAX_RADIUS,subsurface_scatter_size);
- state.sss_shader.set_uniform(SubsurfScatteringShaderGLES3::FOVY,p_cam_projection.get_fov());
- state.sss_shader.set_uniform(SubsurfScatteringShaderGLES3::CAMERA_Z_NEAR,p_cam_projection.get_z_near());
- state.sss_shader.set_uniform(SubsurfScatteringShaderGLES3::CAMERA_Z_FAR,p_cam_projection.get_z_far());
- state.sss_shader.set_uniform(SubsurfScatteringShaderGLES3::DIR,Vector2(1,0));
+ state.sss_shader.set_uniform(SubsurfScatteringShaderGLES3::MAX_RADIUS, subsurface_scatter_size);
+ state.sss_shader.set_uniform(SubsurfScatteringShaderGLES3::FOVY, p_cam_projection.get_fov());
+ state.sss_shader.set_uniform(SubsurfScatteringShaderGLES3::CAMERA_Z_NEAR, p_cam_projection.get_z_near());
+ state.sss_shader.set_uniform(SubsurfScatteringShaderGLES3::CAMERA_Z_FAR, p_cam_projection.get_z_far());
+ state.sss_shader.set_uniform(SubsurfScatteringShaderGLES3::DIR, Vector2(1, 0));
glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D,storage->frame.current_rt->effects.mip_maps[0].color);
+ glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->effects.mip_maps[0].color);
glActiveTexture(GL_TEXTURE1);
- glBindTexture(GL_TEXTURE_2D,storage->frame.current_rt->buffers.effect);
+ glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->buffers.effect);
glActiveTexture(GL_TEXTURE2);
- glBindTexture(GL_TEXTURE_2D,storage->frame.current_rt->depth);
+ glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->depth);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE);
- glBindFramebuffer(GL_FRAMEBUFFER,storage->frame.current_rt->fbo); //copy to front first
+ glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->fbo); //copy to front first
_copy_screen();
glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D,storage->frame.current_rt->color);
- state.sss_shader.set_uniform(SubsurfScatteringShaderGLES3::DIR,Vector2(0,1));
- glBindFramebuffer(GL_FRAMEBUFFER,storage->frame.current_rt->effects.mip_maps[0].sizes[0].fbo); // copy to base level
+ glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->color);
+ state.sss_shader.set_uniform(SubsurfScatteringShaderGLES3::DIR, Vector2(0, 1));
+ glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->effects.mip_maps[0].sizes[0].fbo); // copy to base level
_copy_screen();
-
}
-
-
if (env->ssr_enabled) {
//copy normal and roughness to effect buffer
glBindFramebuffer(GL_READ_FRAMEBUFFER, storage->frame.current_rt->buffers.fbo);
glReadBuffer(GL_COLOR_ATTACHMENT2);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, storage->frame.current_rt->buffers.effect_fbo);
- glBlitFramebuffer(0, 0, storage->frame.current_rt->width, storage->frame.current_rt->height, 0, 0, storage->frame.current_rt->width, storage->frame.current_rt->height, GL_COLOR_BUFFER_BIT , GL_NEAREST);
-
+ glBlitFramebuffer(0, 0, storage->frame.current_rt->width, storage->frame.current_rt->height, 0, 0, storage->frame.current_rt->width, storage->frame.current_rt->height, GL_COLOR_BUFFER_BIT, GL_NEAREST);
//blur diffuse into effect mipmaps using separatable convolution
//storage->shaders.copy.set_conditional(CopyShaderGLES3::GAUSSIAN_HORIZONTAL,true);
- for(int i=0;i<storage->frame.current_rt->effects.mip_maps[1].sizes.size();i++) {
-
+ for (int i = 0; i < storage->frame.current_rt->effects.mip_maps[1].sizes.size(); i++) {
int vp_w = storage->frame.current_rt->effects.mip_maps[1].sizes[i].width;
int vp_h = storage->frame.current_rt->effects.mip_maps[1].sizes[i].height;
- glViewport(0,0,vp_w,vp_h);
+ glViewport(0, 0, vp_w, vp_h);
//horizontal pass
- state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::GAUSSIAN_HORIZONTAL,true);
+ state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::GAUSSIAN_HORIZONTAL, true);
state.effect_blur_shader.bind();
- state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::PIXEL_SIZE,Vector2(1.0/vp_w,1.0/vp_h));
- state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::LOD,float(i));
+ state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::PIXEL_SIZE, Vector2(1.0 / vp_w, 1.0 / vp_h));
+ state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::LOD, float(i));
glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D,storage->frame.current_rt->effects.mip_maps[0].color); //previous level, since mipmaps[0] starts one level bigger
- glBindFramebuffer(GL_FRAMEBUFFER,storage->frame.current_rt->effects.mip_maps[1].sizes[i].fbo);
+ glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->effects.mip_maps[0].color); //previous level, since mipmaps[0] starts one level bigger
+ glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->effects.mip_maps[1].sizes[i].fbo);
_copy_screen();
- state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::GAUSSIAN_HORIZONTAL,false);
+ state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::GAUSSIAN_HORIZONTAL, false);
//vertical pass
- state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::GAUSSIAN_VERTICAL,true);
+ state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::GAUSSIAN_VERTICAL, true);
state.effect_blur_shader.bind();
- state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::PIXEL_SIZE,Vector2(1.0/vp_w,1.0/vp_h));
- state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::LOD,float(i));
+ state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::PIXEL_SIZE, Vector2(1.0 / vp_w, 1.0 / vp_h));
+ state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::LOD, float(i));
glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D,storage->frame.current_rt->effects.mip_maps[1].color);
- glBindFramebuffer(GL_FRAMEBUFFER,storage->frame.current_rt->effects.mip_maps[0].sizes[i+1].fbo); //next level, since mipmaps[0] starts one level bigger
+ glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->effects.mip_maps[1].color);
+ glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->effects.mip_maps[0].sizes[i + 1].fbo); //next level, since mipmaps[0] starts one level bigger
_copy_screen();
- state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::GAUSSIAN_VERTICAL,false);
+ state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::GAUSSIAN_VERTICAL, false);
}
-
//perform SSR
- state.ssr_shader.set_conditional(ScreenSpaceReflectionShaderGLES3::SMOOTH_ACCEL,env->ssr_accel>0 && env->ssr_smooth);
- state.ssr_shader.set_conditional(ScreenSpaceReflectionShaderGLES3::REFLECT_ROUGHNESS,env->ssr_accel>0 && env->ssr_roughness);
+ state.ssr_shader.set_conditional(ScreenSpaceReflectionShaderGLES3::SMOOTH_ACCEL, env->ssr_accel > 0 && env->ssr_smooth);
+ state.ssr_shader.set_conditional(ScreenSpaceReflectionShaderGLES3::REFLECT_ROUGHNESS, env->ssr_accel > 0 && env->ssr_roughness);
state.ssr_shader.bind();
int ssr_w = storage->frame.current_rt->effects.mip_maps[1].sizes[0].width;
int ssr_h = storage->frame.current_rt->effects.mip_maps[1].sizes[0].height;
-
- state.ssr_shader.set_uniform(ScreenSpaceReflectionShaderGLES3::PIXEL_SIZE,Vector2(1.0/(ssr_w*0.5),1.0/(ssr_h*0.5)));
- state.ssr_shader.set_uniform(ScreenSpaceReflectionShaderGLES3::CAMERA_Z_NEAR,p_cam_projection.get_z_near());
- state.ssr_shader.set_uniform(ScreenSpaceReflectionShaderGLES3::CAMERA_Z_FAR,p_cam_projection.get_z_far());
- state.ssr_shader.set_uniform(ScreenSpaceReflectionShaderGLES3::PROJECTION,p_cam_projection);
- state.ssr_shader.set_uniform(ScreenSpaceReflectionShaderGLES3::INVERSE_PROJECTION,p_cam_projection.inverse());
- state.ssr_shader.set_uniform(ScreenSpaceReflectionShaderGLES3::VIEWPORT_SIZE,Size2(ssr_w,ssr_h));
+ state.ssr_shader.set_uniform(ScreenSpaceReflectionShaderGLES3::PIXEL_SIZE, Vector2(1.0 / (ssr_w * 0.5), 1.0 / (ssr_h * 0.5)));
+ state.ssr_shader.set_uniform(ScreenSpaceReflectionShaderGLES3::CAMERA_Z_NEAR, p_cam_projection.get_z_near());
+ state.ssr_shader.set_uniform(ScreenSpaceReflectionShaderGLES3::CAMERA_Z_FAR, p_cam_projection.get_z_far());
+ state.ssr_shader.set_uniform(ScreenSpaceReflectionShaderGLES3::PROJECTION, p_cam_projection);
+ state.ssr_shader.set_uniform(ScreenSpaceReflectionShaderGLES3::INVERSE_PROJECTION, p_cam_projection.inverse());
+ state.ssr_shader.set_uniform(ScreenSpaceReflectionShaderGLES3::VIEWPORT_SIZE, Size2(ssr_w, ssr_h));
//state.ssr_shader.set_uniform(ScreenSpaceReflectionShaderGLES3::FRAME_INDEX,int(render_pass));
- state.ssr_shader.set_uniform(ScreenSpaceReflectionShaderGLES3::FILTER_MIPMAP_LEVELS,float(storage->frame.current_rt->effects.mip_maps[0].sizes.size()));
- state.ssr_shader.set_uniform(ScreenSpaceReflectionShaderGLES3::NUM_STEPS,env->ssr_max_steps);
- state.ssr_shader.set_uniform(ScreenSpaceReflectionShaderGLES3::ACCELERATION,env->ssr_accel);
- state.ssr_shader.set_uniform(ScreenSpaceReflectionShaderGLES3::DEPTH_TOLERANCE,env->ssr_depth_tolerance);
- state.ssr_shader.set_uniform(ScreenSpaceReflectionShaderGLES3::DISTANCE_FADE,env->ssr_fade);
-
+ state.ssr_shader.set_uniform(ScreenSpaceReflectionShaderGLES3::FILTER_MIPMAP_LEVELS, float(storage->frame.current_rt->effects.mip_maps[0].sizes.size()));
+ state.ssr_shader.set_uniform(ScreenSpaceReflectionShaderGLES3::NUM_STEPS, env->ssr_max_steps);
+ state.ssr_shader.set_uniform(ScreenSpaceReflectionShaderGLES3::ACCELERATION, env->ssr_accel);
+ state.ssr_shader.set_uniform(ScreenSpaceReflectionShaderGLES3::DEPTH_TOLERANCE, env->ssr_depth_tolerance);
+ state.ssr_shader.set_uniform(ScreenSpaceReflectionShaderGLES3::DISTANCE_FADE, env->ssr_fade);
glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D,storage->frame.current_rt->effects.mip_maps[0].color);
+ glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->effects.mip_maps[0].color);
glActiveTexture(GL_TEXTURE1);
- glBindTexture(GL_TEXTURE_2D,storage->frame.current_rt->buffers.effect);
+ glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->buffers.effect);
glActiveTexture(GL_TEXTURE2);
- glBindTexture(GL_TEXTURE_2D,storage->frame.current_rt->depth);
+ glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->depth);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE);
- glBindFramebuffer(GL_FRAMEBUFFER,storage->frame.current_rt->effects.mip_maps[1].sizes[0].fbo);
- glViewport(0,0,ssr_w,ssr_h);
+ glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->effects.mip_maps[1].sizes[0].fbo);
+ glViewport(0, 0, ssr_w, ssr_h);
_copy_screen();
- glViewport(0,0,storage->frame.current_rt->width,storage->frame.current_rt->height);
-
+ glViewport(0, 0, storage->frame.current_rt->width, storage->frame.current_rt->height);
}
-
-
glBindFramebuffer(GL_READ_FRAMEBUFFER, storage->frame.current_rt->buffers.fbo);
glReadBuffer(GL_COLOR_ATTACHMENT1);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, storage->frame.current_rt->fbo);
@@ -3238,46 +3005,43 @@ void RasterizerSceneGLES3::_render_mrts(Environment *env,const CameraMatrix &p_c
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
//copy reflection over diffuse, resolving SSR if needed
- state.resolve_shader.set_conditional(ResolveShaderGLES3::USE_SSR,env->ssr_enabled);
+ state.resolve_shader.set_conditional(ResolveShaderGLES3::USE_SSR, env->ssr_enabled);
state.resolve_shader.bind();
glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D,storage->frame.current_rt->color);
+ glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->color);
if (env->ssr_enabled) {
glActiveTexture(GL_TEXTURE1);
- glBindTexture(GL_TEXTURE_2D,storage->frame.current_rt->effects.mip_maps[1].color);
+ glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->effects.mip_maps[1].color);
}
-
- glBindFramebuffer(GL_FRAMEBUFFER,storage->frame.current_rt->effects.mip_maps[0].sizes[0].fbo);
+ glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->effects.mip_maps[0].sizes[0].fbo);
glEnable(GL_BLEND);
glBlendEquation(GL_FUNC_ADD);
- glBlendFunc(GL_ONE,GL_ONE); //use additive to accumulate one over the other
+ glBlendFunc(GL_ONE, GL_ONE); //use additive to accumulate one over the other
_copy_screen();
glDisable(GL_BLEND); //end additive
- state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::SIMPLE_COPY,true);
+ state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::SIMPLE_COPY, true);
state.effect_blur_shader.bind();
- state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::LOD,float(0));
+ state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::LOD, float(0));
{
GLuint db = GL_COLOR_ATTACHMENT0;
- glDrawBuffers(1,&db);
+ glDrawBuffers(1, &db);
}
- glBindFramebuffer(GL_FRAMEBUFFER,storage->frame.current_rt->buffers.fbo);
+ glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->buffers.fbo);
glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D,storage->frame.current_rt->effects.mip_maps[0].color);
+ glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->effects.mip_maps[0].color);
_copy_screen();
- state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::SIMPLE_COPY,false);
-
-
+ state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::SIMPLE_COPY, false);
}
-void RasterizerSceneGLES3::_post_process(Environment *env,const CameraMatrix &p_cam_projection){
+void RasterizerSceneGLES3::_post_process(Environment *env, const CameraMatrix &p_cam_projection) {
//copy to front buffer
@@ -3286,14 +3050,13 @@ void RasterizerSceneGLES3::_post_process(Environment *env,const CameraMatrix &p_
glDisable(GL_CULL_FACE);
glDisable(GL_BLEND);
glDepthFunc(GL_LEQUAL);
- glColorMask(1,1,1,1);
+ glColorMask(1, 1, 1, 1);
//turn off everything used
//copy specular to front buffer
//copy diffuse to effect buffer
-
glReadBuffer(GL_COLOR_ATTACHMENT0);
glBindFramebuffer(GL_READ_FRAMEBUFFER, storage->frame.current_rt->buffers.fbo);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, storage->frame.current_rt->effects.mip_maps[0].sizes[0].fbo);
@@ -3304,23 +3067,21 @@ void RasterizerSceneGLES3::_post_process(Environment *env,const CameraMatrix &p_
if (!env) {
//no environment, simply return and convert to SRGB
- glBindFramebuffer(GL_FRAMEBUFFER,storage->frame.current_rt->fbo);
+ glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->fbo);
glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D,storage->frame.current_rt->effects.mip_maps[0].color);
- storage->shaders.copy.set_conditional(CopyShaderGLES3::LINEAR_TO_SRGB,true);
- storage->shaders.copy.set_conditional(CopyShaderGLES3::DISABLE_ALPHA,true);
+ glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->effects.mip_maps[0].color);
+ storage->shaders.copy.set_conditional(CopyShaderGLES3::LINEAR_TO_SRGB, true);
+ storage->shaders.copy.set_conditional(CopyShaderGLES3::DISABLE_ALPHA, true);
storage->shaders.copy.bind();
_copy_screen();
- storage->shaders.copy.set_conditional(CopyShaderGLES3::LINEAR_TO_SRGB,false);
- storage->shaders.copy.set_conditional(CopyShaderGLES3::DISABLE_ALPHA,false); //compute luminance
+ storage->shaders.copy.set_conditional(CopyShaderGLES3::LINEAR_TO_SRGB, false);
+ storage->shaders.copy.set_conditional(CopyShaderGLES3::DISABLE_ALPHA, false); //compute luminance
return;
-
}
-
//order of operation
//1) DOF Blur (first blur, then copy to buffer applying the blur)
//2) Motion Blur
@@ -3330,7 +3091,6 @@ void RasterizerSceneGLES3::_post_process(Environment *env,const CameraMatrix &p_
GLuint composite_from = storage->frame.current_rt->effects.mip_maps[0].color;
-
if (env->dof_blur_far_enabled) {
//blur diffuse into effect mipmaps using separatable convolution
@@ -3339,54 +3099,51 @@ void RasterizerSceneGLES3::_post_process(Environment *env,const CameraMatrix &p_
int vp_h = storage->frame.current_rt->height;
int vp_w = storage->frame.current_rt->width;
- state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::DOF_FAR_BLUR,true);
- state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::DOF_QUALITY_LOW,env->dof_blur_far_quality==VS::ENV_DOF_BLUR_QUALITY_LOW);
- state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::DOF_QUALITY_MEDIUM,env->dof_blur_far_quality==VS::ENV_DOF_BLUR_QUALITY_MEDIUM);
- state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::DOF_QUALITY_HIGH,env->dof_blur_far_quality==VS::ENV_DOF_BLUR_QUALITY_HIGH);
+ state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::DOF_FAR_BLUR, true);
+ state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::DOF_QUALITY_LOW, env->dof_blur_far_quality == VS::ENV_DOF_BLUR_QUALITY_LOW);
+ state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::DOF_QUALITY_MEDIUM, env->dof_blur_far_quality == VS::ENV_DOF_BLUR_QUALITY_MEDIUM);
+ state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::DOF_QUALITY_HIGH, env->dof_blur_far_quality == VS::ENV_DOF_BLUR_QUALITY_HIGH);
state.effect_blur_shader.bind();
- int qsteps[3]={4,10,20};
+ int qsteps[3] = { 4, 10, 20 };
- float radius = (env->dof_blur_far_amount*env->dof_blur_far_amount) / qsteps[env->dof_blur_far_quality];
+ float radius = (env->dof_blur_far_amount * env->dof_blur_far_amount) / qsteps[env->dof_blur_far_quality];
- state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::DOF_BEGIN,env->dof_blur_far_distance);
- state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::DOF_END,env->dof_blur_far_distance+env->dof_blur_far_transition);
- state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::DOF_DIR,Vector2(1,0));
- state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::DOF_RADIUS,radius);
- state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::PIXEL_SIZE,Vector2(1.0/vp_w,1.0/vp_h));
- state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::CAMERA_Z_NEAR,p_cam_projection.get_z_near());
- state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::CAMERA_Z_FAR,p_cam_projection.get_z_far());
+ state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::DOF_BEGIN, env->dof_blur_far_distance);
+ state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::DOF_END, env->dof_blur_far_distance + env->dof_blur_far_transition);
+ state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::DOF_DIR, Vector2(1, 0));
+ state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::DOF_RADIUS, radius);
+ state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::PIXEL_SIZE, Vector2(1.0 / vp_w, 1.0 / vp_h));
+ state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::CAMERA_Z_NEAR, p_cam_projection.get_z_near());
+ state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::CAMERA_Z_FAR, p_cam_projection.get_z_far());
glActiveTexture(GL_TEXTURE1);
- glBindTexture(GL_TEXTURE_2D,storage->frame.current_rt->depth);
+ glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->depth);
glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D,composite_from);
+ glBindTexture(GL_TEXTURE_2D, composite_from);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- glBindFramebuffer(GL_FRAMEBUFFER,storage->frame.current_rt->fbo); //copy to front first
+ glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->fbo); //copy to front first
_copy_screen();
-
glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D,storage->frame.current_rt->color);
- state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::DOF_DIR,Vector2(0,1));
- glBindFramebuffer(GL_FRAMEBUFFER,storage->frame.current_rt->effects.mip_maps[0].sizes[0].fbo); // copy to base level
+ glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->color);
+ state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::DOF_DIR, Vector2(0, 1));
+ glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->effects.mip_maps[0].sizes[0].fbo); // copy to base level
_copy_screen();
- state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::DOF_FAR_BLUR,false);
- state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::DOF_FAR_BLUR,false);
- state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::DOF_QUALITY_LOW,false);
- state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::DOF_QUALITY_MEDIUM,false);
- state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::DOF_QUALITY_HIGH,false);
-
-
- composite_from=storage->frame.current_rt->effects.mip_maps[0].color;
+ state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::DOF_FAR_BLUR, false);
+ state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::DOF_FAR_BLUR, false);
+ state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::DOF_QUALITY_LOW, false);
+ state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::DOF_QUALITY_MEDIUM, false);
+ state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::DOF_QUALITY_HIGH, false);
+ composite_from = storage->frame.current_rt->effects.mip_maps[0].color;
}
if (env->dof_blur_near_enabled) {
@@ -3397,59 +3154,56 @@ void RasterizerSceneGLES3::_post_process(Environment *env,const CameraMatrix &p_
int vp_h = storage->frame.current_rt->height;
int vp_w = storage->frame.current_rt->width;
- state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::DOF_NEAR_BLUR,true);
- state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::DOF_NEAR_FIRST_TAP,true);
+ state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::DOF_NEAR_BLUR, true);
+ state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::DOF_NEAR_FIRST_TAP, true);
- state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::DOF_QUALITY_LOW,env->dof_blur_near_quality==VS::ENV_DOF_BLUR_QUALITY_LOW);
- state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::DOF_QUALITY_MEDIUM,env->dof_blur_near_quality==VS::ENV_DOF_BLUR_QUALITY_MEDIUM);
- state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::DOF_QUALITY_HIGH,env->dof_blur_near_quality==VS::ENV_DOF_BLUR_QUALITY_HIGH);
+ state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::DOF_QUALITY_LOW, env->dof_blur_near_quality == VS::ENV_DOF_BLUR_QUALITY_LOW);
+ state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::DOF_QUALITY_MEDIUM, env->dof_blur_near_quality == VS::ENV_DOF_BLUR_QUALITY_MEDIUM);
+ state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::DOF_QUALITY_HIGH, env->dof_blur_near_quality == VS::ENV_DOF_BLUR_QUALITY_HIGH);
state.effect_blur_shader.bind();
- int qsteps[3]={4,10,20};
+ int qsteps[3] = { 4, 10, 20 };
- float radius = (env->dof_blur_near_amount*env->dof_blur_near_amount) / qsteps[env->dof_blur_near_quality];
+ float radius = (env->dof_blur_near_amount * env->dof_blur_near_amount) / qsteps[env->dof_blur_near_quality];
- state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::DOF_BEGIN,env->dof_blur_near_distance);
- state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::DOF_END,env->dof_blur_near_distance-env->dof_blur_near_transition);
- state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::DOF_DIR,Vector2(1,0));
- state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::DOF_RADIUS,radius);
- state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::PIXEL_SIZE,Vector2(1.0/vp_w,1.0/vp_h));
- state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::CAMERA_Z_NEAR,p_cam_projection.get_z_near());
- state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::CAMERA_Z_FAR,p_cam_projection.get_z_far());
+ state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::DOF_BEGIN, env->dof_blur_near_distance);
+ state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::DOF_END, env->dof_blur_near_distance - env->dof_blur_near_transition);
+ state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::DOF_DIR, Vector2(1, 0));
+ state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::DOF_RADIUS, radius);
+ state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::PIXEL_SIZE, Vector2(1.0 / vp_w, 1.0 / vp_h));
+ state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::CAMERA_Z_NEAR, p_cam_projection.get_z_near());
+ state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::CAMERA_Z_FAR, p_cam_projection.get_z_far());
glActiveTexture(GL_TEXTURE1);
- glBindTexture(GL_TEXTURE_2D,storage->frame.current_rt->depth);
+ glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->depth);
glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D,composite_from);
+ glBindTexture(GL_TEXTURE_2D, composite_from);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- glBindFramebuffer(GL_FRAMEBUFFER,storage->frame.current_rt->fbo); //copy to front first
+ glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->fbo); //copy to front first
_copy_screen();
//manually do the blend if this is the first operation resolving from the diffuse buffer
- state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::DOF_NEAR_BLUR_MERGE,composite_from == storage->frame.current_rt->buffers.diffuse);
- state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::DOF_NEAR_FIRST_TAP,false);
+ state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::DOF_NEAR_BLUR_MERGE, composite_from == storage->frame.current_rt->buffers.diffuse);
+ state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::DOF_NEAR_FIRST_TAP, false);
state.effect_blur_shader.bind();
-
-
- state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::DOF_BEGIN,env->dof_blur_near_distance);
- state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::DOF_END,env->dof_blur_near_distance-env->dof_blur_near_transition);
- state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::DOF_DIR,Vector2(0,1));
- state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::DOF_RADIUS,radius);
- state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::PIXEL_SIZE,Vector2(1.0/vp_w,1.0/vp_h));
- state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::CAMERA_Z_NEAR,p_cam_projection.get_z_near());
- state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::CAMERA_Z_FAR,p_cam_projection.get_z_far());
-
+ state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::DOF_BEGIN, env->dof_blur_near_distance);
+ state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::DOF_END, env->dof_blur_near_distance - env->dof_blur_near_transition);
+ state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::DOF_DIR, Vector2(0, 1));
+ state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::DOF_RADIUS, radius);
+ state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::PIXEL_SIZE, Vector2(1.0 / vp_w, 1.0 / vp_h));
+ state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::CAMERA_Z_NEAR, p_cam_projection.get_z_near());
+ state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::CAMERA_Z_FAR, p_cam_projection.get_z_far());
glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D,storage->frame.current_rt->color);
+ glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->color);
- glBindFramebuffer(GL_FRAMEBUFFER,storage->frame.current_rt->effects.mip_maps[0].sizes[0].fbo); // copy to base level
+ glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->effects.mip_maps[0].sizes[0].fbo); // copy to base level
if (composite_from != storage->frame.current_rt->buffers.diffuse) {
@@ -3459,8 +3213,7 @@ void RasterizerSceneGLES3::_post_process(Environment *env,const CameraMatrix &p_
} else {
glActiveTexture(GL_TEXTURE2);
- glBindTexture(GL_TEXTURE_2D,storage->frame.current_rt->buffers.diffuse);
-
+ glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->buffers.diffuse);
}
_copy_screen();
@@ -3470,302 +3223,270 @@ void RasterizerSceneGLES3::_post_process(Environment *env,const CameraMatrix &p_
glDisable(GL_BLEND);
}
- state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::DOF_NEAR_BLUR,false);
- state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::DOF_NEAR_FIRST_TAP,false);
- state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::DOF_NEAR_BLUR_MERGE,false);
- state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::DOF_QUALITY_LOW,false);
- state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::DOF_QUALITY_MEDIUM,false);
- state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::DOF_QUALITY_HIGH,false);
-
-
- composite_from=storage->frame.current_rt->effects.mip_maps[0].color;
+ state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::DOF_NEAR_BLUR, false);
+ state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::DOF_NEAR_FIRST_TAP, false);
+ state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::DOF_NEAR_BLUR_MERGE, false);
+ state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::DOF_QUALITY_LOW, false);
+ state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::DOF_QUALITY_MEDIUM, false);
+ state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::DOF_QUALITY_HIGH, false);
+ composite_from = storage->frame.current_rt->effects.mip_maps[0].color;
}
- if ( env->auto_exposure) {
+ if (env->auto_exposure) {
//compute auto exposure
//first step, copy from image to luminance buffer
- state.exposure_shader.set_conditional(ExposureShaderGLES3::EXPOSURE_BEGIN,true);
+ state.exposure_shader.set_conditional(ExposureShaderGLES3::EXPOSURE_BEGIN, true);
state.exposure_shader.bind();
- int ss[2]={
+ int ss[2] = {
storage->frame.current_rt->width,
storage->frame.current_rt->height,
};
- int ds[2]={
+ int ds[2] = {
exposure_shrink_size,
exposure_shrink_size,
};
- glUniform2iv(state.exposure_shader.get_uniform(ExposureShaderGLES3::SOURCE_RENDER_SIZE),1,ss);
- glUniform2iv(state.exposure_shader.get_uniform(ExposureShaderGLES3::TARGET_SIZE),1,ds);
+ glUniform2iv(state.exposure_shader.get_uniform(ExposureShaderGLES3::SOURCE_RENDER_SIZE), 1, ss);
+ glUniform2iv(state.exposure_shader.get_uniform(ExposureShaderGLES3::TARGET_SIZE), 1, ds);
glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D,storage->frame.current_rt->buffers.diffuse);
+ glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->buffers.diffuse);
-
- glBindFramebuffer(GL_FRAMEBUFFER,exposure_shrink[0].fbo);
- glViewport(0,0,exposure_shrink_size,exposure_shrink_size);
+ glBindFramebuffer(GL_FRAMEBUFFER, exposure_shrink[0].fbo);
+ glViewport(0, 0, exposure_shrink_size, exposure_shrink_size);
_copy_screen();
-
-
-
-
//second step, shrink to 2x2 pixels
- state.exposure_shader.set_conditional(ExposureShaderGLES3::EXPOSURE_BEGIN,false);
+ state.exposure_shader.set_conditional(ExposureShaderGLES3::EXPOSURE_BEGIN, false);
state.exposure_shader.bind();
//shrink from second to previous to last level
- int s_size=exposure_shrink_size/3;
- for(int i=1;i<exposure_shrink.size()-1;i++) {
+ int s_size = exposure_shrink_size / 3;
+ for (int i = 1; i < exposure_shrink.size() - 1; i++) {
- glBindFramebuffer(GL_FRAMEBUFFER,exposure_shrink[i].fbo);
+ glBindFramebuffer(GL_FRAMEBUFFER, exposure_shrink[i].fbo);
glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D,exposure_shrink[i-1].color);
+ glBindTexture(GL_TEXTURE_2D, exposure_shrink[i - 1].color);
_copy_screen();
- glViewport(0,0,s_size,s_size);
-
- s_size/=3;
+ glViewport(0, 0, s_size, s_size);
+ s_size /= 3;
}
//third step, shrink to 1x1 pixel taking in consideration the previous exposure
- state.exposure_shader.set_conditional(ExposureShaderGLES3::EXPOSURE_END,true);
+ state.exposure_shader.set_conditional(ExposureShaderGLES3::EXPOSURE_END, true);
uint64_t tick = OS::get_singleton()->get_ticks_usec();
- uint64_t tick_diff = storage->frame.current_rt->last_exposure_tick==0?0:tick-storage->frame.current_rt->last_exposure_tick;
- storage->frame.current_rt->last_exposure_tick=tick;
-
- if (tick_diff==0 || tick_diff>1000000) {
- state.exposure_shader.set_conditional(ExposureShaderGLES3::EXPOSURE_FORCE_SET,true);
+ uint64_t tick_diff = storage->frame.current_rt->last_exposure_tick == 0 ? 0 : tick - storage->frame.current_rt->last_exposure_tick;
+ storage->frame.current_rt->last_exposure_tick = tick;
+ if (tick_diff == 0 || tick_diff > 1000000) {
+ state.exposure_shader.set_conditional(ExposureShaderGLES3::EXPOSURE_FORCE_SET, true);
}
state.exposure_shader.bind();
- glBindFramebuffer(GL_FRAMEBUFFER,exposure_shrink[exposure_shrink.size()-1].fbo);
- glViewport(0,0,1,1);
+ glBindFramebuffer(GL_FRAMEBUFFER, exposure_shrink[exposure_shrink.size() - 1].fbo);
+ glViewport(0, 0, 1, 1);
glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D,exposure_shrink[exposure_shrink.size()-2].color);
+ glBindTexture(GL_TEXTURE_2D, exposure_shrink[exposure_shrink.size() - 2].color);
glActiveTexture(GL_TEXTURE1);
- glBindTexture(GL_TEXTURE_2D,storage->frame.current_rt->exposure.color); //read from previous
-
+ glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->exposure.color); //read from previous
- state.exposure_shader.set_uniform(ExposureShaderGLES3::EXPOSURE_ADJUST,env->auto_exposure_speed*(tick_diff/1000000.0));
- state.exposure_shader.set_uniform(ExposureShaderGLES3::MAX_LUMINANCE,env->auto_exposure_max);
- state.exposure_shader.set_uniform(ExposureShaderGLES3::MIN_LUMINANCE,env->auto_exposure_min);
+ state.exposure_shader.set_uniform(ExposureShaderGLES3::EXPOSURE_ADJUST, env->auto_exposure_speed * (tick_diff / 1000000.0));
+ state.exposure_shader.set_uniform(ExposureShaderGLES3::MAX_LUMINANCE, env->auto_exposure_max);
+ state.exposure_shader.set_uniform(ExposureShaderGLES3::MIN_LUMINANCE, env->auto_exposure_min);
_copy_screen();
- state.exposure_shader.set_conditional(ExposureShaderGLES3::EXPOSURE_FORCE_SET,false);
- state.exposure_shader.set_conditional(ExposureShaderGLES3::EXPOSURE_END,false);
+ state.exposure_shader.set_conditional(ExposureShaderGLES3::EXPOSURE_FORCE_SET, false);
+ state.exposure_shader.set_conditional(ExposureShaderGLES3::EXPOSURE_END, false);
//last step, swap with the framebuffer exposure, so the right exposure is kept int he framebuffer
- SWAP(exposure_shrink[exposure_shrink.size()-1].fbo,storage->frame.current_rt->exposure.fbo);
- SWAP(exposure_shrink[exposure_shrink.size()-1].color,storage->frame.current_rt->exposure.color);
-
-
- glViewport(0,0,storage->frame.current_rt->width,storage->frame.current_rt->height);
+ SWAP(exposure_shrink[exposure_shrink.size() - 1].fbo, storage->frame.current_rt->exposure.fbo);
+ SWAP(exposure_shrink[exposure_shrink.size() - 1].color, storage->frame.current_rt->exposure.color);
+ glViewport(0, 0, storage->frame.current_rt->width, storage->frame.current_rt->height);
}
-
- int max_glow_level=-1;
- int glow_mask=0;
-
+ int max_glow_level = -1;
+ int glow_mask = 0;
if (env->glow_enabled) {
+ for (int i = 0; i < VS::MAX_GLOW_LEVELS; i++) {
+ if (env->glow_levels & (1 << i)) {
- for(int i=0;i<VS::MAX_GLOW_LEVELS;i++) {
- if (env->glow_levels&(1<<i)) {
-
- if (i>=storage->frame.current_rt->effects.mip_maps[1].sizes.size()) {
- max_glow_level=storage->frame.current_rt->effects.mip_maps[1].sizes.size()-1;
- glow_mask|=1<<max_glow_level;
+ if (i >= storage->frame.current_rt->effects.mip_maps[1].sizes.size()) {
+ max_glow_level = storage->frame.current_rt->effects.mip_maps[1].sizes.size() - 1;
+ glow_mask |= 1 << max_glow_level;
} else {
- max_glow_level=i;
- glow_mask|=(1<<i);
+ max_glow_level = i;
+ glow_mask |= (1 << i);
}
-
}
}
-
//blur diffuse into effect mipmaps using separatable convolution
//storage->shaders.copy.set_conditional(CopyShaderGLES3::GAUSSIAN_HORIZONTAL,true);
- for(int i=0;i<(max_glow_level+1);i++) {
-
+ for (int i = 0; i < (max_glow_level + 1); i++) {
int vp_w = storage->frame.current_rt->effects.mip_maps[1].sizes[i].width;
int vp_h = storage->frame.current_rt->effects.mip_maps[1].sizes[i].height;
- glViewport(0,0,vp_w,vp_h);
+ glViewport(0, 0, vp_w, vp_h);
//horizontal pass
- if (i==0) {
- state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::GLOW_FIRST_PASS,true);
- state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::GLOW_USE_AUTO_EXPOSURE,env->auto_exposure);
+ if (i == 0) {
+ state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::GLOW_FIRST_PASS, true);
+ state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::GLOW_USE_AUTO_EXPOSURE, env->auto_exposure);
}
- state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::GLOW_GAUSSIAN_HORIZONTAL,true);
+ state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::GLOW_GAUSSIAN_HORIZONTAL, true);
state.effect_blur_shader.bind();
- state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::PIXEL_SIZE,Vector2(1.0/vp_w,1.0/vp_h));
- state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::LOD,float(i));
- state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::GLOW_STRENGTH,env->glow_strength);
+ state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::PIXEL_SIZE, Vector2(1.0 / vp_w, 1.0 / vp_h));
+ state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::LOD, float(i));
+ state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::GLOW_STRENGTH, env->glow_strength);
glActiveTexture(GL_TEXTURE0);
- if (i==0) {
- glBindTexture(GL_TEXTURE_2D,composite_from);
+ if (i == 0) {
+ glBindTexture(GL_TEXTURE_2D, composite_from);
- state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::EXPOSURE,env->tone_mapper_exposure);
+ state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::EXPOSURE, env->tone_mapper_exposure);
if (env->auto_exposure) {
- state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::AUTO_EXPOSURE_GREY,env->auto_exposure_grey);
+ state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::AUTO_EXPOSURE_GREY, env->auto_exposure_grey);
}
glActiveTexture(GL_TEXTURE1);
- glBindTexture(GL_TEXTURE_2D,storage->frame.current_rt->exposure.color);
+ glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->exposure.color);
- state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::GLOW_BLOOM,env->glow_bloom);
- state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::GLOW_HDR_TRESHOLD,env->glow_hdr_bleed_treshold);
- state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::GLOW_HDR_SCALE,env->glow_hdr_bleed_scale);
+ state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::GLOW_BLOOM, env->glow_bloom);
+ state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::GLOW_HDR_TRESHOLD, env->glow_hdr_bleed_treshold);
+ state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::GLOW_HDR_SCALE, env->glow_hdr_bleed_scale);
} else {
- glBindTexture(GL_TEXTURE_2D,storage->frame.current_rt->effects.mip_maps[0].color); //previous level, since mipmaps[0] starts one level bigger
+ glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->effects.mip_maps[0].color); //previous level, since mipmaps[0] starts one level bigger
}
- glBindFramebuffer(GL_FRAMEBUFFER,storage->frame.current_rt->effects.mip_maps[1].sizes[i].fbo);
+ glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->effects.mip_maps[1].sizes[i].fbo);
_copy_screen();
- state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::GLOW_GAUSSIAN_HORIZONTAL,false);
- state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::GLOW_FIRST_PASS,false);
- state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::GLOW_USE_AUTO_EXPOSURE,false);
+ state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::GLOW_GAUSSIAN_HORIZONTAL, false);
+ state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::GLOW_FIRST_PASS, false);
+ state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::GLOW_USE_AUTO_EXPOSURE, false);
//vertical pass
- state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::GLOW_GAUSSIAN_VERTICAL,true);
+ state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::GLOW_GAUSSIAN_VERTICAL, true);
state.effect_blur_shader.bind();
- state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::PIXEL_SIZE,Vector2(1.0/vp_w,1.0/vp_h));
- state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::LOD,float(i));
- state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::GLOW_STRENGTH,env->glow_strength);
+ state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::PIXEL_SIZE, Vector2(1.0 / vp_w, 1.0 / vp_h));
+ state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::LOD, float(i));
+ state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::GLOW_STRENGTH, env->glow_strength);
glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D,storage->frame.current_rt->effects.mip_maps[1].color);
- glBindFramebuffer(GL_FRAMEBUFFER,storage->frame.current_rt->effects.mip_maps[0].sizes[i+1].fbo); //next level, since mipmaps[0] starts one level bigger
+ glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->effects.mip_maps[1].color);
+ glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->effects.mip_maps[0].sizes[i + 1].fbo); //next level, since mipmaps[0] starts one level bigger
_copy_screen();
- state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::GLOW_GAUSSIAN_VERTICAL,false);
+ state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::GLOW_GAUSSIAN_VERTICAL, false);
}
- glViewport(0,0,storage->frame.current_rt->width,storage->frame.current_rt->height);
-
+ glViewport(0, 0, storage->frame.current_rt->width, storage->frame.current_rt->height);
}
-
-
-
- glBindFramebuffer(GL_FRAMEBUFFER,storage->frame.current_rt->fbo);
+ glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->fbo);
glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D,composite_from);
-
- state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_FILMIC_TONEMAPPER,env->tone_mapper==VS::ENV_TONE_MAPPER_FILMIC);
- state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_ACES_TONEMAPPER,env->tone_mapper==VS::ENV_TONE_MAPPER_ACES);
- state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_REINDHART_TONEMAPPER,env->tone_mapper==VS::ENV_TONE_MAPPER_REINHARDT);
+ glBindTexture(GL_TEXTURE_2D, composite_from);
- state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_AUTO_EXPOSURE,env->auto_exposure);
- state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_GLOW_FILTER_BICUBIC,env->glow_bicubic_upscale);
+ state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_FILMIC_TONEMAPPER, env->tone_mapper == VS::ENV_TONE_MAPPER_FILMIC);
+ state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_ACES_TONEMAPPER, env->tone_mapper == VS::ENV_TONE_MAPPER_ACES);
+ state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_REINDHART_TONEMAPPER, env->tone_mapper == VS::ENV_TONE_MAPPER_REINHARDT);
+ state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_AUTO_EXPOSURE, env->auto_exposure);
+ state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_GLOW_FILTER_BICUBIC, env->glow_bicubic_upscale);
+ if (max_glow_level >= 0) {
- if (max_glow_level>=0) {
+ for (int i = 0; i < (max_glow_level + 1); i++) {
-
- for(int i=0;i<(max_glow_level+1);i++) {
-
- if (glow_mask&(1<<i)) {
- if (i==0) {
- state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_GLOW_LEVEL1,true);
+ if (glow_mask & (1 << i)) {
+ if (i == 0) {
+ state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_GLOW_LEVEL1, true);
}
- if (i==1) {
- state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_GLOW_LEVEL2,true);
+ if (i == 1) {
+ state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_GLOW_LEVEL2, true);
}
- if (i==2) {
- state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_GLOW_LEVEL3,true);
+ if (i == 2) {
+ state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_GLOW_LEVEL3, true);
}
- if (i==3) {
- state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_GLOW_LEVEL4,true);
+ if (i == 3) {
+ state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_GLOW_LEVEL4, true);
}
- if (i==4) {
- state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_GLOW_LEVEL5,true);
+ if (i == 4) {
+ state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_GLOW_LEVEL5, true);
}
- if (i==5) {
- state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_GLOW_LEVEL6,true);
+ if (i == 5) {
+ state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_GLOW_LEVEL6, true);
}
- if (i==6) {
- state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_GLOW_LEVEL7,true);
+ if (i == 6) {
+ state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_GLOW_LEVEL7, true);
}
}
}
- state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_GLOW_SCREEN,env->glow_blend_mode==VS::GLOW_BLEND_MODE_SCREEN);
- state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_GLOW_SOFTLIGHT,env->glow_blend_mode==VS::GLOW_BLEND_MODE_SOFTLIGHT);
- state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_GLOW_REPLACE,env->glow_blend_mode==VS::GLOW_BLEND_MODE_REPLACE);
+ state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_GLOW_SCREEN, env->glow_blend_mode == VS::GLOW_BLEND_MODE_SCREEN);
+ state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_GLOW_SOFTLIGHT, env->glow_blend_mode == VS::GLOW_BLEND_MODE_SOFTLIGHT);
+ state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_GLOW_REPLACE, env->glow_blend_mode == VS::GLOW_BLEND_MODE_REPLACE);
glActiveTexture(GL_TEXTURE2);
- glBindTexture(GL_TEXTURE_2D,storage->frame.current_rt->effects.mip_maps[0].color);
-
+ glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->effects.mip_maps[0].color);
}
state.tonemap_shader.bind();
- state.tonemap_shader.set_uniform(TonemapShaderGLES3::EXPOSURE,env->tone_mapper_exposure);
- state.tonemap_shader.set_uniform(TonemapShaderGLES3::WHITE,env->tone_mapper_exposure_white);
+ state.tonemap_shader.set_uniform(TonemapShaderGLES3::EXPOSURE, env->tone_mapper_exposure);
+ state.tonemap_shader.set_uniform(TonemapShaderGLES3::WHITE, env->tone_mapper_exposure_white);
- if (max_glow_level>=0) {
+ if (max_glow_level >= 0) {
- state.tonemap_shader.set_uniform(TonemapShaderGLES3::GLOW_INTENSITY,env->glow_intensity);
- int ss[2]={
+ state.tonemap_shader.set_uniform(TonemapShaderGLES3::GLOW_INTENSITY, env->glow_intensity);
+ int ss[2] = {
storage->frame.current_rt->width,
storage->frame.current_rt->height,
};
- glUniform2iv(state.tonemap_shader.get_uniform(TonemapShaderGLES3::GLOW_TEXTURE_SIZE),1,ss);
-
+ glUniform2iv(state.tonemap_shader.get_uniform(TonemapShaderGLES3::GLOW_TEXTURE_SIZE), 1, ss);
}
- if (env->auto_exposure) {
+ if (env->auto_exposure) {
glActiveTexture(GL_TEXTURE1);
- glBindTexture(GL_TEXTURE_2D,storage->frame.current_rt->exposure.color);
- state.tonemap_shader.set_uniform(TonemapShaderGLES3::AUTO_EXPOSURE_GREY,env->auto_exposure_grey);
-
+ glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->exposure.color);
+ state.tonemap_shader.set_uniform(TonemapShaderGLES3::AUTO_EXPOSURE_GREY, env->auto_exposure_grey);
}
-
-
_copy_screen();
//turn off everything used
- state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_AUTO_EXPOSURE,false);
- state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_FILMIC_TONEMAPPER,false);
- state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_ACES_TONEMAPPER,false);
- state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_REINDHART_TONEMAPPER,false);
- state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_GLOW_LEVEL1,false);
- state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_GLOW_LEVEL2,false);
- state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_GLOW_LEVEL3,false);
- state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_GLOW_LEVEL4,false);
- state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_GLOW_LEVEL5,false);
- state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_GLOW_LEVEL6,false);
- state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_GLOW_LEVEL7,false);
- state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_GLOW_REPLACE,false);
- state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_GLOW_SCREEN,false);
- state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_GLOW_SOFTLIGHT,false);
- state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_GLOW_FILTER_BICUBIC,false);
-
+ state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_AUTO_EXPOSURE, false);
+ state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_FILMIC_TONEMAPPER, false);
+ state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_ACES_TONEMAPPER, false);
+ state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_REINDHART_TONEMAPPER, false);
+ state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_GLOW_LEVEL1, false);
+ state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_GLOW_LEVEL2, false);
+ state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_GLOW_LEVEL3, false);
+ state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_GLOW_LEVEL4, false);
+ state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_GLOW_LEVEL5, false);
+ state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_GLOW_LEVEL6, false);
+ state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_GLOW_LEVEL7, false);
+ state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_GLOW_REPLACE, false);
+ state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_GLOW_SCREEN, false);
+ state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_GLOW_SOFTLIGHT, false);
+ state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_GLOW_FILTER_BICUBIC, false);
}
-void RasterizerSceneGLES3::render_scene(const Transform& p_cam_transform,const CameraMatrix& p_cam_projection,bool p_cam_ortogonal,InstanceBase** p_cull_result,int p_cull_count,RID* p_light_cull_result,int p_light_cull_count,RID* p_reflection_probe_cull_result,int p_reflection_probe_cull_count,RID p_environment,RID p_shadow_atlas,RID p_reflection_atlas,RID p_reflection_probe,int p_reflection_probe_pass){
+void RasterizerSceneGLES3::render_scene(const Transform &p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_ortogonal, InstanceBase **p_cull_result, int p_cull_count, RID *p_light_cull_result, int p_light_cull_count, RID *p_reflection_probe_cull_result, int p_reflection_probe_cull_count, RID p_environment, RID p_shadow_atlas, RID p_reflection_atlas, RID p_reflection_probe, int p_reflection_probe_pass) {
//first of all, make a new render pass
render_pass++;
-
//fill up ubo
Environment *env = environment_owner.getornull(p_environment);
@@ -3773,73 +3494,69 @@ void RasterizerSceneGLES3::render_scene(const Transform& p_cam_transform,const C
ReflectionAtlas *reflection_atlas = reflection_atlas_owner.getornull(p_reflection_atlas);
if (shadow_atlas && shadow_atlas->size) {
- glActiveTexture(GL_TEXTURE0+storage->config.max_texture_image_units-3);
- glBindTexture(GL_TEXTURE_2D,shadow_atlas->depth);
+ glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 3);
+ glBindTexture(GL_TEXTURE_2D, shadow_atlas->depth);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LESS);
- state.ubo_data.shadow_atlas_pixel_size[0]=1.0/shadow_atlas->size;
- state.ubo_data.shadow_atlas_pixel_size[1]=1.0/shadow_atlas->size;
+ state.ubo_data.shadow_atlas_pixel_size[0] = 1.0 / shadow_atlas->size;
+ state.ubo_data.shadow_atlas_pixel_size[1] = 1.0 / shadow_atlas->size;
}
-
if (reflection_atlas && reflection_atlas->size) {
- glActiveTexture(GL_TEXTURE0+storage->config.max_texture_image_units-5);
- glBindTexture(GL_TEXTURE_2D,reflection_atlas->color);
+ glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 5);
+ glBindTexture(GL_TEXTURE_2D, reflection_atlas->color);
}
if (p_reflection_probe.is_valid()) {
- state.ubo_data.reflection_multiplier=0.0;
+ state.ubo_data.reflection_multiplier = 0.0;
} else {
- state.ubo_data.reflection_multiplier=1.0;
+ state.ubo_data.reflection_multiplier = 1.0;
}
- state.ubo_data.subsurface_scatter_width=subsurface_scatter_size;
+ state.ubo_data.subsurface_scatter_width = subsurface_scatter_size;
-
- state.ubo_data.shadow_z_offset=0;
- state.ubo_data.shadow_slope_scale=0;
- state.ubo_data.shadow_dual_paraboloid_render_side=0;
- state.ubo_data.shadow_dual_paraboloid_render_zfar=0;
+ state.ubo_data.shadow_z_offset = 0;
+ state.ubo_data.shadow_slope_scale = 0;
+ state.ubo_data.shadow_dual_paraboloid_render_side = 0;
+ state.ubo_data.shadow_dual_paraboloid_render_zfar = 0;
if (storage->frame.current_rt) {
- state.ubo_data.screen_pixel_size[0]=1.0/storage->frame.current_rt->width;
- state.ubo_data.screen_pixel_size[1]=1.0/storage->frame.current_rt->height;
+ state.ubo_data.screen_pixel_size[0] = 1.0 / storage->frame.current_rt->width;
+ state.ubo_data.screen_pixel_size[1] = 1.0 / storage->frame.current_rt->height;
}
- _setup_environment(env,p_cam_projection,p_cam_transform);
+ _setup_environment(env, p_cam_projection, p_cam_transform);
- bool fb_cleared=false;
+ bool fb_cleared = false;
glDepthFunc(GL_LEQUAL);
- state.used_contact_shadows=true;
+ state.used_contact_shadows = true;
- if ( storage->frame.current_rt && true) { //detect with state.used_contact_shadows too
+ if (storage->frame.current_rt && true) { //detect with state.used_contact_shadows too
//pre z pass
-
glDisable(GL_BLEND);
glDepthMask(GL_TRUE);
glEnable(GL_DEPTH_TEST);
glDisable(GL_SCISSOR_TEST);
- glBindFramebuffer(GL_FRAMEBUFFER,storage->frame.current_rt->buffers.fbo);
- glDrawBuffers(0,NULL);
+ glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->buffers.fbo);
+ glDrawBuffers(0, NULL);
- glViewport(0,0,storage->frame.current_rt->width,storage->frame.current_rt->height);
+ glViewport(0, 0, storage->frame.current_rt->width, storage->frame.current_rt->height);
- glColorMask(0,0,0,0);
+ glColorMask(0, 0, 0, 0);
glClearDepth(1.0f);
glClear(GL_DEPTH_BUFFER_BIT);
-
render_list.clear();
- _fill_render_list(p_cull_result,p_cull_count,true);
+ _fill_render_list(p_cull_result, p_cull_count, true);
render_list.sort_by_depth(false);
- state.scene_shader.set_conditional(SceneShaderGLES3::RENDER_DEPTH,true);
- _render_list(render_list.elements,render_list.element_count,p_cam_transform,p_cam_projection,0,false,false,true,false,false);
- state.scene_shader.set_conditional(SceneShaderGLES3::RENDER_DEPTH,false);
+ state.scene_shader.set_conditional(SceneShaderGLES3::RENDER_DEPTH, true);
+ _render_list(render_list.elements, render_list.element_count, p_cam_transform, p_cam_projection, 0, false, false, true, false, false);
+ state.scene_shader.set_conditional(SceneShaderGLES3::RENDER_DEPTH, false);
- glColorMask(1,1,1,1);
+ glColorMask(1, 1, 1, 1);
if (state.used_contact_shadows) {
@@ -3850,28 +3567,24 @@ void RasterizerSceneGLES3::render_scene(const Transform& p_cam_transform,const C
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
//bind depth for read
- glActiveTexture(GL_TEXTURE0+storage->config.max_texture_image_units-8);
- glBindTexture(GL_TEXTURE_2D,storage->frame.current_rt->depth);
+ glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 8);
+ glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->depth);
}
- fb_cleared=true;
+ fb_cleared = true;
render_pass++;
}
-
- _setup_lights(p_light_cull_result,p_light_cull_count,p_cam_transform.affine_inverse(),p_cam_projection,p_shadow_atlas);
- _setup_reflections(p_reflection_probe_cull_result,p_reflection_probe_cull_count,p_cam_transform.affine_inverse(),p_cam_projection,p_reflection_atlas,env);
+ _setup_lights(p_light_cull_result, p_light_cull_count, p_cam_transform.affine_inverse(), p_cam_projection, p_shadow_atlas);
+ _setup_reflections(p_reflection_probe_cull_result, p_reflection_probe_cull_count, p_cam_transform.affine_inverse(), p_cam_projection, p_reflection_atlas, env);
render_list.clear();
+ bool use_mrt = false;
- bool use_mrt=false;
-
-
- _fill_render_list(p_cull_result,p_cull_count,false);
+ _fill_render_list(p_cull_result, p_cull_count, false);
//
-
glEnable(GL_BLEND);
glDepthMask(GL_TRUE);
glEnable(GL_DEPTH_TEST);
@@ -3881,45 +3594,42 @@ void RasterizerSceneGLES3::render_scene(const Transform& p_cam_transform,const C
ReflectionProbeInstance *probe = reflection_probe_instance_owner.getornull(p_reflection_probe);
GLuint current_fbo;
-
-
if (probe) {
ReflectionAtlas *ref_atlas = reflection_atlas_owner.getptr(probe->atlas);
ERR_FAIL_COND(!ref_atlas);
- int target_size=ref_atlas->size/ref_atlas->subdiv;
+ int target_size = ref_atlas->size / ref_atlas->subdiv;
- int cubemap_index=reflection_cubemaps.size()-1;
+ int cubemap_index = reflection_cubemaps.size() - 1;
- for(int i=reflection_cubemaps.size()-1;i>=0;i--) {
+ for (int i = reflection_cubemaps.size() - 1; i >= 0; i--) {
//find appropriate cubemap to render to
- if (reflection_cubemaps[i].size>target_size*2)
+ if (reflection_cubemaps[i].size > target_size * 2)
break;
- cubemap_index=i;
+ cubemap_index = i;
}
- current_fbo=reflection_cubemaps[cubemap_index].fbo_id[p_reflection_probe_pass];
- use_mrt=false;
- state.scene_shader.set_conditional(SceneShaderGLES3::USE_MULTIPLE_RENDER_TARGETS,false);
+ current_fbo = reflection_cubemaps[cubemap_index].fbo_id[p_reflection_probe_pass];
+ use_mrt = false;
+ state.scene_shader.set_conditional(SceneShaderGLES3::USE_MULTIPLE_RENDER_TARGETS, false);
- glViewport(0,0,reflection_cubemaps[cubemap_index].size,reflection_cubemaps[cubemap_index].size);
- glBindFramebuffer(GL_FRAMEBUFFER,current_fbo);
+ glViewport(0, 0, reflection_cubemaps[cubemap_index].size, reflection_cubemaps[cubemap_index].size);
+ glBindFramebuffer(GL_FRAMEBUFFER, current_fbo);
} else {
use_mrt = state.used_sss || (env && (env->ssao_enabled || env->ssr_enabled)); //only enable MRT rendering if any of these is enabled
- glViewport(0,0,storage->frame.current_rt->width,storage->frame.current_rt->height);
+ glViewport(0, 0, storage->frame.current_rt->width, storage->frame.current_rt->height);
if (use_mrt) {
- current_fbo=storage->frame.current_rt->buffers.fbo;
-
- glBindFramebuffer(GL_FRAMEBUFFER,storage->frame.current_rt->buffers.fbo);
- state.scene_shader.set_conditional(SceneShaderGLES3::USE_MULTIPLE_RENDER_TARGETS,true);
+ current_fbo = storage->frame.current_rt->buffers.fbo;
+ glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->buffers.fbo);
+ state.scene_shader.set_conditional(SceneShaderGLES3::USE_MULTIPLE_RENDER_TARGETS, true);
Vector<GLenum> draw_buffers;
draw_buffers.push_back(GL_COLOR_ATTACHMENT0);
@@ -3928,27 +3638,24 @@ void RasterizerSceneGLES3::render_scene(const Transform& p_cam_transform,const C
if (state.used_sss) {
draw_buffers.push_back(GL_COLOR_ATTACHMENT3);
}
- glDrawBuffers(draw_buffers.size(),draw_buffers.ptr());
+ glDrawBuffers(draw_buffers.size(), draw_buffers.ptr());
- Color black(0,0,0,0);
- glClearBufferfv(GL_COLOR,1,black.components); // specular
- glClearBufferfv(GL_COLOR,2,black.components); // normal metal rough
+ Color black(0, 0, 0, 0);
+ glClearBufferfv(GL_COLOR, 1, black.components); // specular
+ glClearBufferfv(GL_COLOR, 2, black.components); // normal metal rough
if (state.used_sss) {
- glClearBufferfv(GL_COLOR,3,black.components); // normal metal rough
+ glClearBufferfv(GL_COLOR, 3, black.components); // normal metal rough
}
} else {
-
-
current_fbo = storage->frame.current_rt->buffers.fbo;
- glBindFramebuffer(GL_FRAMEBUFFER,storage->frame.current_rt->buffers.fbo);
- state.scene_shader.set_conditional(SceneShaderGLES3::USE_MULTIPLE_RENDER_TARGETS,false);
+ glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->buffers.fbo);
+ state.scene_shader.set_conditional(SceneShaderGLES3::USE_MULTIPLE_RENDER_TARGETS, false);
Vector<GLenum> draw_buffers;
draw_buffers.push_back(GL_COLOR_ATTACHMENT0);
- glDrawBuffers(draw_buffers.size(),draw_buffers.ptr());
-
+ glDrawBuffers(draw_buffers.size(), draw_buffers.ptr());
}
}
@@ -3957,41 +3664,39 @@ void RasterizerSceneGLES3::render_scene(const Transform& p_cam_transform,const C
glClear(GL_DEPTH_BUFFER_BIT);
}
- Color clear_color(0,0,0,0);
+ Color clear_color(0, 0, 0, 0);
- RasterizerStorageGLES3::SkyBox *skybox=NULL;
- GLuint env_radiance_tex=0;
+ RasterizerStorageGLES3::SkyBox *skybox = NULL;
+ GLuint env_radiance_tex = 0;
- if (!env || env->bg_mode==VS::ENV_BG_CLEAR_COLOR) {
+ if (!env || env->bg_mode == VS::ENV_BG_CLEAR_COLOR) {
if (storage->frame.clear_request) {
clear_color = storage->frame.clear_request_color.to_linear();
- storage->frame.clear_request=false;
-
+ storage->frame.clear_request = false;
}
- } else if (env->bg_mode==VS::ENV_BG_COLOR) {
+ } else if (env->bg_mode == VS::ENV_BG_COLOR) {
clear_color = env->bg_color.to_linear();
- storage->frame.clear_request=false;
- } else if (env->bg_mode==VS::ENV_BG_SKYBOX) {
+ storage->frame.clear_request = false;
+ } else if (env->bg_mode == VS::ENV_BG_SKYBOX) {
skybox = storage->skybox_owner.getornull(env->skybox);
if (skybox) {
- env_radiance_tex=skybox->radiance;
+ env_radiance_tex = skybox->radiance;
}
- storage->frame.clear_request=false;
+ storage->frame.clear_request = false;
} else {
- storage->frame.clear_request=false;
+ storage->frame.clear_request = false;
}
- glClearBufferfv(GL_COLOR,0,clear_color.components); // specular
-
+ glClearBufferfv(GL_COLOR, 0, clear_color.components); // specular
- state.texscreen_copied=false;
+ state.texscreen_copied = false;
glBlendEquation(GL_FUNC_ADD);
@@ -4011,53 +3716,44 @@ void RasterizerSceneGLES3::render_scene(const Transform& p_cam_transform,const C
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
-
-
- if (state.directional_light_count==0) {
- directional_light=NULL;
- _render_list(render_list.elements,render_list.element_count,p_cam_transform,p_cam_projection,env_radiance_tex,false,false,false,false,shadow_atlas!=NULL);
+ if (state.directional_light_count == 0) {
+ directional_light = NULL;
+ _render_list(render_list.elements, render_list.element_count, p_cam_transform, p_cam_projection, env_radiance_tex, false, false, false, false, shadow_atlas != NULL);
} else {
- for(int i=0;i<state.directional_light_count;i++) {
- directional_light=directional_lights[i];
- if (i>0) {
+ for (int i = 0; i < state.directional_light_count; i++) {
+ directional_light = directional_lights[i];
+ if (i > 0) {
glEnable(GL_BLEND);
}
- _setup_directional_light(i,p_cam_transform.affine_inverse(),shadow_atlas!=NULL);
- _render_list(render_list.elements,render_list.element_count,p_cam_transform,p_cam_projection,env_radiance_tex,false,false,false,i>0,shadow_atlas!=NULL);
-
+ _setup_directional_light(i, p_cam_transform.affine_inverse(), shadow_atlas != NULL);
+ _render_list(render_list.elements, render_list.element_count, p_cam_transform, p_cam_projection, env_radiance_tex, false, false, false, i > 0, shadow_atlas != NULL);
}
}
-
- state.scene_shader.set_conditional(SceneShaderGLES3::USE_MULTIPLE_RENDER_TARGETS,false);
+ state.scene_shader.set_conditional(SceneShaderGLES3::USE_MULTIPLE_RENDER_TARGETS, false);
if (use_mrt) {
GLenum gldb = GL_COLOR_ATTACHMENT0;
- glDrawBuffers(1,&gldb);
+ glDrawBuffers(1, &gldb);
}
- if (env && env->bg_mode==VS::ENV_BG_SKYBOX) {
+ if (env && env->bg_mode == VS::ENV_BG_SKYBOX) {
/*
if (use_mrt) {
glBindFramebuffer(GL_FRAMEBUFFER,storage->frame.current_rt->buffers.fbo); //switch to alpha fbo for skybox, only diffuse/ambient matters
*/
- _draw_skybox(skybox,p_cam_projection,p_cam_transform,storage->frame.current_rt && storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_VFLIP],env->skybox_scale);
+ _draw_skybox(skybox, p_cam_projection, p_cam_transform, storage->frame.current_rt && storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_VFLIP], env->skybox_scale);
}
-
-
-
-
//_render_list_forward(&alpha_render_list,camera_transform,camera_transform_inverse,camera_projection,false,fragment_lighting,true);
//glColorMask(1,1,1,1);
//state.scene_shader.set_conditional( SceneShaderGLES3::USE_FOG,false);
-
if (use_mrt) {
- _render_mrts(env,p_cam_projection);
+ _render_mrts(env, p_cam_projection);
}
glEnable(GL_BLEND);
@@ -4067,15 +3763,14 @@ void RasterizerSceneGLES3::render_scene(const Transform& p_cam_transform,const C
render_list.sort_by_depth(true);
- if (state.directional_light_count==0) {
- directional_light=NULL;
- _render_list(&render_list.elements[render_list.max_elements-render_list.alpha_element_count],render_list.alpha_element_count,p_cam_transform,p_cam_projection,env_radiance_tex,false,true,false,false,shadow_atlas!=NULL);
+ if (state.directional_light_count == 0) {
+ directional_light = NULL;
+ _render_list(&render_list.elements[render_list.max_elements - render_list.alpha_element_count], render_list.alpha_element_count, p_cam_transform, p_cam_projection, env_radiance_tex, false, true, false, false, shadow_atlas != NULL);
} else {
- for(int i=0;i<state.directional_light_count;i++) {
- directional_light=directional_lights[i];
- _setup_directional_light(i,p_cam_transform.affine_inverse(),shadow_atlas!=NULL);
- _render_list(&render_list.elements[render_list.max_elements-render_list.alpha_element_count],render_list.alpha_element_count,p_cam_transform,p_cam_projection,env_radiance_tex,false,true,false,i>0,shadow_atlas!=NULL);
-
+ for (int i = 0; i < state.directional_light_count; i++) {
+ directional_light = directional_lights[i];
+ _setup_directional_light(i, p_cam_transform.affine_inverse(), shadow_atlas != NULL);
+ _render_list(&render_list.elements[render_list.max_elements - render_list.alpha_element_count], render_list.alpha_element_count, p_cam_transform, p_cam_projection, env_radiance_tex, false, true, false, i > 0, shadow_atlas != NULL);
}
}
@@ -4084,19 +3779,16 @@ void RasterizerSceneGLES3::render_scene(const Transform& p_cam_transform,const C
return;
}
-
- _post_process(env,p_cam_projection);
-
+ _post_process(env, p_cam_projection);
if (false && shadow_atlas) {
//_copy_texture_to_front_buffer(shadow_atlas->depth);
storage->canvas->canvas_begin();
glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D,shadow_atlas->depth);
+ glBindTexture(GL_TEXTURE_2D, shadow_atlas->depth);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE);
- storage->canvas->draw_generic_textured_rect(Rect2(0,0,storage->frame.current_rt->width/2,storage->frame.current_rt->height/2),Rect2(0,0,1,1));
-
+ storage->canvas->draw_generic_textured_rect(Rect2(0, 0, storage->frame.current_rt->width / 2, storage->frame.current_rt->height / 2), Rect2(0, 0, 1, 1));
}
if (false && storage->frame.current_rt) {
@@ -4104,10 +3796,9 @@ void RasterizerSceneGLES3::render_scene(const Transform& p_cam_transform,const C
//_copy_texture_to_front_buffer(shadow_atlas->depth);
storage->canvas->canvas_begin();
glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D,exposure_shrink[4].color);
+ glBindTexture(GL_TEXTURE_2D, exposure_shrink[4].color);
//glBindTexture(GL_TEXTURE_2D,storage->frame.current_rt->exposure.color);
- storage->canvas->draw_generic_textured_rect(Rect2(0,0,storage->frame.current_rt->width/16,storage->frame.current_rt->height/16),Rect2(0,0,1,1));
-
+ storage->canvas->draw_generic_textured_rect(Rect2(0, 0, storage->frame.current_rt->width / 16, storage->frame.current_rt->height / 16), Rect2(0, 0, 1, 1));
}
if (false && reflection_atlas && storage->frame.current_rt) {
@@ -4115,9 +3806,8 @@ void RasterizerSceneGLES3::render_scene(const Transform& p_cam_transform,const C
//_copy_texture_to_front_buffer(shadow_atlas->depth);
storage->canvas->canvas_begin();
glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D,reflection_atlas->color);
- storage->canvas->draw_generic_textured_rect(Rect2(0,0,storage->frame.current_rt->width/2,storage->frame.current_rt->height/2),Rect2(0,0,1,1));
-
+ glBindTexture(GL_TEXTURE_2D, reflection_atlas->color);
+ storage->canvas->draw_generic_textured_rect(Rect2(0, 0, storage->frame.current_rt->width / 2, storage->frame.current_rt->height / 2), Rect2(0, 0, 1, 1));
}
if (false && directional_shadow.fbo) {
@@ -4125,10 +3815,9 @@ void RasterizerSceneGLES3::render_scene(const Transform& p_cam_transform,const C
//_copy_texture_to_front_buffer(shadow_atlas->depth);
storage->canvas->canvas_begin();
glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D,directional_shadow.depth);
+ glBindTexture(GL_TEXTURE_2D, directional_shadow.depth);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE);
- storage->canvas->draw_generic_textured_rect(Rect2(0,0,storage->frame.current_rt->width/2,storage->frame.current_rt->height/2),Rect2(0,0,1,1));
-
+ storage->canvas->draw_generic_textured_rect(Rect2(0, 0, storage->frame.current_rt->width / 2, storage->frame.current_rt->height / 2), Rect2(0, 0, 1, 1));
}
if (false && env_radiance_tex) {
@@ -4136,12 +3825,10 @@ void RasterizerSceneGLES3::render_scene(const Transform& p_cam_transform,const C
//_copy_texture_to_front_buffer(shadow_atlas->depth);
storage->canvas->canvas_begin();
glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D,env_radiance_tex);
- storage->canvas->draw_generic_textured_rect(Rect2(0,0,storage->frame.current_rt->width/2,storage->frame.current_rt->height/2),Rect2(0,0,1,1));
-
+ glBindTexture(GL_TEXTURE_2D, env_radiance_tex);
+ storage->canvas->draw_generic_textured_rect(Rect2(0, 0, storage->frame.current_rt->width / 2, storage->frame.current_rt->height / 2), Rect2(0, 0, 1, 1));
}
-
#if 0
if (use_fb) {
@@ -4288,106 +3975,97 @@ void RasterizerSceneGLES3::render_scene(const Transform& p_cam_transform,const C
#endif
}
-void RasterizerSceneGLES3::render_shadow(RID p_light,RID p_shadow_atlas,int p_pass,InstanceBase** p_cull_result,int p_cull_count) {
+void RasterizerSceneGLES3::render_shadow(RID p_light, RID p_shadow_atlas, int p_pass, InstanceBase **p_cull_result, int p_cull_count) {
render_pass++;
- directional_light=NULL;
+ directional_light = NULL;
LightInstance *light_instance = light_instance_owner.getornull(p_light);
ERR_FAIL_COND(!light_instance);
RasterizerStorageGLES3::Light *light = storage->light_owner.getornull(light_instance->light);
ERR_FAIL_COND(!light);
- uint32_t x,y,width,height,vp_height;
-
+ uint32_t x, y, width, height, vp_height;
- float dp_direction=0.0;
- float zfar=0;
- bool flip_facing=false;
- int custom_vp_size=0;
+ float dp_direction = 0.0;
+ float zfar = 0;
+ bool flip_facing = false;
+ int custom_vp_size = 0;
GLuint fbo;
- int current_cubemap=-1;
- float bias=0;
- float normal_bias=0;
+ int current_cubemap = -1;
+ float bias = 0;
+ float normal_bias = 0;
CameraMatrix light_projection;
Transform light_transform;
-
- if (light->type==VS::LIGHT_DIRECTIONAL) {
+ if (light->type == VS::LIGHT_DIRECTIONAL) {
//set pssm stuff
- if (light_instance->last_scene_shadow_pass!=scene_pass) {
+ if (light_instance->last_scene_shadow_pass != scene_pass) {
//assign rect if unassigned
light_instance->light_directional_index = directional_shadow.current_light;
- light_instance->last_scene_shadow_pass=scene_pass;
+ light_instance->last_scene_shadow_pass = scene_pass;
directional_shadow.current_light++;
- if (directional_shadow.light_count==1) {
- light_instance->directional_rect=Rect2(0,0,directional_shadow.size,directional_shadow.size);
- } else if (directional_shadow.light_count==2) {
- light_instance->directional_rect=Rect2(0,0,directional_shadow.size,directional_shadow.size/2);
- if (light_instance->light_directional_index==1) {
- light_instance->directional_rect.pos.x+=light_instance->directional_rect.size.x;
+ if (directional_shadow.light_count == 1) {
+ light_instance->directional_rect = Rect2(0, 0, directional_shadow.size, directional_shadow.size);
+ } else if (directional_shadow.light_count == 2) {
+ light_instance->directional_rect = Rect2(0, 0, directional_shadow.size, directional_shadow.size / 2);
+ if (light_instance->light_directional_index == 1) {
+ light_instance->directional_rect.pos.x += light_instance->directional_rect.size.x;
}
- } else { //3 and 4
- light_instance->directional_rect=Rect2(0,0,directional_shadow.size/2,directional_shadow.size/2);
- if (light_instance->light_directional_index&1) {
- light_instance->directional_rect.pos.x+=light_instance->directional_rect.size.x;
+ } else { //3 and 4
+ light_instance->directional_rect = Rect2(0, 0, directional_shadow.size / 2, directional_shadow.size / 2);
+ if (light_instance->light_directional_index & 1) {
+ light_instance->directional_rect.pos.x += light_instance->directional_rect.size.x;
}
- if (light_instance->light_directional_index/2) {
- light_instance->directional_rect.pos.y+=light_instance->directional_rect.size.y;
+ if (light_instance->light_directional_index / 2) {
+ light_instance->directional_rect.pos.y += light_instance->directional_rect.size.y;
}
}
}
- light_projection=light_instance->shadow_transform[p_pass].camera;
- light_transform=light_instance->shadow_transform[p_pass].transform;
-
- x=light_instance->directional_rect.pos.x;
- y=light_instance->directional_rect.pos.y;
- width=light_instance->directional_rect.size.x;
- height=light_instance->directional_rect.size.y;
-
+ light_projection = light_instance->shadow_transform[p_pass].camera;
+ light_transform = light_instance->shadow_transform[p_pass].transform;
+ x = light_instance->directional_rect.pos.x;
+ y = light_instance->directional_rect.pos.y;
+ width = light_instance->directional_rect.size.x;
+ height = light_instance->directional_rect.size.y;
- if (light->directional_shadow_mode==VS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_4_SPLITS) {
+ if (light->directional_shadow_mode == VS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_4_SPLITS) {
+ width /= 2;
+ height /= 2;
- width/=2;
- height/=2;
-
- if (p_pass==0) {
-
- } else if (p_pass==1) {
- x+=width;
- } else if (p_pass==2) {
- y+=height;
- } else if (p_pass==3) {
- x+=width;
- y+=height;
+ if (p_pass == 0) {
+ } else if (p_pass == 1) {
+ x += width;
+ } else if (p_pass == 2) {
+ y += height;
+ } else if (p_pass == 3) {
+ x += width;
+ y += height;
}
+ } else if (light->directional_shadow_mode == VS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_2_SPLITS) {
+ height /= 2;
- } else if (light->directional_shadow_mode==VS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_2_SPLITS) {
-
- height/=2;
-
- if (p_pass==0) {
+ if (p_pass == 0) {
} else {
- y+=height;
+ y += height;
}
-
}
- 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];
- fbo=directional_shadow.fbo;
- vp_height=directional_shadow.size;
+ 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];
+ fbo = directional_shadow.fbo;
+ vp_height = directional_shadow.size;
} else {
//set from shadow atlas
@@ -4396,112 +4074,106 @@ void RasterizerSceneGLES3::render_shadow(RID p_light,RID p_shadow_atlas,int p_pa
ERR_FAIL_COND(!shadow_atlas);
ERR_FAIL_COND(!shadow_atlas->shadow_owners.has(p_light));
- fbo=shadow_atlas->fbo;
- vp_height=shadow_atlas->size;
+ fbo = shadow_atlas->fbo;
+ vp_height = shadow_atlas->size;
uint32_t key = shadow_atlas->shadow_owners[p_light];
- uint32_t quadrant = (key >> ShadowAtlas::QUADRANT_SHIFT)&0x3;
+ uint32_t quadrant = (key >> ShadowAtlas::QUADRANT_SHIFT) & 0x3;
uint32_t shadow = key & ShadowAtlas::SHADOW_INDEX_MASK;
- ERR_FAIL_INDEX(shadow,shadow_atlas->quadrants[quadrant].shadows.size());
+ ERR_FAIL_INDEX(shadow, shadow_atlas->quadrants[quadrant].shadows.size());
- uint32_t quadrant_size = shadow_atlas->size>>1;
+ uint32_t quadrant_size = shadow_atlas->size >> 1;
- x=(quadrant&1)*quadrant_size;
- y=(quadrant>>1)*quadrant_size;
+ x = (quadrant & 1) * quadrant_size;
+ y = (quadrant >> 1) * quadrant_size;
uint32_t shadow_size = (quadrant_size / shadow_atlas->quadrants[quadrant].subdivision);
- x+=(shadow % shadow_atlas->quadrants[quadrant].subdivision) * shadow_size;
- y+=(shadow / shadow_atlas->quadrants[quadrant].subdivision) * shadow_size;
-
- width=shadow_size;
- height=shadow_size;
+ x += (shadow % shadow_atlas->quadrants[quadrant].subdivision) * shadow_size;
+ y += (shadow / shadow_atlas->quadrants[quadrant].subdivision) * shadow_size;
- if (light->type==VS::LIGHT_OMNI) {
+ width = shadow_size;
+ height = shadow_size;
+ if (light->type == VS::LIGHT_OMNI) {
- if (light->omni_shadow_mode==VS::LIGHT_OMNI_SHADOW_CUBE) {
+ if (light->omni_shadow_mode == VS::LIGHT_OMNI_SHADOW_CUBE) {
- int cubemap_index=shadow_cubemaps.size()-1;
+ int cubemap_index = shadow_cubemaps.size() - 1;
- for(int i=shadow_cubemaps.size()-1;i>=0;i--) {
+ for (int i = shadow_cubemaps.size() - 1; i >= 0; i--) {
//find appropriate cubemap to render to
- if (shadow_cubemaps[i].size>shadow_size*2)
+ if (shadow_cubemaps[i].size > shadow_size * 2)
break;
- cubemap_index=i;
+ cubemap_index = i;
}
- fbo=shadow_cubemaps[cubemap_index].fbo_id[p_pass];
- light_projection=light_instance->shadow_transform[0].camera;
- light_transform=light_instance->shadow_transform[0].transform;
- custom_vp_size=shadow_cubemaps[cubemap_index].size;
- zfar=light->param[VS::LIGHT_PARAM_RANGE];
-
- current_cubemap=cubemap_index;
+ fbo = shadow_cubemaps[cubemap_index].fbo_id[p_pass];
+ light_projection = light_instance->shadow_transform[0].camera;
+ light_transform = light_instance->shadow_transform[0].transform;
+ custom_vp_size = shadow_cubemaps[cubemap_index].size;
+ zfar = light->param[VS::LIGHT_PARAM_RANGE];
+ current_cubemap = cubemap_index;
} else {
- light_projection=light_instance->shadow_transform[0].camera;
- light_transform=light_instance->shadow_transform[0].transform;
+ 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 == VS::LIGHT_OMNI_SHADOW_DETAIL_HORIZONTAL) {
- height/=2;
- y+=p_pass*height;
+ height /= 2;
+ y += p_pass * height;
} else {
- width/=2;
- x+=p_pass*width;
-
+ width /= 2;
+ x += p_pass * width;
}
- dp_direction = p_pass==0?1.0:-1.0;
+ dp_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[VS::LIGHT_PARAM_RANGE];
+ bias = light->param[VS::LIGHT_PARAM_SHADOW_BIAS];
- state.scene_shader.set_conditional(SceneShaderGLES3::RENDER_DEPTH_DUAL_PARABOLOID,true);
+ state.scene_shader.set_conditional(SceneShaderGLES3::RENDER_DEPTH_DUAL_PARABOLOID, true);
}
- } else if (light->type==VS::LIGHT_SPOT) {
+ } else if (light->type == VS::LIGHT_SPOT) {
- light_projection=light_instance->shadow_transform[0].camera;
- light_transform=light_instance->shadow_transform[0].transform;
+ light_projection = light_instance->shadow_transform[0].camera;
+ light_transform = light_instance->shadow_transform[0].transform;
dp_direction = 1.0;
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[VS::LIGHT_PARAM_RANGE];
+ bias = light->param[VS::LIGHT_PARAM_SHADOW_BIAS];
+ normal_bias = light->param[VS::LIGHT_PARAM_SHADOW_NORMAL_BIAS];
}
-
}
//todo hacer que se redibuje cuando corresponde
-
render_list.clear();
- _fill_render_list(p_cull_result,p_cull_count,true);
+ _fill_render_list(p_cull_result, p_cull_count, true);
render_list.sort_by_depth(false); //shadow is front to back for performance
glDisable(GL_BLEND);
glDisable(GL_DITHER);
glEnable(GL_DEPTH_TEST);
- glBindFramebuffer(GL_FRAMEBUFFER,fbo);
+ glBindFramebuffer(GL_FRAMEBUFFER, fbo);
glDepthMask(true);
- glColorMask(0,0,0,0);
-
+ glColorMask(0, 0, 0, 0);
if (custom_vp_size) {
- glViewport(0,0,custom_vp_size,custom_vp_size);
- glScissor(0,0,custom_vp_size,custom_vp_size);
+ glViewport(0, 0, custom_vp_size, custom_vp_size);
+ glScissor(0, 0, custom_vp_size, custom_vp_size);
} else {
- glViewport(x,y,width,height);
- glScissor(x,y,width,height);
+ glViewport(x, y, width, height);
+ glScissor(x, y, width, height);
}
glEnable(GL_SCISSOR_TEST);
@@ -4509,54 +4181,53 @@ void RasterizerSceneGLES3::render_shadow(RID p_light,RID p_shadow_atlas,int p_pa
glClear(GL_DEPTH_BUFFER_BIT);
glDisable(GL_SCISSOR_TEST);
- state.ubo_data.shadow_z_offset=bias;
- state.ubo_data.shadow_slope_scale=normal_bias;
- state.ubo_data.shadow_dual_paraboloid_render_side=dp_direction;
- state.ubo_data.shadow_dual_paraboloid_render_zfar=zfar;
-
- _setup_environment(NULL,light_projection,light_transform);
+ state.ubo_data.shadow_z_offset = bias;
+ state.ubo_data.shadow_slope_scale = normal_bias;
+ state.ubo_data.shadow_dual_paraboloid_render_side = dp_direction;
+ state.ubo_data.shadow_dual_paraboloid_render_zfar = zfar;
- state.scene_shader.set_conditional(SceneShaderGLES3::RENDER_DEPTH,true);
+ _setup_environment(NULL, light_projection, light_transform);
- _render_list(render_list.elements,render_list.element_count,light_transform,light_projection,0,flip_facing,false,true,false,false);
+ state.scene_shader.set_conditional(SceneShaderGLES3::RENDER_DEPTH, true);
- state.scene_shader.set_conditional(SceneShaderGLES3::RENDER_DEPTH,false);
- state.scene_shader.set_conditional(SceneShaderGLES3::RENDER_DEPTH_DUAL_PARABOLOID,false);
+ _render_list(render_list.elements, render_list.element_count, light_transform, light_projection, 0, flip_facing, false, true, false, false);
+ state.scene_shader.set_conditional(SceneShaderGLES3::RENDER_DEPTH, false);
+ state.scene_shader.set_conditional(SceneShaderGLES3::RENDER_DEPTH_DUAL_PARABOLOID, false);
- if (light->type==VS::LIGHT_OMNI && light->omni_shadow_mode==VS::LIGHT_OMNI_SHADOW_CUBE && p_pass==5) {
+ if (light->type == VS::LIGHT_OMNI && light->omni_shadow_mode == VS::LIGHT_OMNI_SHADOW_CUBE && p_pass == 5) {
//convert the chosen cubemap to dual paraboloid!
ShadowAtlas *shadow_atlas = shadow_atlas_owner.getornull(p_shadow_atlas);
- glBindFramebuffer(GL_FRAMEBUFFER,shadow_atlas->fbo);
+ glBindFramebuffer(GL_FRAMEBUFFER, shadow_atlas->fbo);
state.cube_to_dp_shader.bind();
glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_CUBE_MAP,shadow_cubemaps[current_cubemap].cubemap);
+ glBindTexture(GL_TEXTURE_CUBE_MAP, shadow_cubemaps[current_cubemap].cubemap);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_MODE, GL_NONE);
glDisable(GL_CULL_FACE);
- for(int i=0;i<2;i++) {
+ for (int i = 0; i < 2; i++) {
- state.cube_to_dp_shader.set_uniform(CubeToDpShaderGLES3::Z_FLIP,i==1);
- state.cube_to_dp_shader.set_uniform(CubeToDpShaderGLES3::Z_NEAR,light_projection.get_z_near());
- state.cube_to_dp_shader.set_uniform(CubeToDpShaderGLES3::Z_FAR,light_projection.get_z_far());
- state.cube_to_dp_shader.set_uniform(CubeToDpShaderGLES3::BIAS,light->param[VS::LIGHT_PARAM_SHADOW_BIAS]);
+ state.cube_to_dp_shader.set_uniform(CubeToDpShaderGLES3::Z_FLIP, i == 1);
+ state.cube_to_dp_shader.set_uniform(CubeToDpShaderGLES3::Z_NEAR, light_projection.get_z_near());
+ state.cube_to_dp_shader.set_uniform(CubeToDpShaderGLES3::Z_FAR, light_projection.get_z_far());
+ state.cube_to_dp_shader.set_uniform(CubeToDpShaderGLES3::BIAS, light->param[VS::LIGHT_PARAM_SHADOW_BIAS]);
- uint32_t local_width=width,local_height=height;
- uint32_t local_x=x,local_y=y;
- if (light->omni_shadow_detail==VS::LIGHT_OMNI_SHADOW_DETAIL_HORIZONTAL) {
+ uint32_t local_width = width, local_height = height;
+ uint32_t local_x = x, local_y = y;
+ if (light->omni_shadow_detail == VS::LIGHT_OMNI_SHADOW_DETAIL_HORIZONTAL) {
- local_height/=2;
- local_y+=i*local_height;
+ local_height /= 2;
+ local_y += i * local_height;
} else {
- local_width/=2;
- local_x+=i*local_width;
+ local_width /= 2;
+ local_x += i * local_width;
}
- glViewport(local_x,local_y,local_width,local_height);
- glScissor(local_x,local_y,local_width,local_height);
+ glViewport(local_x, local_y, local_width, local_height);
+ glScissor(local_x, local_y, local_width, local_height);
glEnable(GL_SCISSOR_TEST);
glClearDepth(1.0f);
glClear(GL_DEPTH_BUFFER_BIT);
@@ -4565,53 +4236,47 @@ void RasterizerSceneGLES3::render_shadow(RID p_light,RID p_shadow_atlas,int p_pa
glDisable(GL_BLEND);
_copy_screen();
-
}
-
}
- glColorMask(1,1,1,1);
-
-
+ glColorMask(1, 1, 1, 1);
}
void RasterizerSceneGLES3::set_scene_pass(uint64_t p_pass) {
- scene_pass=p_pass;
+ scene_pass = p_pass;
}
bool RasterizerSceneGLES3::free(RID p_rid) {
if (light_instance_owner.owns(p_rid)) {
-
LightInstance *light_instance = light_instance_owner.getptr(p_rid);
//remove from shadow atlases..
- for(Set<RID>::Element *E=light_instance->shadow_atlases.front();E;E=E->next()) {
+ for (Set<RID>::Element *E = light_instance->shadow_atlases.front(); E; E = E->next()) {
ShadowAtlas *shadow_atlas = shadow_atlas_owner.get(E->get());
ERR_CONTINUE(!shadow_atlas->shadow_owners.has(p_rid));
uint32_t key = shadow_atlas->shadow_owners[p_rid];
- uint32_t q = (key>>ShadowAtlas::QUADRANT_SHIFT)&0x3;
- uint32_t s = key&ShadowAtlas::SHADOW_INDEX_MASK;
+ uint32_t q = (key >> ShadowAtlas::QUADRANT_SHIFT) & 0x3;
+ uint32_t s = key & ShadowAtlas::SHADOW_INDEX_MASK;
- shadow_atlas->quadrants[q].shadows[s].owner=RID();
+ shadow_atlas->quadrants[q].shadows[s].owner = RID();
shadow_atlas->shadow_owners.erase(p_rid);
}
-
light_instance_owner.free(p_rid);
memdelete(light_instance);
} else if (shadow_atlas_owner.owns(p_rid)) {
ShadowAtlas *shadow_atlas = shadow_atlas_owner.get(p_rid);
- shadow_atlas_set_size(p_rid,0);
+ shadow_atlas_set_size(p_rid, 0);
shadow_atlas_owner.free(p_rid);
memdelete(shadow_atlas);
} else if (reflection_atlas_owner.owns(p_rid)) {
ReflectionAtlas *reflection_atlas = reflection_atlas_owner.get(p_rid);
- reflection_atlas_set_size(p_rid,0);
+ reflection_atlas_set_size(p_rid, 0);
reflection_atlas_owner.free(p_rid);
memdelete(reflection_atlas);
} else if (reflection_probe_instance_owner.owns(p_rid)) {
@@ -4626,46 +4291,44 @@ bool RasterizerSceneGLES3::free(RID p_rid) {
return false;
}
-
return true;
-
}
// http://holger.dammertz.org/stuff/notes_HammersleyOnHemisphere.html
static _FORCE_INLINE_ float radicalInverse_VdC(uint32_t bits) {
- bits = (bits << 16u) | (bits >> 16u);
- bits = ((bits & 0x55555555u) << 1u) | ((bits & 0xAAAAAAAAu) >> 1u);
- bits = ((bits & 0x33333333u) << 2u) | ((bits & 0xCCCCCCCCu) >> 2u);
- bits = ((bits & 0x0F0F0F0Fu) << 4u) | ((bits & 0xF0F0F0F0u) >> 4u);
- bits = ((bits & 0x00FF00FFu) << 8u) | ((bits & 0xFF00FF00u) >> 8u);
- return float(bits) * 2.3283064365386963e-10f; // / 0x100000000
+ bits = (bits << 16u) | (bits >> 16u);
+ bits = ((bits & 0x55555555u) << 1u) | ((bits & 0xAAAAAAAAu) >> 1u);
+ bits = ((bits & 0x33333333u) << 2u) | ((bits & 0xCCCCCCCCu) >> 2u);
+ bits = ((bits & 0x0F0F0F0Fu) << 4u) | ((bits & 0xF0F0F0F0u) >> 4u);
+ bits = ((bits & 0x00FF00FFu) << 8u) | ((bits & 0xFF00FF00u) >> 8u);
+ return float(bits) * 2.3283064365386963e-10f; // / 0x100000000
}
static _FORCE_INLINE_ Vector2 Hammersley(uint32_t i, uint32_t N) {
- return Vector2(float(i) / float(N), radicalInverse_VdC(i));
+ return Vector2(float(i) / float(N), radicalInverse_VdC(i));
}
static _FORCE_INLINE_ Vector3 ImportanceSampleGGX(Vector2 Xi, float Roughness, Vector3 N) {
- float a = Roughness * Roughness; // DISNEY'S ROUGHNESS [see Burley'12 siggraph]
-
- // Compute distribution direction
- float Phi = 2.0f * Math_PI * Xi.x;
- float CosTheta = Math::sqrt((float)(1.0f - Xi.y) / (1.0f + (a*a - 1.0f) * Xi.y));
- float SinTheta = Math::sqrt((float)Math::abs(1.0f - CosTheta * CosTheta));
-
- // Convert to spherical direction
- Vector3 H;
- H.x = SinTheta * Math::cos(Phi);
- H.y = SinTheta * Math::sin(Phi);
- H.z = CosTheta;
-
- Vector3 UpVector = Math::abs(N.z) < 0.999 ? Vector3(0.0, 0.0, 1.0) : Vector3(1.0, 0.0, 0.0);
- Vector3 TangentX = UpVector.cross(N);
- TangentX.normalize();
- Vector3 TangentY = N.cross(TangentX);
-
- // Tangent to world space
- return TangentX * H.x + TangentY * H.y + N * H.z;
+ float a = Roughness * Roughness; // DISNEY'S ROUGHNESS [see Burley'12 siggraph]
+
+ // Compute distribution direction
+ float Phi = 2.0f * Math_PI * Xi.x;
+ float CosTheta = Math::sqrt((float)(1.0f - Xi.y) / (1.0f + (a * a - 1.0f) * Xi.y));
+ float SinTheta = Math::sqrt((float)Math::abs(1.0f - CosTheta * CosTheta));
+
+ // Convert to spherical direction
+ Vector3 H;
+ H.x = SinTheta * Math::cos(Phi);
+ H.y = SinTheta * Math::sin(Phi);
+ H.z = CosTheta;
+
+ Vector3 UpVector = Math::abs(N.z) < 0.999 ? Vector3(0.0, 0.0, 1.0) : Vector3(1.0, 0.0, 0.0);
+ Vector3 TangentX = UpVector.cross(N);
+ TangentX.normalize();
+ Vector3 TangentY = N.cross(TangentX);
+
+ // Tangent to world space
+ return TangentX * H.x + TangentY * H.y + N * H.z;
}
static _FORCE_INLINE_ float GGX(float NdotV, float a) {
@@ -4674,31 +4337,27 @@ static _FORCE_INLINE_ float GGX(float NdotV, float a) {
}
// http://graphicrants.blogspot.com.au/2013/08/specular-brdf-reference.html
-float _FORCE_INLINE_ G_Smith(float a, float nDotV, float nDotL)
-{
+float _FORCE_INLINE_ G_Smith(float a, float nDotV, float nDotL) {
return GGX(nDotL, a * a) * GGX(nDotV, a * a);
}
void RasterizerSceneGLES3::_generate_brdf() {
- int brdf_size=GLOBAL_DEF("rendering/gles3/brdf_texture_size",64);
-
-
+ int brdf_size = GLOBAL_DEF("rendering/gles3/brdf_texture_size", 64);
PoolVector<uint8_t> brdf;
- brdf.resize(brdf_size*brdf_size*2);
+ brdf.resize(brdf_size * brdf_size * 2);
PoolVector<uint8_t>::Write w = brdf.write();
+ for (int i = 0; i < brdf_size; i++) {
+ for (int j = 0; j < brdf_size; j++) {
- for(int i=0;i<brdf_size;i++) {
- for(int j=0;j<brdf_size;j++) {
-
- float Roughness = float(j)/(brdf_size-1);
- float NoV = float(i+1)/(brdf_size); //avoid storing nov0
+ float Roughness = float(j) / (brdf_size - 1);
+ float NoV = float(i + 1) / (brdf_size); //avoid storing nov0
Vector3 V;
- V.x = Math::sqrt( 1.0f - NoV * NoV );
+ V.x = Math::sqrt(1.0f - NoV * NoV);
V.y = 0.0;
V.z = NoV;
@@ -4707,69 +4366,63 @@ void RasterizerSceneGLES3::_generate_brdf() {
float A = 0;
float B = 0;
- for(int s=0;s<512;s++) {
+ for (int s = 0; s < 512; s++) {
+ Vector2 xi = Hammersley(s, 512);
+ Vector3 H = ImportanceSampleGGX(xi, Roughness, N);
+ Vector3 L = 2.0 * V.dot(H) * H - V;
- Vector2 xi = Hammersley(s,512);
- Vector3 H = ImportanceSampleGGX( xi, Roughness, N );
- Vector3 L = 2.0 * V.dot(H) * H - V;
+ float NoL = CLAMP(L.z, 0.0, 1.0);
+ float NoH = CLAMP(H.z, 0.0, 1.0);
+ float VoH = CLAMP(V.dot(H), 0.0, 1.0);
- float NoL = CLAMP( L.z, 0.0, 1.0 );
- float NoH = CLAMP( H.z, 0.0, 1.0 );
- float VoH = CLAMP( V.dot(H), 0.0, 1.0 );
-
- if ( NoL > 0.0 ) {
- float G = G_Smith( Roughness, NoV, NoL );
+ if (NoL > 0.0) {
+ float G = G_Smith(Roughness, NoV, NoL);
float G_Vis = G * VoH / (NoH * NoV);
- float Fc = pow(1.0 - VoH, 5.0);
+ float Fc = pow(1.0 - VoH, 5.0);
A += (1.0 - Fc) * G_Vis;
B += Fc * G_Vis;
}
}
- A/=512.0;
- B/=512.0;
+ A /= 512.0;
+ B /= 512.0;
- int tofs = ((brdf_size-j-1)*brdf_size+i)*2;
- w[tofs+0]=CLAMP(A*255,0,255);
- w[tofs+1]=CLAMP(B*255,0,255);
+ int tofs = ((brdf_size - j - 1) * brdf_size + i) * 2;
+ w[tofs + 0] = CLAMP(A * 255, 0, 255);
+ w[tofs + 1] = CLAMP(B * 255, 0, 255);
}
}
-
//set up brdf texture
-
glGenTextures(1, &state.brdf_texture);
glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D,state.brdf_texture);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RG8, brdf_size, brdf_size, 0, GL_RG, GL_UNSIGNED_BYTE,w.ptr());
+ glBindTexture(GL_TEXTURE_2D, state.brdf_texture);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RG8, brdf_size, brdf_size, 0, GL_RG, GL_UNSIGNED_BYTE, w.ptr());
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- glBindTexture(GL_TEXTURE_2D,0);
-
+ glBindTexture(GL_TEXTURE_2D, 0);
}
void RasterizerSceneGLES3::initialize() {
-
- render_pass=0;
+ render_pass = 0;
state.scene_shader.init();
default_shader = storage->shader_create(VS::SHADER_SPATIAL);
default_material = storage->material_create();
- storage->material_set_shader(default_material,default_shader);
+ storage->material_set_shader(default_material, default_shader);
default_shader_twosided = storage->shader_create(VS::SHADER_SPATIAL);
default_material_twosided = storage->material_create();
- storage->shader_set_code(default_shader_twosided,"render_mode cull_disabled;\n");
- storage->material_set_shader(default_material_twosided,default_shader_twosided);
-
+ storage->shader_set_code(default_shader_twosided, "render_mode cull_disabled;\n");
+ storage->material_set_shader(default_material_twosided, default_shader_twosided);
glGenBuffers(1, &state.scene_ubo);
glBindBuffer(GL_UNIFORM_BUFFER, state.scene_ubo);
@@ -4781,61 +4434,53 @@ void RasterizerSceneGLES3::initialize() {
glBufferData(GL_UNIFORM_BUFFER, sizeof(State::EnvironmentRadianceUBO), &state.env_radiance_ubo, GL_DYNAMIC_DRAW);
glBindBuffer(GL_UNIFORM_BUFFER, 0);
-
- render_list.max_elements=GLOBAL_DEF("rendering/gles3/max_renderable_elements",(int)RenderList::DEFAULT_MAX_ELEMENTS);
- if (render_list.max_elements>1000000)
- render_list.max_elements=1000000;
- if (render_list.max_elements<1024)
- render_list.max_elements=1024;
-
-
+ render_list.max_elements = GLOBAL_DEF("rendering/gles3/max_renderable_elements", (int)RenderList::DEFAULT_MAX_ELEMENTS);
+ if (render_list.max_elements > 1000000)
+ render_list.max_elements = 1000000;
+ if (render_list.max_elements < 1024)
+ render_list.max_elements = 1024;
{
//quad buffers
- glGenBuffers(1,&state.skybox_verts);
- glBindBuffer(GL_ARRAY_BUFFER,state.skybox_verts);
- glBufferData(GL_ARRAY_BUFFER,sizeof(Vector3)*8,NULL,GL_DYNAMIC_DRAW);
- glBindBuffer(GL_ARRAY_BUFFER,0); //unbind
+ glGenBuffers(1, &state.skybox_verts);
+ glBindBuffer(GL_ARRAY_BUFFER, state.skybox_verts);
+ glBufferData(GL_ARRAY_BUFFER, sizeof(Vector3) * 8, NULL, GL_DYNAMIC_DRAW);
+ glBindBuffer(GL_ARRAY_BUFFER, 0); //unbind
-
- glGenVertexArrays(1,&state.skybox_array);
+ glGenVertexArrays(1, &state.skybox_array);
glBindVertexArray(state.skybox_array);
- glBindBuffer(GL_ARRAY_BUFFER,state.skybox_verts);
- glVertexAttribPointer(VS::ARRAY_VERTEX,3,GL_FLOAT,GL_FALSE,sizeof(Vector3)*2,0);
+ glBindBuffer(GL_ARRAY_BUFFER, state.skybox_verts);
+ glVertexAttribPointer(VS::ARRAY_VERTEX, 3, GL_FLOAT, GL_FALSE, sizeof(Vector3) * 2, 0);
glEnableVertexAttribArray(VS::ARRAY_VERTEX);
- glVertexAttribPointer(VS::ARRAY_TEX_UV,3,GL_FLOAT,GL_FALSE,sizeof(Vector3)*2,((uint8_t*)NULL)+sizeof(Vector3));
+ glVertexAttribPointer(VS::ARRAY_TEX_UV, 3, GL_FLOAT, GL_FALSE, sizeof(Vector3) * 2, ((uint8_t *)NULL) + sizeof(Vector3));
glEnableVertexAttribArray(VS::ARRAY_TEX_UV);
glBindVertexArray(0);
- glBindBuffer(GL_ARRAY_BUFFER,0); //unbind
+ glBindBuffer(GL_ARRAY_BUFFER, 0); //unbind
}
render_list.init();
state.cube_to_dp_shader.init();
_generate_brdf();
- shadow_atlas_realloc_tolerance_msec=500;
-
-
+ shadow_atlas_realloc_tolerance_msec = 500;
-
-
- int max_shadow_cubemap_sampler_size=512;
+ int max_shadow_cubemap_sampler_size = 512;
int cube_size = max_shadow_cubemap_sampler_size;
glActiveTexture(GL_TEXTURE0);
- while(cube_size>=32) {
+ while (cube_size >= 32) {
ShadowCubeMap cube;
- cube.size=cube_size;
+ cube.size = cube_size;
- glGenTextures(1,&cube.cubemap);
- glBindTexture(GL_TEXTURE_CUBE_MAP,cube.cubemap);
+ glGenTextures(1, &cube.cubemap);
+ glBindTexture(GL_TEXTURE_CUBE_MAP, cube.cubemap);
//gen cubemap first
- for(int i=0;i<6;i++) {
+ for (int i = 0; i < 6; i++) {
- glTexImage2D(_cube_side_enum[i], 0, GL_DEPTH_COMPONENT24, cube.size, cube.size, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL);
+ glTexImage2D(_cube_side_enum[i], 0, GL_DEPTH_COMPONENT24, cube.size, cube.size, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL);
}
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
@@ -4846,38 +4491,38 @@ void RasterizerSceneGLES3::initialize() {
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
//gen renderbuffers second, because it needs a complete cubemap
- for(int i=0;i<6;i++) {
+ for (int i = 0; i < 6; i++) {
glGenFramebuffers(1, &cube.fbo_id[i]);
glBindFramebuffer(GL_FRAMEBUFFER, cube.fbo_id[i]);
- glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,_cube_side_enum[i], cube.cubemap, 0);
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, _cube_side_enum[i], cube.cubemap, 0);
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
- ERR_CONTINUE(status!=GL_FRAMEBUFFER_COMPLETE);
+ ERR_CONTINUE(status != GL_FRAMEBUFFER_COMPLETE);
}
shadow_cubemaps.push_back(cube);
- cube_size>>=1;
+ cube_size >>= 1;
}
{
//directional light shadow
- directional_shadow.light_count=0;
- directional_shadow.size=nearest_power_of_2(GLOBAL_DEF("rendering/shadows/directional_shadow_size",2048));
- glGenFramebuffers(1,&directional_shadow.fbo);
- glBindFramebuffer(GL_FRAMEBUFFER,directional_shadow.fbo);
- glGenTextures(1,&directional_shadow.depth);
- glBindTexture(GL_TEXTURE_2D,directional_shadow.depth);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, directional_shadow.size, directional_shadow.size, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL);
+ directional_shadow.light_count = 0;
+ directional_shadow.size = nearest_power_of_2(GLOBAL_DEF("rendering/shadows/directional_shadow_size", 2048));
+ glGenFramebuffers(1, &directional_shadow.fbo);
+ glBindFramebuffer(GL_FRAMEBUFFER, directional_shadow.fbo);
+ glGenTextures(1, &directional_shadow.depth);
+ glBindTexture(GL_TEXTURE_2D, directional_shadow.depth);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, directional_shadow.size, directional_shadow.size, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
- glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,GL_TEXTURE_2D, directional_shadow.depth, 0);
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, directional_shadow.depth, 0);
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
- if (status!=GL_FRAMEBUFFER_COMPLETE) {
+ if (status != GL_FRAMEBUFFER_COMPLETE) {
ERR_PRINT("Directional shadow framebuffer status invalid");
}
}
@@ -4886,24 +4531,23 @@ void RasterizerSceneGLES3::initialize() {
//spot and omni ubos
int max_ubo_size;
- glGetIntegerv(GL_MAX_UNIFORM_BLOCK_SIZE,&max_ubo_size);
- const int ubo_light_size=160;
- state.ubo_light_size=ubo_light_size;
- state.max_ubo_lights=MIN(RenderList::MAX_LIGHTS,max_ubo_size/ubo_light_size);
- print_line("max ubo light: "+itos(state.max_ubo_lights));
-
- state.spot_array_tmp = (uint8_t*)memalloc(ubo_light_size*state.max_ubo_lights);
- state.omni_array_tmp = (uint8_t*)memalloc(ubo_light_size*state.max_ubo_lights);
+ glGetIntegerv(GL_MAX_UNIFORM_BLOCK_SIZE, &max_ubo_size);
+ const int ubo_light_size = 160;
+ state.ubo_light_size = ubo_light_size;
+ state.max_ubo_lights = MIN(RenderList::MAX_LIGHTS, max_ubo_size / ubo_light_size);
+ print_line("max ubo light: " + itos(state.max_ubo_lights));
+ state.spot_array_tmp = (uint8_t *)memalloc(ubo_light_size * state.max_ubo_lights);
+ state.omni_array_tmp = (uint8_t *)memalloc(ubo_light_size * state.max_ubo_lights);
glGenBuffers(1, &state.spot_array_ubo);
glBindBuffer(GL_UNIFORM_BUFFER, state.spot_array_ubo);
- glBufferData(GL_UNIFORM_BUFFER, ubo_light_size*state.max_ubo_lights, NULL, GL_DYNAMIC_DRAW);
+ glBufferData(GL_UNIFORM_BUFFER, ubo_light_size * state.max_ubo_lights, NULL, GL_DYNAMIC_DRAW);
glBindBuffer(GL_UNIFORM_BUFFER, 0);
glGenBuffers(1, &state.omni_array_ubo);
glBindBuffer(GL_UNIFORM_BUFFER, state.omni_array_ubo);
- glBufferData(GL_UNIFORM_BUFFER, ubo_light_size*state.max_ubo_lights, NULL, GL_DYNAMIC_DRAW);
+ glBufferData(GL_UNIFORM_BUFFER, ubo_light_size * state.max_ubo_lights, NULL, GL_DYNAMIC_DRAW);
glBindBuffer(GL_UNIFORM_BUFFER, 0);
glGenBuffers(1, &state.directional_ubo);
@@ -4911,67 +4555,63 @@ void RasterizerSceneGLES3::initialize() {
glBufferData(GL_UNIFORM_BUFFER, sizeof(LightDataUBO), NULL, GL_DYNAMIC_DRAW);
glBindBuffer(GL_UNIFORM_BUFFER, 0);
- state.max_forward_lights_per_object=8;
+ state.max_forward_lights_per_object = 8;
+ state.scene_shader.add_custom_define("#define MAX_LIGHT_DATA_STRUCTS " + itos(state.max_ubo_lights) + "\n");
+ state.scene_shader.add_custom_define("#define MAX_FORWARD_LIGHTS " + itos(state.max_forward_lights_per_object) + "\n");
- state.scene_shader.add_custom_define("#define MAX_LIGHT_DATA_STRUCTS "+itos(state.max_ubo_lights)+"\n");
- state.scene_shader.add_custom_define("#define MAX_FORWARD_LIGHTS "+itos(state.max_forward_lights_per_object)+"\n");
+ state.max_ubo_reflections = MIN(RenderList::MAX_REFLECTIONS, max_ubo_size / sizeof(ReflectionProbeDataUBO));
+ print_line("max ubo reflections: " + itos(state.max_ubo_reflections) + " ubo size: " + itos(sizeof(ReflectionProbeDataUBO)));
- state.max_ubo_reflections=MIN(RenderList::MAX_REFLECTIONS,max_ubo_size/sizeof(ReflectionProbeDataUBO));
- print_line("max ubo reflections: "+itos(state.max_ubo_reflections)+" ubo size: "+itos(sizeof(ReflectionProbeDataUBO)));
-
- state.reflection_array_tmp = (uint8_t*)memalloc(sizeof(ReflectionProbeDataUBO)*state.max_ubo_reflections);
+ state.reflection_array_tmp = (uint8_t *)memalloc(sizeof(ReflectionProbeDataUBO) * state.max_ubo_reflections);
glGenBuffers(1, &state.reflection_array_ubo);
glBindBuffer(GL_UNIFORM_BUFFER, state.reflection_array_ubo);
- glBufferData(GL_UNIFORM_BUFFER, sizeof(ReflectionProbeDataUBO)*state.max_ubo_reflections, NULL, GL_DYNAMIC_DRAW);
+ glBufferData(GL_UNIFORM_BUFFER, sizeof(ReflectionProbeDataUBO) * state.max_ubo_reflections, NULL, GL_DYNAMIC_DRAW);
glBindBuffer(GL_UNIFORM_BUFFER, 0);
- state.scene_shader.add_custom_define("#define MAX_REFLECTION_DATA_STRUCTS "+itos(state.max_ubo_reflections)+"\n");
-
- state.max_skeleton_bones=MIN(2048,max_ubo_size/(12*sizeof(float)));
- state.scene_shader.add_custom_define("#define MAX_SKELETON_BONES "+itos(state.max_skeleton_bones)+"\n");
-
+ state.scene_shader.add_custom_define("#define MAX_REFLECTION_DATA_STRUCTS " + itos(state.max_ubo_reflections) + "\n");
+ state.max_skeleton_bones = MIN(2048, max_ubo_size / (12 * sizeof(float)));
+ state.scene_shader.add_custom_define("#define MAX_SKELETON_BONES " + itos(state.max_skeleton_bones) + "\n");
}
- GLOBAL_DEF("rendering/gles3/shadow_filter_mode",1);
- GlobalConfig::get_singleton()->set_custom_property_info("rendering/gles3/shadow_filter_mode",PropertyInfo(Variant::INT,"rendering/gles3/shadow_filter_mode",PROPERTY_HINT_ENUM,"Disabled,PCF5,PCF13"));
- shadow_filter_mode=SHADOW_FILTER_NEAREST;
+ GLOBAL_DEF("rendering/gles3/shadow_filter_mode", 1);
+ GlobalConfig::get_singleton()->set_custom_property_info("rendering/gles3/shadow_filter_mode", PropertyInfo(Variant::INT, "rendering/gles3/shadow_filter_mode", PROPERTY_HINT_ENUM, "Disabled,PCF5,PCF13"));
+ shadow_filter_mode = SHADOW_FILTER_NEAREST;
{ //reflection cubemaps
- int max_reflection_cubemap_sampler_size=512;
+ int max_reflection_cubemap_sampler_size = 512;
int cube_size = max_reflection_cubemap_sampler_size;
glActiveTexture(GL_TEXTURE0);
- bool use_float=true;
+ bool use_float = true;
- GLenum internal_format = use_float?GL_RGBA16F:GL_RGB10_A2;
+ GLenum internal_format = use_float ? GL_RGBA16F : GL_RGB10_A2;
GLenum format = GL_RGBA;
- GLenum type = use_float?GL_HALF_FLOAT:GL_UNSIGNED_INT_2_10_10_10_REV;
+ GLenum type = use_float ? GL_HALF_FLOAT : GL_UNSIGNED_INT_2_10_10_10_REV;
- while(cube_size>=32) {
+ while (cube_size >= 32) {
ReflectionCubeMap cube;
- cube.size=cube_size;
+ cube.size = cube_size;
- glGenTextures(1,&cube.depth);
- glBindTexture(GL_TEXTURE_2D,cube.depth);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, cube.size, cube.size, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL);
+ glGenTextures(1, &cube.depth);
+ glBindTexture(GL_TEXTURE_2D, cube.depth);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, cube.size, cube.size, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
-
- glGenTextures(1,&cube.cubemap);
- glBindTexture(GL_TEXTURE_CUBE_MAP,cube.cubemap);
+ glGenTextures(1, &cube.cubemap);
+ glBindTexture(GL_TEXTURE_CUBE_MAP, cube.cubemap);
//gen cubemap first
- for(int i=0;i<6;i++) {
+ for (int i = 0; i < 6; i++) {
- glTexImage2D(_cube_side_enum[i], 0, internal_format, cube.size, cube.size, 0, format, type, NULL);
+ glTexImage2D(_cube_side_enum[i], 0, internal_format, cube.size, cube.size, 0, format, type, NULL);
}
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
@@ -4982,41 +4622,37 @@ void RasterizerSceneGLES3::initialize() {
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
//gen renderbuffers second, because it needs a complete cubemap
- for(int i=0;i<6;i++) {
+ for (int i = 0; i < 6; i++) {
glGenFramebuffers(1, &cube.fbo_id[i]);
glBindFramebuffer(GL_FRAMEBUFFER, cube.fbo_id[i]);
- glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,_cube_side_enum[i], cube.cubemap, 0);
- glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,GL_TEXTURE_2D, cube.depth, 0);
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, _cube_side_enum[i], cube.cubemap, 0);
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, cube.depth, 0);
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
- ERR_CONTINUE(status!=GL_FRAMEBUFFER_COMPLETE);
+ ERR_CONTINUE(status != GL_FRAMEBUFFER_COMPLETE);
}
reflection_cubemaps.push_back(cube);
- cube_size>>=1;
+ cube_size >>= 1;
}
}
{
-
- uint32_t immediate_buffer_size=GLOBAL_DEF("rendering/buffers/immediate_buffer_size_kb",2048);
+ uint32_t immediate_buffer_size = GLOBAL_DEF("rendering/buffers/immediate_buffer_size_kb", 2048);
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, NULL, GL_DYNAMIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
- glGenVertexArrays(1,&state.immediate_array);
-
-
-
+ glGenVertexArrays(1, &state.immediate_array);
}
#ifdef GLES_OVER_GL
-//"desktop" opengl needs this.
+ //"desktop" opengl needs this.
glEnable(GL_PROGRAM_POINT_SIZE);
#endif
@@ -5031,23 +4667,20 @@ void RasterizerSceneGLES3::initialize() {
state.exposure_shader.init();
state.tonemap_shader.init();
-
{
- GLOBAL_DEF("rendering/ssurf_scattering/quality",1);
- GlobalConfig::get_singleton()->set_custom_property_info("rendering/ssurf_scattering/quality",PropertyInfo(Variant::INT,"rendering/ssurf_scattering/quality",PROPERTY_HINT_ENUM,"Low,Medium,High"));
- GLOBAL_DEF("rendering/ssurf_scattering/max_size",1.0);
- GlobalConfig::get_singleton()->set_custom_property_info("rendering/ssurf_scattering/max_size",PropertyInfo(Variant::INT,"rendering/ssurf_scattering/max_size",PROPERTY_HINT_RANGE,"0.01,8,0.01"));
- GLOBAL_DEF("rendering/ssurf_scattering/follow_surface",false);
-
- GLOBAL_DEF("rendering/reflections/high_quality_vct_gi",true);
-
+ GLOBAL_DEF("rendering/ssurf_scattering/quality", 1);
+ GlobalConfig::get_singleton()->set_custom_property_info("rendering/ssurf_scattering/quality", PropertyInfo(Variant::INT, "rendering/ssurf_scattering/quality", PROPERTY_HINT_ENUM, "Low,Medium,High"));
+ GLOBAL_DEF("rendering/ssurf_scattering/max_size", 1.0);
+ GlobalConfig::get_singleton()->set_custom_property_info("rendering/ssurf_scattering/max_size", PropertyInfo(Variant::INT, "rendering/ssurf_scattering/max_size", PROPERTY_HINT_RANGE, "0.01,8,0.01"));
+ GLOBAL_DEF("rendering/ssurf_scattering/follow_surface", false);
+ GLOBAL_DEF("rendering/reflections/high_quality_vct_gi", true);
}
- exposure_shrink_size=243;
- int max_exposure_shrink_size=exposure_shrink_size;
+ exposure_shrink_size = 243;
+ int max_exposure_shrink_size = exposure_shrink_size;
- while(max_exposure_shrink_size>0) {
+ while (max_exposure_shrink_size > 0) {
RasterizerStorageGLES3::RenderTarget::Exposure e;
@@ -5056,41 +4689,33 @@ void RasterizerSceneGLES3::initialize() {
glGenTextures(1, &e.color);
glBindTexture(GL_TEXTURE_2D, e.color);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_R32F, max_exposure_shrink_size, max_exposure_shrink_size, 0, GL_RED, GL_FLOAT, NULL);
- glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, e.color, 0);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_R32F, max_exposure_shrink_size, max_exposure_shrink_size, 0, GL_RED, GL_FLOAT, NULL);
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, e.color, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
exposure_shrink.push_back(e);
- max_exposure_shrink_size/=3;
+ max_exposure_shrink_size /= 3;
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
- ERR_CONTINUE(status!=GL_FRAMEBUFFER_COMPLETE);
-
-
+ ERR_CONTINUE(status != GL_FRAMEBUFFER_COMPLETE);
}
-
}
void RasterizerSceneGLES3::iteration() {
- shadow_filter_mode=ShadowFilterMode(int(GlobalConfig::get_singleton()->get("rendering/gles3/shadow_filter_mode")));
- subsurface_scatter_follow_surface=GlobalConfig::get_singleton()->get("rendering/ssurf_scattering/follow_surface");
- subsurface_scatter_quality=SubSurfaceScatterQuality(int(GlobalConfig::get_singleton()->get("rendering/ssurf_scattering/quality")));
- subsurface_scatter_size=GlobalConfig::get_singleton()->get("rendering/ssurf_scattering/max_size");
-
+ shadow_filter_mode = ShadowFilterMode(int(GlobalConfig::get_singleton()->get("rendering/gles3/shadow_filter_mode")));
+ subsurface_scatter_follow_surface = GlobalConfig::get_singleton()->get("rendering/ssurf_scattering/follow_surface");
+ subsurface_scatter_quality = SubSurfaceScatterQuality(int(GlobalConfig::get_singleton()->get("rendering/ssurf_scattering/quality")));
+ subsurface_scatter_size = GlobalConfig::get_singleton()->get("rendering/ssurf_scattering/max_size");
- state.scene_shader.set_conditional(SceneShaderGLES3::VCT_QUALITY_HIGH,GlobalConfig::get_singleton()->get("rendering/reflections/high_quality_vct_gi"));
+ state.scene_shader.set_conditional(SceneShaderGLES3::VCT_QUALITY_HIGH, GlobalConfig::get_singleton()->get("rendering/reflections/high_quality_vct_gi"));
}
-void RasterizerSceneGLES3::finalize(){
-
-
+void RasterizerSceneGLES3::finalize() {
}
-
-RasterizerSceneGLES3::RasterizerSceneGLES3()
-{
+RasterizerSceneGLES3::RasterizerSceneGLES3() {
}
diff --git a/drivers/gles3/rasterizer_scene_gles3.h b/drivers/gles3/rasterizer_scene_gles3.h
index b21ef8317f..417a1d8500 100644
--- a/drivers/gles3/rasterizer_scene_gles3.h
+++ b/drivers/gles3/rasterizer_scene_gles3.h
@@ -29,29 +29,27 @@
#ifndef RASTERIZERSCENEGLES3_H
#define RASTERIZERSCENEGLES3_H
-#include "rasterizer_storage_gles3.h"
-#include "drivers/gles3/shaders/scene.glsl.h"
#include "drivers/gles3/shaders/cube_to_dp.glsl.h"
+#include "drivers/gles3/shaders/effect_blur.glsl.h"
+#include "drivers/gles3/shaders/exposure.glsl.h"
#include "drivers/gles3/shaders/resolve.glsl.h"
+#include "drivers/gles3/shaders/scene.glsl.h"
#include "drivers/gles3/shaders/screen_space_reflection.glsl.h"
-#include "drivers/gles3/shaders/effect_blur.glsl.h"
-#include "drivers/gles3/shaders/subsurf_scattering.glsl.h"
-#include "drivers/gles3/shaders/ssao_minify.glsl.h"
#include "drivers/gles3/shaders/ssao.glsl.h"
#include "drivers/gles3/shaders/ssao_blur.glsl.h"
-#include "drivers/gles3/shaders/exposure.glsl.h"
+#include "drivers/gles3/shaders/ssao_minify.glsl.h"
+#include "drivers/gles3/shaders/subsurf_scattering.glsl.h"
#include "drivers/gles3/shaders/tonemap.glsl.h"
+#include "rasterizer_storage_gles3.h"
class RasterizerSceneGLES3 : public RasterizerScene {
public:
-
enum ShadowFilterMode {
SHADOW_FILTER_NEAREST,
SHADOW_FILTER_PCF5,
SHADOW_FILTER_PCF13,
};
-
ShadowFilterMode shadow_filter_mode;
uint64_t shadow_atlas_realloc_tolerance_msec;
@@ -83,8 +81,6 @@ public:
struct State {
-
-
bool texscreen_copied;
int current_blend_mode;
float current_line_width;
@@ -104,7 +100,6 @@ public:
ExposureShaderGLES3 exposure_shader;
TonemapShaderGLES3 tonemap_shader;
-
struct SceneDataUBO {
float projection_matrix[16];
@@ -167,7 +162,6 @@ public:
bool used_contact_shadows;
-
int spot_light_count;
int omni_light_count;
int directional_light_count;
@@ -178,15 +172,14 @@ public:
} state;
-
/* SHADOW ATLAS API */
struct ShadowAtlas : public RID_Data {
enum {
- QUADRANT_SHIFT=27,
- SHADOW_INDEX_MASK=(1<<QUADRANT_SHIFT)-1,
- SHADOW_INVALID=0xFFFFFFFF
+ QUADRANT_SHIFT = 27,
+ SHADOW_INDEX_MASK = (1 << QUADRANT_SHIFT) - 1,
+ SHADOW_INVALID = 0xFFFFFFFF
};
struct Quadrant {
@@ -199,15 +192,15 @@ public:
uint64_t alloc_tick;
Shadow() {
- version=0;
- alloc_tick=0;
+ version = 0;
+ alloc_tick = 0;
}
};
Vector<Shadow> shadows;
Quadrant() {
- subdivision=0; //not in use
+ subdivision = 0; //not in use
}
} quadrants[4];
@@ -220,7 +213,7 @@ public:
GLuint fbo;
GLuint depth;
- Map<RID,uint32_t> shadow_owners;
+ Map<RID, uint32_t> shadow_owners;
};
struct ShadowCubeMap {
@@ -235,10 +228,10 @@ public:
RID_Owner<ShadowAtlas> shadow_atlas_owner;
RID shadow_atlas_create();
- void shadow_atlas_set_size(RID p_atlas,int p_size);
- void shadow_atlas_set_quadrant_subdivision(RID p_atlas,int p_quadrant,int p_subdivision);
+ void shadow_atlas_set_size(RID p_atlas, int p_size);
+ void shadow_atlas_set_quadrant_subdivision(RID p_atlas, int p_quadrant, int p_subdivision);
bool _shadow_atlas_find_shadow(ShadowAtlas *shadow_atlas, int *p_in_quadrants, int p_quadrant_count, int p_current_subdiv, uint64_t p_tick, int &r_quadrant, int &r_shadow);
- bool shadow_atlas_update_light(RID p_atlas,RID p_light_intance,float p_coverage,uint64_t p_light_version);
+ bool shadow_atlas_update_light(RID p_atlas, RID p_light_intance, float p_coverage, uint64_t p_light_version);
struct DirectionalShadow {
GLuint fbo;
@@ -272,8 +265,8 @@ public:
mutable RID_Owner<ReflectionAtlas> reflection_atlas_owner;
virtual RID reflection_atlas_create();
- virtual void reflection_atlas_set_size(RID p_ref_atlas,int p_size);
- virtual void reflection_atlas_set_subdivision(RID p_ref_atlas,int p_subdiv);
+ virtual void reflection_atlas_set_size(RID p_ref_atlas, int p_size);
+ virtual void reflection_atlas_set_subdivision(RID p_ref_atlas, int p_subdiv);
/* REFLECTION CUBEMAPS */
@@ -300,8 +293,6 @@ public:
int render_step;
-
-
uint64_t last_pass;
int reflection_index;
@@ -319,20 +310,16 @@ public:
//notes: for ambientblend, use distance to edge to blend between already existing global environment
};
-
mutable RID_Owner<ReflectionProbeInstance> reflection_probe_instance_owner;
virtual RID reflection_probe_instance_create(RID p_probe);
- virtual void reflection_probe_instance_set_transform(RID p_instance,const Transform& p_transform);
+ virtual void reflection_probe_instance_set_transform(RID p_instance, const Transform &p_transform);
virtual void reflection_probe_release_atlas_index(RID p_instance);
virtual bool reflection_probe_instance_needs_redraw(RID p_instance);
virtual bool reflection_probe_instance_has_reflection(RID p_instance);
virtual bool reflection_probe_instance_begin_render(RID p_instance, RID p_reflection_atlas);
virtual bool reflection_probe_instance_postprocess_step(RID p_instance);
-
-
-
/* ENVIRONMENT API */
struct Environment : public RID_Data {
@@ -360,7 +347,6 @@ public:
bool ssr_smooth;
bool ssr_roughness;
-
bool ssao_enabled;
float ssao_intensity;
float ssao_radius;
@@ -403,62 +389,61 @@ public:
VS::EnvironmentDOFBlurQuality dof_blur_near_quality;
Environment() {
- bg_mode=VS::ENV_BG_CLEAR_COLOR;
- skybox_scale=1.0;
- bg_energy=1.0;
- skybox_ambient=0;
- ambient_energy=1.0;
- ambient_skybox_contribution=0.0;
- canvas_max_layer=0;
-
- ssr_enabled=false;
- ssr_max_steps=64;
- ssr_accel=0.04;
- ssr_fade=2.0;
- ssr_depth_tolerance=0.2;
- ssr_smooth=true;
- ssr_roughness=true;
-
- ssao_enabled=false;
- ssao_intensity=1.0;
- ssao_radius=1.0;
- ssao_intensity2=1.0;
- ssao_radius2=0.0;
- ssao_bias=0.01;
- ssao_light_affect=0;
- ssao_filter=true;
-
- tone_mapper=VS::ENV_TONE_MAPPER_LINEAR;
- tone_mapper_exposure=1.0;
- tone_mapper_exposure_white=1.0;
- auto_exposure=false;
- auto_exposure_speed=0.5;
- auto_exposure_min=0.05;
- auto_exposure_max=8;
- auto_exposure_grey=0.4;
-
- glow_enabled=false;
- glow_levels=(1<<2)|(1<<4);
- glow_intensity=0.8;
- glow_strength=1.0;
- glow_bloom=0.0;
- glow_blend_mode=VS::GLOW_BLEND_MODE_SOFTLIGHT;
- glow_hdr_bleed_treshold=1.0;
- glow_hdr_bleed_scale=2.0;
- glow_bicubic_upscale=false;
-
- dof_blur_far_enabled=false;
- 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_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;
-
+ bg_mode = VS::ENV_BG_CLEAR_COLOR;
+ skybox_scale = 1.0;
+ bg_energy = 1.0;
+ skybox_ambient = 0;
+ ambient_energy = 1.0;
+ ambient_skybox_contribution = 0.0;
+ canvas_max_layer = 0;
+
+ ssr_enabled = false;
+ ssr_max_steps = 64;
+ ssr_accel = 0.04;
+ ssr_fade = 2.0;
+ ssr_depth_tolerance = 0.2;
+ ssr_smooth = true;
+ ssr_roughness = true;
+
+ ssao_enabled = false;
+ ssao_intensity = 1.0;
+ ssao_radius = 1.0;
+ ssao_intensity2 = 1.0;
+ ssao_radius2 = 0.0;
+ ssao_bias = 0.01;
+ ssao_light_affect = 0;
+ ssao_filter = true;
+
+ tone_mapper = VS::ENV_TONE_MAPPER_LINEAR;
+ tone_mapper_exposure = 1.0;
+ tone_mapper_exposure_white = 1.0;
+ auto_exposure = false;
+ auto_exposure_speed = 0.5;
+ auto_exposure_min = 0.05;
+ auto_exposure_max = 8;
+ auto_exposure_grey = 0.4;
+
+ glow_enabled = false;
+ glow_levels = (1 << 2) | (1 << 4);
+ glow_intensity = 0.8;
+ glow_strength = 1.0;
+ glow_bloom = 0.0;
+ glow_blend_mode = VS::GLOW_BLEND_MODE_SOFTLIGHT;
+ glow_hdr_bleed_treshold = 1.0;
+ glow_hdr_bleed_scale = 2.0;
+ glow_bicubic_upscale = false;
+
+ dof_blur_far_enabled = false;
+ 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_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;
}
};
@@ -466,27 +451,25 @@ public:
virtual RID environment_create();
- virtual void environment_set_background(RID p_env,VS::EnvironmentBG p_bg);
- virtual void environment_set_skybox(RID p_env,RID p_skybox);
- virtual void environment_set_skybox_scale(RID p_env,float p_scale);
- virtual void environment_set_bg_color(RID p_env,const Color& p_color);
- virtual void environment_set_bg_energy(RID p_env,float p_energy);
- virtual void environment_set_canvas_max_layer(RID p_env,int p_max_layer);
- virtual void environment_set_ambient_light(RID p_env,const Color& p_color,float p_energy=1.0,float p_skybox_contribution=0.0);
+ virtual void environment_set_background(RID p_env, VS::EnvironmentBG p_bg);
+ virtual void environment_set_skybox(RID p_env, RID p_skybox);
+ virtual void environment_set_skybox_scale(RID p_env, float p_scale);
+ virtual void environment_set_bg_color(RID p_env, const Color &p_color);
+ virtual void environment_set_bg_energy(RID p_env, float p_energy);
+ virtual void environment_set_canvas_max_layer(RID p_env, int p_max_layer);
+ virtual void environment_set_ambient_light(RID p_env, const Color &p_color, float p_energy = 1.0, float p_skybox_contribution = 0.0);
- virtual void environment_set_dof_blur_near(RID p_env,bool p_enable,float p_distance,float p_transition,float p_far_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_far_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_treshold,VS::EnvironmentGlowBlendMode p_blend_mode,float p_hdr_bleed_treshold,float p_hdr_bleed_scale,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_dof_blur_near(RID p_env, bool p_enable, float p_distance, float p_transition, float p_far_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_far_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_treshold, VS::EnvironmentGlowBlendMode p_blend_mode, float p_hdr_bleed_treshold, float p_hdr_bleed_scale, 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_accel,float p_fade,float p_depth_tolerance,bool p_smooth,bool p_roughness);
- virtual void environment_set_ssao(RID p_env,bool p_enable, float p_radius, float p_radius2, float p_intensity2, float p_intensity, float p_bias, float p_light_affect,const Color &p_color,bool p_blur);
+ virtual void environment_set_ssr(RID p_env, bool p_enable, int p_max_steps, float p_accel, float p_fade, float p_depth_tolerance, bool p_smooth, bool p_roughness);
+ virtual void environment_set_ssao(RID p_env, bool p_enable, float p_radius, float p_radius2, float p_intensity2, float p_intensity, float p_bias, float p_light_affect, const Color &p_color, bool p_blur);
+ 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,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_adjustment(RID p_env,bool p_enable,float p_brightness,float p_contrast,float p_saturation,RID p_ramp);
-
+ virtual void environment_set_adjustment(RID p_env, bool p_enable, float p_brightness, float p_contrast, float p_saturation, RID p_ramp);
/* LIGHT INSTANCE */
@@ -503,7 +486,6 @@ public:
float shadow_matrix3[16];
float shadow_matrix4[16];
float shadow_split_offsets[4];
-
};
struct LightInstance : public RID_Data {
@@ -516,8 +498,6 @@ public:
float split;
};
-
-
ShadowTransform shadow_transform[4];
RID self;
@@ -542,18 +522,16 @@ public:
Rect2 directional_rect;
-
Set<RID> shadow_atlases; //shadow atlases where this light is registered
- LightInstance() { }
-
+ LightInstance() {}
};
mutable RID_Owner<LightInstance> light_instance_owner;
virtual RID light_instance_create(RID p_light);
- virtual void light_instance_set_transform(RID p_light_instance,const Transform& p_transform);
- virtual void light_instance_set_shadow_transform(RID p_light_instance,const CameraMatrix& p_projection,const Transform& p_transform,float p_far,float p_split,int p_pass);
+ virtual void light_instance_set_transform(RID p_light_instance, const Transform &p_transform);
+ virtual void light_instance_set_shadow_transform(RID p_light_instance, const CameraMatrix &p_projection, const Transform &p_transform, float p_far, float p_split, int p_pass);
virtual void light_instance_mark_visible(RID p_light_instance);
/* REFLECTION INSTANCE */
@@ -566,42 +544,42 @@ public:
Vector3 bounds;
Transform transform_to_data;
- GIProbeInstance() { probe=NULL; tex_cache=0; }
+ GIProbeInstance() {
+ probe = NULL;
+ tex_cache = 0;
+ }
};
-
-
mutable RID_Owner<GIProbeInstance> gi_probe_instance_owner;
virtual RID gi_probe_instance_create();
- virtual void gi_probe_instance_set_light_data(RID p_probe,RID p_base,RID p_data);
- virtual void gi_probe_instance_set_transform_to_data(RID p_probe,const Transform& p_xform);
- virtual void gi_probe_instance_set_bounds(RID p_probe,const Vector3& p_bounds);
+ virtual void gi_probe_instance_set_light_data(RID p_probe, RID p_base, RID p_data);
+ virtual void gi_probe_instance_set_transform_to_data(RID p_probe, const Transform &p_xform);
+ virtual void gi_probe_instance_set_bounds(RID p_probe, const Vector3 &p_bounds);
/* RENDER LIST */
struct RenderList {
enum {
- DEFAULT_MAX_ELEMENTS=65536,
- SORT_FLAG_SKELETON=1,
- SORT_FLAG_INSTANCING=2,
- MAX_DIRECTIONAL_LIGHTS=16,
- MAX_LIGHTS=4096,
- MAX_REFLECTIONS=1024,
-
-
- SORT_KEY_DEPTH_LAYER_SHIFT=60,
- SORT_KEY_UNSHADED_FLAG=uint64_t(1)<<59,
- SORT_KEY_NO_DIRECTIONAL_FLAG=uint64_t(1)<<58,
- SORT_KEY_GI_PROBES_FLAG=uint64_t(1)<<57,
- SORT_KEY_SHADING_SHIFT=57,
- SORT_KEY_SHADING_MASK=7,
- SORT_KEY_MATERIAL_INDEX_SHIFT=40,
- SORT_KEY_GEOMETRY_INDEX_SHIFT=20,
- SORT_KEY_GEOMETRY_TYPE_SHIFT=15,
- SORT_KEY_SKELETON_FLAG=2,
- SORT_KEY_MIRROR_FLAG=1
+ DEFAULT_MAX_ELEMENTS = 65536,
+ SORT_FLAG_SKELETON = 1,
+ SORT_FLAG_INSTANCING = 2,
+ MAX_DIRECTIONAL_LIGHTS = 16,
+ MAX_LIGHTS = 4096,
+ MAX_REFLECTIONS = 1024,
+
+ SORT_KEY_DEPTH_LAYER_SHIFT = 60,
+ SORT_KEY_UNSHADED_FLAG = uint64_t(1) << 59,
+ SORT_KEY_NO_DIRECTIONAL_FLAG = uint64_t(1) << 58,
+ SORT_KEY_GI_PROBES_FLAG = uint64_t(1) << 57,
+ SORT_KEY_SHADING_SHIFT = 57,
+ SORT_KEY_SHADING_MASK = 7,
+ SORT_KEY_MATERIAL_INDEX_SHIFT = 40,
+ SORT_KEY_GEOMETRY_INDEX_SHIFT = 20,
+ SORT_KEY_GEOMETRY_TYPE_SHIFT = 15,
+ SORT_KEY_SKELETON_FLAG = 2,
+ SORT_KEY_MIRROR_FLAG = 1
};
@@ -614,74 +592,70 @@ public:
RasterizerStorageGLES3::Material *material;
RasterizerStorageGLES3::GeometryOwner *owner;
uint64_t sort_key;
-
};
-
Element *_elements;
Element **elements;
int element_count;
int alpha_element_count;
-
void clear() {
- element_count=0;
- alpha_element_count=0;
+ element_count = 0;
+ alpha_element_count = 0;
}
//should eventually be replaced by radix
struct SortByKey {
- _FORCE_INLINE_ bool operator()(const Element* A, const Element* B ) const {
+ _FORCE_INLINE_ bool operator()(const Element *A, const Element *B) const {
return A->sort_key < B->sort_key;
}
};
void sort_by_key(bool p_alpha) {
- SortArray<Element*,SortByKey> sorter;
+ SortArray<Element *, SortByKey> sorter;
if (p_alpha) {
- sorter.sort(&elements[max_elements-alpha_element_count],alpha_element_count);
+ sorter.sort(&elements[max_elements - alpha_element_count], alpha_element_count);
} else {
- sorter.sort(elements,element_count);
+ sorter.sort(elements, element_count);
}
}
struct SortByDepth {
- _FORCE_INLINE_ bool operator()(const Element* A, const Element* B ) const {
+ _FORCE_INLINE_ bool operator()(const Element *A, const Element *B) const {
return A->instance->depth > B->instance->depth;
}
};
void sort_by_depth(bool p_alpha) {
- SortArray<Element*,SortByDepth> sorter;
+ SortArray<Element *, SortByDepth> sorter;
if (p_alpha) {
- sorter.sort(&elements[max_elements-alpha_element_count],alpha_element_count);
+ sorter.sort(&elements[max_elements - alpha_element_count], alpha_element_count);
} else {
- sorter.sort(elements,element_count);
+ sorter.sort(elements, element_count);
}
}
+ _FORCE_INLINE_ Element *add_element() {
- _FORCE_INLINE_ Element* add_element() {
-
- if (element_count+alpha_element_count>=max_elements)
+ if (element_count + alpha_element_count >= max_elements)
return NULL;
- elements[element_count]=&_elements[element_count];
+ elements[element_count] = &_elements[element_count];
return elements[element_count++];
}
- _FORCE_INLINE_ Element* add_alpha_element() {
+ _FORCE_INLINE_ Element *add_alpha_element() {
- if (element_count+alpha_element_count>=max_elements)
+ if (element_count + alpha_element_count >= max_elements)
return NULL;
- int idx = max_elements-alpha_element_count-1;
- elements[idx]=&_elements[idx];
+ int idx = max_elements - alpha_element_count - 1;
+ elements[idx] = &_elements[idx];
alpha_element_count++;
return elements[idx];
}
@@ -689,18 +663,16 @@ public:
void init() {
element_count = 0;
- alpha_element_count =0;
- elements=memnew_arr(Element*,max_elements);
- _elements=memnew_arr(Element,max_elements);
- for (int i=0;i<max_elements;i++)
- elements[i]=&_elements[i]; // assign elements
-
+ alpha_element_count = 0;
+ elements = memnew_arr(Element *, max_elements);
+ _elements = memnew_arr(Element, max_elements);
+ for (int i = 0; i < max_elements; i++)
+ elements[i] = &_elements[i]; // assign elements
}
-
RenderList() {
- max_elements=DEFAULT_MAX_ELEMENTS;
+ max_elements = DEFAULT_MAX_ELEMENTS;
}
~RenderList() {
@@ -709,45 +681,41 @@ public:
}
};
-
LightInstance *directional_light;
LightInstance *directional_lights[RenderList::MAX_DIRECTIONAL_LIGHTS];
-
-
RenderList render_list;
- _FORCE_INLINE_ void _set_cull(bool p_front,bool p_reverse_cull);
+ _FORCE_INLINE_ void _set_cull(bool p_front, bool p_reverse_cull);
- _FORCE_INLINE_ bool _setup_material(RasterizerStorageGLES3::Material* p_material,bool p_alpha_pass);
- _FORCE_INLINE_ void _setup_transform(InstanceBase *p_instance,const Transform& p_view_transform,const CameraMatrix& p_projection);
+ _FORCE_INLINE_ bool _setup_material(RasterizerStorageGLES3::Material *p_material, bool p_alpha_pass);
+ _FORCE_INLINE_ void _setup_transform(InstanceBase *p_instance, const Transform &p_view_transform, const CameraMatrix &p_projection);
_FORCE_INLINE_ void _setup_geometry(RenderList::Element *e);
_FORCE_INLINE_ void _render_geometry(RenderList::Element *e);
- _FORCE_INLINE_ void _setup_light(RenderList::Element *e,const Transform& p_view_transform);
-
- void _render_list(RenderList::Element **p_elements, int p_element_count, const Transform& p_view_transform, const CameraMatrix& p_projection, GLuint p_base_env, bool p_reverse_cull, bool p_alpha_pass, bool p_shadow, bool p_directional_add, bool p_directional_shadows);
+ _FORCE_INLINE_ void _setup_light(RenderList::Element *e, const Transform &p_view_transform);
+ void _render_list(RenderList::Element **p_elements, int p_element_count, const Transform &p_view_transform, const CameraMatrix &p_projection, GLuint p_base_env, bool p_reverse_cull, bool p_alpha_pass, bool p_shadow, bool p_directional_add, bool p_directional_shadows);
- _FORCE_INLINE_ void _add_geometry( RasterizerStorageGLES3::Geometry* p_geometry, InstanceBase *p_instance, RasterizerStorageGLES3::GeometryOwner *p_owner,int p_material,bool p_shadow);
+ _FORCE_INLINE_ void _add_geometry(RasterizerStorageGLES3::Geometry *p_geometry, InstanceBase *p_instance, RasterizerStorageGLES3::GeometryOwner *p_owner, int p_material, bool p_shadow);
- void _draw_skybox(RasterizerStorageGLES3::SkyBox *p_skybox, const CameraMatrix& p_projection, const Transform& p_transform, bool p_vflip, float p_scale);
+ void _draw_skybox(RasterizerStorageGLES3::SkyBox *p_skybox, const CameraMatrix &p_projection, const Transform &p_transform, bool p_vflip, float p_scale);
- void _setup_environment(Environment *env, const CameraMatrix &p_cam_projection, const Transform& p_cam_transform);
+ void _setup_environment(Environment *env, const CameraMatrix &p_cam_projection, const Transform &p_cam_transform);
void _setup_directional_light(int p_index, const Transform &p_camera_inverse_transformm, bool p_use_shadows);
- void _setup_lights(RID *p_light_cull_result, int p_light_cull_count, const Transform &p_camera_inverse_transform, const CameraMatrix& p_camera_projection, RID p_shadow_atlas);
- void _setup_reflections(RID *p_reflection_probe_cull_result, int p_reflection_probe_cull_count, const Transform& p_camera_inverse_transform, const CameraMatrix& p_camera_projection, RID p_reflection_atlas, Environment *p_env);
+ void _setup_lights(RID *p_light_cull_result, int p_light_cull_count, const Transform &p_camera_inverse_transform, const CameraMatrix &p_camera_projection, RID p_shadow_atlas);
+ void _setup_reflections(RID *p_reflection_probe_cull_result, int p_reflection_probe_cull_count, const Transform &p_camera_inverse_transform, const CameraMatrix &p_camera_projection, RID p_reflection_atlas, Environment *p_env);
void _copy_screen();
void _copy_to_front_buffer(Environment *env);
void _copy_texture_to_front_buffer(GLuint p_texture); //used for debug
- void _fill_render_list(InstanceBase** p_cull_result,int p_cull_count,bool p_shadow);
+ void _fill_render_list(InstanceBase **p_cull_result, int p_cull_count, bool p_shadow);
void _render_mrts(Environment *env, const CameraMatrix &p_cam_projection);
void _post_process(Environment *env, const CameraMatrix &p_cam_projection);
- virtual void render_scene(const Transform& p_cam_transform,const CameraMatrix& p_cam_projection,bool p_cam_ortogonal,InstanceBase** p_cull_result,int p_cull_count,RID* p_light_cull_result,int p_light_cull_count,RID* p_reflection_probe_cull_result,int p_reflection_probe_cull_count,RID p_environment,RID p_shadow_atlas,RID p_reflection_atlas,RID p_reflection_probe,int p_reflection_probe_pass);
- virtual void render_shadow(RID p_light,RID p_shadow_atlas,int p_pass,InstanceBase** p_cull_result,int p_cull_count);
+ virtual void render_scene(const Transform &p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_ortogonal, InstanceBase **p_cull_result, int p_cull_count, RID *p_light_cull_result, int p_light_cull_count, RID *p_reflection_probe_cull_result, int p_reflection_probe_cull_count, RID p_environment, RID p_shadow_atlas, RID p_reflection_atlas, RID p_reflection_probe, int p_reflection_probe_pass);
+ virtual void render_shadow(RID p_light, RID p_shadow_atlas, int p_pass, InstanceBase **p_cull_result, int p_cull_count);
virtual bool free(RID p_rid);
void _generate_brdf();
diff --git a/drivers/gles3/rasterizer_storage_gles3.cpp b/drivers/gles3/rasterizer_storage_gles3.cpp
index 4fea28ddb7..ed4be1cb3d 100644
--- a/drivers/gles3/rasterizer_storage_gles3.cpp
+++ b/drivers/gles3/rasterizer_storage_gles3.cpp
@@ -27,32 +27,30 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "rasterizer_storage_gles3.h"
+#include "global_config.h"
#include "rasterizer_canvas_gles3.h"
#include "rasterizer_scene_gles3.h"
-#include "global_config.h"
/* TEXTURE API */
-#define _EXT_COMPRESSED_RGB_PVRTC_4BPPV1_IMG 0x8C00
-#define _EXT_COMPRESSED_RGB_PVRTC_2BPPV1_IMG 0x8C01
-#define _EXT_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG 0x8C02
-#define _EXT_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG 0x8C03
-
-#define _EXT_COMPRESSED_SRGB_PVRTC_2BPPV1_EXT 0x8A54
-#define _EXT_COMPRESSED_SRGB_PVRTC_4BPPV1_EXT 0x8A55
-#define _EXT_COMPRESSED_SRGB_ALPHA_PVRTC_2BPPV1_EXT 0x8A56
-#define _EXT_COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV1_EXT 0x8A57
+#define _EXT_COMPRESSED_RGB_PVRTC_4BPPV1_IMG 0x8C00
+#define _EXT_COMPRESSED_RGB_PVRTC_2BPPV1_IMG 0x8C01
+#define _EXT_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG 0x8C02
+#define _EXT_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG 0x8C03
+#define _EXT_COMPRESSED_SRGB_PVRTC_2BPPV1_EXT 0x8A54
+#define _EXT_COMPRESSED_SRGB_PVRTC_4BPPV1_EXT 0x8A55
+#define _EXT_COMPRESSED_SRGB_ALPHA_PVRTC_2BPPV1_EXT 0x8A56
+#define _EXT_COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV1_EXT 0x8A57
#define _EXT_COMPRESSED_RGBA_S3TC_DXT1_EXT 0x83F1
#define _EXT_COMPRESSED_RGBA_S3TC_DXT3_EXT 0x83F2
#define _EXT_COMPRESSED_RGBA_S3TC_DXT5_EXT 0x83F3
-#define _EXT_COMPRESSED_LUMINANCE_LATC1_EXT 0x8C70
-#define _EXT_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT 0x8C71
-#define _EXT_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT 0x8C72
-#define _EXT_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT 0x8C73
-
+#define _EXT_COMPRESSED_LUMINANCE_LATC1_EXT 0x8C70
+#define _EXT_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT 0x8C71
+#define _EXT_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT 0x8C72
+#define _EXT_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT 0x8C73
#define _EXT_COMPRESSED_RED_RGTC1_EXT 0x8DBB
#define _EXT_COMPRESSED_RED_RGTC1 0x8DBB
@@ -62,33 +60,27 @@
#define _EXT_COMPRESSED_SIGNED_RED_RGTC1_EXT 0x8DBC
#define _EXT_COMPRESSED_RED_GREEN_RGTC2_EXT 0x8DBD
#define _EXT_COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT 0x8DBE
-#define _EXT_ETC1_RGB8_OES 0x8D64
-
-
-
-#define _EXT_SLUMINANCE_NV 0x8C46
-#define _EXT_SLUMINANCE_ALPHA_NV 0x8C44
-#define _EXT_SRGB8_NV 0x8C41
-#define _EXT_SLUMINANCE8_NV 0x8C47
-#define _EXT_SLUMINANCE8_ALPHA8_NV 0x8C45
+#define _EXT_ETC1_RGB8_OES 0x8D64
+#define _EXT_SLUMINANCE_NV 0x8C46
+#define _EXT_SLUMINANCE_ALPHA_NV 0x8C44
+#define _EXT_SRGB8_NV 0x8C41
+#define _EXT_SLUMINANCE8_NV 0x8C47
+#define _EXT_SLUMINANCE8_ALPHA8_NV 0x8C45
-#define _EXT_COMPRESSED_SRGB_S3TC_DXT1_NV 0x8C4C
-#define _EXT_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_NV 0x8C4D
-#define _EXT_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_NV 0x8C4E
-#define _EXT_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_NV 0x8C4F
+#define _EXT_COMPRESSED_SRGB_S3TC_DXT1_NV 0x8C4C
+#define _EXT_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_NV 0x8C4D
+#define _EXT_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_NV 0x8C4E
+#define _EXT_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_NV 0x8C4F
+#define _EXT_ATC_RGB_AMD 0x8C92
+#define _EXT_ATC_RGBA_EXPLICIT_ALPHA_AMD 0x8C93
+#define _EXT_ATC_RGBA_INTERPOLATED_ALPHA_AMD 0x87EE
+#define _EXT_TEXTURE_CUBE_MAP_SEAMLESS 0x884F
-#define _EXT_ATC_RGB_AMD 0x8C92
-#define _EXT_ATC_RGBA_EXPLICIT_ALPHA_AMD 0x8C93
-#define _EXT_ATC_RGBA_INTERPOLATED_ALPHA_AMD 0x87EE
-
-
-#define _EXT_TEXTURE_CUBE_MAP_SEAMLESS 0x884F
-
-#define _GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE
-#define _GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT 0x84FF
+#define _GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE
+#define _GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT 0x84FF
#define _EXT_COMPRESSED_R11_EAC 0x9270
#define _EXT_COMPRESSED_SIGNED_R11_EAC 0x9271
@@ -108,235 +100,221 @@
GLuint RasterizerStorageGLES3::system_fbo = 0;
-Image RasterizerStorageGLES3::_get_gl_image_and_format(const Image& p_image, Image::Format p_format, uint32_t p_flags,GLenum& r_gl_format,GLenum& r_gl_internal_format,GLenum &r_gl_type,bool &r_compressed,bool &srgb) {
-
+Image RasterizerStorageGLES3::_get_gl_image_and_format(const Image &p_image, Image::Format p_format, uint32_t p_flags, GLenum &r_gl_format, GLenum &r_gl_internal_format, GLenum &r_gl_type, bool &r_compressed, bool &srgb) {
- r_compressed=false;
- r_gl_format=0;
- Image image=p_image;
- srgb=false;
+ r_compressed = false;
+ r_gl_format = 0;
+ Image image = p_image;
+ srgb = false;
- bool need_decompress=false;
+ bool need_decompress = false;
- switch(p_format) {
+ switch (p_format) {
case Image::FORMAT_L8: {
#ifdef GLES_OVER_GL
- r_gl_internal_format=GL_R8;
- r_gl_format=GL_RED;
- r_gl_type=GL_UNSIGNED_BYTE;
+ r_gl_internal_format = GL_R8;
+ r_gl_format = GL_RED;
+ r_gl_type = GL_UNSIGNED_BYTE;
#else
- r_gl_internal_format=GL_LUMINANCE;
- r_gl_format=GL_LUMINANCE;
- r_gl_type=GL_UNSIGNED_BYTE;
+ r_gl_internal_format = GL_LUMINANCE;
+ r_gl_format = GL_LUMINANCE;
+ r_gl_type = GL_UNSIGNED_BYTE;
#endif
} break;
case Image::FORMAT_LA8: {
#ifdef GLES_OVER_GL
- r_gl_internal_format=GL_RG8;
- r_gl_format=GL_RG;
- r_gl_type=GL_UNSIGNED_BYTE;
+ r_gl_internal_format = GL_RG8;
+ r_gl_format = GL_RG;
+ r_gl_type = GL_UNSIGNED_BYTE;
#else
- r_gl_internal_format=GL_LUMINANCE_ALPHA;
- r_gl_format=GL_LUMINANCE_ALPHA;
- r_gl_type=GL_UNSIGNED_BYTE;
+ r_gl_internal_format = GL_LUMINANCE_ALPHA;
+ r_gl_format = GL_LUMINANCE_ALPHA;
+ r_gl_type = GL_UNSIGNED_BYTE;
#endif
} break;
case Image::FORMAT_R8: {
- r_gl_internal_format=GL_R8;
- r_gl_format=GL_RED;
- r_gl_type=GL_UNSIGNED_BYTE;
+ r_gl_internal_format = GL_R8;
+ r_gl_format = GL_RED;
+ r_gl_type = GL_UNSIGNED_BYTE;
} break;
case Image::FORMAT_RG8: {
- r_gl_internal_format=GL_RG8;
- r_gl_format=GL_RG;
- r_gl_type=GL_UNSIGNED_BYTE;
+ r_gl_internal_format = GL_RG8;
+ r_gl_format = GL_RG;
+ r_gl_type = GL_UNSIGNED_BYTE;
} break;
case Image::FORMAT_RGB8: {
- r_gl_internal_format=(config.srgb_decode_supported || p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)?GL_SRGB8:GL_RGB8;
- r_gl_format=GL_RGB;
- r_gl_type=GL_UNSIGNED_BYTE;
- srgb=true;
+ r_gl_internal_format = (config.srgb_decode_supported || p_flags & VS::TEXTURE_FLAG_CONVERT_TO_LINEAR) ? GL_SRGB8 : GL_RGB8;
+ r_gl_format = GL_RGB;
+ r_gl_type = GL_UNSIGNED_BYTE;
+ srgb = true;
} break;
case Image::FORMAT_RGBA8: {
- r_gl_format=GL_RGBA;
- r_gl_internal_format=(config.srgb_decode_supported || p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)?GL_SRGB8_ALPHA8:GL_RGBA8;
- r_gl_type=GL_UNSIGNED_BYTE;
- srgb=true;
+ r_gl_format = GL_RGBA;
+ r_gl_internal_format = (config.srgb_decode_supported || p_flags & VS::TEXTURE_FLAG_CONVERT_TO_LINEAR) ? GL_SRGB8_ALPHA8 : GL_RGBA8;
+ r_gl_type = GL_UNSIGNED_BYTE;
+ srgb = true;
} break;
case Image::FORMAT_RGB565: {
#ifndef GLES_OVER_GL
- r_gl_internal_format=GL_RGB565;
+ r_gl_internal_format = GL_RGB565;
#else
-//#warning TODO: Convert tod 555 if 565 is not supported (GLES3.3-)
- r_gl_internal_format=GL_RGB5;
+ //#warning TODO: Convert tod 555 if 565 is not supported (GLES3.3-)
+ r_gl_internal_format = GL_RGB5;
#endif
//r_gl_internal_format=GL_RGB565;
- r_gl_format=GL_RGB;
- r_gl_type=GL_UNSIGNED_SHORT_5_6_5;
+ r_gl_format = GL_RGB;
+ r_gl_type = GL_UNSIGNED_SHORT_5_6_5;
} break;
case Image::FORMAT_RGBA4444: {
- r_gl_internal_format=GL_RGBA4;
- r_gl_format=GL_RGBA;
- r_gl_type=GL_UNSIGNED_SHORT_4_4_4_4;
+ r_gl_internal_format = GL_RGBA4;
+ r_gl_format = GL_RGBA;
+ r_gl_type = GL_UNSIGNED_SHORT_4_4_4_4;
} break;
case Image::FORMAT_RGBA5551: {
- r_gl_internal_format=GL_RGB5_A1;
- r_gl_format=GL_RGBA;
- r_gl_type=GL_UNSIGNED_SHORT_5_5_5_1;
-
+ r_gl_internal_format = GL_RGB5_A1;
+ r_gl_format = GL_RGBA;
+ r_gl_type = GL_UNSIGNED_SHORT_5_5_5_1;
} break;
case Image::FORMAT_RF: {
-
- r_gl_internal_format=GL_R32F;
- r_gl_format=GL_RED;
- r_gl_type=GL_FLOAT;
+ r_gl_internal_format = GL_R32F;
+ r_gl_format = GL_RED;
+ r_gl_type = GL_FLOAT;
} break;
case Image::FORMAT_RGF: {
- r_gl_internal_format=GL_RG32F;
- r_gl_format=GL_RG;
- r_gl_type=GL_FLOAT;
+ r_gl_internal_format = GL_RG32F;
+ r_gl_format = GL_RG;
+ r_gl_type = GL_FLOAT;
} break;
case Image::FORMAT_RGBF: {
- r_gl_internal_format=GL_RGB32F;
- r_gl_format=GL_RGB;
- r_gl_type=GL_FLOAT;
+ r_gl_internal_format = GL_RGB32F;
+ r_gl_format = GL_RGB;
+ r_gl_type = GL_FLOAT;
} break;
case Image::FORMAT_RGBAF: {
- r_gl_internal_format=GL_RGBA32F;
- r_gl_format=GL_RGBA;
- r_gl_type=GL_FLOAT;
+ r_gl_internal_format = GL_RGBA32F;
+ r_gl_format = GL_RGBA;
+ r_gl_type = GL_FLOAT;
} break;
case Image::FORMAT_RH: {
- r_gl_internal_format=GL_R32F;
- r_gl_format=GL_RED;
- r_gl_type=GL_HALF_FLOAT;
+ r_gl_internal_format = GL_R32F;
+ r_gl_format = GL_RED;
+ r_gl_type = GL_HALF_FLOAT;
} break;
case Image::FORMAT_RGH: {
- r_gl_internal_format=GL_RG32F;
- r_gl_format=GL_RG;
- r_gl_type=GL_HALF_FLOAT;
+ r_gl_internal_format = GL_RG32F;
+ r_gl_format = GL_RG;
+ r_gl_type = GL_HALF_FLOAT;
} break;
case Image::FORMAT_RGBH: {
- r_gl_internal_format=GL_RGB32F;
- r_gl_format=GL_RGB;
- r_gl_type=GL_HALF_FLOAT;
+ r_gl_internal_format = GL_RGB32F;
+ r_gl_format = GL_RGB;
+ r_gl_type = GL_HALF_FLOAT;
} break;
case Image::FORMAT_RGBAH: {
- r_gl_internal_format=GL_RGBA32F;
- r_gl_format=GL_RGBA;
- r_gl_type=GL_HALF_FLOAT;
+ r_gl_internal_format = GL_RGBA32F;
+ r_gl_format = GL_RGBA;
+ r_gl_type = GL_HALF_FLOAT;
} break;
case Image::FORMAT_DXT1: {
if (config.s3tc_supported) {
-
- r_gl_internal_format=(config.srgb_decode_supported || p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)?_EXT_COMPRESSED_SRGB_S3TC_DXT1_NV:_EXT_COMPRESSED_RGBA_S3TC_DXT1_EXT;
- r_gl_format=GL_RGBA;
- r_gl_type=GL_UNSIGNED_BYTE;
- r_compressed=true;
- srgb=true;
+ r_gl_internal_format = (config.srgb_decode_supported || p_flags & VS::TEXTURE_FLAG_CONVERT_TO_LINEAR) ? _EXT_COMPRESSED_SRGB_S3TC_DXT1_NV : _EXT_COMPRESSED_RGBA_S3TC_DXT1_EXT;
+ r_gl_format = GL_RGBA;
+ r_gl_type = GL_UNSIGNED_BYTE;
+ r_compressed = true;
+ srgb = true;
} else {
- need_decompress=true;
+ need_decompress = true;
}
-
} break;
case Image::FORMAT_DXT3: {
-
if (config.s3tc_supported) {
-
- r_gl_internal_format=(config.srgb_decode_supported || p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)?_EXT_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_NV:_EXT_COMPRESSED_RGBA_S3TC_DXT3_EXT;
- r_gl_format=GL_RGBA;
- r_gl_type=GL_UNSIGNED_BYTE;
- r_compressed=true;
- srgb=true;
+ r_gl_internal_format = (config.srgb_decode_supported || p_flags & VS::TEXTURE_FLAG_CONVERT_TO_LINEAR) ? _EXT_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_NV : _EXT_COMPRESSED_RGBA_S3TC_DXT3_EXT;
+ r_gl_format = GL_RGBA;
+ r_gl_type = GL_UNSIGNED_BYTE;
+ r_compressed = true;
+ srgb = true;
} else {
- need_decompress=true;
+ need_decompress = true;
}
-
} break;
case Image::FORMAT_DXT5: {
if (config.s3tc_supported) {
-
- r_gl_internal_format=(config.srgb_decode_supported || p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)?_EXT_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_NV:_EXT_COMPRESSED_RGBA_S3TC_DXT5_EXT;
- r_gl_format=GL_RGBA;
- r_gl_type=GL_UNSIGNED_BYTE;
- r_compressed=true;
- srgb=true;
+ r_gl_internal_format = (config.srgb_decode_supported || p_flags & VS::TEXTURE_FLAG_CONVERT_TO_LINEAR) ? _EXT_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_NV : _EXT_COMPRESSED_RGBA_S3TC_DXT5_EXT;
+ r_gl_format = GL_RGBA;
+ r_gl_type = GL_UNSIGNED_BYTE;
+ r_compressed = true;
+ srgb = true;
} else {
- need_decompress=true;
+ need_decompress = true;
}
-
} break;
case Image::FORMAT_ATI1: {
if (config.latc_supported) {
-
- r_gl_internal_format=_EXT_COMPRESSED_LUMINANCE_LATC1_EXT;
- r_gl_format=GL_RGBA;
- r_gl_type=GL_UNSIGNED_BYTE;
- r_compressed=true;
- srgb=true;
+ r_gl_internal_format = _EXT_COMPRESSED_LUMINANCE_LATC1_EXT;
+ r_gl_format = GL_RGBA;
+ r_gl_type = GL_UNSIGNED_BYTE;
+ r_compressed = true;
+ srgb = true;
} else {
- need_decompress=true;
+ need_decompress = true;
}
-
-
} break;
case Image::FORMAT_ATI2: {
if (config.latc_supported) {
-
- r_gl_internal_format=_EXT_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT;
- r_gl_format=GL_RGBA;
- r_gl_type=GL_UNSIGNED_BYTE;
- r_compressed=true;
+ r_gl_internal_format = _EXT_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT;
+ r_gl_format = GL_RGBA;
+ r_gl_type = GL_UNSIGNED_BYTE;
+ r_compressed = true;
} else {
- need_decompress=true;
+ need_decompress = true;
}
} break;
@@ -344,93 +322,86 @@ Image RasterizerStorageGLES3::_get_gl_image_and_format(const Image& p_image, Ima
if (config.bptc_supported) {
-
- r_gl_internal_format=(config.srgb_decode_supported || p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)?_EXT_COMPRESSED_SRGB_ALPHA_BPTC_UNORM:_EXT_COMPRESSED_RGBA_BPTC_UNORM;
- r_gl_format=GL_RGBA;
- r_gl_type=GL_UNSIGNED_BYTE;
- r_compressed=true;
- srgb=true;
+ r_gl_internal_format = (config.srgb_decode_supported || p_flags & VS::TEXTURE_FLAG_CONVERT_TO_LINEAR) ? _EXT_COMPRESSED_SRGB_ALPHA_BPTC_UNORM : _EXT_COMPRESSED_RGBA_BPTC_UNORM;
+ r_gl_format = GL_RGBA;
+ r_gl_type = GL_UNSIGNED_BYTE;
+ r_compressed = true;
+ srgb = true;
} else {
- need_decompress=true;
+ need_decompress = true;
}
} break;
case Image::FORMAT_BPTC_RGBF: {
if (config.bptc_supported) {
-
- r_gl_internal_format=_EXT_COMPRESSED_RGB_BPTC_SIGNED_FLOAT;
- r_gl_format=GL_RGB;
- r_gl_type=GL_FLOAT;
- r_compressed=true;
+ r_gl_internal_format = _EXT_COMPRESSED_RGB_BPTC_SIGNED_FLOAT;
+ r_gl_format = GL_RGB;
+ r_gl_type = GL_FLOAT;
+ r_compressed = true;
} else {
- need_decompress=true;
+ need_decompress = true;
}
} break;
case Image::FORMAT_BPTC_RGBFU: {
if (config.bptc_supported) {
-
- r_gl_internal_format=_EXT_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT;
- r_gl_format=GL_RGB;
- r_gl_type=GL_FLOAT;
- r_compressed=true;
+ r_gl_internal_format = _EXT_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT;
+ r_gl_format = GL_RGB;
+ r_gl_type = GL_FLOAT;
+ r_compressed = true;
} else {
- need_decompress=true;
+ need_decompress = true;
}
} break;
case Image::FORMAT_PVRTC2: {
if (config.pvrtc_supported) {
-
- r_gl_internal_format=(config.srgb_decode_supported || p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)?_EXT_COMPRESSED_SRGB_PVRTC_2BPPV1_EXT:_EXT_COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
- r_gl_format=GL_RGBA;
- r_gl_type=GL_UNSIGNED_BYTE;
- r_compressed=true;
- srgb=true;
+ r_gl_internal_format = (config.srgb_decode_supported || p_flags & VS::TEXTURE_FLAG_CONVERT_TO_LINEAR) ? _EXT_COMPRESSED_SRGB_PVRTC_2BPPV1_EXT : _EXT_COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
+ r_gl_format = GL_RGBA;
+ r_gl_type = GL_UNSIGNED_BYTE;
+ r_compressed = true;
+ srgb = true;
} else {
- need_decompress=true;
+ need_decompress = true;
}
} break;
case Image::FORMAT_PVRTC2A: {
if (config.pvrtc_supported) {
-
- r_gl_internal_format=(config.srgb_decode_supported || p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)?_EXT_COMPRESSED_SRGB_ALPHA_PVRTC_2BPPV1_EXT:_EXT_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
- r_gl_format=GL_RGBA;
- r_gl_type=GL_UNSIGNED_BYTE;
- r_compressed=true;
- srgb=true;
+ r_gl_internal_format = (config.srgb_decode_supported || p_flags & VS::TEXTURE_FLAG_CONVERT_TO_LINEAR) ? _EXT_COMPRESSED_SRGB_ALPHA_PVRTC_2BPPV1_EXT : _EXT_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
+ r_gl_format = GL_RGBA;
+ r_gl_type = GL_UNSIGNED_BYTE;
+ r_compressed = true;
+ srgb = true;
} else {
- need_decompress=true;
+ need_decompress = true;
}
-
} break;
case Image::FORMAT_PVRTC4: {
if (config.pvrtc_supported) {
-
- r_gl_internal_format=(config.srgb_decode_supported || p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)?_EXT_COMPRESSED_SRGB_PVRTC_4BPPV1_EXT:_EXT_COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
- r_gl_format=GL_RGBA;
- r_gl_type=GL_UNSIGNED_BYTE;
- r_compressed=true;
- srgb=true;
+ r_gl_internal_format = (config.srgb_decode_supported || p_flags & VS::TEXTURE_FLAG_CONVERT_TO_LINEAR) ? _EXT_COMPRESSED_SRGB_PVRTC_4BPPV1_EXT : _EXT_COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
+ r_gl_format = GL_RGBA;
+ r_gl_type = GL_UNSIGNED_BYTE;
+ r_compressed = true;
+ srgb = true;
} else {
- need_decompress=true;
+ need_decompress = true;
}
} break;
@@ -438,32 +409,30 @@ Image RasterizerStorageGLES3::_get_gl_image_and_format(const Image& p_image, Ima
if (config.pvrtc_supported) {
-
- r_gl_internal_format=(config.srgb_decode_supported || p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)?_EXT_COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV1_EXT:_EXT_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
- r_gl_format=GL_RGBA;
- r_gl_type=GL_UNSIGNED_BYTE;
- r_compressed=true;
- srgb=true;
+ r_gl_internal_format = (config.srgb_decode_supported || p_flags & VS::TEXTURE_FLAG_CONVERT_TO_LINEAR) ? _EXT_COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV1_EXT : _EXT_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
+ r_gl_format = GL_RGBA;
+ r_gl_type = GL_UNSIGNED_BYTE;
+ r_compressed = true;
+ srgb = true;
} else {
- need_decompress=true;
+ need_decompress = true;
}
-
} break;
case Image::FORMAT_ETC: {
if (config.etc_supported) {
- r_gl_internal_format=_EXT_ETC1_RGB8_OES;
- r_gl_format=GL_RGBA;
- r_gl_type=GL_UNSIGNED_BYTE;
- r_compressed=true;
+ r_gl_internal_format = _EXT_ETC1_RGB8_OES;
+ r_gl_format = GL_RGBA;
+ r_gl_type = GL_UNSIGNED_BYTE;
+ r_compressed = true;
} else {
- need_decompress=true;
+ need_decompress = true;
}
} break;
@@ -471,102 +440,99 @@ Image RasterizerStorageGLES3::_get_gl_image_and_format(const Image& p_image, Ima
if (config.etc2_supported) {
- r_gl_internal_format=_EXT_COMPRESSED_R11_EAC;
- r_gl_format=GL_RED;
- r_gl_type=GL_UNSIGNED_BYTE;
- r_compressed=true;
+ r_gl_internal_format = _EXT_COMPRESSED_R11_EAC;
+ r_gl_format = GL_RED;
+ r_gl_type = GL_UNSIGNED_BYTE;
+ r_compressed = true;
} else {
- need_decompress=true;
+ need_decompress = true;
}
} break;
case Image::FORMAT_ETC2_R11S: {
if (config.etc2_supported) {
- r_gl_internal_format=_EXT_COMPRESSED_SIGNED_R11_EAC;
- r_gl_format=GL_RED;
- r_gl_type=GL_UNSIGNED_BYTE;
- r_compressed=true;
+ r_gl_internal_format = _EXT_COMPRESSED_SIGNED_R11_EAC;
+ r_gl_format = GL_RED;
+ r_gl_type = GL_UNSIGNED_BYTE;
+ r_compressed = true;
} else {
- need_decompress=true;
+ need_decompress = true;
}
} break;
case Image::FORMAT_ETC2_RG11: {
if (config.etc2_supported) {
- r_gl_internal_format=_EXT_COMPRESSED_RG11_EAC;
- r_gl_format=GL_RG;
- r_gl_type=GL_UNSIGNED_BYTE;
- r_compressed=true;
+ r_gl_internal_format = _EXT_COMPRESSED_RG11_EAC;
+ r_gl_format = GL_RG;
+ r_gl_type = GL_UNSIGNED_BYTE;
+ r_compressed = true;
} else {
- need_decompress=true;
+ need_decompress = true;
}
} break;
case Image::FORMAT_ETC2_RG11S: {
if (config.etc2_supported) {
- r_gl_internal_format=_EXT_COMPRESSED_SIGNED_RG11_EAC;
- r_gl_format=GL_RG;
- r_gl_type=GL_UNSIGNED_BYTE;
- r_compressed=true;
+ r_gl_internal_format = _EXT_COMPRESSED_SIGNED_RG11_EAC;
+ r_gl_format = GL_RG;
+ r_gl_type = GL_UNSIGNED_BYTE;
+ r_compressed = true;
} else {
- need_decompress=true;
+ need_decompress = true;
}
} break;
case Image::FORMAT_ETC2_RGB8: {
if (config.etc2_supported) {
- r_gl_internal_format=(config.srgb_decode_supported || p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)?_EXT_COMPRESSED_SRGB8_ETC2:_EXT_COMPRESSED_RGB8_ETC2;
- r_gl_format=GL_RGB;
- r_gl_type=GL_UNSIGNED_BYTE;
- r_compressed=true;
- srgb=true;
-
+ r_gl_internal_format = (config.srgb_decode_supported || p_flags & VS::TEXTURE_FLAG_CONVERT_TO_LINEAR) ? _EXT_COMPRESSED_SRGB8_ETC2 : _EXT_COMPRESSED_RGB8_ETC2;
+ r_gl_format = GL_RGB;
+ r_gl_type = GL_UNSIGNED_BYTE;
+ r_compressed = true;
+ srgb = true;
} else {
- need_decompress=true;
+ need_decompress = true;
}
} break;
case Image::FORMAT_ETC2_RGBA8: {
if (config.etc2_supported) {
- r_gl_internal_format=(config.srgb_decode_supported || p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)?_EXT_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:_EXT_COMPRESSED_RGBA8_ETC2_EAC;
- r_gl_format=GL_RGBA;
- r_gl_type=GL_UNSIGNED_BYTE;
- r_compressed=true;
- srgb=true;
-
+ r_gl_internal_format = (config.srgb_decode_supported || p_flags & VS::TEXTURE_FLAG_CONVERT_TO_LINEAR) ? _EXT_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC : _EXT_COMPRESSED_RGBA8_ETC2_EAC;
+ r_gl_format = GL_RGBA;
+ r_gl_type = GL_UNSIGNED_BYTE;
+ r_compressed = true;
+ srgb = true;
} else {
- need_decompress=true;
+ need_decompress = true;
}
} break;
case Image::FORMAT_ETC2_RGB8A1: {
if (config.etc2_supported) {
- r_gl_internal_format=(config.srgb_decode_supported || p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)?_EXT_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:_EXT_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2;
- r_gl_format=GL_RGBA;
- r_gl_type=GL_UNSIGNED_BYTE;
- r_compressed=true;
- srgb=true;
-
+ r_gl_internal_format = (config.srgb_decode_supported || p_flags & VS::TEXTURE_FLAG_CONVERT_TO_LINEAR) ? _EXT_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2 : _EXT_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2;
+ r_gl_format = GL_RGBA;
+ r_gl_type = GL_UNSIGNED_BYTE;
+ r_compressed = true;
+ srgb = true;
} else {
- need_decompress=true;
+ need_decompress = true;
}
} break;
default: {
@@ -579,26 +545,23 @@ Image RasterizerStorageGLES3::_get_gl_image_and_format(const Image& p_image, Ima
if (!image.empty()) {
image.decompress();
- ERR_FAIL_COND_V(image.is_compressed(),image);
+ ERR_FAIL_COND_V(image.is_compressed(), image);
image.convert(Image::FORMAT_RGBA8);
}
-
- r_gl_format=GL_RGBA;
- r_gl_internal_format=(config.srgb_decode_supported || p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)?GL_SRGB8_ALPHA8:GL_RGBA8;
- r_gl_type=GL_UNSIGNED_BYTE;
- r_compressed=false;
- srgb=true;
+ r_gl_format = GL_RGBA;
+ r_gl_internal_format = (config.srgb_decode_supported || p_flags & VS::TEXTURE_FLAG_CONVERT_TO_LINEAR) ? GL_SRGB8_ALPHA8 : GL_RGBA8;
+ r_gl_type = GL_UNSIGNED_BYTE;
+ r_compressed = false;
+ srgb = true;
return image;
-
}
-
return image;
}
-static const GLenum _cube_side_enum[6]={
+static const GLenum _cube_side_enum[6] = {
GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
GL_TEXTURE_CUBE_MAP_POSITIVE_X,
@@ -612,16 +575,15 @@ static const GLenum _cube_side_enum[6]={
RID RasterizerStorageGLES3::texture_create() {
Texture *texture = memnew(Texture);
- ERR_FAIL_COND_V(!texture,RID());
+ ERR_FAIL_COND_V(!texture, RID());
glGenTextures(1, &texture->tex_id);
- texture->active=false;
- texture->total_data_size=0;
-
- return texture_owner.make_rid( texture );
+ texture->active = false;
+ texture->total_data_size = 0;
+ return texture_owner.make_rid(texture);
}
-void RasterizerStorageGLES3::texture_allocate(RID p_texture,int p_width, int p_height,Image::Format p_format,uint32_t p_flags) {
+void RasterizerStorageGLES3::texture_allocate(RID p_texture, int p_width, int p_height, Image::Format p_format, uint32_t p_flags) {
int components;
GLenum format;
@@ -631,56 +593,52 @@ void RasterizerStorageGLES3::texture_allocate(RID p_texture,int p_width, int p_h
bool compressed;
bool srgb;
- if (p_flags&VS::TEXTURE_FLAG_USED_FOR_STREAMING) {
- p_flags&=~VS::TEXTURE_FLAG_MIPMAPS; // no mipies for video
+ if (p_flags & VS::TEXTURE_FLAG_USED_FOR_STREAMING) {
+ p_flags &= ~VS::TEXTURE_FLAG_MIPMAPS; // no mipies for video
}
-
- Texture *texture = texture_owner.get( p_texture );
+ Texture *texture = texture_owner.get(p_texture);
ERR_FAIL_COND(!texture);
- texture->width=p_width;
- texture->height=p_height;
- texture->format=p_format;
- texture->flags=p_flags;
- texture->stored_cube_sides=0;
+ texture->width = p_width;
+ texture->height = p_height;
+ texture->format = p_format;
+ texture->flags = p_flags;
+ texture->stored_cube_sides = 0;
texture->target = (p_flags & VS::TEXTURE_FLAG_CUBEMAP) ? GL_TEXTURE_CUBE_MAP : GL_TEXTURE_2D;
- _get_gl_image_and_format(Image(),texture->format,texture->flags,format,internal_format,type,compressed,srgb);
+ _get_gl_image_and_format(Image(), texture->format, texture->flags, format, internal_format, type, compressed, srgb);
texture->alloc_width = texture->width;
texture->alloc_height = texture->height;
-
- texture->gl_format_cache=format;
- texture->gl_type_cache=type;
- texture->gl_internal_format_cache=internal_format;
- texture->compressed=compressed;
- texture->srgb=srgb;
- texture->data_size=0;
- texture->mipmaps=1;
-
+ texture->gl_format_cache = format;
+ texture->gl_type_cache = type;
+ texture->gl_internal_format_cache = internal_format;
+ texture->compressed = compressed;
+ texture->srgb = srgb;
+ texture->data_size = 0;
+ texture->mipmaps = 1;
glActiveTexture(GL_TEXTURE0);
glBindTexture(texture->target, texture->tex_id);
-
- if (p_flags&VS::TEXTURE_FLAG_USED_FOR_STREAMING) {
+ if (p_flags & VS::TEXTURE_FLAG_USED_FOR_STREAMING) {
//prealloc if video
- glTexImage2D(texture->target, 0, internal_format, p_width, p_height, 0, format, type,NULL);
+ glTexImage2D(texture->target, 0, internal_format, p_width, p_height, 0, format, type, NULL);
}
- texture->active=true;
+ texture->active = true;
}
-void RasterizerStorageGLES3::texture_set_data(RID p_texture,const Image& p_image,VS::CubeMapSide p_cube_side) {
+void RasterizerStorageGLES3::texture_set_data(RID p_texture, const Image &p_image, VS::CubeMapSide p_cube_side) {
- Texture * texture = texture_owner.get(p_texture);
+ Texture *texture = texture_owner.get(p_texture);
ERR_FAIL_COND(!texture);
ERR_FAIL_COND(!texture->active);
ERR_FAIL_COND(texture->render_target);
- ERR_FAIL_COND(texture->format != p_image.get_format() );
- ERR_FAIL_COND( p_image.empty() );
+ ERR_FAIL_COND(texture->format != p_image.get_format());
+ ERR_FAIL_COND(p_image.empty());
GLenum type;
GLenum format;
@@ -688,32 +646,29 @@ void RasterizerStorageGLES3::texture_set_data(RID p_texture,const Image& p_image
bool compressed;
bool srgb;
-
- if (config.keep_original_textures && !(texture->flags&VS::TEXTURE_FLAG_USED_FOR_STREAMING)) {
- texture->images[p_cube_side]=p_image;
+ if (config.keep_original_textures && !(texture->flags & VS::TEXTURE_FLAG_USED_FOR_STREAMING)) {
+ texture->images[p_cube_side] = p_image;
}
- Image img = _get_gl_image_and_format(p_image, p_image.get_format(),texture->flags,format,internal_format,type,compressed,srgb);
+ Image img = _get_gl_image_and_format(p_image, p_image.get_format(), texture->flags, format, internal_format, type, compressed, srgb);
- 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 & VS::TEXTURE_FLAG_USED_FOR_STREAMING)) {
- texture->alloc_height = MAX(1,texture->alloc_height/2);
- texture->alloc_width = MAX(1,texture->alloc_width/2);
+ texture->alloc_height = MAX(1, texture->alloc_height / 2);
+ texture->alloc_width = MAX(1, texture->alloc_width / 2);
- if (texture->alloc_width == img.get_width()/2 && texture->alloc_height == img.get_height()/2) {
+ if (texture->alloc_width == img.get_width() / 2 && texture->alloc_height == img.get_height() / 2) {
img.shrink_x2();
} else if (img.get_format() <= Image::FORMAT_RGB565) {
img.resize(texture->alloc_width, texture->alloc_height, Image::INTERPOLATE_BILINEAR);
-
}
};
+ GLenum blit_target = (texture->target == GL_TEXTURE_CUBE_MAP) ? _cube_side_enum[p_cube_side] : GL_TEXTURE_2D;
- GLenum blit_target = (texture->target == GL_TEXTURE_CUBE_MAP)?_cube_side_enum[p_cube_side]:GL_TEXTURE_2D;
-
- texture->data_size=img.get_data().size();
+ texture->data_size = img.get_data().size();
PoolVector<uint8_t>::Read read = img.get_data().read();
glActiveTexture(GL_TEXTURE0);
@@ -721,87 +676,83 @@ void RasterizerStorageGLES3::texture_set_data(RID p_texture,const Image& p_image
texture->ignore_mipmaps = compressed && !img.has_mipmaps();
- if (texture->flags&VS::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);
+ if (texture->flags & VS::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) {
- glTexParameteri(texture->target,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
+ if (texture->flags & VS::TEXTURE_FLAG_FILTER) {
+ glTexParameteri(texture->target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
} else {
- glTexParameteri(texture->target,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
-
+ glTexParameteri(texture->target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
}
}
-
if (config.srgb_decode_supported && srgb) {
- if (texture->flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR) {
+ if (texture->flags & VS::TEXTURE_FLAG_CONVERT_TO_LINEAR) {
- glTexParameteri(texture->target,_TEXTURE_SRGB_DECODE_EXT,_DECODE_EXT);
- texture->using_srgb=true;
+ glTexParameteri(texture->target, _TEXTURE_SRGB_DECODE_EXT, _DECODE_EXT);
+ texture->using_srgb = true;
} else {
- glTexParameteri(texture->target,_TEXTURE_SRGB_DECODE_EXT,_SKIP_DECODE_EXT);
- texture->using_srgb=false;
+ glTexParameteri(texture->target, _TEXTURE_SRGB_DECODE_EXT, _SKIP_DECODE_EXT);
+ texture->using_srgb = false;
}
}
- if (texture->flags&VS::TEXTURE_FLAG_FILTER) {
+ if (texture->flags & VS::TEXTURE_FLAG_FILTER) {
- glTexParameteri(texture->target,GL_TEXTURE_MAG_FILTER,GL_LINEAR); // Linear Filtering
+ glTexParameteri(texture->target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // Linear Filtering
} else {
- glTexParameteri(texture->target,GL_TEXTURE_MAG_FILTER,GL_NEAREST); // raw Filtering
+ 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 & VS::TEXTURE_FLAG_REPEAT || texture->flags & VS::TEXTURE_FLAG_MIRRORED_REPEAT) && texture->target != GL_TEXTURE_CUBE_MAP) {
- if (texture->flags&VS::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{
- glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
- glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
+ if (texture->flags & VS::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 {
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
}
} else {
//glTexParameterf( texture->target, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE );
- glTexParameterf( texture->target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
- glTexParameterf( texture->target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
+ glTexParameterf(texture->target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameterf(texture->target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
}
- //set swizle for older format compatibility
+//set swizle for older format compatibility
#ifdef GLES_OVER_GL
- switch(texture->format) {
+ switch (texture->format) {
case Image::FORMAT_L8: {
- glTexParameteri(texture->target,GL_TEXTURE_SWIZZLE_R,GL_RED);
- glTexParameteri(texture->target,GL_TEXTURE_SWIZZLE_G,GL_RED);
- glTexParameteri(texture->target,GL_TEXTURE_SWIZZLE_B,GL_RED);
- glTexParameteri(texture->target,GL_TEXTURE_SWIZZLE_A,GL_ONE);
+ glTexParameteri(texture->target, GL_TEXTURE_SWIZZLE_R, GL_RED);
+ glTexParameteri(texture->target, GL_TEXTURE_SWIZZLE_G, GL_RED);
+ glTexParameteri(texture->target, GL_TEXTURE_SWIZZLE_B, GL_RED);
+ glTexParameteri(texture->target, GL_TEXTURE_SWIZZLE_A, GL_ONE);
} break;
case Image::FORMAT_LA8: {
- glTexParameteri(texture->target,GL_TEXTURE_SWIZZLE_R,GL_RED);
- glTexParameteri(texture->target,GL_TEXTURE_SWIZZLE_G,GL_RED);
- glTexParameteri(texture->target,GL_TEXTURE_SWIZZLE_B,GL_RED);
- glTexParameteri(texture->target,GL_TEXTURE_SWIZZLE_A,GL_GREEN);
+ glTexParameteri(texture->target, GL_TEXTURE_SWIZZLE_R, GL_RED);
+ glTexParameteri(texture->target, GL_TEXTURE_SWIZZLE_G, GL_RED);
+ glTexParameteri(texture->target, GL_TEXTURE_SWIZZLE_B, GL_RED);
+ glTexParameteri(texture->target, GL_TEXTURE_SWIZZLE_A, GL_GREEN);
} break;
default: {
- glTexParameteri(texture->target,GL_TEXTURE_SWIZZLE_R,GL_RED);
- glTexParameteri(texture->target,GL_TEXTURE_SWIZZLE_G,GL_GREEN);
- glTexParameteri(texture->target,GL_TEXTURE_SWIZZLE_B,GL_BLUE);
- glTexParameteri(texture->target,GL_TEXTURE_SWIZZLE_A,GL_ALPHA);
+ glTexParameteri(texture->target, GL_TEXTURE_SWIZZLE_R, GL_RED);
+ glTexParameteri(texture->target, GL_TEXTURE_SWIZZLE_G, GL_GREEN);
+ glTexParameteri(texture->target, GL_TEXTURE_SWIZZLE_B, GL_BLUE);
+ glTexParameteri(texture->target, GL_TEXTURE_SWIZZLE_A, GL_ALPHA);
} break;
-
}
#endif
if (config.use_anisotropic_filter) {
- if (texture->flags&VS::TEXTURE_FLAG_ANISOTROPIC_FILTER) {
+ if (texture->flags & VS::TEXTURE_FLAG_ANISOTROPIC_FILTER) {
glTexParameterf(texture->target, _GL_TEXTURE_MAX_ANISOTROPY_EXT, config.anisotropic_level);
} else {
@@ -809,72 +760,66 @@ void RasterizerStorageGLES3::texture_set_data(RID p_texture,const Image& p_image
}
}
- int mipmaps= (texture->flags&VS::TEXTURE_FLAG_MIPMAPS && img.has_mipmaps()) ? img.get_mipmap_count() +1: 1;
-
+ int mipmaps = (texture->flags & VS::TEXTURE_FLAG_MIPMAPS && img.has_mipmaps()) ? img.get_mipmap_count() + 1 : 1;
- int w=img.get_width();
- int h=img.get_height();
+ int w = img.get_width();
+ int h = img.get_height();
- int tsize=0;
- for(int i=0;i<mipmaps;i++) {
+ int tsize = 0;
+ for (int i = 0; i < mipmaps; i++) {
- int size,ofs;
- img.get_mipmap_offset_and_size(i,ofs,size);
+ int size, ofs;
+ img.get_mipmap_offset_and_size(i, ofs, size);
//print_line("mipmap: "+itos(i)+" size: "+itos(size)+" w: "+itos(mm_w)+", h: "+itos(mm_h));
if (texture->compressed) {
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
- glCompressedTexImage2D( blit_target, i, internal_format,w,h,0,size,&read[ofs] );
+ glCompressedTexImage2D(blit_target, i, internal_format, w, h, 0, size, &read[ofs]);
} else {
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
- if (texture->flags&VS::TEXTURE_FLAG_USED_FOR_STREAMING) {
- glTexSubImage2D( blit_target, i, 0,0,w, h,format,type,&read[ofs] );
+ if (texture->flags & VS::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]);
+ glTexImage2D(blit_target, i, internal_format, w, h, 0, format, type, &read[ofs]);
}
-
}
- tsize+=size;
-
- w = MAX(1,w>>1);
- h = MAX(1,h>>1);
+ tsize += size;
+ w = MAX(1, w >> 1);
+ h = MAX(1, h >> 1);
}
- info.texture_mem-=texture->total_data_size;
- texture->total_data_size=tsize;
- info.texture_mem+=texture->total_data_size;
+ info.texture_mem -= texture->total_data_size;
+ texture->total_data_size = tsize;
+ info.texture_mem += texture->total_data_size;
//printf("texture: %i x %i - size: %i - total: %i\n",texture->width,texture->height,tsize,_rinfo.texture_mem);
- texture->stored_cube_sides|=(1<<p_cube_side);
+ texture->stored_cube_sides |= (1 << p_cube_side);
- if (texture->flags&VS::TEXTURE_FLAG_MIPMAPS && mipmaps==1 && !texture->ignore_mipmaps && (!(texture->flags&VS::TEXTURE_FLAG_CUBEMAP) || texture->stored_cube_sides==(1<<6)-1)) {
+ if (texture->flags & VS::TEXTURE_FLAG_MIPMAPS && mipmaps == 1 && !texture->ignore_mipmaps && (!(texture->flags & VS::TEXTURE_FLAG_CUBEMAP) || texture->stored_cube_sides == (1 << 6) - 1)) {
//generate mipmaps if they were requested and the image does not contain them
glGenerateMipmap(texture->target);
- } else if (mipmaps>1) {
+ } else if (mipmaps > 1) {
glTexParameteri(texture->target, GL_TEXTURE_BASE_LEVEL, 0);
- glTexParameteri(texture->target, GL_TEXTURE_MAX_LEVEL, mipmaps-1);
-
+ glTexParameteri(texture->target, GL_TEXTURE_MAX_LEVEL, mipmaps - 1);
}
- texture->mipmaps=mipmaps;
+ texture->mipmaps = mipmaps;
//texture_set_flags(p_texture,texture->flags);
-
-
}
-Image RasterizerStorageGLES3::texture_get_data(RID p_texture,VS::CubeMapSide p_cube_side) const {
+Image RasterizerStorageGLES3::texture_get_data(RID p_texture, VS::CubeMapSide p_cube_side) const {
- Texture * texture = texture_owner.get(p_texture);
+ Texture *texture = texture_owner.get(p_texture);
- ERR_FAIL_COND_V(!texture,Image());
- ERR_FAIL_COND_V(!texture->active,Image());
- ERR_FAIL_COND_V(texture->data_size==0,Image());
- ERR_FAIL_COND_V(texture->render_target,Image());
+ ERR_FAIL_COND_V(!texture, Image());
+ ERR_FAIL_COND_V(!texture->active, Image());
+ ERR_FAIL_COND_V(texture->data_size == 0, Image());
+ ERR_FAIL_COND_V(texture->render_target, Image());
if (!texture->images[p_cube_side].empty())
return texture->images[p_cube_side];
@@ -883,46 +828,44 @@ Image RasterizerStorageGLES3::texture_get_data(RID p_texture,VS::CubeMapSide p_c
PoolVector<uint8_t> data;
- int data_size = Image::get_image_data_size(texture->alloc_width,texture->alloc_height,texture->format,texture->mipmaps>1?-1:0);
+ int data_size = Image::get_image_data_size(texture->alloc_width, texture->alloc_height, texture->format, texture->mipmaps > 1 ? -1 : 0);
- data.resize(data_size*2); //add some memory at the end, just in case for buggy drivers
+ data.resize(data_size * 2); //add some memory at the end, just in case for buggy drivers
PoolVector<uint8_t>::Write wb = data.write();
glActiveTexture(GL_TEXTURE0);
- glBindTexture(texture->target,texture->tex_id);
+ glBindTexture(texture->target, texture->tex_id);
glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
- print_line("GET FORMAT: "+Image::get_format_name(texture->format)+" mipmaps: "+itos(texture->mipmaps));
-
+ print_line("GET FORMAT: " + Image::get_format_name(texture->format) + " mipmaps: " + itos(texture->mipmaps));
- for(int i=0;i<texture->mipmaps;i++) {
+ for (int i = 0; i < texture->mipmaps; i++) {
- int ofs=0;
- if (i>0) {
- ofs=Image::get_image_data_size(texture->alloc_width,texture->alloc_height,texture->format,i-1);
+ int ofs = 0;
+ if (i > 0) {
+ ofs = Image::get_image_data_size(texture->alloc_width, texture->alloc_height, texture->format, i - 1);
}
if (texture->compressed) {
glPixelStorei(GL_PACK_ALIGNMENT, 4);
- glGetCompressedTexImage(texture->target,i,&wb[ofs]);
+ glGetCompressedTexImage(texture->target, i, &wb[ofs]);
} else {
glPixelStorei(GL_PACK_ALIGNMENT, 1);
- glGetTexImage(texture->target,i,texture->gl_format_cache,texture->gl_type_cache,&wb[ofs]);
+ glGetTexImage(texture->target, i, texture->gl_format_cache, texture->gl_type_cache, &wb[ofs]);
}
}
-
- wb=PoolVector<uint8_t>::Write();
+ wb = PoolVector<uint8_t>::Write();
data.resize(data_size);
- Image img(texture->alloc_width,texture->alloc_height,texture->mipmaps>1?true:false,texture->format,data);
+ Image img(texture->alloc_width, texture->alloc_height, texture->mipmaps > 1 ? true : false, texture->format, data);
return img;
#else
@@ -932,44 +875,40 @@ Image RasterizerStorageGLES3::texture_get_data(RID p_texture,VS::CubeMapSide p_c
#endif
}
-void RasterizerStorageGLES3::texture_set_flags(RID p_texture,uint32_t p_flags) {
+void RasterizerStorageGLES3::texture_set_flags(RID p_texture, uint32_t p_flags) {
- Texture *texture = texture_owner.get( p_texture );
+ Texture *texture = texture_owner.get(p_texture);
ERR_FAIL_COND(!texture);
if (texture->render_target) {
- p_flags&=VS::TEXTURE_FLAG_FILTER;//can change only filter
+ p_flags &= VS::TEXTURE_FLAG_FILTER; //can change only filter
}
- bool had_mipmaps = texture->flags&VS::TEXTURE_FLAG_MIPMAPS;
+ bool had_mipmaps = texture->flags & VS::TEXTURE_FLAG_MIPMAPS;
glActiveTexture(GL_TEXTURE0);
glBindTexture(texture->target, texture->tex_id);
uint32_t cube = texture->flags & VS::TEXTURE_FLAG_CUBEMAP;
- texture->flags=p_flags|cube; // can't remove a cube from being a cube
+ texture->flags = p_flags | cube; // can't remove a cube from being a cube
+ if ((texture->flags & VS::TEXTURE_FLAG_REPEAT || texture->flags & VS::TEXTURE_FLAG_MIRRORED_REPEAT) && texture->target != GL_TEXTURE_CUBE_MAP) {
- if ((texture->flags&VS::TEXTURE_FLAG_REPEAT || texture->flags&VS::TEXTURE_FLAG_MIRRORED_REPEAT) && texture->target != GL_TEXTURE_CUBE_MAP) {
-
- if (texture->flags&VS::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 {
- glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
- glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
+ if (texture->flags & VS::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 {
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
}
} else {
//glTexParameterf( texture->target, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE );
- glTexParameterf( texture->target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
- glTexParameterf( texture->target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
-
+ glTexParameterf(texture->target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameterf(texture->target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
}
-
if (config.use_anisotropic_filter) {
- if (texture->flags&VS::TEXTURE_FLAG_ANISOTROPIC_FILTER) {
+ if (texture->flags & VS::TEXTURE_FLAG_ANISOTROPIC_FILTER) {
glTexParameterf(texture->target, _GL_TEXTURE_MAX_ANISOTROPY_EXT, config.anisotropic_level);
} else {
@@ -977,278 +916,256 @@ void RasterizerStorageGLES3::texture_set_flags(RID p_texture,uint32_t p_flags) {
}
}
- if (texture->flags&VS::TEXTURE_FLAG_MIPMAPS && !texture->ignore_mipmaps) {
- if (!had_mipmaps && texture->mipmaps==1) {
+ if (texture->flags & VS::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);
+ 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) {
- glTexParameteri(texture->target,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
+ } else {
+ if (texture->flags & VS::TEXTURE_FLAG_FILTER) {
+ glTexParameteri(texture->target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
} else {
- glTexParameteri(texture->target,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
-
+ glTexParameteri(texture->target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
}
}
-
if (config.srgb_decode_supported && texture->srgb) {
- if (texture->flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR) {
+ if (texture->flags & VS::TEXTURE_FLAG_CONVERT_TO_LINEAR) {
- glTexParameteri(texture->target,_TEXTURE_SRGB_DECODE_EXT,_DECODE_EXT);
- texture->using_srgb=true;
+ glTexParameteri(texture->target, _TEXTURE_SRGB_DECODE_EXT, _DECODE_EXT);
+ texture->using_srgb = true;
} else {
- glTexParameteri(texture->target,_TEXTURE_SRGB_DECODE_EXT,_SKIP_DECODE_EXT);
- texture->using_srgb=false;
+ glTexParameteri(texture->target, _TEXTURE_SRGB_DECODE_EXT, _SKIP_DECODE_EXT);
+ texture->using_srgb = false;
}
}
- if (texture->flags&VS::TEXTURE_FLAG_FILTER) {
+ if (texture->flags & VS::TEXTURE_FLAG_FILTER) {
- glTexParameteri(texture->target,GL_TEXTURE_MAG_FILTER,GL_LINEAR); // Linear Filtering
+ glTexParameteri(texture->target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // Linear Filtering
} else {
- glTexParameteri(texture->target,GL_TEXTURE_MAG_FILTER,GL_NEAREST); // raw Filtering
+ glTexParameteri(texture->target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); // raw Filtering
}
-
}
uint32_t RasterizerStorageGLES3::texture_get_flags(RID p_texture) const {
- Texture * texture = texture_owner.get(p_texture);
+ Texture *texture = texture_owner.get(p_texture);
- ERR_FAIL_COND_V(!texture,0);
+ ERR_FAIL_COND_V(!texture, 0);
return texture->flags;
-
}
Image::Format RasterizerStorageGLES3::texture_get_format(RID p_texture) const {
- Texture * texture = texture_owner.get(p_texture);
+ Texture *texture = texture_owner.get(p_texture);
- ERR_FAIL_COND_V(!texture,Image::FORMAT_L8);
+ ERR_FAIL_COND_V(!texture, Image::FORMAT_L8);
return texture->format;
}
uint32_t RasterizerStorageGLES3::texture_get_width(RID p_texture) const {
- Texture * texture = texture_owner.get(p_texture);
+ Texture *texture = texture_owner.get(p_texture);
- ERR_FAIL_COND_V(!texture,0);
+ ERR_FAIL_COND_V(!texture, 0);
return texture->width;
}
uint32_t RasterizerStorageGLES3::texture_get_height(RID p_texture) const {
- Texture * texture = texture_owner.get(p_texture);
+ Texture *texture = texture_owner.get(p_texture);
- ERR_FAIL_COND_V(!texture,0);
+ ERR_FAIL_COND_V(!texture, 0);
return texture->height;
}
+void RasterizerStorageGLES3::texture_set_size_override(RID p_texture, int p_width, int p_height) {
-void RasterizerStorageGLES3::texture_set_size_override(RID p_texture,int p_width, int p_height) {
-
- Texture * texture = texture_owner.get(p_texture);
+ Texture *texture = texture_owner.get(p_texture);
ERR_FAIL_COND(!texture);
ERR_FAIL_COND(texture->render_target);
- ERR_FAIL_COND(p_width<=0 || p_width>16384);
- ERR_FAIL_COND(p_height<=0 || p_height>16384);
+ ERR_FAIL_COND(p_width <= 0 || p_width > 16384);
+ ERR_FAIL_COND(p_height <= 0 || p_height > 16384);
//real texture size is in alloc width and height
- texture->width=p_width;
- texture->height=p_height;
-
+ texture->width = p_width;
+ texture->height = p_height;
}
-void RasterizerStorageGLES3::texture_set_path(RID p_texture,const String& p_path) {
- Texture * texture = texture_owner.get(p_texture);
+void RasterizerStorageGLES3::texture_set_path(RID p_texture, const String &p_path) {
+ Texture *texture = texture_owner.get(p_texture);
ERR_FAIL_COND(!texture);
- texture->path=p_path;
-
+ texture->path = p_path;
}
-String RasterizerStorageGLES3::texture_get_path(RID p_texture) const{
+String RasterizerStorageGLES3::texture_get_path(RID p_texture) const {
- Texture * texture = texture_owner.get(p_texture);
- ERR_FAIL_COND_V(!texture,String());
+ Texture *texture = texture_owner.get(p_texture);
+ ERR_FAIL_COND_V(!texture, String());
return texture->path;
}
-void RasterizerStorageGLES3::texture_debug_usage(List<VS::TextureInfo> *r_info){
+void RasterizerStorageGLES3::texture_debug_usage(List<VS::TextureInfo> *r_info) {
List<RID> textures;
texture_owner.get_owned_list(&textures);
- for (List<RID>::Element *E=textures.front();E;E=E->next()) {
+ for (List<RID>::Element *E = textures.front(); E; E = E->next()) {
Texture *t = texture_owner.get(E->get());
if (!t)
continue;
VS::TextureInfo tinfo;
- tinfo.path=t->path;
- tinfo.format=t->format;
- tinfo.size.x=t->alloc_width;
- tinfo.size.y=t->alloc_height;
- tinfo.bytes=t->total_data_size;
+ tinfo.path = t->path;
+ tinfo.format = t->format;
+ tinfo.size.x = t->alloc_width;
+ tinfo.size.y = t->alloc_height;
+ tinfo.bytes = t->total_data_size;
r_info->push_back(tinfo);
}
-
}
void RasterizerStorageGLES3::texture_set_shrink_all_x2_on_set_data(bool p_enable) {
- config.shrink_textures_x2=p_enable;
+ config.shrink_textures_x2 = p_enable;
}
void RasterizerStorageGLES3::textures_keep_original(bool p_enable) {
- config.keep_original_textures=p_enable;
+ config.keep_original_textures = p_enable;
}
-void RasterizerStorageGLES3::texture_set_detect_3d_callback(RID p_texture,VisualServer::TextureDetectCallback p_callback,void* p_userdata) {
+void RasterizerStorageGLES3::texture_set_detect_3d_callback(RID p_texture, VisualServer::TextureDetectCallback p_callback, void *p_userdata) {
- Texture * texture = texture_owner.get(p_texture);
+ Texture *texture = texture_owner.get(p_texture);
ERR_FAIL_COND(!texture);
- texture->detect_3d=p_callback;
- texture->detect_3d_ud=p_userdata;
+ texture->detect_3d = p_callback;
+ texture->detect_3d_ud = p_userdata;
}
-void RasterizerStorageGLES3::texture_set_detect_srgb_callback(RID p_texture,VisualServer::TextureDetectCallback p_callback,void* p_userdata){
- Texture * texture = texture_owner.get(p_texture);
+void RasterizerStorageGLES3::texture_set_detect_srgb_callback(RID p_texture, VisualServer::TextureDetectCallback p_callback, void *p_userdata) {
+ Texture *texture = texture_owner.get(p_texture);
ERR_FAIL_COND(!texture);
- texture->detect_srgb=p_callback;
- texture->detect_srgb_ud=p_userdata;
-
+ texture->detect_srgb = p_callback;
+ texture->detect_srgb_ud = p_userdata;
}
+RID RasterizerStorageGLES3::texture_create_radiance_cubemap(RID p_source, int p_resolution) const {
+ Texture *texture = texture_owner.get(p_source);
+ ERR_FAIL_COND_V(!texture, RID());
+ ERR_FAIL_COND_V(!(texture->flags & VS::TEXTURE_FLAG_CUBEMAP), RID());
-RID RasterizerStorageGLES3::texture_create_radiance_cubemap(RID p_source,int p_resolution) const {
-
- Texture * texture = texture_owner.get(p_source);
- ERR_FAIL_COND_V(!texture,RID());
- ERR_FAIL_COND_V(!(texture->flags&VS::TEXTURE_FLAG_CUBEMAP),RID());
-
- bool use_float=config.hdr_supported;
+ bool use_float = config.hdr_supported;
- if (p_resolution<0) {
- p_resolution=texture->width;
+ if (p_resolution < 0) {
+ p_resolution = texture->width;
}
-
glBindVertexArray(0);
glDisable(GL_CULL_FACE);
glDisable(GL_DEPTH_TEST);
glDisable(GL_SCISSOR_TEST);
glDisable(GL_BLEND);
-
glActiveTexture(GL_TEXTURE0);
glBindTexture(texture->target, texture->tex_id);
if (config.srgb_decode_supported && texture->srgb && !texture->using_srgb) {
- glTexParameteri(texture->target,_TEXTURE_SRGB_DECODE_EXT,_DECODE_EXT);
- texture->using_srgb=true;
+ glTexParameteri(texture->target, _TEXTURE_SRGB_DECODE_EXT, _DECODE_EXT);
+ texture->using_srgb = true;
#ifdef TOOLS_ENABLED
- if (!(texture->flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)) {
- texture->flags|=VS::TEXTURE_FLAG_CONVERT_TO_LINEAR;
+ if (!(texture->flags & VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)) {
+ texture->flags |= VS::TEXTURE_FLAG_CONVERT_TO_LINEAR;
//notify that texture must be set to linear beforehand, so it works in other platforms when exported
}
#endif
}
-
glActiveTexture(GL_TEXTURE1);
GLuint new_cubemap;
glGenTextures(1, &new_cubemap);
glBindTexture(GL_TEXTURE_CUBE_MAP, new_cubemap);
-
GLuint tmp_fb;
glGenFramebuffers(1, &tmp_fb);
glBindFramebuffer(GL_FRAMEBUFFER, tmp_fb);
-
int size = p_resolution;
- int lod=0;
+ int lod = 0;
shaders.cubemap_filter.bind();
- int mipmaps=6;
+ int mipmaps = 6;
- int mm_level=mipmaps;
+ int mm_level = mipmaps;
- GLenum internal_format = use_float?GL_RGBA16F:GL_RGB10_A2;
+ GLenum internal_format = use_float ? GL_RGBA16F : GL_RGB10_A2;
GLenum format = GL_RGBA;
- GLenum type = use_float?GL_HALF_FLOAT:GL_UNSIGNED_INT_2_10_10_10_REV;
+ GLenum type = use_float ? GL_HALF_FLOAT : GL_UNSIGNED_INT_2_10_10_10_REV;
+ while (mm_level) {
- while(mm_level) {
-
- for(int i=0;i<6;i++) {
- glTexImage2D(_cube_side_enum[i], lod, internal_format, size, size, 0, format, type, NULL);
+ for (int i = 0; i < 6; i++) {
+ glTexImage2D(_cube_side_enum[i], lod, internal_format, size, size, 0, format, type, NULL);
}
lod++;
mm_level--;
- if (size>1)
- size>>=1;
+ if (size > 1)
+ size >>= 1;
}
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BASE_LEVEL, 0);
- glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAX_LEVEL, lod-1);
+ glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAX_LEVEL, lod - 1);
- lod=0;
- mm_level=mipmaps;
+ lod = 0;
+ mm_level = mipmaps;
size = p_resolution;
- shaders.cubemap_filter.set_conditional(CubemapFilterShaderGLES3::USE_DUAL_PARABOLOID,false);
+ shaders.cubemap_filter.set_conditional(CubemapFilterShaderGLES3::USE_DUAL_PARABOLOID, false);
- while(mm_level) {
+ while (mm_level) {
- for(int i=0;i<6;i++) {
+ for (int i = 0; i < 6; i++) {
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, _cube_side_enum[i], new_cubemap, lod);
- glViewport(0,0,size,size);
+ glViewport(0, 0, size, size);
glBindVertexArray(resources.quadie_array);
- shaders.cubemap_filter.set_uniform(CubemapFilterShaderGLES3::FACE_ID,i);
- shaders.cubemap_filter.set_uniform(CubemapFilterShaderGLES3::ROUGHNESS,lod/float(mipmaps-1));
-
+ shaders.cubemap_filter.set_uniform(CubemapFilterShaderGLES3::FACE_ID, i);
+ shaders.cubemap_filter.set_uniform(CubemapFilterShaderGLES3::ROUGHNESS, lod / float(mipmaps - 1));
- glDrawArrays(GL_TRIANGLE_FAN,0,4);
+ glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
glBindVertexArray(0);
#ifdef DEBUG_ENABLED
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
- ERR_CONTINUE(status!=GL_FRAMEBUFFER_COMPLETE);
+ ERR_CONTINUE(status != GL_FRAMEBUFFER_COMPLETE);
#endif
}
-
-
- if (size>1)
- size>>=1;
+ if (size > 1)
+ size >>= 1;
lod++;
mm_level--;
-
}
-
//restore ranges
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BASE_LEVEL, 0);
- glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAX_LEVEL, lod-1);
+ glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAX_LEVEL, lod - 1);
glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
@@ -1259,59 +1176,58 @@ RID RasterizerStorageGLES3::texture_create_radiance_cubemap(RID p_source,int p_r
glBindFramebuffer(GL_FRAMEBUFFER, RasterizerStorageGLES3::system_fbo);
glDeleteFramebuffers(1, &tmp_fb);
- Texture * ctex = memnew( Texture );
-
- ctex->flags=VS::TEXTURE_FLAG_CUBEMAP|VS::TEXTURE_FLAG_MIPMAPS|VS::TEXTURE_FLAG_FILTER;
- ctex->width=p_resolution;
- ctex->height=p_resolution;
- ctex->alloc_width=p_resolution;
- ctex->alloc_height=p_resolution;
- ctex->format=use_float?Image::FORMAT_RGBAH:Image::FORMAT_RGBA8;
- ctex->target=GL_TEXTURE_CUBE_MAP;
- ctex->gl_format_cache=format;
- ctex->gl_internal_format_cache=internal_format;
- ctex->gl_type_cache=type;
- ctex->data_size=0;
- ctex->compressed=false;
- ctex->srgb=false;
- ctex->total_data_size=0;
- ctex->ignore_mipmaps=false;
- ctex->mipmaps=mipmaps;
- ctex->active=true;
- ctex->tex_id=new_cubemap;
- ctex->stored_cube_sides=(1<<6)-1;
- ctex->render_target=NULL;
+ Texture *ctex = memnew(Texture);
+
+ ctex->flags = VS::TEXTURE_FLAG_CUBEMAP | VS::TEXTURE_FLAG_MIPMAPS | VS::TEXTURE_FLAG_FILTER;
+ ctex->width = p_resolution;
+ ctex->height = p_resolution;
+ ctex->alloc_width = p_resolution;
+ ctex->alloc_height = p_resolution;
+ ctex->format = use_float ? Image::FORMAT_RGBAH : Image::FORMAT_RGBA8;
+ ctex->target = GL_TEXTURE_CUBE_MAP;
+ ctex->gl_format_cache = format;
+ ctex->gl_internal_format_cache = internal_format;
+ ctex->gl_type_cache = type;
+ ctex->data_size = 0;
+ ctex->compressed = false;
+ ctex->srgb = false;
+ ctex->total_data_size = 0;
+ ctex->ignore_mipmaps = false;
+ ctex->mipmaps = mipmaps;
+ ctex->active = true;
+ ctex->tex_id = new_cubemap;
+ ctex->stored_cube_sides = (1 << 6) - 1;
+ ctex->render_target = NULL;
return texture_owner.make_rid(ctex);
}
-
RID RasterizerStorageGLES3::skybox_create() {
- SkyBox *skybox = memnew( SkyBox );
- skybox->radiance=0;
+ SkyBox *skybox = memnew(SkyBox);
+ skybox->radiance = 0;
return skybox_owner.make_rid(skybox);
}
-void RasterizerStorageGLES3::skybox_set_texture(RID p_skybox, RID p_cube_map, int p_radiance_size){
+void RasterizerStorageGLES3::skybox_set_texture(RID p_skybox, RID p_cube_map, int p_radiance_size) {
SkyBox *skybox = skybox_owner.getornull(p_skybox);
ERR_FAIL_COND(!skybox);
if (skybox->cubemap.is_valid()) {
- skybox->cubemap=RID();
- glDeleteTextures(1,&skybox->radiance);
- skybox->radiance=0;
+ skybox->cubemap = RID();
+ glDeleteTextures(1, &skybox->radiance);
+ skybox->radiance = 0;
}
- skybox->cubemap=p_cube_map;
+ skybox->cubemap = p_cube_map;
if (!skybox->cubemap.is_valid())
return; //cleared
Texture *texture = texture_owner.getornull(skybox->cubemap);
- if (!texture || !(texture->flags&VS::TEXTURE_FLAG_CUBEMAP)) {
- skybox->cubemap=RID();
- ERR_FAIL_COND(!texture || !(texture->flags&VS::TEXTURE_FLAG_CUBEMAP));
+ if (!texture || !(texture->flags & VS::TEXTURE_FLAG_CUBEMAP)) {
+ skybox->cubemap = RID();
+ ERR_FAIL_COND(!texture || !(texture->flags & VS::TEXTURE_FLAG_CUBEMAP));
}
glBindVertexArray(0);
@@ -1320,23 +1236,21 @@ void RasterizerStorageGLES3::skybox_set_texture(RID p_skybox, RID p_cube_map, in
glDisable(GL_SCISSOR_TEST);
glDisable(GL_BLEND);
-
glActiveTexture(GL_TEXTURE0);
glBindTexture(texture->target, texture->tex_id);
if (config.srgb_decode_supported && texture->srgb && !texture->using_srgb) {
- glTexParameteri(texture->target,_TEXTURE_SRGB_DECODE_EXT,_DECODE_EXT);
- texture->using_srgb=true;
+ glTexParameteri(texture->target, _TEXTURE_SRGB_DECODE_EXT, _DECODE_EXT);
+ texture->using_srgb = true;
#ifdef TOOLS_ENABLED
- if (!(texture->flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)) {
- texture->flags|=VS::TEXTURE_FLAG_CONVERT_TO_LINEAR;
+ if (!(texture->flags & VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)) {
+ texture->flags |= VS::TEXTURE_FLAG_CONVERT_TO_LINEAR;
//notify that texture must be set to linear beforehand, so it works in other platforms when exported
}
#endif
}
-
glActiveTexture(GL_TEXTURE1);
glGenTextures(1, &skybox->radiance);
glBindTexture(GL_TEXTURE_2D, skybox->radiance);
@@ -1346,75 +1260,70 @@ void RasterizerStorageGLES3::skybox_set_texture(RID p_skybox, RID p_cube_map, in
glGenFramebuffers(1, &tmp_fb);
glBindFramebuffer(GL_FRAMEBUFFER, tmp_fb);
-
int size = p_radiance_size;
- int lod=0;
-
+ int lod = 0;
- int mipmaps=6;
+ int mipmaps = 6;
- int mm_level=mipmaps;
+ int mm_level = mipmaps;
- bool use_float=config.hdr_supported;
+ bool use_float = config.hdr_supported;
- GLenum internal_format = use_float?GL_RGBA16F:GL_RGB10_A2;
+ GLenum internal_format = use_float ? GL_RGBA16F : GL_RGB10_A2;
GLenum format = GL_RGBA;
- GLenum type = use_float?GL_HALF_FLOAT:GL_UNSIGNED_INT_2_10_10_10_REV;
+ GLenum type = use_float ? GL_HALF_FLOAT : GL_UNSIGNED_INT_2_10_10_10_REV;
- while(mm_level) {
+ while (mm_level) {
- glTexImage2D(GL_TEXTURE_2D, lod, internal_format, size, size*2, 0, format, type, NULL);
+ glTexImage2D(GL_TEXTURE_2D, lod, internal_format, size, size * 2, 0, format, type, NULL);
lod++;
mm_level--;
- if (size>1)
- size>>=1;
+ if (size > 1)
+ size >>= 1;
}
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, lod-1);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, lod - 1);
- lod=0;
- mm_level=mipmaps;
+ lod = 0;
+ mm_level = mipmaps;
size = p_radiance_size;
- shaders.cubemap_filter.set_conditional(CubemapFilterShaderGLES3::USE_DUAL_PARABOLOID,true);
+ shaders.cubemap_filter.set_conditional(CubemapFilterShaderGLES3::USE_DUAL_PARABOLOID, true);
shaders.cubemap_filter.bind();
- while(mm_level) {
+ while (mm_level) {
- glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, skybox->radiance, lod);
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, skybox->radiance, lod);
#ifdef DEBUG_ENABLED
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
- ERR_CONTINUE(status!=GL_FRAMEBUFFER_COMPLETE);
+ ERR_CONTINUE(status != GL_FRAMEBUFFER_COMPLETE);
#endif
- for(int i=0;i<2;i++) {
- glViewport(0,i*size,size,size);
+ for (int i = 0; i < 2; i++) {
+ glViewport(0, i * size, size, size);
glBindVertexArray(resources.quadie_array);
- shaders.cubemap_filter.set_uniform(CubemapFilterShaderGLES3::Z_FLIP,i>0);
- shaders.cubemap_filter.set_uniform(CubemapFilterShaderGLES3::ROUGHNESS,lod/float(mipmaps-1));
-
+ shaders.cubemap_filter.set_uniform(CubemapFilterShaderGLES3::Z_FLIP, i > 0);
+ shaders.cubemap_filter.set_uniform(CubemapFilterShaderGLES3::ROUGHNESS, lod / float(mipmaps - 1));
- glDrawArrays(GL_TRIANGLE_FAN,0,4);
+ glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
glBindVertexArray(0);
}
- if (size>1)
- size>>=1;
+ if (size > 1)
+ size >>= 1;
lod++;
mm_level--;
-
}
- shaders.cubemap_filter.set_conditional(CubemapFilterShaderGLES3::USE_DUAL_PARABOLOID,false);
-
+ shaders.cubemap_filter.set_conditional(CubemapFilterShaderGLES3::USE_DUAL_PARABOLOID, false);
//restore ranges
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, lod-1);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, lod - 1);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
@@ -1423,26 +1332,23 @@ void RasterizerStorageGLES3::skybox_set_texture(RID p_skybox, RID p_cube_map, in
glBindFramebuffer(GL_FRAMEBUFFER, RasterizerStorageGLES3::system_fbo);
glDeleteFramebuffers(1, &tmp_fb);
-
}
-
/* SHADER API */
+RID RasterizerStorageGLES3::shader_create(VS::ShaderMode p_mode) {
-RID RasterizerStorageGLES3::shader_create(VS::ShaderMode p_mode){
-
- Shader *shader = memnew( Shader );
- shader->mode=p_mode;
+ Shader *shader = memnew(Shader);
+ shader->mode = p_mode;
RID rid = shader_owner.make_rid(shader);
- shader_set_mode(rid,p_mode);
+ shader_set_mode(rid, p_mode);
_shader_make_dirty(shader);
- shader->self=rid;
+ shader->self = rid;
return rid;
}
-void RasterizerStorageGLES3::_shader_make_dirty(Shader* p_shader) {
+void RasterizerStorageGLES3::_shader_make_dirty(Shader *p_shader) {
if (p_shader->dirty_list.in_list())
return;
@@ -1450,217 +1356,212 @@ void RasterizerStorageGLES3::_shader_make_dirty(Shader* p_shader) {
_shader_dirty_list.add(&p_shader->dirty_list);
}
-void RasterizerStorageGLES3::shader_set_mode(RID p_shader,VS::ShaderMode p_mode){
+void RasterizerStorageGLES3::shader_set_mode(RID p_shader, VS::ShaderMode p_mode) {
- ERR_FAIL_INDEX(p_mode,VS::SHADER_MAX);
- Shader *shader=shader_owner.get(p_shader);
+ ERR_FAIL_INDEX(p_mode, VS::SHADER_MAX);
+ Shader *shader = shader_owner.get(p_shader);
ERR_FAIL_COND(!shader);
- if (shader->custom_code_id && p_mode==shader->mode)
+ if (shader->custom_code_id && p_mode == shader->mode)
return;
-
if (shader->custom_code_id) {
shader->shader->free_custom_shader(shader->custom_code_id);
- shader->custom_code_id=0;
+ shader->custom_code_id = 0;
}
- shader->mode=p_mode;
+ shader->mode = p_mode;
- ShaderGLES3* shaders[VS::SHADER_MAX]={
+ ShaderGLES3 *shaders[VS::SHADER_MAX] = {
&scene->state.scene_shader,
&canvas->state.canvas_shader,
&this->shaders.particles,
};
- shader->shader=shaders[p_mode];
+ shader->shader = shaders[p_mode];
shader->custom_code_id = shader->shader->create_custom_shader();
_shader_make_dirty(shader);
-
}
VS::ShaderMode RasterizerStorageGLES3::shader_get_mode(RID p_shader) const {
- const Shader *shader=shader_owner.get(p_shader);
- ERR_FAIL_COND_V(!shader,VS::SHADER_MAX);
+ const Shader *shader = shader_owner.get(p_shader);
+ ERR_FAIL_COND_V(!shader, VS::SHADER_MAX);
return shader->mode;
}
-void RasterizerStorageGLES3::shader_set_code(RID p_shader, const String& p_code){
+void RasterizerStorageGLES3::shader_set_code(RID p_shader, const String &p_code) {
- Shader *shader=shader_owner.get(p_shader);
+ Shader *shader = shader_owner.get(p_shader);
ERR_FAIL_COND(!shader);
- shader->code=p_code;
+ shader->code = p_code;
_shader_make_dirty(shader);
}
-String RasterizerStorageGLES3::shader_get_code(RID p_shader) const{
-
- const Shader *shader=shader_owner.get(p_shader);
- ERR_FAIL_COND_V(!shader,String());
+String RasterizerStorageGLES3::shader_get_code(RID p_shader) const {
+ const Shader *shader = shader_owner.get(p_shader);
+ ERR_FAIL_COND_V(!shader, String());
return shader->code;
}
-void RasterizerStorageGLES3::_update_shader(Shader* p_shader) const {
-
+void RasterizerStorageGLES3::_update_shader(Shader *p_shader) const {
- _shader_dirty_list.remove( &p_shader->dirty_list );
+ _shader_dirty_list.remove(&p_shader->dirty_list);
- p_shader->valid=false;
+ p_shader->valid = false;
p_shader->uniforms.clear();
ShaderCompilerGLES3::GeneratedCode gen_code;
- ShaderCompilerGLES3::IdentifierActions *actions=NULL;
-
+ ShaderCompilerGLES3::IdentifierActions *actions = NULL;
-
- switch(p_shader->mode) {
+ switch (p_shader->mode) {
case VS::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;
+ p_shader->canvas_item.light_mode = Shader::CanvasItem::LIGHT_MODE_NORMAL;
+ p_shader->canvas_item.blend_mode = Shader::CanvasItem::BLEND_MODE_MIX;
- shaders.actions_canvas.render_mode_values["blend_add"]=Pair<int*,int>(&p_shader->canvas_item.blend_mode,Shader::CanvasItem::BLEND_MODE_ADD);
- shaders.actions_canvas.render_mode_values["blend_mix"]=Pair<int*,int>(&p_shader->canvas_item.blend_mode,Shader::CanvasItem::BLEND_MODE_MIX);
- shaders.actions_canvas.render_mode_values["blend_sub"]=Pair<int*,int>(&p_shader->canvas_item.blend_mode,Shader::CanvasItem::BLEND_MODE_SUB);
- shaders.actions_canvas.render_mode_values["blend_mul"]=Pair<int*,int>(&p_shader->canvas_item.blend_mode,Shader::CanvasItem::BLEND_MODE_MUL);
- shaders.actions_canvas.render_mode_values["blend_premul_alpha"]=Pair<int*,int>(&p_shader->canvas_item.blend_mode,Shader::CanvasItem::BLEND_MODE_PMALPHA);
+ shaders.actions_canvas.render_mode_values["blend_add"] = Pair<int *, int>(&p_shader->canvas_item.blend_mode, Shader::CanvasItem::BLEND_MODE_ADD);
+ shaders.actions_canvas.render_mode_values["blend_mix"] = Pair<int *, int>(&p_shader->canvas_item.blend_mode, Shader::CanvasItem::BLEND_MODE_MIX);
+ shaders.actions_canvas.render_mode_values["blend_sub"] = Pair<int *, int>(&p_shader->canvas_item.blend_mode, Shader::CanvasItem::BLEND_MODE_SUB);
+ shaders.actions_canvas.render_mode_values["blend_mul"] = Pair<int *, int>(&p_shader->canvas_item.blend_mode, Shader::CanvasItem::BLEND_MODE_MUL);
+ shaders.actions_canvas.render_mode_values["blend_premul_alpha"] = Pair<int *, int>(&p_shader->canvas_item.blend_mode, Shader::CanvasItem::BLEND_MODE_PMALPHA);
- shaders.actions_canvas.render_mode_values["unshaded"]=Pair<int*,int>(&p_shader->canvas_item.light_mode,Shader::CanvasItem::LIGHT_MODE_UNSHADED);
- shaders.actions_canvas.render_mode_values["light_only"]=Pair<int*,int>(&p_shader->canvas_item.light_mode,Shader::CanvasItem::LIGHT_MODE_LIGHT_ONLY);
+ shaders.actions_canvas.render_mode_values["unshaded"] = Pair<int *, int>(&p_shader->canvas_item.light_mode, Shader::CanvasItem::LIGHT_MODE_UNSHADED);
+ shaders.actions_canvas.render_mode_values["light_only"] = Pair<int *, int>(&p_shader->canvas_item.light_mode, Shader::CanvasItem::LIGHT_MODE_LIGHT_ONLY);
- actions=&shaders.actions_canvas;
- actions->uniforms=&p_shader->uniforms;
+ actions = &shaders.actions_canvas;
+ actions->uniforms = &p_shader->uniforms;
} break;
case VS::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;
- p_shader->spatial.uses_alpha=false;
- p_shader->spatial.uses_discard=false;
- p_shader->spatial.unshaded=false;
- p_shader->spatial.ontop=false;
- p_shader->spatial.uses_sss=false;
- p_shader->spatial.uses_vertex=false;
-
- shaders.actions_scene.render_mode_values["blend_add"]=Pair<int*,int>(&p_shader->spatial.blend_mode,Shader::Spatial::BLEND_MODE_ADD);
- shaders.actions_scene.render_mode_values["blend_mix"]=Pair<int*,int>(&p_shader->spatial.blend_mode,Shader::Spatial::BLEND_MODE_MIX);
- shaders.actions_scene.render_mode_values["blend_sub"]=Pair<int*,int>(&p_shader->spatial.blend_mode,Shader::Spatial::BLEND_MODE_SUB);
- shaders.actions_scene.render_mode_values["blend_mul"]=Pair<int*,int>(&p_shader->spatial.blend_mode,Shader::Spatial::BLEND_MODE_MUL);
+ 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;
+ p_shader->spatial.uses_alpha = false;
+ p_shader->spatial.uses_discard = false;
+ p_shader->spatial.unshaded = false;
+ p_shader->spatial.ontop = false;
+ p_shader->spatial.uses_sss = false;
+ p_shader->spatial.uses_vertex = false;
- shaders.actions_scene.render_mode_values["depth_draw_opaque"]=Pair<int*,int>(&p_shader->spatial.depth_draw_mode,Shader::Spatial::DEPTH_DRAW_OPAQUE);
- shaders.actions_scene.render_mode_values["depth_draw_always"]=Pair<int*,int>(&p_shader->spatial.depth_draw_mode,Shader::Spatial::DEPTH_DRAW_ALWAYS);
- shaders.actions_scene.render_mode_values["depth_draw_never"]=Pair<int*,int>(&p_shader->spatial.depth_draw_mode,Shader::Spatial::DEPTH_DRAW_NEVER);
- shaders.actions_scene.render_mode_values["depth_draw_alpha_prepass"]=Pair<int*,int>(&p_shader->spatial.depth_draw_mode,Shader::Spatial::DEPTH_DRAW_ALPHA_PREPASS);
+ shaders.actions_scene.render_mode_values["blend_add"] = Pair<int *, int>(&p_shader->spatial.blend_mode, Shader::Spatial::BLEND_MODE_ADD);
+ shaders.actions_scene.render_mode_values["blend_mix"] = Pair<int *, int>(&p_shader->spatial.blend_mode, Shader::Spatial::BLEND_MODE_MIX);
+ shaders.actions_scene.render_mode_values["blend_sub"] = Pair<int *, int>(&p_shader->spatial.blend_mode, Shader::Spatial::BLEND_MODE_SUB);
+ shaders.actions_scene.render_mode_values["blend_mul"] = Pair<int *, int>(&p_shader->spatial.blend_mode, Shader::Spatial::BLEND_MODE_MUL);
- shaders.actions_scene.render_mode_values["cull_front"]=Pair<int*,int>(&p_shader->spatial.cull_mode,Shader::Spatial::CULL_MODE_FRONT);
- shaders.actions_scene.render_mode_values["cull_back"]=Pair<int*,int>(&p_shader->spatial.cull_mode,Shader::Spatial::CULL_MODE_BACK);
- shaders.actions_scene.render_mode_values["cull_disabled"]=Pair<int*,int>(&p_shader->spatial.cull_mode,Shader::Spatial::CULL_MODE_DISABLED);
+ shaders.actions_scene.render_mode_values["depth_draw_opaque"] = Pair<int *, int>(&p_shader->spatial.depth_draw_mode, Shader::Spatial::DEPTH_DRAW_OPAQUE);
+ shaders.actions_scene.render_mode_values["depth_draw_always"] = Pair<int *, int>(&p_shader->spatial.depth_draw_mode, Shader::Spatial::DEPTH_DRAW_ALWAYS);
+ shaders.actions_scene.render_mode_values["depth_draw_never"] = Pair<int *, int>(&p_shader->spatial.depth_draw_mode, Shader::Spatial::DEPTH_DRAW_NEVER);
+ shaders.actions_scene.render_mode_values["depth_draw_alpha_prepass"] = Pair<int *, int>(&p_shader->spatial.depth_draw_mode, Shader::Spatial::DEPTH_DRAW_ALPHA_PREPASS);
- shaders.actions_scene.render_mode_flags["unshaded"]=&p_shader->spatial.unshaded;
- shaders.actions_scene.render_mode_flags["ontop"]=&p_shader->spatial.ontop;
+ shaders.actions_scene.render_mode_values["cull_front"] = Pair<int *, int>(&p_shader->spatial.cull_mode, Shader::Spatial::CULL_MODE_FRONT);
+ shaders.actions_scene.render_mode_values["cull_back"] = Pair<int *, int>(&p_shader->spatial.cull_mode, Shader::Spatial::CULL_MODE_BACK);
+ shaders.actions_scene.render_mode_values["cull_disabled"] = Pair<int *, int>(&p_shader->spatial.cull_mode, Shader::Spatial::CULL_MODE_DISABLED);
- shaders.actions_scene.usage_flag_pointers["ALPHA"]=&p_shader->spatial.uses_alpha;
- shaders.actions_scene.usage_flag_pointers["VERTEX"]=&p_shader->spatial.uses_vertex;
+ shaders.actions_scene.render_mode_flags["unshaded"] = &p_shader->spatial.unshaded;
+ shaders.actions_scene.render_mode_flags["ontop"] = &p_shader->spatial.ontop;
- shaders.actions_scene.usage_flag_pointers["SSS_STRENGTH"]=&p_shader->spatial.uses_sss;
- shaders.actions_scene.usage_flag_pointers["DISCARD"]=&p_shader->spatial.uses_discard;
+ shaders.actions_scene.usage_flag_pointers["ALPHA"] = &p_shader->spatial.uses_alpha;
+ shaders.actions_scene.usage_flag_pointers["VERTEX"] = &p_shader->spatial.uses_vertex;
- actions=&shaders.actions_scene;
- actions->uniforms=&p_shader->uniforms;
+ shaders.actions_scene.usage_flag_pointers["SSS_STRENGTH"] = &p_shader->spatial.uses_sss;
+ shaders.actions_scene.usage_flag_pointers["DISCARD"] = &p_shader->spatial.uses_discard;
+ actions = &shaders.actions_scene;
+ actions->uniforms = &p_shader->uniforms;
} break;
case VS::SHADER_PARTICLES: {
- actions=&shaders.actions_particles;
- actions->uniforms=&p_shader->uniforms;
+ actions = &shaders.actions_particles;
+ actions->uniforms = &p_shader->uniforms;
} break;
-
}
+ Error err = shaders.compiler.compile(p_shader->mode, p_shader->code, actions, p_shader->path, gen_code);
- Error err = shaders.compiler.compile(p_shader->mode,p_shader->code,actions,p_shader->path,gen_code);
+ ERR_FAIL_COND(err != OK);
+ p_shader->shader->set_custom_shader_code(p_shader->custom_code_id, gen_code.vertex, gen_code.vertex_global, gen_code.fragment, gen_code.light, gen_code.fragment_global, gen_code.uniforms, gen_code.texture_uniforms, gen_code.defines);
- ERR_FAIL_COND(err!=OK);
+ p_shader->ubo_size = gen_code.uniform_total_size;
+ p_shader->ubo_offsets = gen_code.uniform_offsets;
+ p_shader->texture_count = gen_code.texture_uniforms.size();
+ p_shader->texture_hints = gen_code.texture_hints;
- p_shader->shader->set_custom_shader_code(p_shader->custom_code_id,gen_code.vertex,gen_code.vertex_global,gen_code.fragment,gen_code.light,gen_code.fragment_global,gen_code.uniforms,gen_code.texture_uniforms,gen_code.defines);
-
- p_shader->ubo_size=gen_code.uniform_total_size;
- p_shader->ubo_offsets=gen_code.uniform_offsets;
- p_shader->texture_count=gen_code.texture_uniforms.size();
- p_shader->texture_hints=gen_code.texture_hints;
-
- p_shader->uses_vertex_time=gen_code.uses_vertex_time;
- p_shader->uses_fragment_time=gen_code.uses_fragment_time;
+ p_shader->uses_vertex_time = gen_code.uses_vertex_time;
+ p_shader->uses_fragment_time = gen_code.uses_fragment_time;
//all materials using this shader will have to be invalidated, unfortunately
- for (SelfList<Material>* E = p_shader->materials.first();E;E=E->next() ) {
+ for (SelfList<Material> *E = p_shader->materials.first(); E; E = E->next()) {
_material_make_dirty(E->self());
}
- p_shader->valid=true;
+ p_shader->valid = true;
p_shader->version++;
-
-
}
void RasterizerStorageGLES3::update_dirty_shaders() {
- while( _shader_dirty_list.first() ) {
- _update_shader(_shader_dirty_list.first()->self() );
+ while (_shader_dirty_list.first()) {
+ _update_shader(_shader_dirty_list.first()->self());
}
}
-void RasterizerStorageGLES3::shader_get_param_list(RID p_shader, List<PropertyInfo> *p_param_list) const{
+void RasterizerStorageGLES3::shader_get_param_list(RID p_shader, List<PropertyInfo> *p_param_list) const {
- Shader *shader=shader_owner.get(p_shader);
+ Shader *shader = shader_owner.get(p_shader);
ERR_FAIL_COND(!shader);
-
if (shader->dirty_list.in_list())
_update_shader(shader); // ok should be not anymore dirty
+ Map<int, StringName> order;
- Map<int,StringName> order;
-
-
- for(Map<StringName,ShaderLanguage::ShaderNode::Uniform>::Element *E=shader->uniforms.front();E;E=E->next()) {
+ for (Map<StringName, ShaderLanguage::ShaderNode::Uniform>::Element *E = shader->uniforms.front(); E; E = E->next()) {
-
- order[E->get().order]=E->key();
+ order[E->get().order] = E->key();
}
-
- for(Map<int,StringName>::Element *E=order.front();E;E=E->next()) {
+ for (Map<int, StringName>::Element *E = order.front(); E; E = E->next()) {
PropertyInfo pi;
- ShaderLanguage::ShaderNode::Uniform &u=shader->uniforms[E->get()];
- pi.name=E->get();
- switch(u.type) {
- case ShaderLanguage::TYPE_VOID: pi.type=Variant::NIL; break;
- case ShaderLanguage::TYPE_BOOL: pi.type=Variant::BOOL; break;
- case ShaderLanguage::TYPE_BVEC2: pi.type=Variant::INT; pi.hint=PROPERTY_HINT_FLAGS; pi.hint_string="x,y"; break;
- case ShaderLanguage::TYPE_BVEC3: pi.type=Variant::INT; pi.hint=PROPERTY_HINT_FLAGS; pi.hint_string="x,y,z"; break;
- case ShaderLanguage::TYPE_BVEC4: pi.type=Variant::INT; pi.hint=PROPERTY_HINT_FLAGS; pi.hint_string="x,y,z,w"; break;
+ ShaderLanguage::ShaderNode::Uniform &u = shader->uniforms[E->get()];
+ pi.name = E->get();
+ switch (u.type) {
+ case ShaderLanguage::TYPE_VOID: pi.type = Variant::NIL; break;
+ case ShaderLanguage::TYPE_BOOL: pi.type = Variant::BOOL; break;
+ case ShaderLanguage::TYPE_BVEC2:
+ pi.type = Variant::INT;
+ pi.hint = PROPERTY_HINT_FLAGS;
+ pi.hint_string = "x,y";
+ break;
+ case ShaderLanguage::TYPE_BVEC3:
+ pi.type = Variant::INT;
+ pi.hint = PROPERTY_HINT_FLAGS;
+ pi.hint_string = "x,y,z";
+ break;
+ case ShaderLanguage::TYPE_BVEC4:
+ pi.type = Variant::INT;
+ pi.hint = PROPERTY_HINT_FLAGS;
+ pi.hint_string = "x,y,z,w";
+ break;
case ShaderLanguage::TYPE_UINT:
case ShaderLanguage::TYPE_INT: {
- pi.type=Variant::INT;
- if (u.hint==ShaderLanguage::ShaderNode::Uniform::HINT_RANGE) {
- pi.hint=PROPERTY_HINT_RANGE;
- pi.hint_string=rtos(u.hint_range[0])+","+rtos(u.hint_range[1]);
+ pi.type = Variant::INT;
+ if (u.hint == ShaderLanguage::ShaderNode::Uniform::HINT_RANGE) {
+ pi.hint = PROPERTY_HINT_RANGE;
+ pi.hint_string = rtos(u.hint_range[0]) + "," + rtos(u.hint_range[1]);
}
} break;
@@ -1671,77 +1572,75 @@ void RasterizerStorageGLES3::shader_get_param_list(RID p_shader, List<PropertyIn
case ShaderLanguage::TYPE_UVEC3:
case ShaderLanguage::TYPE_UVEC4: {
- pi.type=Variant::POOL_INT_ARRAY;
+ pi.type = Variant::POOL_INT_ARRAY;
} break;
case ShaderLanguage::TYPE_FLOAT: {
- pi.type=Variant::REAL;
- if (u.hint==ShaderLanguage::ShaderNode::Uniform::HINT_RANGE) {
- pi.hint=PROPERTY_HINT_RANGE;
- pi.hint_string=rtos(u.hint_range[0])+","+rtos(u.hint_range[1])+","+rtos(u.hint_range[2]);
+ pi.type = Variant::REAL;
+ if (u.hint == ShaderLanguage::ShaderNode::Uniform::HINT_RANGE) {
+ pi.hint = PROPERTY_HINT_RANGE;
+ pi.hint_string = rtos(u.hint_range[0]) + "," + rtos(u.hint_range[1]) + "," + rtos(u.hint_range[2]);
}
} break;
- case ShaderLanguage::TYPE_VEC2: pi.type=Variant::VECTOR2; break;
- case ShaderLanguage::TYPE_VEC3: pi.type=Variant::VECTOR3; break;
+ case ShaderLanguage::TYPE_VEC2: pi.type = Variant::VECTOR2; break;
+ case ShaderLanguage::TYPE_VEC3: pi.type = Variant::VECTOR3; break;
case ShaderLanguage::TYPE_VEC4: {
- if (u.hint==ShaderLanguage::ShaderNode::Uniform::HINT_COLOR) {
- pi.type=Variant::COLOR;
+ if (u.hint == ShaderLanguage::ShaderNode::Uniform::HINT_COLOR) {
+ pi.type = Variant::COLOR;
} else {
- pi.type=Variant::PLANE;
+ pi.type = Variant::PLANE;
}
} break;
- case ShaderLanguage::TYPE_MAT2: pi.type=Variant::TRANSFORM2D; break;
- case ShaderLanguage::TYPE_MAT3: pi.type=Variant::BASIS; break;
- case ShaderLanguage::TYPE_MAT4: pi.type=Variant::TRANSFORM; break;
+ case ShaderLanguage::TYPE_MAT2: pi.type = Variant::TRANSFORM2D; break;
+ case ShaderLanguage::TYPE_MAT3: pi.type = Variant::BASIS; break;
+ case ShaderLanguage::TYPE_MAT4: pi.type = Variant::TRANSFORM; break;
case ShaderLanguage::TYPE_SAMPLER2D:
case ShaderLanguage::TYPE_ISAMPLER2D:
case ShaderLanguage::TYPE_USAMPLER2D: {
- pi.type=Variant::OBJECT;
- pi.hint=PROPERTY_HINT_RESOURCE_TYPE;
- pi.hint_string="Texture";
+ pi.type = Variant::OBJECT;
+ pi.hint = PROPERTY_HINT_RESOURCE_TYPE;
+ pi.hint_string = "Texture";
} break;
case ShaderLanguage::TYPE_SAMPLERCUBE: {
- pi.type=Variant::OBJECT;
- pi.hint=PROPERTY_HINT_RESOURCE_TYPE;
- pi.hint_string="CubeMap";
+ pi.type = Variant::OBJECT;
+ pi.hint = PROPERTY_HINT_RESOURCE_TYPE;
+ pi.hint_string = "CubeMap";
} break;
};
p_param_list->push_back(pi);
-
}
}
-void RasterizerStorageGLES3::shader_set_default_texture_param(RID p_shader, const StringName& p_name, RID p_texture){
+void RasterizerStorageGLES3::shader_set_default_texture_param(RID p_shader, const StringName &p_name, RID p_texture) {
- Shader *shader=shader_owner.get(p_shader);
+ Shader *shader = shader_owner.get(p_shader);
ERR_FAIL_COND(!shader);
ERR_FAIL_COND(p_texture.is_valid() && !texture_owner.owns(p_texture));
if (p_texture.is_valid())
- shader->default_textures[p_name]=p_texture;
+ shader->default_textures[p_name] = p_texture;
else
shader->default_textures.erase(p_name);
_shader_make_dirty(shader);
}
-RID RasterizerStorageGLES3::shader_get_default_texture_param(RID p_shader, const StringName& p_name) const{
+RID RasterizerStorageGLES3::shader_get_default_texture_param(RID p_shader, const StringName &p_name) const {
- const Shader *shader=shader_owner.get(p_shader);
- ERR_FAIL_COND_V(!shader,RID());
+ const Shader *shader = shader_owner.get(p_shader);
+ ERR_FAIL_COND_V(!shader, RID());
- const Map<StringName,RID>::Element *E=shader->default_textures.find(p_name);
+ const Map<StringName, RID>::Element *E = shader->default_textures.find(p_name);
if (!E)
return RID();
return E->get();
}
-
/* COMMON MATERIAL API */
-void RasterizerStorageGLES3::_material_make_dirty(Material* p_material) const {
+void RasterizerStorageGLES3::_material_make_dirty(Material *p_material) const {
if (p_material->dirty_list.in_list())
return;
@@ -1749,38 +1648,37 @@ void RasterizerStorageGLES3::_material_make_dirty(Material* p_material) const {
_material_dirty_list.add(&p_material->dirty_list);
}
-RID RasterizerStorageGLES3::material_create(){
+RID RasterizerStorageGLES3::material_create() {
- Material *material = memnew( Material );
+ Material *material = memnew(Material);
return material_owner.make_rid(material);
}
-void RasterizerStorageGLES3::material_set_shader(RID p_material, RID p_shader){
+void RasterizerStorageGLES3::material_set_shader(RID p_material, RID p_shader) {
- Material *material = material_owner.get( p_material );
+ Material *material = material_owner.get(p_material);
ERR_FAIL_COND(!material);
- Shader *shader=shader_owner.getornull(p_shader);
+ Shader *shader = shader_owner.getornull(p_shader);
if (material->shader) {
//if shader, remove from previous shader material list
- material->shader->materials.remove( &material->list );
+ material->shader->materials.remove(&material->list);
}
- material->shader=shader;
+ material->shader = shader;
if (shader) {
shader->materials.add(&material->list);
}
_material_make_dirty(material);
-
}
-RID RasterizerStorageGLES3::material_get_shader(RID p_material) const{
+RID RasterizerStorageGLES3::material_get_shader(RID p_material) const {
- const Material *material = material_owner.get( p_material );
- ERR_FAIL_COND_V(!material,RID());
+ const Material *material = material_owner.get(p_material);
+ ERR_FAIL_COND_V(!material, RID());
if (material->shader)
return material->shader->self;
@@ -1788,23 +1686,22 @@ RID RasterizerStorageGLES3::material_get_shader(RID p_material) const{
return RID();
}
-void RasterizerStorageGLES3::material_set_param(RID p_material, const StringName& p_param, const Variant& p_value){
+void RasterizerStorageGLES3::material_set_param(RID p_material, const StringName &p_param, const Variant &p_value) {
- Material *material = material_owner.get( p_material );
+ Material *material = material_owner.get(p_material);
ERR_FAIL_COND(!material);
- if (p_value.get_type()==Variant::NIL)
+ if (p_value.get_type() == Variant::NIL)
material->params.erase(p_param);
else
- material->params[p_param]=p_value;
+ material->params[p_param] = p_value;
_material_make_dirty(material);
-
}
-Variant RasterizerStorageGLES3::material_get_param(RID p_material, const StringName& p_param) const{
+Variant RasterizerStorageGLES3::material_get_param(RID p_material, const StringName &p_param) const {
- const Material *material = material_owner.get( p_material );
- ERR_FAIL_COND_V(!material,RID());
+ const Material *material = material_owner.get(p_material);
+ ERR_FAIL_COND_V(!material, RID());
if (material->params.has(p_param))
return material->params[p_param];
@@ -1814,29 +1711,26 @@ Variant RasterizerStorageGLES3::material_get_param(RID p_material, const StringN
void RasterizerStorageGLES3::material_set_line_width(RID p_material, float p_width) {
- Material *material = material_owner.get( p_material );
+ Material *material = material_owner.get(p_material);
ERR_FAIL_COND(!material);
- material->line_width=p_width;
-
-
+ material->line_width = p_width;
}
-bool RasterizerStorageGLES3::material_is_animated(RID p_material) {
+bool RasterizerStorageGLES3::material_is_animated(RID p_material) {
- Material *material = material_owner.get( p_material );
- ERR_FAIL_COND_V(!material,false);
+ Material *material = material_owner.get(p_material);
+ ERR_FAIL_COND_V(!material, false);
if (material->dirty_list.in_list()) {
_update_material(material);
}
return material->is_animated_cache;
-
}
-bool RasterizerStorageGLES3::material_casts_shadows(RID p_material) {
+bool RasterizerStorageGLES3::material_casts_shadows(RID p_material) {
- Material *material = material_owner.get( p_material );
- ERR_FAIL_COND_V(!material,false);
+ Material *material = material_owner.get(p_material);
+ ERR_FAIL_COND_V(!material, false);
if (material->dirty_list.in_list()) {
_update_material(material);
}
@@ -1846,90 +1740,87 @@ bool RasterizerStorageGLES3::material_casts_shadows(RID p_material) {
void RasterizerStorageGLES3::material_add_instance_owner(RID p_material, RasterizerScene::InstanceBase *p_instance) {
- Material *material = material_owner.get( p_material );
+ Material *material = material_owner.get(p_material);
ERR_FAIL_COND(!material);
- Map<RasterizerScene::InstanceBase*,int>::Element *E=material->instance_owners.find(p_instance);
+ Map<RasterizerScene::InstanceBase *, int>::Element *E = material->instance_owners.find(p_instance);
if (E) {
E->get()++;
} else {
- material->instance_owners[p_instance]=1;
+ material->instance_owners[p_instance] = 1;
}
}
void RasterizerStorageGLES3::material_remove_instance_owner(RID p_material, RasterizerScene::InstanceBase *p_instance) {
- Material *material = material_owner.get( p_material );
+ Material *material = material_owner.get(p_material);
ERR_FAIL_COND(!material);
- Map<RasterizerScene::InstanceBase*,int>::Element *E=material->instance_owners.find(p_instance);
+ Map<RasterizerScene::InstanceBase *, int>::Element *E = material->instance_owners.find(p_instance);
ERR_FAIL_COND(!E);
E->get()--;
- if (E->get()==0) {
+ if (E->get() == 0) {
material->instance_owners.erase(E);
}
}
-
-
-_FORCE_INLINE_ static void _fill_std140_variant_ubo_value(ShaderLanguage::DataType type, const Variant& value, uint8_t *data,bool p_linear_color) {
- switch(type) {
+_FORCE_INLINE_ static void _fill_std140_variant_ubo_value(ShaderLanguage::DataType type, const Variant &value, uint8_t *data, bool p_linear_color) {
+ switch (type) {
case ShaderLanguage::TYPE_BOOL: {
bool v = value;
- GLuint *gui = (GLuint*)data;
+ GLuint *gui = (GLuint *)data;
*gui = v ? GL_TRUE : GL_FALSE;
} break;
case ShaderLanguage::TYPE_BVEC2: {
int v = value;
- GLuint *gui = (GLuint*)data;
- gui[0]=v&1 ? GL_TRUE : GL_FALSE;
- gui[1]=v&2 ? GL_TRUE : GL_FALSE;
+ GLuint *gui = (GLuint *)data;
+ gui[0] = v & 1 ? GL_TRUE : GL_FALSE;
+ gui[1] = v & 2 ? GL_TRUE : GL_FALSE;
} break;
case ShaderLanguage::TYPE_BVEC3: {
int v = value;
- GLuint *gui = (GLuint*)data;
- gui[0]=v&1 ? GL_TRUE : GL_FALSE;
- gui[1]=v&2 ? GL_TRUE : GL_FALSE;
- gui[2]=v&4 ? GL_TRUE : GL_FALSE;
+ GLuint *gui = (GLuint *)data;
+ gui[0] = v & 1 ? GL_TRUE : GL_FALSE;
+ gui[1] = v & 2 ? GL_TRUE : GL_FALSE;
+ gui[2] = v & 4 ? GL_TRUE : GL_FALSE;
} break;
case ShaderLanguage::TYPE_BVEC4: {
int v = value;
- GLuint *gui = (GLuint*)data;
- gui[0]=v&1 ? GL_TRUE : GL_FALSE;
- gui[1]=v&2 ? GL_TRUE : GL_FALSE;
- gui[2]=v&4 ? GL_TRUE : GL_FALSE;
- gui[3]=v&8 ? GL_TRUE : GL_FALSE;
+ GLuint *gui = (GLuint *)data;
+ gui[0] = v & 1 ? GL_TRUE : GL_FALSE;
+ gui[1] = v & 2 ? GL_TRUE : GL_FALSE;
+ gui[2] = v & 4 ? GL_TRUE : GL_FALSE;
+ gui[3] = v & 8 ? GL_TRUE : GL_FALSE;
} break;
case ShaderLanguage::TYPE_INT: {
int v = value;
- GLint *gui = (GLint*)data;
- gui[0]=v;
+ GLint *gui = (GLint *)data;
+ gui[0] = v;
} break;
case ShaderLanguage::TYPE_IVEC2: {
PoolVector<int> iv = value;
int s = iv.size();
- GLint *gui = (GLint*)data;
+ GLint *gui = (GLint *)data;
PoolVector<int>::Read r = iv.read();
- for(int i=0;i<2;i++) {
- if (i<s)
- gui[i]=r[i];
+ for (int i = 0; i < 2; i++) {
+ if (i < s)
+ gui[i] = r[i];
else
- gui[i]=0;
-
+ gui[i] = 0;
}
} break;
@@ -1937,387 +1828,372 @@ _FORCE_INLINE_ static void _fill_std140_variant_ubo_value(ShaderLanguage::DataTy
PoolVector<int> iv = value;
int s = iv.size();
- GLint *gui = (GLint*)data;
+ GLint *gui = (GLint *)data;
PoolVector<int>::Read r = iv.read();
- for(int i=0;i<3;i++) {
- if (i<s)
- gui[i]=r[i];
+ for (int i = 0; i < 3; i++) {
+ if (i < s)
+ gui[i] = r[i];
else
- gui[i]=0;
-
+ gui[i] = 0;
}
} break;
case ShaderLanguage::TYPE_IVEC4: {
-
PoolVector<int> iv = value;
int s = iv.size();
- GLint *gui = (GLint*)data;
+ GLint *gui = (GLint *)data;
PoolVector<int>::Read r = iv.read();
- for(int i=0;i<4;i++) {
- if (i<s)
- gui[i]=r[i];
+ for (int i = 0; i < 4; i++) {
+ if (i < s)
+ gui[i] = r[i];
else
- gui[i]=0;
-
+ gui[i] = 0;
}
} break;
case ShaderLanguage::TYPE_UINT: {
int v = value;
- GLuint *gui = (GLuint*)data;
- gui[0]=v;
+ GLuint *gui = (GLuint *)data;
+ gui[0] = v;
} break;
case ShaderLanguage::TYPE_UVEC2: {
PoolVector<int> iv = value;
int s = iv.size();
- GLuint *gui = (GLuint*)data;
+ GLuint *gui = (GLuint *)data;
PoolVector<int>::Read r = iv.read();
- for(int i=0;i<2;i++) {
- if (i<s)
- gui[i]=r[i];
+ for (int i = 0; i < 2; i++) {
+ if (i < s)
+ gui[i] = r[i];
else
- gui[i]=0;
-
+ gui[i] = 0;
}
} break;
case ShaderLanguage::TYPE_UVEC3: {
PoolVector<int> iv = value;
int s = iv.size();
- GLuint *gui = (GLuint*)data;
+ GLuint *gui = (GLuint *)data;
PoolVector<int>::Read r = iv.read();
- for(int i=0;i<3;i++) {
- if (i<s)
- gui[i]=r[i];
+ for (int i = 0; i < 3; i++) {
+ if (i < s)
+ gui[i] = r[i];
else
- gui[i]=0;
+ gui[i] = 0;
}
} break;
case ShaderLanguage::TYPE_UVEC4: {
PoolVector<int> iv = value;
int s = iv.size();
- GLuint *gui = (GLuint*)data;
+ GLuint *gui = (GLuint *)data;
PoolVector<int>::Read r = iv.read();
- for(int i=0;i<4;i++) {
- if (i<s)
- gui[i]=r[i];
+ for (int i = 0; i < 4; i++) {
+ if (i < s)
+ gui[i] = r[i];
else
- gui[i]=0;
+ gui[i] = 0;
}
} break;
case ShaderLanguage::TYPE_FLOAT: {
float v = value;
- GLfloat *gui = (GLfloat*)data;
- gui[0]=v;
+ GLfloat *gui = (GLfloat *)data;
+ gui[0] = v;
} break;
case ShaderLanguage::TYPE_VEC2: {
Vector2 v = value;
- GLfloat *gui = (GLfloat*)data;
- gui[0]=v.x;
- gui[1]=v.y;
+ GLfloat *gui = (GLfloat *)data;
+ gui[0] = v.x;
+ gui[1] = v.y;
} break;
case ShaderLanguage::TYPE_VEC3: {
Vector3 v = value;
- GLfloat *gui = (GLfloat*)data;
- gui[0]=v.x;
- gui[1]=v.y;
- gui[2]=v.z;
+ GLfloat *gui = (GLfloat *)data;
+ gui[0] = v.x;
+ gui[1] = v.y;
+ gui[2] = v.z;
} break;
case ShaderLanguage::TYPE_VEC4: {
- GLfloat *gui = (GLfloat*)data;
+ GLfloat *gui = (GLfloat *)data;
- if (value.get_type()==Variant::COLOR) {
- Color v=value;
+ if (value.get_type() == Variant::COLOR) {
+ Color v = value;
if (p_linear_color) {
- v=v.to_linear();
+ v = v.to_linear();
}
- gui[0]=v.r;
- gui[1]=v.g;
- gui[2]=v.b;
- gui[3]=v.a;
- } else if (value.get_type()==Variant::RECT2) {
- Rect2 v=value;
-
- gui[0]=v.pos.x;
- gui[1]=v.pos.y;
- gui[2]=v.size.x;
- gui[3]=v.size.y;
- } else if (value.get_type()==Variant::QUAT) {
- Quat v=value;
-
- gui[0]=v.x;
- gui[1]=v.y;
- gui[2]=v.z;
- gui[3]=v.w;
+ gui[0] = v.r;
+ gui[1] = v.g;
+ gui[2] = v.b;
+ gui[3] = v.a;
+ } else if (value.get_type() == Variant::RECT2) {
+ Rect2 v = value;
+
+ gui[0] = v.pos.x;
+ gui[1] = v.pos.y;
+ gui[2] = v.size.x;
+ gui[3] = v.size.y;
+ } else if (value.get_type() == Variant::QUAT) {
+ Quat v = value;
+
+ gui[0] = v.x;
+ gui[1] = v.y;
+ gui[2] = v.z;
+ gui[3] = v.w;
} else {
- Plane v=value;
-
- gui[0]=v.normal.x;
- gui[1]=v.normal.y;
- gui[2]=v.normal.x;
- gui[3]=v.d;
+ Plane v = value;
+ gui[0] = v.normal.x;
+ gui[1] = v.normal.y;
+ gui[2] = v.normal.x;
+ gui[3] = v.d;
}
} break;
case ShaderLanguage::TYPE_MAT2: {
Transform2D v = value;
- GLfloat *gui = (GLfloat*)data;
+ GLfloat *gui = (GLfloat *)data;
- gui[ 0]=v.elements[0][0];
- gui[ 1]=v.elements[0][1];
- gui[ 2]=v.elements[1][0];
- gui[ 3]=v.elements[1][1];
+ gui[0] = v.elements[0][0];
+ gui[1] = v.elements[0][1];
+ gui[2] = v.elements[1][0];
+ gui[3] = v.elements[1][1];
} break;
case ShaderLanguage::TYPE_MAT3: {
-
Basis v = value;
- GLfloat *gui = (GLfloat*)data;
-
- gui[ 0]=v.elements[0][0];
- gui[ 1]=v.elements[1][0];
- gui[ 2]=v.elements[2][0];
- gui[ 3]=0;
- gui[ 4]=v.elements[0][1];
- gui[ 5]=v.elements[1][1];
- gui[ 6]=v.elements[2][1];
- gui[ 7]=0;
- gui[ 8]=v.elements[0][2];
- gui[ 9]=v.elements[1][2];
- gui[10]=v.elements[2][2];
- gui[11]=0;
+ GLfloat *gui = (GLfloat *)data;
+
+ gui[0] = v.elements[0][0];
+ gui[1] = v.elements[1][0];
+ gui[2] = v.elements[2][0];
+ gui[3] = 0;
+ gui[4] = v.elements[0][1];
+ gui[5] = v.elements[1][1];
+ gui[6] = v.elements[2][1];
+ gui[7] = 0;
+ gui[8] = v.elements[0][2];
+ gui[9] = v.elements[1][2];
+ gui[10] = v.elements[2][2];
+ gui[11] = 0;
} break;
case ShaderLanguage::TYPE_MAT4: {
Transform v = value;
- GLfloat *gui = (GLfloat*)data;
-
- gui[ 0]=v.basis.elements[0][0];
- gui[ 1]=v.basis.elements[1][0];
- gui[ 2]=v.basis.elements[2][0];
- gui[ 3]=0;
- gui[ 4]=v.basis.elements[0][1];
- gui[ 5]=v.basis.elements[1][1];
- gui[ 6]=v.basis.elements[2][1];
- gui[ 7]=0;
- gui[ 8]=v.basis.elements[0][2];
- gui[ 9]=v.basis.elements[1][2];
- gui[10]=v.basis.elements[2][2];
- gui[11]=0;
- gui[12]=v.origin.x;
- gui[13]=v.origin.y;
- gui[14]=v.origin.z;
- gui[15]=1;
+ GLfloat *gui = (GLfloat *)data;
+
+ gui[0] = v.basis.elements[0][0];
+ gui[1] = v.basis.elements[1][0];
+ gui[2] = v.basis.elements[2][0];
+ gui[3] = 0;
+ gui[4] = v.basis.elements[0][1];
+ gui[5] = v.basis.elements[1][1];
+ gui[6] = v.basis.elements[2][1];
+ gui[7] = 0;
+ gui[8] = v.basis.elements[0][2];
+ gui[9] = v.basis.elements[1][2];
+ gui[10] = v.basis.elements[2][2];
+ gui[11] = 0;
+ gui[12] = v.origin.x;
+ gui[13] = v.origin.y;
+ gui[14] = v.origin.z;
+ gui[15] = 1;
} break;
default: {}
}
-
}
-_FORCE_INLINE_ static void _fill_std140_ubo_value(ShaderLanguage::DataType type, const Vector<ShaderLanguage::ConstantNode::Value>& value, uint8_t *data) {
+_FORCE_INLINE_ static void _fill_std140_ubo_value(ShaderLanguage::DataType type, const Vector<ShaderLanguage::ConstantNode::Value> &value, uint8_t *data) {
- switch(type) {
+ switch (type) {
case ShaderLanguage::TYPE_BOOL: {
- GLuint *gui = (GLuint*)data;
+ GLuint *gui = (GLuint *)data;
*gui = value[0].boolean ? GL_TRUE : GL_FALSE;
} break;
case ShaderLanguage::TYPE_BVEC2: {
- GLuint *gui = (GLuint*)data;
- gui[0]=value[0].boolean ? GL_TRUE : GL_FALSE;
- gui[1]=value[1].boolean ? GL_TRUE : GL_FALSE;
+ GLuint *gui = (GLuint *)data;
+ gui[0] = value[0].boolean ? GL_TRUE : GL_FALSE;
+ gui[1] = value[1].boolean ? GL_TRUE : GL_FALSE;
} break;
case ShaderLanguage::TYPE_BVEC3: {
- GLuint *gui = (GLuint*)data;
- gui[0]=value[0].boolean ? GL_TRUE : GL_FALSE;
- gui[1]=value[1].boolean ? GL_TRUE : GL_FALSE;
- gui[2]=value[2].boolean ? GL_TRUE : GL_FALSE;
+ GLuint *gui = (GLuint *)data;
+ gui[0] = value[0].boolean ? GL_TRUE : GL_FALSE;
+ gui[1] = value[1].boolean ? GL_TRUE : GL_FALSE;
+ gui[2] = value[2].boolean ? GL_TRUE : GL_FALSE;
} break;
case ShaderLanguage::TYPE_BVEC4: {
- GLuint *gui = (GLuint*)data;
- gui[0]=value[0].boolean ? GL_TRUE : GL_FALSE;
- gui[1]=value[1].boolean ? GL_TRUE : GL_FALSE;
- gui[2]=value[2].boolean ? GL_TRUE : GL_FALSE;
- gui[3]=value[3].boolean ? GL_TRUE : GL_FALSE;
+ GLuint *gui = (GLuint *)data;
+ gui[0] = value[0].boolean ? GL_TRUE : GL_FALSE;
+ gui[1] = value[1].boolean ? GL_TRUE : GL_FALSE;
+ gui[2] = value[2].boolean ? GL_TRUE : GL_FALSE;
+ gui[3] = value[3].boolean ? GL_TRUE : GL_FALSE;
} break;
case ShaderLanguage::TYPE_INT: {
- GLint *gui = (GLint*)data;
- gui[0]=value[0].sint;
+ GLint *gui = (GLint *)data;
+ gui[0] = value[0].sint;
} break;
case ShaderLanguage::TYPE_IVEC2: {
- GLint *gui = (GLint*)data;
-
- for(int i=0;i<2;i++) {
- gui[i]=value[i].sint;
+ GLint *gui = (GLint *)data;
+ for (int i = 0; i < 2; i++) {
+ gui[i] = value[i].sint;
}
} break;
case ShaderLanguage::TYPE_IVEC3: {
- GLint *gui = (GLint*)data;
-
- for(int i=0;i<3;i++) {
- gui[i]=value[i].sint;
+ GLint *gui = (GLint *)data;
+ for (int i = 0; i < 3; i++) {
+ gui[i] = value[i].sint;
}
} break;
case ShaderLanguage::TYPE_IVEC4: {
- GLint *gui = (GLint*)data;
-
- for(int i=0;i<4;i++) {
- gui[i]=value[i].sint;
+ GLint *gui = (GLint *)data;
+ for (int i = 0; i < 4; i++) {
+ gui[i] = value[i].sint;
}
} break;
case ShaderLanguage::TYPE_UINT: {
-
- GLuint *gui = (GLuint*)data;
- gui[0]=value[0].uint;
+ GLuint *gui = (GLuint *)data;
+ gui[0] = value[0].uint;
} break;
case ShaderLanguage::TYPE_UVEC2: {
- GLint *gui = (GLint*)data;
+ GLint *gui = (GLint *)data;
- for(int i=0;i<2;i++) {
- gui[i]=value[i].uint;
+ for (int i = 0; i < 2; i++) {
+ gui[i] = value[i].uint;
}
} break;
case ShaderLanguage::TYPE_UVEC3: {
- GLint *gui = (GLint*)data;
+ GLint *gui = (GLint *)data;
- for(int i=0;i<3;i++) {
- gui[i]=value[i].uint;
+ for (int i = 0; i < 3; i++) {
+ gui[i] = value[i].uint;
}
} break;
case ShaderLanguage::TYPE_UVEC4: {
- GLint *gui = (GLint*)data;
+ GLint *gui = (GLint *)data;
- for(int i=0;i<4;i++) {
- gui[i]=value[i].uint;
+ for (int i = 0; i < 4; i++) {
+ gui[i] = value[i].uint;
}
} break;
case ShaderLanguage::TYPE_FLOAT: {
- GLfloat *gui = (GLfloat*)data;
- gui[0]=value[0].real;
+ GLfloat *gui = (GLfloat *)data;
+ gui[0] = value[0].real;
} break;
case ShaderLanguage::TYPE_VEC2: {
- GLfloat *gui = (GLfloat*)data;
+ GLfloat *gui = (GLfloat *)data;
- for(int i=0;i<2;i++) {
- gui[i]=value[i].real;
+ for (int i = 0; i < 2; i++) {
+ gui[i] = value[i].real;
}
} break;
case ShaderLanguage::TYPE_VEC3: {
- GLfloat *gui = (GLfloat*)data;
+ GLfloat *gui = (GLfloat *)data;
- for(int i=0;i<3;i++) {
- gui[i]=value[i].real;
+ for (int i = 0; i < 3; i++) {
+ gui[i] = value[i].real;
}
} break;
case ShaderLanguage::TYPE_VEC4: {
- GLfloat *gui = (GLfloat*)data;
+ GLfloat *gui = (GLfloat *)data;
- for(int i=0;i<4;i++) {
- gui[i]=value[i].real;
+ for (int i = 0; i < 4; i++) {
+ gui[i] = value[i].real;
}
} break;
case ShaderLanguage::TYPE_MAT2: {
- GLfloat *gui = (GLfloat*)data;
+ GLfloat *gui = (GLfloat *)data;
- for(int i=0;i<2;i++) {
- gui[i]=value[i].real;
+ for (int i = 0; i < 2; i++) {
+ gui[i] = value[i].real;
}
} break;
case ShaderLanguage::TYPE_MAT3: {
-
-
- GLfloat *gui = (GLfloat*)data;
-
- gui[ 0]=value[0].real;
- gui[ 1]=value[1].real;
- gui[ 2]=value[2].real;
- gui[ 3]=0;
- gui[ 4]=value[3].real;
- gui[ 5]=value[4].real;
- gui[ 6]=value[5].real;
- gui[ 7]=0;
- gui[ 8]=value[6].real;
- gui[ 9]=value[7].real;
- gui[10]=value[8].real;
- gui[11]=0;
+ GLfloat *gui = (GLfloat *)data;
+
+ gui[0] = value[0].real;
+ gui[1] = value[1].real;
+ gui[2] = value[2].real;
+ gui[3] = 0;
+ gui[4] = value[3].real;
+ gui[5] = value[4].real;
+ gui[6] = value[5].real;
+ gui[7] = 0;
+ gui[8] = value[6].real;
+ gui[9] = value[7].real;
+ gui[10] = value[8].real;
+ gui[11] = 0;
} break;
case ShaderLanguage::TYPE_MAT4: {
- GLfloat *gui = (GLfloat*)data;
+ GLfloat *gui = (GLfloat *)data;
- for(int i=0;i<16;i++) {
- gui[i]=value[i].real;
+ for (int i = 0; i < 16; i++) {
+ gui[i] = value[i].real;
}
} break;
default: {}
}
-
}
-
_FORCE_INLINE_ static void _fill_std140_ubo_empty(ShaderLanguage::DataType type, uint8_t *data) {
- switch(type) {
+ switch (type) {
case ShaderLanguage::TYPE_BOOL:
case ShaderLanguage::TYPE_INT:
case ShaderLanguage::TYPE_UINT:
case ShaderLanguage::TYPE_FLOAT: {
- zeromem(data,4);
+ zeromem(data, 4);
} break;
case ShaderLanguage::TYPE_BVEC2:
case ShaderLanguage::TYPE_IVEC2:
case ShaderLanguage::TYPE_UVEC2:
case ShaderLanguage::TYPE_VEC2: {
- zeromem(data,8);
+ zeromem(data, 8);
} break;
case ShaderLanguage::TYPE_BVEC3:
case ShaderLanguage::TYPE_IVEC3:
@@ -2327,28 +2203,26 @@ _FORCE_INLINE_ static void _fill_std140_ubo_empty(ShaderLanguage::DataType type,
case ShaderLanguage::TYPE_IVEC4:
case ShaderLanguage::TYPE_UVEC4:
case ShaderLanguage::TYPE_VEC4:
- case ShaderLanguage::TYPE_MAT2:{
+ case ShaderLanguage::TYPE_MAT2: {
- zeromem(data,16);
+ zeromem(data, 16);
} break;
- case ShaderLanguage::TYPE_MAT3:{
+ case ShaderLanguage::TYPE_MAT3: {
- zeromem(data,48);
+ zeromem(data, 48);
} break;
- case ShaderLanguage::TYPE_MAT4:{
- zeromem(data,64);
+ case ShaderLanguage::TYPE_MAT4: {
+ zeromem(data, 64);
} break;
default: {}
}
-
}
-void RasterizerStorageGLES3::_update_material(Material* material) {
+void RasterizerStorageGLES3::_update_material(Material *material) {
if (material->dirty_list.in_list())
- _material_dirty_list.remove( &material->dirty_list );
-
+ _material_dirty_list.remove(&material->dirty_list);
if (material->shader && material->shader->dirty_list.in_list()) {
_update_shader(material->shader);
@@ -2359,90 +2233,85 @@ void RasterizerStorageGLES3::_update_material(Material* material) {
bool can_cast_shadow = false;
bool is_animated = false;
- if (material->shader && material->shader->mode==VS::SHADER_SPATIAL) {
+ if (material->shader && material->shader->mode == VS::SHADER_SPATIAL) {
- if (!material->shader->spatial.uses_alpha && material->shader->spatial.blend_mode==Shader::Spatial::BLEND_MODE_MIX) {
- can_cast_shadow=true;
+ if (!material->shader->spatial.uses_alpha && material->shader->spatial.blend_mode == Shader::Spatial::BLEND_MODE_MIX) {
+ can_cast_shadow = true;
}
if (material->shader->spatial.uses_discard && material->shader->uses_fragment_time) {
- is_animated=true;
+ is_animated = true;
}
if (material->shader->spatial.uses_vertex && material->shader->uses_vertex_time) {
- is_animated=true;
+ is_animated = true;
}
- if (can_cast_shadow!=material->can_cast_shadow_cache || is_animated!=material->is_animated_cache) {
- material->can_cast_shadow_cache=can_cast_shadow;
- material->is_animated_cache=is_animated;
+ if (can_cast_shadow != material->can_cast_shadow_cache || is_animated != material->is_animated_cache) {
+ material->can_cast_shadow_cache = can_cast_shadow;
+ material->is_animated_cache = is_animated;
- for(Map<Geometry*,int>::Element *E=material->geometry_owners.front();E;E=E->next()) {
+ for (Map<Geometry *, int>::Element *E = material->geometry_owners.front(); E; E = E->next()) {
E->key()->material_changed_notify();
}
- for(Map<RasterizerScene::InstanceBase*,int>::Element *E=material->instance_owners.front();E;E=E->next()) {
+ for (Map<RasterizerScene::InstanceBase *, int>::Element *E = material->instance_owners.front(); E; E = E->next()) {
E->key()->base_material_changed();
}
-
}
}
-
}
-
//clear ubo if it needs to be cleared
if (material->ubo_size) {
- if (!material->shader || material->shader->ubo_size!=material->ubo_size) {
+ if (!material->shader || material->shader->ubo_size != material->ubo_size) {
//by by ubo
- glDeleteBuffers(1,&material->ubo_id);
- material->ubo_id=0;
- material->ubo_size=0;
+ glDeleteBuffers(1, &material->ubo_id);
+ material->ubo_id = 0;
+ material->ubo_size = 0;
}
}
//create ubo if it needs to be created
- if (material->ubo_size==0 && material->shader && material->shader->ubo_size) {
+ if (material->ubo_size == 0 && material->shader && material->shader->ubo_size) {
glGenBuffers(1, &material->ubo_id);
glBindBuffer(GL_UNIFORM_BUFFER, material->ubo_id);
glBufferData(GL_UNIFORM_BUFFER, material->shader->ubo_size, NULL, GL_DYNAMIC_DRAW);
glBindBuffer(GL_UNIFORM_BUFFER, 0);
- material->ubo_size=material->shader->ubo_size;
+ material->ubo_size = material->shader->ubo_size;
}
//fill up the UBO if it needs to be filled
if (material->shader && material->ubo_size) {
- uint8_t* local_ubo = (uint8_t*)alloca(material->ubo_size);
+ uint8_t *local_ubo = (uint8_t *)alloca(material->ubo_size);
- for(Map<StringName,ShaderLanguage::ShaderNode::Uniform>::Element *E=material->shader->uniforms.front();E;E=E->next()) {
+ for (Map<StringName, ShaderLanguage::ShaderNode::Uniform>::Element *E = material->shader->uniforms.front(); E; E = E->next()) {
- if (E->get().order<0)
+ if (E->get().order < 0)
continue; // texture, does not go here
//regular uniform
- uint8_t *data = &local_ubo[ material->shader->ubo_offsets[E->get().order] ];
+ uint8_t *data = &local_ubo[material->shader->ubo_offsets[E->get().order]];
- Map<StringName,Variant>::Element *V = material->params.find(E->key());
+ Map<StringName, Variant>::Element *V = material->params.find(E->key());
if (V) {
- //user provided
- _fill_std140_variant_ubo_value(E->get().type,V->get(),data,material->shader->mode==VS::SHADER_SPATIAL);
+ //user provided
+ _fill_std140_variant_ubo_value(E->get().type, V->get(), data, material->shader->mode == VS::SHADER_SPATIAL);
- } else if (E->get().default_value.size()){
+ } else if (E->get().default_value.size()) {
//default value
- _fill_std140_ubo_value(E->get().type,E->get().default_value,data);
+ _fill_std140_ubo_value(E->get().type, E->get().default_value, data);
//value=E->get().default_value;
} else {
//zero because it was not provided
- _fill_std140_ubo_empty(E->get().type,data);
+ _fill_std140_ubo_empty(E->get().type, data);
}
-
-
}
- glBindBuffer(GL_UNIFORM_BUFFER,material->ubo_id);
+ glBindBuffer(GL_UNIFORM_BUFFER, material->ubo_id);
glBufferSubData(GL_UNIFORM_BUFFER, 0, material->ubo_size, local_ubo);
glBindBuffer(GL_UNIFORM_BUFFER, 0);
}
@@ -2452,70 +2321,64 @@ void RasterizerStorageGLES3::_update_material(Material* material) {
material->textures.resize(material->shader->texture_count);
- for(Map<StringName,ShaderLanguage::ShaderNode::Uniform>::Element *E=material->shader->uniforms.front();E;E=E->next()) {
+ for (Map<StringName, ShaderLanguage::ShaderNode::Uniform>::Element *E = material->shader->uniforms.front(); E; E = E->next()) {
- if (E->get().texture_order<0)
+ if (E->get().texture_order < 0)
continue; // not a texture, does not go here
RID texture;
- Map<StringName,Variant>::Element *V = material->params.find(E->key());
+ Map<StringName, Variant>::Element *V = material->params.find(E->key());
if (V) {
- texture=V->get();
+ texture = V->get();
}
if (!texture.is_valid()) {
- Map<StringName,RID>::Element *W = material->shader->default_textures.find(E->key());
+ Map<StringName, RID>::Element *W = material->shader->default_textures.find(E->key());
if (W) {
- texture=W->get();
+ texture = W->get();
}
}
- material->textures[ E->get().texture_order ]=texture;
-
-
+ material->textures[E->get().texture_order] = texture;
}
-
} else {
material->textures.clear();
}
-
}
-void RasterizerStorageGLES3::_material_add_geometry(RID p_material,Geometry *p_geometry) {
+void RasterizerStorageGLES3::_material_add_geometry(RID p_material, Geometry *p_geometry) {
- Material * material = material_owner.getornull(p_material);
+ Material *material = material_owner.getornull(p_material);
ERR_FAIL_COND(!material);
- Map<Geometry*,int>::Element *I = material->geometry_owners.find(p_geometry);
+ Map<Geometry *, int>::Element *I = material->geometry_owners.find(p_geometry);
if (I) {
I->get()++;
} else {
- material->geometry_owners[p_geometry]=1;
+ material->geometry_owners[p_geometry] = 1;
}
-
}
-void RasterizerStorageGLES3::_material_remove_geometry(RID p_material,Geometry *p_geometry) {
+void RasterizerStorageGLES3::_material_remove_geometry(RID p_material, Geometry *p_geometry) {
- Material * material = material_owner.getornull(p_material);
+ Material *material = material_owner.getornull(p_material);
ERR_FAIL_COND(!material);
- Map<Geometry*,int>::Element *I = material->geometry_owners.find(p_geometry);
+ Map<Geometry *, int>::Element *I = material->geometry_owners.find(p_geometry);
ERR_FAIL_COND(!I);
I->get()--;
- if (I->get()==0) {
+ if (I->get() == 0) {
material->geometry_owners.erase(I);
}
}
-
void RasterizerStorageGLES3::update_dirty_materials() {
- while( _material_dirty_list.first() ) {
+ while (_material_dirty_list.first()) {
Material *material = _material_dirty_list.first()->self();
@@ -2525,389 +2388,366 @@ void RasterizerStorageGLES3::update_dirty_materials() {
/* MESH API */
-RID RasterizerStorageGLES3::mesh_create(){
+RID RasterizerStorageGLES3::mesh_create() {
- Mesh * mesh = memnew( Mesh );
+ Mesh *mesh = memnew(Mesh);
return mesh_owner.make_rid(mesh);
}
-
-void RasterizerStorageGLES3::mesh_add_surface(RID p_mesh,uint32_t p_format,VS::PrimitiveType p_primitive,const PoolVector<uint8_t>& p_array,int p_vertex_count,const PoolVector<uint8_t>& p_index_array,int p_index_count,const Rect3& p_aabb,const Vector<PoolVector<uint8_t> >& p_blend_shapes,const Vector<Rect3>& p_bone_aabbs){
-
+void RasterizerStorageGLES3::mesh_add_surface(RID p_mesh, uint32_t p_format, VS::PrimitiveType p_primitive, const PoolVector<uint8_t> &p_array, int p_vertex_count, const PoolVector<uint8_t> &p_index_array, int p_index_count, const Rect3 &p_aabb, const Vector<PoolVector<uint8_t> > &p_blend_shapes, const Vector<Rect3> &p_bone_aabbs) {
PoolVector<uint8_t> array = p_array;
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 & VS::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 = VS::ARRAY_FORMAT_BONES | VS::ARRAY_FORMAT_WEIGHTS;
ERR_EXPLAIN("Array must have both bones and weights in format or none.");
- ERR_FAIL_COND( (p_format&bones_weight) && (p_format&bones_weight)!=bones_weight );
+ ERR_FAIL_COND((p_format & bones_weight) && (p_format & bones_weight) != bones_weight);
}
-
//bool has_morph = p_blend_shapes.size();
Surface::Attrib attribs[VS::ARRAY_MAX];
- int stride=0;
+ int stride = 0;
- for(int i=0;i<VS::ARRAY_MAX;i++) {
+ for (int i = 0; i < VS::ARRAY_MAX; i++) {
- attribs[i].index=i;
+ attribs[i].index = i;
- if (! (p_format&(1<<i) ) ) {
- attribs[i].enabled=false;
- attribs[i].integer=false;
+ if (!(p_format & (1 << i))) {
+ attribs[i].enabled = false;
+ attribs[i].integer = false;
continue;
}
- attribs[i].enabled=true;
- attribs[i].offset=stride;
- attribs[i].integer=false;
+ attribs[i].enabled = true;
+ attribs[i].offset = stride;
+ attribs[i].integer = false;
- switch(i) {
+ switch (i) {
case VS::ARRAY_VERTEX: {
- if (p_format&VS::ARRAY_FLAG_USE_2D_VERTICES) {
- attribs[i].size=2;
+ if (p_format & VS::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 & VS::ARRAY_COMPRESS_VERTEX) ? 4 : 3;
}
- if (p_format&VS::ARRAY_COMPRESS_VERTEX) {
- attribs[i].type=GL_HALF_FLOAT;
- stride+=attribs[i].size*2;
+ if (p_format & VS::ARRAY_COMPRESS_VERTEX) {
+ attribs[i].type = GL_HALF_FLOAT;
+ stride += attribs[i].size * 2;
} else {
- attribs[i].type=GL_FLOAT;
- stride+=attribs[i].size*4;
+ attribs[i].type = GL_FLOAT;
+ stride += attribs[i].size * 4;
}
- attribs[i].normalized=GL_FALSE;
+ attribs[i].normalized = GL_FALSE;
} break;
case VS::ARRAY_NORMAL: {
- attribs[i].size=3;
+ attribs[i].size = 3;
- if (p_format&VS::ARRAY_COMPRESS_NORMAL) {
- attribs[i].type=GL_BYTE;
- stride+=4; //pad extra byte
- attribs[i].normalized=GL_TRUE;
+ if (p_format & VS::ARRAY_COMPRESS_NORMAL) {
+ attribs[i].type = GL_BYTE;
+ stride += 4; //pad extra byte
+ attribs[i].normalized = GL_TRUE;
} else {
- attribs[i].type=GL_FLOAT;
- stride+=12;
- attribs[i].normalized=GL_FALSE;
+ attribs[i].type = GL_FLOAT;
+ stride += 12;
+ attribs[i].normalized = GL_FALSE;
}
-
-
} break;
case VS::ARRAY_TANGENT: {
- attribs[i].size=4;
+ attribs[i].size = 4;
- if (p_format&VS::ARRAY_COMPRESS_TANGENT) {
- attribs[i].type=GL_BYTE;
- stride+=4;
- attribs[i].normalized=GL_TRUE;
+ if (p_format & VS::ARRAY_COMPRESS_TANGENT) {
+ attribs[i].type = GL_BYTE;
+ stride += 4;
+ attribs[i].normalized = GL_TRUE;
} else {
- attribs[i].type=GL_FLOAT;
- stride+=16;
- attribs[i].normalized=GL_FALSE;
+ attribs[i].type = GL_FLOAT;
+ stride += 16;
+ attribs[i].normalized = GL_FALSE;
}
-
} break;
case VS::ARRAY_COLOR: {
- attribs[i].size=4;
+ attribs[i].size = 4;
- if (p_format&VS::ARRAY_COMPRESS_COLOR) {
- attribs[i].type=GL_UNSIGNED_BYTE;
- stride+=4;
- attribs[i].normalized=GL_TRUE;
+ if (p_format & VS::ARRAY_COMPRESS_COLOR) {
+ attribs[i].type = GL_UNSIGNED_BYTE;
+ stride += 4;
+ attribs[i].normalized = GL_TRUE;
} else {
- attribs[i].type=GL_FLOAT;
- stride+=16;
- attribs[i].normalized=GL_FALSE;
+ attribs[i].type = GL_FLOAT;
+ stride += 16;
+ attribs[i].normalized = GL_FALSE;
}
-
} break;
case VS::ARRAY_TEX_UV: {
- attribs[i].size=2;
+ attribs[i].size = 2;
- if (p_format&VS::ARRAY_COMPRESS_TEX_UV) {
- attribs[i].type=GL_HALF_FLOAT;
- stride+=4;
+ if (p_format & VS::ARRAY_COMPRESS_TEX_UV) {
+ attribs[i].type = GL_HALF_FLOAT;
+ stride += 4;
} else {
- attribs[i].type=GL_FLOAT;
- stride+=8;
+ attribs[i].type = GL_FLOAT;
+ stride += 8;
}
- attribs[i].normalized=GL_FALSE;
-
+ attribs[i].normalized = GL_FALSE;
} break;
case VS::ARRAY_TEX_UV2: {
- attribs[i].size=2;
+ attribs[i].size = 2;
- if (p_format&VS::ARRAY_COMPRESS_TEX_UV2) {
- attribs[i].type=GL_HALF_FLOAT;
- stride+=4;
+ if (p_format & VS::ARRAY_COMPRESS_TEX_UV2) {
+ attribs[i].type = GL_HALF_FLOAT;
+ stride += 4;
} else {
- attribs[i].type=GL_FLOAT;
- stride+=8;
+ attribs[i].type = GL_FLOAT;
+ stride += 8;
}
- attribs[i].normalized=GL_FALSE;
-
-
+ attribs[i].normalized = GL_FALSE;
} break;
case VS::ARRAY_BONES: {
- attribs[i].size=4;
+ attribs[i].size = 4;
- if (p_format&VS::ARRAY_FLAG_USE_16_BIT_BONES) {
- attribs[i].type=GL_UNSIGNED_SHORT;
- stride+=8;
+ if (p_format & VS::ARRAY_FLAG_USE_16_BIT_BONES) {
+ attribs[i].type = GL_UNSIGNED_SHORT;
+ stride += 8;
} else {
- attribs[i].type=GL_UNSIGNED_BYTE;
- stride+=4;
+ attribs[i].type = GL_UNSIGNED_BYTE;
+ stride += 4;
}
- attribs[i].normalized=GL_FALSE;
- attribs[i].integer=true;
-
-
+ attribs[i].normalized = GL_FALSE;
+ attribs[i].integer = true;
} break;
case VS::ARRAY_WEIGHTS: {
- attribs[i].size=4;
+ attribs[i].size = 4;
- if (p_format&VS::ARRAY_COMPRESS_WEIGHTS) {
+ if (p_format & VS::ARRAY_COMPRESS_WEIGHTS) {
- attribs[i].type=GL_UNSIGNED_SHORT;
- stride+=8;
- attribs[i].normalized=GL_TRUE;
+ attribs[i].type = GL_UNSIGNED_SHORT;
+ stride += 8;
+ attribs[i].normalized = GL_TRUE;
} else {
- attribs[i].type=GL_FLOAT;
- stride+=16;
- attribs[i].normalized=GL_FALSE;
+ attribs[i].type = GL_FLOAT;
+ stride += 16;
+ attribs[i].normalized = GL_FALSE;
}
} break;
case VS::ARRAY_INDEX: {
- attribs[i].size=1;
+ attribs[i].size = 1;
- if (p_vertex_count>=(1<<16)) {
- attribs[i].type=GL_UNSIGNED_INT;
- attribs[i].stride=4;
+ if (p_vertex_count >= (1 << 16)) {
+ attribs[i].type = GL_UNSIGNED_INT;
+ attribs[i].stride = 4;
} else {
- attribs[i].type=GL_UNSIGNED_SHORT;
- attribs[i].stride=2;
+ attribs[i].type = GL_UNSIGNED_SHORT;
+ attribs[i].stride = 2;
}
- attribs[i].normalized=GL_FALSE;
+ attribs[i].normalized = GL_FALSE;
} break;
-
}
}
- for(int i=0;i<VS::ARRAY_MAX-1;i++) {
- attribs[i].stride=stride;
+ for (int i = 0; i < VS::ARRAY_MAX - 1; i++) {
+ attribs[i].stride = stride;
}
//validate sizes
int array_size = stride * p_vertex_count;
- int index_array_size=0;
- if (array.size()!=array_size && array.size()+p_vertex_count*2 == array_size) {
+ int index_array_size = 0;
+ if (array.size() != array_size && array.size() + p_vertex_count * 2 == array_size) {
//old format, convert
array = PoolVector<uint8_t>();
- array.resize( p_array.size()+p_vertex_count*2 );
+ array.resize(p_array.size() + p_vertex_count * 2);
PoolVector<uint8_t>::Write w = array.write();
PoolVector<uint8_t>::Read r = p_array.read();
- uint16_t *w16 = (uint16_t*)w.ptr();
- const uint16_t *r16 = (uint16_t*)r.ptr();
+ uint16_t *w16 = (uint16_t *)w.ptr();
+ const uint16_t *r16 = (uint16_t *)r.ptr();
uint16_t one = Math::make_half_float(1);
- for(int i=0;i<p_vertex_count;i++) {
+ for (int i = 0; i < p_vertex_count; i++) {
*w16++ = *r16++;
*w16++ = *r16++;
*w16++ = *r16++;
*w16++ = one;
- for(int j=0;j<(stride/2)-4;j++) {
+ for (int j = 0; j < (stride / 2) - 4; j++) {
*w16++ = *r16++;
}
}
-
}
- ERR_FAIL_COND(array.size()!=array_size);
+ ERR_FAIL_COND(array.size() != array_size);
- if (p_format&VS::ARRAY_FORMAT_INDEX) {
+ if (p_format & VS::ARRAY_FORMAT_INDEX) {
- index_array_size=attribs[VS::ARRAY_INDEX].stride*p_index_count;
+ index_array_size = attribs[VS::ARRAY_INDEX].stride * p_index_count;
}
+ ERR_FAIL_COND(p_index_array.size() != index_array_size);
- ERR_FAIL_COND(p_index_array.size()!=index_array_size);
-
- ERR_FAIL_COND(p_blend_shapes.size()!=mesh->blend_shape_count);
+ ERR_FAIL_COND(p_blend_shapes.size() != mesh->blend_shape_count);
- for(int i=0;i<p_blend_shapes.size();i++) {
- ERR_FAIL_COND(p_blend_shapes[i].size()!=array_size);
+ for (int i = 0; i < p_blend_shapes.size(); i++) {
+ ERR_FAIL_COND(p_blend_shapes[i].size() != array_size);
}
//ok all valid, create stuff
- Surface * surface = memnew( Surface );
-
- surface->active=true;
- surface->array_len=p_vertex_count;
- surface->index_array_len=p_index_count;
- surface->array_byte_size=array.size();
- surface->index_array_byte_size=p_index_array.size();
- surface->primitive=p_primitive;
- surface->mesh=mesh;
- surface->format=p_format;
- surface->skeleton_bone_aabb=p_bone_aabbs;
+ Surface *surface = memnew(Surface);
+
+ surface->active = true;
+ surface->array_len = p_vertex_count;
+ surface->index_array_len = p_index_count;
+ surface->array_byte_size = array.size();
+ surface->index_array_byte_size = p_index_array.size();
+ surface->primitive = p_primitive;
+ surface->mesh = mesh;
+ surface->format = p_format;
+ surface->skeleton_bone_aabb = p_bone_aabbs;
surface->skeleton_bone_used.resize(surface->skeleton_bone_aabb.size());
- surface->aabb=p_aabb;
- surface->max_bone=p_bone_aabbs.size();
+ surface->aabb = p_aabb;
+ surface->max_bone = p_bone_aabbs.size();
- for(int i=0;i<surface->skeleton_bone_used.size();i++) {
- if (surface->skeleton_bone_aabb[i].size.x<0 || surface->skeleton_bone_aabb[i].size.y<0 || surface->skeleton_bone_aabb[i].size.z<0) {
- surface->skeleton_bone_used[i]=false;
+ for (int i = 0; i < surface->skeleton_bone_used.size(); i++) {
+ if (surface->skeleton_bone_aabb[i].size.x < 0 || surface->skeleton_bone_aabb[i].size.y < 0 || surface->skeleton_bone_aabb[i].size.z < 0) {
+ surface->skeleton_bone_used[i] = false;
} else {
- surface->skeleton_bone_used[i]=true;
+ surface->skeleton_bone_used[i] = true;
}
}
- for(int i=0;i<VS::ARRAY_MAX;i++) {
- surface->attribs[i]=attribs[i];
+ for (int i = 0; i < VS::ARRAY_MAX; i++) {
+ surface->attribs[i] = attribs[i];
}
{
PoolVector<uint8_t>::Read vr = array.read();
- glGenBuffers(1,&surface->vertex_id);
- glBindBuffer(GL_ARRAY_BUFFER,surface->vertex_id);
- glBufferData(GL_ARRAY_BUFFER,array_size,vr.ptr(),GL_STATIC_DRAW);
- glBindBuffer(GL_ARRAY_BUFFER,0); //unbind
+ glGenBuffers(1, &surface->vertex_id);
+ glBindBuffer(GL_ARRAY_BUFFER, surface->vertex_id);
+ glBufferData(GL_ARRAY_BUFFER, array_size, vr.ptr(), GL_STATIC_DRAW);
+ glBindBuffer(GL_ARRAY_BUFFER, 0); //unbind
-
- if (p_format&VS::ARRAY_FORMAT_INDEX) {
+ if (p_format & VS::ARRAY_FORMAT_INDEX) {
PoolVector<uint8_t>::Read ir = p_index_array.read();
- glGenBuffers(1,&surface->index_id);
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,surface->index_id);
- glBufferData(GL_ELEMENT_ARRAY_BUFFER,index_array_size,ir.ptr(),GL_STATIC_DRAW);
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0); //unbind
-
-
+ glGenBuffers(1, &surface->index_id);
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, surface->index_id);
+ glBufferData(GL_ELEMENT_ARRAY_BUFFER, index_array_size, ir.ptr(), GL_STATIC_DRAW);
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); //unbind
}
//generate arrays for faster state switching
- for(int ai=0;ai<2;ai++) {
+ for (int ai = 0; ai < 2; ai++) {
- if (ai==0) {
+ if (ai == 0) {
//for normal draw
- glGenVertexArrays(1,&surface->array_id);
+ glGenVertexArrays(1, &surface->array_id);
glBindVertexArray(surface->array_id);
- glBindBuffer(GL_ARRAY_BUFFER,surface->vertex_id);
- } else if (ai==1) {
+ glBindBuffer(GL_ARRAY_BUFFER, surface->vertex_id);
+ } else if (ai == 1) {
//for instancing draw (can be changed and no one cares)
- glGenVertexArrays(1,&surface->instancing_array_id);
+ glGenVertexArrays(1, &surface->instancing_array_id);
glBindVertexArray(surface->instancing_array_id);
- glBindBuffer(GL_ARRAY_BUFFER,surface->vertex_id);
+ glBindBuffer(GL_ARRAY_BUFFER, surface->vertex_id);
}
-
- for(int i=0;i<VS::ARRAY_MAX-1;i++) {
+ for (int i = 0; i < VS::ARRAY_MAX - 1; i++) {
if (!attribs[i].enabled)
continue;
if (attribs[i].integer) {
- glVertexAttribIPointer(attribs[i].index,attribs[i].size,attribs[i].type,attribs[i].stride,((uint8_t*)0)+attribs[i].offset);
+ glVertexAttribIPointer(attribs[i].index, attribs[i].size, attribs[i].type, attribs[i].stride, ((uint8_t *)0) + attribs[i].offset);
} else {
- glVertexAttribPointer(attribs[i].index,attribs[i].size,attribs[i].type,attribs[i].normalized,attribs[i].stride,((uint8_t*)0)+attribs[i].offset);
+ glVertexAttribPointer(attribs[i].index, attribs[i].size, attribs[i].type, attribs[i].normalized, attribs[i].stride, ((uint8_t *)0) + attribs[i].offset);
}
glEnableVertexAttribArray(attribs[i].index);
-
}
if (surface->index_id) {
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,surface->index_id);
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, surface->index_id);
}
glBindVertexArray(0);
- glBindBuffer(GL_ARRAY_BUFFER,0); //unbind
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0);
+ glBindBuffer(GL_ARRAY_BUFFER, 0); //unbind
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}
-
}
{
//blend shapes
- for(int i=0;i<p_blend_shapes.size();i++) {
+ for (int i = 0; i < p_blend_shapes.size(); i++) {
Surface::BlendShape mt;
PoolVector<uint8_t>::Read vr = p_blend_shapes[i].read();
- glGenBuffers(1,&mt.vertex_id);
- glBindBuffer(GL_ARRAY_BUFFER,mt.vertex_id);
- glBufferData(GL_ARRAY_BUFFER,array_size,vr.ptr(),GL_STATIC_DRAW);
- glBindBuffer(GL_ARRAY_BUFFER,0); //unbind
+ glGenBuffers(1, &mt.vertex_id);
+ glBindBuffer(GL_ARRAY_BUFFER, mt.vertex_id);
+ glBufferData(GL_ARRAY_BUFFER, array_size, vr.ptr(), GL_STATIC_DRAW);
+ glBindBuffer(GL_ARRAY_BUFFER, 0); //unbind
- glGenVertexArrays(1,&mt.array_id);
+ glGenVertexArrays(1, &mt.array_id);
glBindVertexArray(mt.array_id);
- glBindBuffer(GL_ARRAY_BUFFER,mt.vertex_id);
+ glBindBuffer(GL_ARRAY_BUFFER, mt.vertex_id);
- for(int j=0;j<VS::ARRAY_MAX-1;j++) {
+ for (int j = 0; j < VS::ARRAY_MAX - 1; j++) {
if (!attribs[j].enabled)
continue;
if (attribs[j].integer) {
- glVertexAttribIPointer(attribs[j].index,attribs[j].size,attribs[j].type,attribs[j].stride,((uint8_t*)0)+attribs[j].offset);
+ glVertexAttribIPointer(attribs[j].index, attribs[j].size, attribs[j].type, attribs[j].stride, ((uint8_t *)0) + attribs[j].offset);
} else {
- glVertexAttribPointer(attribs[j].index,attribs[j].size,attribs[j].type,attribs[j].normalized,attribs[j].stride,((uint8_t*)0)+attribs[j].offset);
+ glVertexAttribPointer(attribs[j].index, attribs[j].size, attribs[j].type, attribs[j].normalized, attribs[j].stride, ((uint8_t *)0) + attribs[j].offset);
}
glEnableVertexAttribArray(attribs[j].index);
-
}
glBindVertexArray(0);
- glBindBuffer(GL_ARRAY_BUFFER,0); //unbind
+ glBindBuffer(GL_ARRAY_BUFFER, 0); //unbind
surface->blend_shapes.push_back(mt);
-
}
}
@@ -2915,105 +2755,98 @@ void RasterizerStorageGLES3::mesh_add_surface(RID p_mesh,uint32_t p_format,VS::P
mesh->instance_change_notify();
}
-void RasterizerStorageGLES3::mesh_set_blend_shape_count(RID p_mesh,int p_amount){
+void RasterizerStorageGLES3::mesh_set_blend_shape_count(RID p_mesh, int p_amount) {
Mesh *mesh = mesh_owner.getornull(p_mesh);
ERR_FAIL_COND(!mesh);
+ ERR_FAIL_COND(mesh->surfaces.size() != 0);
+ ERR_FAIL_COND(p_amount < 0);
- ERR_FAIL_COND(mesh->surfaces.size()!=0);
- ERR_FAIL_COND(p_amount<0);
-
- mesh->blend_shape_count=p_amount;
-
+ mesh->blend_shape_count = p_amount;
}
-int RasterizerStorageGLES3::mesh_get_blend_shape_count(RID p_mesh) const{
+int RasterizerStorageGLES3::mesh_get_blend_shape_count(RID p_mesh) const {
const Mesh *mesh = mesh_owner.getornull(p_mesh);
- ERR_FAIL_COND_V(!mesh,0);
+ ERR_FAIL_COND_V(!mesh, 0);
return mesh->blend_shape_count;
}
-
-void RasterizerStorageGLES3::mesh_set_blend_shape_mode(RID p_mesh,VS::BlendShapeMode p_mode){
+void RasterizerStorageGLES3::mesh_set_blend_shape_mode(RID p_mesh, VS::BlendShapeMode p_mode) {
Mesh *mesh = mesh_owner.getornull(p_mesh);
ERR_FAIL_COND(!mesh);
- mesh->blend_shape_mode=p_mode;
-
+ mesh->blend_shape_mode = p_mode;
}
-VS::BlendShapeMode RasterizerStorageGLES3::mesh_get_blend_shape_mode(RID p_mesh) const{
+VS::BlendShapeMode RasterizerStorageGLES3::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, VS::BLEND_SHAPE_MODE_NORMALIZED);
return mesh->blend_shape_mode;
}
-void RasterizerStorageGLES3::mesh_surface_set_material(RID p_mesh, int p_surface, RID p_material){
+void RasterizerStorageGLES3::mesh_surface_set_material(RID p_mesh, int p_surface, RID p_material) {
Mesh *mesh = mesh_owner.getornull(p_mesh);
ERR_FAIL_COND(!mesh);
- ERR_FAIL_INDEX(p_surface,mesh->surfaces.size());
+ ERR_FAIL_INDEX(p_surface, mesh->surfaces.size());
- if (mesh->surfaces[p_surface]->material==p_material)
+ if (mesh->surfaces[p_surface]->material == p_material)
return;
if (mesh->surfaces[p_surface]->material.is_valid()) {
- _material_remove_geometry(mesh->surfaces[p_surface]->material,mesh->surfaces[p_surface]);
+ _material_remove_geometry(mesh->surfaces[p_surface]->material, mesh->surfaces[p_surface]);
}
- mesh->surfaces[p_surface]->material=p_material;
+ mesh->surfaces[p_surface]->material = p_material;
if (mesh->surfaces[p_surface]->material.is_valid()) {
- _material_add_geometry(mesh->surfaces[p_surface]->material,mesh->surfaces[p_surface]);
+ _material_add_geometry(mesh->surfaces[p_surface]->material, mesh->surfaces[p_surface]);
}
mesh->instance_material_change_notify();
-
-
}
-RID RasterizerStorageGLES3::mesh_surface_get_material(RID p_mesh, int p_surface) const{
+RID RasterizerStorageGLES3::mesh_surface_get_material(RID p_mesh, int p_surface) const {
const Mesh *mesh = mesh_owner.getornull(p_mesh);
- ERR_FAIL_COND_V(!mesh,RID());
- ERR_FAIL_INDEX_V(p_surface,mesh->surfaces.size(),RID());
+ ERR_FAIL_COND_V(!mesh, RID());
+ ERR_FAIL_INDEX_V(p_surface, mesh->surfaces.size(), RID());
return mesh->surfaces[p_surface]->material;
}
-int RasterizerStorageGLES3::mesh_surface_get_array_len(RID p_mesh, int p_surface) const{
+int RasterizerStorageGLES3::mesh_surface_get_array_len(RID p_mesh, int p_surface) const {
const Mesh *mesh = mesh_owner.getornull(p_mesh);
- ERR_FAIL_COND_V(!mesh,0);
- ERR_FAIL_INDEX_V(p_surface,mesh->surfaces.size(),0);
+ ERR_FAIL_COND_V(!mesh, 0);
+ ERR_FAIL_INDEX_V(p_surface, mesh->surfaces.size(), 0);
return mesh->surfaces[p_surface]->array_len;
-
}
-int RasterizerStorageGLES3::mesh_surface_get_array_index_len(RID p_mesh, int p_surface) const{
+int RasterizerStorageGLES3::mesh_surface_get_array_index_len(RID p_mesh, int p_surface) const {
const Mesh *mesh = mesh_owner.getornull(p_mesh);
- ERR_FAIL_COND_V(!mesh,0);
- ERR_FAIL_INDEX_V(p_surface,mesh->surfaces.size(),0);
+ ERR_FAIL_COND_V(!mesh, 0);
+ ERR_FAIL_INDEX_V(p_surface, mesh->surfaces.size(), 0);
return mesh->surfaces[p_surface]->index_array_len;
}
-PoolVector<uint8_t> RasterizerStorageGLES3::mesh_surface_get_array(RID p_mesh, int p_surface) const{
+PoolVector<uint8_t> RasterizerStorageGLES3::mesh_surface_get_array(RID p_mesh, int p_surface) const {
const Mesh *mesh = mesh_owner.getornull(p_mesh);
- ERR_FAIL_COND_V(!mesh,PoolVector<uint8_t>());
- ERR_FAIL_INDEX_V(p_surface,mesh->surfaces.size(),PoolVector<uint8_t>());
+ ERR_FAIL_COND_V(!mesh, PoolVector<uint8_t>());
+ ERR_FAIL_INDEX_V(p_surface, mesh->surfaces.size(), PoolVector<uint8_t>());
Surface *surface = mesh->surfaces[p_surface];
- glBindBuffer(GL_ARRAY_BUFFER,surface->vertex_id);
- void * data = glMapBufferRange(GL_ARRAY_BUFFER,0,surface->array_byte_size,GL_MAP_READ_BIT);
+ glBindBuffer(GL_ARRAY_BUFFER, surface->vertex_id);
+ void *data = glMapBufferRange(GL_ARRAY_BUFFER, 0, surface->array_byte_size, GL_MAP_READ_BIT);
- ERR_FAIL_COND_V(!data,PoolVector<uint8_t>());
+ ERR_FAIL_COND_V(!data, PoolVector<uint8_t>());
PoolVector<uint8_t> ret;
ret.resize(surface->array_byte_size);
@@ -3021,27 +2854,26 @@ PoolVector<uint8_t> RasterizerStorageGLES3::mesh_surface_get_array(RID p_mesh, i
{
PoolVector<uint8_t>::Write w = ret.write();
- copymem(w.ptr(),data,surface->array_byte_size);
+ copymem(w.ptr(), data, surface->array_byte_size);
}
glUnmapBuffer(GL_ARRAY_BUFFER);
-
return ret;
}
PoolVector<uint8_t> RasterizerStorageGLES3::mesh_surface_get_index_array(RID p_mesh, int p_surface) const {
const Mesh *mesh = mesh_owner.getornull(p_mesh);
- ERR_FAIL_COND_V(!mesh,PoolVector<uint8_t>());
- ERR_FAIL_INDEX_V(p_surface,mesh->surfaces.size(),PoolVector<uint8_t>());
+ ERR_FAIL_COND_V(!mesh, PoolVector<uint8_t>());
+ ERR_FAIL_INDEX_V(p_surface, mesh->surfaces.size(), PoolVector<uint8_t>());
Surface *surface = mesh->surfaces[p_surface];
- ERR_FAIL_COND_V(surface->index_array_len==0,PoolVector<uint8_t>());
+ ERR_FAIL_COND_V(surface->index_array_len == 0, PoolVector<uint8_t>());
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,surface->index_id);
- void * data = glMapBufferRange(GL_ELEMENT_ARRAY_BUFFER,0,surface->index_array_byte_size,GL_MAP_READ_BIT);
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, surface->index_id);
+ void *data = glMapBufferRange(GL_ELEMENT_ARRAY_BUFFER, 0, surface->index_array_byte_size, GL_MAP_READ_BIT);
- ERR_FAIL_COND_V(!data,PoolVector<uint8_t>());
+ ERR_FAIL_COND_V(!data, PoolVector<uint8_t>());
PoolVector<uint8_t> ret;
ret.resize(surface->index_array_byte_size);
@@ -3049,7 +2881,7 @@ PoolVector<uint8_t> RasterizerStorageGLES3::mesh_surface_get_index_array(RID p_m
{
PoolVector<uint8_t>::Write w = ret.write();
- copymem(w.ptr(),data,surface->index_array_byte_size);
+ copymem(w.ptr(), data, surface->index_array_byte_size);
}
glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER);
@@ -3057,23 +2889,21 @@ PoolVector<uint8_t> RasterizerStorageGLES3::mesh_surface_get_index_array(RID p_m
return ret;
}
-
-uint32_t RasterizerStorageGLES3::mesh_surface_get_format(RID p_mesh, int p_surface) const{
+uint32_t RasterizerStorageGLES3::mesh_surface_get_format(RID p_mesh, int p_surface) const {
const Mesh *mesh = mesh_owner.getornull(p_mesh);
- ERR_FAIL_COND_V(!mesh,0);
- ERR_FAIL_INDEX_V(p_surface,mesh->surfaces.size(),0);
+ ERR_FAIL_COND_V(!mesh, 0);
+ ERR_FAIL_INDEX_V(p_surface, mesh->surfaces.size(), 0);
return mesh->surfaces[p_surface]->format;
-
}
-VS::PrimitiveType RasterizerStorageGLES3::mesh_surface_get_primitive_type(RID p_mesh, int p_surface) const{
+VS::PrimitiveType RasterizerStorageGLES3::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, VS::PRIMITIVE_MAX);
+ ERR_FAIL_INDEX_V(p_surface, mesh->surfaces.size(), VS::PRIMITIVE_MAX);
return mesh->surfaces[p_surface]->primitive;
}
@@ -3081,27 +2911,25 @@ VS::PrimitiveType RasterizerStorageGLES3::mesh_surface_get_primitive_type(RID p_
Rect3 RasterizerStorageGLES3::mesh_surface_get_aabb(RID p_mesh, int p_surface) const {
const Mesh *mesh = mesh_owner.getornull(p_mesh);
- ERR_FAIL_COND_V(!mesh,Rect3());
- ERR_FAIL_INDEX_V(p_surface,mesh->surfaces.size(),Rect3());
+ ERR_FAIL_COND_V(!mesh, Rect3());
+ ERR_FAIL_INDEX_V(p_surface, mesh->surfaces.size(), Rect3());
return mesh->surfaces[p_surface]->aabb;
-
-
}
-Vector<PoolVector<uint8_t> > RasterizerStorageGLES3::mesh_surface_get_blend_shapes(RID p_mesh, int p_surface) const{
+Vector<PoolVector<uint8_t> > RasterizerStorageGLES3::mesh_surface_get_blend_shapes(RID p_mesh, int p_surface) const {
const Mesh *mesh = mesh_owner.getornull(p_mesh);
- ERR_FAIL_COND_V(!mesh,Vector<PoolVector<uint8_t> >());
- ERR_FAIL_INDEX_V(p_surface,mesh->surfaces.size(),Vector<PoolVector<uint8_t> >());
+ ERR_FAIL_COND_V(!mesh, Vector<PoolVector<uint8_t> >());
+ ERR_FAIL_INDEX_V(p_surface, mesh->surfaces.size(), Vector<PoolVector<uint8_t> >());
Vector<PoolVector<uint8_t> > bsarr;
- for(int i=0;i<mesh->surfaces[p_surface]->blend_shapes.size();i++) {
+ for (int i = 0; i < mesh->surfaces[p_surface]->blend_shapes.size(); i++) {
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,mesh->surfaces[p_surface]->blend_shapes[i].vertex_id);
- void * data = glMapBufferRange(GL_ELEMENT_ARRAY_BUFFER,0,mesh->surfaces[p_surface]->array_byte_size,GL_MAP_READ_BIT);
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mesh->surfaces[p_surface]->blend_shapes[i].vertex_id);
+ void *data = glMapBufferRange(GL_ELEMENT_ARRAY_BUFFER, 0, mesh->surfaces[p_surface]->array_byte_size, GL_MAP_READ_BIT);
- ERR_FAIL_COND_V(!data,Vector<PoolVector<uint8_t> >());
+ ERR_FAIL_COND_V(!data, Vector<PoolVector<uint8_t> >());
PoolVector<uint8_t> ret;
ret.resize(mesh->surfaces[p_surface]->array_byte_size);
@@ -3109,7 +2937,7 @@ Vector<PoolVector<uint8_t> > RasterizerStorageGLES3::mesh_surface_get_blend_shap
{
PoolVector<uint8_t>::Write w = ret.write();
- copymem(w.ptr(),data,mesh->surfaces[p_surface]->array_byte_size);
+ copymem(w.ptr(), data, mesh->surfaces[p_surface]->array_byte_size);
}
bsarr.push_back(ret);
@@ -3118,42 +2946,39 @@ Vector<PoolVector<uint8_t> > RasterizerStorageGLES3::mesh_surface_get_blend_shap
}
return bsarr;
-
}
-Vector<Rect3> RasterizerStorageGLES3::mesh_surface_get_skeleton_aabb(RID p_mesh, int p_surface) const{
+Vector<Rect3> RasterizerStorageGLES3::mesh_surface_get_skeleton_aabb(RID p_mesh, int p_surface) const {
const Mesh *mesh = mesh_owner.getornull(p_mesh);
- ERR_FAIL_COND_V(!mesh,Vector<Rect3 >());
- ERR_FAIL_INDEX_V(p_surface,mesh->surfaces.size(),Vector<Rect3 >());
+ ERR_FAIL_COND_V(!mesh, Vector<Rect3>());
+ ERR_FAIL_INDEX_V(p_surface, mesh->surfaces.size(), Vector<Rect3>());
return mesh->surfaces[p_surface]->skeleton_bone_aabb;
-
}
-
-void RasterizerStorageGLES3::mesh_remove_surface(RID p_mesh, int p_surface){
+void RasterizerStorageGLES3::mesh_remove_surface(RID p_mesh, int p_surface) {
Mesh *mesh = mesh_owner.getornull(p_mesh);
ERR_FAIL_COND(!mesh);
- ERR_FAIL_INDEX(p_surface,mesh->surfaces.size());
+ ERR_FAIL_INDEX(p_surface, mesh->surfaces.size());
Surface *surface = mesh->surfaces[p_surface];
if (surface->material.is_valid()) {
- _material_remove_geometry(surface->material,mesh->surfaces[p_surface]);
+ _material_remove_geometry(surface->material, mesh->surfaces[p_surface]);
}
- glDeleteBuffers(1,&surface->vertex_id);
+ glDeleteBuffers(1, &surface->vertex_id);
if (surface->index_id) {
- glDeleteBuffers(1,&surface->index_id);
+ glDeleteBuffers(1, &surface->index_id);
}
- glDeleteVertexArrays(1,&surface->array_id);
+ glDeleteVertexArrays(1, &surface->array_id);
- for(int i=0;i<surface->blend_shapes.size();i++) {
+ for (int i = 0; i < surface->blend_shapes.size(); i++) {
- glDeleteBuffers(1,&surface->blend_shapes[i].vertex_id);
- glDeleteVertexArrays(1,&surface->blend_shapes[i].array_id);
+ glDeleteBuffers(1, &surface->blend_shapes[i].vertex_id);
+ glDeleteVertexArrays(1, &surface->blend_shapes[i].array_id);
}
mesh->instance_material_change_notify();
@@ -3164,115 +2989,109 @@ void RasterizerStorageGLES3::mesh_remove_surface(RID p_mesh, int p_surface){
mesh->instance_change_notify();
}
-int RasterizerStorageGLES3::mesh_get_surface_count(RID p_mesh) const{
+int RasterizerStorageGLES3::mesh_get_surface_count(RID p_mesh) const {
const Mesh *mesh = mesh_owner.getornull(p_mesh);
- ERR_FAIL_COND_V(!mesh,0);
+ ERR_FAIL_COND_V(!mesh, 0);
return mesh->surfaces.size();
-
}
-void RasterizerStorageGLES3::mesh_set_custom_aabb(RID p_mesh,const Rect3& p_aabb){
+void RasterizerStorageGLES3::mesh_set_custom_aabb(RID p_mesh, const Rect3 &p_aabb) {
Mesh *mesh = mesh_owner.getornull(p_mesh);
ERR_FAIL_COND(!mesh);
- mesh->custom_aabb=p_aabb;
+ mesh->custom_aabb = p_aabb;
}
-Rect3 RasterizerStorageGLES3::mesh_get_custom_aabb(RID p_mesh) const{
+Rect3 RasterizerStorageGLES3::mesh_get_custom_aabb(RID p_mesh) const {
const Mesh *mesh = mesh_owner.getornull(p_mesh);
- ERR_FAIL_COND_V(!mesh,Rect3());
+ ERR_FAIL_COND_V(!mesh, Rect3());
return mesh->custom_aabb;
-
}
-Rect3 RasterizerStorageGLES3::mesh_get_aabb(RID p_mesh,RID p_skeleton) const{
+Rect3 RasterizerStorageGLES3::mesh_get_aabb(RID p_mesh, RID p_skeleton) const {
- Mesh *mesh = mesh_owner.get( p_mesh );
- ERR_FAIL_COND_V(!mesh,Rect3());
+ Mesh *mesh = mesh_owner.get(p_mesh);
+ ERR_FAIL_COND_V(!mesh, Rect3());
- if (mesh->custom_aabb!=Rect3())
+ if (mesh->custom_aabb != Rect3())
return mesh->custom_aabb;
- Skeleton *sk=NULL;
+ Skeleton *sk = NULL;
if (p_skeleton.is_valid())
- sk=skeleton_owner.get(p_skeleton);
+ sk = skeleton_owner.get(p_skeleton);
Rect3 aabb;
- if (sk && sk->size!=0) {
+ if (sk && sk->size != 0) {
-
- for (int i=0;i<mesh->surfaces.size();i++) {
+ for (int i = 0; i < mesh->surfaces.size(); i++) {
Rect3 laabb;
- if (mesh->surfaces[i]->format&VS::ARRAY_FORMAT_BONES && mesh->surfaces[i]->skeleton_bone_aabb.size()) {
-
+ if (mesh->surfaces[i]->format & VS::ARRAY_FORMAT_BONES && mesh->surfaces[i]->skeleton_bone_aabb.size()) {
int bs = mesh->surfaces[i]->skeleton_bone_aabb.size();
const Rect3 *skbones = mesh->surfaces[i]->skeleton_bone_aabb.ptr();
const bool *skused = mesh->surfaces[i]->skeleton_bone_used.ptr();
int sbs = sk->size;
- ERR_CONTINUE(bs>sbs);
+ ERR_CONTINUE(bs > sbs);
float *skb = sk->bones.ptr();
-
-
- bool first=true;
+ bool first = true;
if (sk->use_2d) {
- for(int j=0;j<bs;j++) {
+ for (int j = 0; j < bs; j++) {
if (!skused[j])
continue;
- float *dataptr = &skb[8*j];
+ float *dataptr = &skb[8 * j];
Transform mtx;
- mtx.basis.elements[0][0]=dataptr[ 0];
- mtx.basis.elements[0][1]=dataptr[ 1];
- mtx.origin[0]=dataptr[ 3];
- mtx.basis.elements[1][0]=dataptr[ 4];
- mtx.basis.elements[1][1]=dataptr[ 5];
- mtx.origin[1]=dataptr[ 7];
+ mtx.basis.elements[0][0] = dataptr[0];
+ mtx.basis.elements[0][1] = dataptr[1];
+ mtx.origin[0] = dataptr[3];
+ mtx.basis.elements[1][0] = dataptr[4];
+ mtx.basis.elements[1][1] = dataptr[5];
+ mtx.origin[1] = dataptr[7];
- Rect3 baabb = mtx.xform( skbones[j] );
+ Rect3 baabb = mtx.xform(skbones[j]);
if (first) {
- laabb=baabb;
- first=false;
+ laabb = baabb;
+ first = false;
} else {
laabb.merge_with(baabb);
}
}
} else {
- for(int j=0;j<bs;j++) {
+ for (int j = 0; j < bs; j++) {
if (!skused[j])
continue;
- float *dataptr = &skb[12*j];
+ float *dataptr = &skb[12 * j];
Transform mtx;
- mtx.basis.elements[0][0]=dataptr[ 0];
- mtx.basis.elements[0][1]=dataptr[ 1];
- mtx.basis.elements[0][2]=dataptr[ 2];
- mtx.origin.x=dataptr[ 3];
- mtx.basis.elements[1][0]=dataptr[ 4];
- mtx.basis.elements[1][1]=dataptr[ 5];
- mtx.basis.elements[1][2]=dataptr[ 6];
- mtx.origin.y=dataptr[ 7];
- mtx.basis.elements[2][0]=dataptr[ 8];
- mtx.basis.elements[2][1]=dataptr[ 9];
- mtx.basis.elements[2][2]=dataptr[10];
- mtx.origin.z=dataptr[11];
-
- Rect3 baabb = mtx.xform ( skbones[j] );
+ mtx.basis.elements[0][0] = dataptr[0];
+ mtx.basis.elements[0][1] = dataptr[1];
+ mtx.basis.elements[0][2] = dataptr[2];
+ mtx.origin.x = dataptr[3];
+ mtx.basis.elements[1][0] = dataptr[4];
+ mtx.basis.elements[1][1] = dataptr[5];
+ mtx.basis.elements[1][2] = dataptr[6];
+ mtx.origin.y = dataptr[7];
+ mtx.basis.elements[2][0] = dataptr[8];
+ mtx.basis.elements[2][1] = dataptr[9];
+ mtx.basis.elements[2][2] = dataptr[10];
+ mtx.origin.z = dataptr[11];
+
+ Rect3 baabb = mtx.xform(skbones[j]);
if (first) {
- laabb=baabb;
- first=false;
+ laabb = baabb;
+ first = false;
} else {
laabb.merge_with(baabb);
}
@@ -3281,36 +3100,34 @@ Rect3 RasterizerStorageGLES3::mesh_get_aabb(RID p_mesh,RID p_skeleton) const{
} else {
- laabb=mesh->surfaces[i]->aabb;
+ laabb = mesh->surfaces[i]->aabb;
}
- if (i==0)
- aabb=laabb;
+ if (i == 0)
+ aabb = laabb;
else
aabb.merge_with(laabb);
}
} else {
- for (int i=0;i<mesh->surfaces.size();i++) {
+ for (int i = 0; i < mesh->surfaces.size(); i++) {
- if (i==0)
- aabb=mesh->surfaces[i]->aabb;
+ if (i == 0)
+ aabb = mesh->surfaces[i]->aabb;
else
aabb.merge_with(mesh->surfaces[i]->aabb);
}
-
}
return aabb;
-
}
-void RasterizerStorageGLES3::mesh_clear(RID p_mesh){
+void RasterizerStorageGLES3::mesh_clear(RID p_mesh) {
Mesh *mesh = mesh_owner.getornull(p_mesh);
ERR_FAIL_COND(!mesh);
- while(mesh->surfaces.size()) {
- mesh_remove_surface(p_mesh,0);
+ while (mesh->surfaces.size()) {
+ mesh_remove_surface(p_mesh, 0);
}
}
@@ -3318,7 +3135,7 @@ void RasterizerStorageGLES3::mesh_render_blend_shapes(Surface *s, float *p_weigh
glBindVertexArray(s->array_id);
- BlendShapeShaderGLES3::Conditionals cond[VS::ARRAY_MAX-1]={
+ BlendShapeShaderGLES3::Conditionals cond[VS::ARRAY_MAX - 1] = {
BlendShapeShaderGLES3::ENABLE_NORMAL, //will be ignored
BlendShapeShaderGLES3::ENABLE_NORMAL,
BlendShapeShaderGLES3::ENABLE_TANGENT,
@@ -3329,197 +3146,190 @@ void RasterizerStorageGLES3::mesh_render_blend_shapes(Surface *s, float *p_weigh
BlendShapeShaderGLES3::ENABLE_SKELETON,
};
- int stride=0;
+ int stride = 0;
- if (s->format&VS::ARRAY_FLAG_USE_2D_VERTICES) {
- stride=2*4;
+ if (s->format & VS::ARRAY_FLAG_USE_2D_VERTICES) {
+ stride = 2 * 4;
} else {
- stride=3*4;
- }
-
- static const int sizes[VS::ARRAY_MAX-1]={
- 3*4,
- 3*4,
- 4*4,
- 4*4,
- 2*4,
- 2*4,
- 4*4,
- 4*4
+ stride = 3 * 4;
+ }
+
+ static const int sizes[VS::ARRAY_MAX - 1] = {
+ 3 * 4,
+ 3 * 4,
+ 4 * 4,
+ 4 * 4,
+ 2 * 4,
+ 2 * 4,
+ 4 * 4,
+ 4 * 4
};
- for(int i=1;i<VS::ARRAY_MAX-1;i++) {
- shaders.blend_shapes.set_conditional(cond[i],s->format&(1<<i)); //enable conditional for format
- if (s->format&(1<<i)) {
- stride+=sizes[i];
+ for (int i = 1; i < VS::ARRAY_MAX - 1; i++) {
+ shaders.blend_shapes.set_conditional(cond[i], s->format & (1 << i)); //enable conditional for format
+ if (s->format & (1 << i)) {
+ stride += sizes[i];
}
}
-
//copy all first
- float base_weight=1.0;
+ float base_weight = 1.0;
int mtc = s->blend_shapes.size();
- if (s->mesh->blend_shape_mode==VS::BLEND_SHAPE_MODE_NORMALIZED) {
+ if (s->mesh->blend_shape_mode == VS::BLEND_SHAPE_MODE_NORMALIZED) {
- for(int i=0;i<mtc;i++) {
- base_weight-=p_weights[i];
+ for (int i = 0; i < mtc; i++) {
+ base_weight -= p_weights[i];
}
}
-
-
- shaders.blend_shapes.set_conditional(BlendShapeShaderGLES3::ENABLE_BLEND,false); //first pass does not blend
- shaders.blend_shapes.set_conditional(BlendShapeShaderGLES3::USE_2D_VERTEX,s->format&VS::ARRAY_FLAG_USE_2D_VERTICES); //use 2D vertices if needed
+ shaders.blend_shapes.set_conditional(BlendShapeShaderGLES3::ENABLE_BLEND, false); //first pass does not blend
+ shaders.blend_shapes.set_conditional(BlendShapeShaderGLES3::USE_2D_VERTEX, s->format & VS::ARRAY_FLAG_USE_2D_VERTICES); //use 2D vertices if needed
shaders.blend_shapes.bind();
- shaders.blend_shapes.set_uniform(BlendShapeShaderGLES3::BLEND_AMOUNT,base_weight);
+ shaders.blend_shapes.set_uniform(BlendShapeShaderGLES3::BLEND_AMOUNT, base_weight);
glEnable(GL_RASTERIZER_DISCARD);
glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, resources.transform_feedback_buffers[0]);
glBeginTransformFeedback(GL_POINTS);
- glDrawArrays(GL_POINTS,0,s->array_len);
+ glDrawArrays(GL_POINTS, 0, s->array_len);
glEndTransformFeedback();
-
- shaders.blend_shapes.set_conditional(BlendShapeShaderGLES3::ENABLE_BLEND,true); //first pass does not blend
+ shaders.blend_shapes.set_conditional(BlendShapeShaderGLES3::ENABLE_BLEND, true); //first pass does not blend
shaders.blend_shapes.bind();
- for(int ti=0;ti<mtc;ti++) {
+ for (int ti = 0; ti < mtc; ti++) {
float weight = p_weights[ti];
- if (weight<0.001) //not bother with this one
+ if (weight < 0.001) //not bother with this one
continue;
glBindVertexArray(s->blend_shapes[ti].array_id);
glBindBuffer(GL_ARRAY_BUFFER, resources.transform_feedback_buffers[0]);
glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, resources.transform_feedback_buffers[1]);
- shaders.blend_shapes.set_uniform(BlendShapeShaderGLES3::BLEND_AMOUNT,weight);
+ shaders.blend_shapes.set_uniform(BlendShapeShaderGLES3::BLEND_AMOUNT, weight);
- int ofs=0;
- for(int i=0;i<VS::ARRAY_MAX-1;i++) {
+ int ofs = 0;
+ for (int i = 0; i < VS::ARRAY_MAX - 1; i++) {
- if (s->format&(1<<i)) {
- glEnableVertexAttribArray(i+8);
- switch(i) {
+ if (s->format & (1 << i)) {
+ glEnableVertexAttribArray(i + 8);
+ switch (i) {
case VS::ARRAY_VERTEX: {
- if (s->format&VS::ARRAY_FLAG_USE_2D_VERTICES) {
- glVertexAttribPointer(i+8,2,GL_FLOAT,GL_FALSE,stride,((uint8_t*)0)+ofs);
- ofs+=2*4;
+ if (s->format & VS::ARRAY_FLAG_USE_2D_VERTICES) {
+ glVertexAttribPointer(i + 8, 2, GL_FLOAT, GL_FALSE, stride, ((uint8_t *)0) + ofs);
+ ofs += 2 * 4;
} else {
- glVertexAttribPointer(i+8,3,GL_FLOAT,GL_FALSE,stride,((uint8_t*)0)+ofs);
- ofs+=3*4;
+ glVertexAttribPointer(i + 8, 3, GL_FLOAT, GL_FALSE, stride, ((uint8_t *)0) + ofs);
+ ofs += 3 * 4;
}
} break;
case VS::ARRAY_NORMAL: {
- glVertexAttribPointer(i+8,3,GL_FLOAT,GL_FALSE,stride,((uint8_t*)0)+ofs);
- ofs+=3*4;
+ glVertexAttribPointer(i + 8, 3, GL_FLOAT, GL_FALSE, stride, ((uint8_t *)0) + ofs);
+ ofs += 3 * 4;
} break;
case VS::ARRAY_TANGENT: {
- glVertexAttribPointer(i+8,4,GL_FLOAT,GL_FALSE,stride,((uint8_t*)0)+ofs);
- ofs+=4*4;
+ glVertexAttribPointer(i + 8, 4, GL_FLOAT, GL_FALSE, stride, ((uint8_t *)0) + ofs);
+ ofs += 4 * 4;
} break;
case VS::ARRAY_COLOR: {
- glVertexAttribPointer(i+8,4,GL_FLOAT,GL_FALSE,stride,((uint8_t*)0)+ofs);
- ofs+=4*4;
+ glVertexAttribPointer(i + 8, 4, GL_FLOAT, GL_FALSE, stride, ((uint8_t *)0) + ofs);
+ ofs += 4 * 4;
} break;
case VS::ARRAY_TEX_UV: {
- glVertexAttribPointer(i+8,2,GL_FLOAT,GL_FALSE,stride,((uint8_t*)0)+ofs);
- ofs+=2*4;
+ glVertexAttribPointer(i + 8, 2, GL_FLOAT, GL_FALSE, stride, ((uint8_t *)0) + ofs);
+ ofs += 2 * 4;
} break;
case VS::ARRAY_TEX_UV2: {
- glVertexAttribPointer(i+8,2,GL_FLOAT,GL_FALSE,stride,((uint8_t*)0)+ofs);
- ofs+=2*4;
+ glVertexAttribPointer(i + 8, 2, GL_FLOAT, GL_FALSE, stride, ((uint8_t *)0) + ofs);
+ ofs += 2 * 4;
} break;
case VS::ARRAY_BONES: {
- glVertexAttribIPointer(i+8,4,GL_UNSIGNED_INT,stride,((uint8_t*)0)+ofs);
- ofs+=4*4;
+ glVertexAttribIPointer(i + 8, 4, GL_UNSIGNED_INT, stride, ((uint8_t *)0) + ofs);
+ ofs += 4 * 4;
} break;
case VS::ARRAY_WEIGHTS: {
- glVertexAttribPointer(i+8,4,GL_FLOAT,GL_FALSE,stride,((uint8_t*)0)+ofs);
- ofs+=4*4;
+ glVertexAttribPointer(i + 8, 4, GL_FLOAT, GL_FALSE, stride, ((uint8_t *)0) + ofs);
+ ofs += 4 * 4;
} break;
}
} else {
- glDisableVertexAttribArray(i+8);
+ glDisableVertexAttribArray(i + 8);
}
}
glBeginTransformFeedback(GL_POINTS);
- glDrawArrays(GL_POINTS,0,s->array_len);
+ glDrawArrays(GL_POINTS, 0, s->array_len);
glEndTransformFeedback();
-
- SWAP(resources.transform_feedback_buffers[0],resources.transform_feedback_buffers[1]);
-
+ SWAP(resources.transform_feedback_buffers[0], resources.transform_feedback_buffers[1]);
}
glDisable(GL_RASTERIZER_DISCARD);
glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, 0);
-
glBindVertexArray(resources.transform_feedback_array);
glBindBuffer(GL_ARRAY_BUFFER, resources.transform_feedback_buffers[0]);
- int ofs=0;
- for(int i=0;i<VS::ARRAY_MAX-1;i++) {
+ int ofs = 0;
+ for (int i = 0; i < VS::ARRAY_MAX - 1; i++) {
- if (s->format&(1<<i)) {
+ if (s->format & (1 << i)) {
glEnableVertexAttribArray(i);
- switch(i) {
+ switch (i) {
case VS::ARRAY_VERTEX: {
- if (s->format&VS::ARRAY_FLAG_USE_2D_VERTICES) {
- glVertexAttribPointer(i,2,GL_FLOAT,GL_FALSE,stride,((uint8_t*)0)+ofs);
- ofs+=2*4;
+ if (s->format & VS::ARRAY_FLAG_USE_2D_VERTICES) {
+ glVertexAttribPointer(i, 2, GL_FLOAT, GL_FALSE, stride, ((uint8_t *)0) + ofs);
+ ofs += 2 * 4;
} else {
- glVertexAttribPointer(i,3,GL_FLOAT,GL_FALSE,stride,((uint8_t*)0)+ofs);
- ofs+=3*4;
+ glVertexAttribPointer(i, 3, GL_FLOAT, GL_FALSE, stride, ((uint8_t *)0) + ofs);
+ ofs += 3 * 4;
}
} break;
case VS::ARRAY_NORMAL: {
- glVertexAttribPointer(i,3,GL_FLOAT,GL_FALSE,stride,((uint8_t*)0)+ofs);
- ofs+=3*4;
+ glVertexAttribPointer(i, 3, GL_FLOAT, GL_FALSE, stride, ((uint8_t *)0) + ofs);
+ ofs += 3 * 4;
} break;
case VS::ARRAY_TANGENT: {
- glVertexAttribPointer(i,4,GL_FLOAT,GL_FALSE,stride,((uint8_t*)0)+ofs);
- ofs+=4*4;
+ glVertexAttribPointer(i, 4, GL_FLOAT, GL_FALSE, stride, ((uint8_t *)0) + ofs);
+ ofs += 4 * 4;
} break;
case VS::ARRAY_COLOR: {
- glVertexAttribPointer(i,4,GL_FLOAT,GL_FALSE,stride,((uint8_t*)0)+ofs);
- ofs+=4*4;
+ glVertexAttribPointer(i, 4, GL_FLOAT, GL_FALSE, stride, ((uint8_t *)0) + ofs);
+ ofs += 4 * 4;
} break;
case VS::ARRAY_TEX_UV: {
- glVertexAttribPointer(i,2,GL_FLOAT,GL_FALSE,stride,((uint8_t*)0)+ofs);
- ofs+=2*4;
+ glVertexAttribPointer(i, 2, GL_FLOAT, GL_FALSE, stride, ((uint8_t *)0) + ofs);
+ ofs += 2 * 4;
} break;
case VS::ARRAY_TEX_UV2: {
- glVertexAttribPointer(i,2,GL_FLOAT,GL_FALSE,stride,((uint8_t*)0)+ofs);
- ofs+=2*4;
+ glVertexAttribPointer(i, 2, GL_FLOAT, GL_FALSE, stride, ((uint8_t *)0) + ofs);
+ ofs += 2 * 4;
} break;
case VS::ARRAY_BONES: {
- glVertexAttribIPointer(i,4,GL_UNSIGNED_INT,stride,((uint8_t*)0)+ofs);
- ofs+=4*4;
+ glVertexAttribIPointer(i, 4, GL_UNSIGNED_INT, stride, ((uint8_t *)0) + ofs);
+ ofs += 4 * 4;
} break;
case VS::ARRAY_WEIGHTS: {
- glVertexAttribPointer(i,4,GL_FLOAT,GL_FALSE,stride,((uint8_t*)0)+ofs);
- ofs+=4*4;
+ glVertexAttribPointer(i, 4, GL_FLOAT, GL_FALSE, stride, ((uint8_t *)0) + ofs);
+ ofs += 4 * 4;
} break;
}
@@ -3530,131 +3340,126 @@ void RasterizerStorageGLES3::mesh_render_blend_shapes(Surface *s, float *p_weigh
}
if (s->index_array_len) {
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,s->index_id);
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, s->index_id);
}
-
}
/* MULTIMESH API */
+RID RasterizerStorageGLES3::multimesh_create() {
-RID RasterizerStorageGLES3::multimesh_create(){
-
- MultiMesh *multimesh = memnew( MultiMesh );
+ MultiMesh *multimesh = memnew(MultiMesh);
return multimesh_owner.make_rid(multimesh);
}
-void RasterizerStorageGLES3::multimesh_allocate(RID p_multimesh, int p_instances, VS::MultimeshTransformFormat p_transform_format, VS::MultimeshColorFormat p_color_format){
+void RasterizerStorageGLES3::multimesh_allocate(RID p_multimesh, int p_instances, VS::MultimeshTransformFormat p_transform_format, VS::MultimeshColorFormat p_color_format) {
MultiMesh *multimesh = multimesh_owner.getornull(p_multimesh);
ERR_FAIL_COND(!multimesh);
- if (multimesh->size==p_instances && multimesh->transform_format==p_transform_format && multimesh->color_format==p_color_format)
+ if (multimesh->size == p_instances && multimesh->transform_format == p_transform_format && multimesh->color_format == p_color_format)
return;
if (multimesh->buffer) {
- glDeleteBuffers(1,&multimesh->buffer);
+ glDeleteBuffers(1, &multimesh->buffer);
multimesh->data.resize(0);
}
- multimesh->size=p_instances;
- multimesh->transform_format=p_transform_format;
- multimesh->color_format=p_color_format;
+ multimesh->size = p_instances;
+ multimesh->transform_format = p_transform_format;
+ multimesh->color_format = p_color_format;
if (multimesh->size) {
- if (multimesh->transform_format==VS::MULTIMESH_TRANSFORM_2D) {
- multimesh->xform_floats=8;
+ if (multimesh->transform_format == VS::MULTIMESH_TRANSFORM_2D) {
+ multimesh->xform_floats = 8;
} else {
- multimesh->xform_floats=12;
-
+ multimesh->xform_floats = 12;
}
- if (multimesh->color_format==VS::MULTIMESH_COLOR_NONE) {
- multimesh->color_floats=0;
- } else if (multimesh->color_format==VS::MULTIMESH_COLOR_8BIT) {
- multimesh->color_floats=1;
- } else if (multimesh->color_format==VS::MULTIMESH_COLOR_FLOAT) {
- multimesh->color_floats=4;
+ if (multimesh->color_format == VS::MULTIMESH_COLOR_NONE) {
+ multimesh->color_floats = 0;
+ } else if (multimesh->color_format == VS::MULTIMESH_COLOR_8BIT) {
+ multimesh->color_floats = 1;
+ } else if (multimesh->color_format == VS::MULTIMESH_COLOR_FLOAT) {
+ multimesh->color_floats = 4;
}
- int format_floats = multimesh->color_floats+multimesh->xform_floats;
- multimesh->data.resize(format_floats*p_instances);
- for(int i=0;i<p_instances;i+=format_floats) {
-
- int color_from=0;
-
- if (multimesh->transform_format==VS::MULTIMESH_TRANSFORM_2D) {
- multimesh->data[i+0]=1.0;
- multimesh->data[i+1]=0.0;
- multimesh->data[i+2]=0.0;
- multimesh->data[i+3]=0.0;
- multimesh->data[i+4]=0.0;
- multimesh->data[i+5]=1.0;
- multimesh->data[i+6]=0.0;
- multimesh->data[i+7]=0.0;
- color_from=8;
+ int format_floats = multimesh->color_floats + multimesh->xform_floats;
+ multimesh->data.resize(format_floats * p_instances);
+ for (int i = 0; i < p_instances; i += format_floats) {
+
+ int color_from = 0;
+
+ if (multimesh->transform_format == VS::MULTIMESH_TRANSFORM_2D) {
+ multimesh->data[i + 0] = 1.0;
+ multimesh->data[i + 1] = 0.0;
+ multimesh->data[i + 2] = 0.0;
+ multimesh->data[i + 3] = 0.0;
+ multimesh->data[i + 4] = 0.0;
+ multimesh->data[i + 5] = 1.0;
+ multimesh->data[i + 6] = 0.0;
+ multimesh->data[i + 7] = 0.0;
+ color_from = 8;
} else {
- multimesh->data[i+0]=1.0;
- multimesh->data[i+1]=0.0;
- multimesh->data[i+2]=0.0;
- multimesh->data[i+3]=0.0;
- multimesh->data[i+4]=0.0;
- multimesh->data[i+5]=1.0;
- multimesh->data[i+6]=0.0;
- multimesh->data[i+7]=0.0;
- multimesh->data[i+8]=0.0;
- multimesh->data[i+9]=0.0;
- multimesh->data[i+10]=1.0;
- multimesh->data[i+11]=0.0;
- color_from=12;
+ multimesh->data[i + 0] = 1.0;
+ multimesh->data[i + 1] = 0.0;
+ multimesh->data[i + 2] = 0.0;
+ multimesh->data[i + 3] = 0.0;
+ multimesh->data[i + 4] = 0.0;
+ multimesh->data[i + 5] = 1.0;
+ multimesh->data[i + 6] = 0.0;
+ multimesh->data[i + 7] = 0.0;
+ multimesh->data[i + 8] = 0.0;
+ multimesh->data[i + 9] = 0.0;
+ multimesh->data[i + 10] = 1.0;
+ multimesh->data[i + 11] = 0.0;
+ color_from = 12;
}
- if (multimesh->color_format==VS::MULTIMESH_COLOR_NONE) {
+ if (multimesh->color_format == VS::MULTIMESH_COLOR_NONE) {
//none
- } else if (multimesh->color_format==VS::MULTIMESH_COLOR_8BIT) {
+ } else if (multimesh->color_format == VS::MULTIMESH_COLOR_8BIT) {
union {
uint32_t colu;
float colf;
} cu;
- cu.colu=0xFFFFFFFF;
- multimesh->data[i+color_from+0]=cu.colf;
+ cu.colu = 0xFFFFFFFF;
+ multimesh->data[i + color_from + 0] = cu.colf;
- } else if (multimesh->color_format==VS::MULTIMESH_COLOR_FLOAT) {
- multimesh->data[i+color_from+0]=1.0;
- multimesh->data[i+color_from+1]=1.0;
- multimesh->data[i+color_from+2]=1.0;
- multimesh->data[i+color_from+3]=1.0;
+ } else if (multimesh->color_format == VS::MULTIMESH_COLOR_FLOAT) {
+ multimesh->data[i + color_from + 0] = 1.0;
+ multimesh->data[i + color_from + 1] = 1.0;
+ multimesh->data[i + color_from + 2] = 1.0;
+ multimesh->data[i + color_from + 3] = 1.0;
}
}
- glGenBuffers(1,&multimesh->buffer);
- glBindBuffer(GL_ARRAY_BUFFER,multimesh->buffer);
- glBufferData(GL_ARRAY_BUFFER,multimesh->data.size()*sizeof(float),NULL,GL_DYNAMIC_DRAW);
- glBindBuffer(GL_ARRAY_BUFFER,0);
-
+ glGenBuffers(1, &multimesh->buffer);
+ glBindBuffer(GL_ARRAY_BUFFER, multimesh->buffer);
+ glBufferData(GL_ARRAY_BUFFER, multimesh->data.size() * sizeof(float), NULL, GL_DYNAMIC_DRAW);
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
}
- multimesh->dirty_data=true;
- multimesh->dirty_aabb=true;
+ multimesh->dirty_data = true;
+ multimesh->dirty_aabb = true;
if (!multimesh->update_list.in_list()) {
multimesh_update_list.add(&multimesh->update_list);
}
-
}
-int RasterizerStorageGLES3::multimesh_get_instance_count(RID p_multimesh) const{
+int RasterizerStorageGLES3::multimesh_get_instance_count(RID p_multimesh) const {
MultiMesh *multimesh = multimesh_owner.getornull(p_multimesh);
- ERR_FAIL_COND_V(!multimesh,0);
+ ERR_FAIL_COND_V(!multimesh, 0);
return multimesh->size;
}
-void RasterizerStorageGLES3::multimesh_set_mesh(RID p_multimesh,RID p_mesh){
+void RasterizerStorageGLES3::multimesh_set_mesh(RID p_multimesh, RID p_mesh) {
MultiMesh *multimesh = multimesh_owner.getornull(p_multimesh);
ERR_FAIL_COND(!multimesh);
@@ -3666,8 +3471,7 @@ void RasterizerStorageGLES3::multimesh_set_mesh(RID p_multimesh,RID p_mesh){
}
}
- multimesh->mesh=p_mesh;
-
+ multimesh->mesh = p_mesh;
if (multimesh->mesh.is_valid()) {
Mesh *mesh = mesh_owner.getornull(multimesh->mesh);
@@ -3676,173 +3480,171 @@ void RasterizerStorageGLES3::multimesh_set_mesh(RID p_multimesh,RID p_mesh){
}
}
- multimesh->dirty_aabb=true;
+ multimesh->dirty_aabb = true;
if (!multimesh->update_list.in_list()) {
multimesh_update_list.add(&multimesh->update_list);
}
}
-void RasterizerStorageGLES3::multimesh_instance_set_transform(RID p_multimesh,int p_index,const Transform& p_transform){
+void RasterizerStorageGLES3::multimesh_instance_set_transform(RID p_multimesh, int p_index, const Transform &p_transform) {
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);
-
- int stride = multimesh->color_floats+multimesh->xform_floats;
- float *dataptr=&multimesh->data[stride*p_index];
-
- dataptr[ 0]=p_transform.basis.elements[0][0];
- dataptr[ 1]=p_transform.basis.elements[0][1];
- dataptr[ 2]=p_transform.basis.elements[0][2];
- dataptr[ 3]=p_transform.origin.x;
- dataptr[ 4]=p_transform.basis.elements[1][0];
- dataptr[ 5]=p_transform.basis.elements[1][1];
- dataptr[ 6]=p_transform.basis.elements[1][2];
- dataptr[ 7]=p_transform.origin.y;
- dataptr[ 8]=p_transform.basis.elements[2][0];
- dataptr[ 9]=p_transform.basis.elements[2][1];
- dataptr[10]=p_transform.basis.elements[2][2];
- dataptr[11]=p_transform.origin.z;
-
- multimesh->dirty_data=true;
- multimesh->dirty_aabb=true;
+ ERR_FAIL_INDEX(p_index, multimesh->size);
+ ERR_FAIL_COND(multimesh->transform_format == VS::MULTIMESH_TRANSFORM_2D);
+
+ int stride = multimesh->color_floats + multimesh->xform_floats;
+ float *dataptr = &multimesh->data[stride * p_index];
+
+ dataptr[0] = p_transform.basis.elements[0][0];
+ dataptr[1] = p_transform.basis.elements[0][1];
+ dataptr[2] = p_transform.basis.elements[0][2];
+ dataptr[3] = p_transform.origin.x;
+ dataptr[4] = p_transform.basis.elements[1][0];
+ dataptr[5] = p_transform.basis.elements[1][1];
+ dataptr[6] = p_transform.basis.elements[1][2];
+ dataptr[7] = p_transform.origin.y;
+ dataptr[8] = p_transform.basis.elements[2][0];
+ dataptr[9] = p_transform.basis.elements[2][1];
+ dataptr[10] = p_transform.basis.elements[2][2];
+ dataptr[11] = p_transform.origin.z;
+
+ multimesh->dirty_data = true;
+ multimesh->dirty_aabb = true;
if (!multimesh->update_list.in_list()) {
multimesh_update_list.add(&multimesh->update_list);
}
}
-void RasterizerStorageGLES3::multimesh_instance_set_transform_2d(RID p_multimesh,int p_index,const Transform2D& p_transform){
+void RasterizerStorageGLES3::multimesh_instance_set_transform_2d(RID p_multimesh, int p_index, const Transform2D &p_transform) {
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_INDEX(p_index, multimesh->size);
+ ERR_FAIL_COND(multimesh->transform_format == VS::MULTIMESH_TRANSFORM_3D);
- int stride = multimesh->color_floats+multimesh->xform_floats;
- float *dataptr=&multimesh->data[stride*p_index];
+ int stride = multimesh->color_floats + multimesh->xform_floats;
+ float *dataptr = &multimesh->data[stride * p_index];
- dataptr[ 0]=p_transform.elements[0][0];
- dataptr[ 1]=p_transform.elements[1][0];
- dataptr[ 2]=0;
- dataptr[ 3]=p_transform.elements[2][0];
- dataptr[ 4]=p_transform.elements[0][1];
- dataptr[ 5]=p_transform.elements[1][1];
- dataptr[ 6]=0;
- dataptr[ 7]=p_transform.elements[2][1];
+ dataptr[0] = p_transform.elements[0][0];
+ dataptr[1] = p_transform.elements[1][0];
+ dataptr[2] = 0;
+ dataptr[3] = p_transform.elements[2][0];
+ dataptr[4] = p_transform.elements[0][1];
+ dataptr[5] = p_transform.elements[1][1];
+ dataptr[6] = 0;
+ dataptr[7] = p_transform.elements[2][1];
- multimesh->dirty_data=true;
- multimesh->dirty_aabb=true;
+ multimesh->dirty_data = true;
+ multimesh->dirty_aabb = true;
if (!multimesh->update_list.in_list()) {
multimesh_update_list.add(&multimesh->update_list);
}
}
-void RasterizerStorageGLES3::multimesh_instance_set_color(RID p_multimesh,int p_index,const Color& p_color){
+void RasterizerStorageGLES3::multimesh_instance_set_color(RID p_multimesh, int p_index, const Color &p_color) {
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(p_index, multimesh->size);
+ ERR_FAIL_COND(multimesh->color_format == VS::MULTIMESH_COLOR_NONE);
- int stride = multimesh->color_floats+multimesh->xform_floats;
- float *dataptr=&multimesh->data[stride*p_index+multimesh->xform_floats];
+ int stride = multimesh->color_floats + multimesh->xform_floats;
+ float *dataptr = &multimesh->data[stride * p_index + multimesh->xform_floats];
- if (multimesh->color_format==VS::MULTIMESH_COLOR_8BIT) {
+ if (multimesh->color_format == VS::MULTIMESH_COLOR_8BIT) {
- uint8_t *data8=(uint8_t*)dataptr;
- data8[0]=CLAMP(p_color.r*255.0,0,255);
- data8[1]=CLAMP(p_color.g*255.0,0,255);
- data8[2]=CLAMP(p_color.b*255.0,0,255);
- data8[3]=CLAMP(p_color.a*255.0,0,255);
+ uint8_t *data8 = (uint8_t *)dataptr;
+ data8[0] = CLAMP(p_color.r * 255.0, 0, 255);
+ data8[1] = CLAMP(p_color.g * 255.0, 0, 255);
+ 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) {
- dataptr[ 0]=p_color.r;
- dataptr[ 1]=p_color.g;
- dataptr[ 2]=p_color.b;
- dataptr[ 3]=p_color.a;
+ } else if (multimesh->color_format == VS::MULTIMESH_COLOR_FLOAT) {
+ dataptr[0] = p_color.r;
+ dataptr[1] = p_color.g;
+ dataptr[2] = p_color.b;
+ dataptr[3] = p_color.a;
}
-
- multimesh->dirty_data=true;
- multimesh->dirty_aabb=true;
+ multimesh->dirty_data = true;
+ multimesh->dirty_aabb = true;
if (!multimesh->update_list.in_list()) {
multimesh_update_list.add(&multimesh->update_list);
}
}
-RID RasterizerStorageGLES3::multimesh_get_mesh(RID p_multimesh) const{
+RID RasterizerStorageGLES3::multimesh_get_mesh(RID p_multimesh) const {
MultiMesh *multimesh = multimesh_owner.getornull(p_multimesh);
- ERR_FAIL_COND_V(!multimesh,RID());
+ ERR_FAIL_COND_V(!multimesh, RID());
return multimesh->mesh;
}
-
-Transform RasterizerStorageGLES3::multimesh_instance_get_transform(RID p_multimesh,int p_index) const{
+Transform RasterizerStorageGLES3::multimesh_instance_get_transform(RID p_multimesh, int p_index) const {
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());
+ ERR_FAIL_INDEX_V(p_index, multimesh->size, Transform());
+ ERR_FAIL_COND_V(multimesh->transform_format == VS::MULTIMESH_TRANSFORM_2D, Transform());
- int stride = multimesh->color_floats+multimesh->xform_floats;
- float *dataptr=&multimesh->data[stride*p_index];
+ int stride = multimesh->color_floats + multimesh->xform_floats;
+ float *dataptr = &multimesh->data[stride * p_index];
Transform xform;
- xform.basis.elements[0][0]=dataptr[ 0];
- xform.basis.elements[0][1]=dataptr[ 1];
- xform.basis.elements[0][2]=dataptr[ 2];
- xform.origin.x=dataptr[ 3];
- xform.basis.elements[1][0]=dataptr[ 4];
- xform.basis.elements[1][1]=dataptr[ 5];
- xform.basis.elements[1][2]=dataptr[ 6];
- xform.origin.y=dataptr[ 7];
- xform.basis.elements[2][0]=dataptr[ 8];
- xform.basis.elements[2][1]=dataptr[ 9];
- xform.basis.elements[2][2]=dataptr[10];
- xform.origin.z=dataptr[11];
+ xform.basis.elements[0][0] = dataptr[0];
+ xform.basis.elements[0][1] = dataptr[1];
+ xform.basis.elements[0][2] = dataptr[2];
+ xform.origin.x = dataptr[3];
+ xform.basis.elements[1][0] = dataptr[4];
+ xform.basis.elements[1][1] = dataptr[5];
+ xform.basis.elements[1][2] = dataptr[6];
+ xform.origin.y = dataptr[7];
+ xform.basis.elements[2][0] = dataptr[8];
+ xform.basis.elements[2][1] = dataptr[9];
+ xform.basis.elements[2][2] = dataptr[10];
+ xform.origin.z = dataptr[11];
return xform;
}
-Transform2D RasterizerStorageGLES3::multimesh_instance_get_transform_2d(RID p_multimesh,int p_index) const{
+Transform2D RasterizerStorageGLES3::multimesh_instance_get_transform_2d(RID p_multimesh, int p_index) const {
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, Transform2D());
+ ERR_FAIL_INDEX_V(p_index, multimesh->size, Transform2D());
+ ERR_FAIL_COND_V(multimesh->transform_format == VS::MULTIMESH_TRANSFORM_3D, Transform2D());
- int stride = multimesh->color_floats+multimesh->xform_floats;
- float *dataptr=&multimesh->data[stride*p_index];
+ int stride = multimesh->color_floats + multimesh->xform_floats;
+ float *dataptr = &multimesh->data[stride * p_index];
Transform2D xform;
- xform.elements[0][0]=dataptr[ 0];
- xform.elements[1][0]=dataptr[ 1];
- xform.elements[2][0]=dataptr[ 3];
- xform.elements[0][1]=dataptr[ 4];
- xform.elements[1][1]=dataptr[ 5];
- xform.elements[2][1]=dataptr[ 7];
+ xform.elements[0][0] = dataptr[0];
+ xform.elements[1][0] = dataptr[1];
+ xform.elements[2][0] = dataptr[3];
+ xform.elements[0][1] = dataptr[4];
+ xform.elements[1][1] = dataptr[5];
+ xform.elements[2][1] = dataptr[7];
return xform;
}
-Color RasterizerStorageGLES3::multimesh_instance_get_color(RID p_multimesh,int p_index) const{
+Color RasterizerStorageGLES3::multimesh_instance_get_color(RID p_multimesh, int p_index) const {
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_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());
- int stride = multimesh->color_floats+multimesh->xform_floats;
- float *dataptr=&multimesh->data[stride*p_index+multimesh->color_floats];
+ int stride = multimesh->color_floats + multimesh->xform_floats;
+ float *dataptr = &multimesh->data[stride * p_index + multimesh->color_floats];
- if (multimesh->color_format==VS::MULTIMESH_COLOR_8BIT) {
+ if (multimesh->color_format == VS::MULTIMESH_COLOR_8BIT) {
union {
uint32_t colu;
float colf;
@@ -3850,130 +3652,124 @@ Color RasterizerStorageGLES3::multimesh_instance_get_color(RID p_multimesh,int p
return Color::hex(BSWAP32(cu.colu));
- } else if (multimesh->color_format==VS::MULTIMESH_COLOR_FLOAT) {
+ } else if (multimesh->color_format == VS::MULTIMESH_COLOR_FLOAT) {
Color c;
- c.r=dataptr[ 0];
- c.g=dataptr[ 1];
- c.b=dataptr[ 2];
- c.a=dataptr[ 3];
+ c.r = dataptr[0];
+ c.g = dataptr[1];
+ c.b = dataptr[2];
+ c.a = dataptr[3];
return c;
}
return Color();
-
}
-void RasterizerStorageGLES3::multimesh_set_visible_instances(RID p_multimesh,int p_visible){
+void RasterizerStorageGLES3::multimesh_set_visible_instances(RID p_multimesh, int p_visible) {
MultiMesh *multimesh = multimesh_owner.getornull(p_multimesh);
ERR_FAIL_COND(!multimesh);
- multimesh->visible_instances=p_visible;
+ multimesh->visible_instances = p_visible;
}
-int RasterizerStorageGLES3::multimesh_get_visible_instances(RID p_multimesh) const{
+int RasterizerStorageGLES3::multimesh_get_visible_instances(RID p_multimesh) const {
MultiMesh *multimesh = multimesh_owner.getornull(p_multimesh);
- ERR_FAIL_COND_V(!multimesh,-1);
+ ERR_FAIL_COND_V(!multimesh, -1);
return multimesh->visible_instances;
}
-Rect3 RasterizerStorageGLES3::multimesh_get_aabb(RID p_multimesh) const{
+Rect3 RasterizerStorageGLES3::multimesh_get_aabb(RID p_multimesh) const {
MultiMesh *multimesh = multimesh_owner.getornull(p_multimesh);
- ERR_FAIL_COND_V(!multimesh,Rect3());
+ ERR_FAIL_COND_V(!multimesh, Rect3());
- const_cast<RasterizerStorageGLES3*>(this)->update_dirty_multimeshes(); //update pending AABBs
+ const_cast<RasterizerStorageGLES3 *>(this)->update_dirty_multimeshes(); //update pending AABBs
return multimesh->aabb;
}
void RasterizerStorageGLES3::update_dirty_multimeshes() {
- while(multimesh_update_list.first()) {
+ while (multimesh_update_list.first()) {
MultiMesh *multimesh = multimesh_update_list.first()->self();
if (multimesh->size && multimesh->dirty_data) {
-
- glBindBuffer(GL_ARRAY_BUFFER,multimesh->buffer);
- glBufferSubData(GL_ARRAY_BUFFER,0,multimesh->data.size()*sizeof(float),multimesh->data.ptr());
- glBindBuffer(GL_ARRAY_BUFFER,0);
-
-
+ glBindBuffer(GL_ARRAY_BUFFER, multimesh->buffer);
+ glBufferSubData(GL_ARRAY_BUFFER, 0, multimesh->data.size() * sizeof(float), multimesh->data.ptr());
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
}
-
-
if (multimesh->size && multimesh->dirty_aabb) {
Rect3 mesh_aabb;
if (multimesh->mesh.is_valid()) {
- mesh_aabb=mesh_get_aabb(multimesh->mesh,RID());
+ mesh_aabb = mesh_get_aabb(multimesh->mesh, RID());
} else {
- mesh_aabb.size+=Vector3(0.001,0.001,0.001);
+ mesh_aabb.size += Vector3(0.001, 0.001, 0.001);
}
- int stride=multimesh->color_floats+multimesh->xform_floats;
+ int stride = multimesh->color_floats + multimesh->xform_floats;
int count = multimesh->data.size();
- float *data=multimesh->data.ptr();
+ float *data = multimesh->data.ptr();
Rect3 aabb;
- if (multimesh->transform_format==VS::MULTIMESH_TRANSFORM_2D) {
+ if (multimesh->transform_format == VS::MULTIMESH_TRANSFORM_2D) {
- for(int i=0;i<count;i+=stride) {
+ for (int i = 0; i < count; i += stride) {
- float *dataptr=&data[i];
+ float *dataptr = &data[i];
Transform xform;
- xform.basis[0][0]=dataptr[ 0];
- xform.basis[0][1]=dataptr[ 1];
- xform.origin[0]=dataptr[ 3];
- xform.basis[1][0]=dataptr[ 4];
- xform.basis[1][1]=dataptr[ 5];
- xform.origin[1]=dataptr[ 7];
+ xform.basis[0][0] = dataptr[0];
+ xform.basis[0][1] = dataptr[1];
+ xform.origin[0] = dataptr[3];
+ xform.basis[1][0] = dataptr[4];
+ xform.basis[1][1] = dataptr[5];
+ xform.origin[1] = dataptr[7];
Rect3 laabb = xform.xform(mesh_aabb);
- if (i==0)
- aabb=laabb;
+ if (i == 0)
+ aabb = laabb;
else
aabb.merge_with(laabb);
}
} else {
- for(int i=0;i<count;i+=stride) {
+ for (int i = 0; i < count; i += stride) {
- float *dataptr=&data[i];
+ float *dataptr = &data[i];
Transform xform;
- xform.basis.elements[0][0]=dataptr[ 0];
- xform.basis.elements[0][1]=dataptr[ 1];
- xform.basis.elements[0][2]=dataptr[ 2];
- xform.origin.x=dataptr[ 3];
- xform.basis.elements[1][0]=dataptr[ 4];
- xform.basis.elements[1][1]=dataptr[ 5];
- xform.basis.elements[1][2]=dataptr[ 6];
- xform.origin.y=dataptr[ 7];
- xform.basis.elements[2][0]=dataptr[ 8];
- xform.basis.elements[2][1]=dataptr[ 9];
- xform.basis.elements[2][2]=dataptr[10];
- xform.origin.z=dataptr[11];
+ xform.basis.elements[0][0] = dataptr[0];
+ xform.basis.elements[0][1] = dataptr[1];
+ xform.basis.elements[0][2] = dataptr[2];
+ xform.origin.x = dataptr[3];
+ xform.basis.elements[1][0] = dataptr[4];
+ xform.basis.elements[1][1] = dataptr[5];
+ xform.basis.elements[1][2] = dataptr[6];
+ xform.origin.y = dataptr[7];
+ xform.basis.elements[2][0] = dataptr[8];
+ xform.basis.elements[2][1] = dataptr[9];
+ xform.basis.elements[2][2] = dataptr[10];
+ xform.origin.z = dataptr[11];
Rect3 laabb = xform.xform(mesh_aabb);
- if (i==0)
- aabb=laabb;
+ if (i == 0)
+ aabb = laabb;
else
aabb.merge_with(laabb);
}
}
- multimesh->aabb=aabb;
+ multimesh->aabb = aabb;
}
- multimesh->dirty_aabb=false;
- multimesh->dirty_data=false;
+ multimesh->dirty_aabb = false;
+ multimesh->dirty_data = false;
multimesh->instance_change_notify();
@@ -3983,30 +3779,26 @@ void RasterizerStorageGLES3::update_dirty_multimeshes() {
/* IMMEDIATE API */
-
RID RasterizerStorageGLES3::immediate_create() {
- Immediate *im = memnew( Immediate );
+ Immediate *im = memnew(Immediate);
return immediate_owner.make_rid(im);
-
}
-void RasterizerStorageGLES3::immediate_begin(RID p_immediate, VS::PrimitiveType p_rimitive, RID p_texture){
+void RasterizerStorageGLES3::immediate_begin(RID p_immediate, VS::PrimitiveType p_rimitive, RID p_texture) {
Immediate *im = immediate_owner.get(p_immediate);
ERR_FAIL_COND(!im);
ERR_FAIL_COND(im->building);
Immediate::Chunk ic;
- ic.texture=p_texture;
- ic.primitive=p_rimitive;
+ ic.texture = p_texture;
+ ic.primitive = p_rimitive;
im->chunks.push_back(ic);
- im->mask=0;
- im->building=true;
-
-
+ im->mask = 0;
+ im->building = true;
}
-void RasterizerStorageGLES3::immediate_vertex(RID p_immediate,const Vector3& p_vertex){
+void RasterizerStorageGLES3::immediate_vertex(RID p_immediate, const Vector3 &p_vertex) {
Immediate *im = immediate_owner.get(p_immediate);
ERR_FAIL_COND(!im);
@@ -4014,92 +3806,83 @@ void RasterizerStorageGLES3::immediate_vertex(RID p_immediate,const Vector3& p_v
Immediate::Chunk *c = &im->chunks.back()->get();
+ if (c->vertices.empty() && im->chunks.size() == 1) {
- if (c->vertices.empty() && im->chunks.size()==1) {
-
- im->aabb.pos=p_vertex;
- im->aabb.size=Vector3();
+ im->aabb.pos = p_vertex;
+ im->aabb.size = Vector3();
} else {
im->aabb.expand_to(p_vertex);
}
- if (im->mask&VS::ARRAY_FORMAT_NORMAL)
+ if (im->mask & VS::ARRAY_FORMAT_NORMAL)
c->normals.push_back(chunk_normal);
- if (im->mask&VS::ARRAY_FORMAT_TANGENT)
+ if (im->mask & VS::ARRAY_FORMAT_TANGENT)
c->tangents.push_back(chunk_tangent);
- if (im->mask&VS::ARRAY_FORMAT_COLOR)
+ if (im->mask & VS::ARRAY_FORMAT_COLOR)
c->colors.push_back(chunk_color);
- if (im->mask&VS::ARRAY_FORMAT_TEX_UV)
+ if (im->mask & VS::ARRAY_FORMAT_TEX_UV)
c->uvs.push_back(chunk_uv);
- if (im->mask&VS::ARRAY_FORMAT_TEX_UV2)
+ if (im->mask & VS::ARRAY_FORMAT_TEX_UV2)
c->uvs2.push_back(chunk_uv2);
- im->mask|=VS::ARRAY_FORMAT_VERTEX;
+ im->mask |= VS::ARRAY_FORMAT_VERTEX;
c->vertices.push_back(p_vertex);
-
}
-
-void RasterizerStorageGLES3::immediate_normal(RID p_immediate,const Vector3& p_normal){
+void RasterizerStorageGLES3::immediate_normal(RID p_immediate, const Vector3 &p_normal) {
Immediate *im = immediate_owner.get(p_immediate);
ERR_FAIL_COND(!im);
ERR_FAIL_COND(!im->building);
- im->mask|=VS::ARRAY_FORMAT_NORMAL;
- chunk_normal=p_normal;
-
+ im->mask |= VS::ARRAY_FORMAT_NORMAL;
+ chunk_normal = p_normal;
}
-void RasterizerStorageGLES3::immediate_tangent(RID p_immediate,const Plane& p_tangent){
+void RasterizerStorageGLES3::immediate_tangent(RID p_immediate, const Plane &p_tangent) {
Immediate *im = immediate_owner.get(p_immediate);
ERR_FAIL_COND(!im);
ERR_FAIL_COND(!im->building);
- im->mask|=VS::ARRAY_FORMAT_TANGENT;
- chunk_tangent=p_tangent;
-
+ im->mask |= VS::ARRAY_FORMAT_TANGENT;
+ chunk_tangent = p_tangent;
}
-void RasterizerStorageGLES3::immediate_color(RID p_immediate,const Color& p_color){
+void RasterizerStorageGLES3::immediate_color(RID p_immediate, const Color &p_color) {
Immediate *im = immediate_owner.get(p_immediate);
ERR_FAIL_COND(!im);
ERR_FAIL_COND(!im->building);
- im->mask|=VS::ARRAY_FORMAT_COLOR;
- chunk_color=p_color;
-
+ im->mask |= VS::ARRAY_FORMAT_COLOR;
+ chunk_color = p_color;
}
-void RasterizerStorageGLES3::immediate_uv(RID p_immediate,const Vector2& tex_uv){
+void RasterizerStorageGLES3::immediate_uv(RID p_immediate, const Vector2 &tex_uv) {
Immediate *im = immediate_owner.get(p_immediate);
ERR_FAIL_COND(!im);
ERR_FAIL_COND(!im->building);
- im->mask|=VS::ARRAY_FORMAT_TEX_UV;
- chunk_uv=tex_uv;
-
+ im->mask |= VS::ARRAY_FORMAT_TEX_UV;
+ chunk_uv = tex_uv;
}
-void RasterizerStorageGLES3::immediate_uv2(RID p_immediate,const Vector2& tex_uv){
+void RasterizerStorageGLES3::immediate_uv2(RID p_immediate, const Vector2 &tex_uv) {
Immediate *im = immediate_owner.get(p_immediate);
ERR_FAIL_COND(!im);
ERR_FAIL_COND(!im->building);
- im->mask|=VS::ARRAY_FORMAT_TEX_UV2;
- chunk_uv2=tex_uv;
-
+ im->mask |= VS::ARRAY_FORMAT_TEX_UV2;
+ chunk_uv2 = tex_uv;
}
-void RasterizerStorageGLES3::immediate_end(RID p_immediate){
+void RasterizerStorageGLES3::immediate_end(RID p_immediate) {
Immediate *im = immediate_owner.get(p_immediate);
ERR_FAIL_COND(!im);
ERR_FAIL_COND(!im->building);
- im->building=false;
+ im->building = false;
im->instance_change_notify();
-
}
void RasterizerStorageGLES3::immediate_clear(RID p_immediate) {
@@ -4109,279 +3892,264 @@ void RasterizerStorageGLES3::immediate_clear(RID p_immediate) {
im->chunks.clear();
im->instance_change_notify();
-
}
Rect3 RasterizerStorageGLES3::immediate_get_aabb(RID p_immediate) const {
Immediate *im = immediate_owner.get(p_immediate);
- ERR_FAIL_COND_V(!im,Rect3());
+ ERR_FAIL_COND_V(!im, Rect3());
return im->aabb;
}
-void RasterizerStorageGLES3::immediate_set_material(RID p_immediate,RID p_material) {
+void RasterizerStorageGLES3::immediate_set_material(RID p_immediate, RID p_material) {
Immediate *im = immediate_owner.get(p_immediate);
ERR_FAIL_COND(!im);
- im->material=p_material;
+ im->material = p_material;
im->instance_material_change_notify();
-
}
RID RasterizerStorageGLES3::immediate_get_material(RID p_immediate) const {
const Immediate *im = immediate_owner.get(p_immediate);
- ERR_FAIL_COND_V(!im,RID());
+ ERR_FAIL_COND_V(!im, RID());
return im->material;
-
}
/* SKELETON API */
-RID RasterizerStorageGLES3::skeleton_create(){
+RID RasterizerStorageGLES3::skeleton_create() {
- Skeleton *skeleton = memnew( Skeleton );
+ Skeleton *skeleton = memnew(Skeleton);
return skeleton_owner.make_rid(skeleton);
}
-void RasterizerStorageGLES3::skeleton_allocate(RID p_skeleton,int p_bones,bool p_2d_skeleton){
+void RasterizerStorageGLES3::skeleton_allocate(RID p_skeleton, int p_bones, bool p_2d_skeleton) {
Skeleton *skeleton = skeleton_owner.getornull(p_skeleton);
ERR_FAIL_COND(!skeleton);
- ERR_FAIL_COND(p_bones<0);
+ ERR_FAIL_COND(p_bones < 0);
- if (skeleton->size==p_bones && skeleton->use_2d==p_2d_skeleton)
+ if (skeleton->size == p_bones && skeleton->use_2d == p_2d_skeleton)
return;
if (skeleton->ubo) {
- glDeleteBuffers(1,&skeleton->ubo);
- skeleton->ubo=0;
+ glDeleteBuffers(1, &skeleton->ubo);
+ skeleton->ubo = 0;
}
- skeleton->size=p_bones;
+ skeleton->size = p_bones;
if (p_2d_skeleton) {
- skeleton->bones.resize(p_bones*8);
- for(int i=0;i<skeleton->bones.size();i+=8) {
- skeleton->bones[i+0]=1;
- skeleton->bones[i+1]=0;
- skeleton->bones[i+2]=0;
- skeleton->bones[i+3]=0;
- skeleton->bones[i+4]=0;
- skeleton->bones[i+5]=1;
- skeleton->bones[i+6]=0;
- skeleton->bones[i+7]=0;
+ skeleton->bones.resize(p_bones * 8);
+ for (int i = 0; i < skeleton->bones.size(); i += 8) {
+ skeleton->bones[i + 0] = 1;
+ skeleton->bones[i + 1] = 0;
+ skeleton->bones[i + 2] = 0;
+ skeleton->bones[i + 3] = 0;
+ skeleton->bones[i + 4] = 0;
+ skeleton->bones[i + 5] = 1;
+ skeleton->bones[i + 6] = 0;
+ skeleton->bones[i + 7] = 0;
}
} else {
- skeleton->bones.resize(p_bones*12);
- for(int i=0;i<skeleton->bones.size();i+=12) {
- skeleton->bones[i+0]=1;
- skeleton->bones[i+1]=0;
- skeleton->bones[i+2]=0;
- skeleton->bones[i+3]=0;
- skeleton->bones[i+4]=0;
- skeleton->bones[i+5]=1;
- skeleton->bones[i+6]=0;
- skeleton->bones[i+7]=0;
- skeleton->bones[i+8]=0;
- skeleton->bones[i+9]=0;
- skeleton->bones[i+10]=1;
- skeleton->bones[i+11]=0;
+ skeleton->bones.resize(p_bones * 12);
+ for (int i = 0; i < skeleton->bones.size(); i += 12) {
+ skeleton->bones[i + 0] = 1;
+ skeleton->bones[i + 1] = 0;
+ skeleton->bones[i + 2] = 0;
+ skeleton->bones[i + 3] = 0;
+ skeleton->bones[i + 4] = 0;
+ skeleton->bones[i + 5] = 1;
+ skeleton->bones[i + 6] = 0;
+ skeleton->bones[i + 7] = 0;
+ skeleton->bones[i + 8] = 0;
+ skeleton->bones[i + 9] = 0;
+ skeleton->bones[i + 10] = 1;
+ skeleton->bones[i + 11] = 0;
}
-
}
-
-
if (p_bones) {
glGenBuffers(1, &skeleton->ubo);
glBindBuffer(GL_UNIFORM_BUFFER, skeleton->ubo);
- glBufferData(GL_UNIFORM_BUFFER, skeleton->bones.size()*sizeof(float), NULL, GL_DYNAMIC_DRAW);
+ glBufferData(GL_UNIFORM_BUFFER, skeleton->bones.size() * sizeof(float), NULL, GL_DYNAMIC_DRAW);
glBindBuffer(GL_UNIFORM_BUFFER, 0);
}
if (!skeleton->update_list.in_list()) {
skeleton_update_list.add(&skeleton->update_list);
}
-
-
-
}
-int RasterizerStorageGLES3::skeleton_get_bone_count(RID p_skeleton) const{
+int RasterizerStorageGLES3::skeleton_get_bone_count(RID p_skeleton) const {
Skeleton *skeleton = skeleton_owner.getornull(p_skeleton);
- ERR_FAIL_COND_V(!skeleton,0);
+ ERR_FAIL_COND_V(!skeleton, 0);
return skeleton->size;
}
-void RasterizerStorageGLES3::skeleton_bone_set_transform(RID p_skeleton,int p_bone, const Transform& p_transform){
+void RasterizerStorageGLES3::skeleton_bone_set_transform(RID p_skeleton, int p_bone, const Transform &p_transform) {
Skeleton *skeleton = skeleton_owner.getornull(p_skeleton);
ERR_FAIL_COND(!skeleton);
- ERR_FAIL_INDEX(p_bone,skeleton->size);
+ ERR_FAIL_INDEX(p_bone, skeleton->size);
ERR_FAIL_COND(skeleton->use_2d);
- float * bones = skeleton->bones.ptr();
- bones[p_bone*12+ 0]=p_transform.basis.elements[0][0];
- bones[p_bone*12+ 1]=p_transform.basis.elements[0][1];
- bones[p_bone*12+ 2]=p_transform.basis.elements[0][2];
- bones[p_bone*12+ 3]=p_transform.origin.x;
- bones[p_bone*12+ 4]=p_transform.basis.elements[1][0];
- bones[p_bone*12+ 5]=p_transform.basis.elements[1][1];
- bones[p_bone*12+ 6]=p_transform.basis.elements[1][2];
- bones[p_bone*12+ 7]=p_transform.origin.y;
- bones[p_bone*12+ 8]=p_transform.basis.elements[2][0];
- bones[p_bone*12+ 9]=p_transform.basis.elements[2][1];
- bones[p_bone*12+10]=p_transform.basis.elements[2][2];
- bones[p_bone*12+11]=p_transform.origin.z;
+ float *bones = skeleton->bones.ptr();
+ bones[p_bone * 12 + 0] = p_transform.basis.elements[0][0];
+ bones[p_bone * 12 + 1] = p_transform.basis.elements[0][1];
+ bones[p_bone * 12 + 2] = p_transform.basis.elements[0][2];
+ bones[p_bone * 12 + 3] = p_transform.origin.x;
+ bones[p_bone * 12 + 4] = p_transform.basis.elements[1][0];
+ bones[p_bone * 12 + 5] = p_transform.basis.elements[1][1];
+ bones[p_bone * 12 + 6] = p_transform.basis.elements[1][2];
+ bones[p_bone * 12 + 7] = p_transform.origin.y;
+ bones[p_bone * 12 + 8] = p_transform.basis.elements[2][0];
+ bones[p_bone * 12 + 9] = p_transform.basis.elements[2][1];
+ bones[p_bone * 12 + 10] = p_transform.basis.elements[2][2];
+ bones[p_bone * 12 + 11] = p_transform.origin.z;
if (!skeleton->update_list.in_list()) {
skeleton_update_list.add(&skeleton->update_list);
}
-
}
-
-Transform RasterizerStorageGLES3::skeleton_bone_get_transform(RID p_skeleton,int p_bone) const{
+Transform RasterizerStorageGLES3::skeleton_bone_get_transform(RID p_skeleton, int p_bone) const {
Skeleton *skeleton = skeleton_owner.getornull(p_skeleton);
- ERR_FAIL_COND_V(!skeleton,Transform());
- ERR_FAIL_INDEX_V(p_bone,skeleton->size,Transform());
- ERR_FAIL_COND_V(skeleton->use_2d,Transform());
+ ERR_FAIL_COND_V(!skeleton, Transform());
+ ERR_FAIL_INDEX_V(p_bone, skeleton->size, Transform());
+ ERR_FAIL_COND_V(skeleton->use_2d, Transform());
- float * bones = skeleton->bones.ptr();
+ float *bones = skeleton->bones.ptr();
Transform mtx;
- mtx.basis.elements[0][0]=bones[p_bone*12+ 0];
- mtx.basis.elements[0][1]=bones[p_bone*12+ 1];
- mtx.basis.elements[0][2]=bones[p_bone*12+ 2];
- mtx.origin.x=bones[p_bone*12+ 3];
- mtx.basis.elements[1][0]=bones[p_bone*12+ 4];
- mtx.basis.elements[1][1]=bones[p_bone*12+ 5];
- mtx.basis.elements[1][2]=bones[p_bone*12+ 6];
- mtx.origin.y=bones[p_bone*12+ 7];
- mtx.basis.elements[2][0]=bones[p_bone*12+ 8];
- mtx.basis.elements[2][1]=bones[p_bone*12+ 9];
- mtx.basis.elements[2][2]=bones[p_bone*12+10];
- mtx.origin.z=bones[p_bone*12+11];
+ mtx.basis.elements[0][0] = bones[p_bone * 12 + 0];
+ mtx.basis.elements[0][1] = bones[p_bone * 12 + 1];
+ mtx.basis.elements[0][2] = bones[p_bone * 12 + 2];
+ mtx.origin.x = bones[p_bone * 12 + 3];
+ mtx.basis.elements[1][0] = bones[p_bone * 12 + 4];
+ mtx.basis.elements[1][1] = bones[p_bone * 12 + 5];
+ mtx.basis.elements[1][2] = bones[p_bone * 12 + 6];
+ mtx.origin.y = bones[p_bone * 12 + 7];
+ mtx.basis.elements[2][0] = bones[p_bone * 12 + 8];
+ mtx.basis.elements[2][1] = bones[p_bone * 12 + 9];
+ mtx.basis.elements[2][2] = bones[p_bone * 12 + 10];
+ mtx.origin.z = bones[p_bone * 12 + 11];
return mtx;
}
-void RasterizerStorageGLES3::skeleton_bone_set_transform_2d(RID p_skeleton,int p_bone, const Transform2D& p_transform){
+void RasterizerStorageGLES3::skeleton_bone_set_transform_2d(RID p_skeleton, int p_bone, const Transform2D &p_transform) {
Skeleton *skeleton = skeleton_owner.getornull(p_skeleton);
ERR_FAIL_COND(!skeleton);
- ERR_FAIL_INDEX(p_bone,skeleton->size);
+ ERR_FAIL_INDEX(p_bone, skeleton->size);
ERR_FAIL_COND(!skeleton->use_2d);
- float * bones = skeleton->bones.ptr();
- bones[p_bone*12+ 0]=p_transform.elements[0][0];
- bones[p_bone*12+ 1]=p_transform.elements[1][0];
- bones[p_bone*12+ 2]=0;
- bones[p_bone*12+ 3]=p_transform.elements[2][0];
- bones[p_bone*12+ 4]=p_transform.elements[0][1];
- bones[p_bone*12+ 5]=p_transform.elements[1][1];
- bones[p_bone*12+ 6]=0;
- bones[p_bone*12+ 7]=p_transform.elements[2][1];
+ float *bones = skeleton->bones.ptr();
+ bones[p_bone * 12 + 0] = p_transform.elements[0][0];
+ bones[p_bone * 12 + 1] = p_transform.elements[1][0];
+ bones[p_bone * 12 + 2] = 0;
+ bones[p_bone * 12 + 3] = p_transform.elements[2][0];
+ bones[p_bone * 12 + 4] = p_transform.elements[0][1];
+ bones[p_bone * 12 + 5] = p_transform.elements[1][1];
+ bones[p_bone * 12 + 6] = 0;
+ bones[p_bone * 12 + 7] = p_transform.elements[2][1];
if (!skeleton->update_list.in_list()) {
skeleton_update_list.add(&skeleton->update_list);
}
-
}
-Transform2D RasterizerStorageGLES3::skeleton_bone_get_transform_2d(RID p_skeleton,int p_bone) const{
+Transform2D RasterizerStorageGLES3::skeleton_bone_get_transform_2d(RID p_skeleton, int p_bone) const {
Skeleton *skeleton = skeleton_owner.getornull(p_skeleton);
-
- ERR_FAIL_COND_V(!skeleton,Transform2D());
- ERR_FAIL_INDEX_V(p_bone,skeleton->size,Transform2D());
- ERR_FAIL_COND_V(!skeleton->use_2d,Transform2D());
+ ERR_FAIL_COND_V(!skeleton, Transform2D());
+ ERR_FAIL_INDEX_V(p_bone, skeleton->size, Transform2D());
+ ERR_FAIL_COND_V(!skeleton->use_2d, Transform2D());
Transform2D mtx;
- float * bones = skeleton->bones.ptr();
- mtx.elements[0][0]=bones[p_bone*12+ 0];
- mtx.elements[1][0]=bones[p_bone*12+ 1];
- mtx.elements[2][0]=bones[p_bone*12+ 3];
- mtx.elements[0][1]=bones[p_bone*12+ 4];
- mtx.elements[1][1]=bones[p_bone*12+ 5];
- mtx.elements[2][1]=bones[p_bone*12+ 7];
+ float *bones = skeleton->bones.ptr();
+ mtx.elements[0][0] = bones[p_bone * 12 + 0];
+ mtx.elements[1][0] = bones[p_bone * 12 + 1];
+ mtx.elements[2][0] = bones[p_bone * 12 + 3];
+ mtx.elements[0][1] = bones[p_bone * 12 + 4];
+ mtx.elements[1][1] = bones[p_bone * 12 + 5];
+ mtx.elements[2][1] = bones[p_bone * 12 + 7];
return mtx;
}
void RasterizerStorageGLES3::update_dirty_skeletons() {
- while(skeleton_update_list.first()) {
+ while (skeleton_update_list.first()) {
Skeleton *skeleton = skeleton_update_list.first()->self();
if (skeleton->size) {
glBindBuffer(GL_UNIFORM_BUFFER, skeleton->ubo);
- glBufferSubData(GL_UNIFORM_BUFFER,0,skeleton->bones.size()*sizeof(float),skeleton->bones.ptr());
+ glBufferSubData(GL_UNIFORM_BUFFER, 0, skeleton->bones.size() * sizeof(float), skeleton->bones.ptr());
glBindBuffer(GL_UNIFORM_BUFFER, 0);
}
- for (Set<RasterizerScene::InstanceBase*>::Element *E=skeleton->instances.front();E;E=E->next()) {
+ for (Set<RasterizerScene::InstanceBase *>::Element *E = skeleton->instances.front(); E; E = E->next()) {
E->get()->base_changed();
}
skeleton_update_list.remove(skeleton_update_list.first());
}
-
}
/* Light API */
-RID RasterizerStorageGLES3::light_create(VS::LightType p_type){
-
- Light *light = memnew( Light );
- light->type=p_type;
-
- light->param[VS::LIGHT_PARAM_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->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_blend_splits=false;
-
- light->version=0;
+RID RasterizerStorageGLES3::light_create(VS::LightType p_type) {
+
+ Light *light = memnew(Light);
+ light->type = p_type;
+
+ light->param[VS::LIGHT_PARAM_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->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_blend_splits = false;
+
+ light->version = 0;
return light_owner.make_rid(light);
}
-void RasterizerStorageGLES3::light_set_color(RID p_light,const Color& p_color){
+void RasterizerStorageGLES3::light_set_color(RID p_light, const Color &p_color) {
- Light * light = light_owner.getornull(p_light);
+ Light *light = light_owner.getornull(p_light);
ERR_FAIL_COND(!light);
- light->color=p_color;
+ light->color = p_color;
}
-void RasterizerStorageGLES3::light_set_param(RID p_light,VS::LightParam p_param,float p_value){
+void RasterizerStorageGLES3::light_set_param(RID p_light, VS::LightParam p_param, float p_value) {
- Light * light = light_owner.getornull(p_light);
+ 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, VS::LIGHT_PARAM_MAX);
- switch(p_param) {
+ switch (p_param) {
case VS::LIGHT_PARAM_RANGE:
case VS::LIGHT_PARAM_SPOT_ANGLE:
case VS::LIGHT_PARAM_SHADOW_MAX_DISTANCE:
@@ -4397,185 +4165,173 @@ void RasterizerStorageGLES3::light_set_param(RID p_light,VS::LightParam p_param,
} break;
}
- light->param[p_param]=p_value;
+ light->param[p_param] = p_value;
}
-void RasterizerStorageGLES3::light_set_shadow(RID p_light,bool p_enabled){
+void RasterizerStorageGLES3::light_set_shadow(RID p_light, bool p_enabled) {
- Light * light = light_owner.getornull(p_light);
+ Light *light = light_owner.getornull(p_light);
ERR_FAIL_COND(!light);
- light->shadow=p_enabled;
+ light->shadow = p_enabled;
light->version++;
light->instance_change_notify();
}
-void RasterizerStorageGLES3::light_set_shadow_color(RID p_light,const Color& p_color) {
+void RasterizerStorageGLES3::light_set_shadow_color(RID p_light, const Color &p_color) {
- Light * light = light_owner.getornull(p_light);
+ Light *light = light_owner.getornull(p_light);
ERR_FAIL_COND(!light);
- light->shadow_color=p_color;
-
+ light->shadow_color = p_color;
}
-void RasterizerStorageGLES3::light_set_projector(RID p_light,RID p_texture){
+void RasterizerStorageGLES3::light_set_projector(RID p_light, RID p_texture) {
- Light * light = light_owner.getornull(p_light);
+ Light *light = light_owner.getornull(p_light);
ERR_FAIL_COND(!light);
- light->projector=p_texture;
+ light->projector = p_texture;
}
-void RasterizerStorageGLES3::light_set_negative(RID p_light,bool p_enable){
+void RasterizerStorageGLES3::light_set_negative(RID p_light, bool p_enable) {
- Light * light = light_owner.getornull(p_light);
+ Light *light = light_owner.getornull(p_light);
ERR_FAIL_COND(!light);
- light->negative=p_enable;
+ light->negative = p_enable;
}
-void RasterizerStorageGLES3::light_set_cull_mask(RID p_light,uint32_t p_mask){
+void RasterizerStorageGLES3::light_set_cull_mask(RID p_light, uint32_t p_mask) {
- Light * light = light_owner.getornull(p_light);
+ Light *light = light_owner.getornull(p_light);
ERR_FAIL_COND(!light);
- light->cull_mask=p_mask;
+ light->cull_mask = p_mask;
light->version++;
light->instance_change_notify();
-
}
-void RasterizerStorageGLES3::light_omni_set_shadow_mode(RID p_light,VS::LightOmniShadowMode p_mode) {
+void RasterizerStorageGLES3::light_omni_set_shadow_mode(RID p_light, VS::LightOmniShadowMode p_mode) {
- Light * light = light_owner.getornull(p_light);
+ Light *light = light_owner.getornull(p_light);
ERR_FAIL_COND(!light);
- light->omni_shadow_mode=p_mode;
+ light->omni_shadow_mode = p_mode;
light->version++;
light->instance_change_notify();
-
-
}
VS::LightOmniShadowMode RasterizerStorageGLES3::light_omni_get_shadow_mode(RID p_light) {
- const Light * light = light_owner.getornull(p_light);
- ERR_FAIL_COND_V(!light,VS::LIGHT_OMNI_SHADOW_CUBE);
+ const Light *light = light_owner.getornull(p_light);
+ ERR_FAIL_COND_V(!light, VS::LIGHT_OMNI_SHADOW_CUBE);
return light->omni_shadow_mode;
}
+void RasterizerStorageGLES3::light_omni_set_shadow_detail(RID p_light, VS::LightOmniShadowDetail p_detail) {
-void RasterizerStorageGLES3::light_omni_set_shadow_detail(RID p_light,VS::LightOmniShadowDetail p_detail) {
-
- Light * light = light_owner.getornull(p_light);
+ Light *light = light_owner.getornull(p_light);
ERR_FAIL_COND(!light);
- light->omni_shadow_detail=p_detail;
+ light->omni_shadow_detail = p_detail;
light->version++;
light->instance_change_notify();
}
+void RasterizerStorageGLES3::light_directional_set_shadow_mode(RID p_light, VS::LightDirectionalShadowMode p_mode) {
-void RasterizerStorageGLES3::light_directional_set_shadow_mode(RID p_light,VS::LightDirectionalShadowMode p_mode){
-
- Light * light = light_owner.getornull(p_light);
+ Light *light = light_owner.getornull(p_light);
ERR_FAIL_COND(!light);
- light->directional_shadow_mode=p_mode;
+ light->directional_shadow_mode = p_mode;
light->version++;
light->instance_change_notify();
-
}
-void RasterizerStorageGLES3::light_directional_set_blend_splits(RID p_light,bool p_enable) {
+void RasterizerStorageGLES3::light_directional_set_blend_splits(RID p_light, bool p_enable) {
- Light * light = light_owner.getornull(p_light);
+ Light *light = light_owner.getornull(p_light);
ERR_FAIL_COND(!light);
- light->directional_blend_splits=p_enable;
+ light->directional_blend_splits = p_enable;
light->version++;
light->instance_change_notify();
-
}
-
bool RasterizerStorageGLES3::light_directional_get_blend_splits(RID p_light) const {
- const Light * light = light_owner.getornull(p_light);
- ERR_FAIL_COND_V(!light,false);
+ const Light *light = light_owner.getornull(p_light);
+ ERR_FAIL_COND_V(!light, false);
return light->directional_blend_splits;
}
VS::LightDirectionalShadowMode RasterizerStorageGLES3::light_directional_get_shadow_mode(RID p_light) {
- const Light * light = light_owner.getornull(p_light);
- ERR_FAIL_COND_V(!light,VS::LIGHT_DIRECTIONAL_SHADOW_ORTHOGONAL);
+ const Light *light = light_owner.getornull(p_light);
+ ERR_FAIL_COND_V(!light, VS::LIGHT_DIRECTIONAL_SHADOW_ORTHOGONAL);
return light->directional_shadow_mode;
}
-
VS::LightType RasterizerStorageGLES3::light_get_type(RID p_light) const {
- const Light * light = light_owner.getornull(p_light);
- ERR_FAIL_COND_V(!light,VS::LIGHT_DIRECTIONAL);
+ const Light *light = light_owner.getornull(p_light);
+ ERR_FAIL_COND_V(!light, VS::LIGHT_DIRECTIONAL);
return light->type;
}
-float RasterizerStorageGLES3::light_get_param(RID p_light,VS::LightParam p_param) {
+float RasterizerStorageGLES3::light_get_param(RID p_light, VS::LightParam p_param) {
- const Light * light = light_owner.getornull(p_light);
- ERR_FAIL_COND_V(!light,VS::LIGHT_DIRECTIONAL);
+ const Light *light = light_owner.getornull(p_light);
+ ERR_FAIL_COND_V(!light, VS::LIGHT_DIRECTIONAL);
return light->param[p_param];
}
Color RasterizerStorageGLES3::light_get_color(RID p_light) {
- const Light * light = light_owner.getornull(p_light);
- ERR_FAIL_COND_V(!light,Color());
+ const Light *light = light_owner.getornull(p_light);
+ ERR_FAIL_COND_V(!light, Color());
return light->color;
-
}
bool RasterizerStorageGLES3::light_has_shadow(RID p_light) const {
- const Light * light = light_owner.getornull(p_light);
- ERR_FAIL_COND_V(!light,VS::LIGHT_DIRECTIONAL);
+ const Light *light = light_owner.getornull(p_light);
+ ERR_FAIL_COND_V(!light, VS::LIGHT_DIRECTIONAL);
return light->shadow;
}
uint64_t RasterizerStorageGLES3::light_get_version(RID p_light) const {
- const Light * light = light_owner.getornull(p_light);
- ERR_FAIL_COND_V(!light,0);
+ const Light *light = light_owner.getornull(p_light);
+ ERR_FAIL_COND_V(!light, 0);
return light->version;
}
-
Rect3 RasterizerStorageGLES3::light_get_aabb(RID p_light) const {
- const Light * light = light_owner.getornull(p_light);
- ERR_FAIL_COND_V(!light,Rect3());
+ const Light *light = light_owner.getornull(p_light);
+ ERR_FAIL_COND_V(!light, Rect3());
- switch( light->type ) {
+ 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;
- return Rect3( Vector3( -size,-size,-len ), Vector3( size*2, size*2, len ) );
+ float len = light->param[VS::LIGHT_PARAM_RANGE];
+ float size = Math::tan(Math::deg2rad(light->param[VS::LIGHT_PARAM_SPOT_ANGLE])) * len;
+ return Rect3(Vector3(-size, -size, -len), Vector3(size * 2, size * 2, len));
} break;
case VS::LIGHT_OMNI: {
float r = light->param[VS::LIGHT_PARAM_RANGE];
- return Rect3( -Vector3(r,r,r), Vector3(r,r,r)*2 );
+ return Rect3(-Vector3(r, r, r), Vector3(r, r, r) * 2);
} break;
case VS::LIGHT_DIRECTIONAL: {
@@ -4584,27 +4340,27 @@ Rect3 RasterizerStorageGLES3::light_get_aabb(RID p_light) const {
default: {}
}
- ERR_FAIL_V( Rect3() );
+ ERR_FAIL_V(Rect3());
return Rect3();
}
/* PROBE API */
-RID RasterizerStorageGLES3::reflection_probe_create(){
+RID RasterizerStorageGLES3::reflection_probe_create() {
- ReflectionProbe *reflection_probe = memnew( ReflectionProbe );
+ ReflectionProbe *reflection_probe = memnew(ReflectionProbe);
- reflection_probe->intensity=1.0;
- reflection_probe->interior_ambient=Color();
- reflection_probe->interior_ambient_energy=1.0;
- reflection_probe->max_distance=0;
- reflection_probe->extents=Vector3(1,1,1);
- reflection_probe->origin_offset=Vector3(0,0,0);
- reflection_probe->interior=false;
- 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->intensity = 1.0;
+ reflection_probe->interior_ambient = Color();
+ reflection_probe->interior_ambient_energy = 1.0;
+ reflection_probe->max_distance = 0;
+ reflection_probe->extents = Vector3(1, 1, 1);
+ reflection_probe->origin_offset = Vector3(0, 0, 0);
+ reflection_probe->interior = false;
+ 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;
return reflection_probe_owner.make_rid(reflection_probe);
}
@@ -4614,9 +4370,8 @@ void RasterizerStorageGLES3::reflection_probe_set_update_mode(RID p_probe, VS::R
ReflectionProbe *reflection_probe = reflection_probe_owner.getornull(p_probe);
ERR_FAIL_COND(!reflection_probe);
- reflection_probe->update_mode=p_mode;
+ reflection_probe->update_mode = p_mode;
reflection_probe->instance_change_notify();
-
}
void RasterizerStorageGLES3::reflection_probe_set_intensity(RID p_probe, float p_intensity) {
@@ -4624,17 +4379,15 @@ void RasterizerStorageGLES3::reflection_probe_set_intensity(RID p_probe, float p
ReflectionProbe *reflection_probe = reflection_probe_owner.getornull(p_probe);
ERR_FAIL_COND(!reflection_probe);
- reflection_probe->intensity=p_intensity;
-
+ reflection_probe->intensity = p_intensity;
}
-void RasterizerStorageGLES3::reflection_probe_set_interior_ambient(RID p_probe, const Color& p_ambient) {
+void RasterizerStorageGLES3::reflection_probe_set_interior_ambient(RID p_probe, const Color &p_ambient) {
ReflectionProbe *reflection_probe = reflection_probe_owner.getornull(p_probe);
ERR_FAIL_COND(!reflection_probe);
- reflection_probe->interior_ambient=p_ambient;
-
+ reflection_probe->interior_ambient = p_ambient;
}
void RasterizerStorageGLES3::reflection_probe_set_interior_ambient_energy(RID p_probe, float p_energy) {
@@ -4642,8 +4395,7 @@ void RasterizerStorageGLES3::reflection_probe_set_interior_ambient_energy(RID p_
ReflectionProbe *reflection_probe = reflection_probe_owner.getornull(p_probe);
ERR_FAIL_COND(!reflection_probe);
- reflection_probe->interior_ambient_energy=p_energy;
-
+ reflection_probe->interior_ambient_energy = p_energy;
}
void RasterizerStorageGLES3::reflection_probe_set_interior_ambient_probe_contribution(RID p_probe, float p_contrib) {
@@ -4651,91 +4403,80 @@ void RasterizerStorageGLES3::reflection_probe_set_interior_ambient_probe_contrib
ReflectionProbe *reflection_probe = reflection_probe_owner.getornull(p_probe);
ERR_FAIL_COND(!reflection_probe);
- reflection_probe->interior_ambient_probe_contrib=p_contrib;
-
+ reflection_probe->interior_ambient_probe_contrib = p_contrib;
}
-
-void RasterizerStorageGLES3::reflection_probe_set_max_distance(RID p_probe, float p_distance){
+void RasterizerStorageGLES3::reflection_probe_set_max_distance(RID p_probe, float p_distance) {
ReflectionProbe *reflection_probe = reflection_probe_owner.getornull(p_probe);
ERR_FAIL_COND(!reflection_probe);
- reflection_probe->max_distance=p_distance;
+ reflection_probe->max_distance = p_distance;
reflection_probe->instance_change_notify();
-
}
-void RasterizerStorageGLES3::reflection_probe_set_extents(RID p_probe, const Vector3& p_extents){
+void RasterizerStorageGLES3::reflection_probe_set_extents(RID p_probe, const Vector3 &p_extents) {
ReflectionProbe *reflection_probe = reflection_probe_owner.getornull(p_probe);
ERR_FAIL_COND(!reflection_probe);
- reflection_probe->extents=p_extents;
+ reflection_probe->extents = p_extents;
reflection_probe->instance_change_notify();
-
}
-void RasterizerStorageGLES3::reflection_probe_set_origin_offset(RID p_probe, const Vector3& p_offset){
+void RasterizerStorageGLES3::reflection_probe_set_origin_offset(RID p_probe, const Vector3 &p_offset) {
ReflectionProbe *reflection_probe = reflection_probe_owner.getornull(p_probe);
ERR_FAIL_COND(!reflection_probe);
- reflection_probe->origin_offset=p_offset;
+ reflection_probe->origin_offset = p_offset;
reflection_probe->instance_change_notify();
-
}
-void RasterizerStorageGLES3::reflection_probe_set_as_interior(RID p_probe, bool p_enable){
+void RasterizerStorageGLES3::reflection_probe_set_as_interior(RID p_probe, bool p_enable) {
ReflectionProbe *reflection_probe = reflection_probe_owner.getornull(p_probe);
ERR_FAIL_COND(!reflection_probe);
- reflection_probe->interior=p_enable;
-
+ reflection_probe->interior = p_enable;
}
-void RasterizerStorageGLES3::reflection_probe_set_enable_box_projection(RID p_probe, bool p_enable){
+void RasterizerStorageGLES3::reflection_probe_set_enable_box_projection(RID p_probe, bool p_enable) {
ReflectionProbe *reflection_probe = reflection_probe_owner.getornull(p_probe);
ERR_FAIL_COND(!reflection_probe);
- reflection_probe->box_projection=p_enable;
-
+ reflection_probe->box_projection = p_enable;
}
-void RasterizerStorageGLES3::reflection_probe_set_enable_shadows(RID p_probe, bool p_enable){
+void RasterizerStorageGLES3::reflection_probe_set_enable_shadows(RID p_probe, bool p_enable) {
ReflectionProbe *reflection_probe = reflection_probe_owner.getornull(p_probe);
ERR_FAIL_COND(!reflection_probe);
- reflection_probe->enable_shadows=p_enable;
+ reflection_probe->enable_shadows = p_enable;
reflection_probe->instance_change_notify();
-
}
-void RasterizerStorageGLES3::reflection_probe_set_cull_mask(RID p_probe, uint32_t p_layers){
+void RasterizerStorageGLES3::reflection_probe_set_cull_mask(RID p_probe, uint32_t p_layers) {
ReflectionProbe *reflection_probe = reflection_probe_owner.getornull(p_probe);
ERR_FAIL_COND(!reflection_probe);
- reflection_probe->cull_mask=p_layers;
+ reflection_probe->cull_mask = p_layers;
reflection_probe->instance_change_notify();
-
}
Rect3 RasterizerStorageGLES3::reflection_probe_get_aabb(RID p_probe) const {
const ReflectionProbe *reflection_probe = reflection_probe_owner.getornull(p_probe);
- ERR_FAIL_COND_V(!reflection_probe,Rect3());
+ ERR_FAIL_COND_V(!reflection_probe, Rect3());
Rect3 aabb;
- aabb.pos=-reflection_probe->extents;
- aabb.size=reflection_probe->extents*2.0;
+ aabb.pos = -reflection_probe->extents;
+ aabb.size = reflection_probe->extents * 2.0;
return aabb;
-
-
}
-VS::ReflectionProbeUpdateMode RasterizerStorageGLES3::reflection_probe_get_update_mode(RID p_probe) const{
+VS::ReflectionProbeUpdateMode RasterizerStorageGLES3::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, VS::REFLECTION_PROBE_UPDATE_ALWAYS);
return reflection_probe->update_mode;
}
@@ -4743,60 +4484,51 @@ VS::ReflectionProbeUpdateMode RasterizerStorageGLES3::reflection_probe_get_updat
uint32_t RasterizerStorageGLES3::reflection_probe_get_cull_mask(RID p_probe) const {
const ReflectionProbe *reflection_probe = reflection_probe_owner.getornull(p_probe);
- ERR_FAIL_COND_V(!reflection_probe,0);
+ ERR_FAIL_COND_V(!reflection_probe, 0);
return reflection_probe->cull_mask;
-
}
Vector3 RasterizerStorageGLES3::reflection_probe_get_extents(RID p_probe) const {
const ReflectionProbe *reflection_probe = reflection_probe_owner.getornull(p_probe);
- ERR_FAIL_COND_V(!reflection_probe,Vector3());
+ ERR_FAIL_COND_V(!reflection_probe, Vector3());
return reflection_probe->extents;
-
}
-Vector3 RasterizerStorageGLES3::reflection_probe_get_origin_offset(RID p_probe) const{
+Vector3 RasterizerStorageGLES3::reflection_probe_get_origin_offset(RID p_probe) const {
const ReflectionProbe *reflection_probe = reflection_probe_owner.getornull(p_probe);
- ERR_FAIL_COND_V(!reflection_probe,Vector3());
+ ERR_FAIL_COND_V(!reflection_probe, Vector3());
return reflection_probe->origin_offset;
-
}
bool RasterizerStorageGLES3::reflection_probe_renders_shadows(RID p_probe) const {
const ReflectionProbe *reflection_probe = reflection_probe_owner.getornull(p_probe);
- ERR_FAIL_COND_V(!reflection_probe,false);
+ ERR_FAIL_COND_V(!reflection_probe, false);
return reflection_probe->enable_shadows;
-
}
-float RasterizerStorageGLES3::reflection_probe_get_origin_max_distance(RID p_probe) const{
+float RasterizerStorageGLES3::reflection_probe_get_origin_max_distance(RID p_probe) const {
const ReflectionProbe *reflection_probe = reflection_probe_owner.getornull(p_probe);
- ERR_FAIL_COND_V(!reflection_probe,0);
+ ERR_FAIL_COND_V(!reflection_probe, 0);
return reflection_probe->max_distance;
-
}
/* ROOM API */
-RID RasterizerStorageGLES3::room_create(){
+RID RasterizerStorageGLES3::room_create() {
return RID();
}
-void RasterizerStorageGLES3::room_add_bounds(RID p_room, const PoolVector<Vector2>& p_convex_polygon,float p_height,const Transform& p_transform){
-
-
+void RasterizerStorageGLES3::room_add_bounds(RID p_room, const PoolVector<Vector2> &p_convex_polygon, float p_height, const Transform &p_transform) {
}
-void RasterizerStorageGLES3::room_clear_bounds(RID p_room){
-
-
+void RasterizerStorageGLES3::room_clear_bounds(RID p_room) {
}
/* PORTAL API */
@@ -4804,67 +4536,59 @@ void RasterizerStorageGLES3::room_clear_bounds(RID p_room){
// portals are only (x/y) points, forming a convex shape, which its clockwise
// order points outside. (z is 0);
-RID RasterizerStorageGLES3::portal_create(){
+RID RasterizerStorageGLES3::portal_create() {
return RID();
}
-void RasterizerStorageGLES3::portal_set_shape(RID p_portal, const Vector<Point2>& p_shape){
-
-
+void RasterizerStorageGLES3::portal_set_shape(RID p_portal, const Vector<Point2> &p_shape) {
}
-void RasterizerStorageGLES3::portal_set_enabled(RID p_portal, bool p_enabled){
-
-
+void RasterizerStorageGLES3::portal_set_enabled(RID p_portal, bool p_enabled) {
}
-void RasterizerStorageGLES3::portal_set_disable_distance(RID p_portal, float p_distance){
-
-
+void RasterizerStorageGLES3::portal_set_disable_distance(RID p_portal, float p_distance) {
}
-void RasterizerStorageGLES3::portal_set_disabled_color(RID p_portal, const Color& p_color){
-
-
+void RasterizerStorageGLES3::portal_set_disabled_color(RID p_portal, const Color &p_color) {
}
RID RasterizerStorageGLES3::gi_probe_create() {
- GIProbe *gip = memnew( GIProbe );
+ GIProbe *gip = memnew(GIProbe);
- gip->bounds=Rect3(Vector3(),Vector3(1,1,1));
- gip->dynamic_range=1.0;
- gip->energy=1.0;
- gip->propagation=1.0;
- gip->bias=0.4;
- gip->interior=false;
- gip->compress=false;
- gip->version=1;
- gip->cell_size=1.0;
+ gip->bounds = Rect3(Vector3(), Vector3(1, 1, 1));
+ gip->dynamic_range = 1.0;
+ gip->energy = 1.0;
+ gip->propagation = 1.0;
+ gip->bias = 0.4;
+ gip->interior = false;
+ gip->compress = false;
+ gip->version = 1;
+ gip->cell_size = 1.0;
return gi_probe_owner.make_rid(gip);
}
-void RasterizerStorageGLES3::gi_probe_set_bounds(RID p_probe,const Rect3& p_bounds){
+void RasterizerStorageGLES3::gi_probe_set_bounds(RID p_probe, const Rect3 &p_bounds) {
GIProbe *gip = gi_probe_owner.getornull(p_probe);
ERR_FAIL_COND(!gip);
- gip->bounds=p_bounds;
+ gip->bounds = p_bounds;
gip->version++;
gip->instance_change_notify();
}
-Rect3 RasterizerStorageGLES3::gi_probe_get_bounds(RID p_probe) const{
+Rect3 RasterizerStorageGLES3::gi_probe_get_bounds(RID p_probe) const {
const GIProbe *gip = gi_probe_owner.getornull(p_probe);
- ERR_FAIL_COND_V(!gip,Rect3());
+ ERR_FAIL_COND_V(!gip, Rect3());
return gip->bounds;
}
-void RasterizerStorageGLES3::gi_probe_set_cell_size(RID p_probe,float p_size) {
+void RasterizerStorageGLES3::gi_probe_set_cell_size(RID p_probe, float p_size) {
GIProbe *gip = gi_probe_owner.getornull(p_probe);
ERR_FAIL_COND(!gip);
- gip->cell_size=p_size;
+ gip->cell_size = p_size;
gip->version++;
gip->instance_change_notify();
}
@@ -4872,161 +4596,141 @@ void RasterizerStorageGLES3::gi_probe_set_cell_size(RID p_probe,float p_size) {
float RasterizerStorageGLES3::gi_probe_get_cell_size(RID p_probe) const {
const GIProbe *gip = gi_probe_owner.getornull(p_probe);
- ERR_FAIL_COND_V(!gip,0);
+ ERR_FAIL_COND_V(!gip, 0);
return gip->cell_size;
-
}
-void RasterizerStorageGLES3::gi_probe_set_to_cell_xform(RID p_probe,const Transform& p_xform) {
+void RasterizerStorageGLES3::gi_probe_set_to_cell_xform(RID p_probe, const Transform &p_xform) {
GIProbe *gip = gi_probe_owner.getornull(p_probe);
ERR_FAIL_COND(!gip);
- gip->to_cell=p_xform;
+ gip->to_cell = p_xform;
}
Transform RasterizerStorageGLES3::gi_probe_get_to_cell_xform(RID p_probe) const {
const GIProbe *gip = gi_probe_owner.getornull(p_probe);
- ERR_FAIL_COND_V(!gip,Transform());
+ ERR_FAIL_COND_V(!gip, Transform());
return gip->to_cell;
-
}
-
-
-void RasterizerStorageGLES3::gi_probe_set_dynamic_data(RID p_probe,const PoolVector<int>& p_data){
+void RasterizerStorageGLES3::gi_probe_set_dynamic_data(RID p_probe, const PoolVector<int> &p_data) {
GIProbe *gip = gi_probe_owner.getornull(p_probe);
ERR_FAIL_COND(!gip);
- gip->dynamic_data=p_data;
+ gip->dynamic_data = p_data;
gip->version++;
gip->instance_change_notify();
-
}
-PoolVector<int> RasterizerStorageGLES3::gi_probe_get_dynamic_data(RID p_probe) const{
+PoolVector<int> RasterizerStorageGLES3::gi_probe_get_dynamic_data(RID p_probe) const {
const GIProbe *gip = gi_probe_owner.getornull(p_probe);
- ERR_FAIL_COND_V(!gip,PoolVector<int>());
+ ERR_FAIL_COND_V(!gip, PoolVector<int>());
return gip->dynamic_data;
}
-void RasterizerStorageGLES3::gi_probe_set_dynamic_range(RID p_probe,int p_range){
+void RasterizerStorageGLES3::gi_probe_set_dynamic_range(RID p_probe, int p_range) {
GIProbe *gip = gi_probe_owner.getornull(p_probe);
ERR_FAIL_COND(!gip);
- gip->dynamic_range=p_range;
-
+ gip->dynamic_range = p_range;
}
-int RasterizerStorageGLES3::gi_probe_get_dynamic_range(RID p_probe) const{
+int RasterizerStorageGLES3::gi_probe_get_dynamic_range(RID p_probe) const {
const GIProbe *gip = gi_probe_owner.getornull(p_probe);
- ERR_FAIL_COND_V(!gip,0);
+ ERR_FAIL_COND_V(!gip, 0);
return gip->dynamic_range;
}
-void RasterizerStorageGLES3::gi_probe_set_energy(RID p_probe,float p_range){
+void RasterizerStorageGLES3::gi_probe_set_energy(RID p_probe, float p_range) {
GIProbe *gip = gi_probe_owner.getornull(p_probe);
ERR_FAIL_COND(!gip);
- gip->energy=p_range;
-
+ gip->energy = p_range;
}
-
-void RasterizerStorageGLES3::gi_probe_set_bias(RID p_probe,float p_range){
+void RasterizerStorageGLES3::gi_probe_set_bias(RID p_probe, float p_range) {
GIProbe *gip = gi_probe_owner.getornull(p_probe);
ERR_FAIL_COND(!gip);
- gip->bias=p_range;
-
+ gip->bias = p_range;
}
-void RasterizerStorageGLES3::gi_probe_set_propagation(RID p_probe,float p_range){
+void RasterizerStorageGLES3::gi_probe_set_propagation(RID p_probe, float p_range) {
GIProbe *gip = gi_probe_owner.getornull(p_probe);
ERR_FAIL_COND(!gip);
- gip->propagation=p_range;
-
+ gip->propagation = p_range;
}
-void RasterizerStorageGLES3::gi_probe_set_interior(RID p_probe,bool p_enable) {
+void RasterizerStorageGLES3::gi_probe_set_interior(RID p_probe, bool p_enable) {
GIProbe *gip = gi_probe_owner.getornull(p_probe);
ERR_FAIL_COND(!gip);
- gip->interior=p_enable;
-
+ gip->interior = p_enable;
}
-bool RasterizerStorageGLES3::gi_probe_is_interior(RID p_probe) const{
+bool RasterizerStorageGLES3::gi_probe_is_interior(RID p_probe) const {
const GIProbe *gip = gi_probe_owner.getornull(p_probe);
- ERR_FAIL_COND_V(!gip,false);
+ ERR_FAIL_COND_V(!gip, false);
return gip->interior;
-
}
-
-void RasterizerStorageGLES3::gi_probe_set_compress(RID p_probe,bool p_enable) {
+void RasterizerStorageGLES3::gi_probe_set_compress(RID p_probe, bool p_enable) {
GIProbe *gip = gi_probe_owner.getornull(p_probe);
ERR_FAIL_COND(!gip);
- gip->compress=p_enable;
-
+ gip->compress = p_enable;
}
-bool RasterizerStorageGLES3::gi_probe_is_compressed(RID p_probe) const{
+bool RasterizerStorageGLES3::gi_probe_is_compressed(RID p_probe) const {
const GIProbe *gip = gi_probe_owner.getornull(p_probe);
- ERR_FAIL_COND_V(!gip,false);
+ ERR_FAIL_COND_V(!gip, false);
return gip->compress;
-
}
-float RasterizerStorageGLES3::gi_probe_get_energy(RID p_probe) const{
+float RasterizerStorageGLES3::gi_probe_get_energy(RID p_probe) const {
const GIProbe *gip = gi_probe_owner.getornull(p_probe);
- ERR_FAIL_COND_V(!gip,0);
+ ERR_FAIL_COND_V(!gip, 0);
return gip->energy;
}
-float RasterizerStorageGLES3::gi_probe_get_bias(RID p_probe) const{
+float RasterizerStorageGLES3::gi_probe_get_bias(RID p_probe) const {
const GIProbe *gip = gi_probe_owner.getornull(p_probe);
- ERR_FAIL_COND_V(!gip,0);
+ ERR_FAIL_COND_V(!gip, 0);
return gip->bias;
}
-
-float RasterizerStorageGLES3::gi_probe_get_propagation(RID p_probe) const{
+float RasterizerStorageGLES3::gi_probe_get_propagation(RID p_probe) const {
const GIProbe *gip = gi_probe_owner.getornull(p_probe);
- ERR_FAIL_COND_V(!gip,0);
+ ERR_FAIL_COND_V(!gip, 0);
return gip->propagation;
}
-
-
-
-
uint32_t RasterizerStorageGLES3::gi_probe_get_version(RID p_probe) {
const GIProbe *gip = gi_probe_owner.getornull(p_probe);
- ERR_FAIL_COND_V(!gip,0);
+ ERR_FAIL_COND_V(!gip, 0);
return gip->version;
}
@@ -5041,39 +4745,39 @@ RasterizerStorage::GIProbeCompression RasterizerStorageGLES3::gi_probe_get_dynam
RID RasterizerStorageGLES3::gi_probe_dynamic_data_create(int p_width, int p_height, int p_depth, GIProbeCompression p_compression) {
- GIProbeData *gipd = memnew( GIProbeData );
+ GIProbeData *gipd = memnew(GIProbeData);
- gipd->width=p_width;
- gipd->height=p_height;
- gipd->depth=p_depth;
- gipd->compression=p_compression;
+ gipd->width = p_width;
+ gipd->height = p_height;
+ gipd->depth = p_depth;
+ gipd->compression = p_compression;
glActiveTexture(GL_TEXTURE0);
- glGenTextures(1,&gipd->tex_id);
- glBindTexture(GL_TEXTURE_3D,gipd->tex_id);
+ glGenTextures(1, &gipd->tex_id);
+ glBindTexture(GL_TEXTURE_3D, gipd->tex_id);
- int level=0;
- int min_size=1;
+ int level = 0;
+ int min_size = 1;
- if (gipd->compression==GI_PROBE_S3TC) {
- min_size=4;
+ if (gipd->compression == GI_PROBE_S3TC) {
+ min_size = 4;
}
print_line("dyndata create");
- while(true) {
+ while (true) {
- if (gipd->compression==GI_PROBE_S3TC) {
+ if (gipd->compression == GI_PROBE_S3TC) {
int size = p_width * p_height * p_depth;
- glCompressedTexImage3D(GL_TEXTURE_3D,level,_EXT_COMPRESSED_RGBA_S3TC_DXT5_EXT,p_width,p_height,p_depth,0, size,NULL);
+ glCompressedTexImage3D(GL_TEXTURE_3D, level, _EXT_COMPRESSED_RGBA_S3TC_DXT5_EXT, p_width, p_height, p_depth, 0, size, NULL);
} else {
- glTexImage3D(GL_TEXTURE_3D,level,GL_RGBA8,p_width,p_height,p_depth,0,GL_RGBA,GL_UNSIGNED_BYTE,NULL);
+ glTexImage3D(GL_TEXTURE_3D, level, GL_RGBA8, p_width, p_height, p_depth, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
}
- if (p_width<=min_size || p_height<=min_size || p_depth<=min_size)
+ if (p_width <= min_size || p_height <= min_size || p_depth <= min_size)
break;
- p_width>>=1;
- p_height>>=1;
- p_depth>>=1;
+ p_width >>= 1;
+ p_height >>= 1;
+ p_depth >>= 1;
level++;
}
@@ -5085,7 +4789,7 @@ RID RasterizerStorageGLES3::gi_probe_dynamic_data_create(int p_width, int p_heig
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 0);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, level);
- gipd->levels=level+1;
+ gipd->levels = level + 1;
return gi_probe_data_owner.make_rid(gipd);
}
@@ -5094,7 +4798,7 @@ void RasterizerStorageGLES3::gi_probe_dynamic_data_update(RID p_gi_probe_data, i
GIProbeData *gipd = gi_probe_data_owner.getornull(p_gi_probe_data);
ERR_FAIL_COND(!gipd);
-/*
+ /*
Vector<uint8_t> data;
data.resize((gipd->width>>p_mipmap)*(gipd->height>>p_mipmap)*(gipd->depth>>p_mipmap)*4);
@@ -5113,120 +4817,109 @@ void RasterizerStorageGLES3::gi_probe_dynamic_data_update(RID p_gi_probe_data, i
}
*/
glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_3D,gipd->tex_id);
- if (gipd->compression==GI_PROBE_S3TC) {
- int size = (gipd->width>>p_mipmap) * (gipd->height>>p_mipmap) * p_slice_count;
- glCompressedTexSubImage3D(GL_TEXTURE_3D,p_mipmap,0,0,p_depth_slice,gipd->width>>p_mipmap,gipd->height>>p_mipmap,p_slice_count,_EXT_COMPRESSED_RGBA_S3TC_DXT5_EXT,size, p_data);
+ glBindTexture(GL_TEXTURE_3D, gipd->tex_id);
+ if (gipd->compression == GI_PROBE_S3TC) {
+ int size = (gipd->width >> p_mipmap) * (gipd->height >> p_mipmap) * p_slice_count;
+ glCompressedTexSubImage3D(GL_TEXTURE_3D, p_mipmap, 0, 0, p_depth_slice, gipd->width >> p_mipmap, gipd->height >> p_mipmap, p_slice_count, _EXT_COMPRESSED_RGBA_S3TC_DXT5_EXT, size, p_data);
} else {
- glTexSubImage3D(GL_TEXTURE_3D,p_mipmap,0,0,p_depth_slice,gipd->width>>p_mipmap,gipd->height>>p_mipmap,p_slice_count,GL_RGBA,GL_UNSIGNED_BYTE,p_data);
+ glTexSubImage3D(GL_TEXTURE_3D, p_mipmap, 0, 0, p_depth_slice, gipd->width >> p_mipmap, gipd->height >> p_mipmap, p_slice_count, GL_RGBA, GL_UNSIGNED_BYTE, p_data);
}
//glTexImage3D(GL_TEXTURE_3D,p_mipmap,GL_RGBA8,gipd->width>>p_mipmap,gipd->height>>p_mipmap,gipd->depth>>p_mipmap,0,GL_RGBA,GL_UNSIGNED_BYTE,p_data);
//glTexImage3D(GL_TEXTURE_3D,p_mipmap,GL_RGBA8,gipd->width>>p_mipmap,gipd->height>>p_mipmap,gipd->depth>>p_mipmap,0,GL_RGBA,GL_UNSIGNED_BYTE,data.ptr());
-
}
///////
-
-
RID RasterizerStorageGLES3::particles_create() {
- Particles *particles = memnew( Particles );
-
+ Particles *particles = memnew(Particles);
return particles_owner.make_rid(particles);
}
-void RasterizerStorageGLES3::particles_set_emitting(RID p_particles,bool p_emitting) {
+void RasterizerStorageGLES3::particles_set_emitting(RID p_particles, bool p_emitting) {
Particles *particles = particles_owner.getornull(p_particles);
ERR_FAIL_COND(!particles);
- particles->emitting=p_emitting;
-
+ particles->emitting = p_emitting;
}
-void RasterizerStorageGLES3::particles_set_amount(RID p_particles,int p_amount) {
+void RasterizerStorageGLES3::particles_set_amount(RID p_particles, int p_amount) {
Particles *particles = particles_owner.getornull(p_particles);
ERR_FAIL_COND(!particles);
- int floats = p_amount*24;
- float * data = memnew_arr(float,floats);
+ int floats = p_amount * 24;
+ float *data = memnew_arr(float, floats);
- for(int i=0;i<floats;i++) {
- data[i]=0;
+ for (int i = 0; i < floats; i++) {
+ data[i] = 0;
}
+ glBindBuffer(GL_ARRAY_BUFFER, particles->particle_buffers[0]);
+ glBufferData(GL_ARRAY_BUFFER, floats * sizeof(float), data, GL_DYNAMIC_DRAW);
- glBindBuffer(GL_ARRAY_BUFFER,particles->particle_buffers[0]);
- glBufferData(GL_ARRAY_BUFFER,floats*sizeof(float),data,GL_DYNAMIC_DRAW);
+ glBindBuffer(GL_ARRAY_BUFFER, particles->particle_buffers[1]);
+ glBufferData(GL_ARRAY_BUFFER, floats * sizeof(float), data, GL_DYNAMIC_DRAW);
- glBindBuffer(GL_ARRAY_BUFFER,particles->particle_buffers[1]);
- glBufferData(GL_ARRAY_BUFFER,floats*sizeof(float),data,GL_DYNAMIC_DRAW);
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
- glBindBuffer(GL_ARRAY_BUFFER,0);
-
- particles->prev_ticks=0;
- particles->phase=0;
- particles->prev_phase=0;
+ particles->prev_ticks = 0;
+ particles->phase = 0;
+ particles->prev_phase = 0;
memdelete_arr(data);
-
}
-void RasterizerStorageGLES3::particles_set_lifetime(RID p_particles,float p_lifetime){
+void RasterizerStorageGLES3::particles_set_lifetime(RID p_particles, float p_lifetime) {
Particles *particles = particles_owner.getornull(p_particles);
ERR_FAIL_COND(!particles);
- particles->lifetime=p_lifetime;
+ particles->lifetime = p_lifetime;
}
-void RasterizerStorageGLES3::particles_set_pre_process_time(RID p_particles,float p_time) {
+void RasterizerStorageGLES3::particles_set_pre_process_time(RID p_particles, float p_time) {
Particles *particles = particles_owner.getornull(p_particles);
ERR_FAIL_COND(!particles);
- particles->pre_process_time=p_time;
-
+ particles->pre_process_time = p_time;
}
-void RasterizerStorageGLES3::particles_set_explosiveness_ratio(RID p_particles,float p_ratio) {
+void RasterizerStorageGLES3::particles_set_explosiveness_ratio(RID p_particles, float p_ratio) {
Particles *particles = particles_owner.getornull(p_particles);
ERR_FAIL_COND(!particles);
- particles->explosiveness=p_ratio;
+ particles->explosiveness = p_ratio;
}
-void RasterizerStorageGLES3::particles_set_randomness_ratio(RID p_particles,float p_ratio) {
+void RasterizerStorageGLES3::particles_set_randomness_ratio(RID p_particles, float p_ratio) {
Particles *particles = particles_owner.getornull(p_particles);
ERR_FAIL_COND(!particles);
- particles->randomness=p_ratio;
-
+ particles->randomness = p_ratio;
}
-void RasterizerStorageGLES3::particles_set_custom_aabb(RID p_particles,const Rect3& p_aabb) {
+void RasterizerStorageGLES3::particles_set_custom_aabb(RID p_particles, const Rect3 &p_aabb) {
Particles *particles = particles_owner.getornull(p_particles);
ERR_FAIL_COND(!particles);
- particles->custom_aabb=p_aabb;
-
+ particles->custom_aabb = p_aabb;
}
-void RasterizerStorageGLES3::particles_set_gravity(RID p_particles,const Vector3& p_gravity) {
+void RasterizerStorageGLES3::particles_set_gravity(RID p_particles, const Vector3 &p_gravity) {
Particles *particles = particles_owner.getornull(p_particles);
ERR_FAIL_COND(!particles);
- particles->gravity=p_gravity;
-
+ particles->gravity = p_gravity;
}
-void RasterizerStorageGLES3::particles_set_use_local_coordinates(RID p_particles,bool p_enable) {
+void RasterizerStorageGLES3::particles_set_use_local_coordinates(RID p_particles, bool p_enable) {
Particles *particles = particles_owner.getornull(p_particles);
ERR_FAIL_COND(!particles);
- particles->use_local_coords=p_enable;
+ particles->use_local_coords = p_enable;
}
-void RasterizerStorageGLES3::particles_set_process_material(RID p_particles,RID p_material) {
+void RasterizerStorageGLES3::particles_set_process_material(RID p_particles, RID p_material) {
Particles *particles = particles_owner.getornull(p_particles);
ERR_FAIL_COND(!particles);
- particles->process_material=p_material;
+ particles->process_material = p_material;
}
void RasterizerStorageGLES3::particles_set_emission_shape(RID p_particles, VS::ParticlesEmissionShape p_shape) {
@@ -5234,67 +4927,64 @@ void RasterizerStorageGLES3::particles_set_emission_shape(RID p_particles, VS::P
Particles *particles = particles_owner.getornull(p_particles);
ERR_FAIL_COND(!particles);
- particles->emission_shape=p_shape;
+ particles->emission_shape = p_shape;
}
-void RasterizerStorageGLES3::particles_set_emission_sphere_radius(RID p_particles,float p_radius) {
+void RasterizerStorageGLES3::particles_set_emission_sphere_radius(RID p_particles, float p_radius) {
Particles *particles = particles_owner.getornull(p_particles);
ERR_FAIL_COND(!particles);
- particles->emission_sphere_radius=p_radius;
+ particles->emission_sphere_radius = p_radius;
}
-void RasterizerStorageGLES3::particles_set_emission_box_extents(RID p_particles,const Vector3& p_extents) {
+void RasterizerStorageGLES3::particles_set_emission_box_extents(RID p_particles, const Vector3 &p_extents) {
Particles *particles = particles_owner.getornull(p_particles);
ERR_FAIL_COND(!particles);
- particles->emission_box_extents=p_extents;
+ particles->emission_box_extents = p_extents;
}
-void RasterizerStorageGLES3::particles_set_emission_points(RID p_particles,const PoolVector<Vector3>& p_points) {
+void RasterizerStorageGLES3::particles_set_emission_points(RID p_particles, const PoolVector<Vector3> &p_points) {
Particles *particles = particles_owner.getornull(p_particles);
ERR_FAIL_COND(!particles);
- particles->emission_points=p_points;
+ particles->emission_points = p_points;
}
-
-void RasterizerStorageGLES3::particles_set_draw_order(RID p_particles,VS::ParticlesDrawOrder p_order) {
+void RasterizerStorageGLES3::particles_set_draw_order(RID p_particles, VS::ParticlesDrawOrder p_order) {
Particles *particles = particles_owner.getornull(p_particles);
ERR_FAIL_COND(!particles);
- particles->draw_order=p_order;
+ particles->draw_order = p_order;
}
-void RasterizerStorageGLES3::particles_set_draw_passes(RID p_particles,int p_count) {
+void RasterizerStorageGLES3::particles_set_draw_passes(RID p_particles, int p_count) {
Particles *particles = particles_owner.getornull(p_particles);
ERR_FAIL_COND(!particles);
particles->draw_passes.resize(p_count);
}
-void RasterizerStorageGLES3::particles_set_draw_pass_material(RID p_particles,int p_pass, RID p_material) {
+void RasterizerStorageGLES3::particles_set_draw_pass_material(RID p_particles, int p_pass, RID p_material) {
Particles *particles = particles_owner.getornull(p_particles);
ERR_FAIL_COND(!particles);
- ERR_FAIL_INDEX(p_pass,particles->draw_passes.size());
- particles->draw_passes[p_pass].material=p_material;
-
+ ERR_FAIL_INDEX(p_pass, particles->draw_passes.size());
+ particles->draw_passes[p_pass].material = p_material;
}
-void RasterizerStorageGLES3::particles_set_draw_pass_mesh(RID p_particles,int p_pass, RID p_mesh) {
+void RasterizerStorageGLES3::particles_set_draw_pass_mesh(RID p_particles, int p_pass, RID p_mesh) {
Particles *particles = particles_owner.getornull(p_particles);
ERR_FAIL_COND(!particles);
- ERR_FAIL_INDEX(p_pass,particles->draw_passes.size());
- particles->draw_passes[p_pass].mesh=p_mesh;
-
+ ERR_FAIL_INDEX(p_pass, particles->draw_passes.size());
+ particles->draw_passes[p_pass].mesh = p_mesh;
}
Rect3 RasterizerStorageGLES3::particles_get_current_aabb(RID p_particles) {
const Particles *particles = particles_owner.getornull(p_particles);
- ERR_FAIL_COND_V(!particles,Rect3());
+ ERR_FAIL_COND_V(!particles, Rect3());
return particles->computed_aabb;
}
@@ -5304,122 +4994,111 @@ void RasterizerStorageGLES3::update_particles() {
glEnable(GL_RASTERIZER_DISCARD);
glBindVertexArray(0);
-
while (particle_update_list.first()) {
//use transform feedback to process particles
Particles *particles = particle_update_list.first()->self();
-
Material *material = material_owner.getornull(particles->process_material);
- if (!material || !material->shader || material->shader->mode!=VS::SHADER_PARTICLES) {
+ if (!material || !material->shader || material->shader->mode != VS::SHADER_PARTICLES) {
shaders.particles.set_custom_shader(0);
} else {
- shaders.particles.set_custom_shader( material->shader->custom_code_id );
+ shaders.particles.set_custom_shader(material->shader->custom_code_id);
if (material->ubo_id) {
- glBindBufferBase(GL_UNIFORM_BUFFER,0,material->ubo_id);
+ glBindBufferBase(GL_UNIFORM_BUFFER, 0, material->ubo_id);
}
int tc = material->textures.size();
- RID* textures = material->textures.ptr();
- ShaderLanguage::ShaderNode::Uniform::Hint* texture_hints = material->shader->texture_hints.ptr();
+ RID *textures = material->textures.ptr();
+ ShaderLanguage::ShaderNode::Uniform::Hint *texture_hints = material->shader->texture_hints.ptr();
+ for (int i = 0; i < tc; i++) {
- for(int i=0;i<tc;i++) {
-
- glActiveTexture(GL_TEXTURE0+i);
+ glActiveTexture(GL_TEXTURE0 + i);
GLenum target;
GLuint tex;
- RasterizerStorageGLES3::Texture *t = texture_owner.getornull( textures[i] );
+ RasterizerStorageGLES3::Texture *t = texture_owner.getornull(textures[i]);
if (!t) {
//check hints
- target=GL_TEXTURE_2D;
+ target = GL_TEXTURE_2D;
- switch(texture_hints[i]) {
+ switch (texture_hints[i]) {
case ShaderLanguage::ShaderNode::Uniform::HINT_BLACK_ALBEDO:
case ShaderLanguage::ShaderNode::Uniform::HINT_BLACK: {
- tex=resources.black_tex;
+ tex = resources.black_tex;
} break;
case ShaderLanguage::ShaderNode::Uniform::HINT_ANISO: {
- tex=resources.aniso_tex;
+ tex = resources.aniso_tex;
} break;
case ShaderLanguage::ShaderNode::Uniform::HINT_NORMAL: {
- tex=resources.normal_tex;
+ tex = resources.normal_tex;
} break;
default: {
- tex=resources.white_tex;
+ tex = resources.white_tex;
} break;
}
-
} else {
- target=t->target;
+ target = t->target;
tex = t->tex_id;
-
}
- glBindTexture(target,tex);
+ glBindTexture(target, tex);
}
-
}
shaders.particles.bind();
- shaders.particles.set_uniform(ParticlesShaderGLES3::ORIGIN,particles->origin);
+ shaders.particles.set_uniform(ParticlesShaderGLES3::ORIGIN, particles->origin);
- float new_phase = Math::fmod((float)particles->phase+(frame.delta/particles->lifetime),(float)1.0);
+ float new_phase = Math::fmod((float)particles->phase + (frame.delta / particles->lifetime), (float)1.0);
- shaders.particles.set_uniform(ParticlesShaderGLES3::SYSTEM_PHASE,new_phase);
- shaders.particles.set_uniform(ParticlesShaderGLES3::PREV_SYSTEM_PHASE,particles->phase);
+ shaders.particles.set_uniform(ParticlesShaderGLES3::SYSTEM_PHASE, new_phase);
+ shaders.particles.set_uniform(ParticlesShaderGLES3::PREV_SYSTEM_PHASE, particles->phase);
particles->phase = new_phase;
- shaders.particles.set_uniform(ParticlesShaderGLES3::TOTAL_PARTICLES,particles->amount);
- shaders.particles.set_uniform(ParticlesShaderGLES3::TIME,0.0);
- shaders.particles.set_uniform(ParticlesShaderGLES3::EXPLOSIVENESS,particles->explosiveness);
- shaders.particles.set_uniform(ParticlesShaderGLES3::DELTA,frame.delta);
- shaders.particles.set_uniform(ParticlesShaderGLES3::GRAVITY,particles->gravity);
- shaders.particles.set_uniform(ParticlesShaderGLES3::ATTRACTOR_COUNT,0);
-
-
+ shaders.particles.set_uniform(ParticlesShaderGLES3::TOTAL_PARTICLES, particles->amount);
+ shaders.particles.set_uniform(ParticlesShaderGLES3::TIME, 0.0);
+ shaders.particles.set_uniform(ParticlesShaderGLES3::EXPLOSIVENESS, particles->explosiveness);
+ shaders.particles.set_uniform(ParticlesShaderGLES3::DELTA, frame.delta);
+ shaders.particles.set_uniform(ParticlesShaderGLES3::GRAVITY, particles->gravity);
+ shaders.particles.set_uniform(ParticlesShaderGLES3::ATTRACTOR_COUNT, 0);
-
- glBindBuffer(GL_ARRAY_BUFFER,particles->particle_buffers[0]);
+ glBindBuffer(GL_ARRAY_BUFFER, particles->particle_buffers[0]);
glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, particles->particle_buffers[1]);
- for(int i=0;i<6;i++) {
+ for (int i = 0; i < 6; i++) {
glEnableVertexAttribArray(i);
- glVertexAttribPointer(i,4,GL_FLOAT,GL_FALSE,sizeof(float)*4*6,((uint8_t*)0)+(i*16));
+ glVertexAttribPointer(i, 4, GL_FLOAT, GL_FALSE, sizeof(float) * 4 * 6, ((uint8_t *)0) + (i * 16));
}
-
glBeginTransformFeedback(GL_POINTS);
- glDrawArrays(GL_POINTS,0,particles->amount);
+ glDrawArrays(GL_POINTS, 0, particles->amount);
glEndTransformFeedback();
particle_update_list.remove(particle_update_list.first());
- SWAP(particles->particle_buffers[0],particles->particle_buffers[1]);
+ SWAP(particles->particle_buffers[0], particles->particle_buffers[1]);
}
glDisable(GL_RASTERIZER_DISCARD);
- for(int i=0;i<6;i++) {
+ for (int i = 0; i < 6; i++) {
glDisableVertexAttribArray(i);
}
-
}
////////
-void RasterizerStorageGLES3::instance_add_skeleton(RID p_skeleton,RasterizerScene::InstanceBase *p_instance) {
+void RasterizerStorageGLES3::instance_add_skeleton(RID p_skeleton, RasterizerScene::InstanceBase *p_instance) {
Skeleton *skeleton = skeleton_owner.getornull(p_skeleton);
ERR_FAIL_COND(!skeleton);
@@ -5427,7 +5106,7 @@ void RasterizerStorageGLES3::instance_add_skeleton(RID p_skeleton,RasterizerScen
skeleton->instances.insert(p_instance);
}
-void RasterizerStorageGLES3::instance_remove_skeleton(RID p_skeleton,RasterizerScene::InstanceBase *p_instance) {
+void RasterizerStorageGLES3::instance_remove_skeleton(RID p_skeleton, RasterizerScene::InstanceBase *p_instance) {
Skeleton *skeleton = skeleton_owner.getornull(p_skeleton);
ERR_FAIL_COND(!skeleton);
@@ -5435,11 +5114,10 @@ void RasterizerStorageGLES3::instance_remove_skeleton(RID p_skeleton,RasterizerS
skeleton->instances.erase(p_instance);
}
+void RasterizerStorageGLES3::instance_add_dependency(RID p_base, RasterizerScene::InstanceBase *p_instance) {
-void RasterizerStorageGLES3::instance_add_dependency(RID p_base,RasterizerScene::InstanceBase *p_instance) {
-
- Instantiable *inst=NULL;
- switch(p_instance->base_type) {
+ Instantiable *inst = NULL;
+ switch (p_instance->base_type) {
case VS::INSTANCE_MESH: {
inst = mesh_owner.getornull(p_base);
ERR_FAIL_COND(!inst);
@@ -5471,14 +5149,14 @@ void RasterizerStorageGLES3::instance_add_dependency(RID p_base,RasterizerScene:
}
}
- inst->instance_list.add( &p_instance->dependency_item );
+ inst->instance_list.add(&p_instance->dependency_item);
}
-void RasterizerStorageGLES3::instance_remove_dependency(RID p_base,RasterizerScene::InstanceBase *p_instance){
+void RasterizerStorageGLES3::instance_remove_dependency(RID p_base, RasterizerScene::InstanceBase *p_instance) {
- Instantiable *inst=NULL;
+ Instantiable *inst = NULL;
- switch(p_instance->base_type) {
+ switch (p_instance->base_type) {
case VS::INSTANCE_MESH: {
inst = mesh_owner.getornull(p_base);
ERR_FAIL_COND(!inst);
@@ -5513,85 +5191,76 @@ void RasterizerStorageGLES3::instance_remove_dependency(RID p_base,RasterizerSce
ERR_FAIL_COND(!inst);
- inst->instance_list.remove( &p_instance->dependency_item );
+ inst->instance_list.remove(&p_instance->dependency_item);
}
-
/* RENDER TARGET */
-
void RasterizerStorageGLES3::_render_target_clear(RenderTarget *rt) {
-
if (rt->fbo) {
- glDeleteFramebuffers(1,&rt->fbo);
- glDeleteTextures(1,&rt->color);
- rt->fbo=0;
+ glDeleteFramebuffers(1, &rt->fbo);
+ glDeleteTextures(1, &rt->color);
+ rt->fbo = 0;
}
-
if (rt->buffers.fbo) {
- glDeleteFramebuffers(1,&rt->buffers.fbo);
- glDeleteRenderbuffers(1,&rt->buffers.depth);
- glDeleteRenderbuffers(1,&rt->buffers.diffuse);
- glDeleteRenderbuffers(1,&rt->buffers.specular);
- glDeleteRenderbuffers(1,&rt->buffers.normal_rough);
- glDeleteRenderbuffers(1,&rt->buffers.motion_sss);
- glDeleteFramebuffers(1,&rt->buffers.effect_fbo);
- glDeleteTextures(1,&rt->buffers.effect);
+ glDeleteFramebuffers(1, &rt->buffers.fbo);
+ glDeleteRenderbuffers(1, &rt->buffers.depth);
+ glDeleteRenderbuffers(1, &rt->buffers.diffuse);
+ glDeleteRenderbuffers(1, &rt->buffers.specular);
+ glDeleteRenderbuffers(1, &rt->buffers.normal_rough);
+ glDeleteRenderbuffers(1, &rt->buffers.motion_sss);
+ glDeleteFramebuffers(1, &rt->buffers.effect_fbo);
+ glDeleteTextures(1, &rt->buffers.effect);
- rt->buffers.fbo=0;
+ rt->buffers.fbo = 0;
}
-
if (rt->depth) {
- glDeleteTextures(1,&rt->depth);
- rt->depth=0;
+ glDeleteTextures(1, &rt->depth);
+ rt->depth = 0;
}
-
if (rt->effects.ssao.blur_fbo[0]) {
- glDeleteFramebuffers(1,&rt->effects.ssao.blur_fbo[0]);
- glDeleteTextures(1,&rt->effects.ssao.blur_red[0]);
- glDeleteFramebuffers(1,&rt->effects.ssao.blur_fbo[1]);
- glDeleteTextures(1,&rt->effects.ssao.blur_red[1]);
- for(int i=0;i<rt->effects.ssao.depth_mipmap_fbos.size();i++) {
- glDeleteFramebuffers(1,&rt->effects.ssao.depth_mipmap_fbos[i]);
+ glDeleteFramebuffers(1, &rt->effects.ssao.blur_fbo[0]);
+ glDeleteTextures(1, &rt->effects.ssao.blur_red[0]);
+ glDeleteFramebuffers(1, &rt->effects.ssao.blur_fbo[1]);
+ glDeleteTextures(1, &rt->effects.ssao.blur_red[1]);
+ for (int i = 0; i < rt->effects.ssao.depth_mipmap_fbos.size(); i++) {
+ glDeleteFramebuffers(1, &rt->effects.ssao.depth_mipmap_fbos[i]);
}
rt->effects.ssao.depth_mipmap_fbos.clear();
- glDeleteTextures(1,&rt->effects.ssao.linear_depth);
+ glDeleteTextures(1, &rt->effects.ssao.linear_depth);
- rt->effects.ssao.blur_fbo[0]=0;
- rt->effects.ssao.blur_fbo[1]=0;
+ rt->effects.ssao.blur_fbo[0] = 0;
+ rt->effects.ssao.blur_fbo[1] = 0;
}
-
if (rt->exposure.fbo) {
- glDeleteFramebuffers(1,&rt->exposure.fbo);
- glDeleteTextures(1,&rt->exposure.color);
- rt->exposure.fbo=0;
+ glDeleteFramebuffers(1, &rt->exposure.fbo);
+ glDeleteTextures(1, &rt->exposure.color);
+ rt->exposure.fbo = 0;
}
Texture *tex = texture_owner.get(rt->texture);
- tex->alloc_height=0;
- tex->alloc_width=0;
- tex->width=0;
- tex->height=0;
-
-
- for(int i=0;i<2;i++) {
- for(int j=0;j<rt->effects.mip_maps[i].sizes.size();j++) {
- glDeleteFramebuffers(1,&rt->effects.mip_maps[i].sizes[j].fbo);
+ tex->alloc_height = 0;
+ tex->alloc_width = 0;
+ tex->width = 0;
+ tex->height = 0;
+
+ for (int i = 0; i < 2; i++) {
+ for (int j = 0; j < rt->effects.mip_maps[i].sizes.size(); j++) {
+ glDeleteFramebuffers(1, &rt->effects.mip_maps[i].sizes[j].fbo);
}
- glDeleteTextures(1,&rt->effects.mip_maps[i].color);
+ glDeleteTextures(1, &rt->effects.mip_maps[i].color);
rt->effects.mip_maps[i].sizes.clear();
- rt->effects.mip_maps[i].levels=0;
+ rt->effects.mip_maps[i].levels = 0;
}
-
-/*
+ /*
if (rt->effects.screen_space_depth) {
glDeleteTextures(1,&rt->effects.screen_space_depth);
rt->effects.screen_space_depth=0;
@@ -5600,9 +5269,9 @@ void RasterizerStorageGLES3::_render_target_clear(RenderTarget *rt) {
*/
}
-void RasterizerStorageGLES3::_render_target_allocate(RenderTarget *rt){
+void RasterizerStorageGLES3::_render_target_allocate(RenderTarget *rt) {
- if (rt->width<=0 || rt->height<=0)
+ if (rt->width <= 0 || rt->height <= 0)
return;
GLuint color_internal_format;
@@ -5611,22 +5280,21 @@ void RasterizerStorageGLES3::_render_target_allocate(RenderTarget *rt){
Image::Format image_format;
bool hdr = rt->flags[RENDER_TARGET_HDR] && config.hdr_supported;
- hdr=false;
+ hdr = false;
if (!hdr || rt->flags[RENDER_TARGET_NO_3D]) {
- color_internal_format=GL_RGBA8;
- color_format=GL_RGBA;
- color_type=GL_UNSIGNED_BYTE;
- image_format=Image::FORMAT_RGBA8;
+ color_internal_format = GL_RGBA8;
+ color_format = GL_RGBA;
+ color_type = GL_UNSIGNED_BYTE;
+ image_format = Image::FORMAT_RGBA8;
} else {
- color_internal_format=GL_RGBA16F;
- color_format=GL_RGBA;
- color_type=GL_HALF_FLOAT;
- image_format=Image::FORMAT_RGBAH;
+ color_internal_format = GL_RGBA16F;
+ color_format = GL_RGBA;
+ color_type = GL_HALF_FLOAT;
+ image_format = Image::FORMAT_RGBAH;
}
-
{
/* FRONT FBO */
@@ -5635,23 +5303,22 @@ void RasterizerStorageGLES3::_render_target_allocate(RenderTarget *rt){
glGenFramebuffers(1, &rt->fbo);
glBindFramebuffer(GL_FRAMEBUFFER, rt->fbo);
-
glGenTextures(1, &rt->depth);
glBindTexture(GL_TEXTURE_2D, rt->depth);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, rt->width, rt->height, 0,
- GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL);
+ GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
- GL_TEXTURE_2D, rt->depth, 0);
+ GL_TEXTURE_2D, rt->depth, 0);
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, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
@@ -5663,36 +5330,31 @@ void RasterizerStorageGLES3::_render_target_allocate(RenderTarget *rt){
glBindFramebuffer(GL_FRAMEBUFFER, RasterizerStorageGLES3::system_fbo);
if (status != GL_FRAMEBUFFER_COMPLETE) {
- printf("framebuffer fail, status: %x\n",status);
+ printf("framebuffer fail, status: %x\n", status);
}
- ERR_FAIL_COND( status != GL_FRAMEBUFFER_COMPLETE );
+ ERR_FAIL_COND(status != GL_FRAMEBUFFER_COMPLETE);
Texture *tex = texture_owner.get(rt->texture);
- tex->format=image_format;
- tex->gl_format_cache=color_format;
- tex->gl_type_cache=color_type;
- tex->gl_internal_format_cache=color_internal_format;
- tex->tex_id=rt->color;
- tex->width=rt->width;
- tex->alloc_width=rt->width;
- tex->height=rt->height;
- tex->alloc_height=rt->height;
-
-
- texture_set_flags(rt->texture,tex->flags);
+ tex->format = image_format;
+ tex->gl_format_cache = color_format;
+ tex->gl_type_cache = color_type;
+ tex->gl_internal_format_cache = color_internal_format;
+ tex->tex_id = rt->color;
+ tex->width = rt->width;
+ tex->alloc_width = rt->width;
+ tex->height = rt->height;
+ tex->alloc_height = rt->height;
+ texture_set_flags(rt->texture, tex->flags);
}
-
/* BACK FBO */
- if (config.render_arch==RENDER_ARCH_DESKTOP && !rt->flags[RENDER_TARGET_NO_3D]) {
-
-
+ if (config.render_arch == RENDER_ARCH_DESKTOP && !rt->flags[RENDER_TARGET_NO_3D]) {
- static const int msaa_value[]={0,2,4,8,16};
- int msaa=msaa_value[rt->msaa];
+ static const int msaa_value[] = { 0, 2, 4, 8, 16 };
+ int msaa = msaa_value[rt->msaa];
//regular fbo
glGenFramebuffers(1, &rt->buffers.fbo);
@@ -5700,66 +5362,63 @@ void RasterizerStorageGLES3::_render_target_allocate(RenderTarget *rt){
glGenRenderbuffers(1, &rt->buffers.depth);
glBindRenderbuffer(GL_RENDERBUFFER, rt->buffers.depth);
- if (msaa==0)
- glRenderbufferStorage(GL_RENDERBUFFER,GL_DEPTH24_STENCIL8,rt->width,rt->height);
+ if (msaa == 0)
+ glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, rt->width, rt->height);
else
- glRenderbufferStorageMultisample(GL_RENDERBUFFER,msaa,GL_DEPTH24_STENCIL8,rt->width,rt->height);
+ glRenderbufferStorageMultisample(GL_RENDERBUFFER, msaa, GL_DEPTH24_STENCIL8, rt->width, rt->height);
+
+ glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rt->buffers.depth);
- glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_RENDERBUFFER,rt->buffers.depth);
-
glGenRenderbuffers(1, &rt->buffers.diffuse);
glBindRenderbuffer(GL_RENDERBUFFER, rt->buffers.diffuse);
- if (msaa==0)
- glRenderbufferStorage(GL_RENDERBUFFER,color_internal_format,rt->width,rt->height);
+ if (msaa == 0)
+ glRenderbufferStorage(GL_RENDERBUFFER, color_internal_format, rt->width, rt->height);
else
- glRenderbufferStorageMultisample(GL_RENDERBUFFER,msaa,color_internal_format,rt->width,rt->height);
+ glRenderbufferStorageMultisample(GL_RENDERBUFFER, msaa, color_internal_format, rt->width, rt->height);
- glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_RENDERBUFFER,rt->buffers.diffuse);
+ glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rt->buffers.diffuse);
glGenRenderbuffers(1, &rt->buffers.specular);
glBindRenderbuffer(GL_RENDERBUFFER, rt->buffers.specular);
- if (msaa==0)
- glRenderbufferStorage(GL_RENDERBUFFER,color_internal_format,rt->width,rt->height);
+ if (msaa == 0)
+ glRenderbufferStorage(GL_RENDERBUFFER, color_internal_format, rt->width, rt->height);
else
- glRenderbufferStorageMultisample(GL_RENDERBUFFER,msaa,color_internal_format,rt->width,rt->height);
+ glRenderbufferStorageMultisample(GL_RENDERBUFFER, msaa, color_internal_format, rt->width, rt->height);
- glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT1,GL_RENDERBUFFER,rt->buffers.specular);
+ glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_RENDERBUFFER, rt->buffers.specular);
glGenRenderbuffers(1, &rt->buffers.normal_rough);
glBindRenderbuffer(GL_RENDERBUFFER, rt->buffers.normal_rough);
- if (msaa==0)
- glRenderbufferStorage(GL_RENDERBUFFER,GL_RGBA8,rt->width,rt->height);
+ if (msaa == 0)
+ glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, rt->width, rt->height);
else
- glRenderbufferStorageMultisample(GL_RENDERBUFFER,msaa,GL_RGBA8,rt->width,rt->height);
-
- glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT2,GL_RENDERBUFFER,rt->buffers.normal_rough);
+ glRenderbufferStorageMultisample(GL_RENDERBUFFER, msaa, GL_RGBA8, rt->width, rt->height);
+ glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, GL_RENDERBUFFER, rt->buffers.normal_rough);
glGenRenderbuffers(1, &rt->buffers.motion_sss);
glBindRenderbuffer(GL_RENDERBUFFER, rt->buffers.motion_sss);
- if (msaa==0)
- glRenderbufferStorage(GL_RENDERBUFFER,GL_RGBA8,rt->width,rt->height);
+ if (msaa == 0)
+ glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, rt->width, rt->height);
else
- glRenderbufferStorageMultisample(GL_RENDERBUFFER,msaa,GL_RGBA8,rt->width,rt->height);
-
- glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT3,GL_RENDERBUFFER,rt->buffers.motion_sss);
-
+ glRenderbufferStorageMultisample(GL_RENDERBUFFER, msaa, GL_RGBA8, rt->width, rt->height);
+ glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT3, GL_RENDERBUFFER, rt->buffers.motion_sss);
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
glBindFramebuffer(GL_FRAMEBUFFER, RasterizerStorageGLES3::system_fbo);
if (status != GL_FRAMEBUFFER_COMPLETE) {
- printf("err status: %x\n",status);
+ printf("err status: %x\n", status);
_render_target_clear(rt);
- ERR_FAIL_COND( status != GL_FRAMEBUFFER_COMPLETE );
- }
+ ERR_FAIL_COND(status != GL_FRAMEBUFFER_COMPLETE);
+ }
- glBindRenderbuffer(GL_RENDERBUFFER,0);
+ glBindRenderbuffer(GL_RENDERBUFFER, 0);
// effect resolver
@@ -5769,92 +5428,84 @@ void RasterizerStorageGLES3::_render_target_allocate(RenderTarget *rt){
glGenTextures(1, &rt->buffers.effect);
glBindTexture(GL_TEXTURE_2D, rt->buffers.effect);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, rt->width, rt->height, 0,
- GL_RGBA, GL_UNSIGNED_BYTE, NULL);
+ GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
- GL_TEXTURE_2D, rt->buffers.effect, 0);
-
+ GL_TEXTURE_2D, rt->buffers.effect, 0);
if (status != GL_FRAMEBUFFER_COMPLETE) {
- printf("err status: %x\n",status);
+ printf("err status: %x\n", status);
_render_target_clear(rt);
- ERR_FAIL_COND( status != GL_FRAMEBUFFER_COMPLETE );
+ ERR_FAIL_COND(status != GL_FRAMEBUFFER_COMPLETE);
}
glBindFramebuffer(GL_FRAMEBUFFER, RasterizerStorageGLES3::system_fbo);
if (status != GL_FRAMEBUFFER_COMPLETE) {
_render_target_clear(rt);
- ERR_FAIL_COND( status != GL_FRAMEBUFFER_COMPLETE );
+ ERR_FAIL_COND(status != GL_FRAMEBUFFER_COMPLETE);
}
- for(int i=0;i<2;i++) {
+ for (int i = 0; i < 2; i++) {
- ERR_FAIL_COND( rt->effects.mip_maps[i].sizes.size() );
- int w=rt->width;
- int h=rt->height;
+ ERR_FAIL_COND(rt->effects.mip_maps[i].sizes.size());
+ int w = rt->width;
+ int h = rt->height;
-
- if (i>0) {
- w>>=1;
- h>>=1;
+ if (i > 0) {
+ w >>= 1;
+ h >>= 1;
}
-
glGenTextures(1, &rt->effects.mip_maps[i].color);
glBindTexture(GL_TEXTURE_2D, rt->effects.mip_maps[i].color);
- int level=0;
+ int level = 0;
- while(true) {
+ while (true) {
RenderTarget::Effects::MipMaps::Size mm;
- glTexImage2D(GL_TEXTURE_2D, level, color_internal_format, w, h, 0, color_format, color_type, NULL);
- mm.width=w;
- mm.height=h;
+ glTexImage2D(GL_TEXTURE_2D, level, color_internal_format, w, h, 0, color_format, color_type, NULL);
+ mm.width = w;
+ mm.height = h;
rt->effects.mip_maps[i].sizes.push_back(mm);
- w>>=1;
- h>>=1;
+ w >>= 1;
+ h >>= 1;
- if (w<2 || h<2)
+ if (w < 2 || h < 2)
break;
level++;
-
}
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, level);
+ for (int j = 0; j < rt->effects.mip_maps[i].sizes.size(); j++) {
- for(int j=0;j<rt->effects.mip_maps[i].sizes.size();j++) {
-
- RenderTarget::Effects::MipMaps::Size &mm=rt->effects.mip_maps[i].sizes[j];
+ RenderTarget::Effects::MipMaps::Size &mm = rt->effects.mip_maps[i].sizes[j];
glGenFramebuffers(1, &mm.fbo);
glBindFramebuffer(GL_FRAMEBUFFER, mm.fbo);
- glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,rt->effects.mip_maps[i].color ,j);
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, rt->effects.mip_maps[i].color, j);
status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if (status != GL_FRAMEBUFFER_COMPLETE) {
_render_target_clear(rt);
- ERR_FAIL_COND( status != GL_FRAMEBUFFER_COMPLETE );
+ ERR_FAIL_COND(status != GL_FRAMEBUFFER_COMPLETE);
}
-
- float zero[4]={1,0,1,0};
- glClearBufferfv(GL_COLOR,0,zero);
-
-
+ float zero[4] = { 1, 0, 1, 0 };
+ glClearBufferfv(GL_COLOR, 0, zero);
}
glBindFramebuffer(GL_FRAMEBUFFER, RasterizerStorageGLES3::system_fbo);
- rt->effects.mip_maps[i].levels=level;
+ rt->effects.mip_maps[i].levels = level;
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
@@ -5862,23 +5513,21 @@ void RasterizerStorageGLES3::_render_target_allocate(RenderTarget *rt){
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
-
-
}
///////////////// ssao
//AO strength textures
- for(int i=0;i<2;i++) {
+ for (int i = 0; i < 2; i++) {
glGenFramebuffers(1, &rt->effects.ssao.blur_fbo[i]);
glBindFramebuffer(GL_FRAMEBUFFER, rt->effects.ssao.blur_fbo[i]);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
- GL_TEXTURE_2D, rt->depth, 0);
+ GL_TEXTURE_2D, rt->depth, 0);
glGenTextures(1, &rt->effects.ssao.blur_red[i]);
glBindTexture(GL_TEXTURE_2D, rt->effects.ssao.blur_red[i]);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, rt->width, rt->height, 0, GL_RED, GL_UNSIGNED_BYTE, NULL);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, rt->width, rt->height, 0, GL_RED, GL_UNSIGNED_BYTE, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
@@ -5889,24 +5538,22 @@ void RasterizerStorageGLES3::_render_target_allocate(RenderTarget *rt){
status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if (status != GL_FRAMEBUFFER_COMPLETE) {
_render_target_clear(rt);
- ERR_FAIL_COND( status != GL_FRAMEBUFFER_COMPLETE );
+ ERR_FAIL_COND(status != GL_FRAMEBUFFER_COMPLETE);
}
-
}
//5 mip levels for depth texture, but base is read separately
glGenTextures(1, &rt->effects.ssao.linear_depth);
glBindTexture(GL_TEXTURE_2D, rt->effects.ssao.linear_depth);
- int ssao_w=rt->width/2;
- int ssao_h=rt->height/2;
+ int ssao_w = rt->width / 2;
+ int ssao_h = rt->height / 2;
+ for (int i = 0; i < 4; i++) { //5, but 4 mips, base is read directly to save bw
- for(int i=0;i<4;i++) { //5, but 4 mips, base is read directly to save bw
-
- glTexImage2D(GL_TEXTURE_2D, i, GL_R16UI, ssao_w, ssao_h, 0, GL_RED_INTEGER, GL_UNSIGNED_SHORT, NULL);
- ssao_w>>=1;
- ssao_h>>=1;
+ glTexImage2D(GL_TEXTURE_2D, i, GL_R16UI, ssao_w, ssao_h, 0, GL_RED_INTEGER, GL_UNSIGNED_SHORT, NULL);
+ ssao_w >>= 1;
+ ssao_h >>= 1;
}
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
@@ -5916,7 +5563,7 @@ void RasterizerStorageGLES3::_render_target_allocate(RenderTarget *rt){
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 3);
- for(int i=0;i<4;i++) { //5, but 4 mips, base is read directly to save bw
+ for (int i = 0; i < 4; i++) { //5, but 4 mips, base is read directly to save bw
GLuint fbo;
glGenFramebuffers(1, &fbo);
@@ -5925,7 +5572,6 @@ void RasterizerStorageGLES3::_render_target_allocate(RenderTarget *rt){
rt->effects.ssao.depth_mipmap_fbos.push_back(fbo);
}
-
//////Exposure
glGenFramebuffers(1, &rt->exposure.fbo);
@@ -5933,82 +5579,77 @@ void RasterizerStorageGLES3::_render_target_allocate(RenderTarget *rt){
glGenTextures(1, &rt->exposure.color);
glBindTexture(GL_TEXTURE_2D, rt->exposure.color);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_R32F, 1, 1, 0, GL_RED, GL_FLOAT, NULL);
- glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, rt->exposure.color, 0);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_R32F, 1, 1, 0, GL_RED, GL_FLOAT, NULL);
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, rt->exposure.color, 0);
status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if (status != GL_FRAMEBUFFER_COMPLETE) {
_render_target_clear(rt);
- ERR_FAIL_COND( status != GL_FRAMEBUFFER_COMPLETE );
+ ERR_FAIL_COND(status != GL_FRAMEBUFFER_COMPLETE);
}
-
}
}
+RID RasterizerStorageGLES3::render_target_create() {
-RID RasterizerStorageGLES3::render_target_create(){
-
- RenderTarget *rt = memnew( RenderTarget );
+ RenderTarget *rt = memnew(RenderTarget);
- Texture * t = memnew( Texture );
+ Texture *t = memnew(Texture);
- t->flags=0;
- t->width=0;
- t->height=0;
- t->alloc_height=0;
- t->alloc_width=0;
- t->format=Image::FORMAT_R8;
- t->target=GL_TEXTURE_2D;
- t->gl_format_cache=0;
- t->gl_internal_format_cache=0;
- t->gl_type_cache=0;
- t->data_size=0;
- t->compressed=false;
- t->srgb=false;
- t->total_data_size=0;
- t->ignore_mipmaps=false;
- t->mipmaps=0;
- t->active=true;
- t->tex_id=0;
+ t->flags = 0;
+ t->width = 0;
+ t->height = 0;
+ t->alloc_height = 0;
+ t->alloc_width = 0;
+ t->format = Image::FORMAT_R8;
+ t->target = GL_TEXTURE_2D;
+ t->gl_format_cache = 0;
+ t->gl_internal_format_cache = 0;
+ t->gl_type_cache = 0;
+ t->data_size = 0;
+ t->compressed = false;
+ t->srgb = false;
+ t->total_data_size = 0;
+ t->ignore_mipmaps = false;
+ t->mipmaps = 0;
+ t->active = true;
+ t->tex_id = 0;
-
- rt->texture=texture_owner.make_rid(t);
+ rt->texture = texture_owner.make_rid(t);
return render_target_owner.make_rid(rt);
}
-void RasterizerStorageGLES3::render_target_set_size(RID p_render_target,int p_width, int p_height){
+void RasterizerStorageGLES3::render_target_set_size(RID p_render_target, int p_width, int p_height) {
RenderTarget *rt = render_target_owner.getornull(p_render_target);
ERR_FAIL_COND(!rt);
- if (rt->width==p_width && rt->height==p_height)
+ if (rt->width == p_width && rt->height == p_height)
return;
_render_target_clear(rt);
- rt->width=p_width;
- rt->height=p_height;
+ rt->width = p_width;
+ rt->height = p_height;
_render_target_allocate(rt);
-
}
-
-RID RasterizerStorageGLES3::render_target_get_texture(RID p_render_target) const{
+RID RasterizerStorageGLES3::render_target_get_texture(RID p_render_target) const {
RenderTarget *rt = render_target_owner.getornull(p_render_target);
- ERR_FAIL_COND_V(!rt,RID());
+ ERR_FAIL_COND_V(!rt, RID());
return rt->texture;
}
-void RasterizerStorageGLES3::render_target_set_flag(RID p_render_target,RenderTargetFlags p_flag,bool p_value) {
+void RasterizerStorageGLES3::render_target_set_flag(RID p_render_target, RenderTargetFlags p_flag, bool p_value) {
RenderTarget *rt = render_target_owner.getornull(p_render_target);
ERR_FAIL_COND(!rt);
- rt->flags[p_flag]=p_value;
+ rt->flags[p_flag] = p_value;
- switch(p_flag) {
+ switch (p_flag) {
case RENDER_TARGET_NO_3D:
case RENDER_TARGET_TRANSPARENT: {
//must reset for these formats
@@ -6020,36 +5661,34 @@ void RasterizerStorageGLES3::render_target_set_flag(RID p_render_target,RenderTa
}
}
-bool RasterizerStorageGLES3::render_target_renedered_in_frame(RID p_render_target){
+bool RasterizerStorageGLES3::render_target_renedered_in_frame(RID p_render_target) {
return false;
}
-void RasterizerStorageGLES3::render_target_set_msaa(RID p_render_target,VS::ViewportMSAA p_msaa) {
+void RasterizerStorageGLES3::render_target_set_msaa(RID p_render_target, VS::ViewportMSAA p_msaa) {
RenderTarget *rt = render_target_owner.getornull(p_render_target);
ERR_FAIL_COND(!rt);
- if (rt->msaa==p_msaa)
+ if (rt->msaa == p_msaa)
return;
_render_target_clear(rt);
- rt->msaa=p_msaa;
+ rt->msaa = p_msaa;
_render_target_allocate(rt);
-
}
/* CANVAS SHADOW */
-
RID RasterizerStorageGLES3::canvas_light_shadow_buffer_create(int p_width) {
- CanvasLightShadow *cls = memnew( CanvasLightShadow );
- if (p_width>config.max_texture_size)
- p_width=config.max_texture_size;
+ CanvasLightShadow *cls = memnew(CanvasLightShadow);
+ if (p_width > config.max_texture_size)
+ p_width = config.max_texture_size;
- cls->size=p_width;
- cls->height=16;
+ cls->size = p_width;
+ cls->height = 16;
glActiveTexture(GL_TEXTURE0);
@@ -6057,12 +5696,12 @@ RID RasterizerStorageGLES3::canvas_light_shadow_buffer_create(int p_width) {
glBindFramebuffer(GL_FRAMEBUFFER, cls->fbo);
glGenRenderbuffers(1, &cls->depth);
- glBindRenderbuffer(GL_RENDERBUFFER, cls->depth );
- glRenderbufferStorage(GL_RENDERBUFFER,GL_DEPTH_COMPONENT24, cls->size, cls->height);
+ glBindRenderbuffer(GL_RENDERBUFFER, cls->depth);
+ glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, cls->size, cls->height);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, cls->depth);
- glBindRenderbuffer(GL_RENDERBUFFER, 0 );
+ glBindRenderbuffer(GL_RENDERBUFFER, 0);
- glGenTextures(1,&cls->distance);
+ glGenTextures(1, &cls->distance);
glBindTexture(GL_TEXTURE_2D, cls->distance);
if (config.use_rgba_2d_shadows) {
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, cls->size, cls->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
@@ -6070,139 +5709,124 @@ RID RasterizerStorageGLES3::canvas_light_shadow_buffer_create(int p_width) {
glTexImage2D(GL_TEXTURE_2D, 0, GL_R32F, cls->size, cls->height, 0, GL_RED, GL_FLOAT, NULL);
}
-
-
-
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, cls->distance, 0);
-
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
//printf("errnum: %x\n",status);
glBindFramebuffer(GL_FRAMEBUFFER, RasterizerStorageGLES3::system_fbo);
- ERR_FAIL_COND_V( status != GL_FRAMEBUFFER_COMPLETE, RID() );
+ ERR_FAIL_COND_V(status != GL_FRAMEBUFFER_COMPLETE, RID());
return canvas_light_shadow_owner.make_rid(cls);
}
/* LIGHT SHADOW MAPPING */
-
RID RasterizerStorageGLES3::canvas_light_occluder_create() {
- CanvasOccluder *co = memnew( CanvasOccluder );
- co->index_id=0;
- co->vertex_id=0;
- co->len=0;
+ CanvasOccluder *co = memnew(CanvasOccluder);
+ co->index_id = 0;
+ co->vertex_id = 0;
+ co->len = 0;
return canvas_occluder_owner.make_rid(co);
}
-void RasterizerStorageGLES3::canvas_light_occluder_set_polylines(RID p_occluder, const PoolVector<Vector2>& p_lines) {
+void RasterizerStorageGLES3::canvas_light_occluder_set_polylines(RID p_occluder, const PoolVector<Vector2> &p_lines) {
CanvasOccluder *co = canvas_occluder_owner.get(p_occluder);
ERR_FAIL_COND(!co);
- co->lines=p_lines;
+ co->lines = p_lines;
- if (p_lines.size()!=co->len) {
+ if (p_lines.size() != co->len) {
if (co->index_id)
- glDeleteBuffers(1,&co->index_id);
+ glDeleteBuffers(1, &co->index_id);
if (co->vertex_id)
- glDeleteBuffers(1,&co->vertex_id);
-
- co->index_id=0;
- co->vertex_id=0;
- co->len=0;
+ glDeleteBuffers(1, &co->vertex_id);
+ co->index_id = 0;
+ co->vertex_id = 0;
+ co->len = 0;
}
if (p_lines.size()) {
-
-
PoolVector<float> geometry;
PoolVector<uint16_t> indices;
int lc = p_lines.size();
- geometry.resize(lc*6);
- indices.resize(lc*3);
+ geometry.resize(lc * 6);
+ indices.resize(lc * 3);
- PoolVector<float>::Write vw=geometry.write();
- PoolVector<uint16_t>::Write iw=indices.write();
+ PoolVector<float>::Write vw = geometry.write();
+ PoolVector<uint16_t>::Write iw = indices.write();
-
- PoolVector<Vector2>::Read lr=p_lines.read();
+ PoolVector<Vector2>::Read lr = p_lines.read();
const int POLY_HEIGHT = 16384;
- for(int i=0;i<lc/2;i++) {
-
- vw[i*12+0]=lr[i*2+0].x;
- vw[i*12+1]=lr[i*2+0].y;
- vw[i*12+2]=POLY_HEIGHT;
+ for (int i = 0; i < lc / 2; i++) {
- vw[i*12+3]=lr[i*2+1].x;
- vw[i*12+4]=lr[i*2+1].y;
- vw[i*12+5]=POLY_HEIGHT;
+ vw[i * 12 + 0] = lr[i * 2 + 0].x;
+ vw[i * 12 + 1] = lr[i * 2 + 0].y;
+ vw[i * 12 + 2] = POLY_HEIGHT;
- vw[i*12+6]=lr[i*2+1].x;
- vw[i*12+7]=lr[i*2+1].y;
- vw[i*12+8]=-POLY_HEIGHT;
+ vw[i * 12 + 3] = lr[i * 2 + 1].x;
+ vw[i * 12 + 4] = lr[i * 2 + 1].y;
+ vw[i * 12 + 5] = POLY_HEIGHT;
- vw[i*12+9]=lr[i*2+0].x;
- vw[i*12+10]=lr[i*2+0].y;
- vw[i*12+11]=-POLY_HEIGHT;
+ vw[i * 12 + 6] = lr[i * 2 + 1].x;
+ vw[i * 12 + 7] = lr[i * 2 + 1].y;
+ vw[i * 12 + 8] = -POLY_HEIGHT;
- iw[i*6+0]=i*4+0;
- iw[i*6+1]=i*4+1;
- iw[i*6+2]=i*4+2;
+ vw[i * 12 + 9] = lr[i * 2 + 0].x;
+ vw[i * 12 + 10] = lr[i * 2 + 0].y;
+ vw[i * 12 + 11] = -POLY_HEIGHT;
- iw[i*6+3]=i*4+2;
- iw[i*6+4]=i*4+3;
- iw[i*6+5]=i*4+0;
+ iw[i * 6 + 0] = i * 4 + 0;
+ iw[i * 6 + 1] = i * 4 + 1;
+ iw[i * 6 + 2] = i * 4 + 2;
+ iw[i * 6 + 3] = i * 4 + 2;
+ iw[i * 6 + 4] = i * 4 + 3;
+ iw[i * 6 + 5] = i * 4 + 0;
}
//if same buffer len is being set, just use BufferSubData to avoid a pipeline flush
-
if (!co->vertex_id) {
- glGenBuffers(1,&co->vertex_id);
- glBindBuffer(GL_ARRAY_BUFFER,co->vertex_id);
- glBufferData(GL_ARRAY_BUFFER,lc*6*sizeof(real_t),vw.ptr(),GL_STATIC_DRAW);
+ glGenBuffers(1, &co->vertex_id);
+ glBindBuffer(GL_ARRAY_BUFFER, co->vertex_id);
+ glBufferData(GL_ARRAY_BUFFER, lc * 6 * sizeof(real_t), vw.ptr(), GL_STATIC_DRAW);
} else {
- glBindBuffer(GL_ARRAY_BUFFER,co->vertex_id);
- glBufferSubData(GL_ARRAY_BUFFER,0,lc*6*sizeof(real_t),vw.ptr());
-
+ glBindBuffer(GL_ARRAY_BUFFER, co->vertex_id);
+ glBufferSubData(GL_ARRAY_BUFFER, 0, lc * 6 * sizeof(real_t), vw.ptr());
}
- glBindBuffer(GL_ARRAY_BUFFER,0); //unbind
+ glBindBuffer(GL_ARRAY_BUFFER, 0); //unbind
if (!co->index_id) {
- glGenBuffers(1,&co->index_id);
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,co->index_id);
- glBufferData(GL_ELEMENT_ARRAY_BUFFER,lc*3*sizeof(uint16_t),iw.ptr(),GL_STATIC_DRAW);
+ glGenBuffers(1, &co->index_id);
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, co->index_id);
+ glBufferData(GL_ELEMENT_ARRAY_BUFFER, lc * 3 * sizeof(uint16_t), iw.ptr(), GL_STATIC_DRAW);
} else {
-
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,co->index_id);
- glBufferSubData(GL_ELEMENT_ARRAY_BUFFER,0,lc*3*sizeof(uint16_t),iw.ptr());
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, co->index_id);
+ glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, lc * 3 * sizeof(uint16_t), iw.ptr());
}
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0); //unbind
-
- co->len=lc;
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); //unbind
+ co->len = lc;
}
-
}
VS::InstanceType RasterizerStorageGLES3::get_base_type(RID p_rid) const {
@@ -6234,13 +5858,13 @@ VS::InstanceType RasterizerStorageGLES3::get_base_type(RID p_rid) const {
return VS::INSTANCE_NONE;
}
-bool RasterizerStorageGLES3::free(RID p_rid){
+bool RasterizerStorageGLES3::free(RID p_rid) {
if (render_target_owner.owns(p_rid)) {
RenderTarget *rt = render_target_owner.getornull(p_rid);
_render_target_clear(rt);
- Texture *t=texture_owner.get(rt->texture);
+ Texture *t = texture_owner.get(rt->texture);
texture_owner.free(rt->texture);
memdelete(t);
render_target_owner.free(p_rid);
@@ -6249,14 +5873,14 @@ bool RasterizerStorageGLES3::free(RID p_rid){
} else if (texture_owner.owns(p_rid)) {
// delete the texture
Texture *texture = texture_owner.get(p_rid);
- ERR_FAIL_COND_V(texture->render_target,true); //cant free the render target texture, dude
- info.texture_mem-=texture->total_data_size;
+ ERR_FAIL_COND_V(texture->render_target, true); //cant free the render target texture, dude
+ info.texture_mem -= texture->total_data_size;
texture_owner.free(p_rid);
memdelete(texture);
} else if (skybox_owner.owns(p_rid)) {
// delete the skybox
SkyBox *skybox = skybox_owner.get(p_rid);
- skybox_set_texture(p_rid,RID(),256);
+ skybox_set_texture(p_rid, RID(), 256);
skybox_owner.free(p_rid);
memdelete(skybox);
@@ -6265,7 +5889,6 @@ bool RasterizerStorageGLES3::free(RID p_rid){
// delete the texture
Shader *shader = shader_owner.get(p_rid);
-
if (shader->shader)
shader->shader->free_custom_shader(shader->custom_code_id);
@@ -6276,10 +5899,10 @@ bool RasterizerStorageGLES3::free(RID p_rid){
Material *mat = shader->materials.first()->self();
- mat->shader=NULL;
+ mat->shader = NULL;
_material_make_dirty(mat);
- shader->materials.remove( shader->materials.first() );
+ shader->materials.remove(shader->materials.first());
}
//material_shader.free_custom_shader(shader->custom_code_id);
@@ -6292,31 +5915,30 @@ bool RasterizerStorageGLES3::free(RID p_rid){
Material *material = material_owner.get(p_rid);
if (material->shader) {
- material->shader->materials.remove( & material->list );
+ material->shader->materials.remove(&material->list);
}
if (material->ubo_id) {
- glDeleteBuffers(1,&material->ubo_id);
+ glDeleteBuffers(1, &material->ubo_id);
}
//remove from owners
- for (Map<Geometry*,int>::Element *E=material->geometry_owners.front();E;E=E->next()) {
+ for (Map<Geometry *, int>::Element *E = material->geometry_owners.front(); E; E = E->next()) {
Geometry *g = E->key();
- g->material=RID();
+ g->material = RID();
}
- for (Map<RasterizerScene::InstanceBase*,int>::Element *E=material->instance_owners.front();E;E=E->next()) {
- RasterizerScene::InstanceBase*ins=E->key();
- if (ins->material_override==p_rid) {
- ins->material_override=RID();
+ for (Map<RasterizerScene::InstanceBase *, int>::Element *E = material->instance_owners.front(); E; E = E->next()) {
+ RasterizerScene::InstanceBase *ins = E->key();
+ if (ins->material_override == p_rid) {
+ ins->material_override = RID();
}
- for(int i=0;i<ins->materials.size();i++) {
- if (ins->materials[i]==p_rid) {
- ins->materials[i]=RID();
+ for (int i = 0; i < ins->materials.size(); i++) {
+ if (ins->materials[i] == p_rid) {
+ ins->materials[i] = RID();
}
}
-
}
material_owner.free(p_rid);
@@ -6330,11 +5952,11 @@ bool RasterizerStorageGLES3::free(RID p_rid){
skeleton_update_list.remove(&skeleton->update_list);
}
- for (Set<RasterizerScene::InstanceBase*>::Element *E=skeleton->instances.front();E;E=E->next()) {
- E->get()->skeleton=RID();
+ for (Set<RasterizerScene::InstanceBase *>::Element *E = skeleton->instances.front(); E; E = E->next()) {
+ E->get()->skeleton = RID();
}
- skeleton_allocate(p_rid,0,false);
+ skeleton_allocate(p_rid, 0, false);
skeleton_owner.free(p_rid);
memdelete(skeleton);
@@ -6345,16 +5967,15 @@ bool RasterizerStorageGLES3::free(RID p_rid){
mesh->instance_remove_deps();
mesh_clear(p_rid);
- while(mesh->multimeshes.first()) {
+ while (mesh->multimeshes.first()) {
MultiMesh *multimesh = mesh->multimeshes.first()->self();
- multimesh->mesh=RID();
- multimesh->dirty_aabb=true;
+ multimesh->mesh = RID();
+ multimesh->dirty_aabb = true;
mesh->multimeshes.remove(mesh->multimeshes.first());
if (!multimesh->update_list.in_list()) {
multimesh_update_list.add(&multimesh->update_list);
}
-
}
mesh_owner.free(p_rid);
@@ -6373,10 +5994,9 @@ bool RasterizerStorageGLES3::free(RID p_rid){
}
}
- multimesh_allocate(p_rid,0,VS::MULTIMESH_TRANSFORM_2D,VS::MULTIMESH_COLOR_NONE); //frees multimesh
+ multimesh_allocate(p_rid, 0, VS::MULTIMESH_TRANSFORM_2D, VS::MULTIMESH_COLOR_NONE); //frees multimesh
update_dirty_multimeshes();
-
multimesh_owner.free(p_rid);
memdelete(multimesh);
} else if (immediate_owner.owns(p_rid)) {
@@ -6409,7 +6029,6 @@ bool RasterizerStorageGLES3::free(RID p_rid){
// delete the texture
GIProbe *gi_probe = gi_probe_owner.get(p_rid);
-
gi_probe_owner.free(p_rid);
memdelete(gi_probe);
} else if (gi_probe_data_owner.owns(p_rid)) {
@@ -6418,18 +6037,17 @@ bool RasterizerStorageGLES3::free(RID p_rid){
GIProbeData *gi_probe_data = gi_probe_data_owner.get(p_rid);
print_line("dyndata delete");
- glDeleteTextures(1,&gi_probe_data->tex_id);
+ glDeleteTextures(1, &gi_probe_data->tex_id);
gi_probe_owner.free(p_rid);
memdelete(gi_probe_data);
} else if (canvas_occluder_owner.owns(p_rid)) {
-
CanvasOccluder *co = canvas_occluder_owner.get(p_rid);
if (co->index_id)
- glDeleteBuffers(1,&co->index_id);
+ glDeleteBuffers(1, &co->index_id);
if (co->vertex_id)
- glDeleteBuffers(1,&co->vertex_id);
+ glDeleteBuffers(1, &co->vertex_id);
canvas_occluder_owner.free(p_rid);
memdelete(co);
@@ -6437,9 +6055,9 @@ bool RasterizerStorageGLES3::free(RID p_rid){
} else if (canvas_light_shadow_owner.owns(p_rid)) {
CanvasLightShadow *cls = canvas_light_shadow_owner.get(p_rid);
- glDeleteFramebuffers(1,&cls->fbo);
- glDeleteRenderbuffers(1,&cls->depth);
- glDeleteTextures(1,&cls->distance);
+ glDeleteFramebuffers(1, &cls->fbo);
+ glDeleteRenderbuffers(1, &cls->depth);
+ glDeleteTextures(1, &cls->distance);
canvas_light_shadow_owner.free(p_rid);
memdelete(cls);
} else {
@@ -6449,206 +6067,193 @@ bool RasterizerStorageGLES3::free(RID p_rid){
return true;
}
+bool RasterizerStorageGLES3::has_os_feature(const String &p_feature) const {
-bool RasterizerStorageGLES3::has_os_feature(const String& p_feature) const {
-
- if (p_feature=="s3tc")
+ if (p_feature == "s3tc")
return config.s3tc_supported;
- if (p_feature=="etc")
+ if (p_feature == "etc")
return config.etc_supported;
- if (p_feature=="etc2")
+ if (p_feature == "etc2")
return config.etc2_supported;
- if (p_feature=="pvrtc")
+ if (p_feature == "pvrtc")
return config.pvrtc_supported;
return false;
-
}
////////////////////////////////////////////
-
void RasterizerStorageGLES3::initialize() {
- config.render_arch=RENDER_ARCH_DESKTOP;
+ config.render_arch = RENDER_ARCH_DESKTOP;
//config.fbo_deferred=int(Globals::get_singleton()->get("rendering/gles3/lighting_technique"));
- RasterizerStorageGLES3::system_fbo=0;
-
+ RasterizerStorageGLES3::system_fbo = 0;
//// extensions config
///
{
- int max_extensions=0;
+ int max_extensions = 0;
print_line("getting extensions");
- glGetIntegerv(GL_NUM_EXTENSIONS,&max_extensions);
- print_line("total "+itos(max_extensions));
- for(int i=0;i<max_extensions;i++) {
- const GLubyte *s = glGetStringi( GL_EXTENSIONS,i );
+ glGetIntegerv(GL_NUM_EXTENSIONS, &max_extensions);
+ print_line("total " + itos(max_extensions));
+ for (int i = 0; i < max_extensions; i++) {
+ const GLubyte *s = glGetStringi(GL_EXTENSIONS, i);
if (!s)
break;
- config.extensions.insert((const char*)s);
+ config.extensions.insert((const char *)s);
}
}
- config.shrink_textures_x2=false;
- config.use_fast_texture_filter=int(GlobalConfig::get_singleton()->get("rendering/quality/use_nearest_mipmap_filter"));
+ config.shrink_textures_x2 = false;
+ config.use_fast_texture_filter = int(GlobalConfig::get_singleton()->get("rendering/quality/use_nearest_mipmap_filter"));
config.use_anisotropic_filter = config.extensions.has("GL_EXT_texture_filter_anisotropic");
- config.s3tc_supported=config.extensions.has("GL_EXT_texture_compression_dxt1") || config.extensions.has("GL_EXT_texture_compression_s3tc") || config.extensions.has("WEBGL_compressed_texture_s3tc");
- config.etc_supported=config.extensions.has("GL_OES_compressed_ETC1_RGB8_texture");
- config.latc_supported=config.extensions.has("GL_EXT_texture_compression_latc");
- config.bptc_supported=config.extensions.has("GL_ARB_texture_compression_bptc");
+ config.s3tc_supported = config.extensions.has("GL_EXT_texture_compression_dxt1") || config.extensions.has("GL_EXT_texture_compression_s3tc") || config.extensions.has("WEBGL_compressed_texture_s3tc");
+ config.etc_supported = config.extensions.has("GL_OES_compressed_ETC1_RGB8_texture");
+ config.latc_supported = config.extensions.has("GL_EXT_texture_compression_latc");
+ config.bptc_supported = config.extensions.has("GL_ARB_texture_compression_bptc");
#ifdef GLES_OVER_GL
- config.hdr_supported=true;
- config.etc2_supported=false;
+ config.hdr_supported = true;
+ config.etc2_supported = false;
#else
- config.etc2_supported=true;
- config.hdr_supported=false;
+ config.etc2_supported = true;
+ config.hdr_supported = false;
#endif
- config.pvrtc_supported=config.extensions.has("GL_IMG_texture_compression_pvrtc");
- config.srgb_decode_supported=config.extensions.has("GL_EXT_texture_sRGB_decode");
-
+ config.pvrtc_supported = config.extensions.has("GL_IMG_texture_compression_pvrtc");
+ config.srgb_decode_supported = config.extensions.has("GL_EXT_texture_sRGB_decode");
-
- config.anisotropic_level=1.0;
- config.use_anisotropic_filter=config.extensions.has("GL_EXT_texture_filter_anisotropic");
+ config.anisotropic_level = 1.0;
+ config.use_anisotropic_filter = config.extensions.has("GL_EXT_texture_filter_anisotropic");
if (config.use_anisotropic_filter) {
- glGetFloatv(_GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT,&config.anisotropic_level);
- config.anisotropic_level=MIN(int(GlobalConfig::get_singleton()->get("rendering/quality/anisotropic_filter_level")),config.anisotropic_level);
+ glGetFloatv(_GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &config.anisotropic_level);
+ config.anisotropic_level = MIN(int(GlobalConfig::get_singleton()->get("rendering/quality/anisotropic_filter_level")), config.anisotropic_level);
}
-
- frame.clear_request=false;
+ frame.clear_request = false;
shaders.copy.init();
{
//default textures
-
glGenTextures(1, &resources.white_tex);
- unsigned char whitetexdata[8*8*3];
- for(int i=0;i<8*8*3;i++) {
- whitetexdata[i]=255;
+ unsigned char whitetexdata[8 * 8 * 3];
+ for (int i = 0; i < 8 * 8 * 3; i++) {
+ whitetexdata[i] = 255;
}
glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D,resources.white_tex);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 8, 8, 0, GL_RGB, GL_UNSIGNED_BYTE,whitetexdata);
+ glBindTexture(GL_TEXTURE_2D, resources.white_tex);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 8, 8, 0, GL_RGB, GL_UNSIGNED_BYTE, whitetexdata);
glGenerateMipmap(GL_TEXTURE_2D);
- glBindTexture(GL_TEXTURE_2D,0);
+ glBindTexture(GL_TEXTURE_2D, 0);
glGenTextures(1, &resources.black_tex);
- unsigned char blacktexdata[8*8*3];
- for(int i=0;i<8*8*3;i++) {
- blacktexdata[i]=0;
+ unsigned char blacktexdata[8 * 8 * 3];
+ for (int i = 0; i < 8 * 8 * 3; i++) {
+ blacktexdata[i] = 0;
}
glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D,resources.black_tex);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 8, 8, 0, GL_RGB, GL_UNSIGNED_BYTE,blacktexdata);
+ glBindTexture(GL_TEXTURE_2D, resources.black_tex);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 8, 8, 0, GL_RGB, GL_UNSIGNED_BYTE, blacktexdata);
glGenerateMipmap(GL_TEXTURE_2D);
- glBindTexture(GL_TEXTURE_2D,0);
+ glBindTexture(GL_TEXTURE_2D, 0);
glGenTextures(1, &resources.normal_tex);
- unsigned char normaltexdata[8*8*3];
- for(int i=0;i<8*8*3;i+=3) {
- normaltexdata[i+0]=128;
- normaltexdata[i+1]=128;
- normaltexdata[i+2]=255;
+ unsigned char normaltexdata[8 * 8 * 3];
+ for (int i = 0; i < 8 * 8 * 3; i += 3) {
+ normaltexdata[i + 0] = 128;
+ normaltexdata[i + 1] = 128;
+ normaltexdata[i + 2] = 255;
}
glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D,resources.normal_tex);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 8, 8, 0, GL_RGB, GL_UNSIGNED_BYTE,normaltexdata);
+ glBindTexture(GL_TEXTURE_2D, resources.normal_tex);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 8, 8, 0, GL_RGB, GL_UNSIGNED_BYTE, normaltexdata);
glGenerateMipmap(GL_TEXTURE_2D);
- glBindTexture(GL_TEXTURE_2D,0);
-
+ glBindTexture(GL_TEXTURE_2D, 0);
glGenTextures(1, &resources.aniso_tex);
- unsigned char anisotexdata[8*8*3];
- for(int i=0;i<8*8*3;i+=3) {
- anisotexdata[i+0]=255;
- anisotexdata[i+1]=128;
- anisotexdata[i+2]=0;
+ unsigned char anisotexdata[8 * 8 * 3];
+ for (int i = 0; i < 8 * 8 * 3; i += 3) {
+ anisotexdata[i + 0] = 255;
+ anisotexdata[i + 1] = 128;
+ anisotexdata[i + 2] = 0;
}
glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D,resources.aniso_tex);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 8, 8, 0, GL_RGB, GL_UNSIGNED_BYTE,anisotexdata);
+ glBindTexture(GL_TEXTURE_2D, resources.aniso_tex);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 8, 8, 0, GL_RGB, GL_UNSIGNED_BYTE, anisotexdata);
glGenerateMipmap(GL_TEXTURE_2D);
- glBindTexture(GL_TEXTURE_2D,0);
-
+ glBindTexture(GL_TEXTURE_2D, 0);
}
- glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS,&config.max_texture_image_units);
- glGetIntegerv(GL_MAX_TEXTURE_SIZE,&config.max_texture_size);
+ glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &config.max_texture_image_units);
+ glGetIntegerv(GL_MAX_TEXTURE_SIZE, &config.max_texture_size);
#ifdef GLES_OVER_GL
- config.use_rgba_2d_shadows=false;
+ config.use_rgba_2d_shadows = false;
#else
- config.use_rgba_2d_shadows=true;
+ config.use_rgba_2d_shadows = true;
#endif
-
//generic quadie for copying
{
//quad buffers
- glGenBuffers(1,&resources.quadie);
- glBindBuffer(GL_ARRAY_BUFFER,resources.quadie);
+ glGenBuffers(1, &resources.quadie);
+ glBindBuffer(GL_ARRAY_BUFFER, resources.quadie);
{
- const float qv[16]={
- -1,-1,
- 0, 0,
+ const float qv[16] = {
+ -1, -1,
+ 0, 0,
-1, 1,
- 0, 1,
- 1, 1,
- 1, 1,
- 1,-1,
- 1, 0,
+ 0, 1,
+ 1, 1,
+ 1, 1,
+ 1, -1,
+ 1, 0,
};
- glBufferData(GL_ARRAY_BUFFER,sizeof(float)*16,qv,GL_STATIC_DRAW);
+ glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 16, qv, GL_STATIC_DRAW);
}
- glBindBuffer(GL_ARRAY_BUFFER,0); //unbind
-
+ glBindBuffer(GL_ARRAY_BUFFER, 0); //unbind
- glGenVertexArrays(1,&resources.quadie_array);
+ glGenVertexArrays(1, &resources.quadie_array);
glBindVertexArray(resources.quadie_array);
- glBindBuffer(GL_ARRAY_BUFFER,resources.quadie);
- glVertexAttribPointer(VS::ARRAY_VERTEX,2,GL_FLOAT,GL_FALSE,sizeof(float)*4,0);
+ glBindBuffer(GL_ARRAY_BUFFER, resources.quadie);
+ glVertexAttribPointer(VS::ARRAY_VERTEX, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 4, 0);
glEnableVertexAttribArray(0);
- glVertexAttribPointer(VS::ARRAY_TEX_UV,2,GL_FLOAT,GL_FALSE,sizeof(float)*4,((uint8_t*)NULL)+8);
+ glVertexAttribPointer(VS::ARRAY_TEX_UV, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 4, ((uint8_t *)NULL) + 8);
glEnableVertexAttribArray(4);
glBindVertexArray(0);
- glBindBuffer(GL_ARRAY_BUFFER,0); //unbind
+ glBindBuffer(GL_ARRAY_BUFFER, 0); //unbind
}
//generic quadie for copying without touching skybox
{
//transform feedback buffers
- uint32_t xf_feedback_size = GLOBAL_DEF("rendering/buffers/blend_shape_max_buffer_size_kb",4096);
- for(int i=0;i<2;i++) {
+ uint32_t xf_feedback_size = GLOBAL_DEF("rendering/buffers/blend_shape_max_buffer_size_kb", 4096);
+ for (int i = 0; i < 2; i++) {
- glGenBuffers(1,&resources.transform_feedback_buffers[i]);
- glBindBuffer(GL_ARRAY_BUFFER,resources.transform_feedback_buffers[i]);
- glBufferData(GL_ARRAY_BUFFER,xf_feedback_size*1024,NULL,GL_STREAM_DRAW);
+ glGenBuffers(1, &resources.transform_feedback_buffers[i]);
+ glBindBuffer(GL_ARRAY_BUFFER, resources.transform_feedback_buffers[i]);
+ glBufferData(GL_ARRAY_BUFFER, xf_feedback_size * 1024, NULL, GL_STREAM_DRAW);
}
shaders.blend_shapes.init();
- glGenVertexArrays(1,&resources.transform_feedback_array);
-
+ glGenVertexArrays(1, &resources.transform_feedback_array);
}
shaders.cubemap_filter.init();
@@ -6656,10 +6261,10 @@ void RasterizerStorageGLES3::initialize() {
glEnable(_EXT_TEXTURE_CUBE_MAP_SEAMLESS);
- frame.count=0;
- frame.prev_tick=0;
- frame.delta=0;
- config.keep_original_textures=false;
+ frame.count = 0;
+ frame.prev_tick = 0;
+ frame.delta = 0;
+ config.keep_original_textures = false;
}
void RasterizerStorageGLES3::finalize() {
@@ -6667,7 +6272,6 @@ void RasterizerStorageGLES3::finalize() {
glDeleteTextures(1, &resources.white_tex);
glDeleteTextures(1, &resources.black_tex);
glDeleteTextures(1, &resources.normal_tex);
-
}
void RasterizerStorageGLES3::update_dirty_resources() {
@@ -6679,7 +6283,5 @@ void RasterizerStorageGLES3::update_dirty_resources() {
update_particles();
}
-RasterizerStorageGLES3::RasterizerStorageGLES3()
-{
-
+RasterizerStorageGLES3::RasterizerStorageGLES3() {
}
diff --git a/drivers/gles3/rasterizer_storage_gles3.h b/drivers/gles3/rasterizer_storage_gles3.h
index 1fa15538de..343cee2133 100644
--- a/drivers/gles3/rasterizer_storage_gles3.h
+++ b/drivers/gles3/rasterizer_storage_gles3.h
@@ -29,27 +29,26 @@
#ifndef RASTERIZERSTORAGEGLES3_H
#define RASTERIZERSTORAGEGLES3_H
+#include "self_list.h"
#include "servers/visual/rasterizer.h"
#include "servers/visual/shader_language.h"
+#include "shader_compiler_gles3.h"
#include "shader_gles3.h"
-#include "shaders/copy.glsl.h"
-#include "shaders/canvas.glsl.h"
#include "shaders/blend_shape.glsl.h"
+#include "shaders/canvas.glsl.h"
+#include "shaders/copy.glsl.h"
#include "shaders/cubemap_filter.glsl.h"
#include "shaders/particles.glsl.h"
-#include "self_list.h"
-#include "shader_compiler_gles3.h"
class RasterizerCanvasGLES3;
class RasterizerSceneGLES3;
-#define _TEXTURE_SRGB_DECODE_EXT 0x8A48
-#define _DECODE_EXT 0x8A49
-#define _SKIP_DECODE_EXT 0x8A4A
+#define _TEXTURE_SRGB_DECODE_EXT 0x8A48
+#define _DECODE_EXT 0x8A49
+#define _SKIP_DECODE_EXT 0x8A4A
class RasterizerStorageGLES3 : public RasterizerStorage {
public:
-
RasterizerCanvasGLES3 *canvas;
RasterizerSceneGLES3 *scene;
static GLuint system_fbo; //on some devices, such as apple, screen is rendered to yet another fbo.
@@ -134,18 +133,9 @@ public:
} info;
-
-/////////////////////////////////////////////////////////////////////////////////////////
-//////////////////////////////////DATA///////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////////////////
-
-
-
-
-
-
-
-
+ /////////////////////////////////////////////////////////////////////////////////////////
+ //////////////////////////////////DATA///////////////////////////////////////////////////
+ /////////////////////////////////////////////////////////////////////////////////////////
struct Instantiable : public RID_Data {
@@ -154,37 +144,35 @@ public:
_FORCE_INLINE_ void instance_change_notify() {
SelfList<RasterizerScene::InstanceBase> *instances = instance_list.first();
- while(instances) {
+ while (instances) {
instances->self()->base_changed();
- instances=instances->next();
+ instances = instances->next();
}
}
_FORCE_INLINE_ void instance_material_change_notify() {
SelfList<RasterizerScene::InstanceBase> *instances = instance_list.first();
- while(instances) {
+ while (instances) {
instances->self()->base_material_changed();
- instances=instances->next();
+ instances = instances->next();
}
}
_FORCE_INLINE_ void instance_remove_deps() {
SelfList<RasterizerScene::InstanceBase> *instances = instance_list.first();
- while(instances) {
+ while (instances) {
SelfList<RasterizerScene::InstanceBase> *next = instances->next();
instances->self()->base_removed();
- instances=next;
+ instances = next;
}
}
-
- Instantiable() { }
+ Instantiable() {}
virtual ~Instantiable() {
-
}
};
@@ -201,7 +189,6 @@ public:
GEOMETRY_MULTISURFACE,
};
-
Type type;
RID material;
uint64_t last_pass;
@@ -210,18 +197,14 @@ public:
virtual void material_changed_notify() {}
Geometry() {
- last_pass=0;
- index=0;
+ last_pass = 0;
+ index = 0;
}
-
};
-
-
-/////////////////////////////////////////////////////////////////////////////////////////
-//////////////////////////////////API////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////////////////
-
+ /////////////////////////////////////////////////////////////////////////////////////////
+ //////////////////////////////////API////////////////////////////////////////////////////
+ /////////////////////////////////////////////////////////////////////////////////////////
/* TEXTURE API */
@@ -231,7 +214,7 @@ public:
String path;
uint32_t flags;
- int width,height;
+ int width, height;
int alloc_width, alloc_height;
Image::Format format;
@@ -266,64 +249,62 @@ public:
Texture() {
- using_srgb=false;
- stored_cube_sides=0;
- ignore_mipmaps=false;
- render_target=NULL;
- flags=width=height=0;
- tex_id=0;
- data_size=0;
- format=Image::FORMAT_L8;
- active=false;
- compressed=false;
- total_data_size=0;
- target=GL_TEXTURE_2D;
- mipmaps=0;
- detect_3d=NULL;
- detect_3d_ud=NULL;
- detect_srgb=NULL;
- detect_srgb_ud=NULL;
-
+ using_srgb = false;
+ stored_cube_sides = 0;
+ ignore_mipmaps = false;
+ render_target = NULL;
+ flags = width = height = 0;
+ tex_id = 0;
+ data_size = 0;
+ format = Image::FORMAT_L8;
+ active = false;
+ compressed = false;
+ total_data_size = 0;
+ target = GL_TEXTURE_2D;
+ mipmaps = 0;
+ detect_3d = NULL;
+ detect_3d_ud = NULL;
+ detect_srgb = NULL;
+ detect_srgb_ud = NULL;
}
~Texture() {
- if (tex_id!=0) {
+ if (tex_id != 0) {
- glDeleteTextures(1,&tex_id);
+ glDeleteTextures(1, &tex_id);
}
}
};
mutable RID_Owner<Texture> texture_owner;
- Image _get_gl_image_and_format(const Image& p_image, Image::Format p_format, uint32_t p_flags, GLenum& r_gl_format, GLenum& r_gl_internal_format, GLenum &r_type, bool &r_compressed, bool &srgb);
+ Image _get_gl_image_and_format(const Image &p_image, Image::Format p_format, uint32_t p_flags, GLenum &r_gl_format, GLenum &r_gl_internal_format, GLenum &r_type, bool &r_compressed, bool &srgb);
virtual RID texture_create();
- virtual void texture_allocate(RID p_texture,int p_width, int p_height,Image::Format p_format,uint32_t p_flags=VS::TEXTURE_FLAGS_DEFAULT);
- virtual void texture_set_data(RID p_texture,const Image& p_image,VS::CubeMapSide p_cube_side=VS::CUBEMAP_LEFT);
- virtual Image texture_get_data(RID p_texture,VS::CubeMapSide p_cube_side=VS::CUBEMAP_LEFT) const;
- virtual void texture_set_flags(RID p_texture,uint32_t p_flags);
+ virtual void texture_allocate(RID p_texture, int p_width, int p_height, Image::Format p_format, uint32_t p_flags = VS::TEXTURE_FLAGS_DEFAULT);
+ virtual void texture_set_data(RID p_texture, const Image &p_image, VS::CubeMapSide p_cube_side = VS::CUBEMAP_LEFT);
+ virtual Image texture_get_data(RID p_texture, VS::CubeMapSide p_cube_side = VS::CUBEMAP_LEFT) 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 uint32_t texture_get_width(RID p_texture) const;
virtual uint32_t texture_get_height(RID p_texture) const;
- virtual void texture_set_size_override(RID p_texture,int p_width, int p_height);
+ virtual void texture_set_size_override(RID p_texture, int p_width, int p_height);
- virtual void texture_set_path(RID p_texture,const String& p_path);
+ virtual void texture_set_path(RID p_texture, const String &p_path);
virtual String texture_get_path(RID p_texture) const;
virtual void texture_set_shrink_all_x2_on_set_data(bool p_enable);
virtual void texture_debug_usage(List<VS::TextureInfo> *r_info);
- virtual RID texture_create_radiance_cubemap(RID p_source,int p_resolution=-1) const;
+ virtual RID texture_create_radiance_cubemap(RID p_source, int p_resolution = -1) const;
virtual void textures_keep_original(bool p_enable);
- 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_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);
/* SKYBOX API */
@@ -337,7 +318,7 @@ public:
mutable RID_Owner<SkyBox> skybox_owner;
virtual RID skybox_create();
- virtual void skybox_set_texture(RID p_skybox,RID p_cube_map,int p_radiance_size);
+ virtual void skybox_set_texture(RID p_skybox, RID p_cube_map, int p_radiance_size);
/* SHADER API */
@@ -352,9 +333,7 @@ public:
String code;
SelfList<Material>::List materials;
-
-
- Map<StringName,ShaderLanguage::ShaderNode::Uniform> uniforms;
+ Map<StringName, ShaderLanguage::ShaderNode::Uniform> uniforms;
Vector<uint32_t> ubo_offsets;
uint32_t ubo_size;
@@ -365,7 +344,7 @@ public:
SelfList<Shader> dirty_list;
- Map<StringName,RID> default_textures;
+ Map<StringName, RID> default_textures;
Vector<ShaderLanguage::ShaderNode::Uniform::Hint> texture_hints;
@@ -434,45 +413,42 @@ public:
struct Particles {
-
} particles;
-
bool uses_vertex_time;
bool uses_fragment_time;
- Shader() : dirty_list(this) {
+ Shader()
+ : dirty_list(this) {
- shader=NULL;
- valid=false;
- custom_code_id=0;
- version=1;
+ shader = NULL;
+ valid = false;
+ custom_code_id = 0;
+ version = 1;
}
};
mutable SelfList<Shader>::List _shader_dirty_list;
- void _shader_make_dirty(Shader* p_shader);
+ void _shader_make_dirty(Shader *p_shader);
mutable RID_Owner<Shader> shader_owner;
- virtual RID shader_create(VS::ShaderMode p_mode=VS::SHADER_SPATIAL);
+ virtual RID shader_create(VS::ShaderMode p_mode = VS::SHADER_SPATIAL);
- virtual void shader_set_mode(RID p_shader,VS::ShaderMode p_mode);
+ virtual void shader_set_mode(RID p_shader, VS::ShaderMode p_mode);
virtual VS::ShaderMode shader_get_mode(RID p_shader) const;
- virtual void shader_set_code(RID p_shader, const String& p_code);
+ virtual void shader_set_code(RID p_shader, const String &p_code);
virtual String shader_get_code(RID p_shader) const;
virtual void shader_get_param_list(RID p_shader, List<PropertyInfo> *p_param_list) const;
- virtual void shader_set_default_texture_param(RID p_shader, const StringName& p_name, RID p_texture);
- virtual RID shader_get_default_texture_param(RID p_shader, const StringName& p_name) const;
+ virtual void shader_set_default_texture_param(RID p_shader, const StringName &p_name, RID p_texture);
+ virtual RID shader_get_default_texture_param(RID p_shader, const StringName &p_name) const;
- void _update_shader(Shader* p_shader) const;
+ void _update_shader(Shader *p_shader) const;
void update_dirty_shaders();
-
-
/* COMMON MATERIAL API */
struct Material : public RID_Data {
@@ -480,7 +456,7 @@ public:
Shader *shader;
GLuint ubo_id;
uint32_t ubo_size;
- Map<StringName,Variant> params;
+ Map<StringName, Variant> params;
SelfList<Material> list;
SelfList<Material> dirty_list;
Vector<RID> textures;
@@ -489,30 +465,29 @@ public:
uint32_t index;
uint64_t last_pass;
- Map<Geometry*,int> geometry_owners;
- Map<RasterizerScene::InstanceBase*,int> instance_owners;
+ Map<Geometry *, int> geometry_owners;
+ Map<RasterizerScene::InstanceBase *, int> instance_owners;
bool can_cast_shadow_cache;
bool is_animated_cache;
- Material() : list(this), dirty_list(this) {
- can_cast_shadow_cache=false;
- is_animated_cache=false;
- shader=NULL;
- line_width=1.0;
- ubo_id=0;
- ubo_size=0;
- last_pass=0;
+ Material()
+ : list(this), dirty_list(this) {
+ can_cast_shadow_cache = false;
+ is_animated_cache = false;
+ shader = NULL;
+ line_width = 1.0;
+ ubo_id = 0;
+ ubo_size = 0;
+ last_pass = 0;
}
-
};
mutable SelfList<Material>::List _material_dirty_list;
void _material_make_dirty(Material *p_material) const;
- void _material_add_geometry(RID p_material,Geometry *p_instantiable);
+ void _material_add_geometry(RID p_material, Geometry *p_instantiable);
void _material_remove_geometry(RID p_material, Geometry *p_instantiable);
-
mutable RID_Owner<Material> material_owner;
virtual RID material_create();
@@ -520,8 +495,8 @@ public:
virtual void material_set_shader(RID p_material, RID p_shader);
virtual RID material_get_shader(RID p_material) const;
- virtual void material_set_param(RID p_material, const StringName& p_param, const Variant& p_value);
- virtual Variant material_get_param(RID p_material, const StringName& p_param) const;
+ virtual void material_set_param(RID p_material, const StringName &p_param, const Variant &p_value);
+ virtual Variant material_get_param(RID p_material, const StringName &p_param) const;
virtual void material_set_line_width(RID p_material, float p_width);
@@ -531,17 +506,12 @@ public:
virtual void material_add_instance_owner(RID p_material, RasterizerScene::InstanceBase *p_instance);
virtual void material_remove_instance_owner(RID p_material, RasterizerScene::InstanceBase *p_instance);
- void _update_material(Material* material);
+ void _update_material(Material *material);
void update_dirty_materials();
/* MESH API */
-
-
-
-
-
struct Mesh;
struct Surface : public Geometry {
@@ -559,8 +529,6 @@ public:
Attrib attribs[VS::ARRAY_MAX];
-
-
Mesh *mesh;
uint32_t format;
@@ -590,7 +558,6 @@ public:
int array_byte_size;
int index_array_byte_size;
-
VS::PrimitiveType primitive;
bool active;
@@ -602,23 +569,21 @@ public:
Surface() {
- array_byte_size=0;
- index_array_byte_size=0;
- mesh=NULL;
- format=0;
- array_id=0;
- vertex_id=0;
- index_id=0;
- array_len=0;
- type=GEOMETRY_SURFACE;
- primitive=VS::PRIMITIVE_POINTS;
- index_array_len=0;
- active=false;
-
+ array_byte_size = 0;
+ index_array_byte_size = 0;
+ mesh = NULL;
+ format = 0;
+ array_id = 0;
+ vertex_id = 0;
+ index_id = 0;
+ array_len = 0;
+ type = GEOMETRY_SURFACE;
+ primitive = VS::PRIMITIVE_POINTS;
+ index_array_len = 0;
+ active = false;
}
~Surface() {
-
}
};
@@ -627,7 +592,7 @@ public:
struct Mesh : public GeometryOwner {
bool active;
- Vector<Surface*> surfaces;
+ Vector<Surface *> surfaces;
int blend_shape_count;
VS::BlendShapeMode blend_shape_mode;
Rect3 custom_aabb;
@@ -637,17 +602,17 @@ public:
_FORCE_INLINE_ void update_multimeshes() {
SelfList<MultiMesh> *mm = multimeshes.first();
- while(mm) {
+ while (mm) {
mm->self()->instance_material_change_notify();
- mm=mm->next();
+ mm = mm->next();
}
}
Mesh() {
- blend_shape_mode=VS::BLEND_SHAPE_MODE_NORMALIZED;
- blend_shape_count=0;
- last_pass=0;
- active=false;
+ blend_shape_mode = VS::BLEND_SHAPE_MODE_NORMALIZED;
+ blend_shape_count = 0;
+ last_pass = 0;
+ active = false;
}
};
@@ -655,13 +620,12 @@ public:
virtual RID mesh_create();
- virtual void mesh_add_surface(RID p_mesh,uint32_t p_format,VS::PrimitiveType p_primitive,const PoolVector<uint8_t>& p_array,int p_vertex_count,const PoolVector<uint8_t>& p_index_array,int p_index_count,const Rect3& p_aabb,const Vector<PoolVector<uint8_t> >& p_blend_shapes=Vector<PoolVector<uint8_t> >(),const Vector<Rect3>& p_bone_aabbs=Vector<Rect3>());
+ virtual void mesh_add_surface(RID p_mesh, uint32_t p_format, VS::PrimitiveType p_primitive, const PoolVector<uint8_t> &p_array, int p_vertex_count, const PoolVector<uint8_t> &p_index_array, int p_index_count, const Rect3 &p_aabb, const Vector<PoolVector<uint8_t> > &p_blend_shapes = Vector<PoolVector<uint8_t> >(), const Vector<Rect3> &p_bone_aabbs = Vector<Rect3>());
- virtual void mesh_set_blend_shape_count(RID p_mesh,int p_amount);
+ 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 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_surface_set_material(RID p_mesh, int p_surface, RID p_material);
@@ -673,7 +637,6 @@ public:
virtual PoolVector<uint8_t> mesh_surface_get_array(RID p_mesh, int p_surface) const;
virtual PoolVector<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;
@@ -684,7 +647,7 @@ public:
virtual void mesh_remove_surface(RID p_mesh, int p_surface);
virtual int mesh_get_surface_count(RID p_mesh) const;
- virtual void mesh_set_custom_aabb(RID p_mesh,const Rect3& p_aabb);
+ virtual void mesh_set_custom_aabb(RID p_mesh, const Rect3 &p_aabb);
virtual Rect3 mesh_get_custom_aabb(RID p_mesh) const;
virtual Rect3 mesh_get_aabb(RID p_mesh, RID p_skeleton) const;
@@ -712,16 +675,17 @@ public:
bool dirty_aabb;
bool dirty_data;
- MultiMesh() : update_list(this), mesh_list(this) {
- dirty_aabb=true;
- dirty_data=true;
- xform_floats=0;
- color_floats=0;
- visible_instances=-1;
- size=0;
- buffer=0;
- transform_format=VS::MULTIMESH_TRANSFORM_2D;
- color_format=VS::MULTIMESH_COLOR_NONE;
+ MultiMesh()
+ : update_list(this), mesh_list(this) {
+ dirty_aabb = true;
+ dirty_data = true;
+ xform_floats = 0;
+ color_floats = 0;
+ visible_instances = -1;
+ size = 0;
+ buffer = 0;
+ transform_format = VS::MULTIMESH_TRANSFORM_2D;
+ color_format = VS::MULTIMESH_COLOR_NONE;
}
};
@@ -733,21 +697,21 @@ 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);
+ virtual void multimesh_allocate(RID p_multimesh, int p_instances, VS::MultimeshTransformFormat p_transform_format, VS::MultimeshColorFormat p_color_format);
virtual int multimesh_get_instance_count(RID p_multimesh) const;
- virtual void multimesh_set_mesh(RID p_multimesh,RID p_mesh);
- virtual void multimesh_instance_set_transform(RID p_multimesh,int p_index,const Transform& p_transform);
- virtual void multimesh_instance_set_transform_2d(RID p_multimesh,int p_index,const Transform2D& p_transform);
- virtual void multimesh_instance_set_color(RID p_multimesh,int p_index,const Color& p_color);
+ virtual void multimesh_set_mesh(RID p_multimesh, RID p_mesh);
+ virtual void multimesh_instance_set_transform(RID p_multimesh, int p_index, const Transform &p_transform);
+ virtual void multimesh_instance_set_transform_2d(RID p_multimesh, int p_index, const Transform2D &p_transform);
+ virtual void multimesh_instance_set_color(RID p_multimesh, int p_index, const Color &p_color);
virtual RID multimesh_get_mesh(RID p_multimesh) const;
- virtual Transform multimesh_instance_get_transform(RID p_multimesh,int p_index) const;
- virtual Transform2D multimesh_instance_get_transform_2d(RID p_multimesh,int p_index) const;
- virtual Color multimesh_instance_get_color(RID p_multimesh,int p_index) const;
+ virtual Transform multimesh_instance_get_transform(RID p_multimesh, int p_index) const;
+ virtual Transform2D multimesh_instance_get_transform_2d(RID p_multimesh, int p_index) const;
+ virtual Color multimesh_instance_get_color(RID p_multimesh, int p_index) const;
- virtual void multimesh_set_visible_instances(RID p_multimesh,int p_visible);
+ virtual void multimesh_set_visible_instances(RID p_multimesh, int p_visible);
virtual int multimesh_get_visible_instances(RID p_multimesh) const;
virtual Rect3 multimesh_get_aabb(RID p_multimesh) const;
@@ -773,8 +737,10 @@ public:
int mask;
Rect3 aabb;
- Immediate() { type=GEOMETRY_IMMEDIATE; building=false;}
-
+ Immediate() {
+ type = GEOMETRY_IMMEDIATE;
+ building = false;
+ }
};
Vector3 chunk_vertex;
@@ -787,16 +753,16 @@ public:
mutable RID_Owner<Immediate> immediate_owner;
virtual RID immediate_create();
- virtual void immediate_begin(RID p_immediate,VS::PrimitiveType p_rimitive,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);
- virtual void immediate_color(RID p_immediate,const Color& p_color);
- virtual void immediate_uv(RID p_immediate,const Vector2& tex_uv);
- virtual void immediate_uv2(RID p_immediate,const Vector2& tex_uv);
+ virtual void immediate_begin(RID p_immediate, VS::PrimitiveType p_rimitive, 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);
+ virtual void immediate_color(RID p_immediate, const Color &p_color);
+ virtual void immediate_uv(RID p_immediate, const Vector2 &tex_uv);
+ virtual void immediate_uv2(RID p_immediate, const Vector2 &tex_uv);
virtual void immediate_end(RID p_immediate);
virtual void immediate_clear(RID p_immediate);
- virtual void immediate_set_material(RID p_immediate,RID p_material);
+ virtual void immediate_set_material(RID p_immediate, RID p_material);
virtual RID immediate_get_material(RID p_immediate) const;
virtual Rect3 immediate_get_aabb(RID p_immediate) const;
@@ -808,12 +774,13 @@ public:
Vector<float> bones; //4x3 or 4x2 depending on what is needed
GLuint ubo;
SelfList<Skeleton> update_list;
- Set<RasterizerScene::InstanceBase*> instances; //instances using skeleton
+ Set<RasterizerScene::InstanceBase *> instances; //instances using skeleton
- Skeleton() : update_list(this) {
- size=0;
- use_2d=false;
- ubo=0;
+ Skeleton()
+ : update_list(this) {
+ size = 0;
+ use_2d = false;
+ ubo = 0;
}
};
@@ -824,16 +791,15 @@ public:
void update_dirty_skeletons();
virtual RID skeleton_create();
- virtual void skeleton_allocate(RID p_skeleton,int p_bones,bool p_2d_skeleton=false);
+ virtual void skeleton_allocate(RID p_skeleton, int p_bones, bool p_2d_skeleton = false);
virtual int skeleton_get_bone_count(RID p_skeleton) const;
- virtual void skeleton_bone_set_transform(RID p_skeleton,int p_bone, const Transform& p_transform);
- virtual Transform skeleton_bone_get_transform(RID p_skeleton,int p_bone) const;
- virtual void skeleton_bone_set_transform_2d(RID p_skeleton,int p_bone, const Transform2D& p_transform);
- virtual Transform2D skeleton_bone_get_transform_2d(RID p_skeleton,int p_bone) const;
+ virtual void skeleton_bone_set_transform(RID p_skeleton, int p_bone, const Transform &p_transform);
+ virtual Transform skeleton_bone_get_transform(RID p_skeleton, int p_bone) const;
+ virtual void skeleton_bone_set_transform_2d(RID p_skeleton, int p_bone, const Transform2D &p_transform);
+ virtual Transform2D skeleton_bone_get_transform_2d(RID p_skeleton, int p_bone) const;
/* Light API */
-
struct Light : Instantiable {
VS::LightType type;
@@ -855,20 +821,19 @@ public:
virtual RID light_create(VS::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_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);
- virtual void light_set_negative(RID p_light,bool p_enable);
- virtual void light_set_cull_mask(RID p_light,uint32_t p_mask);
-
+ 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_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);
+ virtual void light_set_negative(RID p_light, bool p_enable);
+ virtual void light_set_cull_mask(RID p_light, uint32_t p_mask);
- 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, VS::LightOmniShadowMode p_mode);
+ virtual void light_omni_set_shadow_detail(RID p_light, VS::LightOmniShadowDetail p_detail);
- virtual void light_directional_set_shadow_mode(RID p_light,VS::LightDirectionalShadowMode p_mode);
- virtual void light_directional_set_blend_splits(RID p_light,bool p_enable);
+ virtual void light_directional_set_shadow_mode(RID p_light, VS::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);
@@ -877,7 +842,7 @@ public:
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 float light_get_param(RID p_light, VS::LightParam p_param);
virtual Color light_get_color(RID p_light);
virtual Rect3 light_get_aabb(RID p_light) const;
@@ -899,7 +864,6 @@ public:
bool box_projection;
bool enable_shadows;
uint32_t cull_mask;
-
};
mutable RID_Owner<ReflectionProbe> reflection_probe_owner;
@@ -908,12 +872,12 @@ public:
virtual void reflection_probe_set_update_mode(RID p_probe, VS::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(RID p_probe, const Color &p_ambient);
virtual void reflection_probe_set_interior_ambient_energy(RID p_probe, float p_energy);
virtual void reflection_probe_set_interior_ambient_probe_contribution(RID p_probe, float p_contrib);
virtual void reflection_probe_set_max_distance(RID p_probe, float p_distance);
- virtual void reflection_probe_set_extents(RID p_probe, const Vector3& p_extents);
- virtual void reflection_probe_set_origin_offset(RID p_probe, const Vector3& p_offset);
+ virtual void reflection_probe_set_extents(RID p_probe, const Vector3 &p_extents);
+ virtual void reflection_probe_set_origin_offset(RID p_probe, const Vector3 &p_offset);
virtual void reflection_probe_set_as_interior(RID p_probe, bool p_enable);
virtual void reflection_probe_set_enable_box_projection(RID p_probe, bool p_enable);
virtual void reflection_probe_set_enable_shadows(RID p_probe, bool p_enable);
@@ -928,13 +892,10 @@ public:
virtual float reflection_probe_get_origin_max_distance(RID p_probe) const;
virtual bool reflection_probe_renders_shadows(RID p_probe) const;
-
-
-
/* ROOM API */
virtual RID room_create();
- virtual void room_add_bounds(RID p_room, const PoolVector<Vector2>& p_convex_polygon,float p_height,const Transform& p_transform);
+ virtual void room_add_bounds(RID p_room, const PoolVector<Vector2> &p_convex_polygon, float p_height, const Transform &p_transform);
virtual void room_clear_bounds(RID p_room);
/* PORTAL API */
@@ -943,22 +904,15 @@ public:
// order points outside. (z is 0);
virtual RID portal_create();
- virtual void portal_set_shape(RID p_portal, const Vector<Point2>& p_shape);
+ virtual void portal_set_shape(RID p_portal, const Vector<Point2> &p_shape);
virtual void portal_set_enabled(RID p_portal, bool p_enabled);
virtual void portal_set_disable_distance(RID p_portal, float p_distance);
- virtual void portal_set_disabled_color(RID p_portal, const Color& p_color);
-
-
-
-
-
-
+ virtual void portal_set_disabled_color(RID p_portal, const Color &p_color);
/* GI PROBE API */
struct GIProbe : public Instantiable {
-
Rect3 bounds;
Transform to_cell;
float cell_size;
@@ -973,42 +927,40 @@ public:
uint32_t version;
PoolVector<int> dynamic_data;
-
-
};
mutable RID_Owner<GIProbe> gi_probe_owner;
virtual RID gi_probe_create();
- virtual void gi_probe_set_bounds(RID p_probe,const Rect3& p_bounds);
+ virtual void gi_probe_set_bounds(RID p_probe, const Rect3 &p_bounds);
virtual Rect3 gi_probe_get_bounds(RID p_probe) const;
virtual void gi_probe_set_cell_size(RID p_probe, float p_size);
virtual float gi_probe_get_cell_size(RID p_probe) const;
- virtual void gi_probe_set_to_cell_xform(RID p_probe,const Transform& p_xform);
+ virtual void gi_probe_set_to_cell_xform(RID p_probe, const Transform &p_xform);
virtual Transform gi_probe_get_to_cell_xform(RID p_probe) const;
- virtual void gi_probe_set_dynamic_data(RID p_probe,const PoolVector<int>& p_data);
+ virtual void gi_probe_set_dynamic_data(RID p_probe, const PoolVector<int> &p_data);
virtual PoolVector<int> gi_probe_get_dynamic_data(RID p_probe) const;
- virtual void gi_probe_set_dynamic_range(RID p_probe,int p_range);
+ virtual void gi_probe_set_dynamic_range(RID p_probe, int p_range);
virtual int gi_probe_get_dynamic_range(RID p_probe) const;
- virtual void gi_probe_set_energy(RID p_probe,float p_range);
+ virtual void gi_probe_set_energy(RID p_probe, float p_range);
virtual float gi_probe_get_energy(RID p_probe) const;
- virtual void gi_probe_set_bias(RID p_probe,float p_range);
+ virtual void gi_probe_set_bias(RID p_probe, float p_range);
virtual float gi_probe_get_bias(RID p_probe) const;
- virtual void gi_probe_set_propagation(RID p_probe,float p_range);
+ virtual void gi_probe_set_propagation(RID p_probe, float p_range);
virtual float gi_probe_get_propagation(RID p_probe) const;
- virtual void gi_probe_set_interior(RID p_probe,bool p_enable);
+ virtual void gi_probe_set_interior(RID p_probe, bool p_enable);
virtual bool gi_probe_is_interior(RID p_probe) const;
- virtual void gi_probe_set_compress(RID p_probe,bool p_enable);
+ virtual void gi_probe_set_compress(RID p_probe, bool p_enable);
virtual bool gi_probe_is_compressed(RID p_probe) const;
virtual uint32_t gi_probe_get_version(RID p_probe);
@@ -1029,8 +981,8 @@ public:
mutable RID_Owner<GIProbeData> gi_probe_data_owner;
virtual GIProbeCompression gi_probe_get_dynamic_data_get_preferred_compression() const;
- virtual RID gi_probe_dynamic_data_create(int p_width,int p_height,int p_depth,GIProbeCompression p_compression);
- virtual void gi_probe_dynamic_data_update(RID p_gi_probe_data,int p_depth_slice,int p_slice_count,int p_mipmap,const void* p_data);
+ virtual RID gi_probe_dynamic_data_create(int p_width, int p_height, int p_depth, GIProbeCompression p_compression);
+ virtual void gi_probe_dynamic_data_update(RID p_gi_probe_data, int p_depth_slice, int p_slice_count, int p_mipmap, const void *p_data);
/* PARTICLES */
@@ -1073,77 +1025,74 @@ public:
Transform origin;
- Particles() : particle_element(this) {
- emitting=false;
- amount=0;
- lifetime=1.0;
- pre_process_time=0.0;
- explosiveness=0.0;
- randomness=0.0;
- use_local_coords=true;
-
- draw_order=VS::PARTICLES_DRAW_ORDER_INDEX;
- emission_shape=VS::PARTICLES_EMSSION_POINT;
- emission_sphere_radius=1.0;
- emission_box_extents=Vector3(1,1,1);
- emission_point_texture=0;
- particle_buffers[0]=0;
- particle_buffers[1]=0;
-
- prev_ticks=0;
-
- glGenBuffers(2,particle_buffers);
+ Particles()
+ : particle_element(this) {
+ emitting = false;
+ amount = 0;
+ lifetime = 1.0;
+ pre_process_time = 0.0;
+ explosiveness = 0.0;
+ randomness = 0.0;
+ use_local_coords = true;
+
+ draw_order = VS::PARTICLES_DRAW_ORDER_INDEX;
+ emission_shape = VS::PARTICLES_EMSSION_POINT;
+ emission_sphere_radius = 1.0;
+ emission_box_extents = Vector3(1, 1, 1);
+ emission_point_texture = 0;
+ particle_buffers[0] = 0;
+ particle_buffers[1] = 0;
+
+ prev_ticks = 0;
+
+ glGenBuffers(2, particle_buffers);
}
~Particles() {
- glDeleteBuffers(2,particle_buffers);
+ glDeleteBuffers(2, particle_buffers);
}
-
-
};
SelfList<Particles>::List particle_update_list;
void update_particles();
-
mutable RID_Owner<Particles> particles_owner;
virtual RID particles_create();
- virtual void particles_set_emitting(RID p_particles,bool p_emitting);
- virtual void particles_set_amount(RID p_particles,int p_amount);
- virtual void particles_set_lifetime(RID p_particles,float p_lifetime);
- virtual void particles_set_pre_process_time(RID p_particles,float p_time);
- virtual void particles_set_explosiveness_ratio(RID p_particles,float p_ratio);
- virtual void particles_set_randomness_ratio(RID p_particles,float p_ratio);
- virtual void particles_set_custom_aabb(RID p_particles,const Rect3& p_aabb);
- virtual void particles_set_gravity(RID p_particles,const Vector3& p_gravity);
- virtual void particles_set_use_local_coordinates(RID p_particles,bool p_enable);
- virtual void particles_set_process_material(RID p_particles,RID p_material);
+ virtual void particles_set_emitting(RID p_particles, bool p_emitting);
+ virtual void particles_set_amount(RID p_particles, int p_amount);
+ virtual void particles_set_lifetime(RID p_particles, float p_lifetime);
+ virtual void particles_set_pre_process_time(RID p_particles, float p_time);
+ virtual void particles_set_explosiveness_ratio(RID p_particles, float p_ratio);
+ virtual void particles_set_randomness_ratio(RID p_particles, float p_ratio);
+ virtual void particles_set_custom_aabb(RID p_particles, const Rect3 &p_aabb);
+ virtual void particles_set_gravity(RID p_particles, const Vector3 &p_gravity);
+ virtual void particles_set_use_local_coordinates(RID p_particles, bool p_enable);
+ virtual void particles_set_process_material(RID p_particles, RID p_material);
- virtual void particles_set_emission_shape(RID p_particles,VS::ParticlesEmissionShape p_shape);
- virtual void particles_set_emission_sphere_radius(RID p_particles,float p_radius);
- virtual void particles_set_emission_box_extents(RID p_particles,const Vector3& p_extents);
- virtual void particles_set_emission_points(RID p_particles,const PoolVector<Vector3>& p_points);
+ virtual void particles_set_emission_shape(RID p_particles, VS::ParticlesEmissionShape p_shape);
+ virtual void particles_set_emission_sphere_radius(RID p_particles, float p_radius);
+ virtual void particles_set_emission_box_extents(RID p_particles, const Vector3 &p_extents);
+ virtual void particles_set_emission_points(RID p_particles, const PoolVector<Vector3> &p_points);
+ virtual void particles_set_draw_order(RID p_particles, VS::ParticlesDrawOrder p_order);
- virtual void particles_set_draw_order(RID p_particles,VS::ParticlesDrawOrder p_order);
-
- virtual void particles_set_draw_passes(RID p_particles,int p_count);
- virtual void particles_set_draw_pass_material(RID p_particles,int p_pass, RID p_material);
- virtual void particles_set_draw_pass_mesh(RID p_particles,int p_pass, RID p_mesh);
+ virtual void particles_set_draw_passes(RID p_particles, int p_count);
+ virtual void particles_set_draw_pass_material(RID p_particles, int p_pass, RID p_material);
+ virtual void particles_set_draw_pass_mesh(RID p_particles, int p_pass, RID p_mesh);
virtual Rect3 particles_get_current_aabb(RID p_particles);
/* INSTANCE */
- virtual void instance_add_skeleton(RID p_skeleton,RasterizerScene::InstanceBase *p_instance);
- virtual void instance_remove_skeleton(RID p_skeleton,RasterizerScene::InstanceBase *p_instance);
+ virtual void instance_add_skeleton(RID p_skeleton, RasterizerScene::InstanceBase *p_instance);
+ virtual void instance_remove_skeleton(RID p_skeleton, RasterizerScene::InstanceBase *p_instance);
- virtual void instance_add_dependency(RID p_base,RasterizerScene::InstanceBase *p_instance);
- virtual void instance_remove_dependency(RID p_base,RasterizerScene::InstanceBase *p_instance);
+ virtual void instance_add_dependency(RID p_base, RasterizerScene::InstanceBase *p_instance);
+ virtual void instance_remove_dependency(RID p_base, RasterizerScene::InstanceBase *p_instance);
/* RENDER TARGET */
@@ -1180,7 +1129,10 @@ public:
GLuint color;
int levels;
- MipMaps() { color=0; levels=0;}
+ MipMaps() {
+ color = 0;
+ levels = 0;
+ }
};
MipMaps mip_maps[2]; //first mipmap chain starts from full-screen
@@ -1194,7 +1146,11 @@ public:
Vector<GLuint> depth_mipmap_fbos; //fbos for depth mipmapsla ver
- SSAO() { blur_fbo[0]=0; blur_fbo[1]=0; linear_depth=0; }
+ SSAO() {
+ blur_fbo[0] = 0;
+ blur_fbo[1] = 0;
+ linear_depth = 0;
+ }
} ssao;
Effects() {}
@@ -1205,12 +1161,12 @@ public:
GLuint fbo;
GLuint color;
- Exposure() { fbo=0; }
+ Exposure() { fbo = 0; }
} exposure;
uint64_t last_exposure_tick;
- int width,height;
+ int width, height;
bool flags[RENDER_TARGET_FLAG_MAX];
@@ -1221,23 +1177,22 @@ public:
RenderTarget() {
- msaa=VS::VIEWPORT_MSAA_DISABLED;
- width=0;
- height=0;
- depth=0;
- fbo=0;
- exposure.fbo=0;
- buffers.fbo=0;
- used_in_frame=false;
-
-
- flags[RENDER_TARGET_VFLIP]=false;
- flags[RENDER_TARGET_TRANSPARENT]=false;
- flags[RENDER_TARGET_NO_3D]=false;
- flags[RENDER_TARGET_HDR]=true;
- flags[RENDER_TARGET_NO_SAMPLING]=false;
-
- last_exposure_tick=0;
+ msaa = VS::VIEWPORT_MSAA_DISABLED;
+ width = 0;
+ height = 0;
+ depth = 0;
+ fbo = 0;
+ exposure.fbo = 0;
+ buffers.fbo = 0;
+ used_in_frame = false;
+
+ flags[RENDER_TARGET_VFLIP] = false;
+ flags[RENDER_TARGET_TRANSPARENT] = false;
+ flags[RENDER_TARGET_NO_3D] = false;
+ flags[RENDER_TARGET_HDR] = true;
+ flags[RENDER_TARGET_NO_SAMPLING] = false;
+
+ last_exposure_tick = 0;
}
};
@@ -1247,12 +1202,12 @@ public:
void _render_target_allocate(RenderTarget *rt);
virtual RID render_target_create();
- virtual void render_target_set_size(RID p_render_target,int p_width, int p_height);
+ virtual void render_target_set_size(RID p_render_target, int p_width, int p_height);
virtual RID render_target_get_texture(RID p_render_target) const;
- virtual void render_target_set_flag(RID p_render_target,RenderTargetFlags p_flag,bool p_value);
+ virtual void render_target_set_flag(RID p_render_target, RenderTargetFlags p_flag, bool p_value);
virtual bool render_target_renedered_in_frame(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, VS::ViewportMSAA p_msaa);
/* CANVAS SHADOW */
@@ -1282,13 +1237,12 @@ public:
RID_Owner<CanvasOccluder> canvas_occluder_owner;
virtual RID canvas_light_occluder_create();
- virtual void canvas_light_occluder_set_polylines(RID p_occluder, const PoolVector<Vector2>& p_lines);
+ virtual void canvas_light_occluder_set_polylines(RID p_occluder, const PoolVector<Vector2> &p_lines);
virtual VS::InstanceType get_base_type(RID p_rid) const;
virtual bool free(RID p_rid);
-
struct Frame {
RenderTarget *current_rt;
@@ -1305,12 +1259,11 @@ public:
void initialize();
void finalize();
- virtual bool has_os_feature(const String& p_feature) const;
+ virtual bool has_os_feature(const String &p_feature) const;
virtual void update_dirty_resources();
RasterizerStorageGLES3();
};
-
#endif // RASTERIZERSTORAGEGLES3_H
diff --git a/drivers/gles3/shader_compiler_gles3.cpp b/drivers/gles3/shader_compiler_gles3.cpp
index 260f1787c4..12934a82e7 100644
--- a/drivers/gles3/shader_compiler_gles3.cpp
+++ b/drivers/gles3/shader_compiler_gles3.cpp
@@ -35,8 +35,8 @@
static String _mktab(int p_level) {
String tb;
- for(int i=0;i<p_level;i++) {
- tb+="\t";
+ for (int i = 0; i < p_level; i++) {
+ tb += "\t";
}
return tb;
@@ -49,7 +49,7 @@ static String _typestr(SL::DataType p_type) {
static int _get_datatype_size(SL::DataType p_type) {
- switch(p_type) {
+ switch (p_type) {
case SL::TYPE_VOID: return 0;
case SL::TYPE_BOOL: return 4;
@@ -80,12 +80,9 @@ static int _get_datatype_size(SL::DataType p_type) {
ERR_FAIL_V(0);
}
-
-
static String _prestr(SL::DataPrecision p_pres) {
-
- switch(p_pres) {
+ switch (p_pres) {
case SL::PRECISION_LOWP: return "lowp ";
case SL::PRECISION_MEDIUMP: return "mediump ";
case SL::PRECISION_HIGHP: return "highp ";
@@ -94,89 +91,87 @@ static String _prestr(SL::DataPrecision p_pres) {
return "";
}
-
static String _opstr(SL::Operator p_op) {
return SL::get_operator_text(p_op);
}
-static String _mkid(const String& p_id) {
+static String _mkid(const String &p_id) {
- return "m_"+p_id;
+ return "m_" + p_id;
}
static String f2sp0(float p_float) {
- if (int(p_float)==p_float)
- return itos(p_float)+".0";
+ if (int(p_float) == p_float)
+ return itos(p_float) + ".0";
else
return rtoss(p_float);
}
-static String get_constant_text(SL::DataType p_type, const Vector<SL::ConstantNode::Value>& p_values) {
+static String get_constant_text(SL::DataType p_type, const Vector<SL::ConstantNode::Value> &p_values) {
- switch(p_type) {
- case SL::TYPE_BOOL: return p_values[0].boolean?"true":"false";
+ switch (p_type) {
+ case SL::TYPE_BOOL: return p_values[0].boolean ? "true" : "false";
case SL::TYPE_BVEC2:
case SL::TYPE_BVEC3:
case SL::TYPE_BVEC4: {
+ String text = "bvec" + itos(p_type - SL::TYPE_BOOL + 1) + "(";
+ for (int i = 0; i < p_values.size(); i++) {
+ if (i > 0)
+ text += ",";
- String text="bvec"+itos(p_type-SL::TYPE_BOOL+1)+"(";
- for(int i=0;i<p_values.size();i++) {
- if (i>0)
- text+=",";
-
- text+=p_values[i].boolean?"true":"false";
+ text += p_values[i].boolean ? "true" : "false";
}
- text+=")";
+ text += ")";
return text;
}
- case SL::TYPE_INT: return itos(p_values[0].sint);
+ case SL::TYPE_INT: return itos(p_values[0].sint);
case SL::TYPE_IVEC2:
case SL::TYPE_IVEC3:
case SL::TYPE_IVEC4: {
- String text="ivec"+itos(p_type-SL::TYPE_INT+1)+"(";
- for(int i=0;i<p_values.size();i++) {
- if (i>0)
- text+=",";
+ String text = "ivec" + itos(p_type - SL::TYPE_INT + 1) + "(";
+ for (int i = 0; i < p_values.size(); i++) {
+ if (i > 0)
+ text += ",";
- text+=itos(p_values[i].sint);
+ text += itos(p_values[i].sint);
}
- text+=")";
+ text += ")";
return text;
} break;
- case SL::TYPE_UINT: return itos(p_values[0].uint)+"u";
+ case SL::TYPE_UINT: return itos(p_values[0].uint) + "u";
case SL::TYPE_UVEC2:
case SL::TYPE_UVEC3:
- case SL::TYPE_UVEC4: {
+ case SL::TYPE_UVEC4: {
- String text="uvec"+itos(p_type-SL::TYPE_UINT+1)+"(";
- for(int i=0;i<p_values.size();i++) {
- if (i>0)
- text+=",";
+ String text = "uvec" + itos(p_type - SL::TYPE_UINT + 1) + "(";
+ for (int i = 0; i < p_values.size(); i++) {
+ if (i > 0)
+ text += ",";
- text+=itos(p_values[i].uint)+"u";
+ text += itos(p_values[i].uint) + "u";
}
- text+=")";
+ text += ")";
return text;
} break;
- case SL::TYPE_FLOAT: return f2sp0(p_values[0].real)+"f";
+ case SL::TYPE_FLOAT: return f2sp0(p_values[0].real) + "f";
case SL::TYPE_VEC2:
case SL::TYPE_VEC3:
- case SL::TYPE_VEC4: {
+ case SL::TYPE_VEC4: {
- String text="vec"+itos(p_type-SL::TYPE_FLOAT+1)+"(";
- for(int i=0;i<p_values.size();i++) {
- if (i>0)
- text+=",";
+ String text = "vec" + itos(p_type - SL::TYPE_FLOAT + 1) + "(";
+ for (int i = 0; i < p_values.size(); i++) {
+ if (i > 0)
+ text += ",";
- text+=f2sp0(p_values[i].real);
+ text += f2sp0(p_values[i].real);
}
- text+=")";
+ text += ")";
return text;
} break;
@@ -184,68 +179,68 @@ static String get_constant_text(SL::DataType p_type, const Vector<SL::ConstantNo
}
}
-void ShaderCompilerGLES3::_dump_function_deps(SL::ShaderNode* p_node, const StringName& p_for_func, const Map<StringName,String>& p_func_code, String& r_to_add, Set<StringName> &added) {
+void ShaderCompilerGLES3::_dump_function_deps(SL::ShaderNode *p_node, const StringName &p_for_func, const Map<StringName, String> &p_func_code, String &r_to_add, Set<StringName> &added) {
- int fidx=-1;
+ int fidx = -1;
- for(int i=0;i<p_node->functions.size();i++) {
- if (p_node->functions[i].name==p_for_func) {
- fidx=i;
+ for (int i = 0; i < p_node->functions.size(); i++) {
+ if (p_node->functions[i].name == p_for_func) {
+ fidx = i;
break;
}
}
- ERR_FAIL_COND(fidx==-1);
+ ERR_FAIL_COND(fidx == -1);
- for (Set<StringName>::Element *E=p_node->functions[fidx].uses_function.front();E;E=E->next()) {
+ for (Set<StringName>::Element *E = p_node->functions[fidx].uses_function.front(); E; E = E->next()) {
if (added.has(E->get())) {
continue; //was added already
}
- _dump_function_deps(p_node,E->get(),p_func_code,r_to_add,added);
+ _dump_function_deps(p_node, E->get(), p_func_code, r_to_add, added);
- SL::FunctionNode *fnode=NULL;
+ SL::FunctionNode *fnode = NULL;
- for(int i=0;i<p_node->functions.size();i++) {
- if (p_node->functions[i].name==E->get()) {
- fnode=p_node->functions[i].function;
+ for (int i = 0; i < p_node->functions.size(); i++) {
+ if (p_node->functions[i].name == E->get()) {
+ fnode = p_node->functions[i].function;
break;
}
}
ERR_FAIL_COND(!fnode);
- r_to_add+="\n";
+ r_to_add += "\n";
String header;
- header=_typestr(fnode->return_type)+" "+_mkid(fnode->name)+"(";
- for(int i=0;i<fnode->arguments.size();i++) {
+ header = _typestr(fnode->return_type) + " " + _mkid(fnode->name) + "(";
+ for (int i = 0; i < fnode->arguments.size(); i++) {
- if (i>0)
- header+=", ";
- header+=_prestr(fnode->arguments[i].precision)+_typestr(fnode->arguments[i].type)+" "+_mkid(fnode->arguments[i].name);
+ if (i > 0)
+ header += ", ";
+ header += _prestr(fnode->arguments[i].precision) + _typestr(fnode->arguments[i].type) + " " + _mkid(fnode->arguments[i].name);
}
- header+=")\n";
- r_to_add+=header;
- r_to_add+=p_func_code[E->get()];
+ header += ")\n";
+ r_to_add += header;
+ r_to_add += p_func_code[E->get()];
added.insert(E->get());
}
}
-String ShaderCompilerGLES3::_dump_node_code(SL::Node *p_node, int p_level, GeneratedCode& r_gen_code, IdentifierActions &p_actions, const DefaultIdentifierActions &p_default_actions) {
+String ShaderCompilerGLES3::_dump_node_code(SL::Node *p_node, int p_level, GeneratedCode &r_gen_code, IdentifierActions &p_actions, const DefaultIdentifierActions &p_default_actions) {
String code;
- switch(p_node->type) {
+ switch (p_node->type) {
case SL::Node::TYPE_SHADER: {
- SL::ShaderNode *pnode=(SL::ShaderNode*)p_node;
+ SL::ShaderNode *pnode = (SL::ShaderNode *)p_node;
- for(int i=0;i<pnode->render_modes.size();i++) {
+ for (int i = 0; i < pnode->render_modes.size(); i++) {
if (p_default_actions.render_mode_defines.has(pnode->render_modes[i]) && !used_rmode_defines.has(pnode->render_modes[i])) {
@@ -254,20 +249,19 @@ String ShaderCompilerGLES3::_dump_node_code(SL::Node *p_node, int p_level, Gener
}
if (p_actions.render_mode_flags.has(pnode->render_modes[i])) {
- *p_actions.render_mode_flags[pnode->render_modes[i]]=true;
+ *p_actions.render_mode_flags[pnode->render_modes[i]] = true;
}
if (p_actions.render_mode_values.has(pnode->render_modes[i])) {
- Pair<int*,int> &p = p_actions.render_mode_values[pnode->render_modes[i]];
- *p.first=p.second;
+ Pair<int *, int> &p = p_actions.render_mode_values[pnode->render_modes[i]];
+ *p.first = p.second;
}
}
+ int max_texture_uniforms = 0;
+ int max_uniforms = 0;
- int max_texture_uniforms=0;
- int max_uniforms=0;
-
- for(Map<StringName,SL::ShaderNode::Uniform>::Element *E=pnode->uniforms.front();E;E=E->next()) {
+ for (Map<StringName, SL::ShaderNode::Uniform>::Element *E = pnode->uniforms.front(); E; E = E->next()) {
if (SL::is_sampler_type(E->get().type))
max_texture_uniforms++;
else
@@ -284,66 +278,62 @@ String ShaderCompilerGLES3::_dump_node_code(SL::Node *p_node, int p_level, Gener
uniform_alignments.resize(max_uniforms);
uniform_defines.resize(max_uniforms);
- for(Map<StringName,SL::ShaderNode::Uniform>::Element *E=pnode->uniforms.front();E;E=E->next()) {
+ for (Map<StringName, SL::ShaderNode::Uniform>::Element *E = pnode->uniforms.front(); E; E = E->next()) {
String ucode;
if (SL::is_sampler_type(E->get().type)) {
- ucode="uniform ";
+ ucode = "uniform ";
}
- ucode+=_prestr(E->get().precission);
- ucode+=_typestr(E->get().type);
- ucode+=" "+_mkid(E->key());
- ucode+=";\n";
+ ucode += _prestr(E->get().precission);
+ ucode += _typestr(E->get().type);
+ ucode += " " + _mkid(E->key());
+ ucode += ";\n";
if (SL::is_sampler_type(E->get().type)) {
- r_gen_code.vertex_global+=ucode;
- r_gen_code.fragment_global+=ucode;
- r_gen_code.texture_uniforms[E->get().texture_order]=_mkid(E->key());
- r_gen_code.texture_hints[E->get().texture_order]=E->get().hint;
+ r_gen_code.vertex_global += ucode;
+ r_gen_code.fragment_global += ucode;
+ r_gen_code.texture_uniforms[E->get().texture_order] = _mkid(E->key());
+ r_gen_code.texture_hints[E->get().texture_order] = E->get().hint;
} else {
if (r_gen_code.uniforms.empty()) {
r_gen_code.defines.push_back(String("#define USE_MATERIAL\n").ascii());
}
- uniform_defines[E->get().order]=ucode;
- uniform_sizes[E->get().order]=_get_datatype_size(E->get().type);
- uniform_alignments[E->get().order]=MIN(16,_get_datatype_size(E->get().type));
+ uniform_defines[E->get().order] = ucode;
+ uniform_sizes[E->get().order] = _get_datatype_size(E->get().type);
+ uniform_alignments[E->get().order] = MIN(16, _get_datatype_size(E->get().type));
}
- p_actions.uniforms->insert(E->key(),E->get());
-
+ p_actions.uniforms->insert(E->key(), E->get());
}
- for(int i=0;i<max_uniforms;i++) {
- r_gen_code.uniforms+=uniform_defines[i];
+ for (int i = 0; i < max_uniforms; i++) {
+ r_gen_code.uniforms += uniform_defines[i];
}
// add up
- for(int i=0;i<uniform_sizes.size();i++) {
+ for (int i = 0; i < uniform_sizes.size(); i++) {
- if (i>0) {
+ if (i > 0) {
- int align = uniform_sizes[i-1] % uniform_alignments[i];
- if (align!=0) {
- uniform_sizes[i-1]+=uniform_alignments[i]-align;
+ int align = uniform_sizes[i - 1] % uniform_alignments[i];
+ if (align != 0) {
+ uniform_sizes[i - 1] += uniform_alignments[i] - align;
}
- uniform_sizes[i]=uniform_sizes[i]+uniform_sizes[i-1];
-
+ uniform_sizes[i] = uniform_sizes[i] + uniform_sizes[i - 1];
}
}
//offset
r_gen_code.uniform_offsets.resize(uniform_sizes.size());
- for(int i=0;i<uniform_sizes.size();i++) {
+ for (int i = 0; i < uniform_sizes.size(); i++) {
- if (i>0)
- r_gen_code.uniform_offsets[i]=uniform_sizes[i-1];
+ if (i > 0)
+ r_gen_code.uniform_offsets[i] = uniform_sizes[i - 1];
else
- r_gen_code.uniform_offsets[i]=0;
-
-
+ r_gen_code.uniform_offsets[i] = 0;
}
-/*
+ /*
for(Map<StringName,SL::ShaderNode::Uniform>::Element *E=pnode->uniforms.front();E;E=E->next()) {
if (SL::is_sampler_type(E->get().type)) {
@@ -356,28 +346,28 @@ String ShaderCompilerGLES3::_dump_node_code(SL::Node *p_node, int p_level, Gener
*/
if (uniform_sizes.size()) {
- r_gen_code.uniform_total_size=uniform_sizes[ uniform_sizes.size() -1 ];
+ r_gen_code.uniform_total_size = uniform_sizes[uniform_sizes.size() - 1];
} else {
- r_gen_code.uniform_total_size=0;
+ r_gen_code.uniform_total_size = 0;
}
- for(Map<StringName,SL::ShaderNode::Varying>::Element *E=pnode->varyings.front();E;E=E->next()) {
+ for (Map<StringName, SL::ShaderNode::Varying>::Element *E = pnode->varyings.front(); E; E = E->next()) {
String vcode;
- vcode+=_prestr(E->get().precission);
- vcode+=_typestr(E->get().type);
- vcode+=" "+String(E->key());
- vcode+=";\n";
- r_gen_code.vertex_global+="out "+vcode;
- r_gen_code.fragment_global+="in "+vcode;
+ vcode += _prestr(E->get().precission);
+ vcode += _typestr(E->get().type);
+ vcode += " " + String(E->key());
+ vcode += ";\n";
+ r_gen_code.vertex_global += "out " + vcode;
+ r_gen_code.fragment_global += "in " + vcode;
}
- Map<StringName,String> function_code;
+ Map<StringName, String> function_code;
//code for functions
- for(int i=0;i<pnode->functions.size();i++) {
- SL::FunctionNode *fnode=pnode->functions[i].function;
- function_code[fnode->name]=_dump_node_code(fnode->body,p_level+1,r_gen_code,p_actions,p_default_actions);
+ for (int i = 0; i < pnode->functions.size(); i++) {
+ SL::FunctionNode *fnode = pnode->functions[i].function;
+ function_code[fnode->name] = _dump_node_code(fnode->body, p_level + 1, r_gen_code, p_actions, p_default_actions);
}
//place functions in actual code
@@ -385,28 +375,28 @@ String ShaderCompilerGLES3::_dump_node_code(SL::Node *p_node, int p_level, Gener
Set<StringName> added_vtx;
Set<StringName> added_fragment; //share for light
- for(int i=0;i<pnode->functions.size();i++) {
+ for (int i = 0; i < pnode->functions.size(); i++) {
- SL::FunctionNode *fnode=pnode->functions[i].function;
+ SL::FunctionNode *fnode = pnode->functions[i].function;
- current_func_name=fnode->name;
+ current_func_name = fnode->name;
- if (fnode->name=="vertex") {
+ if (fnode->name == "vertex") {
- _dump_function_deps(pnode,fnode->name,function_code,r_gen_code.vertex_global,added_vtx);
- r_gen_code.vertex=function_code["vertex"];
+ _dump_function_deps(pnode, fnode->name, function_code, r_gen_code.vertex_global, added_vtx);
+ r_gen_code.vertex = function_code["vertex"];
}
- if (fnode->name=="fragment") {
+ if (fnode->name == "fragment") {
- _dump_function_deps(pnode,fnode->name,function_code,r_gen_code.fragment_global,added_fragment);
- r_gen_code.fragment=function_code["fragment"];
+ _dump_function_deps(pnode, fnode->name, function_code, r_gen_code.fragment_global, added_fragment);
+ r_gen_code.fragment = function_code["fragment"];
}
- if (fnode->name=="light") {
+ if (fnode->name == "light") {
- _dump_function_deps(pnode,fnode->name,function_code,r_gen_code.fragment_global,added_fragment);
- r_gen_code.light=function_code["light"];
+ _dump_function_deps(pnode, fnode->name, function_code, r_gen_code.fragment_global, added_fragment);
+ r_gen_code.light = function_code["light"];
}
}
@@ -416,72 +406,70 @@ String ShaderCompilerGLES3::_dump_node_code(SL::Node *p_node, int p_level, Gener
} break;
case SL::Node::TYPE_BLOCK: {
- SL::BlockNode *bnode=(SL::BlockNode*)p_node;
+ SL::BlockNode *bnode = (SL::BlockNode *)p_node;
//variables
- code+=_mktab(p_level-1)+"{\n";
- for(Map<StringName,SL::BlockNode::Variable>::Element *E=bnode->variables.front();E;E=E->next()) {
+ code += _mktab(p_level - 1) + "{\n";
+ for (Map<StringName, SL::BlockNode::Variable>::Element *E = bnode->variables.front(); E; E = E->next()) {
- code+=_mktab(p_level)+_prestr(E->get().precision)+_typestr(E->get().type)+" "+_mkid(E->key())+";\n";
+ code += _mktab(p_level) + _prestr(E->get().precision) + _typestr(E->get().type) + " " + _mkid(E->key()) + ";\n";
}
- for(int i=0;i<bnode->statements.size();i++) {
+ for (int i = 0; i < bnode->statements.size(); i++) {
- String scode = _dump_node_code(bnode->statements[i],p_level,r_gen_code,p_actions,p_default_actions);
+ String scode = _dump_node_code(bnode->statements[i], p_level, r_gen_code, p_actions, p_default_actions);
- if (bnode->statements[i]->type==SL::Node::TYPE_CONTROL_FLOW || bnode->statements[i]->type==SL::Node::TYPE_CONTROL_FLOW) {
+ if (bnode->statements[i]->type == SL::Node::TYPE_CONTROL_FLOW || bnode->statements[i]->type == SL::Node::TYPE_CONTROL_FLOW) {
// FIXME: if (A || A) ? I am hesitant to delete one of them, could be copy-paste error.
- code+=scode; //use directly
+ code += scode; //use directly
} else {
- code+=_mktab(p_level)+scode+";\n";
+ code += _mktab(p_level) + scode + ";\n";
}
}
- code+=_mktab(p_level-1)+"}\n";
-
+ code += _mktab(p_level - 1) + "}\n";
} break;
case SL::Node::TYPE_VARIABLE: {
- SL::VariableNode *vnode=(SL::VariableNode*)p_node;
+ SL::VariableNode *vnode = (SL::VariableNode *)p_node;
if (p_default_actions.usage_defines.has(vnode->name) && !used_name_defines.has(vnode->name)) {
String define = p_default_actions.usage_defines[vnode->name];
if (define.begins_with("@")) {
- define = p_default_actions.usage_defines[define.substr(1,define.length())];
+ define = p_default_actions.usage_defines[define.substr(1, define.length())];
}
r_gen_code.defines.push_back(define.utf8());
used_name_defines.insert(vnode->name);
}
if (p_actions.usage_flag_pointers.has(vnode->name) && !used_flag_pointers.has(vnode->name)) {
- *p_actions.usage_flag_pointers[vnode->name]=true;
+ *p_actions.usage_flag_pointers[vnode->name] = true;
used_flag_pointers.insert(vnode->name);
}
if (p_default_actions.renames.has(vnode->name))
- code=p_default_actions.renames[vnode->name];
+ code = p_default_actions.renames[vnode->name];
else
- code=_mkid(vnode->name);
+ code = _mkid(vnode->name);
- if (vnode->name==time_name) {
- if (current_func_name==vertex_name) {
- r_gen_code.uses_vertex_time=true;
+ if (vnode->name == time_name) {
+ if (current_func_name == vertex_name) {
+ r_gen_code.uses_vertex_time = true;
}
- if (current_func_name==fragment_name) {
- r_gen_code.uses_fragment_time=true;
+ if (current_func_name == fragment_name) {
+ r_gen_code.uses_fragment_time = true;
}
}
} break;
case SL::Node::TYPE_CONSTANT: {
- SL::ConstantNode *cnode=(SL::ConstantNode*)p_node;
- return get_constant_text(cnode->datatype,cnode->values);
+ SL::ConstantNode *cnode = (SL::ConstantNode *)p_node;
+ return get_constant_text(cnode->datatype, cnode->values);
} break;
case SL::Node::TYPE_OPERATOR: {
- SL::OperatorNode *onode=(SL::OperatorNode*)p_node;
+ SL::OperatorNode *onode = (SL::OperatorNode *)p_node;
-
- switch(onode->op) {
+ switch (onode->op) {
case SL::OP_ASSIGN:
case SL::OP_ASSIGN_ADD:
@@ -494,276 +482,259 @@ String ShaderCompilerGLES3::_dump_node_code(SL::Node *p_node, int p_level, Gener
case SL::OP_ASSIGN_BIT_AND:
case SL::OP_ASSIGN_BIT_OR:
case SL::OP_ASSIGN_BIT_XOR:
- code=_dump_node_code(onode->arguments[0],p_level,r_gen_code,p_actions,p_default_actions)+_opstr(onode->op)+_dump_node_code(onode->arguments[1],p_level,r_gen_code,p_actions,p_default_actions);
+ code = _dump_node_code(onode->arguments[0], p_level, r_gen_code, p_actions, p_default_actions) + _opstr(onode->op) + _dump_node_code(onode->arguments[1], p_level, r_gen_code, p_actions, p_default_actions);
break;
case SL::OP_BIT_INVERT:
case SL::OP_NEGATE:
case SL::OP_NOT:
case SL::OP_DECREMENT:
case SL::OP_INCREMENT:
- code=_opstr(onode->op)+_dump_node_code(onode->arguments[0],p_level,r_gen_code,p_actions,p_default_actions);
+ code = _opstr(onode->op) + _dump_node_code(onode->arguments[0], p_level, r_gen_code, p_actions, p_default_actions);
break;
case SL::OP_POST_DECREMENT:
case SL::OP_POST_INCREMENT:
- code=_dump_node_code(onode->arguments[0],p_level,r_gen_code,p_actions,p_default_actions)+_opstr(onode->op);
+ code = _dump_node_code(onode->arguments[0], p_level, r_gen_code, p_actions, p_default_actions) + _opstr(onode->op);
break;
case SL::OP_CALL:
case SL::OP_CONSTRUCT: {
- ERR_FAIL_COND_V(onode->arguments[0]->type!=SL::Node::TYPE_VARIABLE,String());
+ ERR_FAIL_COND_V(onode->arguments[0]->type != SL::Node::TYPE_VARIABLE, String());
- SL::VariableNode *vnode=(SL::VariableNode*)onode->arguments[0];
+ SL::VariableNode *vnode = (SL::VariableNode *)onode->arguments[0];
- if (onode->op==SL::OP_CONSTRUCT) {
- code+=String(vnode->name);
+ if (onode->op == SL::OP_CONSTRUCT) {
+ code += String(vnode->name);
} else {
if (internal_functions.has(vnode->name)) {
- code+=vnode->name;
+ code += vnode->name;
} else if (p_default_actions.renames.has(vnode->name)) {
- code+=p_default_actions.renames[vnode->name];
+ code += p_default_actions.renames[vnode->name];
} else {
- code+=_mkid(vnode->name);
+ code += _mkid(vnode->name);
}
}
- code+="(";
+ code += "(";
- for(int i=1;i<onode->arguments.size();i++) {
- if (i>1)
- code+=", ";
- code+=_dump_node_code(onode->arguments[i],p_level,r_gen_code,p_actions,p_default_actions);
+ for (int i = 1; i < onode->arguments.size(); i++) {
+ if (i > 1)
+ code += ", ";
+ code += _dump_node_code(onode->arguments[i], p_level, r_gen_code, p_actions, p_default_actions);
}
- code+=")";
+ code += ")";
} break;
default: {
- code="("+_dump_node_code(onode->arguments[0],p_level,r_gen_code,p_actions,p_default_actions)+_opstr(onode->op)+_dump_node_code(onode->arguments[1],p_level,r_gen_code,p_actions,p_default_actions)+")";
+ code = "(" + _dump_node_code(onode->arguments[0], p_level, r_gen_code, p_actions, p_default_actions) + _opstr(onode->op) + _dump_node_code(onode->arguments[1], p_level, r_gen_code, p_actions, p_default_actions) + ")";
break;
-
}
}
} break;
case SL::Node::TYPE_CONTROL_FLOW: {
- SL::ControlFlowNode *cfnode=(SL::ControlFlowNode*)p_node;
- if (cfnode->flow_op==SL::FLOW_OP_IF) {
+ SL::ControlFlowNode *cfnode = (SL::ControlFlowNode *)p_node;
+ if (cfnode->flow_op == SL::FLOW_OP_IF) {
- code+=_mktab(p_level)+"if ("+_dump_node_code(cfnode->expressions[0],p_level,r_gen_code,p_actions,p_default_actions)+")\n";
- code+=_dump_node_code(cfnode->blocks[0],p_level+1,r_gen_code,p_actions,p_default_actions);
- if (cfnode->blocks.size()==2) {
+ code += _mktab(p_level) + "if (" + _dump_node_code(cfnode->expressions[0], p_level, r_gen_code, p_actions, p_default_actions) + ")\n";
+ code += _dump_node_code(cfnode->blocks[0], p_level + 1, r_gen_code, p_actions, p_default_actions);
+ if (cfnode->blocks.size() == 2) {
- code+=_mktab(p_level)+"else\n";
- code+=_dump_node_code(cfnode->blocks[1],p_level+1,r_gen_code,p_actions,p_default_actions);
+ code += _mktab(p_level) + "else\n";
+ code += _dump_node_code(cfnode->blocks[1], p_level + 1, r_gen_code, p_actions, p_default_actions);
}
-
- } else if (cfnode->flow_op==SL::FLOW_OP_RETURN) {
+ } else if (cfnode->flow_op == SL::FLOW_OP_RETURN) {
if (cfnode->blocks.size()) {
- code="return "+_dump_node_code(cfnode->blocks[0],p_level,r_gen_code,p_actions,p_default_actions);
+ code = "return " + _dump_node_code(cfnode->blocks[0], p_level, r_gen_code, p_actions, p_default_actions);
} else {
- code="return";
+ code = "return";
}
}
} break;
case SL::Node::TYPE_MEMBER: {
- SL::MemberNode *mnode=(SL::MemberNode*)p_node;
- code=_dump_node_code(mnode->owner,p_level,r_gen_code,p_actions,p_default_actions)+"."+mnode->name;
+ SL::MemberNode *mnode = (SL::MemberNode *)p_node;
+ code = _dump_node_code(mnode->owner, p_level, r_gen_code, p_actions, p_default_actions) + "." + mnode->name;
} break;
}
return code;
-
}
+Error ShaderCompilerGLES3::compile(VS::ShaderMode p_mode, const String &p_code, IdentifierActions *p_actions, const String &p_path, GeneratedCode &r_gen_code) {
-Error ShaderCompilerGLES3::compile(VS::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));
-
-
- Error err = parser.compile(p_code,ShaderTypes::get_singleton()->get_functions(p_mode),ShaderTypes::get_singleton()->get_modes(p_mode));
-
- if (err!=OK) {
+ if (err != OK) {
#if 1
Vector<String> shader = p_code.split("\n");
- for(int i=0;i<shader.size();i++) {
- print_line(itos(i)+" "+shader[i]);
+ for (int i = 0; i < shader.size(); i++) {
+ print_line(itos(i) + " " + shader[i]);
}
#endif
- _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(NULL, p_path.utf8().get_data(), parser.get_error_line(), parser.get_error_text().utf8().get_data(), ERR_HANDLER_SHADER);
return err;
}
r_gen_code.defines.clear();
- r_gen_code.vertex=String();
- r_gen_code.vertex_global=String();
- r_gen_code.fragment=String();
- r_gen_code.fragment_global=String();
- r_gen_code.light=String();
- r_gen_code.uses_fragment_time=false;
- r_gen_code.uses_vertex_time=false;
-
-
+ r_gen_code.vertex = String();
+ r_gen_code.vertex_global = String();
+ r_gen_code.fragment = String();
+ r_gen_code.fragment_global = String();
+ r_gen_code.light = String();
+ r_gen_code.uses_fragment_time = false;
+ r_gen_code.uses_vertex_time = false;
used_name_defines.clear();
used_rmode_defines.clear();
used_flag_pointers.clear();
- _dump_node_code(parser.get_shader(),1,r_gen_code,*p_actions,actions[p_mode]);
+ _dump_node_code(parser.get_shader(), 1, r_gen_code, *p_actions, actions[p_mode]);
return OK;
-
}
-
ShaderCompilerGLES3::ShaderCompilerGLES3() {
/** CANVAS ITEM SHADER **/
- actions[VS::SHADER_CANVAS_ITEM].renames["SRC_VERTEX"]="vertex";
- actions[VS::SHADER_CANVAS_ITEM].renames["VERTEX"]="outvec.xy";
- actions[VS::SHADER_CANVAS_ITEM].renames["VERTEX_COLOR"]="vertex_color";
- actions[VS::SHADER_CANVAS_ITEM].renames["UV"]="uv_interp";
- actions[VS::SHADER_CANVAS_ITEM].renames["POINT_SIZE"]="gl_PointSize";
-
- 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";
- actions[VS::SHADER_CANVAS_ITEM].renames["TIME"]="time";
-
- 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["UV"]="uv_interp";
- actions[VS::SHADER_CANVAS_ITEM].renames["COLOR"]="color";
- 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["SCREEN_UV"]="screen_uv";
- actions[VS::SHADER_CANVAS_ITEM].renames["SCREEN_TEXTURE"]="screen_texture";
- 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["SRC_VERTEX"] = "vertex";
+ actions[VS::SHADER_CANVAS_ITEM].renames["VERTEX"] = "outvec.xy";
+ actions[VS::SHADER_CANVAS_ITEM].renames["VERTEX_COLOR"] = "vertex_color";
+ actions[VS::SHADER_CANVAS_ITEM].renames["UV"] = "uv_interp";
+ actions[VS::SHADER_CANVAS_ITEM].renames["POINT_SIZE"] = "gl_PointSize";
+
+ 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";
+ actions[VS::SHADER_CANVAS_ITEM].renames["TIME"] = "time";
+
+ 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["UV"] = "uv_interp";
+ actions[VS::SHADER_CANVAS_ITEM].renames["COLOR"] = "color";
+ 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["SCREEN_UV"] = "screen_uv";
+ actions[VS::SHADER_CANVAS_ITEM].renames["SCREEN_TEXTURE"] = "screen_texture";
+ 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_SHADOW_COLOR"]="light_shadow_color";
- actions[VS::SHADER_CANVAS_ITEM].renames["LIGHT"]="light";
- actions[VS::SHADER_CANVAS_ITEM].renames["SHADOW_COLOR"]="shadow_color";
+ actions[VS::SHADER_CANVAS_ITEM].renames["LIGHT"] = "light";
+ actions[VS::SHADER_CANVAS_ITEM].renames["SHADOW_COLOR"] = "shadow_color";
- 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["NORMAL"]="#define NORMAL_USED\n";
- actions[VS::SHADER_CANVAS_ITEM].usage_defines["NORMALMAP"]="#define NORMALMAP_USED\n";
- actions[VS::SHADER_CANVAS_ITEM].usage_defines["SHADOW_COLOR"]="#define SHADOW_COLOR_USED\n";
+ 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["NORMAL"] = "#define NORMAL_USED\n";
+ actions[VS::SHADER_CANVAS_ITEM].usage_defines["NORMALMAP"] = "#define NORMALMAP_USED\n";
+ actions[VS::SHADER_CANVAS_ITEM].usage_defines["SHADOW_COLOR"] = "#define SHADOW_COLOR_USED\n";
- actions[VS::SHADER_CANVAS_ITEM].render_mode_defines["skip_transform"]="#define SKIP_TRANSFORM_USED\n";
+ actions[VS::SHADER_CANVAS_ITEM].render_mode_defines["skip_transform"] = "#define SKIP_TRANSFORM_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["PROJECTION_MATRIX"]="projection_matrix";
-
-
- 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["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"]="gl_PointSize";
+ 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["PROJECTION_MATRIX"] = "projection_matrix";
+
+ 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["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"] = "gl_PointSize";
//actions[VS::SHADER_SPATIAL].renames["INSTANCE_ID"]=ShaderLanguage::TYPE_INT;
//builtins
- actions[VS::SHADER_SPATIAL].renames["TIME"]="time";
+ actions[VS::SHADER_SPATIAL].renames["TIME"] = "time";
//actions[VS::SHADER_SPATIAL].renames["VIEWPORT_SIZE"]=ShaderLanguage::TYPE_VEC2;
- actions[VS::SHADER_SPATIAL].renames["FRAGCOORD"]="gl_FragCoord";
- actions[VS::SHADER_SPATIAL].renames["FRONT_FACING"]="gl_FrotFacing";
- 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["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_SPREAD"]="sss_spread";
- actions[VS::SHADER_SPATIAL].renames["SSS_STRENGTH"]="sss_strength";
- actions[VS::SHADER_SPATIAL].renames["AO"]="ao";
- actions[VS::SHADER_SPATIAL].renames["EMISSION"]="emission";
- actions[VS::SHADER_SPATIAL].renames["DISCARD"]="_discard";
+ actions[VS::SHADER_SPATIAL].renames["FRAGCOORD"] = "gl_FragCoord";
+ actions[VS::SHADER_SPATIAL].renames["FRONT_FACING"] = "gl_FrotFacing";
+ 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["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_SPREAD"] = "sss_spread";
+ actions[VS::SHADER_SPATIAL].renames["SSS_STRENGTH"] = "sss_strength";
+ actions[VS::SHADER_SPATIAL].renames["AO"] = "ao";
+ actions[VS::SHADER_SPATIAL].renames["EMISSION"] = "emission";
+ actions[VS::SHADER_SPATIAL].renames["DISCARD"] = "_discard";
//actions[VS::SHADER_SPATIAL].renames["SCREEN_UV"]=ShaderLanguage::TYPE_VEC2;
- actions[VS::SHADER_SPATIAL].renames["POINT_COORD"]="gl_PointCoord";
-
-
- 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["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["SSS_STRENGTH"]="#define ENABLE_SSS_MOTION\n";
+ actions[VS::SHADER_SPATIAL].renames["POINT_COORD"] = "gl_PointCoord";
- actions[VS::SHADER_SPATIAL].renames["SSS_STRENGTH"]="sss_strength";
+ 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["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["SSS_STRENGTH"] = "#define ENABLE_SSS_MOTION\n";
- actions[VS::SHADER_SPATIAL].render_mode_defines["skip_transform"]="#define SKIP_TRANSFORM_USED\n";
+ actions[VS::SHADER_SPATIAL].renames["SSS_STRENGTH"] = "sss_strength";
+ actions[VS::SHADER_SPATIAL].render_mode_defines["skip_transform"] = "#define SKIP_TRANSFORM_USED\n";
/* PARTICLES SHADER */
- actions[VS::SHADER_PARTICLES].renames["COLOR"]="color";
- actions[VS::SHADER_PARTICLES].renames["VELOCITY"]="out_velocity_active.xyz";
- actions[VS::SHADER_PARTICLES].renames["MASS"]="mass";
- actions[VS::SHADER_PARTICLES].renames["ACTIVE"]="active";
- actions[VS::SHADER_PARTICLES].renames["RESTART"]="restart";
- actions[VS::SHADER_PARTICLES].renames["CUSTOM"]="out_custom";
- actions[VS::SHADER_PARTICLES].renames["TRANSFORM"]="xform";
- actions[VS::SHADER_PARTICLES].renames["TIME"]="time";
- actions[VS::SHADER_PARTICLES].renames["LIFETIME"]="lifetime";
- actions[VS::SHADER_PARTICLES].renames["DELTA"]="delta";
- actions[VS::SHADER_PARTICLES].renames["SEED"]="seed";
- actions[VS::SHADER_PARTICLES].renames["ORIGIN"]="origin";
- actions[VS::SHADER_PARTICLES].renames["INDEX"]="index";
-
- 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";
-
-
- vertex_name="vertex";
- fragment_name="fragment";
- time_name="TIME";
-
+ actions[VS::SHADER_PARTICLES].renames["COLOR"] = "color";
+ actions[VS::SHADER_PARTICLES].renames["VELOCITY"] = "out_velocity_active.xyz";
+ actions[VS::SHADER_PARTICLES].renames["MASS"] = "mass";
+ actions[VS::SHADER_PARTICLES].renames["ACTIVE"] = "active";
+ actions[VS::SHADER_PARTICLES].renames["RESTART"] = "restart";
+ actions[VS::SHADER_PARTICLES].renames["CUSTOM"] = "out_custom";
+ actions[VS::SHADER_PARTICLES].renames["TRANSFORM"] = "xform";
+ actions[VS::SHADER_PARTICLES].renames["TIME"] = "time";
+ actions[VS::SHADER_PARTICLES].renames["LIFETIME"] = "lifetime";
+ actions[VS::SHADER_PARTICLES].renames["DELTA"] = "delta";
+ actions[VS::SHADER_PARTICLES].renames["SEED"] = "seed";
+ actions[VS::SHADER_PARTICLES].renames["ORIGIN"] = "origin";
+ actions[VS::SHADER_PARTICLES].renames["INDEX"] = "index";
+
+ 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";
+
+ vertex_name = "vertex";
+ fragment_name = "fragment";
+ time_name = "TIME";
List<String> func_list;
ShaderLanguage::get_builtin_funcs(&func_list);
- for (List<String>::Element *E=func_list.front();E;E=E->next()) {
+ for (List<String>::Element *E = func_list.front(); E; E = E->next()) {
internal_functions.insert(E->get());
}
}
diff --git a/drivers/gles3/shader_compiler_gles3.h b/drivers/gles3/shader_compiler_gles3.h
index bbdfc7865f..44d6b3a349 100644
--- a/drivers/gles3/shader_compiler_gles3.h
+++ b/drivers/gles3/shader_compiler_gles3.h
@@ -29,20 +29,20 @@
#ifndef SHADERCOMPILERGLES3_H
#define SHADERCOMPILERGLES3_H
+#include "pair.h"
#include "servers/visual/shader_language.h"
#include "servers/visual/shader_types.h"
#include "servers/visual_server.h"
-#include "pair.h"
class ShaderCompilerGLES3 {
public:
struct IdentifierActions {
- Map<StringName,Pair<int*,int> > render_mode_values;
- Map<StringName,bool*> render_mode_flags;
- Map<StringName,bool*> usage_flag_pointers;
+ Map<StringName, Pair<int *, int> > render_mode_values;
+ Map<StringName, bool *> render_mode_flags;
+ Map<StringName, bool *> usage_flag_pointers;
- Map<StringName,ShaderLanguage::ShaderNode::Uniform> *uniforms;
+ Map<StringName, ShaderLanguage::ShaderNode::Uniform> *uniforms;
};
struct GeneratedCode {
@@ -62,23 +62,20 @@ public:
bool uses_fragment_time;
bool uses_vertex_time;
-
};
private:
-
ShaderLanguage parser;
struct DefaultIdentifierActions {
- Map<StringName,String> renames;
- Map<StringName,String> render_mode_defines;
- Map<StringName,String> usage_defines;
+ Map<StringName, String> renames;
+ Map<StringName, String> render_mode_defines;
+ Map<StringName, String> usage_defines;
};
- void _dump_function_deps(ShaderLanguage::ShaderNode *p_node, const StringName& p_for_func, const Map<StringName, String> &p_func_code, String& r_to_add,Set<StringName> &added);
- String _dump_node_code(ShaderLanguage::Node *p_node, int p_level, GeneratedCode &r_gen_code, IdentifierActions& p_actions, const DefaultIdentifierActions& p_default_actions);
-
+ void _dump_function_deps(ShaderLanguage::ShaderNode *p_node, const StringName &p_for_func, const Map<StringName, String> &p_func_code, String &r_to_add, Set<StringName> &added);
+ String _dump_node_code(ShaderLanguage::Node *p_node, int p_level, GeneratedCode &r_gen_code, IdentifierActions &p_actions, const DefaultIdentifierActions &p_default_actions);
StringName current_func_name;
StringName vertex_name;
@@ -90,14 +87,10 @@ private:
Set<StringName> used_rmode_defines;
Set<StringName> internal_functions;
-
DefaultIdentifierActions actions[VS::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(VS::ShaderMode p_mode, const String &p_code, IdentifierActions *p_actions, const String &p_path, GeneratedCode &r_gen_code);
ShaderCompilerGLES3();
};
diff --git a/drivers/gles3/shader_gles3.cpp b/drivers/gles3/shader_gles3.cpp
index a148d68a91..3894f24295 100644
--- a/drivers/gles3/shader_gles3.cpp
+++ b/drivers/gles3/shader_gles3.cpp
@@ -28,29 +28,26 @@
/*************************************************************************/
#include "shader_gles3.h"
-
#include "print_string.h"
//#define DEBUG_OPENGL
#ifdef DEBUG_OPENGL
-#define DEBUG_TEST_ERROR(m_section)\
-{\
- uint32_t err = glGetError();\
- if (err) {\
- print_line("OpenGL Error #"+itos(err)+" at: "+m_section);\
- }\
-}
+#define DEBUG_TEST_ERROR(m_section) \
+ { \
+ uint32_t err = glGetError(); \
+ if (err) { \
+ print_line("OpenGL Error #" + itos(err) + " at: " + m_section); \
+ } \
+ }
#else
#define DEBUG_TEST_ERROR(m_section)
#endif
-ShaderGLES3 *ShaderGLES3::active=NULL;
-
-
+ShaderGLES3 *ShaderGLES3::active = NULL;
//#define DEBUG_SHADER
@@ -64,7 +61,6 @@ ShaderGLES3 *ShaderGLES3::active=NULL;
#endif
-
void ShaderGLES3::bind_uniforms() {
if (!uniforms_dirty) {
@@ -72,34 +68,33 @@ void ShaderGLES3::bind_uniforms() {
};
// upload default uniforms
- const Map<uint32_t,Variant>::Element *E =uniform_defaults.front();
+ const Map<uint32_t, Variant>::Element *E = uniform_defaults.front();
- while(E) {
- int idx=E->key();
- int location=version->uniform_location[idx];
+ while (E) {
+ int idx = E->key();
+ int location = version->uniform_location[idx];
- if (location<0) {
- E=E->next();
+ if (location < 0) {
+ E = E->next();
continue;
-
}
- const Variant &v=E->value();
+ const Variant &v = E->value();
_set_uniform_variant(location, v);
//print_line("uniform "+itos(location)+" value "+v+ " type "+Variant::get_type_name(v.get_type()));
- E=E->next();
+ E = E->next();
};
- const Map<uint32_t,CameraMatrix>::Element* C = uniform_cameras.front();
+ const Map<uint32_t, CameraMatrix>::Element *C = uniform_cameras.front();
while (C) {
int location = version->uniform_location[C->key()];
- if (location<0) {
- C=C->next();
+ if (location < 0) {
+ C = C->next();
continue;
}
- glUniformMatrix4fv(location,1,false,&(C->get().matrix[0][0]));
+ glUniformMatrix4fv(location, 1, false, &(C->get().matrix[0][0]));
C = C->next();
};
@@ -114,24 +109,24 @@ GLint ShaderGLES3::get_uniform_location(int p_idx) const {
};
bool ShaderGLES3::bind() {
-
- if (active!=this || !version || new_conditional_version.key!=conditional_version.key) {
- conditional_version=new_conditional_version;
+
+ if (active != this || !version || new_conditional_version.key != conditional_version.key) {
+ conditional_version = new_conditional_version;
version = get_current_version();
} else {
return false;
}
-
- ERR_FAIL_COND_V(!version,false);
- glUseProgram( version->id );
+ ERR_FAIL_COND_V(!version, false);
+
+ glUseProgram(version->id);
DEBUG_TEST_ERROR("Use Program");
- active=this;
+ active = this;
uniforms_dirty = true;
-/*
+ /*
* why on earth is this code here?
for (int i=0;i<texunit_pair_count;i++) {
@@ -145,152 +140,133 @@ bool ShaderGLES3::bind() {
void ShaderGLES3::unbind() {
- version=NULL;
+ version = NULL;
glUseProgram(0);
uniforms_dirty = true;
- active=NULL;
+ active = NULL;
}
+static void _display_error_with_code(const String &p_error, const Vector<const char *> &p_code) {
-static void _display_error_with_code(const String& p_error,const Vector<const char*>& p_code) {
-
-
- int line=1;
+ int line = 1;
String total_code;
- for(int i=0;i<p_code.size();i++) {
- total_code+=String(p_code[i]);
+ for (int i = 0; i < p_code.size(); i++) {
+ total_code += String(p_code[i]);
}
Vector<String> lines = String(total_code).split("\n");
- for(int j=0;j<lines.size();j++) {
+ for (int j = 0; j < lines.size(); j++) {
- print_line(itos(line)+": "+lines[j]);
+ print_line(itos(line) + ": " + lines[j]);
line++;
}
ERR_PRINTS(p_error);
-
}
-ShaderGLES3::Version* ShaderGLES3::get_current_version() {
+ShaderGLES3::Version *ShaderGLES3::get_current_version() {
- Version *_v=version_map.getptr(conditional_version);
+ Version *_v = version_map.getptr(conditional_version);
if (_v) {
- if (conditional_version.code_version!=0) {
- CustomCode *cc=custom_code_map.getptr(conditional_version.code_version);
- ERR_FAIL_COND_V(!cc,_v);
- if (cc->version==_v->code_version)
+ if (conditional_version.code_version != 0) {
+ CustomCode *cc = custom_code_map.getptr(conditional_version.code_version);
+ ERR_FAIL_COND_V(!cc, _v);
+ if (cc->version == _v->code_version)
return _v;
} else {
return _v;
}
-
}
-
-
if (!_v)
- version_map[conditional_version]=Version();
-
+ version_map[conditional_version] = Version();
Version &v = version_map[conditional_version];
if (!_v) {
- v.uniform_location = memnew_arr( GLint, uniform_count );
+ v.uniform_location = memnew_arr(GLint, uniform_count);
} else {
if (v.ok) {
//bye bye shaders
- glDeleteShader( v.vert_id );
- glDeleteShader( v.frag_id );
- glDeleteProgram( v.id );
- v.id=0;
+ glDeleteShader(v.vert_id);
+ glDeleteShader(v.frag_id);
+ glDeleteProgram(v.id);
+ v.id = 0;
}
-
}
-
-
- v.ok=false;
+ v.ok = false;
/* SETUP CONDITIONALS */
-
- Vector<const char*> strings;
+
+ Vector<const char *> strings;
#ifdef GLES_OVER_GL
strings.push_back("#version 330\n");
#else
strings.push_back("#version 300 es\n");
#endif
+ int define_line_ofs = 1;
-
- int define_line_ofs=1;
-
- for(int i=0;i<custom_defines.size();i++) {
+ for (int i = 0; i < custom_defines.size(); i++) {
strings.push_back(custom_defines[i].get_data());
define_line_ofs++;
}
- for(int j=0;j<conditional_count;j++) {
-
- bool enable=((1<<j)&conditional_version.version);
- strings.push_back(enable?conditional_defines[j]:"");
+ for (int j = 0; j < conditional_count; j++) {
+
+ bool enable = ((1 << j) & conditional_version.version);
+ strings.push_back(enable ? conditional_defines[j] : "");
if (enable)
define_line_ofs++;
if (enable) {
DEBUG_PRINT(conditional_defines[j]);
}
-
}
-
-
//keep them around during the function
CharString code_string;
CharString code_string2;
CharString code_globals;
CharString material_string;
-
//print_line("code version? "+itos(conditional_version.code_version));
- CustomCode *cc=NULL;
+ CustomCode *cc = NULL;
- if ( conditional_version.code_version>0 ) {
+ if (conditional_version.code_version > 0) {
//do custom code related stuff
- ERR_FAIL_COND_V( !custom_code_map.has( conditional_version.code_version ), NULL );
- cc=&custom_code_map[conditional_version.code_version];
- v.code_version=cc->version;
- define_line_ofs+=2;
-
+ ERR_FAIL_COND_V(!custom_code_map.has(conditional_version.code_version), NULL);
+ cc = &custom_code_map[conditional_version.code_version];
+ v.code_version = cc->version;
+ define_line_ofs += 2;
}
-
/* CREATE PROGRAM */
-
+
v.id = glCreateProgram();
-
- ERR_FAIL_COND_V(v.id==0, NULL);
-
- /* VERTEX SHADER */
+ ERR_FAIL_COND_V(v.id == 0, NULL);
+
+ /* VERTEX SHADER */
if (cc) {
- for(int i=0;i<cc->custom_defines.size();i++) {
+ for (int i = 0; i < cc->custom_defines.size(); i++) {
strings.push_back(cc->custom_defines[i].get_data());
- DEBUG_PRINT("CD #"+itos(i)+": "+String(cc->custom_defines[i]));
+ DEBUG_PRINT("CD #" + itos(i) + ": " + String(cc->custom_defines[i]));
}
}
- int strings_base_size=strings.size();
+ int strings_base_size = strings.size();
//vertex precision is high
strings.push_back("precision highp float;\n");
@@ -311,83 +287,78 @@ ShaderGLES3::Version* ShaderGLES3::get_current_version() {
}
#endif
-
strings.push_back(vertex_code0.get_data());
if (cc) {
- code_globals=cc->vertex_globals.ascii();
+ code_globals = cc->vertex_globals.ascii();
strings.push_back(code_globals.get_data());
}
strings.push_back(vertex_code1.get_data());
if (cc) {
- material_string=cc->uniforms.ascii();
+ material_string = cc->uniforms.ascii();
strings.push_back(material_string.get_data());
}
strings.push_back(vertex_code2.get_data());
if (cc) {
- code_string=cc->vertex.ascii();
+ code_string = cc->vertex.ascii();
strings.push_back(code_string.get_data());
}
strings.push_back(vertex_code3.get_data());
#ifdef DEBUG_SHADER
- DEBUG_PRINT("\nVertex Code:\n\n"+String(code_string.get_data()));
- for(int i=0;i<strings.size();i++) {
+ DEBUG_PRINT("\nVertex Code:\n\n" + String(code_string.get_data()));
+ for (int i = 0; i < strings.size(); i++) {
//print_line("vert strings "+itos(i)+":"+String(strings[i]));
}
#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], NULL);
glCompileShader(v.vert_id);
-
+
GLint status;
-
- glGetShaderiv(v.vert_id,GL_COMPILE_STATUS,&status);
- if (status==GL_FALSE) {
- // error compiling
+
+ glGetShaderiv(v.vert_id, GL_COMPILE_STATUS, &status);
+ if (status == GL_FALSE) {
+ // error compiling
GLsizei iloglen;
- glGetShaderiv(v.vert_id,GL_INFO_LOG_LENGTH,&iloglen);
-
- if (iloglen<0) {
-
+ glGetShaderiv(v.vert_id, GL_INFO_LOG_LENGTH, &iloglen);
+
+ if (iloglen < 0) {
+
glDeleteShader(v.vert_id);
- glDeleteProgram( v.id );
- v.id=0;
-
+ glDeleteProgram(v.id);
+ v.id = 0;
+
ERR_PRINT("NO LOG, WTF");
} else {
- if (iloglen==0) {
+ if (iloglen == 0) {
iloglen = 4096; //buggy driver (Adreno 220+....)
}
-
- char *ilogmem = (char*)memalloc(iloglen+1);
- ilogmem[iloglen]=0;
- glGetShaderInfoLog(v.vert_id, iloglen, &iloglen, ilogmem);
-
- String err_string=get_shader_name()+": Vertex Program Compilation Failed:\n";
-
- err_string+=ilogmem;
- _display_error_with_code(err_string,strings);
+ char *ilogmem = (char *)memalloc(iloglen + 1);
+ ilogmem[iloglen] = 0;
+ glGetShaderInfoLog(v.vert_id, iloglen, &iloglen, ilogmem);
+
+ String err_string = get_shader_name() + ": Vertex Program Compilation Failed:\n";
+
+ err_string += ilogmem;
+ _display_error_with_code(err_string, strings);
memfree(ilogmem);
glDeleteShader(v.vert_id);
- glDeleteProgram( v.id );
- v.id=0;
-
+ glDeleteProgram(v.id);
+ v.id = 0;
}
-
- ERR_FAIL_V(NULL);
- }
+ ERR_FAIL_V(NULL);
+ }
/* FRAGMENT SHADER */
@@ -411,317 +382,308 @@ ShaderGLES3::Version* ShaderGLES3::get_current_version() {
}
#endif
-
strings.push_back(fragment_code0.get_data());
if (cc) {
- code_globals=cc->fragment_globals.ascii();
+ code_globals = cc->fragment_globals.ascii();
strings.push_back(code_globals.get_data());
}
strings.push_back(fragment_code1.get_data());
if (cc) {
- material_string=cc->uniforms.ascii();
+ material_string = cc->uniforms.ascii();
strings.push_back(material_string.get_data());
}
strings.push_back(fragment_code2.get_data());
if (cc) {
- code_string=cc->fragment.ascii();
+ code_string = cc->fragment.ascii();
strings.push_back(code_string.get_data());
}
strings.push_back(fragment_code3.get_data());
if (cc) {
- code_string2=cc->light.ascii();
+ code_string2 = cc->light.ascii();
strings.push_back(code_string2.get_data());
}
strings.push_back(fragment_code4.get_data());
#ifdef DEBUG_SHADER
- DEBUG_PRINT("\nFragment Code:\n\n"+String(code_string.get_data()));
- for(int i=0;i<strings.size();i++) {
+ DEBUG_PRINT("\nFragment Code:\n\n" + String(code_string.get_data()));
+ for (int i = 0; i < strings.size(); i++) {
//print_line("frag strings "+itos(i)+":"+String(strings[i]));
}
#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], NULL);
glCompileShader(v.frag_id);
-
- glGetShaderiv(v.frag_id,GL_COMPILE_STATUS,&status);
- if (status==GL_FALSE) {
- // error compiling
+
+ glGetShaderiv(v.frag_id, GL_COMPILE_STATUS, &status);
+ if (status == GL_FALSE) {
+ // error compiling
GLsizei iloglen;
- glGetShaderiv(v.frag_id,GL_INFO_LOG_LENGTH,&iloglen);
-
- if (iloglen<0) {
+ glGetShaderiv(v.frag_id, GL_INFO_LOG_LENGTH, &iloglen);
+
+ if (iloglen < 0) {
glDeleteShader(v.frag_id);
glDeleteShader(v.vert_id);
- glDeleteProgram( v.id );
- v.id=0;
+ glDeleteProgram(v.id);
+ v.id = 0;
ERR_PRINT("NO LOG, WTF");
} else {
-
- if (iloglen==0) {
+
+ if (iloglen == 0) {
iloglen = 4096; //buggy driver (Adreno 220+....)
}
- char *ilogmem = (char*)memalloc(iloglen+1);
- ilogmem[iloglen]=0;
- glGetShaderInfoLog(v.frag_id, iloglen, &iloglen, ilogmem);
-
- String err_string=get_shader_name()+": Fragment Program Compilation Failed:\n";
-
- err_string+=ilogmem;
- _display_error_with_code(err_string,strings);
+ char *ilogmem = (char *)memalloc(iloglen + 1);
+ ilogmem[iloglen] = 0;
+ glGetShaderInfoLog(v.frag_id, iloglen, &iloglen, ilogmem);
+
+ String err_string = get_shader_name() + ": Fragment Program Compilation Failed:\n";
+
+ err_string += ilogmem;
+ _display_error_with_code(err_string, strings);
ERR_PRINT(err_string.ascii().get_data());
memfree(ilogmem);
glDeleteShader(v.frag_id);
glDeleteShader(v.vert_id);
- glDeleteProgram( v.id );
- v.id=0;
-
+ glDeleteProgram(v.id);
+ v.id = 0;
}
-
- ERR_FAIL_V( NULL );
- }
- glAttachShader(v.id,v.frag_id);
- glAttachShader(v.id,v.vert_id);
+ ERR_FAIL_V(NULL);
+ }
+
+ glAttachShader(v.id, v.frag_id);
+ glAttachShader(v.id, v.vert_id);
// bind attributes before linking
- for (int i=0;i<attribute_pair_count;i++) {
+ for (int i = 0; i < attribute_pair_count; i++) {
- glBindAttribLocation(v.id, attribute_pairs[i].index, attribute_pairs[i].name );
+ glBindAttribLocation(v.id, attribute_pairs[i].index, attribute_pairs[i].name);
}
//if feedback exists, set it up
if (feedback_count) {
- Vector<const char*> feedback;
- for(int i=0;i<feedback_count;i++) {
+ Vector<const char *> feedback;
+ for (int i = 0; i < feedback_count; i++) {
- if (feedbacks[i].conditional==-1 || (1<<feedbacks[i].conditional)&conditional_version.version) {
+ if (feedbacks[i].conditional == -1 || (1 << feedbacks[i].conditional) & conditional_version.version) {
//conditional for this feedback is enabled
- print_line("tf varying: "+itos(feedback.size())+" "+String(feedbacks[i].name));
+ print_line("tf varying: " + itos(feedback.size()) + " " + String(feedbacks[i].name));
feedback.push_back(feedbacks[i].name);
}
}
if (feedback.size()) {
- glTransformFeedbackVaryings(v.id,feedback.size(),feedback.ptr(),GL_INTERLEAVED_ATTRIBS );
+ glTransformFeedbackVaryings(v.id, feedback.size(), feedback.ptr(), GL_INTERLEAVED_ATTRIBS);
}
-
}
glLinkProgram(v.id);
-
+
glGetProgramiv(v.id, GL_LINK_STATUS, &status);
-
- if (status==GL_FALSE) {
- // error linking
+
+ if (status == GL_FALSE) {
+ // error linking
GLsizei iloglen;
- glGetProgramiv(v.id,GL_INFO_LOG_LENGTH,&iloglen);
-
- if (iloglen<0) {
-
+ glGetProgramiv(v.id, GL_INFO_LOG_LENGTH, &iloglen);
+
+ if (iloglen < 0) {
+
glDeleteShader(v.frag_id);
glDeleteShader(v.vert_id);
- glDeleteProgram( v.id );
- v.id=0;
- ERR_FAIL_COND_V(iloglen<=0, NULL);
+ glDeleteProgram(v.id);
+ v.id = 0;
+ ERR_FAIL_COND_V(iloglen <= 0, NULL);
}
- if (iloglen==0) {
+ if (iloglen == 0) {
iloglen = 4096; //buggy driver (Adreno 220+....)
}
-
- char *ilogmem = (char*)Memory::alloc_static(iloglen+1);
- ilogmem[iloglen]=0;
- glGetProgramInfoLog(v.id, iloglen, &iloglen, ilogmem);
-
- String err_string=get_shader_name()+": Program LINK FAILED:\n";
-
- err_string+=ilogmem;
- _display_error_with_code(err_string,strings);
+ char *ilogmem = (char *)Memory::alloc_static(iloglen + 1);
+ ilogmem[iloglen] = 0;
+ glGetProgramInfoLog(v.id, iloglen, &iloglen, ilogmem);
+
+ String err_string = get_shader_name() + ": Program LINK FAILED:\n";
+
+ err_string += ilogmem;
+ _display_error_with_code(err_string, strings);
ERR_PRINT(err_string.ascii().get_data());
Memory::free_static(ilogmem);
glDeleteShader(v.frag_id);
glDeleteShader(v.vert_id);
- glDeleteProgram( v.id );
- v.id=0;
-
+ glDeleteProgram(v.id);
+ v.id = 0;
+
ERR_FAIL_V(NULL);
}
-
- /* UNIFORMS */
-
- glUseProgram(v.id);
+ /* UNIFORMS */
+
+ glUseProgram(v.id);
//print_line("uniforms: ");
- for(int j=0;j<uniform_count;j++) {
-
-
- v.uniform_location[j]=glGetUniformLocation(v.id,uniform_names[j]);
+ for (int j = 0; j < uniform_count; j++) {
+
+ v.uniform_location[j] = glGetUniformLocation(v.id, uniform_names[j]);
//print_line("uniform "+String(uniform_names[j])+" location "+itos(v.uniform_location[j]));
}
-
+
// set texture uniforms
- for (int i=0;i<texunit_pair_count;i++) {
+ for (int i = 0; i < texunit_pair_count; i++) {
- GLint loc = glGetUniformLocation(v.id,texunit_pairs[i].name);
- if (loc>=0) {
- if (texunit_pairs[i].index<0) {
- glUniform1i(loc,max_image_units+texunit_pairs[i].index); //negative, goes down
+ GLint loc = glGetUniformLocation(v.id, texunit_pairs[i].name);
+ if (loc >= 0) {
+ if (texunit_pairs[i].index < 0) {
+ glUniform1i(loc, max_image_units + texunit_pairs[i].index); //negative, goes down
} else {
- glUniform1i(loc,texunit_pairs[i].index);
+ glUniform1i(loc, texunit_pairs[i].index);
}
}
}
// assign uniform block bind points
- for (int i=0;i<ubo_count;i++) {
+ for (int i = 0; i < ubo_count; i++) {
- GLint loc = glGetUniformBlockIndex(v.id,ubo_pairs[i].name);
- if (loc>=0)
- glUniformBlockBinding(v.id,loc,ubo_pairs[i].index);
+ GLint loc = glGetUniformBlockIndex(v.id, ubo_pairs[i].name);
+ if (loc >= 0)
+ glUniformBlockBinding(v.id, loc, ubo_pairs[i].index);
}
- if ( cc ) {
+ if (cc) {
v.texture_uniform_locations.resize(cc->texture_uniforms.size());
- for(int i=0;i<cc->texture_uniforms.size();i++) {
+ for (int i = 0; i < cc->texture_uniforms.size(); i++) {
- v.texture_uniform_locations[i]=glGetUniformLocation(v.id,String(cc->texture_uniforms[i]).ascii().get_data());
- glUniform1i(v.texture_uniform_locations[i],i+base_material_tex_index);
+ v.texture_uniform_locations[i] = glGetUniformLocation(v.id, String(cc->texture_uniforms[i]).ascii().get_data());
+ glUniform1i(v.texture_uniform_locations[i], i + base_material_tex_index);
}
}
glUseProgram(0);
-
- v.ok=true;
+ v.ok = true;
return &v;
}
-GLint ShaderGLES3::get_uniform_location(const String& p_name) const {
+GLint ShaderGLES3::get_uniform_location(const String &p_name) const {
- ERR_FAIL_COND_V(!version,-1);
- return glGetUniformLocation(version->id,p_name.ascii().get_data());
+ ERR_FAIL_COND_V(!version, -1);
+ return glGetUniformLocation(version->id, p_name.ascii().get_data());
}
-
-void ShaderGLES3::setup(const char** p_conditional_defines, int p_conditional_count,const char** p_uniform_names,int p_uniform_count, const AttributePair* p_attribute_pairs, int p_attribute_count, const TexUnitPair *p_texunit_pairs, int p_texunit_pair_count, const UBOPair *p_ubo_pairs, int p_ubo_pair_count, const Feedback* p_feedback, int p_feedback_count,const char*p_vertex_code, const char *p_fragment_code,int p_vertex_code_start,int p_fragment_code_start) {
+void ShaderGLES3::setup(const char **p_conditional_defines, int p_conditional_count, const char **p_uniform_names, int p_uniform_count, const AttributePair *p_attribute_pairs, int p_attribute_count, const TexUnitPair *p_texunit_pairs, int p_texunit_pair_count, const UBOPair *p_ubo_pairs, int p_ubo_pair_count, const Feedback *p_feedback, int p_feedback_count, const char *p_vertex_code, const char *p_fragment_code, int p_vertex_code_start, int p_fragment_code_start) {
ERR_FAIL_COND(version);
- conditional_version.key=0;
- new_conditional_version.key=0;
- uniform_count=p_uniform_count;
- conditional_count=p_conditional_count;
- conditional_defines=p_conditional_defines;
- uniform_names=p_uniform_names;
- vertex_code=p_vertex_code;
- fragment_code=p_fragment_code;
- texunit_pairs=p_texunit_pairs;
- texunit_pair_count=p_texunit_pair_count;
- vertex_code_start=p_vertex_code_start;
- fragment_code_start=p_fragment_code_start;
- attribute_pairs=p_attribute_pairs;
- attribute_pair_count=p_attribute_count;
- ubo_pairs=p_ubo_pairs;
- ubo_count=p_ubo_pair_count;
- feedbacks=p_feedback;
- feedback_count=p_feedback_count;
+ conditional_version.key = 0;
+ new_conditional_version.key = 0;
+ uniform_count = p_uniform_count;
+ conditional_count = p_conditional_count;
+ conditional_defines = p_conditional_defines;
+ uniform_names = p_uniform_names;
+ vertex_code = p_vertex_code;
+ fragment_code = p_fragment_code;
+ texunit_pairs = p_texunit_pairs;
+ texunit_pair_count = p_texunit_pair_count;
+ vertex_code_start = p_vertex_code_start;
+ fragment_code_start = p_fragment_code_start;
+ attribute_pairs = p_attribute_pairs;
+ attribute_pair_count = p_attribute_count;
+ ubo_pairs = p_ubo_pairs;
+ ubo_count = p_ubo_pair_count;
+ feedbacks = p_feedback;
+ feedback_count = p_feedback_count;
//split vertex and shader code (thank you, retarded shader compiler programmers from you know what company).
{
- String globals_tag="\nVERTEX_SHADER_GLOBALS";
- String material_tag="\nMATERIAL_UNIFORMS";
- String code_tag="\nVERTEX_SHADER_CODE";
- String code = vertex_code;
+ String globals_tag = "\nVERTEX_SHADER_GLOBALS";
+ String material_tag = "\nMATERIAL_UNIFORMS";
+ String code_tag = "\nVERTEX_SHADER_CODE";
+ String code = vertex_code;
int cpos = code.find(globals_tag);
- if (cpos==-1) {
- vertex_code0=code.ascii();
+ if (cpos == -1) {
+ vertex_code0 = code.ascii();
} else {
- vertex_code0=code.substr(0,cpos).ascii();
- code = code.substr(cpos+globals_tag.length(),code.length());
+ vertex_code0 = code.substr(0, cpos).ascii();
+ code = code.substr(cpos + globals_tag.length(), code.length());
cpos = code.find(material_tag);
- if (cpos==-1) {
- vertex_code1=code.ascii();
+ if (cpos == -1) {
+ vertex_code1 = code.ascii();
} else {
- vertex_code1=code.substr(0,cpos).ascii();
- String code2 = code.substr(cpos+material_tag.length(),code.length());
+ vertex_code1 = code.substr(0, cpos).ascii();
+ String code2 = code.substr(cpos + material_tag.length(), code.length());
cpos = code2.find(code_tag);
- if (cpos==-1) {
- vertex_code2=code2.ascii();
+ if (cpos == -1) {
+ vertex_code2 = code2.ascii();
} else {
- vertex_code2=code2.substr(0,cpos).ascii();
- vertex_code3 = code2.substr(cpos+code_tag.length(),code2.length()).ascii();
+ vertex_code2 = code2.substr(0, cpos).ascii();
+ vertex_code3 = code2.substr(cpos + code_tag.length(), code2.length()).ascii();
}
-
}
}
}
{
- String globals_tag="\nFRAGMENT_SHADER_GLOBALS";
- String material_tag="\nMATERIAL_UNIFORMS";
- String code_tag="\nFRAGMENT_SHADER_CODE";
- String light_code_tag="\nLIGHT_SHADER_CODE";
- String code = fragment_code;
+ String globals_tag = "\nFRAGMENT_SHADER_GLOBALS";
+ String material_tag = "\nMATERIAL_UNIFORMS";
+ String code_tag = "\nFRAGMENT_SHADER_CODE";
+ String light_code_tag = "\nLIGHT_SHADER_CODE";
+ String code = fragment_code;
int cpos = code.find(globals_tag);
- if (cpos==-1) {
- fragment_code0=code.ascii();
+ if (cpos == -1) {
+ fragment_code0 = code.ascii();
} else {
- fragment_code0=code.substr(0,cpos).ascii();
+ fragment_code0 = code.substr(0, cpos).ascii();
//print_line("CODE0:\n"+String(fragment_code0.get_data()));
- code = code.substr(cpos+globals_tag.length(),code.length());
+ code = code.substr(cpos + globals_tag.length(), code.length());
cpos = code.find(material_tag);
- if (cpos==-1) {
- fragment_code1=code.ascii();
+ if (cpos == -1) {
+ fragment_code1 = code.ascii();
} else {
- fragment_code1=code.substr(0,cpos).ascii();
+ fragment_code1 = code.substr(0, cpos).ascii();
//print_line("CODE1:\n"+String(fragment_code1.get_data()));
- String code2 = code.substr(cpos+material_tag.length(),code.length());
+ String code2 = code.substr(cpos + material_tag.length(), code.length());
cpos = code2.find(code_tag);
- if (cpos==-1) {
- fragment_code2=code2.ascii();
+ if (cpos == -1) {
+ fragment_code2 = code2.ascii();
} else {
- fragment_code2=code2.substr(0,cpos).ascii();
+ fragment_code2 = code2.substr(0, cpos).ascii();
//print_line("CODE2:\n"+String(fragment_code2.get_data()));
- String code3 = code2.substr(cpos+code_tag.length(),code2.length());
+ String code3 = code2.substr(cpos + code_tag.length(), code2.length());
cpos = code3.find(light_code_tag);
- if (cpos==-1) {
- fragment_code3=code3.ascii();
+ if (cpos == -1) {
+ fragment_code3 = code3.ascii();
} else {
- fragment_code3=code3.substr(0,cpos).ascii();
+ fragment_code3 = code3.substr(0, cpos).ascii();
//print_line("CODE3:\n"+String(fragment_code3.get_data()));
- fragment_code4 = code3.substr(cpos+light_code_tag.length(),code3.length()).ascii();
+ fragment_code4 = code3.substr(cpos + light_code_tag.length(), code3.length()).ascii();
//print_line("CODE4:\n"+String(fragment_code4.get_data()));
}
}
@@ -729,111 +691,99 @@ void ShaderGLES3::setup(const char** p_conditional_defines, int p_conditional_co
}
}
- glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS,&max_image_units);
-
+ glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &max_image_units);
}
void ShaderGLES3::finish() {
-
- const VersionKey *V=NULL;
- while((V=version_map.next(V))) {
-
- Version &v=version_map[*V];
- glDeleteShader( v.vert_id );
- glDeleteShader( v.frag_id );
- glDeleteProgram( v.id );
- memdelete_arr( v.uniform_location );
-
- }
-
-}
+ const VersionKey *V = NULL;
+ while ((V = version_map.next(V))) {
+
+ Version &v = version_map[*V];
+ glDeleteShader(v.vert_id);
+ glDeleteShader(v.frag_id);
+ glDeleteProgram(v.id);
+ memdelete_arr(v.uniform_location);
+ }
+}
void ShaderGLES3::clear_caches() {
- const VersionKey *V=NULL;
- while((V=version_map.next(V))) {
-
- Version &v=version_map[*V];
- glDeleteShader( v.vert_id );
- glDeleteShader( v.frag_id );
- glDeleteProgram( v.id );
- memdelete_arr( v.uniform_location );
+ const VersionKey *V = NULL;
+ while ((V = version_map.next(V))) {
+
+ Version &v = version_map[*V];
+ glDeleteShader(v.vert_id);
+ glDeleteShader(v.frag_id);
+ glDeleteProgram(v.id);
+ memdelete_arr(v.uniform_location);
}
version_map.clear();
custom_code_map.clear();
- version=NULL;
- last_custom_code=1;
+ version = NULL;
+ last_custom_code = 1;
uniforms_dirty = true;
-
}
uint32_t ShaderGLES3::create_custom_shader() {
- custom_code_map[last_custom_code]=CustomCode();
- custom_code_map[last_custom_code].version=1;
+ custom_code_map[last_custom_code] = CustomCode();
+ custom_code_map[last_custom_code].version = 1;
return last_custom_code++;
}
-void ShaderGLES3::set_custom_shader_code(uint32_t p_code_id, const String& p_vertex, const String& p_vertex_globals, const String& p_fragment, const String& p_light, const String& p_fragment_globals, const String &p_uniforms, const Vector<StringName> &p_texture_uniforms, const Vector<CharString> &p_custom_defines) {
+void ShaderGLES3::set_custom_shader_code(uint32_t p_code_id, const String &p_vertex, const String &p_vertex_globals, const String &p_fragment, const String &p_light, const String &p_fragment_globals, const String &p_uniforms, const Vector<StringName> &p_texture_uniforms, const Vector<CharString> &p_custom_defines) {
ERR_FAIL_COND(!custom_code_map.has(p_code_id));
- CustomCode *cc=&custom_code_map[p_code_id];
-
-
- cc->vertex=p_vertex;
- cc->vertex_globals=p_vertex_globals;
- cc->fragment=p_fragment;
- cc->fragment_globals=p_fragment_globals;
- cc->light=p_light;
- cc->texture_uniforms=p_texture_uniforms;
- cc->uniforms=p_uniforms;
- cc->custom_defines=p_custom_defines;
+ CustomCode *cc = &custom_code_map[p_code_id];
+
+ cc->vertex = p_vertex;
+ cc->vertex_globals = p_vertex_globals;
+ cc->fragment = p_fragment;
+ cc->fragment_globals = p_fragment_globals;
+ cc->light = p_light;
+ cc->texture_uniforms = p_texture_uniforms;
+ cc->uniforms = p_uniforms;
+ cc->custom_defines = p_custom_defines;
cc->version++;
}
void ShaderGLES3::set_custom_shader(uint32_t p_code_id) {
- new_conditional_version.code_version=p_code_id;
+ new_conditional_version.code_version = p_code_id;
}
void ShaderGLES3::free_custom_shader(uint32_t p_code_id) {
- /* if (! custom_code_map.has( p_code_id )) {
+ /* if (! custom_code_map.has( p_code_id )) {
print_line("no code id "+itos(p_code_id));
} else {
print_line("freed code id "+itos(p_code_id));
}*/
- ERR_FAIL_COND(! custom_code_map.has( p_code_id ));
- if (conditional_version.code_version==p_code_id)
- conditional_version.code_version=0; //bye
+ ERR_FAIL_COND(!custom_code_map.has(p_code_id));
+ if (conditional_version.code_version == p_code_id)
+ conditional_version.code_version = 0; //bye
custom_code_map.erase(p_code_id);
-
}
void ShaderGLES3::set_base_material_tex_index(int p_idx) {
- base_material_tex_index=p_idx;
+ base_material_tex_index = p_idx;
}
ShaderGLES3::ShaderGLES3() {
- version=NULL;
- last_custom_code=1;
+ version = NULL;
+ last_custom_code = 1;
uniforms_dirty = true;
- base_material_tex_index=0;
-
+ base_material_tex_index = 0;
}
-
ShaderGLES3::~ShaderGLES3() {
-
+
finish();
}
-
-
-
diff --git a/drivers/gles3/shader_gles3.h b/drivers/gles3/shader_gles3.h
index 464f359d51..6f5ccc9126 100644
--- a/drivers/gles3/shader_gles3.h
+++ b/drivers/gles3/shader_gles3.h
@@ -38,19 +38,17 @@
#include GLES3_INCLUDE_H
#endif
+#include "camera_matrix.h"
#include "hash_map.h"
#include "map.h"
#include "variant.h"
-#include "camera_matrix.h"
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
-
class ShaderGLES3 {
-protected:
-
+protected:
struct Enum {
uint64_t mask;
@@ -71,7 +69,7 @@ protected:
};
struct UniformPair {
- const char* name;
+ const char *name;
Variant::Type type_hint;
};
@@ -94,8 +92,8 @@ protected:
};
bool uniforms_dirty;
-private:
+private:
//@TODO Optimize to a fixed set of shader pools and use a LRU
int uniform_count;
int texunit_pair_count;
@@ -117,22 +115,24 @@ private:
uint32_t version;
Vector<StringName> texture_uniforms;
Vector<CharString> custom_defines;
-
};
-
struct Version {
-
+
GLuint id;
GLuint vert_id;
- GLuint frag_id;
+ GLuint frag_id;
GLint *uniform_location;
Vector<GLint> texture_uniform_locations;
uint32_t code_version;
bool ok;
- Version() { code_version=0; ok=false; uniform_location=NULL; }
+ Version() {
+ code_version = 0;
+ ok = false;
+ uniform_location = NULL;
+ }
};
-
+
Version *version;
union VersionKey {
@@ -142,36 +142,34 @@ private:
uint32_t code_version;
};
uint64_t key;
- bool operator==(const VersionKey& p_key) const { return key==p_key.key; }
- bool operator<(const VersionKey& p_key) const { return key<p_key.key; }
-
+ bool operator==(const VersionKey &p_key) const { return key == p_key.key; }
+ bool operator<(const VersionKey &p_key) const { return key < p_key.key; }
};
struct VersionKeyHash {
- static _FORCE_INLINE_ uint32_t hash( const VersionKey& p_key) { return HashMapHasherDefault::hash(p_key.key); };
+ static _FORCE_INLINE_ uint32_t hash(const VersionKey &p_key) { return HashMapHasherDefault::hash(p_key.key); };
};
//this should use a way more cachefriendly version..
- HashMap<VersionKey,Version,VersionKeyHash> version_map;
+ HashMap<VersionKey, Version, VersionKeyHash> version_map;
- HashMap<uint32_t,CustomCode> custom_code_map;
+ HashMap<uint32_t, CustomCode> custom_code_map;
uint32_t last_custom_code;
-
-
+
VersionKey conditional_version;
VersionKey new_conditional_version;
-
- virtual String get_shader_name() const=0;
-
- const char** conditional_defines;
- const char** uniform_names;
+
+ virtual String get_shader_name() const = 0;
+
+ const char **conditional_defines;
+ const char **uniform_names;
const AttributePair *attribute_pairs;
const TexUnitPair *texunit_pairs;
const UBOPair *ubo_pairs;
const Feedback *feedbacks;
- const char* vertex_code;
- const char* fragment_code;
+ const char *vertex_code;
+ const char *fragment_code;
CharString fragment_code0;
CharString fragment_code1;
CharString fragment_code2;
@@ -187,213 +185,204 @@ private:
int base_material_tex_index;
- Version * get_current_version();
-
+ Version *get_current_version();
+
static ShaderGLES3 *active;
int max_image_units;
- _FORCE_INLINE_ void _set_uniform_variant(GLint p_uniform,const Variant& p_value) {
+ _FORCE_INLINE_ void _set_uniform_variant(GLint p_uniform, const Variant &p_value) {
- if (p_uniform<0)
+ if (p_uniform < 0)
return; // do none
- switch(p_value.get_type()) {
-
- case Variant::BOOL:
- case Variant::INT: {
-
- int val=p_value;
- glUniform1i( p_uniform, val );
- } break;
- case Variant::REAL: {
-
- real_t val=p_value;
- glUniform1f( p_uniform, val );
- } break;
- case Variant::COLOR: {
-
- Color val=p_value;
- glUniform4f( p_uniform, val.r, val.g,val.b,val.a );
- } break;
- case Variant::VECTOR2: {
-
- Vector2 val=p_value;
- glUniform2f( p_uniform, val.x,val.y );
- } break;
- case Variant::VECTOR3: {
-
- Vector3 val=p_value;
- glUniform3f( p_uniform, val.x,val.y,val.z );
- } break;
- case Variant::PLANE: {
-
- Plane val=p_value;
- glUniform4f( p_uniform, val.normal.x,val.normal.y,val.normal.z,val.d );
- } break;
- case Variant::QUAT: {
-
- Quat val=p_value;
- glUniform4f( p_uniform, val.x,val.y,val.z,val.w );
- } break;
-
- case Variant::TRANSFORM2D: {
-
- Transform2D tr=p_value;
- GLfloat matrix[16]={ /* build a 16x16 matrix */
- tr.elements[0][0],
- tr.elements[0][1],
- 0,
- 0,
- tr.elements[1][0],
- tr.elements[1][1],
- 0,
- 0,
- 0,
- 0,
- 1,
- 0,
- tr.elements[2][0],
- tr.elements[2][1],
- 0,
- 1
- };
-
- glUniformMatrix4fv(p_uniform,1,false,matrix);
-
- } break;
- case Variant::BASIS:
- case Variant::TRANSFORM: {
-
- Transform tr=p_value;
- GLfloat matrix[16]={ /* build a 16x16 matrix */
- tr.basis.elements[0][0],
- tr.basis.elements[1][0],
- tr.basis.elements[2][0],
- 0,
- tr.basis.elements[0][1],
- tr.basis.elements[1][1],
- tr.basis.elements[2][1],
- 0,
- tr.basis.elements[0][2],
- tr.basis.elements[1][2],
- tr.basis.elements[2][2],
- 0,
- tr.origin.x,
- tr.origin.y,
- tr.origin.z,
- 1
- };
-
-
- glUniformMatrix4fv(p_uniform,1,false,matrix);
- } break;
- default: { ERR_FAIL(); } // do nothing
-
- }
+ switch (p_value.get_type()) {
+
+ case Variant::BOOL:
+ case Variant::INT: {
+
+ int val = p_value;
+ glUniform1i(p_uniform, val);
+ } break;
+ case Variant::REAL: {
+
+ real_t val = p_value;
+ glUniform1f(p_uniform, val);
+ } break;
+ case Variant::COLOR: {
+
+ Color val = p_value;
+ glUniform4f(p_uniform, val.r, val.g, val.b, val.a);
+ } break;
+ case Variant::VECTOR2: {
+
+ Vector2 val = p_value;
+ glUniform2f(p_uniform, val.x, val.y);
+ } break;
+ case Variant::VECTOR3: {
+
+ Vector3 val = p_value;
+ glUniform3f(p_uniform, val.x, val.y, val.z);
+ } break;
+ case Variant::PLANE: {
+
+ Plane val = p_value;
+ glUniform4f(p_uniform, val.normal.x, val.normal.y, val.normal.z, val.d);
+ } break;
+ case Variant::QUAT: {
+
+ Quat val = p_value;
+ glUniform4f(p_uniform, val.x, val.y, val.z, val.w);
+ } break;
+
+ case Variant::TRANSFORM2D: {
+
+ Transform2D tr = p_value;
+ GLfloat matrix[16] = { /* build a 16x16 matrix */
+ tr.elements[0][0],
+ tr.elements[0][1],
+ 0,
+ 0,
+ tr.elements[1][0],
+ tr.elements[1][1],
+ 0,
+ 0,
+ 0,
+ 0,
+ 1,
+ 0,
+ tr.elements[2][0],
+ tr.elements[2][1],
+ 0,
+ 1
+ };
+
+ glUniformMatrix4fv(p_uniform, 1, false, matrix);
+
+ } break;
+ case Variant::BASIS:
+ case Variant::TRANSFORM: {
+
+ Transform tr = p_value;
+ GLfloat matrix[16] = { /* build a 16x16 matrix */
+ tr.basis.elements[0][0],
+ tr.basis.elements[1][0],
+ tr.basis.elements[2][0],
+ 0,
+ tr.basis.elements[0][1],
+ tr.basis.elements[1][1],
+ tr.basis.elements[2][1],
+ 0,
+ tr.basis.elements[0][2],
+ tr.basis.elements[1][2],
+ tr.basis.elements[2][2],
+ 0,
+ tr.origin.x,
+ tr.origin.y,
+ tr.origin.z,
+ 1
+ };
+
+ glUniformMatrix4fv(p_uniform, 1, false, matrix);
+ } break;
+ default: { ERR_FAIL(); } // do nothing
+ }
}
- Map<uint32_t,Variant> uniform_defaults;
- Map<uint32_t,CameraMatrix> uniform_cameras;
-
-
-protected:
+ Map<uint32_t, Variant> uniform_defaults;
+ Map<uint32_t, CameraMatrix> uniform_cameras;
+protected:
_FORCE_INLINE_ int _get_uniform(int p_which) const;
_FORCE_INLINE_ void _set_conditional(int p_which, bool p_value);
-
- void setup(const char** p_conditional_defines, int p_conditional_count,const char** p_uniform_names,int p_uniform_count, const AttributePair* p_attribute_pairs, int p_attribute_count, const TexUnitPair *p_texunit_pairs, int p_texunit_pair_count, const UBOPair *p_ubo_pairs,int p_ubo_pair_count, const Feedback* p_feedback, int p_feedback_count,const char*p_vertex_code, const char *p_fragment_code,int p_vertex_code_start,int p_fragment_code_start);
-
+
+ void setup(const char **p_conditional_defines, int p_conditional_count, const char **p_uniform_names, int p_uniform_count, const AttributePair *p_attribute_pairs, int p_attribute_count, const TexUnitPair *p_texunit_pairs, int p_texunit_pair_count, const UBOPair *p_ubo_pairs, int p_ubo_pair_count, const Feedback *p_feedback, int p_feedback_count, const char *p_vertex_code, const char *p_fragment_code, int p_vertex_code_start, int p_fragment_code_start);
+
ShaderGLES3();
+
public:
-
enum {
- CUSTOM_SHADER_DISABLED=0
+ CUSTOM_SHADER_DISABLED = 0
};
- GLint get_uniform_location(const String& p_name) const;
+ GLint get_uniform_location(const String &p_name) const;
GLint get_uniform_location(int p_uniform) const;
-
+
static _FORCE_INLINE_ ShaderGLES3 *get_active() { return active; };
bool bind();
void unbind();
void bind_uniforms();
-
- inline GLuint get_program() const { return version?version->id:0; }
-
+ inline GLuint get_program() const { return version ? version->id : 0; }
+
void clear_caches();
uint32_t create_custom_shader();
- void set_custom_shader_code(uint32_t p_id,const String& p_vertex, const String& p_vertex_globals,const String& p_fragment,const String& p_p_light,const String& p_fragment_globals,const String& p_uniforms,const Vector<StringName>& p_texture_uniforms,const Vector<CharString> &p_custom_defines);
+ void set_custom_shader_code(uint32_t p_id, const String &p_vertex, const String &p_vertex_globals, const String &p_fragment, const String &p_p_light, const String &p_fragment_globals, const String &p_uniforms, const Vector<StringName> &p_texture_uniforms, const Vector<CharString> &p_custom_defines);
void set_custom_shader(uint32_t p_id);
void free_custom_shader(uint32_t p_id);
- void set_uniform_default(int p_idx, const Variant& p_value) {
+ void set_uniform_default(int p_idx, const Variant &p_value) {
- if (p_value.get_type()==Variant::NIL) {
+ if (p_value.get_type() == Variant::NIL) {
uniform_defaults.erase(p_idx);
} else {
- uniform_defaults[p_idx]=p_value;
+ uniform_defaults[p_idx] = p_value;
}
uniforms_dirty = true;
}
uint32_t get_version() const { return new_conditional_version.version; }
- void set_uniform_camera(int p_idx, const CameraMatrix& p_mat) {
+ void set_uniform_camera(int p_idx, const CameraMatrix &p_mat) {
uniform_cameras[p_idx] = p_mat;
uniforms_dirty = true;
};
- _FORCE_INLINE_ void set_texture_uniform(int p_idx, const Variant& p_value) {
+ _FORCE_INLINE_ void set_texture_uniform(int p_idx, const Variant &p_value) {
ERR_FAIL_COND(!version);
- ERR_FAIL_INDEX(p_idx,version->texture_uniform_locations.size());
- _set_uniform_variant( version->texture_uniform_locations[p_idx], p_value );
+ ERR_FAIL_INDEX(p_idx, version->texture_uniform_locations.size());
+ _set_uniform_variant(version->texture_uniform_locations[p_idx], p_value);
}
-
+
_FORCE_INLINE_ GLint get_texture_uniform_location(int p_idx) {
- ERR_FAIL_COND_V(!version,-1);
- ERR_FAIL_INDEX_V(p_idx,version->texture_uniform_locations.size(),-1);
+ ERR_FAIL_COND_V(!version, -1);
+ ERR_FAIL_INDEX_V(p_idx, version->texture_uniform_locations.size(), -1);
return version->texture_uniform_locations[p_idx];
}
- virtual void init()=0;
+ virtual void init() = 0;
void finish();
void set_base_material_tex_index(int p_idx);
- void add_custom_define(const String& p_define) {
+ void add_custom_define(const String &p_define) {
custom_defines.push_back(p_define.utf8());
}
virtual ~ShaderGLES3();
-
};
-
-// called a lot, made inline
-
+// called a lot, made inline
int ShaderGLES3::_get_uniform(int p_which) const {
-
- ERR_FAIL_INDEX_V( p_which, uniform_count,-1 );
- ERR_FAIL_COND_V( !version, -1 );
+
+ ERR_FAIL_INDEX_V(p_which, uniform_count, -1);
+ ERR_FAIL_COND_V(!version, -1);
return version->uniform_location[p_which];
}
void ShaderGLES3::_set_conditional(int p_which, bool p_value) {
-
- ERR_FAIL_INDEX(p_which,conditional_count);
+
+ ERR_FAIL_INDEX(p_which, conditional_count);
if (p_value)
- new_conditional_version.version|=(1<<p_which);
+ new_conditional_version.version |= (1 << p_which);
else
- new_conditional_version.version&=~(1<<p_which);
+ new_conditional_version.version &= ~(1 << p_which);
}
#endif
-
diff --git a/drivers/png/image_loader_png.cpp b/drivers/png/image_loader_png.cpp
index 51429f3416..c524bee43c 100644
--- a/drivers/png/image_loader_png.cpp
+++ b/drivers/png/image_loader_png.cpp
@@ -28,16 +28,15 @@
/*************************************************************************/
#include "image_loader_png.h"
-#include "print_string.h"
#include "os/os.h"
+#include "print_string.h"
#include <string.h>
+void ImageLoaderPNG::_read_png_data(png_structp png_ptr, png_bytep data, png_size_t p_length) {
-void ImageLoaderPNG::_read_png_data(png_structp png_ptr,png_bytep data, png_size_t p_length) {
-
- FileAccess *f = (FileAccess*)png_get_io_ptr(png_ptr);
- f->get_buffer( (uint8_t*)data, p_length );
+ FileAccess *f = (FileAccess *)png_get_io_ptr(png_ptr);
+ f->get_buffer((uint8_t *)data, p_length);
}
/*
@@ -51,7 +50,7 @@ static png_voidp _png_malloc_fn(png_structp png_ptr, png_size_t size) {
return memalloc(size);
}
-static void _png_free_fn(png_structp png_ptr, png_voidp ptr) {
+static void _png_free_fn(png_structp png_ptr, png_voidp ptr) {
memfree(ptr);
}
@@ -66,42 +65,39 @@ static void _png_warn_function(png_structp, png_const_charp text) {
WARN_PRINT(text);
}
-typedef void (PNGAPI *png_error_ptr) PNGARG((png_structp, png_const_charp));
-
-Error ImageLoaderPNG::_load_image(void *rf_up,png_rw_ptr p_func,Image *p_image) {
-
+typedef void(PNGAPI *png_error_ptr) PNGARG((png_structp, png_const_charp));
+Error ImageLoaderPNG::_load_image(void *rf_up, png_rw_ptr p_func, Image *p_image) {
png_structp png;
png_infop info;
//png = png_create_read_struct(PNG_LIBPNG_VER_STRING, (png_voidp)NULL, NULL, NULL);
- png = png_create_read_struct_2(PNG_LIBPNG_VER_STRING, (png_voidp)NULL,_png_error_function,_png_warn_function,(png_voidp)NULL,
- _png_malloc_fn,_png_free_fn );
+ png = png_create_read_struct_2(PNG_LIBPNG_VER_STRING, (png_voidp)NULL, _png_error_function, _png_warn_function, (png_voidp)NULL,
+ _png_malloc_fn, _png_free_fn);
ERR_FAIL_COND_V(!png, ERR_OUT_OF_MEMORY);
info = png_create_info_struct(png);
if (!info) {
- png_destroy_read_struct(&png,NULL,NULL);
+ png_destroy_read_struct(&png, NULL, NULL);
ERR_PRINT("Out of Memory");
return ERR_OUT_OF_MEMORY;
}
if (setjmp(png_jmpbuf(png))) {
- png_destroy_read_struct(&png,NULL,NULL);
- ERR_PRINT("PNG Corrupted");
- return ERR_FILE_CORRUPT;
+ png_destroy_read_struct(&png, NULL, NULL);
+ ERR_PRINT("PNG Corrupted");
+ return ERR_FILE_CORRUPT;
}
- png_set_read_fn(png,(void*)rf_up,p_func);
+ png_set_read_fn(png, (void *)rf_up, p_func);
png_uint_32 width, height;
int depth, color;
-
png_read_info(png, info);
png_get_IHDR(png, info, &width, &height, &depth, &color, NULL, NULL, NULL);
@@ -114,29 +110,28 @@ Error ImageLoaderPNG::_load_image(void *rf_up,png_rw_ptr p_func,Image *p_image)
printf("Color type:%i\n", color);
*/
- bool update_info=false;
+ bool update_info = false;
- if (depth<8) { //only bit dept 8 per channel is handled
+ if (depth < 8) { //only bit dept 8 per channel is handled
png_set_packing(png);
- update_info=true;
-
+ update_info = true;
};
- if (png_get_color_type(png,info)==PNG_COLOR_TYPE_PALETTE) {
+ if (png_get_color_type(png, info) == PNG_COLOR_TYPE_PALETTE) {
png_set_palette_to_rgb(png);
- update_info=true;
+ update_info = true;
}
if (depth > 8) {
png_set_strip_16(png);
- update_info=true;
+ update_info = true;
}
- if (png_get_valid(png,info,PNG_INFO_tRNS)) {
+ if (png_get_valid(png, info, PNG_INFO_tRNS)) {
//png_set_expand_gray_1_2_4_to_8(png);
png_set_tRNS_to_alpha(png);
- update_info=true;
+ update_info = true;
}
if (update_info) {
@@ -147,29 +142,28 @@ Error ImageLoaderPNG::_load_image(void *rf_up,png_rw_ptr p_func,Image *p_image)
int components = 0;
Image::Format fmt;
- switch(color) {
-
+ switch (color) {
case PNG_COLOR_TYPE_GRAY: {
- fmt=Image::FORMAT_L8;
- components=1;
+ fmt = Image::FORMAT_L8;
+ components = 1;
} break;
case PNG_COLOR_TYPE_GRAY_ALPHA: {
- fmt=Image::FORMAT_LA8;
- components=2;
+ fmt = Image::FORMAT_LA8;
+ components = 2;
} break;
case PNG_COLOR_TYPE_RGB: {
- fmt=Image::FORMAT_RGB8;
- components=3;
+ fmt = Image::FORMAT_RGB8;
+ components = 3;
} break;
case PNG_COLOR_TYPE_RGB_ALPHA: {
- fmt=Image::FORMAT_RGBA8;
- components=4;
- } break;
+ fmt = Image::FORMAT_RGBA8;
+ components = 4;
+ } break;
default: {
ERR_PRINT("INVALID PNG TYPE");
@@ -183,39 +177,35 @@ Error ImageLoaderPNG::_load_image(void *rf_up,png_rw_ptr p_func,Image *p_image)
PoolVector<uint8_t> dstbuff;
- dstbuff.resize( rowsize * height );
+ dstbuff.resize(rowsize * height);
PoolVector<uint8_t>::Write dstbuff_write = dstbuff.write();
- uint8_t* data = dstbuff_write.ptr();
+ uint8_t *data = dstbuff_write.ptr();
- uint8_t **row_p = memnew_arr( uint8_t*, height );
+ uint8_t **row_p = memnew_arr(uint8_t *, height);
for (unsigned int i = 0; i < height; i++) {
- row_p[i] = &data[components*width*i];
+ row_p[i] = &data[components * width * i];
}
- png_read_image(png, (png_bytep*)row_p);
-
+ png_read_image(png, (png_bytep *)row_p);
- memdelete_arr( row_p );
+ memdelete_arr(row_p);
- p_image->create( width, height, 0,fmt, dstbuff );
+ p_image->create(width, height, 0, fmt, dstbuff);
- png_destroy_read_struct(&png, &info, NULL );
+ png_destroy_read_struct(&png, &info, NULL);
return OK;
}
+Error ImageLoaderPNG::load_image(Image *p_image, FileAccess *f) {
-Error ImageLoaderPNG::load_image(Image *p_image,FileAccess *f) {
-
- Error err = _load_image(f,_read_png_data,p_image);
+ Error err = _load_image(f, _read_png_data, p_image);
f->close();
-
return err;
-
}
void ImageLoaderPNG::get_recognized_extensions(List<String> *p_extensions) const {
@@ -223,7 +213,6 @@ void ImageLoaderPNG::get_recognized_extensions(List<String> *p_extensions) const
p_extensions->push_back("png");
}
-
struct PNGReadStatus {
int offset;
@@ -231,84 +220,76 @@ struct PNGReadStatus {
const unsigned char *image;
};
-static void user_read_data(png_structp png_ptr,png_bytep data, png_size_t p_length) {
+static void user_read_data(png_structp png_ptr, png_bytep data, png_size_t p_length) {
PNGReadStatus *rstatus;
- rstatus=(PNGReadStatus*)png_get_io_ptr(png_ptr);
+ rstatus = (PNGReadStatus *)png_get_io_ptr(png_ptr);
- png_size_t to_read=p_length;
- if (rstatus->size>=0) {
- to_read = MIN( p_length, rstatus->size - rstatus->offset);
+ png_size_t to_read = p_length;
+ if (rstatus->size >= 0) {
+ to_read = MIN(p_length, rstatus->size - rstatus->offset);
}
- memcpy(data,&rstatus->image[rstatus->offset],to_read);
- rstatus->offset+=to_read;
+ memcpy(data, &rstatus->image[rstatus->offset], to_read);
+ rstatus->offset += to_read;
- if (to_read<p_length) {
- memset(&data[to_read],0,p_length-to_read);
+ if (to_read < p_length) {
+ memset(&data[to_read], 0, p_length - to_read);
}
}
-
-static Image _load_mem_png(const uint8_t* p_png,int p_size) {
-
+static Image _load_mem_png(const uint8_t *p_png, int p_size) {
PNGReadStatus prs;
- prs.image=p_png;
- prs.offset=0;
- prs.size=p_size;
+ prs.image = p_png;
+ prs.offset = 0;
+ prs.size = p_size;
Image img;
- Error err = ImageLoaderPNG::_load_image(&prs,user_read_data,&img);
- ERR_FAIL_COND_V(err,Image());
+ Error err = ImageLoaderPNG::_load_image(&prs, user_read_data, &img);
+ ERR_FAIL_COND_V(err, Image());
return img;
}
-
-static Image _lossless_unpack_png(const PoolVector<uint8_t>& p_data) {
+static Image _lossless_unpack_png(const PoolVector<uint8_t> &p_data) {
int len = p_data.size();
PoolVector<uint8_t>::Read r = p_data.read();
- ERR_FAIL_COND_V(r[0]!='P' || r[1]!='N' || r[2]!='G' || r[3]!=' ',Image());
- return _load_mem_png(&r[4],len-4);
-
+ ERR_FAIL_COND_V(r[0] != 'P' || r[1] != 'N' || r[2] != 'G' || r[3] != ' ', Image());
+ return _load_mem_png(&r[4], len - 4);
}
-static void _write_png_data(png_structp png_ptr,png_bytep data, png_size_t p_length) {
+static void _write_png_data(png_structp png_ptr, png_bytep data, png_size_t p_length) {
- PoolVector<uint8_t> &v = *(PoolVector<uint8_t>*)png_get_io_ptr(png_ptr);
+ PoolVector<uint8_t> &v = *(PoolVector<uint8_t> *)png_get_io_ptr(png_ptr);
int vs = v.size();
- v.resize(vs+p_length);
+ v.resize(vs + p_length);
PoolVector<uint8_t>::Write w = v.write();
- copymem(&w[vs],data,p_length);
+ copymem(&w[vs], data, p_length);
//print_line("png write: "+itos(p_length));
}
-
-static PoolVector<uint8_t> _lossless_pack_png(const Image& p_image) {
-
+static PoolVector<uint8_t> _lossless_pack_png(const Image &p_image) {
Image img = p_image;
if (img.is_compressed())
img.decompress();
-
ERR_FAIL_COND_V(img.is_compressed(), PoolVector<uint8_t>());
png_structp png_ptr;
png_infop info_ptr;
- png_bytep * row_pointers;
-
+ png_bytep *row_pointers;
/* initialize stuff */
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
- ERR_FAIL_COND_V(!png_ptr,PoolVector<uint8_t>());
+ ERR_FAIL_COND_V(!png_ptr, PoolVector<uint8_t>());
info_ptr = png_create_info_struct(png_ptr);
- ERR_FAIL_COND_V(!info_ptr,PoolVector<uint8_t>());
+ ERR_FAIL_COND_V(!info_ptr, PoolVector<uint8_t>());
if (setjmp(png_jmpbuf(png_ptr))) {
ERR_FAIL_V(PoolVector<uint8_t>());
@@ -319,76 +300,73 @@ static PoolVector<uint8_t> _lossless_pack_png(const Image& p_image) {
ret.push_back('G');
ret.push_back(' ');
- png_set_write_fn(png_ptr,&ret,_write_png_data,NULL);
+ png_set_write_fn(png_ptr, &ret, _write_png_data, NULL);
/* write header */
if (setjmp(png_jmpbuf(png_ptr))) {
ERR_FAIL_V(PoolVector<uint8_t>());
}
- int pngf=0;
- int cs=0;
+ int pngf = 0;
+ int cs = 0;
- switch(img.get_format()) {
+ switch (img.get_format()) {
case Image::FORMAT_L8: {
- pngf=PNG_COLOR_TYPE_GRAY;
- cs=1;
+ pngf = PNG_COLOR_TYPE_GRAY;
+ cs = 1;
} break;
case Image::FORMAT_LA8: {
- pngf=PNG_COLOR_TYPE_GRAY_ALPHA;
- cs=2;
+ pngf = PNG_COLOR_TYPE_GRAY_ALPHA;
+ cs = 2;
} break;
case Image::FORMAT_RGB8: {
- pngf=PNG_COLOR_TYPE_RGB;
- cs=3;
+ pngf = PNG_COLOR_TYPE_RGB;
+ cs = 3;
} break;
case Image::FORMAT_RGBA8: {
- pngf=PNG_COLOR_TYPE_RGB_ALPHA;
- cs=4;
+ pngf = PNG_COLOR_TYPE_RGB_ALPHA;
+ cs = 4;
} break;
default: {
if (img.detect_alpha()) {
img.convert(Image::FORMAT_RGBA8);
- pngf=PNG_COLOR_TYPE_RGB_ALPHA;
- cs=4;
+ pngf = PNG_COLOR_TYPE_RGB_ALPHA;
+ cs = 4;
} else {
img.convert(Image::FORMAT_RGB8);
- pngf=PNG_COLOR_TYPE_RGB;
- cs=3;
+ pngf = PNG_COLOR_TYPE_RGB;
+ cs = 3;
}
-
}
}
int w = img.get_width();
int h = img.get_height();
- png_set_IHDR(png_ptr, info_ptr, w,h,
- 8, pngf, PNG_INTERLACE_NONE,
- PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
+ png_set_IHDR(png_ptr, info_ptr, w, h,
+ 8, pngf, PNG_INTERLACE_NONE,
+ PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
png_write_info(png_ptr, info_ptr);
-
/* write bytes */
if (setjmp(png_jmpbuf(png_ptr))) {
ERR_FAIL_V(PoolVector<uint8_t>());
}
-
PoolVector<uint8_t>::Read r = img.get_data().read();
- row_pointers = (png_bytep*)memalloc(sizeof(png_bytep)*h);
- for(int i=0;i<h;i++) {
+ row_pointers = (png_bytep *)memalloc(sizeof(png_bytep) * h);
+ for (int i = 0; i < h; i++) {
- row_pointers[i]=(png_bytep)&r[i*w*cs];
+ row_pointers[i] = (png_bytep)&r[i * w * cs];
}
png_write_image(png_ptr, row_pointers);
@@ -402,16 +380,12 @@ static PoolVector<uint8_t> _lossless_pack_png(const Image& p_image) {
png_write_end(png_ptr, NULL);
-
return ret;
}
ImageLoaderPNG::ImageLoaderPNG() {
-
- Image::_png_mem_loader_func=_load_mem_png;
- Image::lossless_unpacker=_lossless_unpack_png;
- Image::lossless_packer=_lossless_pack_png;
-
-
+ Image::_png_mem_loader_func = _load_mem_png;
+ Image::lossless_unpacker = _lossless_unpack_png;
+ Image::lossless_packer = _lossless_pack_png;
}
diff --git a/drivers/png/image_loader_png.h b/drivers/png/image_loader_png.h
index a98ad513db..00a64c5537 100644
--- a/drivers/png/image_loader_png.h
+++ b/drivers/png/image_loader_png.h
@@ -38,19 +38,13 @@
*/
class ImageLoaderPNG : public ImageFormatLoader {
- static void _read_png_data(png_structp png_ptr,png_bytep data, png_size_t p_length);
-
-
+ static void _read_png_data(png_structp png_ptr, png_bytep data, png_size_t p_length);
public:
-
-
- static Error _load_image(void *rf_up,png_rw_ptr p_func,Image *p_image);
- virtual Error load_image(Image *p_image,FileAccess *f);
- virtual void get_recognized_extensions(List<String> *p_extensions) const;
+ static Error _load_image(void *rf_up, png_rw_ptr p_func, Image *p_image);
+ virtual Error load_image(Image *p_image, FileAccess *f);
+ virtual void get_recognized_extensions(List<String> *p_extensions) const;
ImageLoaderPNG();
};
-
-
#endif
diff --git a/drivers/png/resource_saver_png.cpp b/drivers/png/resource_saver_png.cpp
index f55b089ded..ce1ffde1c8 100644
--- a/drivers/png/resource_saver_png.cpp
+++ b/drivers/png/resource_saver_png.cpp
@@ -35,20 +35,19 @@
#include <png.h>
-static void _write_png_data(png_structp png_ptr,png_bytep data, png_size_t p_length) {
+static void _write_png_data(png_structp png_ptr, png_bytep data, png_size_t p_length) {
- FileAccess *f = (FileAccess*)png_get_io_ptr(png_ptr);
- f->store_buffer( (const uint8_t*)data,p_length);
+ FileAccess *f = (FileAccess *)png_get_io_ptr(png_ptr);
+ f->store_buffer((const uint8_t *)data, p_length);
}
-Error ResourceSaverPNG::save(const String &p_path,const RES& p_resource,uint32_t p_flags) {
+Error ResourceSaverPNG::save(const String &p_path, const RES &p_resource, uint32_t p_flags) {
- Ref<ImageTexture> texture=p_resource;
+ Ref<ImageTexture> texture = p_resource;
- ERR_FAIL_COND_V(!texture.is_valid(),ERR_INVALID_PARAMETER);
+ ERR_FAIL_COND_V(!texture.is_valid(), ERR_INVALID_PARAMETER);
ERR_EXPLAIN("Can't save empty texture as PNG");
- ERR_FAIL_COND_V(!texture->get_width() || !texture->get_height(),ERR_INVALID_PARAMETER);
-
+ ERR_FAIL_COND_V(!texture->get_width() || !texture->get_height(), ERR_INVALID_PARAMETER);
Image img = texture->get_data();
@@ -62,28 +61,28 @@ Error ResourceSaverPNG::save(const String &p_path,const RES& p_resource,uint32_t
String text;
- if (global_filter!=bool(texture->get_flags()&Texture::FLAG_FILTER)) {
- text+=bool(texture->get_flags()&Texture::FLAG_FILTER)?"filter=true\n":"filter=false\n";
+ if (global_filter != bool(texture->get_flags() & Texture::FLAG_FILTER)) {
+ text += bool(texture->get_flags() & Texture::FLAG_FILTER) ? "filter=true\n" : "filter=false\n";
}
- if (global_mipmaps!=bool(texture->get_flags()&Texture::FLAG_MIPMAPS)) {
- text+=bool(texture->get_flags()&Texture::FLAG_MIPMAPS)?"gen_mipmaps=true\n":"gen_mipmaps=false\n";
+ if (global_mipmaps != bool(texture->get_flags() & Texture::FLAG_MIPMAPS)) {
+ text += bool(texture->get_flags() & Texture::FLAG_MIPMAPS) ? "gen_mipmaps=true\n" : "gen_mipmaps=false\n";
}
- if (global_repeat!=bool(texture->get_flags()&Texture::FLAG_REPEAT)) {
- text+=bool(texture->get_flags()&Texture::FLAG_REPEAT)?"repeat=true\n":"repeat=false\n";
+ if (global_repeat != bool(texture->get_flags() & Texture::FLAG_REPEAT)) {
+ text += bool(texture->get_flags() & Texture::FLAG_REPEAT) ? "repeat=true\n" : "repeat=false\n";
}
- if (bool(texture->get_flags()&Texture::FLAG_ANISOTROPIC_FILTER)) {
- text+="anisotropic=true\n";
+ if (bool(texture->get_flags() & Texture::FLAG_ANISOTROPIC_FILTER)) {
+ text += "anisotropic=true\n";
}
- if (bool(texture->get_flags()&Texture::FLAG_CONVERT_TO_LINEAR)) {
- text+="tolinear=true\n";
+ if (bool(texture->get_flags() & Texture::FLAG_CONVERT_TO_LINEAR)) {
+ text += "tolinear=true\n";
}
- if (bool(texture->get_flags()&Texture::FLAG_MIRRORED_REPEAT)) {
- text+="mirroredrepeat=true\n";
+ if (bool(texture->get_flags() & Texture::FLAG_MIRRORED_REPEAT)) {
+ text += "mirroredrepeat=true\n";
}
- if (text!="" || FileAccess::exists(p_path+".flags")) {
+ if (text != "" || FileAccess::exists(p_path + ".flags")) {
- FileAccess* f = FileAccess::open(p_path+".flags",FileAccess::WRITE);
+ FileAccess *f = FileAccess::open(p_path + ".flags", FileAccess::WRITE);
if (f) {
f->store_string(text);
@@ -92,7 +91,6 @@ Error ResourceSaverPNG::save(const String &p_path,const RES& p_resource,uint32_t
}
}
-
return err;
};
@@ -105,100 +103,95 @@ Error ResourceSaverPNG::save_image(const String &p_path, Image &p_img) {
png_structp png_ptr;
png_infop info_ptr;
- png_bytep * row_pointers;
-
+ png_bytep *row_pointers;
/* initialize stuff */
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
- ERR_FAIL_COND_V(!png_ptr,ERR_CANT_CREATE);
+ ERR_FAIL_COND_V(!png_ptr, ERR_CANT_CREATE);
info_ptr = png_create_info_struct(png_ptr);
- ERR_FAIL_COND_V(!info_ptr,ERR_CANT_CREATE);
+ ERR_FAIL_COND_V(!info_ptr, ERR_CANT_CREATE);
if (setjmp(png_jmpbuf(png_ptr))) {
ERR_FAIL_V(ERR_CANT_OPEN);
}
//change this
Error err;
- FileAccess* f = FileAccess::open(p_path,FileAccess::WRITE,&err);
+ FileAccess *f = FileAccess::open(p_path, FileAccess::WRITE, &err);
if (err) {
ERR_FAIL_V(err);
}
- png_set_write_fn(png_ptr,f,_write_png_data,NULL);
+ png_set_write_fn(png_ptr, f, _write_png_data, NULL);
/* write header */
if (setjmp(png_jmpbuf(png_ptr))) {
ERR_FAIL_V(ERR_CANT_OPEN);
}
- int pngf=0;
- int cs=0;
-
+ int pngf = 0;
+ int cs = 0;
- switch(p_img.get_format()) {
+ switch (p_img.get_format()) {
case Image::FORMAT_L8: {
- pngf=PNG_COLOR_TYPE_GRAY;
- cs=1;
+ pngf = PNG_COLOR_TYPE_GRAY;
+ cs = 1;
} break;
case Image::FORMAT_LA8: {
- pngf=PNG_COLOR_TYPE_GRAY_ALPHA;
- cs=2;
+ pngf = PNG_COLOR_TYPE_GRAY_ALPHA;
+ cs = 2;
} break;
case Image::FORMAT_RGB8: {
- pngf=PNG_COLOR_TYPE_RGB;
- cs=3;
+ pngf = PNG_COLOR_TYPE_RGB;
+ cs = 3;
} break;
case Image::FORMAT_RGBA8: {
- pngf=PNG_COLOR_TYPE_RGB_ALPHA;
- cs=4;
+ pngf = PNG_COLOR_TYPE_RGB_ALPHA;
+ cs = 4;
} break;
default: {
if (p_img.detect_alpha()) {
p_img.convert(Image::FORMAT_RGBA8);
- pngf=PNG_COLOR_TYPE_RGB_ALPHA;
- cs=4;
+ pngf = PNG_COLOR_TYPE_RGB_ALPHA;
+ cs = 4;
} else {
p_img.convert(Image::FORMAT_RGB8);
- pngf=PNG_COLOR_TYPE_RGB;
- cs=3;
+ pngf = PNG_COLOR_TYPE_RGB;
+ cs = 3;
}
-
}
}
int w = p_img.get_width();
int h = p_img.get_height();
- png_set_IHDR(png_ptr, info_ptr, w,h,
- 8, pngf, PNG_INTERLACE_NONE,
- PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
+ png_set_IHDR(png_ptr, info_ptr, w, h,
+ 8, pngf, PNG_INTERLACE_NONE,
+ PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
png_write_info(png_ptr, info_ptr);
-
/* write bytes */
if (setjmp(png_jmpbuf(png_ptr))) {
memdelete(f);
ERR_FAIL_V(ERR_CANT_OPEN);
}
-
PoolVector<uint8_t>::Read r = p_img.get_data().read();
- row_pointers = (png_bytep*)memalloc(sizeof(png_bytep)*h);
- for(int i=0;i<h;i++) {
+ row_pointers = (png_bytep *)memalloc(sizeof(png_bytep) * h);
+ for (int i = 0; i < h; i++) {
- row_pointers[i]=(png_bytep)&r[i*w*cs];
+ row_pointers[i] = (png_bytep)&r[i * w * cs];
}
png_write_image(png_ptr, row_pointers);
@@ -220,16 +213,15 @@ Error ResourceSaverPNG::save_image(const String &p_path, Image &p_img) {
return OK;
}
-bool ResourceSaverPNG::recognize(const RES& p_resource) const {
+bool ResourceSaverPNG::recognize(const RES &p_resource) const {
return (p_resource.is_valid() && p_resource->is_class("ImageTexture"));
}
-void ResourceSaverPNG::get_recognized_extensions(const RES& p_resource,List<String> *p_extensions) const{
+void ResourceSaverPNG::get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const {
if (p_resource->cast_to<Texture>()) {
p_extensions->push_back("png");
}
-
}
ResourceSaverPNG::ResourceSaverPNG() {
diff --git a/drivers/png/resource_saver_png.h b/drivers/png/resource_saver_png.h
index c71877d728..ebc8d8e3ae 100644
--- a/drivers/png/resource_saver_png.h
+++ b/drivers/png/resource_saver_png.h
@@ -33,15 +33,13 @@
class ResourceSaverPNG : public ResourceFormatSaver {
public:
+ static Error save_image(const String &p_path, Image &p_img);
- static Error save_image(const String &p_path, Image& p_img);
-
- virtual Error save(const String &p_path,const RES& p_resource,uint32_t p_flags=0);
- virtual bool recognize(const RES& p_resource) const;
- virtual void get_recognized_extensions(const RES& p_resource,List<String> *p_extensions) const;
+ virtual Error save(const String &p_path, const RES &p_resource, uint32_t p_flags = 0);
+ virtual bool recognize(const RES &p_resource) const;
+ virtual void get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const;
ResourceSaverPNG();
};
-
#endif // RESOURCE_SAVER_PNG_H
diff --git a/drivers/pulseaudio/audio_driver_pulseaudio.cpp b/drivers/pulseaudio/audio_driver_pulseaudio.cpp
index f5268f3ebd..d33ec3ce3a 100644
--- a/drivers/pulseaudio/audio_driver_pulseaudio.cpp
+++ b/drivers/pulseaudio/audio_driver_pulseaudio.cpp
@@ -43,7 +43,7 @@ Error AudioDriverPulseAudio::init() {
samples_in = NULL;
samples_out = NULL;
- mix_rate = GLOBAL_DEF("audio/mix_rate",44100);
+ mix_rate = GLOBAL_DEF("audio/mix_rate", 44100);
speaker_mode = SPEAKER_MODE_STEREO;
channels = 2;
@@ -64,23 +64,21 @@ Error AudioDriverPulseAudio::init() {
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
- );
+ 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));\
+ fprintf(stderr, "PulseAudio ERR: %s\n", pa_strerror(error_code));
ERR_FAIL_COND_V(pulse == NULL, ERR_CANT_OPEN);
}
-
samples_in = memnew_arr(int32_t, buffer_size * channels);
samples_out = memnew_arr(int16_t, buffer_size * channels);
@@ -92,23 +90,23 @@ Error AudioDriverPulseAudio::init() {
float AudioDriverPulseAudio::get_latency() {
- if (latency==0) { //only do this once since it's approximate anyway
+ 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;
+ pa_usec_t palat = pa_simple_get_latency(pulse, &error_code);
+ latency = double(palat) / 1000000.0;
}
return latency;
}
-void AudioDriverPulseAudio::thread_func(void* p_udata) {
+void AudioDriverPulseAudio::thread_func(void *p_udata) {
print_line("thread");
- AudioDriverPulseAudio* ad = (AudioDriverPulseAudio*)p_udata;
+ AudioDriverPulseAudio *ad = (AudioDriverPulseAudio *)p_udata;
while (!ad->exit_thread) {
if (!ad->active) {
- for (unsigned int i=0; i < ad->buffer_size * ad->channels; i++) {
+ for (unsigned int i = 0; i < ad->buffer_size * ad->channels; i++) {
ad->samples_out[i] = 0;
}
@@ -119,7 +117,7 @@ void AudioDriverPulseAudio::thread_func(void* p_udata) {
ad->unlock();
- for (unsigned int i=0; i < ad->buffer_size * ad->channels;i ++) {
+ for (unsigned int i = 0; i < ad->buffer_size * ad->channels; i++) {
ad->samples_out[i] = ad->samples_in[i] >> 16;
}
}
@@ -199,11 +197,10 @@ AudioDriverPulseAudio::AudioDriverPulseAudio() {
mutex = NULL;
thread = NULL;
pulse = NULL;
- latency=0;
+ latency = 0;
}
AudioDriverPulseAudio::~AudioDriverPulseAudio() {
-
}
#endif
diff --git a/drivers/pulseaudio/audio_driver_pulseaudio.h b/drivers/pulseaudio/audio_driver_pulseaudio.h
index 36ae8c2e53..b6508434d4 100644
--- a/drivers/pulseaudio/audio_driver_pulseaudio.h
+++ b/drivers/pulseaudio/audio_driver_pulseaudio.h
@@ -30,27 +30,27 @@
#ifdef PULSEAUDIO_ENABLED
-#include "core/os/thread.h"
#include "core/os/mutex.h"
+#include "core/os/thread.h"
#include <pulse/simple.h>
-class AudioDriverPulseAudio : public AudioDriver{
+class AudioDriverPulseAudio : public AudioDriver {
- Thread* thread;
- Mutex* mutex;
+ Thread *thread;
+ Mutex *mutex;
- pa_simple* pulse;
+ pa_simple *pulse;
- int32_t* samples_in;
- int16_t* samples_out;
+ int32_t *samples_in;
+ int16_t *samples_out;
- static void thread_func(void* p_udata);
+ static void thread_func(void *p_udata);
unsigned int mix_rate;
SpeakerMode speaker_mode;
- unsigned int buffer_size;
+ unsigned int buffer_size;
int channels;
bool active;
@@ -61,9 +61,8 @@ class AudioDriverPulseAudio : public AudioDriver{
float latency;
public:
-
- const char* get_name() const {
- return "PulseAudio";
+ const char *get_name() const {
+ return "PulseAudio";
};
virtual Error init();
@@ -76,9 +75,8 @@ public:
virtual float get_latency();
-
- AudioDriverPulseAudio();
- ~AudioDriverPulseAudio();
+ AudioDriverPulseAudio();
+ ~AudioDriverPulseAudio();
};
#endif
diff --git a/drivers/register_driver_types.cpp b/drivers/register_driver_types.cpp
index d1d5f42944..9540a16089 100644
--- a/drivers/register_driver_types.cpp
+++ b/drivers/register_driver_types.cpp
@@ -40,32 +40,30 @@
#include "platform/windows/export/export.h"
#endif
-static ImageLoaderPNG *image_loader_png=NULL;
-static ResourceSaverPNG *resource_saver_png=NULL;
-
+static ImageLoaderPNG *image_loader_png = NULL;
+static ResourceSaverPNG *resource_saver_png = NULL;
void register_core_driver_types() {
- image_loader_png = memnew( ImageLoaderPNG );
- ImageLoader::add_image_format_loader( image_loader_png );
+ image_loader_png = memnew(ImageLoaderPNG);
+ ImageLoader::add_image_format_loader(image_loader_png);
- resource_saver_png = memnew( ResourceSaverPNG );
+ resource_saver_png = memnew(ResourceSaverPNG);
ResourceSaver::add_resource_format_saver(resource_saver_png);
}
void unregister_core_driver_types() {
if (image_loader_png)
- memdelete( image_loader_png );
+ memdelete(image_loader_png);
if (resource_saver_png)
- memdelete( resource_saver_png );
+ memdelete(resource_saver_png);
}
-
void register_driver_types() {
#ifdef TOOLS_ENABLED
- Geometry::_decompose_func=b2d_decompose;
+ Geometry::_decompose_func = b2d_decompose;
#endif
}
diff --git a/drivers/rtaudio/audio_driver_rtaudio.cpp b/drivers/rtaudio/audio_driver_rtaudio.cpp
index cc715545bd..5ecd4cbaec 100644
--- a/drivers/rtaudio/audio_driver_rtaudio.cpp
+++ b/drivers/rtaudio/audio_driver_rtaudio.cpp
@@ -33,7 +33,7 @@
#ifdef RTAUDIO_ENABLED
-const char* AudioDriverRtAudio::get_name() const {
+const char *AudioDriverRtAudio::get_name() const {
#ifdef OSX_ENABLED
return "RtAudio-OSX";
@@ -44,10 +44,9 @@ const char* AudioDriverRtAudio::get_name() const {
#else
return "RtAudio-None";
#endif
-
}
-int AudioDriverRtAudio::callback( void *outputBuffer, void *inputBuffer, unsigned int nBufferFrames, double streamTime, RtAudioStreamStatus status, void *userData ) {
+int AudioDriverRtAudio::callback(void *outputBuffer, void *inputBuffer, unsigned int nBufferFrames, double streamTime, RtAudioStreamStatus status, void *userData) {
if (status) {
if (status & RTAUDIO_INPUT_OVERFLOW) {
@@ -57,19 +56,19 @@ int AudioDriverRtAudio::callback( void *outputBuffer, void *inputBuffer, unsigne
WARN_PRINT("RtAudio output underflow!");
}
}
- int32_t *buffer = (int32_t *) outputBuffer;
+ int32_t *buffer = (int32_t *)outputBuffer;
- AudioDriverRtAudio *self = (AudioDriverRtAudio*)userData;
+ AudioDriverRtAudio *self = (AudioDriverRtAudio *)userData;
- if (self->mutex->try_lock()!=OK) {
+ if (self->mutex->try_lock() != OK) {
// what should i do..
- for(unsigned int i=0;i<nBufferFrames;i++)
- buffer[i]=0;
+ for (unsigned int i = 0; i < nBufferFrames; i++)
+ buffer[i] = 0;
return 0;
}
- self->audio_server_process(nBufferFrames,buffer);
+ self->audio_server_process(nBufferFrames, buffer);
self->mutex->unlock();
@@ -78,12 +77,12 @@ int AudioDriverRtAudio::callback( void *outputBuffer, void *inputBuffer, unsigne
Error AudioDriverRtAudio::init() {
- active=false;
- mutex=NULL;
- dac = memnew( RtAudio );
+ active = false;
+ mutex = NULL;
+ dac = memnew(RtAudio);
ERR_EXPLAIN("Cannot initialize RtAudio audio driver: No devices present.")
- ERR_FAIL_COND_V( dac->getDeviceCount() < 1, ERR_UNAVAILABLE );
+ ERR_FAIL_COND_V(dac->getDeviceCount() < 1, ERR_UNAVAILABLE);
// FIXME: Adapt to the OutputFormat -> SpeakerMode change
/*
@@ -114,60 +113,60 @@ Error AudioDriverRtAudio::init() {
//int priority; /*!< Scheduling priority of callback thread (only used with flag RTAUDIO_SCHEDULE_REALTIME). */
parameters.firstChannel = 0;
- mix_rate = GLOBAL_DEF("audio/mix_rate",44100);
+ mix_rate = GLOBAL_DEF("audio/mix_rate", 44100);
- int latency = GLOBAL_DEF("audio/output_latency",25);
+ int latency = GLOBAL_DEF("audio/output_latency", 25);
// calculate desired buffer_size, taking the desired numberOfBuffers into account (latency depends on numberOfBuffers*buffer_size)
- unsigned int buffer_size = nearest_power_of_2( latency * mix_rate / 1000 / target_number_of_buffers);
+ unsigned int buffer_size = nearest_power_of_2(latency * mix_rate / 1000 / target_number_of_buffers);
if (OS::get_singleton()->is_stdout_verbose()) {
- print_line("audio buffer size: "+itos(buffer_size));
+ print_line("audio buffer size: " + itos(buffer_size));
}
short int tries = 2;
- while(true) {
- while( true) {
- switch(speaker_mode) {
+ while (true) {
+ while (true) {
+ switch (speaker_mode) {
case SPEAKER_MODE_STEREO: parameters.nChannels = 2; break;
case SPEAKER_SURROUND_51: parameters.nChannels = 6; break;
case SPEAKER_SURROUND_71: parameters.nChannels = 8; break;
};
try {
- dac->openStream( &parameters, NULL, RTAUDIO_SINT32, mix_rate, &buffer_size, &callback, this,&options );
+ dac->openStream(&parameters, NULL, RTAUDIO_SINT32, mix_rate, &buffer_size, &callback, this, &options);
mutex = Mutex::create(true);
- active=true;
+ active = true;
break;
- } catch ( RtAudioError& e ) {
+ } catch (RtAudioError &e) {
// try with less channels
ERR_PRINT("Unable to open audio, retrying with fewer channels..");
- switch(speaker_mode) {
- case SPEAKER_MODE_STEREO: speaker_mode=SPEAKER_MODE_STEREO; break;
- case SPEAKER_SURROUND_51: speaker_mode=SPEAKER_SURROUND_51; break;
- case SPEAKER_SURROUND_71: speaker_mode=SPEAKER_SURROUND_71; break;
+ switch (speaker_mode) {
+ case SPEAKER_MODE_STEREO: speaker_mode = SPEAKER_MODE_STEREO; break;
+ case SPEAKER_SURROUND_51: speaker_mode = SPEAKER_SURROUND_51; break;
+ case SPEAKER_SURROUND_71: speaker_mode = SPEAKER_SURROUND_71; break;
};
}
}
// compare actual numberOfBuffers with the desired one. If not equal, close and reopen the stream with adjusted buffer size, so the desired output_latency is still correct
- if(target_number_of_buffers != options.numberOfBuffers) {
- if(tries <= 0) {
+ if (target_number_of_buffers != options.numberOfBuffers) {
+ if (tries <= 0) {
ERR_EXPLAIN("RtAudio: Unable to set correct number of buffers.");
- ERR_FAIL_V( ERR_UNAVAILABLE );
+ ERR_FAIL_V(ERR_UNAVAILABLE);
break;
}
-
+
try {
dac->closeStream();
- } catch ( RtAudioError& e ) {
+ } catch (RtAudioError &e) {
ERR_PRINT(e.what());
- ERR_FAIL_V( ERR_UNAVAILABLE );
+ ERR_FAIL_V(ERR_UNAVAILABLE);
break;
}
- if (OS::get_singleton()->is_stdout_verbose())
+ if (OS::get_singleton()->is_stdout_verbose())
print_line("RtAudio: Desired number of buffers (" + itos(target_number_of_buffers) + ") not available. Using " + itos(options.numberOfBuffers) + " instead. Reopening stream with adjusted buffer_size.");
// new buffer size dependent on the ratio between set and actual numberOfBuffers
@@ -177,14 +176,11 @@ Error AudioDriverRtAudio::init() {
} else {
break;
}
-
-
}
return OK;
}
-
int AudioDriverRtAudio::get_mix_rate() const {
return mix_rate;
@@ -215,24 +211,19 @@ void AudioDriverRtAudio::unlock() {
void AudioDriverRtAudio::finish() {
- if ( active && dac->isStreamOpen() )
- dac->closeStream();
- if (mutex)
- memdelete(mutex);
- if (dac)
- memdelete(dac);
+ if (active && dac->isStreamOpen())
+ dac->closeStream();
+ if (mutex)
+ memdelete(mutex);
+ if (dac)
+ memdelete(dac);
}
+AudioDriverRtAudio::AudioDriverRtAudio() {
-
-AudioDriverRtAudio::AudioDriverRtAudio()
-{
-
- mutex=NULL;
- mix_rate=44100;
- speaker_mode=SPEAKER_MODE_STEREO;
+ mutex = NULL;
+ mix_rate = 44100;
+ speaker_mode = SPEAKER_MODE_STEREO;
}
-
-
#endif
diff --git a/drivers/rtaudio/audio_driver_rtaudio.h b/drivers/rtaudio/audio_driver_rtaudio.h
index 3f293db6a6..e7b480b7b2 100644
--- a/drivers/rtaudio/audio_driver_rtaudio.h
+++ b/drivers/rtaudio/audio_driver_rtaudio.h
@@ -37,29 +37,26 @@
class AudioDriverRtAudio : public AudioDriver {
-
- static int callback( void *outputBuffer, void *inputBuffer, unsigned int nBufferFrames,
- double streamTime, RtAudioStreamStatus status, void *userData );
+ static int callback(void *outputBuffer, void *inputBuffer, unsigned int nBufferFrames,
+ double streamTime, RtAudioStreamStatus status, void *userData);
SpeakerMode speaker_mode;
Mutex *mutex;
RtAudio *dac;
int mix_rate;
bool active;
-public:
-
- virtual const char* get_name() const;
+public:
+ virtual const char *get_name() const;
virtual Error init();
virtual void start();
- virtual int get_mix_rate() const ;
+ virtual int get_mix_rate() const;
virtual SpeakerMode get_speaker_mode() const;
virtual void lock();
virtual void unlock();
virtual void finish();
AudioDriverRtAudio();
-
};
#endif // AUDIO_DRIVER_RTAUDIO_H
diff --git a/drivers/unix/dir_access_unix.cpp b/drivers/unix/dir_access_unix.cpp
index a09cf80e6c..d3c7a42c70 100644
--- a/drivers/unix/dir_access_unix.cpp
+++ b/drivers/unix/dir_access_unix.cpp
@@ -34,20 +34,19 @@
#include <sys/statvfs.h>
#endif
-#include <stdio.h>
#include "os/memory.h"
#include "print_string.h"
#include <errno.h>
+#include <stdio.h>
DirAccess *DirAccessUnix::create_fs() {
- return memnew( DirAccessUnix );
+ return memnew(DirAccessUnix);
}
Error DirAccessUnix::list_dir_begin() {
-
+
list_dir_end(); //close any previous dir opening!
-
//char real_current_dir_name[2048]; //is this enough?!
//getcwd(real_current_dir_name,2048);
@@ -61,55 +60,51 @@ Error DirAccessUnix::list_dir_begin() {
}
bool DirAccessUnix::file_exists(String p_file) {
-
- GLOBAL_LOCK_FUNCTION
+ GLOBAL_LOCK_FUNCTION
if (p_file.is_rel_path())
- p_file=current_dir.plus_file(p_file);
+ p_file = current_dir.plus_file(p_file);
- p_file=fix_path(p_file);
+ p_file = fix_path(p_file);
struct stat flags;
- bool success = (stat(p_file.utf8().get_data(),&flags)==0);
+ bool success = (stat(p_file.utf8().get_data(), &flags) == 0);
if (success && S_ISDIR(flags.st_mode)) {
- success=false;
+ success = false;
}
return success;
-
}
bool DirAccessUnix::dir_exists(String p_dir) {
GLOBAL_LOCK_FUNCTION
-
if (p_dir.is_rel_path())
- p_dir=get_current_dir().plus_file(p_dir);
+ p_dir = get_current_dir().plus_file(p_dir);
- p_dir=fix_path(p_dir);
+ p_dir = fix_path(p_dir);
struct stat flags;
- bool success = (stat(p_dir.utf8().get_data(),&flags)==0);
+ bool success = (stat(p_dir.utf8().get_data(), &flags) == 0);
if (success && S_ISDIR(flags.st_mode))
return true;
return false;
-
}
uint64_t DirAccessUnix::get_modified_time(String p_file) {
if (p_file.is_rel_path())
- p_file=current_dir.plus_file(p_file);
+ p_file = current_dir.plus_file(p_file);
- p_file=fix_path(p_file);
+ p_file = fix_path(p_file);
struct stat flags;
- bool success = (stat(p_file.utf8().get_data(),&flags)==0);
+ bool success = (stat(p_file.utf8().get_data(), &flags) == 0);
if (success) {
return flags.st_mtime;
@@ -120,16 +115,15 @@ uint64_t DirAccessUnix::get_modified_time(String p_file) {
return 0;
};
-
-String DirAccessUnix::get_next() {
+String DirAccessUnix::get_next() {
if (!dir_stream)
return "";
dirent *entry;
- entry=readdir(dir_stream);
+ entry = readdir(dir_stream);
- if (entry==NULL) {
+ if (entry == NULL) {
list_dir_end();
return "";
@@ -140,31 +134,27 @@ String DirAccessUnix::get_next() {
String fname = fix_unicode_name(entry->d_name);
- String f=current_dir.plus_file(fname);
+ String f = current_dir.plus_file(fname);
- if (stat(f.utf8().get_data(),&flags)==0) {
+ if (stat(f.utf8().get_data(), &flags) == 0) {
if (S_ISDIR(flags.st_mode)) {
- _cisdir=true;
+ _cisdir = true;
} else {
- _cisdir=false;
+ _cisdir = false;
}
} else {
- _cisdir=false;
-
+ _cisdir = false;
}
- _cishidden=(fname!="." && fname!=".." && fname.begins_with("."));
-
-
+ _cishidden = (fname != "." && fname != ".." && fname.begins_with("."));
return fname;
-
}
bool DirAccessUnix::current_is_dir() const {
@@ -177,13 +167,12 @@ bool DirAccessUnix::current_is_hidden() const {
return _cishidden;
}
-
void DirAccessUnix::list_dir_end() {
if (dir_stream)
closedir(dir_stream);
- dir_stream=0;
- _cisdir=false;
+ dir_stream = 0;
+ _cisdir = false;
}
int DirAccessUnix::get_drive_count() {
@@ -200,24 +189,21 @@ Error DirAccessUnix::make_dir(String p_dir) {
GLOBAL_LOCK_FUNCTION
if (p_dir.is_rel_path())
- p_dir=get_current_dir().plus_file(p_dir);
-
-
- p_dir=fix_path(p_dir);
+ p_dir = get_current_dir().plus_file(p_dir);
+ p_dir = fix_path(p_dir);
#if 1
-
- bool success=(mkdir(p_dir.utf8().get_data(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH)==0);
+ bool success = (mkdir(p_dir.utf8().get_data(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) == 0);
int err = errno;
#else
char real_current_dir_name[2048];
- getcwd(real_current_dir_name,2048);
+ getcwd(real_current_dir_name, 2048);
chdir(current_dir.utf8().get_data()); //ascii since this may be unicode or wathever the host os wants
- bool success=(mkdir(p_dir.utf8().get_data(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH)==0);
+ bool success = (mkdir(p_dir.utf8().get_data(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) == 0);
int err = errno;
chdir(real_current_dir_name);
@@ -233,91 +219,86 @@ Error DirAccessUnix::make_dir(String p_dir) {
return ERR_CANT_CREATE;
}
-
Error DirAccessUnix::change_dir(String p_dir) {
GLOBAL_LOCK_FUNCTION
- p_dir=fix_path(p_dir);
-
+ p_dir = fix_path(p_dir);
char real_current_dir_name[2048];
- getcwd(real_current_dir_name,2048);
+ getcwd(real_current_dir_name, 2048);
String prev_dir;
if (prev_dir.parse_utf8(real_current_dir_name))
- prev_dir=real_current_dir_name; //no utf8, maybe latin?
+ prev_dir = real_current_dir_name; //no utf8, maybe latin?
chdir(current_dir.utf8().get_data()); //ascii since this may be unicode or wathever the host os wants
- bool worked=(chdir(p_dir.utf8().get_data())==0); // we can only give this utf8
+ bool worked = (chdir(p_dir.utf8().get_data()) == 0); // we can only give this utf8
String base = _get_root_path();
- if (base!="") {
+ if (base != "") {
- getcwd(real_current_dir_name,2048);
+ getcwd(real_current_dir_name, 2048);
String new_dir;
new_dir.parse_utf8(real_current_dir_name);
if (!new_dir.begins_with(base))
- worked=false;
+ worked = false;
}
if (worked) {
- getcwd(real_current_dir_name,2048);
+ getcwd(real_current_dir_name, 2048);
if (current_dir.parse_utf8(real_current_dir_name))
- current_dir=real_current_dir_name; //no utf8, maybe latin?
+ current_dir = real_current_dir_name; //no utf8, maybe latin?
}
chdir(prev_dir.utf8().get_data());
- return worked?OK:ERR_INVALID_PARAMETER;
-
+ return worked ? OK : ERR_INVALID_PARAMETER;
}
String DirAccessUnix::get_current_dir() {
String base = _get_root_path();
- if (base!="") {
+ if (base != "") {
- String bd = current_dir.replace_first(base,"");
+ String bd = current_dir.replace_first(base, "");
if (bd.begins_with("/"))
- return _get_root_string()+bd.substr(1,bd.length());
+ return _get_root_string() + bd.substr(1, bd.length());
else
- return _get_root_string()+bd;
-
+ return _get_root_string() + bd;
}
return current_dir;
}
-Error DirAccessUnix::rename(String p_path,String p_new_path) {
+Error DirAccessUnix::rename(String p_path, String p_new_path) {
if (p_path.is_rel_path())
- p_path=get_current_dir().plus_file(p_path);
+ p_path = get_current_dir().plus_file(p_path);
- p_path=fix_path(p_path);
+ p_path = fix_path(p_path);
if (p_new_path.is_rel_path())
- p_new_path=get_current_dir().plus_file(p_new_path);
+ p_new_path = get_current_dir().plus_file(p_new_path);
- p_new_path=fix_path(p_new_path);
+ p_new_path = fix_path(p_new_path);
- return ::rename(p_path.utf8().get_data(),p_new_path.utf8().get_data())==0?OK:FAILED;
+ return ::rename(p_path.utf8().get_data(), p_new_path.utf8().get_data()) == 0 ? OK : FAILED;
}
-Error DirAccessUnix::remove(String p_path) {
+Error DirAccessUnix::remove(String p_path) {
if (p_path.is_rel_path())
- p_path=get_current_dir().plus_file(p_path);
+ p_path = get_current_dir().plus_file(p_path);
- p_path=fix_path(p_path);
+ p_path = fix_path(p_path);
struct stat flags;
- if ((stat(p_path.utf8().get_data(),&flags)!=0))
+ if ((stat(p_path.utf8().get_data(), &flags) != 0))
return FAILED;
if (S_ISDIR(flags.st_mode))
- return ::rmdir(p_path.utf8().get_data())==0?OK:FAILED;
+ return ::rmdir(p_path.utf8().get_data()) == 0 ? OK : FAILED;
else
- return ::unlink(p_path.utf8().get_data())==0?OK:FAILED;
+ return ::unlink(p_path.utf8().get_data()) == 0 ? OK : FAILED;
}
-
size_t DirAccessUnix::get_space_left() {
#ifndef NO_STATVFS
@@ -331,28 +312,23 @@ size_t DirAccessUnix::get_space_left() {
#else
#warning THIS IS BROKEN
return 0;
-#endif
+#endif
};
-
-
DirAccessUnix::DirAccessUnix() {
- dir_stream=0;
- current_dir=".";
- _cisdir=false;
+ dir_stream = 0;
+ current_dir = ".";
+ _cisdir = false;
/* determine drive count */
change_dir(current_dir);
-
}
-
DirAccessUnix::~DirAccessUnix() {
list_dir_end();
}
-
#endif //posix_enabled
diff --git a/drivers/unix/dir_access_unix.h b/drivers/unix/dir_access_unix.h
index f075c48268..0ec0e551d7 100644
--- a/drivers/unix/dir_access_unix.h
+++ b/drivers/unix/dir_access_unix.h
@@ -31,65 +31,57 @@
#if defined(UNIX_ENABLED) || defined(LIBC_FILEIO_ENABLED)
-#include <sys/types.h>
+#include <dirent.h>
#include <sys/stat.h>
+#include <sys/types.h>
#include <unistd.h>
-#include <dirent.h>
#include "os/dir_access.h"
-
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
class DirAccessUnix : public DirAccess {
-
+
DIR *dir_stream;
-
+
static DirAccess *create_fs();
-
+
String current_dir;
bool _cisdir;
bool _cishidden;
-protected:
- virtual String fix_unicode_name(const char* p_name) const { return String::utf8(p_name); }
+protected:
+ virtual String fix_unicode_name(const char *p_name) const { return String::utf8(p_name); }
public:
-
virtual Error list_dir_begin(); ///< This starts dir listing
virtual String get_next();
virtual bool current_is_dir() const;
virtual bool current_is_hidden() const;
-
- virtual void list_dir_end(); ///<
-
+
+ virtual void list_dir_end(); ///<
+
virtual int get_drive_count();
virtual String get_drive(int p_drive);
-
+
virtual Error change_dir(String p_dir); ///< can be relative or absolute, return false on success
virtual String get_current_dir(); ///< return current dir location
virtual Error make_dir(String p_dir);
-
+
virtual bool file_exists(String p_file);
virtual bool dir_exists(String p_dir);
virtual uint64_t get_modified_time(String p_file);
-
-
virtual Error rename(String p_from, String p_to);
virtual Error remove(String p_name);
virtual size_t get_space_left();
-
-
+
DirAccessUnix();
~DirAccessUnix();
-
};
-
-
#endif //UNIX ENABLED
#endif
diff --git a/drivers/unix/file_access_unix.cpp b/drivers/unix/file_access_unix.cpp
index ee51db6694..723bf3321a 100644
--- a/drivers/unix/file_access_unix.cpp
+++ b/drivers/unix/file_access_unix.cpp
@@ -30,20 +30,20 @@
#if defined(UNIX_ENABLED) || defined(LIBC_FILEIO_ENABLED)
-#include <sys/types.h>
-#include <sys/stat.h>
-#include "print_string.h"
#include "core/os/os.h"
+#include "print_string.h"
+#include <sys/stat.h>
+#include <sys/types.h>
#ifndef ANDROID_ENABLED
#include <sys/statvfs.h>
#endif
#ifdef MSVC
- #define S_ISREG(m) ((m)&_S_IFREG)
+#define S_ISREG(m) ((m)&_S_IFREG)
#endif
#ifndef S_ISREG
- #define S_ISREG(m) ((m) & S_IFREG)
+#define S_ISREG(m) ((m)&S_IFREG)
#endif
void FileAccessUnix::check_errors() const {
@@ -52,31 +52,30 @@ void FileAccessUnix::check_errors() const {
if (feof(f)) {
- last_error=ERR_FILE_EOF;
+ last_error = ERR_FILE_EOF;
}
-
}
-Error FileAccessUnix::_open(const String& p_path, int p_mode_flags) {
+Error FileAccessUnix::_open(const String &p_path, int p_mode_flags) {
if (f)
fclose(f);
- f=NULL;
+ f = NULL;
- path=fix_path(p_path);
+ path = fix_path(p_path);
//printf("opening %ls, %i\n", path.c_str(), Memory::get_static_mem_usage());
- ERR_FAIL_COND_V(f,ERR_ALREADY_IN_USE);
- const char* mode_string;
-
- if (p_mode_flags==READ)
- mode_string="rb";
- else if (p_mode_flags==WRITE)
- mode_string="wb";
- else if (p_mode_flags==READ_WRITE)
- mode_string="rb+";
- else if (p_mode_flags==WRITE_READ)
- mode_string="wb+";
+ ERR_FAIL_COND_V(f, ERR_ALREADY_IN_USE);
+ const char *mode_string;
+
+ if (p_mode_flags == READ)
+ mode_string = "rb";
+ else if (p_mode_flags == WRITE)
+ mode_string = "wb";
+ else if (p_mode_flags == READ_WRITE)
+ mode_string = "rb+";
+ else if (p_mode_flags == WRITE_READ)
+ mode_string = "wb+";
else
return ERR_INVALID_PARAMETER;
@@ -85,30 +84,28 @@ Error FileAccessUnix::_open(const String& p_path, int p_mode_flags) {
//printf("opening %s as %s\n", p_path.utf8().get_data(), path.utf8().get_data());
struct stat st;
- if (stat(path.utf8().get_data(),&st) == 0) {
+ if (stat(path.utf8().get_data(), &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=path;
- path=path+".tmp";
+ if (is_backup_save_enabled() && p_mode_flags & WRITE && !(p_mode_flags & READ)) {
+ save_path = path;
+ path = path + ".tmp";
//print_line("saving instead to "+path);
}
- f=fopen(path.utf8().get_data(),mode_string);
+ f = fopen(path.utf8().get_data(), mode_string);
- if (f==NULL) {
- last_error=ERR_FILE_CANT_OPEN;
+ if (f == NULL) {
+ last_error = ERR_FILE_CANT_OPEN;
return ERR_FILE_CANT_OPEN;
} else {
- last_error=OK;
- flags=p_mode_flags;
+ last_error = OK;
+ flags = p_mode_flags;
return OK;
}
-
}
void FileAccessUnix::close() {
@@ -117,57 +114,53 @@ void FileAccessUnix::close() {
fclose(f);
f = NULL;
if (close_notification_func) {
- close_notification_func(path,flags);
+ close_notification_func(path, flags);
}
- if (save_path!="") {
+ if (save_path != "") {
//unlink(save_path.utf8().get_data());
//print_line("renaming..");
- int rename_error = rename((save_path+".tmp").utf8().get_data(),save_path.utf8().get_data());
+ int rename_error = rename((save_path + ".tmp").utf8().get_data(), save_path.utf8().get_data());
if (rename_error && close_fail_notify) {
close_fail_notify(save_path);
}
- save_path="";
- ERR_FAIL_COND( rename_error != 0);
+ save_path = "";
+ ERR_FAIL_COND(rename_error != 0);
}
-
-
}
-bool FileAccessUnix::is_open() const{
+bool FileAccessUnix::is_open() const {
- return (f!=NULL);
+ return (f != NULL);
}
void FileAccessUnix::seek(size_t p_position) {
ERR_FAIL_COND(!f);
- last_error=OK;
- if ( fseek(f,p_position,SEEK_SET) )
+ last_error = OK;
+ if (fseek(f, p_position, SEEK_SET))
check_errors();
}
-void FileAccessUnix::seek_end(int64_t p_position) {
+void FileAccessUnix::seek_end(int64_t p_position) {
ERR_FAIL_COND(!f);
- if ( fseek(f,p_position,SEEK_END) )
+ if (fseek(f, p_position, SEEK_END))
check_errors();
}
-size_t FileAccessUnix::get_pos() const{
-
+size_t FileAccessUnix::get_pos() const {
- size_t aux_position=0;
- if ( !(aux_position = ftell(f)) ) {
+ size_t aux_position = 0;
+ if (!(aux_position = ftell(f))) {
check_errors();
};
return aux_position;
}
-size_t FileAccessUnix::get_len() const{
+size_t FileAccessUnix::get_len() const {
+ ERR_FAIL_COND_V(!f, 0);
- ERR_FAIL_COND_V(!f,0);
-
- FileAccessUnix *fau = const_cast<FileAccessUnix*>(this);
+ FileAccessUnix *fau = const_cast<FileAccessUnix *>(this);
int pos = fau->get_pos();
fau->seek_end();
int size = fau->get_pos();
@@ -176,16 +169,16 @@ size_t FileAccessUnix::get_len() const{
return size;
}
-bool FileAccessUnix::eof_reached() const{
+bool FileAccessUnix::eof_reached() const {
- return last_error==ERR_FILE_EOF;
+ return last_error == ERR_FILE_EOF;
}
-uint8_t FileAccessUnix::get_8() const{
+uint8_t FileAccessUnix::get_8() const {
- ERR_FAIL_COND_V(!f,0);
+ ERR_FAIL_COND_V(!f, 0);
uint8_t b;
- if (fread(&b,1,1,f) == 0) {
+ if (fread(&b, 1, 1, f) == 0) {
check_errors();
};
@@ -194,13 +187,13 @@ uint8_t FileAccessUnix::get_8() const{
int FileAccessUnix::get_buffer(uint8_t *p_dst, int p_length) const {
- ERR_FAIL_COND_V(!f,-1);
+ ERR_FAIL_COND_V(!f, -1);
int read = fread(p_dst, 1, p_length, f);
check_errors();
return read;
};
-Error FileAccessUnix::get_error() const{
+Error FileAccessUnix::get_error() const {
return last_error;
}
@@ -208,18 +201,16 @@ Error FileAccessUnix::get_error() const{
void FileAccessUnix::store_8(uint8_t p_dest) {
ERR_FAIL_COND(!f);
- fwrite(&p_dest,1,1,f);
-
+ fwrite(&p_dest, 1, 1, f);
}
-
bool FileAccessUnix::file_exists(const String &p_path) {
FILE *g;
//printf("opening file %s\n", p_fname.c_str());
- String filename=fix_path(p_path);
- g=fopen(filename.utf8().get_data(),"rb");
- if (g==NULL) {
+ String filename = fix_path(p_path);
+ g = fopen(filename.utf8().get_data(), "rb");
+ if (g == NULL) {
return false;
} else {
@@ -231,38 +222,35 @@ bool FileAccessUnix::file_exists(const String &p_path) {
uint64_t FileAccessUnix::_get_modified_time(const String &p_file) {
- String file=fix_path(p_file);
+ String file = fix_path(p_file);
struct stat flags;
- bool success = (stat(file.utf8().get_data(),&flags)==0);
+ bool success = (stat(file.utf8().get_data(), &flags) == 0);
if (success) {
return flags.st_mtime;
} else {
- print_line("ERROR IN: "+p_file);
+ print_line("ERROR IN: " + p_file);
ERR_FAIL_V(0);
};
-
}
-FileAccess * FileAccessUnix::create_libc() {
+FileAccess *FileAccessUnix::create_libc() {
- return memnew( FileAccessUnix );
+ return memnew(FileAccessUnix);
}
-CloseNotificationFunc FileAccessUnix::close_notification_func=NULL;
+CloseNotificationFunc FileAccessUnix::close_notification_func = NULL;
FileAccessUnix::FileAccessUnix() {
- f=NULL;
- flags=0;
- last_error=OK;
-
+ f = NULL;
+ flags = 0;
+ last_error = OK;
}
FileAccessUnix::~FileAccessUnix() {
close();
-
}
#endif
diff --git a/drivers/unix/file_access_unix.h b/drivers/unix/file_access_unix.h
index 57b643dc26..4b5897e9a5 100644
--- a/drivers/unix/file_access_unix.h
+++ b/drivers/unix/file_access_unix.h
@@ -39,50 +39,47 @@
@author Juan Linietsky <reduzio@gmail.com>
*/
-
-typedef void (*CloseNotificationFunc)(const String& p_file,int p_flags);
+typedef void (*CloseNotificationFunc)(const String &p_file, int p_flags);
class FileAccessUnix : public FileAccess {
-
+
FILE *f;
int flags;
void check_errors() const;
mutable Error last_error;
String save_path;
String path;
-
- static FileAccess* create_libc();
+
+ static FileAccess *create_libc();
+
public:
-
static CloseNotificationFunc close_notification_func;
- virtual Error _open(const String& p_path, int p_mode_flags); ///< open a file
+ virtual Error _open(const String &p_path, int p_mode_flags); ///< open a file
virtual void close(); ///< close a file
- virtual bool is_open() const; ///< true when file is open
+ virtual bool is_open() const; ///< true when file is open
- 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_pos() const; ///< get position in the file
- virtual size_t get_len() const; ///< get size of the 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_pos() const; ///< get position in the file
+ virtual size_t get_len() const; ///< get size of the file
- virtual bool eof_reached() const; ///< reading passed EOF
+ virtual bool eof_reached() const; ///< reading passed EOF
- virtual uint8_t get_8() const; ///< get a byte
+ virtual uint8_t get_8() const; ///< get a byte
virtual int get_buffer(uint8_t *p_dst, int p_length) const;
- virtual Error get_error() const; ///< get last error
+ virtual Error get_error() const; ///< get last error
- virtual void store_8(uint8_t p_dest); ///< store a byte
-
- virtual bool file_exists(const String& p_path); ///< return true if a file exists
+ virtual void store_8(uint8_t p_dest); ///< store a byte
- virtual uint64_t _get_modified_time(const String& p_file);
+ virtual bool file_exists(const String &p_path); ///< return true if a file exists
+
+ virtual uint64_t _get_modified_time(const String &p_file);
FileAccessUnix();
virtual ~FileAccessUnix();
-
};
-
#endif
#endif
diff --git a/drivers/unix/ip_unix.cpp b/drivers/unix/ip_unix.cpp
index fc0b3faccc..d9dfd3c736 100644
--- a/drivers/unix/ip_unix.cpp
+++ b/drivers/unix/ip_unix.cpp
@@ -33,60 +33,60 @@
#include <string.h>
#ifdef WINDOWS_ENABLED
- #include <ws2tcpip.h>
- #include <winsock2.h>
- #include <windows.h>
- #include <stdio.h>
- #ifndef UWP_ENABLED
- #if defined(__MINGW32__ ) && (!defined(__MINGW64_VERSION_MAJOR) || __MINGW64_VERSION_MAJOR < 4)
- // MinGW-w64 on Ubuntu 12.04 (our Travis build env) has bugs in this code where
- // some includes are missing in dependencies of iphlpapi.h for WINVER >= 0x0600 (Vista).
- // We don't use this Vista code for now, so working it around by disabling it.
- // MinGW-w64 >= 4.0 seems to be better judging by its headers.
- #undef _WIN32_WINNT
- #define _WIN32_WINNT 0x0501 // Windows XP, disable Vista API
- #include <iphlpapi.h>
- #undef _WIN32_WINNT
- #define _WIN32_WINNT 0x0600 // Reenable Vista API
- #else
- #include <iphlpapi.h>
- #endif // MINGW hack
- #endif
+#include <stdio.h>
+#include <windows.h>
+#include <winsock2.h>
+#include <ws2tcpip.h>
+#ifndef UWP_ENABLED
+#if defined(__MINGW32__) && (!defined(__MINGW64_VERSION_MAJOR) || __MINGW64_VERSION_MAJOR < 4)
+// MinGW-w64 on Ubuntu 12.04 (our Travis build env) has bugs in this code where
+// some includes are missing in dependencies of iphlpapi.h for WINVER >= 0x0600 (Vista).
+// We don't use this Vista code for now, so working it around by disabling it.
+// MinGW-w64 >= 4.0 seems to be better judging by its headers.
+#undef _WIN32_WINNT
+#define _WIN32_WINNT 0x0501 // Windows XP, disable Vista API
+#include <iphlpapi.h>
+#undef _WIN32_WINNT
+#define _WIN32_WINNT 0x0600 // Reenable Vista API
#else
- #include <netdb.h>
- #ifdef ANDROID_ENABLED
- #include "platform/android/ifaddrs_android.h"
- #else
- #ifdef __FreeBSD__
- #include <sys/types.h>
- #endif
- #include <ifaddrs.h>
- #endif
- #include <arpa/inet.h>
- #include <sys/socket.h>
- #ifdef __FreeBSD__
- #include <netinet/in.h>
- #endif
+#include <iphlpapi.h>
+#endif // MINGW hack
+#endif
+#else
+#include <netdb.h>
+#ifdef ANDROID_ENABLED
+#include "platform/android/ifaddrs_android.h"
+#else
+#ifdef __FreeBSD__
+#include <sys/types.h>
+#endif
+#include <ifaddrs.h>
+#endif
+#include <arpa/inet.h>
+#include <sys/socket.h>
+#ifdef __FreeBSD__
+#include <netinet/in.h>
+#endif
#endif
-static IP_Address _sockaddr2ip(struct sockaddr* p_addr) {
+static IP_Address _sockaddr2ip(struct sockaddr *p_addr) {
IP_Address ip;
if (p_addr->sa_family == AF_INET) {
- struct sockaddr_in* addr = (struct sockaddr_in*)p_addr;
+ struct sockaddr_in *addr = (struct sockaddr_in *)p_addr;
ip.set_ipv4((uint8_t *)&(addr->sin_addr));
} else {
- struct sockaddr_in6* addr6 = (struct sockaddr_in6*)p_addr;
+ struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)p_addr;
ip.set_ipv6(addr6->sin6_addr.s6_addr);
};
return ip;
};
-IP_Address IP_Unix::_resolve_hostname(const String& p_hostname, Type p_type) {
+IP_Address IP_Unix::_resolve_hostname(const String &p_hostname, Type p_type) {
struct addrinfo hints;
- struct addrinfo* result;
+ struct addrinfo *result;
memset(&hints, 0, sizeof(struct addrinfo));
if (p_type == TYPE_IPV4) {
@@ -115,7 +115,6 @@ IP_Address IP_Unix::_resolve_hostname(const String& p_hostname, Type p_type) {
freeaddrinfo(result);
return ip;
-
}
#if defined(WINDOWS_ENABLED)
@@ -136,23 +135,22 @@ void IP_Unix::get_local_addresses(List<IP_Address> *r_addresses) const {
r_addresses->push_back(IP_Address(String(hostnames->GetAt(i)->CanonicalName->Data())));
}
}
-
};
#else
void IP_Unix::get_local_addresses(List<IP_Address> *r_addresses) const {
ULONG buf_size = 1024;
- IP_ADAPTER_ADDRESSES* addrs;
+ IP_ADAPTER_ADDRESSES *addrs;
while (true) {
- addrs = (IP_ADAPTER_ADDRESSES*)memalloc(buf_size);
+ 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);
+ GAA_FLAG_SKIP_MULTICAST |
+ GAA_FLAG_SKIP_DNS_SERVER |
+ GAA_FLAG_SKIP_FRIENDLY_NAME,
+ NULL, addrs, &buf_size);
if (err == NO_ERROR) {
break;
};
@@ -166,29 +164,27 @@ void IP_Unix::get_local_addresses(List<IP_Address> *r_addresses) const {
return;
};
-
- IP_ADAPTER_ADDRESSES* adapter = addrs;
+ IP_ADAPTER_ADDRESSES *adapter = addrs;
while (adapter != NULL) {
- IP_ADAPTER_UNICAST_ADDRESS* address = adapter->FirstUnicastAddress;
+ IP_ADAPTER_UNICAST_ADDRESS *address = adapter->FirstUnicastAddress;
while (address != NULL) {
IP_Address ip;
if (address->Address.lpSockaddr->sa_family == AF_INET) {
- SOCKADDR_IN* ipv4 = reinterpret_cast<SOCKADDR_IN*>(address->Address.lpSockaddr);
+ SOCKADDR_IN *ipv4 = reinterpret_cast<SOCKADDR_IN *>(address->Address.lpSockaddr);
ip.set_ipv4((uint8_t *)&(ipv4->sin_addr));
} else { // ipv6
- SOCKADDR_IN6* ipv6 = reinterpret_cast<SOCKADDR_IN6*>(address->Address.lpSockaddr);
+ SOCKADDR_IN6 *ipv6 = reinterpret_cast<SOCKADDR_IN6 *>(address->Address.lpSockaddr);
ip.set_ipv6(ipv6->sin6_addr.s6_addr);
};
-
r_addresses->push_back(ip);
address = address->Next;
@@ -205,8 +201,8 @@ void IP_Unix::get_local_addresses(List<IP_Address> *r_addresses) const {
void IP_Unix::get_local_addresses(List<IP_Address> *r_addresses) const {
- struct ifaddrs * ifAddrStruct=NULL;
- struct ifaddrs * ifa=NULL;
+ struct ifaddrs *ifAddrStruct = NULL;
+ struct ifaddrs *ifa = NULL;
getifaddrs(&ifAddrStruct);
@@ -218,19 +214,18 @@ void IP_Unix::get_local_addresses(List<IP_Address> *r_addresses) const {
r_addresses->push_back(ip);
}
- if (ifAddrStruct!=NULL) freeifaddrs(ifAddrStruct);
-
+ if (ifAddrStruct != NULL) freeifaddrs(ifAddrStruct);
}
#endif
void IP_Unix::make_default() {
- _create=_create_unix;
+ _create = _create_unix;
}
-IP* IP_Unix::_create_unix() {
+IP *IP_Unix::_create_unix() {
- return memnew( IP_Unix );
+ return memnew(IP_Unix);
}
IP_Unix::IP_Unix() {
diff --git a/drivers/unix/ip_unix.h b/drivers/unix/ip_unix.h
index eb7ebf8bb0..c22fedfe1c 100644
--- a/drivers/unix/ip_unix.h
+++ b/drivers/unix/ip_unix.h
@@ -36,11 +36,11 @@
class IP_Unix : public IP {
GDCLASS(IP_Unix, IP);
- virtual IP_Address _resolve_hostname(const String& p_hostname, IP::Type p_type);
+ virtual IP_Address _resolve_hostname(const String &p_hostname, IP::Type p_type);
- static IP* _create_unix();
-public:
+ static IP *_create_unix();
+public:
virtual void get_local_addresses(List<IP_Address> *r_addresses) const;
static void make_default();
diff --git a/drivers/unix/mutex_posix.cpp b/drivers/unix/mutex_posix.cpp
index c9b5bdce75..9009da2065 100644
--- a/drivers/unix/mutex_posix.cpp
+++ b/drivers/unix/mutex_posix.cpp
@@ -34,7 +34,6 @@
void MutexPosix::lock() {
pthread_mutex_lock(&mutex);
-
}
void MutexPosix::unlock() {
@@ -42,32 +41,30 @@ void MutexPosix::unlock() {
}
Error MutexPosix::try_lock() {
- return (pthread_mutex_trylock(&mutex)==0)?OK:ERR_BUSY;
+ return (pthread_mutex_trylock(&mutex) == 0) ? OK : ERR_BUSY;
}
Mutex *MutexPosix::create_func_posix(bool p_recursive) {
- return memnew( MutexPosix(p_recursive) );
+ return memnew(MutexPosix(p_recursive));
}
void MutexPosix::make_default() {
- create_func=create_func_posix;
+ create_func = create_func_posix;
}
MutexPosix::MutexPosix(bool p_recursive) {
-
+
pthread_mutexattr_init(&attr);
if (p_recursive)
- pthread_mutexattr_settype(&attr,PTHREAD_MUTEX_RECURSIVE);
- pthread_mutex_init(&mutex,&attr);
+ pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
+ pthread_mutex_init(&mutex, &attr);
}
-
MutexPosix::~MutexPosix() {
pthread_mutex_destroy(&mutex);
}
-
#endif
diff --git a/drivers/unix/mutex_posix.h b/drivers/unix/mutex_posix.h
index a71400924a..84fb32b844 100644
--- a/drivers/unix/mutex_posix.h
+++ b/drivers/unix/mutex_posix.h
@@ -31,29 +31,26 @@
#if defined(UNIX_ENABLED) || defined(PTHREAD_ENABLED)
-#include <pthread.h>
#include "os/mutex.h"
+#include <pthread.h>
class MutexPosix : public Mutex {
- pthread_mutexattr_t attr;
+ pthread_mutexattr_t attr;
pthread_mutex_t mutex;
-
+
static Mutex *create_func_posix(bool p_recursive);
-
-public:
- virtual void lock();
+public:
+ virtual void lock();
virtual void unlock();
- virtual Error try_lock();
-
+ virtual Error try_lock();
static void make_default();
MutexPosix(bool p_recursive);
-
- ~MutexPosix();
+ ~MutexPosix();
};
#endif
diff --git a/drivers/unix/os_unix.cpp b/drivers/unix/os_unix.cpp
index fe49501328..e2a544b676 100644
--- a/drivers/unix/os_unix.cpp
+++ b/drivers/unix/os_unix.cpp
@@ -32,18 +32,18 @@
#include "servers/visual_server.h"
-#include "thread_posix.h"
-#include "semaphore_posix.h"
+#include "core/os/thread_dummy.h"
#include "mutex_posix.h"
#include "rw_lock_posix.h"
-#include "core/os/thread_dummy.h"
+#include "semaphore_posix.h"
+#include "thread_posix.h"
//#include "core/io/file_access_buffered_fa.h"
-#include "file_access_unix.h"
#include "dir_access_unix.h"
-#include "tcp_server_posix.h"
-#include "stream_peer_tcp_posix.h"
+#include "file_access_unix.h"
#include "packet_peer_udp_posix.h"
+#include "stream_peer_tcp_posix.h"
+#include "tcp_server_posix.h"
#ifdef __APPLE__
#include <mach-o/dyld.h>
@@ -52,51 +52,50 @@
#ifdef __FreeBSD__
#include <sys/param.h>
#endif
+#include "global_config.h"
+#include <assert.h>
+#include <errno.h>
+#include <poll.h>
+#include <signal.h>
#include <stdarg.h>
-#include <sys/time.h>
-#include <sys/wait.h>
#include <stdlib.h>
-#include <signal.h>
#include <string.h>
-#include <poll.h>
-#include <errno.h>
-#include <assert.h>
-#include "global_config.h"
+#include <sys/time.h>
+#include <sys/wait.h>
extern bool _print_error_enabled;
-void OS_Unix::print_error(const char* p_function,const char* p_file,int p_line,const char *p_code,const char*p_rationale,ErrorType p_type) {
+void OS_Unix::print_error(const char *p_function, const char *p_file, int p_line, const char *p_code, const char *p_rationale, ErrorType p_type) {
if (!_print_error_enabled)
return;
- const char* err_details;
+ const char *err_details;
if (p_rationale && p_rationale[0])
- err_details=p_rationale;
+ err_details = p_rationale;
else
- err_details=p_code;
+ err_details = p_code;
- switch(p_type) {
+ switch (p_type) {
case ERR_ERROR:
- print("\E[1;31mERROR: %s: \E[0m\E[1m%s\n",p_function,err_details);
- print("\E[0;31m At: %s:%i.\E[0m\n",p_file,p_line);
+ print("\E[1;31mERROR: %s: \E[0m\E[1m%s\n", p_function, err_details);
+ print("\E[0;31m At: %s:%i.\E[0m\n", p_file, p_line);
break;
case ERR_WARNING:
- print("\E[1;33mWARNING: %s: \E[0m\E[1m%s\n",p_function,err_details);
- print("\E[0;33m At: %s:%i.\E[0m\n",p_file,p_line);
+ print("\E[1;33mWARNING: %s: \E[0m\E[1m%s\n", p_function, err_details);
+ print("\E[0;33m At: %s:%i.\E[0m\n", p_file, p_line);
break;
case ERR_SCRIPT:
- print("\E[1;35mSCRIPT ERROR: %s: \E[0m\E[1m%s\n",p_function,err_details);
- print("\E[0;35m At: %s:%i.\E[0m\n",p_file,p_line);
+ print("\E[1;35mSCRIPT ERROR: %s: \E[0m\E[1m%s\n", p_function, err_details);
+ print("\E[0;35m At: %s:%i.\E[0m\n", p_file, p_line);
break;
case ERR_SHADER:
- print("\E[1;36mSHADER ERROR: %s: \E[0m\E[1m%s\n",p_function,err_details);
- print("\E[0;36m At: %s:%i.\E[0m\n",p_file,p_line);
+ print("\E[1;36mSHADER ERROR: %s: \E[0m\E[1m%s\n", p_function, err_details);
+ print("\E[0;36m At: %s:%i.\E[0m\n", p_file, p_line);
break;
}
}
-
void OS_Unix::debug_break() {
assert(false);
@@ -105,26 +104,26 @@ void OS_Unix::debug_break() {
int OS_Unix::get_audio_driver_count() const {
return 1;
-
}
-const char * OS_Unix::get_audio_driver_name(int p_driver) const {
+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;
}
-
+
// Very simple signal handler to reap processes where ::execute was called with
// !p_blocking
void handle_sigchld(int sig) {
int saved_errno = errno;
- while (waitpid((pid_t)(-1), 0, WNOHANG) > 0) {}
+ while (waitpid((pid_t)(-1), 0, WNOHANG) > 0) {
+ }
errno = saved_errno;
}
-
+
void OS_Unix::initialize_core() {
#ifdef NO_PTHREADS
@@ -132,9 +131,9 @@ void OS_Unix::initialize_core() {
SemaphoreDummy::make_default();
MutexDummy::make_default();
#else
- ThreadPosix::make_default();
+ ThreadPosix::make_default();
SemaphorePosix::make_default();
- MutexPosix::make_default();
+ MutexPosix::make_default();
RWLockPosix::make_default();
#endif
FileAccess::make_default<FileAccessUnix>(FileAccess::ACCESS_RESOURCES);
@@ -152,8 +151,8 @@ void OS_Unix::initialize_core() {
IP_Unix::make_default();
#endif
- ticks_start=0;
- ticks_start=get_ticks_usec();
+ ticks_start = 0;
+ ticks_start = get_ticks_usec();
struct sigaction sa;
sa.sa_handler = &handle_sigchld;
@@ -165,39 +164,34 @@ void OS_Unix::initialize_core() {
}
void OS_Unix::finalize_core() {
-
-
-
}
-
-void OS_Unix::vprint(const char* p_format, va_list p_list,bool p_stder) {
+void OS_Unix::vprint(const char *p_format, va_list p_list, bool p_stder) {
if (p_stder) {
- vfprintf(stderr,p_format,p_list);
+ vfprintf(stderr, p_format, p_list);
fflush(stderr);
} else {
- vprintf(p_format,p_list);
+ vprintf(p_format, p_list);
fflush(stdout);
}
}
-void OS_Unix::print(const char *p_format, ... ) {
+void OS_Unix::print(const char *p_format, ...) {
va_list argp;
va_start(argp, p_format);
- vprintf(p_format, argp );
+ vprintf(p_format, argp);
va_end(argp);
-
}
-void OS_Unix::alert(const String& p_alert,const String& p_title) {
+void OS_Unix::alert(const String &p_alert, const String &p_title) {
- fprintf(stderr,"ERROR: %s\n",p_alert.utf8().get_data());
+ fprintf(stderr, "ERROR: %s\n", p_alert.utf8().get_data());
}
-static int has_data(FILE* p_fd, int timeout_usec = 0) {
+static int has_data(FILE *p_fd, int timeout_usec = 0) {
fd_set readset;
int fd = fileno(p_fd);
@@ -206,17 +200,16 @@ static int has_data(FILE* p_fd, int timeout_usec = 0) {
timeval time;
time.tv_sec = 0;
time.tv_usec = timeout_usec;
- int res = 0;//select(fd + 1, &readset, NULL, NULL, &time);
+ int res = 0; //select(fd + 1, &readset, NULL, NULL, &time);
return res > 0;
};
-
String OS_Unix::get_stdin_string(bool p_block) {
String ret;
if (p_block) {
char buff[1024];
- ret = stdin_buf + fgets(buff,1024,stdin);
+ ret = stdin_buf + fgets(buff, 1024, stdin);
stdin_buf = "";
return ret;
};
@@ -243,7 +236,6 @@ String OS_Unix::get_name() {
return "Unix";
}
-
uint64_t OS_Unix::get_unix_time() const {
return time(NULL);
@@ -257,39 +249,38 @@ uint64_t OS_Unix::get_system_time_secs() const {
return uint64_t(tv_now.tv_sec);
}
-
OS::Date OS_Unix::get_date(bool utc) const {
- time_t t=time(NULL);
+ time_t t = time(NULL);
struct tm *lt;
if (utc)
- lt=gmtime(&t);
+ lt = gmtime(&t);
else
- lt=localtime(&t);
+ lt = localtime(&t);
Date ret;
- ret.year=1900+lt->tm_year;
+ ret.year = 1900 + lt->tm_year;
// Index starting at 1 to match OS_Unix::get_date
- // and Windows SYSTEMTIME and tm_mon follows the typical structure
+ // and Windows SYSTEMTIME and tm_mon follows the typical structure
// of 0-11, noted here: http://www.cplusplus.com/reference/ctime/tm/
- ret.month=(Month)(lt->tm_mon + 1);
- ret.day=lt->tm_mday;
- ret.weekday=(Weekday)lt->tm_wday;
- ret.dst=lt->tm_isdst;
-
+ ret.month = (Month)(lt->tm_mon + 1);
+ ret.day = lt->tm_mday;
+ ret.weekday = (Weekday)lt->tm_wday;
+ ret.dst = lt->tm_isdst;
+
return ret;
}
OS::Time OS_Unix::get_time(bool utc) const {
- time_t t=time(NULL);
+ time_t t = time(NULL);
struct tm *lt;
if (utc)
- lt=gmtime(&t);
+ lt = gmtime(&t);
else
- lt=localtime(&t);
+ lt = localtime(&t);
Time ret;
- ret.hour=lt->tm_hour;
- ret.min=lt->tm_min;
- ret.sec=lt->tm_sec;
+ ret.hour = lt->tm_hour;
+ ret.min = lt->tm_min;
+ ret.sec = lt->tm_sec;
get_time_zone_info();
return ret;
}
@@ -327,105 +318,99 @@ void OS_Unix::delay_usec(uint32_t p_usec) const {
uint64_t OS_Unix::get_ticks_usec() const {
struct timeval tv_now;
- gettimeofday(&tv_now,NULL);
-
- uint64_t longtime = (uint64_t)tv_now.tv_usec + (uint64_t)tv_now.tv_sec*1000000L;
- longtime-=ticks_start;
-
+ gettimeofday(&tv_now, NULL);
+
+ uint64_t longtime = (uint64_t)tv_now.tv_usec + (uint64_t)tv_now.tv_sec * 1000000L;
+ longtime -= ticks_start;
+
return longtime;
}
-Error OS_Unix::execute(const String& p_path, const List<String>& p_arguments,bool p_blocking,ProcessID *r_child_id,String* r_pipe,int *r_exitcode) {
-
+Error OS_Unix::execute(const String &p_path, const List<String> &p_arguments, bool p_blocking, ProcessID *r_child_id, String *r_pipe, int *r_exitcode) {
if (p_blocking && r_pipe) {
-
String argss;
- argss="\""+p_path+"\"";
+ argss = "\"" + p_path + "\"";
- for(int i=0;i<p_arguments.size();i++) {
+ for (int i = 0; i < p_arguments.size(); i++) {
- argss+=String(" \"")+p_arguments[i]+"\"";
+ argss += String(" \"") + p_arguments[i] + "\"";
}
- argss+=" 2>/dev/null"; //silence stderr
- FILE* f=popen(argss.utf8().get_data(),"r");
+ argss += " 2>/dev/null"; //silence stderr
+ FILE *f = popen(argss.utf8().get_data(), "r");
- ERR_FAIL_COND_V(!f,ERR_CANT_OPEN);
+ ERR_FAIL_COND_V(!f, ERR_CANT_OPEN);
char buf[65535];
- while(fgets(buf,65535,f)) {
+ while (fgets(buf, 65535, f)) {
- (*r_pipe)+=buf;
+ (*r_pipe) += buf;
}
int rv = pclose(f);
if (r_exitcode)
- *r_exitcode=rv;
+ *r_exitcode = rv;
return OK;
}
-
pid_t pid = fork();
- ERR_FAIL_COND_V(pid<0,ERR_CANT_FORK);
-
+ ERR_FAIL_COND_V(pid < 0, ERR_CANT_FORK);
- if (pid==0) {
+ if (pid == 0) {
// is child
Vector<CharString> cs;
cs.push_back(p_path.utf8());
- for(int i=0;i<p_arguments.size();i++)
+ for (int i = 0; i < p_arguments.size(); i++)
cs.push_back(p_arguments[i].utf8());
- Vector<char*> args;
- for(int i=0;i<cs.size();i++)
- args.push_back((char*)cs[i].get_data());// shitty C cast
+ Vector<char *> args;
+ for (int i = 0; i < cs.size(); i++)
+ args.push_back((char *)cs[i].get_data()); // shitty C cast
args.push_back(0);
#ifdef __FreeBSD__
- if(p_path.find("/")) {
+ if (p_path.find("/")) {
// exec name contains path so use it
- execv(p_path.utf8().get_data(),&args[0]);
- }else{
+ execv(p_path.utf8().get_data(), &args[0]);
+ } else {
// use program name and search through PATH to find it
- execvp(getprogname(),&args[0]);
+ execvp(getprogname(), &args[0]);
}
#else
- execv(p_path.utf8().get_data(),&args[0]);
+ execv(p_path.utf8().get_data(), &args[0]);
#endif
// still alive? something failed..
- fprintf(stderr,"**ERROR** OS_Unix::execute - Could not create child process while executing: %s\n",p_path.utf8().get_data());
+ fprintf(stderr, "**ERROR** OS_Unix::execute - Could not create child process while executing: %s\n", p_path.utf8().get_data());
abort();
}
if (p_blocking) {
int status;
- waitpid(pid,&status,0);
+ waitpid(pid, &status, 0);
if (r_exitcode)
- *r_exitcode=WEXITSTATUS(status);
+ *r_exitcode = WEXITSTATUS(status);
} else {
if (r_child_id)
- *r_child_id=pid;
+ *r_child_id = pid;
}
return OK;
-
}
-Error OS_Unix::kill(const ProcessID& p_pid) {
+Error OS_Unix::kill(const ProcessID &p_pid) {
- int ret = ::kill(p_pid,SIGKILL);
+ int ret = ::kill(p_pid, SIGKILL);
if (!ret) {
//avoid zombie process
int st;
- ::waitpid(p_pid,&st,0);
-
+ ::waitpid(p_pid, &st, 0);
}
- return ret?ERR_INVALID_PARAMETER:OK;
+ return ret ? ERR_INVALID_PARAMETER : OK;
}
int OS_Unix::get_process_ID() const {
@@ -433,10 +418,9 @@ int OS_Unix::get_process_ID() const {
return getpid();
};
+bool OS_Unix::has_environment(const String &p_var) 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()) != NULL;
}
String OS_Unix::get_locale() const {
@@ -446,21 +430,20 @@ String OS_Unix::get_locale() const {
String locale = get_environment("LANG");
int tp = locale.find(".");
- if (tp!=-1)
- locale=locale.substr(0,tp);
+ if (tp != -1)
+ locale = locale.substr(0, tp);
return locale;
}
-Error OS_Unix::set_cwd(const String& p_cwd) {
+Error OS_Unix::set_cwd(const String &p_cwd) {
- if (chdir(p_cwd.utf8().get_data())!=0)
+ if (chdir(p_cwd.utf8().get_data()) != 0)
return ERR_CANT_OPEN;
return OK;
}
-
-String OS_Unix::get_environment(const String& p_var) const {
+String OS_Unix::get_environment(const String &p_var) const {
if (getenv(p_var.utf8().get_data()))
return getenv(p_var.utf8().get_data());
@@ -475,35 +458,30 @@ int OS_Unix::get_processor_count() const {
String OS_Unix::get_data_dir() const {
String an = get_safe_application_name();
- if (an!="") {
-
-
+ if (an != "") {
if (has_environment("HOME")) {
bool use_godot = GlobalConfig::get_singleton()->get("application/use_shared_user_dir");
if (use_godot)
- return get_environment("HOME")+"/.godot/app_userdata/"+an;
+ return get_environment("HOME") + "/.godot/app_userdata/" + an;
else
- return get_environment("HOME")+"/."+an;
+ return get_environment("HOME") + "/." + an;
}
}
return GlobalConfig::get_singleton()->get_resource_path();
-
}
-bool OS_Unix::check_feature_support(const String& p_feature) {
+bool OS_Unix::check_feature_support(const String &p_feature) {
return VisualServer::get_singleton()->has_os_feature(p_feature);
-
}
-
String OS_Unix::get_installed_templates_path() const {
- String p=get_global_settings_path();
- if (p!="")
- return p+"/templates/";
+ String p = get_global_settings_path();
+ if (p != "")
+ return p + "/templates/";
else
return "";
}
@@ -513,11 +491,11 @@ String OS_Unix::get_executable_path() const {
#ifdef __linux__
//fix for running from a symlink
char buf[256];
- memset(buf,0,256);
+ memset(buf, 0, 256);
readlink("/proc/self/exe", buf, sizeof(buf));
String b;
b.parse_utf8(buf);
- if (b=="") {
+ if (b == "") {
WARN_PRINT("Couldn't get executable path from /proc/self/exe, using argv[0]");
return OS::get_executable_path();
}
@@ -530,10 +508,10 @@ String OS_Unix::get_executable_path() const {
return String(resolved_path);
#elif defined(__APPLE__)
char temp_path[1];
- uint32_t buff_size=1;
+ uint32_t buff_size = 1;
_NSGetExecutablePath(temp_path, &buff_size);
- char* resolved_path = new char[buff_size + 1];
+ char *resolved_path = new char[buff_size + 1];
if (_NSGetExecutablePath(resolved_path, &buff_size) == 1)
WARN_PRINT("MAXPATHLEN is too small");
@@ -548,5 +526,4 @@ String OS_Unix::get_executable_path() const {
#endif
}
-
#endif
diff --git a/drivers/unix/os_unix.h b/drivers/unix/os_unix.h
index 220f818ff6..3ac4f46109 100644
--- a/drivers/unix/os_unix.h
+++ b/drivers/unix/os_unix.h
@@ -35,61 +35,57 @@
#ifdef UNIX_ENABLED
-
-#include "os/os.h"
#include "drivers/unix/ip_unix.h"
-
+#include "os/os.h"
class OS_Unix : public OS {
uint64_t ticks_start;
-protected:
+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 const char * get_video_driver_name(int p_driver) const;
//virtual VideoMode get_default_video_mode() const;
-
+
virtual int get_audio_driver_count() const;
- virtual const char * get_audio_driver_name(int p_driver) 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 void initialize(int p_video_driver,int p_audio_driver);
-
+
//virtual void finalize();
virtual void finalize_core();
-
+
String stdin_buf;
String get_global_settings_path() const;
public:
+ virtual void print_error(const char *p_function, const char *p_file, int p_line, const char *p_code, const char *p_rationale, ErrorType p_type = ERR_ERROR);
-
- virtual void print_error(const char* p_function,const char* p_file,int p_line,const char *p_code,const char*p_rationale,ErrorType p_type=ERR_ERROR);
-
- virtual void print(const char *p_format, ... );
- virtual void vprint(const char* p_format, va_list p_list,bool p_stderr=false);
- virtual void alert(const String& p_alert,const String& p_title="ALERT!");
+ virtual void print(const char *p_format, ...);
+ virtual void vprint(const char *p_format, va_list p_list, bool p_stderr = false);
+ virtual void alert(const String &p_alert, const String &p_title = "ALERT!");
virtual String get_stdin_string(bool p_block);
//virtual void set_mouse_show(bool p_show);
//virtual void set_mouse_grab(bool p_grab);
//virtual bool is_mouse_grab_enabled() const = 0;
- //virtual void get_mouse_pos(int &x, int &y) const;
+ //virtual void get_mouse_pos(int &x, int &y) const;
//virtual void set_window_title(const String& p_title);
-
+
//virtual void set_video_mode(const VideoMode& p_video_mode);
//virtual VideoMode get_video_mode() const;
//virtual void get_fullscreen_mode_list(List<VideoMode> *p_list) const;
- virtual Error set_cwd(const String& p_cwd);
+ virtual Error set_cwd(const String &p_cwd);
virtual String get_name();
-
+
virtual Date get_date(bool utc) const;
virtual Time get_time(bool utc) const;
virtual TimeZoneInfo get_time_zone_info() const;
@@ -97,31 +93,28 @@ public:
virtual uint64_t get_unix_time() const;
virtual uint64_t get_system_time_secs() const;
- virtual void delay_usec(uint32_t p_usec) const;
+ 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,ProcessID *r_child_id=NULL,String* r_pipe=NULL,int *r_exitcode=NULL);
- virtual Error kill(const ProcessID& p_pid);
+ virtual Error execute(const String &p_path, const List<String> &p_arguments, bool p_blocking, ProcessID *r_child_id = NULL, String *r_pipe = NULL, int *r_exitcode = NULL);
+ virtual Error kill(const ProcessID &p_pid);
virtual int get_process_ID() const;
- virtual bool has_environment(const String& p_var) const;
- virtual String get_environment(const String& p_var) const;
+ virtual bool has_environment(const String &p_var) const;
+ virtual String get_environment(const String &p_var) const;
virtual String get_locale() const;
virtual int get_processor_count() const;
-
virtual void debug_break();
virtual String get_installed_templates_path() const;
virtual String get_executable_path() const;
virtual String get_data_dir() const;
- virtual bool check_feature_support(const String& p_feature);
+ virtual bool check_feature_support(const String &p_feature);
//virtual void run( MainLoop * p_main_loop );
-
-
};
#endif
diff --git a/drivers/unix/packet_peer_udp_posix.cpp b/drivers/unix/packet_peer_udp_posix.cpp
index 7696a5fcb5..98883f3267 100644
--- a/drivers/unix/packet_peer_udp_posix.cpp
+++ b/drivers/unix/packet_peer_udp_posix.cpp
@@ -30,22 +30,21 @@
#ifdef UNIX_ENABLED
-
#include <errno.h>
-#include <unistd.h>
#include <netdb.h>
-#include <sys/types.h>
#include <sys/socket.h>
+#include <sys/types.h>
+#include <unistd.h>
#include <netinet/in.h>
#include <stdio.h>
#ifndef NO_FCNTL
- #ifdef __HAIKU__
- #include <fcntl.h>
- #else
- #include <sys/fcntl.h>
- #endif
+#ifdef __HAIKU__
+#include <fcntl.h>
+#else
+#include <sys/fcntl.h>
+#endif
#else
#include <sys/ioctl.h>
#endif
@@ -58,19 +57,19 @@
int PacketPeerUDPPosix::get_available_packet_count() const {
- Error err = const_cast<PacketPeerUDPPosix*>(this)->_poll(false);
- if (err!=OK)
+ Error err = const_cast<PacketPeerUDPPosix *>(this)->_poll(false);
+ if (err != OK)
return 0;
return queue_count;
}
-Error PacketPeerUDPPosix::get_packet(const uint8_t **r_buffer,int &r_buffer_size) const{
+Error PacketPeerUDPPosix::get_packet(const uint8_t **r_buffer, int &r_buffer_size) const {
- Error err = const_cast<PacketPeerUDPPosix*>(this)->_poll(false);
- if (err!=OK)
+ Error err = const_cast<PacketPeerUDPPosix *>(this)->_poll(false);
+ if (err != OK)
return err;
- if (queue_count==0)
+ if (queue_count == 0)
return ERR_UNAVAILABLE;
uint32_t size;
@@ -78,38 +77,37 @@ Error PacketPeerUDPPosix::get_packet(const uint8_t **r_buffer,int &r_buffer_size
rb.read(&type, 1, true);
if (type == IP::TYPE_IPV4) {
uint8_t ip[4];
- rb.read(ip,4,true);
+ rb.read(ip, 4, true);
packet_ip.set_ipv4(ip);
} else {
uint8_t ipv6[16];
- rb.read(ipv6,16,true);
+ rb.read(ipv6, 16, true);
packet_ip.set_ipv6(ipv6);
};
- rb.read((uint8_t*)&packet_port,4,true);
- rb.read((uint8_t*)&size,4,true);
- rb.read(packet_buffer,size,true);
+ rb.read((uint8_t *)&packet_port, 4, true);
+ rb.read((uint8_t *)&size, 4, true);
+ rb.read(packet_buffer, size, true);
--queue_count;
- *r_buffer=packet_buffer;
- r_buffer_size=size;
+ *r_buffer = packet_buffer;
+ r_buffer_size = size;
return OK;
-
}
-Error PacketPeerUDPPosix::put_packet(const uint8_t *p_buffer,int p_buffer_size){
+Error PacketPeerUDPPosix::put_packet(const uint8_t *p_buffer, int p_buffer_size) {
ERR_FAIL_COND_V(!peer_addr.is_valid(), ERR_UNCONFIGURED);
- if (sock_type==IP::TYPE_NONE)
+ if (sock_type == IP::TYPE_NONE)
sock_type = peer_addr.is_ipv4() ? IP::TYPE_IPV4 : IP::TYPE_IPV6;
int sock = _get_socket();
- ERR_FAIL_COND_V( sock == -1, FAILED );
+ ERR_FAIL_COND_V(sock == -1, FAILED);
struct sockaddr_storage addr;
size_t addr_size = _set_sockaddr(&addr, peer_addr, peer_port, sock_type);
errno = 0;
int err;
- while ( (err = sendto(sock, p_buffer, p_buffer_size, 0, (struct sockaddr*)&addr, addr_size)) != p_buffer_size) {
+ while ((err = sendto(sock, p_buffer, p_buffer_size, 0, (struct sockaddr *)&addr, addr_size)) != p_buffer_size) {
if (errno != EAGAIN) {
return FAILED;
@@ -119,15 +117,15 @@ Error PacketPeerUDPPosix::put_packet(const uint8_t *p_buffer,int p_buffer_size){
return OK;
}
-int PacketPeerUDPPosix::get_max_packet_size() const{
+int PacketPeerUDPPosix::get_max_packet_size() const {
return 512; // uhm maybe not
}
Error PacketPeerUDPPosix::listen(int p_port, IP_Address p_bind_address, int p_recv_buffer_size) {
- ERR_FAIL_COND_V(sockfd!=-1,ERR_ALREADY_IN_USE);
- ERR_FAIL_COND_V(!p_bind_address.is_valid() && !p_bind_address.is_wildcard(),ERR_INVALID_PARAMETER);
+ ERR_FAIL_COND_V(sockfd != -1, ERR_ALREADY_IN_USE);
+ ERR_FAIL_COND_V(!p_bind_address.is_valid() && !p_bind_address.is_wildcard(), ERR_INVALID_PARAMETER);
#ifdef __OpenBSD__
sock_type = IP::TYPE_IPV4; // OpenBSD does not support dual stacking, fallback to IPv4 only.
@@ -135,18 +133,18 @@ Error PacketPeerUDPPosix::listen(int p_port, IP_Address p_bind_address, int p_re
sock_type = IP::TYPE_ANY;
#endif
- if(p_bind_address.is_valid())
+ if (p_bind_address.is_valid())
sock_type = p_bind_address.is_ipv4() ? IP::TYPE_IPV4 : IP::TYPE_IPV6;
int sock = _get_socket();
- if (sock == -1 )
+ if (sock == -1)
return ERR_CANT_CREATE;
- sockaddr_storage addr = {0};
+ sockaddr_storage addr = { 0 };
size_t addr_size = _set_listen_sockaddr(&addr, p_port, sock_type, IP_Address());
- if (bind(sock, (struct sockaddr*)&addr, addr_size) == -1 ) {
+ if (bind(sock, (struct sockaddr *)&addr, addr_size) == -1) {
close();
return ERR_UNAVAILABLE;
}
@@ -154,17 +152,16 @@ Error PacketPeerUDPPosix::listen(int p_port, IP_Address p_bind_address, int p_re
return OK;
}
-void PacketPeerUDPPosix::close(){
+void PacketPeerUDPPosix::close() {
if (sockfd != -1)
::close(sockfd);
- sockfd=-1;
+ sockfd = -1;
sock_type = IP::TYPE_NONE;
rb.resize(16);
- queue_count=0;
+ queue_count = 0;
}
-
Error PacketPeerUDPPosix::wait() {
return _poll(true);
@@ -172,22 +169,22 @@ Error PacketPeerUDPPosix::wait() {
Error PacketPeerUDPPosix::_poll(bool p_wait) {
- if (sockfd==-1) {
+ if (sockfd == -1) {
return FAILED;
}
- struct sockaddr_storage from = {0};
+ struct sockaddr_storage from = { 0 };
socklen_t len = sizeof(struct sockaddr_storage);
int ret;
- while ( (ret = recvfrom(sockfd, recv_buffer, MIN((int)sizeof(recv_buffer),MAX(rb.space_left()-24, 0)), p_wait?0:MSG_DONTWAIT, (struct sockaddr*)&from, &len)) > 0) {
+ while ((ret = recvfrom(sockfd, recv_buffer, MIN((int)sizeof(recv_buffer), MAX(rb.space_left() - 24, 0)), p_wait ? 0 : MSG_DONTWAIT, (struct sockaddr *)&from, &len)) > 0) {
uint32_t port = 0;
if (from.ss_family == AF_INET) {
uint8_t type = (uint8_t)IP::TYPE_IPV4;
rb.write(&type, 1);
- struct sockaddr_in* sin_from = (struct sockaddr_in*)&from;
- rb.write((uint8_t*)&sin_from->sin_addr, 4);
+ struct sockaddr_in *sin_from = (struct sockaddr_in *)&from;
+ rb.write((uint8_t *)&sin_from->sin_addr, 4);
port = ntohs(sin_from->sin_port);
} else if (from.ss_family == AF_INET6) {
@@ -195,8 +192,8 @@ Error PacketPeerUDPPosix::_poll(bool p_wait) {
uint8_t type = (uint8_t)IP::TYPE_IPV6;
rb.write(&type, 1);
- struct sockaddr_in6* s6_from = (struct sockaddr_in6*)&from;
- rb.write((uint8_t*)&s6_from->sin6_addr, 16);
+ struct sockaddr_in6 *s6_from = (struct sockaddr_in6 *)&from;
+ rb.write((uint8_t *)&s6_from->sin6_addr, 16);
port = ntohs(s6_from->sin6_port);
@@ -206,26 +203,25 @@ Error PacketPeerUDPPosix::_poll(bool p_wait) {
rb.write(&type, 1);
};
- rb.write((uint8_t*)&port, 4);
- rb.write((uint8_t*)&ret, 4);
+ rb.write((uint8_t *)&port, 4);
+ rb.write((uint8_t *)&ret, 4);
rb.write(recv_buffer, ret);
len = sizeof(struct sockaddr_storage);
++queue_count;
};
-
// TODO: Should ECONNRESET be handled here?
- if (ret == 0 || (ret == -1 && errno != EAGAIN) ) {
+ if (ret == 0 || (ret == -1 && errno != EAGAIN)) {
close();
return FAILED;
};
return OK;
}
-bool PacketPeerUDPPosix::is_listening() const{
+bool PacketPeerUDPPosix::is_listening() const {
- return sockfd!=-1;
+ return sockfd != -1;
}
IP_Address PacketPeerUDPPosix::get_packet_address() const {
@@ -233,14 +229,14 @@ IP_Address PacketPeerUDPPosix::get_packet_address() const {
return packet_ip;
}
-int PacketPeerUDPPosix::get_packet_port() const{
+int PacketPeerUDPPosix::get_packet_port() const {
return packet_port;
}
int PacketPeerUDPPosix::_get_socket() {
- ERR_FAIL_COND_V(sock_type==IP::TYPE_NONE, -1);
+ ERR_FAIL_COND_V(sock_type == IP::TYPE_NONE, -1);
if (sockfd != -1)
return sockfd;
@@ -250,14 +246,13 @@ int PacketPeerUDPPosix::_get_socket() {
return sockfd;
}
+void PacketPeerUDPPosix::set_dest_address(const IP_Address &p_address, int p_port) {
-void PacketPeerUDPPosix::set_dest_address(const IP_Address& p_address,int p_port) {
-
- peer_addr=p_address;
- peer_port=p_port;
+ peer_addr = p_address;
+ peer_port = p_port;
}
-PacketPeerUDP* PacketPeerUDPPosix::_create() {
+PacketPeerUDP *PacketPeerUDPPosix::_create() {
return memnew(PacketPeerUDPPosix);
};
@@ -267,13 +262,12 @@ void PacketPeerUDPPosix::make_default() {
PacketPeerUDP::_create = PacketPeerUDPPosix::_create;
};
-
PacketPeerUDPPosix::PacketPeerUDPPosix() {
- sockfd=-1;
- packet_port=0;
- queue_count=0;
- peer_port=0;
+ sockfd = -1;
+ packet_port = 0;
+ queue_count = 0;
+ peer_port = 0;
sock_type = IP::TYPE_NONE;
rb.resize(16);
}
diff --git a/drivers/unix/packet_peer_udp_posix.h b/drivers/unix/packet_peer_udp_posix.h
index ac68344d78..b44ef49f2c 100644
--- a/drivers/unix/packet_peer_udp_posix.h
+++ b/drivers/unix/packet_peer_udp_posix.h
@@ -36,9 +36,8 @@
class PacketPeerUDPPosix : public PacketPeerUDP {
-
enum {
- PACKET_BUFFER_SIZE=65536
+ PACKET_BUFFER_SIZE = 65536
};
mutable RingBuffer<uint8_t> rb;
@@ -55,18 +54,17 @@ class PacketPeerUDPPosix : public PacketPeerUDP {
_FORCE_INLINE_ int _get_socket();
- static PacketPeerUDP* _create();
+ static PacketPeerUDP *_create();
virtual Error _poll(bool p_block);
public:
-
virtual int get_available_packet_count() const;
- virtual Error get_packet(const uint8_t **r_buffer,int &r_buffer_size) const;
- virtual Error put_packet(const uint8_t *p_buffer,int p_buffer_size);
+ virtual Error get_packet(const uint8_t **r_buffer, int &r_buffer_size) const;
+ virtual Error put_packet(const uint8_t *p_buffer, int p_buffer_size);
virtual int get_max_packet_size() const;
- virtual Error listen(int p_port, IP_Address p_bind_address=IP_Address("*"), int p_recv_buffer_size=65536);
+ virtual Error listen(int p_port, IP_Address p_bind_address = IP_Address("*"), int p_recv_buffer_size = 65536);
virtual void close();
virtual Error wait();
virtual bool is_listening() const;
@@ -74,7 +72,7 @@ public:
virtual IP_Address get_packet_address() const;
virtual int get_packet_port() const;
- virtual void set_dest_address(const IP_Address& p_address,int p_port);
+ virtual void set_dest_address(const IP_Address &p_address, int p_port);
static void make_default();
diff --git a/drivers/unix/rw_lock_posix.cpp b/drivers/unix/rw_lock_posix.cpp
index 455dde73b1..9c9ad26165 100644
--- a/drivers/unix/rw_lock_posix.cpp
+++ b/drivers/unix/rw_lock_posix.cpp
@@ -30,17 +30,17 @@
#include "rw_lock_posix.h"
-#include "os/memory.h"
#include "error_macros.h"
+#include "os/memory.h"
#include <stdio.h>
void RWLockPosix::read_lock() {
- int err =pthread_rwlock_rdlock(&rwlock);
- if (err!=0) {
+ int err = pthread_rwlock_rdlock(&rwlock);
+ if (err != 0) {
perror("wtf: ");
}
- ERR_FAIL_COND(err!=0);
+ ERR_FAIL_COND(err != 0);
}
void RWLockPosix::read_unlock() {
@@ -50,18 +50,17 @@ void RWLockPosix::read_unlock() {
Error RWLockPosix::read_try_lock() {
- if (pthread_rwlock_tryrdlock(&rwlock)!=0) {
+ if (pthread_rwlock_tryrdlock(&rwlock) != 0) {
return ERR_BUSY;
} else {
return OK;
}
-
}
void RWLockPosix::write_lock() {
int err = pthread_rwlock_wrlock(&rwlock);
- ERR_FAIL_COND(err!=0);
+ ERR_FAIL_COND(err != 0);
}
void RWLockPosix::write_unlock() {
@@ -70,36 +69,32 @@ void RWLockPosix::write_unlock() {
}
Error RWLockPosix::write_try_lock() {
- if (pthread_rwlock_trywrlock(&rwlock)!=0) {
+ if (pthread_rwlock_trywrlock(&rwlock) != 0) {
return ERR_BUSY;
} else {
return OK;
}
}
-
RWLock *RWLockPosix::create_func_posix() {
- return memnew( RWLockPosix );
+ return memnew(RWLockPosix);
}
void RWLockPosix::make_default() {
- create_func=create_func_posix;
+ create_func = create_func_posix;
}
-
RWLockPosix::RWLockPosix() {
//rwlock=PTHREAD_RWLOCK_INITIALIZER; fails on OSX
- pthread_rwlock_init(&rwlock,NULL);
+ pthread_rwlock_init(&rwlock, NULL);
}
-
RWLockPosix::~RWLockPosix() {
pthread_rwlock_destroy(&rwlock);
-
}
#endif
diff --git a/drivers/unix/rw_lock_posix.h b/drivers/unix/rw_lock_posix.h
index 35a686b15c..429b5c22d7 100644
--- a/drivers/unix/rw_lock_posix.h
+++ b/drivers/unix/rw_lock_posix.h
@@ -31,18 +31,16 @@
#if defined(UNIX_ENABLED) || defined(PTHREAD_ENABLED)
-#include <pthread.h>
#include "os/rw_lock.h"
+#include <pthread.h>
class RWLockPosix : public RWLock {
-
pthread_rwlock_t rwlock;
static RWLock *create_func_posix();
public:
-
virtual void read_lock();
virtual void read_unlock();
virtual Error read_try_lock();
@@ -56,10 +54,8 @@ public:
RWLockPosix();
~RWLockPosix();
-
};
#endif
-
#endif // RWLOCKPOSIX_H
diff --git a/drivers/unix/semaphore_posix.cpp b/drivers/unix/semaphore_posix.cpp
index 83b34a42dd..69f499bb52 100644
--- a/drivers/unix/semaphore_posix.cpp
+++ b/drivers/unix/semaphore_posix.cpp
@@ -36,10 +36,9 @@
Error SemaphorePosix::wait() {
-
- while(sem_wait(&sem)) {
- if (errno==EINTR) {
- errno=0;
+ while (sem_wait(&sem)) {
+ if (errno == EINTR) {
+ errno = 0;
continue;
} else {
perror("sem waiting");
@@ -51,39 +50,36 @@ Error SemaphorePosix::wait() {
Error SemaphorePosix::post() {
- return (sem_post(&sem)==0)?OK:ERR_BUSY;
+ return (sem_post(&sem) == 0) ? OK : ERR_BUSY;
}
int SemaphorePosix::get() const {
int val;
sem_getvalue(&sem, &val);
-
- return val;
-}
+ return val;
+}
Semaphore *SemaphorePosix::create_semaphore_posix() {
- return memnew( SemaphorePosix );
+ return memnew(SemaphorePosix);
}
void SemaphorePosix::make_default() {
- create_func=create_semaphore_posix;
+ create_func = create_semaphore_posix;
}
SemaphorePosix::SemaphorePosix() {
- int r = sem_init(&sem,0,0);
+ int r = sem_init(&sem, 0, 0);
if (r != 0)
perror("sem creating");
}
-
SemaphorePosix::~SemaphorePosix() {
sem_destroy(&sem);
}
-
#endif
diff --git a/drivers/unix/semaphore_posix.h b/drivers/unix/semaphore_posix.h
index 96d1ff5c06..66e10db3c3 100644
--- a/drivers/unix/semaphore_posix.h
+++ b/drivers/unix/semaphore_posix.h
@@ -29,8 +29,6 @@
#ifndef SEMAPHORE_POSIX_H
#define SEMAPHORE_POSIX_H
-
-
#include "os/semaphore.h"
#if defined(UNIX_ENABLED) || defined(PTHREAD_ENABLED)
@@ -46,16 +44,14 @@ class SemaphorePosix : public Semaphore {
static Semaphore *create_semaphore_posix();
public:
-
virtual Error wait();
- virtual Error post();
+ virtual Error post();
virtual int get() const;
static void make_default();
SemaphorePosix();
-
- ~SemaphorePosix();
+ ~SemaphorePosix();
};
#endif
diff --git a/drivers/unix/socket_helpers.h b/drivers/unix/socket_helpers.h
index fd5fa618ca..d27328a01e 100644
--- a/drivers/unix/socket_helpers.h
+++ b/drivers/unix/socket_helpers.h
@@ -31,28 +31,28 @@
#include <string.h>
-#if defined(__MINGW32__ ) && (!defined(__MINGW64_VERSION_MAJOR) || __MINGW64_VERSION_MAJOR < 4)
- // Workaround for mingw-w64 < 4.0
- #ifndef IPV6_V6ONLY
- #define IPV6_V6ONLY 27
- #endif
+#if defined(__MINGW32__) && (!defined(__MINGW64_VERSION_MAJOR) || __MINGW64_VERSION_MAJOR < 4)
+// Workaround for mingw-w64 < 4.0
+#ifndef IPV6_V6ONLY
+#define IPV6_V6ONLY 27
+#endif
#endif
// helpers for sockaddr -> IP_Address and back, should work for posix and winsock. All implementations should use this
-static size_t _set_sockaddr(struct sockaddr_storage* p_addr, const IP_Address& p_ip, int p_port, IP::Type p_sock_type = IP::TYPE_ANY) {
+static size_t _set_sockaddr(struct sockaddr_storage *p_addr, const IP_Address &p_ip, int p_port, IP::Type p_sock_type = IP::TYPE_ANY) {
memset(p_addr, 0, sizeof(struct sockaddr_storage));
- ERR_FAIL_COND_V(!p_ip.is_valid(),0);
+ ERR_FAIL_COND_V(!p_ip.is_valid(), 0);
// IPv6 socket
if (p_sock_type == IP::TYPE_IPV6 || p_sock_type == IP::TYPE_ANY) {
// IPv6 only socket with IPv4 address
- ERR_FAIL_COND_V(p_sock_type == IP::TYPE_IPV6 && p_ip.is_ipv4(),0);
+ ERR_FAIL_COND_V(p_sock_type == IP::TYPE_IPV6 && p_ip.is_ipv4(), 0);
- struct sockaddr_in6* addr6 = (struct sockaddr_in6*)p_addr;
+ struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)p_addr;
addr6->sin6_family = AF_INET6;
addr6->sin6_port = htons(p_port);
copymem(&addr6->sin6_addr.s6_addr, p_ip.get_ipv6(), 16);
@@ -61,36 +61,36 @@ static size_t _set_sockaddr(struct sockaddr_storage* p_addr, const IP_Address& p
} else { // IPv4 socket
// IPv4 socket with IPv6 address
- ERR_FAIL_COND_V(!p_ip.is_ipv4(),0);
+ ERR_FAIL_COND_V(!p_ip.is_ipv4(), 0);
uint32_t ipv4 = *((uint32_t *)p_ip.get_ipv4());
- struct sockaddr_in* addr4 = (struct sockaddr_in*)p_addr;
+ struct sockaddr_in *addr4 = (struct sockaddr_in *)p_addr;
addr4->sin_family = AF_INET;
- addr4->sin_port = htons(p_port); // short, network byte order
+ addr4->sin_port = htons(p_port); // short, network byte order
copymem(&addr4->sin_addr.s_addr, p_ip.get_ipv4(), 16);
return sizeof(sockaddr_in);
};
};
-static size_t _set_listen_sockaddr(struct sockaddr_storage* p_addr, int p_port, IP::Type p_sock_type, const IP_Address p_bind_address) {
+static size_t _set_listen_sockaddr(struct sockaddr_storage *p_addr, int p_port, IP::Type p_sock_type, const IP_Address p_bind_address) {
memset(p_addr, 0, sizeof(struct sockaddr_storage));
if (p_sock_type == IP::TYPE_IPV4) {
- struct sockaddr_in* addr4 = (struct sockaddr_in*)p_addr;
+ struct sockaddr_in *addr4 = (struct sockaddr_in *)p_addr;
addr4->sin_family = AF_INET;
addr4->sin_port = htons(p_port);
- if(p_bind_address.is_valid()) {
+ if (p_bind_address.is_valid()) {
copymem(&addr4->sin_addr.s_addr, p_bind_address.get_ipv4(), 4);
} else {
addr4->sin_addr.s_addr = INADDR_ANY;
}
return sizeof(sockaddr_in);
} else {
- struct sockaddr_in6* addr6 = (struct sockaddr_in6*)p_addr;
+ struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)p_addr;
addr6->sin6_family = AF_INET6;
addr6->sin6_port = htons(p_port);
- if(p_bind_address.is_valid()) {
+ if (p_bind_address.is_valid()) {
copymem(&addr6->sin6_addr.s6_addr, p_bind_address.get_ipv6(), 16);
} else {
addr6->sin6_addr = in6addr_any;
@@ -106,12 +106,12 @@ static int _socket_create(IP::Type p_type, int type, int protocol) {
int family = p_type == IP::TYPE_IPV4 ? AF_INET : AF_INET6;
int sockfd = socket(family, type, protocol);
- ERR_FAIL_COND_V( sockfd == -1, -1 );
+ ERR_FAIL_COND_V(sockfd == -1, -1);
- if(family == AF_INET6) {
+ if (family == AF_INET6) {
// Select IPv4 over IPv6 mapping
int opt = p_type != IP::TYPE_ANY;
- if(setsockopt(sockfd, IPPROTO_IPV6, IPV6_V6ONLY, (const char*)&opt, sizeof(opt)) != 0) {
+ if (setsockopt(sockfd, IPPROTO_IPV6, IPV6_V6ONLY, (const char *)&opt, sizeof(opt)) != 0) {
WARN_PRINT("Unable to set/unset IPv4 address mapping over IPv6");
}
}
@@ -119,24 +119,22 @@ static int _socket_create(IP::Type p_type, int type, int protocol) {
return sockfd;
}
-
-static void _set_ip_addr_port(IP_Address& r_ip, int& r_port, struct sockaddr_storage* p_addr) {
+static void _set_ip_addr_port(IP_Address &r_ip, int &r_port, struct sockaddr_storage *p_addr) {
if (p_addr->ss_family == AF_INET) {
- struct sockaddr_in* addr4 = (struct sockaddr_in*)p_addr;
+ struct sockaddr_in *addr4 = (struct sockaddr_in *)p_addr;
r_ip.set_ipv4((uint8_t *)&(addr4->sin_addr.s_addr));
r_port = ntohs(addr4->sin_port);
} else if (p_addr->ss_family == AF_INET6) {
- struct sockaddr_in6* addr6 = (struct sockaddr_in6*)p_addr;
+ struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)p_addr;
r_ip.set_ipv6(addr6->sin6_addr.s6_addr);
r_port = ntohs(addr6->sin6_port);
};
};
-
#endif
diff --git a/drivers/unix/stream_peer_tcp_posix.cpp b/drivers/unix/stream_peer_tcp_posix.cpp
index 08a2954617..fc4838f1e0 100644
--- a/drivers/unix/stream_peer_tcp_posix.cpp
+++ b/drivers/unix/stream_peer_tcp_posix.cpp
@@ -30,21 +30,21 @@
#include "stream_peer_tcp_posix.h"
+#include <errno.h>
+#include <netdb.h>
#include <poll.h>
#include <stdio.h>
#include <stdlib.h>
-#include <unistd.h>
-#include <errno.h>
#include <string.h>
-#include <netdb.h>
-#include <sys/types.h>
#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <unistd.h>
#ifndef NO_FCNTL
- #ifdef __HAIKU__
- #include <fcntl.h>
- #else
- #include <sys/fcntl.h>
- #endif
+#ifdef __HAIKU__
+#include <fcntl.h>
+#else
+#include <sys/fcntl.h>
+#endif
#else
#include <sys/ioctl.h>
#endif
@@ -58,12 +58,12 @@
#include <netinet/tcp.h>
#if defined(OSX_ENABLED) || defined(IPHONE_ENABLED)
- #define MSG_NOSIGNAL SO_NOSIGPIPE
+#define MSG_NOSIGNAL SO_NOSIGPIPE
#endif
#include "drivers/unix/socket_helpers.h"
-StreamPeerTCP* StreamPeerTCPPosix::_create() {
+StreamPeerTCP *StreamPeerTCPPosix::_create() {
return memnew(StreamPeerTCPPosix);
};
@@ -95,7 +95,7 @@ Error StreamPeerTCPPosix::_poll_connection() const {
struct sockaddr_storage their_addr;
size_t addr_size = _set_sockaddr(&their_addr, peer_host, peer_port, sock_type);
- if (::connect(sockfd, (struct sockaddr *)&their_addr,addr_size) == -1) {
+ if (::connect(sockfd, (struct sockaddr *)&their_addr, addr_size) == -1) {
if (errno == EISCONN) {
status = STATUS_CONNECTED;
@@ -134,9 +134,9 @@ void StreamPeerTCPPosix::set_socket(int p_sockfd, IP_Address p_host, int p_port,
peer_port = p_port;
};
-Error StreamPeerTCPPosix::connect_to_host(const IP_Address& p_host, uint16_t p_port) {
+Error StreamPeerTCPPosix::connect_to_host(const IP_Address &p_host, uint16_t p_port) {
- ERR_FAIL_COND_V( !p_host.is_valid(), ERR_INVALID_PARAMETER);
+ ERR_FAIL_COND_V(!p_host.is_valid(), ERR_INVALID_PARAMETER);
sock_type = p_host.is_ipv4() ? IP::TYPE_IPV4 : IP::TYPE_IPV6;
sockfd = _socket_create(sock_type, SOCK_STREAM, IPPROTO_TCP);
@@ -158,7 +158,7 @@ Error StreamPeerTCPPosix::connect_to_host(const IP_Address& p_host, uint16_t p_p
size_t addr_size = _set_sockaddr(&their_addr, p_host, p_port, sock_type);
errno = 0;
- if (::connect(sockfd, (struct sockaddr *)&their_addr,addr_size) == -1 && errno != EINPROGRESS) {
+ if (::connect(sockfd, (struct sockaddr *)&their_addr, addr_size) == -1 && errno != EINPROGRESS) {
ERR_PRINT("Connection to remote host failed!");
disconnect_from_host();
@@ -177,7 +177,7 @@ Error StreamPeerTCPPosix::connect_to_host(const IP_Address& p_host, uint16_t p_p
return OK;
};
-Error StreamPeerTCPPosix::write(const uint8_t* p_data,int p_bytes, int &r_sent, bool p_block) {
+Error StreamPeerTCPPosix::write(const uint8_t *p_data, int p_bytes, int &r_sent, bool p_block) {
if (status == STATUS_NONE || status == STATUS_ERROR) {
@@ -237,7 +237,7 @@ Error StreamPeerTCPPosix::write(const uint8_t* p_data,int p_bytes, int &r_sent,
return OK;
};
-Error StreamPeerTCPPosix::read(uint8_t* p_buffer, int p_bytes,int &r_received, bool p_block) {
+Error StreamPeerTCPPosix::read(uint8_t *p_buffer, int p_bytes, int &r_received, bool p_block) {
if (!is_connected_to_host()) {
@@ -282,9 +282,9 @@ Error StreamPeerTCPPosix::read(uint8_t* p_buffer, int p_bytes,int &r_received, b
};
_block(sockfd, true, false);
- } else if (read==0) {
+ } else if (read == 0) {
- sockfd=-1;
+ sockfd = -1;
status = STATUS_NONE;
peer_port = 0;
peer_host = IP_Address();
@@ -305,8 +305,8 @@ Error StreamPeerTCPPosix::read(uint8_t* p_buffer, int p_bytes,int &r_received, b
void StreamPeerTCPPosix::set_nodelay(bool p_enabled) {
ERR_FAIL_COND(!is_connected_to_host());
- int flag=p_enabled?1:0;
- setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, (char*)&flag, sizeof(int));
+ int flag = p_enabled ? 1 : 0;
+ setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, (char *)&flag, sizeof(int));
}
bool StreamPeerTCPPosix::is_connected_to_host() const {
@@ -319,7 +319,7 @@ bool StreamPeerTCPPosix::is_connected_to_host() const {
return true;
};
- return (sockfd!=-1);
+ return (sockfd != -1);
};
StreamPeerTCP::Status StreamPeerTCPPosix::get_status() const {
@@ -331,39 +331,37 @@ StreamPeerTCP::Status StreamPeerTCPPosix::get_status() const {
return status;
};
-
void StreamPeerTCPPosix::disconnect_from_host() {
if (sockfd != -1)
close(sockfd);
sock_type = IP::TYPE_NONE;
- sockfd=-1;
+ sockfd = -1;
status = STATUS_NONE;
peer_port = 0;
peer_host = IP_Address();
};
-
-Error StreamPeerTCPPosix::put_data(const uint8_t* p_data,int p_bytes) {
+Error StreamPeerTCPPosix::put_data(const uint8_t *p_data, int p_bytes) {
int total;
return write(p_data, p_bytes, total, true);
};
-Error StreamPeerTCPPosix::put_partial_data(const uint8_t* p_data,int p_bytes, int &r_sent) {
+Error StreamPeerTCPPosix::put_partial_data(const uint8_t *p_data, int p_bytes, int &r_sent) {
return write(p_data, p_bytes, r_sent, false);
};
-Error StreamPeerTCPPosix::get_data(uint8_t* p_buffer, int p_bytes) {
+Error StreamPeerTCPPosix::get_data(uint8_t *p_buffer, int p_bytes) {
int total;
return read(p_buffer, p_bytes, total, true);
};
-Error StreamPeerTCPPosix::get_partial_data(uint8_t* p_buffer, int p_bytes,int &r_received) {
+Error StreamPeerTCPPosix::get_partial_data(uint8_t *p_buffer, int p_bytes, int &r_received) {
return read(p_buffer, p_bytes, r_received, false);
};
@@ -371,10 +369,9 @@ Error StreamPeerTCPPosix::get_partial_data(uint8_t* p_buffer, int p_bytes,int &r
int StreamPeerTCPPosix::get_available_bytes() const {
unsigned long len;
- int ret = ioctl(sockfd,FIONREAD,&len);
- ERR_FAIL_COND_V(ret==-1,0)
+ int ret = ioctl(sockfd, FIONREAD, &len);
+ ERR_FAIL_COND_V(ret == -1, 0)
return len;
-
}
IP_Address StreamPeerTCPPosix::get_connected_host() const {
diff --git a/drivers/unix/stream_peer_tcp_posix.h b/drivers/unix/stream_peer_tcp_posix.h
index 7f8d90a448..ef98f2ab83 100644
--- a/drivers/unix/stream_peer_tcp_posix.h
+++ b/drivers/unix/stream_peer_tcp_posix.h
@@ -38,7 +38,6 @@
class StreamPeerTCPPosix : public StreamPeerTCP {
protected:
-
mutable Status status;
IP::Type sock_type;
@@ -51,20 +50,19 @@ protected:
IP_Address peer_host;
int peer_port;
- Error write(const uint8_t* p_data,int p_bytes, int &r_sent, bool p_block);
- Error read(uint8_t* p_buffer, int p_bytes,int &r_received, bool p_block);
+ Error write(const uint8_t *p_data, int p_bytes, int &r_sent, bool p_block);
+ Error read(uint8_t *p_buffer, int p_bytes, int &r_received, bool p_block);
- static StreamPeerTCP* _create();
+ static StreamPeerTCP *_create();
public:
+ virtual Error connect_to_host(const IP_Address &p_host, uint16_t p_port);
- virtual Error connect_to_host(const IP_Address& p_host, uint16_t p_port);
-
- virtual Error put_data(const uint8_t* p_data,int p_bytes);
- virtual Error put_partial_data(const uint8_t* p_data,int p_bytes, int &r_sent);
+ virtual Error put_data(const uint8_t *p_data, int p_bytes);
+ virtual Error put_partial_data(const uint8_t *p_data, int p_bytes, int &r_sent);
- virtual Error get_data(uint8_t* p_buffer, int p_bytes);
- virtual Error get_partial_data(uint8_t* p_buffer, int p_bytes,int &r_received);
+ virtual Error get_data(uint8_t *p_buffer, int p_bytes);
+ virtual Error get_partial_data(uint8_t *p_buffer, int p_bytes, int &r_received);
virtual int get_available_bytes() const;
diff --git a/drivers/unix/tcp_server_posix.cpp b/drivers/unix/tcp_server_posix.cpp
index 7e9970453f..9049faebb8 100644
--- a/drivers/unix/tcp_server_posix.cpp
+++ b/drivers/unix/tcp_server_posix.cpp
@@ -33,32 +33,32 @@
#include <poll.h>
+#include <errno.h>
+#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
-#include <unistd.h>
-#include <errno.h>
#include <string.h>
-#include <netdb.h>
#include <sys/types.h>
+#include <unistd.h>
#ifndef NO_FCNTL
- #ifdef __HAIKU__
- #include <fcntl.h>
- #else
- #include <sys/fcntl.h>
- #endif
+#ifdef __HAIKU__
+#include <fcntl.h>
+#else
+#include <sys/fcntl.h>
+#endif
#else
#include <sys/ioctl.h>
#endif
#ifdef JAVASCRIPT_ENABLED
#include <arpa/inet.h>
#endif
+#include <assert.h>
#include <netinet/in.h>
#include <sys/socket.h>
-#include <assert.h>
#include "drivers/unix/socket_helpers.h"
-TCP_Server* TCPServerPosix::_create() {
+TCP_Server *TCPServerPosix::_create() {
return memnew(TCPServerPosix);
};
@@ -68,9 +68,9 @@ void TCPServerPosix::make_default() {
TCP_Server::_create = TCPServerPosix::_create;
};
-Error TCPServerPosix::listen(uint16_t p_port,const IP_Address p_bind_address) {
+Error TCPServerPosix::listen(uint16_t p_port, const IP_Address p_bind_address) {
- ERR_FAIL_COND_V(listen_sockfd!=-1,ERR_ALREADY_IN_USE);
+ ERR_FAIL_COND_V(listen_sockfd != -1, ERR_ALREADY_IN_USE);
ERR_FAIL_COND_V(!p_bind_address.is_valid() && !p_bind_address.is_wildcard(), ERR_INVALID_PARAMETER);
int sockfd;
@@ -95,8 +95,8 @@ Error TCPServerPosix::listen(uint16_t p_port,const IP_Address p_bind_address) {
ioctl(sockfd, FIONBIO, &bval);
#endif
- int reuse=1;
- if(setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, (char *)&reuse, sizeof(reuse)) < 0) {
+ int reuse = 1;
+ if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, (char *)&reuse, sizeof(reuse)) < 0) {
WARN_PRINT("REUSEADDR failed!")
}
@@ -110,8 +110,7 @@ Error TCPServerPosix::listen(uint16_t p_port,const IP_Address p_bind_address) {
close(sockfd);
ERR_FAIL_V(FAILED);
};
- }
- else {
+ } else {
return ERR_ALREADY_IN_USE;
};
@@ -177,14 +176,13 @@ void TCPServerPosix::stop() {
if (listen_sockfd != -1) {
int ret = close(listen_sockfd);
- ERR_FAIL_COND(ret!=0);
+ ERR_FAIL_COND(ret != 0);
};
listen_sockfd = -1;
sock_type = IP::TYPE_NONE;
};
-
TCPServerPosix::TCPServerPosix() {
listen_sockfd = -1;
diff --git a/drivers/unix/tcp_server_posix.h b/drivers/unix/tcp_server_posix.h
index ea42d0fc0c..408179c197 100644
--- a/drivers/unix/tcp_server_posix.h
+++ b/drivers/unix/tcp_server_posix.h
@@ -37,11 +37,10 @@ class TCPServerPosix : public TCP_Server {
int listen_sockfd;
IP::Type sock_type;
- static TCP_Server* _create();
+ static TCP_Server *_create();
public:
-
- virtual Error listen(uint16_t p_port, IP_Address p_bind_address=IP_Address("*"));
+ virtual Error listen(uint16_t p_port, IP_Address p_bind_address = IP_Address("*"));
virtual bool is_connection_available() const;
virtual Ref<StreamPeerTCP> take_connection();
@@ -53,6 +52,5 @@ public:
~TCPServerPosix();
};
-
#endif // TCP_SERVER_POSIX_H
#endif
diff --git a/drivers/unix/thread_posix.cpp b/drivers/unix/thread_posix.cpp
index ecea67c37b..c33cc8cc5d 100644
--- a/drivers/unix/thread_posix.cpp
+++ b/drivers/unix/thread_posix.cpp
@@ -39,18 +39,18 @@
Thread::ID ThreadPosix::get_ID() const {
- return id;
+ return id;
}
-Thread* ThreadPosix::create_thread_posix() {
+Thread *ThreadPosix::create_thread_posix() {
- return memnew( ThreadPosix );
+ return memnew(ThreadPosix);
}
void *ThreadPosix::thread_callback(void *userdata) {
- ThreadPosix *t=reinterpret_cast<ThreadPosix*>(userdata);
- t->id=(ID)pthread_self();
+ ThreadPosix *t = reinterpret_cast<ThreadPosix *>(userdata);
+ t->id = (ID)pthread_self();
ScriptServer::thread_enter(); //scripts may need to attach a stack
@@ -61,80 +61,77 @@ void *ThreadPosix::thread_callback(void *userdata) {
return NULL;
}
-Thread* ThreadPosix::create_func_posix(ThreadCreateCallback p_callback,void *p_user,const Settings&) {
+Thread *ThreadPosix::create_func_posix(ThreadCreateCallback p_callback, void *p_user, const Settings &) {
- ThreadPosix *tr= memnew(ThreadPosix);
- tr->callback=p_callback;
- tr->user=p_user;
+ ThreadPosix *tr = memnew(ThreadPosix);
+ tr->callback = p_callback;
+ tr->user = p_user;
pthread_attr_init(&tr->pthread_attr);
pthread_attr_setdetachstate(&tr->pthread_attr, PTHREAD_CREATE_JOINABLE);
pthread_attr_setstacksize(&tr->pthread_attr, 256 * 1024);
-
+
pthread_create(&tr->pthread, &tr->pthread_attr, thread_callback, tr);
-
+
return tr;
}
Thread::ID ThreadPosix::get_thread_ID_func_posix() {
return (ID)pthread_self();
}
-void ThreadPosix::wait_to_finish_func_posix(Thread* p_thread) {
+void ThreadPosix::wait_to_finish_func_posix(Thread *p_thread) {
- ThreadPosix *tp=static_cast<ThreadPosix*>(p_thread);
+ ThreadPosix *tp = static_cast<ThreadPosix *>(p_thread);
ERR_FAIL_COND(!tp);
- ERR_FAIL_COND(tp->pthread==0);
-
- pthread_join(tp->pthread,NULL);
- tp->pthread=0;
+ ERR_FAIL_COND(tp->pthread == 0);
+
+ pthread_join(tp->pthread, NULL);
+ tp->pthread = 0;
}
-Error ThreadPosix::set_name_func_posix(const String& p_name) {
+Error ThreadPosix::set_name_func_posix(const String &p_name) {
pthread_t running_thread = pthread_self();
- #ifdef PTHREAD_NO_RENAME
+#ifdef PTHREAD_NO_RENAME
return ERR_UNAVAILABLE;
- #else
+#else
- #ifdef PTHREAD_RENAME_SELF
+#ifdef PTHREAD_RENAME_SELF
// check if thread is the same as caller
int err = pthread_setname_np(p_name.utf8().get_data());
-
- #else
- #ifdef PTHREAD_BSD_SET_NAME
+#else
+
+#ifdef PTHREAD_BSD_SET_NAME
pthread_set_name_np(running_thread, p_name.utf8().get_data());
int err = 0; // Open/FreeBSD ignore errors in this function
- #else
+#else
int err = pthread_setname_np(running_thread, p_name.utf8().get_data());
- #endif // PTHREAD_BSD_SET_NAME
+#endif // PTHREAD_BSD_SET_NAME
- #endif // PTHREAD_RENAME_SELF
+#endif // PTHREAD_RENAME_SELF
return err == 0 ? OK : ERR_INVALID_PARAMETER;
- #endif // PTHREAD_NO_RENAME
+#endif // PTHREAD_NO_RENAME
};
void ThreadPosix::make_default() {
- create_func=create_func_posix;
- get_thread_ID_func=get_thread_ID_func_posix;
- wait_to_finish_func=wait_to_finish_func_posix;
+ create_func = create_func_posix;
+ get_thread_ID_func = get_thread_ID_func_posix;
+ wait_to_finish_func = wait_to_finish_func_posix;
set_name_func = set_name_func_posix;
}
ThreadPosix::ThreadPosix() {
- pthread=0;
+ pthread = 0;
}
-
ThreadPosix::~ThreadPosix() {
-
}
-
#endif
diff --git a/drivers/unix/thread_posix.h b/drivers/unix/thread_posix.h
index cf360e164a..a756ed972c 100644
--- a/drivers/unix/thread_posix.h
+++ b/drivers/unix/thread_posix.h
@@ -35,9 +35,9 @@
#if defined(UNIX_ENABLED) || defined(PTHREAD_ENABLED)
-#include <sys/types.h>
-#include <pthread.h>
#include "os/thread.h"
+#include <pthread.h>
+#include <sys/types.h>
class ThreadPosix : public Thread {
@@ -47,31 +47,26 @@ class ThreadPosix : public Thread {
void *user;
ID id;
- static Thread* create_thread_posix();
-
-
+ static Thread *create_thread_posix();
+
static void *thread_callback(void *userdata);
-
- static Thread* create_func_posix(ThreadCreateCallback p_callback,void *,const Settings&);
+
+ static Thread *create_func_posix(ThreadCreateCallback p_callback, void *, const Settings &);
static ID get_thread_ID_func_posix();
- static void wait_to_finish_func_posix(Thread* p_thread);
+ static void wait_to_finish_func_posix(Thread *p_thread);
- static Error set_name_func_posix(const String& p_name);
+ static Error set_name_func_posix(const String &p_name);
+
+ ThreadPosix();
- ThreadPosix();
public:
-
-
virtual ID get_ID() const;
-
+
static void make_default();
-
-
- ~ThreadPosix();
+ ~ThreadPosix();
};
-
#endif
#endif
diff --git a/drivers/windows/dir_access_windows.cpp b/drivers/windows/dir_access_windows.cpp
index 14742aa420..bb5ab02d8c 100644
--- a/drivers/windows/dir_access_windows.cpp
+++ b/drivers/windows/dir_access_windows.cpp
@@ -32,10 +32,10 @@
#include "os/memory.h"
-#include <windows.h>
-#include <wchar.h>
-#include <stdio.h>
#include "print_string.h"
+#include <stdio.h>
+#include <wchar.h>
+#include <windows.h>
/*
@@ -61,36 +61,32 @@ struct DirAccessWindowsPrivate {
Error DirAccessWindows::list_dir_begin() {
- _cisdir=false;
- _cishidden=false;
+ _cisdir = false;
+ _cishidden = false;
list_dir_end();
- p->h = FindFirstFileExW((current_dir+"\\*").c_str(), FindExInfoStandard, &p->fu, FindExSearchNameMatch, NULL, 0);
-
- return (p->h==INVALID_HANDLE_VALUE) ? ERR_CANT_OPEN : OK;
+ p->h = FindFirstFileExW((current_dir + "\\*").c_str(), FindExInfoStandard, &p->fu, FindExSearchNameMatch, NULL, 0);
+ return (p->h == INVALID_HANDLE_VALUE) ? ERR_CANT_OPEN : OK;
}
-
String DirAccessWindows::get_next() {
- if (p->h==INVALID_HANDLE_VALUE)
+ if (p->h == INVALID_HANDLE_VALUE)
return "";
+ _cisdir = (p->fu.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY);
+ _cishidden = (p->fu.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN);
- _cisdir=(p->fu.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY);
- _cishidden=(p->fu.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN);
-
- String name=p->fu.cFileName;
+ String name = p->fu.cFileName;
if (FindNextFileW(p->h, &p->fu) == 0) {
FindClose(p->h);
- p->h=INVALID_HANDLE_VALUE;
+ p->h = INVALID_HANDLE_VALUE;
}
return name;
-
}
bool DirAccessWindows::current_is_dir() const {
@@ -105,65 +101,60 @@ bool DirAccessWindows::current_is_hidden() const {
void DirAccessWindows::list_dir_end() {
- if (p->h!=INVALID_HANDLE_VALUE) {
+ if (p->h != INVALID_HANDLE_VALUE) {
FindClose(p->h);
- p->h=INVALID_HANDLE_VALUE;
+ p->h = INVALID_HANDLE_VALUE;
}
-
}
int DirAccessWindows::get_drive_count() {
return drive_count;
-
}
String DirAccessWindows::get_drive(int p_drive) {
- if (p_drive<0 || p_drive>=drive_count)
+ if (p_drive < 0 || p_drive >= drive_count)
return "";
- return String::chr(drives[p_drive])+":";
+ return String::chr(drives[p_drive]) + ":";
}
Error DirAccessWindows::change_dir(String p_dir) {
GLOBAL_LOCK_FUNCTION
-
- p_dir=fix_path(p_dir);
-
+ p_dir = fix_path(p_dir);
wchar_t real_current_dir_name[2048];
- GetCurrentDirectoryW(2048,real_current_dir_name);
- String prev_dir=real_current_dir_name;
+ GetCurrentDirectoryW(2048, real_current_dir_name);
+ String prev_dir = real_current_dir_name;
SetCurrentDirectoryW(current_dir.c_str());
- bool worked=(SetCurrentDirectoryW(p_dir.c_str())!=0);
+ bool worked = (SetCurrentDirectoryW(p_dir.c_str()) != 0);
String base = _get_root_path();
- if (base!="") {
+ if (base != "") {
- GetCurrentDirectoryW(2048,real_current_dir_name);
+ GetCurrentDirectoryW(2048, real_current_dir_name);
String new_dir;
- new_dir = String(real_current_dir_name).replace("\\","/");
+ new_dir = String(real_current_dir_name).replace("\\", "/");
if (!new_dir.begins_with(base)) {
- worked=false;
+ worked = false;
}
}
if (worked) {
-
- GetCurrentDirectoryW(2048,real_current_dir_name);
- current_dir=real_current_dir_name; // TODO, utf8 parser
- current_dir=current_dir.replace("\\","/");
+ GetCurrentDirectoryW(2048, real_current_dir_name);
+ current_dir = real_current_dir_name; // TODO, utf8 parser
+ current_dir = current_dir.replace("\\", "/");
} //else {
- SetCurrentDirectoryW(prev_dir.c_str());
+ SetCurrentDirectoryW(prev_dir.c_str());
//}
- return worked?OK:ERR_INVALID_PARAMETER;
+ return worked ? OK : ERR_INVALID_PARAMETER;
}
Error DirAccessWindows::make_dir(String p_dir) {
@@ -171,18 +162,18 @@ Error DirAccessWindows::make_dir(String p_dir) {
GLOBAL_LOCK_FUNCTION
if (p_dir.is_rel_path())
- p_dir=get_current_dir().plus_file(p_dir);
+ p_dir = get_current_dir().plus_file(p_dir);
- p_dir=fix_path(p_dir);
- p_dir = p_dir.replace("/","\\");
+ p_dir = fix_path(p_dir);
+ p_dir = p_dir.replace("/", "\\");
bool success;
int err;
- p_dir="\\\\?\\"+p_dir; //done according to
-// https://msdn.microsoft.com/en-us/library/windows/desktop/aa363855(v=vs.85).aspx
+ 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(), NULL);
err = GetLastError();
if (success) {
@@ -196,21 +187,18 @@ Error DirAccessWindows::make_dir(String p_dir) {
return ERR_CANT_CREATE;
}
-
String DirAccessWindows::get_current_dir() {
String base = _get_root_path();
- if (base!="") {
-
+ if (base != "") {
- String bd = current_dir.replace("\\","/").replace_first(base,"");
+ String bd = current_dir.replace("\\", "/").replace_first(base, "");
if (bd.begins_with("/"))
- return _get_root_string()+bd.substr(1,bd.length());
+ return _get_root_string() + bd.substr(1, bd.length());
else
- return _get_root_string()+bd;
+ return _get_root_string() + bd;
} else {
-
}
return current_dir;
@@ -221,9 +209,9 @@ bool DirAccessWindows::file_exists(String p_file) {
GLOBAL_LOCK_FUNCTION
if (!p_file.is_abs_path())
- p_file=get_current_dir().plus_file(p_file);
+ p_file = get_current_dir().plus_file(p_file);
- p_file=fix_path(p_file);
+ p_file = fix_path(p_file);
//p_file.replace("/","\\");
@@ -235,7 +223,7 @@ bool DirAccessWindows::file_exists(String p_file) {
if (INVALID_FILE_ATTRIBUTES == fileAttr)
return false;
- return !(fileAttr&FILE_ATTRIBUTE_DIRECTORY);
+ return !(fileAttr & FILE_ATTRIBUTE_DIRECTORY);
}
bool DirAccessWindows::dir_exists(String p_dir) {
@@ -243,34 +231,33 @@ bool DirAccessWindows::dir_exists(String p_dir) {
GLOBAL_LOCK_FUNCTION
if (p_dir.is_rel_path())
- p_dir=get_current_dir().plus_file(p_dir);
+ p_dir = get_current_dir().plus_file(p_dir);
- p_dir=fix_path(p_dir);
+ p_dir = fix_path(p_dir);
//p_dir.replace("/","\\");
//WIN32_FILE_ATTRIBUTE_DATA fileInfo;
-
DWORD fileAttr;
fileAttr = GetFileAttributesW(p_dir.c_str());
if (INVALID_FILE_ATTRIBUTES == fileAttr)
- return false;
- return (fileAttr&FILE_ATTRIBUTE_DIRECTORY);
+ return false;
+ return (fileAttr & FILE_ATTRIBUTE_DIRECTORY);
}
-Error DirAccessWindows::rename(String p_path,String p_new_path) {
+Error DirAccessWindows::rename(String p_path, String p_new_path) {
if (p_path.is_rel_path())
- p_path=get_current_dir().plus_file(p_path);
+ p_path = get_current_dir().plus_file(p_path);
- p_path=fix_path(p_path);
+ p_path = fix_path(p_path);
if (p_new_path.is_rel_path())
- p_new_path=get_current_dir().plus_file(p_new_path);
+ p_new_path = get_current_dir().plus_file(p_new_path);
- p_new_path=fix_path(p_new_path);
+ p_new_path = fix_path(p_new_path);
if (file_exists(p_new_path)) {
if (remove(p_new_path) != OK) {
@@ -278,18 +265,17 @@ Error DirAccessWindows::rename(String p_path,String p_new_path) {
};
};
- return ::_wrename(p_path.c_str(),p_new_path.c_str())==0?OK:FAILED;
+ return ::_wrename(p_path.c_str(), p_new_path.c_str()) == 0 ? OK : FAILED;
}
-Error DirAccessWindows::remove(String p_path) {
+Error DirAccessWindows::remove(String p_path) {
if (p_path.is_rel_path())
- p_path=get_current_dir().plus_file(p_path);
+ p_path = get_current_dir().plus_file(p_path);
- p_path=fix_path(p_path);
+ p_path = fix_path(p_path);
-
- printf("erasing %s\n",p_path.utf8().get_data());
+ printf("erasing %s\n", p_path.utf8().get_data());
//WIN32_FILE_ATTRIBUTE_DATA fileInfo;
//DWORD fileAttr = GetFileAttributesExW(p_path.c_str(), GetFileExInfoStandard, &fileInfo);
@@ -297,11 +283,11 @@ Error DirAccessWindows::remove(String p_path) {
fileAttr = GetFileAttributesW(p_path.c_str());
if (INVALID_FILE_ATTRIBUTES == fileAttr)
- return FAILED;
- if ((fileAttr&FILE_ATTRIBUTE_DIRECTORY))
- return ::_wrmdir(p_path.c_str())==0?OK:FAILED;
+ return FAILED;
+ if ((fileAttr & FILE_ATTRIBUTE_DIRECTORY))
+ return ::_wrmdir(p_path.c_str()) == 0 ? OK : FAILED;
else
- return ::_wunlink(p_path.c_str())==0?OK:FAILED;
+ return ::_wunlink(p_path.c_str()) == 0 ? OK : FAILED;
}
/*
@@ -331,10 +317,10 @@ FileType DirAccessWindows::get_file_type(const String& p_file) const {
return (attr&FILE_ATTRIBUTE_DIRECTORY)?FILE_TYPE_
}
*/
-size_t DirAccessWindows::get_space_left() {
+size_t DirAccessWindows::get_space_left() {
uint64_t bytes = 0;
- if (!GetDiskFreeSpaceEx(NULL,(PULARGE_INTEGER)&bytes,NULL,NULL))
+ if (!GetDiskFreeSpaceEx(NULL, (PULARGE_INTEGER)&bytes, NULL, NULL))
return 0;
//this is either 0 or a value in bytes.
@@ -343,26 +329,25 @@ size_t DirAccessWindows::get_space_left() {
DirAccessWindows::DirAccessWindows() {
- p = memnew( DirAccessWindowsPrivate );
- p->h=INVALID_HANDLE_VALUE;
- current_dir=".";
+ p = memnew(DirAccessWindowsPrivate);
+ p->h = INVALID_HANDLE_VALUE;
+ current_dir = ".";
- drive_count=0;
+ drive_count = 0;
#ifdef UWP_ENABLED
- Windows::Storage::StorageFolder ^install_folder = Windows::ApplicationModel::Package::Current->InstalledLocation;
+ Windows::Storage::StorageFolder ^ install_folder = Windows::ApplicationModel::Package::Current->InstalledLocation;
change_dir(install_folder->Path->Data());
#else
+ DWORD mask = GetLogicalDrives();
- DWORD mask=GetLogicalDrives();
-
- for (int i=0;i<MAX_DRIVES;i++) {
+ for (int i = 0; i < MAX_DRIVES; i++) {
- if (mask&(1<<i)) { //DRIVE EXISTS
+ if (mask & (1 << i)) { //DRIVE EXISTS
- drives[drive_count]='a'+i;
+ drives[drive_count] = 'a' + i;
drive_count++;
}
}
@@ -371,10 +356,9 @@ DirAccessWindows::DirAccessWindows() {
#endif
}
-
DirAccessWindows::~DirAccessWindows() {
- memdelete( p );
+ memdelete(p);
}
#endif //windows DirAccess support
diff --git a/drivers/windows/dir_access_windows.h b/drivers/windows/dir_access_windows.h
index f4105b7bc9..e0815f2c09 100644
--- a/drivers/windows/dir_access_windows.h
+++ b/drivers/windows/dir_access_windows.h
@@ -29,7 +29,6 @@
#ifndef DIR_ACCESS_WINDOWS_H
#define DIR_ACCESS_WINDOWS_H
-
#ifdef WINDOWS_ENABLED
#include "os/dir_access.h"
@@ -40,14 +39,12 @@
struct DirAccessWindowsPrivate;
-
class DirAccessWindows : public DirAccess {
enum {
- MAX_DRIVES=26
+ MAX_DRIVES = 26
};
-
DirAccessWindowsPrivate *p;
/* Windows stuff */
@@ -56,12 +53,10 @@ class DirAccessWindows : public DirAccess {
String current_dir;
-
bool _cisdir;
bool _cishidden;
public:
-
virtual Error list_dir_begin(); ///< This starts dir listing
virtual String get_next();
virtual bool current_is_dir() const;
@@ -74,7 +69,6 @@ public:
virtual Error change_dir(String p_dir); ///< can be relative or absolute, return false on success
virtual String get_current_dir(); ///< return current dir location
-
virtual bool file_exists(String p_file);
virtual bool dir_exists(String p_dir);
@@ -88,7 +82,6 @@ public:
DirAccessWindows();
~DirAccessWindows();
-
};
#endif //WINDOWS_ENABLED
diff --git a/drivers/windows/file_access_windows.cpp b/drivers/windows/file_access_windows.cpp
index 894b49231b..0bb6c1d196 100644
--- a/drivers/windows/file_access_windows.cpp
+++ b/drivers/windows/file_access_windows.cpp
@@ -28,20 +28,18 @@
/*************************************************************************/
#ifdef WINDOWS_ENABLED
-#include <windows.h>
-#include "shlwapi.h"
#include "file_access_windows.h"
+#include "shlwapi.h"
+#include <windows.h>
-
-#include <sys/types.h>
+#include "print_string.h"
#include <sys/stat.h>
-#include <wchar.h>
+#include <sys/types.h>
#include <tchar.h>
-#include "print_string.h"
-
+#include <wchar.h>
#ifdef _MSC_VER
- #define S_ISREG(m) ((m)&_S_IFREG)
+#define S_ISREG(m) ((m)&_S_IFREG)
#endif
void FileAccessWindows::check_errors() const {
@@ -50,28 +48,26 @@ void FileAccessWindows::check_errors() const {
if (feof(f)) {
- last_error=ERR_FILE_EOF;
+ last_error = ERR_FILE_EOF;
}
-
}
-Error FileAccessWindows::_open(const String& p_filename, int p_mode_flags) {
+Error FileAccessWindows::_open(const String &p_filename, int p_mode_flags) {
- String filename=fix_path(p_filename);
+ String filename = fix_path(p_filename);
if (f)
close();
+ const wchar_t *mode_string;
- const wchar_t* mode_string;
-
- if (p_mode_flags==READ)
- mode_string=L"rb";
- else if (p_mode_flags==WRITE)
- mode_string=L"wb";
- else if (p_mode_flags==READ_WRITE)
- mode_string=L"rb+";
- else if (p_mode_flags==WRITE_READ)
- mode_string=L"wb+";
+ if (p_mode_flags == READ)
+ mode_string = L"rb";
+ else if (p_mode_flags == WRITE)
+ mode_string = L"wb";
+ else if (p_mode_flags == READ_WRITE)
+ mode_string = L"rb+";
+ else if (p_mode_flags == WRITE_READ)
+ mode_string = L"wb+";
else
return ERR_INVALID_PARAMETER;
@@ -83,27 +79,24 @@ Error FileAccessWindows::_open(const String& p_filename, int p_mode_flags) {
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";
+ if (is_backup_save_enabled() && p_mode_flags & WRITE && !(p_mode_flags & READ)) {
+ save_path = filename;
+ filename = filename + ".tmp";
//print_line("saving instead to "+path);
}
- f=_wfopen(filename.c_str(), mode_string);
+ f = _wfopen(filename.c_str(), mode_string);
-
- if (f==NULL) {
- last_error=ERR_FILE_CANT_OPEN;
+ if (f == NULL) {
+ last_error = ERR_FILE_CANT_OPEN;
return ERR_FILE_CANT_OPEN;
} else {
- last_error=OK;
- flags=p_mode_flags;
+ last_error = OK;
+ flags = p_mode_flags;
return OK;
}
-
}
void FileAccessWindows::close() {
@@ -113,14 +106,13 @@ void FileAccessWindows::close() {
fclose(f);
f = NULL;
- if (save_path!="") {
+ if (save_path != "") {
//unlink(save_path.utf8().get_data());
//print_line("renaming..");
//_wunlink(save_path.c_str()); //unlink if exists
//int rename_error = _wrename((save_path+".tmp").c_str(),save_path.c_str());
-
bool rename_error;
#ifdef UWP_ENABLED
@@ -133,53 +125,50 @@ void FileAccessWindows::close() {
if (!PathFileExistsW(save_path.c_str())) {
#endif
//creating new file
- rename_error = _wrename((save_path+".tmp").c_str(),save_path.c_str())!=0;
+ 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(), NULL, 2 | 4, NULL, NULL);
}
if (rename_error && close_fail_notify) {
close_fail_notify(save_path);
}
- save_path="";
- ERR_FAIL_COND( rename_error );
+ save_path = "";
+ ERR_FAIL_COND(rename_error);
}
-
}
bool FileAccessWindows::is_open() const {
- return (f!=NULL);
+ return (f != NULL);
}
void FileAccessWindows::seek(size_t p_position) {
ERR_FAIL_COND(!f);
- last_error=OK;
- if ( fseek(f,p_position,SEEK_SET) )
+ last_error = OK;
+ if (fseek(f, p_position, SEEK_SET))
check_errors();
}
void FileAccessWindows::seek_end(int64_t p_position) {
ERR_FAIL_COND(!f);
- if ( fseek(f,p_position,SEEK_END) )
+ if (fseek(f, p_position, SEEK_END))
check_errors();
}
size_t FileAccessWindows::get_pos() const {
-
- size_t aux_position=0;
- if ( !(aux_position = ftell(f)) ) {
+ size_t aux_position = 0;
+ if (!(aux_position = ftell(f))) {
check_errors();
};
return aux_position;
}
size_t FileAccessWindows::get_len() const {
-
- ERR_FAIL_COND_V(!f,0);
+ ERR_FAIL_COND_V(!f, 0);
size_t pos = get_pos();
- fseek(f,0,SEEK_END);
+ fseek(f, 0, SEEK_END);
int size = get_pos();
fseek(f, pos, SEEK_SET);
@@ -189,14 +178,14 @@ size_t FileAccessWindows::get_len() const {
bool FileAccessWindows::eof_reached() const {
check_errors();
- return last_error==ERR_FILE_EOF;
+ return last_error == ERR_FILE_EOF;
}
uint8_t FileAccessWindows::get_8() const {
- ERR_FAIL_COND_V(!f,0);
+ ERR_FAIL_COND_V(!f, 0);
uint8_t b;
- if (fread(&b,1,1,f) == 0) {
+ if (fread(&b, 1, 1, f) == 0) {
check_errors();
};
@@ -205,13 +194,12 @@ uint8_t FileAccessWindows::get_8() const {
int FileAccessWindows::get_buffer(uint8_t *p_dst, int p_length) const {
- ERR_FAIL_COND_V(!f,-1);
- int read = fread(p_dst, 1,p_length, f);
+ ERR_FAIL_COND_V(!f, -1);
+ int read = fread(p_dst, 1, p_length, f);
check_errors();
return read;
};
-
Error FileAccessWindows::get_error() const {
return last_error;
@@ -220,18 +208,16 @@ Error FileAccessWindows::get_error() const {
void FileAccessWindows::store_8(uint8_t p_dest) {
ERR_FAIL_COND(!f);
- fwrite(&p_dest,1,1,f);
-
+ fwrite(&p_dest, 1, 1, f);
}
-
-bool FileAccessWindows::file_exists(const String& p_name) {
+bool FileAccessWindows::file_exists(const String &p_name) {
FILE *g;
//printf("opening file %s\n", p_fname.c_str());
- String filename=fix_path(p_name);
- g=_wfopen(filename.c_str(),L"rb");
- if (g==NULL) {
+ String filename = fix_path(p_name);
+ g = _wfopen(filename.c_str(), L"rb");
+ if (g == NULL) {
return false;
} else {
@@ -241,11 +227,11 @@ bool FileAccessWindows::file_exists(const String& p_name) {
}
}
-uint64_t FileAccessWindows::_get_modified_time(const String& p_file) {
+uint64_t FileAccessWindows::_get_modified_time(const String &p_file) {
- String file=fix_path(p_file);
- if (file.ends_with("/") && file!="/")
- file=file.substr(0,file.length()-1);
+ String file = fix_path(p_file);
+ if (file.ends_with("/") && file != "/")
+ file = file.substr(0, file.length() - 1);
struct _stat st;
int rv = _wstat(file.c_str(), &st);
@@ -254,25 +240,21 @@ uint64_t FileAccessWindows::_get_modified_time(const String& p_file) {
return st.st_mtime;
} else {
- print_line("no access to "+file );
+ print_line("no access to " + file);
}
-
ERR_FAIL_V(0);
};
-
FileAccessWindows::FileAccessWindows() {
- f=NULL;
- flags=0;
- last_error=OK;
-
+ f = NULL;
+ flags = 0;
+ last_error = OK;
}
FileAccessWindows::~FileAccessWindows() {
close();
-
}
#endif
diff --git a/drivers/windows/file_access_windows.h b/drivers/windows/file_access_windows.h
index 9f06918b72..d64a4b98fc 100644
--- a/drivers/windows/file_access_windows.h
+++ b/drivers/windows/file_access_windows.h
@@ -47,12 +47,12 @@ class FileAccessWindows : public FileAccess {
String save_path;
public:
- virtual Error _open(const String& p_path, int p_mode_flags); ///< open a file
+ virtual Error _open(const String &p_path, int p_mode_flags); ///< open a file
virtual void close(); ///< close a file
virtual bool is_open() const; ///< true when file is open
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 void seek_end(int64_t p_position = 0); ///< seek from the end of file
virtual size_t get_pos() const; ///< get position in the file
virtual size_t get_len() const; ///< get size of the file
@@ -65,15 +65,13 @@ public:
virtual void store_8(uint8_t p_dest); ///< store a byte
- virtual bool file_exists(const String& p_name); ///< return true if a file exists
+ virtual bool file_exists(const String &p_name); ///< return true if a file exists
- uint64_t _get_modified_time(const String& p_file);
+ uint64_t _get_modified_time(const String &p_file);
FileAccessWindows();
virtual ~FileAccessWindows();
-
};
-
#endif
#endif
diff --git a/drivers/windows/mutex_windows.cpp b/drivers/windows/mutex_windows.cpp
index 6ae7e52124..bacf89efbb 100644
--- a/drivers/windows/mutex_windows.cpp
+++ b/drivers/windows/mutex_windows.cpp
@@ -31,76 +31,68 @@
#ifdef WINDOWS_ENABLED
-
-
void MutexWindows::lock() {
#ifdef WINDOWS_USE_MUTEX
- WaitForSingleObject(mutex,INFINITE);
+ WaitForSingleObject(mutex, INFINITE);
#else
- EnterCriticalSection( &mutex );
+ EnterCriticalSection(&mutex);
#endif
}
-
void MutexWindows::unlock() {
#ifdef WINDOWS_USE_MUTEX
ReleaseMutex(mutex);
#else
- LeaveCriticalSection( &mutex );
+ LeaveCriticalSection(&mutex);
#endif
}
Error MutexWindows::try_lock() {
#ifdef WINDOWS_USE_MUTEX
- return (WaitForSingleObject(mutex,0)==WAIT_TIMEOUT)?ERR_BUSY:OK;
+ return (WaitForSingleObject(mutex, 0) == WAIT_TIMEOUT) ? ERR_BUSY : OK;
#else
- if (TryEnterCriticalSection( &mutex ))
- return OK;
- else
- return ERR_BUSY;
+ if (TryEnterCriticalSection(&mutex))
+ return OK;
+ else
+ return ERR_BUSY;
#endif
-
}
Mutex *MutexWindows::create_func_windows(bool p_recursive) {
- return memnew( MutexWindows );
+ return memnew(MutexWindows);
}
void MutexWindows::make_default() {
- create_func=create_func_windows;
+ create_func = create_func_windows;
}
MutexWindows::MutexWindows() {
-
+
#ifdef WINDOWS_USE_MUTEX
- mutex = CreateMutex( NULL, FALSE, NULL );
+ mutex = CreateMutex(NULL, FALSE, NULL);
+#else
+#ifdef UWP_ENABLED
+ InitializeCriticalSectionEx(&mutex, 0, 0);
#else
- #ifdef UWP_ENABLED
- InitializeCriticalSectionEx( &mutex, 0, 0 );
- #else
- InitializeCriticalSection( &mutex );
- #endif
+ InitializeCriticalSection(&mutex);
+#endif
#endif
-
}
-
MutexWindows::~MutexWindows() {
#ifdef WINDOWS_USE_MUTEX
- CloseHandle(mutex);
+ CloseHandle(mutex);
#else
- DeleteCriticalSection(&mutex);
+ DeleteCriticalSection(&mutex);
#endif
-
}
-
#endif
diff --git a/drivers/windows/mutex_windows.h b/drivers/windows/mutex_windows.h
index 4202735f2b..0c6cbd472a 100644
--- a/drivers/windows/mutex_windows.h
+++ b/drivers/windows/mutex_windows.h
@@ -31,33 +31,30 @@
#ifdef WINDOWS_ENABLED
-#include <windows.h>
#include "os/mutex.h"
+#include <windows.h>
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
class MutexWindows : public Mutex {
#ifdef WINDOWS_USE_MUTEX
- HANDLE mutex;
+ HANDLE mutex;
#else
- CRITICAL_SECTION mutex;
+ CRITICAL_SECTION mutex;
#endif
-
+
static Mutex *create_func_windows(bool p_recursive);
-
-public:
- virtual void lock();
+public:
+ virtual void lock();
virtual void unlock();
- virtual Error try_lock();
-
+ virtual Error try_lock();
static void make_default();
- MutexWindows();
+ MutexWindows();
~MutexWindows();
-
};
#endif
diff --git a/drivers/windows/rw_lock_windows.cpp b/drivers/windows/rw_lock_windows.cpp
index edbd7b6a0f..615bcd22aa 100644
--- a/drivers/windows/rw_lock_windows.cpp
+++ b/drivers/windows/rw_lock_windows.cpp
@@ -30,14 +30,13 @@
#include "rw_lock_windows.h"
-#include "os/memory.h"
#include "error_macros.h"
+#include "os/memory.h"
#include <stdio.h>
void RWLockWindows::read_lock() {
AcquireSRWLockShared(&lock);
-
}
void RWLockWindows::read_unlock() {
@@ -47,18 +46,16 @@ void RWLockWindows::read_unlock() {
Error RWLockWindows::read_try_lock() {
- if (TryAcquireSRWLockShared(&lock)==0) {
+ if (TryAcquireSRWLockShared(&lock) == 0) {
return ERR_BUSY;
} else {
return OK;
}
-
}
void RWLockWindows::write_lock() {
AcquireSRWLockExclusive(&lock);
-
}
void RWLockWindows::write_unlock() {
@@ -67,34 +64,29 @@ void RWLockWindows::write_unlock() {
}
Error RWLockWindows::write_try_lock() {
- if (TryAcquireSRWLockExclusive(&lock)==0) {
+ if (TryAcquireSRWLockExclusive(&lock) == 0) {
return ERR_BUSY;
} else {
return OK;
}
}
-
RWLock *RWLockWindows::create_func_windows() {
- return memnew( RWLockWindows );
+ return memnew(RWLockWindows);
}
void RWLockWindows::make_default() {
- create_func=create_func_windows;
+ create_func = create_func_windows;
}
-
RWLockWindows::RWLockWindows() {
InitializeSRWLock(&lock);
}
-
RWLockWindows::~RWLockWindows() {
-
-
}
#endif
diff --git a/drivers/windows/rw_lock_windows.h b/drivers/windows/rw_lock_windows.h
index 059704e5c7..e4b5367c2f 100644
--- a/drivers/windows/rw_lock_windows.h
+++ b/drivers/windows/rw_lock_windows.h
@@ -31,18 +31,16 @@
#if defined(WINDOWS_ENABLED)
-#include <windows.h>
#include "os/rw_lock.h"
+#include <windows.h>
class RWLockWindows : public RWLock {
-
SRWLOCK lock;
static RWLock *create_func_windows();
public:
-
virtual void read_lock();
virtual void read_unlock();
virtual Error read_try_lock();
@@ -56,10 +54,8 @@ public:
RWLockWindows();
~RWLockWindows();
-
};
#endif
-
#endif // RWLOCKWINDOWS_H
diff --git a/drivers/windows/semaphore_windows.cpp b/drivers/windows/semaphore_windows.cpp
index cdd1a7b888..b1c9ee0182 100644
--- a/drivers/windows/semaphore_windows.cpp
+++ b/drivers/windows/semaphore_windows.cpp
@@ -34,19 +34,19 @@
Error SemaphoreWindows::wait() {
- WaitForSingleObjectEx(semaphore,INFINITE, false);
+ WaitForSingleObjectEx(semaphore, INFINITE, false);
return OK;
}
Error SemaphoreWindows::post() {
- ReleaseSemaphore(semaphore,1,NULL);
+ ReleaseSemaphore(semaphore, 1, NULL);
return OK;
}
int SemaphoreWindows::get() const {
long previous;
switch (WaitForSingleObjectEx(semaphore, 0, false)) {
case WAIT_OBJECT_0: {
- ERR_FAIL_COND_V(!ReleaseSemaphore(semaphore, 1, &previous),-1);
+ ERR_FAIL_COND_V(!ReleaseSemaphore(semaphore, 1, &previous), -1);
return previous + 1;
} break;
case WAIT_TIMEOUT: {
@@ -58,41 +58,38 @@ int SemaphoreWindows::get() const {
ERR_FAIL_V(-1);
}
-
Semaphore *SemaphoreWindows::create_semaphore_windows() {
- return memnew( SemaphoreWindows );
+ return memnew(SemaphoreWindows);
}
void SemaphoreWindows::make_default() {
- create_func=create_semaphore_windows;
+ create_func = create_semaphore_windows;
}
SemaphoreWindows::SemaphoreWindows() {
#ifdef UWP_ENABLED
- semaphore=CreateSemaphoreEx(
- NULL,
- 0,
- 0xFFFFFFF, //wathever
- NULL,
- 0,
- SEMAPHORE_ALL_ACCESS);
+ semaphore = CreateSemaphoreEx(
+ NULL,
+ 0,
+ 0xFFFFFFF, //wathever
+ NULL,
+ 0,
+ SEMAPHORE_ALL_ACCESS);
#else
- semaphore=CreateSemaphore(
- NULL,
- 0,
- 0xFFFFFFF, //wathever
- NULL);
+ semaphore = CreateSemaphore(
+ NULL,
+ 0,
+ 0xFFFFFFF, //wathever
+ NULL);
#endif
}
-
SemaphoreWindows::~SemaphoreWindows() {
CloseHandle(semaphore);
}
-
#endif
diff --git a/drivers/windows/semaphore_windows.h b/drivers/windows/semaphore_windows.h
index 564087a691..5594cb0c58 100644
--- a/drivers/windows/semaphore_windows.h
+++ b/drivers/windows/semaphore_windows.h
@@ -29,8 +29,6 @@
#ifndef SEMAPHORE_WINDOWS_H
#define SEMAPHORE_WINDOWS_H
-
-
#include "os/semaphore.h"
#ifdef WINDOWS_ENABLED
@@ -41,21 +39,19 @@
*/
class SemaphoreWindows : public Semaphore {
- mutable HANDLE semaphore;
+ mutable HANDLE semaphore;
static Semaphore *create_semaphore_windows();
public:
-
virtual Error wait();
- virtual Error post();
+ virtual Error post();
virtual int get() const;
static void make_default();
SemaphoreWindows();
-
- ~SemaphoreWindows();
+ ~SemaphoreWindows();
};
#endif
diff --git a/drivers/windows/shell_windows.cpp b/drivers/windows/shell_windows.cpp
index a96bc6a7db..715d886ed2 100644
--- a/drivers/windows/shell_windows.cpp
+++ b/drivers/windows/shell_windows.cpp
@@ -52,17 +52,12 @@
void ShellWindows::execute(String p_path) {
ShellExecuteW(NULL, L"open", p_path.c_str(), NULL, NULL, SW_SHOWNORMAL);
-
}
-
-ShellWindows::ShellWindows()
-{
+ShellWindows::ShellWindows() {
}
-
-ShellWindows::~ShellWindows()
-{
+ShellWindows::~ShellWindows() {
}
#endif
diff --git a/drivers/windows/shell_windows.h b/drivers/windows/shell_windows.h
index 92203df98a..e0baf3e765 100644
--- a/drivers/windows/shell_windows.h
+++ b/drivers/windows/shell_windows.h
@@ -37,13 +37,11 @@
*/
class ShellWindows : public Shell {
public:
-
virtual void execute(String p_path);
ShellWindows();
-
- ~ShellWindows();
+ ~ShellWindows();
};
#endif
diff --git a/drivers/windows/thread_windows.cpp b/drivers/windows/thread_windows.cpp
index dbe2f93fd4..e6143b4af3 100644
--- a/drivers/windows/thread_windows.cpp
+++ b/drivers/windows/thread_windows.cpp
@@ -32,24 +32,23 @@
#include "os/memory.h"
-
Thread::ID ThreadWindows::get_ID() const {
- return id;
+ return id;
}
-Thread* ThreadWindows::create_thread_windows() {
+Thread *ThreadWindows::create_thread_windows() {
- return memnew( ThreadWindows );
+ return memnew(ThreadWindows);
}
-DWORD ThreadWindows::thread_callback( LPVOID userdata ) {
+DWORD ThreadWindows::thread_callback(LPVOID userdata) {
- ThreadWindows *t=reinterpret_cast<ThreadWindows*>(userdata);
+ ThreadWindows *t = reinterpret_cast<ThreadWindows *>(userdata);
ScriptServer::thread_enter(); //scripts may need to attach a stack
- t->id=(ID)GetCurrentThreadId(); // must implement
+ t->id = (ID)GetCurrentThreadId(); // must implement
t->callback(t->user);
ScriptServer::thread_exit();
@@ -57,53 +56,47 @@ DWORD ThreadWindows::thread_callback( LPVOID userdata ) {
return 0;
}
-Thread* ThreadWindows::create_func_windows(ThreadCreateCallback p_callback,void *p_user,const Settings&) {
-
- ThreadWindows *tr= memnew(ThreadWindows);
- tr->callback=p_callback;
- tr->user=p_user;
- tr->handle=CreateThread(
- NULL, // default security attributes
- 0, // use default stack size
- thread_callback, // thread function name
- tr, // argument to thread function
- 0, // use default creation flags
- NULL); // returns the thread identifier
-
+Thread *ThreadWindows::create_func_windows(ThreadCreateCallback p_callback, void *p_user, const Settings &) {
+
+ ThreadWindows *tr = memnew(ThreadWindows);
+ tr->callback = p_callback;
+ tr->user = p_user;
+ tr->handle = CreateThread(
+ NULL, // default security attributes
+ 0, // use default stack size
+ thread_callback, // thread function name
+ tr, // argument to thread function
+ 0, // use default creation flags
+ NULL); // returns the thread identifier
+
return tr;
}
Thread::ID ThreadWindows::get_thread_ID_func_windows() {
return (ID)GetCurrentThreadId(); //must implement
}
-void ThreadWindows::wait_to_finish_func_windows(Thread* p_thread) {
+void ThreadWindows::wait_to_finish_func_windows(Thread *p_thread) {
-
- ThreadWindows *tp=static_cast<ThreadWindows*>(p_thread);
+ ThreadWindows *tp = static_cast<ThreadWindows *>(p_thread);
ERR_FAIL_COND(!tp);
- WaitForSingleObject( tp->handle, INFINITE );
+ WaitForSingleObject(tp->handle, INFINITE);
CloseHandle(tp->handle);
- //`memdelete(tp);
+ //`memdelete(tp);
}
-
void ThreadWindows::make_default() {
- create_func=create_func_windows;
- get_thread_ID_func=get_thread_ID_func_windows;
- wait_to_finish_func=wait_to_finish_func_windows;
-
+ create_func = create_func_windows;
+ get_thread_ID_func = get_thread_ID_func_windows;
+ wait_to_finish_func = wait_to_finish_func_windows;
}
ThreadWindows::ThreadWindows() {
- handle=NULL;
+ handle = NULL;
}
-
ThreadWindows::~ThreadWindows() {
-
}
-
#endif
diff --git a/drivers/windows/thread_windows.h b/drivers/windows/thread_windows.h
index c8f395e062..5b2c076c7f 100644
--- a/drivers/windows/thread_windows.h
+++ b/drivers/windows/thread_windows.h
@@ -41,36 +41,29 @@
class ThreadWindows : public Thread {
-
ThreadCreateCallback callback;
void *user;
ID id;
HANDLE handle;
- static Thread* create_thread_windows();
-
-
-
- static DWORD WINAPI thread_callback( LPVOID userdata );
-
- static Thread* create_func_windows(ThreadCreateCallback p_callback,void *,const Settings&);
+ static Thread *create_thread_windows();
+
+ static DWORD WINAPI thread_callback(LPVOID userdata);
+
+ static Thread *create_func_windows(ThreadCreateCallback p_callback, void *, const Settings &);
static ID get_thread_ID_func_windows();
- static void wait_to_finish_func_windows(Thread* p_thread);
-
- ThreadWindows();
+ static void wait_to_finish_func_windows(Thread *p_thread);
+
+ ThreadWindows();
+
public:
-
-
virtual ID get_ID() const;
-
+
static void make_default();
-
-
- ~ThreadWindows();
+ ~ThreadWindows();
};
-
#endif
#endif
diff --git a/drivers/xaudio2/audio_driver_xaudio2.cpp b/drivers/xaudio2/audio_driver_xaudio2.cpp
index cd61fefd91..546bbff1ba 100644
--- a/drivers/xaudio2/audio_driver_xaudio2.cpp
+++ b/drivers/xaudio2/audio_driver_xaudio2.cpp
@@ -31,8 +31,7 @@
#include "global_config.h"
#include "os/os.h"
-const char * AudioDriverXAudio2::get_name() const
-{
+const char *AudioDriverXAudio2::get_name() const {
return "XAudio2";
}
@@ -44,7 +43,6 @@ Error AudioDriverXAudio2::init() {
pcm_open = false;
samples_in = NULL;
-
mix_rate = 48000;
// FIXME: speaker_mode seems unused in the Xaudio2 driver so far
speaker_mode = SPEAKER_MODE_STEREO;
@@ -53,11 +51,11 @@ Error AudioDriverXAudio2::init() {
int latency = GLOBAL_DEF("audio/output_latency", 25);
buffer_size = nearest_power_of_2(latency * mix_rate / 1000);
- samples_in = memnew_arr(int32_t, buffer_size*channels);
+ samples_in = memnew_arr(int32_t, buffer_size * channels);
for (int i = 0; i < AUDIO_BUFFERS; i++) {
- samples_out[i] = memnew_arr(int16_t, buffer_size*channels);
+ samples_out[i] = memnew_arr(int16_t, buffer_size * channels);
xaudio_buffer[i].AudioBytes = buffer_size * channels * sizeof(int16_t);
- xaudio_buffer[i].pAudioData = (const BYTE*)(samples_out[i]);
+ xaudio_buffer[i].pAudioData = (const BYTE *)(samples_out[i]);
xaudio_buffer[i].Flags = 0;
}
@@ -93,15 +91,14 @@ Error AudioDriverXAudio2::init() {
return OK;
};
-void AudioDriverXAudio2::thread_func(void* p_udata) {
+void AudioDriverXAudio2::thread_func(void *p_udata) {
- AudioDriverXAudio2* ad = (AudioDriverXAudio2*)p_udata;
+ AudioDriverXAudio2 *ad = (AudioDriverXAudio2 *)p_udata;
uint64_t usdelay = (ad->buffer_size / float(ad->mix_rate)) * 1000000;
while (!ad->exit_thread) {
-
if (!ad->active) {
for (int i = 0; i < AUDIO_BUFFERS; i++) {
@@ -116,30 +113,27 @@ void AudioDriverXAudio2::thread_func(void* p_udata) {
ad->unlock();
- for (unsigned int i = 0;i < ad->buffer_size*ad->channels;i++) {
+ for (unsigned int i = 0; i < ad->buffer_size * ad->channels; i++) {
ad->samples_out[ad->current_buffer][i] = ad->samples_in[i] >> 16;
}
ad->xaudio_buffer[ad->current_buffer].Flags = 0;
ad->xaudio_buffer[ad->current_buffer].AudioBytes = ad->buffer_size * ad->channels * sizeof(int16_t);
- ad->xaudio_buffer[ad->current_buffer].pAudioData = (const BYTE*)(ad->samples_out[ad->current_buffer]);
+ ad->xaudio_buffer[ad->current_buffer].pAudioData = (const BYTE *)(ad->samples_out[ad->current_buffer]);
ad->xaudio_buffer[ad->current_buffer].PlayBegin = 0;
ad->source_voice->SubmitSourceBuffer(&(ad->xaudio_buffer[ad->current_buffer]));
ad->current_buffer = (ad->current_buffer + 1) % AUDIO_BUFFERS;
XAUDIO2_VOICE_STATE state;
- while (ad->source_voice->GetState(&state), state.BuffersQueued > AUDIO_BUFFERS - 1)
- {
+ while (ad->source_voice->GetState(&state), state.BuffersQueued > AUDIO_BUFFERS - 1) {
WaitForSingleObject(ad->voice_callback.buffer_end_event, INFINITE);
}
}
-
};
ad->thread_exited = true;
-
};
void AudioDriverXAudio2::start() {
@@ -228,9 +222,6 @@ AudioDriverXAudio2::AudioDriverXAudio2() {
current_buffer = 0;
};
-AudioDriverXAudio2::~AudioDriverXAudio2() {
-
+AudioDriverXAudio2::~AudioDriverXAudio2(){
};
-
-
diff --git a/drivers/xaudio2/audio_driver_xaudio2.h b/drivers/xaudio2/audio_driver_xaudio2.h
index afafb84c23..9a37ba7a7b 100644
--- a/drivers/xaudio2/audio_driver_xaudio2.h
+++ b/drivers/xaudio2/audio_driver_xaudio2.h
@@ -29,15 +29,15 @@
#ifndef AUDIO_DRIVER_XAUDIO2_H
#define AUDIO_DRIVER_XAUDIO2_H
-#include "servers/audio_server.h"
-#include "core/os/thread.h"
#include "core/os/mutex.h"
+#include "core/os/thread.h"
+#include "servers/audio_server.h"
-#include <windows.h>
-#include <mmsystem.h>
#include <mmreg.h>
-#include <xaudio2.h>
+#include <mmsystem.h>
+#include <windows.h>
#include <wrl/client.h>
+#include <xaudio2.h>
class AudioDriverXAudio2 : public AudioDriver {
@@ -48,26 +48,28 @@ class AudioDriverXAudio2 : public AudioDriver {
struct XAudio2DriverVoiceCallback : public IXAudio2VoiceCallback {
HANDLE buffer_end_event;
- XAudio2DriverVoiceCallback() : buffer_end_event(CreateEvent(NULL, FALSE, FALSE, NULL)) {}
- void STDMETHODCALLTYPE OnBufferEnd(void* pBufferContext) { /*print_line("buffer ended");*/ SetEvent(buffer_end_event); }
+ XAudio2DriverVoiceCallback()
+ : buffer_end_event(CreateEvent(NULL, FALSE, FALSE, NULL)) {}
+ void STDMETHODCALLTYPE OnBufferEnd(void *pBufferContext) { /*print_line("buffer ended");*/
+ SetEvent(buffer_end_event);
+ }
//Unused methods are stubs
void STDMETHODCALLTYPE OnStreamEnd() {}
void STDMETHODCALLTYPE OnVoiceProcessingPassEnd() {}
void STDMETHODCALLTYPE OnVoiceProcessingPassStart(UINT32 SamplesRequired) {}
- void STDMETHODCALLTYPE OnBufferStart(void * pBufferContext) {}
- void STDMETHODCALLTYPE OnLoopEnd(void * pBufferContext) {}
- void STDMETHODCALLTYPE OnVoiceError(void * pBufferContext, HRESULT Error) {}
-
+ void STDMETHODCALLTYPE OnBufferStart(void *pBufferContext) {}
+ void STDMETHODCALLTYPE OnLoopEnd(void *pBufferContext) {}
+ void STDMETHODCALLTYPE OnVoiceError(void *pBufferContext, HRESULT Error) {}
};
- Thread* thread;
- Mutex* mutex;
+ Thread *thread;
+ Mutex *mutex;
- int32_t* samples_in;
- int16_t* samples_out[AUDIO_BUFFERS];
+ int32_t *samples_in;
+ int16_t *samples_out[AUDIO_BUFFERS];
- static void thread_func(void* p_udata);
+ static void thread_func(void *p_udata);
int buffer_size;
unsigned int mix_rate;
@@ -83,14 +85,13 @@ class AudioDriverXAudio2 : public AudioDriver {
WAVEFORMATEX wave_format;
Microsoft::WRL::ComPtr<IXAudio2> xaudio;
int current_buffer;
- IXAudio2MasteringVoice* mastering_voice;
+ IXAudio2MasteringVoice *mastering_voice;
XAUDIO2_BUFFER xaudio_buffer[AUDIO_BUFFERS];
- IXAudio2SourceVoice* source_voice;
+ IXAudio2SourceVoice *source_voice;
XAudio2DriverVoiceCallback voice_callback;
public:
-
- const char* get_name() const;
+ const char *get_name() const;
virtual Error init();
virtual void start();