2007-07-09 16:12:13 -06: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.
|
|
|
|
*
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Authors:
|
|
|
|
* Keith Whitwell <keith@tungstengraphics.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2007-08-16 18:11:55 -06:00
|
|
|
#ifdef MESA
|
|
|
|
#include "main/macros.h"
|
|
|
|
#else
|
|
|
|
#include "pipe/p_util.h"
|
|
|
|
#endif
|
2007-07-09 16:12:13 -06:00
|
|
|
#include "draw_context.h"
|
|
|
|
#include "draw_private.h"
|
|
|
|
|
|
|
|
struct draw_context *draw_create( void )
|
|
|
|
{
|
|
|
|
struct draw_context *draw = CALLOC_STRUCT( draw_context );
|
|
|
|
|
|
|
|
/* create pipeline stages */
|
2007-07-12 13:32:31 -06:00
|
|
|
draw->pipeline.unfilled = draw_unfilled_stage( draw );
|
|
|
|
draw->pipeline.twoside = draw_twoside_stage( draw );
|
|
|
|
draw->pipeline.offset = draw_offset_stage( draw );
|
|
|
|
draw->pipeline.clip = draw_clip_stage( draw );
|
|
|
|
draw->pipeline.flatshade = draw_flatshade_stage( draw );
|
|
|
|
draw->pipeline.cull = draw_cull_stage( draw );
|
2007-07-09 16:12:13 -06:00
|
|
|
|
|
|
|
ASSIGN_4V( draw->plane[0], -1, 0, 0, 1 );
|
|
|
|
ASSIGN_4V( draw->plane[1], 1, 0, 0, 1 );
|
|
|
|
ASSIGN_4V( draw->plane[2], 0, -1, 0, 1 );
|
|
|
|
ASSIGN_4V( draw->plane[3], 0, 1, 0, 1 );
|
|
|
|
ASSIGN_4V( draw->plane[4], 0, 0, 1, 1 ); /* yes these are correct */
|
|
|
|
ASSIGN_4V( draw->plane[5], 0, 0, -1, 1 ); /* mesa's a bit wonky */
|
|
|
|
draw->nr_planes = 6;
|
|
|
|
|
2007-08-16 18:11:55 -06:00
|
|
|
#ifdef MESA
|
2007-07-09 16:12:13 -06:00
|
|
|
draw->vf = vf_create( GL_TRUE );
|
2007-08-16 18:11:55 -06:00
|
|
|
#endif
|
2007-07-09 16:12:13 -06:00
|
|
|
|
2007-08-14 15:44:41 +01:00
|
|
|
/* Statically allocate maximum sized vertices for the cache - could be cleverer...
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char *tmp = malloc(Elements(draw->vcache.vertex) * MAX_VERTEX_SIZE);
|
|
|
|
|
|
|
|
for (i = 0; i < Elements(draw->vcache.vertex); i++)
|
|
|
|
draw->vcache.vertex[i] = (struct vertex_header *)(tmp + i * MAX_VERTEX_SIZE);
|
|
|
|
}
|
|
|
|
|
2007-07-09 16:12:13 -06:00
|
|
|
return draw;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void draw_destroy( struct draw_context *draw )
|
|
|
|
{
|
2007-08-16 18:11:55 -06:00
|
|
|
#ifdef MESA
|
|
|
|
if (draw->header.storage) {
|
2007-07-09 16:12:13 -06:00
|
|
|
ALIGN_FREE( draw->header.storage );
|
2007-08-16 18:11:55 -06:00
|
|
|
}
|
2007-07-09 16:12:13 -06:00
|
|
|
|
|
|
|
vf_destroy( draw->vf );
|
2007-08-16 18:11:55 -06:00
|
|
|
#endif
|
2007-07-09 16:12:13 -06:00
|
|
|
|
2007-08-14 17:20:40 -06:00
|
|
|
free( draw->vcache.vertex[0] ); /* Frees all the vertices. */
|
|
|
|
free( draw );
|
2007-07-09 16:12:13 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Rebuild the rendering pipeline.
|
|
|
|
*/
|
|
|
|
static void validate_pipeline( struct draw_context *draw )
|
|
|
|
{
|
2007-07-12 13:32:31 -06:00
|
|
|
struct draw_stage *next = draw->pipeline.setup;
|
2007-07-09 16:12:13 -06:00
|
|
|
|
2007-07-10 13:33:45 -06:00
|
|
|
/*
|
|
|
|
* NOTE: we build up the pipeline in end-to-start order.
|
|
|
|
*
|
|
|
|
* TODO: make the current primitive part of the state and build
|
2007-07-09 16:12:13 -06:00
|
|
|
* shorter pipelines for lines & points.
|
|
|
|
*/
|
2007-07-10 13:33:45 -06:00
|
|
|
|
2007-07-09 16:12:13 -06:00
|
|
|
if (draw->setup.fill_cw != PIPE_POLYGON_MODE_FILL ||
|
|
|
|
draw->setup.fill_ccw != PIPE_POLYGON_MODE_FILL) {
|
|
|
|
draw->pipeline.unfilled->next = next;
|
|
|
|
next = draw->pipeline.unfilled;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (draw->setup.offset_cw ||
|
|
|
|
draw->setup.offset_ccw) {
|
|
|
|
draw->pipeline.offset->next = next;
|
|
|
|
next = draw->pipeline.offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (draw->setup.light_twoside) {
|
|
|
|
draw->pipeline.twoside->next = next;
|
|
|
|
next = draw->pipeline.twoside;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Always run the cull stage as we calculate determinant there
|
|
|
|
* also. Fix this..
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
draw->pipeline.cull->next = next;
|
|
|
|
next = draw->pipeline.cull;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Clip stage
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
draw->pipeline.clip->next = next;
|
|
|
|
next = draw->pipeline.clip;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Do software flatshading prior to clipping. XXX: should only do
|
|
|
|
* this for clipped primitives, ie it is a part of the clip
|
|
|
|
* routine.
|
|
|
|
*/
|
|
|
|
if (draw->setup.flatshade) {
|
|
|
|
draw->pipeline.flatshade->next = next;
|
|
|
|
next = draw->pipeline.flatshade;
|
|
|
|
}
|
|
|
|
|
|
|
|
draw->pipeline.first = next;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register new primitive setup/rendering state.
|
|
|
|
* This causes the drawing pipeline to be rebuilt.
|
|
|
|
*/
|
|
|
|
void draw_set_setup_state( struct draw_context *draw,
|
|
|
|
const struct pipe_setup_state *setup )
|
|
|
|
{
|
2007-08-17 12:40:35 -06:00
|
|
|
draw->setup = *setup; /* struct copy */
|
2007-07-09 16:12:13 -06:00
|
|
|
validate_pipeline( draw );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Plug in the primitive rendering/rasterization stage.
|
|
|
|
* This is provided by the device driver.
|
|
|
|
*/
|
|
|
|
void draw_set_setup_stage( struct draw_context *draw,
|
2007-07-12 13:32:31 -06:00
|
|
|
struct draw_stage *stage )
|
2007-07-09 16:12:13 -06:00
|
|
|
{
|
|
|
|
draw->pipeline.setup = stage;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the draw module's clipping state.
|
|
|
|
*/
|
|
|
|
void draw_set_clip_state( struct draw_context *draw,
|
|
|
|
const struct pipe_clip_state *clip )
|
|
|
|
{
|
|
|
|
memcpy(&draw->plane[6], clip->ucp, clip->nr * sizeof(clip->ucp[0]));
|
|
|
|
draw->nr_planes = 6 + clip->nr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the draw module's viewport state.
|
|
|
|
*/
|
|
|
|
void draw_set_viewport_state( struct draw_context *draw,
|
|
|
|
const struct pipe_viewport_state *viewport )
|
|
|
|
{
|
|
|
|
draw->viewport = *viewport; /* struct copy */
|
|
|
|
|
2007-08-16 18:11:55 -06:00
|
|
|
#ifdef MESA
|
2007-07-09 16:12:13 -06:00
|
|
|
vf_set_vp_scale_translate( draw->vf, viewport->scale, viewport->translate );
|
2007-08-16 18:11:55 -06:00
|
|
|
#endif
|
2007-07-09 16:12:13 -06:00
|
|
|
|
|
|
|
/* Using tnl/ and vf/ modules is temporary while getting started.
|
|
|
|
* Full pipe will have vertex shader, vertex fetch of its own.
|
|
|
|
*/
|
|
|
|
}
|