1946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca/************************************************************************** 2946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca * 3946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. 4946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca * All Rights Reserved. 5946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca * 6946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca * Permission is hereby granted, free of charge, to any person obtaining a 7946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca * copy of this software and associated documentation files (the 8946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca * "Software"), to deal in the Software without restriction, including 9946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca * without limitation the rights to use, copy, modify, merge, publish, 10946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca * distribute, sub license, and/or sell copies of the Software, and to 11946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca * permit persons to whom the Software is furnished to do so, subject to 12946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca * the following conditions: 13946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca * 14946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca * The above copyright notice and this permission notice (including the 15946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca * next paragraph) shall be included in all copies or substantial portions 16946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca * of the Software. 17946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca * 18946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR 22946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca * 26946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca **************************************************************************/ 27946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca 28946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca#include "pipe/p_defines.h" 29946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca#include "util/u_memory.h" 30946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca#include "lp_context.h" 31946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca#include "lp_state.h" 3215a2a588d88ae02e575ff1ef9287c789ebdadeadBrian Paul#include "lp_setup.h" 33946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca#include "draw/draw_context.h" 34946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca 35a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwellstruct lp_rast_state { 36a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwell struct pipe_rasterizer_state lp_state; 37a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwell struct pipe_rasterizer_state draw_state; 38a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwell}; 39a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwell 40a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwell/* State which might be handled in either the draw module or locally. 41a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwell * This function is used to turn that state off in one of the two 42a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwell * places. 43a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwell */ 44a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwellstatic void 45a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwellclear_flags(struct pipe_rasterizer_state *rast) 46a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwell{ 47a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwell rast->light_twoside = 0; 48a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwell rast->offset_tri = 0; 49a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwell} 50a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwell 51946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca 52946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca 538975ade13b7efdea2273e91e05cc6ecbda6ca454Brian Paulstatic void * 54946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonsecallvmpipe_create_rasterizer_state(struct pipe_context *pipe, 55946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca const struct pipe_rasterizer_state *rast) 56946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca{ 57a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwell boolean need_pipeline; 58a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwell 59a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwell /* Partition rasterizer state into what we want the draw module to 60a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwell * handle, and what we'll look after ourselves. 61a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwell */ 62a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwell struct lp_rast_state *state = MALLOC_STRUCT(lp_rast_state); 63a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwell if (state == NULL) 64a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwell return NULL; 65a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwell 66a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwell memcpy(&state->draw_state, rast, sizeof *rast); 67a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwell memcpy(&state->lp_state, rast, sizeof *rast); 68a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwell 69a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwell /* We rely on draw module to do unfilled polyons, AA lines and 70a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwell * points and stipple. 71a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwell * 72a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwell * Over time, reduce this list of conditions, and expand the list 73a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwell * of flags which get cleared in clear_flags(). 74e3a34cc7f6c9f959cdc2af4486e84587fab4d0d7Brian Paul */ 75a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwell need_pipeline = (rast->fill_front != PIPE_POLYGON_MODE_FILL || 76a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwell rast->fill_back != PIPE_POLYGON_MODE_FILL || 77a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwell rast->point_smooth || 78a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwell rast->line_smooth || 79a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwell rast->line_stipple_enable || 80a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwell rast->poly_stipple_enable); 81a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwell 82a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwell /* If not using the pipeline, clear out the flags which we can 83a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwell * handle ourselves. If we *are* using the pipeline, do everything 84a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwell * on the pipeline and clear those flags on our internal copy of 85a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwell * the state. 86a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwell */ 87a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwell if (need_pipeline) 88a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwell clear_flags(&state->lp_state); 89a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwell else 90a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwell clear_flags(&state->draw_state); 91a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwell 92a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwell return state; 93946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca} 94946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca 95e3a34cc7f6c9f959cdc2af4486e84587fab4d0d7Brian Paul 96e3a34cc7f6c9f959cdc2af4486e84587fab4d0d7Brian Paul 978975ade13b7efdea2273e91e05cc6ecbda6ca454Brian Paulstatic void 98e3a34cc7f6c9f959cdc2af4486e84587fab4d0d7Brian Paulllvmpipe_bind_rasterizer_state(struct pipe_context *pipe, void *handle) 99946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca{ 100946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe); 101a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwell const struct lp_rast_state *state = 102a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwell (const struct lp_rast_state *) handle; 103080703e398f737b71336312fd3dc8d6f38f61e51José Fonseca 104a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwell if (state) { 105a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwell llvmpipe->rasterizer = &state->lp_state; 106a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwell draw_set_rasterizer_state(llvmpipe->draw, &state->draw_state, handle); 107946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca 108a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwell /* XXX: just pass lp_state directly to setup. 109a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwell */ 11015a2a588d88ae02e575ff1ef9287c789ebdadeadBrian Paul lp_setup_set_triangle_state( llvmpipe->setup, 111a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwell state->lp_state.cull_face, 112a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwell state->lp_state.front_ccw, 113a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwell state->lp_state.scissor, 114a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwell state->lp_state.gl_rasterization_rules); 11530a1c36dc85f0928a9adb69630c418f9aabbdd98José Fonseca lp_setup_set_flatshade_first( llvmpipe->setup, 116a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwell state->lp_state.flatshade_first); 1175286dd701640976ffc328e8e85fb3830746851a1Hui Qi Tay lp_setup_set_line_state( llvmpipe->setup, 118a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwell state->lp_state.line_width); 11957d84d9ca4a645ca326b66ff3b82bee0db18ac97Hui Qi Tay lp_setup_set_point_state( llvmpipe->setup, 120a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwell state->lp_state.point_size, 121a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwell state->lp_state.point_size_per_vertex, 122a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwell state->lp_state.sprite_coord_enable, 123a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwell state->lp_state.sprite_coord_mode); 124a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwell } 125a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwell else { 126a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwell llvmpipe->rasterizer = NULL; 127a1ca5ac7c27c8bc3e294b50ab9ad340095f3030dKeith Whitwell draw_set_rasterizer_state(llvmpipe->draw, NULL, handle); 128ebba92875aca586b661f6547888a2ed95e70e0ffBrian Paul } 12915a2a588d88ae02e575ff1ef9287c789ebdadeadBrian Paul 130c9a5930fe45a0a0299769bd2b672ca516d1bf39eJosé Fonseca llvmpipe->dirty |= LP_NEW_RASTERIZER; 131946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca} 132946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca 133e3a34cc7f6c9f959cdc2af4486e84587fab4d0d7Brian Paul 1348975ade13b7efdea2273e91e05cc6ecbda6ca454Brian Paulstatic void 1358975ade13b7efdea2273e91e05cc6ecbda6ca454Brian Paulllvmpipe_delete_rasterizer_state(struct pipe_context *pipe, 1368975ade13b7efdea2273e91e05cc6ecbda6ca454Brian Paul void *rasterizer) 137946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca{ 138946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca FREE( rasterizer ); 139946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca} 140946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca 141946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca 1428975ade13b7efdea2273e91e05cc6ecbda6ca454Brian Paul 1438975ade13b7efdea2273e91e05cc6ecbda6ca454Brian Paulvoid 1448975ade13b7efdea2273e91e05cc6ecbda6ca454Brian Paulllvmpipe_init_rasterizer_funcs(struct llvmpipe_context *llvmpipe) 1458975ade13b7efdea2273e91e05cc6ecbda6ca454Brian Paul{ 1468975ade13b7efdea2273e91e05cc6ecbda6ca454Brian Paul llvmpipe->pipe.create_rasterizer_state = llvmpipe_create_rasterizer_state; 1478975ade13b7efdea2273e91e05cc6ecbda6ca454Brian Paul llvmpipe->pipe.bind_rasterizer_state = llvmpipe_bind_rasterizer_state; 1488975ade13b7efdea2273e91e05cc6ecbda6ca454Brian Paul llvmpipe->pipe.delete_rasterizer_state = llvmpipe_delete_rasterizer_state; 1498975ade13b7efdea2273e91e05cc6ecbda6ca454Brian Paul} 150