|
Blender
V2.59
|
00001 /* 00002 * $Id: GPU_extensions.h 35376 2011-03-06 23:12:12Z campbellbarton $ 00003 * 00004 * ***** BEGIN GPL LICENSE BLOCK ***** 00005 * 00006 * This shader is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License 00008 * as published by the Free Software Foundation; either version 2 00009 * of the License, or (at your option) any later version. The Blender 00010 * Foundation also sells licenses for use in proprietary software under 00011 * the Blender License. See http://www.blender.org/BL/ for information 00012 * about this. 00013 * 00014 * This shader is distributed in the hope that it will be useful, 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 * GNU General Public License for more details. 00018 * 00019 * You should have received a copy of the GNU General Public License 00020 * along with this shader; if not, write to the Free Software Foundation, 00021 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00022 * 00023 * The Original Code is Copyright (C) 2005 Blender Foundation. 00024 * All rights reserved. 00025 * 00026 * The Original Code is: all of this file. 00027 * 00028 * Contributor(s): Brecht Van Lommel. 00029 * 00030 * ***** END GPL LICENSE BLOCK ***** 00031 */ 00032 00037 #ifndef GPU_EXTENSIONS_H 00038 #define GPU_EXTENSIONS_H 00039 00040 #ifdef __cplusplus 00041 extern "C" { 00042 #endif 00043 00044 struct Image; 00045 struct ImageUser; 00046 00047 struct GPUTexture; 00048 typedef struct GPUTexture GPUTexture; 00049 00050 struct GPUFrameBuffer; 00051 typedef struct GPUFrameBuffer GPUFrameBuffer; 00052 00053 struct GPUOffScreen; 00054 typedef struct GPUOffScreen GPUOffScreen; 00055 00056 struct GPUShader; 00057 typedef struct GPUShader GPUShader; 00058 00059 /* GPU extensions support */ 00060 00061 void GPU_extensions_disable(void); 00062 void GPU_extensions_init(void); /* call this before running any of the functions below */ 00063 void GPU_extensions_exit(void); 00064 int GPU_print_error(const char *str); 00065 00066 int GPU_glsl_support(void); 00067 int GPU_non_power_of_two_support(void); 00068 int GPU_color_depth(void); 00069 00070 /* GPU Types */ 00071 00072 typedef enum GPUDeviceType { 00073 GPU_DEVICE_NVIDIA = (1<<0), 00074 GPU_DEVICE_ATI = (1<<1), 00075 GPU_DEVICE_INTEL = (1<<2), 00076 GPU_DEVICE_SOFTWARE = (1<<3), 00077 GPU_DEVICE_UNKNOWN = (1<<4), 00078 GPU_DEVICE_ANY = (0xff) 00079 } GPUDeviceType; 00080 00081 typedef enum GPUOSType { 00082 GPU_OS_WIN = (1<<8), 00083 GPU_OS_MAC = (1<<9), 00084 GPU_OS_UNIX = (1<<10), 00085 GPU_OS_ANY = (0xff00) 00086 } GPUOSType; 00087 00088 typedef enum GPUDriverType { 00089 GPU_DRIVER_OFFICIAL = (1<<16), 00090 GPU_DRIVER_OPENSOURCE = (1<<17), 00091 GPU_DRIVER_SOFTWARE = (1<<18), 00092 GPU_DRIVER_ANY = (0xff0000) 00093 } GPUDriverType; 00094 00095 int GPU_type_matches(GPUDeviceType device, GPUOSType os, GPUDriverType driver); 00096 00097 /* GPU Texture 00098 - always returns unsigned char RGBA textures 00099 - if texture with non square dimensions is created, depending on the 00100 graphics card capabilities the texture may actually be stored in a 00101 larger texture with power of two dimensions. the actual dimensions 00102 may be queried with GPU_texture_opengl_width/height. GPU_texture_coord_2f 00103 calls glTexCoord2f with the coordinates adjusted for this. 00104 - can use reference counting: 00105 - reference counter after GPU_texture_create is 1 00106 - GPU_texture_ref increases by one 00107 - GPU_texture_free decreases by one, and frees if 0 00108 - if created with from_blender, will not free the texture 00109 */ 00110 00111 GPUTexture *GPU_texture_create_1D(int w, float *pixels, char err_out[256]); 00112 GPUTexture *GPU_texture_create_2D(int w, int h, float *pixels, char err_out[256]); 00113 GPUTexture *GPU_texture_create_3D(int w, int h, int depth, float *fpixels); 00114 GPUTexture *GPU_texture_create_depth(int w, int h, char err_out[256]); 00115 GPUTexture *GPU_texture_from_blender(struct Image *ima, 00116 struct ImageUser *iuser, double time, int mipmap); 00117 void GPU_texture_free(GPUTexture *tex); 00118 00119 void GPU_texture_ref(GPUTexture *tex); 00120 00121 void GPU_texture_bind(GPUTexture *tex, int number); 00122 void GPU_texture_unbind(GPUTexture *tex); 00123 00124 GPUFrameBuffer *GPU_texture_framebuffer(GPUTexture *tex); 00125 00126 int GPU_texture_target(GPUTexture *tex); 00127 int GPU_texture_opengl_width(GPUTexture *tex); 00128 int GPU_texture_opengl_height(GPUTexture *tex); 00129 00130 /* GPU Framebuffer 00131 - this is a wrapper for an OpenGL framebuffer object (FBO). in practice 00132 multiple FBO's may be created, to get around limitations on the number 00133 of attached textures and the dimension requirements. 00134 - after any of the GPU_framebuffer_* functions, GPU_framebuffer_restore must 00135 be called before rendering to the window framebuffer again */ 00136 00137 GPUFrameBuffer *GPU_framebuffer_create(void); 00138 int GPU_framebuffer_texture_attach(GPUFrameBuffer *fb, GPUTexture *tex, char err_out[256]); 00139 void GPU_framebuffer_texture_detach(GPUFrameBuffer *fb, GPUTexture *tex); 00140 void GPU_framebuffer_texture_bind(GPUFrameBuffer *fb, GPUTexture *tex); 00141 void GPU_framebuffer_texture_unbind(GPUFrameBuffer *fb, GPUTexture *tex); 00142 void GPU_framebuffer_free(GPUFrameBuffer *fb); 00143 00144 void GPU_framebuffer_restore(void); 00145 00146 /* GPU OffScreen 00147 - wrapper around framebuffer and texture for simple offscreen drawing 00148 - changes size if graphics card can't support it */ 00149 00150 GPUOffScreen *GPU_offscreen_create(int *width, int *height, char err_out[256]); 00151 void GPU_offscreen_free(GPUOffScreen *ofs); 00152 void GPU_offscreen_bind(GPUOffScreen *ofs); 00153 void GPU_offscreen_unbind(GPUOffScreen *ofs); 00154 00155 /* GPU Shader 00156 - only for fragment shaders now 00157 - must call texture bind before setting a texture as uniform! */ 00158 00159 GPUShader *GPU_shader_create(const char *vertexcode, const char *fragcode, const char *libcode); /*GPUShader *lib);*/ 00160 /*GPUShader *GPU_shader_create_lib(const char *code);*/ 00161 void GPU_shader_free(GPUShader *shader); 00162 00163 void GPU_shader_bind(GPUShader *shader); 00164 void GPU_shader_unbind(GPUShader *shader); 00165 00166 int GPU_shader_get_uniform(GPUShader *shader, const char *name); 00167 void GPU_shader_uniform_vector(GPUShader *shader, int location, int length, 00168 int arraysize, float *value); 00169 void GPU_shader_uniform_texture(GPUShader *shader, int location, GPUTexture *tex); 00170 00171 int GPU_shader_get_attribute(GPUShader *shader, char *name); 00172 00173 /* Vertex attributes for shaders */ 00174 00175 #define GPU_MAX_ATTRIB 32 00176 00177 typedef struct GPUVertexAttribs { 00178 struct { 00179 int type; 00180 int glindex; 00181 char name[32]; 00182 } layer[GPU_MAX_ATTRIB]; 00183 00184 int totlayer; 00185 } GPUVertexAttribs; 00186 00187 #ifdef __cplusplus 00188 } 00189 #endif 00190 00191 #endif 00192