st_atom_viewport.c

Go to the documentation of this file.
00001 /**************************************************************************
00002  * 
00003  * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
00004  * All Rights Reserved.
00005  * 
00006  * Permission is hereby granted, free of charge, to any person obtaining a
00007  * copy of this software and associated documentation files (the
00008  * "Software"), to deal in the Software without restriction, including
00009  * without limitation the rights to use, copy, modify, merge, publish,
00010  * distribute, sub license, and/or sell copies of the Software, and to
00011  * permit persons to whom the Software is furnished to do so, subject to
00012  * the following conditions:
00013  * 
00014  * The above copyright notice and this permission notice (including the
00015  * next paragraph) shall be included in all copies or substantial portions
00016  * of the Software.
00017  * 
00018  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00019  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00020  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
00021  * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
00022  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
00023  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
00024  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00025  * 
00026  **************************************************************************/
00027 
00028 
00029 #include "main/context.h"
00030 #include "main/colormac.h"
00031 #include "st_context.h"
00032 #include "st_atom.h"
00033 #include "pipe/p_context.h"
00034 #include "cso_cache/cso_context.h"
00035 
00042 static void
00043 update_viewport( struct st_context *st )
00044 {
00045    GLcontext *ctx = st->ctx;
00046    GLfloat yScale, yBias;
00047 
00048    /* _NEW_BUFFERS
00049     */
00050    if (st_fb_orientation(ctx->DrawBuffer) == Y_0_TOP) {
00051       yScale = -1;
00052       yBias = (GLfloat)ctx->DrawBuffer->Height;
00053    }
00054    else {
00055       yScale = 1.0;
00056       yBias = 0.0;
00057    }
00058 
00059    /* _NEW_VIEWPORT 
00060     */
00061    {
00062       GLfloat x = (GLfloat)ctx->Viewport.X;
00063       GLfloat y = (GLfloat)ctx->Viewport.Y;
00064       GLfloat z = ctx->Viewport.Near;
00065       GLfloat half_width = (GLfloat)ctx->Viewport.Width / 2.0f;
00066       GLfloat half_height = (GLfloat)ctx->Viewport.Height / 2.0f;
00067       GLfloat half_depth = (GLfloat)(ctx->Viewport.Far - ctx->Viewport.Near) / 2.0f;
00068       
00069       st->state.viewport.scale[0] = half_width;
00070       st->state.viewport.scale[1] = half_height * yScale;
00071       st->state.viewport.scale[2] = half_depth;
00072       st->state.viewport.scale[3] = 1.0;
00073 
00074       st->state.viewport.translate[0] = half_width + x;
00075       st->state.viewport.translate[1] = (half_height + y) * yScale + yBias;
00076       st->state.viewport.translate[2] = half_depth + z;
00077       st->state.viewport.translate[3] = 0.0;
00078 
00079       cso_set_viewport(st->cso_context, &st->state.viewport);
00080    }
00081 }
00082 
00083 
00084 const struct st_tracked_state st_update_viewport = {
00085    "st_update_viewport",                                /* name */
00086    {                                                    /* dirty */
00087       _NEW_BUFFERS | _NEW_VIEWPORT,                     /* mesa */
00088       0,                                                /* st */
00089    },
00090    update_viewport                                      /* update */
00091 };

Generated on Tue Sep 29 06:25:18 2009 for Gallium3D by  doxygen 1.5.4