Skip to content

Commit

Permalink
Merge pull request godotengine#45982 from clayjohn/GLES2-max-dims
Browse files Browse the repository at this point in the history
Check limits on texture or framebuffer creation
  • Loading branch information
akien-mga authored Feb 14, 2021
2 parents ab252c3 + 7efcafd commit a1222e4
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
19 changes: 19 additions & 0 deletions drivers/gles2/rasterizer_scene_gles2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ void RasterizerSceneGLES2::shadow_atlas_set_size(RID p_atlas, int p_size) {
glGenFramebuffers(1, &shadow_atlas->fbo);
glBindFramebuffer(GL_FRAMEBUFFER, shadow_atlas->fbo);

if (shadow_atlas->size > storage->config.max_viewport_dimensions[0] || shadow_atlas->size > storage->config.max_viewport_dimensions[1]) {
WARN_PRINTS("Cannot set shadow atlas size larger than maximum hardware supported size of (" + itos(storage->config.max_viewport_dimensions[0]) + ", " + itos(storage->config.max_viewport_dimensions[1]) + "). Setting size to maximum.");
shadow_atlas->size = MIN(shadow_atlas->size, storage->config.max_viewport_dimensions[0]);
shadow_atlas->size = MIN(shadow_atlas->size, storage->config.max_viewport_dimensions[1]);
}

// create a depth texture
glActiveTexture(GL_TEXTURE0);

Expand Down Expand Up @@ -540,6 +546,13 @@ bool RasterizerSceneGLES2::reflection_probe_instance_begin_render(RID p_instance

//update cubemap if resolution changed
int size = rpi->probe_ptr->resolution;

if (size > storage->config.max_viewport_dimensions[0] || size > storage->config.max_viewport_dimensions[1]) {
WARN_PRINT_ONCE("Cannot set reflection probe resolution larger than maximum hardware supported size of (" + itos(storage->config.max_viewport_dimensions[0]) + ", " + itos(storage->config.max_viewport_dimensions[1]) + "). Setting size to maximum.");
size = MIN(size, storage->config.max_viewport_dimensions[0]);
size = MIN(size, storage->config.max_viewport_dimensions[1]);
}

rpi->current_resolution = size;

GLenum internal_format = GL_RGB;
Expand Down Expand Up @@ -4011,6 +4024,12 @@ void RasterizerSceneGLES2::initialize() {
directional_shadow.light_count = 0;
directional_shadow.size = next_power_of_2(GLOBAL_GET("rendering/quality/directional_shadow/size"));

if (directional_shadow.size > storage->config.max_viewport_dimensions[0] || directional_shadow.size > storage->config.max_viewport_dimensions[1]) {
WARN_PRINTS("Cannot set directional shadow size larger than maximum hardware supported size of (" + itos(storage->config.max_viewport_dimensions[0]) + ", " + itos(storage->config.max_viewport_dimensions[1]) + "). Setting size to maximum.");
directional_shadow.size = MIN(directional_shadow.size, storage->config.max_viewport_dimensions[0]);
directional_shadow.size = MIN(directional_shadow.size, storage->config.max_viewport_dimensions[1]);
}

glGenFramebuffers(1, &directional_shadow.fbo);
glBindFramebuffer(GL_FRAMEBUFFER, directional_shadow.fbo);

Expand Down
14 changes: 14 additions & 0 deletions drivers/gles2/rasterizer_storage_gles2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,13 @@ void RasterizerStorageGLES2::texture_allocate(RID p_texture, int p_width, int p_
texture->width = p_width;
texture->height = p_height;
texture->format = p_format;

if (texture->width > config.max_texture_size || texture->height > config.max_texture_size) {
WARN_PRINTS("Cannot create texture larger than maximum hardware supported size of " + itos(config.max_texture_size) + ". Setting size to maximum.");
texture->width = MIN(texture->width, config.max_texture_size);
texture->height = MIN(texture->height, config.max_texture_size);
}

texture->flags = p_flags;
texture->stored_cube_sides = 0;
texture->type = p_type;
Expand Down Expand Up @@ -4740,6 +4747,12 @@ void RasterizerStorageGLES2::_render_target_allocate(RenderTarget *rt) {
return;
}

if (rt->width > config.max_viewport_dimensions[0] || rt->height > config.max_viewport_dimensions[1]) {
WARN_PRINTS("Cannot create render target larger than maximum hardware supported size of (" + itos(config.max_viewport_dimensions[0]) + ", " + itos(config.max_viewport_dimensions[1]) + "). Setting size to maximum.");
rt->width = MIN(rt->width, config.max_viewport_dimensions[0]);
rt->height = MIN(rt->height, config.max_viewport_dimensions[1]);
}

GLuint color_internal_format;
GLuint color_format;
GLuint color_type = GL_UNSIGNED_BYTE;
Expand Down Expand Up @@ -6176,6 +6189,7 @@ void RasterizerStorageGLES2::initialize() {
glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &config.max_vertex_texture_image_units);
glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &config.max_texture_image_units);
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &config.max_texture_size);
glGetIntegerv(GL_MAX_VIEWPORT_DIMS, config.max_viewport_dimensions);

// the use skeleton software path should be used if either float texture is not supported,
// OR max_vertex_texture_image_units is zero
Expand Down
1 change: 1 addition & 0 deletions drivers/gles2/rasterizer_storage_gles2.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class RasterizerStorageGLES2 : public RasterizerStorage {
int max_vertex_texture_image_units;
int max_texture_image_units;
int max_texture_size;
int max_viewport_dimensions[2];

// TODO implement wireframe in GLES2
// bool generate_wireframes;
Expand Down

0 comments on commit a1222e4

Please sign in to comment.