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
] =
255 &st
->bitmap
.samplers
[sv
->texture
->target
!= PIPE_TEXTURE_RECT
];
256 cso_set_samplers(cso
, PIPE_SHADER_FRAGMENT
, num
,
257 (const struct pipe_sampler_state
**) samplers
);
260 /* user textures, plus the bitmap texture */
262 struct pipe_sampler_view
*sampler_views
[PIPE_MAX_SAMPLERS
];
263 uint num
= MAX2(fpv
->bitmap_sampler
+ 1,
264 st
->state
.num_sampler_views
[PIPE_SHADER_FRAGMENT
]);
265 memcpy(sampler_views
, st
->state
.sampler_views
[PIPE_SHADER_FRAGMENT
],
266 sizeof(sampler_views
));
267 sampler_views
[fpv
->bitmap_sampler
] = sv
;
268 cso_set_sampler_views(cso
, PIPE_SHADER_FRAGMENT
, num
, sampler_views
);
271 /* viewport state: viewport matching window dims */
273 const GLboolean invert
= st
->state
.fb_orientation
== Y_0_TOP
;
274 const GLfloat width
= (GLfloat
)st
->state
.framebuffer
.width
;
275 const GLfloat height
= (GLfloat
)st
->state
.framebuffer
.height
;
276 struct pipe_viewport_state vp
;
277 vp
.scale
[0] = 0.5f
* width
;
278 vp
.scale
[1] = height
* (invert
? -0.5f
: 0.5f
);
280 vp
.translate
[0] = 0.5f
* width
;
281 vp
.translate
[1] = 0.5f
* height
;
282 vp
.translate
[2] = 0.5f
;
283 cso_set_viewport(cso
, &vp
);
286 cso_set_vertex_elements(cso
, 3, st
->velems_util_draw
);
287 cso_set_stream_outputs(st
->cso_context
, 0, NULL
, NULL
);
292 * Restore pipeline state after rendering the bitmap textured quad.
295 restore_render_state(struct gl_context
*ctx
)
297 struct st_context
*st
= st_context(ctx
);
298 struct cso_context
*cso
= st
->cso_context
;
300 cso_restore_rasterizer(cso
);
301 cso_restore_fragment_samplers(cso
);
302 cso_restore_fragment_sampler_views(cso
);
303 cso_restore_viewport(cso
);
304 cso_restore_fragment_shader(cso
);
305 cso_restore_vertex_shader(cso
);
306 cso_restore_tessctrl_shader(cso
);
307 cso_restore_tesseval_shader(cso
);
308 cso_restore_geometry_shader(cso
);
309 cso_restore_vertex_elements(cso
);
310 cso_restore_aux_vertex_buffer_slot(cso
);
311 cso_restore_stream_outputs(cso
);
316 * Render a glBitmap by drawing a textured quad
319 draw_bitmap_quad(struct gl_context
*ctx
, GLint x
, GLint y
, GLfloat z
,
320 GLsizei width
, GLsizei height
,
321 struct pipe_sampler_view
*sv
,
322 const GLfloat
*color
)
324 struct st_context
*st
= st_context(ctx
);
325 struct pipe_context
*pipe
= st
->pipe
;
326 struct pipe_resource
*vbuf
= NULL
;
327 const float fb_width
= (float) st
->state
.framebuffer
.width
;
328 const float fb_height
= (float) st
->state
.framebuffer
.height
;
329 const float x0
= (float) x
;
330 const float x1
= (float) (x
+ width
);
331 const float y0
= (float) y
;
332 const float y1
= (float) (y
+ height
);
333 float sLeft
= 0.0f
, sRight
= 1.0f
;
334 float tTop
= 0.0f
, tBot
= 1.0f
- tTop
;
335 const float clip_x0
= x0
/ fb_width
* 2.0f
- 1.0f
;
336 const float clip_y0
= y0
/ fb_height
* 2.0f
- 1.0f
;
337 const float clip_x1
= x1
/ fb_width
* 2.0f
- 1.0f
;
338 const float clip_y1
= y1
/ fb_height
* 2.0f
- 1.0f
;
339 float (*vertices
)[3][4]; /**< vertex pos + color + texcoord */
344 /* XXX if the bitmap is larger than the max texture size, break
347 GLuint maxSize
= 1 << (pipe
->screen
->get_param(pipe
->screen
,
348 PIPE_CAP_MAX_TEXTURE_2D_LEVELS
) - 1);
349 assert(width
<= (GLsizei
) maxSize
);
350 assert(height
<= (GLsizei
) maxSize
);
353 setup_render_state(ctx
, sv
, color
);
355 /* convert Z from [0,1] to [-1,-1] to match viewport Z scale/bias */
358 if (sv
->texture
->target
== PIPE_TEXTURE_RECT
) {
359 /* use non-normalized texcoords */
360 sRight
= (float) width
;
361 tBot
= (float) height
;
364 u_upload_alloc(st
->uploader
, 0, 4 * sizeof(vertices
[0]), 4,
365 &offset
, &vbuf
, (void **) &vertices
);
367 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBitmap");
368 restore_render_state(ctx
);
372 /* Positions are in clip coords since we need to do clipping in case
373 * the bitmap quad goes beyond the window bounds.
375 vertices
[0][0][0] = clip_x0
;
376 vertices
[0][0][1] = clip_y0
;
377 vertices
[0][2][0] = sLeft
;
378 vertices
[0][2][1] = tTop
;
380 vertices
[1][0][0] = clip_x1
;
381 vertices
[1][0][1] = clip_y0
;
382 vertices
[1][2][0] = sRight
;
383 vertices
[1][2][1] = tTop
;
385 vertices
[2][0][0] = clip_x1
;
386 vertices
[2][0][1] = clip_y1
;
387 vertices
[2][2][0] = sRight
;
388 vertices
[2][2][1] = tBot
;
390 vertices
[3][0][0] = clip_x0
;
391 vertices
[3][0][1] = clip_y1
;
392 vertices
[3][2][0] = sLeft
;
393 vertices
[3][2][1] = tBot
;
395 /* same for all verts: */
396 for (i
= 0; i
< 4; i
++) {
397 vertices
[i
][0][2] = z
;
398 vertices
[i
][0][3] = 1.0f
;
399 vertices
[i
][1][0] = color
[0];
400 vertices
[i
][1][1] = color
[1];
401 vertices
[i
][1][2] = color
[2];
402 vertices
[i
][1][3] = color
[3];
403 vertices
[i
][2][2] = 0.0; /*R*/
404 vertices
[i
][2][3] = 1.0; /*Q*/
407 u_upload_unmap(st
->uploader
);
409 util_draw_vertex_buffer(pipe
, st
->cso_context
, vbuf
,
410 cso_get_aux_vertex_buffer_slot(st
->cso_context
),
412 PIPE_PRIM_TRIANGLE_FAN
,
414 3); /* attribs/vert */
416 restore_render_state(ctx
);
418 pipe_resource_reference(&vbuf
, NULL
);
420 /* We uploaded modified constants, need to invalidate them. */
421 st
->dirty
.mesa
|= _NEW_PROGRAM_CONSTANTS
;
426 reset_cache(struct st_context
*st
)
428 struct bitmap_cache
*cache
= st
->bitmap
.cache
;
430 /*memset(cache->buffer, 0xff, sizeof(cache->buffer));*/
431 cache
->empty
= GL_TRUE
;
433 cache
->xmin
= 1000000;
434 cache
->xmax
= -1000000;
435 cache
->ymin
= 1000000;
436 cache
->ymax
= -1000000;
438 assert(!cache
->texture
);
440 /* allocate a new texture */
441 cache
->texture
= st_texture_create(st
, PIPE_TEXTURE_2D
,
442 st
->bitmap
.tex_format
, 0,
443 BITMAP_CACHE_WIDTH
, BITMAP_CACHE_HEIGHT
,
445 PIPE_BIND_SAMPLER_VIEW
);
449 /** Print bitmap image to stdout (debug) */
451 print_cache(const struct bitmap_cache
*cache
)
455 for (i
= 0; i
< BITMAP_CACHE_HEIGHT
; i
++) {
456 k
= BITMAP_CACHE_WIDTH
* (BITMAP_CACHE_HEIGHT
- i
- 1);
457 for (j
= 0; j
< BITMAP_CACHE_WIDTH
; j
++) {
458 if (cache
->buffer
[k
])
470 * Create gallium pipe_transfer object for the bitmap cache.
473 create_cache_trans(struct st_context
*st
)
475 struct pipe_context
*pipe
= st
->pipe
;
476 struct bitmap_cache
*cache
= st
->bitmap
.cache
;
481 /* Map the texture transfer.
482 * Subsequent glBitmap calls will write into the texture image.
484 cache
->buffer
= pipe_transfer_map(pipe
, cache
->texture
, 0, 0,
485 PIPE_TRANSFER_WRITE
, 0, 0,
487 BITMAP_CACHE_HEIGHT
, &cache
->trans
);
489 /* init image to all 0xff */
490 memset(cache
->buffer
, 0xff, cache
->trans
->stride
* BITMAP_CACHE_HEIGHT
);
495 * If there's anything in the bitmap cache, draw/flush it now.
498 st_flush_bitmap_cache(struct st_context
*st
)
500 struct bitmap_cache
*cache
= st
->bitmap
.cache
;
502 if (cache
&& !cache
->empty
) {
503 struct pipe_context
*pipe
= st
->pipe
;
504 struct pipe_sampler_view
*sv
;
506 assert(cache
->xmin
<= cache
->xmax
);
509 printf("flush bitmap, size %d x %d at %d, %d\n",
510 cache
->xmax
- cache
->xmin
,
511 cache
->ymax
- cache
->ymin
,
512 cache
->xpos
, cache
->ypos
);
514 /* The texture transfer has been mapped until now.
515 * So unmap and release the texture transfer before drawing.
517 if (cache
->trans
&& cache
->buffer
) {
520 pipe_transfer_unmap(pipe
, cache
->trans
);
521 cache
->buffer
= NULL
;
525 sv
= st_create_texture_sampler_view(st
->pipe
, cache
->texture
);
527 draw_bitmap_quad(st
->ctx
,
531 BITMAP_CACHE_WIDTH
, BITMAP_CACHE_HEIGHT
,
535 pipe_sampler_view_reference(&sv
, NULL
);
538 /* release/free the texture */
539 pipe_resource_reference(&cache
->texture
, NULL
);
547 * Try to accumulate this glBitmap call in the bitmap cache.
548 * \return GL_TRUE for success, GL_FALSE if bitmap is too large, etc.
551 accum_bitmap(struct gl_context
*ctx
,
552 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
553 const struct gl_pixelstore_attrib
*unpack
,
554 const GLubyte
*bitmap
)
556 struct st_context
*st
= ctx
->st
;
557 struct bitmap_cache
*cache
= st
->bitmap
.cache
;
558 int px
= -999, py
= -999;
559 const GLfloat z
= st
->ctx
->Current
.RasterPos
[2];
561 if (width
> BITMAP_CACHE_WIDTH
||
562 height
> BITMAP_CACHE_HEIGHT
)
563 return GL_FALSE
; /* too big to cache */
566 px
= x
- cache
->xpos
; /* pos in buffer */
567 py
= y
- cache
->ypos
;
568 if (px
< 0 || px
+ width
> BITMAP_CACHE_WIDTH
||
569 py
< 0 || py
+ height
> BITMAP_CACHE_HEIGHT
||
570 !TEST_EQ_4V(st
->ctx
->Current
.RasterColor
, cache
->color
) ||
571 ((fabs(z
- cache
->zpos
) > Z_EPSILON
))) {
572 /* This bitmap would extend beyond cache bounds, or the bitmap
574 * so flush and continue.
576 st_flush_bitmap_cache(st
);
581 /* Initialize. Center bitmap vertically in the buffer. */
583 py
= (BITMAP_CACHE_HEIGHT
- height
) / 2;
585 cache
->ypos
= y
- py
;
587 cache
->empty
= GL_FALSE
;
588 COPY_4FV(cache
->color
, st
->ctx
->Current
.RasterColor
);
598 if (x
+ width
> cache
->xmax
)
599 cache
->xmax
= x
+ width
;
600 if (y
+ height
> cache
->ymax
)
601 cache
->ymax
= y
+ height
;
603 /* create the transfer if needed */
604 create_cache_trans(st
);
607 bitmap
= _mesa_map_pbo_source(ctx
, unpack
, bitmap
);
612 unpack_bitmap(st
, px
, py
, width
, height
, unpack
, bitmap
,
613 cache
->buffer
, BITMAP_CACHE_WIDTH
);
615 _mesa_unmap_pbo_source(ctx
, unpack
);
617 return GL_TRUE
; /* accumulated */
622 * One-time init for drawing bitmaps.
625 init_bitmap_state(struct st_context
*st
)
627 struct pipe_sampler_state
*sampler
= &st
->bitmap
.samplers
[0];
628 struct pipe_context
*pipe
= st
->pipe
;
629 struct pipe_screen
*screen
= pipe
->screen
;
631 /* This function should only be called once */
632 assert(st
->bitmap
.cache
== NULL
);
634 /* alloc bitmap cache object */
635 st
->bitmap
.cache
= ST_CALLOC_STRUCT(bitmap_cache
);
637 /* init sampler state once */
638 memset(sampler
, 0, sizeof(*sampler
));
639 sampler
->wrap_s
= PIPE_TEX_WRAP_CLAMP
;
640 sampler
->wrap_t
= PIPE_TEX_WRAP_CLAMP
;
641 sampler
->wrap_r
= PIPE_TEX_WRAP_CLAMP
;
642 sampler
->min_img_filter
= PIPE_TEX_FILTER_NEAREST
;
643 sampler
->min_mip_filter
= PIPE_TEX_MIPFILTER_NONE
;
644 sampler
->mag_img_filter
= PIPE_TEX_FILTER_NEAREST
;
645 st
->bitmap
.samplers
[1] = *sampler
;
646 st
->bitmap
.samplers
[1].normalized_coords
= 1;
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
,
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
,
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
,
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
;