forked from bartvdbraak/blender
cleanup: use spaces for alignment
while studying GPU lib
This commit is contained in:
parent
722ddaaccd
commit
38321faa8d
@ -51,10 +51,10 @@ struct GPUVertPointLink;
|
||||
struct PBVH;
|
||||
|
||||
typedef struct GPUBuffer {
|
||||
int size; /* in bytes */
|
||||
void *pointer; /* used with vertex arrays */
|
||||
unsigned int id; /* used with vertex buffer objects */
|
||||
bool use_vbo; /* true for VBOs, false for vertex arrays */
|
||||
int size; /* in bytes */
|
||||
void *pointer; /* used with vertex arrays */
|
||||
unsigned int id; /* used with vertex buffer objects */
|
||||
bool use_vbo; /* true for VBOs, false for vertex arrays */
|
||||
} GPUBuffer;
|
||||
|
||||
typedef struct GPUBufferMaterial {
|
||||
|
@ -52,7 +52,7 @@ enum eGPUFXFlags;
|
||||
|
||||
typedef enum GPUFXShaderEffect {
|
||||
/* Screen space ambient occlusion shader */
|
||||
GPU_SHADER_FX_SSAO = 1,
|
||||
GPU_SHADER_FX_SSAO = 1,
|
||||
|
||||
/* depth of field passes. Yep, quite a complex effect */
|
||||
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);
|
||||
void GPU_clear_tpage(bool force);
|
||||
|
||||
/* Lights
|
||||
* - returns how many lights were enabled
|
||||
* - this affects fixed functions materials and texface, not glsl */
|
||||
|
@ -72,26 +72,26 @@ void GPU_code_generate_glsl_lib(void);
|
||||
/* GPU Types */
|
||||
|
||||
typedef enum GPUDeviceType {
|
||||
GPU_DEVICE_NVIDIA = (1<<0),
|
||||
GPU_DEVICE_ATI = (1<<1),
|
||||
GPU_DEVICE_INTEL = (1<<2),
|
||||
GPU_DEVICE_SOFTWARE = (1<<3),
|
||||
GPU_DEVICE_UNKNOWN = (1<<4),
|
||||
GPU_DEVICE_ANY = (0xff)
|
||||
GPU_DEVICE_NVIDIA = (1<<0),
|
||||
GPU_DEVICE_ATI = (1<<1),
|
||||
GPU_DEVICE_INTEL = (1<<2),
|
||||
GPU_DEVICE_SOFTWARE = (1<<3),
|
||||
GPU_DEVICE_UNKNOWN = (1<<4),
|
||||
GPU_DEVICE_ANY = (0xff)
|
||||
} GPUDeviceType;
|
||||
|
||||
typedef enum GPUOSType {
|
||||
GPU_OS_WIN = (1<<8),
|
||||
GPU_OS_MAC = (1<<9),
|
||||
GPU_OS_UNIX = (1<<10),
|
||||
GPU_OS_ANY = (0xff00)
|
||||
GPU_OS_WIN = (1<<8),
|
||||
GPU_OS_MAC = (1<<9),
|
||||
GPU_OS_UNIX = (1<<10),
|
||||
GPU_OS_ANY = (0xff00)
|
||||
} GPUOSType;
|
||||
|
||||
typedef enum GPUDriverType {
|
||||
GPU_DRIVER_OFFICIAL = (1<<16),
|
||||
GPU_DRIVER_OFFICIAL = (1<<16),
|
||||
GPU_DRIVER_OPENSOURCE = (1<<17),
|
||||
GPU_DRIVER_SOFTWARE = (1<<18),
|
||||
GPU_DRIVER_ANY = (0xff0000)
|
||||
GPU_DRIVER_SOFTWARE = (1<<18),
|
||||
GPU_DRIVER_ANY = (0xff0000)
|
||||
} GPUDriverType;
|
||||
|
||||
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 */
|
||||
typedef enum GPUBuiltinShader {
|
||||
GPU_SHADER_VSM_STORE = (1<<0),
|
||||
GPU_SHADER_SEP_GAUSSIAN_BLUR = (1<<1),
|
||||
GPU_SHADER_VSM_STORE = (1<<0),
|
||||
GPU_SHADER_SEP_GAUSSIAN_BLUR = (1<<1),
|
||||
} GPUBuiltinShader;
|
||||
|
||||
GPUShader *GPU_shader_get_builtin_shader(GPUBuiltinShader shader);
|
||||
@ -215,7 +215,7 @@ void GPU_shader_free_builtin_shaders(void);
|
||||
|
||||
/* Vertex attributes for shaders */
|
||||
|
||||
#define GPU_MAX_ATTRIB 32
|
||||
#define GPU_MAX_ATTRIB 32
|
||||
|
||||
typedef struct GPUVertexAttribs {
|
||||
struct {
|
||||
|
@ -92,7 +92,7 @@ typedef enum GPUBuiltin {
|
||||
GPU_VIEW_NORMAL = (1 << 5),
|
||||
GPU_OBCOLOR = (1 << 6),
|
||||
GPU_AUTO_BUMPSCALE = (1 << 7),
|
||||
GPU_CAMERA_TEXCO_FACTORS = (1 << 8),
|
||||
GPU_CAMERA_TEXCO_FACTORS = (1 << 8),
|
||||
} GPUBuiltin;
|
||||
|
||||
typedef enum GPUOpenGLBuiltin {
|
||||
@ -213,7 +213,7 @@ void GPU_shaderesult_set(GPUShadeInput *shi, GPUShadeResult *shr);
|
||||
|
||||
typedef enum GPUDataType {
|
||||
GPU_DATA_NONE = 0,
|
||||
GPU_DATA_1I = 1, // 1 integer
|
||||
GPU_DATA_1I = 1, /* 1 integer */
|
||||
GPU_DATA_1F = 2,
|
||||
GPU_DATA_2F = 3,
|
||||
GPU_DATA_3F = 4,
|
||||
@ -226,23 +226,23 @@ typedef enum GPUDataType {
|
||||
/* this structure gives information of each uniform found in the shader */
|
||||
typedef struct GPUInputUniform {
|
||||
struct GPUInputUniform *next, *prev;
|
||||
char varname[32]; /* name of uniform in shader */
|
||||
GPUDynamicType type; /* type of uniform, data format and calculation derive from it */
|
||||
GPUDataType datatype; /* type of uniform data */
|
||||
struct Object *lamp; /* when type=GPU_DYNAMIC_LAMP_... or GPU_DYNAMIC_SAMPLER_2DSHADOW */
|
||||
struct Image *image; /* when type=GPU_DYNAMIC_SAMPLER_2DIMAGE */
|
||||
int texnumber; /* when type=GPU_DYNAMIC_SAMPLER, texture number: 0.. */
|
||||
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) */
|
||||
char varname[32]; /* name of uniform in shader */
|
||||
GPUDynamicType type; /* type of uniform, data format and calculation derive from it */
|
||||
GPUDataType datatype; /* type of uniform data */
|
||||
struct Object *lamp; /* when type=GPU_DYNAMIC_LAMP_... or GPU_DYNAMIC_SAMPLER_2DSHADOW */
|
||||
struct Image *image; /* when type=GPU_DYNAMIC_SAMPLER_2DIMAGE */
|
||||
int texnumber; /* when type=GPU_DYNAMIC_SAMPLER, texture number: 0.. */
|
||||
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) */
|
||||
} GPUInputUniform;
|
||||
|
||||
typedef struct GPUInputAttribute {
|
||||
struct GPUInputAttribute *next, *prev;
|
||||
char varname[32]; /* name of attribute in shader */
|
||||
int type; /* from CustomData.type, data type derives from it */
|
||||
GPUDataType datatype; /* type of attribute data */
|
||||
const char *name; /* layer name */
|
||||
int number; /* generic attribute number */
|
||||
char varname[32]; /* name of attribute in shader */
|
||||
int type; /* from CustomData.type, data type derives from it */
|
||||
GPUDataType datatype; /* type of attribute data */
|
||||
const char *name; /* layer name */
|
||||
int number; /* generic attribute number */
|
||||
} GPUInputAttribute;
|
||||
|
||||
typedef struct GPUShaderExport {
|
||||
|
@ -42,11 +42,11 @@ extern "C" {
|
||||
|
||||
typedef enum GPUSimpleShaderOption {
|
||||
GPU_SHADER_OVERRIDE_DIFFUSE = (1<<0), /* replace diffuse with glcolor */
|
||||
GPU_SHADER_LIGHTING = (1<<1), /* use lighting */
|
||||
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_LIGHTING = (1<<1), /* use lighting */
|
||||
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_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_OPTION_COMBINATIONS = (1<<GPU_SHADER_OPTIONS_NUM)
|
||||
} GPUSimpleShaderOption;
|
||||
|
@ -383,8 +383,9 @@ void GPU_buffer_free(GPUBuffer *buffer)
|
||||
BLI_mutex_unlock(&buffer_mutex);
|
||||
}
|
||||
|
||||
/* currently unused */
|
||||
// #define USE_GPU_POINT_LINK
|
||||
#if 0 /* currently unused */
|
||||
# define USE_GPU_POINT_LINK
|
||||
#endif
|
||||
|
||||
typedef struct GPUVertPointLink {
|
||||
#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;
|
||||
|
||||
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 */
|
||||
gdo->vert_points = MEM_mallocN(sizeof(GPUVertPointLink) * gdo->totvert,
|
||||
"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_mcol, GL_ARRAY_BUFFER_ARB, 3},
|
||||
{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_uvedge, GL_ELEMENT_ARRAY_BUFFER_ARB, 4}
|
||||
};
|
||||
@ -1498,6 +1499,7 @@ struct GPU_PBVH_Buffers {
|
||||
bool use_matcaps;
|
||||
float diffuse_color[4];
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
VBO_ENABLED,
|
||||
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,
|
||||
int *vert_indices, int totvert, const float *vmask,
|
||||
int (*face_vert_indices)[4], bool show_diffuse_color)
|
||||
int *vert_indices, int totvert, const float *vmask,
|
||||
int (*face_vert_indices)[4], bool show_diffuse_color)
|
||||
{
|
||||
VertexBufferFormat *vert_data;
|
||||
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],
|
||||
MFace *mface, MVert *mvert,
|
||||
int *face_indices,
|
||||
int totface)
|
||||
MFace *mface, MVert *mvert,
|
||||
int *face_indices,
|
||||
int totface)
|
||||
{
|
||||
GPU_PBVH_Buffers *buffers;
|
||||
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,
|
||||
const DMFlagMat *grid_flag_mats, int *grid_indices,
|
||||
int totgrid, const CCGKey *key, bool show_diffuse_color)
|
||||
const DMFlagMat *grid_flag_mats, int *grid_indices,
|
||||
int totgrid, const CCGKey *key, bool show_diffuse_color)
|
||||
{
|
||||
VertexBufferFormat *vert_data;
|
||||
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
|
||||
* unsigned shorts or unsigned ints. */
|
||||
#define FILL_QUAD_BUFFER(type_, tot_quad_, buffer_) \
|
||||
{ \
|
||||
type_ *tri_data; \
|
||||
int offset = 0; \
|
||||
int i, j, k; \
|
||||
\
|
||||
glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, \
|
||||
sizeof(type_) * (tot_quad_) * 6, NULL, \
|
||||
GL_STATIC_DRAW_ARB); \
|
||||
\
|
||||
/* Fill the buffer */ \
|
||||
tri_data = glMapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, \
|
||||
GL_WRITE_ONLY_ARB); \
|
||||
if (tri_data) { \
|
||||
for (i = 0; i < totgrid; ++i) { \
|
||||
BLI_bitmap *gh = NULL; \
|
||||
if (grid_hidden) \
|
||||
gh = grid_hidden[(grid_indices)[i]]; \
|
||||
\
|
||||
for (j = 0; j < gridsize - 1; ++j) { \
|
||||
for (k = 0; k < gridsize - 1; ++k) { \
|
||||
/* Skip hidden grid face */ \
|
||||
if (gh && \
|
||||
paint_is_grid_face_hidden(gh, \
|
||||
gridsize, k, j)) \
|
||||
continue; \
|
||||
\
|
||||
*(tri_data++) = offset + j * gridsize + k + 1; \
|
||||
*(tri_data++) = offset + j * gridsize + k; \
|
||||
*(tri_data++) = offset + (j + 1) * gridsize + k; \
|
||||
\
|
||||
*(tri_data++) = offset + (j + 1) * gridsize + k + 1; \
|
||||
*(tri_data++) = offset + j * gridsize + k + 1; \
|
||||
*(tri_data++) = offset + (j + 1) * gridsize + k; \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
offset += gridsize * gridsize; \
|
||||
} \
|
||||
glUnmapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB); \
|
||||
} \
|
||||
else { \
|
||||
glDeleteBuffersARB(1, &(buffer_)); \
|
||||
(buffer_) = 0; \
|
||||
} \
|
||||
} (void)0
|
||||
{ \
|
||||
type_ *tri_data; \
|
||||
int offset = 0; \
|
||||
int i, j, k; \
|
||||
\
|
||||
glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, \
|
||||
sizeof(type_) * (tot_quad_) * 6, NULL, \
|
||||
GL_STATIC_DRAW_ARB); \
|
||||
\
|
||||
/* Fill the buffer */ \
|
||||
tri_data = glMapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, \
|
||||
GL_WRITE_ONLY_ARB); \
|
||||
if (tri_data) { \
|
||||
for (i = 0; i < totgrid; ++i) { \
|
||||
BLI_bitmap *gh = NULL; \
|
||||
if (grid_hidden) \
|
||||
gh = grid_hidden[(grid_indices)[i]]; \
|
||||
\
|
||||
for (j = 0; j < gridsize - 1; ++j) { \
|
||||
for (k = 0; k < gridsize - 1; ++k) { \
|
||||
/* Skip hidden grid face */ \
|
||||
if (gh && \
|
||||
paint_is_grid_face_hidden(gh, \
|
||||
gridsize, k, j)) \
|
||||
continue; \
|
||||
\
|
||||
*(tri_data++) = offset + j * gridsize + k + 1; \
|
||||
*(tri_data++) = offset + j * gridsize + k; \
|
||||
*(tri_data++) = offset + (j + 1) * gridsize + k; \
|
||||
\
|
||||
*(tri_data++) = offset + (j + 1) * gridsize + k + 1; \
|
||||
*(tri_data++) = offset + j * gridsize + k + 1; \
|
||||
*(tri_data++) = offset + (j + 1) * gridsize + k; \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
offset += gridsize * gridsize; \
|
||||
} \
|
||||
glUnmapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB); \
|
||||
} \
|
||||
else { \
|
||||
glDeleteBuffersARB(1, &(buffer_)); \
|
||||
(buffer_) = 0; \
|
||||
} \
|
||||
} (void)0
|
||||
/* end FILL_QUAD_BUFFER */
|
||||
|
||||
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,
|
||||
BLI_bitmap **grid_hidden, int gridsize)
|
||||
BLI_bitmap **grid_hidden, int gridsize)
|
||||
{
|
||||
GPU_PBVH_Buffers *buffers;
|
||||
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),
|
||||
diffuse_color,
|
||||
vd->color);
|
||||
|
||||
|
||||
/* Assign index for use in the triangle index buffer */
|
||||
/* 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
|
||||
* shading, an element index buffer. */
|
||||
void GPU_update_bmesh_pbvh_buffers(GPU_PBVH_Buffers *buffers,
|
||||
BMesh *bm,
|
||||
GSet *bm_faces,
|
||||
GSet *bm_unique_verts,
|
||||
GSet *bm_other_verts,
|
||||
bool show_diffuse_color)
|
||||
BMesh *bm,
|
||||
GSet *bm_faces,
|
||||
GSet *bm_unique_verts,
|
||||
GSet *bm_other_verts,
|
||||
bool show_diffuse_color)
|
||||
{
|
||||
VertexBufferFormat *vert_data;
|
||||
void *tri_data;
|
||||
@ -2204,8 +2205,8 @@ void GPU_update_bmesh_pbvh_buffers(GPU_PBVH_Buffers *buffers,
|
||||
/* Initialize vertex buffer */
|
||||
glBindBufferARB(GL_ARRAY_BUFFER_ARB, buffers->vert_buf);
|
||||
glBufferDataARB(GL_ARRAY_BUFFER_ARB,
|
||||
sizeof(VertexBufferFormat) * totvert,
|
||||
NULL, GL_STATIC_DRAW_ARB);
|
||||
sizeof(VertexBufferFormat) * totvert,
|
||||
NULL, GL_STATIC_DRAW_ARB);
|
||||
|
||||
/* Fill vertex buffer */
|
||||
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;
|
||||
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);
|
||||
|
||||
/* 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);
|
||||
}
|
||||
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) {
|
||||
GSetIterator gs_iter;
|
||||
BMFace *f;
|
||||
@ -2717,7 +2720,7 @@ static void gpu_pbvh_buffer_free_intern(GLuint id)
|
||||
if (pool->maxpbvhsize == pool->totpbvhbufids) {
|
||||
pool->maxpbvhsize += MAX_FREE_GPU_BUFF_IDS;
|
||||
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 */
|
||||
@ -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)
|
||||
{
|
||||
const float quads[4][4][3] = {
|
||||
{
|
||||
{min[0], min[1], min[2]},
|
||||
{max[0], min[1], min[2]},
|
||||
{max[0], min[1], max[2]},
|
||||
{min[0], min[1], max[2]}
|
||||
},
|
||||
{
|
||||
{min[0], min[1], min[2]},
|
||||
{max[0], min[1], min[2]},
|
||||
{max[0], min[1], max[2]},
|
||||
{min[0], min[1], max[2]}
|
||||
},
|
||||
|
||||
{
|
||||
{min[0], min[1], min[2]},
|
||||
{min[0], max[1], min[2]},
|
||||
{min[0], max[1], max[2]},
|
||||
{min[0], min[1], max[2]}
|
||||
},
|
||||
{
|
||||
{min[0], min[1], min[2]},
|
||||
{min[0], max[1], min[2]},
|
||||
{min[0], max[1], max[2]},
|
||||
{min[0], min[1], max[2]}
|
||||
},
|
||||
|
||||
{
|
||||
{max[0], max[1], min[2]},
|
||||
{max[0], min[1], min[2]},
|
||||
{max[0], min[1], max[2]},
|
||||
{max[0], max[1], max[2]}
|
||||
},
|
||||
{
|
||||
{max[0], max[1], min[2]},
|
||||
{max[0], min[1], min[2]},
|
||||
{max[0], min[1], max[2]},
|
||||
{max[0], max[1], max[2]}
|
||||
},
|
||||
|
||||
{
|
||||
{max[0], max[1], min[2]},
|
||||
{min[0], max[1], min[2]},
|
||||
{min[0], max[1], max[2]},
|
||||
{max[0], max[1], max[2]}
|
||||
},
|
||||
{
|
||||
{max[0], max[1], min[2]},
|
||||
{min[0], max[1], min[2]},
|
||||
{min[0], max[1], max[2]},
|
||||
{max[0], max[1], max[2]}
|
||||
},
|
||||
};
|
||||
|
||||
if (leaf)
|
||||
|
@ -46,7 +46,7 @@
|
||||
#include "GPU_material.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"
|
||||
|
||||
@ -90,9 +90,11 @@ static const char *GPU_DATATYPE_STR[17] = {"", "float", "vec2", "vec3", "vec4",
|
||||
/* GLSL code parsing for finding function definitions.
|
||||
* These are stored in a hash for lookup when creating a material. */
|
||||
|
||||
static GHash *FUNCTION_HASH= NULL;
|
||||
/* static char *FUNCTION_PROTOTYPES= NULL;
|
||||
* static GPUShader *FUNCTION_LIB= NULL;*/
|
||||
static GHash *FUNCTION_HASH = NULL;
|
||||
#if 0
|
||||
static char *FUNCTION_PROTOTYPES = NULL;
|
||||
static GPUShader *FUNCTION_LIB = NULL;
|
||||
#endif
|
||||
|
||||
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;
|
||||
else {
|
||||
if (token && len < max-1) {
|
||||
*token= *str;
|
||||
*token = *str;
|
||||
token++;
|
||||
len++;
|
||||
}
|
||||
@ -126,7 +128,7 @@ static char *gpu_str_skip_token(char *str, char *token, int max)
|
||||
}
|
||||
|
||||
if (token)
|
||||
*token= '\0';
|
||||
*token = '\0';
|
||||
|
||||
/* skip the next special characters:
|
||||
* 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);
|
||||
|
||||
/* test for type */
|
||||
type= GPU_NONE;
|
||||
for (i=1; i<=16; i++) {
|
||||
type = GPU_NONE;
|
||||
for (i = 1; i <= 16; i++) {
|
||||
if (GPU_DATATYPE_STR[i] && gpu_str_prefix(code, GPU_DATATYPE_STR[i])) {
|
||||
type= i;
|
||||
type = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -220,7 +222,7 @@ static char *gpu_generate_function_prototyps(GHash *hash)
|
||||
function = BLI_ghashIterator_getValue(ghi);
|
||||
|
||||
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)
|
||||
BLI_dynstr_append(ds, "out ");
|
||||
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");
|
||||
else
|
||||
BLI_dynstr_append(ds, GPU_DATATYPE_STR[function->paramtype[a]]);
|
||||
|
||||
//BLI_dynstr_appendf(ds, " param%d", a);
|
||||
|
||||
# if 0
|
||||
BLI_dynstr_appendf(ds, " param%d", a);
|
||||
# endif
|
||||
|
||||
if (a != function->totparam-1)
|
||||
BLI_dynstr_append(ds, ", ");
|
||||
}
|
||||
@ -267,7 +270,7 @@ void gpu_codegen_init(void)
|
||||
|
||||
void gpu_codegen_exit(void)
|
||||
{
|
||||
extern Material defmaterial; // render module abuse...
|
||||
extern Material defmaterial; /* render module abuse... */
|
||||
|
||||
if (defmaterial.gpumaterial.first)
|
||||
GPU_material_free(&defmaterial.gpumaterial);
|
||||
@ -284,14 +287,16 @@ void gpu_codegen_exit(void)
|
||||
glsl_material_library = NULL;
|
||||
}
|
||||
|
||||
/*if (FUNCTION_PROTOTYPES) {
|
||||
#if 0
|
||||
if (FUNCTION_PROTOTYPES) {
|
||||
MEM_freeN(FUNCTION_PROTOTYPES);
|
||||
FUNCTION_PROTOTYPES = NULL;
|
||||
}*/
|
||||
/*if (FUNCTION_LIB) {
|
||||
}
|
||||
if (FUNCTION_LIB) {
|
||||
GPU_shader_free(FUNCTION_LIB);
|
||||
FUNCTION_LIB = NULL;
|
||||
}*/
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/* 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]);
|
||||
|
||||
for (i=0; i<type; i++) {
|
||||
for (i = 0; i < type; i++) {
|
||||
BLI_dynstr_appendf(ds, "%f", data[i]);
|
||||
if (i == type-1)
|
||||
if (i == type - 1)
|
||||
BLI_dynstr_append(ds, ")");
|
||||
else
|
||||
BLI_dynstr_append(ds, ", ");
|
||||
@ -412,11 +417,11 @@ static void codegen_set_unique_ids(ListBase *nodes)
|
||||
GPUOutput *output;
|
||||
int id = 1, texid = 0;
|
||||
|
||||
bindhash= BLI_ghash_ptr_new("codegen_set_unique_ids1 gh");
|
||||
definehash= BLI_ghash_ptr_new("codegen_set_unique_ids2 gh");
|
||||
bindhash = BLI_ghash_ptr_new("codegen_set_unique_ids1 gh");
|
||||
definehash = BLI_ghash_ptr_new("codegen_set_unique_ids2 gh");
|
||||
|
||||
for (node=nodes->first; node; node=node->next) {
|
||||
for (input=node->inputs.first; input; input=input->next) {
|
||||
for (node = nodes->first; node; node = node->next) {
|
||||
for (input = node->inputs.first; input; input = input->next) {
|
||||
/* set id for unique names of uniform variables */
|
||||
input->id = id++;
|
||||
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 */
|
||||
output->id = id++;
|
||||
}
|
||||
@ -480,8 +485,8 @@ static int codegen_print_uniforms_functions(DynStr *ds, ListBase *nodes)
|
||||
int builtins = 0;
|
||||
|
||||
/* print uniforms */
|
||||
for (node=nodes->first; node; node=node->next) {
|
||||
for (input=node->inputs.first; input; input=input->next) {
|
||||
for (node = nodes->first; node; node = node->next) {
|
||||
for (input = node->inputs.first; input; input = input->next) {
|
||||
if ((input->source == GPU_SOURCE_TEX) || (input->source == GPU_SOURCE_TEX_PIXEL)) {
|
||||
/* create exactly one sampler for each texture */
|
||||
if (codegen_input_has_texture(input) && input->bindtex)
|
||||
@ -537,9 +542,9 @@ static void codegen_declare_tmps(DynStr *ds, ListBase *nodes)
|
||||
GPUInput *input;
|
||||
GPUOutput *output;
|
||||
|
||||
for (node=nodes->first; node; node=node->next) {
|
||||
for (node = nodes->first; node; node = node->next) {
|
||||
/* 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 (codegen_input_has_texture(input) && input->definetex) {
|
||||
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 */
|
||||
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",
|
||||
GPU_DATATYPE_STR[output->type], output->id);
|
||||
}
|
||||
@ -564,10 +569,10 @@ static void codegen_call_functions(DynStr *ds, ListBase *nodes, GPUOutput *final
|
||||
GPUInput *input;
|
||||
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);
|
||||
|
||||
for (input=node->inputs.first; input; input=input->next) {
|
||||
for (input = node->inputs.first; input; input = input->next) {
|
||||
if (input->source == GPU_SOURCE_TEX) {
|
||||
BLI_dynstr_appendf(ds, "samp%d", input->texid);
|
||||
if (input->link)
|
||||
@ -602,7 +607,7 @@ static void codegen_call_functions(DynStr *ds, ListBase *nodes, GPUOutput *final
|
||||
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);
|
||||
if (output->next)
|
||||
BLI_dynstr_append(ds, ", ");
|
||||
@ -622,13 +627,17 @@ static char *code_generate_fragment(ListBase *nodes, GPUOutput *output)
|
||||
char *code;
|
||||
int builtins;
|
||||
|
||||
/*BLI_dynstr_append(ds, FUNCTION_PROTOTYPES);*/
|
||||
#if 0
|
||||
BLI_dynstr_append(ds, FUNCTION_PROTOTYPES);
|
||||
#endif
|
||||
|
||||
codegen_set_unique_ids(nodes);
|
||||
builtins = codegen_print_uniforms_functions(ds, nodes);
|
||||
|
||||
//if (G.debug & G_DEBUG)
|
||||
// BLI_dynstr_appendf(ds, "/* %s */\n", name);
|
||||
#if 0
|
||||
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, "{\n");
|
||||
@ -645,7 +654,9 @@ static char *code_generate_fragment(ListBase *nodes, GPUOutput *output)
|
||||
code = BLI_dynstr_get_cstring(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;
|
||||
}
|
||||
@ -658,8 +669,8 @@ static char *code_generate_vertex(ListBase *nodes, const GPUMatType type)
|
||||
char *code;
|
||||
char *vertcode;
|
||||
|
||||
for (node=nodes->first; node; node=node->next) {
|
||||
for (input=node->inputs.first; input; input=input->next) {
|
||||
for (node = nodes->first; node; node = node->next) {
|
||||
for (input = node->inputs.first; input; input = input->next) {
|
||||
if (input->source == GPU_SOURCE_ATTRIB && input->attribfirst) {
|
||||
BLI_dynstr_appendf(ds, "attribute %s att%d;\n",
|
||||
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);
|
||||
|
||||
for (node=nodes->first; node; node=node->next)
|
||||
for (input=node->inputs.first; input; input=input->next)
|
||||
for (node = nodes->first; node; node = node->next)
|
||||
for (input = node->inputs.first; input; input = input->next)
|
||||
if (input->source == GPU_SOURCE_ATTRIB && input->attribfirst) {
|
||||
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);
|
||||
@ -714,7 +725,9 @@ static char *code_generate_vertex(ListBase *nodes, const GPUMatType type)
|
||||
|
||||
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;
|
||||
}
|
||||
@ -760,9 +773,9 @@ static void gpu_nodes_extract_dynamic_inputs(GPUPass *pass, ListBase *nodes)
|
||||
|
||||
GPU_shader_bind(shader);
|
||||
|
||||
for (node=nodes->first; node; node=node->next) {
|
||||
for (node = nodes->first; node; node = node->next) {
|
||||
z = 0;
|
||||
for (input=node->inputs.first; input; input=next, z++) {
|
||||
for (input = node->inputs.first; input; input = next, z++) {
|
||||
next = input->next;
|
||||
|
||||
/* 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);
|
||||
|
||||
/* now bind the textures */
|
||||
for (input=inputs->first; input; input=input->next) {
|
||||
for (input = inputs->first; input; input = input->next) {
|
||||
if (input->ima)
|
||||
input->tex = GPU_texture_from_blender(input->ima, input->iuser, input->image_isdata, time, mipmap);
|
||||
else if (input->prv)
|
||||
@ -839,7 +852,7 @@ void GPU_pass_update_uniforms(GPUPass *pass)
|
||||
return;
|
||||
|
||||
/* 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))
|
||||
GPU_shader_uniform_vector(shader, input->shaderloc, input->type, 1,
|
||||
input->dynamicvec);
|
||||
@ -854,7 +867,7 @@ void GPU_pass_unbind(GPUPass *pass)
|
||||
if (!shader)
|
||||
return;
|
||||
|
||||
for (input=inputs->first; input; input=input->next) {
|
||||
for (input = inputs->first; input; input = input->next) {
|
||||
if (input->tex && input->bindtex)
|
||||
GPU_texture_unbind(input->tex);
|
||||
|
||||
@ -896,7 +909,7 @@ static GPUNode *GPU_node_begin(const char *name)
|
||||
{
|
||||
GPUNode *node = MEM_callocN(sizeof(GPUNode), "GPUNode");
|
||||
|
||||
node->name= name;
|
||||
node->name = name;
|
||||
|
||||
return node;
|
||||
}
|
||||
@ -965,7 +978,9 @@ static void gpu_node_input_link(GPUNode *node, GPUNodeLink *link, const GPUType
|
||||
input->source = GPU_SOURCE_TEX;
|
||||
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->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));
|
||||
if (link->dynamic) {
|
||||
input->dynamicvec= link->ptr1;
|
||||
input->dynamictype= link->dynamictype;
|
||||
input->dynamicdata= link->ptr2;
|
||||
input->dynamicvec = link->ptr1;
|
||||
input->dynamictype = link->dynamictype;
|
||||
input->dynamicdata = link->ptr2;
|
||||
}
|
||||
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->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
|
||||
* set that pointer to NULL */
|
||||
}
|
||||
@ -1052,7 +1067,7 @@ static void gpu_inputs_free(ListBase *inputs)
|
||||
{
|
||||
GPUInput *input;
|
||||
|
||||
for (input=inputs->first; input; input=input->next) {
|
||||
for (input = inputs->first; input; input = input->next) {
|
||||
if (input->link)
|
||||
gpu_node_link_free(input->link);
|
||||
else if (input->tex && !input->dynamictex)
|
||||
@ -1068,7 +1083,7 @@ static void gpu_node_free(GPUNode *node)
|
||||
|
||||
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) {
|
||||
output->link->output = NULL;
|
||||
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));
|
||||
|
||||
for (node=nodes->first; node; node=node->next) {
|
||||
for (input=node->inputs.first; input; input=input->next) {
|
||||
for (node = nodes->first; node; node = node->next) {
|
||||
for (input = node->inputs.first; input; input = input->next) {
|
||||
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 &&
|
||||
STREQ(attribs->layer[a].name, input->attribname))
|
||||
{
|
||||
@ -1135,10 +1150,10 @@ static void gpu_nodes_get_builtin_flag(ListBase *nodes, int *builtin)
|
||||
GPUNode *node;
|
||||
GPUInput *input;
|
||||
|
||||
*builtin= 0;
|
||||
*builtin = 0;
|
||||
|
||||
for (node=nodes->first; node; node=node->next)
|
||||
for (input=node->inputs.first; input; input=input->next)
|
||||
for (node = nodes->first; node; node = node->next)
|
||||
for (input = node->inputs.first; input; input = input->next)
|
||||
if (input->source == GPU_SOURCE_BUILTIN)
|
||||
*builtin |= input->builtin;
|
||||
}
|
||||
@ -1149,8 +1164,8 @@ GPUNodeLink *GPU_attribute(const CustomDataType type, const char *name)
|
||||
{
|
||||
GPUNodeLink *link = GPU_node_link_create();
|
||||
|
||||
link->attribtype= type;
|
||||
link->attribname= name;
|
||||
link->attribtype = type;
|
||||
link->attribname = name;
|
||||
|
||||
return link;
|
||||
}
|
||||
@ -1159,8 +1174,8 @@ GPUNodeLink *GPU_uniform(float *num)
|
||||
{
|
||||
GPUNodeLink *link = GPU_node_link_create();
|
||||
|
||||
link->ptr1= num;
|
||||
link->ptr2= NULL;
|
||||
link->ptr1 = num;
|
||||
link->ptr2 = NULL;
|
||||
|
||||
return link;
|
||||
}
|
||||
@ -1169,9 +1184,9 @@ GPUNodeLink *GPU_dynamic_uniform(float *num, GPUDynamicType dynamictype, void *d
|
||||
{
|
||||
GPUNodeLink *link = GPU_node_link_create();
|
||||
|
||||
link->ptr1= num;
|
||||
link->ptr2= data;
|
||||
link->dynamic= true;
|
||||
link->ptr1 = num;
|
||||
link->ptr2 = data;
|
||||
link->dynamic = true;
|
||||
link->dynamictype = dynamictype;
|
||||
|
||||
|
||||
@ -1194,8 +1209,8 @@ GPUNodeLink *GPU_image_preview(PreviewImage *prv)
|
||||
{
|
||||
GPUNodeLink *link = GPU_node_link_create();
|
||||
|
||||
link->image= GPU_NODE_LINK_IMAGE_PREVIEW;
|
||||
link->ptr1= prv;
|
||||
link->image = GPU_NODE_LINK_IMAGE_PREVIEW;
|
||||
link->ptr1 = prv;
|
||||
|
||||
return link;
|
||||
}
|
||||
@ -1207,7 +1222,7 @@ GPUNodeLink *GPU_texture(int size, float *pixels)
|
||||
|
||||
link->texture = true;
|
||||
link->texturesize = size;
|
||||
link->ptr1= pixels;
|
||||
link->ptr1 = pixels;
|
||||
|
||||
return link;
|
||||
}
|
||||
@ -1259,13 +1274,13 @@ bool GPU_link(GPUMaterial *mat, const char *name, ...)
|
||||
node = GPU_node_begin(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) {
|
||||
linkptr= va_arg(params, GPUNodeLink**);
|
||||
linkptr = va_arg(params, GPUNodeLink**);
|
||||
gpu_node_output(node, function->paramtype[i], linkptr);
|
||||
}
|
||||
else {
|
||||
link= va_arg(params, GPUNodeLink*);
|
||||
link = va_arg(params, GPUNodeLink*);
|
||||
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);
|
||||
for (i=0; i<function->totparam; i++) {
|
||||
for (i = 0; i<function->totparam; i++) {
|
||||
if (function->paramqual[i] != FUNCTION_QUAL_IN) {
|
||||
if (totout == 0) {
|
||||
linkptr= va_arg(params, GPUNodeLink**);
|
||||
linkptr = va_arg(params, GPUNodeLink**);
|
||||
gpu_node_output(node, function->paramtype[i], linkptr);
|
||||
}
|
||||
else
|
||||
@ -1320,7 +1335,7 @@ bool GPU_stack_link(GPUMaterial *mat, const char *name, GPUNodeStack *in, GPUNod
|
||||
}
|
||||
else {
|
||||
if (totin == 0) {
|
||||
link= va_arg(params, GPUNodeLink*);
|
||||
link = va_arg(params, GPUNodeLink*);
|
||||
if (link->socket)
|
||||
gpu_node_input_socket(node, link->socket);
|
||||
else
|
||||
@ -1373,7 +1388,7 @@ static void gpu_nodes_tag(GPUNodeLink *link)
|
||||
return;
|
||||
|
||||
node->tag = true;
|
||||
for (input=node->inputs.first; input; input=input->next)
|
||||
for (input = node->inputs.first; input; input = input->next)
|
||||
if (input->link)
|
||||
gpu_nodes_tag(input->link);
|
||||
}
|
||||
@ -1382,12 +1397,12 @@ static void gpu_nodes_prune(ListBase *nodes, GPUNodeLink *outlink)
|
||||
{
|
||||
GPUNode *node, *next;
|
||||
|
||||
for (node=nodes->first; node; node=node->next)
|
||||
for (node = nodes->first; node; node = node->next)
|
||||
node->tag = false;
|
||||
|
||||
gpu_nodes_tag(outlink);
|
||||
|
||||
for (node=nodes->first; node; node=next) {
|
||||
for (node = nodes->first; node; node = next) {
|
||||
next = node->next;
|
||||
|
||||
if (!node->tag) {
|
||||
@ -1405,10 +1420,12 @@ GPUPass *GPU_generate_pass(ListBase *nodes, GPUNodeLink *outlink,
|
||||
GPUPass *pass;
|
||||
char *vertexcode, *fragmentcode;
|
||||
|
||||
/*if (!FUNCTION_LIB) {
|
||||
#if 0
|
||||
if (!FUNCTION_LIB) {
|
||||
GPU_nodes_free(nodes);
|
||||
return NULL;
|
||||
}*/
|
||||
}
|
||||
#endif
|
||||
|
||||
/* prune unused nodes */
|
||||
gpu_nodes_prune(nodes, outlink);
|
||||
|
@ -113,9 +113,9 @@ typedef struct GPUOutput {
|
||||
struct GPUOutput *next, *prev;
|
||||
|
||||
GPUNode *node;
|
||||
GPUType type; /* data type = length of vector/matrix */
|
||||
GPUNodeLink *link; /* output link */
|
||||
int id; /* unique id as created by code generator */
|
||||
GPUType type; /* data type = length of vector/matrix */
|
||||
GPUNodeLink *link; /* output link */
|
||||
int id; /* unique id as created by code generator */
|
||||
} GPUOutput;
|
||||
|
||||
typedef struct GPUInput {
|
||||
@ -123,35 +123,35 @@ typedef struct GPUInput {
|
||||
|
||||
GPUNode *node;
|
||||
|
||||
GPUType type; /* datatype */
|
||||
GPUDataSource source; /* data source */
|
||||
GPUType type; /* datatype */
|
||||
GPUDataSource source; /* data source */
|
||||
|
||||
int id; /* unique id as created by code generator */
|
||||
int texid; /* number for multitexture, starting from zero */
|
||||
int attribid; /* id for vertex attributes */
|
||||
bool bindtex; /* input is responsible for binding the texture? */
|
||||
bool definetex; /* input is responsible for defining the pixel? */
|
||||
int textarget; /* GL texture target, e.g. GL_TEXTURE_2D */
|
||||
GPUType textype; /* datatype */
|
||||
int id; /* unique id as created by code generator */
|
||||
int texid; /* number for multitexture, starting from zero */
|
||||
int attribid; /* id for vertex attributes */
|
||||
bool bindtex; /* input is responsible for binding the texture? */
|
||||
bool definetex; /* input is responsible for defining the pixel? */
|
||||
int textarget; /* GL texture target, e.g. GL_TEXTURE_2D */
|
||||
GPUType textype; /* datatype */
|
||||
|
||||
struct Image *ima; /* image */
|
||||
struct ImageUser *iuser;/* image user */
|
||||
struct PreviewImage *prv; /* preview images & icons */
|
||||
bool image_isdata; /* image does not contain color data */
|
||||
float *dynamicvec; /* vector data in case it is dynamic */
|
||||
GPUDynamicType dynamictype; /* origin of the dynamic uniform */
|
||||
void *dynamicdata; /* data source of the dynamic uniform */
|
||||
struct GPUTexture *tex; /* input texture, only set at runtime */
|
||||
int shaderloc; /* id from opengl */
|
||||
char shadername[32]; /* name in shader */
|
||||
struct Image *ima; /* image */
|
||||
struct ImageUser *iuser; /* image user */
|
||||
struct PreviewImage *prv; /* preview images & icons */
|
||||
bool image_isdata; /* image does not contain color data */
|
||||
float *dynamicvec; /* vector data in case it is dynamic */
|
||||
GPUDynamicType dynamictype; /* origin of the dynamic uniform */
|
||||
void *dynamicdata; /* data source of the dynamic uniform */
|
||||
struct GPUTexture *tex; /* input texture, only set at runtime */
|
||||
int shaderloc; /* id from opengl */
|
||||
char shadername[32]; /* name in shader */
|
||||
|
||||
float vec[16]; /* vector data */
|
||||
float vec[16]; /* vector data */
|
||||
GPUNodeLink *link;
|
||||
bool dynamictex; /* dynamic? */
|
||||
CustomDataType attribtype; /* attribute type */
|
||||
char attribname[MAX_CUSTOMDATA_LAYER_NAME]; /* attribute name */
|
||||
int attribfirst; /* this is the first one that is bound */
|
||||
GPUBuiltin builtin; /* builtin uniform */
|
||||
bool dynamictex; /* dynamic? */
|
||||
CustomDataType attribtype; /* attribute type */
|
||||
char attribname[MAX_CUSTOMDATA_LAYER_NAME]; /* attribute name */
|
||||
int attribfirst; /* this is the first one that is bound */
|
||||
GPUBuiltin builtin; /* builtin uniform */
|
||||
GPUOpenGLBuiltin oglbuiltin; /* opengl built in varying */
|
||||
} GPUInput;
|
||||
|
||||
@ -170,8 +170,8 @@ struct GPUPass {
|
||||
typedef struct GPUPass GPUPass;
|
||||
|
||||
GPUPass *GPU_generate_pass(ListBase *nodes, struct GPUNodeLink *outlink,
|
||||
struct GPUVertexAttribs *attribs, int *builtin,
|
||||
const GPUMatType type, const char *name);
|
||||
struct GPUVertexAttribs *attribs, int *builtin,
|
||||
const GPUMatType type, const char *name);
|
||||
|
||||
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 {
|
||||
/* 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 */
|
||||
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))) {
|
||||
printf(".256%s\n", err_out);
|
||||
cleanup_fx_gl_data(fx, true);
|
||||
@ -497,13 +497,13 @@ bool GPU_fx_compositor_initialize_passes(
|
||||
/* bind the 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);
|
||||
|
||||
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);
|
||||
|
||||
if(!GPU_framebuffer_check_valid(fx->gbuffer, err_out))
|
||||
if (!GPU_framebuffer_check_valid(fx->gbuffer, err_out))
|
||||
printf("%.256s\n", err_out);
|
||||
|
||||
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);
|
||||
|
||||
/* 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);
|
||||
}
|
||||
|
||||
|
@ -45,7 +45,7 @@
|
||||
|
||||
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_INVALID_ENUM)
|
||||
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)
|
||||
{
|
||||
switch(err) {
|
||||
switch (err) {
|
||||
case GL_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_GREEN_BITS, &g);
|
||||
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);
|
||||
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])
|
||||
{
|
||||
const char *err= "unknown";
|
||||
const char *err = "unknown";
|
||||
|
||||
switch (status) {
|
||||
case GL_FRAMEBUFFER_COMPLETE_EXT:
|
||||
break;
|
||||
case GL_INVALID_OPERATION:
|
||||
err= "Invalid operation";
|
||||
err = "Invalid operation";
|
||||
break;
|
||||
case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT:
|
||||
err= "Incomplete attachment";
|
||||
err = "Incomplete attachment";
|
||||
break;
|
||||
case GL_FRAMEBUFFER_UNSUPPORTED_EXT:
|
||||
err= "Unsupported framebuffer format";
|
||||
err = "Unsupported framebuffer format";
|
||||
break;
|
||||
case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT:
|
||||
err= "Missing attachment";
|
||||
err = "Missing attachment";
|
||||
break;
|
||||
case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT:
|
||||
err= "Attached images must have same dimensions";
|
||||
err = "Attached images must have same dimensions";
|
||||
break;
|
||||
case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT:
|
||||
err= "Attached images must have same format";
|
||||
err = "Attached images must have same format";
|
||||
break;
|
||||
case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT:
|
||||
err= "Missing draw buffer";
|
||||
err = "Missing draw buffer";
|
||||
break;
|
||||
case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT:
|
||||
err= "Missing read buffer";
|
||||
err = "Missing read buffer";
|
||||
break;
|
||||
}
|
||||
|
||||
@ -343,36 +343,36 @@ static void GPU_print_framebuffer_error(GLenum status, char err_out[256])
|
||||
/* GPUTexture */
|
||||
|
||||
struct GPUTexture {
|
||||
int w, h; /* width/height */
|
||||
int number; /* number for multitexture binding */
|
||||
int refcount; /* reference count */
|
||||
GLenum target; /* GL_TEXTURE_* */
|
||||
GLuint bindcode; /* opengl identifier for texture */
|
||||
int fromblender; /* we got the texture from Blender */
|
||||
int w, h; /* width/height */
|
||||
int number; /* number for multitexture binding */
|
||||
int refcount; /* reference count */
|
||||
GLenum target; /* GL_TEXTURE_* */
|
||||
GLuint bindcode; /* opengl identifier for texture */
|
||||
int fromblender; /* we got the texture from Blender */
|
||||
|
||||
GPUFrameBuffer *fb; /* GPUFramebuffer this texture is attached to */
|
||||
int fb_attachment; /* slot the texture is attached to */
|
||||
int depth; /* is a depth texture? if 3D how deep? */
|
||||
GPUFrameBuffer *fb; /* GPUFramebuffer this texture is attached to */
|
||||
int fb_attachment; /* slot the texture is attached to */
|
||||
int depth; /* is a depth texture? if 3D how deep? */
|
||||
};
|
||||
|
||||
static unsigned char *GPU_texture_convert_pixels(int length, const float *fpixels)
|
||||
{
|
||||
unsigned char *pixels, *p;
|
||||
const float *fp = fpixels;
|
||||
const int len = 4*length;
|
||||
const int len = 4 * length;
|
||||
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++)
|
||||
*p = FTOCHAR(*fp);
|
||||
for (a = 0; a < len; a++, p++, fp++)
|
||||
*p = FTOCHAR((*fp));
|
||||
|
||||
return pixels;
|
||||
}
|
||||
|
||||
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)
|
||||
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;
|
||||
}
|
||||
|
||||
//if (fpixels)
|
||||
// pixels = GPU_texture_convert_pixels(w*h*depth, fpixels);
|
||||
#if 0
|
||||
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);
|
||||
|
||||
@ -972,7 +974,7 @@ GPUFrameBuffer *GPU_framebuffer_create(void)
|
||||
if (!GLEW_EXT_framebuffer_object)
|
||||
return NULL;
|
||||
|
||||
fb= MEM_callocN(sizeof(GPUFrameBuffer), "GPUFrameBuffer");
|
||||
fb = MEM_callocN(sizeof(GPUFrameBuffer), "GPUFrameBuffer");
|
||||
glGenFramebuffersEXT(1, &fb->object);
|
||||
|
||||
if (!fb->object) {
|
||||
@ -1065,8 +1067,7 @@ void GPU_framebuffer_texture_detach(GPUTexture *tex)
|
||||
attachment = GL_COLOR_ATTACHMENT0_EXT + tex->fb_attachment;
|
||||
}
|
||||
|
||||
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, attachment,
|
||||
tex->target, 0, 0);
|
||||
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, attachment, tex->target, 0, 0);
|
||||
|
||||
tex->fb = NULL;
|
||||
tex->fb_attachment = -1;
|
||||
@ -1116,7 +1117,7 @@ void GPU_framebuffer_slots_bind(GPUFrameBuffer *fb, int slot)
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0 ; i < 4; i++) {
|
||||
for (i = 0; i < 4; i++) {
|
||||
if (fb->colortex[i]) {
|
||||
attachments[numslots] = GL_COLOR_ATTACHMENT0_EXT + i;
|
||||
numslots++;
|
||||
@ -1306,7 +1307,7 @@ GPUOffScreen *GPU_offscreen_create(int width, int height, char err_out[256])
|
||||
{
|
||||
GPUOffScreen *ofs;
|
||||
|
||||
ofs= MEM_callocN(sizeof(GPUOffScreen), "GPUOffScreen");
|
||||
ofs = MEM_callocN(sizeof(GPUOffScreen), "GPUOffScreen");
|
||||
|
||||
ofs->fb = GPU_framebuffer_create();
|
||||
if (!ofs->fb) {
|
||||
@ -1395,13 +1396,13 @@ int GPU_offscreen_height(const GPUOffScreen *ofs)
|
||||
/* GPUShader */
|
||||
|
||||
struct GPUShader {
|
||||
GLhandleARB object; /* handle for full shader */
|
||||
GLhandleARB vertex; /* handle for vertex shader */
|
||||
GLhandleARB fragment; /* handle for fragment shader */
|
||||
GLhandleARB geometry; /* handle for geometry shader */
|
||||
GLhandleARB lib; /* handle for libment shader */
|
||||
int totattrib; /* total number of attributes */
|
||||
int uniforms; /* required uniforms */
|
||||
GLhandleARB object; /* handle for full shader */
|
||||
GLhandleARB vertex; /* handle for vertex shader */
|
||||
GLhandleARB fragment; /* handle for fragment shader */
|
||||
GLhandleARB geometry; /* handle for geometry shader */
|
||||
GLhandleARB lib; /* handle for libment shader */
|
||||
int totattrib; /* total number of attributes */
|
||||
int uniforms; /* required uniforms */
|
||||
};
|
||||
|
||||
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];
|
||||
while ((c < end) && (pos = strchr(c, '\n'))) {
|
||||
fprintf(stderr, "%2d ", line);
|
||||
fwrite(c, (pos+1)-c, 1, stderr);
|
||||
c = pos+1;
|
||||
fwrite(c, (pos + 1) - c, 1, stderr);
|
||||
c = pos + 1;
|
||||
line++;
|
||||
}
|
||||
|
||||
@ -1447,7 +1448,7 @@ static const char *gpu_shader_version(void)
|
||||
|
||||
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())
|
||||
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]) {
|
||||
GPUShader *shader;
|
||||
|
||||
switch(effects) {
|
||||
switch (effects) {
|
||||
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);
|
||||
break;
|
||||
@ -1896,7 +1897,8 @@ void GPU_shader_free_builtin_shaders(void)
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
#if 0 /* unused */
|
||||
|
||||
/* GPUPixelBuffer */
|
||||
|
||||
typedef struct GPUPixelBuffer {
|
||||
@ -1922,7 +1924,7 @@ GPUPixelBuffer *gpu_pixelbuffer_create(int x, int y, int halffloat, int numbuffe
|
||||
return NULL;
|
||||
|
||||
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->halffloat = halffloat;
|
||||
|
||||
@ -1950,10 +1952,13 @@ void GPU_pixelbuffer_texture(GPUTexture *tex, GPUPixelBuffer *pb)
|
||||
GL_STREAM_DRAW_ARB);
|
||||
|
||||
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)) {
|
||||
fprintf(stderr, "Could not unmap opengl PBO\n");
|
||||
fprintf(stderr, "Could not unmap OpenGL PBO\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -1971,7 +1976,7 @@ static int pixelbuffer_map_into_gpu(GLuint bindcode)
|
||||
/* do stuff in pixels */
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@ -1984,8 +1989,7 @@ static void pixelbuffer_copy_to_texture(GPUTexture *tex, GPUPixelBuffer *pb, GLu
|
||||
glBindTexture(GL_TEXTURE_RECTANGLE_EXT, tex->bindcode);
|
||||
glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, bindcode);
|
||||
|
||||
glTexSubImage2D(GL_TEXTURE_RECTANGLE_EXT, 0, 0, 0, tex->w, tex->h,
|
||||
GL_RGBA, type, NULL);
|
||||
glTexSubImage2D(GL_TEXTURE_RECTANGLE_EXT, 0, 0, 0, tex->w, tex->h, GL_RGBA, type, NULL);
|
||||
|
||||
glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_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]);
|
||||
}
|
||||
else {
|
||||
pb->current = (pb->current+1)%pb->numbuffers;
|
||||
newbuffer = (pb->current+1)%pb->numbuffers;
|
||||
pb->current = (pb->current + 1) % pb->numbuffers;
|
||||
newbuffer = (pb->current + 1) % pb->numbuffers;
|
||||
|
||||
pixelbuffer_map_into_gpu(pb->bindcode[newbuffer]);
|
||||
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");
|
||||
|
||||
material->ma= ma;
|
||||
material->ma = ma;
|
||||
|
||||
return material;
|
||||
}
|
||||
@ -170,14 +170,14 @@ static void gpu_material_set_attrib_id(GPUMaterial *material)
|
||||
char name[32];
|
||||
int a, b;
|
||||
|
||||
attribs= &material->attribs;
|
||||
pass= material->pass;
|
||||
attribs = &material->attribs;
|
||||
pass = material->pass;
|
||||
if (!pass) {
|
||||
attribs->totlayer = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
shader= GPU_pass_shader(pass);
|
||||
shader = GPU_pass_shader(pass);
|
||||
if (!shader) {
|
||||
attribs->totlayer = 0;
|
||||
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
|
||||
* 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);
|
||||
attribs->layer[a].glindex = GPU_shader_get_attribute(shader, name);
|
||||
|
||||
@ -242,19 +242,19 @@ void GPU_material_free(ListBase *gpumaterial)
|
||||
LinkData *link;
|
||||
LinkData *nlink, *mlink, *next;
|
||||
|
||||
for (link=gpumaterial->first; link; link=link->next) {
|
||||
for (link = gpumaterial->first; link; link = link->next) {
|
||||
GPUMaterial *material = link->data;
|
||||
|
||||
if (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;
|
||||
|
||||
if (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;
|
||||
if (mlink->data == ma)
|
||||
BLI_freelinkN(&lamp->materials, mlink);
|
||||
@ -293,8 +293,8 @@ void GPU_material_bind(GPUMaterial *material, int oblay, int viewlay, double tim
|
||||
|
||||
/* handle layer lamps */
|
||||
if (material->type == GPU_MATERIAL_TYPE_MESH) {
|
||||
for (nlink=material->lamps.first; nlink; nlink=nlink->next) {
|
||||
lamp= nlink->data;
|
||||
for (nlink = material->lamps.first; nlink; nlink = nlink->next) {
|
||||
lamp = nlink->data;
|
||||
|
||||
if (!lamp->hide && (lamp->lay & viewlay) && (!(lamp->mode & LA_LAYER) || (lamp->lay & oblay))
|
||||
&& 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 {
|
||||
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) {
|
||||
@ -414,12 +414,12 @@ void GPU_material_vertex_attributes(GPUMaterial *material, GPUVertexAttribs *att
|
||||
void GPU_material_output_link(GPUMaterial *material, GPUNodeLink *link)
|
||||
{
|
||||
if (!material->outlink)
|
||||
material->outlink= link;
|
||||
material->outlink = link;
|
||||
}
|
||||
|
||||
void GPU_material_enable_alpha(GPUMaterial *material)
|
||||
{
|
||||
material->alpha= 1;
|
||||
material->alpha = 1;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
/* 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;
|
||||
GPU_link(mat, "lamp_visibility_sun_hemi", GPU_dynamic_uniform(lamp->dynvec, GPU_DYNAMIC_LAMP_DYNVEC, lamp->ob), lv, dist, &visifac);
|
||||
return visifac;
|
||||
@ -464,7 +464,7 @@ static GPUNodeLink *lamp_get_visibility(GPUMaterial *mat, GPULamp *lamp, GPUNode
|
||||
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);
|
||||
|
||||
if (lamp->type==LA_AREA)
|
||||
if (lamp->type == LA_AREA)
|
||||
return visifac;
|
||||
|
||||
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);
|
||||
break;
|
||||
case LA_FALLOFF_CURVE:
|
||||
{
|
||||
float *array;
|
||||
int size;
|
||||
{
|
||||
float *array;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
if (lamp->mode & LA_SPHERE)
|
||||
@ -516,34 +517,34 @@ static GPUNodeLink *lamp_get_visibility(GPUMaterial *mat, GPULamp *lamp, GPUNode
|
||||
#if 0
|
||||
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 */
|
||||
multifac= 1.0f/sqrt((float)lar->ray_totsamp);
|
||||
multifac = 1.0f / sqrtf((float)lar->ray_totsamp);
|
||||
xsize *= multifac;
|
||||
ysize *= multifac;
|
||||
|
||||
/* corner vectors */
|
||||
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][2]= lar->co[2] - xsize*lar->mat[0][2] - ysize*lar->mat[1][2];
|
||||
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][2] = lar->co[2] - xsize * lar->mat[0][2] - ysize * lar->mat[1][2];
|
||||
|
||||
/* corner vectors */
|
||||
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][2]= lar->co[2] - xsize*lar->mat[0][2] + ysize*lar->mat[1][2];
|
||||
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][2] = lar->co[2] - xsize * lar->mat[0][2] + ysize * lar->mat[1][2];
|
||||
|
||||
/* corner vectors */
|
||||
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][2]= lar->co[2] + xsize*lar->mat[0][2] + ysize*lar->mat[1][2];
|
||||
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][2] = lar->co[2] + xsize * lar->mat[0][2] + ysize * lar->mat[1][2];
|
||||
|
||||
/* corner vectors */
|
||||
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][2]= lar->co[2] + xsize*lar->mat[0][2] - ysize*lar->mat[1][2];
|
||||
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][2] = lar->co[2] + xsize * lar->mat[0][2] - ysize * lar->mat[1][2];
|
||||
/* 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
|
||||
|
||||
@ -577,8 +578,8 @@ static void do_colorband_blend(GPUMaterial *mat, ColorBand *coba, GPUNodeLink *f
|
||||
|
||||
static void ramp_diffuse_result(GPUShadeInput *shi, GPUNodeLink **diff)
|
||||
{
|
||||
Material *ma= shi->mat;
|
||||
GPUMaterial *mat= shi->gpumat;
|
||||
Material *ma = shi->mat;
|
||||
GPUMaterial *mat = shi->gpumat;
|
||||
GPUNodeLink *fac;
|
||||
|
||||
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 {
|
||||
/* input */
|
||||
switch (ma->rampin_col) {
|
||||
case MA_RAMP_IN_ENERGY:
|
||||
GPU_link(mat, "ramp_rgbtobw", rgb, &fac);
|
||||
break;
|
||||
case MA_RAMP_IN_SHADER:
|
||||
fac= is;
|
||||
break;
|
||||
case MA_RAMP_IN_NOR:
|
||||
GPU_link(mat, "vec_math_dot", shi->view, shi->vn, &tmp, &fac);
|
||||
break;
|
||||
default:
|
||||
GPU_link(mat, "set_value_zero", &fac);
|
||||
break;
|
||||
case MA_RAMP_IN_ENERGY:
|
||||
GPU_link(mat, "ramp_rgbtobw", rgb, &fac);
|
||||
break;
|
||||
case MA_RAMP_IN_SHADER:
|
||||
fac= is;
|
||||
break;
|
||||
case MA_RAMP_IN_NOR:
|
||||
GPU_link(mat, "vec_math_dot", shi->view, shi->vn, &tmp, &fac);
|
||||
break;
|
||||
default:
|
||||
GPU_link(mat, "set_value_zero", &fac);
|
||||
break;
|
||||
}
|
||||
|
||||
/* 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)
|
||||
{
|
||||
Material *ma= shi->mat;
|
||||
GPUMaterial *mat= shi->gpumat;
|
||||
Material *ma = shi->mat;
|
||||
GPUMaterial *mat = shi->gpumat;
|
||||
GPUNodeLink *fac;
|
||||
|
||||
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);
|
||||
|
||||
@ -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)
|
||||
{
|
||||
Material *ma= shi->mat;
|
||||
GPUMaterial *mat= shi->gpumat;
|
||||
Material *ma = shi->mat;
|
||||
GPUMaterial *mat = shi->gpumat;
|
||||
GPUNodeLink *fac, *tmp;
|
||||
|
||||
*spec = shi->specrgb;
|
||||
|
||||
/* 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 */
|
||||
switch (ma->rampin_spec) {
|
||||
case MA_RAMP_IN_ENERGY:
|
||||
fac = t;
|
||||
break;
|
||||
case MA_RAMP_IN_SHADER:
|
||||
fac = is;
|
||||
break;
|
||||
case MA_RAMP_IN_NOR:
|
||||
GPU_link(mat, "vec_math_dot", shi->view, shi->vn, &tmp, &fac);
|
||||
break;
|
||||
default:
|
||||
GPU_link(mat, "set_value_zero", &fac);
|
||||
break;
|
||||
case MA_RAMP_IN_ENERGY:
|
||||
fac = t;
|
||||
break;
|
||||
case MA_RAMP_IN_SHADER:
|
||||
fac = is;
|
||||
break;
|
||||
case MA_RAMP_IN_NOR:
|
||||
GPU_link(mat, "vec_math_dot", shi->view, shi->vn, &tmp, &fac);
|
||||
break;
|
||||
default:
|
||||
GPU_link(mat, "set_value_zero", &fac);
|
||||
break;
|
||||
}
|
||||
|
||||
/* colorband + blend */
|
||||
@ -694,10 +695,10 @@ static void shade_light_textures(GPUMaterial *mat, GPULamp *lamp, GPUNodeLink **
|
||||
int i;
|
||||
float one = 1.f;
|
||||
|
||||
for (i=0; i<MAX_MTEX; ++i) {
|
||||
for (i = 0; i < MAX_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;
|
||||
|
||||
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_dynamic_uniform((float*)lamp->dynpersmat, GPU_DYNAMIC_LAMP_DYNPERSMAT, lamp->ob),
|
||||
&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)
|
||||
{
|
||||
Material *ma= shi->mat;
|
||||
GPUMaterial *mat= shi->gpumat;
|
||||
Material *ma = shi->mat;
|
||||
GPUMaterial *mat = shi->gpumat;
|
||||
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;
|
||||
|
||||
if ((lamp->mode & LA_ONLYSHADOW) && !(ma->mode & MA_SHADOW))
|
||||
return;
|
||||
|
||||
vn= shi->vn;
|
||||
view= shi->view;
|
||||
vn = shi->vn;
|
||||
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)
|
||||
GPU_link(mat, "shade_tangent_v", lv, GPU_attribute(CD_TANGENT, ""), &vn);*/
|
||||
#if 0
|
||||
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);
|
||||
|
||||
@ -739,23 +742,23 @@ static void shade_one_light(GPUShadeInput *shi, GPUShadeResult *shr, GPULamp *la
|
||||
}
|
||||
else {
|
||||
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;
|
||||
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);
|
||||
}
|
||||
|
||||
is= inp; /* Lambert */
|
||||
is = inp; /* Lambert */
|
||||
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
@ -777,7 +780,7 @@ static void shade_one_light(GPUShadeInput *shi, GPUShadeResult *shr, GPULamp *la
|
||||
#endif
|
||||
|
||||
/* 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 (!(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);
|
||||
}
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
else
|
||||
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_t", shadfac, shi->spec, visifac, specfac, &t);
|
||||
@ -891,9 +894,9 @@ static void material_lights(GPUShadeInput *shi, GPUShadeResult *shr)
|
||||
GPULamp *lamp;
|
||||
|
||||
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);
|
||||
if (lamp)
|
||||
shade_one_light(shi, shr, lamp);
|
||||
@ -903,10 +906,10 @@ static void material_lights(GPUShadeInput *shi, GPUShadeResult *shr)
|
||||
DupliObject *dob;
|
||||
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;
|
||||
|
||||
if (ob_iter->type==OB_LAMP) {
|
||||
if (ob_iter->type == OB_LAMP) {
|
||||
float omat[4][4];
|
||||
copy_m4_m4(omat, ob_iter->obmat);
|
||||
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)
|
||||
{
|
||||
Material *ma= shi->mat;
|
||||
GPUMaterial *mat= shi->gpumat;
|
||||
Material *ma = shi->mat;
|
||||
GPUMaterial *mat = shi->gpumat;
|
||||
MTex *mtex;
|
||||
Tex *tex;
|
||||
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];
|
||||
int tex_nr, rgbnor, talpha;
|
||||
bool init_done = false;
|
||||
int iBumpSpacePrev = 0; /* Not necessary, quiting gcc warning. */
|
||||
int iBumpSpacePrev = 0; /* Not necessary, quieting gcc warning. */
|
||||
GPUNodeLink *vNorg, *vNacc, *fPrevMagnitude;
|
||||
int iFirstTimeNMap=1;
|
||||
int iFirstTimeNMap = 1;
|
||||
int found_deriv_map = 0;
|
||||
|
||||
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_builtin(GPU_INVERSE_OBJECT_MATRIX),
|
||||
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_builtin(GPU_VIEW_POSITION), &texco_global);
|
||||
|
||||
orn= texco_norm;
|
||||
|
||||
/* 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 */
|
||||
if (ma->septex & (1<<tex_nr)) continue;
|
||||
if (ma->septex & (1 << tex_nr)) continue;
|
||||
|
||||
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;
|
||||
|
||||
/* which coords */
|
||||
if (mtex->texco==TEXCO_ORCO)
|
||||
texco= texco_orco;
|
||||
else if (mtex->texco==TEXCO_OBJECT)
|
||||
texco= texco_object;
|
||||
else if (mtex->texco==TEXCO_NORM)
|
||||
texco= orn;
|
||||
else if (mtex->texco==TEXCO_TANGENT)
|
||||
texco= texco_object;
|
||||
else if (mtex->texco==TEXCO_GLOB)
|
||||
texco= texco_global;
|
||||
else if (mtex->texco==TEXCO_REFL) {
|
||||
if (mtex->texco == TEXCO_ORCO)
|
||||
texco = texco_orco;
|
||||
else if (mtex->texco == TEXCO_OBJECT)
|
||||
texco = texco_object;
|
||||
else if (mtex->texco == TEXCO_NORM)
|
||||
texco = orn;
|
||||
else if (mtex->texco == TEXCO_TANGENT)
|
||||
texco = texco_object;
|
||||
else if (mtex->texco == TEXCO_GLOB)
|
||||
texco = texco_global;
|
||||
else if (mtex->texco == TEXCO_REFL) {
|
||||
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)) {
|
||||
GPU_link(mat, "texco_uv", GPU_attribute(CD_MTFACE, mtex->uvname), &texco_uv);
|
||||
/*lastuvname = mtex->uvname;*/ /*UNUSED*/
|
||||
}
|
||||
texco= texco_uv;
|
||||
texco = texco_uv;
|
||||
}
|
||||
else
|
||||
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)
|
||||
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[1] = mtex->ofs[1] + 0.5f - 0.5f*mtex->size[1];
|
||||
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[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);
|
||||
@ -1106,7 +1111,7 @@ static void do_material_tex(GPUShadeInput *shi)
|
||||
|
||||
if (tex && tex->type == TEX_IMAGE && tex->ima) {
|
||||
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);
|
||||
}
|
||||
@ -1151,7 +1156,7 @@ static void do_material_tex(GPUShadeInput *shi)
|
||||
GPU_link(mat, "set_value_one", &tin);
|
||||
}
|
||||
|
||||
if (tex->type==TEX_IMAGE)
|
||||
if (tex->type == TEX_IMAGE)
|
||||
if (GPU_material_do_color_management(mat))
|
||||
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 (tex->type==TEX_IMAGE) {
|
||||
if (tex->type == TEX_IMAGE) {
|
||||
found_deriv_map = tex->imaflag & TEX_DERIVATIVEMAP;
|
||||
|
||||
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 */
|
||||
int iBumpSpace;
|
||||
float ima_x, ima_y;
|
||||
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;
|
||||
|
||||
GPUNodeLink *vR1, *vR2;
|
||||
GPUNodeLink *dBs, *dBt, *fDet;
|
||||
|
||||
hScale = 0.1; // compatibility adjustment factor for all bumpspace types
|
||||
if ( mtex->texflag & MTEX_BUMP_TEXTURESPACE )
|
||||
hScale = 13.0f; // factor for scaling texspace bumps
|
||||
hScale = 0.1; /* compatibility adjustment factor for all bumpspace types */
|
||||
if (mtex->texflag & MTEX_BUMP_TEXTURESPACE)
|
||||
hScale = 13.0f; /* factor for scaling texspace bumps */
|
||||
else if (found_deriv_map!=0)
|
||||
hScale = 1.0f;
|
||||
|
||||
// resolve texture resolution
|
||||
if ( (mtex->texflag & MTEX_BUMP_TEXTURESPACE) || found_deriv_map ) {
|
||||
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
|
||||
/* resolve texture resolution */
|
||||
if ((mtex->texflag & MTEX_BUMP_TEXTURESPACE) || found_deriv_map) {
|
||||
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 */
|
||||
if (ibuf) {
|
||||
ima_x= ibuf->x;
|
||||
ima_y= ibuf->y;
|
||||
aspect = ((float) ima_y) / ima_x;
|
||||
ima_x = ibuf->x;
|
||||
ima_y = ibuf->y;
|
||||
aspect = (float)ima_y / ima_x;
|
||||
}
|
||||
BKE_image_release_ibuf(tex->ima, ibuf, NULL);
|
||||
}
|
||||
|
||||
// The negate on norfac is done because the
|
||||
// normal in the renderer points inward which corresponds
|
||||
// to inverting the bump map. Should this ever change
|
||||
// this negate must be removed.
|
||||
/* The negate on norfac is done because the
|
||||
* normal in the renderer points inward which corresponds
|
||||
* to inverting the bump map. Should this ever change
|
||||
* this negate must be removed. */
|
||||
norfac = -hScale * mtex->norfac;
|
||||
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);
|
||||
}
|
||||
|
||||
@ -1273,26 +1278,26 @@ static void do_material_tex(GPUShadeInput *shi)
|
||||
if (GPU_link_changed(stencil))
|
||||
GPU_link(mat, "math_multiply", tnorfac, stencil, &tnorfac);
|
||||
|
||||
if ( !init_done ) {
|
||||
// copy shi->vn to vNorg and vNacc, set magnitude to 1
|
||||
if (!init_done) {
|
||||
/* copy shi->vn to vNorg and vNacc, set magnitude to 1 */
|
||||
GPU_link(mat, "mtex_bump_normals_init", shi->vn, &vNorg, &vNacc, &fPrevMagnitude);
|
||||
iBumpSpacePrev = 0;
|
||||
init_done = true;
|
||||
}
|
||||
|
||||
// find current bump space
|
||||
if ( mtex->texflag & MTEX_BUMP_OBJECTSPACE )
|
||||
if (mtex->texflag & MTEX_BUMP_OBJECTSPACE)
|
||||
iBumpSpace = 1;
|
||||
else if ( mtex->texflag & MTEX_BUMP_TEXTURESPACE )
|
||||
else if (mtex->texflag & MTEX_BUMP_TEXTURESPACE)
|
||||
iBumpSpace = 2;
|
||||
else
|
||||
iBumpSpace = 4; // ViewSpace
|
||||
iBumpSpace = 4; /* ViewSpace */
|
||||
|
||||
// re-initialize if bump space changed
|
||||
if ( iBumpSpacePrev != iBumpSpace ) {
|
||||
/* re-initialize if bump space changed */
|
||||
if (iBumpSpacePrev != iBumpSpace) {
|
||||
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",
|
||||
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),
|
||||
@ -1300,7 +1305,7 @@ static void do_material_tex(GPUShadeInput *shi)
|
||||
&fPrevMagnitude, &vNacc,
|
||||
&vR1, &vR2, &fDet);
|
||||
|
||||
else if ( mtex->texflag & MTEX_BUMP_TEXTURESPACE )
|
||||
else if (mtex->texflag & MTEX_BUMP_TEXTURESPACE)
|
||||
GPU_link(mat, "mtex_bump_init_texturespace",
|
||||
surf_pos, vNorg,
|
||||
fPrevMagnitude, vNacc,
|
||||
@ -1321,17 +1326,17 @@ static void do_material_tex(GPUShadeInput *shi)
|
||||
if (found_deriv_map) {
|
||||
GPU_link(mat, "mtex_bump_deriv",
|
||||
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",
|
||||
texco, GPU_image(tex->ima, &tex->iuser, true), tnorfac,
|
||||
&dBs, &dBt );
|
||||
else if ( mtex->texflag & MTEX_5TAP_BUMP)
|
||||
&dBs, &dBt);
|
||||
else if (mtex->texflag & MTEX_5TAP_BUMP)
|
||||
GPU_link(mat, "mtex_bump_tap5",
|
||||
texco, GPU_image(tex->ima, &tex->iuser, true), tnorfac,
|
||||
&dBs, &dBt );
|
||||
else if ( mtex->texflag & MTEX_BICUBIC_BUMP ) {
|
||||
&dBs, &dBt);
|
||||
else if (mtex->texflag & MTEX_BICUBIC_BUMP) {
|
||||
if (GPU_bicubic_bump_support()) {
|
||||
GPU_link(mat, "mtex_bump_bicubic",
|
||||
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 ) {
|
||||
float imag_tspace_dimension_y = aspect*imag_tspace_dimension_x;
|
||||
if (mtex->texflag & MTEX_BUMP_TEXTURESPACE) {
|
||||
float imag_tspace_dimension_y = aspect * imag_tspace_dimension_x;
|
||||
GPU_link(mat, "mtex_bump_apply_texspace",
|
||||
fDet, dBs, dBt, vR1, vR2,
|
||||
GPU_image(tex->ima, &tex->iuser, true), texco,
|
||||
GPU_uniform(&imag_tspace_dimension_x), GPU_uniform(&imag_tspace_dimension_y), vNacc,
|
||||
&vNacc, &shi->vn );
|
||||
&vNacc, &shi->vn);
|
||||
}
|
||||
else
|
||||
GPU_link(mat, "mtex_bump_apply",
|
||||
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)
|
||||
{
|
||||
GPUMaterial *mat= shi->gpumat;
|
||||
GPUMaterial *mat = shi->gpumat;
|
||||
GPUNodeLink *emit, *ulinfac, *ulogfac, *mistfac;
|
||||
Material *ma= shi->mat;
|
||||
World *world= mat->scene->world;
|
||||
Material *ma = shi->mat;
|
||||
World *world = mat->scene->world;
|
||||
float linfac, logfac, misttype;
|
||||
|
||||
memset(shr, 0, sizeof(*shr));
|
||||
@ -1487,7 +1492,7 @@ void GPU_shaderesult_set(GPUShadeInput *shi, GPUShadeResult *shr)
|
||||
}
|
||||
else {
|
||||
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_mul", emit, shi->rgb, &shr->diff);
|
||||
}
|
||||
@ -1507,9 +1512,9 @@ void GPU_shaderesult_set(GPUShadeInput *shi, GPUShadeResult *shr)
|
||||
|
||||
if (world) {
|
||||
/* exposure correction */
|
||||
if (world->exp!=0.0f || world->range!=1.0f) {
|
||||
linfac= 1.0f + powf((2.0f*world->exp + 0.5f), -10);
|
||||
logfac= logf((linfac-1.0f)/linfac)/world->range;
|
||||
if (world->exp != 0.0f || world->range != 1.0f) {
|
||||
linfac = 1.0f + powf((2.0f * world->exp + 0.5f), -10);
|
||||
logfac = logf((linfac - 1.0f) / linfac) / world->range;
|
||||
|
||||
GPU_link(mat, "set_value", GPU_uniform(&linfac), &ulinfac);
|
||||
GPU_link(mat, "set_value", GPU_uniform(&logfac), &ulogfac);
|
||||
@ -1521,7 +1526,7 @@ void GPU_shaderesult_set(GPUShadeInput *shi, GPUShadeResult *shr)
|
||||
}
|
||||
|
||||
/* 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)
|
||||
GPU_link(mat, "shade_maddf", shr->combined, GPU_uniform(&ma->amb),
|
||||
GPU_uniform(&world->ambr), &shr->combined);
|
||||
@ -1612,7 +1617,7 @@ GPUMaterial *GPU_material_matcap(Scene *scene, Material *ma)
|
||||
GPUNodeLink *outlink;
|
||||
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)
|
||||
return link->data;
|
||||
|
||||
@ -1648,7 +1653,7 @@ GPUMaterial *GPU_material_world(struct Scene *scene, struct World *wo)
|
||||
LinkData *link;
|
||||
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)
|
||||
return link->data;
|
||||
|
||||
@ -1688,7 +1693,7 @@ GPUMaterial *GPU_material_from_blender(Scene *scene, Material *ma)
|
||||
GPUNodeLink *outlink;
|
||||
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)
|
||||
return link->data;
|
||||
|
||||
@ -1745,15 +1750,15 @@ void GPU_materials_free(void)
|
||||
World *wo;
|
||||
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);
|
||||
|
||||
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(&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);
|
||||
}
|
||||
|
||||
@ -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)
|
||||
{
|
||||
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[1]= g;
|
||||
lamp->col[2]= b;
|
||||
lamp->col[0] = r;
|
||||
lamp->col[1] = g;
|
||||
lamp->col[2] = b;
|
||||
}
|
||||
|
||||
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->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[1]= la->g;
|
||||
lamp->col[2]= la->b;
|
||||
lamp->col[0] = la->r;
|
||||
lamp->col[1] = la->g;
|
||||
lamp->col[2] = la->b;
|
||||
|
||||
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))
|
||||
lamp->spotsi = DEG2RADF(170.0f);
|
||||
lamp->spotsi = cosf(lamp->spotsi * 0.5f);
|
||||
lamp->spotbl= (1.0f - lamp->spotsi)*la->spotblend;
|
||||
lamp->k= la->k;
|
||||
lamp->spotbl = (1.0f - lamp->spotsi) * la->spotblend;
|
||||
lamp->k = la->k;
|
||||
|
||||
lamp->dist= la->dist;
|
||||
lamp->falloff_type= la->falloff_type;
|
||||
lamp->att1= la->att1;
|
||||
lamp->att2= la->att2;
|
||||
lamp->curfalloff= la->curfalloff;
|
||||
lamp->dist = la->dist;
|
||||
lamp->falloff_type = la->falloff_type;
|
||||
lamp->att1 = la->att1;
|
||||
lamp->att2 = la->att2;
|
||||
lamp->curfalloff = la->curfalloff;
|
||||
|
||||
/* initshadowbuf */
|
||||
lamp->bias = 0.02f*la->bias;
|
||||
lamp->bias = 0.02f * la->bias;
|
||||
lamp->size = la->bufsize;
|
||||
lamp->d= la->clipsta;
|
||||
lamp->clipend= la->clipend;
|
||||
lamp->d = la->clipsta;
|
||||
lamp->clipend = la->clipend;
|
||||
|
||||
/* arbitrary correction for the fact we do no soft transition */
|
||||
lamp->bias *= 0.25f;
|
||||
@ -1868,23 +1873,23 @@ static void gpu_lamp_shadow_free(GPULamp *lamp)
|
||||
{
|
||||
if (lamp->tex) {
|
||||
GPU_texture_free(lamp->tex);
|
||||
lamp->tex= NULL;
|
||||
lamp->tex = NULL;
|
||||
}
|
||||
if (lamp->depthtex) {
|
||||
GPU_texture_free(lamp->depthtex);
|
||||
lamp->depthtex= NULL;
|
||||
lamp->depthtex = NULL;
|
||||
}
|
||||
if (lamp->fb) {
|
||||
GPU_framebuffer_free(lamp->fb);
|
||||
lamp->fb= NULL;
|
||||
lamp->fb = NULL;
|
||||
}
|
||||
if (lamp->blurtex) {
|
||||
GPU_texture_free(lamp->blurtex);
|
||||
lamp->blurtex= NULL;
|
||||
lamp->blurtex = NULL;
|
||||
}
|
||||
if (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;
|
||||
LinkData *link;
|
||||
|
||||
for (link=ob->gpulamp.first; link; link=link->next) {
|
||||
for (link = ob->gpulamp.first; link; link = link->next) {
|
||||
lamp = (GPULamp*)link->data;
|
||||
|
||||
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;
|
||||
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 */
|
||||
lamp->fb = GPU_framebuffer_create();
|
||||
if (!lamp->fb) {
|
||||
@ -1955,7 +1960,7 @@ GPULamp *GPU_lamp_from_blender(Scene *scene, Object *ob, Object *par)
|
||||
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) {
|
||||
gpu_lamp_shadow_free(lamp);
|
||||
return lamp;
|
||||
@ -2016,7 +2021,7 @@ void GPU_lamp_free(Object *ob)
|
||||
LinkData *nlink;
|
||||
Material *ma;
|
||||
|
||||
for (link=ob->gpulamp.first; link; link=link->next) {
|
||||
for (link = ob->gpulamp.first; link; link = link->next) {
|
||||
lamp = link->data;
|
||||
|
||||
while (lamp->materials.first) {
|
||||
@ -2275,7 +2280,7 @@ GPUShaderExport *GPU_shader_export(struct Scene *scene, struct Material *ma)
|
||||
}
|
||||
|
||||
/* process builtin uniform */
|
||||
for (i=0; builtins[i].gputype; i++) {
|
||||
for (i = 0; builtins[i].gputype; i++) {
|
||||
if (mat->builtins & builtins[i].gputype) {
|
||||
uniform = MEM_callocN(sizeof(GPUInputUniform), "GPUInputUniform");
|
||||
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 */
|
||||
liblen = (pass->libcode) ? strlen(pass->libcode) : 0;
|
||||
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)
|
||||
memcpy(shader->fragment, pass->libcode, liblen);
|
||||
memcpy(&shader->fragment[liblen], pass->fragmentcode, fraglen);
|
||||
shader->fragment[liblen+fraglen] = 0;
|
||||
shader->fragment[liblen + fraglen] = 0;
|
||||
|
||||
// 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->type = mat->attribs.layer[i].type;
|
||||
attribute->number = mat->attribs.layer[i].glindex;
|
||||
@ -2325,7 +2330,7 @@ GPUShaderExport *GPU_shader_export(struct Scene *scene, struct Material *ma)
|
||||
MEM_freeN(attribute);
|
||||
}
|
||||
|
||||
// export the vertex shader
|
||||
/* export the vertex shader */
|
||||
shader->vertex = BLI_strdup(pass->vertexcode);
|
||||
}
|
||||
|
||||
@ -2339,7 +2344,7 @@ void GPU_free_shader_export(GPUShaderExport *shader)
|
||||
if (shader == NULL)
|
||||
return;
|
||||
|
||||
for (uniform = shader->uniforms.first; uniform; uniform=uniform->next)
|
||||
for (uniform = shader->uniforms.first; uniform; uniform = uniform->next)
|
||||
if (uniform->texpixels)
|
||||
MEM_freeN(uniform->texpixels);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user