cleanup: use spaces for alignment

while studying GPU lib
This commit is contained in:
Mike Erwin 2015-03-23 15:29:42 -04:00
parent 722ddaaccd
commit 38321faa8d
14 changed files with 773 additions and 745 deletions

@ -51,10 +51,10 @@ struct GPUVertPointLink;
struct PBVH; struct PBVH;
typedef struct GPUBuffer { typedef struct GPUBuffer {
int size; /* in bytes */ int size; /* in bytes */
void *pointer; /* used with vertex arrays */ void *pointer; /* used with vertex arrays */
unsigned int id; /* used with vertex buffer objects */ unsigned int id; /* used with vertex buffer objects */
bool use_vbo; /* true for VBOs, false for vertex arrays */ bool use_vbo; /* true for VBOs, false for vertex arrays */
} GPUBuffer; } GPUBuffer;
typedef struct GPUBufferMaterial { typedef struct GPUBufferMaterial {

@ -52,7 +52,7 @@ enum eGPUFXFlags;
typedef enum GPUFXShaderEffect { typedef enum GPUFXShaderEffect {
/* Screen space ambient occlusion shader */ /* Screen space ambient occlusion shader */
GPU_SHADER_FX_SSAO = 1, GPU_SHADER_FX_SSAO = 1,
/* depth of field passes. Yep, quite a complex effect */ /* depth of field passes. Yep, quite a complex effect */
GPU_SHADER_FX_DEPTH_OF_FIELD_PASS_ONE = 2, GPU_SHADER_FX_DEPTH_OF_FIELD_PASS_ONE = 2,

@ -84,6 +84,7 @@ int GPU_get_material_alpha_blend(void);
int GPU_set_tpage(struct MTFace *tface, int mipmap, int transp); int GPU_set_tpage(struct MTFace *tface, int mipmap, int transp);
void GPU_clear_tpage(bool force); void GPU_clear_tpage(bool force);
/* Lights /* Lights
* - returns how many lights were enabled * - returns how many lights were enabled
* - this affects fixed functions materials and texface, not glsl */ * - this affects fixed functions materials and texface, not glsl */

@ -72,26 +72,26 @@ void GPU_code_generate_glsl_lib(void);
/* GPU Types */ /* GPU Types */
typedef enum GPUDeviceType { typedef enum GPUDeviceType {
GPU_DEVICE_NVIDIA = (1<<0), GPU_DEVICE_NVIDIA = (1<<0),
GPU_DEVICE_ATI = (1<<1), GPU_DEVICE_ATI = (1<<1),
GPU_DEVICE_INTEL = (1<<2), GPU_DEVICE_INTEL = (1<<2),
GPU_DEVICE_SOFTWARE = (1<<3), GPU_DEVICE_SOFTWARE = (1<<3),
GPU_DEVICE_UNKNOWN = (1<<4), GPU_DEVICE_UNKNOWN = (1<<4),
GPU_DEVICE_ANY = (0xff) GPU_DEVICE_ANY = (0xff)
} GPUDeviceType; } GPUDeviceType;
typedef enum GPUOSType { typedef enum GPUOSType {
GPU_OS_WIN = (1<<8), GPU_OS_WIN = (1<<8),
GPU_OS_MAC = (1<<9), GPU_OS_MAC = (1<<9),
GPU_OS_UNIX = (1<<10), GPU_OS_UNIX = (1<<10),
GPU_OS_ANY = (0xff00) GPU_OS_ANY = (0xff00)
} GPUOSType; } GPUOSType;
typedef enum GPUDriverType { typedef enum GPUDriverType {
GPU_DRIVER_OFFICIAL = (1<<16), GPU_DRIVER_OFFICIAL = (1<<16),
GPU_DRIVER_OPENSOURCE = (1<<17), GPU_DRIVER_OPENSOURCE = (1<<17),
GPU_DRIVER_SOFTWARE = (1<<18), GPU_DRIVER_SOFTWARE = (1<<18),
GPU_DRIVER_ANY = (0xff0000) GPU_DRIVER_ANY = (0xff0000)
} GPUDriverType; } GPUDriverType;
bool GPU_type_matches(GPUDeviceType device, GPUOSType os, GPUDriverType driver); bool GPU_type_matches(GPUDeviceType device, GPUOSType os, GPUDriverType driver);
@ -204,8 +204,8 @@ int GPU_shader_get_attribute(GPUShader *shader, const char *name);
/* Builtin/Non-generated shaders */ /* Builtin/Non-generated shaders */
typedef enum GPUBuiltinShader { typedef enum GPUBuiltinShader {
GPU_SHADER_VSM_STORE = (1<<0), GPU_SHADER_VSM_STORE = (1<<0),
GPU_SHADER_SEP_GAUSSIAN_BLUR = (1<<1), GPU_SHADER_SEP_GAUSSIAN_BLUR = (1<<1),
} GPUBuiltinShader; } GPUBuiltinShader;
GPUShader *GPU_shader_get_builtin_shader(GPUBuiltinShader shader); GPUShader *GPU_shader_get_builtin_shader(GPUBuiltinShader shader);
@ -215,7 +215,7 @@ void GPU_shader_free_builtin_shaders(void);
/* Vertex attributes for shaders */ /* Vertex attributes for shaders */
#define GPU_MAX_ATTRIB 32 #define GPU_MAX_ATTRIB 32
typedef struct GPUVertexAttribs { typedef struct GPUVertexAttribs {
struct { struct {

@ -92,7 +92,7 @@ typedef enum GPUBuiltin {
GPU_VIEW_NORMAL = (1 << 5), GPU_VIEW_NORMAL = (1 << 5),
GPU_OBCOLOR = (1 << 6), GPU_OBCOLOR = (1 << 6),
GPU_AUTO_BUMPSCALE = (1 << 7), GPU_AUTO_BUMPSCALE = (1 << 7),
GPU_CAMERA_TEXCO_FACTORS = (1 << 8), GPU_CAMERA_TEXCO_FACTORS = (1 << 8),
} GPUBuiltin; } GPUBuiltin;
typedef enum GPUOpenGLBuiltin { typedef enum GPUOpenGLBuiltin {
@ -213,7 +213,7 @@ void GPU_shaderesult_set(GPUShadeInput *shi, GPUShadeResult *shr);
typedef enum GPUDataType { typedef enum GPUDataType {
GPU_DATA_NONE = 0, GPU_DATA_NONE = 0,
GPU_DATA_1I = 1, // 1 integer GPU_DATA_1I = 1, /* 1 integer */
GPU_DATA_1F = 2, GPU_DATA_1F = 2,
GPU_DATA_2F = 3, GPU_DATA_2F = 3,
GPU_DATA_3F = 4, GPU_DATA_3F = 4,
@ -226,23 +226,23 @@ typedef enum GPUDataType {
/* this structure gives information of each uniform found in the shader */ /* this structure gives information of each uniform found in the shader */
typedef struct GPUInputUniform { typedef struct GPUInputUniform {
struct GPUInputUniform *next, *prev; struct GPUInputUniform *next, *prev;
char varname[32]; /* name of uniform in shader */ char varname[32]; /* name of uniform in shader */
GPUDynamicType type; /* type of uniform, data format and calculation derive from it */ GPUDynamicType type; /* type of uniform, data format and calculation derive from it */
GPUDataType datatype; /* type of uniform data */ GPUDataType datatype; /* type of uniform data */
struct Object *lamp; /* when type=GPU_DYNAMIC_LAMP_... or GPU_DYNAMIC_SAMPLER_2DSHADOW */ struct Object *lamp; /* when type=GPU_DYNAMIC_LAMP_... or GPU_DYNAMIC_SAMPLER_2DSHADOW */
struct Image *image; /* when type=GPU_DYNAMIC_SAMPLER_2DIMAGE */ struct Image *image; /* when type=GPU_DYNAMIC_SAMPLER_2DIMAGE */
int texnumber; /* when type=GPU_DYNAMIC_SAMPLER, texture number: 0.. */ int texnumber; /* when type=GPU_DYNAMIC_SAMPLER, texture number: 0.. */
unsigned char *texpixels; /* for internally generated texture, pixel data in RGBA format */ unsigned char *texpixels; /* for internally generated texture, pixel data in RGBA format */
int texsize; /* size in pixel of the texture in texpixels buffer: for 2D textures, this is S and T size (square texture) */ int texsize; /* size in pixel of the texture in texpixels buffer: for 2D textures, this is S and T size (square texture) */
} GPUInputUniform; } GPUInputUniform;
typedef struct GPUInputAttribute { typedef struct GPUInputAttribute {
struct GPUInputAttribute *next, *prev; struct GPUInputAttribute *next, *prev;
char varname[32]; /* name of attribute in shader */ char varname[32]; /* name of attribute in shader */
int type; /* from CustomData.type, data type derives from it */ int type; /* from CustomData.type, data type derives from it */
GPUDataType datatype; /* type of attribute data */ GPUDataType datatype; /* type of attribute data */
const char *name; /* layer name */ const char *name; /* layer name */
int number; /* generic attribute number */ int number; /* generic attribute number */
} GPUInputAttribute; } GPUInputAttribute;
typedef struct GPUShaderExport { typedef struct GPUShaderExport {

@ -42,11 +42,11 @@ extern "C" {
typedef enum GPUSimpleShaderOption { typedef enum GPUSimpleShaderOption {
GPU_SHADER_OVERRIDE_DIFFUSE = (1<<0), /* replace diffuse with glcolor */ GPU_SHADER_OVERRIDE_DIFFUSE = (1<<0), /* replace diffuse with glcolor */
GPU_SHADER_LIGHTING = (1<<1), /* use lighting */ GPU_SHADER_LIGHTING = (1<<1), /* use lighting */
GPU_SHADER_TWO_SIDED = (1<<2), /* flip normals towards viewer */ GPU_SHADER_TWO_SIDED = (1<<2), /* flip normals towards viewer */
GPU_SHADER_TEXTURE_2D = (1<<3), /* use 2D texture to replace diffuse color */ GPU_SHADER_TEXTURE_2D = (1<<3), /* use 2D texture to replace diffuse color */
GPU_SHADER_SOLID_LIGHTING = (1<<4), /* use faster lighting (set automatically) */ GPU_SHADER_SOLID_LIGHTING = (1<<4), /* use faster lighting (set automatically) */
GPU_SHADER_OPTIONS_NUM = 5, GPU_SHADER_OPTIONS_NUM = 5,
GPU_SHADER_OPTION_COMBINATIONS = (1<<GPU_SHADER_OPTIONS_NUM) GPU_SHADER_OPTION_COMBINATIONS = (1<<GPU_SHADER_OPTIONS_NUM)
} GPUSimpleShaderOption; } GPUSimpleShaderOption;

@ -383,8 +383,9 @@ void GPU_buffer_free(GPUBuffer *buffer)
BLI_mutex_unlock(&buffer_mutex); BLI_mutex_unlock(&buffer_mutex);
} }
/* currently unused */ #if 0 /* currently unused */
// #define USE_GPU_POINT_LINK # define USE_GPU_POINT_LINK
#endif
typedef struct GPUVertPointLink { typedef struct GPUVertPointLink {
#ifdef USE_GPU_POINT_LINK #ifdef USE_GPU_POINT_LINK
@ -452,7 +453,7 @@ static void gpu_drawobject_init_vert_points(GPUDrawObject *gdo, MFace *f, int to
int i, *mat_orig_to_new; int i, *mat_orig_to_new;
mat_orig_to_new = MEM_callocN(sizeof(*mat_orig_to_new) * totmat, mat_orig_to_new = MEM_callocN(sizeof(*mat_orig_to_new) * totmat,
"GPUDrawObject.mat_orig_to_new"); "GPUDrawObject.mat_orig_to_new");
/* allocate the array and space for links */ /* allocate the array and space for links */
gdo->vert_points = MEM_mallocN(sizeof(GPUVertPointLink) * gdo->totvert, gdo->vert_points = MEM_mallocN(sizeof(GPUVertPointLink) * gdo->totvert,
"GPUDrawObject.vert_points"); "GPUDrawObject.vert_points");
@ -1007,7 +1008,7 @@ const GPUBufferTypeSettings gpu_buffer_type_settings[] = {
{GPU_buffer_copy_normal, GL_ARRAY_BUFFER_ARB, 3}, {GPU_buffer_copy_normal, GL_ARRAY_BUFFER_ARB, 3},
{GPU_buffer_copy_mcol, GL_ARRAY_BUFFER_ARB, 3}, {GPU_buffer_copy_mcol, GL_ARRAY_BUFFER_ARB, 3},
{GPU_buffer_copy_uv, GL_ARRAY_BUFFER_ARB, 2}, {GPU_buffer_copy_uv, GL_ARRAY_BUFFER_ARB, 2},
{GPU_buffer_copy_uv_texpaint, GL_ARRAY_BUFFER_ARB, 4}, {GPU_buffer_copy_uv_texpaint, GL_ARRAY_BUFFER_ARB, 4},
{GPU_buffer_copy_edge, GL_ELEMENT_ARRAY_BUFFER_ARB, 2}, {GPU_buffer_copy_edge, GL_ELEMENT_ARRAY_BUFFER_ARB, 2},
{GPU_buffer_copy_uvedge, GL_ELEMENT_ARRAY_BUFFER_ARB, 4} {GPU_buffer_copy_uvedge, GL_ELEMENT_ARRAY_BUFFER_ARB, 4}
}; };
@ -1498,6 +1499,7 @@ struct GPU_PBVH_Buffers {
bool use_matcaps; bool use_matcaps;
float diffuse_color[4]; float diffuse_color[4];
}; };
typedef enum { typedef enum {
VBO_ENABLED, VBO_ENABLED,
VBO_DISABLED VBO_DISABLED
@ -1577,8 +1579,8 @@ static void gpu_color_from_mask_quad_set(const CCGKey *key,
} }
void GPU_update_mesh_pbvh_buffers(GPU_PBVH_Buffers *buffers, MVert *mvert, void GPU_update_mesh_pbvh_buffers(GPU_PBVH_Buffers *buffers, MVert *mvert,
int *vert_indices, int totvert, const float *vmask, int *vert_indices, int totvert, const float *vmask,
int (*face_vert_indices)[4], bool show_diffuse_color) int (*face_vert_indices)[4], bool show_diffuse_color)
{ {
VertexBufferFormat *vert_data; VertexBufferFormat *vert_data;
int i, j, k; int i, j, k;
@ -1715,9 +1717,9 @@ void GPU_update_mesh_pbvh_buffers(GPU_PBVH_Buffers *buffers, MVert *mvert,
} }
GPU_PBVH_Buffers *GPU_build_mesh_pbvh_buffers(int (*face_vert_indices)[4], GPU_PBVH_Buffers *GPU_build_mesh_pbvh_buffers(int (*face_vert_indices)[4],
MFace *mface, MVert *mvert, MFace *mface, MVert *mvert,
int *face_indices, int *face_indices,
int totface) int totface)
{ {
GPU_PBVH_Buffers *buffers; GPU_PBVH_Buffers *buffers;
unsigned short *tri_data; unsigned short *tri_data;
@ -1807,8 +1809,8 @@ GPU_PBVH_Buffers *GPU_build_mesh_pbvh_buffers(int (*face_vert_indices)[4],
} }
void GPU_update_grid_pbvh_buffers(GPU_PBVH_Buffers *buffers, CCGElem **grids, void GPU_update_grid_pbvh_buffers(GPU_PBVH_Buffers *buffers, CCGElem **grids,
const DMFlagMat *grid_flag_mats, int *grid_indices, const DMFlagMat *grid_flag_mats, int *grid_indices,
int totgrid, const CCGKey *key, bool show_diffuse_color) int totgrid, const CCGKey *key, bool show_diffuse_color)
{ {
VertexBufferFormat *vert_data; VertexBufferFormat *vert_data;
int i, j, k, x, y; int i, j, k, x, y;
@ -1921,51 +1923,51 @@ void GPU_update_grid_pbvh_buffers(GPU_PBVH_Buffers *buffers, CCGElem **grids,
/* Build the element array buffer of grid indices using either /* Build the element array buffer of grid indices using either
* unsigned shorts or unsigned ints. */ * unsigned shorts or unsigned ints. */
#define FILL_QUAD_BUFFER(type_, tot_quad_, buffer_) \ #define FILL_QUAD_BUFFER(type_, tot_quad_, buffer_) \
{ \ { \
type_ *tri_data; \ type_ *tri_data; \
int offset = 0; \ int offset = 0; \
int i, j, k; \ int i, j, k; \
\ \
glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, \ glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, \
sizeof(type_) * (tot_quad_) * 6, NULL, \ sizeof(type_) * (tot_quad_) * 6, NULL, \
GL_STATIC_DRAW_ARB); \ GL_STATIC_DRAW_ARB); \
\ \
/* Fill the buffer */ \ /* Fill the buffer */ \
tri_data = glMapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, \ tri_data = glMapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, \
GL_WRITE_ONLY_ARB); \ GL_WRITE_ONLY_ARB); \
if (tri_data) { \ if (tri_data) { \
for (i = 0; i < totgrid; ++i) { \ for (i = 0; i < totgrid; ++i) { \
BLI_bitmap *gh = NULL; \ BLI_bitmap *gh = NULL; \
if (grid_hidden) \ if (grid_hidden) \
gh = grid_hidden[(grid_indices)[i]]; \ gh = grid_hidden[(grid_indices)[i]]; \
\ \
for (j = 0; j < gridsize - 1; ++j) { \ for (j = 0; j < gridsize - 1; ++j) { \
for (k = 0; k < gridsize - 1; ++k) { \ for (k = 0; k < gridsize - 1; ++k) { \
/* Skip hidden grid face */ \ /* Skip hidden grid face */ \
if (gh && \ if (gh && \
paint_is_grid_face_hidden(gh, \ paint_is_grid_face_hidden(gh, \
gridsize, k, j)) \ gridsize, k, j)) \
continue; \ continue; \
\ \
*(tri_data++) = offset + j * gridsize + k + 1; \ *(tri_data++) = offset + j * gridsize + k + 1; \
*(tri_data++) = offset + j * gridsize + k; \ *(tri_data++) = offset + j * gridsize + k; \
*(tri_data++) = offset + (j + 1) * gridsize + k; \ *(tri_data++) = offset + (j + 1) * gridsize + k; \
\ \
*(tri_data++) = offset + (j + 1) * gridsize + k + 1; \ *(tri_data++) = offset + (j + 1) * gridsize + k + 1; \
*(tri_data++) = offset + j * gridsize + k + 1; \ *(tri_data++) = offset + j * gridsize + k + 1; \
*(tri_data++) = offset + (j + 1) * gridsize + k; \ *(tri_data++) = offset + (j + 1) * gridsize + k; \
} \ } \
} \ } \
\ \
offset += gridsize * gridsize; \ offset += gridsize * gridsize; \
} \ } \
glUnmapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB); \ glUnmapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB); \
} \ } \
else { \ else { \
glDeleteBuffersARB(1, &(buffer_)); \ glDeleteBuffersARB(1, &(buffer_)); \
(buffer_) = 0; \ (buffer_) = 0; \
} \ } \
} (void)0 } (void)0
/* end FILL_QUAD_BUFFER */ /* end FILL_QUAD_BUFFER */
static GLuint gpu_get_grid_buffer(int gridsize, GLenum *index_type, unsigned *totquad) static GLuint gpu_get_grid_buffer(int gridsize, GLenum *index_type, unsigned *totquad)
@ -2021,7 +2023,7 @@ static GLuint gpu_get_grid_buffer(int gridsize, GLenum *index_type, unsigned *to
} }
GPU_PBVH_Buffers *GPU_build_grid_pbvh_buffers(int *grid_indices, int totgrid, GPU_PBVH_Buffers *GPU_build_grid_pbvh_buffers(int *grid_indices, int totgrid,
BLI_bitmap **grid_hidden, int gridsize) BLI_bitmap **grid_hidden, int gridsize)
{ {
GPU_PBVH_Buffers *buffers; GPU_PBVH_Buffers *buffers;
int totquad; int totquad;
@ -2103,7 +2105,6 @@ static void gpu_bmesh_vert_to_buffer_copy(BMVert *v,
BM_ELEM_CD_GET_FLOAT(v, cd_vert_mask_offset), BM_ELEM_CD_GET_FLOAT(v, cd_vert_mask_offset),
diffuse_color, diffuse_color,
vd->color); vd->color);
/* Assign index for use in the triangle index buffer */ /* Assign index for use in the triangle index buffer */
/* note: caller must set: bm->elem_index_dirty |= BM_VERT; */ /* note: caller must set: bm->elem_index_dirty |= BM_VERT; */
@ -2153,11 +2154,11 @@ static int gpu_bmesh_face_visible_count(GSet *bm_faces)
/* Creates a vertex buffer (coordinate, normal, color) and, if smooth /* Creates a vertex buffer (coordinate, normal, color) and, if smooth
* shading, an element index buffer. */ * shading, an element index buffer. */
void GPU_update_bmesh_pbvh_buffers(GPU_PBVH_Buffers *buffers, void GPU_update_bmesh_pbvh_buffers(GPU_PBVH_Buffers *buffers,
BMesh *bm, BMesh *bm,
GSet *bm_faces, GSet *bm_faces,
GSet *bm_unique_verts, GSet *bm_unique_verts,
GSet *bm_other_verts, GSet *bm_other_verts,
bool show_diffuse_color) bool show_diffuse_color)
{ {
VertexBufferFormat *vert_data; VertexBufferFormat *vert_data;
void *tri_data; void *tri_data;
@ -2204,8 +2205,8 @@ void GPU_update_bmesh_pbvh_buffers(GPU_PBVH_Buffers *buffers,
/* Initialize vertex buffer */ /* Initialize vertex buffer */
glBindBufferARB(GL_ARRAY_BUFFER_ARB, buffers->vert_buf); glBindBufferARB(GL_ARRAY_BUFFER_ARB, buffers->vert_buf);
glBufferDataARB(GL_ARRAY_BUFFER_ARB, glBufferDataARB(GL_ARRAY_BUFFER_ARB,
sizeof(VertexBufferFormat) * totvert, sizeof(VertexBufferFormat) * totvert,
NULL, GL_STATIC_DRAW_ARB); NULL, GL_STATIC_DRAW_ARB);
/* Fill vertex buffer */ /* Fill vertex buffer */
vert_data = glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB); vert_data = glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB);
@ -2246,7 +2247,9 @@ void GPU_update_bmesh_pbvh_buffers(GPU_PBVH_Buffers *buffers,
float fmask = 0; float fmask = 0;
int i; int i;
// BM_iter_as_array(bm, BM_VERTS_OF_FACE, f, (void**)v, 3); #if 0
BM_iter_as_array(bm, BM_VERTS_OF_FACE, f, (void**)v, 3);
#endif
BM_face_as_array_vert_tri(f, v); BM_face_as_array_vert_tri(f, v);
/* Average mask value */ /* Average mask value */
@ -2666,7 +2669,7 @@ bool GPU_pbvh_buffers_diffuse_changed(GPU_PBVH_Buffers *buffers, GSet *bm_faces,
GPU_material_diffuse_get(f->mat_nr + 1, diffuse_color); GPU_material_diffuse_get(f->mat_nr + 1, diffuse_color);
} }
else if (buffers->use_bmesh) { else if (buffers->use_bmesh) {
/* due to dynamc nature of dyntopo, only get first material */ /* due to dynamic nature of dyntopo, only get first material */
if (BLI_gset_size(bm_faces) > 0) { if (BLI_gset_size(bm_faces) > 0) {
GSetIterator gs_iter; GSetIterator gs_iter;
BMFace *f; BMFace *f;
@ -2717,7 +2720,7 @@ static void gpu_pbvh_buffer_free_intern(GLuint id)
if (pool->maxpbvhsize == pool->totpbvhbufids) { if (pool->maxpbvhsize == pool->totpbvhbufids) {
pool->maxpbvhsize += MAX_FREE_GPU_BUFF_IDS; pool->maxpbvhsize += MAX_FREE_GPU_BUFF_IDS;
pool->pbvhbufids = MEM_reallocN(pool->pbvhbufids, pool->pbvhbufids = MEM_reallocN(pool->pbvhbufids,
sizeof(*pool->pbvhbufids) * pool->maxpbvhsize); sizeof(*pool->pbvhbufids) * pool->maxpbvhsize);
} }
/* insert the buffer into the beginning of the pool */ /* insert the buffer into the beginning of the pool */
@ -2742,33 +2745,33 @@ void GPU_free_pbvh_buffers(GPU_PBVH_Buffers *buffers)
void GPU_draw_pbvh_BB(float min[3], float max[3], bool leaf) void GPU_draw_pbvh_BB(float min[3], float max[3], bool leaf)
{ {
const float quads[4][4][3] = { const float quads[4][4][3] = {
{ {
{min[0], min[1], min[2]}, {min[0], min[1], min[2]},
{max[0], min[1], min[2]}, {max[0], min[1], min[2]},
{max[0], min[1], max[2]}, {max[0], min[1], max[2]},
{min[0], min[1], max[2]} {min[0], min[1], max[2]}
}, },
{ {
{min[0], min[1], min[2]}, {min[0], min[1], min[2]},
{min[0], max[1], min[2]}, {min[0], max[1], min[2]},
{min[0], max[1], max[2]}, {min[0], max[1], max[2]},
{min[0], min[1], max[2]} {min[0], min[1], max[2]}
}, },
{ {
{max[0], max[1], min[2]}, {max[0], max[1], min[2]},
{max[0], min[1], min[2]}, {max[0], min[1], min[2]},
{max[0], min[1], max[2]}, {max[0], min[1], max[2]},
{max[0], max[1], max[2]} {max[0], max[1], max[2]}
}, },
{ {
{max[0], max[1], min[2]}, {max[0], max[1], min[2]},
{min[0], max[1], min[2]}, {min[0], max[1], min[2]},
{min[0], max[1], max[2]}, {min[0], max[1], max[2]},
{max[0], max[1], max[2]} {max[0], max[1], max[2]}
}, },
}; };
if (leaf) if (leaf)

@ -46,7 +46,7 @@
#include "GPU_material.h" #include "GPU_material.h"
#include "GPU_extensions.h" #include "GPU_extensions.h"
#include "BLI_sys_types.h" // for intptr_t support #include "BLI_sys_types.h" /* for intptr_t support */
#include "gpu_codegen.h" #include "gpu_codegen.h"
@ -90,9 +90,11 @@ static const char *GPU_DATATYPE_STR[17] = {"", "float", "vec2", "vec3", "vec4",
/* GLSL code parsing for finding function definitions. /* GLSL code parsing for finding function definitions.
* These are stored in a hash for lookup when creating a material. */ * These are stored in a hash for lookup when creating a material. */
static GHash *FUNCTION_HASH= NULL; static GHash *FUNCTION_HASH = NULL;
/* static char *FUNCTION_PROTOTYPES= NULL; #if 0
* static GPUShader *FUNCTION_LIB= NULL;*/ static char *FUNCTION_PROTOTYPES = NULL;
static GPUShader *FUNCTION_LIB = NULL;
#endif
static int gpu_str_prefix(const char *str, const char *prefix) static int gpu_str_prefix(const char *str, const char *prefix)
{ {
@ -117,7 +119,7 @@ static char *gpu_str_skip_token(char *str, char *token, int max)
break; break;
else { else {
if (token && len < max-1) { if (token && len < max-1) {
*token= *str; *token = *str;
token++; token++;
len++; len++;
} }
@ -126,7 +128,7 @@ static char *gpu_str_skip_token(char *str, char *token, int max)
} }
if (token) if (token)
*token= '\0'; *token = '\0';
/* skip the next special characters: /* skip the next special characters:
* note the missing ')' */ * note the missing ')' */
@ -165,10 +167,10 @@ static void gpu_parse_functions_string(GHash *hash, char *code)
code = gpu_str_skip_token(code, NULL, 0); code = gpu_str_skip_token(code, NULL, 0);
/* test for type */ /* test for type */
type= GPU_NONE; type = GPU_NONE;
for (i=1; i<=16; i++) { for (i = 1; i <= 16; i++) {
if (GPU_DATATYPE_STR[i] && gpu_str_prefix(code, GPU_DATATYPE_STR[i])) { if (GPU_DATATYPE_STR[i] && gpu_str_prefix(code, GPU_DATATYPE_STR[i])) {
type= i; type = i;
break; break;
} }
} }
@ -220,7 +222,7 @@ static char *gpu_generate_function_prototyps(GHash *hash)
function = BLI_ghashIterator_getValue(ghi); function = BLI_ghashIterator_getValue(ghi);
BLI_dynstr_appendf(ds, "void %s(", name); BLI_dynstr_appendf(ds, "void %s(", name);
for (a=0; a<function->totparam; a++) { for (a = 0; a < function->totparam; a++) {
if (function->paramqual[a] == FUNCTION_QUAL_OUT) if (function->paramqual[a] == FUNCTION_QUAL_OUT)
BLI_dynstr_append(ds, "out "); BLI_dynstr_append(ds, "out ");
else if (function->paramqual[a] == FUNCTION_QUAL_INOUT) else if (function->paramqual[a] == FUNCTION_QUAL_INOUT)
@ -232,9 +234,10 @@ static char *gpu_generate_function_prototyps(GHash *hash)
BLI_dynstr_append(ds, "sampler2DShadow"); BLI_dynstr_append(ds, "sampler2DShadow");
else else
BLI_dynstr_append(ds, GPU_DATATYPE_STR[function->paramtype[a]]); BLI_dynstr_append(ds, GPU_DATATYPE_STR[function->paramtype[a]]);
# if 0
//BLI_dynstr_appendf(ds, " param%d", a); BLI_dynstr_appendf(ds, " param%d", a);
# endif
if (a != function->totparam-1) if (a != function->totparam-1)
BLI_dynstr_append(ds, ", "); BLI_dynstr_append(ds, ", ");
} }
@ -267,7 +270,7 @@ void gpu_codegen_init(void)
void gpu_codegen_exit(void) void gpu_codegen_exit(void)
{ {
extern Material defmaterial; // render module abuse... extern Material defmaterial; /* render module abuse... */
if (defmaterial.gpumaterial.first) if (defmaterial.gpumaterial.first)
GPU_material_free(&defmaterial.gpumaterial); GPU_material_free(&defmaterial.gpumaterial);
@ -284,14 +287,16 @@ void gpu_codegen_exit(void)
glsl_material_library = NULL; glsl_material_library = NULL;
} }
/*if (FUNCTION_PROTOTYPES) { #if 0
if (FUNCTION_PROTOTYPES) {
MEM_freeN(FUNCTION_PROTOTYPES); MEM_freeN(FUNCTION_PROTOTYPES);
FUNCTION_PROTOTYPES = NULL; FUNCTION_PROTOTYPES = NULL;
}*/ }
/*if (FUNCTION_LIB) { if (FUNCTION_LIB) {
GPU_shader_free(FUNCTION_LIB); GPU_shader_free(FUNCTION_LIB);
FUNCTION_LIB = NULL; FUNCTION_LIB = NULL;
}*/ }
#endif
} }
/* GLSL code generation */ /* GLSL code generation */
@ -345,9 +350,9 @@ static void codegen_print_datatype(DynStr *ds, const GPUType type, float *data)
BLI_dynstr_appendf(ds, "%s(", GPU_DATATYPE_STR[type]); BLI_dynstr_appendf(ds, "%s(", GPU_DATATYPE_STR[type]);
for (i=0; i<type; i++) { for (i = 0; i < type; i++) {
BLI_dynstr_appendf(ds, "%f", data[i]); BLI_dynstr_appendf(ds, "%f", data[i]);
if (i == type-1) if (i == type - 1)
BLI_dynstr_append(ds, ")"); BLI_dynstr_append(ds, ")");
else else
BLI_dynstr_append(ds, ", "); BLI_dynstr_append(ds, ", ");
@ -412,11 +417,11 @@ static void codegen_set_unique_ids(ListBase *nodes)
GPUOutput *output; GPUOutput *output;
int id = 1, texid = 0; int id = 1, texid = 0;
bindhash= BLI_ghash_ptr_new("codegen_set_unique_ids1 gh"); bindhash = BLI_ghash_ptr_new("codegen_set_unique_ids1 gh");
definehash= BLI_ghash_ptr_new("codegen_set_unique_ids2 gh"); definehash = BLI_ghash_ptr_new("codegen_set_unique_ids2 gh");
for (node=nodes->first; node; node=node->next) { for (node = nodes->first; node; node = node->next) {
for (input=node->inputs.first; input; input=input->next) { for (input = node->inputs.first; input; input = input->next) {
/* set id for unique names of uniform variables */ /* set id for unique names of uniform variables */
input->id = id++; input->id = id++;
input->bindtex = false; input->bindtex = false;
@ -463,7 +468,7 @@ static void codegen_set_unique_ids(ListBase *nodes)
} }
} }
for (output=node->outputs.first; output; output=output->next) for (output = node->outputs.first; output; output = output->next)
/* set id for unique names of tmp variables storing output */ /* set id for unique names of tmp variables storing output */
output->id = id++; output->id = id++;
} }
@ -480,8 +485,8 @@ static int codegen_print_uniforms_functions(DynStr *ds, ListBase *nodes)
int builtins = 0; int builtins = 0;
/* print uniforms */ /* print uniforms */
for (node=nodes->first; node; node=node->next) { for (node = nodes->first; node; node = node->next) {
for (input=node->inputs.first; input; input=input->next) { for (input = node->inputs.first; input; input = input->next) {
if ((input->source == GPU_SOURCE_TEX) || (input->source == GPU_SOURCE_TEX_PIXEL)) { if ((input->source == GPU_SOURCE_TEX) || (input->source == GPU_SOURCE_TEX_PIXEL)) {
/* create exactly one sampler for each texture */ /* create exactly one sampler for each texture */
if (codegen_input_has_texture(input) && input->bindtex) if (codegen_input_has_texture(input) && input->bindtex)
@ -537,9 +542,9 @@ static void codegen_declare_tmps(DynStr *ds, ListBase *nodes)
GPUInput *input; GPUInput *input;
GPUOutput *output; GPUOutput *output;
for (node=nodes->first; node; node=node->next) { for (node = nodes->first; node; node = node->next) {
/* load pixels from textures */ /* load pixels from textures */
for (input=node->inputs.first; input; input=input->next) { for (input = node->inputs.first; input; input = input->next) {
if (input->source == GPU_SOURCE_TEX_PIXEL) { if (input->source == GPU_SOURCE_TEX_PIXEL) {
if (codegen_input_has_texture(input) && input->definetex) { if (codegen_input_has_texture(input) && input->definetex) {
BLI_dynstr_appendf(ds, "\tvec4 tex%d = texture2D(", input->texid); BLI_dynstr_appendf(ds, "\tvec4 tex%d = texture2D(", input->texid);
@ -550,7 +555,7 @@ static void codegen_declare_tmps(DynStr *ds, ListBase *nodes)
} }
/* declare temporary variables for node output storage */ /* declare temporary variables for node output storage */
for (output=node->outputs.first; output; output=output->next) for (output = node->outputs.first; output; output = output->next)
BLI_dynstr_appendf(ds, "\t%s tmp%d;\n", BLI_dynstr_appendf(ds, "\t%s tmp%d;\n",
GPU_DATATYPE_STR[output->type], output->id); GPU_DATATYPE_STR[output->type], output->id);
} }
@ -564,10 +569,10 @@ static void codegen_call_functions(DynStr *ds, ListBase *nodes, GPUOutput *final
GPUInput *input; GPUInput *input;
GPUOutput *output; GPUOutput *output;
for (node=nodes->first; node; node=node->next) { for (node = nodes->first; node; node = node->next) {
BLI_dynstr_appendf(ds, "\t%s(", node->name); BLI_dynstr_appendf(ds, "\t%s(", node->name);
for (input=node->inputs.first; input; input=input->next) { for (input = node->inputs.first; input; input = input->next) {
if (input->source == GPU_SOURCE_TEX) { if (input->source == GPU_SOURCE_TEX) {
BLI_dynstr_appendf(ds, "samp%d", input->texid); BLI_dynstr_appendf(ds, "samp%d", input->texid);
if (input->link) if (input->link)
@ -602,7 +607,7 @@ static void codegen_call_functions(DynStr *ds, ListBase *nodes, GPUOutput *final
BLI_dynstr_append(ds, ", "); BLI_dynstr_append(ds, ", ");
} }
for (output=node->outputs.first; output; output=output->next) { for (output = node->outputs.first; output; output = output->next) {
BLI_dynstr_appendf(ds, "tmp%d", output->id); BLI_dynstr_appendf(ds, "tmp%d", output->id);
if (output->next) if (output->next)
BLI_dynstr_append(ds, ", "); BLI_dynstr_append(ds, ", ");
@ -622,13 +627,17 @@ static char *code_generate_fragment(ListBase *nodes, GPUOutput *output)
char *code; char *code;
int builtins; int builtins;
/*BLI_dynstr_append(ds, FUNCTION_PROTOTYPES);*/ #if 0
BLI_dynstr_append(ds, FUNCTION_PROTOTYPES);
#endif
codegen_set_unique_ids(nodes); codegen_set_unique_ids(nodes);
builtins = codegen_print_uniforms_functions(ds, nodes); builtins = codegen_print_uniforms_functions(ds, nodes);
//if (G.debug & G_DEBUG) #if 0
// BLI_dynstr_appendf(ds, "/* %s */\n", name); if (G.debug & G_DEBUG)
BLI_dynstr_appendf(ds, "/* %s */\n", name);
#endif
BLI_dynstr_append(ds, "void main(void)\n"); BLI_dynstr_append(ds, "void main(void)\n");
BLI_dynstr_append(ds, "{\n"); BLI_dynstr_append(ds, "{\n");
@ -645,7 +654,9 @@ static char *code_generate_fragment(ListBase *nodes, GPUOutput *output)
code = BLI_dynstr_get_cstring(ds); code = BLI_dynstr_get_cstring(ds);
BLI_dynstr_free(ds); BLI_dynstr_free(ds);
//if (G.debug & G_DEBUG) printf("%s\n", code); #if 0
if (G.debug & G_DEBUG) printf("%s\n", code);
#endif
return code; return code;
} }
@ -658,8 +669,8 @@ static char *code_generate_vertex(ListBase *nodes, const GPUMatType type)
char *code; char *code;
char *vertcode; char *vertcode;
for (node=nodes->first; node; node=node->next) { for (node = nodes->first; node; node = node->next) {
for (input=node->inputs.first; input; input=input->next) { for (input = node->inputs.first; input; input = input->next) {
if (input->source == GPU_SOURCE_ATTRIB && input->attribfirst) { if (input->source == GPU_SOURCE_ATTRIB && input->attribfirst) {
BLI_dynstr_appendf(ds, "attribute %s att%d;\n", BLI_dynstr_appendf(ds, "attribute %s att%d;\n",
GPU_DATATYPE_STR[input->type], input->attribid); GPU_DATATYPE_STR[input->type], input->attribid);
@ -685,8 +696,8 @@ static char *code_generate_vertex(ListBase *nodes, const GPUMatType type)
BLI_dynstr_append(ds, vertcode); BLI_dynstr_append(ds, vertcode);
for (node=nodes->first; node; node=node->next) for (node = nodes->first; node; node = node->next)
for (input=node->inputs.first; input; input=input->next) for (input = node->inputs.first; input; input = input->next)
if (input->source == GPU_SOURCE_ATTRIB && input->attribfirst) { if (input->source == GPU_SOURCE_ATTRIB && input->attribfirst) {
if (input->attribtype == CD_TANGENT) { /* silly exception */ if (input->attribtype == CD_TANGENT) { /* silly exception */
BLI_dynstr_appendf(ds, "\tvar%d.xyz = normalize(gl_NormalMatrix * att%d.xyz);\n", input->attribid, input->attribid); BLI_dynstr_appendf(ds, "\tvar%d.xyz = normalize(gl_NormalMatrix * att%d.xyz);\n", input->attribid, input->attribid);
@ -714,7 +725,9 @@ static char *code_generate_vertex(ListBase *nodes, const GPUMatType type)
BLI_dynstr_free(ds); BLI_dynstr_free(ds);
//if (G.debug & G_DEBUG) printf("%s\n", code); #if 0
if (G.debug & G_DEBUG) printf("%s\n", code);
#endif
return code; return code;
} }
@ -760,9 +773,9 @@ static void gpu_nodes_extract_dynamic_inputs(GPUPass *pass, ListBase *nodes)
GPU_shader_bind(shader); GPU_shader_bind(shader);
for (node=nodes->first; node; node=node->next) { for (node = nodes->first; node; node = node->next) {
z = 0; z = 0;
for (input=node->inputs.first; input; input=next, z++) { for (input = node->inputs.first; input; input = next, z++) {
next = input->next; next = input->next;
/* attributes don't need to be bound, they already have /* attributes don't need to be bound, they already have
@ -815,7 +828,7 @@ void GPU_pass_bind(GPUPass *pass, double time, int mipmap)
GPU_shader_bind(shader); GPU_shader_bind(shader);
/* now bind the textures */ /* now bind the textures */
for (input=inputs->first; input; input=input->next) { for (input = inputs->first; input; input = input->next) {
if (input->ima) if (input->ima)
input->tex = GPU_texture_from_blender(input->ima, input->iuser, input->image_isdata, time, mipmap); input->tex = GPU_texture_from_blender(input->ima, input->iuser, input->image_isdata, time, mipmap);
else if (input->prv) else if (input->prv)
@ -839,7 +852,7 @@ void GPU_pass_update_uniforms(GPUPass *pass)
return; return;
/* pass dynamic inputs to opengl, others were removed */ /* pass dynamic inputs to opengl, others were removed */
for (input=inputs->first; input; input=input->next) for (input = inputs->first; input; input = input->next)
if (!(input->ima || input->tex || input->prv)) if (!(input->ima || input->tex || input->prv))
GPU_shader_uniform_vector(shader, input->shaderloc, input->type, 1, GPU_shader_uniform_vector(shader, input->shaderloc, input->type, 1,
input->dynamicvec); input->dynamicvec);
@ -854,7 +867,7 @@ void GPU_pass_unbind(GPUPass *pass)
if (!shader) if (!shader)
return; return;
for (input=inputs->first; input; input=input->next) { for (input = inputs->first; input; input = input->next) {
if (input->tex && input->bindtex) if (input->tex && input->bindtex)
GPU_texture_unbind(input->tex); GPU_texture_unbind(input->tex);
@ -896,7 +909,7 @@ static GPUNode *GPU_node_begin(const char *name)
{ {
GPUNode *node = MEM_callocN(sizeof(GPUNode), "GPUNode"); GPUNode *node = MEM_callocN(sizeof(GPUNode), "GPUNode");
node->name= name; node->name = name;
return node; return node;
} }
@ -965,7 +978,9 @@ static void gpu_node_input_link(GPUNode *node, GPUNodeLink *link, const GPUType
input->source = GPU_SOURCE_TEX; input->source = GPU_SOURCE_TEX;
input->textype = type; input->textype = type;
//input->tex = GPU_texture_create_2D(link->texturesize, link->texturesize, link->ptr2, NULL); #if 0
input->tex = GPU_texture_create_2D(link->texturesize, link->texturesize, link->ptr2, NULL);
#endif
input->tex = GPU_texture_create_2D(link->texturesize, 1, link->ptr1, GPU_HDR_NONE, NULL); input->tex = GPU_texture_create_2D(link->texturesize, 1, link->ptr1, GPU_HDR_NONE, NULL);
input->textarget = GL_TEXTURE_2D; input->textarget = GL_TEXTURE_2D;
@ -1004,9 +1019,9 @@ static void gpu_node_input_link(GPUNode *node, GPUNodeLink *link, const GPUType
memcpy(input->vec, link->ptr1, type*sizeof(float)); memcpy(input->vec, link->ptr1, type*sizeof(float));
if (link->dynamic) { if (link->dynamic) {
input->dynamicvec= link->ptr1; input->dynamicvec = link->ptr1;
input->dynamictype= link->dynamictype; input->dynamictype = link->dynamictype;
input->dynamicdata= link->ptr2; input->dynamicdata = link->ptr2;
} }
MEM_freeN(link); MEM_freeN(link);
} }
@ -1040,7 +1055,7 @@ static void gpu_node_output(GPUNode *node, const GPUType type, GPUNodeLink **lin
output->link->type = type; output->link->type = type;
output->link->output = output; output->link->output = output;
/* note: the caller owns the reference to the linkfer, GPUOutput /* note: the caller owns the reference to the link, GPUOutput
* merely points to it, and if the node is destroyed it will * merely points to it, and if the node is destroyed it will
* set that pointer to NULL */ * set that pointer to NULL */
} }
@ -1052,7 +1067,7 @@ static void gpu_inputs_free(ListBase *inputs)
{ {
GPUInput *input; GPUInput *input;
for (input=inputs->first; input; input=input->next) { for (input = inputs->first; input; input = input->next) {
if (input->link) if (input->link)
gpu_node_link_free(input->link); gpu_node_link_free(input->link);
else if (input->tex && !input->dynamictex) else if (input->tex && !input->dynamictex)
@ -1068,7 +1083,7 @@ static void gpu_node_free(GPUNode *node)
gpu_inputs_free(&node->inputs); gpu_inputs_free(&node->inputs);
for (output=node->outputs.first; output; output=output->next) for (output = node->outputs.first; output; output = output->next)
if (output->link) { if (output->link) {
output->link->output = NULL; output->link->output = NULL;
gpu_node_link_free(output->link); gpu_node_link_free(output->link);
@ -1100,10 +1115,10 @@ static void gpu_nodes_get_vertex_attributes(ListBase *nodes, GPUVertexAttribs *a
memset(attribs, 0, sizeof(*attribs)); memset(attribs, 0, sizeof(*attribs));
for (node=nodes->first; node; node=node->next) { for (node = nodes->first; node; node = node->next) {
for (input=node->inputs.first; input; input=input->next) { for (input = node->inputs.first; input; input = input->next) {
if (input->source == GPU_SOURCE_ATTRIB) { if (input->source == GPU_SOURCE_ATTRIB) {
for (a=0; a<attribs->totlayer; a++) { for (a = 0; a < attribs->totlayer; a++) {
if (attribs->layer[a].type == input->attribtype && if (attribs->layer[a].type == input->attribtype &&
STREQ(attribs->layer[a].name, input->attribname)) STREQ(attribs->layer[a].name, input->attribname))
{ {
@ -1135,10 +1150,10 @@ static void gpu_nodes_get_builtin_flag(ListBase *nodes, int *builtin)
GPUNode *node; GPUNode *node;
GPUInput *input; GPUInput *input;
*builtin= 0; *builtin = 0;
for (node=nodes->first; node; node=node->next) for (node = nodes->first; node; node = node->next)
for (input=node->inputs.first; input; input=input->next) for (input = node->inputs.first; input; input = input->next)
if (input->source == GPU_SOURCE_BUILTIN) if (input->source == GPU_SOURCE_BUILTIN)
*builtin |= input->builtin; *builtin |= input->builtin;
} }
@ -1149,8 +1164,8 @@ GPUNodeLink *GPU_attribute(const CustomDataType type, const char *name)
{ {
GPUNodeLink *link = GPU_node_link_create(); GPUNodeLink *link = GPU_node_link_create();
link->attribtype= type; link->attribtype = type;
link->attribname= name; link->attribname = name;
return link; return link;
} }
@ -1159,8 +1174,8 @@ GPUNodeLink *GPU_uniform(float *num)
{ {
GPUNodeLink *link = GPU_node_link_create(); GPUNodeLink *link = GPU_node_link_create();
link->ptr1= num; link->ptr1 = num;
link->ptr2= NULL; link->ptr2 = NULL;
return link; return link;
} }
@ -1169,9 +1184,9 @@ GPUNodeLink *GPU_dynamic_uniform(float *num, GPUDynamicType dynamictype, void *d
{ {
GPUNodeLink *link = GPU_node_link_create(); GPUNodeLink *link = GPU_node_link_create();
link->ptr1= num; link->ptr1 = num;
link->ptr2= data; link->ptr2 = data;
link->dynamic= true; link->dynamic = true;
link->dynamictype = dynamictype; link->dynamictype = dynamictype;
@ -1194,8 +1209,8 @@ GPUNodeLink *GPU_image_preview(PreviewImage *prv)
{ {
GPUNodeLink *link = GPU_node_link_create(); GPUNodeLink *link = GPU_node_link_create();
link->image= GPU_NODE_LINK_IMAGE_PREVIEW; link->image = GPU_NODE_LINK_IMAGE_PREVIEW;
link->ptr1= prv; link->ptr1 = prv;
return link; return link;
} }
@ -1207,7 +1222,7 @@ GPUNodeLink *GPU_texture(int size, float *pixels)
link->texture = true; link->texture = true;
link->texturesize = size; link->texturesize = size;
link->ptr1= pixels; link->ptr1 = pixels;
return link; return link;
} }
@ -1259,13 +1274,13 @@ bool GPU_link(GPUMaterial *mat, const char *name, ...)
node = GPU_node_begin(name); node = GPU_node_begin(name);
va_start(params, name); va_start(params, name);
for (i=0; i<function->totparam; i++) { for (i = 0; i<function->totparam; i++) {
if (function->paramqual[i] != FUNCTION_QUAL_IN) { if (function->paramqual[i] != FUNCTION_QUAL_IN) {
linkptr= va_arg(params, GPUNodeLink**); linkptr = va_arg(params, GPUNodeLink**);
gpu_node_output(node, function->paramtype[i], linkptr); gpu_node_output(node, function->paramtype[i], linkptr);
} }
else { else {
link= va_arg(params, GPUNodeLink*); link = va_arg(params, GPUNodeLink*);
gpu_node_input_link(node, link, function->paramtype[i]); gpu_node_input_link(node, link, function->paramtype[i]);
} }
} }
@ -1309,10 +1324,10 @@ bool GPU_stack_link(GPUMaterial *mat, const char *name, GPUNodeStack *in, GPUNod
} }
va_start(params, out); va_start(params, out);
for (i=0; i<function->totparam; i++) { for (i = 0; i<function->totparam; i++) {
if (function->paramqual[i] != FUNCTION_QUAL_IN) { if (function->paramqual[i] != FUNCTION_QUAL_IN) {
if (totout == 0) { if (totout == 0) {
linkptr= va_arg(params, GPUNodeLink**); linkptr = va_arg(params, GPUNodeLink**);
gpu_node_output(node, function->paramtype[i], linkptr); gpu_node_output(node, function->paramtype[i], linkptr);
} }
else else
@ -1320,7 +1335,7 @@ bool GPU_stack_link(GPUMaterial *mat, const char *name, GPUNodeStack *in, GPUNod
} }
else { else {
if (totin == 0) { if (totin == 0) {
link= va_arg(params, GPUNodeLink*); link = va_arg(params, GPUNodeLink*);
if (link->socket) if (link->socket)
gpu_node_input_socket(node, link->socket); gpu_node_input_socket(node, link->socket);
else else
@ -1373,7 +1388,7 @@ static void gpu_nodes_tag(GPUNodeLink *link)
return; return;
node->tag = true; node->tag = true;
for (input=node->inputs.first; input; input=input->next) for (input = node->inputs.first; input; input = input->next)
if (input->link) if (input->link)
gpu_nodes_tag(input->link); gpu_nodes_tag(input->link);
} }
@ -1382,12 +1397,12 @@ static void gpu_nodes_prune(ListBase *nodes, GPUNodeLink *outlink)
{ {
GPUNode *node, *next; GPUNode *node, *next;
for (node=nodes->first; node; node=node->next) for (node = nodes->first; node; node = node->next)
node->tag = false; node->tag = false;
gpu_nodes_tag(outlink); gpu_nodes_tag(outlink);
for (node=nodes->first; node; node=next) { for (node = nodes->first; node; node = next) {
next = node->next; next = node->next;
if (!node->tag) { if (!node->tag) {
@ -1405,10 +1420,12 @@ GPUPass *GPU_generate_pass(ListBase *nodes, GPUNodeLink *outlink,
GPUPass *pass; GPUPass *pass;
char *vertexcode, *fragmentcode; char *vertexcode, *fragmentcode;
/*if (!FUNCTION_LIB) { #if 0
if (!FUNCTION_LIB) {
GPU_nodes_free(nodes); GPU_nodes_free(nodes);
return NULL; return NULL;
}*/ }
#endif
/* prune unused nodes */ /* prune unused nodes */
gpu_nodes_prune(nodes, outlink); gpu_nodes_prune(nodes, outlink);

@ -113,9 +113,9 @@ typedef struct GPUOutput {
struct GPUOutput *next, *prev; struct GPUOutput *next, *prev;
GPUNode *node; GPUNode *node;
GPUType type; /* data type = length of vector/matrix */ GPUType type; /* data type = length of vector/matrix */
GPUNodeLink *link; /* output link */ GPUNodeLink *link; /* output link */
int id; /* unique id as created by code generator */ int id; /* unique id as created by code generator */
} GPUOutput; } GPUOutput;
typedef struct GPUInput { typedef struct GPUInput {
@ -123,35 +123,35 @@ typedef struct GPUInput {
GPUNode *node; GPUNode *node;
GPUType type; /* datatype */ GPUType type; /* datatype */
GPUDataSource source; /* data source */ GPUDataSource source; /* data source */
int id; /* unique id as created by code generator */ int id; /* unique id as created by code generator */
int texid; /* number for multitexture, starting from zero */ int texid; /* number for multitexture, starting from zero */
int attribid; /* id for vertex attributes */ int attribid; /* id for vertex attributes */
bool bindtex; /* input is responsible for binding the texture? */ bool bindtex; /* input is responsible for binding the texture? */
bool definetex; /* input is responsible for defining the pixel? */ bool definetex; /* input is responsible for defining the pixel? */
int textarget; /* GL texture target, e.g. GL_TEXTURE_2D */ int textarget; /* GL texture target, e.g. GL_TEXTURE_2D */
GPUType textype; /* datatype */ GPUType textype; /* datatype */
struct Image *ima; /* image */ struct Image *ima; /* image */
struct ImageUser *iuser;/* image user */ struct ImageUser *iuser; /* image user */
struct PreviewImage *prv; /* preview images & icons */ struct PreviewImage *prv; /* preview images & icons */
bool image_isdata; /* image does not contain color data */ bool image_isdata; /* image does not contain color data */
float *dynamicvec; /* vector data in case it is dynamic */ float *dynamicvec; /* vector data in case it is dynamic */
GPUDynamicType dynamictype; /* origin of the dynamic uniform */ GPUDynamicType dynamictype; /* origin of the dynamic uniform */
void *dynamicdata; /* data source of the dynamic uniform */ void *dynamicdata; /* data source of the dynamic uniform */
struct GPUTexture *tex; /* input texture, only set at runtime */ struct GPUTexture *tex; /* input texture, only set at runtime */
int shaderloc; /* id from opengl */ int shaderloc; /* id from opengl */
char shadername[32]; /* name in shader */ char shadername[32]; /* name in shader */
float vec[16]; /* vector data */ float vec[16]; /* vector data */
GPUNodeLink *link; GPUNodeLink *link;
bool dynamictex; /* dynamic? */ bool dynamictex; /* dynamic? */
CustomDataType attribtype; /* attribute type */ CustomDataType attribtype; /* attribute type */
char attribname[MAX_CUSTOMDATA_LAYER_NAME]; /* attribute name */ char attribname[MAX_CUSTOMDATA_LAYER_NAME]; /* attribute name */
int attribfirst; /* this is the first one that is bound */ int attribfirst; /* this is the first one that is bound */
GPUBuiltin builtin; /* builtin uniform */ GPUBuiltin builtin; /* builtin uniform */
GPUOpenGLBuiltin oglbuiltin; /* opengl built in varying */ GPUOpenGLBuiltin oglbuiltin; /* opengl built in varying */
} GPUInput; } GPUInput;
@ -170,8 +170,8 @@ struct GPUPass {
typedef struct GPUPass GPUPass; typedef struct GPUPass GPUPass;
GPUPass *GPU_generate_pass(ListBase *nodes, struct GPUNodeLink *outlink, GPUPass *GPU_generate_pass(ListBase *nodes, struct GPUNodeLink *outlink,
struct GPUVertexAttribs *attribs, int *builtin, struct GPUVertexAttribs *attribs, int *builtin,
const GPUMatType type, const char *name); const GPUMatType type, const char *name);
struct GPUShader *GPU_pass_shader(GPUPass *pass); struct GPUShader *GPU_pass_shader(GPUPass *pass);

@ -469,7 +469,7 @@ bool GPU_fx_compositor_initialize_passes(
} }
} }
fx->dof_high_quality = dof_high_quality && GPU_geometry_shader_support() && GPU_instanced_drawing_support(); fx->dof_high_quality = dof_high_quality && GPU_geometry_shader_support() && GPU_instanced_drawing_support();
} }
else { else {
/* cleanup unnecessary buffers */ /* cleanup unnecessary buffers */
@ -478,7 +478,7 @@ bool GPU_fx_compositor_initialize_passes(
/* we need to pass data between shader stages, allocate an extra color buffer */ /* we need to pass data between shader stages, allocate an extra color buffer */
if (num_passes > 1) { if (num_passes > 1) {
if(!fx->color_buffer_sec) { if (!fx->color_buffer_sec) {
if (!(fx->color_buffer_sec = GPU_texture_create_2D(w, h, NULL, GPU_HDR_NONE, err_out))) { if (!(fx->color_buffer_sec = GPU_texture_create_2D(w, h, NULL, GPU_HDR_NONE, err_out))) {
printf(".256%s\n", err_out); printf(".256%s\n", err_out);
cleanup_fx_gl_data(fx, true); cleanup_fx_gl_data(fx, true);
@ -497,13 +497,13 @@ bool GPU_fx_compositor_initialize_passes(
/* bind the buffers */ /* bind the buffers */
/* first depth buffer, because system assumes read/write buffers */ /* first depth buffer, because system assumes read/write buffers */
if(!GPU_framebuffer_texture_attach(fx->gbuffer, fx->depth_buffer, 0, err_out)) if (!GPU_framebuffer_texture_attach(fx->gbuffer, fx->depth_buffer, 0, err_out))
printf("%.256s\n", err_out); printf("%.256s\n", err_out);
if(!GPU_framebuffer_texture_attach(fx->gbuffer, fx->color_buffer, 0, err_out)) if (!GPU_framebuffer_texture_attach(fx->gbuffer, fx->color_buffer, 0, err_out))
printf("%.256s\n", err_out); printf("%.256s\n", err_out);
if(!GPU_framebuffer_check_valid(fx->gbuffer, err_out)) if (!GPU_framebuffer_check_valid(fx->gbuffer, err_out))
printf("%.256s\n", err_out); printf("%.256s\n", err_out);
GPU_texture_bind_as_framebuffer(fx->color_buffer); GPU_texture_bind_as_framebuffer(fx->color_buffer);
@ -573,7 +573,7 @@ void GPU_fx_compositor_setup_XRay_pass(GPUFX *fx, bool do_xray)
GPU_framebuffer_texture_detach(fx->depth_buffer); GPU_framebuffer_texture_detach(fx->depth_buffer);
/* first depth buffer, because system assumes read/write buffers */ /* first depth buffer, because system assumes read/write buffers */
if(!GPU_framebuffer_texture_attach(fx->gbuffer, fx->depth_buffer_xray, 0, err_out)) if (!GPU_framebuffer_texture_attach(fx->gbuffer, fx->depth_buffer_xray, 0, err_out))
printf("%.256s\n", err_out); printf("%.256s\n", err_out);
} }

@ -45,7 +45,7 @@
static const char* gpu_gl_error_symbol(GLenum err) static const char* gpu_gl_error_symbol(GLenum err)
{ {
switch(err) { switch (err) {
CASE_CODE_RETURN_STR(GL_NO_ERROR) CASE_CODE_RETURN_STR(GL_NO_ERROR)
CASE_CODE_RETURN_STR(GL_INVALID_ENUM) CASE_CODE_RETURN_STR(GL_INVALID_ENUM)
CASE_CODE_RETURN_STR(GL_INVALID_VALUE) CASE_CODE_RETURN_STR(GL_INVALID_VALUE)
@ -109,7 +109,7 @@ static bool gpu_report_gl_errors(const char *file, int line, const char *str)
const char* gpuErrorString(GLenum err) const char* gpuErrorString(GLenum err)
{ {
switch(err) { switch (err) {
case GL_NO_ERROR: case GL_NO_ERROR:
return "No Error"; return "No Error";

File diff suppressed because it is too large Load Diff

@ -164,7 +164,7 @@ void gpu_extensions_init(void)
glGetIntegerv(GL_RED_BITS, &r); glGetIntegerv(GL_RED_BITS, &r);
glGetIntegerv(GL_GREEN_BITS, &g); glGetIntegerv(GL_GREEN_BITS, &g);
glGetIntegerv(GL_BLUE_BITS, &b); glGetIntegerv(GL_BLUE_BITS, &b);
GG.colordepth = r+g+b; /* assumes same depth for RGB */ GG.colordepth = r + g + b; /* assumes same depth for RGB */
vendor = (const char *)glGetString(GL_VENDOR); vendor = (const char *)glGetString(GL_VENDOR);
renderer = (const char *)glGetString(GL_RENDERER); renderer = (const char *)glGetString(GL_RENDERER);
@ -299,34 +299,34 @@ int GPU_color_depth(void)
static void GPU_print_framebuffer_error(GLenum status, char err_out[256]) static void GPU_print_framebuffer_error(GLenum status, char err_out[256])
{ {
const char *err= "unknown"; const char *err = "unknown";
switch (status) { switch (status) {
case GL_FRAMEBUFFER_COMPLETE_EXT: case GL_FRAMEBUFFER_COMPLETE_EXT:
break; break;
case GL_INVALID_OPERATION: case GL_INVALID_OPERATION:
err= "Invalid operation"; err = "Invalid operation";
break; break;
case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT: case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT:
err= "Incomplete attachment"; err = "Incomplete attachment";
break; break;
case GL_FRAMEBUFFER_UNSUPPORTED_EXT: case GL_FRAMEBUFFER_UNSUPPORTED_EXT:
err= "Unsupported framebuffer format"; err = "Unsupported framebuffer format";
break; break;
case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT: case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT:
err= "Missing attachment"; err = "Missing attachment";
break; break;
case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT: case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT:
err= "Attached images must have same dimensions"; err = "Attached images must have same dimensions";
break; break;
case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT: case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT:
err= "Attached images must have same format"; err = "Attached images must have same format";
break; break;
case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT: case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT:
err= "Missing draw buffer"; err = "Missing draw buffer";
break; break;
case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT: case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT:
err= "Missing read buffer"; err = "Missing read buffer";
break; break;
} }
@ -343,36 +343,36 @@ static void GPU_print_framebuffer_error(GLenum status, char err_out[256])
/* GPUTexture */ /* GPUTexture */
struct GPUTexture { struct GPUTexture {
int w, h; /* width/height */ int w, h; /* width/height */
int number; /* number for multitexture binding */ int number; /* number for multitexture binding */
int refcount; /* reference count */ int refcount; /* reference count */
GLenum target; /* GL_TEXTURE_* */ GLenum target; /* GL_TEXTURE_* */
GLuint bindcode; /* opengl identifier for texture */ GLuint bindcode; /* opengl identifier for texture */
int fromblender; /* we got the texture from Blender */ int fromblender; /* we got the texture from Blender */
GPUFrameBuffer *fb; /* GPUFramebuffer this texture is attached to */ GPUFrameBuffer *fb; /* GPUFramebuffer this texture is attached to */
int fb_attachment; /* slot the texture is attached to */ int fb_attachment; /* slot the texture is attached to */
int depth; /* is a depth texture? if 3D how deep? */ int depth; /* is a depth texture? if 3D how deep? */
}; };
static unsigned char *GPU_texture_convert_pixels(int length, const float *fpixels) static unsigned char *GPU_texture_convert_pixels(int length, const float *fpixels)
{ {
unsigned char *pixels, *p; unsigned char *pixels, *p;
const float *fp = fpixels; const float *fp = fpixels;
const int len = 4*length; const int len = 4 * length;
int a; int a;
p = pixels = MEM_callocN(sizeof(unsigned char)*len, "GPUTexturePixels"); p = pixels = MEM_callocN(sizeof(unsigned char) * len, "GPUTexturePixels");
for (a=0; a<len; a++, p++, fp++) for (a = 0; a < len; a++, p++, fp++)
*p = FTOCHAR(*fp); *p = FTOCHAR((*fp));
return pixels; return pixels;
} }
static void GPU_glTexSubImageEmpty(GLenum target, GLenum format, int x, int y, int w, int h) static void GPU_glTexSubImageEmpty(GLenum target, GLenum format, int x, int y, int w, int h)
{ {
void *pixels = MEM_callocN(sizeof(char)*4*w*h, "GPUTextureEmptyPixels"); void *pixels = MEM_callocN(sizeof(char) * 4 * w * h, "GPUTextureEmptyPixels");
if (target == GL_TEXTURE_1D) if (target == GL_TEXTURE_1D)
glTexSubImage1D(target, 0, x, w, format, GL_UNSIGNED_BYTE, pixels); glTexSubImage1D(target, 0, x, w, format, GL_UNSIGNED_BYTE, pixels);
@ -573,8 +573,10 @@ GPUTexture *GPU_texture_create_3D(int w, int h, int depth, int channels, const f
internalformat = GL_INTENSITY; internalformat = GL_INTENSITY;
} }
//if (fpixels) #if 0
// pixels = GPU_texture_convert_pixels(w*h*depth, fpixels); if (fpixels)
pixels = GPU_texture_convert_pixels(w*h*depth, fpixels);
#endif
glTexImage3D(tex->target, 0, internalformat, tex->w, tex->h, tex->depth, 0, format, type, NULL); glTexImage3D(tex->target, 0, internalformat, tex->w, tex->h, tex->depth, 0, format, type, NULL);
@ -972,7 +974,7 @@ GPUFrameBuffer *GPU_framebuffer_create(void)
if (!GLEW_EXT_framebuffer_object) if (!GLEW_EXT_framebuffer_object)
return NULL; return NULL;
fb= MEM_callocN(sizeof(GPUFrameBuffer), "GPUFrameBuffer"); fb = MEM_callocN(sizeof(GPUFrameBuffer), "GPUFrameBuffer");
glGenFramebuffersEXT(1, &fb->object); glGenFramebuffersEXT(1, &fb->object);
if (!fb->object) { if (!fb->object) {
@ -1065,8 +1067,7 @@ void GPU_framebuffer_texture_detach(GPUTexture *tex)
attachment = GL_COLOR_ATTACHMENT0_EXT + tex->fb_attachment; attachment = GL_COLOR_ATTACHMENT0_EXT + tex->fb_attachment;
} }
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, attachment, glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, attachment, tex->target, 0, 0);
tex->target, 0, 0);
tex->fb = NULL; tex->fb = NULL;
tex->fb_attachment = -1; tex->fb_attachment = -1;
@ -1116,7 +1117,7 @@ void GPU_framebuffer_slots_bind(GPUFrameBuffer *fb, int slot)
return; return;
} }
for (i = 0 ; i < 4; i++) { for (i = 0; i < 4; i++) {
if (fb->colortex[i]) { if (fb->colortex[i]) {
attachments[numslots] = GL_COLOR_ATTACHMENT0_EXT + i; attachments[numslots] = GL_COLOR_ATTACHMENT0_EXT + i;
numslots++; numslots++;
@ -1306,7 +1307,7 @@ GPUOffScreen *GPU_offscreen_create(int width, int height, char err_out[256])
{ {
GPUOffScreen *ofs; GPUOffScreen *ofs;
ofs= MEM_callocN(sizeof(GPUOffScreen), "GPUOffScreen"); ofs = MEM_callocN(sizeof(GPUOffScreen), "GPUOffScreen");
ofs->fb = GPU_framebuffer_create(); ofs->fb = GPU_framebuffer_create();
if (!ofs->fb) { if (!ofs->fb) {
@ -1395,13 +1396,13 @@ int GPU_offscreen_height(const GPUOffScreen *ofs)
/* GPUShader */ /* GPUShader */
struct GPUShader { struct GPUShader {
GLhandleARB object; /* handle for full shader */ GLhandleARB object; /* handle for full shader */
GLhandleARB vertex; /* handle for vertex shader */ GLhandleARB vertex; /* handle for vertex shader */
GLhandleARB fragment; /* handle for fragment shader */ GLhandleARB fragment; /* handle for fragment shader */
GLhandleARB geometry; /* handle for geometry shader */ GLhandleARB geometry; /* handle for geometry shader */
GLhandleARB lib; /* handle for libment shader */ GLhandleARB lib; /* handle for libment shader */
int totattrib; /* total number of attributes */ int totattrib; /* total number of attributes */
int uniforms; /* required uniforms */ int uniforms; /* required uniforms */
}; };
static void shader_print_errors(const char *task, char *log, const char **code, int totcode) static void shader_print_errors(const char *task, char *log, const char **code, int totcode)
@ -1420,8 +1421,8 @@ static void shader_print_errors(const char *task, char *log, const char **code,
c = code[i]; c = code[i];
while ((c < end) && (pos = strchr(c, '\n'))) { while ((c < end) && (pos = strchr(c, '\n'))) {
fprintf(stderr, "%2d ", line); fprintf(stderr, "%2d ", line);
fwrite(c, (pos+1)-c, 1, stderr); fwrite(c, (pos + 1) - c, 1, stderr);
c = pos+1; c = pos + 1;
line++; line++;
} }
@ -1447,7 +1448,7 @@ static const char *gpu_shader_version(void)
static void gpu_shader_standard_extensions(char defines[MAX_EXT_DEFINE_LENGTH]) static void gpu_shader_standard_extensions(char defines[MAX_EXT_DEFINE_LENGTH])
{ {
/* need this extensions for high quality bump mapping */ /* need this extension for high quality bump mapping */
if (GPU_bicubic_bump_support()) if (GPU_bicubic_bump_support())
strcat(defines, "#extension GL_ARB_texture_query_lod: enable\n"); strcat(defines, "#extension GL_ARB_texture_query_lod: enable\n");
@ -1818,7 +1819,7 @@ GPUShader *GPU_shader_get_builtin_fx_shader(int effects, bool persp)
if (!GG.shaders.fx_shaders[offset]) { if (!GG.shaders.fx_shaders[offset]) {
GPUShader *shader; GPUShader *shader;
switch(effects) { switch (effects) {
case GPU_SHADER_FX_SSAO: case GPU_SHADER_FX_SSAO:
GG.shaders.fx_shaders[offset] = GPU_shader_create(datatoc_gpu_shader_fx_vert_glsl, datatoc_gpu_shader_fx_ssao_frag_glsl, NULL, datatoc_gpu_shader_fx_lib_glsl, defines, 0, 0, 0); GG.shaders.fx_shaders[offset] = GPU_shader_create(datatoc_gpu_shader_fx_vert_glsl, datatoc_gpu_shader_fx_ssao_frag_glsl, NULL, datatoc_gpu_shader_fx_lib_glsl, defines, 0, 0, 0);
break; break;
@ -1896,7 +1897,8 @@ void GPU_shader_free_builtin_shaders(void)
} }
} }
#if 0 #if 0 /* unused */
/* GPUPixelBuffer */ /* GPUPixelBuffer */
typedef struct GPUPixelBuffer { typedef struct GPUPixelBuffer {
@ -1922,7 +1924,7 @@ GPUPixelBuffer *gpu_pixelbuffer_create(int x, int y, int halffloat, int numbuffe
return NULL; return NULL;
pb = MEM_callocN(sizeof(GPUPixelBuffer), "GPUPBO"); pb = MEM_callocN(sizeof(GPUPixelBuffer), "GPUPBO");
pb->datasize = x*y*4*((halffloat)? 16: 8); pb->datasize = x * y * 4 * (halffloat ? 16 : 8);
pb->numbuffers = numbuffers; pb->numbuffers = numbuffers;
pb->halffloat = halffloat; pb->halffloat = halffloat;
@ -1950,10 +1952,13 @@ void GPU_pixelbuffer_texture(GPUTexture *tex, GPUPixelBuffer *pb)
GL_STREAM_DRAW_ARB); GL_STREAM_DRAW_ARB);
pixels = glMapBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, GL_WRITE_ONLY); pixels = glMapBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, GL_WRITE_ONLY);
/*memcpy(pixels, _oImage.data(), pb->datasize);*/
# if 0
memcpy(pixels, _oImage.data(), pb->datasize);
# endif
if (!glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT)) { if (!glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT)) {
fprintf(stderr, "Could not unmap opengl PBO\n"); fprintf(stderr, "Could not unmap OpenGL PBO\n");
break; break;
} }
} }
@ -1971,7 +1976,7 @@ static int pixelbuffer_map_into_gpu(GLuint bindcode)
/* do stuff in pixels */ /* do stuff in pixels */
if (!glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT)) { if (!glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT)) {
fprintf(stderr, "Could not unmap opengl PBO\n"); fprintf(stderr, "Could not unmap OpenGL PBO\n");
return 0; return 0;
} }
@ -1984,8 +1989,7 @@ static void pixelbuffer_copy_to_texture(GPUTexture *tex, GPUPixelBuffer *pb, GLu
glBindTexture(GL_TEXTURE_RECTANGLE_EXT, tex->bindcode); glBindTexture(GL_TEXTURE_RECTANGLE_EXT, tex->bindcode);
glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, bindcode); glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, bindcode);
glTexSubImage2D(GL_TEXTURE_RECTANGLE_EXT, 0, 0, 0, tex->w, tex->h, glTexSubImage2D(GL_TEXTURE_RECTANGLE_EXT, 0, 0, 0, tex->w, tex->h, GL_RGBA, type, NULL);
GL_RGBA, type, NULL);
glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, 0); glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, 0);
glBindTexture(GL_TEXTURE_RECTANGLE_EXT, 0); glBindTexture(GL_TEXTURE_RECTANGLE_EXT, 0);
@ -2000,12 +2004,12 @@ void GPU_pixelbuffer_async_to_gpu(GPUTexture *tex, GPUPixelBuffer *pb)
pixelbuffer_map_into_gpu(pb->bindcode[0]); pixelbuffer_map_into_gpu(pb->bindcode[0]);
} }
else { else {
pb->current = (pb->current+1)%pb->numbuffers; pb->current = (pb->current + 1) % pb->numbuffers;
newbuffer = (pb->current+1)%pb->numbuffers; newbuffer = (pb->current + 1) % pb->numbuffers;
pixelbuffer_map_into_gpu(pb->bindcode[newbuffer]); pixelbuffer_map_into_gpu(pb->bindcode[newbuffer]);
pixelbuffer_copy_to_texture(tex, pb, pb->bindcode[pb->current]); pixelbuffer_copy_to_texture(tex, pb, pb->bindcode[pb->current]);
} }
} }
#endif #endif /* unused */

@ -157,7 +157,7 @@ static GPUMaterial *GPU_material_construct_begin(Material *ma)
{ {
GPUMaterial *material = MEM_callocN(sizeof(GPUMaterial), "GPUMaterial"); GPUMaterial *material = MEM_callocN(sizeof(GPUMaterial), "GPUMaterial");
material->ma= ma; material->ma = ma;
return material; return material;
} }
@ -170,14 +170,14 @@ static void gpu_material_set_attrib_id(GPUMaterial *material)
char name[32]; char name[32];
int a, b; int a, b;
attribs= &material->attribs; attribs = &material->attribs;
pass= material->pass; pass = material->pass;
if (!pass) { if (!pass) {
attribs->totlayer = 0; attribs->totlayer = 0;
return; return;
} }
shader= GPU_pass_shader(pass); shader = GPU_pass_shader(pass);
if (!shader) { if (!shader) {
attribs->totlayer = 0; attribs->totlayer = 0;
return; return;
@ -187,7 +187,7 @@ static void gpu_material_set_attrib_id(GPUMaterial *material)
* in case the attrib does not get a valid index back, it was probably * in case the attrib does not get a valid index back, it was probably
* removed by the glsl compiler by dead code elimination */ * removed by the glsl compiler by dead code elimination */
for (a=0, b=0; a<attribs->totlayer; a++) { for (a = 0, b = 0; a < attribs->totlayer; a++) {
BLI_snprintf(name, sizeof(name), "att%d", attribs->layer[a].attribid); BLI_snprintf(name, sizeof(name), "att%d", attribs->layer[a].attribid);
attribs->layer[a].glindex = GPU_shader_get_attribute(shader, name); attribs->layer[a].glindex = GPU_shader_get_attribute(shader, name);
@ -242,19 +242,19 @@ void GPU_material_free(ListBase *gpumaterial)
LinkData *link; LinkData *link;
LinkData *nlink, *mlink, *next; LinkData *nlink, *mlink, *next;
for (link=gpumaterial->first; link; link=link->next) { for (link = gpumaterial->first; link; link = link->next) {
GPUMaterial *material = link->data; GPUMaterial *material = link->data;
if (material->pass) if (material->pass)
GPU_pass_free(material->pass); GPU_pass_free(material->pass);
for (nlink=material->lamps.first; nlink; nlink=nlink->next) { for (nlink = material->lamps.first; nlink; nlink = nlink->next) {
GPULamp *lamp = nlink->data; GPULamp *lamp = nlink->data;
if (material->ma) { if (material->ma) {
Material *ma = material->ma; Material *ma = material->ma;
for (mlink=lamp->materials.first; mlink; mlink=next) { for (mlink = lamp->materials.first; mlink; mlink = next) {
next = mlink->next; next = mlink->next;
if (mlink->data == ma) if (mlink->data == ma)
BLI_freelinkN(&lamp->materials, mlink); BLI_freelinkN(&lamp->materials, mlink);
@ -293,8 +293,8 @@ void GPU_material_bind(GPUMaterial *material, int oblay, int viewlay, double tim
/* handle layer lamps */ /* handle layer lamps */
if (material->type == GPU_MATERIAL_TYPE_MESH) { if (material->type == GPU_MATERIAL_TYPE_MESH) {
for (nlink=material->lamps.first; nlink; nlink=nlink->next) { for (nlink = material->lamps.first; nlink; nlink = nlink->next) {
lamp= nlink->data; lamp = nlink->data;
if (!lamp->hide && (lamp->lay & viewlay) && (!(lamp->mode & LA_LAYER) || (lamp->lay & oblay)) if (!lamp->hide && (lamp->lay & viewlay) && (!(lamp->mode & LA_LAYER) || (lamp->lay & oblay))
&& GPU_lamp_override_visible(lamp, srl, material->ma)) { && GPU_lamp_override_visible(lamp, srl, material->ma)) {
@ -303,7 +303,7 @@ void GPU_material_bind(GPUMaterial *material, int oblay, int viewlay, double tim
} }
else { else {
lamp->dynenergy = 0.0f; lamp->dynenergy = 0.0f;
lamp->dyncol[0]= lamp->dyncol[1]= lamp->dyncol[2] = 0.0f; lamp->dyncol[0] = lamp->dyncol[1] = lamp->dyncol[2] = 0.0f;
} }
if (material->dynproperty & DYN_LAMP_VEC) { if (material->dynproperty & DYN_LAMP_VEC) {
@ -414,12 +414,12 @@ void GPU_material_vertex_attributes(GPUMaterial *material, GPUVertexAttribs *att
void GPU_material_output_link(GPUMaterial *material, GPUNodeLink *link) void GPU_material_output_link(GPUMaterial *material, GPUNodeLink *link)
{ {
if (!material->outlink) if (!material->outlink)
material->outlink= link; material->outlink = link;
} }
void GPU_material_enable_alpha(GPUMaterial *material) void GPU_material_enable_alpha(GPUMaterial *material)
{ {
material->alpha= 1; material->alpha = 1;
} }
GPUBlendMode GPU_material_alpha_blend(GPUMaterial *material, float obcol[4]) GPUBlendMode GPU_material_alpha_blend(GPUMaterial *material, float obcol[4])
@ -455,7 +455,7 @@ static GPUNodeLink *lamp_get_visibility(GPUMaterial *mat, GPULamp *lamp, GPUNode
GPUNodeLink *visifac, *inpr; GPUNodeLink *visifac, *inpr;
/* from get_lamp_visibility */ /* from get_lamp_visibility */
if (lamp->type==LA_SUN || lamp->type==LA_HEMI) { if (lamp->type == LA_SUN || lamp->type == LA_HEMI) {
mat->dynproperty |= DYN_LAMP_VEC; mat->dynproperty |= DYN_LAMP_VEC;
GPU_link(mat, "lamp_visibility_sun_hemi", GPU_dynamic_uniform(lamp->dynvec, GPU_DYNAMIC_LAMP_DYNVEC, lamp->ob), lv, dist, &visifac); GPU_link(mat, "lamp_visibility_sun_hemi", GPU_dynamic_uniform(lamp->dynvec, GPU_DYNAMIC_LAMP_DYNVEC, lamp->ob), lv, dist, &visifac);
return visifac; return visifac;
@ -464,7 +464,7 @@ static GPUNodeLink *lamp_get_visibility(GPUMaterial *mat, GPULamp *lamp, GPUNode
mat->dynproperty |= DYN_LAMP_CO; mat->dynproperty |= DYN_LAMP_CO;
GPU_link(mat, "lamp_visibility_other", GPU_builtin(GPU_VIEW_POSITION), GPU_dynamic_uniform(lamp->dynco, GPU_DYNAMIC_LAMP_DYNCO, lamp->ob), lv, dist, &visifac); GPU_link(mat, "lamp_visibility_other", GPU_builtin(GPU_VIEW_POSITION), GPU_dynamic_uniform(lamp->dynco, GPU_DYNAMIC_LAMP_DYNCO, lamp->ob), lv, dist, &visifac);
if (lamp->type==LA_AREA) if (lamp->type == LA_AREA)
return visifac; return visifac;
switch (lamp->falloff_type) { switch (lamp->falloff_type) {
@ -480,15 +480,16 @@ static GPUNodeLink *lamp_get_visibility(GPUMaterial *mat, GPULamp *lamp, GPUNode
GPU_link(mat, "lamp_falloff_sliders", GPU_dynamic_uniform(&lamp->dist, GPU_DYNAMIC_LAMP_DISTANCE, lamp->ob), GPU_dynamic_uniform(&lamp->att1, GPU_DYNAMIC_LAMP_ATT1, lamp->ob), GPU_dynamic_uniform(&lamp->att2, GPU_DYNAMIC_LAMP_ATT2, lamp->ob), *dist, &visifac); GPU_link(mat, "lamp_falloff_sliders", GPU_dynamic_uniform(&lamp->dist, GPU_DYNAMIC_LAMP_DISTANCE, lamp->ob), GPU_dynamic_uniform(&lamp->att1, GPU_DYNAMIC_LAMP_ATT1, lamp->ob), GPU_dynamic_uniform(&lamp->att2, GPU_DYNAMIC_LAMP_ATT2, lamp->ob), *dist, &visifac);
break; break;
case LA_FALLOFF_CURVE: case LA_FALLOFF_CURVE:
{ {
float *array; float *array;
int size; int size;
curvemapping_initialize(lamp->curfalloff);
curvemapping_table_RGBA(lamp->curfalloff, &array, &size);
GPU_link(mat, "lamp_falloff_curve", GPU_dynamic_uniform(&lamp->dist, GPU_DYNAMIC_LAMP_DISTANCE, lamp->ob), GPU_texture(size, array), *dist, &visifac);
curvemapping_initialize(lamp->curfalloff);
curvemapping_table_RGBA(lamp->curfalloff, &array, &size);
GPU_link(mat, "lamp_falloff_curve", GPU_dynamic_uniform(&lamp->dist, GPU_DYNAMIC_LAMP_DISTANCE, lamp->ob), GPU_texture(size, array), *dist, &visifac);
}
break; break;
}
} }
if (lamp->mode & LA_SPHERE) if (lamp->mode & LA_SPHERE)
@ -516,34 +517,34 @@ static GPUNodeLink *lamp_get_visibility(GPUMaterial *mat, GPULamp *lamp, GPUNode
#if 0 #if 0
static void area_lamp_vectors(LampRen *lar) static void area_lamp_vectors(LampRen *lar)
{ {
float xsize= 0.5*lar->area_size, ysize= 0.5*lar->area_sizey, multifac; float xsize = 0.5f * lar->area_size, ysize = 0.5f * lar->area_sizey, multifac;
/* make it smaller, so area light can be multisampled */ /* make it smaller, so area light can be multisampled */
multifac= 1.0f/sqrt((float)lar->ray_totsamp); multifac = 1.0f / sqrtf((float)lar->ray_totsamp);
xsize *= multifac; xsize *= multifac;
ysize *= multifac; ysize *= multifac;
/* corner vectors */ /* corner vectors */
lar->area[0][0]= lar->co[0] - xsize*lar->mat[0][0] - ysize*lar->mat[1][0]; lar->area[0][0] = lar->co[0] - xsize * lar->mat[0][0] - ysize * lar->mat[1][0];
lar->area[0][1]= lar->co[1] - xsize*lar->mat[0][1] - ysize*lar->mat[1][1]; lar->area[0][1] = lar->co[1] - xsize * lar->mat[0][1] - ysize * lar->mat[1][1];
lar->area[0][2]= lar->co[2] - xsize*lar->mat[0][2] - ysize*lar->mat[1][2]; lar->area[0][2] = lar->co[2] - xsize * lar->mat[0][2] - ysize * lar->mat[1][2];
/* corner vectors */ /* corner vectors */
lar->area[1][0]= lar->co[0] - xsize*lar->mat[0][0] + ysize*lar->mat[1][0]; lar->area[1][0] = lar->co[0] - xsize * lar->mat[0][0] + ysize * lar->mat[1][0];
lar->area[1][1]= lar->co[1] - xsize*lar->mat[0][1] + ysize*lar->mat[1][1]; lar->area[1][1] = lar->co[1] - xsize * lar->mat[0][1] + ysize * lar->mat[1][1];
lar->area[1][2]= lar->co[2] - xsize*lar->mat[0][2] + ysize*lar->mat[1][2]; lar->area[1][2] = lar->co[2] - xsize * lar->mat[0][2] + ysize * lar->mat[1][2];
/* corner vectors */ /* corner vectors */
lar->area[2][0]= lar->co[0] + xsize*lar->mat[0][0] + ysize*lar->mat[1][0]; lar->area[2][0] = lar->co[0] + xsize * lar->mat[0][0] + ysize * lar->mat[1][0];
lar->area[2][1]= lar->co[1] + xsize*lar->mat[0][1] + ysize*lar->mat[1][1]; lar->area[2][1] = lar->co[1] + xsize * lar->mat[0][1] + ysize * lar->mat[1][1];
lar->area[2][2]= lar->co[2] + xsize*lar->mat[0][2] + ysize*lar->mat[1][2]; lar->area[2][2] = lar->co[2] + xsize * lar->mat[0][2] + ysize * lar->mat[1][2];
/* corner vectors */ /* corner vectors */
lar->area[3][0]= lar->co[0] + xsize*lar->mat[0][0] - ysize*lar->mat[1][0]; lar->area[3][0] = lar->co[0] + xsize * lar->mat[0][0] - ysize * lar->mat[1][0];
lar->area[3][1]= lar->co[1] + xsize*lar->mat[0][1] - ysize*lar->mat[1][1]; lar->area[3][1] = lar->co[1] + xsize * lar->mat[0][1] - ysize * lar->mat[1][1];
lar->area[3][2]= lar->co[2] + xsize*lar->mat[0][2] - ysize*lar->mat[1][2]; lar->area[3][2] = lar->co[2] + xsize * lar->mat[0][2] - ysize * lar->mat[1][2];
/* only for correction button size, matrix size works on energy */ /* only for correction button size, matrix size works on energy */
lar->areasize= lar->dist*lar->dist/(4.0*xsize*ysize); lar->areasize = lar->dist * lar->dist / (4.0f * xsize * ysize);
} }
#endif #endif
@ -577,8 +578,8 @@ static void do_colorband_blend(GPUMaterial *mat, ColorBand *coba, GPUNodeLink *f
static void ramp_diffuse_result(GPUShadeInput *shi, GPUNodeLink **diff) static void ramp_diffuse_result(GPUShadeInput *shi, GPUNodeLink **diff)
{ {
Material *ma= shi->mat; Material *ma = shi->mat;
GPUMaterial *mat= shi->gpumat; GPUMaterial *mat = shi->gpumat;
GPUNodeLink *fac; GPUNodeLink *fac;
if (!(mat->scene->gm.flag & GAME_GLSL_NO_RAMPS)) { if (!(mat->scene->gm.flag & GAME_GLSL_NO_RAMPS)) {
@ -607,18 +608,18 @@ static void add_to_diffuse(GPUMaterial *mat, Material *ma, GPUShadeInput *shi, G
else { else {
/* input */ /* input */
switch (ma->rampin_col) { switch (ma->rampin_col) {
case MA_RAMP_IN_ENERGY: case MA_RAMP_IN_ENERGY:
GPU_link(mat, "ramp_rgbtobw", rgb, &fac); GPU_link(mat, "ramp_rgbtobw", rgb, &fac);
break; break;
case MA_RAMP_IN_SHADER: case MA_RAMP_IN_SHADER:
fac= is; fac= is;
break; break;
case MA_RAMP_IN_NOR: case MA_RAMP_IN_NOR:
GPU_link(mat, "vec_math_dot", shi->view, shi->vn, &tmp, &fac); GPU_link(mat, "vec_math_dot", shi->view, shi->vn, &tmp, &fac);
break; break;
default: default:
GPU_link(mat, "set_value_zero", &fac); GPU_link(mat, "set_value_zero", &fac);
break; break;
} }
/* colorband + blend */ /* colorband + blend */
@ -634,12 +635,12 @@ static void add_to_diffuse(GPUMaterial *mat, Material *ma, GPUShadeInput *shi, G
static void ramp_spec_result(GPUShadeInput *shi, GPUNodeLink **spec) static void ramp_spec_result(GPUShadeInput *shi, GPUNodeLink **spec)
{ {
Material *ma= shi->mat; Material *ma = shi->mat;
GPUMaterial *mat= shi->gpumat; GPUMaterial *mat = shi->gpumat;
GPUNodeLink *fac; GPUNodeLink *fac;
if (!(mat->scene->gm.flag & GAME_GLSL_NO_RAMPS) && if (!(mat->scene->gm.flag & GAME_GLSL_NO_RAMPS) &&
ma->ramp_spec && ma->rampin_spec==MA_RAMP_IN_RESULT) ma->ramp_spec && ma->rampin_spec == MA_RAMP_IN_RESULT)
{ {
GPU_link(mat, "ramp_rgbtobw", *spec, &fac); GPU_link(mat, "ramp_rgbtobw", *spec, &fac);
@ -650,29 +651,29 @@ static void ramp_spec_result(GPUShadeInput *shi, GPUNodeLink **spec)
static void do_specular_ramp(GPUShadeInput *shi, GPUNodeLink *is, GPUNodeLink *t, GPUNodeLink **spec) static void do_specular_ramp(GPUShadeInput *shi, GPUNodeLink *is, GPUNodeLink *t, GPUNodeLink **spec)
{ {
Material *ma= shi->mat; Material *ma = shi->mat;
GPUMaterial *mat= shi->gpumat; GPUMaterial *mat = shi->gpumat;
GPUNodeLink *fac, *tmp; GPUNodeLink *fac, *tmp;
*spec = shi->specrgb; *spec = shi->specrgb;
/* MA_RAMP_IN_RESULT is exception */ /* MA_RAMP_IN_RESULT is exception */
if (ma->ramp_spec && (ma->rampin_spec!=MA_RAMP_IN_RESULT)) { if (ma->ramp_spec && (ma->rampin_spec != MA_RAMP_IN_RESULT)) {
/* input */ /* input */
switch (ma->rampin_spec) { switch (ma->rampin_spec) {
case MA_RAMP_IN_ENERGY: case MA_RAMP_IN_ENERGY:
fac = t; fac = t;
break; break;
case MA_RAMP_IN_SHADER: case MA_RAMP_IN_SHADER:
fac = is; fac = is;
break; break;
case MA_RAMP_IN_NOR: case MA_RAMP_IN_NOR:
GPU_link(mat, "vec_math_dot", shi->view, shi->vn, &tmp, &fac); GPU_link(mat, "vec_math_dot", shi->view, shi->vn, &tmp, &fac);
break; break;
default: default:
GPU_link(mat, "set_value_zero", &fac); GPU_link(mat, "set_value_zero", &fac);
break; break;
} }
/* colorband + blend */ /* colorband + blend */
@ -694,10 +695,10 @@ static void shade_light_textures(GPUMaterial *mat, GPULamp *lamp, GPUNodeLink **
int i; int i;
float one = 1.f; float one = 1.f;
for (i=0; i<MAX_MTEX; ++i) { for (i = 0; i < MAX_MTEX; ++i) {
mtex = lamp->la->mtex[i]; mtex = lamp->la->mtex[i];
if (mtex && mtex->tex->type & TEX_IMAGE && mtex->tex->ima) { if (mtex && mtex->tex->type & TEX_IMAGE && mtex->tex->ima) {
mat->dynproperty |= DYN_LAMP_PERSMAT; mat->dynproperty |= DYN_LAMP_PERSMAT;
GPU_link(mat, "shade_light_texture", GPU_link(mat, "shade_light_texture",
@ -705,29 +706,31 @@ static void shade_light_textures(GPUMaterial *mat, GPULamp *lamp, GPUNodeLink **
GPU_image(mtex->tex->ima, &mtex->tex->iuser, false), GPU_image(mtex->tex->ima, &mtex->tex->iuser, false),
GPU_dynamic_uniform((float*)lamp->dynpersmat, GPU_DYNAMIC_LAMP_DYNPERSMAT, lamp->ob), GPU_dynamic_uniform((float*)lamp->dynpersmat, GPU_DYNAMIC_LAMP_DYNPERSMAT, lamp->ob),
&tex_rgb); &tex_rgb);
texture_rgb_blend(mat, tex_rgb, *rgb, GPU_uniform(&one), GPU_uniform(&mtex->colfac), mtex->blendtype, rgb); texture_rgb_blend(mat, tex_rgb, *rgb, GPU_uniform(&one), GPU_uniform(&mtex->colfac), mtex->blendtype, rgb);
} }
} }
} }
static void shade_one_light(GPUShadeInput *shi, GPUShadeResult *shr, GPULamp *lamp) static void shade_one_light(GPUShadeInput *shi, GPUShadeResult *shr, GPULamp *lamp)
{ {
Material *ma= shi->mat; Material *ma = shi->mat;
GPUMaterial *mat= shi->gpumat; GPUMaterial *mat = shi->gpumat;
GPUNodeLink *lv, *dist, *visifac, *is, *inp, *i, *vn, *view; GPUNodeLink *lv, *dist, *visifac, *is, *inp, *i, *vn, *view;
GPUNodeLink *outcol, *specfac, *t, *shadfac= NULL, *lcol; GPUNodeLink *outcol, *specfac, *t, *shadfac = NULL, *lcol;
float one = 1.0f; float one = 1.0f;
if ((lamp->mode & LA_ONLYSHADOW) && !(ma->mode & MA_SHADOW)) if ((lamp->mode & LA_ONLYSHADOW) && !(ma->mode & MA_SHADOW))
return; return;
vn= shi->vn; vn = shi->vn;
view= shi->view; view = shi->view;
visifac= lamp_get_visibility(mat, lamp, &lv, &dist); visifac = lamp_get_visibility(mat, lamp, &lv, &dist);
/*if (ma->mode & MA_TANGENT_V) #if 0
GPU_link(mat, "shade_tangent_v", lv, GPU_attribute(CD_TANGENT, ""), &vn);*/ if (ma->mode & MA_TANGENT_V)
GPU_link(mat, "shade_tangent_v", lv, GPU_attribute(CD_TANGENT, ""), &vn);
#endif
GPU_link(mat, "shade_inp", vn, lv, &inp); GPU_link(mat, "shade_inp", vn, lv, &inp);
@ -739,23 +742,23 @@ static void shade_one_light(GPUShadeInput *shi, GPUShadeResult *shr, GPULamp *la
} }
else { else {
if (lamp->type == LA_AREA) { if (lamp->type == LA_AREA) {
float area[4][4]= {{0.0f}}, areasize= 0.0f; float area[4][4] = {{0.0f}}, areasize = 0.0f;
mat->dynproperty |= DYN_LAMP_VEC|DYN_LAMP_CO; mat->dynproperty |= DYN_LAMP_VEC|DYN_LAMP_CO;
GPU_link(mat, "shade_inp_area", GPU_builtin(GPU_VIEW_POSITION), GPU_dynamic_uniform(lamp->dynco, GPU_DYNAMIC_LAMP_DYNCO, lamp->ob), GPU_dynamic_uniform(lamp->dynvec, GPU_DYNAMIC_LAMP_DYNVEC, lamp->ob), vn, GPU_uniform((float*)area), GPU_link(mat, "shade_inp_area", GPU_builtin(GPU_VIEW_POSITION), GPU_dynamic_uniform(lamp->dynco, GPU_DYNAMIC_LAMP_DYNCO, lamp->ob), GPU_dynamic_uniform(lamp->dynvec, GPU_DYNAMIC_LAMP_DYNVEC, lamp->ob), vn, GPU_uniform((float*)area),
GPU_uniform(&areasize), GPU_uniform(&lamp->k), &inp); GPU_uniform(&areasize), GPU_uniform(&lamp->k), &inp);
} }
is= inp; /* Lambert */ is = inp; /* Lambert */
if (!(mat->scene->gm.flag & GAME_GLSL_NO_SHADERS)) { if (!(mat->scene->gm.flag & GAME_GLSL_NO_SHADERS)) {
if (ma->diff_shader==MA_DIFF_ORENNAYAR) if (ma->diff_shader == MA_DIFF_ORENNAYAR)
GPU_link(mat, "shade_diffuse_oren_nayer", inp, vn, lv, view, GPU_uniform(&ma->roughness), &is); GPU_link(mat, "shade_diffuse_oren_nayer", inp, vn, lv, view, GPU_uniform(&ma->roughness), &is);
else if (ma->diff_shader==MA_DIFF_TOON) else if (ma->diff_shader == MA_DIFF_TOON)
GPU_link(mat, "shade_diffuse_toon", vn, lv, view, GPU_uniform(&ma->param[0]), GPU_uniform(&ma->param[1]), &is); GPU_link(mat, "shade_diffuse_toon", vn, lv, view, GPU_uniform(&ma->param[0]), GPU_uniform(&ma->param[1]), &is);
else if (ma->diff_shader==MA_DIFF_MINNAERT) else if (ma->diff_shader == MA_DIFF_MINNAERT)
GPU_link(mat, "shade_diffuse_minnaert", inp, vn, view, GPU_uniform(&ma->darkness), &is); GPU_link(mat, "shade_diffuse_minnaert", inp, vn, view, GPU_uniform(&ma->darkness), &is);
else if (ma->diff_shader==MA_DIFF_FRESNEL) else if (ma->diff_shader == MA_DIFF_FRESNEL)
GPU_link(mat, "shade_diffuse_fresnel", vn, lv, view, GPU_uniform(&ma->param[0]), GPU_uniform(&ma->param[1]), &is); GPU_link(mat, "shade_diffuse_fresnel", vn, lv, view, GPU_uniform(&ma->param[0]), GPU_uniform(&ma->param[1]), &is);
} }
} }
@ -777,7 +780,7 @@ static void shade_one_light(GPUShadeInput *shi, GPUShadeResult *shr, GPULamp *la
#endif #endif
/* this replaces if (i > 0.0) conditional until that is supported */ /* this replaces if (i > 0.0) conditional until that is supported */
// done in shade_visifac now, GPU_link(mat, "mtex_value_clamp_positive", i, &i); /* done in shade_visifac now, GPU_link(mat, "mtex_value_clamp_positive", i, &i); */
if ((ma->mode & MA_SHADOW) && GPU_lamp_has_shadow_buffer(lamp)) { if ((ma->mode & MA_SHADOW) && GPU_lamp_has_shadow_buffer(lamp)) {
if (!(mat->scene->gm.flag & GAME_GLSL_NO_SHADOWS)) { if (!(mat->scene->gm.flag & GAME_GLSL_NO_SHADOWS)) {
@ -850,18 +853,18 @@ static void shade_one_light(GPUShadeInput *shi, GPUShadeResult *shr, GPULamp *la
GPU_link(mat, "shade_add_clamped", shr->spec, outcol, &shr->spec); GPU_link(mat, "shade_add_clamped", shr->spec, outcol, &shr->spec);
} }
else { else {
if (ma->spec_shader==MA_SPEC_PHONG) if (ma->spec_shader == MA_SPEC_PHONG)
GPU_link(mat, "shade_phong_spec", vn, lv, view, shi->har, &specfac); GPU_link(mat, "shade_phong_spec", vn, lv, view, shi->har, &specfac);
else if (ma->spec_shader==MA_SPEC_COOKTORR) else if (ma->spec_shader == MA_SPEC_COOKTORR)
GPU_link(mat, "shade_cooktorr_spec", vn, lv, view, shi->har, &specfac); GPU_link(mat, "shade_cooktorr_spec", vn, lv, view, shi->har, &specfac);
else if (ma->spec_shader==MA_SPEC_BLINN) else if (ma->spec_shader == MA_SPEC_BLINN)
GPU_link(mat, "shade_blinn_spec", vn, lv, view, GPU_uniform(&ma->refrac), shi->har, &specfac); GPU_link(mat, "shade_blinn_spec", vn, lv, view, GPU_uniform(&ma->refrac), shi->har, &specfac);
else if (ma->spec_shader==MA_SPEC_WARDISO) else if (ma->spec_shader == MA_SPEC_WARDISO)
GPU_link(mat, "shade_wardiso_spec", vn, lv, view, GPU_uniform(&ma->rms), &specfac); GPU_link(mat, "shade_wardiso_spec", vn, lv, view, GPU_uniform(&ma->rms), &specfac);
else else
GPU_link(mat, "shade_toon_spec", vn, lv, view, GPU_uniform(&ma->param[2]), GPU_uniform(&ma->param[3]), &specfac); GPU_link(mat, "shade_toon_spec", vn, lv, view, GPU_uniform(&ma->param[2]), GPU_uniform(&ma->param[3]), &specfac);
if (lamp->type==LA_AREA) if (lamp->type == LA_AREA)
GPU_link(mat, "shade_spec_area_inp", specfac, inp, &specfac); GPU_link(mat, "shade_spec_area_inp", specfac, inp, &specfac);
GPU_link(mat, "shade_spec_t", shadfac, shi->spec, visifac, specfac, &t); GPU_link(mat, "shade_spec_t", shadfac, shi->spec, visifac, specfac, &t);
@ -891,9 +894,9 @@ static void material_lights(GPUShadeInput *shi, GPUShadeResult *shr)
GPULamp *lamp; GPULamp *lamp;
for (SETLOOPER(shi->gpumat->scene, sce_iter, base)) { for (SETLOOPER(shi->gpumat->scene, sce_iter, base)) {
ob= base->object; ob = base->object;
if (ob->type==OB_LAMP) { if (ob->type == OB_LAMP) {
lamp = GPU_lamp_from_blender(shi->gpumat->scene, ob, NULL); lamp = GPU_lamp_from_blender(shi->gpumat->scene, ob, NULL);
if (lamp) if (lamp)
shade_one_light(shi, shr, lamp); shade_one_light(shi, shr, lamp);
@ -903,10 +906,10 @@ static void material_lights(GPUShadeInput *shi, GPUShadeResult *shr)
DupliObject *dob; DupliObject *dob;
ListBase *lb = object_duplilist(G.main->eval_ctx, shi->gpumat->scene, ob); ListBase *lb = object_duplilist(G.main->eval_ctx, shi->gpumat->scene, ob);
for (dob=lb->first; dob; dob=dob->next) { for (dob = lb->first; dob; dob = dob->next) {
Object *ob_iter = dob->ob; Object *ob_iter = dob->ob;
if (ob_iter->type==OB_LAMP) { if (ob_iter->type == OB_LAMP) {
float omat[4][4]; float omat[4][4];
copy_m4_m4(omat, ob_iter->obmat); copy_m4_m4(omat, ob_iter->obmat);
copy_m4_m4(ob_iter->obmat, dob->mat); copy_m4_m4(ob_iter->obmat, dob->mat);
@ -1023,8 +1026,8 @@ static void texture_value_blend(GPUMaterial *mat, GPUNodeLink *tex, GPUNodeLink
static void do_material_tex(GPUShadeInput *shi) static void do_material_tex(GPUShadeInput *shi)
{ {
Material *ma= shi->mat; Material *ma = shi->mat;
GPUMaterial *mat= shi->gpumat; GPUMaterial *mat = shi->gpumat;
MTex *mtex; MTex *mtex;
Tex *tex; Tex *tex;
GPUNodeLink *texco, *tin, *trgb, *tnor, *tcol, *stencil, *tnorfac; GPUNodeLink *texco, *tin, *trgb, *tnor, *tcol, *stencil, *tnorfac;
@ -1035,9 +1038,9 @@ static void do_material_tex(GPUShadeInput *shi)
float one = 1.0f, norfac, ofs[3]; float one = 1.0f, norfac, ofs[3];
int tex_nr, rgbnor, talpha; int tex_nr, rgbnor, talpha;
bool init_done = false; bool init_done = false;
int iBumpSpacePrev = 0; /* Not necessary, quiting gcc warning. */ int iBumpSpacePrev = 0; /* Not necessary, quieting gcc warning. */
GPUNodeLink *vNorg, *vNacc, *fPrevMagnitude; GPUNodeLink *vNorg, *vNacc, *fPrevMagnitude;
int iFirstTimeNMap=1; int iFirstTimeNMap = 1;
int found_deriv_map = 0; int found_deriv_map = 0;
GPU_link(mat, "set_value", GPU_uniform(&one), &stencil); GPU_link(mat, "set_value", GPU_uniform(&one), &stencil);
@ -1047,44 +1050,46 @@ static void do_material_tex(GPUShadeInput *shi)
GPU_link(mat, "texco_object", GPU_builtin(GPU_INVERSE_VIEW_MATRIX), GPU_link(mat, "texco_object", GPU_builtin(GPU_INVERSE_VIEW_MATRIX),
GPU_builtin(GPU_INVERSE_OBJECT_MATRIX), GPU_builtin(GPU_INVERSE_OBJECT_MATRIX),
GPU_builtin(GPU_VIEW_POSITION), &texco_object); GPU_builtin(GPU_VIEW_POSITION), &texco_object);
//GPU_link(mat, "texco_tangent", GPU_attribute(CD_TANGENT, ""), &texco_tangent); #if 0
GPU_link(mat, "texco_tangent", GPU_attribute(CD_TANGENT, ""), &texco_tangent);
#endif
GPU_link(mat, "texco_global", GPU_builtin(GPU_INVERSE_VIEW_MATRIX), GPU_link(mat, "texco_global", GPU_builtin(GPU_INVERSE_VIEW_MATRIX),
GPU_builtin(GPU_VIEW_POSITION), &texco_global); GPU_builtin(GPU_VIEW_POSITION), &texco_global);
orn= texco_norm; orn= texco_norm;
/* go over texture slots */ /* go over texture slots */
for (tex_nr=0; tex_nr<MAX_MTEX; tex_nr++) { for (tex_nr = 0; tex_nr < MAX_MTEX; tex_nr++) {
/* separate tex switching */ /* separate tex switching */
if (ma->septex & (1<<tex_nr)) continue; if (ma->septex & (1 << tex_nr)) continue;
if (ma->mtex[tex_nr]) { if (ma->mtex[tex_nr]) {
mtex= ma->mtex[tex_nr]; mtex = ma->mtex[tex_nr];
tex= mtex->tex; tex = mtex->tex;
if (tex == NULL) continue; if (tex == NULL) continue;
/* which coords */ /* which coords */
if (mtex->texco==TEXCO_ORCO) if (mtex->texco == TEXCO_ORCO)
texco= texco_orco; texco = texco_orco;
else if (mtex->texco==TEXCO_OBJECT) else if (mtex->texco == TEXCO_OBJECT)
texco= texco_object; texco = texco_object;
else if (mtex->texco==TEXCO_NORM) else if (mtex->texco == TEXCO_NORM)
texco= orn; texco = orn;
else if (mtex->texco==TEXCO_TANGENT) else if (mtex->texco == TEXCO_TANGENT)
texco= texco_object; texco = texco_object;
else if (mtex->texco==TEXCO_GLOB) else if (mtex->texco == TEXCO_GLOB)
texco= texco_global; texco = texco_global;
else if (mtex->texco==TEXCO_REFL) { else if (mtex->texco == TEXCO_REFL) {
GPU_link(mat, "texco_refl", shi->vn, shi->view, &shi->ref); GPU_link(mat, "texco_refl", shi->vn, shi->view, &shi->ref);
texco= shi->ref; texco = shi->ref;
} }
else if (mtex->texco==TEXCO_UV) { else if (mtex->texco == TEXCO_UV) {
if (1) { //!(texco_uv && strcmp(mtex->uvname, lastuvname) == 0)) { if (1) { //!(texco_uv && strcmp(mtex->uvname, lastuvname) == 0)) {
GPU_link(mat, "texco_uv", GPU_attribute(CD_MTFACE, mtex->uvname), &texco_uv); GPU_link(mat, "texco_uv", GPU_attribute(CD_MTFACE, mtex->uvname), &texco_uv);
/*lastuvname = mtex->uvname;*/ /*UNUSED*/ /*lastuvname = mtex->uvname;*/ /*UNUSED*/
} }
texco= texco_uv; texco = texco_uv;
} }
else else
continue; continue;
@ -1096,8 +1101,8 @@ static void do_material_tex(GPUShadeInput *shi)
if (mtex->size[0] != 1.0f || mtex->size[1] != 1.0f || mtex->size[2] != 1.0f) if (mtex->size[0] != 1.0f || mtex->size[1] != 1.0f || mtex->size[2] != 1.0f)
GPU_link(mat, "mtex_mapping_size", texco, GPU_uniform(mtex->size), &texco); GPU_link(mat, "mtex_mapping_size", texco, GPU_uniform(mtex->size), &texco);
ofs[0] = mtex->ofs[0] + 0.5f - 0.5f*mtex->size[0]; ofs[0] = mtex->ofs[0] + 0.5f - 0.5f * mtex->size[0];
ofs[1] = mtex->ofs[1] + 0.5f - 0.5f*mtex->size[1]; ofs[1] = mtex->ofs[1] + 0.5f - 0.5f * mtex->size[1];
ofs[2] = 0.0f; ofs[2] = 0.0f;
if (ofs[0] != 0.0f || ofs[1] != 0.0f || ofs[2] != 0.0f) if (ofs[0] != 0.0f || ofs[1] != 0.0f || ofs[2] != 0.0f)
GPU_link(mat, "mtex_mapping_ofs", texco, GPU_uniform(ofs), &texco); GPU_link(mat, "mtex_mapping_ofs", texco, GPU_uniform(ofs), &texco);
@ -1106,7 +1111,7 @@ static void do_material_tex(GPUShadeInput *shi)
if (tex && tex->type == TEX_IMAGE && tex->ima) { if (tex && tex->type == TEX_IMAGE && tex->ima) {
GPU_link(mat, "mtex_image", texco, GPU_image(tex->ima, &tex->iuser, false), &tin, &trgb); GPU_link(mat, "mtex_image", texco, GPU_image(tex->ima, &tex->iuser, false), &tin, &trgb);
rgbnor= TEX_RGB; rgbnor = TEX_RGB;
talpha = ((tex->imaflag & TEX_USEALPHA) && tex->ima && (tex->ima->flag & IMA_IGNORE_ALPHA) == 0); talpha = ((tex->imaflag & TEX_USEALPHA) && tex->ima && (tex->ima->flag & IMA_IGNORE_ALPHA) == 0);
} }
@ -1151,7 +1156,7 @@ static void do_material_tex(GPUShadeInput *shi)
GPU_link(mat, "set_value_one", &tin); GPU_link(mat, "set_value_one", &tin);
} }
if (tex->type==TEX_IMAGE) if (tex->type == TEX_IMAGE)
if (GPU_material_do_color_management(mat)) if (GPU_material_do_color_management(mat))
GPU_link(mat, "srgb_to_linearrgb", tcol, &tcol); GPU_link(mat, "srgb_to_linearrgb", tcol, &tcol);
@ -1175,7 +1180,7 @@ static void do_material_tex(GPUShadeInput *shi)
} }
if (!(mat->scene->gm.flag & GAME_GLSL_NO_EXTRA_TEX) && (mtex->mapto & MAP_NORM)) { if (!(mat->scene->gm.flag & GAME_GLSL_NO_EXTRA_TEX) && (mtex->mapto & MAP_NORM)) {
if (tex->type==TEX_IMAGE) { if (tex->type == TEX_IMAGE) {
found_deriv_map = tex->imaflag & TEX_DERIVATIVEMAP; found_deriv_map = tex->imaflag & TEX_DERIVATIVEMAP;
if (tex->imaflag & TEX_NORMALMAP) { if (tex->imaflag & TEX_NORMALMAP) {
@ -1225,43 +1230,43 @@ static void do_material_tex(GPUShadeInput *shi)
} }
} }
else if ( (mtex->texflag & (MTEX_3TAP_BUMP|MTEX_5TAP_BUMP|MTEX_BICUBIC_BUMP)) || found_deriv_map) { else if ((mtex->texflag & (MTEX_3TAP_BUMP | MTEX_5TAP_BUMP | MTEX_BICUBIC_BUMP)) || found_deriv_map) {
/* ntap bumpmap image */ /* ntap bumpmap image */
int iBumpSpace; int iBumpSpace;
float ima_x, ima_y; float ima_x, ima_y;
float hScale; float hScale;
float imag_tspace_dimension_x = 1024.0f; // only used for texture space variant float imag_tspace_dimension_x = 1024.0f; /* only used for texture space variant */
float aspect = 1.0f; float aspect = 1.0f;
GPUNodeLink *vR1, *vR2; GPUNodeLink *vR1, *vR2;
GPUNodeLink *dBs, *dBt, *fDet; GPUNodeLink *dBs, *dBt, *fDet;
hScale = 0.1; // compatibility adjustment factor for all bumpspace types hScale = 0.1; /* compatibility adjustment factor for all bumpspace types */
if ( mtex->texflag & MTEX_BUMP_TEXTURESPACE ) if (mtex->texflag & MTEX_BUMP_TEXTURESPACE)
hScale = 13.0f; // factor for scaling texspace bumps hScale = 13.0f; /* factor for scaling texspace bumps */
else if (found_deriv_map!=0) else if (found_deriv_map!=0)
hScale = 1.0f; hScale = 1.0f;
// resolve texture resolution /* resolve texture resolution */
if ( (mtex->texflag & MTEX_BUMP_TEXTURESPACE) || found_deriv_map ) { if ((mtex->texflag & MTEX_BUMP_TEXTURESPACE) || found_deriv_map) {
ImBuf *ibuf= BKE_image_acquire_ibuf(tex->ima, &tex->iuser, NULL); ImBuf *ibuf = BKE_image_acquire_ibuf(tex->ima, &tex->iuser, NULL);
ima_x= 512.0f; ima_y= 512.f; // prevent calling textureSize, glsl 1.3 only ima_x = 512.0f; ima_y = 512.f; /* prevent calling textureSize, glsl 1.3 only */
if (ibuf) { if (ibuf) {
ima_x= ibuf->x; ima_x = ibuf->x;
ima_y= ibuf->y; ima_y = ibuf->y;
aspect = ((float) ima_y) / ima_x; aspect = (float)ima_y / ima_x;
} }
BKE_image_release_ibuf(tex->ima, ibuf, NULL); BKE_image_release_ibuf(tex->ima, ibuf, NULL);
} }
// The negate on norfac is done because the /* The negate on norfac is done because the
// normal in the renderer points inward which corresponds * normal in the renderer points inward which corresponds
// to inverting the bump map. Should this ever change * to inverting the bump map. Should this ever change
// this negate must be removed. * this negate must be removed. */
norfac = -hScale * mtex->norfac; norfac = -hScale * mtex->norfac;
if (found_deriv_map) { if (found_deriv_map) {
float fVirtDim = sqrtf(fabsf(ima_x*mtex->size[0]*ima_y*mtex->size[1])); float fVirtDim = sqrtf(fabsf(ima_x * mtex->size[0] * ima_y * mtex->size[1]));
norfac /= MAX2(fVirtDim, FLT_EPSILON); norfac /= MAX2(fVirtDim, FLT_EPSILON);
} }
@ -1273,26 +1278,26 @@ static void do_material_tex(GPUShadeInput *shi)
if (GPU_link_changed(stencil)) if (GPU_link_changed(stencil))
GPU_link(mat, "math_multiply", tnorfac, stencil, &tnorfac); GPU_link(mat, "math_multiply", tnorfac, stencil, &tnorfac);
if ( !init_done ) { if (!init_done) {
// copy shi->vn to vNorg and vNacc, set magnitude to 1 /* copy shi->vn to vNorg and vNacc, set magnitude to 1 */
GPU_link(mat, "mtex_bump_normals_init", shi->vn, &vNorg, &vNacc, &fPrevMagnitude); GPU_link(mat, "mtex_bump_normals_init", shi->vn, &vNorg, &vNacc, &fPrevMagnitude);
iBumpSpacePrev = 0; iBumpSpacePrev = 0;
init_done = true; init_done = true;
} }
// find current bump space // find current bump space
if ( mtex->texflag & MTEX_BUMP_OBJECTSPACE ) if (mtex->texflag & MTEX_BUMP_OBJECTSPACE)
iBumpSpace = 1; iBumpSpace = 1;
else if ( mtex->texflag & MTEX_BUMP_TEXTURESPACE ) else if (mtex->texflag & MTEX_BUMP_TEXTURESPACE)
iBumpSpace = 2; iBumpSpace = 2;
else else
iBumpSpace = 4; // ViewSpace iBumpSpace = 4; /* ViewSpace */
// re-initialize if bump space changed /* re-initialize if bump space changed */
if ( iBumpSpacePrev != iBumpSpace ) { if (iBumpSpacePrev != iBumpSpace) {
GPUNodeLink *surf_pos = GPU_builtin(GPU_VIEW_POSITION); GPUNodeLink *surf_pos = GPU_builtin(GPU_VIEW_POSITION);
if ( mtex->texflag & MTEX_BUMP_OBJECTSPACE ) if (mtex->texflag & MTEX_BUMP_OBJECTSPACE)
GPU_link(mat, "mtex_bump_init_objspace", GPU_link(mat, "mtex_bump_init_objspace",
surf_pos, vNorg, surf_pos, vNorg,
GPU_builtin(GPU_VIEW_MATRIX), GPU_builtin(GPU_INVERSE_VIEW_MATRIX), GPU_builtin(GPU_OBJECT_MATRIX), GPU_builtin(GPU_INVERSE_OBJECT_MATRIX), GPU_builtin(GPU_VIEW_MATRIX), GPU_builtin(GPU_INVERSE_VIEW_MATRIX), GPU_builtin(GPU_OBJECT_MATRIX), GPU_builtin(GPU_INVERSE_OBJECT_MATRIX),
@ -1300,7 +1305,7 @@ static void do_material_tex(GPUShadeInput *shi)
&fPrevMagnitude, &vNacc, &fPrevMagnitude, &vNacc,
&vR1, &vR2, &fDet); &vR1, &vR2, &fDet);
else if ( mtex->texflag & MTEX_BUMP_TEXTURESPACE ) else if (mtex->texflag & MTEX_BUMP_TEXTURESPACE)
GPU_link(mat, "mtex_bump_init_texturespace", GPU_link(mat, "mtex_bump_init_texturespace",
surf_pos, vNorg, surf_pos, vNorg,
fPrevMagnitude, vNacc, fPrevMagnitude, vNacc,
@ -1321,17 +1326,17 @@ static void do_material_tex(GPUShadeInput *shi)
if (found_deriv_map) { if (found_deriv_map) {
GPU_link(mat, "mtex_bump_deriv", GPU_link(mat, "mtex_bump_deriv",
texco, GPU_image(tex->ima, &tex->iuser, true), GPU_uniform(&ima_x), GPU_uniform(&ima_y), tnorfac, texco, GPU_image(tex->ima, &tex->iuser, true), GPU_uniform(&ima_x), GPU_uniform(&ima_y), tnorfac,
&dBs, &dBt ); &dBs, &dBt);
} }
else if ( mtex->texflag & MTEX_3TAP_BUMP) else if (mtex->texflag & MTEX_3TAP_BUMP)
GPU_link(mat, "mtex_bump_tap3", GPU_link(mat, "mtex_bump_tap3",
texco, GPU_image(tex->ima, &tex->iuser, true), tnorfac, texco, GPU_image(tex->ima, &tex->iuser, true), tnorfac,
&dBs, &dBt ); &dBs, &dBt);
else if ( mtex->texflag & MTEX_5TAP_BUMP) else if (mtex->texflag & MTEX_5TAP_BUMP)
GPU_link(mat, "mtex_bump_tap5", GPU_link(mat, "mtex_bump_tap5",
texco, GPU_image(tex->ima, &tex->iuser, true), tnorfac, texco, GPU_image(tex->ima, &tex->iuser, true), tnorfac,
&dBs, &dBt ); &dBs, &dBt);
else if ( mtex->texflag & MTEX_BICUBIC_BUMP ) { else if (mtex->texflag & MTEX_BICUBIC_BUMP) {
if (GPU_bicubic_bump_support()) { if (GPU_bicubic_bump_support()) {
GPU_link(mat, "mtex_bump_bicubic", GPU_link(mat, "mtex_bump_bicubic",
texco, GPU_image(tex->ima, &tex->iuser, true), tnorfac, texco, GPU_image(tex->ima, &tex->iuser, true), tnorfac,
@ -1345,18 +1350,18 @@ static void do_material_tex(GPUShadeInput *shi)
} }
if ( mtex->texflag & MTEX_BUMP_TEXTURESPACE ) { if (mtex->texflag & MTEX_BUMP_TEXTURESPACE) {
float imag_tspace_dimension_y = aspect*imag_tspace_dimension_x; float imag_tspace_dimension_y = aspect * imag_tspace_dimension_x;
GPU_link(mat, "mtex_bump_apply_texspace", GPU_link(mat, "mtex_bump_apply_texspace",
fDet, dBs, dBt, vR1, vR2, fDet, dBs, dBt, vR1, vR2,
GPU_image(tex->ima, &tex->iuser, true), texco, GPU_image(tex->ima, &tex->iuser, true), texco,
GPU_uniform(&imag_tspace_dimension_x), GPU_uniform(&imag_tspace_dimension_y), vNacc, GPU_uniform(&imag_tspace_dimension_x), GPU_uniform(&imag_tspace_dimension_y), vNacc,
&vNacc, &shi->vn ); &vNacc, &shi->vn);
} }
else else
GPU_link(mat, "mtex_bump_apply", GPU_link(mat, "mtex_bump_apply",
fDet, dBs, dBt, vR1, vR2, vNacc, fDet, dBs, dBt, vR1, vR2, vNacc,
&vNacc, &shi->vn ); &vNacc, &shi->vn);
} }
} }
@ -1466,10 +1471,10 @@ void GPU_shadeinput_set(GPUMaterial *mat, Material *ma, GPUShadeInput *shi)
void GPU_shaderesult_set(GPUShadeInput *shi, GPUShadeResult *shr) void GPU_shaderesult_set(GPUShadeInput *shi, GPUShadeResult *shr)
{ {
GPUMaterial *mat= shi->gpumat; GPUMaterial *mat = shi->gpumat;
GPUNodeLink *emit, *ulinfac, *ulogfac, *mistfac; GPUNodeLink *emit, *ulinfac, *ulogfac, *mistfac;
Material *ma= shi->mat; Material *ma = shi->mat;
World *world= mat->scene->world; World *world = mat->scene->world;
float linfac, logfac, misttype; float linfac, logfac, misttype;
memset(shr, 0, sizeof(*shr)); memset(shr, 0, sizeof(*shr));
@ -1487,7 +1492,7 @@ void GPU_shaderesult_set(GPUShadeInput *shi, GPUShadeResult *shr)
} }
else { else {
if (GPU_link_changed(shi->emit) || ma->emit != 0.0f) { if (GPU_link_changed(shi->emit) || ma->emit != 0.0f) {
if ((ma->mode & (MA_VERTEXCOL|MA_VERTEXCOLP))== MA_VERTEXCOL) { if ((ma->mode & (MA_VERTEXCOL|MA_VERTEXCOLP)) == MA_VERTEXCOL) {
GPU_link(mat, "shade_add", shi->emit, shi->vcol, &emit); GPU_link(mat, "shade_add", shi->emit, shi->vcol, &emit);
GPU_link(mat, "shade_mul", emit, shi->rgb, &shr->diff); GPU_link(mat, "shade_mul", emit, shi->rgb, &shr->diff);
} }
@ -1507,9 +1512,9 @@ void GPU_shaderesult_set(GPUShadeInput *shi, GPUShadeResult *shr)
if (world) { if (world) {
/* exposure correction */ /* exposure correction */
if (world->exp!=0.0f || world->range!=1.0f) { if (world->exp != 0.0f || world->range != 1.0f) {
linfac= 1.0f + powf((2.0f*world->exp + 0.5f), -10); linfac = 1.0f + powf((2.0f * world->exp + 0.5f), -10);
logfac= logf((linfac-1.0f)/linfac)/world->range; logfac = logf((linfac - 1.0f) / linfac) / world->range;
GPU_link(mat, "set_value", GPU_uniform(&linfac), &ulinfac); GPU_link(mat, "set_value", GPU_uniform(&linfac), &ulinfac);
GPU_link(mat, "set_value", GPU_uniform(&logfac), &ulogfac); GPU_link(mat, "set_value", GPU_uniform(&logfac), &ulogfac);
@ -1521,7 +1526,7 @@ void GPU_shaderesult_set(GPUShadeInput *shi, GPUShadeResult *shr)
} }
/* ambient color */ /* ambient color */
if (world->ambr!=0.0f || world->ambg!=0.0f || world->ambb!=0.0f) { if (world->ambr != 0.0f || world->ambg != 0.0f || world->ambb != 0.0f) {
if (GPU_link_changed(shi->amb) || ma->amb != 0.0f) if (GPU_link_changed(shi->amb) || ma->amb != 0.0f)
GPU_link(mat, "shade_maddf", shr->combined, GPU_uniform(&ma->amb), GPU_link(mat, "shade_maddf", shr->combined, GPU_uniform(&ma->amb),
GPU_uniform(&world->ambr), &shr->combined); GPU_uniform(&world->ambr), &shr->combined);
@ -1612,7 +1617,7 @@ GPUMaterial *GPU_material_matcap(Scene *scene, Material *ma)
GPUNodeLink *outlink; GPUNodeLink *outlink;
LinkData *link; LinkData *link;
for (link=ma->gpumaterial.first; link; link=link->next) for (link = ma->gpumaterial.first; link; link = link->next)
if (((GPUMaterial*)link->data)->scene == scene) if (((GPUMaterial*)link->data)->scene == scene)
return link->data; return link->data;
@ -1648,7 +1653,7 @@ GPUMaterial *GPU_material_world(struct Scene *scene, struct World *wo)
LinkData *link; LinkData *link;
GPUMaterial *mat; GPUMaterial *mat;
for (link=wo->gpumaterial.first; link; link=link->next) for (link = wo->gpumaterial.first; link; link = link->next)
if (((GPUMaterial*)link->data)->scene == scene) if (((GPUMaterial*)link->data)->scene == scene)
return link->data; return link->data;
@ -1688,7 +1693,7 @@ GPUMaterial *GPU_material_from_blender(Scene *scene, Material *ma)
GPUNodeLink *outlink; GPUNodeLink *outlink;
LinkData *link; LinkData *link;
for (link=ma->gpumaterial.first; link; link=link->next) for (link = ma->gpumaterial.first; link; link = link->next)
if (((GPUMaterial*)link->data)->scene == scene) if (((GPUMaterial*)link->data)->scene == scene)
return link->data; return link->data;
@ -1745,15 +1750,15 @@ void GPU_materials_free(void)
World *wo; World *wo;
extern Material defmaterial; extern Material defmaterial;
for (ma=G.main->mat.first; ma; ma=ma->id.next) for (ma = G.main->mat.first; ma; ma = ma->id.next)
GPU_material_free(&ma->gpumaterial); GPU_material_free(&ma->gpumaterial);
for (wo=G.main->world.first; wo; wo=wo->id.next) for (wo = G.main->world.first; wo; wo = wo->id.next)
GPU_material_free(&wo->gpumaterial); GPU_material_free(&wo->gpumaterial);
GPU_material_free(&defmaterial.gpumaterial); GPU_material_free(&defmaterial.gpumaterial);
for (ob=G.main->object.first; ob; ob=ob->id.next) for (ob = G.main->object.first; ob; ob = ob->id.next)
GPU_lamp_free(ob); GPU_lamp_free(ob);
} }
@ -1795,11 +1800,11 @@ void GPU_lamp_update(GPULamp *lamp, int lay, int hide, float obmat[4][4])
void GPU_lamp_update_colors(GPULamp *lamp, float r, float g, float b, float energy) void GPU_lamp_update_colors(GPULamp *lamp, float r, float g, float b, float energy)
{ {
lamp->energy = energy; lamp->energy = energy;
if (lamp->mode & LA_NEG) lamp->energy= -lamp->energy; if (lamp->mode & LA_NEG) lamp->energy = -lamp->energy;
lamp->col[0]= r; lamp->col[0] = r;
lamp->col[1]= g; lamp->col[1] = g;
lamp->col[2]= b; lamp->col[2] = b;
} }
void GPU_lamp_update_distance(GPULamp *lamp, float distance, float att1, float att2) void GPU_lamp_update_distance(GPULamp *lamp, float distance, float att1, float att2)
@ -1829,11 +1834,11 @@ static void gpu_lamp_from_blender(Scene *scene, Object *ob, Object *par, Lamp *l
lamp->type = la->type; lamp->type = la->type;
lamp->energy = la->energy; lamp->energy = la->energy;
if (lamp->mode & LA_NEG) lamp->energy= -lamp->energy; if (lamp->mode & LA_NEG) lamp->energy = -lamp->energy;
lamp->col[0]= la->r; lamp->col[0] = la->r;
lamp->col[1]= la->g; lamp->col[1] = la->g;
lamp->col[2]= la->b; lamp->col[2] = la->b;
GPU_lamp_update(lamp, ob->lay, (ob->restrictflag & OB_RESTRICT_RENDER), ob->obmat); GPU_lamp_update(lamp, ob->lay, (ob->restrictflag & OB_RESTRICT_RENDER), ob->obmat);
@ -1842,20 +1847,20 @@ static void gpu_lamp_from_blender(Scene *scene, Object *ob, Object *par, Lamp *l
if (lamp->spotsi > DEG2RADF(170.0f)) if (lamp->spotsi > DEG2RADF(170.0f))
lamp->spotsi = DEG2RADF(170.0f); lamp->spotsi = DEG2RADF(170.0f);
lamp->spotsi = cosf(lamp->spotsi * 0.5f); lamp->spotsi = cosf(lamp->spotsi * 0.5f);
lamp->spotbl= (1.0f - lamp->spotsi)*la->spotblend; lamp->spotbl = (1.0f - lamp->spotsi) * la->spotblend;
lamp->k= la->k; lamp->k = la->k;
lamp->dist= la->dist; lamp->dist = la->dist;
lamp->falloff_type= la->falloff_type; lamp->falloff_type = la->falloff_type;
lamp->att1= la->att1; lamp->att1 = la->att1;
lamp->att2= la->att2; lamp->att2 = la->att2;
lamp->curfalloff= la->curfalloff; lamp->curfalloff = la->curfalloff;
/* initshadowbuf */ /* initshadowbuf */
lamp->bias = 0.02f*la->bias; lamp->bias = 0.02f * la->bias;
lamp->size = la->bufsize; lamp->size = la->bufsize;
lamp->d= la->clipsta; lamp->d = la->clipsta;
lamp->clipend= la->clipend; lamp->clipend = la->clipend;
/* arbitrary correction for the fact we do no soft transition */ /* arbitrary correction for the fact we do no soft transition */
lamp->bias *= 0.25f; lamp->bias *= 0.25f;
@ -1868,23 +1873,23 @@ static void gpu_lamp_shadow_free(GPULamp *lamp)
{ {
if (lamp->tex) { if (lamp->tex) {
GPU_texture_free(lamp->tex); GPU_texture_free(lamp->tex);
lamp->tex= NULL; lamp->tex = NULL;
} }
if (lamp->depthtex) { if (lamp->depthtex) {
GPU_texture_free(lamp->depthtex); GPU_texture_free(lamp->depthtex);
lamp->depthtex= NULL; lamp->depthtex = NULL;
} }
if (lamp->fb) { if (lamp->fb) {
GPU_framebuffer_free(lamp->fb); GPU_framebuffer_free(lamp->fb);
lamp->fb= NULL; lamp->fb = NULL;
} }
if (lamp->blurtex) { if (lamp->blurtex) {
GPU_texture_free(lamp->blurtex); GPU_texture_free(lamp->blurtex);
lamp->blurtex= NULL; lamp->blurtex = NULL;
} }
if (lamp->blurfb) { if (lamp->blurfb) {
GPU_framebuffer_free(lamp->blurfb); GPU_framebuffer_free(lamp->blurfb);
lamp->blurfb= NULL; lamp->blurfb = NULL;
} }
} }
@ -1894,7 +1899,7 @@ GPULamp *GPU_lamp_from_blender(Scene *scene, Object *ob, Object *par)
GPULamp *lamp; GPULamp *lamp;
LinkData *link; LinkData *link;
for (link=ob->gpulamp.first; link; link=link->next) { for (link = ob->gpulamp.first; link; link = link->next) {
lamp = (GPULamp*)link->data; lamp = (GPULamp*)link->data;
if (lamp->par == par && lamp->scene == scene) if (lamp->par == par && lamp->scene == scene)
@ -1910,7 +1915,7 @@ GPULamp *GPU_lamp_from_blender(Scene *scene, Object *ob, Object *par)
la = ob->data; la = ob->data;
gpu_lamp_from_blender(scene, ob, par, la, lamp); gpu_lamp_from_blender(scene, ob, par, la, lamp);
if ((la->type==LA_SPOT && (la->mode & (LA_SHAD_BUF | LA_SHAD_RAY))) || (la->type==LA_SUN && (la->mode & LA_SHAD_RAY))) { if ((la->type == LA_SPOT && (la->mode & (LA_SHAD_BUF | LA_SHAD_RAY))) || (la->type == LA_SUN && (la->mode & LA_SHAD_RAY))) {
/* opengl */ /* opengl */
lamp->fb = GPU_framebuffer_create(); lamp->fb = GPU_framebuffer_create();
if (!lamp->fb) { if (!lamp->fb) {
@ -1955,7 +1960,7 @@ GPULamp *GPU_lamp_from_blender(Scene *scene, Object *ob, Object *par)
return lamp; return lamp;
} }
lamp->blurtex = GPU_texture_create_vsm_shadow_map(lamp->size*0.5, NULL); lamp->blurtex = GPU_texture_create_vsm_shadow_map(lamp->size * 0.5, NULL);
if (!lamp->blurtex) { if (!lamp->blurtex) {
gpu_lamp_shadow_free(lamp); gpu_lamp_shadow_free(lamp);
return lamp; return lamp;
@ -2016,7 +2021,7 @@ void GPU_lamp_free(Object *ob)
LinkData *nlink; LinkData *nlink;
Material *ma; Material *ma;
for (link=ob->gpulamp.first; link; link=link->next) { for (link = ob->gpulamp.first; link; link = link->next) {
lamp = link->data; lamp = link->data;
while (lamp->materials.first) { while (lamp->materials.first) {
@ -2275,7 +2280,7 @@ GPUShaderExport *GPU_shader_export(struct Scene *scene, struct Material *ma)
} }
/* process builtin uniform */ /* process builtin uniform */
for (i=0; builtins[i].gputype; i++) { for (i = 0; builtins[i].gputype; i++) {
if (mat->builtins & builtins[i].gputype) { if (mat->builtins & builtins[i].gputype) {
uniform = MEM_callocN(sizeof(GPUInputUniform), "GPUInputUniform"); uniform = MEM_callocN(sizeof(GPUInputUniform), "GPUInputUniform");
uniform->type = builtins[i].dynamictype; uniform->type = builtins[i].dynamictype;
@ -2289,14 +2294,14 @@ GPUShaderExport *GPU_shader_export(struct Scene *scene, struct Material *ma)
/* TBD: remove the function that are not used in the main function */ /* TBD: remove the function that are not used in the main function */
liblen = (pass->libcode) ? strlen(pass->libcode) : 0; liblen = (pass->libcode) ? strlen(pass->libcode) : 0;
fraglen = strlen(pass->fragmentcode); fraglen = strlen(pass->fragmentcode);
shader->fragment = (char *)MEM_mallocN(liblen+fraglen+1, "GPUFragShader"); shader->fragment = (char *)MEM_mallocN(liblen + fraglen + 1, "GPUFragShader");
if (pass->libcode) if (pass->libcode)
memcpy(shader->fragment, pass->libcode, liblen); memcpy(shader->fragment, pass->libcode, liblen);
memcpy(&shader->fragment[liblen], pass->fragmentcode, fraglen); memcpy(&shader->fragment[liblen], pass->fragmentcode, fraglen);
shader->fragment[liblen+fraglen] = 0; shader->fragment[liblen + fraglen] = 0;
// export the attribute // export the attribute
for (i=0; i<mat->attribs.totlayer; i++) { for (i = 0; i < mat->attribs.totlayer; i++) {
attribute = MEM_callocN(sizeof(GPUInputAttribute), "GPUInputAttribute"); attribute = MEM_callocN(sizeof(GPUInputAttribute), "GPUInputAttribute");
attribute->type = mat->attribs.layer[i].type; attribute->type = mat->attribs.layer[i].type;
attribute->number = mat->attribs.layer[i].glindex; attribute->number = mat->attribs.layer[i].glindex;
@ -2325,7 +2330,7 @@ GPUShaderExport *GPU_shader_export(struct Scene *scene, struct Material *ma)
MEM_freeN(attribute); MEM_freeN(attribute);
} }
// export the vertex shader /* export the vertex shader */
shader->vertex = BLI_strdup(pass->vertexcode); shader->vertex = BLI_strdup(pass->vertexcode);
} }
@ -2339,7 +2344,7 @@ void GPU_free_shader_export(GPUShaderExport *shader)
if (shader == NULL) if (shader == NULL)
return; return;
for (uniform = shader->uniforms.first; uniform; uniform=uniform->next) for (uniform = shader->uniforms.first; uniform; uniform = uniform->next)
if (uniform->texpixels) if (uniform->texpixels)
MEM_freeN(uniform->texpixels); MEM_freeN(uniform->texpixels);