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
87 /** Epsilon for Z comparisons */
88 #define Z_EPSILON 1e-06
92 * Copy user-provide bitmap bits into texture buffer, expanding
94 * "On" bits will set texels to 0x0.
95 * "Off" bits will not modify texels.
96 * Note that the image is actually going to be upside down in
97 * the texture. We deal with that with texcoords.
100 unpack_bitmap(struct st_context
*st
,
101 GLint px
, GLint py
, GLsizei width
, GLsizei height
,
102 const struct gl_pixelstore_attrib
*unpack
,
103 const GLubyte
*bitmap
,
104 ubyte
*destBuffer
, uint destStride
)
106 destBuffer
+= py
* destStride
+ px
;
108 _mesa_expand_bitmap(width
, height
, unpack
, bitmap
,
109 destBuffer
, destStride
, 0x0);
114 * Create a texture which represents a bitmap image.
116 static struct pipe_resource
*
117 make_bitmap_texture(struct gl_context
*ctx
, GLsizei width
, GLsizei height
,
118 const struct gl_pixelstore_attrib
*unpack
,
119 const GLubyte
*bitmap
)
121 struct st_context
*st
= st_context(ctx
);
122 struct pipe_context
*pipe
= st
->pipe
;
123 struct pipe_transfer
*transfer
;
125 struct pipe_resource
*pt
;
128 bitmap
= _mesa_map_pbo_source(ctx
, unpack
, bitmap
);
134 * Create texture to hold bitmap pattern.
136 pt
= st_texture_create(st
, st
->internal_target
, st
->bitmap
.tex_format
,
137 0, width
, height
, 1, 1, 0,
138 PIPE_BIND_SAMPLER_VIEW
);
140 _mesa_unmap_pbo_source(ctx
, unpack
);
144 dest
= pipe_transfer_map(st
->pipe
, pt
, 0, 0,
146 0, 0, width
, height
, &transfer
);
148 /* Put image into texture transfer */
149 memset(dest
, 0xff, height
* transfer
->stride
);
150 unpack_bitmap(st
, 0, 0, width
, height
, unpack
, bitmap
,
151 dest
, transfer
->stride
);
153 _mesa_unmap_pbo_source(ctx
, unpack
);
155 /* Release transfer */
156 pipe_transfer_unmap(pipe
, transfer
);
162 * Setup pipeline state prior to rendering the bitmap textured quad.
165 setup_render_state(struct gl_context
*ctx
,
166 struct pipe_sampler_view
*sv
,
167 const GLfloat
*color
,
170 struct st_context
*st
= st_context(ctx
);
171 struct cso_context
*cso
= st
->cso_context
;
172 struct st_fp_variant
*fpv
;
173 struct st_fp_variant_key key
;
175 memset(&key
, 0, sizeof(key
));
176 key
.st
= st
->has_shareable_shaders
? NULL
: st
;
177 key
.bitmap
= GL_TRUE
;
178 key
.clamp_color
= st
->clamp_frag_color_in_shader
&&
179 ctx
->Color
._ClampFragmentColor
;
181 fpv
= st_get_fp_variant(st
, st
->fp
, &key
);
183 /* As an optimization, Mesa's fragment programs will sometimes get the
184 * primary color from a statevar/constant rather than a varying variable.
185 * when that's the case, we need to ensure that we use the 'color'
186 * parameter and not the current attribute color (which may have changed
187 * through glRasterPos and state validation.
188 * So, we force the proper color here. Not elegant, but it works.
191 GLfloat colorSave
[4];
192 COPY_4V(colorSave
, ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR0
]);
193 COPY_4V(ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR0
], color
);
194 st_upload_constants(st
, &st
->fp
->Base
);
195 COPY_4V(ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR0
], colorSave
);
198 cso_save_state(cso
, (CSO_BIT_RASTERIZER
|
199 CSO_BIT_FRAGMENT_SAMPLERS
|
200 CSO_BIT_FRAGMENT_SAMPLER_VIEWS
|
202 CSO_BIT_STREAM_OUTPUTS
|
203 CSO_BIT_VERTEX_ELEMENTS
|
204 CSO_BIT_AUX_VERTEX_BUFFER_SLOT
|
205 CSO_BITS_ALL_SHADERS
));
208 /* rasterizer state: just scissor */
209 st
->bitmap
.rasterizer
.scissor
= ctx
->Scissor
.EnableFlags
& 1;
210 cso_set_rasterizer(cso
, &st
->bitmap
.rasterizer
);
212 /* fragment shader state: TEX lookup program */
213 cso_set_fragment_shader_handle(cso
, fpv
->driver_shader
);
215 /* vertex shader state: position + texcoord pass-through */
216 cso_set_vertex_shader_handle(cso
, st
->bitmap
.vs
);
218 /* disable other shaders */
219 cso_set_tessctrl_shader_handle(cso
, NULL
);
220 cso_set_tesseval_shader_handle(cso
, NULL
);
221 cso_set_geometry_shader_handle(cso
, NULL
);
223 /* user samplers, plus our bitmap sampler */
225 struct pipe_sampler_state
*samplers
[PIPE_MAX_SAMPLERS
];
226 uint num
= MAX2(fpv
->bitmap_sampler
+ 1,
227 st
->state
.num_samplers
[PIPE_SHADER_FRAGMENT
]);
229 for (i
= 0; i
< st
->state
.num_samplers
[PIPE_SHADER_FRAGMENT
]; i
++) {
230 samplers
[i
] = &st
->state
.samplers
[PIPE_SHADER_FRAGMENT
][i
];
233 samplers
[fpv
->bitmap_sampler
] = &st
->bitmap
.atlas_sampler
;
235 samplers
[fpv
->bitmap_sampler
] = &st
->bitmap
.sampler
;
236 cso_set_samplers(cso
, PIPE_SHADER_FRAGMENT
, num
,
237 (const struct pipe_sampler_state
**) samplers
);
240 /* user textures, plus the bitmap texture */
242 struct pipe_sampler_view
*sampler_views
[PIPE_MAX_SAMPLERS
];
243 uint num
= MAX2(fpv
->bitmap_sampler
+ 1,
244 st
->state
.num_sampler_views
[PIPE_SHADER_FRAGMENT
]);
245 memcpy(sampler_views
, st
->state
.sampler_views
[PIPE_SHADER_FRAGMENT
],
246 sizeof(sampler_views
));
247 sampler_views
[fpv
->bitmap_sampler
] = sv
;
248 cso_set_sampler_views(cso
, PIPE_SHADER_FRAGMENT
, num
, sampler_views
);
251 /* viewport state: viewport matching window dims */
252 cso_set_viewport_dims(cso
, st
->state
.fb_width
,
254 st
->state
.fb_orientation
== Y_0_TOP
);
256 cso_set_vertex_elements(cso
, 3, st
->util_velems
);
258 cso_set_stream_outputs(st
->cso_context
, 0, NULL
, NULL
);
263 * Restore pipeline state after rendering the bitmap textured quad.
266 restore_render_state(struct gl_context
*ctx
)
268 struct st_context
*st
= st_context(ctx
);
269 struct cso_context
*cso
= st
->cso_context
;
271 cso_restore_state(cso
);
276 * Render a glBitmap by drawing a textured quad
279 draw_bitmap_quad(struct gl_context
*ctx
, GLint x
, GLint y
, GLfloat z
,
280 GLsizei width
, GLsizei height
,
281 struct pipe_sampler_view
*sv
,
282 const GLfloat
*color
)
284 struct st_context
*st
= st_context(ctx
);
285 struct pipe_context
*pipe
= st
->pipe
;
286 const float fb_width
= (float) st
->state
.fb_width
;
287 const float fb_height
= (float) st
->state
.fb_height
;
288 const float x0
= (float) x
;
289 const float x1
= (float) (x
+ width
);
290 const float y0
= (float) y
;
291 const float y1
= (float) (y
+ height
);
292 float sLeft
= 0.0f
, sRight
= 1.0f
;
293 float tTop
= 0.0f
, tBot
= 1.0f
- tTop
;
294 const float clip_x0
= x0
/ fb_width
* 2.0f
- 1.0f
;
295 const float clip_y0
= y0
/ fb_height
* 2.0f
- 1.0f
;
296 const float clip_x1
= x1
/ fb_width
* 2.0f
- 1.0f
;
297 const float clip_y1
= y1
/ fb_height
* 2.0f
- 1.0f
;
301 /* XXX if the bitmap is larger than the max texture size, break
304 GLuint maxSize
= 1 << (pipe
->screen
->get_param(pipe
->screen
,
305 PIPE_CAP_MAX_TEXTURE_2D_LEVELS
) - 1);
306 assert(width
<= (GLsizei
) maxSize
);
307 assert(height
<= (GLsizei
) maxSize
);
310 setup_render_state(ctx
, sv
, color
, false);
312 /* convert Z from [0,1] to [-1,-1] to match viewport Z scale/bias */
315 if (sv
->texture
->target
== PIPE_TEXTURE_RECT
) {
316 /* use non-normalized texcoords */
317 sRight
= (float) width
;
318 tBot
= (float) height
;
321 if (!st_draw_quad(st
, clip_x0
, clip_y0
, clip_x1
, clip_y1
, z
,
322 sLeft
, tBot
, sRight
, tTop
, color
, 0)) {
323 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBitmap");
326 restore_render_state(ctx
);
328 /* We uploaded modified constants, need to invalidate them. */
329 st
->dirty
|= ST_NEW_FS_CONSTANTS
;
334 reset_cache(struct st_context
*st
)
336 struct st_bitmap_cache
*cache
= &st
->bitmap
.cache
;
338 /*memset(cache->buffer, 0xff, sizeof(cache->buffer));*/
339 cache
->empty
= GL_TRUE
;
341 cache
->xmin
= 1000000;
342 cache
->xmax
= -1000000;
343 cache
->ymin
= 1000000;
344 cache
->ymax
= -1000000;
346 assert(!cache
->texture
);
348 /* allocate a new texture */
349 cache
->texture
= st_texture_create(st
, st
->internal_target
,
350 st
->bitmap
.tex_format
, 0,
351 BITMAP_CACHE_WIDTH
, BITMAP_CACHE_HEIGHT
,
353 PIPE_BIND_SAMPLER_VIEW
);
357 /** Print bitmap image to stdout (debug) */
359 print_cache(const struct st_bitmap_cache
*cache
)
363 for (i
= 0; i
< BITMAP_CACHE_HEIGHT
; i
++) {
364 k
= BITMAP_CACHE_WIDTH
* (BITMAP_CACHE_HEIGHT
- i
- 1);
365 for (j
= 0; j
< BITMAP_CACHE_WIDTH
; j
++) {
366 if (cache
->buffer
[k
])
378 * Create gallium pipe_transfer object for the bitmap cache.
381 create_cache_trans(struct st_context
*st
)
383 struct pipe_context
*pipe
= st
->pipe
;
384 struct st_bitmap_cache
*cache
= &st
->bitmap
.cache
;
389 /* Map the texture transfer.
390 * Subsequent glBitmap calls will write into the texture image.
392 cache
->buffer
= pipe_transfer_map(pipe
, cache
->texture
, 0, 0,
393 PIPE_TRANSFER_WRITE
, 0, 0,
395 BITMAP_CACHE_HEIGHT
, &cache
->trans
);
397 /* init image to all 0xff */
398 memset(cache
->buffer
, 0xff, cache
->trans
->stride
* BITMAP_CACHE_HEIGHT
);
403 * If there's anything in the bitmap cache, draw/flush it now.
406 st_flush_bitmap_cache(struct st_context
*st
)
408 struct st_bitmap_cache
*cache
= &st
->bitmap
.cache
;
411 struct pipe_context
*pipe
= st
->pipe
;
412 struct pipe_sampler_view
*sv
;
414 assert(cache
->xmin
<= cache
->xmax
);
417 printf("flush bitmap, size %d x %d at %d, %d\n",
418 cache
->xmax
- cache
->xmin
,
419 cache
->ymax
- cache
->ymin
,
420 cache
->xpos
, cache
->ypos
);
422 /* The texture transfer has been mapped until now.
423 * So unmap and release the texture transfer before drawing.
425 if (cache
->trans
&& cache
->buffer
) {
428 pipe_transfer_unmap(pipe
, cache
->trans
);
429 cache
->buffer
= NULL
;
433 sv
= st_create_texture_sampler_view(st
->pipe
, cache
->texture
);
435 draw_bitmap_quad(st
->ctx
,
439 BITMAP_CACHE_WIDTH
, BITMAP_CACHE_HEIGHT
,
443 pipe_sampler_view_reference(&sv
, NULL
);
446 /* release/free the texture */
447 pipe_resource_reference(&cache
->texture
, NULL
);
455 * Try to accumulate this glBitmap call in the bitmap cache.
456 * \return GL_TRUE for success, GL_FALSE if bitmap is too large, etc.
459 accum_bitmap(struct gl_context
*ctx
,
460 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
461 const struct gl_pixelstore_attrib
*unpack
,
462 const GLubyte
*bitmap
)
464 struct st_context
*st
= ctx
->st
;
465 struct st_bitmap_cache
*cache
= &st
->bitmap
.cache
;
466 int px
= -999, py
= -999;
467 const GLfloat z
= ctx
->Current
.RasterPos
[2];
469 if (width
> BITMAP_CACHE_WIDTH
||
470 height
> BITMAP_CACHE_HEIGHT
)
471 return GL_FALSE
; /* too big to cache */
474 px
= x
- cache
->xpos
; /* pos in buffer */
475 py
= y
- cache
->ypos
;
476 if (px
< 0 || px
+ width
> BITMAP_CACHE_WIDTH
||
477 py
< 0 || py
+ height
> BITMAP_CACHE_HEIGHT
||
478 !TEST_EQ_4V(ctx
->Current
.RasterColor
, cache
->color
) ||
479 ((fabs(z
- cache
->zpos
) > Z_EPSILON
))) {
480 /* This bitmap would extend beyond cache bounds, or the bitmap
482 * so flush and continue.
484 st_flush_bitmap_cache(st
);
489 /* Initialize. Center bitmap vertically in the buffer. */
491 py
= (BITMAP_CACHE_HEIGHT
- height
) / 2;
493 cache
->ypos
= y
- py
;
495 cache
->empty
= GL_FALSE
;
496 COPY_4FV(cache
->color
, ctx
->Current
.RasterColor
);
506 if (x
+ width
> cache
->xmax
)
507 cache
->xmax
= x
+ width
;
508 if (y
+ height
> cache
->ymax
)
509 cache
->ymax
= y
+ height
;
511 /* create the transfer if needed */
512 create_cache_trans(st
);
515 bitmap
= _mesa_map_pbo_source(ctx
, unpack
, bitmap
);
520 unpack_bitmap(st
, px
, py
, width
, height
, unpack
, bitmap
,
521 cache
->buffer
, BITMAP_CACHE_WIDTH
);
523 _mesa_unmap_pbo_source(ctx
, unpack
);
525 return GL_TRUE
; /* accumulated */
530 * One-time init for drawing bitmaps.
533 init_bitmap_state(struct st_context
*st
)
535 struct pipe_context
*pipe
= st
->pipe
;
536 struct pipe_screen
*screen
= pipe
->screen
;
538 /* This function should only be called once */
539 assert(st
->bitmap
.vs
== NULL
);
541 assert(st
->internal_target
== PIPE_TEXTURE_2D
||
542 st
->internal_target
== PIPE_TEXTURE_RECT
);
544 /* init sampler state once */
545 memset(&st
->bitmap
.sampler
, 0, sizeof(st
->bitmap
.sampler
));
546 st
->bitmap
.sampler
.wrap_s
= PIPE_TEX_WRAP_CLAMP
;
547 st
->bitmap
.sampler
.wrap_t
= PIPE_TEX_WRAP_CLAMP
;
548 st
->bitmap
.sampler
.wrap_r
= PIPE_TEX_WRAP_CLAMP
;
549 st
->bitmap
.sampler
.min_img_filter
= PIPE_TEX_FILTER_NEAREST
;
550 st
->bitmap
.sampler
.min_mip_filter
= PIPE_TEX_MIPFILTER_NONE
;
551 st
->bitmap
.sampler
.mag_img_filter
= PIPE_TEX_FILTER_NEAREST
;
552 st
->bitmap
.sampler
.normalized_coords
= st
->internal_target
== PIPE_TEXTURE_2D
;
554 st
->bitmap
.atlas_sampler
= st
->bitmap
.sampler
;
555 st
->bitmap
.atlas_sampler
.normalized_coords
= 0;
557 /* init baseline rasterizer state once */
558 memset(&st
->bitmap
.rasterizer
, 0, sizeof(st
->bitmap
.rasterizer
));
559 st
->bitmap
.rasterizer
.half_pixel_center
= 1;
560 st
->bitmap
.rasterizer
.bottom_edge_rule
= 1;
561 st
->bitmap
.rasterizer
.depth_clip
= 1;
563 /* find a usable texture format */
564 if (screen
->is_format_supported(screen
, PIPE_FORMAT_I8_UNORM
,
565 st
->internal_target
, 0,
566 PIPE_BIND_SAMPLER_VIEW
)) {
567 st
->bitmap
.tex_format
= PIPE_FORMAT_I8_UNORM
;
569 else if (screen
->is_format_supported(screen
, PIPE_FORMAT_A8_UNORM
,
570 st
->internal_target
, 0,
571 PIPE_BIND_SAMPLER_VIEW
)) {
572 st
->bitmap
.tex_format
= PIPE_FORMAT_A8_UNORM
;
574 else if (screen
->is_format_supported(screen
, PIPE_FORMAT_L8_UNORM
,
575 st
->internal_target
, 0,
576 PIPE_BIND_SAMPLER_VIEW
)) {
577 st
->bitmap
.tex_format
= PIPE_FORMAT_L8_UNORM
;
580 /* XXX support more formats */
584 /* Create the vertex shader */
586 const uint semantic_names
[] = { TGSI_SEMANTIC_POSITION
,
588 st
->needs_texcoord_semantic
? TGSI_SEMANTIC_TEXCOORD
:
589 TGSI_SEMANTIC_GENERIC
};
590 const uint semantic_indexes
[] = { 0, 0, 0 };
591 st
->bitmap
.vs
= util_make_vertex_passthrough_shader(st
->pipe
, 3,
602 * Called via ctx->Driver.Bitmap()
605 st_Bitmap(struct gl_context
*ctx
, GLint x
, GLint y
,
606 GLsizei width
, GLsizei height
,
607 const struct gl_pixelstore_attrib
*unpack
, const GLubyte
*bitmap
)
609 struct st_context
*st
= st_context(ctx
);
610 struct pipe_resource
*pt
;
615 st_invalidate_readpix_cache(st
);
617 if (!st
->bitmap
.vs
) {
618 init_bitmap_state(st
);
621 /* We only need to validate any non-ST_NEW_CONSTANTS state. The VS we use
622 * for bitmap drawing uses no constants and the FS constants are
623 * explicitly uploaded in the draw_bitmap_quad() function.
625 if ((st
->dirty
| ctx
->NewDriverState
) & ~ST_NEW_CONSTANTS
&
626 ST_PIPELINE_RENDER_STATE_MASK
||
627 st
->gfx_shaders_may_be_dirty
) {
628 st_validate_state(st
, ST_PIPELINE_RENDER
);
631 if (UseBitmapCache
&& accum_bitmap(ctx
, x
, y
, width
, height
, unpack
, bitmap
))
634 pt
= make_bitmap_texture(ctx
, width
, height
, unpack
, bitmap
);
636 struct pipe_sampler_view
*sv
=
637 st_create_texture_sampler_view(st
->pipe
, pt
);
639 assert(pt
->target
== PIPE_TEXTURE_2D
|| pt
->target
== PIPE_TEXTURE_RECT
);
642 draw_bitmap_quad(ctx
, x
, y
, ctx
->Current
.RasterPos
[2],
643 width
, height
, sv
, ctx
->Current
.RasterColor
);
645 pipe_sampler_view_reference(&sv
, NULL
);
648 /* release/free the texture */
649 pipe_resource_reference(&pt
, NULL
);
655 * Called via ctx->Driver.DrawAtlasBitmap()
658 st_DrawAtlasBitmaps(struct gl_context
*ctx
,
659 const struct gl_bitmap_atlas
*atlas
,
660 GLuint count
, const GLubyte
*ids
)
662 struct st_context
*st
= st_context(ctx
);
663 struct pipe_context
*pipe
= st
->pipe
;
664 struct st_texture_object
*stObj
= st_texture_object(atlas
->texObj
);
665 struct pipe_sampler_view
*sv
;
666 /* convert Z from [0,1] to [-1,-1] to match viewport Z scale/bias */
667 const float z
= ctx
->Current
.RasterPos
[2] * 2.0f
- 1.0f
;
668 const float *color
= ctx
->Current
.RasterColor
;
669 const float clip_x_scale
= 2.0f
/ st
->state
.fb_width
;
670 const float clip_y_scale
= 2.0f
/ st
->state
.fb_height
;
671 const unsigned num_verts
= count
* 4;
672 const unsigned num_vert_bytes
= num_verts
* sizeof(struct st_util_vertex
);
673 struct st_util_vertex
*verts
;
674 struct pipe_vertex_buffer vb
= {0};
677 if (!st
->bitmap
.vs
) {
678 init_bitmap_state(st
);
681 st_flush_bitmap_cache(st
);
683 st_validate_state(st
, ST_PIPELINE_RENDER
);
684 st_invalidate_readpix_cache(st
);
686 sv
= st_create_texture_sampler_view(pipe
, stObj
->pt
);
688 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCallLists(bitmap text)");
692 setup_render_state(ctx
, sv
, color
, true);
694 vb
.stride
= sizeof(struct st_util_vertex
);
696 u_upload_alloc(pipe
->stream_uploader
, 0, num_vert_bytes
, 4,
697 &vb
.buffer_offset
, &vb
.buffer
.resource
, (void **) &verts
);
699 if (unlikely(!verts
)) {
700 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCallLists(bitmap text)");
704 /* build quads vertex data */
705 for (i
= 0; i
< count
; i
++) {
706 const GLfloat epsilon
= 0.0001F
;
707 const struct gl_bitmap_glyph
*g
= &atlas
->glyphs
[ids
[i
]];
708 const float xmove
= g
->xmove
, ymove
= g
->ymove
;
709 const float xorig
= g
->xorig
, yorig
= g
->yorig
;
710 const float s0
= g
->x
, t0
= g
->y
;
711 const float s1
= s0
+ g
->w
, t1
= t0
+ g
->h
;
712 const float x0
= IFLOOR(ctx
->Current
.RasterPos
[0] - xorig
+ epsilon
);
713 const float y0
= IFLOOR(ctx
->Current
.RasterPos
[1] - yorig
+ epsilon
);
714 const float x1
= x0
+ g
->w
, y1
= y0
+ g
->h
;
715 const float clip_x0
= x0
* clip_x_scale
- 1.0f
;
716 const float clip_y0
= y0
* clip_y_scale
- 1.0f
;
717 const float clip_x1
= x1
* clip_x_scale
- 1.0f
;
718 const float clip_y1
= y1
* clip_y_scale
- 1.0f
;
720 /* lower-left corner */
732 /* lower-right corner */
744 /* upper-right corner */
756 /* upper-left corner */
768 /* Update the raster position */
769 ctx
->Current
.RasterPos
[0] += xmove
;
770 ctx
->Current
.RasterPos
[1] += ymove
;
773 u_upload_unmap(pipe
->stream_uploader
);
775 cso_set_vertex_buffers(st
->cso_context
,
776 cso_get_aux_vertex_buffer_slot(st
->cso_context
),
779 cso_draw_arrays(st
->cso_context
, PIPE_PRIM_QUADS
, 0, num_verts
);
782 restore_render_state(ctx
);
784 pipe_resource_reference(&vb
.buffer
.resource
, NULL
);
786 pipe_sampler_view_reference(&sv
, NULL
);
788 /* We uploaded modified constants, need to invalidate them. */
789 st
->dirty
|= ST_NEW_FS_CONSTANTS
;
794 /** Per-context init */
796 st_init_bitmap_functions(struct dd_function_table
*functions
)
798 functions
->Bitmap
= st_Bitmap
;
799 functions
->DrawAtlasBitmaps
= st_DrawAtlasBitmaps
;
803 /** Per-context tear-down */
805 st_destroy_bitmap(struct st_context
*st
)
807 struct pipe_context
*pipe
= st
->pipe
;
808 struct st_bitmap_cache
*cache
= &st
->bitmap
.cache
;
811 cso_delete_vertex_shader(st
->cso_context
, st
->bitmap
.vs
);
812 st
->bitmap
.vs
= NULL
;
815 if (cache
->trans
&& cache
->buffer
) {
816 pipe_transfer_unmap(pipe
, cache
->trans
);
818 pipe_resource_reference(&st
->bitmap
.cache
.texture
, NULL
);