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
);
180 setup_bitmap_vertex_data(struct st_context
*st
, bool normalized
,
181 int x
, int y
, int width
, int height
,
182 float z
, const float color
[4],
183 struct pipe_resource
**vbuf
,
184 unsigned *vbuf_offset
)
186 const GLfloat fb_width
= (GLfloat
)st
->state
.framebuffer
.width
;
187 const GLfloat fb_height
= (GLfloat
)st
->state
.framebuffer
.height
;
188 const GLfloat x0
= (GLfloat
)x
;
189 const GLfloat x1
= (GLfloat
)(x
+ width
);
190 const GLfloat y0
= (GLfloat
)y
;
191 const GLfloat y1
= (GLfloat
)(y
+ height
);
192 GLfloat sLeft
= (GLfloat
)0.0, sRight
= (GLfloat
)1.0;
193 GLfloat tTop
= (GLfloat
)0.0, tBot
= (GLfloat
)1.0 - tTop
;
194 const GLfloat clip_x0
= (GLfloat
)(x0
/ fb_width
* 2.0 - 1.0);
195 const GLfloat clip_y0
= (GLfloat
)(y0
/ fb_height
* 2.0 - 1.0);
196 const GLfloat clip_x1
= (GLfloat
)(x1
/ fb_width
* 2.0 - 1.0);
197 const GLfloat clip_y1
= (GLfloat
)(y1
/ fb_height
* 2.0 - 1.0);
199 float (*vertices
)[3][4]; /**< vertex pos + color + texcoord */
202 sRight
= (GLfloat
) width
;
203 tBot
= (GLfloat
) height
;
206 u_upload_alloc(st
->uploader
, 0, 4 * sizeof(vertices
[0]), 4,
207 vbuf_offset
, vbuf
, (void **) &vertices
);
212 /* Positions are in clip coords since we need to do clipping in case
213 * the bitmap quad goes beyond the window bounds.
215 vertices
[0][0][0] = clip_x0
;
216 vertices
[0][0][1] = clip_y0
;
217 vertices
[0][2][0] = sLeft
;
218 vertices
[0][2][1] = tTop
;
220 vertices
[1][0][0] = clip_x1
;
221 vertices
[1][0][1] = clip_y0
;
222 vertices
[1][2][0] = sRight
;
223 vertices
[1][2][1] = tTop
;
225 vertices
[2][0][0] = clip_x1
;
226 vertices
[2][0][1] = clip_y1
;
227 vertices
[2][2][0] = sRight
;
228 vertices
[2][2][1] = tBot
;
230 vertices
[3][0][0] = clip_x0
;
231 vertices
[3][0][1] = clip_y1
;
232 vertices
[3][2][0] = sLeft
;
233 vertices
[3][2][1] = tBot
;
235 /* same for all verts: */
236 for (i
= 0; i
< 4; i
++) {
237 vertices
[i
][0][2] = z
;
238 vertices
[i
][0][3] = 1.0f
;
239 vertices
[i
][1][0] = color
[0];
240 vertices
[i
][1][1] = color
[1];
241 vertices
[i
][1][2] = color
[2];
242 vertices
[i
][1][3] = color
[3];
243 vertices
[i
][2][2] = 0.0; /*R*/
244 vertices
[i
][2][3] = 1.0; /*Q*/
247 u_upload_unmap(st
->uploader
);
252 * Setup pipeline state prior to rendering the bitmap textured quad.
255 setup_render_state(struct gl_context
*ctx
,
256 struct pipe_sampler_view
*sv
,
257 const GLfloat
*color
)
259 struct st_context
*st
= st_context(ctx
);
260 struct cso_context
*cso
= st
->cso_context
;
261 struct st_fp_variant
*fpv
;
262 struct st_fp_variant_key key
;
264 memset(&key
, 0, sizeof(key
));
265 key
.st
= st
->has_shareable_shaders
? NULL
: st
;
266 key
.bitmap
= GL_TRUE
;
267 key
.clamp_color
= st
->clamp_frag_color_in_shader
&&
268 st
->ctx
->Color
._ClampFragmentColor
;
270 fpv
= st_get_fp_variant(st
, st
->fp
, &key
);
272 /* As an optimization, Mesa's fragment programs will sometimes get the
273 * primary color from a statevar/constant rather than a varying variable.
274 * when that's the case, we need to ensure that we use the 'color'
275 * parameter and not the current attribute color (which may have changed
276 * through glRasterPos and state validation.
277 * So, we force the proper color here. Not elegant, but it works.
280 GLfloat colorSave
[4];
281 COPY_4V(colorSave
, ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR0
]);
282 COPY_4V(ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR0
], color
);
283 st_upload_constants(st
, st
->fp
->Base
.Base
.Parameters
,
284 PIPE_SHADER_FRAGMENT
);
285 COPY_4V(ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR0
], colorSave
);
288 cso_save_rasterizer(cso
);
289 cso_save_fragment_samplers(cso
);
290 cso_save_fragment_sampler_views(cso
);
291 cso_save_viewport(cso
);
292 cso_save_fragment_shader(cso
);
293 cso_save_stream_outputs(cso
);
294 cso_save_vertex_shader(cso
);
295 cso_save_tessctrl_shader(cso
);
296 cso_save_tesseval_shader(cso
);
297 cso_save_geometry_shader(cso
);
298 cso_save_vertex_elements(cso
);
299 cso_save_aux_vertex_buffer_slot(cso
);
301 /* rasterizer state: just scissor */
302 st
->bitmap
.rasterizer
.scissor
= ctx
->Scissor
.EnableFlags
& 1;
303 cso_set_rasterizer(cso
, &st
->bitmap
.rasterizer
);
305 /* fragment shader state: TEX lookup program */
306 cso_set_fragment_shader_handle(cso
, fpv
->driver_shader
);
308 /* vertex shader state: position + texcoord pass-through */
309 cso_set_vertex_shader_handle(cso
, st
->bitmap
.vs
);
311 /* disable other shaders */
312 cso_set_tessctrl_shader_handle(cso
, NULL
);
313 cso_set_tesseval_shader_handle(cso
, NULL
);
314 cso_set_geometry_shader_handle(cso
, NULL
);
316 /* user samplers, plus our bitmap sampler */
318 struct pipe_sampler_state
*samplers
[PIPE_MAX_SAMPLERS
];
319 uint num
= MAX2(fpv
->bitmap_sampler
+ 1,
320 st
->state
.num_samplers
[PIPE_SHADER_FRAGMENT
]);
322 for (i
= 0; i
< st
->state
.num_samplers
[PIPE_SHADER_FRAGMENT
]; i
++) {
323 samplers
[i
] = &st
->state
.samplers
[PIPE_SHADER_FRAGMENT
][i
];
325 samplers
[fpv
->bitmap_sampler
] =
326 &st
->bitmap
.samplers
[sv
->texture
->target
!= PIPE_TEXTURE_RECT
];
327 cso_set_samplers(cso
, PIPE_SHADER_FRAGMENT
, num
,
328 (const struct pipe_sampler_state
**) samplers
);
331 /* user textures, plus the bitmap texture */
333 struct pipe_sampler_view
*sampler_views
[PIPE_MAX_SAMPLERS
];
334 uint num
= MAX2(fpv
->bitmap_sampler
+ 1,
335 st
->state
.num_sampler_views
[PIPE_SHADER_FRAGMENT
]);
336 memcpy(sampler_views
, st
->state
.sampler_views
[PIPE_SHADER_FRAGMENT
],
337 sizeof(sampler_views
));
338 sampler_views
[fpv
->bitmap_sampler
] = sv
;
339 cso_set_sampler_views(cso
, PIPE_SHADER_FRAGMENT
, num
, sampler_views
);
342 /* viewport state: viewport matching window dims */
344 const GLboolean invert
= st
->state
.fb_orientation
== Y_0_TOP
;
345 const GLfloat width
= (GLfloat
)st
->state
.framebuffer
.width
;
346 const GLfloat height
= (GLfloat
)st
->state
.framebuffer
.height
;
347 struct pipe_viewport_state vp
;
348 vp
.scale
[0] = 0.5f
* width
;
349 vp
.scale
[1] = height
* (invert
? -0.5f
: 0.5f
);
351 vp
.translate
[0] = 0.5f
* width
;
352 vp
.translate
[1] = 0.5f
* height
;
353 vp
.translate
[2] = 0.5f
;
354 cso_set_viewport(cso
, &vp
);
357 cso_set_vertex_elements(cso
, 3, st
->velems_util_draw
);
358 cso_set_stream_outputs(st
->cso_context
, 0, NULL
, NULL
);
363 * Restore pipeline state after rendering the bitmap textured quad.
366 restore_render_state(struct gl_context
*ctx
)
368 struct st_context
*st
= st_context(ctx
);
369 struct cso_context
*cso
= st
->cso_context
;
371 cso_restore_rasterizer(cso
);
372 cso_restore_fragment_samplers(cso
);
373 cso_restore_fragment_sampler_views(cso
);
374 cso_restore_viewport(cso
);
375 cso_restore_fragment_shader(cso
);
376 cso_restore_vertex_shader(cso
);
377 cso_restore_tessctrl_shader(cso
);
378 cso_restore_tesseval_shader(cso
);
379 cso_restore_geometry_shader(cso
);
380 cso_restore_vertex_elements(cso
);
381 cso_restore_aux_vertex_buffer_slot(cso
);
382 cso_restore_stream_outputs(cso
);
387 * Render a glBitmap by drawing a textured quad
390 draw_bitmap_quad(struct gl_context
*ctx
, GLint x
, GLint y
, GLfloat z
,
391 GLsizei width
, GLsizei height
,
392 struct pipe_sampler_view
*sv
,
393 const GLfloat
*color
)
395 struct st_context
*st
= st_context(ctx
);
396 struct pipe_context
*pipe
= st
->pipe
;
397 struct pipe_resource
*vbuf
= NULL
;
402 /* XXX if the bitmap is larger than the max texture size, break
405 maxSize
= 1 << (pipe
->screen
->get_param(pipe
->screen
,
406 PIPE_CAP_MAX_TEXTURE_2D_LEVELS
) - 1);
407 assert(width
<= (GLsizei
)maxSize
);
408 assert(height
<= (GLsizei
)maxSize
);
410 setup_render_state(ctx
, sv
, color
);
412 /* convert Z from [0,1] to [-1,-1] to match viewport Z scale/bias */
415 /* draw textured quad */
416 setup_bitmap_vertex_data(st
, sv
->texture
->target
!= PIPE_TEXTURE_RECT
,
417 x
, y
, width
, height
, z
, color
, &vbuf
, &offset
);
420 util_draw_vertex_buffer(pipe
, st
->cso_context
, vbuf
,
421 cso_get_aux_vertex_buffer_slot(st
->cso_context
),
423 PIPE_PRIM_TRIANGLE_FAN
,
425 3); /* attribs/vert */
428 restore_render_state(ctx
);
430 pipe_resource_reference(&vbuf
, NULL
);
432 /* We uploaded modified constants, need to invalidate them. */
433 st
->dirty
.mesa
|= _NEW_PROGRAM_CONSTANTS
;
438 reset_cache(struct st_context
*st
)
440 struct bitmap_cache
*cache
= st
->bitmap
.cache
;
442 /*memset(cache->buffer, 0xff, sizeof(cache->buffer));*/
443 cache
->empty
= GL_TRUE
;
445 cache
->xmin
= 1000000;
446 cache
->xmax
= -1000000;
447 cache
->ymin
= 1000000;
448 cache
->ymax
= -1000000;
450 assert(!cache
->texture
);
452 /* allocate a new texture */
453 cache
->texture
= st_texture_create(st
, PIPE_TEXTURE_2D
,
454 st
->bitmap
.tex_format
, 0,
455 BITMAP_CACHE_WIDTH
, BITMAP_CACHE_HEIGHT
,
457 PIPE_BIND_SAMPLER_VIEW
);
461 /** Print bitmap image to stdout (debug) */
463 print_cache(const struct bitmap_cache
*cache
)
467 for (i
= 0; i
< BITMAP_CACHE_HEIGHT
; i
++) {
468 k
= BITMAP_CACHE_WIDTH
* (BITMAP_CACHE_HEIGHT
- i
- 1);
469 for (j
= 0; j
< BITMAP_CACHE_WIDTH
; j
++) {
470 if (cache
->buffer
[k
])
482 * Create gallium pipe_transfer object for the bitmap cache.
485 create_cache_trans(struct st_context
*st
)
487 struct pipe_context
*pipe
= st
->pipe
;
488 struct bitmap_cache
*cache
= st
->bitmap
.cache
;
493 /* Map the texture transfer.
494 * Subsequent glBitmap calls will write into the texture image.
496 cache
->buffer
= pipe_transfer_map(pipe
, cache
->texture
, 0, 0,
497 PIPE_TRANSFER_WRITE
, 0, 0,
499 BITMAP_CACHE_HEIGHT
, &cache
->trans
);
501 /* init image to all 0xff */
502 memset(cache
->buffer
, 0xff, cache
->trans
->stride
* BITMAP_CACHE_HEIGHT
);
507 * If there's anything in the bitmap cache, draw/flush it now.
510 st_flush_bitmap_cache(struct st_context
*st
)
512 if (!st
->bitmap
.cache
->empty
) {
513 struct bitmap_cache
*cache
= st
->bitmap
.cache
;
514 struct pipe_context
*pipe
= st
->pipe
;
515 struct pipe_sampler_view
*sv
;
517 assert(cache
->xmin
<= cache
->xmax
);
520 printf("flush bitmap, size %d x %d at %d, %d\n",
521 cache
->xmax
- cache
->xmin
,
522 cache
->ymax
- cache
->ymin
,
523 cache
->xpos
, cache
->ypos
);
525 /* The texture transfer has been mapped until now.
526 * So unmap and release the texture transfer before drawing.
528 if (cache
->trans
&& cache
->buffer
) {
531 pipe_transfer_unmap(pipe
, cache
->trans
);
532 cache
->buffer
= NULL
;
536 sv
= st_create_texture_sampler_view(st
->pipe
, cache
->texture
);
538 draw_bitmap_quad(st
->ctx
,
542 BITMAP_CACHE_WIDTH
, BITMAP_CACHE_HEIGHT
,
546 pipe_sampler_view_reference(&sv
, NULL
);
549 /* release/free the texture */
550 pipe_resource_reference(&cache
->texture
, NULL
);
558 * Try to accumulate this glBitmap call in the bitmap cache.
559 * \return GL_TRUE for success, GL_FALSE if bitmap is too large, etc.
562 accum_bitmap(struct gl_context
*ctx
,
563 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
564 const struct gl_pixelstore_attrib
*unpack
,
565 const GLubyte
*bitmap
)
567 struct st_context
*st
= ctx
->st
;
568 struct bitmap_cache
*cache
= st
->bitmap
.cache
;
569 int px
= -999, py
= -999;
570 const GLfloat z
= st
->ctx
->Current
.RasterPos
[2];
572 if (width
> BITMAP_CACHE_WIDTH
||
573 height
> BITMAP_CACHE_HEIGHT
)
574 return GL_FALSE
; /* too big to cache */
577 px
= x
- cache
->xpos
; /* pos in buffer */
578 py
= y
- cache
->ypos
;
579 if (px
< 0 || px
+ width
> BITMAP_CACHE_WIDTH
||
580 py
< 0 || py
+ height
> BITMAP_CACHE_HEIGHT
||
581 !TEST_EQ_4V(st
->ctx
->Current
.RasterColor
, cache
->color
) ||
582 ((fabs(z
- cache
->zpos
) > Z_EPSILON
))) {
583 /* This bitmap would extend beyond cache bounds, or the bitmap
585 * so flush and continue.
587 st_flush_bitmap_cache(st
);
592 /* Initialize. Center bitmap vertically in the buffer. */
594 py
= (BITMAP_CACHE_HEIGHT
- height
) / 2;
596 cache
->ypos
= y
- py
;
598 cache
->empty
= GL_FALSE
;
599 COPY_4FV(cache
->color
, st
->ctx
->Current
.RasterColor
);
609 if (x
+ width
> cache
->xmax
)
610 cache
->xmax
= x
+ width
;
611 if (y
+ height
> cache
->ymax
)
612 cache
->ymax
= y
+ height
;
614 /* create the transfer if needed */
615 create_cache_trans(st
);
618 bitmap
= _mesa_map_pbo_source(ctx
, unpack
, bitmap
);
623 unpack_bitmap(st
, px
, py
, width
, height
, unpack
, bitmap
,
624 cache
->buffer
, BITMAP_CACHE_WIDTH
);
626 _mesa_unmap_pbo_source(ctx
, unpack
);
628 return GL_TRUE
; /* accumulated */
634 * Called via ctx->Driver.Bitmap()
637 st_Bitmap(struct gl_context
*ctx
, GLint x
, GLint y
,
638 GLsizei width
, GLsizei height
,
639 const struct gl_pixelstore_attrib
*unpack
, const GLubyte
*bitmap
)
641 struct st_context
*st
= st_context(ctx
);
642 struct pipe_resource
*pt
;
647 /* We only need to validate state of the st dirty flags are set or
648 * any non-_NEW_PROGRAM_CONSTANTS mesa flags are set. The VS we use
649 * for bitmap drawing uses no constants and the FS constants are
650 * explicitly uploaded in the draw_bitmap_quad() function.
652 if ((st
->dirty
.mesa
& ~_NEW_PROGRAM_CONSTANTS
) || st
->dirty
.st
) {
653 st_validate_state(st
);
656 if (!st
->bitmap
.vs
) {
657 /* create pass-through vertex shader now */
658 const uint semantic_names
[] = { TGSI_SEMANTIC_POSITION
,
660 st
->needs_texcoord_semantic
? TGSI_SEMANTIC_TEXCOORD
:
661 TGSI_SEMANTIC_GENERIC
};
662 const uint semantic_indexes
[] = { 0, 0, 0 };
663 st
->bitmap
.vs
= util_make_vertex_passthrough_shader(st
->pipe
, 3,
669 if (UseBitmapCache
&& accum_bitmap(ctx
, x
, y
, width
, height
, unpack
, bitmap
))
672 pt
= make_bitmap_texture(ctx
, width
, height
, unpack
, bitmap
);
674 struct pipe_sampler_view
*sv
=
675 st_create_texture_sampler_view(st
->pipe
, pt
);
677 assert(pt
->target
== PIPE_TEXTURE_2D
|| pt
->target
== PIPE_TEXTURE_RECT
);
680 draw_bitmap_quad(ctx
, x
, y
, ctx
->Current
.RasterPos
[2],
682 st
->ctx
->Current
.RasterColor
);
684 pipe_sampler_view_reference(&sv
, NULL
);
687 /* release/free the texture */
688 pipe_resource_reference(&pt
, NULL
);
693 /** Per-context init */
695 st_init_bitmap_functions(struct dd_function_table
*functions
)
697 functions
->Bitmap
= st_Bitmap
;
701 /** Per-context init */
703 st_init_bitmap(struct st_context
*st
)
705 struct pipe_sampler_state
*sampler
= &st
->bitmap
.samplers
[0];
706 struct pipe_context
*pipe
= st
->pipe
;
707 struct pipe_screen
*screen
= pipe
->screen
;
709 /* init sampler state once */
710 memset(sampler
, 0, sizeof(*sampler
));
711 sampler
->wrap_s
= PIPE_TEX_WRAP_CLAMP
;
712 sampler
->wrap_t
= PIPE_TEX_WRAP_CLAMP
;
713 sampler
->wrap_r
= PIPE_TEX_WRAP_CLAMP
;
714 sampler
->min_img_filter
= PIPE_TEX_FILTER_NEAREST
;
715 sampler
->min_mip_filter
= PIPE_TEX_MIPFILTER_NONE
;
716 sampler
->mag_img_filter
= PIPE_TEX_FILTER_NEAREST
;
717 st
->bitmap
.samplers
[1] = *sampler
;
718 st
->bitmap
.samplers
[1].normalized_coords
= 1;
720 /* init baseline rasterizer state once */
721 memset(&st
->bitmap
.rasterizer
, 0, sizeof(st
->bitmap
.rasterizer
));
722 st
->bitmap
.rasterizer
.half_pixel_center
= 1;
723 st
->bitmap
.rasterizer
.bottom_edge_rule
= 1;
724 st
->bitmap
.rasterizer
.depth_clip
= 1;
726 /* find a usable texture format */
727 if (screen
->is_format_supported(screen
, PIPE_FORMAT_I8_UNORM
,
729 PIPE_BIND_SAMPLER_VIEW
)) {
730 st
->bitmap
.tex_format
= PIPE_FORMAT_I8_UNORM
;
732 else if (screen
->is_format_supported(screen
, PIPE_FORMAT_A8_UNORM
,
734 PIPE_BIND_SAMPLER_VIEW
)) {
735 st
->bitmap
.tex_format
= PIPE_FORMAT_A8_UNORM
;
737 else if (screen
->is_format_supported(screen
, PIPE_FORMAT_L8_UNORM
,
739 PIPE_BIND_SAMPLER_VIEW
)) {
740 st
->bitmap
.tex_format
= PIPE_FORMAT_L8_UNORM
;
743 /* XXX support more formats */
747 /* alloc bitmap cache object */
748 st
->bitmap
.cache
= ST_CALLOC_STRUCT(bitmap_cache
);
754 /** Per-context tear-down */
756 st_destroy_bitmap(struct st_context
*st
)
758 struct pipe_context
*pipe
= st
->pipe
;
759 struct bitmap_cache
*cache
= st
->bitmap
.cache
;
762 cso_delete_vertex_shader(st
->cso_context
, st
->bitmap
.vs
);
763 st
->bitmap
.vs
= NULL
;
767 if (cache
->trans
&& cache
->buffer
) {
768 pipe_transfer_unmap(pipe
, cache
->trans
);
770 pipe_resource_reference(&st
->bitmap
.cache
->texture
, NULL
);
771 free(st
->bitmap
.cache
);
772 st
->bitmap
.cache
= NULL
;