conversion-explicit: use a different value for normalized +/- min
[piglit.git] / tests / spec / arb_texture_view / common.c
blobf2453f537680907a09b1f992dc6daa3de0bc287a
1 /*
2 * Copyright © 2013 LunarG, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
23 * Author: Jon Ashburn <jon@lunarg.com>
26 #include "piglit-util-gl.h"
27 #include <stdarg.h>
29 const GLubyte Colors[][8] = {
30 {127, 0, 0, 255, 0, 10, 20, 0},
31 { 0, 127, 0, 255, 0, 0, 80, 90},
32 { 0, 0, 127, 255, 25, 0, 0, 60},
33 { 0, 127, 127, 255, 15, 15, 0, 0},
34 {127, 0, 127, 255, 0, 2, 50, 0},
35 {127, 127, 0, 255, 80, 10, 70, 20},
36 {255, 0, 0, 255, 60, 0, 40, 30},
37 { 0, 255, 0, 255, 50, 20, 2, 40},
38 { 0, 0, 255, 255, 40, 0, 1, 0},
39 { 0, 255, 255, 255, 30, 5, 3, 8},
40 {255, 0, 255, 255, 20, 18, 4, 7},
41 {255, 255, 0, 255, 10, 24, 77, 67},
42 {255, 255, 255, 255, 5, 33, 88, 44}
45 /**
46 * Create a single-color image. Up to 64 bits per pixel depending upon bytes
48 GLubyte *
49 create_solid_image(GLint w, GLint h, GLint d, const unsigned int bytes,
50 const unsigned int idx)
52 GLubyte *buf = (GLubyte *) malloc(w * h * d * bytes);
53 int i,j;
55 if (buf == NULL || idx > (sizeof(Colors) / bytes - 1)) {
56 free(buf);
57 return NULL;
59 for (i = 0; i < w * h * d; i++) {
60 for (j = 0; j < bytes; j++) {
61 buf[i*bytes+j] = Colors[idx][j];
64 return buf;
67 /**
68 * This function takes an array of valid and invalid GLenums. The invalid
69 * enums array starts fully populated and the valid array is empty.
70 * It adds the varargs GLenum values to the valid array and removes them
71 * from the invalid array.
72 * @param numInvalid the size of array invalid
73 * An variable argument equal to zero will signal the end of
74 * the variable parameters.
76 unsigned int
77 update_valid_arrays(GLenum *valid, GLenum *invalid, unsigned int numInvalid,
78 ... )
80 va_list args;
81 GLenum val;
82 unsigned int j, num;
84 va_start(args, numInvalid);
85 val = va_arg(args, GLenum);
86 num = 0;
87 while (val) {
88 valid[num++] = val;
89 /* remove the valid enum from the invalid array */
90 for (j= 0; j < numInvalid; j++) {
91 if (invalid[j] == val)
92 invalid[j] = 0;
94 val = va_arg(args, GLenum);
96 va_end(args);
97 return num;
101 * Draw a textured quad, sampling only the given depth of the 3D texture.
102 * Use shader pipeline.
104 void
105 draw_3d_depth(float x, float y, float w, float h, int depth)
107 const GLfloat vertices[16] = {x, y, depth, 0.0,
108 x+w, y, depth, 0.0,
109 x, y+h, depth, 0.0,
110 x+w, y+h, depth, 0.0};
111 const GLfloat texcoords[8] = {0.0, 0.0,
112 1.0, 0.0,
113 0.0, 1.0,
114 1.0, 1.0};
116 piglit_draw_rect_from_arrays(vertices, texcoords, false, 1);