1 /**************************************************************************
3 * Copyright 2007 VMware, Inc.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
32 #include "st_context.h"
33 #include "st_texture.h"
35 #include "util/u_inlines.h"
36 #include "util/u_pack_color.h"
40 * Update the pixelmap texture with the contents of the R/G/B/A pixel maps.
43 load_color_map_texture(struct gl_context
*ctx
, struct pipe_resource
*pt
)
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
;
56 dest
= (uint
*) pipe_transfer_map(pipe
,
57 pt
, 0, 0, PIPE_TRANSFER_WRITE
,
58 0, 0, texSize
, texSize
, &transfer
);
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
66 for (i
= 0; i
< texSize
; i
++) {
67 for (j
= 0; j
< texSize
; j
++) {
69 int k
= (i
* texSize
+ j
);
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];
80 pipe_transfer_unmap(pipe
, transfer
);
84 * Upload the pixel transfer color map texture.
87 update_pixel_transfer(struct st_context
*st
)
89 struct gl_context
*ctx
= st
->ctx
;
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
);
99 load_color_map_texture(ctx
, st
->pixel_xfer
.pixelmap_texture
);
104 const struct st_tracked_state st_update_pixel_transfer
= {
106 _NEW_PIXEL
, /* mesa */
109 update_pixel_transfer
/* update */