Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

  1. /**************************************************************************
  2.  *
  3.  * Copyright 2005 Tungsten Graphics, Inc., Cedar Park, Texas.
  4.  * All Rights Reserved.
  5.  *
  6.  * Permission is hereby granted, free of charge, to any person obtaining a
  7.  * copy of this software and associated documentation files (the
  8.  * "Software"), to deal in the Software without restriction, including
  9.  * without limitation the rights to use, copy, modify, merge, publish,
  10.  * distribute, sub license, and/or sell copies of the Software, and to
  11.  * permit persons to whom the Software is furnished to do so, subject to
  12.  * the following conditions:
  13.  *
  14.  * The above copyright notice and this permission notice (including the
  15.  * next paragraph) shall be included in all copies or substantial portions
  16.  * of the Software.
  17.  *
  18.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  19.  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  20.  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
  21.  * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
  22.  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  23.  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  24.  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  25.  *
  26.  **************************************************************************/
  27.  
  28. #include "main/context.h"
  29. #include "main/glheader.h"
  30. #include "main/enums.h"
  31. #include "main/imports.h"
  32. #include "main/mtypes.h"
  33. #include "main/dispatch.h"
  34. #include "glapi/glapi.h"
  35.  
  36. #include "vbo_context.h"
  37.  
  38.  
  39. typedef void (*attr_func)( struct gl_context *ctx, GLint target, const GLfloat * );
  40.  
  41.  
  42. /* This file makes heavy use of the aliasing of NV vertex attributes
  43.  * with the legacy attributes, and also with ARB and Material
  44.  * attributes as currently implemented.
  45.  */
  46. static void VertexAttrib1fvNV(struct gl_context *ctx, GLint target, const GLfloat *v)
  47. {
  48.    CALL_VertexAttrib1fvNV(ctx->Exec, (target, v));
  49. }
  50.  
  51. static void VertexAttrib2fvNV(struct gl_context *ctx, GLint target, const GLfloat *v)
  52. {
  53.    CALL_VertexAttrib2fvNV(ctx->Exec, (target, v));
  54. }
  55.  
  56. static void VertexAttrib3fvNV(struct gl_context *ctx, GLint target, const GLfloat *v)
  57. {
  58.    CALL_VertexAttrib3fvNV(ctx->Exec, (target, v));
  59. }
  60.  
  61. static void VertexAttrib4fvNV(struct gl_context *ctx, GLint target, const GLfloat *v)
  62. {
  63.    CALL_VertexAttrib4fvNV(ctx->Exec, (target, v));
  64. }
  65.  
  66. static attr_func vert_attrfunc[4] = {
  67.    VertexAttrib1fvNV,
  68.    VertexAttrib2fvNV,
  69.    VertexAttrib3fvNV,
  70.    VertexAttrib4fvNV
  71. };
  72.  
  73. struct loopback_attr {
  74.    GLint target;
  75.    GLint sz;
  76.    attr_func func;
  77. };
  78.  
  79. /* Don't emit ends and begins on wrapped primitives.  Don't replay
  80.  * wrapped vertices.  If we get here, it's probably because the
  81.  * precalculated wrapping is wrong.
  82.  */
  83. static void loopback_prim( struct gl_context *ctx,
  84.                            const GLfloat *buffer,
  85.                            const struct _mesa_prim *prim,
  86.                            GLuint wrap_count,
  87.                            GLuint vertex_size,
  88.                            const struct loopback_attr *la, GLuint nr )
  89. {
  90.    GLint start = prim->start;
  91.    GLint end = start + prim->count;
  92.    const GLfloat *data;
  93.    GLint j;
  94.    GLuint k;
  95.  
  96.    if (0)
  97.       printf("loopback prim %s(%s,%s) verts %d..%d\n",
  98.              _mesa_lookup_prim_by_nr(prim->mode),
  99.              prim->begin ? "begin" : "..",
  100.              prim->end ? "end" : "..",
  101.              start,
  102.              end);
  103.  
  104.    if (prim->begin) {
  105.       CALL_Begin(GET_DISPATCH(), ( prim->mode ));
  106.    }
  107.    else {
  108.       assert(start == 0);
  109.       start += wrap_count;
  110.    }
  111.  
  112.    data = buffer + start * vertex_size;
  113.  
  114.    for (j = start ; j < end ; j++) {
  115.       const GLfloat *tmp = data + la[0].sz;
  116.  
  117.       for (k = 1 ; k < nr ; k++) {
  118.          la[k].func( ctx, la[k].target, tmp );
  119.          tmp += la[k].sz;
  120.       }
  121.          
  122.       /* Fire the vertex
  123.        */
  124.       la[0].func( ctx, VBO_ATTRIB_POS, data );
  125.       data = tmp;
  126.    }
  127.  
  128.    if (prim->end) {
  129.       CALL_End(GET_DISPATCH(), ());
  130.    }
  131. }
  132.  
  133. /* Primitives generated by DrawArrays/DrawElements/Rectf may be
  134.  * caught here.  If there is no primitive in progress, execute them
  135.  * normally, otherwise need to track and discard the generated
  136.  * primitives.
  137.  */
  138. static void loopback_weak_prim( struct gl_context *ctx,
  139.                                 const struct _mesa_prim *prim )
  140. {
  141.    /* Use the prim_weak flag to ensure that if this primitive
  142.     * wraps, we don't mistake future vertex_lists for part of the
  143.     * surrounding primitive.
  144.     *
  145.     * While this flag is set, we are simply disposing of data
  146.     * generated by an operation now known to be a noop.
  147.     */
  148.    if (prim->begin)
  149.       ctx->Driver.CurrentExecPrimitive |= VBO_SAVE_PRIM_WEAK;
  150.    if (prim->end)
  151.       ctx->Driver.CurrentExecPrimitive &= ~VBO_SAVE_PRIM_WEAK;
  152. }
  153.  
  154.  
  155. void vbo_loopback_vertex_list( struct gl_context *ctx,
  156.                                const GLfloat *buffer,
  157.                                const GLubyte *attrsz,
  158.                                const struct _mesa_prim *prim,
  159.                                GLuint prim_count,
  160.                                GLuint wrap_count,
  161.                                GLuint vertex_size)
  162. {
  163.    struct loopback_attr la[VBO_ATTRIB_MAX];
  164.    GLuint i, nr = 0;
  165.  
  166.    /* All Legacy, NV, ARB and Material attributes are routed through
  167.     * the NV attributes entrypoints:
  168.     */
  169.    for (i = 0 ; i < VBO_ATTRIB_MAX ; i++) {
  170.       if (attrsz[i]) {
  171.          la[nr].target = i;
  172.          la[nr].sz = attrsz[i];
  173.          la[nr].func = vert_attrfunc[attrsz[i]-1];
  174.          nr++;
  175.       }
  176.    }
  177.  
  178.    for (i = 0 ; i < prim_count ; i++) {
  179.       if ((prim[i].mode & VBO_SAVE_PRIM_WEAK) &&
  180.           _mesa_inside_begin_end(ctx))
  181.       {
  182.          loopback_weak_prim( ctx, &prim[i] );
  183.       }
  184.       else
  185.       {
  186.          loopback_prim( ctx, buffer, &prim[i], wrap_count, vertex_size, la, nr );
  187.       }
  188.    }
  189. }
  190.