2020-11-18 19:11:30 +01:00
|
|
|
/**************************************************************************/
|
2021-10-26 17:18:39 +02:00
|
|
|
/* rasterizer_gles3.cpp */
|
2020-11-18 19:11:30 +01:00
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/**************************************************************************/
|
|
|
|
|
2021-10-26 17:18:39 +02:00
|
|
|
#include "rasterizer_gles3.h"
|
2022-06-21 02:08:33 +02:00
|
|
|
#include "storage/utilities.h"
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2021-11-16 16:25:42 +01:00
|
|
|
#ifdef GLES3_ENABLED
|
2020-11-18 19:11:30 +01:00
|
|
|
|
|
|
|
#include "core/config/project_settings.h"
|
2023-04-15 16:07:51 +02:00
|
|
|
#include "core/io/dir_access.h"
|
2020-11-18 19:11:30 +01:00
|
|
|
#include "core/os/os.h"
|
2022-04-07 16:00:51 +02:00
|
|
|
#include "storage/texture_storage.h"
|
2020-11-18 19:11:30 +01:00
|
|
|
|
|
|
|
#define _EXT_DEBUG_OUTPUT_SYNCHRONOUS_ARB 0x8242
|
|
|
|
#define _EXT_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH_ARB 0x8243
|
|
|
|
#define _EXT_DEBUG_CALLBACK_FUNCTION_ARB 0x8244
|
|
|
|
#define _EXT_DEBUG_CALLBACK_USER_PARAM_ARB 0x8245
|
|
|
|
#define _EXT_DEBUG_SOURCE_API_ARB 0x8246
|
|
|
|
#define _EXT_DEBUG_SOURCE_WINDOW_SYSTEM_ARB 0x8247
|
|
|
|
#define _EXT_DEBUG_SOURCE_SHADER_COMPILER_ARB 0x8248
|
|
|
|
#define _EXT_DEBUG_SOURCE_THIRD_PARTY_ARB 0x8249
|
|
|
|
#define _EXT_DEBUG_SOURCE_APPLICATION_ARB 0x824A
|
|
|
|
#define _EXT_DEBUG_SOURCE_OTHER_ARB 0x824B
|
|
|
|
#define _EXT_DEBUG_TYPE_ERROR_ARB 0x824C
|
|
|
|
#define _EXT_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB 0x824D
|
|
|
|
#define _EXT_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB 0x824E
|
|
|
|
#define _EXT_DEBUG_TYPE_PORTABILITY_ARB 0x824F
|
|
|
|
#define _EXT_DEBUG_TYPE_PERFORMANCE_ARB 0x8250
|
|
|
|
#define _EXT_DEBUG_TYPE_OTHER_ARB 0x8251
|
|
|
|
#define _EXT_MAX_DEBUG_MESSAGE_LENGTH_ARB 0x9143
|
|
|
|
#define _EXT_MAX_DEBUG_LOGGED_MESSAGES_ARB 0x9144
|
|
|
|
#define _EXT_DEBUG_LOGGED_MESSAGES_ARB 0x9145
|
|
|
|
#define _EXT_DEBUG_SEVERITY_HIGH_ARB 0x9146
|
|
|
|
#define _EXT_DEBUG_SEVERITY_MEDIUM_ARB 0x9147
|
|
|
|
#define _EXT_DEBUG_SEVERITY_LOW_ARB 0x9148
|
|
|
|
#define _EXT_DEBUG_OUTPUT 0x92E0
|
|
|
|
|
|
|
|
#ifndef GLAPIENTRY
|
2023-09-07 15:01:59 +02:00
|
|
|
#if defined(WINDOWS_ENABLED)
|
2020-11-18 19:11:30 +01:00
|
|
|
#define GLAPIENTRY APIENTRY
|
|
|
|
#else
|
|
|
|
#define GLAPIENTRY
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2022-08-28 20:27:45 +02:00
|
|
|
#if !defined(IOS_ENABLED) && !defined(WEB_ENABLED)
|
2020-11-18 19:11:30 +01:00
|
|
|
// We include EGL below to get debug callback on GLES2 platforms,
|
|
|
|
// but EGL is not available on iOS.
|
|
|
|
#define CAN_DEBUG
|
|
|
|
#endif
|
|
|
|
|
2021-11-12 13:49:49 +01:00
|
|
|
#include "platform_gl.h"
|
2020-11-18 19:11:30 +01:00
|
|
|
|
|
|
|
#if defined(MINGW_ENABLED) || defined(_MSC_VER)
|
|
|
|
#define strcpy strcpy_s
|
|
|
|
#endif
|
|
|
|
|
2021-11-12 13:49:49 +01:00
|
|
|
bool RasterizerGLES3::gles_over_gl = true;
|
|
|
|
|
2021-10-26 17:18:39 +02:00
|
|
|
void RasterizerGLES3::begin_frame(double frame_step) {
|
2020-11-18 19:11:30 +01:00
|
|
|
frame++;
|
|
|
|
delta = frame_step;
|
|
|
|
|
2021-11-16 16:25:42 +01:00
|
|
|
time_total += frame_step;
|
2020-11-18 19:11:30 +01:00
|
|
|
|
|
|
|
double time_roll_over = GLOBAL_GET("rendering/limits/time/time_rollover_secs");
|
|
|
|
time_total = Math::fmod(time_total, time_roll_over);
|
|
|
|
|
2022-02-20 01:08:53 +01:00
|
|
|
canvas->set_time(time_total);
|
|
|
|
scene->set_time(time_total, frame_step);
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2022-09-29 11:53:28 +02:00
|
|
|
GLES3::Utilities *utils = GLES3::Utilities::get_singleton();
|
2022-10-07 06:24:38 +02:00
|
|
|
utils->_capture_timestamps_begin();
|
2020-11-18 19:11:30 +01:00
|
|
|
|
|
|
|
//scene->iteration();
|
|
|
|
}
|
|
|
|
|
2021-10-26 17:18:39 +02:00
|
|
|
void RasterizerGLES3::end_frame(bool p_swap_buffers) {
|
2023-10-31 11:56:23 +01:00
|
|
|
GLES3::Utilities *utils = GLES3::Utilities::get_singleton();
|
|
|
|
utils->capture_timestamps_end();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RasterizerGLES3::end_viewport(bool p_swap_buffers) {
|
2021-11-16 16:25:42 +01:00
|
|
|
if (p_swap_buffers) {
|
2020-11-18 19:11:30 +01:00
|
|
|
DisplayServer::get_singleton()->swap_buffers();
|
2021-11-16 16:25:42 +01:00
|
|
|
} else {
|
2020-11-18 19:11:30 +01:00
|
|
|
glFinish();
|
2021-11-16 16:25:42 +01:00
|
|
|
}
|
2020-11-18 19:11:30 +01:00
|
|
|
}
|
|
|
|
|
2021-11-12 13:49:49 +01:00
|
|
|
void RasterizerGLES3::clear_depth(float p_depth) {
|
|
|
|
#ifdef GL_API_ENABLED
|
|
|
|
if (is_gles_over_gl()) {
|
|
|
|
glClearDepth(p_depth);
|
|
|
|
}
|
|
|
|
#endif // GL_API_ENABLED
|
|
|
|
#ifdef GLES_API_ENABLED
|
|
|
|
if (!is_gles_over_gl()) {
|
|
|
|
glClearDepthf(p_depth);
|
|
|
|
}
|
|
|
|
#endif // GLES_API_ENABLED
|
|
|
|
}
|
|
|
|
|
2020-11-18 19:11:30 +01:00
|
|
|
#ifdef CAN_DEBUG
|
|
|
|
static void GLAPIENTRY _gl_debug_print(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, const GLvoid *userParam) {
|
2022-01-27 17:34:33 +01:00
|
|
|
if (type == _EXT_DEBUG_TYPE_OTHER_ARB) {
|
2020-11-18 19:11:30 +01:00
|
|
|
return;
|
2022-01-27 17:34:33 +01:00
|
|
|
}
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2022-01-27 17:34:33 +01:00
|
|
|
if (type == _EXT_DEBUG_TYPE_PERFORMANCE_ARB) {
|
2020-11-18 19:11:30 +01:00
|
|
|
return; //these are ultimately annoying, so removing for now
|
2022-01-27 17:34:33 +01:00
|
|
|
}
|
2020-11-18 19:11:30 +01:00
|
|
|
|
|
|
|
char debSource[256], debType[256], debSev[256];
|
|
|
|
|
2022-01-27 17:34:33 +01:00
|
|
|
if (source == _EXT_DEBUG_SOURCE_API_ARB) {
|
2020-11-18 19:11:30 +01:00
|
|
|
strcpy(debSource, "OpenGL");
|
2022-01-27 17:34:33 +01:00
|
|
|
} else if (source == _EXT_DEBUG_SOURCE_WINDOW_SYSTEM_ARB) {
|
2020-11-18 19:11:30 +01:00
|
|
|
strcpy(debSource, "Windows");
|
2022-01-27 17:34:33 +01:00
|
|
|
} else if (source == _EXT_DEBUG_SOURCE_SHADER_COMPILER_ARB) {
|
2020-11-18 19:11:30 +01:00
|
|
|
strcpy(debSource, "Shader Compiler");
|
2022-01-27 17:34:33 +01:00
|
|
|
} else if (source == _EXT_DEBUG_SOURCE_THIRD_PARTY_ARB) {
|
2020-11-18 19:11:30 +01:00
|
|
|
strcpy(debSource, "Third Party");
|
2022-01-27 17:34:33 +01:00
|
|
|
} else if (source == _EXT_DEBUG_SOURCE_APPLICATION_ARB) {
|
2020-11-18 19:11:30 +01:00
|
|
|
strcpy(debSource, "Application");
|
2022-01-27 17:34:33 +01:00
|
|
|
} else if (source == _EXT_DEBUG_SOURCE_OTHER_ARB) {
|
2020-11-18 19:11:30 +01:00
|
|
|
strcpy(debSource, "Other");
|
2022-01-27 17:34:33 +01:00
|
|
|
}
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2022-01-27 17:34:33 +01:00
|
|
|
if (type == _EXT_DEBUG_TYPE_ERROR_ARB) {
|
2020-11-18 19:11:30 +01:00
|
|
|
strcpy(debType, "Error");
|
2022-01-27 17:34:33 +01:00
|
|
|
} else if (type == _EXT_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB) {
|
2020-11-18 19:11:30 +01:00
|
|
|
strcpy(debType, "Deprecated behavior");
|
2022-01-27 17:34:33 +01:00
|
|
|
} else if (type == _EXT_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB) {
|
2020-11-18 19:11:30 +01:00
|
|
|
strcpy(debType, "Undefined behavior");
|
2022-01-27 17:34:33 +01:00
|
|
|
} else if (type == _EXT_DEBUG_TYPE_PORTABILITY_ARB) {
|
2020-11-18 19:11:30 +01:00
|
|
|
strcpy(debType, "Portability");
|
2022-01-27 17:34:33 +01:00
|
|
|
} else if (type == _EXT_DEBUG_TYPE_PERFORMANCE_ARB) {
|
2020-11-18 19:11:30 +01:00
|
|
|
strcpy(debType, "Performance");
|
2022-01-27 17:34:33 +01:00
|
|
|
} else if (type == _EXT_DEBUG_TYPE_OTHER_ARB) {
|
2020-11-18 19:11:30 +01:00
|
|
|
strcpy(debType, "Other");
|
2022-01-27 17:34:33 +01:00
|
|
|
}
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2022-01-27 17:34:33 +01:00
|
|
|
if (severity == _EXT_DEBUG_SEVERITY_HIGH_ARB) {
|
2020-11-18 19:11:30 +01:00
|
|
|
strcpy(debSev, "High");
|
2022-01-27 17:34:33 +01:00
|
|
|
} else if (severity == _EXT_DEBUG_SEVERITY_MEDIUM_ARB) {
|
2020-11-18 19:11:30 +01:00
|
|
|
strcpy(debSev, "Medium");
|
2022-01-27 17:34:33 +01:00
|
|
|
} else if (severity == _EXT_DEBUG_SEVERITY_LOW_ARB) {
|
2020-11-18 19:11:30 +01:00
|
|
|
strcpy(debSev, "Low");
|
2022-01-27 17:34:33 +01:00
|
|
|
}
|
2020-11-18 19:11:30 +01:00
|
|
|
|
|
|
|
String output = String() + "GL ERROR: Source: " + debSource + "\tType: " + debType + "\tID: " + itos(id) + "\tSeverity: " + debSev + "\tMessage: " + message;
|
|
|
|
|
|
|
|
ERR_PRINT(output);
|
|
|
|
}
|
2021-10-26 17:18:39 +02:00
|
|
|
#endif
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2021-11-12 13:49:49 +01:00
|
|
|
typedef void(GLAPIENTRY *DEBUGPROCARB)(GLenum source,
|
2020-11-18 19:11:30 +01:00
|
|
|
GLenum type,
|
|
|
|
GLuint id,
|
|
|
|
GLenum severity,
|
|
|
|
GLsizei length,
|
|
|
|
const char *message,
|
|
|
|
const void *userParam);
|
|
|
|
|
2021-11-12 13:49:49 +01:00
|
|
|
typedef void(GLAPIENTRY *DebugMessageCallbackARB)(DEBUGPROCARB callback, const void *userParam);
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2021-10-26 17:18:39 +02:00
|
|
|
void RasterizerGLES3::initialize() {
|
2023-07-07 19:07:09 +02:00
|
|
|
Engine::get_singleton()->print_header(vformat("OpenGL API %s - Compatibility - Using Device: %s - %s", RS::get_singleton()->get_video_adapter_api_version(), RS::get_singleton()->get_video_adapter_vendor(), RS::get_singleton()->get_video_adapter_name()));
|
2024-01-19 00:07:28 +01:00
|
|
|
|
|
|
|
// FLIP XY Bug: Are more devices affected?
|
|
|
|
// Confirmed so far: all Adreno 3xx
|
|
|
|
// ok on some tested Adreno devices: 4xx, 5xx and 6xx
|
|
|
|
flip_xy_bugfix = GLES3::Config::get_singleton()->adreno_3xx_compatibility;
|
2022-02-20 01:08:53 +01:00
|
|
|
}
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2022-02-20 01:08:53 +01:00
|
|
|
void RasterizerGLES3::finalize() {
|
|
|
|
memdelete(scene);
|
|
|
|
memdelete(canvas);
|
2022-05-20 04:52:19 +02:00
|
|
|
memdelete(gi);
|
2022-06-21 02:08:33 +02:00
|
|
|
memdelete(fog);
|
2024-01-19 06:14:36 +01:00
|
|
|
memdelete(post_effects);
|
|
|
|
memdelete(glow);
|
2024-02-02 14:20:31 +01:00
|
|
|
memdelete(cubemap_filter);
|
2022-05-20 04:52:19 +02:00
|
|
|
memdelete(copy_effects);
|
2022-02-20 01:08:53 +01:00
|
|
|
memdelete(light_storage);
|
|
|
|
memdelete(particles_storage);
|
|
|
|
memdelete(mesh_storage);
|
|
|
|
memdelete(material_storage);
|
|
|
|
memdelete(texture_storage);
|
2022-06-21 02:08:33 +02:00
|
|
|
memdelete(utilities);
|
2022-02-20 01:08:53 +01:00
|
|
|
memdelete(config);
|
2022-04-19 18:54:30 +02:00
|
|
|
}
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2023-01-29 10:14:22 +01:00
|
|
|
RasterizerGLES3 *RasterizerGLES3::singleton = nullptr;
|
|
|
|
|
2021-11-12 13:49:49 +01:00
|
|
|
#ifdef EGL_ENABLED
|
|
|
|
void *_egl_load_function_wrapper(const char *p_name) {
|
|
|
|
return (void *)eglGetProcAddress(p_name);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-04-19 18:54:30 +02:00
|
|
|
RasterizerGLES3::RasterizerGLES3() {
|
2023-01-29 10:14:22 +01:00
|
|
|
singleton = this;
|
|
|
|
|
2020-11-18 19:11:30 +01:00
|
|
|
#ifdef GLAD_ENABLED
|
2021-11-12 13:49:49 +01:00
|
|
|
bool glad_loaded = false;
|
|
|
|
|
|
|
|
#ifdef EGL_ENABLED
|
|
|
|
// There should be a more flexible system for getting the GL pointer, as
|
|
|
|
// different DisplayServers can have different ways. We can just use the GLAD
|
|
|
|
// version global to see if it loaded for now though, otherwise we fall back to
|
|
|
|
// the generic loader below.
|
|
|
|
#if defined(EGL_STATIC)
|
|
|
|
bool has_egl = true;
|
|
|
|
#else
|
|
|
|
bool has_egl = (eglGetProcAddress != nullptr);
|
2020-11-18 19:11:30 +01:00
|
|
|
#endif
|
|
|
|
|
2021-11-12 13:49:49 +01:00
|
|
|
if (gles_over_gl) {
|
|
|
|
if (has_egl && !glad_loaded && gladLoadGL((GLADloadfunc)&_egl_load_function_wrapper)) {
|
|
|
|
glad_loaded = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (has_egl && !glad_loaded && gladLoadGLES2((GLADloadfunc)&_egl_load_function_wrapper)) {
|
|
|
|
glad_loaded = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // EGL_ENABLED
|
|
|
|
|
|
|
|
if (gles_over_gl) {
|
|
|
|
if (!glad_loaded && gladLoaderLoadGL()) {
|
|
|
|
glad_loaded = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!glad_loaded && gladLoaderLoadGLES2()) {
|
|
|
|
glad_loaded = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME this is an early return from a constructor. Any other code using this instance will crash or the finalizer will crash, because none of
|
|
|
|
// the members of this instance are initialized, so this just makes debugging harder. It should either crash here intentionally,
|
|
|
|
// or we need to actually test for this situation before constructing this.
|
|
|
|
ERR_FAIL_COND_MSG(!glad_loaded, "Error initializing GLAD.");
|
|
|
|
|
|
|
|
if (gles_over_gl) {
|
|
|
|
if (OS::get_singleton()->is_stdout_verbose()) {
|
|
|
|
if (GLAD_GL_ARB_debug_output) {
|
|
|
|
glEnable(_EXT_DEBUG_OUTPUT_SYNCHRONOUS_ARB);
|
|
|
|
glDebugMessageCallbackARB((GLDEBUGPROCARB)_gl_debug_print, nullptr);
|
|
|
|
glEnable(_EXT_DEBUG_OUTPUT);
|
|
|
|
} else {
|
|
|
|
print_line("OpenGL debugging not supported!");
|
|
|
|
}
|
2020-11-18 19:11:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // GLAD_ENABLED
|
|
|
|
|
|
|
|
// For debugging
|
|
|
|
#ifdef CAN_DEBUG
|
2021-11-12 13:49:49 +01:00
|
|
|
#ifdef GL_API_ENABLED
|
|
|
|
if (gles_over_gl) {
|
|
|
|
if (OS::get_singleton()->is_stdout_verbose() && GLAD_GL_ARB_debug_output) {
|
|
|
|
glDebugMessageControlARB(_EXT_DEBUG_SOURCE_API_ARB, _EXT_DEBUG_TYPE_ERROR_ARB, _EXT_DEBUG_SEVERITY_HIGH_ARB, 0, nullptr, GL_TRUE);
|
|
|
|
glDebugMessageControlARB(_EXT_DEBUG_SOURCE_API_ARB, _EXT_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB, _EXT_DEBUG_SEVERITY_HIGH_ARB, 0, nullptr, GL_TRUE);
|
|
|
|
glDebugMessageControlARB(_EXT_DEBUG_SOURCE_API_ARB, _EXT_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB, _EXT_DEBUG_SEVERITY_HIGH_ARB, 0, nullptr, GL_TRUE);
|
|
|
|
glDebugMessageControlARB(_EXT_DEBUG_SOURCE_API_ARB, _EXT_DEBUG_TYPE_PORTABILITY_ARB, _EXT_DEBUG_SEVERITY_HIGH_ARB, 0, nullptr, GL_TRUE);
|
|
|
|
glDebugMessageControlARB(_EXT_DEBUG_SOURCE_API_ARB, _EXT_DEBUG_TYPE_PERFORMANCE_ARB, _EXT_DEBUG_SEVERITY_HIGH_ARB, 0, nullptr, GL_TRUE);
|
|
|
|
glDebugMessageControlARB(_EXT_DEBUG_SOURCE_API_ARB, _EXT_DEBUG_TYPE_OTHER_ARB, _EXT_DEBUG_SEVERITY_HIGH_ARB, 0, nullptr, GL_TRUE);
|
2020-11-18 19:11:30 +01:00
|
|
|
}
|
2021-11-12 13:49:49 +01:00
|
|
|
}
|
|
|
|
#endif // GL_API_ENABLED
|
|
|
|
#ifdef GLES_API_ENABLED
|
|
|
|
if (!gles_over_gl) {
|
|
|
|
if (OS::get_singleton()->is_stdout_verbose()) {
|
|
|
|
DebugMessageCallbackARB callback = (DebugMessageCallbackARB)eglGetProcAddress("glDebugMessageCallback");
|
|
|
|
if (!callback) {
|
|
|
|
callback = (DebugMessageCallbackARB)eglGetProcAddress("glDebugMessageCallbackKHR");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (callback) {
|
|
|
|
print_line("godot: ENABLING GL DEBUG");
|
|
|
|
glEnable(_EXT_DEBUG_OUTPUT_SYNCHRONOUS_ARB);
|
2024-03-12 15:40:40 +01:00
|
|
|
callback((DEBUGPROCARB)_gl_debug_print, nullptr);
|
2021-11-12 13:49:49 +01:00
|
|
|
glEnable(_EXT_DEBUG_OUTPUT);
|
|
|
|
}
|
2020-11-18 19:11:30 +01:00
|
|
|
}
|
|
|
|
}
|
2021-11-12 13:49:49 +01:00
|
|
|
#endif // GLES_API_ENABLED
|
2020-11-18 19:11:30 +01:00
|
|
|
#endif // CAN_DEBUG
|
|
|
|
|
2023-04-15 16:07:51 +02:00
|
|
|
{
|
|
|
|
String shader_cache_dir = Engine::get_singleton()->get_shader_cache_path();
|
|
|
|
if (shader_cache_dir.is_empty()) {
|
|
|
|
shader_cache_dir = "user://";
|
|
|
|
}
|
|
|
|
Ref<DirAccess> da = DirAccess::open(shader_cache_dir);
|
|
|
|
if (da.is_null()) {
|
|
|
|
ERR_PRINT("Can't create shader cache folder, no shader caching will happen: " + shader_cache_dir);
|
|
|
|
} else {
|
|
|
|
Error err = da->change_dir("shader_cache");
|
|
|
|
if (err != OK) {
|
|
|
|
err = da->make_dir("shader_cache");
|
|
|
|
}
|
|
|
|
if (err != OK) {
|
|
|
|
ERR_PRINT("Can't create shader cache folder, no shader caching will happen: " + shader_cache_dir);
|
|
|
|
} else {
|
|
|
|
shader_cache_dir = shader_cache_dir.path_join("shader_cache");
|
|
|
|
|
|
|
|
bool shader_cache_enabled = GLOBAL_GET("rendering/shader_compiler/shader_cache/enabled");
|
|
|
|
if (!Engine::get_singleton()->is_editor_hint() && !shader_cache_enabled) {
|
|
|
|
shader_cache_dir = String(); //disable only if not editor
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!shader_cache_dir.is_empty()) {
|
|
|
|
ShaderGLES3::set_shader_cache_dir(shader_cache_dir);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-19 18:54:30 +02:00
|
|
|
// OpenGL needs to be initialized before initializing the Rasterizers
|
|
|
|
config = memnew(GLES3::Config);
|
2022-06-21 02:08:33 +02:00
|
|
|
utilities = memnew(GLES3::Utilities);
|
2022-04-19 18:54:30 +02:00
|
|
|
texture_storage = memnew(GLES3::TextureStorage);
|
|
|
|
material_storage = memnew(GLES3::MaterialStorage);
|
|
|
|
mesh_storage = memnew(GLES3::MeshStorage);
|
|
|
|
particles_storage = memnew(GLES3::ParticlesStorage);
|
|
|
|
light_storage = memnew(GLES3::LightStorage);
|
2022-05-18 17:04:41 +02:00
|
|
|
copy_effects = memnew(GLES3::CopyEffects);
|
2024-02-02 14:20:31 +01:00
|
|
|
cubemap_filter = memnew(GLES3::CubemapFilter);
|
2024-01-19 06:14:36 +01:00
|
|
|
glow = memnew(GLES3::Glow);
|
|
|
|
post_effects = memnew(GLES3::PostEffects);
|
2022-05-20 04:52:19 +02:00
|
|
|
gi = memnew(GLES3::GI);
|
2022-06-21 02:08:33 +02:00
|
|
|
fog = memnew(GLES3::Fog);
|
|
|
|
canvas = memnew(RasterizerCanvasGLES3());
|
|
|
|
scene = memnew(RasterizerSceneGLES3());
|
2020-11-18 19:11:30 +01:00
|
|
|
}
|
|
|
|
|
2022-04-19 18:54:30 +02:00
|
|
|
RasterizerGLES3::~RasterizerGLES3() {
|
2020-11-18 19:11:30 +01:00
|
|
|
}
|
|
|
|
|
2023-02-21 04:18:23 +01:00
|
|
|
void RasterizerGLES3::_blit_render_target_to_screen(RID p_render_target, DisplayServer::WindowID p_screen, const Rect2 &p_screen_rect, uint32_t p_layer, bool p_first) {
|
2022-09-29 11:53:28 +02:00
|
|
|
GLES3::RenderTarget *rt = GLES3::TextureStorage::get_singleton()->get_render_target(p_render_target);
|
2022-09-04 16:56:24 +02:00
|
|
|
|
2023-09-09 17:46:44 +02:00
|
|
|
ERR_FAIL_NULL(rt);
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2022-12-04 21:09:52 +01:00
|
|
|
// We normally render to the render target upside down, so flip Y when blitting to the screen.
|
|
|
|
bool flip_y = true;
|
|
|
|
if (rt->overridden.color.is_valid()) {
|
|
|
|
// If we've overridden the render target's color texture, that means we
|
|
|
|
// didn't render upside down, so we don't need to flip it.
|
|
|
|
// We're probably rendering directly to an XR device.
|
|
|
|
flip_y = false;
|
|
|
|
}
|
|
|
|
|
2022-09-04 16:56:24 +02:00
|
|
|
GLuint read_fbo = 0;
|
2023-03-15 17:55:10 +01:00
|
|
|
glGenFramebuffers(1, &read_fbo);
|
|
|
|
glBindFramebuffer(GL_READ_FRAMEBUFFER, read_fbo);
|
|
|
|
|
2022-09-04 16:56:24 +02:00
|
|
|
if (rt->view_count > 1) {
|
|
|
|
glFramebufferTextureLayer(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, rt->color, 0, p_layer);
|
|
|
|
} else {
|
2023-03-15 17:55:10 +01:00
|
|
|
glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, rt->color, 0);
|
2022-09-04 16:56:24 +02:00
|
|
|
}
|
|
|
|
|
2021-11-16 16:25:42 +01:00
|
|
|
glReadBuffer(GL_COLOR_ATTACHMENT0);
|
2022-04-07 16:00:51 +02:00
|
|
|
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, GLES3::TextureStorage::system_fbo);
|
2023-02-14 19:30:02 +01:00
|
|
|
|
2023-02-21 04:18:23 +01:00
|
|
|
if (p_first) {
|
2023-02-14 19:30:02 +01:00
|
|
|
Size2i win_size = DisplayServer::get_singleton()->window_get_size();
|
2023-02-21 04:18:23 +01:00
|
|
|
if (p_screen_rect.position != Vector2() || p_screen_rect.size != rt->size) {
|
|
|
|
// Viewport doesn't cover entire window so clear window to black before blitting.
|
|
|
|
glViewport(0, 0, win_size.width, win_size.height);
|
|
|
|
glClearColor(0.0, 0.0, 0.0, 1.0);
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
}
|
2023-02-14 19:30:02 +01:00
|
|
|
}
|
|
|
|
|
2022-09-04 16:56:24 +02:00
|
|
|
Vector2i screen_rect_end = p_screen_rect.get_end();
|
2024-01-19 00:07:28 +01:00
|
|
|
|
|
|
|
// Adreno (TM) 3xx devices have a bug that create wrong Landscape rotation of 180 degree
|
|
|
|
// Reversing both the X and Y axis is equivalent to rotating 180 degrees
|
|
|
|
bool flip_x = false;
|
|
|
|
if (flip_xy_bugfix && screen_rect_end.x > screen_rect_end.y) {
|
|
|
|
flip_y = !flip_y;
|
|
|
|
flip_x = !flip_x;
|
|
|
|
}
|
|
|
|
|
2022-09-04 16:56:24 +02:00
|
|
|
glBlitFramebuffer(0, 0, rt->size.x, rt->size.y,
|
2024-01-19 00:07:28 +01:00
|
|
|
flip_x ? screen_rect_end.x : p_screen_rect.position.x, flip_y ? screen_rect_end.y : p_screen_rect.position.y,
|
|
|
|
flip_x ? p_screen_rect.position.x : screen_rect_end.x, flip_y ? p_screen_rect.position.y : screen_rect_end.y,
|
2022-09-04 16:56:24 +02:00
|
|
|
GL_COLOR_BUFFER_BIT, GL_NEAREST);
|
|
|
|
|
|
|
|
if (read_fbo != 0) {
|
2024-02-24 01:38:34 +01:00
|
|
|
glBindFramebuffer(GL_READ_FRAMEBUFFER, GLES3::TextureStorage::system_fbo);
|
2022-09-04 16:56:24 +02:00
|
|
|
glDeleteFramebuffers(1, &read_fbo);
|
|
|
|
}
|
2020-11-18 19:11:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// is this p_screen useless in a multi window environment?
|
2021-10-26 17:18:39 +02:00
|
|
|
void RasterizerGLES3::blit_render_targets_to_screen(DisplayServer::WindowID p_screen, const BlitToScreen *p_render_targets, int p_amount) {
|
2020-11-18 19:11:30 +01:00
|
|
|
for (int i = 0; i < p_amount; i++) {
|
|
|
|
const BlitToScreen &blit = p_render_targets[i];
|
|
|
|
|
|
|
|
RID rid_rt = blit.render_target;
|
|
|
|
|
|
|
|
Rect2 dst_rect = blit.dst_rect;
|
2023-02-21 04:18:23 +01:00
|
|
|
_blit_render_target_to_screen(rid_rt, p_screen, dst_rect, blit.multi_view.use_layer ? blit.multi_view.layer : 0, i == 0);
|
2020-11-18 19:11:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-19 16:09:52 +01:00
|
|
|
void RasterizerGLES3::set_boot_image(const Ref<Image> &p_image, const Color &p_color, bool p_scale, bool p_use_filter) {
|
2022-01-27 17:34:33 +01:00
|
|
|
if (p_image.is_null() || p_image->is_empty()) {
|
2020-11-18 19:11:30 +01:00
|
|
|
return;
|
2022-01-27 17:34:33 +01:00
|
|
|
}
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2022-12-16 22:27:33 +01:00
|
|
|
Size2i win_size = DisplayServer::get_singleton()->window_get_size();
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2024-02-24 01:38:34 +01:00
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, GLES3::TextureStorage::system_fbo);
|
2022-01-19 16:09:52 +01:00
|
|
|
glViewport(0, 0, win_size.width, win_size.height);
|
2022-12-16 22:27:33 +01:00
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ZERO, GL_ONE);
|
2020-11-18 19:11:30 +01:00
|
|
|
glDepthMask(GL_FALSE);
|
2022-12-16 22:27:33 +01:00
|
|
|
glClearColor(p_color.r, p_color.g, p_color.b, 1.0);
|
2020-11-18 19:11:30 +01:00
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
|
2022-02-20 01:08:53 +01:00
|
|
|
RID texture = texture_storage->texture_allocate();
|
|
|
|
texture_storage->texture_2d_initialize(texture, p_image);
|
2020-11-18 19:11:30 +01:00
|
|
|
|
|
|
|
Rect2 imgrect(0, 0, p_image->get_width(), p_image->get_height());
|
|
|
|
Rect2 screenrect;
|
2022-01-19 16:09:52 +01:00
|
|
|
if (p_scale) {
|
|
|
|
if (win_size.width > win_size.height) {
|
|
|
|
//scale horizontally
|
|
|
|
screenrect.size.y = win_size.height;
|
|
|
|
screenrect.size.x = imgrect.size.x * win_size.height / imgrect.size.y;
|
|
|
|
screenrect.position.x = (win_size.width - screenrect.size.x) / 2;
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2022-01-19 16:09:52 +01:00
|
|
|
} else {
|
|
|
|
//scale vertically
|
|
|
|
screenrect.size.x = win_size.width;
|
|
|
|
screenrect.size.y = imgrect.size.y * win_size.width / imgrect.size.x;
|
|
|
|
screenrect.position.y = (win_size.height - screenrect.size.y) / 2;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
screenrect = imgrect;
|
|
|
|
screenrect.position += ((Size2(win_size.width, win_size.height) - screenrect.size) / 2.0).floor();
|
|
|
|
}
|
2021-10-25 19:27:12 +02:00
|
|
|
|
2022-12-16 22:27:33 +01:00
|
|
|
// Flip Y.
|
|
|
|
screenrect.position.y = win_size.y - screenrect.position.y;
|
|
|
|
screenrect.size.y = -screenrect.size.y;
|
|
|
|
|
|
|
|
// Normalize texture coordinates to window size.
|
|
|
|
screenrect.position /= win_size;
|
|
|
|
screenrect.size /= win_size;
|
|
|
|
|
2022-04-19 18:54:30 +02:00
|
|
|
GLES3::Texture *t = texture_storage->get_texture(texture);
|
2022-12-16 22:27:33 +01:00
|
|
|
t->gl_set_filter(p_use_filter ? RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR : RS::CANVAS_ITEM_TEXTURE_FILTER_NEAREST);
|
|
|
|
glActiveTexture(GL_TEXTURE0);
|
2020-11-18 19:11:30 +01:00
|
|
|
glBindTexture(GL_TEXTURE_2D, t->tex_id);
|
2022-12-16 22:27:33 +01:00
|
|
|
copy_effects->copy_to_rect(screenrect);
|
2020-11-18 19:11:30 +01:00
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
|
|
|
|
2023-10-31 11:56:23 +01:00
|
|
|
end_viewport(true);
|
2022-12-16 22:27:33 +01:00
|
|
|
|
|
|
|
texture_storage->texture_free(texture);
|
2020-11-18 19:11:30 +01:00
|
|
|
}
|
|
|
|
|
2021-11-16 16:25:42 +01:00
|
|
|
#endif // GLES3_ENABLED
|