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 00033 #ifndef __GPU_CODEGEN_H__ 00034 #define __GPU_CODEGEN_H__ 00035 00036 #include "DNA_listBase.h" 00037 #include "GPU_material.h" 00038 #include "GL/glew.h" 00039 00040 struct ListBase; 00041 struct GPUShader; 00042 struct GPUOutput; 00043 struct GPUNode; 00044 struct GPUVertexAttribs; 00045 struct GPUFrameBuffer; 00046 00047 #define MAX_FUNCTION_NAME 64 00048 #define MAX_PARAMETER 32 00049 00050 #define FUNCTION_QUAL_IN 0 00051 #define FUNCTION_QUAL_OUT 1 00052 #define FUNCTION_QUAL_INOUT 2 00053 00054 typedef struct GPUFunction { 00055 char name[MAX_FUNCTION_NAME]; 00056 int paramtype[MAX_PARAMETER]; 00057 int paramqual[MAX_PARAMETER]; 00058 int totparam; 00059 } GPUFunction; 00060 00061 GPUFunction *GPU_lookup_function(const char *name); 00062 00063 /* Pass Generation 00064 - Takes a list of nodes and a desired output, and makes a pass. This 00065 will take ownership of the nodes and free them early if unused or 00066 at the end if used. 00067 */ 00068 00069 typedef enum GPUDataSource { 00070 GPU_SOURCE_VEC_UNIFORM, 00071 GPU_SOURCE_BUILTIN, 00072 GPU_SOURCE_TEX_PIXEL, 00073 GPU_SOURCE_TEX, 00074 GPU_SOURCE_ATTRIB 00075 } GPUDataSource; 00076 00077 struct GPUNode { 00078 struct GPUNode *next, *prev; 00079 00080 const char *name; 00081 int tag; 00082 00083 ListBase inputs; 00084 ListBase outputs; 00085 }; 00086 00087 struct GPUNodeLink { 00088 GPUNodeStack *socket; 00089 00090 int attribtype; 00091 const char *attribname; 00092 00093 int image; 00094 00095 int texture; 00096 int texturesize; 00097 00098 void *ptr1, *ptr2; 00099 00100 int dynamic; 00101 int dynamictype; 00102 00103 int type; 00104 int users; 00105 00106 GPUTexture *dynamictex; 00107 00108 GPUBuiltin builtin; 00109 00110 struct GPUOutput *output; 00111 }; 00112 00113 typedef struct GPUOutput { 00114 struct GPUOutput *next, *prev; 00115 00116 GPUNode *node; 00117 int type; /* data type = length of vector/matrix */ 00118 GPUNodeLink *link; /* output link */ 00119 int id; /* unique id as created by code generator */ 00120 } GPUOutput; 00121 00122 typedef struct GPUInput { 00123 struct GPUInput *next, *prev; 00124 00125 GPUNode *node; 00126 00127 int type; /* datatype */ 00128 int source; /* data source */ 00129 00130 int id; /* unique id as created by code generator */ 00131 int texid; /* number for multitexture */ 00132 int attribid; /* id for vertex attributes */ 00133 int bindtex; /* input is responsible for binding the texture? */ 00134 int definetex; /* input is responsible for defining the pixel? */ 00135 int textarget; /* GL_TEXTURE_* */ 00136 int textype; /* datatype */ 00137 00138 struct Image *ima; /* image */ 00139 struct ImageUser *iuser;/* image user */ 00140 float *dynamicvec; /* vector data in case it is dynamic */ 00141 int dynamictype; /* origin of the dynamic uniform (GPUDynamicType) */ 00142 void *dynamicdata; /* data source of the dynamic uniform */ 00143 GPUTexture *tex; /* input texture, only set at runtime */ 00144 int shaderloc; /* id from opengl */ 00145 char shadername[32]; /* name in shader */ 00146 00147 float vec[16]; /* vector data */ 00148 GPUNodeLink *link; 00149 int dynamictex; /* dynamic? */ 00150 int attribtype; /* attribute type */ 00151 char attribname[32]; /* attribute name */ 00152 int attribfirst; /* this is the first one that is bound */ 00153 GPUBuiltin builtin; /* builtin uniform */ 00154 } GPUInput; 00155 00156 struct GPUPass { 00157 struct GPUPass *next, *prev; 00158 00159 ListBase inputs; 00160 struct GPUOutput *output; 00161 struct GPUShader *shader; 00162 char *fragmentcode; 00163 char *vertexcode; 00164 const char *libcode; 00165 }; 00166 00167 00168 typedef struct GPUPass GPUPass; 00169 00170 GPUPass *GPU_generate_pass(ListBase *nodes, struct GPUNodeLink *outlink, 00171 struct GPUVertexAttribs *attribs, int *builtin, const char *name); 00172 00173 struct GPUShader *GPU_pass_shader(GPUPass *pass); 00174 00175 void GPU_pass_bind(GPUPass *pass, double time, int mipmap); 00176 void GPU_pass_update_uniforms(GPUPass *pass); 00177 void GPU_pass_unbind(GPUPass *pass); 00178 00179 void GPU_pass_free(GPUPass *pass); 00180 00181 void GPU_codegen_init(void); 00182 void GPU_codegen_exit(void); 00183 00184 /* Material calls */ 00185 00186 const char *GPU_builtin_name(GPUBuiltin builtin); 00187 void gpu_material_add_node(struct GPUMaterial *material, struct GPUNode *node); 00188 int GPU_link_changed(struct GPUNodeLink *link); 00189 00190 #endif 00191