summaryrefslogtreecommitdiff
path: root/drivers/gles3/rasterizer_gles3.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gles3/rasterizer_gles3.cpp')
-rw-r--r--drivers/gles3/rasterizer_gles3.cpp249
1 files changed, 114 insertions, 135 deletions
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() {