Blender V2.61 - r43446
|
00001 /* 00002 * ***** BEGIN GPL LICENSE BLOCK ***** 00003 * 00004 * This program is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public License 00006 * as published by the Free Software Foundation; either version 2 00007 * of the License, or (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software Foundation, 00016 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00017 * 00018 * The Original Code is Copyright (C) 2005 Blender Foundation. 00019 * All rights reserved. 00020 * 00021 * The Original Code is: all of this file. 00022 * 00023 * Contributor(s): Brecht Van Lommel. 00024 * 00025 * ***** END GPL LICENSE BLOCK ***** 00026 */ 00027 00032 #ifndef __GPU_BUFFERS_H__ 00033 #define __GPU_BUFFERS_H__ 00034 00035 #ifdef _DEBUG 00036 /*#define DEBUG_VBO(X) printf(X)*/ 00037 #define DEBUG_VBO(X) 00038 #else 00039 #define DEBUG_VBO(X) 00040 #endif 00041 00042 struct DerivedMesh; 00043 struct DMGridData; 00044 struct GHash; 00045 struct DMGridData; 00046 struct GPUVertPointLink; 00047 00048 typedef struct GPUBuffer { 00049 int size; /* in bytes */ 00050 void *pointer; /* used with vertex arrays */ 00051 unsigned int id; /* used with vertex buffer objects */ 00052 } GPUBuffer; 00053 00054 typedef struct GPUBufferMaterial { 00055 /* range of points used for this material */ 00056 int start; 00057 int totpoint; 00058 00059 /* original material index */ 00060 short mat_nr; 00061 } GPUBufferMaterial; 00062 00063 /* meshes are split up by material since changing materials requires 00064 GL state changes that can't occur in the middle of drawing an 00065 array. 00066 00067 some simplifying assumptions are made: 00068 * all quads are treated as two triangles. 00069 * no vertex sharing is used; each triangle gets its own copy of the 00070 vertices it uses (this makes it easy to deal with a vertex used 00071 by faces with different properties, such as smooth/solid shading, 00072 different MCols, etc.) 00073 00074 to avoid confusion between the original MVert vertices and the 00075 arrays of OpenGL vertices, the latter are referred to here and in 00076 the source as `points'. similarly, the OpenGL triangles generated 00077 for MFaces are referred to as triangles rather than faces. 00078 */ 00079 typedef struct GPUDrawObject { 00080 GPUBuffer *points; 00081 GPUBuffer *normals; 00082 GPUBuffer *uv; 00083 GPUBuffer *colors; 00084 GPUBuffer *edges; 00085 GPUBuffer *uvedges; 00086 00087 /* for each triangle, the original MFace index */ 00088 int *triangle_to_mface; 00089 00090 /* for each original vertex, the list of related points */ 00091 struct GPUVertPointLink *vert_points; 00092 /* storage for the vert_points lists */ 00093 struct GPUVertPointLink *vert_points_mem; 00094 int vert_points_usage; 00095 00096 int colType; 00097 00098 GPUBufferMaterial *materials; 00099 int totmaterial; 00100 00101 int tot_triangle_point; 00102 int tot_loose_point; 00103 00104 /* caches of the original DerivedMesh values */ 00105 int totvert; 00106 int totedge; 00107 00108 /* if there was a failure allocating some buffer, use old 00109 rendering code */ 00110 int legacy; 00111 } GPUDrawObject; 00112 00113 /* used for GLSL materials */ 00114 typedef struct GPUAttrib { 00115 int index; 00116 int size; 00117 int type; 00118 } GPUAttrib; 00119 00120 void GPU_global_buffer_pool_free(void); 00121 00122 GPUBuffer *GPU_buffer_alloc(int size); 00123 void GPU_buffer_free(GPUBuffer *buffer); 00124 00125 GPUDrawObject *GPU_drawobject_new( struct DerivedMesh *dm ); 00126 void GPU_drawobject_free( struct DerivedMesh *dm ); 00127 00128 /* called before drawing */ 00129 void GPU_vertex_setup( struct DerivedMesh *dm ); 00130 void GPU_normal_setup( struct DerivedMesh *dm ); 00131 void GPU_uv_setup( struct DerivedMesh *dm ); 00132 void GPU_color_setup( struct DerivedMesh *dm ); 00133 void GPU_edge_setup( struct DerivedMesh *dm ); /* does not mix with other data */ 00134 void GPU_uvedge_setup( struct DerivedMesh *dm ); 00135 void GPU_interleaved_setup( GPUBuffer *buffer, int data[] ); 00136 int GPU_attrib_element_size( GPUAttrib data[], int numdata ); 00137 void GPU_interleaved_attrib_setup( GPUBuffer *buffer, GPUAttrib data[], int numdata ); 00138 00139 /* can't lock more than one buffer at once */ 00140 void *GPU_buffer_lock( GPUBuffer *buffer ); 00141 void *GPU_buffer_lock_stream( GPUBuffer *buffer ); 00142 void GPU_buffer_unlock( GPUBuffer *buffer ); 00143 00144 /* upload three unsigned chars, representing RGB colors, for each vertex. Resets dm->drawObject->colType to -1 */ 00145 void GPU_color3_upload( struct DerivedMesh *dm, unsigned char *data ); 00146 /* upload four unsigned chars, representing RGBA colors, for each vertex. Resets dm->drawObject->colType to -1 */ 00147 void GPU_color4_upload( struct DerivedMesh *dm, unsigned char *data ); 00148 /* switch color rendering on=1/off=0 */ 00149 void GPU_color_switch( int mode ); 00150 00151 /* used for drawing edges */ 00152 void GPU_buffer_draw_elements( GPUBuffer *elements, unsigned int mode, int start, int count ); 00153 00154 /* called after drawing */ 00155 void GPU_buffer_unbind(void); 00156 00157 /* used to check whether to use the old (without buffers) code */ 00158 int GPU_buffer_legacy( struct DerivedMesh *dm ); 00159 00160 /* Buffers for non-DerivedMesh drawing */ 00161 typedef struct GPU_Buffers GPU_Buffers; 00162 GPU_Buffers *GPU_build_mesh_buffers(struct GHash *map, struct MVert *mvert, 00163 struct MFace *mface, int *face_indices, 00164 int totface, int *vert_indices, int uniq_verts, 00165 int totvert); 00166 void GPU_update_mesh_buffers(GPU_Buffers *buffers, struct MVert *mvert, 00167 int *vert_indices, int totvert); 00168 GPU_Buffers *GPU_build_grid_buffers(struct DMGridData **grids, 00169 int *grid_indices, int totgrid, int gridsize); 00170 void GPU_update_grid_buffers(GPU_Buffers *buffers, struct DMGridData **grids, 00171 int *grid_indices, int totgrid, int gridsize, int smooth); 00172 void GPU_draw_buffers(GPU_Buffers *buffers); 00173 void GPU_free_buffers(GPU_Buffers *buffers); 00174 00175 #endif