/** * Iterate through array of texture formats and check if call to TextureView * causes the gl error "err" */ static bool check_format_array(const GLenum err, const unsigned int numFormats, const GLenum *formatArray, const GLenum target, const GLuint tex, const GLuint levels, const GLuint layers) { unsigned int i; bool pass = true; for (i = 0; i < numFormats; i++) { GLenum format; GLuint newTex; format = formatArray[i]; if (format == 0) continue; glGenTextures(1, &newTex); glTextureView(newTex, target, tex, format, 0, levels, 0, layers); glDeleteTextures(1, &newTex); if (!piglit_check_gl_error(err)) { printf("failing texView format=%s\n", piglit_get_gl_enum_name(format)); pass = false; break; } } return pass; }
EXTERN_C_ENTER JNIEXPORT void JNICALL Java_org_lwjgl_opengl_ARBTextureView_glTextureView(JNIEnv *__env, jclass clazz, jint texture, jint target, jint origtexture, jint internalformat, jint minlevel, jint numlevels, jint minlayer, jint numlayers) { glTextureViewPROC glTextureView = (glTextureViewPROC)tlsGetFunction(906); UNUSED_PARAM(clazz) glTextureView(texture, target, origtexture, internalformat, minlevel, numlevels, minlayer, numlayers); }
static void wined3d_shader_resource_view_create_texture_view(struct wined3d_shader_resource_view *view, const struct wined3d_shader_resource_view_desc *desc, struct wined3d_texture *texture, const struct wined3d_format *view_format) { const struct wined3d_gl_info *gl_info; struct wined3d_context *context; struct gl_texture *gl_texture; context = context_acquire(texture->resource.device, NULL); gl_info = context->gl_info; if (!gl_info->supported[ARB_TEXTURE_VIEW]) { context_release(context); FIXME("OpenGL implementation does not support texture views.\n"); return; } wined3d_texture_prepare_texture(texture, context, FALSE); gl_texture = wined3d_texture_get_gl_texture(texture, FALSE); gl_info->gl_ops.gl.p_glGenTextures(1, &view->object); GL_EXTCALL(glTextureView(view->object, view->target, gl_texture->name, view_format->glInternal, desc->u.texture.level_idx, desc->u.texture.level_count, desc->u.texture.layer_idx, desc->u.texture.layer_count)); checkGLcall("Create texture view"); context_release(context); }
/** * Iterate through array of texture targets and check if call to TextureView * causes the gl error "err" */ static bool check_target_array(const GLenum err, const unsigned int numTargets, const GLenum *targetArray, const GLenum format, const GLuint tex, const GLuint levels) { unsigned int i; bool pass = true; for (i = 0; i < numTargets; i++) { GLenum target; GLuint newTex, layers=1; target = targetArray[i]; if (target == 0) continue; glGenTextures(1, &newTex); if (target== GL_TEXTURE_CUBE_MAP) layers = 6; else if (target == GL_TEXTURE_CUBE_MAP_ARRAY) layers = 12; glTextureView(newTex, target, tex, format, 0, levels, 0, layers); glDeleteTextures(1, &newTex); if (!piglit_check_gl_error(err)) { pass = false; break; } } return pass; }
static bool query_layers_state(void) { bool pass = true; GLuint tex[2], viewtex, l; GLint param; glGenTextures(2, tex); glBindTexture(GL_TEXTURE_2D_ARRAY, tex[0]); glTexStorage3D(GL_TEXTURE_2D_ARRAY, 7, GL_RG16F, 64, 64, 10); glTextureView(tex[1], GL_TEXTURE_2D_ARRAY,tex[0], GL_RG16I, 0, 3, 1, 8); pass = piglit_check_gl_error(GL_NO_ERROR) && pass; for (l = 0; l < 4; l++) { glGenTextures(1, &viewtex); glTextureView(viewtex, GL_TEXTURE_2D_ARRAY, tex[1], GL_RG16UI, 0, 4, l, 9); glBindTexture(GL_TEXTURE_2D_ARRAY, viewtex); /* test min_layers are additive using chained views */ glGetTexParameteriv(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_VIEW_MIN_LAYER, ¶m); if (param != (1 + l)) { glDeleteTextures(1, &viewtex); printf("bad query of view_min_layer expected %u got %u\n", 1+l, param); pass = false; break; } /* test num_layers are correct for chained views */ glGetTexParameteriv(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_VIEW_NUM_LAYERS, ¶m); if (param != (8 - l)) { glDeleteTextures(1, &viewtex); printf("bad query of view_num_layers expected %u got %u\n", 8 - l, param); pass = false; break; } glDeleteTextures(1, &viewtex); } glDeleteTextures(2, tex); return pass; }
bool initTexture() { gli::texture2D Texture(gli::load_dds((getDataDirectory() + TEXTURE_DIFFUSE).c_str())); assert(!Texture.empty()); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glGenTextures(texture::MAX, &TextureName[0]); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, TextureName[texture::TEXTURE]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_R, GL_RED); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_G, GL_GREEN); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_B, GL_BLUE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_A, GL_ALPHA); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, GLint(Texture.levels() - 1)); glTexStorage2D(GL_TEXTURE_2D, GLint(Texture.levels()), GL_RGBA8UI, GLsizei(Texture.dimensions().x), GLsizei(Texture.dimensions().y)); for(gli::texture2D::size_type Level = 0; Level < Texture.levels(); ++Level) { glTexSubImage2D( GL_TEXTURE_2D, GLint(Level), 0, 0, GLsizei(Texture[Level].dimensions().x), GLsizei(Texture[Level].dimensions().y), GL_BGR_INTEGER, GL_UNSIGNED_BYTE, Texture[Level].data()); } glTextureView(TextureName[texture::VIEW_A], GL_TEXTURE_2D_ARRAY, TextureName[texture::TEXTURE], GL_RGBA8, 0, GLuint(Texture.levels()), 0, 1); glTextureView(TextureName[texture::VIEW_B], GL_TEXTURE_2D_ARRAY, TextureName[texture::TEXTURE], GL_RGBA8, 0, 1, 0, 1); glPixelStorei(GL_UNPACK_ALIGNMENT, 4); return true; }
static bool test_single_layer(const Params* p, int layer) { int l; GLuint tex_src, tex_view; GLboolean pass; GLubyte *image; assert(layer < p->num_layers); glGenTextures(1, &tex_src); glBindTexture(GL_TEXTURE_2D_ARRAY, tex_src); glTexStorage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, p->width, p->height, p->num_layers); /* load each array layer with red */ image = makesolidimage(p->width, p->height, red); for (l = 0; l < p->num_layers; l++) { glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, l, p->width, p->height, 1, GL_RGBA, GL_UNSIGNED_BYTE, image); } /* make layer to check red, but green for pixel at (0,0) which should be the only one sampled */ memcpy(image, green, sizeof(green)); glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, layer, p->width, p->height, 1, GL_RGBA, GL_UNSIGNED_BYTE, image); free(image); glGenTextures(1, &tex_view); /* checked layer is supposed to be green */ glTextureView(tex_view, GL_TEXTURE_2D, tex_src, GL_RGBA8, 0, 1, layer, 1); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glBindTexture(GL_TEXTURE_2D, tex_view); /* draw it! */ piglit_draw_rect(-1, -1, 2, 2); pass = piglit_probe_rect_rgba(0, 0, piglit_width, piglit_height, greenf); if (!pass) { printf("layer %d failed\n", layer); } glDeleteTextures(1, &tex_view); glDeleteTextures(1, &tex_src); return pass; }
void piglit_init(int argc, char **argv) { int tex_loc_cube, prog_cube, l; GLuint tex_2DArray, tex_Cube; #ifdef PIGLIT_USE_OPENGL piglit_require_extension("GL_ARB_texture_view"); piglit_require_extension("GL_ARB_texture_cube_map_array"); #else piglit_require_extension("GL_OES_texture_view"); piglit_require_extension("GL_OES_texture_cube_map_array"); #endif /* setup shaders and program object for Cube rendering */ prog_cube = piglit_build_simple_program(vs, fs); tex_loc_cube = glGetUniformLocation(prog_cube, "tex"); glGenTextures(1, &tex_2DArray); glBindTexture(GL_TEXTURE_2D_ARRAY, tex_2DArray); glTexStorage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 1, 1, 16); /* load each array layer with red */ for (l = 0; l < 16; l++) { glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, l, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, red); } /* make array layer 9 have green */ glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 9, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, green); glGenTextures(1, &tex_Cube); /* the texture view starts at layer 2, so face 1 (-X) of * element 1 will have green */ glTextureView(tex_Cube, GL_TEXTURE_CUBE_MAP_ARRAY, tex_2DArray, GL_RGBA8, 0, 1, 2, 12); glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glBindTexture(GL_TEXTURE_CUBE_MAP_ARRAY, tex_Cube); glUseProgram(prog_cube); glUniform1i(tex_loc_cube, 0); }
static void CreateTextures() { stencilTexId = glcache.GenTexture(); glcache.BindTexture(GL_TEXTURE_2D, stencilTexId); glcache.TexParameteri(GL_TEXTURE_2D, GL_DEPTH_STENCIL_TEXTURE_MODE, GL_STENCIL_INDEX); // OpenGL >= 4.3 glcache.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glcache.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); // Using glTexStorage2D instead of glTexImage2D to satisfy requirement GL_TEXTURE_IMMUTABLE_FORMAT=true, needed for glTextureView below glTexStorage2D(GL_TEXTURE_2D, 1, GL_DEPTH32F_STENCIL8, screen_width, screen_height); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, stencilTexId, 0); glCheck(); glCheck(); opaqueTexId = CreateColorFBOTexture(); depthTexId = glcache.GenTexture(); glTextureView(depthTexId, GL_TEXTURE_2D, stencilTexId, GL_DEPTH32F_STENCIL8, 0, 1, 0, 1); glcache.BindTexture(GL_TEXTURE_2D, depthTexId); glcache.TexParameteri(GL_TEXTURE_2D, GL_DEPTH_STENCIL_TEXTURE_MODE, GL_DEPTH_COMPONENT); glcache.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glcache.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); }
/** * Texture views with varying minimum and number of levels, 2D only */ static bool test_render_levels(void) { GLuint tex, new_tex; GLint width = 4096, height = 4096, levels =13; GLuint numLevels[] = {3,2,2,1}; GLint l; int expectedLevel; GLfloat expected[3]; int p; bool pass = true; glUseProgram(0); glGenTextures(1, &tex); glBindTexture(GL_TEXTURE_2D, tex); glTexStorage2D(GL_TEXTURE_2D, levels, GL_RGBA8, width, height); glEnable(GL_TEXTURE_2D); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); /* load each mipmap with a different color texture */ for (l = 0; l < levels; l++) { GLubyte *buf = create_solid_image(width, height, 1, 4, l); if (buf != NULL) { glTexSubImage2D(GL_TEXTURE_2D, l, 0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, buf); free(buf); } if (width > 1) width /= 2; if (height > 1) height /= 2; } pass = piglit_check_gl_error(GL_NO_ERROR) && pass; /* create view of texture with restricted levels and draw quad */ /* using smallest mip level in the view range which varies every loop */ for (l = 0; l < ARRAY_SIZE(numLevels); l++) { glGenTextures(1, &new_tex); glTextureView(new_tex, GL_TEXTURE_2D, tex, GL_RGBA8, l, numLevels[l], 0, 1); glBindTexture(GL_TEXTURE_2D, new_tex); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, levels-1); glClear(GL_COLOR_BUFFER_BIT); piglit_draw_rect_tex(-1.0, -1.0, 2.0/(float) (l+2), 2.0/ (float) (l+2), 0.0, 0.0, 1.0, 1.0); expectedLevel = l + numLevels[l] - 1; expected[0] = Colors[expectedLevel][0] / 255.0; expected[1] = Colors[expectedLevel][1] / 255.0; expected[2] = Colors[expectedLevel][2] / 255.0; p = piglit_probe_pixel_rgb(piglit_width/(2*(l+3)), piglit_height/(2*(l+3)), expected); piglit_present_results(); #if 0 { /* debug */ GLint param; glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, ¶m); printf("for view min level=%d base_level=%d exp color=%f %f %f\n", l, param, expected[0], expected[1], expected[2]); glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, ¶m); printf("max_level=%d\n", param); glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_VIEW_MIN_LEVEL, ¶m); printf("view min_level=%d\n", param); glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_VIEW_NUM_LEVELS, ¶m); printf("view num_level=%d\n", param); glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_IMMUTABLE_LEVELS, ¶m); printf("immutable levels=%d\n", param); sleep(1); } #endif if (!p) { printf("%s: wrong color for view min level %d, expectedLevel %d\n", TestName, l, expectedLevel); pass = false; } glDeleteTextures(1, &new_tex); } glDisable(GL_TEXTURE_2D); glDeleteTextures(1, &tex); return pass; }
/** * Views with varying minimum and number of layers 2D_ARRAY only */ static bool test_render_layers(void) { GLuint tex, new_tex; GLint width = 16, height = 16, layers = 8; GLint l; GLint numLayers[] = {7, 1, 2, 2}; int expectedLayer; GLfloat expected[3]; int p; bool pass = true; glUseProgram(prog2Darray); glUniform1i(tex_loc_2Darray, 0); glGenTextures(1, &tex); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D_ARRAY, tex); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 0); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 0); glTexStorage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, width, height, layers); /* load each array layer with a different color texture */ for (l = 0; l < layers; l++) { GLubyte *buf = create_solid_image(width, height, 1, 4, l); if (buf != NULL) { glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, l, width, height, 1, GL_RGBA, GL_UNSIGNED_BYTE, buf); free(buf); } } pass = piglit_check_gl_error(GL_NO_ERROR) && pass; /* create view of texture with restricted layers and draw quad */ /* using a single layer in the view range which varies every loop */ for (l = 0; l < ARRAY_SIZE(numLayers); l++) { glGenTextures(1, &new_tex); glTextureView(new_tex, GL_TEXTURE_2D_ARRAY, tex, GL_RGBA8, 0, 1, l, numLayers[l]); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D_ARRAY, new_tex); glClear(GL_COLOR_BUFFER_BIT); expectedLayer = l + numLayers[l] - 1; draw_3d_depth(-1.0, -1.0, 2.0, 2.0, expectedLayer); expected[0] = Colors[expectedLayer][0] / 255.0; expected[1] = Colors[expectedLayer][1] / 255.0; expected[2] = Colors[expectedLayer][2] / 255.0; p = piglit_probe_pixel_rgb(piglit_width/2, piglit_height/2, expected); piglit_present_results(); #if 0 printf("for view min layer=%d expectedLayer=%d expected color=%f %f %f\n", l, expectedLayer, expected[0], expected[1], expected[2]); sleep(1); #endif if (!p) { printf("%s: wrong color for view min layer %d, expectedLayer %d\n", TestName, l, expectedLayer); pass = false; } glDeleteTextures(1, &new_tex); } glDeleteTextures(1, &tex); return pass; }
static void create_texture_view(struct wined3d_gl_view *view, GLenum view_target, const struct wined3d_view_desc *desc, struct wined3d_texture *texture, const struct wined3d_format *view_format) { const struct wined3d_gl_info *gl_info; unsigned int layer_idx, layer_count; struct wined3d_context *context; GLuint texture_name; view->target = view_target; context = context_acquire(texture->resource.device, NULL, 0); gl_info = context->gl_info; if (!gl_info->supported[ARB_TEXTURE_VIEW]) { context_release(context); FIXME("OpenGL implementation does not support texture views.\n"); return; } wined3d_texture_prepare_texture(texture, context, FALSE); texture_name = wined3d_texture_get_texture_name(texture, context, FALSE); layer_idx = desc->u.texture.layer_idx; layer_count = desc->u.texture.layer_count; if (view_target == GL_TEXTURE_3D && (layer_idx || layer_count != 1)) { FIXME("Depth slice (%u-%u) not supported.\n", layer_idx, layer_count); layer_idx = 0; layer_count = 1; } gl_info->gl_ops.gl.p_glGenTextures(1, &view->name); GL_EXTCALL(glTextureView(view->name, view->target, texture_name, view_format->glInternal, desc->u.texture.level_idx, desc->u.texture.level_count, layer_idx, layer_count)); checkGLcall("Create texture view"); if (is_stencil_view_format(view_format)) { static const GLint swizzle[] = {GL_ZERO, GL_RED, GL_ZERO, GL_ZERO}; if (!gl_info->supported[ARB_STENCIL_TEXTURING]) { context_release(context); FIXME("OpenGL implementation does not support stencil texturing.\n"); return; } context_bind_texture(context, view->target, view->name); gl_info->gl_ops.gl.p_glTexParameteriv(view->target, GL_TEXTURE_SWIZZLE_RGBA, swizzle); gl_info->gl_ops.gl.p_glTexParameteri(view->target, GL_DEPTH_STENCIL_TEXTURE_MODE, GL_STENCIL_INDEX); checkGLcall("Initialize stencil view"); context_invalidate_compute_state(context, STATE_COMPUTE_SHADER_RESOURCE_BINDING); context_invalidate_state(context, STATE_GRAPHICS_SHADER_RESOURCE_BINDING); } context_release(context); }
void piglit_init(int argc, char **argv) { GLuint tex, view, scratch; GLuint fbo; int i, j; bool pass = true; piglit_require_extension("GL_ARB_texture_storage"); piglit_require_extension("GL_ARB_texture_view"); /* build a 2d array texture; no mip levels */ glGenTextures(1, &tex); glBindTexture(GL_TEXTURE_2D_ARRAY, tex); glTexStorage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, TEX_SIZE, TEX_SIZE, NUM_LAYERS); for (i=0; i < NUM_LAYERS; i++) { GLubyte *pixels = create_solid_image(TEX_SIZE, TEX_SIZE, 1, 4, i); if (!pixels) { printf("Allocation failure for layer %d\n", i); piglit_report_result(PIGLIT_FAIL); } glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, i, TEX_SIZE, TEX_SIZE, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels); free(pixels); } /* create a view of just one layer, as a non-array 2d texture */ glGenTextures(1, &view); glTextureView(view, GL_TEXTURE_2D, tex, GL_RGBA8, 0, 1, VIEW_MIN_LAYER, VIEW_NUM_LAYERS); if (!piglit_check_gl_error(GL_NO_ERROR)) piglit_report_result(PIGLIT_FAIL); /* create scratch fbo, clear into it */ glGenFramebuffers(1, &fbo); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo); glGenTextures(1, &scratch); glBindTexture(GL_TEXTURE_2D, scratch); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, TEX_SIZE, TEX_SIZE, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, scratch, 0); if (glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) piglit_report_result(PIGLIT_FAIL); glViewport(0, 0, TEX_SIZE, TEX_SIZE); glClearColor(Colors[NUM_LAYERS][0] / 255.0f, Colors[NUM_LAYERS][1] / 255.0f, Colors[NUM_LAYERS][2] / 255.0f, Colors[NUM_LAYERS][3] / 255.0f); glClear(GL_COLOR_BUFFER_BIT); /* glCopyTexSubImage2D out of the scratch fbo */ glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo); glReadBuffer(GL_COLOR_ATTACHMENT0); glBindTexture(GL_TEXTURE_2D, view); glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, TEX_SIZE, TEX_SIZE); if (!piglit_check_gl_error(GL_NO_ERROR)) piglit_report_result(PIGLIT_FAIL); /* bind the underlying texture and readback */ glBindTexture(GL_TEXTURE_2D_ARRAY, tex); for (i = 0; i < NUM_LAYERS; i++) { /* only the layer in the view should have been touched. */ int color_index; float expected_color[4]; color_index = i; if (i >= VIEW_MIN_LAYER && i < VIEW_MIN_LAYER + VIEW_NUM_LAYERS) color_index = i + NUM_LAYERS - VIEW_MIN_LAYER; printf("Testing layer %d\n", i); for (j = 0; j < 4; j++) expected_color[j] = Colors[color_index][j] / 255.0f; pass = piglit_probe_texel_volume_rgba(GL_TEXTURE_2D_ARRAY, 0, 0, 0, i, TEX_SIZE, TEX_SIZE, 1, expected_color) && pass; } piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL); }
/** * Simple views of textures; test rendering with various texture view targets */ static bool test_render_with_targets(GLenum target) { GLuint tex, newTex; GLint width = 128, height = 64, depth = 4, levels = 8; GLint l; bool pass = true; glUseProgram(0); glGenTextures(1, &tex); glBindTexture(target, tex); switch (target) { case GL_TEXTURE_1D: glTexStorage1D(target, levels, GL_RGBA8, width); height = 1; depth = 1; break; case GL_TEXTURE_2D: glTexStorage2D(target, levels, GL_RGBA8, width, height); depth = 1; break; case GL_TEXTURE_3D: case GL_TEXTURE_2D_ARRAY: glTexStorage3D(target, levels, GL_RGBA8, width, height, depth); break; default: /* only handle subset of legal targets */ piglit_report_result(PIGLIT_FAIL); assert(!"Illegal target for test_render_with_targets()\n"); break; } /* load each mipmap with a different color texture */ for (l = 0; l < levels; l++) { GLubyte *buf = create_solid_image(width, height, depth, 4, l); if (buf != NULL) { switch(target) { case GL_TEXTURE_1D: glTexSubImage1D(GL_TEXTURE_1D, l, 0, width, GL_RGBA, GL_UNSIGNED_BYTE, buf); break; case GL_TEXTURE_2D: glTexSubImage2D(GL_TEXTURE_2D, l, 0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, buf); break; case GL_TEXTURE_3D: case GL_TEXTURE_2D_ARRAY: glTexSubImage3D(target, l, 0, 0, 0, width, height, depth, GL_RGBA, GL_UNSIGNED_BYTE, buf); break; } free(buf); } else { piglit_report_result(PIGLIT_FAIL); assert(!"create_solid_image() failed\n"); } if (width > 1) width /= 2; if (height > 1) height /= 2; if (depth > 1 && target == GL_TEXTURE_3D) depth /= 2; } if (piglit_check_gl_error(GL_NO_ERROR) == GL_FALSE) { printf("%s: Found gl errors prior to testing glTextureView\n", TestName); glDeleteTextures(1, &tex); return false; } /* create view of texture and bind it to target */ glGenTextures(1, &newTex); glTextureView(newTex, target, tex, GL_RGBA8, 0, levels, 0, 1); glDeleteTextures(1, &tex); pass = piglit_check_gl_error(GL_NO_ERROR) && pass; glActiveTexture(GL_TEXTURE0); glBindTexture(target, newTex); /* draw a quad/line using each texture mipmap level */ glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); for (l = 0; l < levels; l++) { GLfloat expected[3]; int p; glTexParameteri(target, GL_TEXTURE_BASE_LEVEL, l); glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, l); glClear(GL_COLOR_BUFFER_BIT); switch (target) { case GL_TEXTURE_1D: glUseProgram(prog1D); glUniform1i(tex_loc_1D, 0); piglit_draw_rect_tex(-1.0, -1.0, 2.0, 2.0, 0.0, 0.0, 1.0, 1.0); break; case GL_TEXTURE_2D: glEnable(target); piglit_draw_rect_tex(-1.0, -1.0, 2.0, 2.0, 0.0, 0.0, 1.0, 1.0); glDisable(target); break; case GL_TEXTURE_2D_ARRAY: glUseProgram(prog2Darray); glUniform1i(tex_loc_2Darray, 0); draw_3d_depth(-1.0, -1.0, 2.0, 2.0, l); break; case GL_TEXTURE_3D: glEnable(target); draw_3d_depth(-1.0, -1.0, 2.0, 2.0, l); glDisable(target); break; } expected[0] = Colors[l][0] / 255.0; expected[1] = Colors[l][1] / 255.0; expected[2] = Colors[l][2] / 255.0; p = piglit_probe_pixel_rgb(piglit_width/2, piglit_height/2, expected); piglit_present_results(); #if 0 /* debug */ printf("for level=%d, target=%s, expected color=%f %f %f\n", l, piglit_get_gl_enum_name(target), expected[0], expected[1], expected[2]); sleep(1); #endif if (!p) { printf("%s: wrong color for mipmap level %d\n", TestName, l); pass = false; } } glDeleteTextures(1, &newTex); return pass; }
void TextureBaseGL::CreateViewInternal( const struct TextureViewDesc &OrigViewDesc, class ITextureView **ppView, bool bIsDefaultView ) { VERIFY( ppView != nullptr, "Null pointer provided" ); if( !ppView )return; VERIFY( *ppView == nullptr, "Overwriting reference to existing object may cause memory leaks" ); *ppView = nullptr; try { auto ViewDesc = OrigViewDesc; CorrectTextureViewDesc(ViewDesc); auto *pDeviceGLImpl = ValidatedCast<RenderDeviceGLImpl>(GetDevice()); auto &TexViewAllocator = pDeviceGLImpl->GetTexViewObjAllocator(); VERIFY( &TexViewAllocator == &m_dbgTexViewObjAllocator, "Texture view allocator does not match allocator provided during texture initialization" ); // http://www.opengl.org/wiki/Texture_Storage#Texture_views GLenum GLViewFormat = TexFormatToGLInternalTexFormat( ViewDesc.Format, m_Desc.BindFlags ); VERIFY( GLViewFormat != 0, "Unsupported texture format" ); TextureViewGLImpl *pViewOGL = nullptr; if( ViewDesc.ViewType == TEXTURE_VIEW_SHADER_RESOURCE ) { bool bIsFullTextureView = ViewDesc.TextureDim == m_Desc.Type && ViewDesc.Format == GetDefaultTextureViewFormat( m_Desc.Format, ViewDesc.ViewType, m_Desc.BindFlags ) && ViewDesc.MostDetailedMip == 0 && ViewDesc.NumMipLevels == m_Desc.MipLevels && ViewDesc.FirstArraySlice == 0 && ViewDesc.NumArraySlices == m_Desc.ArraySize; pViewOGL = NEW_RC_OBJ(TexViewAllocator, "TextureViewGLImpl instance", TextureViewGLImpl, bIsDefaultView ? this : nullptr)( pDeviceGLImpl, ViewDesc, this, !bIsFullTextureView, // Create OpenGL texture view object if view // does not address the whole texture bIsDefaultView ); if( !bIsFullTextureView ) { GLenum GLViewTarget = 0; switch(ViewDesc.TextureDim) { case RESOURCE_DIM_TEX_1D: GLViewTarget = GL_TEXTURE_1D; ViewDesc.NumArraySlices = 1; break; case RESOURCE_DIM_TEX_1D_ARRAY: GLViewTarget = GL_TEXTURE_1D_ARRAY; break; case RESOURCE_DIM_TEX_2D: GLViewTarget = m_Desc.SampleCount > 1 ? GL_TEXTURE_2D_MULTISAMPLE : GL_TEXTURE_2D; ViewDesc.NumArraySlices = 1; break; case RESOURCE_DIM_TEX_2D_ARRAY: GLViewTarget = m_Desc.SampleCount > 1 ? GL_TEXTURE_2D_MULTISAMPLE_ARRAY : GL_TEXTURE_2D_ARRAY; break; case RESOURCE_DIM_TEX_3D: GLViewTarget = GL_TEXTURE_3D; break; case RESOURCE_DIM_TEX_CUBE: GLViewTarget = GL_TEXTURE_CUBE_MAP; break; case RESOURCE_DIM_TEX_CUBE_ARRAY: GLViewTarget = GL_TEXTURE_CUBE_MAP_ARRAY; break; default: UNEXPECTED("Unsupported texture view type"); } glTextureView( pViewOGL->GetHandle(), GLViewTarget, m_GlTexture, GLViewFormat, ViewDesc.MostDetailedMip, ViewDesc.NumMipLevels, ViewDesc.FirstArraySlice, ViewDesc.NumArraySlices ); CHECK_GL_ERROR_AND_THROW( "Failed to create texture view" ); pViewOGL->SetBindTarget(GLViewTarget); } } else if( ViewDesc.ViewType == TEXTURE_VIEW_UNORDERED_ACCESS ) { VERIFY( ViewDesc.NumArraySlices == 1 || ViewDesc.NumArraySlices == m_Desc.ArraySize, "Only single array/depth slice or the whole texture can be bound as UAV in OpenGL"); VERIFY( ViewDesc.AccessFlags != 0, "At least one access flag must be specified" ); pViewOGL = NEW_RC_OBJ(TexViewAllocator, "TextureViewGLImpl instance", TextureViewGLImpl, bIsDefaultView ? this : nullptr)( pDeviceGLImpl, ViewDesc, this, false, // Do NOT create texture view OpenGL object bIsDefaultView ); } else if( ViewDesc.ViewType == TEXTURE_VIEW_RENDER_TARGET ) { VERIFY( ViewDesc.NumMipLevels == 1, "Only single mip level can be bound as RTV" ); pViewOGL = NEW_RC_OBJ(TexViewAllocator, "TextureViewGLImpl instance", TextureViewGLImpl, bIsDefaultView ? this : nullptr)( pDeviceGLImpl, ViewDesc, this, false, // Do NOT create texture view OpenGL object bIsDefaultView ); } else if( ViewDesc.ViewType == TEXTURE_VIEW_DEPTH_STENCIL ) { VERIFY( ViewDesc.NumMipLevels == 1, "Only single mip level can be bound as DSV" ); pViewOGL = NEW_RC_OBJ(TexViewAllocator, "TextureViewGLImpl instance", TextureViewGLImpl, bIsDefaultView ? this : nullptr)( pDeviceGLImpl, ViewDesc, this, false, // Do NOT create texture view OpenGL object bIsDefaultView ); } if( bIsDefaultView ) *ppView = pViewOGL; else { if( pViewOGL ) { pViewOGL->QueryInterface( IID_TextureView, reinterpret_cast<IObject**>(ppView) ); } } } catch( const std::runtime_error& ) { const auto *ViewTypeName = GetTexViewTypeLiteralName(OrigViewDesc.ViewType); LOG_ERROR("Failed to create view \"", OrigViewDesc.Name ? OrigViewDesc.Name : "", "\" (", ViewTypeName, ") for texture \"", m_Desc.Name ? m_Desc.Name : "", "\"" ) } }
PIGLIT_GL_TEST_CONFIG_END /** * make sure default intial state is correct for textureView * In OpenGL Core 4.3 spec see table 23.15 for default values. */ static bool query_default_state(void) { bool pass = true; GLuint tex[2]; GLint param; glGenTextures(2,tex); glBindTexture(GL_TEXTURE_CUBE_MAP, tex[0]); glTexStorage2D(GL_TEXTURE_CUBE_MAP, 7, GL_R32F, 64, 64); glTextureView(tex[1], GL_TEXTURE_CUBE_MAP, tex[0], GL_RG16I, 2, 4, 0, 6); glBindTexture(GL_TEXTURE_CUBE_MAP, tex[1]); glDeleteTextures(1, &tex[1]); /* tex[1] which is bound to GL_TEXTURE_CUBE_MAP is deleted */ glGetTexParameteriv(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_VIEW_MIN_LEVEL, ¶m); if (param != 0) { printf("bad default of min_level, expected 0 got %u\n", param); pass = false; } glGetTexParameteriv(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_VIEW_NUM_LEVELS, ¶m); if (param != 0) { printf("bad default of num_levels, expected 0 got %u\n", param); pass = false; } glGetTexParameteriv(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_VIEW_MIN_LAYER, ¶m); if (param != 0) { printf("bad default of min_layer, expected 0 got %u\n", param); pass = false; } glGetTexParameteriv(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_VIEW_NUM_LAYERS, ¶m); if (param != 0) { printf("bad default of num_layers, expected 0 got %u\n", param); pass = false; } glGetTexParameteriv(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_IMMUTABLE_FORMAT, ¶m); if (param != 0) { printf("bad default of immutable_format, expected 0 got %u\n", param); pass = false; } glGetTexParameteriv(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_IMMUTABLE_LEVELS, ¶m); if (param != 0) { printf("bad default of immutable_levels, expected 0 got %u\n", param); pass = false; } glDeleteTextures(1, tex); return pass; }
/** * This tests min_levels, num_levels, immutable_levels and imutable_format. * note: see params test for more min/num level query testing * * In OpenGL Core 4.3 spec see section 8.18: * "The minlevel and minlayer parameters are relative to the view of * origtexture. If numlayers or numlevels extend beyond origtexture, they * are clamped to the maximum extent of the original texture. * If the command is successful, the texture parameters in <texture> are * updated as follows: * - TEXTURE_IMMUTABLE_FORMAT is set to TRUE. * * - TEXTURE_IMMUTABLE_LEVELS is set to the value of * TEXTURE_IMMUTABLE_LEVELS from the original texture. * * - TEXTURE_VIEW_MIN_LEVEL is set to <minlevel> plus the value of * TEXTURE_VIEW_MIN_LEVEL from the original texture. * * - TEXTURE_VIEW_NUM_LEVELS is set to the lesser of numlevels and the * value of TEXTURE_VIEW_NUM_LEVELS for origtexture minus minlevels." * In the ARB_texture_view extension registry spec see this for chained views: * "(3) Is it possible to create a texture view using an original texture * which is itself a view? And if so, how are the level/layer values * interpreted? * * RESOLVED: It is legal. For example, let's say texture 1 is a 2D_ARRAY * texture with 200 layers. It will have TEXTURE_VIEW_MIN_LAYER=0, * TEXTURE_VIEW_NUM_LAYERS=200. Then we create texture 2 from texture 1 using * <minlayer>=100, <numlayers>=100. It will have TEXTURE_VIEW_MIN_LAYER=100, * TEXTURE_VIEW_NUM_LAYERS=100. Then we create texture 3 from texture 2 using * <minlayer>=50, <numlayers>=50. It will have TEXTURE_VIEW_MIN_LAYER=150, * TEXTURE_VIEW_NUM_LAYERS=50." */ static bool query_levels_test(void) { GLuint tex[2], viewtex, l; GLint param; bool pass = true; glGenTextures(2, tex); /* test the view causes immutable_format to be set */ glBindTexture(GL_TEXTURE_2D, tex[0]); glTexStorage2D(GL_TEXTURE_2D, 6, GL_R32F, 16, 32); glTextureView(tex[1], GL_TEXTURE_2D, tex[0], GL_RG16F, 0, 1, 0, 1); pass = piglit_check_gl_error(GL_NO_ERROR) && pass; glBindTexture(GL_TEXTURE_2D, tex[1]); glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_IMMUTABLE_FORMAT, ¶m); pass = piglit_check_gl_error(GL_NO_ERROR) && pass; if (param != GL_TRUE) { printf("bad query of immutable_format\n"); pass = false; } glDeleteTextures(2,tex); /** * test min_levels are additive using chained views * test immutable_levels get set correctly based on origtexture * test num_levels are correct for chained views */ glGenTextures(2,tex); glBindTexture(GL_TEXTURE_CUBE_MAP, tex[0]); glTexStorage2D(GL_TEXTURE_CUBE_MAP, 7, GL_R32F, 64, 64); glTextureView(tex[1], GL_TEXTURE_CUBE_MAP,tex[0], GL_RG16I, 2, 4, 0, 6); pass = piglit_check_gl_error(GL_NO_ERROR) && pass; glBindTexture(GL_TEXTURE_CUBE_MAP, tex[1]); glGetTexParameteriv(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_IMMUTABLE_LEVELS, ¶m); if (param != 7) { printf("bad query of immutable_levels, expected 7 got %u\n", param); pass = false; } for (l = 0; l < 4; l++) { glGenTextures(1, &viewtex); glTextureView(viewtex, GL_TEXTURE_CUBE_MAP, tex[1], GL_RG16F, l, 4, 0, 6); glBindTexture(GL_TEXTURE_CUBE_MAP, viewtex); glGetTexParameteriv(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_VIEW_MIN_LEVEL, ¶m); if (param != (2 + l)) { glDeleteTextures(1, &viewtex); printf("bad query of view_min_level expected %u got %u\n", 2+l, param); pass = false; break; } glGetTexParameteriv(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_IMMUTABLE_LEVELS, ¶m); if (param != 7) { glDeleteTextures(1, &viewtex); printf("query of immutable_levels not tracking orig, expected 7 got %u\n", param); pass = false; break; } glGetTexParameteriv(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_VIEW_NUM_LEVELS, ¶m); if (param != (4 - l)) { glDeleteTextures(1, &viewtex); printf("bad query of view_num_levels expected %u got %u\n", 4 - l, param); pass = false; break; } glDeleteTextures(1, &viewtex); } glDeleteTextures(2, tex); pass = piglit_check_gl_error(GL_NO_ERROR) && pass; return pass; }
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GL43_nglTextureView(JNIEnv *env, jclass clazz, jint texture, jint target, jint origtexture, jint internalformat, jint minlevel, jint numlevels, jint minlayer, jint numlayers, jlong function_pointer) { glTextureViewPROC glTextureView = (glTextureViewPROC)((intptr_t)function_pointer); glTextureView(texture, target, origtexture, internalformat, minlevel, numlevels, minlayer, numlayers); }
void Texture::textureView(const GLuint originalTexture, const GLenum internalFormat, const GLuint minLevel, const GLuint numLevels, const GLuint minLayer, const GLuint numLayers) { glTextureView(id(), m_target, originalTexture, internalFormat, minLevel, numLevels, minLayer, numLayers); }
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GL43_nglTextureView(JNIEnv *__env, jclass clazz, jint texture, jint target, jint origtexture, jint internalformat, jint minlevel, jint numlevels, jint minlayer, jint numlayers, jlong __functionAddress) { glTextureViewPROC glTextureView = (glTextureViewPROC)(intptr_t)__functionAddress; UNUSED_PARAMS(__env, clazz) glTextureView(texture, target, origtexture, internalformat, minlevel, numlevels, minlayer, numlayers); }
void piglit_init(int argc, char **argv) { GLuint tex, view; GLuint buffer; int i, j; bool use_pbo = false; bool pass = true; #ifdef PIGLIT_USE_OPENGL piglit_require_extension("GL_ARB_texture_view"); #else piglit_require_extension("GL_OES_texture_view"); #endif for (i = 1; i < argc; ++i) { if (strcmp(argv[i], "pbo") == 0) { piglit_require_extension("GL_ARB_pixel_buffer_object"); use_pbo = true; } } /* build a texture with full miptree */ glGenTextures(1, &tex); glBindTexture(GL_TEXTURE_2D, tex); glTexStorage2D(GL_TEXTURE_2D, NUM_LEVELS, GL_RGBA8, TEX_SIZE, TEX_SIZE); if (use_pbo) { glGenBuffers(1, &buffer); glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffer); } for (i=0; i < NUM_LEVELS; i++) { int dim = TEX_SIZE >> i; GLubyte *pixels = create_solid_image(dim, dim, 1, 4, i); if (!pixels) { printf("Failed to allocate image for level %d\n", i); piglit_report_result(PIGLIT_FAIL); } if (use_pbo) { glBufferData(GL_PIXEL_UNPACK_BUFFER, dim * dim * 4, pixels, GL_STREAM_DRAW); } glTexSubImage2D(GL_TEXTURE_2D, i, 0, 0, dim, dim, GL_RGBA, GL_UNSIGNED_BYTE, use_pbo ? NULL : pixels); free(pixels); } /* create a view to a subset of the layers */ glGenTextures(1, &view); glTextureView(view, GL_TEXTURE_2D, tex, GL_RGBA8, VIEW_MIN_LEVEL, VIEW_NUM_LEVELS, 0, 1); if (!piglit_check_gl_error(GL_NO_ERROR)) piglit_report_result(PIGLIT_FAIL); /* upload through the view */ glBindTexture(GL_TEXTURE_2D, view); for (i = 0; i < VIEW_NUM_LEVELS; i++) { int dim = TEX_SIZE >> (VIEW_MIN_LEVEL + i); GLubyte *pixels = create_solid_image(dim, dim, 1, 4, i + NUM_LEVELS); if (!pixels) { printf("Failed to allocate image for view level %d\n", i); piglit_report_result(PIGLIT_FAIL); } if (use_pbo) { glBufferData(GL_PIXEL_UNPACK_BUFFER, dim * dim * 4, pixels, GL_STREAM_DRAW); } glTexSubImage2D(GL_TEXTURE_2D, i, 0, 0, dim, dim, GL_RGBA, GL_UNSIGNED_BYTE, use_pbo ? NULL : pixels); free(pixels); } if (!piglit_check_gl_error(GL_NO_ERROR)) piglit_report_result(PIGLIT_FAIL); /* bind the underlying texture and readback */ glBindTexture(GL_TEXTURE_2D, tex); for (i = 0; i < NUM_LEVELS; i++) { /* the levels inside the view should have been replaced. * everything else should be untouched. */ float expected_color[4]; int dim = TEX_SIZE >> i; int color_index = i; if (i >= VIEW_MIN_LEVEL && i < VIEW_MIN_LEVEL + VIEW_NUM_LEVELS) { color_index = i + NUM_LEVELS - VIEW_MIN_LEVEL; } printf("Testing level %d\n", i); for (j = 0; j < 4; j++) expected_color[j] = Colors[color_index][j] / 255.0f; pass = piglit_probe_texel_rect_rgba(GL_TEXTURE_2D, i, 0, 0, dim, dim, expected_color) && pass; } if (use_pbo) glDeleteBuffers(1, &buffer); piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL); }
static bool test_format_lifetime(const struct format_desc desc0, const struct format_desc desc1) { GLuint tex, viewTex[3]; GLint width = 32, w, levels = 6; GLint l; int bytes; unsigned char *buffer0, *buffer1; bool pass = true; glGenTextures(1, &tex); glBindTexture(GL_TEXTURE_1D, tex); glTexStorage1D(GL_TEXTURE_1D, levels, desc0.storagefmt, width); glGenTextures(3, viewTex); glTextureView(viewTex[0], GL_TEXTURE_1D, tex, desc0.internalfmt, 0, levels, 0, 1); glTextureView(viewTex[1], GL_TEXTURE_1D, viewTex[0], desc1.internalfmt, 0, levels, 0, 1); pass = piglit_check_gl_error(GL_NO_ERROR) && pass; /* load each mipmap with a different color texture */ w = width; bytes = (desc0.red + desc0.green + desc0.blue + desc0.alpha) / 8; for (l = 0; l < levels; l++) { GLubyte *buf = create_solid_image(width, 1, 1, bytes, l); if (buf != NULL) { glTexSubImage1D(GL_TEXTURE_1D, l, 0, w, desc0.imagefmt, desc0.imagetype, buf); free(buf); } else { piglit_report_result(PIGLIT_FAIL); assert(!"create_solid_image() failed\n"); } if (w > 1) w /= 2; } #if 0 /* debug */ printf("fmt0=%s, fmt1=%s, strgfmt0=%s, gettype0=%s\n", piglit_get_gl_enum_name(desc0.internalfmt), piglit_get_gl_enum_name(desc1.internalfmt), piglit_get_gl_enum_name(desc0.storagefmt), piglit_get_gl_enum_name(desc0.gettype)); printf("bytes=%d, width=%d, viewTex[0]=%d, [1]=%d, [2]=%d\n",bytes, width, viewTex[0], viewTex[1], viewTex[2]); #endif glDeleteTextures(1, &tex); pass = piglit_check_gl_error(GL_NO_ERROR) && pass; /* compare view0 all level texels bytes to view1 texels bytes */ buffer0 = malloc(width * bytes); buffer1 = malloc(width * bytes); w = width; for (l = 0; l < levels; l++) { glBindTexture(GL_TEXTURE_1D, viewTex[0]); glGetTexImage(GL_TEXTURE_1D, l, desc0.getfmt, desc0.gettype, buffer0); glBindTexture(GL_TEXTURE_1D, viewTex[1]); glGetTexImage(GL_TEXTURE_1D, l, desc1.getfmt, desc1.gettype, buffer1); if (buffers_equal(buffer0, buffer1, w)) { pass = piglit_check_gl_error(GL_NO_ERROR) && pass; printf("level %d texel mismatch view0 and view1, width=%d\n", l, w); printf("internal format0 %s, internal format1 %s\n", piglit_get_gl_enum_name(desc0.internalfmt), piglit_get_gl_enum_name(desc1.internalfmt)); pass = false; } if (w > 1) w /= 2; } /* compare view1 base level texels to view2 after view0 and view1 deleted */ glBindTexture(GL_TEXTURE_1D, viewTex[1]); glGetTexImage(GL_TEXTURE_1D, 0, desc1.getfmt, desc1.gettype, buffer1); glTextureView(viewTex[2], GL_TEXTURE_1D, viewTex[0], desc0.internalfmt, 0, 1, 0, 1); pass = piglit_check_gl_error(GL_NO_ERROR) && pass; glDeleteTextures(2, viewTex); glBindTexture(GL_TEXTURE_1D, viewTex[2]); glGetTexImage(GL_TEXTURE_1D, 0, desc0.getfmt, desc0.gettype, buffer0); if (buffers_equal(buffer0, buffer1, width)) { pass = piglit_check_gl_error(GL_NO_ERROR) && pass; printf("Mismatched texels view1 and view2\n"); printf("internal format0 %s, internal format1 %s\n", piglit_get_gl_enum_name(desc0.internalfmt), piglit_get_gl_enum_name(desc1.internalfmt)); pass = false; } free(buffer0); free(buffer1); glDeleteTextures(1, &viewTex[2]); return pass; }