ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

ss_context.c
Go to the documentation of this file.
00001 /*
00002  * Mesa 3-D graphics library
00003  * Version:  7.1
00004  *
00005  * Copyright (C) 1999-2007  Brian Paul   All Rights Reserved.
00006  *
00007  * Permission is hereby granted, free of charge, to any person obtaining a
00008  * copy of this software and associated documentation files (the "Software"),
00009  * to deal in the Software without restriction, including without limitation
00010  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
00011  * and/or sell copies of the Software, and to permit persons to whom the
00012  * Software is furnished to do so, subject to the following conditions:
00013  *
00014  * The above copyright notice and this permission notice shall be included
00015  * in all copies or substantial portions of the Software.
00016  *
00017  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00018  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00019  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
00020  * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
00021  * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00022  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00023  *
00024  * Authors:
00025  *    Keith Whitwell <keith@tungstengraphics.com>
00026  */
00027 
00028 #include "main/glheader.h"
00029 #include "main/imports.h"
00030 #include "main/colormac.h"
00031 #include "tnl/tnl.h"
00032 #include "tnl/t_context.h"
00033 #include "tnl/t_pipeline.h"
00034 #include "tnl/t_vertex.h"
00035 #include "swrast_setup.h"
00036 #include "ss_context.h"
00037 #include "ss_triangle.h"
00038 
00039 
00040 /* Need to check lighting state and vertex program state to know
00041  * if two-sided lighting is in effect.
00042  */
00043 #define _SWSETUP_NEW_RENDERINDEX (_NEW_POLYGON|_NEW_LIGHT|_NEW_PROGRAM)
00044 
00045 
00046 #define VARYING_EMIT_STYLE  EMIT_4F
00047 
00048 
00049 GLboolean
00050 _swsetup_CreateContext( GLcontext *ctx )
00051 {
00052    SScontext *swsetup = (SScontext *)CALLOC(sizeof(SScontext));
00053 
00054    if (!swsetup)
00055       return GL_FALSE;
00056 
00057    ctx->swsetup_context = swsetup;
00058 
00059    swsetup->NewState = ~0;
00060    _swsetup_trifuncs_init( ctx );
00061 
00062    _tnl_init_vertices( ctx, ctx->Const.MaxArrayLockSize + 12, 
00063                sizeof(SWvertex) );
00064 
00065 
00066    return GL_TRUE;
00067 }
00068 
00069 void
00070 _swsetup_DestroyContext( GLcontext *ctx )
00071 {
00072    SScontext *swsetup = SWSETUP_CONTEXT(ctx);
00073 
00074    if (swsetup) {
00075       FREE(swsetup);
00076       ctx->swsetup_context = 0;
00077    }
00078 
00079    _tnl_free_vertices( ctx );
00080 }
00081 
00082 static void
00083 _swsetup_RenderPrimitive( GLcontext *ctx, GLenum mode )
00084 {
00085    SWSETUP_CONTEXT(ctx)->render_prim = mode;
00086    _swrast_render_primitive( ctx, mode );
00087 }
00088 
00089 
00093 #define SWZ ((SWvertex *)0)
00094 #define SWOffset(MEMBER) (((char *)&(SWZ->MEMBER)) - ((char *)SWZ))
00095 
00096 #define EMIT_ATTR( ATTR, STYLE, MEMBER )    \
00097 do {                        \
00098    map[e].attrib = (ATTR);          \
00099    map[e].format = (STYLE);         \
00100    map[e].offset = SWOffset(MEMBER);            \
00101    e++;                     \
00102 } while (0)
00103 
00104 
00110 static void
00111 setup_vertex_format(GLcontext *ctx)
00112 {
00113    TNLcontext *tnl = TNL_CONTEXT(ctx);
00114    SScontext *swsetup = SWSETUP_CONTEXT(ctx);
00115    GLboolean intColors = !ctx->FragmentProgram._Current
00116                       && !ctx->ATIFragmentShader._Enabled
00117                       && ctx->RenderMode == GL_RENDER
00118                       && CHAN_TYPE == GL_UNSIGNED_BYTE;
00119 
00120    if (intColors != swsetup->intColors ||
00121        !RENDERINPUTS_EQUAL(tnl->render_inputs_bitset,
00122                            swsetup->last_index_bitset)) {
00123       DECLARE_RENDERINPUTS(index_bitset);
00124       struct tnl_attr_map map[_TNL_ATTRIB_MAX];
00125       int i, e = 0;
00126 
00127       swsetup->intColors = intColors;
00128 
00129       RENDERINPUTS_COPY( index_bitset, tnl->render_inputs_bitset );
00130 
00131       EMIT_ATTR( _TNL_ATTRIB_POS, EMIT_4F_VIEWPORT, attrib[FRAG_ATTRIB_WPOS] );
00132 
00133       if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_COLOR0 )) {
00134          if (swsetup->intColors)
00135             EMIT_ATTR( _TNL_ATTRIB_COLOR0, EMIT_4CHAN_4F_RGBA, color );
00136          else
00137             EMIT_ATTR( _TNL_ATTRIB_COLOR0, EMIT_4F, attrib[FRAG_ATTRIB_COL0]);
00138       }
00139 
00140       if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_COLOR1 )) {
00141          EMIT_ATTR( _TNL_ATTRIB_COLOR1, EMIT_4F, attrib[FRAG_ATTRIB_COL1]);
00142       }
00143 
00144       if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_COLOR_INDEX )) {
00145          EMIT_ATTR( _TNL_ATTRIB_COLOR_INDEX, EMIT_1F,
00146                     attrib[FRAG_ATTRIB_CI][0] );
00147       }
00148 
00149       if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_FOG )) {
00150          const GLint emit = ctx->FragmentProgram._Current ? EMIT_4F : EMIT_1F;
00151          EMIT_ATTR( _TNL_ATTRIB_FOG, emit, attrib[FRAG_ATTRIB_FOGC]);
00152       }
00153 
00154       if (RENDERINPUTS_TEST_RANGE(index_bitset, _TNL_FIRST_TEX, _TNL_LAST_TEX))
00155       {
00156          for (i = 0; i < MAX_TEXTURE_COORD_UNITS; i++) {
00157             if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_TEX(i) )) {
00158                EMIT_ATTR( _TNL_ATTRIB_TEX(i), EMIT_4F,
00159                           attrib[FRAG_ATTRIB_TEX0 + i] );
00160             }
00161          }
00162       }
00163 
00164       /* shader varying vars */
00165       if (RENDERINPUTS_TEST_RANGE( index_bitset,
00166                                    _TNL_FIRST_GENERIC, _TNL_LAST_GENERIC )) {
00167          for (i = 0; i < ctx->Const.MaxVarying; i++) {
00168             if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_GENERIC(i) )) {
00169                EMIT_ATTR( _TNL_ATTRIB_GENERIC(i), VARYING_EMIT_STYLE,
00170                           attrib[FRAG_ATTRIB_VAR0 + i] );
00171             }
00172          }
00173       }
00174 
00175       if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_POINTSIZE ))
00176          EMIT_ATTR( _TNL_ATTRIB_POINTSIZE, EMIT_1F, pointSize );
00177 
00178       _tnl_install_attrs( ctx, map, e,
00179                           ctx->Viewport._WindowMap.m,
00180                           sizeof(SWvertex) );
00181 
00182       RENDERINPUTS_COPY( swsetup->last_index_bitset, index_bitset );
00183    }
00184 }
00185 
00186 
00191 static void
00192 _swsetup_RenderStart( GLcontext *ctx )
00193 {
00194    SScontext *swsetup = SWSETUP_CONTEXT(ctx);
00195    TNLcontext *tnl = TNL_CONTEXT(ctx);
00196    struct vertex_buffer *VB = &tnl->vb;
00197 
00198    if (swsetup->NewState & _SWSETUP_NEW_RENDERINDEX) {
00199       _swsetup_choose_trifuncs(ctx);
00200    }
00201 
00202    if (swsetup->NewState & _NEW_PROGRAM) {
00203       RENDERINPUTS_ZERO( swsetup->last_index_bitset );
00204    }
00205 
00206    swsetup->NewState = 0;
00207 
00208    /* This will change if drawing unfilled tris */
00209    _swrast_SetFacing(ctx, 0);
00210 
00211    _swrast_render_start(ctx);
00212 
00213    /* Important */
00214    VB->AttribPtr[VERT_ATTRIB_POS] = VB->NdcPtr;
00215 
00216    setup_vertex_format(ctx);
00217 }
00218 
00219 
00220 /*
00221  * We patch this function into tnl->Driver.Render.Finish.
00222  * It's called when we finish rendering a vertex buffer.
00223  */
00224 static void
00225 _swsetup_RenderFinish( GLcontext *ctx )
00226 {
00227    _swrast_render_finish( ctx );
00228 }
00229 
00230 void
00231 _swsetup_InvalidateState( GLcontext *ctx, GLuint new_state )
00232 {
00233    SScontext *swsetup = SWSETUP_CONTEXT(ctx);
00234    swsetup->NewState |= new_state;
00235    _tnl_invalidate_vertex_state( ctx, new_state );
00236 }
00237 
00238 
00239 void
00240 _swsetup_Wakeup( GLcontext *ctx )
00241 {
00242    TNLcontext *tnl = TNL_CONTEXT(ctx);
00243    SScontext *swsetup = SWSETUP_CONTEXT(ctx);
00244 
00245    tnl->Driver.Render.Start = _swsetup_RenderStart;
00246    tnl->Driver.Render.Finish = _swsetup_RenderFinish;
00247    tnl->Driver.Render.PrimitiveNotify = _swsetup_RenderPrimitive;
00248    tnl->Driver.Render.Interp = _tnl_interp;
00249    tnl->Driver.Render.CopyPV = _tnl_copy_pv;
00250    tnl->Driver.Render.ClippedPolygon = _tnl_RenderClippedPolygon; /* new */
00251    tnl->Driver.Render.ClippedLine = _tnl_RenderClippedLine; /* new */
00252    /* points */
00253    /* line */
00254    /* triangle */
00255    /* quad */
00256    tnl->Driver.Render.PrimTabVerts = _tnl_render_tab_verts;
00257    tnl->Driver.Render.PrimTabElts = _tnl_render_tab_elts;
00258    tnl->Driver.Render.ResetLineStipple = _swrast_ResetLineStipple;
00259    tnl->Driver.Render.BuildVertices = _tnl_build_vertices;
00260    tnl->Driver.Render.Multipass = 0;
00261 
00262    _tnl_invalidate_vertices( ctx, ~0 );
00263    _tnl_need_projected_coords( ctx, GL_TRUE );
00264    _swsetup_InvalidateState( ctx, ~0 );
00265 
00266    swsetup->verts = (SWvertex *)tnl->clipspace.vertex_buf;
00267    RENDERINPUTS_ZERO( swsetup->last_index_bitset );
00268 }
00269 
00270 
00274 void 
00275 _swsetup_Translate( GLcontext *ctx, const void *vertex, SWvertex *dest )
00276 {
00277    const GLfloat *m = ctx->Viewport._WindowMap.m;
00278    GLfloat tmp[4];
00279    GLuint i;
00280 
00281    _tnl_get_attr( ctx, vertex, _TNL_ATTRIB_POS, tmp );
00282 
00283    dest->attrib[FRAG_ATTRIB_WPOS][0] = m[0]  * tmp[0] + m[12];
00284    dest->attrib[FRAG_ATTRIB_WPOS][1] = m[5]  * tmp[1] + m[13];
00285    dest->attrib[FRAG_ATTRIB_WPOS][2] = m[10] * tmp[2] + m[14];
00286    dest->attrib[FRAG_ATTRIB_WPOS][3] =         tmp[3];
00287 
00289    for (i = 0 ; i < ctx->Const.MaxTextureCoordUnits ; i++)
00290       _tnl_get_attr( ctx, vertex, _TNL_ATTRIB_TEX0 + i,
00291                      dest->attrib[FRAG_ATTRIB_TEX0 + i] );
00292 
00293    for (i = 0 ; i < ctx->Const.MaxVarying ; i++)
00294       _tnl_get_attr( ctx, vertex, _TNL_ATTRIB_GENERIC0 + i,
00295                      dest->attrib[FRAG_ATTRIB_VAR0 + i] );
00296 
00297    if (ctx->Visual.rgbMode) {
00298       _tnl_get_attr( ctx, vertex, _TNL_ATTRIB_COLOR0,
00299                      dest->attrib[FRAG_ATTRIB_COL0] );
00300       UNCLAMPED_FLOAT_TO_RGBA_CHAN( dest->color, tmp );
00301 
00302       _tnl_get_attr( ctx, vertex, _TNL_ATTRIB_COLOR1,
00303                      dest->attrib[FRAG_ATTRIB_COL1]);
00304    }
00305    else {
00306       _tnl_get_attr( ctx, vertex, _TNL_ATTRIB_COLOR_INDEX, tmp );
00307       dest->attrib[FRAG_ATTRIB_CI][0] = tmp[0];
00308    }
00309 
00310    _tnl_get_attr( ctx, vertex, _TNL_ATTRIB_FOG, tmp );
00311    dest->attrib[FRAG_ATTRIB_FOGC][0] = tmp[0];
00312 
00313    /* XXX See _tnl_get_attr about pointsize ... */
00314    _tnl_get_attr( ctx, vertex, _TNL_ATTRIB_POINTSIZE, tmp );
00315    dest->pointSize = tmp[0];
00316 }
00317 

Generated on Sat May 26 2012 04:19:35 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.