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_sampler_view.h"
34 #include "st_texture.h"
36 #include "util/u_inlines.h"
37 #include "util/u_pack_color.h"
41 * Update the pixelmap texture with the contents of the R/G/B/A pixel maps.
44 load_color_map_texture(struct gl_context
*ctx
, struct pipe_resource
*pt
)
46 struct st_context
*st
= st_context(ctx
);
47 struct pipe_context
*pipe
= st
->pipe
;
48 struct pipe_transfer
*transfer
;
49 const GLuint rSize
= ctx
->PixelMaps
.RtoR
.Size
;
50 const GLuint gSize
= ctx
->PixelMaps
.GtoG
.Size
;
51 const GLuint bSize
= ctx
->PixelMaps
.BtoB
.Size
;
52 const GLuint aSize
= ctx
->PixelMaps
.AtoA
.Size
;
53 const uint texSize
= pt
->width0
;
57 dest
= (uint
*) pipe_transfer_map(pipe
,
58 pt
, 0, 0, PIPE_TRANSFER_WRITE
,
59 0, 0, texSize
, texSize
, &transfer
);
61 /* Pack four 1D maps into a 2D texture:
62 * R map is placed horizontally, indexed by S, in channel 0
63 * G map is placed vertically, indexed by T, in channel 1
64 * B map is placed horizontally, indexed by S, in channel 2
65 * A map is placed vertically, indexed by T, in channel 3
67 for (i
= 0; i
< texSize
; i
++) {
68 for (j
= 0; j
< texSize
; j
++) {
70 int k
= (i
* texSize
+ j
);
72 rgba
[0] = ctx
->PixelMaps
.RtoR
.Map
[j
* rSize
/ texSize
];
73 rgba
[1] = ctx
->PixelMaps
.GtoG
.Map
[i
* gSize
/ texSize
];
74 rgba
[2] = ctx
->PixelMaps
.BtoB
.Map
[j
* bSize
/ texSize
];
75 rgba
[3] = ctx
->PixelMaps
.AtoA
.Map
[i
* aSize
/ texSize
];
76 util_pack_color(rgba
, pt
->format
, &uc
);
77 *(dest
+ k
) = uc
.ui
[0];
81 pipe_transfer_unmap(pipe
, transfer
);
85 * Upload the pixel transfer color map texture.
88 st_update_pixel_transfer(struct st_context
*st
)
90 struct gl_context
*ctx
= st
->ctx
;
92 if (ctx
->Pixel
.MapColorFlag
) {
93 /* create the colormap/texture now if not already done */
94 if (!st
->pixel_xfer
.pixelmap_texture
) {
95 st
->pixel_xfer
.pixelmap_texture
= st_create_color_map_texture(ctx
);
96 st
->pixel_xfer
.pixelmap_sampler_view
=
97 st_create_texture_sampler_view(st
->pipe
,
98 st
->pixel_xfer
.pixelmap_texture
);
100 load_color_map_texture(ctx
, st
->pixel_xfer
.pixelmap_texture
);