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/errors.h"
35 #include "main/image.h"
36 #include "main/bufferobj.h"
37 #include "main/dlist.h"
38 #include "main/macros.h"
40 #include "program/program.h"
41 #include "program/prog_print.h"
43 #include "st_context.h"
45 #include "st_atom_constbuf.h"
47 #include "st_program.h"
48 #include "st_cb_bitmap.h"
49 #include "st_cb_drawpixels.h"
50 #include "st_sampler_view.h"
51 #include "st_texture.h"
54 #include "pipe/p_context.h"
55 #include "pipe/p_defines.h"
56 #include "pipe/p_shader_tokens.h"
57 #include "util/u_inlines.h"
58 #include "util/u_upload_mgr.h"
59 #include "program/prog_instruction.h"
60 #include "cso_cache/cso_context.h"
64 * glBitmaps are drawn as textured quads. The user's bitmap pattern
65 * is stored in a texture image. An alpha8 texture format is used.
66 * The fragment shader samples a bit (texel) from the texture, then
67 * discards the fragment if the bit is off.
69 * Note that we actually store the inverse image of the bitmap to
70 * simplify the fragment program. An "on" bit gets stored as texel=0x0
71 * and an "off" bit is stored as texel=0xff. Then we kill the
72 * fragment if the negated texel value is less than zero.
77 * The bitmap cache attempts to accumulate multiple glBitmap calls in a
78 * buffer which is then rendered en mass upon a flush, state change, etc.
79 * A wide, short buffer is used to target the common case of a series
80 * of glBitmap calls being used to draw text.
82 static GLboolean UseBitmapCache
= GL_TRUE
;
85 #define BITMAP_CACHE_WIDTH 512
86 #define BITMAP_CACHE_HEIGHT 32
89 /** Epsilon for Z comparisons */
90 #define Z_EPSILON 1e-06
94 * Copy user-provide bitmap bits into texture buffer, expanding
96 * "On" bits will set texels to 0x0.
97 * "Off" bits will not modify texels.
98 * Note that the image is actually going to be upside down in
99 * the texture. We deal with that with texcoords.
102 unpack_bitmap(struct st_context
*st
,
103 GLint px
, GLint py
, GLsizei width
, GLsizei height
,
104 const struct gl_pixelstore_attrib
*unpack
,
105 const GLubyte
*bitmap
,
106 ubyte
*destBuffer
, uint destStride
)
108 destBuffer
+= py
* destStride
+ px
;
110 _mesa_expand_bitmap(width
, height
, unpack
, bitmap
,
111 destBuffer
, destStride
, 0x0);
116 * Create a texture which represents a bitmap image.
118 static struct pipe_resource
*
119 make_bitmap_texture(struct gl_context
*ctx
, GLsizei width
, GLsizei height
,
120 const struct gl_pixelstore_attrib
*unpack
,
121 const GLubyte
*bitmap
)
123 struct st_context
*st
= st_context(ctx
);
124 struct pipe_context
*pipe
= st
->pipe
;
125 struct pipe_transfer
*transfer
;
127 struct pipe_resource
*pt
;
130 bitmap
= _mesa_map_pbo_source(ctx
, unpack
, bitmap
);
136 * Create texture to hold bitmap pattern.
138 pt
= st_texture_create(st
, st
->internal_target
, st
->bitmap
.tex_format
,
139 0, width
, height
, 1, 1, 0,
140 PIPE_BIND_SAMPLER_VIEW
);
142 _mesa_unmap_pbo_source(ctx
, unpack
);
146 dest
= pipe_transfer_map(st
->pipe
, pt
, 0, 0,
148 0, 0, width
, height
, &transfer
);
150 /* Put image into texture transfer */
151 memset(dest
, 0xff, height
* transfer
->stride
);
152 unpack_bitmap(st
, 0, 0, width
, height
, unpack
, bitmap
,
153 dest
, transfer
->stride
);
155 _mesa_unmap_pbo_source(ctx
, unpack
);
157 /* Release transfer */
158 pipe_transfer_unmap(pipe
, transfer
);
164 * Setup pipeline state prior to rendering the bitmap textured quad.
167 setup_render_state(struct gl_context
*ctx
,
168 struct pipe_sampler_view
*sv
,
169 const GLfloat
*color
,
172 struct st_context
*st
= st_context(ctx
);
173 struct cso_context
*cso
= st
->cso_context
;
174 struct st_fp_variant
*fpv
;
175 struct st_fp_variant_key key
;
177 memset(&key
, 0, sizeof(key
));
178 key
.st
= st
->has_shareable_shaders
? NULL
: st
;
179 key
.bitmap
= GL_TRUE
;
180 key
.clamp_color
= st
->clamp_frag_color_in_shader
&&
181 ctx
->Color
._ClampFragmentColor
;
183 fpv
= st_get_fp_variant(st
, st
->fp
, &key
);
185 /* As an optimization, Mesa's fragment programs will sometimes get the
186 * primary color from a statevar/constant rather than a varying variable.
187 * when that's the case, we need to ensure that we use the 'color'
188 * parameter and not the current attribute color (which may have changed
189 * through glRasterPos and state validation.
190 * So, we force the proper color here. Not elegant, but it works.
193 GLfloat colorSave
[4];
194 COPY_4V(colorSave
, ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR0
]);
195 COPY_4V(ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR0
], color
);
196 st_upload_constants(st
, &st
->fp
->Base
);
197 COPY_4V(ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR0
], colorSave
);
200 cso_save_state(cso
, (CSO_BIT_RASTERIZER
|
201 CSO_BIT_FRAGMENT_SAMPLERS
|
202 CSO_BIT_FRAGMENT_SAMPLER_VIEWS
|
204 CSO_BIT_STREAM_OUTPUTS
|
205 CSO_BIT_VERTEX_ELEMENTS
|
206 CSO_BIT_AUX_VERTEX_BUFFER_SLOT
|
207 CSO_BITS_ALL_SHADERS
));
210 /* rasterizer state: just scissor */
211 st
->bitmap
.rasterizer
.scissor
= ctx
->Scissor
.EnableFlags
& 1;
212 cso_set_rasterizer(cso
, &st
->bitmap
.rasterizer
);
214 /* fragment shader state: TEX lookup program */
215 cso_set_fragment_shader_handle(cso
, fpv
->base
.driver_shader
);
217 /* vertex shader state: position + texcoord pass-through */
218 cso_set_vertex_shader_handle(cso
, st
->passthrough_vs
);
220 /* disable other shaders */
221 cso_set_tessctrl_shader_handle(cso
, NULL
);
222 cso_set_tesseval_shader_handle(cso
, NULL
);
223 cso_set_geometry_shader_handle(cso
, NULL
);
225 /* user samplers, plus our bitmap sampler */
227 struct pipe_sampler_state
*samplers
[PIPE_MAX_SAMPLERS
];
228 uint num
= MAX2(fpv
->bitmap_sampler
+ 1,
229 st
->state
.num_frag_samplers
);
231 for (i
= 0; i
< st
->state
.num_frag_samplers
; i
++) {
232 samplers
[i
] = &st
->state
.frag_samplers
[i
];
235 samplers
[fpv
->bitmap_sampler
] = &st
->bitmap
.atlas_sampler
;
237 samplers
[fpv
->bitmap_sampler
] = &st
->bitmap
.sampler
;
238 cso_set_samplers(cso
, PIPE_SHADER_FRAGMENT
, num
,
239 (const struct pipe_sampler_state
**) samplers
);
242 /* user textures, plus the bitmap texture */
244 struct pipe_sampler_view
*sampler_views
[PIPE_MAX_SAMPLERS
];
245 uint num
= MAX2(fpv
->bitmap_sampler
+ 1,
246 st
->state
.num_sampler_views
[PIPE_SHADER_FRAGMENT
]);
247 memcpy(sampler_views
, st
->state
.frag_sampler_views
,
248 sizeof(sampler_views
));
249 sampler_views
[fpv
->bitmap_sampler
] = sv
;
250 cso_set_sampler_views(cso
, PIPE_SHADER_FRAGMENT
, num
, sampler_views
);
253 /* viewport state: viewport matching window dims */
254 cso_set_viewport_dims(cso
, st
->state
.fb_width
,
256 st
->state
.fb_orientation
== Y_0_TOP
);
258 st
->util_velems
.count
= 3;
259 cso_set_vertex_elements(cso
, &st
->util_velems
);
261 cso_set_stream_outputs(st
->cso_context
, 0, NULL
, NULL
);
266 * Restore pipeline state after rendering the bitmap textured quad.
269 restore_render_state(struct gl_context
*ctx
)
271 struct st_context
*st
= st_context(ctx
);
272 struct cso_context
*cso
= st
->cso_context
;
274 cso_restore_state(cso
);
279 * Render a glBitmap by drawing a textured quad
282 draw_bitmap_quad(struct gl_context
*ctx
, GLint x
, GLint y
, GLfloat z
,
283 GLsizei width
, GLsizei height
,
284 struct pipe_sampler_view
*sv
,
285 const GLfloat
*color
)
287 struct st_context
*st
= st_context(ctx
);
288 struct pipe_context
*pipe
= st
->pipe
;
289 const float fb_width
= (float) st
->state
.fb_width
;
290 const float fb_height
= (float) st
->state
.fb_height
;
291 const float x0
= (float) x
;
292 const float x1
= (float) (x
+ width
);
293 const float y0
= (float) y
;
294 const float y1
= (float) (y
+ height
);
295 float sLeft
= 0.0f
, sRight
= 1.0f
;
296 float tTop
= 0.0f
, tBot
= 1.0f
- tTop
;
297 const float clip_x0
= x0
/ fb_width
* 2.0f
- 1.0f
;
298 const float clip_y0
= y0
/ fb_height
* 2.0f
- 1.0f
;
299 const float clip_x1
= x1
/ fb_width
* 2.0f
- 1.0f
;
300 const float clip_y1
= y1
/ fb_height
* 2.0f
- 1.0f
;
304 /* XXX if the bitmap is larger than the max texture size, break
307 ASSERTED GLuint maxSize
=
308 pipe
->screen
->get_param(pipe
->screen
, PIPE_CAP_MAX_TEXTURE_2D_SIZE
);
309 assert(width
<= (GLsizei
) maxSize
);
310 assert(height
<= (GLsizei
) maxSize
);
313 setup_render_state(ctx
, sv
, color
, false);
315 /* convert Z from [0,1] to [-1,-1] to match viewport Z scale/bias */
318 if (sv
->texture
->target
== PIPE_TEXTURE_RECT
) {
319 /* use non-normalized texcoords */
320 sRight
= (float) width
;
321 tBot
= (float) height
;
324 if (!st_draw_quad(st
, clip_x0
, clip_y0
, clip_x1
, clip_y1
, z
,
325 sLeft
, tBot
, sRight
, tTop
, color
, 0)) {
326 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBitmap");
329 restore_render_state(ctx
);
331 /* We uploaded modified constants, need to invalidate them. */
332 st
->dirty
|= ST_NEW_FS_CONSTANTS
;
337 reset_cache(struct st_context
*st
)
339 struct st_bitmap_cache
*cache
= &st
->bitmap
.cache
;
341 /*memset(cache->buffer, 0xff, sizeof(cache->buffer));*/
342 cache
->empty
= GL_TRUE
;
344 cache
->xmin
= 1000000;
345 cache
->xmax
= -1000000;
346 cache
->ymin
= 1000000;
347 cache
->ymax
= -1000000;
349 assert(!cache
->texture
);
351 /* allocate a new texture */
352 cache
->texture
= st_texture_create(st
, st
->internal_target
,
353 st
->bitmap
.tex_format
, 0,
354 BITMAP_CACHE_WIDTH
, BITMAP_CACHE_HEIGHT
,
356 PIPE_BIND_SAMPLER_VIEW
);
360 /** Print bitmap image to stdout (debug) */
362 print_cache(const struct st_bitmap_cache
*cache
)
366 for (i
= 0; i
< BITMAP_CACHE_HEIGHT
; i
++) {
367 k
= BITMAP_CACHE_WIDTH
* (BITMAP_CACHE_HEIGHT
- i
- 1);
368 for (j
= 0; j
< BITMAP_CACHE_WIDTH
; j
++) {
369 if (cache
->buffer
[k
])
381 * Create gallium pipe_transfer object for the bitmap cache.
384 create_cache_trans(struct st_context
*st
)
386 struct pipe_context
*pipe
= st
->pipe
;
387 struct st_bitmap_cache
*cache
= &st
->bitmap
.cache
;
392 /* Map the texture transfer.
393 * Subsequent glBitmap calls will write into the texture image.
395 cache
->buffer
= pipe_transfer_map(pipe
, cache
->texture
, 0, 0,
396 PIPE_TRANSFER_WRITE
, 0, 0,
398 BITMAP_CACHE_HEIGHT
, &cache
->trans
);
400 /* init image to all 0xff */
401 memset(cache
->buffer
, 0xff, cache
->trans
->stride
* BITMAP_CACHE_HEIGHT
);
406 * If there's anything in the bitmap cache, draw/flush it now.
409 st_flush_bitmap_cache(struct st_context
*st
)
411 struct st_bitmap_cache
*cache
= &st
->bitmap
.cache
;
414 struct pipe_context
*pipe
= st
->pipe
;
415 struct pipe_sampler_view
*sv
;
417 assert(cache
->xmin
<= cache
->xmax
);
420 printf("flush bitmap, size %d x %d at %d, %d\n",
421 cache
->xmax
- cache
->xmin
,
422 cache
->ymax
- cache
->ymin
,
423 cache
->xpos
, cache
->ypos
);
425 /* The texture transfer has been mapped until now.
426 * So unmap and release the texture transfer before drawing.
428 if (cache
->trans
&& cache
->buffer
) {
431 pipe_transfer_unmap(pipe
, cache
->trans
);
432 cache
->buffer
= NULL
;
436 sv
= st_create_texture_sampler_view(st
->pipe
, cache
->texture
);
438 draw_bitmap_quad(st
->ctx
,
442 BITMAP_CACHE_WIDTH
, BITMAP_CACHE_HEIGHT
,
446 pipe_sampler_view_reference(&sv
, NULL
);
449 /* release/free the texture */
450 pipe_resource_reference(&cache
->texture
, NULL
);
458 * Try to accumulate this glBitmap call in the bitmap cache.
459 * \return GL_TRUE for success, GL_FALSE if bitmap is too large, etc.
462 accum_bitmap(struct gl_context
*ctx
,
463 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
464 const struct gl_pixelstore_attrib
*unpack
,
465 const GLubyte
*bitmap
)
467 struct st_context
*st
= ctx
->st
;
468 struct st_bitmap_cache
*cache
= &st
->bitmap
.cache
;
469 int px
= -999, py
= -999;
470 const GLfloat z
= ctx
->Current
.RasterPos
[2];
472 if (width
> BITMAP_CACHE_WIDTH
||
473 height
> BITMAP_CACHE_HEIGHT
)
474 return GL_FALSE
; /* too big to cache */
477 px
= x
- cache
->xpos
; /* pos in buffer */
478 py
= y
- cache
->ypos
;
479 if (px
< 0 || px
+ width
> BITMAP_CACHE_WIDTH
||
480 py
< 0 || py
+ height
> BITMAP_CACHE_HEIGHT
||
481 !TEST_EQ_4V(ctx
->Current
.RasterColor
, cache
->color
) ||
482 ((fabsf(z
- cache
->zpos
) > Z_EPSILON
))) {
483 /* This bitmap would extend beyond cache bounds, or the bitmap
485 * so flush and continue.
487 st_flush_bitmap_cache(st
);
492 /* Initialize. Center bitmap vertically in the buffer. */
494 py
= (BITMAP_CACHE_HEIGHT
- height
) / 2;
496 cache
->ypos
= y
- py
;
498 cache
->empty
= GL_FALSE
;
499 COPY_4FV(cache
->color
, ctx
->Current
.RasterColor
);
509 if (x
+ width
> cache
->xmax
)
510 cache
->xmax
= x
+ width
;
511 if (y
+ height
> cache
->ymax
)
512 cache
->ymax
= y
+ height
;
514 /* create the transfer if needed */
515 create_cache_trans(st
);
518 bitmap
= _mesa_map_pbo_source(ctx
, unpack
, bitmap
);
523 unpack_bitmap(st
, px
, py
, width
, height
, unpack
, bitmap
,
524 cache
->buffer
, BITMAP_CACHE_WIDTH
);
526 _mesa_unmap_pbo_source(ctx
, unpack
);
528 return GL_TRUE
; /* accumulated */
533 * One-time init for drawing bitmaps.
536 init_bitmap_state(struct st_context
*st
)
538 struct pipe_context
*pipe
= st
->pipe
;
539 struct pipe_screen
*screen
= pipe
->screen
;
541 /* This function should only be called once */
542 assert(!st
->bitmap
.tex_format
);
544 assert(st
->internal_target
== PIPE_TEXTURE_2D
||
545 st
->internal_target
== PIPE_TEXTURE_RECT
);
547 /* init sampler state once */
548 memset(&st
->bitmap
.sampler
, 0, sizeof(st
->bitmap
.sampler
));
549 st
->bitmap
.sampler
.wrap_s
= PIPE_TEX_WRAP_CLAMP
;
550 st
->bitmap
.sampler
.wrap_t
= PIPE_TEX_WRAP_CLAMP
;
551 st
->bitmap
.sampler
.wrap_r
= PIPE_TEX_WRAP_CLAMP
;
552 st
->bitmap
.sampler
.min_img_filter
= PIPE_TEX_FILTER_NEAREST
;
553 st
->bitmap
.sampler
.min_mip_filter
= PIPE_TEX_MIPFILTER_NONE
;
554 st
->bitmap
.sampler
.mag_img_filter
= PIPE_TEX_FILTER_NEAREST
;
555 st
->bitmap
.sampler
.normalized_coords
= st
->internal_target
== PIPE_TEXTURE_2D
;
557 st
->bitmap
.atlas_sampler
= st
->bitmap
.sampler
;
558 st
->bitmap
.atlas_sampler
.normalized_coords
= 0;
560 /* init baseline rasterizer state once */
561 memset(&st
->bitmap
.rasterizer
, 0, sizeof(st
->bitmap
.rasterizer
));
562 st
->bitmap
.rasterizer
.half_pixel_center
= 1;
563 st
->bitmap
.rasterizer
.bottom_edge_rule
= 1;
564 st
->bitmap
.rasterizer
.depth_clip_near
= 1;
565 st
->bitmap
.rasterizer
.depth_clip_far
= 1;
567 /* find a usable texture format */
568 if (screen
->is_format_supported(screen
, PIPE_FORMAT_R8_UNORM
,
569 st
->internal_target
, 0, 0,
570 PIPE_BIND_SAMPLER_VIEW
)) {
571 st
->bitmap
.tex_format
= PIPE_FORMAT_R8_UNORM
;
573 else if (screen
->is_format_supported(screen
, PIPE_FORMAT_A8_UNORM
,
574 st
->internal_target
, 0, 0,
575 PIPE_BIND_SAMPLER_VIEW
)) {
576 st
->bitmap
.tex_format
= PIPE_FORMAT_A8_UNORM
;
579 /* XXX support more formats */
583 /* Create the vertex shader */
584 st_make_passthrough_vertex_shader(st
);
591 * Called via ctx->Driver.Bitmap()
594 st_Bitmap(struct gl_context
*ctx
, GLint x
, GLint y
,
595 GLsizei width
, GLsizei height
,
596 const struct gl_pixelstore_attrib
*unpack
, const GLubyte
*bitmap
)
598 struct st_context
*st
= st_context(ctx
);
599 struct pipe_resource
*pt
;
604 st_invalidate_readpix_cache(st
);
606 if (!st
->bitmap
.tex_format
) {
607 init_bitmap_state(st
);
610 /* We only need to validate any non-ST_NEW_CONSTANTS state. The VS we use
611 * for bitmap drawing uses no constants and the FS constants are
612 * explicitly uploaded in the draw_bitmap_quad() function.
614 if ((st
->dirty
| ctx
->NewDriverState
) & ~ST_NEW_CONSTANTS
&
615 ST_PIPELINE_RENDER_STATE_MASK
||
616 st
->gfx_shaders_may_be_dirty
) {
617 st_validate_state(st
, ST_PIPELINE_META
);
620 if (UseBitmapCache
&& accum_bitmap(ctx
, x
, y
, width
, height
, unpack
, bitmap
))
623 pt
= make_bitmap_texture(ctx
, width
, height
, unpack
, bitmap
);
625 struct pipe_sampler_view
*sv
=
626 st_create_texture_sampler_view(st
->pipe
, pt
);
628 assert(pt
->target
== PIPE_TEXTURE_2D
|| pt
->target
== PIPE_TEXTURE_RECT
);
631 draw_bitmap_quad(ctx
, x
, y
, ctx
->Current
.RasterPos
[2],
632 width
, height
, sv
, ctx
->Current
.RasterColor
);
634 pipe_sampler_view_reference(&sv
, NULL
);
637 /* release/free the texture */
638 pipe_resource_reference(&pt
, NULL
);
644 * Called via ctx->Driver.DrawAtlasBitmap()
647 st_DrawAtlasBitmaps(struct gl_context
*ctx
,
648 const struct gl_bitmap_atlas
*atlas
,
649 GLuint count
, const GLubyte
*ids
)
651 struct st_context
*st
= st_context(ctx
);
652 struct pipe_context
*pipe
= st
->pipe
;
653 struct st_texture_object
*stObj
= st_texture_object(atlas
->texObj
);
654 struct pipe_sampler_view
*sv
;
655 /* convert Z from [0,1] to [-1,-1] to match viewport Z scale/bias */
656 const float z
= ctx
->Current
.RasterPos
[2] * 2.0f
- 1.0f
;
657 const float *color
= ctx
->Current
.RasterColor
;
658 const float clip_x_scale
= 2.0f
/ st
->state
.fb_width
;
659 const float clip_y_scale
= 2.0f
/ st
->state
.fb_height
;
660 const unsigned num_verts
= count
* 4;
661 const unsigned num_vert_bytes
= num_verts
* sizeof(struct st_util_vertex
);
662 struct st_util_vertex
*verts
;
663 struct pipe_vertex_buffer vb
= {0};
666 if (!st
->bitmap
.tex_format
) {
667 init_bitmap_state(st
);
670 st_flush_bitmap_cache(st
);
672 st_validate_state(st
, ST_PIPELINE_META
);
673 st_invalidate_readpix_cache(st
);
675 sv
= st_create_texture_sampler_view(pipe
, stObj
->pt
);
677 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCallLists(bitmap text)");
681 setup_render_state(ctx
, sv
, color
, true);
683 vb
.stride
= sizeof(struct st_util_vertex
);
685 u_upload_alloc(pipe
->stream_uploader
, 0, num_vert_bytes
, 4,
686 &vb
.buffer_offset
, &vb
.buffer
.resource
, (void **) &verts
);
688 if (unlikely(!verts
)) {
689 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCallLists(bitmap text)");
693 /* build quads vertex data */
694 for (i
= 0; i
< count
; i
++) {
695 const GLfloat epsilon
= 0.0001F
;
696 const struct gl_bitmap_glyph
*g
= &atlas
->glyphs
[ids
[i
]];
697 const float xmove
= g
->xmove
, ymove
= g
->ymove
;
698 const float xorig
= g
->xorig
, yorig
= g
->yorig
;
699 const float s0
= g
->x
, t0
= g
->y
;
700 const float s1
= s0
+ g
->w
, t1
= t0
+ g
->h
;
701 const float x0
= util_ifloor(ctx
->Current
.RasterPos
[0] - xorig
+ epsilon
);
702 const float y0
= util_ifloor(ctx
->Current
.RasterPos
[1] - yorig
+ epsilon
);
703 const float x1
= x0
+ g
->w
, y1
= y0
+ g
->h
;
704 const float clip_x0
= x0
* clip_x_scale
- 1.0f
;
705 const float clip_y0
= y0
* clip_y_scale
- 1.0f
;
706 const float clip_x1
= x1
* clip_x_scale
- 1.0f
;
707 const float clip_y1
= y1
* clip_y_scale
- 1.0f
;
709 /* lower-left corner */
721 /* lower-right corner */
733 /* upper-right corner */
745 /* upper-left corner */
757 /* Update the raster position */
758 ctx
->Current
.RasterPos
[0] += xmove
;
759 ctx
->Current
.RasterPos
[1] += ymove
;
762 u_upload_unmap(pipe
->stream_uploader
);
764 cso_set_vertex_buffers(st
->cso_context
, 0, 1, &vb
);
765 cso_draw_arrays(st
->cso_context
, PIPE_PRIM_QUADS
, 0, num_verts
);
768 restore_render_state(ctx
);
770 pipe_resource_reference(&vb
.buffer
.resource
, NULL
);
772 pipe_sampler_view_reference(&sv
, NULL
);
774 /* We uploaded modified constants, need to invalidate them. */
775 st
->dirty
|= ST_NEW_FS_CONSTANTS
;
780 /** Per-context init */
782 st_init_bitmap_functions(struct dd_function_table
*functions
)
784 functions
->Bitmap
= st_Bitmap
;
785 functions
->DrawAtlasBitmaps
= st_DrawAtlasBitmaps
;
789 /** Per-context tear-down */
791 st_destroy_bitmap(struct st_context
*st
)
793 struct pipe_context
*pipe
= st
->pipe
;
794 struct st_bitmap_cache
*cache
= &st
->bitmap
.cache
;
796 if (cache
->trans
&& cache
->buffer
) {
797 pipe_transfer_unmap(pipe
, cache
->trans
);
799 pipe_resource_reference(&st
->bitmap
.cache
.texture
, NULL
);