diff mbox

[Branch,~glmark2-dev/glmark2/trunk] Rev 276: Scene{Shadow, Refract}: When testing on Nexus 10, it was discovered that the

Message ID 20130612175814.17380.30982.launchpad@ackee.canonical.com
State Accepted
Headers show

Commit Message

Jesse Barker June 12, 2013, 5:58 p.m. UTC
------------------------------------------------------------
revno: 276
committer: Jesse Barker <jesse.barker@linaro.org>
branch nick: trunk
timestamp: Wed 2013-06-12 10:54:21 -0700
message:
  Scene{Shadow,Refract}: When testing on Nexus 10, it was discovered that the
  default texture allocation for these scenes can blow out the max texture size
  for an implementation (canvas size on that platform is 2560 x 1504, which
  makes us try to allocate textures at 5120 x 3008).  So, clamp the texture
  dimensions while maintaining proper aspect ratio.
modified:
  src/scene-refract.cpp
  src/scene-shadow.cpp


--
lp:glmark2
https://code.launchpad.net/~glmark2-dev/glmark2/trunk

You are subscribed to branch lp:glmark2.
To unsubscribe from this branch go to https://code.launchpad.net/~glmark2-dev/glmark2/trunk/+edit-subscription
diff mbox

Patch

=== modified file 'src/scene-refract.cpp'
--- src/scene-refract.cpp	2013-01-29 17:17:28 +0000
+++ src/scene-refract.cpp	2013-06-12 17:54:21 +0000
@@ -176,19 +176,32 @@ 
 bool
 DistanceRenderTarget::setup(unsigned int width, unsigned int height)
 {
+    static const string vtx_shader_filename(GLMARK_DATA_PATH"/shaders/depth.vert");
+    static const string frg_shader_filename(GLMARK_DATA_PATH"/shaders/depth.frag");
+
+    ShaderSource vtx_source(vtx_shader_filename);
+    ShaderSource frg_source(frg_shader_filename);
+
+    if (!Scene::load_shaders_from_strings(program_, vtx_source.str(), frg_source.str())) {
+        return false;
+    }
+
     canvas_width_ = width;
     canvas_height_ = height;
     width_ = canvas_width_ * 2;
     height_ = canvas_height_ * 2;
 
-    static const string vtx_shader_filename(GLMARK_DATA_PATH"/shaders/depth.vert");
-    static const string frg_shader_filename(GLMARK_DATA_PATH"/shaders/depth.frag");
-
-    ShaderSource vtx_source(vtx_shader_filename);
-    ShaderSource frg_source(frg_shader_filename);
-
-    if (!Scene::load_shaders_from_strings(program_, vtx_source.str(), frg_source.str())) {
-        return false;
+    // If the texture will be too large for the implemnetation, we need to
+    // clamp the dimensions but maintain the aspect ratio.
+    GLint tex_size(0);
+    glGetIntegerv(GL_MAX_TEXTURE_SIZE, &tex_size);
+    unsigned int max_size = static_cast<unsigned int>(tex_size);
+    if (max_size < width_ || max_size < height_) {
+        float aspect = static_cast<float>(width) / static_cast<float>(height);
+        width_ = max_size;
+        height_ = width_ / aspect;
+        Log::debug("DistanceRenderTarget::setup: original texture size (%u x %u), clamped to (%u x %u)\n",
+            canvas_width_ * 2, canvas_height_ * 2, width_, height_);
     }
 
     glGenTextures(2, &tex_[0]);
@@ -217,7 +230,7 @@ 
                            tex_[COLOR], 0);
     unsigned int status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
     if (status != GL_FRAMEBUFFER_COMPLETE) {
-        Log::error("DepthRenderState::setup: glCheckFramebufferStatus failed (0x%x)\n", status);
+        Log::error("DistanceRenderTarget::setup: glCheckFramebufferStatus failed (0x%x)\n", status);
         return false;
     }
     glBindFramebuffer(GL_FRAMEBUFFER, 0);

=== modified file 'src/scene-shadow.cpp'
--- src/scene-shadow.cpp	2013-01-29 17:17:28 +0000
+++ src/scene-shadow.cpp	2013-06-12 17:54:21 +0000
@@ -73,19 +73,32 @@ 
 bool
 DepthRenderTarget::setup(unsigned int width, unsigned int height)
 {
+    static const string vtx_shader_filename(GLMARK_DATA_PATH"/shaders/depth.vert");
+    static const string frg_shader_filename(GLMARK_DATA_PATH"/shaders/depth.frag");
+
+    ShaderSource vtx_source(vtx_shader_filename);
+    ShaderSource frg_source(frg_shader_filename);
+
+    if (!Scene::load_shaders_from_strings(program_, vtx_source.str(), frg_source.str())) {
+        return false;
+    }
+
     canvas_width_ = width;
     canvas_height_ = height;
     width_ = canvas_width_ * 2;
     height_ = canvas_height_ * 2;
 
-    static const string vtx_shader_filename(GLMARK_DATA_PATH"/shaders/depth.vert");
-    static const string frg_shader_filename(GLMARK_DATA_PATH"/shaders/depth.frag");
-
-    ShaderSource vtx_source(vtx_shader_filename);
-    ShaderSource frg_source(frg_shader_filename);
-
-    if (!Scene::load_shaders_from_strings(program_, vtx_source.str(), frg_source.str())) {
-        return false;
+    // If the texture will be too large for the implemnetation, we need to
+    // clamp the dimensions but maintain the aspect ratio.
+    GLint tex_size(0);
+    glGetIntegerv(GL_MAX_TEXTURE_SIZE, &tex_size);
+    unsigned int max_size = static_cast<unsigned int>(tex_size);
+    if (max_size < width_ || max_size < height_) {
+        float aspect = static_cast<float>(width) / static_cast<float>(height);
+        width_ = max_size;
+        height_ = width_ / aspect;
+        Log::debug("DepthRenderTarget::setup: original texture size (%u x %u), clamped to (%u x %u)\n",
+            canvas_width_ * 2, canvas_height_ * 2, width_, height_);
     }
 
     glGenTextures(1, &tex_);
@@ -104,7 +117,7 @@ 
                            tex_, 0);
     unsigned int status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
     if (status != GL_FRAMEBUFFER_COMPLETE) {
-        Log::error("DepthRenderState::setup: glCheckFramebufferStatus failed (0x%x)\n", status);
+        Log::error("DepthRenderTarget::setup: glCheckFramebufferStatus failed (0x%x)\n", status);
         return false;
     }
     glBindFramebuffer(GL_FRAMEBUFFER, 0);