1 /**************************************************************************
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
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 TUNGSTEN GRAPHICS 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"
37 #include "main/texformat.h"
38 #include "shader/program.h"
39 #include "shader/prog_parameter.h"
40 #include "shader/prog_print.h"
42 #include "st_context.h"
44 #include "st_atom_constbuf.h"
45 #include "st_program.h"
46 #include "st_cb_bitmap.h"
47 #include "st_cb_program.h"
48 #include "st_mesa_to_tgsi.h"
49 #include "st_texture.h"
50 #include "pipe/p_context.h"
51 #include "pipe/p_defines.h"
52 #include "pipe/p_inlines.h"
53 #include "util/p_tile.h"
54 #include "util/u_draw_quad.h"
55 #include "util/u_simple_shaders.h"
56 #include "shader/prog_instruction.h"
57 #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
;
93 struct pipe_texture
*texture
;
94 struct pipe_surface
*surf
;
98 /** An I8 texture image: */
106 * Make fragment program for glBitmap:
107 * Sample the texture and kill the fragment if the bit is 0.
108 * This program will be combined with the user's fragment program.
110 static struct st_fragment_program
*
111 make_bitmap_fragment_program(GLcontext
*ctx
, GLuint samplerIndex
)
113 struct st_fragment_program
*stfp
;
114 struct gl_program
*p
;
117 p
= ctx
->Driver
.NewProgram(ctx
, GL_FRAGMENT_PROGRAM_ARB
, 0);
121 p
->NumInstructions
= 3;
123 p
->Instructions
= _mesa_alloc_instructions(p
->NumInstructions
);
124 if (!p
->Instructions
) {
125 ctx
->Driver
.DeleteProgram(ctx
, p
);
128 _mesa_init_instructions(p
->Instructions
, p
->NumInstructions
);
130 /* TEX tmp0, fragment.texcoord[0], texture[0], 2D; */
131 p
->Instructions
[ic
].Opcode
= OPCODE_TEX
;
132 p
->Instructions
[ic
].DstReg
.File
= PROGRAM_TEMPORARY
;
133 p
->Instructions
[ic
].DstReg
.Index
= 0;
134 p
->Instructions
[ic
].SrcReg
[0].File
= PROGRAM_INPUT
;
135 p
->Instructions
[ic
].SrcReg
[0].Index
= FRAG_ATTRIB_TEX0
;
136 p
->Instructions
[ic
].TexSrcUnit
= samplerIndex
;
137 p
->Instructions
[ic
].TexSrcTarget
= TEXTURE_2D_INDEX
;
140 /* KIL if -tmp0 < 0 # texel=0 -> keep / texel=0 -> discard */
141 p
->Instructions
[ic
].Opcode
= OPCODE_KIL
;
142 p
->Instructions
[ic
].SrcReg
[0].File
= PROGRAM_TEMPORARY
;
143 p
->Instructions
[ic
].SrcReg
[0].Index
= 0;
144 p
->Instructions
[ic
].SrcReg
[0].NegateBase
= NEGATE_XYZW
;
148 p
->Instructions
[ic
++].Opcode
= OPCODE_END
;
150 assert(ic
== p
->NumInstructions
);
152 p
->InputsRead
= FRAG_BIT_TEX0
;
153 p
->OutputsWritten
= 0x0;
154 p
->SamplersUsed
= (1 << samplerIndex
);
156 stfp
= (struct st_fragment_program
*) p
;
157 stfp
->Base
.UsesKill
= GL_TRUE
;
158 st_translate_fragment_program(ctx
->st
, stfp
, NULL
);
165 find_free_bit(uint bitfield
)
168 for (i
= 0; i
< 32; i
++) {
169 if ((bitfield
& (1 << i
)) == 0) {
178 * Combine basic bitmap fragment program with the user-defined program.
180 static struct st_fragment_program
*
181 combined_bitmap_fragment_program(GLcontext
*ctx
)
183 struct st_context
*st
= ctx
->st
;
184 struct st_fragment_program
*stfp
= st
->fp
;
186 if (!stfp
->bitmap_program
) {
188 * Generate new program which is the user-defined program prefixed
189 * with the bitmap sampler/kill instructions.
191 struct st_fragment_program
*bitmap_prog
;
194 sampler
= find_free_bit(st
->fp
->Base
.Base
.SamplersUsed
);
195 bitmap_prog
= make_bitmap_fragment_program(ctx
, sampler
);
197 stfp
->bitmap_program
= (struct st_fragment_program
*)
198 _mesa_combine_programs(ctx
,
199 &bitmap_prog
->Base
.Base
, &stfp
->Base
.Base
);
200 stfp
->bitmap_program
->bitmap_sampler
= sampler
;
203 struct gl_program
*p
= &stfp
->bitmap_program
->Base
.Base
;
204 printf("Combined bitmap program:\n");
205 _mesa_print_program(p
);
206 printf("InputsRead: 0x%x\n", p
->InputsRead
);
207 printf("OutputsWritten: 0x%x\n", p
->OutputsWritten
);
208 _mesa_print_parameter_list(p
->Parameters
);
212 /* translate to TGSI tokens */
213 st_translate_fragment_program(st
, stfp
->bitmap_program
, NULL
);
216 /* Ideally we'd have updated the pipe constants during the normal
217 * st/atom mechanism. But we can't since this is specific to glBitmap.
219 st_upload_constants(st
, stfp
->Base
.Base
.Parameters
, PIPE_SHADER_FRAGMENT
);
221 return stfp
->bitmap_program
;
226 * Copy user-provide bitmap bits into texture buffer, expanding
228 * "On" bits will set texels to 0xff.
229 * "Off" bits will not modify texels.
230 * Note that the image is actually going to be upside down in
231 * the texture. We deal with that with texcoords.
234 unpack_bitmap(struct st_context
*st
,
235 GLint px
, GLint py
, GLsizei width
, GLsizei height
,
236 const struct gl_pixelstore_attrib
*unpack
,
237 const GLubyte
*bitmap
,
238 ubyte
*destBuffer
, uint destStride
)
242 #define SET_PIXEL(COL, ROW) \
243 destBuffer[(py + (ROW)) * destStride + px + (COL)] = 0x0;
245 for (row
= 0; row
< height
; row
++) {
246 const GLubyte
*src
= (const GLubyte
*) _mesa_image_address2d(unpack
,
247 bitmap
, width
, height
, GL_COLOR_INDEX
, GL_BITMAP
, row
, 0);
249 if (unpack
->LsbFirst
) {
251 GLubyte mask
= 1U << (unpack
->SkipPixels
& 0x7);
252 for (col
= 0; col
< width
; col
++) {
267 /* get ready for next row */
273 GLubyte mask
= 128U >> (unpack
->SkipPixels
& 0x7);
274 for (col
= 0; col
< width
; col
++) {
289 /* get ready for next row */
301 * Create a texture which represents a bitmap image.
303 static struct pipe_texture
*
304 make_bitmap_texture(GLcontext
*ctx
, GLsizei width
, GLsizei height
,
305 const struct gl_pixelstore_attrib
*unpack
,
306 const GLubyte
*bitmap
)
308 struct pipe_context
*pipe
= ctx
->st
->pipe
;
309 struct pipe_screen
*screen
= pipe
->screen
;
310 struct pipe_surface
*surface
;
312 struct pipe_texture
*pt
;
315 bitmap
= _mesa_map_bitmap_pbo(ctx
, unpack
, bitmap
);
321 * Create texture to hold bitmap pattern.
323 pt
= st_texture_create(ctx
->st
, PIPE_TEXTURE_2D
, ctx
->st
->bitmap
.tex_format
,
324 0, width
, height
, 1, 0,
325 PIPE_TEXTURE_USAGE_SAMPLER
);
327 _mesa_unmap_bitmap_pbo(ctx
, unpack
);
331 surface
= screen
->get_tex_surface(screen
, pt
, 0, 0, 0,
332 PIPE_BUFFER_USAGE_CPU_WRITE
);
334 /* map texture surface */
335 dest
= screen
->surface_map(screen
, surface
, PIPE_BUFFER_USAGE_CPU_WRITE
);
337 /* Put image into texture surface */
338 memset(dest
, 0xff, height
* surface
->pitch
);
339 unpack_bitmap(ctx
->st
, 0, 0, width
, height
, unpack
, bitmap
,
340 dest
, surface
->pitch
);
342 _mesa_unmap_bitmap_pbo(ctx
, unpack
);
344 /* Release surface */
345 screen
->surface_unmap(screen
, surface
);
346 pipe_surface_reference(&surface
, NULL
);
353 setup_bitmap_vertex_data(struct st_context
*st
,
354 int x
, int y
, int width
, int height
,
355 float z
, const float color
[4])
357 struct pipe_context
*pipe
= st
->pipe
;
358 const struct gl_framebuffer
*fb
= st
->ctx
->DrawBuffer
;
359 const GLfloat fb_width
= fb
->Width
;
360 const GLfloat fb_height
= fb
->Height
;
361 const GLfloat x0
= x
;
362 const GLfloat x1
= x
+ width
;
363 const GLfloat y0
= y
;
364 const GLfloat y1
= y
+ height
;
365 const GLfloat sLeft
= 0.0F
, sRight
= 1.0F
;
366 const GLfloat tTop
= 0.0, tBot
= 1.0 - tTop
;
367 const GLfloat clip_x0
= x0
/ fb_width
* 2.0 - 1.0;
368 const GLfloat clip_y0
= y0
/ fb_height
* 2.0 - 1.0;
369 const GLfloat clip_x1
= x1
/ fb_width
* 2.0 - 1.0;
370 const GLfloat clip_y1
= y1
/ fb_height
* 2.0 - 1.0;
374 if (!st
->bitmap
.vbuf
) {
375 st
->bitmap
.vbuf
= pipe_buffer_create(pipe
, 32, PIPE_BUFFER_USAGE_VERTEX
,
376 sizeof(st
->bitmap
.vertices
));
379 /* Positions are in clip coords since we need to do clipping in case
380 * the bitmap quad goes beyond the window bounds.
382 st
->bitmap
.vertices
[0][0][0] = clip_x0
;
383 st
->bitmap
.vertices
[0][0][1] = clip_y0
;
384 st
->bitmap
.vertices
[0][2][0] = sLeft
;
385 st
->bitmap
.vertices
[0][2][1] = tTop
;
387 st
->bitmap
.vertices
[1][0][0] = clip_x1
;
388 st
->bitmap
.vertices
[1][0][1] = clip_y0
;
389 st
->bitmap
.vertices
[1][2][0] = sRight
;
390 st
->bitmap
.vertices
[1][2][1] = tTop
;
392 st
->bitmap
.vertices
[2][0][0] = clip_x1
;
393 st
->bitmap
.vertices
[2][0][1] = clip_y1
;
394 st
->bitmap
.vertices
[2][2][0] = sRight
;
395 st
->bitmap
.vertices
[2][2][1] = tBot
;
397 st
->bitmap
.vertices
[3][0][0] = clip_x0
;
398 st
->bitmap
.vertices
[3][0][1] = clip_y1
;
399 st
->bitmap
.vertices
[3][2][0] = sLeft
;
400 st
->bitmap
.vertices
[3][2][1] = tBot
;
402 /* same for all verts: */
403 for (i
= 0; i
< 4; i
++) {
404 st
->bitmap
.vertices
[i
][0][2] = z
;
405 st
->bitmap
.vertices
[i
][0][3] = 1.0;
406 st
->bitmap
.vertices
[i
][1][0] = color
[0];
407 st
->bitmap
.vertices
[i
][1][1] = color
[1];
408 st
->bitmap
.vertices
[i
][1][2] = color
[2];
409 st
->bitmap
.vertices
[i
][1][3] = color
[3];
410 st
->bitmap
.vertices
[i
][2][2] = 0.0; /*R*/
411 st
->bitmap
.vertices
[i
][2][3] = 1.0; /*Q*/
414 /* put vertex data into vbuf */
415 buf
= pipe_buffer_map(pipe
, st
->bitmap
.vbuf
, PIPE_BUFFER_USAGE_CPU_WRITE
);
416 memcpy(buf
, st
->bitmap
.vertices
, sizeof(st
->bitmap
.vertices
));
417 pipe_buffer_unmap(pipe
, st
->bitmap
.vbuf
);
423 * Render a glBitmap by drawing a textured quad
426 draw_bitmap_quad(GLcontext
*ctx
, GLint x
, GLint y
, GLfloat z
,
427 GLsizei width
, GLsizei height
,
428 struct pipe_texture
*pt
)
430 struct st_context
*st
= ctx
->st
;
431 struct pipe_context
*pipe
= ctx
->st
->pipe
;
432 struct cso_context
*cso
= ctx
->st
->cso_context
;
433 struct st_fragment_program
*stfp
;
436 stfp
= combined_bitmap_fragment_program(ctx
);
439 /* XXX if the bitmap is larger than the max texture size, break
442 maxSize
= 1 << (pipe
->screen
->get_param(pipe
->screen
, PIPE_CAP_MAX_TEXTURE_2D_LEVELS
) - 1);
443 assert(width
<= maxSize
);
444 assert(height
<= maxSize
);
446 cso_save_rasterizer(cso
);
447 cso_save_samplers(cso
);
448 cso_save_sampler_textures(cso
);
449 cso_save_viewport(cso
);
450 cso_save_fragment_shader(cso
);
451 cso_save_vertex_shader(cso
);
453 /* rasterizer state: just scissor */
454 st
->bitmap
.rasterizer
.scissor
= ctx
->Scissor
.Enabled
;
455 cso_set_rasterizer(cso
, &st
->bitmap
.rasterizer
);
457 /* fragment shader state: TEX lookup program */
458 cso_set_fragment_shader_handle(cso
, stfp
->driver_shader
);
460 /* vertex shader state: position + texcoord pass-through */
461 cso_set_vertex_shader_handle(cso
, st
->bitmap
.vs
);
463 /* user samplers, plus our bitmap sampler */
465 struct pipe_sampler_state
*samplers
[PIPE_MAX_SAMPLERS
];
466 uint num
= MAX2(stfp
->bitmap_sampler
+ 1, st
->state
.num_samplers
);
468 for (i
= 0; i
< st
->state
.num_samplers
; i
++) {
469 samplers
[i
] = &st
->state
.samplers
[i
];
471 samplers
[stfp
->bitmap_sampler
] = &st
->bitmap
.sampler
;
472 cso_set_samplers(cso
, num
, (const struct pipe_sampler_state
**) samplers
); }
474 /* user textures, plus the bitmap texture */
476 struct pipe_texture
*textures
[PIPE_MAX_SAMPLERS
];
477 uint num
= MAX2(stfp
->bitmap_sampler
+ 1, st
->state
.num_textures
);
478 memcpy(textures
, st
->state
.sampler_texture
, sizeof(textures
));
479 textures
[stfp
->bitmap_sampler
] = pt
;
480 cso_set_sampler_textures(cso
, num
, textures
);
483 /* viewport state: viewport matching window dims */
485 const struct gl_framebuffer
*fb
= st
->ctx
->DrawBuffer
;
486 const GLboolean invert
= (st_fb_orientation(fb
) == Y_0_TOP
);
487 const float width
= fb
->Width
;
488 const float height
= fb
->Height
;
489 struct pipe_viewport_state vp
;
490 vp
.scale
[0] = 0.5 * width
;
491 vp
.scale
[1] = height
* (invert
? -0.5 : 0.5);
494 vp
.translate
[0] = 0.5 * width
;
495 vp
.translate
[1] = 0.5 * height
;
496 vp
.translate
[2] = 0.0;
497 vp
.translate
[3] = 0.0;
498 cso_set_viewport(cso
, &vp
);
501 /* draw textured quad */
502 setup_bitmap_vertex_data(st
, x
, y
, width
, height
,
503 ctx
->Current
.RasterPos
[2],
504 ctx
->Current
.RasterColor
);
506 util_draw_vertex_buffer(pipe
, st
->bitmap
.vbuf
,
507 PIPE_PRIM_TRIANGLE_FAN
,
509 3); /* attribs/vert */
513 cso_restore_rasterizer(cso
);
514 cso_restore_samplers(cso
);
515 cso_restore_sampler_textures(cso
);
516 cso_restore_viewport(cso
);
517 cso_restore_fragment_shader(cso
);
518 cso_restore_vertex_shader(cso
);
523 reset_cache(struct st_context
*st
)
525 struct pipe_context
*pipe
= st
->pipe
;
526 struct pipe_screen
*screen
= pipe
->screen
;
527 struct bitmap_cache
*cache
= st
->bitmap
.cache
;
529 //memset(cache->buffer, 0xff, sizeof(cache->buffer));
530 cache
->empty
= GL_TRUE
;
532 cache
->xmin
= 1000000;
533 cache
->xmax
= -1000000;
534 cache
->ymin
= 1000000;
535 cache
->ymax
= -1000000;
537 assert(!cache
->texture
);
539 /* allocate a new texture */
540 cache
->texture
= st_texture_create(st
, PIPE_TEXTURE_2D
,
541 st
->bitmap
.tex_format
, 0,
542 BITMAP_CACHE_WIDTH
, BITMAP_CACHE_HEIGHT
,
544 PIPE_TEXTURE_USAGE_SAMPLER
);
546 /* Map the texture surface.
547 * Subsequent glBitmap calls will write into the texture image.
549 cache
->surf
= screen
->get_tex_surface(screen
, cache
->texture
, 0, 0, 0,
550 PIPE_BUFFER_USAGE_CPU_WRITE
);
551 cache
->buffer
= screen
->surface_map(screen
, cache
->surf
,
552 PIPE_BUFFER_USAGE_CPU_WRITE
);
554 /* init image to all 0xff */
555 memset(cache
->buffer
, 0xff, BITMAP_CACHE_WIDTH
* BITMAP_CACHE_HEIGHT
);
560 * If there's anything in the bitmap cache, draw/flush it now.
563 st_flush_bitmap_cache(struct st_context
*st
)
565 if (!st
->bitmap
.cache
->empty
) {
566 if (st
->ctx
->DrawBuffer
) {
567 struct bitmap_cache
*cache
= st
->bitmap
.cache
;
568 struct pipe_context
*pipe
= st
->pipe
;
569 struct pipe_screen
*screen
= pipe
->screen
;
571 assert(cache
->xmin
<= cache
->xmax
);
573 printf("flush size %d x %d at %d, %d\n",
574 cache->xmax - cache->xmin,
575 cache->ymax - cache->ymin,
576 cache->xpos, cache->ypos);
579 /* The texture surface has been mapped until now.
580 * So unmap and release the texture surface before drawing.
582 screen
->surface_unmap(screen
, cache
->surf
);
583 screen
->tex_surface_release(screen
, &cache
->surf
);
585 draw_bitmap_quad(st
->ctx
,
588 st
->ctx
->Current
.RasterPos
[2],
589 BITMAP_CACHE_WIDTH
, BITMAP_CACHE_HEIGHT
,
592 /* release/free the texture */
593 pipe_texture_reference(&cache
->texture
, NULL
);
601 * Try to accumulate this glBitmap call in the bitmap cache.
602 * \return GL_TRUE for success, GL_FALSE if bitmap is too large, etc.
605 accum_bitmap(struct st_context
*st
,
606 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
607 const struct gl_pixelstore_attrib
*unpack
,
608 const GLubyte
*bitmap
)
610 struct bitmap_cache
*cache
= st
->bitmap
.cache
;
613 if (width
> BITMAP_CACHE_WIDTH
||
614 height
> BITMAP_CACHE_HEIGHT
)
615 return GL_FALSE
; /* too big to cache */
618 px
= x
- cache
->xpos
; /* pos in buffer */
619 py
= y
- cache
->ypos
;
620 if (px
< 0 || px
+ width
> BITMAP_CACHE_WIDTH
||
621 py
< 0 || py
+ height
> BITMAP_CACHE_HEIGHT
) {
622 /* This bitmap would extend beyond cache bounds,
623 * so flush and continue.
625 st_flush_bitmap_cache(st
);
630 /* Initialize. Center bitmap vertically in the buffer. */
632 py
= (BITMAP_CACHE_HEIGHT
- height
) / 2;
634 cache
->ypos
= y
- py
;
635 cache
->empty
= GL_FALSE
;
644 if (x
+ width
> cache
->xmax
)
645 cache
->xmax
= x
+ width
;
646 if (y
+ height
> cache
->ymax
)
647 cache
->ymax
= y
+ height
;
649 unpack_bitmap(st
, px
, py
, width
, height
, unpack
, bitmap
,
650 cache
->buffer
, BITMAP_CACHE_WIDTH
);
652 return GL_TRUE
; /* accumulated */
658 * Called via ctx->Driver.Bitmap()
661 st_Bitmap(GLcontext
*ctx
, GLint x
, GLint y
, GLsizei width
, GLsizei height
,
662 const struct gl_pixelstore_attrib
*unpack
, const GLubyte
*bitmap
)
664 struct st_context
*st
= ctx
->st
;
665 struct pipe_texture
*pt
;
667 if (width
== 0 || height
== 0)
670 st_validate_state(st
);
672 if (!st
->bitmap
.vs
) {
673 /* create pass-through vertex shader now */
674 const uint semantic_names
[] = { TGSI_SEMANTIC_POSITION
,
676 TGSI_SEMANTIC_GENERIC
};
677 const uint semantic_indexes
[] = { 0, 0, 0 };
678 st
->bitmap
.vs
= util_make_vertex_passthrough_shader(st
->pipe
, 3,
681 &st
->bitmap
.vert_shader
);
684 if (UseBitmapCache
&& accum_bitmap(st
, x
, y
, width
, height
, unpack
, bitmap
))
687 pt
= make_bitmap_texture(ctx
, width
, height
, unpack
, bitmap
);
689 assert(pt
->target
== PIPE_TEXTURE_2D
);
690 draw_bitmap_quad(ctx
, x
, y
, ctx
->Current
.RasterPos
[2],
692 /* release/free the texture */
693 pipe_texture_reference(&pt
, NULL
);
698 /** Per-context init */
700 st_init_bitmap_functions(struct dd_function_table
*functions
)
702 functions
->Bitmap
= st_Bitmap
;
706 /** Per-context init */
708 st_init_bitmap(struct st_context
*st
)
710 struct pipe_sampler_state
*sampler
= &st
->bitmap
.sampler
;
711 struct pipe_context
*pipe
= st
->pipe
;
712 struct pipe_screen
*screen
= pipe
->screen
;
714 /* init sampler state once */
715 memset(sampler
, 0, sizeof(*sampler
));
716 sampler
->wrap_s
= PIPE_TEX_WRAP_CLAMP
;
717 sampler
->wrap_t
= PIPE_TEX_WRAP_CLAMP
;
718 sampler
->wrap_r
= PIPE_TEX_WRAP_CLAMP
;
719 sampler
->min_img_filter
= PIPE_TEX_FILTER_NEAREST
;
720 sampler
->min_mip_filter
= PIPE_TEX_MIPFILTER_NONE
;
721 sampler
->mag_img_filter
= PIPE_TEX_FILTER_NEAREST
;
722 sampler
->normalized_coords
= 1;
724 /* init baseline rasterizer state once */
725 memset(&st
->bitmap
.rasterizer
, 0, sizeof(st
->bitmap
.rasterizer
));
726 st
->bitmap
.rasterizer
.gl_rasterization_rules
= 1;
727 st
->bitmap
.rasterizer
.bypass_vs
= 1;
729 /* find a usable texture format */
730 if (screen
->is_format_supported(screen
, PIPE_FORMAT_I8_UNORM
, PIPE_TEXTURE
)) {
731 st
->bitmap
.tex_format
= PIPE_FORMAT_I8_UNORM
;
734 /* XXX support more formats */
738 /* alloc bitmap cache object */
739 st
->bitmap
.cache
= CALLOC_STRUCT(bitmap_cache
);
745 /** Per-context tear-down */
747 st_destroy_bitmap(struct st_context
*st
)
749 struct pipe_context
*pipe
= st
->pipe
;
750 struct pipe_screen
*screen
= pipe
->screen
;
751 struct bitmap_cache
*cache
= st
->bitmap
.cache
;
753 screen
->surface_unmap(screen
, cache
->surf
);
754 screen
->tex_surface_release(screen
, &cache
->surf
);
757 if (st
->bitmap
.combined_prog
) {
758 st_delete_program(st
->ctx
, &st
->bitmap
.combined_prog
->Base
.Base
);
761 if (st
->bitmap
.program
) {
762 st_delete_program(st
->ctx
, &st
->bitmap
.program
->Base
.Base
);
766 cso_delete_vertex_shader(st
->cso_context
, st
->bitmap
.vs
);
767 st
->bitmap
.vs
= NULL
;
770 if (st
->bitmap
.vbuf
) {
771 pipe_buffer_destroy(pipe
, st
->bitmap
.vbuf
);
772 st
->bitmap
.vbuf
= NULL
;
775 if (st
->bitmap
.cache
) {
776 pipe_texture_release(&st
->bitmap
.cache
->texture
);
777 FREE(st
->bitmap
.cache
);
778 st
->bitmap
.cache
= NULL
;