2007-09-10 23:28:10 +01:00
|
|
|
/**************************************************************************
|
|
|
|
*
|
|
|
|
* Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
|
|
|
|
* All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sub license, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice (including the
|
|
|
|
* next paragraph) shall be included in all copies or substantial portions
|
|
|
|
* of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
|
|
|
|
* IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
|
|
|
|
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
|
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
|
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
**************************************************************************/
|
|
|
|
|
2007-11-17 00:13:01 +00:00
|
|
|
/**
|
|
|
|
* glRasterPos implementation. Basically render a GL_POINT with our
|
|
|
|
* private draw module. Plug in a special "rasterpos" stage at the end
|
|
|
|
* of the 'draw' pipeline to capture the results and update the current
|
|
|
|
* raster pos attributes.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Brian Paul
|
|
|
|
*/
|
|
|
|
|
2007-09-10 23:28:10 +01:00
|
|
|
|
|
|
|
#include "main/imports.h"
|
|
|
|
#include "main/macros.h"
|
2008-02-28 16:44:09 +00:00
|
|
|
#include "main/feedback.h"
|
2007-09-10 23:28:10 +01:00
|
|
|
|
|
|
|
#include "st_context.h"
|
|
|
|
#include "st_atom.h"
|
|
|
|
#include "st_draw.h"
|
|
|
|
#include "st_cb_rasterpos.h"
|
|
|
|
#include "st_draw.h"
|
2008-02-15 08:50:12 +00:00
|
|
|
#include "draw/draw_context.h"
|
2008-04-19 15:29:27 +01:00
|
|
|
#include "draw/draw_pipe.h"
|
2007-09-10 23:28:10 +01:00
|
|
|
#include "shader/prog_instruction.h"
|
2007-11-17 00:13:01 +00:00
|
|
|
#include "vbo/vbo.h"
|
2007-09-10 23:28:10 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2007-11-17 00:13:01 +00:00
|
|
|
/**
|
|
|
|
* Our special drawing pipeline stage (replaces rasterization).
|
|
|
|
*/
|
|
|
|
struct rastpos_stage
|
2007-09-10 23:28:10 +01:00
|
|
|
{
|
2007-11-17 00:13:01 +00:00
|
|
|
struct draw_stage stage; /**< Base class */
|
|
|
|
GLcontext *ctx; /**< Rendering context */
|
2007-09-10 23:28:10 +01:00
|
|
|
|
2007-11-17 00:13:01 +00:00
|
|
|
/* vertex attrib info we can setup once and re-use */
|
|
|
|
struct gl_client_array array[VERT_ATTRIB_MAX];
|
|
|
|
const struct gl_client_array *arrays[VERT_ATTRIB_MAX];
|
|
|
|
struct _mesa_prim prim;
|
|
|
|
};
|
2007-09-10 23:28:10 +01:00
|
|
|
|
|
|
|
|
2007-11-17 00:13:01 +00:00
|
|
|
static INLINE struct rastpos_stage *
|
|
|
|
rastpos_stage( struct draw_stage *stage )
|
|
|
|
{
|
|
|
|
return (struct rastpos_stage *) stage;
|
|
|
|
}
|
2007-09-10 23:28:10 +01:00
|
|
|
|
|
|
|
static void
|
2008-01-25 22:59:27 +00:00
|
|
|
rastpos_flush( struct draw_stage *stage, unsigned flags )
|
2007-11-17 00:13:01 +00:00
|
|
|
{
|
|
|
|
/* no-op */
|
|
|
|
}
|
2007-09-10 23:28:10 +01:00
|
|
|
|
2007-11-17 00:13:01 +00:00
|
|
|
static void
|
|
|
|
rastpos_reset_stipple_counter( struct draw_stage *stage )
|
2007-09-10 23:28:10 +01:00
|
|
|
{
|
2007-11-17 00:13:01 +00:00
|
|
|
/* no-op */
|
2007-09-10 23:28:10 +01:00
|
|
|
}
|
|
|
|
|
2007-11-17 00:13:01 +00:00
|
|
|
static void
|
|
|
|
rastpos_tri( struct draw_stage *stage, struct prim_header *prim )
|
|
|
|
{
|
|
|
|
/* should never get here */
|
|
|
|
assert(0);
|
|
|
|
}
|
2007-09-10 23:28:10 +01:00
|
|
|
|
2007-11-17 00:13:01 +00:00
|
|
|
static void
|
|
|
|
rastpos_line( struct draw_stage *stage, struct prim_header *prim )
|
2007-09-10 23:28:10 +01:00
|
|
|
{
|
2007-11-17 00:13:01 +00:00
|
|
|
/* should never get here */
|
|
|
|
assert(0);
|
2007-09-10 23:28:10 +01:00
|
|
|
}
|
|
|
|
|
2008-01-24 23:05:33 +00:00
|
|
|
static void
|
|
|
|
rastpos_destroy(struct draw_stage *stage)
|
|
|
|
{
|
|
|
|
free(stage);
|
|
|
|
}
|
|
|
|
|
2007-09-10 23:28:10 +01:00
|
|
|
|
|
|
|
/**
|
2007-11-17 00:13:01 +00:00
|
|
|
* Update a raster pos attribute from the vertex result if it's present,
|
|
|
|
* else copy the current attrib.
|
2007-09-10 23:28:10 +01:00
|
|
|
*/
|
2007-11-17 00:13:01 +00:00
|
|
|
static void
|
|
|
|
update_attrib(GLcontext *ctx, const GLuint *outputMapping,
|
|
|
|
const struct vertex_header *vert,
|
|
|
|
GLfloat *dest,
|
|
|
|
GLuint result, GLuint defaultAttrib)
|
2007-09-10 23:28:10 +01:00
|
|
|
{
|
2007-11-17 00:13:01 +00:00
|
|
|
const GLfloat *src;
|
|
|
|
const GLuint k = outputMapping[result];
|
2008-01-22 04:19:24 +00:00
|
|
|
if (k != ~0U)
|
2007-11-17 00:13:01 +00:00
|
|
|
src = vert->data[k];
|
|
|
|
else
|
|
|
|
src = ctx->Current.Attrib[defaultAttrib];
|
|
|
|
COPY_4V(dest, src);
|
2007-09-10 23:28:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2007-11-17 00:13:01 +00:00
|
|
|
* Normally, this function would render a GL_POINT.
|
2007-09-10 23:28:10 +01:00
|
|
|
*/
|
|
|
|
static void
|
2007-11-17 00:13:01 +00:00
|
|
|
rastpos_point(struct draw_stage *stage, struct prim_header *prim)
|
2007-09-10 23:28:10 +01:00
|
|
|
{
|
2007-11-17 00:13:01 +00:00
|
|
|
struct rastpos_stage *rs = rastpos_stage(stage);
|
|
|
|
GLcontext *ctx = rs->ctx;
|
|
|
|
struct st_context *st = ctx->st;
|
2008-07-15 10:26:38 +01:00
|
|
|
const GLfloat height = (GLfloat) ctx->DrawBuffer->Height;
|
2007-11-17 00:13:01 +00:00
|
|
|
const GLuint *outputMapping = st->vertex_result_to_slot;
|
|
|
|
const GLfloat *pos;
|
|
|
|
GLuint i;
|
|
|
|
|
|
|
|
/* if we get here, we didn't get clipped */
|
|
|
|
ctx->Current.RasterPosValid = GL_TRUE;
|
2007-09-10 23:28:10 +01:00
|
|
|
|
2007-11-17 00:13:01 +00:00
|
|
|
/* update raster pos */
|
|
|
|
pos = prim->v[0]->data[0];
|
|
|
|
ctx->Current.RasterPos[0] = pos[0];
|
2008-11-25 01:37:18 +00:00
|
|
|
if (st_fb_orientation(ctx->DrawBuffer) == Y_0_TOP)
|
|
|
|
ctx->Current.RasterPos[1] = height - pos[1]; /* invert Y */
|
|
|
|
else
|
|
|
|
ctx->Current.RasterPos[1] = pos[1];
|
2007-11-17 00:13:01 +00:00
|
|
|
ctx->Current.RasterPos[2] = pos[2];
|
|
|
|
ctx->Current.RasterPos[3] = pos[3];
|
2007-09-10 23:28:10 +01:00
|
|
|
|
2007-11-17 00:13:01 +00:00
|
|
|
/* update other raster attribs */
|
|
|
|
update_attrib(ctx, outputMapping, prim->v[0],
|
|
|
|
ctx->Current.RasterColor,
|
|
|
|
VERT_RESULT_COL0, VERT_ATTRIB_COLOR0);
|
2007-09-10 23:28:10 +01:00
|
|
|
|
2007-11-17 00:13:01 +00:00
|
|
|
update_attrib(ctx, outputMapping, prim->v[0],
|
|
|
|
ctx->Current.RasterSecondaryColor,
|
|
|
|
VERT_RESULT_COL1, VERT_ATTRIB_COLOR1);
|
2007-10-17 19:32:21 +01:00
|
|
|
|
2007-11-17 00:13:01 +00:00
|
|
|
for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
|
|
|
|
update_attrib(ctx, outputMapping, prim->v[0],
|
|
|
|
ctx->Current.RasterTexCoords[i],
|
|
|
|
VERT_RESULT_TEX0 + i, VERT_ATTRIB_TEX0 + i);
|
2007-10-17 19:32:21 +01:00
|
|
|
}
|
2008-02-28 16:44:09 +00:00
|
|
|
|
|
|
|
if (ctx->RenderMode == GL_SELECT) {
|
|
|
|
_mesa_update_hitflag( ctx, ctx->Current.RasterPos[2] );
|
|
|
|
}
|
2007-09-10 23:28:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-17 00:13:01 +00:00
|
|
|
/**
|
|
|
|
* Create rasterpos "drawing" stage.
|
|
|
|
*/
|
|
|
|
static struct rastpos_stage *
|
|
|
|
new_draw_rastpos_stage(GLcontext *ctx, struct draw_context *draw)
|
|
|
|
{
|
|
|
|
struct rastpos_stage *rs = CALLOC_STRUCT(rastpos_stage);
|
2007-12-11 13:00:12 +00:00
|
|
|
GLuint i;
|
2007-11-17 00:13:01 +00:00
|
|
|
|
|
|
|
rs->stage.draw = draw;
|
|
|
|
rs->stage.next = NULL;
|
|
|
|
rs->stage.point = rastpos_point;
|
|
|
|
rs->stage.line = rastpos_line;
|
|
|
|
rs->stage.tri = rastpos_tri;
|
2008-01-25 22:59:27 +00:00
|
|
|
rs->stage.flush = rastpos_flush;
|
2008-01-24 22:23:27 +00:00
|
|
|
rs->stage.destroy = rastpos_destroy;
|
2007-11-17 00:13:01 +00:00
|
|
|
rs->stage.reset_stipple_counter = rastpos_reset_stipple_counter;
|
2008-01-24 23:05:33 +00:00
|
|
|
rs->stage.destroy = rastpos_destroy;
|
2007-11-17 00:13:01 +00:00
|
|
|
rs->ctx = ctx;
|
|
|
|
|
2007-12-11 13:00:12 +00:00
|
|
|
for (i = 0; i < VERT_ATTRIB_MAX; i++) {
|
|
|
|
rs->array[i].Size = 4;
|
|
|
|
rs->array[i].Type = GL_FLOAT;
|
|
|
|
rs->array[i].Stride = 0;
|
|
|
|
rs->array[i].StrideB = 0;
|
|
|
|
rs->array[i].Ptr = (GLubyte *) ctx->Current.Attrib[i];
|
|
|
|
rs->array[i].Enabled = GL_TRUE;
|
|
|
|
rs->array[i].Normalized = GL_TRUE;
|
|
|
|
rs->array[i].BufferObj = NULL;
|
|
|
|
rs->arrays[i] = &rs->array[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
rs->prim.mode = GL_POINTS;
|
|
|
|
rs->prim.indexed = 0;
|
|
|
|
rs->prim.begin = 1;
|
|
|
|
rs->prim.end = 1;
|
|
|
|
rs->prim.weak = 0;
|
|
|
|
rs->prim.start = 0;
|
|
|
|
rs->prim.count = 1;
|
|
|
|
|
2007-11-17 00:13:01 +00:00
|
|
|
return rs;
|
|
|
|
}
|
|
|
|
|
2007-09-10 23:28:10 +01:00
|
|
|
|
|
|
|
static void
|
|
|
|
st_RasterPos(GLcontext *ctx, const GLfloat v[4])
|
|
|
|
{
|
2007-11-17 00:13:01 +00:00
|
|
|
struct st_context *st = ctx->st;
|
|
|
|
struct draw_context *draw = st->draw;
|
|
|
|
struct rastpos_stage *rs;
|
2007-09-10 23:28:10 +01:00
|
|
|
|
2007-11-17 00:13:01 +00:00
|
|
|
if (st->rastpos_stage) {
|
|
|
|
/* get rastpos stage info */
|
|
|
|
rs = rastpos_stage(st->rastpos_stage);
|
2007-09-10 23:28:10 +01:00
|
|
|
}
|
2007-11-17 00:13:01 +00:00
|
|
|
else {
|
|
|
|
/* create rastpos draw stage */
|
|
|
|
rs = new_draw_rastpos_stage(ctx, draw);
|
|
|
|
st->rastpos_stage = &rs->stage;
|
|
|
|
}
|
2007-09-10 23:28:10 +01:00
|
|
|
|
2007-11-17 00:13:01 +00:00
|
|
|
/* plug our rastpos stage into the draw module */
|
|
|
|
draw_set_rasterize_stage(st->draw, st->rastpos_stage);
|
2007-10-18 17:42:47 +01:00
|
|
|
|
2007-11-17 00:13:01 +00:00
|
|
|
/* make sure everything's up to date */
|
|
|
|
st_validate_state(ctx->st);
|
2007-09-25 21:29:11 +01:00
|
|
|
|
2007-11-17 00:13:01 +00:00
|
|
|
/* This will get set only if rastpos_point(), above, gets called */
|
|
|
|
ctx->Current.RasterPosValid = GL_FALSE;
|
2007-09-10 23:28:10 +01:00
|
|
|
|
2007-11-17 00:13:01 +00:00
|
|
|
/* All vertex attribs but position were previously initialized above.
|
|
|
|
* Just plug in position pointer now.
|
|
|
|
*/
|
|
|
|
rs->array[0].Ptr = (GLubyte *) v;
|
2007-09-10 23:28:10 +01:00
|
|
|
|
2007-11-17 00:13:01 +00:00
|
|
|
/* draw the point */
|
|
|
|
st_feedback_draw_vbo(ctx, rs->arrays, &rs->prim, 1, NULL, 0, 1);
|
2007-09-10 23:28:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-17 00:13:01 +00:00
|
|
|
|
2007-09-10 23:28:10 +01:00
|
|
|
void st_init_rasterpos_functions(struct dd_function_table *functions)
|
|
|
|
{
|
|
|
|
functions->RasterPos = st_RasterPos;
|
|
|
|
}
|