#include "main/image.h"
#include "main/bufferobj.h"
#include "main/macros.h"
-#include "main/texformat.h"
-#include "shader/program.h"
-#include "shader/prog_parameter.h"
-#include "shader/prog_print.h"
+#include "program/program.h"
+#include "program/prog_print.h"
#include "st_context.h"
#include "st_atom.h"
#include "st_atom_constbuf.h"
#include "st_program.h"
#include "st_cb_bitmap.h"
-#include "st_cb_program.h"
-#include "st_mesa_to_tgsi.h"
#include "st_texture.h"
-#include "st_inlines.h"
#include "pipe/p_context.h"
#include "pipe/p_defines.h"
-#include "pipe/p_inlines.h"
-#include "util/u_tile.h"
+#include "pipe/p_shader_tokens.h"
+#include "util/u_inlines.h"
#include "util/u_draw_quad.h"
#include "util/u_simple_shaders.h"
-#include "shader/prog_instruction.h"
+#include "program/prog_instruction.h"
#include "cso_cache/cso_context.h"
+#if FEATURE_drawpix
/**
* glBitmaps are drawn as textured quads. The user's bitmap pattern
/** Bitmap's Z position */
GLfloat zpos;
- struct pipe_texture *texture;
+ struct pipe_resource *texture;
struct pipe_transfer *trans;
GLboolean empty;
static struct st_fragment_program *
make_bitmap_fragment_program(GLcontext *ctx, GLuint samplerIndex)
{
+ struct st_context *st = st_context(ctx);
struct st_fragment_program *stfp;
struct gl_program *p;
GLuint ic = 0;
p->Instructions[ic].Opcode = OPCODE_KIL;
p->Instructions[ic].SrcReg[0].File = PROGRAM_TEMPORARY;
- if (ctx->st->bitmap.tex_format == PIPE_FORMAT_L8_UNORM)
+ if (st->bitmap.tex_format == PIPE_FORMAT_L8_UNORM)
p->Instructions[ic].SrcReg[0].Swizzle = SWIZZLE_XXXX;
p->Instructions[ic].SrcReg[0].Index = 0;
stfp = (struct st_fragment_program *) p;
stfp->Base.UsesKill = GL_TRUE;
- /* No need to send this incomplete program down to hardware:
- *
- * st_translate_fragment_program(ctx->st, stfp, NULL);
- */
-
return stfp;
}
static struct st_fragment_program *
combined_bitmap_fragment_program(GLcontext *ctx)
{
- struct st_context *st = ctx->st;
+ struct st_context *st = st_context(ctx);
struct st_fragment_program *stfp = st->fp;
if (!stfp->bitmap_program) {
#endif
/* translate to TGSI tokens */
- st_translate_fragment_program(st, stfp->bitmap_program, NULL);
+ st_translate_fragment_program(st, stfp->bitmap_program);
}
return stfp->bitmap_program;
/**
* Create a texture which represents a bitmap image.
*/
-static struct pipe_texture *
+static struct pipe_resource *
make_bitmap_texture(GLcontext *ctx, GLsizei width, GLsizei height,
const struct gl_pixelstore_attrib *unpack,
const GLubyte *bitmap)
{
- struct pipe_context *pipe = ctx->st->pipe;
- struct pipe_screen *screen = pipe->screen;
+ struct st_context *st = st_context(ctx);
+ struct pipe_context *pipe = st->pipe;
struct pipe_transfer *transfer;
ubyte *dest;
- struct pipe_texture *pt;
+ struct pipe_resource *pt;
/* PBO source... */
bitmap = _mesa_map_pbo_source(ctx, unpack, bitmap);
/**
* Create texture to hold bitmap pattern.
*/
- pt = st_texture_create(ctx->st, PIPE_TEXTURE_2D, ctx->st->bitmap.tex_format,
+ pt = st_texture_create(st, st->internal_target, st->bitmap.tex_format,
0, width, height, 1,
- PIPE_TEXTURE_USAGE_SAMPLER);
+ PIPE_BIND_SAMPLER_VIEW);
if (!pt) {
_mesa_unmap_pbo_source(ctx, unpack);
return NULL;
}
- transfer = st_no_flush_get_tex_transfer(st_context(ctx), pt, 0, 0, 0,
+ transfer = pipe_get_transfer(st->pipe, pt, 0, 0, 0,
PIPE_TRANSFER_WRITE,
0, 0, width, height);
- dest = screen->transfer_map(screen, transfer);
+ dest = pipe_transfer_map(pipe, transfer);
/* Put image into texture transfer */
memset(dest, 0xff, height * transfer->stride);
- unpack_bitmap(ctx->st, 0, 0, width, height, unpack, bitmap,
+ unpack_bitmap(st, 0, 0, width, height, unpack, bitmap,
dest, transfer->stride);
_mesa_unmap_pbo_source(ctx, unpack);
/* Release transfer */
- screen->transfer_unmap(screen, transfer);
- screen->tex_transfer_destroy(transfer);
+ pipe_transfer_unmap(pipe, transfer);
+ pipe->transfer_destroy(pipe, transfer);
return pt;
}
static GLuint
-setup_bitmap_vertex_data(struct st_context *st,
+setup_bitmap_vertex_data(struct st_context *st, bool normalized,
int x, int y, int width, int height,
float z, const float color[4])
{
const GLfloat x1 = (GLfloat)(x + width);
const GLfloat y0 = (GLfloat)y;
const GLfloat y1 = (GLfloat)(y + height);
- const GLfloat sLeft = (GLfloat)0.0, sRight = (GLfloat)1.0;
- const GLfloat tTop = (GLfloat)0.0, tBot = (GLfloat)1.0 - tTop;
+ GLfloat sLeft = (GLfloat)0.0, sRight = (GLfloat)1.0;
+ GLfloat tTop = (GLfloat)0.0, tBot = (GLfloat)1.0 - tTop;
const GLfloat clip_x0 = (GLfloat)(x0 / fb_width * 2.0 - 1.0);
const GLfloat clip_y0 = (GLfloat)(y0 / fb_height * 2.0 - 1.0);
const GLfloat clip_x1 = (GLfloat)(x1 / fb_width * 2.0 - 1.0);
const GLfloat clip_y1 = (GLfloat)(y1 / fb_height * 2.0 - 1.0);
+ const GLuint max_slots = 1; /* 4096 / sizeof(st->bitmap.vertices); */
+ GLuint i;
+
+ if(!normalized)
+ {
+ sRight = width;
+ tBot = height;
+ }
/* XXX: Need to improve buffer_write to allow NO_WAIT (as well as
* no_flush) updates to buffers where we know there is no conflict
* price of allocating a new buffer for each bitmap cache-flush to
* avoid synchronous rendering.
*/
- const GLuint max_slots = 1; /* 4096 / sizeof(st->bitmap.vertices); */
- GLuint i;
-
if (st->bitmap.vbuf_slot >= max_slots) {
- pipe_buffer_reference(&st->bitmap.vbuf, NULL);
+ pipe_resource_reference(&st->bitmap.vbuf, NULL);
st->bitmap.vbuf_slot = 0;
}
if (!st->bitmap.vbuf) {
- st->bitmap.vbuf = pipe_buffer_create(pipe->screen, 32,
- PIPE_BUFFER_USAGE_VERTEX,
+ st->bitmap.vbuf = pipe_buffer_create(pipe->screen,
+ PIPE_BIND_VERTEX_BUFFER,
max_slots * sizeof(st->bitmap.vertices));
}
}
/* put vertex data into vbuf */
- st_no_flush_pipe_buffer_write(st,
- st->bitmap.vbuf,
- st->bitmap.vbuf_slot * sizeof st->bitmap.vertices,
- sizeof st->bitmap.vertices,
- st->bitmap.vertices);
+ pipe_buffer_write_nooverlap(st->pipe,
+ st->bitmap.vbuf,
+ st->bitmap.vbuf_slot * sizeof st->bitmap.vertices,
+ sizeof st->bitmap.vertices,
+ st->bitmap.vertices);
return st->bitmap.vbuf_slot++ * sizeof st->bitmap.vertices;
}
static void
draw_bitmap_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z,
GLsizei width, GLsizei height,
- struct pipe_texture *pt,
+ struct pipe_sampler_view *sv,
const GLfloat *color)
{
- struct st_context *st = ctx->st;
- struct pipe_context *pipe = ctx->st->pipe;
- struct cso_context *cso = ctx->st->cso_context;
+ struct st_context *st = st_context(ctx);
+ struct pipe_context *pipe = st->pipe;
+ struct cso_context *cso = st->cso_context;
struct st_fragment_program *stfp;
GLuint maxSize;
GLuint offset;
cso_save_rasterizer(cso);
cso_save_samplers(cso);
- cso_save_sampler_textures(cso);
+ cso_save_fragment_sampler_views(cso);
cso_save_viewport(cso);
cso_save_fragment_shader(cso);
cso_save_vertex_shader(cso);
+ cso_save_vertex_elements(cso);
/* rasterizer state: just scissor */
st->bitmap.rasterizer.scissor = ctx->Scissor.Enabled;
for (i = 0; i < st->state.num_samplers; i++) {
samplers[i] = &st->state.samplers[i];
}
- samplers[stfp->bitmap_sampler] = &st->bitmap.sampler;
+ samplers[stfp->bitmap_sampler] = &st->bitmap.samplers[sv->texture->target != PIPE_TEXTURE_RECT];
cso_set_samplers(cso, num, (const struct pipe_sampler_state **) samplers);
}
/* user textures, plus the bitmap texture */
{
- struct pipe_texture *textures[PIPE_MAX_SAMPLERS];
+ struct pipe_sampler_view *sampler_views[PIPE_MAX_SAMPLERS];
uint num = MAX2(stfp->bitmap_sampler + 1, st->state.num_textures);
- memcpy(textures, st->state.sampler_texture, sizeof(textures));
- textures[stfp->bitmap_sampler] = pt;
- cso_set_sampler_textures(cso, num, textures);
+ memcpy(sampler_views, st->state.sampler_views, sizeof(sampler_views));
+ sampler_views[stfp->bitmap_sampler] = sv;
+ cso_set_fragment_sampler_views(cso, num, sampler_views);
}
/* viewport state: viewport matching window dims */
struct pipe_viewport_state vp;
vp.scale[0] = 0.5f * width;
vp.scale[1] = height * (invert ? -0.5f : 0.5f);
- vp.scale[2] = 1.0f;
+ vp.scale[2] = 0.5f;
vp.scale[3] = 1.0f;
vp.translate[0] = 0.5f * width;
vp.translate[1] = 0.5f * height;
- vp.translate[2] = 0.0f;
+ vp.translate[2] = 0.5f;
vp.translate[3] = 0.0f;
cso_set_viewport(cso, &vp);
}
+ cso_set_vertex_elements(cso, 3, st->velems_util_draw);
+
+ /* convert Z from [0,1] to [-1,-1] to match viewport Z scale/bias */
+ z = z * 2.0 - 1.0;
+
/* draw textured quad */
- offset = setup_bitmap_vertex_data(st, x, y, width, height, z, color);
+ offset = setup_bitmap_vertex_data(st, sv->texture->target != PIPE_TEXTURE_RECT, x, y, width, height, z, color);
util_draw_vertex_buffer(pipe, st->bitmap.vbuf, offset,
PIPE_PRIM_TRIANGLE_FAN,
/* restore state */
cso_restore_rasterizer(cso);
cso_restore_samplers(cso);
- cso_restore_sampler_textures(cso);
+ cso_restore_fragment_sampler_views(cso);
cso_restore_viewport(cso);
cso_restore_fragment_shader(cso);
cso_restore_vertex_shader(cso);
+ cso_restore_vertex_elements(cso);
}
reset_cache(struct st_context *st)
{
struct pipe_context *pipe = st->pipe;
- struct pipe_screen *screen = pipe->screen;
struct bitmap_cache *cache = st->bitmap.cache;
/*memset(cache->buffer, 0xff, sizeof(cache->buffer));*/
cache->ymax = -1000000;
if (cache->trans) {
- screen->tex_transfer_destroy(cache->trans);
+ pipe->transfer_destroy(pipe, cache->trans);
cache->trans = NULL;
}
cache->texture = st_texture_create(st, PIPE_TEXTURE_2D,
st->bitmap.tex_format, 0,
BITMAP_CACHE_WIDTH, BITMAP_CACHE_HEIGHT,
- 1, PIPE_TEXTURE_USAGE_SAMPLER);
+ 1,
+ PIPE_BIND_SAMPLER_VIEW);
+}
+
+/** Print bitmap image to stdout (debug) */
+static void
+print_cache(const struct bitmap_cache *cache)
+{
+ int i, j, k;
+
+ for (i = 0; i < BITMAP_CACHE_HEIGHT; i++) {
+ k = BITMAP_CACHE_WIDTH * (BITMAP_CACHE_HEIGHT - i - 1);
+ for (j = 0; j < BITMAP_CACHE_WIDTH; j++) {
+ if (cache->buffer[k])
+ printf("X");
+ else
+ printf(" ");
+ k++;
+ }
+ printf("\n");
+ }
}
+
static void
create_cache_trans(struct st_context *st)
{
struct pipe_context *pipe = st->pipe;
- struct pipe_screen *screen = pipe->screen;
struct bitmap_cache *cache = st->bitmap.cache;
if (cache->trans)
/* Map the texture transfer.
* Subsequent glBitmap calls will write into the texture image.
*/
- cache->trans = st_no_flush_get_tex_transfer(st, cache->texture, 0, 0, 0,
+ cache->trans = pipe_get_transfer(st->pipe, cache->texture, 0, 0, 0,
PIPE_TRANSFER_WRITE, 0, 0,
BITMAP_CACHE_WIDTH,
BITMAP_CACHE_HEIGHT);
- cache->buffer = screen->transfer_map(screen, cache->trans);
+ cache->buffer = pipe_transfer_map(pipe, cache->trans);
/* init image to all 0xff */
memset(cache->buffer, 0xff, cache->trans->stride * BITMAP_CACHE_HEIGHT);
if (st->ctx->DrawBuffer) {
struct pipe_context *pipe = st->pipe;
- struct pipe_screen *screen = pipe->screen;
+ struct pipe_sampler_view *sv;
assert(cache->xmin <= cache->xmax);
* So unmap and release the texture transfer before drawing.
*/
if (cache->trans) {
- screen->transfer_unmap(screen, cache->trans);
+ if (0)
+ print_cache(cache);
+ pipe_transfer_unmap(pipe, cache->trans);
cache->buffer = NULL;
- screen->tex_transfer_destroy(cache->trans);
+ pipe->transfer_destroy(pipe, cache->trans);
cache->trans = NULL;
}
- draw_bitmap_quad(st->ctx,
- cache->xpos,
- cache->ypos,
- cache->zpos,
- BITMAP_CACHE_WIDTH, BITMAP_CACHE_HEIGHT,
- cache->texture,
- cache->color);
+ sv = st_create_texture_sampler_view(st->pipe, cache->texture);
+ if (sv) {
+ draw_bitmap_quad(st->ctx,
+ cache->xpos,
+ cache->ypos,
+ cache->zpos,
+ BITMAP_CACHE_WIDTH, BITMAP_CACHE_HEIGHT,
+ sv,
+ cache->color);
+
+ pipe_sampler_view_reference(&sv, NULL);
+ }
}
/* release/free the texture */
- pipe_texture_reference(&cache->texture, NULL);
+ pipe_resource_reference(&cache->texture, NULL);
reset_cache(st);
}
/* Release vertex buffer to avoid synchronous rendering if we were
* to map it in the next frame.
*/
- pipe_buffer_reference(&st->bitmap.vbuf, NULL);
+ pipe_resource_reference(&st->bitmap.vbuf, NULL);
st->bitmap.vbuf_slot = 0;
}
const GLubyte *bitmap )
{
struct bitmap_cache *cache = st->bitmap.cache;
- int px = -999, py;
+ int px = -999, py = -999;
const GLfloat z = st->ctx->Current.RasterPos[2];
if (width > BITMAP_CACHE_WIDTH ||
}
assert(px != -999);
+ assert(py != -999);
if (x < cache->xmin)
cache->xmin = x;
st_Bitmap(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height,
const struct gl_pixelstore_attrib *unpack, const GLubyte *bitmap )
{
- struct st_context *st = ctx->st;
- struct pipe_texture *pt;
+ struct st_context *st = st_context(ctx);
+ struct pipe_resource *pt;
if (width == 0 || height == 0)
return;
pt = make_bitmap_texture(ctx, width, height, unpack, bitmap);
if (pt) {
- assert(pt->target == PIPE_TEXTURE_2D);
- draw_bitmap_quad(ctx, x, y, ctx->Current.RasterPos[2],
- width, height, pt,
- st->ctx->Current.RasterColor);
+ struct pipe_sampler_view *sv = st_create_texture_sampler_view(st->pipe, pt);
+
+ assert(pt->target == PIPE_TEXTURE_2D || pt->target == PIPE_TEXTURE_RECT);
+
+ if (sv) {
+ draw_bitmap_quad(ctx, x, y, ctx->Current.RasterPos[2],
+ width, height, sv,
+ st->ctx->Current.RasterColor);
+
+ pipe_sampler_view_reference(&sv, NULL);
+ }
+
/* release/free the texture */
- pipe_texture_reference(&pt, NULL);
+ pipe_resource_reference(&pt, NULL);
}
}
void
st_init_bitmap(struct st_context *st)
{
- struct pipe_sampler_state *sampler = &st->bitmap.sampler;
+ struct pipe_sampler_state *sampler = &st->bitmap.samplers[0];
struct pipe_context *pipe = st->pipe;
struct pipe_screen *screen = pipe->screen;
sampler->min_img_filter = PIPE_TEX_FILTER_NEAREST;
sampler->min_mip_filter = PIPE_TEX_MIPFILTER_NONE;
sampler->mag_img_filter = PIPE_TEX_FILTER_NEAREST;
- sampler->normalized_coords = 1;
+ st->bitmap.samplers[1] = *sampler;
+ st->bitmap.samplers[1].normalized_coords = 1;
/* init baseline rasterizer state once */
memset(&st->bitmap.rasterizer, 0, sizeof(st->bitmap.rasterizer));
st->bitmap.rasterizer.gl_rasterization_rules = 1;
/* find a usable texture format */
- if (screen->is_format_supported(screen, PIPE_FORMAT_I8_UNORM, PIPE_TEXTURE_2D,
- PIPE_TEXTURE_USAGE_SAMPLER, 0)) {
+ if (screen->is_format_supported(screen, PIPE_FORMAT_I8_UNORM, PIPE_TEXTURE_2D, 0,
+ PIPE_BIND_SAMPLER_VIEW, 0)) {
st->bitmap.tex_format = PIPE_FORMAT_I8_UNORM;
}
- else if (screen->is_format_supported(screen, PIPE_FORMAT_A8_UNORM, PIPE_TEXTURE_2D,
- PIPE_TEXTURE_USAGE_SAMPLER, 0)) {
+ else if (screen->is_format_supported(screen, PIPE_FORMAT_A8_UNORM, PIPE_TEXTURE_2D, 0,
+ PIPE_BIND_SAMPLER_VIEW, 0)) {
st->bitmap.tex_format = PIPE_FORMAT_A8_UNORM;
}
- else if (screen->is_format_supported(screen, PIPE_FORMAT_L8_UNORM, PIPE_TEXTURE_2D,
- PIPE_TEXTURE_USAGE_SAMPLER, 0)) {
+ else if (screen->is_format_supported(screen, PIPE_FORMAT_L8_UNORM, PIPE_TEXTURE_2D, 0,
+ PIPE_BIND_SAMPLER_VIEW, 0)) {
st->bitmap.tex_format = PIPE_FORMAT_L8_UNORM;
}
else {
st_destroy_bitmap(struct st_context *st)
{
struct pipe_context *pipe = st->pipe;
- struct pipe_screen *screen = pipe->screen;
struct bitmap_cache *cache = st->bitmap.cache;
}
if (st->bitmap.vbuf) {
- pipe_buffer_reference(&st->bitmap.vbuf, NULL);
+ pipe_resource_reference(&st->bitmap.vbuf, NULL);
st->bitmap.vbuf = NULL;
}
if (cache) {
if (cache->trans) {
- screen->transfer_unmap(screen, cache->trans);
- screen->tex_transfer_destroy(cache->trans);
+ pipe_transfer_unmap(pipe, cache->trans);
+ pipe->transfer_destroy(pipe, cache->trans);
}
- pipe_texture_reference(&st->bitmap.cache->texture, NULL);
- _mesa_free(st->bitmap.cache);
+ pipe_resource_reference(&st->bitmap.cache->texture, NULL);
+ free(st->bitmap.cache);
st->bitmap.cache = NULL;
}
}
+
+#endif /* FEATURE_drawpix */