Skip to content

Commit

Permalink
Make query for GL_MAX_VIEWPORT_DIMS compatible with web exports
Browse files Browse the repository at this point in the history
  • Loading branch information
patwork committed Jun 13, 2024
1 parent 680e489 commit ed5f33e
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 22 deletions.
3 changes: 1 addition & 2 deletions drivers/gles3/rasterizer_canvas_gles3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2742,8 +2742,7 @@ RasterizerCanvasGLES3::RasterizerCanvasGLES3() {
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}

int uniform_max_size = config->max_uniform_buffer_size;
if (uniform_max_size < 65536) {
if (config->max_uniform_buffer_size < 65536) {
data.max_lights_per_render = 64;
} else {
data.max_lights_per_render = 256;
Expand Down
3 changes: 1 addition & 2 deletions drivers/gles3/rasterizer_gles3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,7 @@ void RasterizerGLES3::_blit_render_target_to_screen(RID p_render_target, Display
// Viewport doesn't cover entire window so clear window to black before blitting.
// Querying the actual window size from the DisplayServer would deadlock in separate render thread mode,
// so let's set the biggest viewport the implementation supports, to be sure the window is fully covered.
GLsizei max_vp[2] = {};
glGetIntegerv(GL_MAX_VIEWPORT_DIMS, max_vp);
Size2i max_vp = GLES3::Utilities::get_singleton()->get_maximum_viewport_size();
glViewport(0, 0, max_vp[0], max_vp[1]);
glClearColor(0.0, 0.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
Expand Down
5 changes: 4 additions & 1 deletion drivers/gles3/shader_gles3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "core/io/file_access.h"

#include "drivers/gles3/rasterizer_gles3.h"
#include "drivers/gles3/storage/config.h"

static String _mkid(const String &p_id) {
String id = "m_" + p_id.replace("__", "_dus_");
Expand Down Expand Up @@ -801,7 +802,9 @@ void ShaderGLES3::initialize(const String &p_general_defines, int p_base_texture
print_verbose("Shader '" + name + "' SHA256: " + base_sha256);
}

glGetInteger64v(GL_MAX_TEXTURE_IMAGE_UNITS, &max_image_units);
GLES3::Config *config = GLES3::Config::get_singleton();
ERR_FAIL_NULL(config);
max_image_units = config->max_texture_image_units;
}

void ShaderGLES3::set_shader_cache_dir(const String &p_dir) {
Expand Down
2 changes: 1 addition & 1 deletion drivers/gles3/shader_gles3.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class ShaderGLES3 {
static bool shader_cache_save_debug;
bool shader_cache_dir_valid = false;

int64_t max_image_units = 0;
GLint max_image_units = 0;

enum StageType {
STAGE_TYPE_VERTEX,
Expand Down
17 changes: 10 additions & 7 deletions drivers/gles3/storage/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ Config::Config() {
singleton = this;

{
int64_t max_extensions = 0;
glGetInteger64v(GL_NUM_EXTENSIONS, &max_extensions);
for (int64_t i = 0; i < max_extensions; i++) {
GLint max_extensions = 0;
glGetIntegerv(GL_NUM_EXTENSIONS, &max_extensions);
for (int i = 0; i < max_extensions; i++) {
const GLubyte *s = glGetStringi(GL_EXTENSIONS, i);
if (!s) {
break;
Expand Down Expand Up @@ -80,11 +80,14 @@ Config::Config() {
rgtc_supported = extensions.has("GL_EXT_texture_compression_rgtc") || extensions.has("GL_ARB_texture_compression_rgtc") || extensions.has("EXT_texture_compression_rgtc");
}

glGetInteger64v(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &max_vertex_texture_image_units);
glGetInteger64v(GL_MAX_TEXTURE_IMAGE_UNITS, &max_texture_image_units);
glGetInteger64v(GL_MAX_TEXTURE_SIZE, &max_texture_size);
glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &max_vertex_texture_image_units);
glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &max_texture_image_units);
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size);
glGetIntegerv(GL_MAX_VIEWPORT_DIMS, max_viewport_size);
glGetInteger64v(GL_MAX_UNIFORM_BLOCK_SIZE, &max_uniform_buffer_size);
glGetInteger64v(GL_MAX_VIEWPORT_DIMS, max_viewport_size);

// sanity clamp buffer size to 16K..1MB
max_uniform_buffer_size = CLAMP(max_uniform_buffer_size, 16384, 1048576);

support_anisotropic_filter = extensions.has("GL_EXT_texture_filter_anisotropic");
if (support_anisotropic_filter) {
Expand Down
11 changes: 6 additions & 5 deletions drivers/gles3/storage/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,12 @@ class Config {
bool use_nearest_mip_filter = false;
bool use_depth_prepass = true;

int64_t max_vertex_texture_image_units = 0;
int64_t max_texture_image_units = 0;
int64_t max_texture_size = 0;
int64_t max_viewport_size[2] = { 0, 0 };
int64_t max_uniform_buffer_size = 0;
GLint max_vertex_texture_image_units = 0;
GLint max_texture_image_units = 0;
GLint max_texture_size = 0;
GLint max_viewport_size[2] = { 0, 0 };
GLint64 max_uniform_buffer_size = 0;

int64_t max_renderable_elements = 0;
int64_t max_renderable_lights = 0;
int64_t max_lights_per_object = 0;
Expand Down
5 changes: 1 addition & 4 deletions drivers/gles3/storage/utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -463,10 +463,7 @@ String Utilities::get_video_adapter_api_version() const {

Size2i Utilities::get_maximum_viewport_size() const {
Config *config = Config::get_singleton();
if (!config) {
return Size2i();
}

ERR_FAIL_NULL_V(config, Size2i());
return Size2i(config->max_viewport_size[0], config->max_viewport_size[1]);
}

Expand Down

0 comments on commit ed5f33e

Please sign in to comment.