/* * Copyright © 2009 Intel Corporation * Copyright © 2010 Red Hat, Inc. * * 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 (including the next * paragraph) 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. * * Authors: * Shuang He * */ /** @file fbo-copytex-depth-max.c * * Tests that glCopyTexImage2D can be used to copy from fbo with max supported size * into depth texture. */ #include "piglit-util.h" int piglit_width = 100; int piglit_height = 100; int piglit_window_mode = GLUT_DOUBLE | GLUT_RGB; enum piglit_result piglit_display(void) { GLboolean pass = GL_TRUE; GLuint tex, fb, rb; GLint maxTextureSize, maxRenderbufferSize, textureSize; GLenum status; GLubyte *depth = NULL; glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize); glGetIntegerv(GL_MAX_RENDERBUFFER_SIZE, &maxRenderbufferSize); textureSize = (maxTextureSize > maxRenderbufferSize) ? maxRenderbufferSize:maxTextureSize; glGenTextures(1, &tex); glBindTexture(GL_TEXTURE_2D, tex); glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, textureSize, textureSize, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL); assert(glGetError() == 0); glGenFramebuffersEXT(1, &fb); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb); glGenRenderbuffersEXT(1, &rb); glBindRenderbufferEXT(GL_RENDERBUFFER, rb); glRenderbufferStorageEXT(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, textureSize, textureSize); glFramebufferRenderbufferEXT(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rb); glDrawBuffer(GL_NONE); glReadBuffer(GL_NONE); assert(glGetError() == 0); status = glCheckFramebufferStatusEXT (GL_FRAMEBUFFER_EXT); if (status != GL_FRAMEBUFFER_COMPLETE_EXT) { fprintf(stderr, "FBO incomplete\n"); piglit_report_result(PIGLIT_SKIP); } glClearDepth(0.5); glClear(GL_DEPTH_BUFFER_BIT); glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 0, 0, 100, 100, 0); depth = malloc(sizeof(GLubyte) * textureSize * textureSize); glGetTexImage(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, depth); if (depth[0] != 127) pass = GL_FALSE; glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); free(depth); glDeleteRenderbuffersEXT(1, &rb); glDeleteFramebuffersEXT(1, &fb); glDeleteTextures(1, &tex); return pass ? PIGLIT_PASS : PIGLIT_FAIL; } void piglit_init(int argc, char **argv) { piglit_require_extension("GL_EXT_framebuffer_object"); }