home *** CD-ROM | disk | FTP | other *** search
/ Amiga Magazin: Amiga-CD 2000 April & May / AMIGA_2000_04.iso / patches / mesa3.1 / mesa-3_1.lha / src / vector.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-01-07  |  5.0 KB  |  168 lines

  1. /* $Id: vector.h,v 1.1.1.1 1999/08/19 00:55:41 jtg Exp $ */
  2.  
  3. /*
  4.  * Mesa 3-D graphics library
  5.  * Version:  3.1
  6.  * 
  7.  * Copyright (C) 1999  Brian Paul   All Rights Reserved.
  8.  * 
  9.  * Permission is hereby granted, free of charge, to any person obtaining a
  10.  * copy of this software and associated documentation files (the "Software"),
  11.  * to deal in the Software without restriction, including without limitation
  12.  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  13.  * and/or sell copies of the Software, and to permit persons to whom the
  14.  * Software is furnished to do so, subject to the following conditions:
  15.  * 
  16.  * The above copyright notice and this permission notice shall be included
  17.  * in all copies or substantial portions of the Software.
  18.  * 
  19.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  20.  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21.  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  22.  * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  23.  * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  24.  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  25.  */
  26.  
  27. /*
  28.  * New (3.1) transformation code written by Keith Whitwell.
  29.  */
  30.  
  31.  
  32. #ifndef _VECTOR_H_
  33. #define _VECTOR_H_
  34.  
  35. #include "GL/gl.h"
  36.  
  37. /* Wrap all the information about vertices up in a struct.  Has
  38.  * additional fields compared to the other vectors to help us track of
  39.  * different vertex sizes, and whether we need to clean columns out
  40.  * because they contain non-(0,0,0,1) values.  
  41.  *
  42.  * The start field is used to reserve data for copied vertices at the
  43.  * end of gl_transform_vb, and avoids the need for a multiplication in
  44.  * the transformation routines.
  45.  */
  46. typedef struct {
  47.    GLfloat (*data)[4];           /* may be malloced or point to client data */
  48.    GLfloat *start;
  49.    GLuint count;
  50.    GLuint stride;         /* start to start */
  51.    GLuint size;             /* 2-4 for vertices and 1-4 for texcoords */
  52.    GLuint flags;         /* which columns are dirty */
  53.    void *storage;
  54. } GLvector4f;
  55.  
  56.  
  57. extern void gl_vector4f_print( GLvector4f *v, GLubyte *, GLboolean );
  58. extern void gl_vector4f_init( GLvector4f *v, GLuint flags,
  59.                   GLfloat (*storage)[4] );
  60. extern void gl_vector4f_alloc( GLvector4f *v, GLuint sz, GLuint flags,
  61.                    GLuint count, GLuint alignment );
  62. extern void gl_vector4f_free( GLvector4f *v );
  63. extern void gl_vector4f_clean_elem( GLvector4f *vec, GLuint nr, GLuint elt );
  64.  
  65.  
  66. #define VEC_DIRTY_0        0x1    /* dirty flags not really used any more */
  67. #define VEC_DIRTY_1        0x2
  68. #define VEC_DIRTY_2        0x4
  69. #define VEC_DIRTY_3        0x8
  70. #define VEC_MALLOC         0x10
  71. #define VEC_WRITABLE       0x20    /* keep both + and - bits for easy testing */
  72. #define VEC_NOT_WRITABLE   0x40
  73. #define VEC_GOOD_STRIDE    0x80    
  74. #define VEC_BAD_STRIDE     0x100
  75.  
  76. #define VEC_WRITABLE_FLAGS (VEC_WRITABLE|VEC_NOT_WRITABLE)
  77. #define VEC_STRIDE_FLAGS   (VEC_GOOD_STRIDE|VEC_BAD_STRIDE)
  78.  
  79.  
  80. #define VEC_SIZE_1   VEC_DIRTY_0
  81. #define VEC_SIZE_2   (VEC_DIRTY_0|VEC_DIRTY_1)
  82. #define VEC_SIZE_3   (VEC_DIRTY_0|VEC_DIRTY_1|VEC_DIRTY_2)
  83. #define VEC_SIZE_4   (VEC_DIRTY_0|VEC_DIRTY_1|VEC_DIRTY_2|VEC_DIRTY_3)
  84.  
  85.  
  86. /* Could use a single vector type for normals and vertices, but
  87.  * this way avoids some casts.  
  88.  */
  89. typedef struct {
  90.    GLfloat (*data)[3];       
  91.    GLfloat *start;
  92.    GLuint count;
  93.    GLuint stride;
  94.    GLuint flags;
  95.    void *storage;
  96. } GLvector3f;
  97.  
  98. extern void gl_vector3f_print( GLvector3f *v, GLubyte *, GLboolean );
  99. extern void gl_vector3f_free( GLvector3f *v );
  100. extern void gl_vector3f_init( GLvector3f *v, GLuint flags, GLfloat (*)[3] );
  101. extern void gl_vector3f_alloc( GLvector3f *v, GLuint flags, GLuint count,
  102.                    GLuint alignment );
  103.  
  104.  
  105. /* For 4ub rgba values.
  106.  */
  107. typedef struct {
  108.    GLubyte (*data)[4];
  109.    GLubyte *start;
  110.    GLuint count;
  111.    GLuint stride;         
  112.    GLuint flags; 
  113.    void *storage;
  114. } GLvector4ub;
  115.  
  116. extern void gl_vector4ub_init( GLvector4ub *v, GLuint flags, 
  117.                    GLubyte (*storage)[4] );
  118. extern void gl_vector4ub_free( GLvector4ub * );
  119. extern void gl_vector4ub_alloc( GLvector4ub *v, GLuint flags, GLuint count,
  120.                 GLuint alignment );
  121.  
  122.  
  123.  
  124.  
  125. /* For 1ub values, eg edgeflag.
  126.  */
  127. typedef struct {
  128.    GLubyte *data;
  129.    GLubyte *start;
  130.    GLuint count;
  131.    GLuint stride;         
  132.    GLuint flags; 
  133.    void *storage;
  134. } GLvector1ub;
  135.  
  136. extern void gl_vector1ub_init( GLvector1ub *v, GLuint flags, GLubyte *storage);
  137. extern void gl_vector1ub_free( GLvector1ub * );
  138. extern void gl_vector1ub_alloc( GLvector1ub *v, GLuint flags, GLuint count,
  139.                 GLuint alignment );
  140.  
  141.  
  142.  
  143.  
  144. /* For, eg Index, Array element.
  145.  */
  146. typedef struct {
  147.    GLuint *data;
  148.    GLuint *start;
  149.    GLuint count;
  150.    GLuint stride; 
  151.    GLuint flags; 
  152.    void *storage;
  153. } GLvector1ui;
  154.  
  155. extern void gl_vector1ui_init( GLvector1ui *v, GLuint flags, GLuint *storage );
  156. extern void gl_vector1ui_free( GLvector1ui * );
  157. extern void gl_vector1ui_alloc( GLvector1ui *v, GLuint flags, GLuint count, 
  158.                 GLuint alignment );
  159.  
  160.  
  161.  
  162. /* End up doing a lot of slow imuls if not careful.
  163.  */
  164. #define VEC_ELT( v, t, i ) ((t *) (((GLbyte *)((v)->data))+(i)*(v)->stride) )
  165.  
  166.  
  167. #endif
  168.