st/mesa: remove st_tracked_state::name
[mesa.git] / src / mesa / state_tracker / st_atom_pixeltransfer.c
1 /**************************************************************************
2 *
3 * Copyright 2007 VMware, Inc.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 /* Authors:
29 * Brian Paul
30 */
31
32 #include "st_context.h"
33 #include "st_texture.h"
34
35 #include "util/u_inlines.h"
36 #include "util/u_pack_color.h"
37
38
39 /**
40 * Update the pixelmap texture with the contents of the R/G/B/A pixel maps.
41 */
42 static void
43 load_color_map_texture(struct gl_context *ctx, struct pipe_resource *pt)
44 {
45 struct st_context *st = st_context(ctx);
46 struct pipe_context *pipe = st->pipe;
47 struct pipe_transfer *transfer;
48 const GLuint rSize = ctx->PixelMaps.RtoR.Size;
49 const GLuint gSize = ctx->PixelMaps.GtoG.Size;
50 const GLuint bSize = ctx->PixelMaps.BtoB.Size;
51 const GLuint aSize = ctx->PixelMaps.AtoA.Size;
52 const uint texSize = pt->width0;
53 uint *dest;
54 uint i, j;
55
56 dest = (uint *) pipe_transfer_map(pipe,
57 pt, 0, 0, PIPE_TRANSFER_WRITE,
58 0, 0, texSize, texSize, &transfer);
59
60 /* Pack four 1D maps into a 2D texture:
61 * R map is placed horizontally, indexed by S, in channel 0
62 * G map is placed vertically, indexed by T, in channel 1
63 * B map is placed horizontally, indexed by S, in channel 2
64 * A map is placed vertically, indexed by T, in channel 3
65 */
66 for (i = 0; i < texSize; i++) {
67 for (j = 0; j < texSize; j++) {
68 union util_color uc;
69 int k = (i * texSize + j);
70 float rgba[4];
71 rgba[0] = ctx->PixelMaps.RtoR.Map[j * rSize / texSize];
72 rgba[1] = ctx->PixelMaps.GtoG.Map[i * gSize / texSize];
73 rgba[2] = ctx->PixelMaps.BtoB.Map[j * bSize / texSize];
74 rgba[3] = ctx->PixelMaps.AtoA.Map[i * aSize / texSize];
75 util_pack_color(rgba, pt->format, &uc);
76 *(dest + k) = uc.ui[0];
77 }
78 }
79
80 pipe_transfer_unmap(pipe, transfer);
81 }
82
83 /**
84 * Upload the pixel transfer color map texture.
85 */
86 static void
87 update_pixel_transfer(struct st_context *st)
88 {
89 struct gl_context *ctx = st->ctx;
90
91 if (ctx->Pixel.MapColorFlag) {
92 /* create the colormap/texture now if not already done */
93 if (!st->pixel_xfer.pixelmap_texture) {
94 st->pixel_xfer.pixelmap_texture = st_create_color_map_texture(ctx);
95 st->pixel_xfer.pixelmap_sampler_view =
96 st_create_texture_sampler_view(st->pipe,
97 st->pixel_xfer.pixelmap_texture);
98 }
99 load_color_map_texture(ctx, st->pixel_xfer.pixelmap_texture);
100 }
101 }
102
103
104 const struct st_tracked_state st_update_pixel_transfer = {
105 { /* dirty */
106 _NEW_PIXEL, /* mesa */
107 0, /* st */
108 },
109 update_pixel_transfer /* update */
110 };