diff options
Diffstat (limited to 'progs')
34 files changed, 2058 insertions, 625 deletions
diff --git a/progs/demos/dissolve.c b/progs/demos/dissolve.c index 0b8df1bb66..8ab5242d91 100644 --- a/progs/demos/dissolve.c +++ b/progs/demos/dissolve.c @@ -1,5 +1,5 @@ /** - * Dissolve between two images using randomized stencil buffer + * Dissolve between two images using randomized/patterned stencil buffer * and varying stencil ref. * * Brian Paul @@ -9,6 +9,7 @@ #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <math.h> #include <GL/glut.h> #include "readtex.h" @@ -28,6 +29,8 @@ static GLfloat ScaleX[2], ScaleY[2]; static GLubyte StencilRef = 0; +static int Mode = 0; + static void Idle(void) @@ -38,13 +41,114 @@ Idle(void) static void -RandomizeStencilBuffer(void) +FillRandomPixels(GLubyte *b) { - GLubyte *b = malloc(WinWidth * WinHeight); int i; for (i = 0; i < WinWidth * WinHeight; i++) { b[i] = rand() & 0xff; } +} + + +static void +FillRandomRects(GLubyte *b) +{ + int i; + + memset(b, 0, WinWidth * WinHeight); + + for (i = 0; i < 256; i++) { + int x = rand() % WinWidth; + int y = rand() % WinHeight; + int w = rand() % 60; + int h = rand() % 60; + int ix, iy; + + if (x + w > WinWidth) + w = WinWidth - x; + if (y + h > WinHeight) + h = WinHeight - y; + + for (iy = 0; iy < h; iy++) { + for (ix = 0; ix < w; ix++) { + int p = (y + iy) * WinWidth + x + ix; + b[p] = i; + } + } + } +} + + +static void +FillWipe(GLubyte *b) +{ + int iy, ix; + + memset(b, 0, WinWidth * WinHeight); + + for (iy = 0; iy < WinHeight; iy++) { + for (ix = 0; ix < WinWidth; ix++) { + int p = iy * WinWidth + ix; + b[p] = 2 * ix + iy / 2; + } + } +} + + +static void +FillMoire(GLubyte *b) +{ + int iy, ix; + + memset(b, 0, WinWidth * WinHeight); + + for (iy = 0; iy < WinHeight; iy++) { + for (ix = 0; ix < WinWidth; ix++) { + int p = iy * WinWidth + ix; + b[p] = (ix / 2) * (ix / 2) - (iy / 2) * (iy / 2); + } + } +} + + +static void +FillWaves(GLubyte *b) +{ + int iy, ix; + + memset(b, 0, WinWidth * WinHeight); + + for (iy = 0; iy < WinHeight; iy++) { + for (ix = 0; ix < WinWidth; ix++) { + int p = iy * WinWidth + ix; + float x = 8.0 * 3.1415 * ix / (float) WinWidth; + b[p] = (int) (25.0 * sin(x) ) - iy*2; + } + } +} + + +typedef void (*FillFunc)(GLubyte *b); + + +static FillFunc Funcs[] = { + FillRandomPixels, + FillRandomRects, + FillWipe, + FillMoire, + FillWaves +}; + +#define NUM_MODES (sizeof(Funcs) / sizeof(Funcs[0])) + + + +static void +InitStencilBuffer(void) +{ + GLubyte *b = malloc(WinWidth * WinHeight); + + Funcs[Mode](b); glStencilFunc(GL_ALWAYS, 0, ~0); glPixelZoom(1.0, 1.0); @@ -54,7 +158,6 @@ RandomizeStencilBuffer(void) } - static void Draw(void) { @@ -85,7 +188,7 @@ Reshape(int width, int height) glLoadIdentity(); glTranslatef(0.0, 0.0, -15.0); - RandomizeStencilBuffer(); + InitStencilBuffer(); ScaleX[0] = (float) width / ImgWidth[0]; ScaleY[0] = (float) height / ImgHeight[0]; @@ -102,12 +205,26 @@ Key(unsigned char key, int x, int y) (void) y; switch (key) { case 'a': + case ' ': Anim = !Anim; if (Anim) glutIdleFunc(Idle); else glutIdleFunc(NULL); break; + case 'i': + InitStencilBuffer(); + break; + case '-': + StencilRef--; + break; + case '+': + StencilRef++; + break; + case 'm': + Mode = (Mode + 1) % NUM_MODES; + InitStencilBuffer(); + break; case 27: glutDestroyWindow(Win); exit(0); @@ -143,8 +260,8 @@ Init(void) int main(int argc, char *argv[]) { - glutInit(&argc, argv); glutInitWindowSize(WinWidth, WinHeight); + glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_STENCIL); Win = glutCreateWindow(argv[0]); glutReshapeFunc(Reshape); @@ -153,6 +270,14 @@ main(int argc, char *argv[]) if (Anim) glutIdleFunc(Idle); Init(); + + printf("Keys:\n"); + printf(" a/SPACE toggle animation\n"); + printf(" +/- single step\n"); + printf(" i re-init pattern\n"); + printf(" m change pattern/dissolve mode\n"); + printf(" ESC exit\n"); + glutMainLoop(); return 0; } diff --git a/progs/demos/stex3d.c b/progs/demos/stex3d.c index c0bbea0960..de18480c25 100644 --- a/progs/demos/stex3d.c +++ b/progs/demos/stex3d.c @@ -36,6 +36,7 @@ static int tex_width=64, tex_height=64, tex_depth=64; static float angx=0, angy=0, angz=0; static int texgen = 2, animate = 1, smooth = 1, wireframe = 0; static int CurTexture = NOISE_TEXTURE, CurObject = TORUS; +static GLenum Filter = GL_LINEAR; static void @@ -298,8 +299,6 @@ create3Dtexture(void) printf("setting up 3d texture...\n"); glBindTexture(GL_TEXTURE_3D, NOISE_TEXTURE); - glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_REPEAT); @@ -406,6 +405,9 @@ drawScene(void) glDisable(GL_TEXTURE_GEN_R); } + glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, Filter); + glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, Filter); + glCallList(CurObject); glPopMatrix(); @@ -505,6 +507,12 @@ KeyHandler(unsigned char key, int x, int y) else CurObject = TORUS; break; + case 'f': + if (Filter == GL_LINEAR) + Filter = GL_NEAREST; + else + Filter = GL_LINEAR; + break; case 'i': if (CurTexture == NOISE_TEXTURE) CurTexture = GRADIENT_TEXTURE; @@ -513,6 +521,7 @@ KeyHandler(unsigned char key, int x, int y) glBindTexture(GL_TEXTURE_3D, CurTexture); break; case 'a': + case ' ': animate = !animate; if (animate) glutIdleFunc(Idle); @@ -559,8 +568,6 @@ create3Dgradient(void) glBindTexture(GL_TEXTURE_3D, GRADIENT_TEXTURE); - glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_REPEAT); diff --git a/progs/egl/Makefile b/progs/egl/Makefile index 25de6e1f70..890240f9a3 100644 --- a/progs/egl/Makefile +++ b/progs/egl/Makefile @@ -57,13 +57,13 @@ peglgears: peglgears.o $(HEADERS) $(LIB_DEP) $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(LIBDRM_LIB) -lm xeglgears: xeglgears.o $(HEADERS) $(LIB_DEP) - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) -lm -L$(libdir) -lX11 + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) -lm $(X11_LIBS) xeglthreads: xeglthreads.o $(HEADERS) $(LIB_DEP) - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) -lm -L$(libdir) -lX11 + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) -lpthread -lm $(X11_LIBS) xegl_tri: xegl_tri.o $(HEADERS) $(LIB_DEP) - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) -lm -L$(libdir) -lX11 + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) -lm $(X11_LIBS) clean: -rm -f *.o *~ diff --git a/progs/fpglsl/dowhile.glsl b/progs/fpglsl/dowhile.glsl new file mode 100644 index 0000000000..ed9d729675 --- /dev/null +++ b/progs/fpglsl/dowhile.glsl @@ -0,0 +1,8 @@ +void main() { + float sum = 0.0; + do { + sum += 0.1; + break; + } while (true); + gl_FragColor = vec4(sum); +} diff --git a/progs/fpglsl/dowhile2.glsl b/progs/fpglsl/dowhile2.glsl new file mode 100644 index 0000000000..f3e00b8e86 --- /dev/null +++ b/progs/fpglsl/dowhile2.glsl @@ -0,0 +1,10 @@ +void main() { + float sum = 0.0; + do { + sum += 0.1; + if (sum < 0.499999) + continue; + break; + } while (true); + gl_FragColor = vec4(sum); +} diff --git a/progs/fpglsl/for.glsl b/progs/fpglsl/for.glsl new file mode 100644 index 0000000000..862ca8bd6c --- /dev/null +++ b/progs/fpglsl/for.glsl @@ -0,0 +1,11 @@ +uniform int KernelSizeInt; + +void main() { + int i; + vec4 sum = vec4(0.0); + for (i = 0; i < KernelSizeInt; ++i) { + sum.g += 0.25; + } + sum.a = 1.0; + gl_FragColor = sum; +} diff --git a/progs/fpglsl/forbreak.glsl b/progs/fpglsl/forbreak.glsl new file mode 100644 index 0000000000..0b8d957cb0 --- /dev/null +++ b/progs/fpglsl/forbreak.glsl @@ -0,0 +1,13 @@ +uniform int KernelSizeInt; + +void main() { + int i; + vec4 sum = vec4(0.0); + for (i = 0; i < KernelSizeInt; ++i) { + sum.g += 0.25; + if (i > 0) + break; + } + sum.a = 1.0; + gl_FragColor = sum; +} diff --git a/progs/fpglsl/fp-tri.c b/progs/fpglsl/fp-tri.c index c9b08fbbad..8af09845dd 100644 --- a/progs/fpglsl/fp-tri.c +++ b/progs/fpglsl/fp-tri.c @@ -129,6 +129,11 @@ static void setup_uniforms() } { + GLint loci = glGetUniformLocationARB(program, "KernelSizeInt"); + if (loci >= 0) + glUniform1i(loci, 4); + } + { GLint loc1f = glGetUniformLocationARB(program, "KernelValue1f"); GLint loc2f = glGetUniformLocationARB(program, "KernelValue2f"); GLint loc4f = glGetUniformLocationARB(program, "KernelValue4f"); diff --git a/progs/fpglsl/simpleif.glsl b/progs/fpglsl/simpleif.glsl new file mode 100644 index 0000000000..922421b410 --- /dev/null +++ b/progs/fpglsl/simpleif.glsl @@ -0,0 +1,6 @@ +void main() { + // this should always be true + if (gl_FragCoord.x >= 0.0) { + gl_FragColor = vec4(0.5, 0.0, 0.5, 1.0); + } +} diff --git a/progs/fpglsl/while.glsl b/progs/fpglsl/while.glsl new file mode 100644 index 0000000000..05fb860ddc --- /dev/null +++ b/progs/fpglsl/while.glsl @@ -0,0 +1,7 @@ +void main() { + float sum = 0.0; + while (sum < 0.499999) { + sum += 0.1; + } + gl_FragColor = vec4(sum); +} diff --git a/progs/fpglsl/while2.glsl b/progs/fpglsl/while2.glsl new file mode 100644 index 0000000000..19c8904e28 --- /dev/null +++ b/progs/fpglsl/while2.glsl @@ -0,0 +1,9 @@ +void main() { + float sum = 0.0; + while (true) { + sum += 0.1; + if (sum > 0.8) + break; + } + gl_FragColor = vec4(sum); +} diff --git a/progs/gallium/python/retrace/interpreter.py b/progs/gallium/python/retrace/interpreter.py index b30469dfae..1a96181255 100755 --- a/progs/gallium/python/retrace/interpreter.py +++ b/progs/gallium/python/retrace/interpreter.py @@ -551,7 +551,6 @@ class Context(Object): data = vbuf.buffer.read() values = unpack_from(format, data, offset) sys.stdout.write('\t\t{' + ', '.join(map(str, values)) + '},\n') - assert len(values) == velem.nr_components sys.stdout.write('\t},\n') sys.stdout.flush() diff --git a/progs/gallium/trivial/.gitignore b/progs/gallium/trivial/.gitignore new file mode 100644 index 0000000000..af6cdedbeb --- /dev/null +++ b/progs/gallium/trivial/.gitignore @@ -0,0 +1,3 @@ +tri +quad-tex +result.bmp diff --git a/progs/gallium/trivial/Makefile b/progs/gallium/trivial/Makefile new file mode 100644 index 0000000000..2b8af1ac06 --- /dev/null +++ b/progs/gallium/trivial/Makefile @@ -0,0 +1,44 @@ +# progs/gallium/simple/Makefile + +TOP = ../../.. +include $(TOP)/configs/current + +INCLUDES = \ + -I. \ + -I$(TOP)/src/gallium/include \ + -I$(TOP)/src/gallium/auxiliary \ + -I$(TOP)/src/gallium/drivers \ + -I$(TOP)/src/gallium/winsys \ + $(PROG_INCLUDES) + +LINKS = \ + $(TOP)/src/gallium/drivers/trace/libtrace.a \ + $(TOP)/src/gallium/winsys/sw/null/libws_null.a \ + $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ + $(GALLIUM_AUXILIARIES) \ + $(PROG_LINKS) + +SOURCES = \ + tri.c \ + quad-tex.c + +OBJECTS = $(SOURCES:.c=.o) + +PROGS = $(OBJECTS:.o=) + +##### TARGETS ##### + +default: $(PROGS) + +clean: + -rm -f $(PROGS) + -rm -f *.o + -rm -f result.bmp + +##### RULES ##### + +$(OBJECTS): %.o: %.c + $(CC) -c $(INCLUDES) $(CFLAGS) $(DEFINES) $(PROG_DEFINES) $< -o $@ + +$(PROGS): %: %.o + $(CC) $(LDFLAGS) $< $(LINKS) -lm -lpthread -o $@ diff --git a/progs/gallium/trivial/quad-tex.c b/progs/gallium/trivial/quad-tex.c new file mode 100644 index 0000000000..553f5582e7 --- /dev/null +++ b/progs/gallium/trivial/quad-tex.c @@ -0,0 +1,346 @@ +/************************************************************************** + * + * Copyright © 2010 Jakob Bornecrantz + * + * 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. + * + **************************************************************************/ + + +#define USE_TRACE 0 +#define WIDTH 300 +#define HEIGHT 300 +#define NEAR 30 +#define FAR 1000 +#define FLIP 0 + +/* pipe_*_state structs */ +#include "pipe/p_state.h" +/* pipe_context */ +#include "pipe/p_context.h" +/* pipe_screen */ +#include "pipe/p_screen.h" +/* PIPE_* */ +#include "pipe/p_defines.h" +/* TGSI_SEMANTIC_{POSITION|GENERIC} */ +#include "pipe/p_shader_tokens.h" +/* pipe_buffer_* helpers */ +#include "util/u_inlines.h" + +/* constant state object helper */ +#include "cso_cache/cso_context.h" + +/* u_sampler_view_default_template */ +#include "util/u_sampler.h" +/* debug_dump_surface_bmp */ +#include "util/u_debug.h" +/* util_draw_vertex_buffer helper */ +#include "util/u_draw_quad.h" +/* FREE & CALLOC_STRUCT */ +#include "util/u_memory.h" +/* util_make_[fragment|vertex]_passthrough_shader */ +#include "util/u_simple_shaders.h" + +/* softpipe software driver */ +#include "softpipe/sp_public.h" + +/* null software winsys */ +#include "sw/null/null_sw_winsys.h" + +/* traceing support see src/gallium/drivers/trace/README for more info. */ +#if USE_TRACE +#include "trace/tr_screen.h" +#include "trace/tr_context.h" +#endif + +struct program +{ + struct pipe_screen *screen; + struct pipe_context *pipe; + struct cso_context *cso; + + struct pipe_blend_state blend; + struct pipe_depth_stencil_alpha_state depthstencil; + struct pipe_rasterizer_state rasterizer; + struct pipe_sampler_state sampler; + struct pipe_viewport_state viewport; + struct pipe_framebuffer_state framebuffer; + struct pipe_vertex_element velem[2]; + + void *vs; + void *fs; + + float clear_color[4]; + + struct pipe_buffer *vbuf; + struct pipe_texture *target; + struct pipe_texture *tex; + struct pipe_sampler_view *view; +}; + +static void init_prog(struct program *p) +{ + /* create the software rasterizer */ + p->screen = softpipe_create_screen(null_sw_create()); +#if USE_TRACE + p->screen = trace_screen_create(p->screen); +#endif + p->pipe = p->screen->context_create(p->screen, NULL); + p->cso = cso_create_context(p->pipe); + + /* set clear color */ + p->clear_color[0] = 0.3; + p->clear_color[1] = 0.1; + p->clear_color[2] = 0.3; + p->clear_color[3] = 1.0; + + /* vertex buffer */ + { + float vertices[4][2][4] = { + { + { 0.9f, 0.9f, 0.0f, 1.0f }, + { 1.0f, 1.0f, 0.0f, 1.0f } + }, + { + { -0.9f, 0.9f, 0.0f, 1.0f }, + { 0.0f, 1.0f, 0.0f, 1.0f } + }, + { + { -0.9f, -0.9f, 0.0f, 1.0f }, + { 0.0f, 0.0f, 1.0f, 1.0f } + }, + { + { 0.9f, -0.9f, 0.0f, 1.0f }, + { 1.0f, 0.0f, 1.0f, 1.0f } + } + }; + + p->vbuf = pipe_buffer_create(p->screen, 16, PIPE_BUFFER_USAGE_VERTEX, sizeof(vertices)); + pipe_buffer_write(p->screen, p->vbuf, 0, sizeof(vertices), vertices); + } + + /* render target texture */ + { + struct pipe_texture tmplt; + memset(&tmplt, 0, sizeof(tmplt)); + tmplt.target = PIPE_TEXTURE_2D; + tmplt.format = PIPE_FORMAT_B8G8R8A8_UNORM; /* All drivers support this */ + tmplt.width0 = WIDTH; + tmplt.height0 = HEIGHT; + tmplt.depth0 = 1; + tmplt.last_level = 0; + tmplt.tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET; + + p->target = p->screen->texture_create(p->screen, &tmplt); + } + + /* sampler texture */ + { + uint32_t *ptr; + struct pipe_transfer *t; + struct pipe_texture t_tmplt; + struct pipe_sampler_view v_tmplt; + + memset(&t_tmplt, 0, sizeof(t_tmplt)); + t_tmplt.target = PIPE_TEXTURE_2D; + t_tmplt.format = PIPE_FORMAT_B8G8R8A8_UNORM; /* All drivers support this */ + t_tmplt.width0 = 2; + t_tmplt.height0 = 2; + t_tmplt.depth0 = 1; + t_tmplt.last_level = 0; + t_tmplt.tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET; + + p->tex = p->screen->texture_create(p->screen, &t_tmplt); + + t = p->pipe->get_tex_transfer(p->pipe, p->tex, + 0, 0, 0, /* face, level, zslice */ + PIPE_TRANSFER_WRITE, + 0, 0, 2, 2); /* x, y, width, height */ + + ptr = p->pipe->transfer_map(p->pipe, t); + ptr[0] = 0xffff0000; + ptr[1] = 0xff0000ff; + ptr[2] = 0xff00ff00; + ptr[3] = 0xffffff00; + p->pipe->transfer_unmap(p->pipe, t); + + p->pipe->tex_transfer_destroy(p->pipe, t); + + u_sampler_view_default_template(&v_tmplt, p->tex, p->tex->format); + + p->view = p->pipe->create_sampler_view(p->pipe, p->tex, &v_tmplt); + } + + /* disabled blending/masking */ + memset(&p->blend, 0, sizeof(p->blend)); + p->blend.rt[0].colormask = PIPE_MASK_RGBA; + + /* no-op depth/stencil/alpha */ + memset(&p->depthstencil, 0, sizeof(p->depthstencil)); + + /* rasterizer */ + memset(&p->rasterizer, 0, sizeof(p->rasterizer)); + p->rasterizer.front_winding = PIPE_WINDING_CW; + p->rasterizer.cull_mode = PIPE_WINDING_NONE; + p->rasterizer.gl_rasterization_rules = 1; + + /* sampler */ + memset(&p->sampler, 0, sizeof(p->sampler)); + p->sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE; + p->sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE; + p->sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE; + p->sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE; + p->sampler.min_img_filter = PIPE_TEX_MIPFILTER_LINEAR; + p->sampler.mag_img_filter = PIPE_TEX_MIPFILTER_LINEAR; + p->sampler.normalized_coords = 1; + + /* drawing destination */ + memset(&p->framebuffer, 0, sizeof(p->framebuffer)); + p->framebuffer.width = WIDTH; + p->framebuffer.height = HEIGHT; + p->framebuffer.nr_cbufs = 1; + p->framebuffer.cbufs[0] = p->screen->get_tex_surface(p->screen, p->target, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_WRITE); + + /* viewport, depth isn't really needed */ + { + float x = 0; + float y = 0; + float z = FAR; + float half_width = (float)WIDTH / 2.0f; + float half_height = (float)HEIGHT / 2.0f; + float half_depth = ((float)FAR - (float)NEAR) / 2.0f; + float scale, bias; + + if (FLIP) { + scale = -1.0f; + bias = (float)HEIGHT; + } else { + scale = 1.0f; + bias = 0.0f; + } + + p->viewport.scale[0] = half_width; + p->viewport.scale[1] = half_height * scale; + p->viewport.scale[2] = half_depth; + p->viewport.scale[3] = 1.0f; + + p->viewport.translate[0] = half_width + x; + p->viewport.translate[1] = (half_height + y) * scale + bias; + p->viewport.translate[2] = half_depth + z; + p->viewport.translate[3] = 0.0f; + } + + /* vertex elements state */ + memset(p->velem, 0, sizeof(p->velem)); + p->velem[0].src_offset = 0 * 4 * sizeof(float); /* offset 0, first element */ + p->velem[0].instance_divisor = 0; + p->velem[0].vertex_buffer_index = 0; + p->velem[0].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; + + p->velem[1].src_offset = 1 * 4 * sizeof(float); /* offset 16, second element */ + p->velem[1].instance_divisor = 0; + p->velem[1].vertex_buffer_index = 0; + p->velem[1].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; + + /* vertex shader */ + { + const uint semantic_names[] = { TGSI_SEMANTIC_POSITION, + TGSI_SEMANTIC_GENERIC }; + const uint semantic_indexes[] = { 0, 0 }; + p->vs = util_make_vertex_passthrough_shader(p->pipe, 2, semantic_names, semantic_indexes); + } + + /* fragment shader */ + p->fs = util_make_fragment_tex_shader(p->pipe, TGSI_TEXTURE_2D); +} + +static void close_prog(struct program *p) +{ + /* unset bound textures as well */ + cso_set_fragment_sampler_views(p->cso, 0, NULL); + + /* unset all state */ + cso_release_all(p->cso); + + p->pipe->delete_vs_state(p->pipe, p->vs); + p->pipe->delete_fs_state(p->pipe, p->fs); + + pipe_surface_reference(&p->framebuffer.cbufs[0], NULL); + pipe_sampler_view_reference(&p->view, NULL); + pipe_texture_reference(&p->target, NULL); + pipe_texture_reference(&p->tex, NULL); + pipe_buffer_reference(&p->vbuf, NULL); + + cso_destroy_context(p->cso); + p->pipe->destroy(p->pipe); + p->screen->destroy(p->screen); + + FREE(p); +} + +static void draw(struct program *p) +{ + /* set the render target */ + cso_set_framebuffer(p->cso, &p->framebuffer); + + /* clear the render target */ + p->pipe->clear(p->pipe, PIPE_CLEAR_COLOR, p->clear_color, 0, 0); + + /* set misc state we care about */ + cso_set_blend(p->cso, &p->blend); + cso_set_depth_stencil_alpha(p->cso, &p->depthstencil); + cso_set_rasterizer(p->cso, &p->rasterizer); + cso_set_viewport(p->cso, &p->viewport); + + /* sampler */ + cso_single_sampler(p->cso, 0, &p->sampler); + cso_single_sampler_done(p->cso); + + /* texture sampler view */ + cso_set_fragment_sampler_views(p->cso, 1, &p->view); + + /* shaders */ + cso_set_fragment_shader_handle(p->cso, p->fs); + cso_set_vertex_shader_handle(p->cso, p->vs); + + /* vertex element data */ + cso_set_vertex_elements(p->cso, 2, p->velem); + + util_draw_vertex_buffer(p->pipe, + p->vbuf, 0, + PIPE_PRIM_QUADS, + 4, /* verts */ + 2); /* attribs/vert */ + + p->pipe->flush(p->pipe, PIPE_FLUSH_RENDER_CACHE, NULL); + + debug_dump_surface_bmp(p->pipe, "result.bmp", p->framebuffer.cbufs[0]); +} + +int main(int argc, char** argv) +{ + struct program *p = CALLOC_STRUCT(program); + + init_prog(p); + draw(p); + close_prog(p); + + return 0; +} diff --git a/progs/gallium/trivial/tri.c b/progs/gallium/trivial/tri.c new file mode 100644 index 0000000000..cae1bdb1b1 --- /dev/null +++ b/progs/gallium/trivial/tri.c @@ -0,0 +1,278 @@ +/************************************************************************** + * + * Copyright © 2010 Jakob Bornecrantz + * + * 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. + * + **************************************************************************/ + + +#define USE_TRACE 0 +#define WIDTH 300 +#define HEIGHT 300 +#define NEAR 30 +#define FAR 1000 +#define FLIP 0 + +/* pipe_*_state structs */ +#include "pipe/p_state.h" +/* pipe_context */ +#include "pipe/p_context.h" +/* pipe_screen */ +#include "pipe/p_screen.h" +/* PIPE_* */ +#include "pipe/p_defines.h" +/* TGSI_SEMANTIC_{POSITION|GENERIC} */ +#include "pipe/p_shader_tokens.h" +/* pipe_buffer_* helpers */ +#include "util/u_inlines.h" + +/* constant state object helper */ +#include "cso_cache/cso_context.h" + +/* debug_dump_surface_bmp */ +#include "util/u_debug.h" +/* util_draw_vertex_buffer helper */ +#include "util/u_draw_quad.h" +/* FREE & CALLOC_STRUCT */ +#include "util/u_memory.h" +/* util_make_[fragment|vertex]_passthrough_shader */ +#include "util/u_simple_shaders.h" + +/* softpipe software driver */ +#include "softpipe/sp_public.h" + +/* null software winsys */ +#include "sw/null/null_sw_winsys.h" + +/* traceing support see src/gallium/drivers/trace/README for more info. */ +#if USE_TRACE +#include "trace/tr_screen.h" +#include "trace/tr_context.h" +#endif + +struct program +{ + struct pipe_screen *screen; + struct pipe_context *pipe; + struct cso_context *cso; + + struct pipe_blend_state blend; + struct pipe_depth_stencil_alpha_state depthstencil; + struct pipe_rasterizer_state rasterizer; + struct pipe_viewport_state viewport; + struct pipe_framebuffer_state framebuffer; + struct pipe_vertex_element velem[2]; + + void *vs; + void *fs; + + float clear_color[4]; + + struct pipe_buffer *vbuf; + struct pipe_texture *target; +}; + +static void init_prog(struct program *p) +{ + /* create the software rasterizer */ + p->screen = softpipe_create_screen(null_sw_create()); +#if USE_TRACE + p->screen = trace_screen_create(p->screen); +#endif + p->pipe = p->screen->context_create(p->screen, NULL); + p->cso = cso_create_context(p->pipe); + + /* set clear color */ + p->clear_color[0] = 0.3; + p->clear_color[1] = 0.1; + p->clear_color[2] = 0.3; + p->clear_color[3] = 1.0; + + /* vertex buffer */ + { + float vertices[4][2][4] = { + { + { 0.0f, -0.9f, 0.0f, 1.0f }, + { 1.0f, 0.0f, 0.0f, 1.0f } + }, + { + { -0.9f, 0.9f, 0.0f, 1.0f }, + { 0.0f, 1.0f, 0.0f, 1.0f } + }, + { + { 0.9f, 0.9f, 0.0f, 1.0f }, + { 0.0f, 0.0f, 1.0f, 1.0f } + } + }; + + p->vbuf = pipe_buffer_create(p->screen, 16, PIPE_BUFFER_USAGE_VERTEX, sizeof(vertices)); + pipe_buffer_write(p->screen, p->vbuf, 0, sizeof(vertices), vertices); + } + + /* render target texture */ + { + struct pipe_texture tmplt; + memset(&tmplt, 0, sizeof(tmplt)); + tmplt.target = PIPE_TEXTURE_2D; + tmplt.format = PIPE_FORMAT_B8G8R8A8_UNORM; /* All drivers support this */ + tmplt.width0 = WIDTH; + tmplt.height0 = HEIGHT; + tmplt.depth0 = 1; + tmplt.last_level = 0; + tmplt.tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET; + + p->target = p->screen->texture_create(p->screen, &tmplt); + } + + /* disabled blending/masking */ + memset(&p->blend, 0, sizeof(p->blend)); + p->blend.rt[0].colormask = PIPE_MASK_RGBA; + + /* no-op depth/stencil/alpha */ + memset(&p->depthstencil, 0, sizeof(p->depthstencil)); + + /* rasterizer */ + memset(&p->rasterizer, 0, sizeof(p->rasterizer)); + p->rasterizer.front_winding = PIPE_WINDING_CW; + p->rasterizer.cull_mode = PIPE_WINDING_NONE; + p->rasterizer.gl_rasterization_rules = 1; + + /* drawing destination */ + memset(&p->framebuffer, 0, sizeof(p->framebuffer)); + p->framebuffer.width = WIDTH; + p->framebuffer.height = HEIGHT; + p->framebuffer.nr_cbufs = 1; + p->framebuffer.cbufs[0] = p->screen->get_tex_surface(p->screen, p->target, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_WRITE); + + /* viewport, depth isn't really needed */ + { + float x = 0; + float y = 0; + float z = FAR; + float half_width = (float)WIDTH / 2.0f; + float half_height = (float)HEIGHT / 2.0f; + float half_depth = ((float)FAR - (float)NEAR) / 2.0f; + float scale, bias; + + if (FLIP) { + scale = -1.0f; + bias = (float)HEIGHT; + } else { + scale = 1.0f; + bias = 0.0f; + } + + p->viewport.scale[0] = half_width; + p->viewport.scale[1] = half_height * scale; + p->viewport.scale[2] = half_depth; + p->viewport.scale[3] = 1.0f; + + p->viewport.translate[0] = half_width + x; + p->viewport.translate[1] = (half_height + y) * scale + bias; + p->viewport.translate[2] = half_depth + z; + p->viewport.translate[3] = 0.0f; + } + + /* vertex elements state */ + memset(p->velem, 0, sizeof(p->velem)); + p->velem[0].src_offset = 0 * 4 * sizeof(float); /* offset 0, first element */ + p->velem[0].instance_divisor = 0; + p->velem[0].vertex_buffer_index = 0; + p->velem[0].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; + + p->velem[1].src_offset = 1 * 4 * sizeof(float); /* offset 16, second element */ + p->velem[1].instance_divisor = 0; + p->velem[1].vertex_buffer_index = 0; + p->velem[1].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; + + /* vertex shader */ + { + const uint semantic_names[] = { TGSI_SEMANTIC_POSITION, + TGSI_SEMANTIC_COLOR }; + const uint semantic_indexes[] = { 0, 0 }; + p->vs = util_make_vertex_passthrough_shader(p->pipe, 2, semantic_names, semantic_indexes); + } + + /* fragment shader */ + p->fs = util_make_fragment_passthrough_shader(p->pipe); +} + +static void close_prog(struct program *p) +{ + /* unset all state */ + cso_release_all(p->cso); + + p->pipe->delete_vs_state(p->pipe, p->vs); + p->pipe->delete_fs_state(p->pipe, p->fs); + + pipe_surface_reference(&p->framebuffer.cbufs[0], NULL); + pipe_texture_reference(&p->target, NULL); + pipe_buffer_reference(&p->vbuf, NULL); + + cso_destroy_context(p->cso); + p->pipe->destroy(p->pipe); + p->screen->destroy(p->screen); + + FREE(p); +} + +static void draw(struct program *p) +{ + /* set the render target */ + cso_set_framebuffer(p->cso, &p->framebuffer); + + /* clear the render target */ + p->pipe->clear(p->pipe, PIPE_CLEAR_COLOR, p->clear_color, 0, 0); + + /* set misc state we care about */ + cso_set_blend(p->cso, &p->blend); + cso_set_depth_stencil_alpha(p->cso, &p->depthstencil); + cso_set_rasterizer(p->cso, &p->rasterizer); + cso_set_viewport(p->cso, &p->viewport); + + /* shaders */ + cso_set_fragment_shader_handle(p->cso, p->fs); + cso_set_vertex_shader_handle(p->cso, p->vs); + + /* vertex element data */ + cso_set_vertex_elements(p->cso, 2, p->velem); + + util_draw_vertex_buffer(p->pipe, + p->vbuf, 0, + PIPE_PRIM_TRIANGLES, + 3, /* verts */ + 2); /* attribs/vert */ + + p->pipe->flush(p->pipe, PIPE_FLUSH_RENDER_CACHE, NULL); + + debug_dump_surface_bmp(p->pipe, "result.bmp", p->framebuffer.cbufs[0]); +} + +int main(int argc, char** argv) +{ + struct program *p = CALLOC_STRUCT(program); + + init_prog(p); + draw(p); + close_prog(p); + + return 0; +} diff --git a/progs/gallium/unit/u_format_test.c b/progs/gallium/unit/u_format_test.c index 2dfba5538b..5274311e03 100644 --- a/progs/gallium/unit/u_format_test.c +++ b/progs/gallium/unit/u_format_test.c @@ -30,546 +30,10 @@ #include <stdio.h> #include "util/u_format.h" +#include "util/u_format_tests.h" #include "util/u_format_pack.h" -#define MAX_PACKED_BYTES 16 - - -/** - * A (packed, unpacked) color pair. - */ -struct util_format_test_case -{ - enum pipe_format format; - - /** - * Mask of the bits that actually meaningful data. Used to mask out the - * "X" channels. - */ - uint8_t mask[MAX_PACKED_BYTES]; - - uint8_t packed[MAX_PACKED_BYTES]; - - /** - * RGBA. - */ - double unpacked[4]; -}; - - -/* - * Helper macros to create the packed bytes for longer words. - */ - -#define PACKED_1x8(x) {x, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} -#define PACKED_2x8(x, y) {x, y, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} -#define PACKED_3x8(x, y, z) {x, y, z, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} -#define PACKED_4x8(x, y, z, w) {x, y, z, w, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} - -#define PACKED_1x16(x) {(x) & 0xff, (x) >> 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} -#define PACKED_2x16(x, y) {(x) & 0xff, (x) >> 8, (y) & 0xff, (y) >> 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} -#define PACKED_3x16(x, y, z) {(x) & 0xff, (x) >> 8, (y) & 0xff, (y) >> 8, (z) & 0xff, (z) >> 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} -#define PACKED_4x16(x, y, z, w) {(x) & 0xff, (x) >> 8, (y) & 0xff, (y) >> 8, (z) & 0xff, (z) >> 8, (w) & 0xff, (w) >> 8, 0, 0, 0, 0, 0, 0, 0, 0} - -#define PACKED_1x32(x) {(x) & 0xff, ((x) >> 8) & 0xff, ((x) >> 16) & 0xff, (x) >> 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} -#define PACKED_2x32(x, y) {(x) & 0xff, ((x) >> 8) & 0xff, ((x) >> 16) & 0xff, (x) >> 24, (y) & 0xff, ((y) >> 8) & 0xff, ((y) >> 16) & 0xff, (y) >> 24, 0, 0, 0, 0, 0, 0, 0, 0} -#define PACKED_3x32(x, y, z) {(x) & 0xff, ((x) >> 8) & 0xff, ((x) >> 16) & 0xff, (x) >> 24, (y) & 0xff, ((y) >> 8) & 0xff, ((y) >> 16) & 0xff, (y) >> 24, (z) & 0xff, ((z) >> 8) & 0xff, ((z) >> 16) & 0xff, (z) >> 24, 0, 0, 0, 0} -#define PACKED_4x32(x, y, z, w) {(x) & 0xff, ((x) >> 8) & 0xff, ((x) >> 16) & 0xff, (x) >> 24, (y) & 0xff, ((y) >> 8) & 0xff, ((y) >> 16) & 0xff, (y) >> 24, (z) & 0xff, ((z) >> 8) & 0xff, ((z) >> 16) & 0xff, (z) >> 24, (w) & 0xff, ((w) >> 8) & 0xff, ((w) >> 16) & 0xff, (w) >> 24} - - -/** - * Test cases. - * - * These were manually entered. We could generate these - * - * To keep this to a we cover only the corner cases, which should produce - * good enough coverage since that pixel format transformations are afine for - * non SRGB formats. - */ -static const struct util_format_test_case -test_cases[] = -{ - - /* - * 32-bit rendertarget formats - */ - - {PIPE_FORMAT_B8G8R8A8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x00000000), {0.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_B8G8R8A8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x000000ff), {0.0, 0.0, 1.0, 0.0}}, - {PIPE_FORMAT_B8G8R8A8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x0000ff00), {0.0, 1.0, 0.0, 0.0}}, - {PIPE_FORMAT_B8G8R8A8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x00ff0000), {1.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_B8G8R8A8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0xff000000), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_B8G8R8A8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0xffffffff), {1.0, 1.0, 1.0, 1.0}}, - - {PIPE_FORMAT_B8G8R8X8_UNORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0x00000000), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_B8G8R8X8_UNORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0x000000ff), {0.0, 0.0, 1.0, 1.0}}, - {PIPE_FORMAT_B8G8R8X8_UNORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0x0000ff00), {0.0, 1.0, 0.0, 1.0}}, - {PIPE_FORMAT_B8G8R8X8_UNORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0x00ff0000), {1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_B8G8R8X8_UNORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0xff000000), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_B8G8R8X8_UNORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0xffffffff), {1.0, 1.0, 1.0, 1.0}}, - - {PIPE_FORMAT_A8R8G8B8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x00000000), {0.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_A8R8G8B8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x000000ff), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_A8R8G8B8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x0000ff00), {1.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_A8R8G8B8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x00ff0000), {0.0, 1.0, 0.0, 0.0}}, - {PIPE_FORMAT_A8R8G8B8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0xff000000), {0.0, 0.0, 1.0, 0.0}}, - {PIPE_FORMAT_A8R8G8B8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0xffffffff), {1.0, 1.0, 1.0, 1.0}}, - - {PIPE_FORMAT_X8R8G8B8_UNORM, PACKED_1x32(0xffffff00), PACKED_1x32(0x00000000), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_X8R8G8B8_UNORM, PACKED_1x32(0xffffff00), PACKED_1x32(0x000000ff), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_X8R8G8B8_UNORM, PACKED_1x32(0xffffff00), PACKED_1x32(0x0000ff00), {1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_X8R8G8B8_UNORM, PACKED_1x32(0xffffff00), PACKED_1x32(0x00ff0000), {0.0, 1.0, 0.0, 1.0}}, - {PIPE_FORMAT_X8R8G8B8_UNORM, PACKED_1x32(0xffffff00), PACKED_1x32(0xff000000), {0.0, 0.0, 1.0, 1.0}}, - {PIPE_FORMAT_X8R8G8B8_UNORM, PACKED_1x32(0xffffff00), PACKED_1x32(0xffffffff), {1.0, 1.0, 1.0, 1.0}}, - - {PIPE_FORMAT_A8B8G8R8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x00000000), {0.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_A8B8G8R8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x000000ff), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_A8B8G8R8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x0000ff00), {0.0, 0.0, 1.0, 0.0}}, - {PIPE_FORMAT_A8B8G8R8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x00ff0000), {0.0, 1.0, 0.0, 0.0}}, - {PIPE_FORMAT_A8B8G8R8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0xff000000), {1.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_A8B8G8R8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0xffffffff), {1.0, 1.0, 1.0, 1.0}}, - - {PIPE_FORMAT_X8B8G8R8_UNORM, PACKED_1x32(0xffffff00), PACKED_1x32(0x00000000), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_X8B8G8R8_UNORM, PACKED_1x32(0xffffff00), PACKED_1x32(0x000000ff), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_X8B8G8R8_UNORM, PACKED_1x32(0xffffff00), PACKED_1x32(0x0000ff00), {0.0, 0.0, 1.0, 1.0}}, - {PIPE_FORMAT_X8B8G8R8_UNORM, PACKED_1x32(0xffffff00), PACKED_1x32(0x00ff0000), {0.0, 1.0, 0.0, 1.0}}, - {PIPE_FORMAT_X8B8G8R8_UNORM, PACKED_1x32(0xffffff00), PACKED_1x32(0xff000000), {1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_X8B8G8R8_UNORM, PACKED_1x32(0xffffff00), PACKED_1x32(0xffffffff), {1.0, 1.0, 1.0, 1.0}}, - - {PIPE_FORMAT_R10G10B10A2_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x00000000), {0.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R10G10B10A2_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x000003ff), {1.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R10G10B10A2_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x000ffc00), {0.0, 1.0, 0.0, 0.0}}, - {PIPE_FORMAT_R10G10B10A2_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x3ff00000), {0.0, 0.0, 1.0, 0.0}}, - {PIPE_FORMAT_R10G10B10A2_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0xc0000000), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R10G10B10A2_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0xffffffff), {1.0, 1.0, 1.0, 1.0}}, - - /* - * 16-bit rendertarget formats - */ - - {PIPE_FORMAT_B5G5R5A1_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x0000), {0.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_B5G5R5A1_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x001f), {0.0, 0.0, 1.0, 0.0}}, - {PIPE_FORMAT_B5G5R5A1_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x03e0), {0.0, 1.0, 0.0, 0.0}}, - {PIPE_FORMAT_B5G5R5A1_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x7c00), {1.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_B5G5R5A1_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x8000), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_B5G5R5A1_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0xffff), {1.0, 1.0, 1.0, 1.0}}, - - {PIPE_FORMAT_B4G4R4A4_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x0000), {0.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_B4G4R4A4_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x000f), {0.0, 0.0, 1.0, 0.0}}, - {PIPE_FORMAT_B4G4R4A4_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x00f0), {0.0, 1.0, 0.0, 0.0}}, - {PIPE_FORMAT_B4G4R4A4_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x0f00), {1.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_B4G4R4A4_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0xf000), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_B4G4R4A4_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0xffff), {1.0, 1.0, 1.0, 1.0}}, - - {PIPE_FORMAT_B5G6R5_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x0000), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_B5G6R5_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x001f), {0.0, 0.0, 1.0, 1.0}}, - {PIPE_FORMAT_B5G6R5_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x07e0), {0.0, 1.0, 0.0, 1.0}}, - {PIPE_FORMAT_B5G6R5_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0xf800), {1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_B5G6R5_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0xffff), {1.0, 1.0, 1.0, 1.0}}, - - /* - * Luminance/intensity/alpha formats - */ - - {PIPE_FORMAT_L8_UNORM, PACKED_1x8(0xff), PACKED_1x8(0x00), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_L8_UNORM, PACKED_1x8(0xff), PACKED_1x8(0xff), {1.0, 1.0, 1.0, 1.0}}, - - {PIPE_FORMAT_A8_UNORM, PACKED_1x8(0xff), PACKED_1x8(0x00), {0.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_A8_UNORM, PACKED_1x8(0xff), PACKED_1x8(0xff), {0.0, 0.0, 0.0, 1.0}}, - - {PIPE_FORMAT_I8_UNORM, PACKED_1x8(0xff), PACKED_1x8(0x00), {0.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_I8_UNORM, PACKED_1x8(0xff), PACKED_1x8(0xff), {1.0, 1.0, 1.0, 1.0}}, - - {PIPE_FORMAT_L8A8_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x0000), {0.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_L8A8_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x00ff), {1.0, 1.0, 1.0, 0.0}}, - {PIPE_FORMAT_L8A8_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0xff00), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_L8A8_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0xffff), {1.0, 1.0, 1.0, 1.0}}, - - {PIPE_FORMAT_L16_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x0000), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_L16_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0xffff), {1.0, 1.0, 1.0, 1.0}}, - - /* - * TODO: SRGB formats - */ - - /* - * Mixed-signed formats - */ - - {PIPE_FORMAT_R8SG8SB8UX8U_NORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0x00000000), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8SG8SB8UX8U_NORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0x0000007f), { 1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8SG8SB8UX8U_NORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0x00000081), {-1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8SG8SB8UX8U_NORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0x00007f00), { 0.0, 1.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8SG8SB8UX8U_NORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0x00008100), { 0.0, -1.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8SG8SB8UX8U_NORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0x00ff0000), { 0.0, 0.0, 1.0, 1.0}}, - {PIPE_FORMAT_R8SG8SB8UX8U_NORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0xff000000), { 0.0, 0.0, 0.0, 1.0}}, - - {PIPE_FORMAT_R5SG5SB6U_NORM, PACKED_1x16(0xffff), PACKED_1x16(0x0000), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R5SG5SB6U_NORM, PACKED_1x16(0xffff), PACKED_1x16(0x000f), { 1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R5SG5SB6U_NORM, PACKED_1x16(0xffff), PACKED_1x16(0x0011), {-1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R5SG5SB6U_NORM, PACKED_1x16(0xffff), PACKED_1x16(0x01e0), { 0.0, 1.0, 0.0, 1.0}}, - {PIPE_FORMAT_R5SG5SB6U_NORM, PACKED_1x16(0xffff), PACKED_1x16(0x0220), { 0.0, -1.0, 0.0, 1.0}}, - {PIPE_FORMAT_R5SG5SB6U_NORM, PACKED_1x16(0xffff), PACKED_1x16(0xfc00), { 0.0, 0.0, 1.0, 1.0}}, - - /* - * TODO: Depth-stencil formats - */ - - /* - * TODO: YUV formats - */ - - /* - * TODO: Compressed formats - */ - - /* - * Standard 8-bit integer formats - */ - - {PIPE_FORMAT_R8_UNORM, PACKED_1x8(0xff), PACKED_1x8(0x00), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8_UNORM, PACKED_1x8(0xff), PACKED_1x8(0xff), {1.0, 0.0, 0.0, 1.0}}, - - {PIPE_FORMAT_R8G8_UNORM, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x00, 0x00), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8G8_UNORM, PACKED_2x8(0xff, 0xff), PACKED_2x8(0xff, 0x00), {1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8G8_UNORM, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x00, 0xff), {0.0, 1.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8G8_UNORM, PACKED_2x8(0xff, 0xff), PACKED_2x8(0xff, 0xff), {1.0, 1.0, 0.0, 1.0}}, - - {PIPE_FORMAT_R8G8B8_UNORM, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x00, 0x00), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8G8B8_UNORM, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0xff, 0x00, 0x00), {1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8G8B8_UNORM, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0xff, 0x00), {0.0, 1.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8G8B8_UNORM, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x00, 0xff), {0.0, 0.0, 1.0, 1.0}}, - {PIPE_FORMAT_R8G8B8_UNORM, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0xff, 0xff, 0xff), {1.0, 1.0, 1.0, 1.0}}, - - {PIPE_FORMAT_R8G8B8A8_UNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x00, 0x00), {0.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R8G8B8A8_UNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0xff, 0x00, 0x00, 0x00), {1.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R8G8B8A8_UNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0xff, 0x00, 0x00), {0.0, 1.0, 0.0, 0.0}}, - {PIPE_FORMAT_R8G8B8A8_UNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0xff, 0x00), {0.0, 0.0, 1.0, 0.0}}, - {PIPE_FORMAT_R8G8B8A8_UNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x00, 0xff), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8G8B8A8_UNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0xff, 0xff, 0xff, 0xff), {1.0, 1.0, 1.0, 1.0}}, - - {PIPE_FORMAT_R8_USCALED, PACKED_1x8(0xff), PACKED_1x8(0x00), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8_USCALED, PACKED_1x8(0xff), PACKED_1x8(0xff), {255.0, 0.0, 0.0, 1.0}}, - - {PIPE_FORMAT_R8G8_USCALED, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x00, 0x00), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8G8_USCALED, PACKED_2x8(0xff, 0xff), PACKED_2x8(0xff, 0x00), {255.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8G8_USCALED, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x00, 0xff), { 0.0, 255.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8G8_USCALED, PACKED_2x8(0xff, 0xff), PACKED_2x8(0xff, 0xff), {255.0, 255.0, 0.0, 1.0}}, - - {PIPE_FORMAT_R8G8B8_USCALED, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x00, 0x00), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8G8B8_USCALED, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0xff, 0x00, 0x00), {255.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8G8B8_USCALED, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0xff, 0x00), { 0.0, 255.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8G8B8_USCALED, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x00, 0xff), { 0.0, 0.0, 255.0, 1.0}}, - {PIPE_FORMAT_R8G8B8_USCALED, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0xff, 0xff, 0xff), {255.0, 255.0, 255.0, 1.0}}, - - {PIPE_FORMAT_R8G8B8A8_USCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x00, 0x00), { 0.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R8G8B8A8_USCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0xff, 0x00, 0x00, 0x00), {255.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R8G8B8A8_USCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0xff, 0x00, 0x00), { 0.0, 255.0, 0.0, 0.0}}, - {PIPE_FORMAT_R8G8B8A8_USCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0xff, 0x00), { 0.0, 0.0, 255.0, 0.0}}, - {PIPE_FORMAT_R8G8B8A8_USCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x00, 0xff), { 0.0, 0.0, 0.0, 255.0}}, - {PIPE_FORMAT_R8G8B8A8_USCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0xff, 0xff, 0xff, 0xff), {255.0, 255.0, 255.0, 255.0}}, - - {PIPE_FORMAT_R8_SNORM, PACKED_1x8(0xff), PACKED_1x8(0x00), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8_SNORM, PACKED_1x8(0xff), PACKED_1x8(0x7f), { 1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8_SNORM, PACKED_1x8(0xff), PACKED_1x8(0x81), {-1.0, 0.0, 0.0, 1.0}}, - - {PIPE_FORMAT_R8G8_SNORM, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x00, 0x00), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8G8_SNORM, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x7f, 0x00), { 1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8G8_SNORM, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x81, 0x00), {-1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8G8_SNORM, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x00, 0x7f), { 0.0, 1.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8G8_SNORM, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x00, 0x81), { 0.0, -1.0, 0.0, 1.0}}, - - {PIPE_FORMAT_R8G8B8_SNORM, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x00, 0x00), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8G8B8_SNORM, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x7f, 0x00, 0x00), { 1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8G8B8_SNORM, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x81, 0x00, 0x00), {-1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8G8B8_SNORM, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x7f, 0x00), { 0.0, 1.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8G8B8_SNORM, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x81, 0x00), { 0.0, -1.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8G8B8_SNORM, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x00, 0x7f), { 0.0, 0.0, 1.0, 1.0}}, - {PIPE_FORMAT_R8G8B8_SNORM, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x00, 0x81), { 0.0, 0.0, -1.0, 1.0}}, - - {PIPE_FORMAT_R8G8B8A8_SNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x00, 0x00), { 0.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R8G8B8A8_SNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x7f, 0x00, 0x00, 0x00), { 1.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R8G8B8A8_SNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x81, 0x00, 0x00, 0x00), {-1.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R8G8B8A8_SNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x7f, 0x00, 0x00), { 0.0, 1.0, 0.0, 0.0}}, - {PIPE_FORMAT_R8G8B8A8_SNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x81, 0x00, 0x00), { 0.0, -1.0, 0.0, 0.0}}, - {PIPE_FORMAT_R8G8B8A8_SNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x7f, 0x00), { 0.0, 0.0, 1.0, 0.0}}, - {PIPE_FORMAT_R8G8B8A8_SNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x81, 0x00), { 0.0, 0.0, -1.0, 0.0}}, - {PIPE_FORMAT_R8G8B8A8_SNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x00, 0x7f), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8G8B8A8_SNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x00, 0x81), { 0.0, 0.0, 0.0, -1.0}}, - - {PIPE_FORMAT_R8_SSCALED, PACKED_1x8(0xff), PACKED_1x8(0x00), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8_SSCALED, PACKED_1x8(0xff), PACKED_1x8(0x7f), { 127.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8_SSCALED, PACKED_1x8(0xff), PACKED_1x8(0x80), {-128.0, 0.0, 0.0, 1.0}}, - - {PIPE_FORMAT_R8G8_SSCALED, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x00, 0x00), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8G8_SSCALED, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x7f, 0x00), { 127.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8G8_SSCALED, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x80, 0x00), {-128.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8G8_SSCALED, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x00, 0x7f), { 0.0, 127.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8G8_SSCALED, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x00, 0x80), { 0.0, -128.0, 0.0, 1.0}}, - - {PIPE_FORMAT_R8G8B8_SSCALED, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x00, 0x00), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8G8B8_SSCALED, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x7f, 0x00, 0x00), { 127.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8G8B8_SSCALED, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x80, 0x00, 0x00), {-128.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8G8B8_SSCALED, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x7f, 0x00), { 0.0, 127.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8G8B8_SSCALED, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x80, 0x00), { 0.0, -128.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8G8B8_SSCALED, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x00, 0x7f), { 0.0, 0.0, 127.0, 1.0}}, - {PIPE_FORMAT_R8G8B8_SSCALED, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x00, 0x80), { 0.0, 0.0, -128.0, 1.0}}, - - {PIPE_FORMAT_R8G8B8A8_SSCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x00, 0x00), { 0.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R8G8B8A8_SSCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x7f, 0x00, 0x00, 0x00), { 127.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R8G8B8A8_SSCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x80, 0x00, 0x00, 0x00), {-128.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R8G8B8A8_SSCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x7f, 0x00, 0x00), { 0.0, 127.0, 0.0, 0.0}}, - {PIPE_FORMAT_R8G8B8A8_SSCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x80, 0x00, 0x00), { 0.0, -128.0, 0.0, 0.0}}, - {PIPE_FORMAT_R8G8B8A8_SSCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x7f, 0x00), { 0.0, 0.0, 127.0, 0.0}}, - {PIPE_FORMAT_R8G8B8A8_SSCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x80, 0x00), { 0.0, 0.0, -128.0, 0.0}}, - {PIPE_FORMAT_R8G8B8A8_SSCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x00, 0x7f), { 0.0, 0.0, 0.0, 127.0}}, - {PIPE_FORMAT_R8G8B8A8_SSCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x00, 0x80), { 0.0, 0.0, 0.0, -128.0}}, - - /* - * Standard 16-bit integer formats - */ - - {PIPE_FORMAT_R16_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x0000), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0xffff), {1.0, 0.0, 0.0, 1.0}}, - - {PIPE_FORMAT_R16G16_UNORM, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x0000, 0x0000), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16G16_UNORM, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0xffff, 0x0000), {1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16G16_UNORM, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x0000, 0xffff), {0.0, 1.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16G16_UNORM, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0xffff, 0xffff), {1.0, 1.0, 0.0, 1.0}}, - - {PIPE_FORMAT_R16G16B16_UNORM, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x0000, 0x0000), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16G16B16_UNORM, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0xffff, 0x0000, 0x0000), {1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16G16B16_UNORM, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0xffff, 0x0000), {0.0, 1.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16G16B16_UNORM, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x0000, 0xffff), {0.0, 0.0, 1.0, 1.0}}, - {PIPE_FORMAT_R16G16B16_UNORM, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0xffff, 0xffff, 0xffff), {1.0, 1.0, 1.0, 1.0}}, - - {PIPE_FORMAT_R16G16B16A16_UNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x0000, 0x0000), {0.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R16G16B16A16_UNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0xffff, 0x0000, 0x0000, 0x0000), {1.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R16G16B16A16_UNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0xffff, 0x0000, 0x0000), {0.0, 1.0, 0.0, 0.0}}, - {PIPE_FORMAT_R16G16B16A16_UNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0xffff, 0x0000), {0.0, 0.0, 1.0, 0.0}}, - {PIPE_FORMAT_R16G16B16A16_UNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x0000, 0xffff), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16G16B16A16_UNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), {1.0, 1.0, 1.0, 1.0}}, - - {PIPE_FORMAT_R16_USCALED, PACKED_1x16(0xffff), PACKED_1x16(0x0000), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16_USCALED, PACKED_1x16(0xffff), PACKED_1x16(0xffff), {65535.0, 0.0, 0.0, 1.0}}, - - {PIPE_FORMAT_R16G16_USCALED, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x0000, 0x0000), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16G16_USCALED, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0xffff, 0x0000), {65535.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16G16_USCALED, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x0000, 0xffff), { 0.0, 65535.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16G16_USCALED, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0xffff, 0xffff), {65535.0, 65535.0, 0.0, 1.0}}, - - {PIPE_FORMAT_R16G16B16_USCALED, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x0000, 0x0000), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16G16B16_USCALED, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0xffff, 0x0000, 0x0000), {65535.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16G16B16_USCALED, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0xffff, 0x0000), { 0.0, 65535.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16G16B16_USCALED, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x0000, 0xffff), { 0.0, 0.0, 65535.0, 1.0}}, - {PIPE_FORMAT_R16G16B16_USCALED, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0xffff, 0xffff, 0xffff), {65535.0, 65535.0, 65535.0, 1.0}}, - - {PIPE_FORMAT_R16G16B16A16_USCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x0000, 0x0000), { 0.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R16G16B16A16_USCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0xffff, 0x0000, 0x0000, 0x0000), {65535.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R16G16B16A16_USCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0xffff, 0x0000, 0x0000), { 0.0, 65535.0, 0.0, 0.0}}, - {PIPE_FORMAT_R16G16B16A16_USCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0xffff, 0x0000), { 0.0, 0.0, 65535.0, 0.0}}, - {PIPE_FORMAT_R16G16B16A16_USCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x0000, 0xffff), { 0.0, 0.0, 0.0, 65535.0}}, - {PIPE_FORMAT_R16G16B16A16_USCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), {65535.0, 65535.0, 65535.0, 65535.0}}, - - {PIPE_FORMAT_R16_SNORM, PACKED_1x16(0xffff), PACKED_1x16(0x0000), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16_SNORM, PACKED_1x16(0xffff), PACKED_1x16(0x7fff), { 1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16_SNORM, PACKED_1x16(0xffff), PACKED_1x16(0x8001), { -1.0, 0.0, 0.0, 1.0}}, - - {PIPE_FORMAT_R16G16_SNORM, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x0000, 0x0000), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16G16_SNORM, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x7fff, 0x0000), { 1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16G16_SNORM, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x8001, 0x0000), { -1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16G16_SNORM, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x0000, 0x7fff), { 0.0, 1.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16G16_SNORM, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x0000, 0x8001), { 0.0, -1.0, 0.0, 1.0}}, - - {PIPE_FORMAT_R16G16B16_SNORM, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x0000, 0x0000), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16G16B16_SNORM, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x7fff, 0x0000, 0x0000), { 1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16G16B16_SNORM, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x8001, 0x0000, 0x0000), { -1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16G16B16_SNORM, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x7fff, 0x0000), { 0.0, 1.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16G16B16_SNORM, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x8001, 0x0000), { 0.0, -1.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16G16B16_SNORM, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x0000, 0x7fff), { 0.0, 0.0, 1.0, 1.0}}, - {PIPE_FORMAT_R16G16B16_SNORM, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x0000, 0x8001), { 0.0, 0.0, -1.0, 1.0}}, - - {PIPE_FORMAT_R16G16B16A16_SNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x0000, 0x0000), { 0.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R16G16B16A16_SNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x7fff, 0x0000, 0x0000, 0x0000), { 1.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R16G16B16A16_SNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x8001, 0x0000, 0x0000, 0x0000), { -1.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R16G16B16A16_SNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x7fff, 0x0000, 0x0000), { 0.0, 1.0, 0.0, 0.0}}, - {PIPE_FORMAT_R16G16B16A16_SNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x8001, 0x0000, 0x0000), { 0.0, -1.0, 0.0, 0.0}}, - {PIPE_FORMAT_R16G16B16A16_SNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x7fff, 0x0000), { 0.0, 0.0, 1.0, 0.0}}, - {PIPE_FORMAT_R16G16B16A16_SNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x8001, 0x0000), { 0.0, 0.0, -1.0, 0.0}}, - {PIPE_FORMAT_R16G16B16A16_SNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x0000, 0x7fff), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16G16B16A16_SNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x0000, 0x8001), { 0.0, 0.0, 0.0, -1.0}}, - - {PIPE_FORMAT_R16_SSCALED, PACKED_1x16(0xffff), PACKED_1x16(0x0000), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16_SSCALED, PACKED_1x16(0xffff), PACKED_1x16(0x7fff), { 32767.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16_SSCALED, PACKED_1x16(0xffff), PACKED_1x16(0x8000), {-32768.0, 0.0, 0.0, 1.0}}, - - {PIPE_FORMAT_R16G16_SSCALED, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x0000, 0x0000), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16G16_SSCALED, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x7fff, 0x0000), { 32767.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16G16_SSCALED, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x8000, 0x0000), {-32768.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16G16_SSCALED, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x0000, 0x7fff), { 0.0, 32767.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16G16_SSCALED, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x0000, 0x8000), { 0.0, -32768.0, 0.0, 1.0}}, - - {PIPE_FORMAT_R16G16B16_SSCALED, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x0000, 0x0000), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16G16B16_SSCALED, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x7fff, 0x0000, 0x0000), { 32767.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16G16B16_SSCALED, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x8000, 0x0000, 0x0000), {-32768.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16G16B16_SSCALED, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x7fff, 0x0000), { 0.0, 32767.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16G16B16_SSCALED, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x8000, 0x0000), { 0.0, -32768.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16G16B16_SSCALED, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x0000, 0x7fff), { 0.0, 0.0, 32767.0, 1.0}}, - {PIPE_FORMAT_R16G16B16_SSCALED, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x0000, 0x8000), { 0.0, 0.0, -32768.0, 1.0}}, - - {PIPE_FORMAT_R16G16B16A16_SSCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x0000, 0x0000), { 0.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R16G16B16A16_SSCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x7fff, 0x0000, 0x0000, 0x0000), { 32767.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R16G16B16A16_SSCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x8000, 0x0000, 0x0000, 0x0000), {-32768.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R16G16B16A16_SSCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x7fff, 0x0000, 0x0000), { 0.0, 32767.0, 0.0, 0.0}}, - {PIPE_FORMAT_R16G16B16A16_SSCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x8000, 0x0000, 0x0000), { 0.0, -32768.0, 0.0, 0.0}}, - {PIPE_FORMAT_R16G16B16A16_SSCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x7fff, 0x0000), { 0.0, 0.0, 32767.0, 0.0}}, - {PIPE_FORMAT_R16G16B16A16_SSCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x8000, 0x0000), { 0.0, 0.0, -32768.0, 0.0}}, - {PIPE_FORMAT_R16G16B16A16_SSCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x0000, 0x7fff), { 0.0, 0.0, 0.0, 32767.0}}, - {PIPE_FORMAT_R16G16B16A16_SSCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x0000, 0x8000), { 0.0, 0.0, 0.0, -32768.0}}, - - /* - * Standard 32-bit integer formats - * - * NOTE: We can't accurately represent integers larger than +/-0x1000000 - * with single precision floats, so that's as far as we test. - */ - - {PIPE_FORMAT_R32_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x00000000), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0xffffffff), {1.0, 0.0, 0.0, 1.0}}, - - {PIPE_FORMAT_R32G32_UNORM, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x00000000, 0x00000000), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32_UNORM, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0xffffffff, 0x00000000), {1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32_UNORM, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x00000000, 0xffffffff), {0.0, 1.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32_UNORM, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0xffffffff, 0xffffffff), {1.0, 1.0, 0.0, 1.0}}, - - {PIPE_FORMAT_R32G32B32_UNORM, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x00000000, 0x00000000), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32B32_UNORM, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0xffffffff, 0x00000000, 0x00000000), {1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32B32_UNORM, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0xffffffff, 0x00000000), {0.0, 1.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32B32_UNORM, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x00000000, 0xffffffff), {0.0, 0.0, 1.0, 1.0}}, - {PIPE_FORMAT_R32G32B32_UNORM, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), {1.0, 1.0, 1.0, 1.0}}, - - {PIPE_FORMAT_R32G32B32A32_UNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x00000000, 0x00000000), {0.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R32G32B32A32_UNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0xffffffff, 0x00000000, 0x00000000, 0x00000000), {1.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R32G32B32A32_UNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0xffffffff, 0x00000000, 0x00000000), {0.0, 1.0, 0.0, 0.0}}, - {PIPE_FORMAT_R32G32B32A32_UNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0xffffffff, 0x00000000), {0.0, 0.0, 1.0, 0.0}}, - {PIPE_FORMAT_R32G32B32A32_UNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x00000000, 0xffffffff), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32B32A32_UNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), {1.0, 1.0, 1.0, 1.0}}, - - {PIPE_FORMAT_R32_USCALED, PACKED_1x32(0xffffffff), PACKED_1x32(0x00000000), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32_USCALED, PACKED_1x32(0xffffffff), PACKED_1x32(0x01000000), {16777216.0, 0.0, 0.0, 1.0}}, - - {PIPE_FORMAT_R32G32_USCALED, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x00000000, 0x00000000), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32_USCALED, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x01000000, 0x00000000), {16777216.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32_USCALED, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x00000000, 0x01000000), { 0.0, 16777216.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32_USCALED, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x01000000, 0x01000000), {16777216.0, 16777216.0, 0.0, 1.0}}, - - {PIPE_FORMAT_R32G32B32_USCALED, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x00000000, 0x00000000), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32B32_USCALED, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x01000000, 0x00000000, 0x00000000), {16777216.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32B32_USCALED, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x01000000, 0x00000000), { 0.0, 16777216.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32B32_USCALED, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x00000000, 0x01000000), { 0.0, 0.0, 16777216.0, 1.0}}, - {PIPE_FORMAT_R32G32B32_USCALED, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x01000000, 0x01000000, 0x01000000), {16777216.0, 16777216.0, 16777216.0, 1.0}}, - - {PIPE_FORMAT_R32G32B32A32_USCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x00000000, 0x00000000), { 0.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R32G32B32A32_USCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x01000000, 0x00000000, 0x00000000, 0x00000000), {16777216.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R32G32B32A32_USCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x01000000, 0x00000000, 0x00000000), { 0.0, 16777216.0, 0.0, 0.0}}, - {PIPE_FORMAT_R32G32B32A32_USCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x01000000, 0x00000000), { 0.0, 0.0, 16777216.0, 0.0}}, - {PIPE_FORMAT_R32G32B32A32_USCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x00000000, 0x01000000), { 0.0, 0.0, 0.0, 16777216.0}}, - {PIPE_FORMAT_R32G32B32A32_USCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x01000000, 0x01000000, 0x01000000, 0x01000000), {16777216.0, 16777216.0, 16777216.0, 16777216.0}}, - - {PIPE_FORMAT_R32_SNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x00000000), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32_SNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x7fffffff), { 1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32_SNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x80000001), { -1.0, 0.0, 0.0, 1.0}}, - - {PIPE_FORMAT_R32G32_SNORM, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x00000000, 0x00000000), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32_SNORM, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x7fffffff, 0x00000000), { 1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32_SNORM, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x80000001, 0x00000000), { -1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32_SNORM, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x00000000, 0x7fffffff), { 0.0, 1.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32_SNORM, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x00000000, 0x80000001), { 0.0, -1.0, 0.0, 1.0}}, - - {PIPE_FORMAT_R32G32B32_SNORM, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x00000000, 0x00000000), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32B32_SNORM, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x7fffffff, 0x00000000, 0x00000000), { 1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32B32_SNORM, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x80000001, 0x00000000, 0x00000000), { -1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32B32_SNORM, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x7fffffff, 0x00000000), { 0.0, 1.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32B32_SNORM, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x80000001, 0x00000000), { 0.0, -1.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32B32_SNORM, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x00000000, 0x7fffffff), { 0.0, 0.0, 1.0, 1.0}}, - {PIPE_FORMAT_R32G32B32_SNORM, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x00000000, 0x80000001), { 0.0, 0.0, -1.0, 1.0}}, - - {PIPE_FORMAT_R32G32B32A32_SNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x00000000, 0x00000000), { 0.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R32G32B32A32_SNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x7fffffff, 0x00000000, 0x00000000, 0x00000000), { 1.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R32G32B32A32_SNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x80000001, 0x00000000, 0x00000000, 0x00000000), { -1.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R32G32B32A32_SNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x7fffffff, 0x00000000, 0x00000000), { 0.0, 1.0, 0.0, 0.0}}, - {PIPE_FORMAT_R32G32B32A32_SNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x80000001, 0x00000000, 0x00000000), { 0.0, -1.0, 0.0, 0.0}}, - {PIPE_FORMAT_R32G32B32A32_SNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x7fffffff, 0x00000000), { 0.0, 0.0, 1.0, 0.0}}, - {PIPE_FORMAT_R32G32B32A32_SNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x80000001, 0x00000000), { 0.0, 0.0, -1.0, 0.0}}, - {PIPE_FORMAT_R32G32B32A32_SNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x00000000, 0x7fffffff), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32B32A32_SNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x00000000, 0x80000001), { 0.0, 0.0, 0.0, -1.0}}, - - {PIPE_FORMAT_R32_SSCALED, PACKED_1x32(0xffffffff), PACKED_1x32(0x00000000), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32_SSCALED, PACKED_1x32(0xffffffff), PACKED_1x32(0x01000000), { 16777216.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32_SSCALED, PACKED_1x32(0xffffffff), PACKED_1x32(0xff000000), {-16777216.0, 0.0, 0.0, 1.0}}, - - {PIPE_FORMAT_R32G32_SSCALED, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x00000000, 0x00000000), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32_SSCALED, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x01000000, 0x00000000), { 16777216.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32_SSCALED, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0xff000000, 0x00000000), {-16777216.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32_SSCALED, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x00000000, 0x01000000), { 0.0, 16777216.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32_SSCALED, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x00000000, 0xff000000), { 0.0, -16777216.0, 0.0, 1.0}}, - - {PIPE_FORMAT_R32G32B32_SSCALED, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x00000000, 0x00000000), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32B32_SSCALED, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x01000000, 0x00000000, 0x00000000), { 16777216.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32B32_SSCALED, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0xff000000, 0x00000000, 0x00000000), {-16777216.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32B32_SSCALED, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x01000000, 0x00000000), { 0.0, 16777216.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32B32_SSCALED, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0xff000000, 0x00000000), { 0.0, -16777216.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32B32_SSCALED, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x00000000, 0x01000000), { 0.0, 0.0, 16777216.0, 1.0}}, - {PIPE_FORMAT_R32G32B32_SSCALED, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x00000000, 0xff000000), { 0.0, 0.0, -16777216.0, 1.0}}, - - {PIPE_FORMAT_R32G32B32A32_SSCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x00000000, 0x00000000), { 0.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R32G32B32A32_SSCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x01000000, 0x00000000, 0x00000000, 0x00000000), { 16777216.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R32G32B32A32_SSCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0xff000000, 0x00000000, 0x00000000, 0x00000000), {-16777216.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R32G32B32A32_SSCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x01000000, 0x00000000, 0x00000000), { 0.0, 16777216.0, 0.0, 0.0}}, - {PIPE_FORMAT_R32G32B32A32_SSCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0xff000000, 0x00000000, 0x00000000), { 0.0, -16777216.0, 0.0, 0.0}}, - {PIPE_FORMAT_R32G32B32A32_SSCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x01000000, 0x00000000), { 0.0, 0.0, 16777216.0, 0.0}}, - {PIPE_FORMAT_R32G32B32A32_SSCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0xff000000, 0x00000000), { 0.0, 0.0, -16777216.0, 0.0}}, - {PIPE_FORMAT_R32G32B32A32_SSCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x00000000, 0x01000000), { 0.0, 0.0, 0.0, 16777216.0}}, - {PIPE_FORMAT_R32G32B32A32_SSCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x00000000, 0xff000000), { 0.0, 0.0, 0.0, -16777216.0}}, - - /* - * Standard 32-bit float formats - */ - - {PIPE_FORMAT_R32_FLOAT, PACKED_1x32(0xffffffff), PACKED_1x32(0x00000000), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32_FLOAT, PACKED_1x32(0xffffffff), PACKED_1x32(0x3f800000), { 1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32_FLOAT, PACKED_1x32(0xffffffff), PACKED_1x32(0xbf800000), { -1.0, 0.0, 0.0, 1.0}}, - - {PIPE_FORMAT_R32G32_FLOAT, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x00000000, 0x00000000), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32_FLOAT, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x3f800000, 0x00000000), { 1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32_FLOAT, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0xbf800000, 0x00000000), {-1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32_FLOAT, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x00000000, 0x3f800000), { 0.0, 1.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32_FLOAT, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x00000000, 0xbf800000), { 0.0, -1.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32_FLOAT, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x3f800000, 0x3f800000), { 1.0, 1.0, 0.0, 1.0}}, - - {PIPE_FORMAT_R32G32B32_FLOAT, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x00000000, 0x00000000), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32B32_FLOAT, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x3f800000, 0x00000000, 0x00000000), { 1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32B32_FLOAT, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0xbf800000, 0x00000000, 0x00000000), {-1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32B32_FLOAT, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x3f800000, 0x00000000), { 0.0, 1.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32B32_FLOAT, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0xbf800000, 0x00000000), { 0.0, -1.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32B32_FLOAT, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x00000000, 0x3f800000), { 0.0, 0.0, 1.0, 1.0}}, - {PIPE_FORMAT_R32G32B32_FLOAT, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x00000000, 0xbf800000), { 0.0, 0.0, -1.0, 1.0}}, - {PIPE_FORMAT_R32G32B32_FLOAT, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x3f800000, 0x3f800000, 0x3f800000), { 1.0, 1.0, 1.0, 1.0}}, - - {PIPE_FORMAT_R32G32B32A32_FLOAT, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x00000000, 0x00000000), { 0.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R32G32B32A32_FLOAT, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x3f800000, 0x00000000, 0x00000000, 0x00000000), { 1.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R32G32B32A32_FLOAT, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0xbf800000, 0x00000000, 0x00000000, 0x00000000), {-1.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R32G32B32A32_FLOAT, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x3f800000, 0x00000000, 0x00000000), { 0.0, 1.0, 0.0, 0.0}}, - {PIPE_FORMAT_R32G32B32A32_FLOAT, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0xbf800000, 0x00000000, 0x00000000), { 0.0, -1.0, 0.0, 0.0}}, - {PIPE_FORMAT_R32G32B32A32_FLOAT, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x3f800000, 0x00000000), { 0.0, 0.0, 1.0, 0.0}}, - {PIPE_FORMAT_R32G32B32A32_FLOAT, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0xbf800000, 0x00000000), { 0.0, 0.0, -1.0, 0.0}}, - {PIPE_FORMAT_R32G32B32A32_FLOAT, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x00000000, 0x3f800000), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32B32A32_FLOAT, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x00000000, 0xbf800000), { 0.0, 0.0, 0.0, -1.0}}, - {PIPE_FORMAT_R32G32B32A32_FLOAT, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000), { 1.0, 1.0, 1.0, 1.0}}, -}; - - static boolean test_format_unpack_4f(const struct util_format_test_case *test) { @@ -596,7 +60,7 @@ test_format_unpack_4f(const struct util_format_test_case *test) static boolean test_format_pack_4f(const struct util_format_test_case *test) { - uint8_t packed[MAX_PACKED_BYTES]; + uint8_t packed[UTIL_FORMAT_MAX_PACKED_BYTES]; unsigned i; boolean success; @@ -605,7 +69,7 @@ test_format_pack_4f(const struct util_format_test_case *test) util_format_pack_4f(test->format, packed, test->unpacked[0], test->unpacked[1], test->unpacked[2], test->unpacked[3]); success = TRUE; - for (i = 0; i < MAX_PACKED_BYTES; ++i) + for (i = 0; i < UTIL_FORMAT_MAX_PACKED_BYTES; ++i) if ((test->packed[i] & test->mask[i]) != (packed[i] & test->mask[i])) success = FALSE; @@ -627,13 +91,27 @@ test_format_pack_4f(const struct util_format_test_case *test) } -static void +static boolean convert_4f_to_4ub(uint8_t *dst, const double *src) { unsigned i; + boolean accurate = TRUE; - for (i = 0; i < 4; ++i) - dst[i] = CLAMP(src[i], 0.0, 1.0) * 255.0; + for (i = 0; i < 4; ++i) { + if (src[i] < 0.0) { + accurate = FALSE; + dst[i] = 0; + } + else if (src[i] > 1.0) { + accurate = FALSE; + dst[i] = 255; + } + else { + dst[i] = src[i] * 255.0; + } + } + + return accurate; } @@ -667,18 +145,23 @@ static boolean test_format_pack_4ub(const struct util_format_test_case *test) { uint8_t unpacked[4]; - uint8_t packed[MAX_PACKED_BYTES]; + uint8_t packed[UTIL_FORMAT_MAX_PACKED_BYTES]; unsigned i; boolean success; - convert_4f_to_4ub(unpacked, test->unpacked); + if (!convert_4f_to_4ub(unpacked, test->unpacked)) { + /* + * Skip test cases which cannot be represented by four unorm bytes. + */ + return TRUE; + } memset(packed, 0, sizeof packed); util_format_pack_4ub(test->format, packed, unpacked[0], unpacked[1], unpacked[2], unpacked[3]); success = TRUE; - for (i = 0; i < MAX_PACKED_BYTES; ++i) + for (i = 0; i < UTIL_FORMAT_MAX_PACKED_BYTES; ++i) if ((test->packed[i] & test->mask[i]) != (packed[i] & test->mask[i])) success = FALSE; @@ -711,15 +194,16 @@ test_one(test_func_t func, const char *suffix) unsigned i; bool success = TRUE; - for (i = 0; i < sizeof(test_cases)/sizeof(test_cases[0]); ++i) { - if (test_cases[i].format != last_format) { + for (i = 0; i < util_format_nr_test_cases; ++i) { + const struct util_format_test_case *test = &util_format_test_cases[i]; + if (test->format != last_format) { const struct util_format_description *format_desc; - format_desc = util_format_description(test_cases[i].format); - printf("Testing %s.%s ...\n", format_desc->name, suffix); - last_format = test_cases[i].format; + format_desc = util_format_description(test->format); + printf("Testing util_format_%s_%s ...\n", format_desc->short_name, suffix); + last_format = test->format; } - if (!func(&test_cases[i])) + if (!func(&util_format_test_cases[i])) success = FALSE; } diff --git a/progs/glsl/Makefile b/progs/glsl/Makefile index 3b5a5959ae..6030c8002f 100644 --- a/progs/glsl/Makefile +++ b/progs/glsl/Makefile @@ -26,6 +26,7 @@ PROG_SOURCES = \ convolutions.c \ deriv.c \ fragcoord.c \ + fsraytrace.c \ identity.c \ linktest.c \ mandelbrot.c \ @@ -46,7 +47,8 @@ PROG_SOURCES = \ trirast.c \ twoside.c \ vert-or-frag-only.c \ - vert-tex.c + vert-tex.c \ + vsraytrace.c UTIL_HEADERS = \ extfuncs.h \ diff --git a/progs/glsl/SConscript b/progs/glsl/SConscript index 8f2ebcf69c..02884e5a71 100644 --- a/progs/glsl/SConscript +++ b/progs/glsl/SConscript @@ -8,6 +8,7 @@ progs = [ 'convolutions', 'deriv', 'fragcoord', + 'fsraytrace', 'identity', 'linktest', 'mandelbrot', @@ -27,6 +28,7 @@ progs = [ 'twoside', 'vert-or-frag-only', 'vert-tex', + 'vsraytrace', ] for prog in progs: diff --git a/progs/glsl/fsraytrace.c b/progs/glsl/fsraytrace.c new file mode 100644 index 0000000000..8d54757e59 --- /dev/null +++ b/progs/glsl/fsraytrace.c @@ -0,0 +1,388 @@ +/* -*- mode: c; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; coding: utf-8-unix -*- */ +/* + Copyright (c) 2010 Kristóf Ralovich + + 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 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. +*/ + + +#include <stdio.h> +#include <stdlib.h> +#include <GL/glew.h> +#include <GL/glut.h> +#include "shaderutil.h" + + +static int Win; +static int WinWidth = 512, WinHeight = 512; +static GLfloat Xrot = 0, Yrot = 0; +static int mouseGrabbed = 0; +static GLuint vertShader; +static GLuint fragShader; +static GLuint program; + +static const char* vsSource = + "varying vec2 rayDir;\n" + "\n" + "void main()\n" + "{\n" + " rayDir = gl_MultiTexCoord0.xy - vec2(0.5,0.5);\n" + " gl_Position = gl_ProjectionMatrix * gl_Vertex;\n" + "}\n"; + +static const char* fsSource = + "const float INF = 9999.9; \n" + "const float EPSILON = 0.00001; \n" + "const vec3 lightPos = vec3(0.0, 8.0, 1.0); \n" + "const vec4 backgroundColor = vec4(0.2,0.3,0.4,1); \n" + " \n" + "varying vec2 rayDir; \n" + " \n" + "uniform mat3 rot; \n" + " \n" + "struct Ray \n" + "{ \n" + "vec3 orig; \n" + "vec3 dir; \n" + "}; \n" + " \n" + "struct Sphere \n" + "{ \n" + " vec3 c; \n" + " float r; \n" + "}; \n" + " \n" + "struct Isec \n" + "{ \n" + " float t; \n" + " int idx; \n" + " vec3 hit; \n" + " vec3 n; \n" + "}; \n" + " \n" + "const Sphere spheres0 = Sphere( vec3(0.0,0.0,-1.0), 0.5 ); \n" + "const Sphere spheres1 = Sphere( vec3(-3.0,0.0,-1.0), 1.5 ); \n" + "const Sphere spheres2 = Sphere( vec3(0.0,3.0,-1.0), 0.5 ); \n" + "const Sphere spheres3 = Sphere( vec3(2.0,0.0,-1.0), 1.0 ); \n" + " \n" + "// Mesa intel gen4 generates \"unsupported IR in fragment shader 13\" for\n" + "// sqrt, let's work around. \n" + "float \n" + "sqrt_hack(float f2) \n" + "{ \n" + " vec3 v = vec3(f2,0.0,0.0); \n" + " return length(v); \n" + "} \n" + " \n" + "void \n" + "intersect(const in Ray ray, \n" + " const in Sphere sph, \n" + " const in int idx, \n" + " inout Isec isec) \n" + "{ \n" + " // Project both o and the sphere to the plane perpendicular to d \n" + " // and containing c. Let x be the point where the ray intersects \n" + " // the plane. If |x-c| < r, the ray intersects the sphere. \n" + " vec3 o = ray.orig; \n" + " vec3 d = ray.dir; \n" + " vec3 n = -d; \n" + " vec3 c = sph.c; \n" + " float r = sph.r; \n" + " float t = dot(c-o,n)/dot(n,d); \n" + " vec3 x = o+d*t; \n" + " float e = length(x-c); \n" + " if(e > r) \n" + " { \n" + " // no intersection \n" + " return; \n" + " } \n" + " \n" + " // Apply Pythagorean theorem on the (intersection,x,c) triangle \n" + " // to get the distance between c and the intersection. \n" + "#ifndef BUGGY_INTEL_GEN4_GLSL \n" + " float f = sqrt(r*r - e*e); \n" + "#else \n" + " float f = sqrt_hack(r*r - e*e); \n" + "#endif \n" + " float dist = t - f; \n" + " if(dist < 0.0) \n" + " { \n" + " // inside the sphere \n" + " return; \n" + " } \n" + " \n" + " if(dist < EPSILON) \n" + " return; \n" + " \n" + " if(dist > isec.t) \n" + " return; \n" + " \n" + " isec.t = dist; \n" + " isec.idx = idx; \n" + " \n" + " isec.hit = ray.orig + ray.dir * isec.t; \n" + " isec.n = (isec.hit - c) / r; \n" + "} \n" + " \n" + "Isec \n" + "intersect(const in Ray ray, \n" + " const in float max_t /*= INF*/) \n" + "{ \n" + " Isec nearest; \n" + " nearest.t = max_t; \n" + " nearest.idx = -1; \n" + " \n" + " intersect(ray, spheres0, 0, nearest); \n" + " intersect(ray, spheres1, 1, nearest); \n" + " intersect(ray, spheres2, 2, nearest); \n" + " intersect(ray, spheres3, 3, nearest); \n" + " \n" + " return nearest; \n" + "} \n" + " \n" + "vec4 \n" + "idx2color(const in int idx) \n" + "{ \n" + " vec4 diff; \n" + " if(idx == 0) \n" + " diff = vec4(1.0, 0.0, 0.0, 0.0); \n" + " else if(idx == 1) \n" + " diff = vec4(0.0, 1.0, 0.0, 0.0); \n" + " else if(idx == 2) \n" + " diff = vec4(0.0, 0.0, 1.0, 0.0); \n" + " else if(idx == 3) \n" + " diff = vec4(1.0, 1.0, 0.0, 0.0); \n" + " return diff; \n" + "} \n" + " \n" + "vec4 \n" + "trace0(const in Ray ray) \n" + "{ \n" + " Isec isec = intersect(ray, INF); \n" + " \n" + " if(isec.idx == -1) \n" + " { \n" + " return backgroundColor; \n" + " } \n" + " \n" + " vec4 diff = idx2color(isec.idx); \n" + " \n" + " vec3 N = isec.n; \n" + " vec3 L = normalize(lightPos-isec.hit); \n" + " vec3 camera_dir = normalize(ray.orig - isec.hit); \n" + " return dot(N,L)*diff + pow( \n" + " clamp(dot(reflect(-L,N),camera_dir),0.0,1.0),16.0); \n" + "} \n" + " \n" + "vec4 \n" + "trace1(const in Ray ray) \n" + "{ \n" + " Isec isec = intersect(ray, INF); \n" + " \n" + " if(isec.idx == -1) \n" + " { \n" + " return backgroundColor; \n" + " } \n" + " \n" + " Ray reflRay = Ray(isec.hit, reflect(ray.dir, isec.n)); \n" + " \n" + " vec4 reflCol = trace0(reflRay); \n" + " \n" + " vec4 diff = idx2color(isec.idx) + reflCol; \n" + " \n" + " vec3 N = isec.n; \n" + " vec3 L = normalize(lightPos-isec.hit); \n" + " vec3 camera_dir = normalize(ray.orig - isec.hit); \n" + " return dot(N,L)*diff + pow( \n" + " clamp(dot(reflect(-L,N),camera_dir),0.0,1.0),16.0); \n" + "} \n" + " \n" + "\n" + "void\n" + "main()\n" + "{\n" + " const float z = -0.5;\n" + " const vec3 cameraPos = vec3(0,0,3); \n" + " Ray r = Ray(cameraPos, normalize(vec3(rayDir, z) * rot));\n" + " gl_FragColor = trace1(r);\n" + "}\n"; + + + +static void +Idle(void) +{ + glutPostRedisplay(); +} + + +static void +Draw(void) +{ + float rot[9] = {1,0,0, 0,1,0, 0,0,1}; + GLint location = glGetUniformLocation(program, "rot"); + static const float m = -10.F; + static const float p = 10.F; + static const float d = -0.5F; + + glUseProgram(program); + glUniformMatrix3fv(location, 1, 0, rot); + + glBegin(GL_QUADS); + { + glTexCoord2f(0.0F, 0.0F); glVertex3f(m, m, d); + glTexCoord2f(1.0F, 0.0F); glVertex3f(p, m, d); + glTexCoord2f(1.0F, 1.0F); glVertex3f(p, p, d); + glTexCoord2f(0.0F, 1.0F); glVertex3f(m, p, d); + } + glEnd(); + glUseProgram(0); + + glutSwapBuffers(); + + { + static int frames = 0; + static int t0 = 0; + static int t1 = 0; + float dt; + frames++; + t1 = glutGet(GLUT_ELAPSED_TIME); + dt = (float)(t1-t0)/1000.0F; + if(dt >= 5.0F) + { + float fps = (float)frames / dt; + printf("%f FPS (%d frames in %f seconds)\n", fps, frames, dt); + frames = 0; + t0 = t1; + } + } +} + + +static void +Reshape(int width, int height) +{ + WinWidth = width; + WinHeight = height; + glViewport(0, 0, width, height); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-10, 10, -10, 10, -1, 1); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); +} + + +static void +Key(unsigned char key, int x, int y) +{ + (void) x; + (void) y; + switch (key) { + case 27: + glutDestroyWindow(Win); + exit(0); + break; + } + glutPostRedisplay(); +} + + +static +void +drag(int x, int y) +{ + float scale = 1.5F; + if(mouseGrabbed) + { + Xrot = (float)(x - WinWidth/2) / scale; + Yrot = (float)(y - WinHeight/2) / scale; + printf("%4.2f %4.2f\n", Xrot, Yrot); + } +} + + +static +void +mouse(int button, int state, int x, int y) +{ + if(state == GLUT_DOWN) + { + mouseGrabbed = !mouseGrabbed; + } +} + + +static void +Init(void) +{ + glDisable(GL_DEPTH_TEST); + + if(!ShadersSupported()) + { + fprintf(stderr, "Shaders are not supported!\n"); + exit(-1); + } + + vertShader = CompileShaderText(GL_VERTEX_SHADER, vsSource); + fragShader = CompileShaderText(GL_FRAGMENT_SHADER, fsSource); + program = LinkShaders(vertShader, fragShader); + glUseProgram(0); + + if(glGetError() != 0) + { + fprintf(stderr, "Shaders were not loaded!\n"); + exit(-1); + } + + if(!glIsShader(vertShader)) + { + fprintf(stderr, "Vertex shader failed!\n"); + exit(-1); + } + + if(!glIsProgram(program)) + { + fprintf(stderr, "Shader program failed!\n"); + exit(-1); + } + + printf("GL_RENDERER = %s\n",(const char *) glGetString(GL_RENDERER)); +} + + +int +main(int argc, char *argv[]) +{ + glutInitWindowSize(WinWidth, WinHeight); + glutInit(&argc, argv); + glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); + Win = glutCreateWindow(argv[0]); + glewInit(); + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutDisplayFunc(Draw); + glutMouseFunc(mouse); + glutPassiveMotionFunc(drag); + glutIdleFunc(Idle); + Init(); + glutMainLoop(); + return 0; +} + diff --git a/progs/glsl/vsraytrace.c b/progs/glsl/vsraytrace.c new file mode 100644 index 0000000000..962b1bdb4c --- /dev/null +++ b/progs/glsl/vsraytrace.c @@ -0,0 +1,363 @@ +/* -*- mode: c; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; coding: utf-8-unix -*- */ +/* + Copyright (c) 2010 Kristóf Ralovich + + 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 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. +*/ + + +#include <stdio.h> +#include <stdlib.h> +#include <GL/glew.h> +#include <GL/glut.h> +#include "shaderutil.h" + + +static int Win; +static int WinWidth = 256, WinHeight = 256; +static int mouseGrabbed = 0; + +static const char* vsSource = + "const float INF = 9999.9; \n" + "const float EPSILON = 0.00001; \n" + "const vec3 lightPos = vec3(0.0, 8.0, 1.0); \n" + "const vec4 backgroundColor = vec4(0.2,0.3,0.4,1); \n" + " \n" + "uniform mat3 rot; \n" + " \n" + "struct Ray \n" + "{ \n" + "vec3 orig; \n" + "vec3 dir; \n" + "}; \n" + " \n" + "struct Sphere \n" + "{ \n" + " vec3 c; \n" + " float r; \n" + "}; \n" + " \n" + "struct Isec \n" + "{ \n" + " float t; \n" + " int idx; \n" + " vec3 hit; \n" + " vec3 n; \n" + "}; \n" + " \n" + "const Sphere spheres0 = Sphere( vec3(0.0,0.0,-1.0), 0.5 ); \n" + "const Sphere spheres1 = Sphere( vec3(-3.0,0.0,-1.0), 1.5 ); \n" + "const Sphere spheres2 = Sphere( vec3(0.0,3.0,-1.0), 0.5 ); \n" + "const Sphere spheres3 = Sphere( vec3(2.0,0.0,-1.0), 1.0 ); \n" + " \n" + "// Mesa intel gen4 generates \"unsupported IR in fragment shader 13\" for\n" + "// sqrt, let's work around. \n" + "float \n" + "sqrt_hack(float f2) \n" + "{ \n" + " vec3 v = vec3(f2,0.0,0.0); \n" + " return length(v); \n" + "} \n" + " \n" + "void \n" + "intersect(const in Ray ray, \n" + " const in Sphere sph, \n" + " const in int idx, \n" + " inout Isec isec) \n" + "{ \n" + " // Project both o and the sphere to the plane perpendicular to d \n" + " // and containing c. Let x be the point where the ray intersects \n" + " // the plane. If |x-c| < r, the ray intersects the sphere. \n" + " vec3 o = ray.orig; \n" + " vec3 d = ray.dir; \n" + " vec3 n = -d; \n" + " vec3 c = sph.c; \n" + " float r = sph.r; \n" + " float t = dot(c-o,n)/dot(n,d); \n" + " vec3 x = o+d*t; \n" + " float e = length(x-c); \n" + " if(e > r) \n" + " { \n" + " // no intersection \n" + " return; \n" + " } \n" + " \n" + " // Apply Pythagorean theorem on the (intersection,x,c) triangle \n" + " // to get the distance between c and the intersection. \n" + "#define BUGGY_INTEL_GEN4_GLSL 1 \n" + "#ifndef BUGGY_INTEL_GEN4_GLSL \n" + " float f = sqrt(r*r - e*e); \n" + "#else \n" + " float f = sqrt_hack(r*r - e*e); \n" + "#endif \n" + " float dist = t - f; \n" + " if(dist < 0.0) \n" + " { \n" + " // inside the sphere \n" + " return; \n" + " } \n" + " \n" + " if(dist < EPSILON) \n" + " return; \n" + " \n" + " if(dist > isec.t) \n" + " return; \n" + " \n" + " isec.t = dist; \n" + " isec.idx = idx; \n" + " \n" + " isec.hit = ray.orig + ray.dir * isec.t; \n" + " isec.n = (isec.hit - c) / r; \n" + "} \n" + " \n" + "Isec \n" + "intersect(const in Ray ray, \n" + " const in float max_t /*= INF*/) \n" + "{ \n" + " Isec nearest; \n" + " nearest.t = max_t; \n" + " nearest.idx = -1; \n" + " \n" + " intersect(ray, spheres0, 0, nearest); \n" + " intersect(ray, spheres1, 1, nearest); \n" + " intersect(ray, spheres2, 2, nearest); \n" + " intersect(ray, spheres3, 3, nearest); \n" + " \n" + " return nearest; \n" + "} \n" + " \n" + "vec4 \n" + "idx2color(const in int idx) \n" + "{ \n" + " vec4 diff; \n" + " if(idx == 0) \n" + " diff = vec4(1.0, 0.0, 0.0, 0.0); \n" + " else if(idx == 1) \n" + " diff = vec4(0.0, 1.0, 0.0, 0.0); \n" + " else if(idx == 2) \n" + " diff = vec4(0.0, 0.0, 1.0, 0.0); \n" + " else if(idx == 3) \n" + " diff = vec4(1.0, 1.0, 0.0, 0.0); \n" + " return diff; \n" + "} \n" + " \n" + "vec4 \n" + "trace0(const in Ray ray) \n" + "{ \n" + " Isec isec = intersect(ray, INF); \n" + " \n" + " if(isec.idx == -1) \n" + " { \n" + " return backgroundColor; \n" + " } \n" + " \n" + " vec4 diff = idx2color(isec.idx); \n" + " \n" + " vec3 N = isec.n; \n" + " vec3 L = normalize(lightPos-isec.hit); \n" + " vec3 camera_dir = normalize(ray.orig - isec.hit); \n" + " return dot(N,L)*diff + pow( \n" + " clamp(dot(reflect(-L,N),camera_dir),0.0,1.0),16.0); \n" + "} \n" + " \n" + "vec4 \n" + "trace1(const in Ray ray) \n" + "{ \n" + " Isec isec = intersect(ray, INF); \n" + " \n" + " if(isec.idx == -1) \n" + " { \n" + " return backgroundColor; \n" + " } \n" + " \n" + " Ray reflRay = Ray(isec.hit, reflect(ray.dir, isec.n)); \n" + " \n" + " vec4 reflCol = trace0(reflRay); \n" + " \n" + " vec4 diff = idx2color(isec.idx) + reflCol; \n" + " \n" + " vec3 N = isec.n; \n" + " vec3 L = normalize(lightPos-isec.hit); \n" + " vec3 camera_dir = normalize(ray.orig - isec.hit); \n" + " return dot(N,L)*diff + pow( \n" + " clamp(dot(reflect(-L,N),camera_dir),0.0,1.0),16.0); \n" + "} \n" + " \n" + "void main() \n" + "{ \n" + " const vec3 cameraPos = vec3(0,0,3); \n" + " vec3 rayDir = normalize(vec3(gl_Vertex.x, gl_Vertex.y, -1.0) * rot);\n" + " Ray ray = Ray(cameraPos, rayDir); \n" + " gl_Position = gl_Vertex; \n" + " gl_FrontColor = trace1(ray); \n" + "} \n"; + +static GLuint vertShader; +static GLuint program; + + +static void +Draw(void) +{ + const float w = 0.5F * WinWidth; + const float h = 0.5F * WinHeight; + int x,y; + + float rot[9] = {1,0,0, 0,1,0, 0,0,1}; + GLint location = glGetUniformLocation(program, "rot"); + + glUseProgram(program); + glUniformMatrix3fv(location, 1, 0, rot); + glBegin(GL_POINTS); + for(y = 0; y < WinHeight; y++) + { + for(x = 0; x < WinWidth; x++) + { + const float posx = x / w - 1.0F; + const float posy = y / h - 1.0F; + glVertex2f(posx, posy); + } + } + glEnd(); + glUseProgram(0); + + glutSwapBuffers(); + + { + static int frames = 0; + static int t0 = 0; + static int t1 = 0; + float dt; + frames++; + t1 = glutGet(GLUT_ELAPSED_TIME); + dt = (float)(t1-t0)/1000.0F; + if (dt >= 5.0F) + { + float fps = (float)frames / dt; + printf("%f FPS (%d frames in %f seconds)\n", fps, frames, dt); + frames = 0; + t0 = t1; + } + } +} + + +static void +Reshape(int width, int height) +{ + WinWidth = width; + WinHeight = height; + glViewport(0, 0, width, height); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); +} + + +static void +Key(unsigned char key, int x, int y) +{ + if(key == 27) + { + glutDestroyWindow(Win); + exit(0); + } + glutPostRedisplay(); +} + + +static +void +drag(int x, int y) +{ + if(mouseGrabbed) + { + printf("%4d %4d\n", x, y); + } +} + + +static +void +mouse(int button, int state, int x, int y) +{ + if(state == GLUT_DOWN) + { + mouseGrabbed = !mouseGrabbed; + } +} + + +static void +Init(void) +{ + glDisable(GL_DEPTH_TEST); + + if(!ShadersSupported()) + { + fprintf(stderr, "Shaders are not supported!\n"); + exit(-1); + } + + vertShader = CompileShaderText(GL_VERTEX_SHADER, vsSource); + program = LinkShaders(vertShader, 0); + glUseProgram(0); + + if(glGetError() != 0) + { + fprintf(stderr, "Shaders were not loaded!\n"); + exit(-1); + } + + if(!glIsShader(vertShader)) + { + fprintf(stderr, "Vertex shader failed!\n"); + exit(-1); + } + + if(!glIsProgram(program)) + { + fprintf(stderr, "Shader program failed!\n"); + exit(-1); + } + + printf("GL_RENDERER = %s\n",(const char *) glGetString(GL_RENDERER)); +} + + +int +main(int argc, char *argv[]) +{ + glutInitWindowSize(WinWidth, WinHeight); + glutInit(&argc, argv); + glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); + Win = glutCreateWindow(argv[0]); + glewInit(); + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutDisplayFunc(Draw); + glutIdleFunc(Draw); + glutMouseFunc(mouse); + glutMotionFunc(drag); + Init(); + glutMainLoop(); + return 0; +} + diff --git a/progs/objviewer/skybox.c b/progs/objviewer/skybox.c index 4e30742e20..93331b9c16 100644 --- a/progs/objviewer/skybox.c +++ b/progs/objviewer/skybox.c @@ -88,9 +88,9 @@ LoadSkyBoxCubeTexture(const char *filePosX, return 0; if (!load(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, fileNegX, GL_TRUE, GL_TRUE)) return 0; - if (!load(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, filePosY, 1+GL_FALSE, GL_TRUE)) + if (!load(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, filePosY, GL_TRUE, GL_TRUE)) return 0; - if (!load(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, fileNegY, 1+GL_FALSE, GL_TRUE)) + if (!load(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, fileNegY, GL_TRUE, GL_TRUE)) return 0; if (!load(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, filePosZ, GL_TRUE, GL_TRUE)) return 0; diff --git a/progs/samples/copy.c b/progs/samples/copy.c index 391c637d6f..353a3a2e1a 100644 --- a/progs/samples/copy.c +++ b/progs/samples/copy.c @@ -25,6 +25,7 @@ #include <stdio.h> #include <string.h> #include <stdlib.h> +#include <GL/glew.h> #include <GL/glut.h> @@ -35,7 +36,6 @@ GLint windW, windH; char *fileName = 0; PPMImage *image; -float point[3]; float zoom; GLint x, y; @@ -97,27 +97,27 @@ static void Mouse(int button, int state, int mouseX, int mouseY) static void Draw(void) { + GLint src[3], dst[3]; glClear(GL_COLOR_BUFFER_BIT); - point[0] = (windW / 2) - (image->sizeX / 2); - point[1] = (windH / 2) - (image->sizeY / 2); - point[2] = 0; - glRasterPos3fv(point); + src[0] = (int) ((windW / 2.0) - (image->sizeX / 2.0)); + src[1] = (int) ((windH / 2.0) - (image->sizeY / 2.0)); + src[2] = 0; + glWindowPos3ivARB(src); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glPixelZoom(1.0, 1.0); glDrawPixels(image->sizeX, image->sizeY, GL_RGB, GL_UNSIGNED_BYTE, image->data); - point[0] = (float)x; - point[1] = windH - (float)y; - point[2] = 0.0; - glRasterPos3fv(point); + dst[0] = x; + dst[1] = windH - y; + dst[2] = 0; + glWindowPos3ivARB(dst); glPixelZoom(zoom, zoom); - glCopyPixels((windW/2)-(image->sizeX/2), - (windH/2)-(image->sizeY/2), + glCopyPixels(src[0], src[1], image->sizeX, image->sizeY, GL_COLOR); glFlush(); @@ -170,8 +170,8 @@ int main(int argc, char **argv) image = LoadPPM(fileName); - windW = 300; - windH = 300; + windW = 2*300; + windH = 2*300; glutInitWindowPosition(0, 0); glutInitWindowSize( windW, windH); type = GLUT_RGB; @@ -182,6 +182,7 @@ int main(int argc, char **argv) exit(1); } + glewInit(); Init(); glutReshapeFunc(Reshape); diff --git a/progs/samples/loadppm.c b/progs/samples/loadppm.c index be056d6294..adae9b491e 100644 --- a/progs/samples/loadppm.c +++ b/progs/samples/loadppm.c @@ -9,7 +9,7 @@ static PPMImage *LoadPPM(const char *filename) char buff[16]; PPMImage *result; FILE *fp; - int maxval; + int maxval, w, h; fp = fopen(filename, "rb"); if (!fp) @@ -37,11 +37,13 @@ static PPMImage *LoadPPM(const char *filename) exit(1); } - if (fscanf(fp, "%lu %lu", &result->sizeX, &result->sizeY) != 2) + if (fscanf(fp, "%d %d", &w, &h) != 2) { fprintf(stderr, "Error loading image `%s'\n", filename); exit(1); } + result->sizeX = w; + result->sizeY = h; if (fscanf(fp, "%d", &maxval) != 1) { diff --git a/progs/tests/fbotest1.c b/progs/tests/fbotest1.c index 0cd7f95c35..a95fdff74c 100644 --- a/progs/tests/fbotest1.c +++ b/progs/tests/fbotest1.c @@ -36,8 +36,8 @@ Display( void ) /* draw to user framebuffer */ glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, MyFB); - glDrawBuffer(GL_COLOR_ATTACHMENT1_EXT); - glReadBuffer(GL_COLOR_ATTACHMENT1_EXT); + glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT); + glReadBuffer(GL_COLOR_ATTACHMENT0_EXT); status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); if (status != GL_FRAMEBUFFER_COMPLETE_EXT) { @@ -161,7 +161,7 @@ Init( void ) assert(i == MyFB); CheckError(__LINE__); - glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT, + glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, MyRB); glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGB, Width, Height); diff --git a/progs/tests/fbotest2.c b/progs/tests/fbotest2.c index f9c506193f..faf0dd8748 100644 --- a/progs/tests/fbotest2.c +++ b/progs/tests/fbotest2.c @@ -33,15 +33,16 @@ CheckError(int line) static void Display( void ) { - GLubyte *buffer = malloc(Width * Height * 4); + GLboolean copyPix = GL_FALSE; + GLboolean blitPix = GL_FALSE; GLenum status; CheckError(__LINE__); /* draw to user framebuffer */ glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, MyFB); - glDrawBuffer(GL_COLOR_ATTACHMENT1_EXT); - glReadBuffer(GL_COLOR_ATTACHMENT1_EXT); + glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT); + glReadBuffer(GL_COLOR_ATTACHMENT0_EXT); status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); if (status != GL_FRAMEBUFFER_COMPLETE_EXT) { @@ -63,16 +64,43 @@ Display( void ) glutSolidTeapot(2.0); glPopMatrix(); - /* read from user framebuffer */ - glReadPixels(0, 0, Width, Height, GL_RGBA, GL_UNSIGNED_BYTE, buffer); + if (copyPix) { + glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, MyFB); + glReadBuffer(GL_COLOR_ATTACHMENT0_EXT); + glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, 0); + glDrawBuffer(GL_BACK); - /* draw to window */ - glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); - glDisable(GL_DEPTH_TEST); /* in case window has depth buffer */ - glWindowPos2iARB(0, 0); - glDrawPixels(Width, Height, GL_RGBA, GL_UNSIGNED_BYTE, buffer); + glDisable(GL_DEPTH_TEST); /* in case window has depth buffer */ + + glWindowPos2iARB(0, 0); + glCopyPixels(0, 0, Width, Height, GL_COLOR); + } + else if (blitPix) { + glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, MyFB); + glReadBuffer(GL_COLOR_ATTACHMENT0_EXT); + glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, 0); + glDrawBuffer(GL_BACK); + + glDisable(GL_DEPTH_TEST); /* in case window has depth buffer */ + + glBlitFramebufferEXT(0, 0, Width, Height, + 0, 0, Width, Height, + GL_COLOR_BUFFER_BIT, GL_NEAREST); + } + else { + GLubyte *buffer = malloc(Width * Height * 4); + /* read from user framebuffer */ + glReadPixels(0, 0, Width, Height, GL_RGBA, GL_UNSIGNED_BYTE, buffer); + + /* draw to window */ + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); + glDisable(GL_DEPTH_TEST); /* in case window has depth buffer */ + glWindowPos2iARB(0, 0); + glDrawPixels(Width, Height, GL_RGBA, GL_UNSIGNED_BYTE, buffer); + + free(buffer); + } - free(buffer); glutSwapBuffers(); CheckError(__LINE__); } @@ -163,7 +191,7 @@ Init( void ) glGenRenderbuffersEXT(1, &ColorRb); glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, ColorRb); assert(glIsRenderbufferEXT(ColorRb)); - glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT, + glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, ColorRb); glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGB, Width, Height); diff --git a/progs/tests/fbotest3.c b/progs/tests/fbotest3.c index 8e288b38b8..c176f82d2b 100644 --- a/progs/tests/fbotest3.c +++ b/progs/tests/fbotest3.c @@ -50,8 +50,8 @@ Display( void ) /* draw to user framebuffer */ glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, MyFB); - glDrawBuffer(GL_COLOR_ATTACHMENT1_EXT); - glReadBuffer(GL_COLOR_ATTACHMENT1_EXT); + glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT); + glReadBuffer(GL_COLOR_ATTACHMENT0_EXT); status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); if (status != GL_FRAMEBUFFER_COMPLETE_EXT) { @@ -189,7 +189,7 @@ Init( void ) glGenRenderbuffersEXT(1, &ColorRb); glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, ColorRb); assert(glIsRenderbufferEXT(ColorRb)); - glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT, + glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, ColorRb); glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGB, Width, Height); diff --git a/progs/tests/stencil_twoside.c b/progs/tests/stencil_twoside.c index 7d871e5877..1010139a20 100644 --- a/progs/tests/stencil_twoside.c +++ b/progs/tests/stencil_twoside.c @@ -26,7 +26,7 @@ * \file stencil_twoside.c * * Simple test of GL_ATI_separate_stencil (or the OGL 2.0 equivalent) functionality. - * Four squares are drawn + * Five squares (or six if stencil wrap is available) are drawn * with different stencil modes, but all should be rendered with the same * final color. */ @@ -37,7 +37,7 @@ #include <GL/glut.h> static int use20syntax = 1; -static int Width = 550; +static int Width = 650; static int Height = 200; static const GLfloat Near = 5.0, Far = 25.0; @@ -70,7 +70,7 @@ static void Display( void ) */ glDisable(GL_STENCIL_TEST); - glTranslatef(-6.0, 0, 0); + glTranslatef(-7.0, 0, 0); glBegin(GL_QUADS); glColor3f( 0.5, 0.5, 0.5 ); glVertex2f(-1, -1); @@ -85,6 +85,9 @@ static void Display( void ) /* Draw the first two squares using incr for the affected face */ + /************************************************************************* + * 2nd square + */ if (use20syntax) { stencil_func_separate(GL_FRONT, GL_ALWAYS, 0, ~0); stencil_func_separate(GL_BACK, GL_ALWAYS, 0, ~0); @@ -98,8 +101,8 @@ static void Display( void ) glTranslatef(3.0, 0, 0); glBegin(GL_QUADS); glColor3f( 0.9, 0.9, 0.9 ); - /* this should be front facing */ for ( i = 0 ; i < (max_stencil + 5) ; i++ ) { + /* this should be front facing */ glVertex2f(-1, -1); glVertex2f( 1, -1); glVertex2f( 1, 1); @@ -107,6 +110,7 @@ static void Display( void ) } glEnd(); + /* stencil vals should be equal to max_stencil */ glStencilFunc(GL_EQUAL, max_stencil, ~0); glBegin(GL_QUADS); glColor3f( 0.5, 0.5, 0.5 ); @@ -116,6 +120,9 @@ static void Display( void ) glVertex2f(-1, 1); glEnd(); + /************************************************************************* + * 3rd square + */ if (use20syntax) { stencil_func_separate(GL_FRONT, GL_ALWAYS, 0, ~0); stencil_func_separate(GL_BACK, GL_ALWAYS, 0, ~0); @@ -129,9 +136,8 @@ static void Display( void ) glTranslatef(3.0, 0, 0); glBegin(GL_QUADS); glColor3f( 0.9, 0.9, 0.9 ); - - /* this should be back facing */ for ( i = 0 ; i < (max_stencil + 5) ; i++ ) { + /* this should be back facing */ glVertex2f(-1, -1); glVertex2f(-1, 1); glVertex2f( 1, 1); @@ -139,6 +145,7 @@ static void Display( void ) } glEnd(); + /* stencil vals should be equal to max_stencil */ glStencilFunc(GL_EQUAL, max_stencil, ~0); glBegin(GL_QUADS); glColor3f( 0.5, 0.5, 0.5 ); @@ -148,6 +155,9 @@ static void Display( void ) glVertex2f(-1, 1); glEnd(); + /************************************************************************* + * 4th square + */ if (use20syntax) { stencil_func_separate(GL_FRONT, GL_NEVER, 0, ~0); stencil_func_separate(GL_BACK, GL_ALWAYS, 0, ~0); @@ -161,15 +171,13 @@ static void Display( void ) glTranslatef(3.0, 0, 0); glBegin(GL_QUADS); glColor3f( 0.9, 0.9, 0.9 ); - - /* this should be back facing */ for ( i = 0 ; i < (max_stencil + 5) ; i++ ) { - /* this should be back facing */ + /* this should be back facing */ glVertex2f(-1, -1); glVertex2f(-1, 1); glVertex2f( 1, 1); glVertex2f( 1, -1); - /* this should be front facing */ + /* this should be front facing */ glVertex2f(-1, -1); glVertex2f( 1, -1); glVertex2f( 1, 1); @@ -177,6 +185,7 @@ static void Display( void ) } glEnd(); + /* stencil vals should be equal to max_stencil */ glStencilFunc(GL_EQUAL, max_stencil, ~0); glBegin(GL_QUADS); glColor3f( 0.5, 0.5, 0.5 ); @@ -186,6 +195,9 @@ static void Display( void ) glVertex2f(-1, 1); glEnd(); + /************************************************************************* + * 5th square + */ if (use20syntax) { stencil_func_separate(GL_FRONT, GL_ALWAYS, 0, ~0); stencil_func_separate(GL_BACK, GL_ALWAYS, 0, ~0); @@ -193,21 +205,19 @@ static void Display( void ) else { stencil_func_separate_ati(GL_ALWAYS, GL_ALWAYS, 0, ~0); } - stencil_op_separate(GL_FRONT, GL_KEEP, GL_KEEP, GL_DECR); - stencil_op_separate(GL_BACK, GL_KEEP, GL_KEEP, GL_INCR); + stencil_op_separate(GL_FRONT, GL_KEEP, GL_KEEP, GL_INCR); + stencil_op_separate(GL_BACK, GL_KEEP, GL_KEEP, GL_DECR); glTranslatef(3.0, 0, 0); glBegin(GL_QUADS); glColor3f( 0.9, 0.9, 0.9 ); - - /* this should be back facing */ for ( i = 0 ; i < (max_stencil + 5) ; i++ ) { - /* this should be back facing */ + /* this should be back facing */ glVertex2f(-1, -1); glVertex2f(-1, 1); glVertex2f( 1, 1); glVertex2f( 1, -1); - /* this should be front facing */ + /* this should be front facing */ glVertex2f(-1, -1); glVertex2f( 1, -1); glVertex2f( 1, 1); @@ -224,6 +234,47 @@ static void Display( void ) glVertex2f(-1, 1); glEnd(); + /************************************************************************* + * 6th square + */ + if (glutExtensionSupported("GL_EXT_stencil_wrap")) { + if (use20syntax) { + stencil_func_separate(GL_FRONT, GL_ALWAYS, 0, ~0); + stencil_func_separate(GL_BACK, GL_ALWAYS, 0, ~0); + } + else { + stencil_func_separate_ati(GL_ALWAYS, GL_ALWAYS, 0, ~0); + } + stencil_op_separate(GL_FRONT, GL_KEEP, GL_KEEP, GL_KEEP); + stencil_op_separate(GL_BACK, GL_KEEP, GL_KEEP, GL_INCR_WRAP); + + glTranslatef(3.0, 0, 0); + glBegin(GL_QUADS); + glColor3f( 0.9, 0.9, 0.9 ); + for ( i = 0 ; i < (max_stencil + 5) ; i++ ) { + /* this should be back facing */ + glVertex2f(-1, -1); + glVertex2f(-1, 1); + glVertex2f( 1, 1); + glVertex2f( 1, -1); + /* this should be front facing */ + glVertex2f(-1, -1); + glVertex2f( 1, -1); + glVertex2f( 1, 1); + glVertex2f(-1, 1); + } + glEnd(); + + glStencilFunc(GL_EQUAL, 260 - 255, ~0); + glBegin(GL_QUADS); + glColor3f( 0.5, 0.5, 0.5 ); + glVertex2f(-1, -1); + glVertex2f( 1, -1); + glVertex2f( 1, 1); + glVertex2f(-1, 1); + glEnd(); + } + glPopMatrix(); glutSwapBuffers(); @@ -278,7 +329,7 @@ static void Init( void ) stencil_func_separate_ati = (PFNGLSTENCILFUNCSEPARATEATIPROC) glutGetProcAddress( "glStencilFuncSeparateATI" ); stencil_op_separate = (PFNGLSTENCILOPSEPARATEPROC) glutGetProcAddress( "glStencilOpSeparate" ); - printf("\nAll 5 squares should be the same color.\n"); + printf("\nAll 5 (or 6) squares should be the same color.\n"); } diff --git a/progs/trivial/Makefile b/progs/trivial/Makefile index b4a903cb68..a10748f948 100644 --- a/progs/trivial/Makefile +++ b/progs/trivial/Makefile @@ -11,6 +11,7 @@ include $(TOP)/configs/current LIBS = -L$(TOP)/$(LIB_DIR) -l $(GLEW_LIB) -l$(GLUT_LIB) -l$(GLU_LIB) -l$(GL_LIB) $(APP_LIB_DEPS) SOURCES = \ + clear-fbo-scissor.c \ clear-fbo-tex.c \ clear-fbo.c \ clear-scissor.c \ diff --git a/progs/trivial/SConscript b/progs/trivial/SConscript index f480da047e..24b4f91fb0 100644 --- a/progs/trivial/SConscript +++ b/progs/trivial/SConscript @@ -1,7 +1,8 @@ Import('*') progs = [ - 'clear-fbo-tex', + 'clear-fbo-scissor', + 'clear-fbo-tex', 'clear-fbo', 'clear-scissor', 'clear-undefined', diff --git a/progs/trivial/clear-fbo-scissor.c b/progs/trivial/clear-fbo-scissor.c new file mode 100644 index 0000000000..6a605e16a8 --- /dev/null +++ b/progs/trivial/clear-fbo-scissor.c @@ -0,0 +1,234 @@ +/* + * Use scissor to clear the four quadrants of the FBO to different + * colors. Then draw a grey triangle in the middle. + */ + + +#include <assert.h> +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <string.h> +#include <GL/glew.h> +#include <GL/glut.h> +#include <GL/glu.h> + + +static int Width = 512, Height = 512; +static GLuint MyFB, MyRB; +static GLboolean UseTex = GL_FALSE; +static GLboolean UseCopyPix = GL_FALSE; + + +#define CheckError() \ + do { \ + GLenum err = glGetError(); \ + if (err != GL_NO_ERROR) \ + printf("Error: %s\n", gluErrorString(err)); \ + assert(err == GL_NO_ERROR); \ + } while (0) + + +static void +Init(void) +{ + GLenum status; + + fprintf(stderr, "GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); + fprintf(stderr, "GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); + fprintf(stderr, "GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR)); + fflush(stderr); + + if (!glutExtensionSupported("GL_EXT_framebuffer_object")) { + printf("GL_EXT_framebuffer_object not found!\n"); + exit(0); + } + + glGenFramebuffersEXT(1, &MyFB); + glGenRenderbuffersEXT(1, &MyRB); + + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, MyFB); + + if (UseTex) { + GLuint tex; + glGenTextures(1, &tex); + glBindTexture(GL_TEXTURE_2D, tex); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, Width, Height, 0, + GL_RGBA, GL_UNSIGNED_BYTE, NULL); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, + GL_COLOR_ATTACHMENT0_EXT, + GL_TEXTURE_2D, tex, 0); + } + else { + glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, MyRB); + + glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, + GL_COLOR_ATTACHMENT0_EXT, + GL_RENDERBUFFER_EXT, MyRB); + + glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGB, Width, Height); + } + + status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); + if (status != GL_FRAMEBUFFER_COMPLETE_EXT) { + fprintf(stderr, "Framebuffer object is incomplete (0x%x)!\n", status); + } + + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); +} + + +static void +Reshape(int width, int height) +{ + glViewport(0, 0, width, height); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); + glMatrixMode(GL_MODELVIEW); + + Width = width; + Height = height; + if (!UseTex) { + glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGB, Width, Height); + } +} + + +static void +Key(unsigned char key, int x, int y) +{ + if (key == 27) { + exit(0); + } + glutPostRedisplay(); +} + + +static void +Draw(void) +{ + GLboolean scissor = GL_TRUE; + + /* draw to user framebuffer */ + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, MyFB); + glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT); + glReadBuffer(GL_COLOR_ATTACHMENT0_EXT); + + glViewport(0, 0, Width, Height); + CheckError(); + + if (scissor) { + glEnable(GL_SCISSOR_TEST); + + /* lower-left = red */ + glClearColor(1, 0, 0, 0); + glScissor(0, 0, Width / 2, Height / 2); + glClear(GL_COLOR_BUFFER_BIT); + + /* lower-right = green */ + glClearColor(0, 1, 0, 0); + glScissor(Width / 2, 0, Width - Width / 2, Height / 2); + glClear(GL_COLOR_BUFFER_BIT); + + /* upper-left = blue */ + glClearColor(0, 0, 1, 0); + glScissor(0, Height / 2, Width / 2, Height - Height / 2); + glClear(GL_COLOR_BUFFER_BIT); + + /* upper-right = white */ + glClearColor(1, 1, 1, 0); + glScissor(Width / 2, Height / 2, Width - Width / 2, Height - Height / 2); + glClear(GL_COLOR_BUFFER_BIT); + + glDisable(GL_SCISSOR_TEST); + } + else { + glClearColor(0, 1, 0, 0); + glClear(GL_COLOR_BUFFER_BIT); + } + + CheckError(); + + /* gray triangle in middle, pointing up */ + glColor3f(0.5, 0.5, 0.5); + glBegin(GL_TRIANGLES); + glVertex2f(Width/4, Height/4); + glVertex2f(Width*3/4, Height/4); + glVertex2f(Width/2, Height*3/4); + glVertex2f(-0.5, -0.5); + glVertex2f(+0.5, -0.5); + glVertex2f( 0.0, 0.7); + glEnd(); + + CheckError(); + + /* copy fbo to window */ + glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, MyFB); + glReadBuffer(GL_COLOR_ATTACHMENT0_EXT); + glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, 0); + glDrawBuffer(GL_BACK); + + if (UseCopyPix) { + glWindowPos2i(0, 0); + glCopyPixels(0, 0, Width, Height, GL_COLOR); + } + else { + GLubyte *buffer = malloc(Width * Height * 4); + + /* read from user framebuffer */ + glReadPixels(0, 0, Width, Height, GL_RGBA, GL_UNSIGNED_BYTE, buffer); + + /* draw to window */ + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); + glWindowPos2iARB(0, 0); + glDrawPixels(Width, Height, GL_RGBA, GL_UNSIGNED_BYTE, buffer); + + free(buffer); + } + + /* Bind normal framebuffer */ + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); + + glutSwapBuffers(); + + CheckError(); +} + + +int +main(int argc, char *argv[]) +{ + int i; + + glutInit(&argc, argv); + glutInitWindowPosition(100, 0); + glutInitWindowSize(Width, Height); + glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-t") == 0) + UseTex = GL_TRUE; + else if (strcmp(argv[i], "-c") == 0) + UseCopyPix = GL_TRUE; + } + + if (UseTex) + printf("Using render to texture\n"); + else + printf("Using user-created render buffer\n"); + + if (!glutCreateWindow(argv[0])) { + exit(1); + } + + glewInit(); + Init(); + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutDisplayFunc(Draw); + glutMainLoop(); + return 0; +} diff --git a/progs/trivial/tri-stencil.c b/progs/trivial/tri-stencil.c index 9f68bca914..d66b68c415 100644 --- a/progs/trivial/tri-stencil.c +++ b/progs/trivial/tri-stencil.c @@ -77,6 +77,7 @@ static void Draw(void) glStencilFunc(GL_ALWAYS, 1, 1); glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); + /* red triangle (setting stencil to 1) */ glColor3ub(200, 0, 0); glBegin(GL_POLYGON); glVertex3i(-4, -4, 0); @@ -88,6 +89,7 @@ static void Draw(void) glStencilFunc(GL_EQUAL, 1, 1); glStencilOp(GL_INCR, GL_KEEP, GL_DECR); + /* green quad (if over red, decr stencil to 0, else incr to 1) */ glColor3ub(0, 200, 0); glBegin(GL_POLYGON); glVertex3i(3, 3, 0); @@ -101,6 +103,7 @@ static void Draw(void) glStencilFunc(GL_EQUAL, 1, 1); glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); + /* blue quad (where stencil == 1) */ glColor3ub(0, 0, 200); glBegin(GL_POLYGON); glVertex3f(2.5, 2.5, 0); diff --git a/progs/xdemos/Makefile b/progs/xdemos/Makefile index e87d55d011..660c540657 100644 --- a/progs/xdemos/Makefile +++ b/progs/xdemos/Makefile @@ -9,9 +9,9 @@ INCDIR = $(TOP)/include LIB_DEP = $(TOP)/$(LIB_DIR)/$(GL_LIB_NAME) # Add X11 and pthread libs to satisfy GNU gold. -APP_LIB_DEPS += -lX11 -lpthread +APP_LIB_DEPS += $(X11_LIBS) -lpthread -LIBS = -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) -L$(libdir) $(APP_LIB_DEPS) +LIBS = -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) $(APP_LIB_DEPS) PROGS = \ corender \ diff --git a/progs/xdemos/omlsync.c b/progs/xdemos/omlsync.c index a2baf4ad72..061d6c6861 100644 --- a/progs/xdemos/omlsync.c +++ b/progs/xdemos/omlsync.c @@ -249,11 +249,13 @@ int main(int argc, char *argv[]) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glRectf(0, 0, width, height); - glXSwapBuffersMscOML(disp, winGL, 0, divisor, remainder); - - if (wait_interval) { + if (!wait_interval) + glXSwapBuffersMscOML(disp, winGL, 0, divisor, + remainder); + else { glXWaitForMscOML(disp, winGL, msc + wait_interval, - 0, 0, &ust, &msc, &sbc); + divisor, remainder, &ust, &msc, &sbc); + glXSwapBuffersMscOML(disp, winGL, 0, 0, 0); } } |