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

vbo_context.c
Go to the documentation of this file.
00001 /*
00002  * Mesa 3-D graphics library
00003  * Version:  6.3
00004  *
00005  * Copyright (C) 1999-2005  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/imports.h"
00029 #include "main/mtypes.h"
00030 #include "main/api_arrayelt.h"
00031 #include "vbo.h"
00032 #include "vbo_context.h"
00033 
00034 /* Reach out and grab this to use as the default:
00035  */
00036 extern void _tnl_draw_prims( GLcontext *ctx,
00037                  const struct gl_client_array *arrays[],
00038                  const struct _mesa_prim *prims,
00039                  GLuint nr_prims,
00040                  const struct _mesa_index_buffer *ib,
00041                  GLuint min_index,
00042                  GLuint max_index );
00043 
00044 
00045 
00046 #define NR_LEGACY_ATTRIBS 16
00047 #define NR_GENERIC_ATTRIBS 16
00048 #define NR_MAT_ATTRIBS 12
00049 
00050 static GLuint check_size( const GLfloat *attr )
00051 {
00052    if (attr[3] != 1.0) return 4;
00053    if (attr[2] != 0.0) return 3;
00054    if (attr[1] != 0.0) return 2;
00055    return 1;        
00056 }
00057 
00058 static void init_legacy_currval(GLcontext *ctx)
00059 {
00060    struct vbo_context *vbo = vbo_context(ctx);
00061    struct gl_client_array *arrays = vbo->legacy_currval;
00062    GLuint i;
00063 
00064    memset(arrays, 0, sizeof(*arrays) * NR_LEGACY_ATTRIBS);
00065 
00066    /* Set up a constant (StrideB == 0) array for each current
00067     * attribute:
00068     */
00069    for (i = 0; i < NR_LEGACY_ATTRIBS; i++) {
00070       struct gl_client_array *cl = &arrays[i];
00071 
00072       /* Size will have to be determined at runtime:
00073        */
00074       cl->Size = check_size(ctx->Current.Attrib[i]);
00075       cl->Stride = 0;
00076       cl->StrideB = 0;
00077       cl->Enabled = 1;
00078       cl->Type = GL_FLOAT;
00079       cl->Ptr = (const void *)ctx->Current.Attrib[i];
00080       cl->BufferObj = ctx->Array.NullBufferObj;
00081    }
00082 }
00083 
00084 
00085 static void init_generic_currval(GLcontext *ctx)
00086 {
00087    struct vbo_context *vbo = vbo_context(ctx);
00088    struct gl_client_array *arrays = vbo->generic_currval;
00089    GLuint i;
00090 
00091    memset(arrays, 0, sizeof(*arrays) * NR_GENERIC_ATTRIBS);
00092 
00093    for (i = 0; i < NR_GENERIC_ATTRIBS; i++) {
00094       struct gl_client_array *cl = &arrays[i];
00095 
00096       /* This will have to be determined at runtime:
00097        */
00098       cl->Size = 1;
00099       cl->Type = GL_FLOAT;
00100       cl->Ptr = (const void *)ctx->Current.Attrib[VERT_ATTRIB_GENERIC0 + i];
00101       cl->Stride = 0;
00102       cl->StrideB = 0;
00103       cl->Enabled = 1;
00104       cl->BufferObj = ctx->Array.NullBufferObj;
00105    }
00106 }
00107 
00108 
00109 static void init_mat_currval(GLcontext *ctx)
00110 {
00111    struct vbo_context *vbo = vbo_context(ctx);
00112    struct gl_client_array *arrays = vbo->mat_currval;
00113    GLuint i;
00114 
00115    ASSERT(NR_MAT_ATTRIBS == MAT_ATTRIB_MAX);
00116 
00117    memset(arrays, 0, sizeof(*arrays) * NR_MAT_ATTRIBS);
00118 
00119    /* Set up a constant (StrideB == 0) array for each current
00120     * attribute:
00121     */
00122    for (i = 0; i < NR_MAT_ATTRIBS; i++) {
00123       struct gl_client_array *cl = &arrays[i];
00124 
00125       /* Size is fixed for the material attributes, for others will
00126        * be determined at runtime:
00127        */
00128       switch (i - VERT_ATTRIB_GENERIC0) {
00129       case MAT_ATTRIB_FRONT_SHININESS:
00130       case MAT_ATTRIB_BACK_SHININESS:
00131      cl->Size = 1;
00132      break;
00133       case MAT_ATTRIB_FRONT_INDEXES:
00134       case MAT_ATTRIB_BACK_INDEXES:
00135      cl->Size = 3;
00136      break;
00137       default:
00138      cl->Size = 4;
00139      break;
00140       }
00141 
00142       cl->Ptr = (const void *)ctx->Light.Material.Attrib[i];
00143       cl->Type = GL_FLOAT;
00144       cl->Stride = 0;
00145       cl->StrideB = 0;
00146       cl->Enabled = 1;
00147       cl->BufferObj = ctx->Array.NullBufferObj;
00148    }
00149 }
00150 
00151 #if 0
00152 
00153 static void vbo_exec_current_init( struct vbo_exec_context *exec ) 
00154 {
00155    GLcontext *ctx = exec->ctx;
00156    GLint i;
00157 
00158    /* setup the pointers for the typical 16 vertex attributes */
00159    for (i = 0; i < VBO_ATTRIB_FIRST_MATERIAL; i++) 
00160       exec->vtx.current[i] = ctx->Current.Attrib[i];
00161 
00162    /* setup pointers for the 12 material attributes */
00163    for (i = 0; i < MAT_ATTRIB_MAX; i++)
00164       exec->vtx.current[VBO_ATTRIB_FIRST_MATERIAL + i] = 
00165      ctx->Light.Material.Attrib[i];
00166 }
00167 #endif
00168 
00169 GLboolean _vbo_CreateContext( GLcontext *ctx )
00170 {
00171    struct vbo_context *vbo = CALLOC_STRUCT(vbo_context);
00172 
00173    ctx->swtnl_im = (void *)vbo;
00174 
00175    /* Initialize the arrayelt helper
00176     */
00177    if (!ctx->aelt_context &&
00178        !_ae_create_context( ctx )) {
00179       return GL_FALSE;
00180    }
00181 
00182    /* TODO: remove these pointers.
00183     */
00184    vbo->legacy_currval = &vbo->currval[VBO_ATTRIB_POS];
00185    vbo->generic_currval = &vbo->currval[VBO_ATTRIB_GENERIC0];
00186    vbo->mat_currval = &vbo->currval[VBO_ATTRIB_MAT_FRONT_AMBIENT];
00187 
00188    init_legacy_currval( ctx );
00189    init_generic_currval( ctx );
00190    init_mat_currval( ctx );
00191 
00192    /* Build mappings from VERT_ATTRIB -> VBO_ATTRIB depending on type
00193     * of vertex program active.
00194     */
00195    {
00196       GLuint i;
00197 
00198       /* When no vertex program, pull in the material attributes in
00199        * the 16..32 generic range.
00200        */
00201       for (i = 0; i < 16; i++) 
00202      vbo->map_vp_none[i] = i;
00203       for (i = 0; i < 12; i++) 
00204      vbo->map_vp_none[16+i] = VBO_ATTRIB_MAT_FRONT_AMBIENT + i;
00205       for (i = 0; i < 4; i++)
00206      vbo->map_vp_none[28+i] = i;    
00207       
00208       for (i = 0; i < VERT_ATTRIB_MAX; i++)
00209      vbo->map_vp_arb[i] = i;
00210    }
00211 
00212 
00213    /* By default: 
00214     */
00215    vbo->draw_prims = _tnl_draw_prims;
00216 
00217    /* Hook our functions into exec and compile dispatch tables.  These
00218     * will pretty much be permanently installed, which means that the
00219     * vtxfmt mechanism can be removed now.
00220     */
00221    vbo_exec_init( ctx );
00222 #if FEATURE_dlist
00223    vbo_save_init( ctx );
00224 #endif
00225 
00226    return GL_TRUE;
00227 }
00228 
00229 void _vbo_InvalidateState( GLcontext *ctx, GLuint new_state )
00230 {
00231    _ae_invalidate_state(ctx, new_state);
00232    vbo_exec_invalidate_state(ctx, new_state);
00233 }
00234 
00235 
00236 void _vbo_DestroyContext( GLcontext *ctx )
00237 {
00238    if (ctx->aelt_context) {
00239       _ae_destroy_context( ctx );
00240       ctx->aelt_context = NULL;
00241    }
00242 
00243    vbo_exec_destroy(ctx);
00244 #if FEATURE_dlist
00245    vbo_save_destroy(ctx);
00246 #endif
00247    FREE(vbo_context(ctx));
00248    ctx->swtnl_im = NULL;
00249 }

Generated on Sun May 27 2012 04:20:48 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.