1e89bd0fbc56ecfb96f3aff926c5891c45221dd37Brian/************************************************************************** 2e89bd0fbc56ecfb96f3aff926c5891c45221dd37Brian * 3e89bd0fbc56ecfb96f3aff926c5891c45221dd37Brian * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. 4e89bd0fbc56ecfb96f3aff926c5891c45221dd37Brian * All Rights Reserved. 5e89bd0fbc56ecfb96f3aff926c5891c45221dd37Brian * 6e89bd0fbc56ecfb96f3aff926c5891c45221dd37Brian * Permission is hereby granted, free of charge, to any person obtaining a 7e89bd0fbc56ecfb96f3aff926c5891c45221dd37Brian * copy of this software and associated documentation files (the 8e89bd0fbc56ecfb96f3aff926c5891c45221dd37Brian * "Software"), to deal in the Software without restriction, including 9e89bd0fbc56ecfb96f3aff926c5891c45221dd37Brian * without limitation the rights to use, copy, modify, merge, publish, 10e89bd0fbc56ecfb96f3aff926c5891c45221dd37Brian * distribute, sub license, and/or sell copies of the Software, and to 11e89bd0fbc56ecfb96f3aff926c5891c45221dd37Brian * permit persons to whom the Software is furnished to do so, subject to 12e89bd0fbc56ecfb96f3aff926c5891c45221dd37Brian * the following conditions: 13e89bd0fbc56ecfb96f3aff926c5891c45221dd37Brian * 14e89bd0fbc56ecfb96f3aff926c5891c45221dd37Brian * The above copyright notice and this permission notice (including the 15e89bd0fbc56ecfb96f3aff926c5891c45221dd37Brian * next paragraph) shall be included in all copies or substantial portions 16e89bd0fbc56ecfb96f3aff926c5891c45221dd37Brian * of the Software. 17e89bd0fbc56ecfb96f3aff926c5891c45221dd37Brian * 18e89bd0fbc56ecfb96f3aff926c5891c45221dd37Brian * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19e89bd0fbc56ecfb96f3aff926c5891c45221dd37Brian * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20e89bd0fbc56ecfb96f3aff926c5891c45221dd37Brian * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21e89bd0fbc56ecfb96f3aff926c5891c45221dd37Brian * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR 22e89bd0fbc56ecfb96f3aff926c5891c45221dd37Brian * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23e89bd0fbc56ecfb96f3aff926c5891c45221dd37Brian * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24e89bd0fbc56ecfb96f3aff926c5891c45221dd37Brian * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25e89bd0fbc56ecfb96f3aff926c5891c45221dd37Brian * 26e89bd0fbc56ecfb96f3aff926c5891c45221dd37Brian **************************************************************************/ 27e89bd0fbc56ecfb96f3aff926c5891c45221dd37Brian 28e89bd0fbc56ecfb96f3aff926c5891c45221dd37Brian /* 29e89bd0fbc56ecfb96f3aff926c5891c45221dd37Brian * \brief polygon stipple state 30e89bd0fbc56ecfb96f3aff926c5891c45221dd37Brian * 31e89bd0fbc56ecfb96f3aff926c5891c45221dd37Brian * Authors: 32e89bd0fbc56ecfb96f3aff926c5891c45221dd37Brian * Brian Paul 33e89bd0fbc56ecfb96f3aff926c5891c45221dd37Brian */ 34e89bd0fbc56ecfb96f3aff926c5891c45221dd37Brian 35e89bd0fbc56ecfb96f3aff926c5891c45221dd37Brian 369846b0627149e221c9fbd7c3379e33fb68e68511Vinson Lee#include <assert.h> 379846b0627149e221c9fbd7c3379e33fb68e68511Vinson Lee 38e89bd0fbc56ecfb96f3aff926c5891c45221dd37Brian#include "st_context.h" 39e89bd0fbc56ecfb96f3aff926c5891c45221dd37Brian#include "st_atom.h" 40e89bd0fbc56ecfb96f3aff926c5891c45221dd37Brian#include "pipe/p_context.h" 41e89bd0fbc56ecfb96f3aff926c5891c45221dd37Brian#include "pipe/p_defines.h" 42e89bd0fbc56ecfb96f3aff926c5891c45221dd37Brian 43e89bd0fbc56ecfb96f3aff926c5891c45221dd37Brian 44401cbd0d2365e5b2d371a2a01edf1cecca4a99ddBrian Paul/** 45401cbd0d2365e5b2d371a2a01edf1cecca4a99ddBrian Paul * OpenGL's polygon stipple is indexed with window coordinates in which 46401cbd0d2365e5b2d371a2a01edf1cecca4a99ddBrian Paul * the origin (0,0) is the lower-left corner of the window. 47401cbd0d2365e5b2d371a2a01edf1cecca4a99ddBrian Paul * With Gallium, the origin is the upper-left corner of the window. 48401cbd0d2365e5b2d371a2a01edf1cecca4a99ddBrian Paul * To convert GL's polygon stipple to what gallium expects we need to 49401cbd0d2365e5b2d371a2a01edf1cecca4a99ddBrian Paul * invert the pattern vertically and rotate the stipple rows according 50401cbd0d2365e5b2d371a2a01edf1cecca4a99ddBrian Paul * to the window height. 51401cbd0d2365e5b2d371a2a01edf1cecca4a99ddBrian Paul */ 52401cbd0d2365e5b2d371a2a01edf1cecca4a99ddBrian Paulstatic void 53401cbd0d2365e5b2d371a2a01edf1cecca4a99ddBrian Paulinvert_stipple(GLuint dest[32], const GLuint src[32], GLuint winHeight) 54401cbd0d2365e5b2d371a2a01edf1cecca4a99ddBrian Paul{ 55401cbd0d2365e5b2d371a2a01edf1cecca4a99ddBrian Paul GLuint i; 56401cbd0d2365e5b2d371a2a01edf1cecca4a99ddBrian Paul 57401cbd0d2365e5b2d371a2a01edf1cecca4a99ddBrian Paul for (i = 0; i < 32; i++) { 58401cbd0d2365e5b2d371a2a01edf1cecca4a99ddBrian Paul dest[i] = src[(winHeight - 1 - i) & 0x1f]; 59401cbd0d2365e5b2d371a2a01edf1cecca4a99ddBrian Paul } 60401cbd0d2365e5b2d371a2a01edf1cecca4a99ddBrian Paul} 61401cbd0d2365e5b2d371a2a01edf1cecca4a99ddBrian Paul 62401cbd0d2365e5b2d371a2a01edf1cecca4a99ddBrian Paul 63401cbd0d2365e5b2d371a2a01edf1cecca4a99ddBrian Paul 64e89bd0fbc56ecfb96f3aff926c5891c45221dd37Brianstatic void 65e89bd0fbc56ecfb96f3aff926c5891c45221dd37Brianupdate_stipple( struct st_context *st ) 66e89bd0fbc56ecfb96f3aff926c5891c45221dd37Brian{ 6799feecc7d1d0a6efb2511859973d6029d9fed9fdBrian Paul const struct gl_context *ctx = st->ctx; 68401cbd0d2365e5b2d371a2a01edf1cecca4a99ddBrian Paul const GLuint sz = sizeof(st->state.poly_stipple); 6999feecc7d1d0a6efb2511859973d6029d9fed9fdBrian Paul assert(sz == sizeof(ctx->PolygonStipple)); 70e89bd0fbc56ecfb96f3aff926c5891c45221dd37Brian 7199feecc7d1d0a6efb2511859973d6029d9fed9fdBrian Paul if (memcmp(st->state.poly_stipple, ctx->PolygonStipple, sz)) { 72e89bd0fbc56ecfb96f3aff926c5891c45221dd37Brian /* state has changed */ 73401cbd0d2365e5b2d371a2a01edf1cecca4a99ddBrian Paul struct pipe_poly_stipple newStipple; 74401cbd0d2365e5b2d371a2a01edf1cecca4a99ddBrian Paul 7599feecc7d1d0a6efb2511859973d6029d9fed9fdBrian Paul memcpy(st->state.poly_stipple, ctx->PolygonStipple, sz); 76401cbd0d2365e5b2d371a2a01edf1cecca4a99ddBrian Paul 7799feecc7d1d0a6efb2511859973d6029d9fed9fdBrian Paul invert_stipple(newStipple.stipple, ctx->PolygonStipple, 7899feecc7d1d0a6efb2511859973d6029d9fed9fdBrian Paul ctx->DrawBuffer->Height); 79401cbd0d2365e5b2d371a2a01edf1cecca4a99ddBrian Paul 80401cbd0d2365e5b2d371a2a01edf1cecca4a99ddBrian Paul st->pipe->set_polygon_stipple(st->pipe, &newStipple); 81e89bd0fbc56ecfb96f3aff926c5891c45221dd37Brian } 82e89bd0fbc56ecfb96f3aff926c5891c45221dd37Brian} 83e89bd0fbc56ecfb96f3aff926c5891c45221dd37Brian 84e89bd0fbc56ecfb96f3aff926c5891c45221dd37Brian 85401cbd0d2365e5b2d371a2a01edf1cecca4a99ddBrian Paul/** Update the stipple when the pattern or window height changes */ 86e89bd0fbc56ecfb96f3aff926c5891c45221dd37Brianconst struct st_tracked_state st_update_polygon_stipple = { 8754507125e735ffa595e252282eaabf38095c21e1Alan Hourihane "st_update_polygon_stipple", /* name */ 8854507125e735ffa595e252282eaabf38095c21e1Alan Hourihane { /* dirty */ 89401cbd0d2365e5b2d371a2a01edf1cecca4a99ddBrian Paul (_NEW_POLYGONSTIPPLE | 90401cbd0d2365e5b2d371a2a01edf1cecca4a99ddBrian Paul _NEW_BUFFERS), /* mesa */ 9154507125e735ffa595e252282eaabf38095c21e1Alan Hourihane 0, /* st */ 92e89bd0fbc56ecfb96f3aff926c5891c45221dd37Brian }, 9354507125e735ffa595e252282eaabf38095c21e1Alan Hourihane update_stipple /* update */ 94e89bd0fbc56ecfb96f3aff926c5891c45221dd37Brian}; 95