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 **************************************************************************/
33 #include "main/imports.h"
34 #include "main/image.h"
35 #include "main/bufferobj.h"
36 #include "main/macros.h"
38 #include "program/program.h"
39 #include "program/prog_print.h"
41 #include "st_context.h"
43 #include "st_atom_constbuf.h"
44 #include "st_program.h"
45 #include "st_cb_bitmap.h"
46 #include "st_texture.h"
48 #include "pipe/p_context.h"
49 #include "pipe/p_defines.h"
50 #include "pipe/p_shader_tokens.h"
51 #include "util/u_inlines.h"
52 #include "util/u_draw_quad.h"
53 #include "util/u_simple_shaders.h"
54 #include "util/u_upload_mgr.h"
55 #include "program/prog_instruction.h"
56 #include "cso_cache/cso_context.h"
60 * glBitmaps are drawn as textured quads. The user's bitmap pattern
61 * is stored in a texture image. An alpha8 texture format is used.
62 * The fragment shader samples a bit (texel) from the texture, then
63 * discards the fragment if the bit is off.
65 * Note that we actually store the inverse image of the bitmap to
66 * simplify the fragment program. An "on" bit gets stored as texel=0x0
67 * and an "off" bit is stored as texel=0xff. Then we kill the
68 * fragment if the negated texel value is less than zero.
73 * The bitmap cache attempts to accumulate multiple glBitmap calls in a
74 * buffer which is then rendered en mass upon a flush, state change, etc.
75 * A wide, short buffer is used to target the common case of a series
76 * of glBitmap calls being used to draw text.
78 static GLboolean UseBitmapCache
= GL_TRUE
;
81 #define BITMAP_CACHE_WIDTH 512
82 #define BITMAP_CACHE_HEIGHT 32
86 /** Window pos to render the cached image */
88 /** Bounds of region used in window coords */
89 GLint xmin
, ymin
, xmax
, ymax
;
93 /** Bitmap's Z position */
96 struct pipe_resource
*texture
;
97 struct pipe_transfer
*trans
;
101 /** An I8 texture image: */
106 /** Epsilon for Z comparisons */
107 #define Z_EPSILON 1e-06
111 * Copy user-provide bitmap bits into texture buffer, expanding
113 * "On" bits will set texels to 0x0.
114 * "Off" bits will not modify texels.
115 * Note that the image is actually going to be upside down in
116 * the texture. We deal with that with texcoords.
119 unpack_bitmap(struct st_context
*st
,
120 GLint px
, GLint py
, GLsizei width
, GLsizei height
,
121 const struct gl_pixelstore_attrib
*unpack
,
122 const GLubyte
*bitmap
,
123 ubyte
*destBuffer
, uint destStride
)
125 destBuffer
+= py
* destStride
+ px
;
127 _mesa_expand_bitmap(width
, height
, unpack
, bitmap
,
128 destBuffer
, destStride
, 0x0);
133 * Create a texture which represents a bitmap image.
135 static struct pipe_resource
*
136 make_bitmap_texture(struct gl_context
*ctx
, GLsizei width
, GLsizei height
,
137 const struct gl_pixelstore_attrib
*unpack
,
138 const GLubyte
*bitmap
)
140 struct st_context
*st
= st_context(ctx
);
141 struct pipe_context
*pipe
= st
->pipe
;
142 struct pipe_transfer
*transfer
;
144 struct pipe_resource
*pt
;
147 bitmap
= _mesa_map_pbo_source(ctx
, unpack
, bitmap
);
153 * Create texture to hold bitmap pattern.
155 pt
= st_texture_create(st
, st
->internal_target
, st
->bitmap
.tex_format
,
156 0, width
, height
, 1, 1, 0,
157 PIPE_BIND_SAMPLER_VIEW
);
159 _mesa_unmap_pbo_source(ctx
, unpack
);
163 dest
= pipe_transfer_map(st
->pipe
, pt
, 0, 0,
165 0, 0, width
, height
, &transfer
);
167 /* Put image into texture transfer */
168 memset(dest
, 0xff, height
* transfer
->stride
);
169 unpack_bitmap(st
, 0, 0, width
, height
, unpack
, bitmap
,
170 dest
, transfer
->stride
);
172 _mesa_unmap_pbo_source(ctx
, unpack
);
174 /* Release transfer */
175 pipe_transfer_unmap(pipe
, transfer
);
181 * Setup pipeline state prior to rendering the bitmap textured quad.
184 setup_render_state(struct gl_context
*ctx
,
185 struct pipe_sampler_view
*sv
,
186 const GLfloat
*color
)
188 struct st_context
*st
= st_context(ctx
);
189 struct cso_context
*cso
= st
->cso_context
;
190 struct st_fp_variant
*fpv
;
191 struct st_fp_variant_key key
;
193 memset(&key
, 0, sizeof(key
));
194 key
.st
= st
->has_shareable_shaders
? NULL
: st
;
195 key
.bitmap
= GL_TRUE
;
196 key
.clamp_color
= st
->clamp_frag_color_in_shader
&&
197 st
->ctx
->Color
._ClampFragmentColor
;
199 fpv
= st_get_fp_variant(st
, st
->fp
, &key
);
201 /* As an optimization, Mesa's fragment programs will sometimes get the
202 * primary color from a statevar/constant rather than a varying variable.
203 * when that's the case, we need to ensure that we use the 'color'
204 * parameter and not the current attribute color (which may have changed
205 * through glRasterPos and state validation.
206 * So, we force the proper color here. Not elegant, but it works.
209 GLfloat colorSave
[4];
210 COPY_4V(colorSave
, ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR0
]);
211 COPY_4V(ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR0
], color
);
212 st_upload_constants(st
, st
->fp
->Base
.Base
.Parameters
,
213 PIPE_SHADER_FRAGMENT
);
214 COPY_4V(ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR0
], colorSave
);
217 cso_save_rasterizer(cso
);
218 cso_save_fragment_samplers(cso
);
219 cso_save_fragment_sampler_views(cso
);
220 cso_save_viewport(cso
);
221 cso_save_fragment_shader(cso
);
222 cso_save_stream_outputs(cso
);
223 cso_save_vertex_shader(cso
);
224 cso_save_tessctrl_shader(cso
);
225 cso_save_tesseval_shader(cso
);
226 cso_save_geometry_shader(cso
);
227 cso_save_vertex_elements(cso
);
228 cso_save_aux_vertex_buffer_slot(cso
);
230 /* rasterizer state: just scissor */
231 st
->bitmap
.rasterizer
.scissor
= ctx
->Scissor
.EnableFlags
& 1;
232 cso_set_rasterizer(cso
, &st
->bitmap
.rasterizer
);
234 /* fragment shader state: TEX lookup program */
235 cso_set_fragment_shader_handle(cso
, fpv
->driver_shader
);
237 /* vertex shader state: position + texcoord pass-through */
238 cso_set_vertex_shader_handle(cso
, st
->bitmap
.vs
);
240 /* disable other shaders */
241 cso_set_tessctrl_shader_handle(cso
, NULL
);
242 cso_set_tesseval_shader_handle(cso
, NULL
);
243 cso_set_geometry_shader_handle(cso
, NULL
);
245 /* user samplers, plus our bitmap sampler */
247 struct pipe_sampler_state
*samplers
[PIPE_MAX_SAMPLERS
];
248 uint num
= MAX2(fpv
->bitmap_sampler
+ 1,
249 st
->state
.num_samplers
[PIPE_SHADER_FRAGMENT
]);
251 for (i
= 0; i
< st
->state
.num_samplers
[PIPE_SHADER_FRAGMENT
]; i
++) {
252 samplers
[i
] = &st
->state
.samplers
[PIPE_SHADER_FRAGMENT
][i
];
254 samplers
[fpv
->bitmap_sampler
] = &st
->bitmap
.sampler
;
255 cso_set_samplers(cso
, PIPE_SHADER_FRAGMENT
, num
,
256 (const struct pipe_sampler_state
**) samplers
);
259 /* user textures, plus the bitmap texture */
261 struct pipe_sampler_view
*sampler_views
[PIPE_MAX_SAMPLERS
];
262 uint num
= MAX2(fpv
->bitmap_sampler
+ 1,
263 st
->state
.num_sampler_views
[PIPE_SHADER_FRAGMENT
]);
264 memcpy(sampler_views
, st
->state
.sampler_views
[PIPE_SHADER_FRAGMENT
],
265 sizeof(sampler_views
));
266 sampler_views
[fpv
->bitmap_sampler
] = sv
;
267 cso_set_sampler_views(cso
, PIPE_SHADER_FRAGMENT
, num
, sampler_views
);
270 /* viewport state: viewport matching window dims */
272 const GLboolean invert
= st
->state
.fb_orientation
== Y_0_TOP
;
273 const GLfloat width
= (GLfloat
)st
->state
.framebuffer
.width
;
274 const GLfloat height
= (GLfloat
)st
->state
.framebuffer
.height
;
275 struct pipe_viewport_state vp
;
276 vp
.scale
[0] = 0.5f
* width
;
277 vp
.scale
[1] = height
* (invert
? -0.5f
: 0.5f
);
279 vp
.translate
[0] = 0.5f
* width
;
280 vp
.translate
[1] = 0.5f
* height
;
281 vp
.translate
[2] = 0.5f
;
282 cso_set_viewport(cso
, &vp
);
285 cso_set_vertex_elements(cso
, 3, st
->velems_util_draw
);
286 cso_set_stream_outputs(st
->cso_context
, 0, NULL
, NULL
);
291 * Restore pipeline state after rendering the bitmap textured quad.
294 restore_render_state(struct gl_context
*ctx
)
296 struct st_context
*st
= st_context(ctx
);
297 struct cso_context
*cso
= st
->cso_context
;
299 cso_restore_rasterizer(cso
);
300 cso_restore_fragment_samplers(cso
);
301 cso_restore_fragment_sampler_views(cso
);
302 cso_restore_viewport(cso
);
303 cso_restore_fragment_shader(cso
);
304 cso_restore_vertex_shader(cso
);
305 cso_restore_tessctrl_shader(cso
);
306 cso_restore_tesseval_shader(cso
);
307 cso_restore_geometry_shader(cso
);
308 cso_restore_vertex_elements(cso
);
309 cso_restore_aux_vertex_buffer_slot(cso
);
310 cso_restore_stream_outputs(cso
);
315 * Render a glBitmap by drawing a textured quad
318 draw_bitmap_quad(struct gl_context
*ctx
, GLint x
, GLint y
, GLfloat z
,
319 GLsizei width
, GLsizei height
,
320 struct pipe_sampler_view
*sv
,
321 const GLfloat
*color
)
323 struct st_context
*st
= st_context(ctx
);
324 struct pipe_context
*pipe
= st
->pipe
;
325 struct pipe_resource
*vbuf
= NULL
;
326 const float fb_width
= (float) st
->state
.framebuffer
.width
;
327 const float fb_height
= (float) st
->state
.framebuffer
.height
;
328 const float x0
= (float) x
;
329 const float x1
= (float) (x
+ width
);
330 const float y0
= (float) y
;
331 const float y1
= (float) (y
+ height
);
332 float sLeft
= 0.0f
, sRight
= 1.0f
;
333 float tTop
= 0.0f
, tBot
= 1.0f
- tTop
;
334 const float clip_x0
= x0
/ fb_width
* 2.0f
- 1.0f
;
335 const float clip_y0
= y0
/ fb_height
* 2.0f
- 1.0f
;
336 const float clip_x1
= x1
/ fb_width
* 2.0f
- 1.0f
;
337 const float clip_y1
= y1
/ fb_height
* 2.0f
- 1.0f
;
338 float (*vertices
)[3][4]; /**< vertex pos + color + texcoord */
343 /* XXX if the bitmap is larger than the max texture size, break
346 GLuint maxSize
= 1 << (pipe
->screen
->get_param(pipe
->screen
,
347 PIPE_CAP_MAX_TEXTURE_2D_LEVELS
) - 1);
348 assert(width
<= (GLsizei
) maxSize
);
349 assert(height
<= (GLsizei
) maxSize
);
352 setup_render_state(ctx
, sv
, color
);
354 /* convert Z from [0,1] to [-1,-1] to match viewport Z scale/bias */
357 if (sv
->texture
->target
== PIPE_TEXTURE_RECT
) {
358 /* use non-normalized texcoords */
359 sRight
= (float) width
;
360 tBot
= (float) height
;
363 u_upload_alloc(st
->uploader
, 0, 4 * sizeof(vertices
[0]), 4,
364 &offset
, &vbuf
, (void **) &vertices
);
366 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBitmap");
367 restore_render_state(ctx
);
371 /* Positions are in clip coords since we need to do clipping in case
372 * the bitmap quad goes beyond the window bounds.
374 vertices
[0][0][0] = clip_x0
;
375 vertices
[0][0][1] = clip_y0
;
376 vertices
[0][2][0] = sLeft
;
377 vertices
[0][2][1] = tTop
;
379 vertices
[1][0][0] = clip_x1
;
380 vertices
[1][0][1] = clip_y0
;
381 vertices
[1][2][0] = sRight
;
382 vertices
[1][2][1] = tTop
;
384 vertices
[2][0][0] = clip_x1
;
385 vertices
[2][0][1] = clip_y1
;
386 vertices
[2][2][0] = sRight
;
387 vertices
[2][2][1] = tBot
;
389 vertices
[3][0][0] = clip_x0
;
390 vertices
[3][0][1] = clip_y1
;
391 vertices
[3][2][0] = sLeft
;
392 vertices
[3][2][1] = tBot
;
394 /* same for all verts: */
395 for (i
= 0; i
< 4; i
++) {
396 vertices
[i
][0][2] = z
;
397 vertices
[i
][0][3] = 1.0f
;
398 vertices
[i
][1][0] = color
[0];
399 vertices
[i
][1][1] = color
[1];
400 vertices
[i
][1][2] = color
[2];
401 vertices
[i
][1][3] = color
[3];
402 vertices
[i
][2][2] = 0.0; /*R*/
403 vertices
[i
][2][3] = 1.0; /*Q*/
406 u_upload_unmap(st
->uploader
);
408 util_draw_vertex_buffer(pipe
, st
->cso_context
, vbuf
,
409 cso_get_aux_vertex_buffer_slot(st
->cso_context
),
411 PIPE_PRIM_TRIANGLE_FAN
,
413 3); /* attribs/vert */
415 restore_render_state(ctx
);
417 pipe_resource_reference(&vbuf
, NULL
);
419 /* We uploaded modified constants, need to invalidate them. */
420 st
->dirty
.mesa
|= _NEW_PROGRAM_CONSTANTS
;
425 reset_cache(struct st_context
*st
)
427 struct bitmap_cache
*cache
= st
->bitmap
.cache
;
429 /*memset(cache->buffer, 0xff, sizeof(cache->buffer));*/
430 cache
->empty
= GL_TRUE
;
432 cache
->xmin
= 1000000;
433 cache
->xmax
= -1000000;
434 cache
->ymin
= 1000000;
435 cache
->ymax
= -1000000;
437 assert(!cache
->texture
);
439 /* allocate a new texture */
440 cache
->texture
= st_texture_create(st
, st
->internal_target
,
441 st
->bitmap
.tex_format
, 0,
442 BITMAP_CACHE_WIDTH
, BITMAP_CACHE_HEIGHT
,
444 PIPE_BIND_SAMPLER_VIEW
);
448 /** Print bitmap image to stdout (debug) */
450 print_cache(const struct bitmap_cache
*cache
)
454 for (i
= 0; i
< BITMAP_CACHE_HEIGHT
; i
++) {
455 k
= BITMAP_CACHE_WIDTH
* (BITMAP_CACHE_HEIGHT
- i
- 1);
456 for (j
= 0; j
< BITMAP_CACHE_WIDTH
; j
++) {
457 if (cache
->buffer
[k
])
469 * Create gallium pipe_transfer object for the bitmap cache.
472 create_cache_trans(struct st_context
*st
)
474 struct pipe_context
*pipe
= st
->pipe
;
475 struct bitmap_cache
*cache
= st
->bitmap
.cache
;
480 /* Map the texture transfer.
481 * Subsequent glBitmap calls will write into the texture image.
483 cache
->buffer
= pipe_transfer_map(pipe
, cache
->texture
, 0, 0,
484 PIPE_TRANSFER_WRITE
, 0, 0,
486 BITMAP_CACHE_HEIGHT
, &cache
->trans
);
488 /* init image to all 0xff */
489 memset(cache
->buffer
, 0xff, cache
->trans
->stride
* BITMAP_CACHE_HEIGHT
);
494 * If there's anything in the bitmap cache, draw/flush it now.
497 st_flush_bitmap_cache(struct st_context
*st
)
499 struct bitmap_cache
*cache
= st
->bitmap
.cache
;
501 if (cache
&& !cache
->empty
) {
502 struct pipe_context
*pipe
= st
->pipe
;
503 struct pipe_sampler_view
*sv
;
505 assert(cache
->xmin
<= cache
->xmax
);
508 printf("flush bitmap, size %d x %d at %d, %d\n",
509 cache
->xmax
- cache
->xmin
,
510 cache
->ymax
- cache
->ymin
,
511 cache
->xpos
, cache
->ypos
);
513 /* The texture transfer has been mapped until now.
514 * So unmap and release the texture transfer before drawing.
516 if (cache
->trans
&& cache
->buffer
) {
519 pipe_transfer_unmap(pipe
, cache
->trans
);
520 cache
->buffer
= NULL
;
524 sv
= st_create_texture_sampler_view(st
->pipe
, cache
->texture
);
526 draw_bitmap_quad(st
->ctx
,
530 BITMAP_CACHE_WIDTH
, BITMAP_CACHE_HEIGHT
,
534 pipe_sampler_view_reference(&sv
, NULL
);
537 /* release/free the texture */
538 pipe_resource_reference(&cache
->texture
, NULL
);
546 * Try to accumulate this glBitmap call in the bitmap cache.
547 * \return GL_TRUE for success, GL_FALSE if bitmap is too large, etc.
550 accum_bitmap(struct gl_context
*ctx
,
551 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
552 const struct gl_pixelstore_attrib
*unpack
,
553 const GLubyte
*bitmap
)
555 struct st_context
*st
= ctx
->st
;
556 struct bitmap_cache
*cache
= st
->bitmap
.cache
;
557 int px
= -999, py
= -999;
558 const GLfloat z
= st
->ctx
->Current
.RasterPos
[2];
560 if (width
> BITMAP_CACHE_WIDTH
||
561 height
> BITMAP_CACHE_HEIGHT
)
562 return GL_FALSE
; /* too big to cache */
565 px
= x
- cache
->xpos
; /* pos in buffer */
566 py
= y
- cache
->ypos
;
567 if (px
< 0 || px
+ width
> BITMAP_CACHE_WIDTH
||
568 py
< 0 || py
+ height
> BITMAP_CACHE_HEIGHT
||
569 !TEST_EQ_4V(st
->ctx
->Current
.RasterColor
, cache
->color
) ||
570 ((fabs(z
- cache
->zpos
) > Z_EPSILON
))) {
571 /* This bitmap would extend beyond cache bounds, or the bitmap
573 * so flush and continue.
575 st_flush_bitmap_cache(st
);
580 /* Initialize. Center bitmap vertically in the buffer. */
582 py
= (BITMAP_CACHE_HEIGHT
- height
) / 2;
584 cache
->ypos
= y
- py
;
586 cache
->empty
= GL_FALSE
;
587 COPY_4FV(cache
->color
, st
->ctx
->Current
.RasterColor
);
597 if (x
+ width
> cache
->xmax
)
598 cache
->xmax
= x
+ width
;
599 if (y
+ height
> cache
->ymax
)
600 cache
->ymax
= y
+ height
;
602 /* create the transfer if needed */
603 create_cache_trans(st
);
606 bitmap
= _mesa_map_pbo_source(ctx
, unpack
, bitmap
);
611 unpack_bitmap(st
, px
, py
, width
, height
, unpack
, bitmap
,
612 cache
->buffer
, BITMAP_CACHE_WIDTH
);
614 _mesa_unmap_pbo_source(ctx
, unpack
);
616 return GL_TRUE
; /* accumulated */
621 * One-time init for drawing bitmaps.
624 init_bitmap_state(struct st_context
*st
)
626 struct pipe_context
*pipe
= st
->pipe
;
627 struct pipe_screen
*screen
= pipe
->screen
;
629 /* This function should only be called once */
630 assert(st
->bitmap
.cache
== NULL
);
632 assert(st
->internal_target
== PIPE_TEXTURE_2D
||
633 st
->internal_target
== PIPE_TEXTURE_RECT
);
635 /* alloc bitmap cache object */
636 st
->bitmap
.cache
= ST_CALLOC_STRUCT(bitmap_cache
);
638 /* init sampler state once */
639 memset(&st
->bitmap
.sampler
, 0, sizeof(st
->bitmap
.sampler
));
640 st
->bitmap
.sampler
.wrap_s
= PIPE_TEX_WRAP_CLAMP
;
641 st
->bitmap
.sampler
.wrap_t
= PIPE_TEX_WRAP_CLAMP
;
642 st
->bitmap
.sampler
.wrap_r
= PIPE_TEX_WRAP_CLAMP
;
643 st
->bitmap
.sampler
.min_img_filter
= PIPE_TEX_FILTER_NEAREST
;
644 st
->bitmap
.sampler
.min_mip_filter
= PIPE_TEX_MIPFILTER_NONE
;
645 st
->bitmap
.sampler
.mag_img_filter
= PIPE_TEX_FILTER_NEAREST
;
646 st
->bitmap
.sampler
.normalized_coords
= st
->internal_target
== PIPE_TEXTURE_2D
;
648 /* init baseline rasterizer state once */
649 memset(&st
->bitmap
.rasterizer
, 0, sizeof(st
->bitmap
.rasterizer
));
650 st
->bitmap
.rasterizer
.half_pixel_center
= 1;
651 st
->bitmap
.rasterizer
.bottom_edge_rule
= 1;
652 st
->bitmap
.rasterizer
.depth_clip
= 1;
654 /* find a usable texture format */
655 if (screen
->is_format_supported(screen
, PIPE_FORMAT_I8_UNORM
,
656 st
->internal_target
, 0,
657 PIPE_BIND_SAMPLER_VIEW
)) {
658 st
->bitmap
.tex_format
= PIPE_FORMAT_I8_UNORM
;
660 else if (screen
->is_format_supported(screen
, PIPE_FORMAT_A8_UNORM
,
661 st
->internal_target
, 0,
662 PIPE_BIND_SAMPLER_VIEW
)) {
663 st
->bitmap
.tex_format
= PIPE_FORMAT_A8_UNORM
;
665 else if (screen
->is_format_supported(screen
, PIPE_FORMAT_L8_UNORM
,
666 st
->internal_target
, 0,
667 PIPE_BIND_SAMPLER_VIEW
)) {
668 st
->bitmap
.tex_format
= PIPE_FORMAT_L8_UNORM
;
671 /* XXX support more formats */
675 /* Create the vertex shader */
677 const uint semantic_names
[] = { TGSI_SEMANTIC_POSITION
,
679 st
->needs_texcoord_semantic
? TGSI_SEMANTIC_TEXCOORD
:
680 TGSI_SEMANTIC_GENERIC
};
681 const uint semantic_indexes
[] = { 0, 0, 0 };
682 st
->bitmap
.vs
= util_make_vertex_passthrough_shader(st
->pipe
, 3,
693 * Called via ctx->Driver.Bitmap()
696 st_Bitmap(struct gl_context
*ctx
, GLint x
, GLint y
,
697 GLsizei width
, GLsizei height
,
698 const struct gl_pixelstore_attrib
*unpack
, const GLubyte
*bitmap
)
700 struct st_context
*st
= st_context(ctx
);
701 struct pipe_resource
*pt
;
706 if (!st
->bitmap
.cache
) {
707 init_bitmap_state(st
);
710 /* We only need to validate state of the st dirty flags are set or
711 * any non-_NEW_PROGRAM_CONSTANTS mesa flags are set. The VS we use
712 * for bitmap drawing uses no constants and the FS constants are
713 * explicitly uploaded in the draw_bitmap_quad() function.
715 if ((st
->dirty
.mesa
& ~_NEW_PROGRAM_CONSTANTS
) || st
->dirty
.st
) {
716 st_validate_state(st
);
719 if (UseBitmapCache
&& accum_bitmap(ctx
, x
, y
, width
, height
, unpack
, bitmap
))
722 pt
= make_bitmap_texture(ctx
, width
, height
, unpack
, bitmap
);
724 struct pipe_sampler_view
*sv
=
725 st_create_texture_sampler_view(st
->pipe
, pt
);
727 assert(pt
->target
== PIPE_TEXTURE_2D
|| pt
->target
== PIPE_TEXTURE_RECT
);
730 draw_bitmap_quad(ctx
, x
, y
, ctx
->Current
.RasterPos
[2],
732 st
->ctx
->Current
.RasterColor
);
734 pipe_sampler_view_reference(&sv
, NULL
);
737 /* release/free the texture */
738 pipe_resource_reference(&pt
, NULL
);
743 /** Per-context init */
745 st_init_bitmap_functions(struct dd_function_table
*functions
)
747 functions
->Bitmap
= st_Bitmap
;
751 /** Per-context tear-down */
753 st_destroy_bitmap(struct st_context
*st
)
755 struct pipe_context
*pipe
= st
->pipe
;
756 struct bitmap_cache
*cache
= st
->bitmap
.cache
;
759 cso_delete_vertex_shader(st
->cso_context
, st
->bitmap
.vs
);
760 st
->bitmap
.vs
= NULL
;
764 if (cache
->trans
&& cache
->buffer
) {
765 pipe_transfer_unmap(pipe
, cache
->trans
);
767 pipe_resource_reference(&st
->bitmap
.cache
->texture
, NULL
);
768 free(st
->bitmap
.cache
);
769 st
->bitmap
.cache
= NULL
;