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/dlist.h"
37 #include "main/macros.h"
39 #include "program/program.h"
40 #include "program/prog_print.h"
42 #include "st_context.h"
44 #include "st_atom_constbuf.h"
46 #include "st_program.h"
47 #include "st_cb_bitmap.h"
48 #include "st_sampler_view.h"
49 #include "st_texture.h"
51 #include "pipe/p_context.h"
52 #include "pipe/p_defines.h"
53 #include "pipe/p_shader_tokens.h"
54 #include "util/u_inlines.h"
55 #include "util/u_simple_shaders.h"
56 #include "util/u_upload_mgr.h"
57 #include "program/prog_instruction.h"
58 #include "cso_cache/cso_context.h"
62 * glBitmaps are drawn as textured quads. The user's bitmap pattern
63 * is stored in a texture image. An alpha8 texture format is used.
64 * The fragment shader samples a bit (texel) from the texture, then
65 * discards the fragment if the bit is off.
67 * Note that we actually store the inverse image of the bitmap to
68 * simplify the fragment program. An "on" bit gets stored as texel=0x0
69 * and an "off" bit is stored as texel=0xff. Then we kill the
70 * fragment if the negated texel value is less than zero.
75 * The bitmap cache attempts to accumulate multiple glBitmap calls in a
76 * buffer which is then rendered en mass upon a flush, state change, etc.
77 * A wide, short buffer is used to target the common case of a series
78 * of glBitmap calls being used to draw text.
80 static GLboolean UseBitmapCache
= GL_TRUE
;
83 #define BITMAP_CACHE_WIDTH 512
84 #define BITMAP_CACHE_HEIGHT 32
88 /** Window pos to render the cached image */
90 /** Bounds of region used in window coords */
91 GLint xmin
, ymin
, xmax
, ymax
;
95 /** Bitmap's Z position */
98 struct pipe_resource
*texture
;
99 struct pipe_transfer
*trans
;
103 /** An I8 texture image: */
108 /** Epsilon for Z comparisons */
109 #define Z_EPSILON 1e-06
113 * Copy user-provide bitmap bits into texture buffer, expanding
115 * "On" bits will set texels to 0x0.
116 * "Off" bits will not modify texels.
117 * Note that the image is actually going to be upside down in
118 * the texture. We deal with that with texcoords.
121 unpack_bitmap(struct st_context
*st
,
122 GLint px
, GLint py
, GLsizei width
, GLsizei height
,
123 const struct gl_pixelstore_attrib
*unpack
,
124 const GLubyte
*bitmap
,
125 ubyte
*destBuffer
, uint destStride
)
127 destBuffer
+= py
* destStride
+ px
;
129 _mesa_expand_bitmap(width
, height
, unpack
, bitmap
,
130 destBuffer
, destStride
, 0x0);
135 * Create a texture which represents a bitmap image.
137 static struct pipe_resource
*
138 make_bitmap_texture(struct gl_context
*ctx
, GLsizei width
, GLsizei height
,
139 const struct gl_pixelstore_attrib
*unpack
,
140 const GLubyte
*bitmap
)
142 struct st_context
*st
= st_context(ctx
);
143 struct pipe_context
*pipe
= st
->pipe
;
144 struct pipe_transfer
*transfer
;
146 struct pipe_resource
*pt
;
149 bitmap
= _mesa_map_pbo_source(ctx
, unpack
, bitmap
);
155 * Create texture to hold bitmap pattern.
157 pt
= st_texture_create(st
, st
->internal_target
, st
->bitmap
.tex_format
,
158 0, width
, height
, 1, 1, 0,
159 PIPE_BIND_SAMPLER_VIEW
);
161 _mesa_unmap_pbo_source(ctx
, unpack
);
165 dest
= pipe_transfer_map(st
->pipe
, pt
, 0, 0,
167 0, 0, width
, height
, &transfer
);
169 /* Put image into texture transfer */
170 memset(dest
, 0xff, height
* transfer
->stride
);
171 unpack_bitmap(st
, 0, 0, width
, height
, unpack
, bitmap
,
172 dest
, transfer
->stride
);
174 _mesa_unmap_pbo_source(ctx
, unpack
);
176 /* Release transfer */
177 pipe_transfer_unmap(pipe
, transfer
);
183 * Setup pipeline state prior to rendering the bitmap textured quad.
186 setup_render_state(struct gl_context
*ctx
,
187 struct pipe_sampler_view
*sv
,
188 const GLfloat
*color
,
191 struct st_context
*st
= st_context(ctx
);
192 struct cso_context
*cso
= st
->cso_context
;
193 struct st_fp_variant
*fpv
;
194 struct st_fp_variant_key key
;
196 memset(&key
, 0, sizeof(key
));
197 key
.st
= st
->has_shareable_shaders
? NULL
: st
;
198 key
.bitmap
= GL_TRUE
;
199 key
.clamp_color
= st
->clamp_frag_color_in_shader
&&
200 ctx
->Color
._ClampFragmentColor
;
202 fpv
= st_get_fp_variant(st
, st
->fp
, &key
);
204 /* As an optimization, Mesa's fragment programs will sometimes get the
205 * primary color from a statevar/constant rather than a varying variable.
206 * when that's the case, we need to ensure that we use the 'color'
207 * parameter and not the current attribute color (which may have changed
208 * through glRasterPos and state validation.
209 * So, we force the proper color here. Not elegant, but it works.
212 GLfloat colorSave
[4];
213 COPY_4V(colorSave
, ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR0
]);
214 COPY_4V(ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR0
], color
);
215 st_upload_constants(st
, st
->fp
->Base
.Base
.Parameters
,
216 MESA_SHADER_FRAGMENT
);
217 COPY_4V(ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR0
], colorSave
);
220 cso_save_state(cso
, (CSO_BIT_RASTERIZER
|
221 CSO_BIT_FRAGMENT_SAMPLERS
|
222 CSO_BIT_FRAGMENT_SAMPLER_VIEWS
|
224 CSO_BIT_STREAM_OUTPUTS
|
225 CSO_BIT_VERTEX_ELEMENTS
|
226 CSO_BIT_AUX_VERTEX_BUFFER_SLOT
|
227 CSO_BITS_ALL_SHADERS
));
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
];
255 samplers
[fpv
->bitmap_sampler
] = &st
->bitmap
.atlas_sampler
;
257 samplers
[fpv
->bitmap_sampler
] = &st
->bitmap
.sampler
;
258 cso_set_samplers(cso
, PIPE_SHADER_FRAGMENT
, num
,
259 (const struct pipe_sampler_state
**) samplers
);
262 /* user textures, plus the bitmap texture */
264 struct pipe_sampler_view
*sampler_views
[PIPE_MAX_SAMPLERS
];
265 uint num
= MAX2(fpv
->bitmap_sampler
+ 1,
266 st
->state
.num_sampler_views
[PIPE_SHADER_FRAGMENT
]);
267 memcpy(sampler_views
, st
->state
.sampler_views
[PIPE_SHADER_FRAGMENT
],
268 sizeof(sampler_views
));
269 sampler_views
[fpv
->bitmap_sampler
] = sv
;
270 cso_set_sampler_views(cso
, PIPE_SHADER_FRAGMENT
, num
, sampler_views
);
273 /* viewport state: viewport matching window dims */
274 cso_set_viewport_dims(cso
, st
->state
.framebuffer
.width
,
275 st
->state
.framebuffer
.height
,
276 st
->state
.fb_orientation
== Y_0_TOP
);
278 cso_set_vertex_elements(cso
, 3, st
->util_velems
);
280 cso_set_stream_outputs(st
->cso_context
, 0, NULL
, NULL
);
285 * Restore pipeline state after rendering the bitmap textured quad.
288 restore_render_state(struct gl_context
*ctx
)
290 struct st_context
*st
= st_context(ctx
);
291 struct cso_context
*cso
= st
->cso_context
;
293 cso_restore_state(cso
);
298 * Render a glBitmap by drawing a textured quad
301 draw_bitmap_quad(struct gl_context
*ctx
, GLint x
, GLint y
, GLfloat z
,
302 GLsizei width
, GLsizei height
,
303 struct pipe_sampler_view
*sv
,
304 const GLfloat
*color
)
306 struct st_context
*st
= st_context(ctx
);
307 struct pipe_context
*pipe
= st
->pipe
;
308 const float fb_width
= (float) st
->state
.framebuffer
.width
;
309 const float fb_height
= (float) st
->state
.framebuffer
.height
;
310 const float x0
= (float) x
;
311 const float x1
= (float) (x
+ width
);
312 const float y0
= (float) y
;
313 const float y1
= (float) (y
+ height
);
314 float sLeft
= 0.0f
, sRight
= 1.0f
;
315 float tTop
= 0.0f
, tBot
= 1.0f
- tTop
;
316 const float clip_x0
= x0
/ fb_width
* 2.0f
- 1.0f
;
317 const float clip_y0
= y0
/ fb_height
* 2.0f
- 1.0f
;
318 const float clip_x1
= x1
/ fb_width
* 2.0f
- 1.0f
;
319 const float clip_y1
= y1
/ fb_height
* 2.0f
- 1.0f
;
323 /* XXX if the bitmap is larger than the max texture size, break
326 GLuint maxSize
= 1 << (pipe
->screen
->get_param(pipe
->screen
,
327 PIPE_CAP_MAX_TEXTURE_2D_LEVELS
) - 1);
328 assert(width
<= (GLsizei
) maxSize
);
329 assert(height
<= (GLsizei
) maxSize
);
332 setup_render_state(ctx
, sv
, color
, false);
334 /* convert Z from [0,1] to [-1,-1] to match viewport Z scale/bias */
337 if (sv
->texture
->target
== PIPE_TEXTURE_RECT
) {
338 /* use non-normalized texcoords */
339 sRight
= (float) width
;
340 tBot
= (float) height
;
343 if (!st_draw_quad(st
, clip_x0
, clip_y0
, clip_x1
, clip_y1
, z
,
344 sLeft
, tBot
, sRight
, tTop
, color
, 0)) {
345 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBitmap");
348 restore_render_state(ctx
);
350 /* We uploaded modified constants, need to invalidate them. */
351 st
->dirty
|= ST_NEW_FS_CONSTANTS
;
356 reset_cache(struct st_context
*st
)
358 struct bitmap_cache
*cache
= st
->bitmap
.cache
;
360 /*memset(cache->buffer, 0xff, sizeof(cache->buffer));*/
361 cache
->empty
= GL_TRUE
;
363 cache
->xmin
= 1000000;
364 cache
->xmax
= -1000000;
365 cache
->ymin
= 1000000;
366 cache
->ymax
= -1000000;
368 assert(!cache
->texture
);
370 /* allocate a new texture */
371 cache
->texture
= st_texture_create(st
, st
->internal_target
,
372 st
->bitmap
.tex_format
, 0,
373 BITMAP_CACHE_WIDTH
, BITMAP_CACHE_HEIGHT
,
375 PIPE_BIND_SAMPLER_VIEW
);
379 /** Print bitmap image to stdout (debug) */
381 print_cache(const struct bitmap_cache
*cache
)
385 for (i
= 0; i
< BITMAP_CACHE_HEIGHT
; i
++) {
386 k
= BITMAP_CACHE_WIDTH
* (BITMAP_CACHE_HEIGHT
- i
- 1);
387 for (j
= 0; j
< BITMAP_CACHE_WIDTH
; j
++) {
388 if (cache
->buffer
[k
])
400 * Create gallium pipe_transfer object for the bitmap cache.
403 create_cache_trans(struct st_context
*st
)
405 struct pipe_context
*pipe
= st
->pipe
;
406 struct bitmap_cache
*cache
= st
->bitmap
.cache
;
411 /* Map the texture transfer.
412 * Subsequent glBitmap calls will write into the texture image.
414 cache
->buffer
= pipe_transfer_map(pipe
, cache
->texture
, 0, 0,
415 PIPE_TRANSFER_WRITE
, 0, 0,
417 BITMAP_CACHE_HEIGHT
, &cache
->trans
);
419 /* init image to all 0xff */
420 memset(cache
->buffer
, 0xff, cache
->trans
->stride
* BITMAP_CACHE_HEIGHT
);
425 * If there's anything in the bitmap cache, draw/flush it now.
428 st_flush_bitmap_cache(struct st_context
*st
)
430 struct bitmap_cache
*cache
= st
->bitmap
.cache
;
432 if (cache
&& !cache
->empty
) {
433 struct pipe_context
*pipe
= st
->pipe
;
434 struct pipe_sampler_view
*sv
;
436 assert(cache
->xmin
<= cache
->xmax
);
439 printf("flush bitmap, size %d x %d at %d, %d\n",
440 cache
->xmax
- cache
->xmin
,
441 cache
->ymax
- cache
->ymin
,
442 cache
->xpos
, cache
->ypos
);
444 /* The texture transfer has been mapped until now.
445 * So unmap and release the texture transfer before drawing.
447 if (cache
->trans
&& cache
->buffer
) {
450 pipe_transfer_unmap(pipe
, cache
->trans
);
451 cache
->buffer
= NULL
;
455 sv
= st_create_texture_sampler_view(st
->pipe
, cache
->texture
);
457 draw_bitmap_quad(st
->ctx
,
461 BITMAP_CACHE_WIDTH
, BITMAP_CACHE_HEIGHT
,
465 pipe_sampler_view_reference(&sv
, NULL
);
468 /* release/free the texture */
469 pipe_resource_reference(&cache
->texture
, NULL
);
477 * Try to accumulate this glBitmap call in the bitmap cache.
478 * \return GL_TRUE for success, GL_FALSE if bitmap is too large, etc.
481 accum_bitmap(struct gl_context
*ctx
,
482 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
483 const struct gl_pixelstore_attrib
*unpack
,
484 const GLubyte
*bitmap
)
486 struct st_context
*st
= ctx
->st
;
487 struct bitmap_cache
*cache
= st
->bitmap
.cache
;
488 int px
= -999, py
= -999;
489 const GLfloat z
= ctx
->Current
.RasterPos
[2];
491 if (width
> BITMAP_CACHE_WIDTH
||
492 height
> BITMAP_CACHE_HEIGHT
)
493 return GL_FALSE
; /* too big to cache */
496 px
= x
- cache
->xpos
; /* pos in buffer */
497 py
= y
- cache
->ypos
;
498 if (px
< 0 || px
+ width
> BITMAP_CACHE_WIDTH
||
499 py
< 0 || py
+ height
> BITMAP_CACHE_HEIGHT
||
500 !TEST_EQ_4V(ctx
->Current
.RasterColor
, cache
->color
) ||
501 ((fabs(z
- cache
->zpos
) > Z_EPSILON
))) {
502 /* This bitmap would extend beyond cache bounds, or the bitmap
504 * so flush and continue.
506 st_flush_bitmap_cache(st
);
511 /* Initialize. Center bitmap vertically in the buffer. */
513 py
= (BITMAP_CACHE_HEIGHT
- height
) / 2;
515 cache
->ypos
= y
- py
;
517 cache
->empty
= GL_FALSE
;
518 COPY_4FV(cache
->color
, ctx
->Current
.RasterColor
);
528 if (x
+ width
> cache
->xmax
)
529 cache
->xmax
= x
+ width
;
530 if (y
+ height
> cache
->ymax
)
531 cache
->ymax
= y
+ height
;
533 /* create the transfer if needed */
534 create_cache_trans(st
);
537 bitmap
= _mesa_map_pbo_source(ctx
, unpack
, bitmap
);
542 unpack_bitmap(st
, px
, py
, width
, height
, unpack
, bitmap
,
543 cache
->buffer
, BITMAP_CACHE_WIDTH
);
545 _mesa_unmap_pbo_source(ctx
, unpack
);
547 return GL_TRUE
; /* accumulated */
552 * One-time init for drawing bitmaps.
555 init_bitmap_state(struct st_context
*st
)
557 struct pipe_context
*pipe
= st
->pipe
;
558 struct pipe_screen
*screen
= pipe
->screen
;
560 /* This function should only be called once */
561 assert(st
->bitmap
.cache
== NULL
);
563 assert(st
->internal_target
== PIPE_TEXTURE_2D
||
564 st
->internal_target
== PIPE_TEXTURE_RECT
);
566 /* alloc bitmap cache object */
567 st
->bitmap
.cache
= ST_CALLOC_STRUCT(bitmap_cache
);
569 /* init sampler state once */
570 memset(&st
->bitmap
.sampler
, 0, sizeof(st
->bitmap
.sampler
));
571 st
->bitmap
.sampler
.wrap_s
= PIPE_TEX_WRAP_CLAMP
;
572 st
->bitmap
.sampler
.wrap_t
= PIPE_TEX_WRAP_CLAMP
;
573 st
->bitmap
.sampler
.wrap_r
= PIPE_TEX_WRAP_CLAMP
;
574 st
->bitmap
.sampler
.min_img_filter
= PIPE_TEX_FILTER_NEAREST
;
575 st
->bitmap
.sampler
.min_mip_filter
= PIPE_TEX_MIPFILTER_NONE
;
576 st
->bitmap
.sampler
.mag_img_filter
= PIPE_TEX_FILTER_NEAREST
;
577 st
->bitmap
.sampler
.normalized_coords
= st
->internal_target
== PIPE_TEXTURE_2D
;
579 st
->bitmap
.atlas_sampler
= st
->bitmap
.sampler
;
580 st
->bitmap
.atlas_sampler
.normalized_coords
= 0;
582 /* init baseline rasterizer state once */
583 memset(&st
->bitmap
.rasterizer
, 0, sizeof(st
->bitmap
.rasterizer
));
584 st
->bitmap
.rasterizer
.half_pixel_center
= 1;
585 st
->bitmap
.rasterizer
.bottom_edge_rule
= 1;
586 st
->bitmap
.rasterizer
.depth_clip
= 1;
588 /* find a usable texture format */
589 if (screen
->is_format_supported(screen
, PIPE_FORMAT_I8_UNORM
,
590 st
->internal_target
, 0,
591 PIPE_BIND_SAMPLER_VIEW
)) {
592 st
->bitmap
.tex_format
= PIPE_FORMAT_I8_UNORM
;
594 else if (screen
->is_format_supported(screen
, PIPE_FORMAT_A8_UNORM
,
595 st
->internal_target
, 0,
596 PIPE_BIND_SAMPLER_VIEW
)) {
597 st
->bitmap
.tex_format
= PIPE_FORMAT_A8_UNORM
;
599 else if (screen
->is_format_supported(screen
, PIPE_FORMAT_L8_UNORM
,
600 st
->internal_target
, 0,
601 PIPE_BIND_SAMPLER_VIEW
)) {
602 st
->bitmap
.tex_format
= PIPE_FORMAT_L8_UNORM
;
605 /* XXX support more formats */
609 /* Create the vertex shader */
611 const uint semantic_names
[] = { TGSI_SEMANTIC_POSITION
,
613 st
->needs_texcoord_semantic
? TGSI_SEMANTIC_TEXCOORD
:
614 TGSI_SEMANTIC_GENERIC
};
615 const uint semantic_indexes
[] = { 0, 0, 0 };
616 st
->bitmap
.vs
= util_make_vertex_passthrough_shader(st
->pipe
, 3,
627 * Called via ctx->Driver.Bitmap()
630 st_Bitmap(struct gl_context
*ctx
, GLint x
, GLint y
,
631 GLsizei width
, GLsizei height
,
632 const struct gl_pixelstore_attrib
*unpack
, const GLubyte
*bitmap
)
634 struct st_context
*st
= st_context(ctx
);
635 struct pipe_resource
*pt
;
640 st_invalidate_readpix_cache(st
);
642 if (!st
->bitmap
.cache
) {
643 init_bitmap_state(st
);
646 /* We only need to validate any non-ST_NEW_CONSTANTS state. The VS we use
647 * for bitmap drawing uses no constants and the FS constants are
648 * explicitly uploaded in the draw_bitmap_quad() function.
650 if ((st
->dirty
| ctx
->NewDriverState
) & ~ST_NEW_CONSTANTS
&
651 ST_PIPELINE_RENDER_STATE_MASK
||
652 st
->gfx_shaders_may_be_dirty
) {
653 st_validate_state(st
, ST_PIPELINE_RENDER
);
656 if (UseBitmapCache
&& accum_bitmap(ctx
, x
, y
, width
, height
, unpack
, bitmap
))
659 pt
= make_bitmap_texture(ctx
, width
, height
, unpack
, bitmap
);
661 struct pipe_sampler_view
*sv
=
662 st_create_texture_sampler_view(st
->pipe
, pt
);
664 assert(pt
->target
== PIPE_TEXTURE_2D
|| pt
->target
== PIPE_TEXTURE_RECT
);
667 draw_bitmap_quad(ctx
, x
, y
, ctx
->Current
.RasterPos
[2],
668 width
, height
, sv
, ctx
->Current
.RasterColor
);
670 pipe_sampler_view_reference(&sv
, NULL
);
673 /* release/free the texture */
674 pipe_resource_reference(&pt
, NULL
);
680 * Called via ctx->Driver.DrawAtlasBitmap()
683 st_DrawAtlasBitmaps(struct gl_context
*ctx
,
684 const struct gl_bitmap_atlas
*atlas
,
685 GLuint count
, const GLubyte
*ids
)
687 struct st_context
*st
= st_context(ctx
);
688 struct pipe_context
*pipe
= st
->pipe
;
689 struct st_texture_object
*stObj
= st_texture_object(atlas
->texObj
);
690 struct pipe_sampler_view
*sv
;
691 /* convert Z from [0,1] to [-1,-1] to match viewport Z scale/bias */
692 const float z
= ctx
->Current
.RasterPos
[2] * 2.0f
- 1.0f
;
693 const float *color
= ctx
->Current
.RasterColor
;
694 const float clip_x_scale
= 2.0f
/ st
->state
.framebuffer
.width
;
695 const float clip_y_scale
= 2.0f
/ st
->state
.framebuffer
.height
;
696 const unsigned num_verts
= count
* 4;
697 const unsigned num_vert_bytes
= num_verts
* sizeof(struct st_util_vertex
);
698 struct st_util_vertex
*verts
;
699 struct pipe_vertex_buffer vb
= {0};
702 if (!st
->bitmap
.cache
) {
703 init_bitmap_state(st
);
706 st_flush_bitmap_cache(st
);
708 st_validate_state(st
, ST_PIPELINE_RENDER
);
709 st_invalidate_readpix_cache(st
);
711 sv
= st_create_texture_sampler_view(pipe
, stObj
->pt
);
713 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCallLists(bitmap text)");
717 setup_render_state(ctx
, sv
, color
, true);
719 vb
.stride
= sizeof(struct st_util_vertex
);
721 u_upload_alloc(st
->uploader
, 0, num_vert_bytes
, 4,
722 &vb
.buffer_offset
, &vb
.buffer
, (void **) &verts
);
724 /* build quads vertex data */
725 for (i
= 0; i
< count
; i
++) {
726 const GLfloat epsilon
= 0.0001F
;
727 const struct gl_bitmap_glyph
*g
= &atlas
->glyphs
[ids
[i
]];
728 const float xmove
= g
->xmove
, ymove
= g
->ymove
;
729 const float xorig
= g
->xorig
, yorig
= g
->yorig
;
730 const float s0
= g
->x
, t0
= g
->y
;
731 const float s1
= s0
+ g
->w
, t1
= t0
+ g
->h
;
732 const float x0
= IFLOOR(ctx
->Current
.RasterPos
[0] - xorig
+ epsilon
);
733 const float y0
= IFLOOR(ctx
->Current
.RasterPos
[1] - yorig
+ epsilon
);
734 const float x1
= x0
+ g
->w
, y1
= y0
+ g
->h
;
735 const float clip_x0
= x0
* clip_x_scale
- 1.0f
;
736 const float clip_y0
= y0
* clip_y_scale
- 1.0f
;
737 const float clip_x1
= x1
* clip_x_scale
- 1.0f
;
738 const float clip_y1
= y1
* clip_y_scale
- 1.0f
;
740 /* lower-left corner */
752 /* lower-right corner */
764 /* upper-right corner */
776 /* upper-left corner */
788 /* Update the raster position */
789 ctx
->Current
.RasterPos
[0] += xmove
;
790 ctx
->Current
.RasterPos
[1] += ymove
;
793 u_upload_unmap(st
->uploader
);
795 cso_set_vertex_buffers(st
->cso_context
,
796 cso_get_aux_vertex_buffer_slot(st
->cso_context
),
799 cso_draw_arrays(st
->cso_context
, PIPE_PRIM_QUADS
, 0, num_verts
);
801 restore_render_state(ctx
);
803 pipe_resource_reference(&vb
.buffer
, NULL
);
805 pipe_sampler_view_reference(&sv
, NULL
);
807 /* We uploaded modified constants, need to invalidate them. */
808 st
->dirty
|= ST_NEW_FS_CONSTANTS
;
813 /** Per-context init */
815 st_init_bitmap_functions(struct dd_function_table
*functions
)
817 functions
->Bitmap
= st_Bitmap
;
818 functions
->DrawAtlasBitmaps
= st_DrawAtlasBitmaps
;
822 /** Per-context tear-down */
824 st_destroy_bitmap(struct st_context
*st
)
826 struct pipe_context
*pipe
= st
->pipe
;
827 struct bitmap_cache
*cache
= st
->bitmap
.cache
;
830 cso_delete_vertex_shader(st
->cso_context
, st
->bitmap
.vs
);
831 st
->bitmap
.vs
= NULL
;
835 if (cache
->trans
&& cache
->buffer
) {
836 pipe_transfer_unmap(pipe
, cache
->trans
);
838 pipe_resource_reference(&st
->bitmap
.cache
->texture
, NULL
);
839 free(st
->bitmap
.cache
);
840 st
->bitmap
.cache
= NULL
;