Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2012-03-24 10:38:07 +0400
committerCampbell Barton <ideasman42@gmail.com>2012-03-24 10:38:07 +0400
commitab4a2aaf4a4b2b4e416aa1f113b30362cbe0dec3 (patch)
tree81af4c18519181490074508dbe9a8d515eab634f /source/blender/gpu
parent5a90ea77bc1333efe4e1e54984a080550ed3f707 (diff)
style cleanup: follow style guide for formatting of if/for/while loops, and else if's
Diffstat (limited to 'source/blender/gpu')
-rw-r--r--source/blender/gpu/intern/gpu_buffers.c379
-rw-r--r--source/blender/gpu/intern/gpu_codegen.c214
-rw-r--r--source/blender/gpu/intern/gpu_draw.c276
-rw-r--r--source/blender/gpu/intern/gpu_extensions.c102
-rw-r--r--source/blender/gpu/intern/gpu_material.c428
5 files changed, 701 insertions, 698 deletions
diff --git a/source/blender/gpu/intern/gpu_buffers.c b/source/blender/gpu/intern/gpu_buffers.c
index 8698f036491..bf4df2e9b0a 100644
--- a/source/blender/gpu/intern/gpu_buffers.c
+++ b/source/blender/gpu/intern/gpu_buffers.c
@@ -98,7 +98,7 @@ static GPUBufferPool *gpu_buffer_pool_new(void)
GPUBufferPool *pool;
/* enable VBOs if supported */
- if(useVBOs == -1)
+ if (useVBOs == -1)
useVBOs = (GLEW_ARB_vertex_buffer_object ? 1 : 0);
pool = MEM_callocN(sizeof(GPUBufferPool), "GPUBuffer");
@@ -115,15 +115,15 @@ static void gpu_buffer_pool_remove_index(GPUBufferPool *pool, int index)
{
int i;
- if(!pool || index < 0 || index >= pool->totbuf)
+ if (!pool || index < 0 || index >= pool->totbuf)
return;
/* shift entries down, overwriting the buffer at `index' */
- for(i = index; i < pool->totbuf - 1; i++)
+ for (i = index; i < pool->totbuf - 1; i++)
pool->buffers[i] = pool->buffers[i+1];
/* clear the last entry */
- if(pool->totbuf > 0)
+ if (pool->totbuf > 0)
pool->buffers[pool->totbuf - 1] = NULL;
pool->totbuf--;
@@ -134,15 +134,15 @@ static void gpu_buffer_pool_delete_last(GPUBufferPool *pool)
{
GPUBuffer *last;
- if(pool->totbuf <= 0)
+ if (pool->totbuf <= 0)
return;
/* get the last entry */
- if(!(last = pool->buffers[pool->totbuf - 1]))
+ if (!(last = pool->buffers[pool->totbuf - 1]))
return;
/* delete the buffer's data */
- if(useVBOs)
+ if (useVBOs)
glDeleteBuffersARB(1, &last->id);
else
MEM_freeN(last->pointer);
@@ -157,7 +157,7 @@ static void gpu_buffer_pool_delete_last(GPUBufferPool *pool)
GPUBuffers */
static void gpu_buffer_pool_free(GPUBufferPool *pool)
{
- if(!pool)
+ if (!pool)
return;
while(pool->totbuf)
@@ -171,7 +171,7 @@ static GPUBufferPool *gpu_buffer_pool = NULL;
static GPUBufferPool *gpu_get_global_buffer_pool(void)
{
/* initialize the pool */
- if(!gpu_buffer_pool)
+ if (!gpu_buffer_pool)
gpu_buffer_pool = gpu_buffer_pool_new();
return gpu_buffer_pool;
@@ -201,21 +201,21 @@ GPUBuffer *GPU_buffer_alloc(int size)
/* check the global buffer pool for a recently-deleted buffer
that is at least as big as the request, but not more than
twice as big */
- for(i = 0; i < pool->totbuf; i++) {
+ for (i = 0; i < pool->totbuf; i++) {
bufsize = pool->buffers[i]->size;
/* check for an exact size match */
- if(bufsize == size) {
+ if (bufsize == size) {
bestfit = i;
break;
}
/* smaller buffers won't fit data and buffers at least
twice as big are a waste of memory */
- else if(bufsize > size && size > (bufsize / 2)) {
+ else if (bufsize > size && size > (bufsize / 2)) {
/* is it closer to the required size than the
last appropriate buffer found. try to save
memory */
- if(bestfit == -1 || pool->buffers[bestfit]->size > bufsize) {
+ if (bestfit == -1 || pool->buffers[bestfit]->size > bufsize) {
bestfit = i;
}
}
@@ -223,7 +223,7 @@ GPUBuffer *GPU_buffer_alloc(int size)
/* if an acceptable buffer was found in the pool, remove it
from the pool and return it */
- if(bestfit != -1) {
+ if (bestfit != -1) {
buf = pool->buffers[bestfit];
gpu_buffer_pool_remove_index(pool, bestfit);
return buf;
@@ -233,7 +233,7 @@ GPUBuffer *GPU_buffer_alloc(int size)
buf = MEM_callocN(sizeof(GPUBuffer), "GPUBuffer");
buf->size = size;
- if(useVBOs == 1) {
+ if (useVBOs == 1) {
/* create a new VBO and initialize it to the requested
size */
glGenBuffersARB(1, &buf->id);
@@ -252,7 +252,7 @@ GPUBuffer *GPU_buffer_alloc(int size)
gpu_buffer_pool_delete_last(pool);
buf->pointer = MEM_mallocN(size, "GPUBuffer.pointer");
}
- if(!buf->pointer)
+ if (!buf->pointer)
return NULL;
}
@@ -267,7 +267,7 @@ void GPU_buffer_free(GPUBuffer *buffer)
GPUBufferPool *pool;
int i;
- if(!buffer)
+ if (!buffer)
return;
pool = gpu_get_global_buffer_pool();
@@ -276,7 +276,7 @@ void GPU_buffer_free(GPUBuffer *buffer)
if we are in the main thread. for e.g. rendering or baking it can
happen that we are in other thread and can't call OpenGL, in that
case cleanup will be done GPU_buffer_pool_free_unused */
- if(BLI_thread_is_main()) {
+ if (BLI_thread_is_main()) {
/* in main thread, safe to decrease size of pool back
down to MAX_FREE_GPU_BUFFERS */
while(pool->totbuf >= MAX_FREE_GPU_BUFFERS)
@@ -285,7 +285,7 @@ void GPU_buffer_free(GPUBuffer *buffer)
else {
/* outside of main thread, can't safely delete the
buffer, so increase pool size */
- if(pool->maxsize == pool->totbuf) {
+ if (pool->maxsize == pool->totbuf) {
pool->maxsize += MAX_FREE_GPU_BUFFERS;
pool->buffers = MEM_reallocN(pool->buffers,
sizeof(GPUBuffer*) * pool->maxsize);
@@ -293,7 +293,7 @@ void GPU_buffer_free(GPUBuffer *buffer)
}
/* shift pool entries up by one */
- for(i = pool->totbuf; i > 0; i--)
+ for (i = pool->totbuf; i > 0; i--)
pool->buffers[i] = pool->buffers[i-1];
/* insert the buffer into the beginning of the pool */
@@ -316,9 +316,9 @@ static void gpu_drawobject_add_vert_point(GPUDrawObject *gdo, int vert_index, in
lnk = &gdo->vert_points[vert_index];
/* if first link is in use, add a new link at the end */
- if(lnk->point_index != -1) {
+ if (lnk->point_index != -1) {
/* get last link */
- for(; lnk->next; lnk = lnk->next);
+ for (; lnk->next; lnk = lnk->next);
/* add a new link from the pool */
lnk = lnk->next = &gdo->vert_points_mem[gdo->vert_points_usage];
@@ -336,7 +336,7 @@ static void gpu_drawobject_add_triangle(GPUDrawObject *gdo,
int v1, int v2, int v3)
{
int i, v[3] = {v1, v2, v3};
- for(i = 0; i < 3; i++)
+ for (i = 0; i < 3; i++)
gpu_drawobject_add_vert_point(gdo, v[i], base_point_index + i);
gdo->triangle_to_mface[base_point_index / 3] = face_index;
}
@@ -357,14 +357,14 @@ static void gpu_drawobject_init_vert_points(GPUDrawObject *gdo, MFace *f, int to
/* build a map from the original material indices to the new
GPUBufferMaterial indices */
- for(i = 0; i < gdo->totmaterial; i++)
+ for (i = 0; i < gdo->totmaterial; i++)
mat_orig_to_new[gdo->materials[i].mat_nr] = i;
/* -1 indicates the link is not yet used */
- for(i = 0; i < gdo->totvert; i++)
+ for (i = 0; i < gdo->totvert; i++)
gdo->vert_points[i].point_index = -1;
- for(i = 0; i < totface; i++, f++) {
+ for (i = 0; i < totface; i++, f++) {
mat = &gdo->materials[mat_orig_to_new[f->mat_nr]];
/* add triangle */
@@ -373,7 +373,7 @@ static void gpu_drawobject_init_vert_points(GPUDrawObject *gdo, MFace *f, int to
mat->totpoint += 3;
/* add second triangle for quads */
- if(f->v4) {
+ if (f->v4) {
gpu_drawobject_add_triangle(gdo, mat->start + mat->totpoint,
i, f->v3, f->v4, f->v1);
mat->totpoint += 3;
@@ -381,8 +381,8 @@ static void gpu_drawobject_init_vert_points(GPUDrawObject *gdo, MFace *f, int to
}
/* map any unused vertices to loose points */
- for(i = 0; i < gdo->totvert; i++) {
- if(gdo->vert_points[i].point_index == -1) {
+ for (i = 0; i < gdo->totvert; i++) {
+ if (gdo->vert_points[i].point_index == -1) {
gdo->vert_points[i].point_index = gdo->tot_triangle_point + gdo->tot_loose_point;
gdo->tot_loose_point++;
}
@@ -404,7 +404,7 @@ GPUDrawObject *GPU_drawobject_new( DerivedMesh *dm )
/* get the number of points used by each material, treating
each quad as two triangles */
memset(points_per_mat, 0, sizeof(int)*MAX_MATERIALS);
- for(i = 0; i < totface; i++)
+ for (i = 0; i < totface; i++)
points_per_mat[mface[i].mat_nr] += mface[i].v4 ? 6 : 3;
/* create the GPUDrawObject */
@@ -413,8 +413,8 @@ GPUDrawObject *GPU_drawobject_new( DerivedMesh *dm )
gdo->totedge = dm->getNumEdges(dm);
/* count the number of materials used by this DerivedMesh */
- for(i = 0; i < MAX_MATERIALS; i++) {
- if(points_per_mat[i] > 0)
+ for (i = 0; i < MAX_MATERIALS; i++) {
+ if (points_per_mat[i] > 0)
gdo->totmaterial++;
}
@@ -423,8 +423,8 @@ GPUDrawObject *GPU_drawobject_new( DerivedMesh *dm )
"GPUDrawObject.materials");
/* initialize the materials array */
- for(i = 0, curmat = 0, curpoint = 0; i < MAX_MATERIALS; i++) {
- if(points_per_mat[i] > 0) {
+ for (i = 0, curmat = 0, curpoint = 0; i < MAX_MATERIALS; i++) {
+ if (points_per_mat[i] > 0) {
gdo->materials[curmat].start = curpoint;
gdo->materials[curmat].totpoint = 0;
gdo->materials[curmat].mat_nr = i;
@@ -449,7 +449,7 @@ void GPU_drawobject_free(DerivedMesh *dm)
{
GPUDrawObject *gdo;
- if(!dm || !(gdo = dm->drawObject))
+ if (!dm || !(gdo = dm->drawObject))
return;
MEM_freeN(gdo->materials);
@@ -486,16 +486,16 @@ static GPUBuffer *gpu_buffer_setup(DerivedMesh *dm, GPUDrawObject *object,
pool = gpu_get_global_buffer_pool();
/* alloc a GPUBuffer; fall back to legacy mode on failure */
- if(!(buffer = GPU_buffer_alloc(size)))
+ if (!(buffer = GPU_buffer_alloc(size)))
dm->drawObject->legacy = 1;
/* nothing to do for legacy mode */
- if(dm->drawObject->legacy)
+ if (dm->drawObject->legacy)
return NULL;
cur_index_per_mat = MEM_mallocN(sizeof(int)*object->totmaterial,
"GPU_buffer_setup.cur_index_per_mat");
- for(i = 0; i < object->totmaterial; i++) {
+ for (i = 0; i < object->totmaterial; i++) {
/* for each material, the current index to copy data to */
cur_index_per_mat[i] = object->materials[i].start * vector_size;
@@ -504,7 +504,7 @@ static GPUBuffer *gpu_buffer_setup(DerivedMesh *dm, GPUDrawObject *object,
mat_orig_to_new[object->materials[i].mat_nr] = i;
}
- if(useVBOs) {
+ if (useVBOs) {
success = 0;
while(!success) {
@@ -514,7 +514,7 @@ static GPUBuffer *gpu_buffer_setup(DerivedMesh *dm, GPUDrawObject *object,
glBufferDataARB(target, buffer->size, NULL, GL_STATIC_DRAW_ARB);
/* attempt to map the buffer */
- if(!(varray = glMapBufferARB(target, GL_WRITE_ONLY_ARB))) {
+ if (!(varray = glMapBufferARB(target, GL_WRITE_ONLY_ARB))) {
/* failed to map the buffer; delete it */
GPU_buffer_free(buffer);
gpu_buffer_pool_delete_last(pool);
@@ -522,14 +522,14 @@ static GPUBuffer *gpu_buffer_setup(DerivedMesh *dm, GPUDrawObject *object,
/* try freeing an entry from the pool
and reallocating the buffer */
- if(pool->totbuf > 0) {
+ if (pool->totbuf > 0) {
gpu_buffer_pool_delete_last(pool);
buffer = GPU_buffer_alloc(size);
}
/* allocation still failed; fall back
to legacy mode */
- if(!buffer) {
+ if (!buffer) {
dm->drawObject->legacy = 1;
success = 1;
}
@@ -540,7 +540,7 @@ static GPUBuffer *gpu_buffer_setup(DerivedMesh *dm, GPUDrawObject *object,
}
/* check legacy fallback didn't happen */
- if(dm->drawObject->legacy == 0) {
+ if (dm->drawObject->legacy == 0) {
uploaded = GL_FALSE;
/* attempt to upload the data to the VBO */
while(uploaded == GL_FALSE) {
@@ -555,7 +555,7 @@ static GPUBuffer *gpu_buffer_setup(DerivedMesh *dm, GPUDrawObject *object,
}
else {
/* VBO not supported, use vertex array fallback */
- if(buffer->pointer) {
+ if (buffer->pointer) {
varray = buffer->pointer;
(*copy_f)(dm, varray, cur_index_per_mat, mat_orig_to_new, user);
}
@@ -579,7 +579,7 @@ static void GPU_buffer_copy_vertex(DerivedMesh *dm, float *varray, int *index, i
f = dm->getTessFaceArray(dm);
totface= dm->getNumTessFaces(dm);
- for(i = 0; i < totface; i++, f++) {
+ for (i = 0; i < totface; i++, f++) {
start = index[mat_orig_to_new[f->mat_nr]];
/* v1 v2 v3 */
@@ -588,7 +588,7 @@ static void GPU_buffer_copy_vertex(DerivedMesh *dm, float *varray, int *index, i
copy_v3_v3(&varray[start+6], mvert[f->v3].co);
index[mat_orig_to_new[f->mat_nr]] += 9;
- if(f->v4) {
+ if (f->v4) {
/* v3 v4 v1 */
copy_v3_v3(&varray[start+9], mvert[f->v3].co);
copy_v3_v3(&varray[start+12], mvert[f->v4].co);
@@ -599,8 +599,8 @@ static void GPU_buffer_copy_vertex(DerivedMesh *dm, float *varray, int *index, i
/* copy loose points */
j = dm->drawObject->tot_triangle_point*3;
- for(i = 0; i < dm->drawObject->totvert; i++) {
- if(dm->drawObject->vert_points[i].point_index >= dm->drawObject->tot_triangle_point) {
+ for (i = 0; i < dm->drawObject->totvert; i++) {
+ if (dm->drawObject->vert_points[i].point_index >= dm->drawObject->tot_triangle_point) {
copy_v3_v3(&varray[j],mvert[i].co);
j+=3;
}
@@ -618,31 +618,31 @@ static void GPU_buffer_copy_normal(DerivedMesh *dm, float *varray, int *index, i
MFace *f = dm->getTessFaceArray(dm);
totface= dm->getNumTessFaces(dm);
- for(i = 0; i < totface; i++, f++) {
+ for (i = 0; i < totface; i++, f++) {
const int smoothnormal = (f->flag & ME_SMOOTH);
start = index[mat_orig_to_new[f->mat_nr]];
index[mat_orig_to_new[f->mat_nr]] += f->v4 ? 18 : 9;
- if(smoothnormal) {
+ if (smoothnormal) {
/* copy vertex normal */
normal_short_to_float_v3(&varray[start], mvert[f->v1].no);
normal_short_to_float_v3(&varray[start+3], mvert[f->v2].no);
normal_short_to_float_v3(&varray[start+6], mvert[f->v3].no);
- if(f->v4) {
+ if (f->v4) {
normal_short_to_float_v3(&varray[start+9], mvert[f->v3].no);
normal_short_to_float_v3(&varray[start+12], mvert[f->v4].no);
normal_short_to_float_v3(&varray[start+15], mvert[f->v1].no);
}
}
- else if(nors) {
+ else if (nors) {
/* copy cached face normal */
copy_v3_v3(&varray[start], &nors[i*3]);
copy_v3_v3(&varray[start+3], &nors[i*3]);
copy_v3_v3(&varray[start+6], &nors[i*3]);
- if(f->v4) {
+ if (f->v4) {
copy_v3_v3(&varray[start+9], &nors[i*3]);
copy_v3_v3(&varray[start+12], &nors[i*3]);
copy_v3_v3(&varray[start+15], &nors[i*3]);
@@ -650,7 +650,7 @@ static void GPU_buffer_copy_normal(DerivedMesh *dm, float *varray, int *index, i
}
else {
/* calculate face normal */
- if(f->v4)
+ if (f->v4)
normal_quad_v3(f_no, mvert[f->v1].co, mvert[f->v2].co, mvert[f->v3].co, mvert[f->v4].co);
else
normal_tri_v3(f_no, mvert[f->v1].co, mvert[f->v2].co, mvert[f->v3].co);
@@ -659,7 +659,7 @@ static void GPU_buffer_copy_normal(DerivedMesh *dm, float *varray, int *index, i
copy_v3_v3(&varray[start+3], f_no);
copy_v3_v3(&varray[start+6], f_no);
- if(f->v4) {
+ if (f->v4) {
copy_v3_v3(&varray[start+9], f_no);
copy_v3_v3(&varray[start+12], f_no);
copy_v3_v3(&varray[start+15], f_no);
@@ -676,12 +676,12 @@ static void GPU_buffer_copy_uv(DerivedMesh *dm, float *varray, int *index, int *
MTFace *mtface;
MFace *f;
- if(!(mtface = DM_get_tessface_data_layer(dm, CD_MTFACE)))
+ if (!(mtface = DM_get_tessface_data_layer(dm, CD_MTFACE)))
return;
f = dm->getTessFaceArray(dm);
totface = dm->getNumTessFaces(dm);
- for(i = 0; i < totface; i++, f++) {
+ for (i = 0; i < totface; i++, f++) {
start = index[mat_orig_to_new[f->mat_nr]];
/* v1 v2 v3 */
@@ -690,7 +690,7 @@ static void GPU_buffer_copy_uv(DerivedMesh *dm, float *varray, int *index, int *
copy_v2_v2(&varray[start+4],mtface[i].uv[2]);
index[mat_orig_to_new[f->mat_nr]] += 6;
- if(f->v4) {
+ if (f->v4) {
/* v3 v4 v1 */
copy_v2_v2(&varray[start+6],mtface[i].uv[2]);
copy_v2_v2(&varray[start+8],mtface[i].uv[3]);
@@ -709,7 +709,7 @@ static void GPU_buffer_copy_color3(DerivedMesh *dm, float *varray_, int *index,
MFace *f = dm->getTessFaceArray(dm);
totface= dm->getNumTessFaces(dm);
- for(i=0; i < totface; i++, f++) {
+ for (i=0; i < totface; i++, f++) {
int start = index[mat_orig_to_new[f->mat_nr]];
/* v1 v2 v3 */
@@ -718,7 +718,7 @@ static void GPU_buffer_copy_color3(DerivedMesh *dm, float *varray_, int *index,
copy_v3_v3_char(&varray[start+6], &mcol[i*12+6]);
index[mat_orig_to_new[f->mat_nr]] += 9;
- if(f->v4) {
+ if (f->v4) {
/* v3 v4 v1 */
copy_v3_v3_char(&varray[start+9], &mcol[i*12+6]);
copy_v3_v3_char(&varray[start+12], &mcol[i*12+9]);
@@ -744,7 +744,7 @@ static void GPU_buffer_copy_mcol(DerivedMesh *dm, float *varray_, int *index, in
MFace *f = dm->getTessFaceArray(dm);
totface= dm->getNumTessFaces(dm);
- for(i=0; i < totface; i++, f++) {
+ for (i=0; i < totface; i++, f++) {
int start = index[mat_orig_to_new[f->mat_nr]];
/* v1 v2 v3 */
@@ -753,7 +753,7 @@ static void GPU_buffer_copy_mcol(DerivedMesh *dm, float *varray_, int *index, in
copy_mcol_uc3(&varray[start+6], &mcol[i*16+8]);
index[mat_orig_to_new[f->mat_nr]] += 9;
- if(f->v4) {
+ if (f->v4) {
/* v3 v4 v1 */
copy_mcol_uc3(&varray[start+9], &mcol[i*16+8]);
copy_mcol_uc3(&varray[start+12], &mcol[i*16+12]);
@@ -772,7 +772,7 @@ static void GPU_buffer_copy_edge(DerivedMesh *dm, float *varray_, int *UNUSED(in
medge = dm->getEdgeArray(dm);
totedge = dm->getNumEdges(dm);
- for(i = 0; i < totedge; i++, medge++) {
+ for (i = 0; i < totedge; i++, medge++) {
varray[i*2] = dm->drawObject->vert_points[medge->v1].point_index;
varray[i*2+1] = dm->drawObject->vert_points[medge->v2].point_index;
}
@@ -783,10 +783,10 @@ static void GPU_buffer_copy_uvedge(DerivedMesh *dm, float *varray, int *UNUSED(i
MTFace *tf = DM_get_tessface_data_layer(dm, CD_MTFACE);
int i, j=0;
- if(!tf)
+ if (!tf)
return;
- for(i = 0; i < dm->numTessFaceData; i++, tf++) {
+ for (i = 0; i < dm->numTessFaceData; i++, tf++) {
MFace mf;
dm->getTessFace(dm,i,&mf);
@@ -796,11 +796,12 @@ static void GPU_buffer_copy_uvedge(DerivedMesh *dm, float *varray, int *UNUSED(i
copy_v2_v2(&varray[j+4],tf->uv[1]);
copy_v2_v2(&varray[j+6],tf->uv[2]);
- if(!mf.v4) {
+ if (!mf.v4) {
copy_v2_v2(&varray[j+8],tf->uv[2]);
copy_v2_v2(&varray[j+10],tf->uv[0]);
j+=12;
- } else {
+ }
+ else {
copy_v2_v2(&varray[j+8],tf->uv[2]);
copy_v2_v2(&varray[j+10],tf->uv[3]);
@@ -820,10 +821,10 @@ static MCol *gpu_buffer_color_type(DerivedMesh *dm)
type = CD_ID_MCOL;
c = DM_get_tessface_data_layer(dm, type);
- if(!c) {
+ if (!c) {
type = CD_PREVIEW_MCOL;
c = DM_get_tessface_data_layer(dm, type);
- if(!c) {
+ if (!c) {
type = CD_MCOL;
c = DM_get_tessface_data_layer(dm, type);
}
@@ -914,12 +915,12 @@ static GPUBuffer *gpu_buffer_setup_type(DerivedMesh *dm, GPUBufferType type)
ts = &gpu_buffer_type_settings[type];
/* special handling for MCol and UV buffers */
- if(type == GPU_BUFFER_COLOR) {
- if(!(user_data = gpu_buffer_color_type(dm)))
+ if (type == GPU_BUFFER_COLOR) {
+ if (!(user_data = gpu_buffer_color_type(dm)))
return NULL;
}
- else if(type == GPU_BUFFER_UV) {
- if(!DM_get_tessface_data_layer(dm, CD_MTFACE))
+ else if (type == GPU_BUFFER_UV) {
+ if (!DM_get_tessface_data_layer(dm, CD_MTFACE))
return NULL;
}
@@ -936,11 +937,11 @@ static GPUBuffer *gpu_buffer_setup_common(DerivedMesh *dm, GPUBufferType type)
{
GPUBuffer **buf;
- if(!dm->drawObject)
+ if (!dm->drawObject)
dm->drawObject = GPU_drawobject_new(dm);
buf = gpu_drawobject_buffer_from_type(dm->drawObject, type);
- if(!(*buf))
+ if (!(*buf))
*buf = gpu_buffer_setup_type(dm, type);
return *buf;
@@ -948,11 +949,11 @@ static GPUBuffer *gpu_buffer_setup_common(DerivedMesh *dm, GPUBufferType type)
void GPU_vertex_setup(DerivedMesh *dm)
{
- if(!gpu_buffer_setup_common(dm, GPU_BUFFER_VERTEX))
+ if (!gpu_buffer_setup_common(dm, GPU_BUFFER_VERTEX))
return;
glEnableClientState(GL_VERTEX_ARRAY);
- if(useVBOs) {
+ if (useVBOs) {
glBindBufferARB(GL_ARRAY_BUFFER_ARB, dm->drawObject->points->id);
glVertexPointer(3, GL_FLOAT, 0, 0);
}
@@ -965,11 +966,11 @@ void GPU_vertex_setup(DerivedMesh *dm)
void GPU_normal_setup(DerivedMesh *dm)
{
- if(!gpu_buffer_setup_common(dm, GPU_BUFFER_NORMAL))
+ if (!gpu_buffer_setup_common(dm, GPU_BUFFER_NORMAL))
return;
glEnableClientState(GL_NORMAL_ARRAY);
- if(useVBOs) {
+ if (useVBOs) {
glBindBufferARB(GL_ARRAY_BUFFER_ARB, dm->drawObject->normals->id);
glNormalPointer(GL_FLOAT, 0, 0);
}
@@ -982,11 +983,11 @@ void GPU_normal_setup(DerivedMesh *dm)
void GPU_uv_setup(DerivedMesh *dm)
{
- if(!gpu_buffer_setup_common(dm, GPU_BUFFER_UV))
+ if (!gpu_buffer_setup_common(dm, GPU_BUFFER_UV))
return;
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
- if(useVBOs) {
+ if (useVBOs) {
glBindBufferARB(GL_ARRAY_BUFFER_ARB, dm->drawObject->uv->id);
glTexCoordPointer(2, GL_FLOAT, 0, 0);
}
@@ -999,11 +1000,11 @@ void GPU_uv_setup(DerivedMesh *dm)
void GPU_color_setup(DerivedMesh *dm)
{
- if(!gpu_buffer_setup_common(dm, GPU_BUFFER_COLOR))
+ if (!gpu_buffer_setup_common(dm, GPU_BUFFER_COLOR))
return;
glEnableClientState(GL_COLOR_ARRAY);
- if(useVBOs) {
+ if (useVBOs) {
glBindBufferARB(GL_ARRAY_BUFFER_ARB, dm->drawObject->colors->id);
glColorPointer(3, GL_UNSIGNED_BYTE, 0, 0);
}
@@ -1016,14 +1017,14 @@ void GPU_color_setup(DerivedMesh *dm)
void GPU_edge_setup(DerivedMesh *dm)
{
- if(!gpu_buffer_setup_common(dm, GPU_BUFFER_EDGE))
+ if (!gpu_buffer_setup_common(dm, GPU_BUFFER_EDGE))
return;
- if(!gpu_buffer_setup_common(dm, GPU_BUFFER_VERTEX))
+ if (!gpu_buffer_setup_common(dm, GPU_BUFFER_VERTEX))
return;
glEnableClientState(GL_VERTEX_ARRAY);
- if(useVBOs) {
+ if (useVBOs) {
glBindBufferARB(GL_ARRAY_BUFFER_ARB, dm->drawObject->points->id);
glVertexPointer(3, GL_FLOAT, 0, 0);
}
@@ -1033,7 +1034,7 @@ void GPU_edge_setup(DerivedMesh *dm)
GLStates |= GPU_BUFFER_VERTEX_STATE;
- if(useVBOs)
+ if (useVBOs)
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, dm->drawObject->edges->id);
GLStates |= GPU_BUFFER_ELEMENT_STATE;
@@ -1041,11 +1042,11 @@ void GPU_edge_setup(DerivedMesh *dm)
void GPU_uvedge_setup(DerivedMesh *dm)
{
- if(!gpu_buffer_setup_common(dm, GPU_BUFFER_UVEDGE))
+ if (!gpu_buffer_setup_common(dm, GPU_BUFFER_UVEDGE))
return;
glEnableClientState(GL_VERTEX_ARRAY);
- if(useVBOs) {
+ if (useVBOs) {
glBindBufferARB(GL_ARRAY_BUFFER_ARB, dm->drawObject->uvedges->id);
glVertexPointer(2, GL_FLOAT, 0, 0);
}
@@ -1078,9 +1079,9 @@ int GPU_attrib_element_size(GPUAttrib data[], int numdata)
{
int i, elementsize = 0;
- for(i = 0; i < numdata; i++) {
+ for (i = 0; i < numdata; i++) {
int typesize = GPU_typesize(data[i].type);
- if(typesize != 0)
+ if (typesize != 0)
elementsize += typesize*data[i].size;
}
return elementsize;
@@ -1092,8 +1093,8 @@ void GPU_interleaved_attrib_setup(GPUBuffer *buffer, GPUAttrib data[], int numda
int elementsize;
intptr_t offset = 0;
- for(i = 0; i < MAX_GPU_ATTRIB_DATA; i++) {
- if(attribData[i].index != -1) {
+ for (i = 0; i < MAX_GPU_ATTRIB_DATA; i++) {
+ if (attribData[i].index != -1) {
glDisableVertexAttribArrayARB(attribData[i].index);
}
else
@@ -1101,9 +1102,9 @@ void GPU_interleaved_attrib_setup(GPUBuffer *buffer, GPUAttrib data[], int numda
}
elementsize = GPU_attrib_element_size(data, numdata);
- if(useVBOs) {
+ if (useVBOs) {
glBindBufferARB(GL_ARRAY_BUFFER_ARB, buffer->id);
- for(i = 0; i < numdata; i++) {
+ for (i = 0; i < numdata; i++) {
glEnableVertexAttribArrayARB(data[i].index);
glVertexAttribPointerARB(data[i].index, data[i].size, data[i].type,
GL_FALSE, elementsize, (void *)offset);
@@ -1116,7 +1117,7 @@ void GPU_interleaved_attrib_setup(GPUBuffer *buffer, GPUAttrib data[], int numda
attribData[numdata].index = -1;
}
else {
- for(i = 0; i < numdata; i++) {
+ for (i = 0; i < numdata; i++) {
glEnableVertexAttribArrayARB(data[i].index);
glVertexAttribPointerARB(data[i].index, data[i].size, data[i].type,
GL_FALSE, elementsize, (char *)buffer->pointer + offset);
@@ -1130,16 +1131,16 @@ void GPU_buffer_unbind(void)
{
int i;
- if(GLStates & GPU_BUFFER_VERTEX_STATE)
+ if (GLStates & GPU_BUFFER_VERTEX_STATE)
glDisableClientState(GL_VERTEX_ARRAY);
- if(GLStates & GPU_BUFFER_NORMAL_STATE)
+ if (GLStates & GPU_BUFFER_NORMAL_STATE)
glDisableClientState(GL_NORMAL_ARRAY);
- if(GLStates & GPU_BUFFER_TEXCOORD_STATE)
+ if (GLStates & GPU_BUFFER_TEXCOORD_STATE)
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
- if(GLStates & GPU_BUFFER_COLOR_STATE)
+ if (GLStates & GPU_BUFFER_COLOR_STATE)
glDisableClientState(GL_COLOR_ARRAY);
- if(GLStates & GPU_BUFFER_ELEMENT_STATE) {
- if(useVBOs) {
+ if (GLStates & GPU_BUFFER_ELEMENT_STATE) {
+ if (useVBOs) {
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
}
}
@@ -1147,15 +1148,15 @@ void GPU_buffer_unbind(void)
GPU_BUFFER_TEXCOORD_STATE | GPU_BUFFER_COLOR_STATE |
GPU_BUFFER_ELEMENT_STATE);
- for(i = 0; i < MAX_GPU_ATTRIB_DATA; i++) {
- if(attribData[i].index != -1) {
+ for (i = 0; i < MAX_GPU_ATTRIB_DATA; i++) {
+ if (attribData[i].index != -1) {
glDisableVertexAttribArrayARB(attribData[i].index);
}
else
break;
}
- if(useVBOs)
+ if (useVBOs)
glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
}
@@ -1164,7 +1165,7 @@ void GPU_buffer_unbind(void)
like it will just needlessly overwrite? --nicholas */
void GPU_color3_upload(DerivedMesh *dm, unsigned char *data)
{
- if(dm->drawObject == 0)
+ if (dm->drawObject == 0)
dm->drawObject = GPU_drawobject_new(dm);
GPU_buffer_free(dm->drawObject->colors);
@@ -1175,13 +1176,13 @@ void GPU_color3_upload(DerivedMesh *dm, unsigned char *data)
void GPU_color_switch(int mode)
{
- if(mode) {
- if(!(GLStates & GPU_BUFFER_COLOR_STATE))
+ if (mode) {
+ if (!(GLStates & GPU_BUFFER_COLOR_STATE))
glEnableClientState(GL_COLOR_ARRAY);
GLStates |= GPU_BUFFER_COLOR_STATE;
}
else {
- if(GLStates & GPU_BUFFER_COLOR_STATE)
+ if (GLStates & GPU_BUFFER_COLOR_STATE)
glDisableClientState(GL_COLOR_ARRAY);
GLStates &= (!GPU_BUFFER_COLOR_STATE);
}
@@ -1192,10 +1193,10 @@ void GPU_color_switch(int mode)
int GPU_buffer_legacy(DerivedMesh *dm)
{
int test= (U.gameflags & USER_DISABLE_VBO);
- if(test)
+ if (test)
return 1;
- if(dm->drawObject == 0)
+ if (dm->drawObject == 0)
dm->drawObject = GPU_drawobject_new(dm);
return dm->drawObject->legacy;
}
@@ -1204,10 +1205,10 @@ void *GPU_buffer_lock(GPUBuffer *buffer)
{
float *varray;
- if(!buffer)
+ if (!buffer)
return 0;
- if(useVBOs) {
+ if (useVBOs) {
glBindBufferARB(GL_ARRAY_BUFFER_ARB, buffer->id);
varray = glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB);
return varray;
@@ -1221,10 +1222,10 @@ void *GPU_buffer_lock_stream(GPUBuffer *buffer)
{
float *varray;
- if(!buffer)
+ if (!buffer)
return 0;
- if(useVBOs) {
+ if (useVBOs) {
glBindBufferARB(GL_ARRAY_BUFFER_ARB, buffer->id);
/* discard previous data, avoid stalling gpu */
glBufferDataARB(GL_ARRAY_BUFFER_ARB, buffer->size, 0, GL_STREAM_DRAW_ARB);
@@ -1238,8 +1239,8 @@ void *GPU_buffer_lock_stream(GPUBuffer *buffer)
void GPU_buffer_unlock(GPUBuffer *buffer)
{
- if(useVBOs) {
- if(buffer) {
+ if (useVBOs) {
+ if (buffer) {
/* note: this operation can fail, could return
an error code from this function? */
glUnmapBufferARB(GL_ARRAY_BUFFER_ARB);
@@ -1296,7 +1297,7 @@ void GPU_update_mesh_buffers(GPU_Buffers *buffers, MVert *mvert,
VertexBufferFormat *vert_data;
int i;
- if(buffers->vert_buf) {
+ if (buffers->vert_buf) {
/* Build VBO */
glBindBufferARB(GL_ARRAY_BUFFER_ARB, buffers->vert_buf);
glBufferDataARB(GL_ARRAY_BUFFER_ARB,
@@ -1304,8 +1305,8 @@ void GPU_update_mesh_buffers(GPU_Buffers *buffers, MVert *mvert,
NULL, GL_STATIC_DRAW_ARB);
vert_data = glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB);
- if(vert_data) {
- for(i = 0; i < totvert; ++i) {
+ if (vert_data) {
+ for (i = 0; i < totvert; ++i) {
MVert *v = mvert + vert_indices[i];
VertexBufferFormat *out = vert_data + i;
@@ -1339,16 +1340,16 @@ GPU_Buffers *GPU_build_mesh_buffers(int (*face_vert_indices)[4],
buffers->index_type = GL_UNSIGNED_SHORT;
/* Count the number of visible triangles */
- for(i = 0, tottri = 0; i < totface; ++i) {
+ for (i = 0, tottri = 0; i < totface; ++i) {
const MFace *f = &mface[face_indices[i]];
- if(!paint_is_face_hidden(f, mvert))
+ if (!paint_is_face_hidden(f, mvert))
tottri += f->v4 ? 2 : 1;
}
- if(GLEW_ARB_vertex_buffer_object && !(U.gameflags & USER_DISABLE_VBO))
+ if (GLEW_ARB_vertex_buffer_object && !(U.gameflags & USER_DISABLE_VBO))
glGenBuffersARB(1, &buffers->index_buf);
- if(buffers->index_buf) {
+ if (buffers->index_buf) {
/* Generate index buffer object */
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, buffers->index_buf);
glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB,
@@ -1356,21 +1357,21 @@ GPU_Buffers *GPU_build_mesh_buffers(int (*face_vert_indices)[4],
/* Fill the triangle buffer */
tri_data = glMapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB);
- if(tri_data) {
- for(i = 0; i < totface; ++i) {
+ if (tri_data) {
+ for (i = 0; i < totface; ++i) {
const MFace *f = mface + face_indices[i];
int v[3];
/* Skip hidden faces */
- if(paint_is_face_hidden(f, mvert))
+ if (paint_is_face_hidden(f, mvert))
continue;
v[0]= 0;
v[1]= 1;
v[2]= 2;
- for(j = 0; j < (f->v4 ? 2 : 1); ++j) {
- for(k = 0; k < 3; ++k) {
+ for (j = 0; j < (f->v4 ? 2 : 1); ++j) {
+ for (k = 0; k < 3; ++k) {
*tri_data = face_vert_indices[i][v[k]];
++tri_data;
}
@@ -1389,7 +1390,7 @@ GPU_Buffers *GPU_build_mesh_buffers(int (*face_vert_indices)[4],
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
}
- if(buffers->index_buf)
+ if (buffers->index_buf)
glGenBuffersARB(1, &buffers->vert_buf);
buffers->tot_tri = tottri;
@@ -1410,7 +1411,7 @@ void GPU_update_grid_buffers(GPU_Buffers *buffers, DMGridData **grids,
totvert= gridsize*gridsize*totgrid;
/* Build VBO */
- if(buffers->vert_buf) {
+ if (buffers->vert_buf) {
int smooth = grid_flag_mats[grid_indices[0]].flag & ME_SMOOTH;
glBindBufferARB(GL_ARRAY_BUFFER_ARB, buffers->vert_buf);
@@ -1418,17 +1419,17 @@ void GPU_update_grid_buffers(GPU_Buffers *buffers, DMGridData **grids,
sizeof(DMGridData) * totvert,
NULL, GL_STATIC_DRAW_ARB);
vert_data = glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB);
- if(vert_data) {
- for(i = 0; i < totgrid; ++i) {
+ if (vert_data) {
+ for (i = 0; i < totgrid; ++i) {
DMGridData *grid= grids[grid_indices[i]];
memcpy(vert_data, grid, sizeof(DMGridData)*gridsize*gridsize);
- if(!smooth) {
+ if (!smooth) {
/* for flat shading, recalc normals and set the last vertex of
each quad in the index buffer to have the flat normal as
that is what opengl will use */
- for(j = 0; j < gridsize-1; ++j) {
- for(k = 0; k < gridsize-1; ++k) {
+ for (j = 0; j < gridsize-1; ++j) {
+ for (k = 0; k < gridsize-1; ++k) {
float fno[3];
normal_quad_v3(fno,
grid[(j+1)*gridsize + k].co,
@@ -1472,14 +1473,14 @@ static int gpu_count_grid_quads(BLI_bitmap *grid_hidden,
/* grid hidden layer is present, so have to check each grid for
visiblity */
- for(i = 0, totquad = 0; i < totgrid; i++) {
+ for (i = 0, totquad = 0; i < totgrid; i++) {
const BLI_bitmap gh = grid_hidden[grid_indices[i]];
- if(gh) {
+ if (gh) {
/* grid hidden are present, have to check each element */
- for(y = 0; y < gridsize-1; y++) {
- for(x = 0; x < gridsize-1; x++) {
- if(!paint_is_grid_face_hidden(gh, gridsize, x, y))
+ for (y = 0; y < gridsize-1; y++) {
+ for (x = 0; x < gridsize-1; x++) {
+ if (!paint_is_grid_face_hidden(gh, gridsize, x, y))
totquad++;
}
}
@@ -1506,16 +1507,16 @@ static int gpu_count_grid_quads(BLI_bitmap *grid_hidden,
/* Fill the quad buffer */ \
quad_data = glMapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, \
GL_WRITE_ONLY_ARB); \
- if(quad_data) { \
- for(i = 0; i < totgrid; ++i) { \
+ if (quad_data) { \
+ for (i = 0; i < totgrid; ++i) { \
BLI_bitmap gh = NULL; \
- if(grid_hidden) \
+ if (grid_hidden) \
gh = grid_hidden[(grid_indices)[i]]; \
\
- for(j = 0; j < gridsize-1; ++j) { \
- for(k = 0; k < gridsize-1; ++k) { \
+ for (j = 0; j < gridsize-1; ++j) { \
+ for (k = 0; k < gridsize-1; ++k) { \
/* Skip hidden grid face */ \
- if(gh && \
+ if (gh && \
paint_is_grid_face_hidden(gh, \
gridsize, k, j)) \
continue; \
@@ -1552,14 +1553,14 @@ static GLuint gpu_get_grid_buffer(int gridsize, GLenum *index_type, unsigned *to
/* VBO is disabled; delete the previous buffer (if it exists) and
return an invalid handle */
- if(!GLEW_ARB_vertex_buffer_object || (U.gameflags & USER_DISABLE_VBO)) {
- if(buffer)
+ if (!GLEW_ARB_vertex_buffer_object || (U.gameflags & USER_DISABLE_VBO)) {
+ if (buffer)
glDeleteBuffersARB(1, &buffer);
return 0;
}
/* VBO is already built */
- if(buffer && prev_gridsize == gridsize) {
+ if (buffer && prev_gridsize == gridsize) {
*index_type = prev_index_type;
*totquad = prev_totquad;
return buffer;
@@ -1567,12 +1568,12 @@ static GLuint gpu_get_grid_buffer(int gridsize, GLenum *index_type, unsigned *to
/* Build new VBO */
glGenBuffersARB(1, &buffer);
- if(buffer) {
+ if (buffer) {
*totquad= (gridsize-1)*(gridsize-1);
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, buffer);
- if(gridsize * gridsize < USHRT_MAX) {
+ if (gridsize * gridsize < USHRT_MAX) {
*index_type = GL_UNSIGNED_SHORT;
FILL_QUAD_BUFFER(unsigned short, *totquad, buffer);
}
@@ -1605,19 +1606,19 @@ GPU_Buffers *GPU_build_grid_buffers(int *grid_indices, int totgrid,
/* Count the number of quads */
totquad= gpu_count_grid_quads(grid_hidden, grid_indices, totgrid, gridsize);
- if(totquad == fully_visible_totquad) {
+ if (totquad == fully_visible_totquad) {
buffers->index_buf = gpu_get_grid_buffer(gridsize, &buffers->index_type, &buffers->tot_quad);
buffers->has_hidden = 0;
}
- else if(GLEW_ARB_vertex_buffer_object && !(U.gameflags & USER_DISABLE_VBO)) {
+ else if (GLEW_ARB_vertex_buffer_object && !(U.gameflags & USER_DISABLE_VBO)) {
/* Build new VBO */
glGenBuffersARB(1, &buffers->index_buf);
- if(buffers->index_buf) {
+ if (buffers->index_buf) {
buffers->tot_quad= totquad;
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, buffers->index_buf);
- if(totgrid * gridsize * gridsize < USHRT_MAX) {
+ if (totgrid * gridsize * gridsize < USHRT_MAX) {
buffers->index_type = GL_UNSIGNED_SHORT;
FILL_QUAD_BUFFER(unsigned short, totquad, buffers->index_buf);
}
@@ -1633,7 +1634,7 @@ GPU_Buffers *GPU_build_grid_buffers(int *grid_indices, int totgrid,
}
/* Build coord/normal VBO */
- if(buffers->index_buf)
+ if (buffers->index_buf)
glGenBuffersARB(1, &buffers->vert_buf);
return buffers;
@@ -1646,18 +1647,18 @@ static void gpu_draw_buffers_legacy_mesh(GPU_Buffers *buffers, int smooth)
const MVert *mvert = buffers->mvert;
int i, j;
- for(i = 0; i < buffers->totface; ++i) {
+ for (i = 0; i < buffers->totface; ++i) {
MFace *f = buffers->mface + buffers->face_indices[i];
int S = f->v4 ? 4 : 3;
unsigned int *fv = &f->v1;
- if(paint_is_face_hidden(f, buffers->mvert))
+ if (paint_is_face_hidden(f, buffers->mvert))
continue;
glBegin((f->v4)? GL_QUADS: GL_TRIANGLES);
- if(smooth) {
- for(j = 0; j < S; j++) {
+ if (smooth) {
+ for (j = 0; j < S; j++) {
glNormal3sv(mvert[fv[j]].no);
glVertex3fv(mvert[fv[j]].co);
}
@@ -1666,7 +1667,7 @@ static void gpu_draw_buffers_legacy_mesh(GPU_Buffers *buffers, int smooth)
float fno[3];
/* calculate face normal */
- if(f->v4) {
+ if (f->v4) {
normal_quad_v3(fno, mvert[fv[0]].co, mvert[fv[1]].co,
mvert[fv[2]].co, mvert[fv[3]].co);
}
@@ -1674,7 +1675,7 @@ static void gpu_draw_buffers_legacy_mesh(GPU_Buffers *buffers, int smooth)
normal_tri_v3(fno, mvert[fv[0]].co, mvert[fv[1]].co, mvert[fv[2]].co);
glNormal3fv(fno);
- for(j = 0; j < S; j++)
+ for (j = 0; j < S; j++)
glVertex3fv(mvert[fv[j]].co);
}
@@ -1686,18 +1687,18 @@ static void gpu_draw_buffers_legacy_grids(GPU_Buffers *buffers, int smooth)
{
int i, j, x, y, gridsize = buffers->gridsize;
- for(i = 0; i < buffers->totgrid; ++i) {
+ for (i = 0; i < buffers->totgrid; ++i) {
int g = buffers->grid_indices[i];
const DMGridData *grid = buffers->grids[g];
BLI_bitmap gh = buffers->grid_hidden[g];
/* TODO: could use strips with hiding as well */
- if(gh) {
+ if (gh) {
glBegin(GL_QUADS);
- for(y = 0; y < gridsize-1; y++) {
- for(x = 0; x < gridsize-1; x++) {
+ for (y = 0; y < gridsize-1; y++) {
+ for (x = 0; x < gridsize-1; x++) {
const DMGridData *e[4] = {
&grid[y*gridsize + x],
&grid[(y+1)*gridsize + x],
@@ -1706,11 +1707,11 @@ static void gpu_draw_buffers_legacy_grids(GPU_Buffers *buffers, int smooth)
};
/* skip face if any of its corners are hidden */
- if(paint_is_grid_face_hidden(gh, gridsize, x, y))
+ if (paint_is_grid_face_hidden(gh, gridsize, x, y))
continue;
- if(smooth) {
- for(j = 0; j < 4; j++) {
+ if (smooth) {
+ for (j = 0; j < 4; j++) {
glNormal3fv(e[j]->no);
glVertex3fv(e[j]->co);
}
@@ -1720,7 +1721,7 @@ static void gpu_draw_buffers_legacy_grids(GPU_Buffers *buffers, int smooth)
normal_quad_v3(fno, e[0]->co, e[1]->co, e[2]->co, e[3]->co);
glNormal3fv(fno);
- for(j = 0; j < 4; j++)
+ for (j = 0; j < 4; j++)
glVertex3fv(e[j]->co);
}
}
@@ -1728,10 +1729,10 @@ static void gpu_draw_buffers_legacy_grids(GPU_Buffers *buffers, int smooth)
glEnd();
}
- else if(smooth) {
- for(y = 0; y < gridsize-1; y++) {
+ else if (smooth) {
+ for (y = 0; y < gridsize-1; y++) {
glBegin(GL_QUAD_STRIP);
- for(x = 0; x < gridsize; x++) {
+ for (x = 0; x < gridsize; x++) {
const DMGridData *a = &grid[y*gridsize + x];
const DMGridData *b = &grid[(y+1)*gridsize + x];
@@ -1744,13 +1745,13 @@ static void gpu_draw_buffers_legacy_grids(GPU_Buffers *buffers, int smooth)
}
}
else {
- for(y = 0; y < gridsize-1; y++) {
+ for (y = 0; y < gridsize-1; y++) {
glBegin(GL_QUAD_STRIP);
- for(x = 0; x < gridsize; x++) {
+ for (x = 0; x < gridsize; x++) {
const DMGridData *a = &grid[y*gridsize + x];
const DMGridData *b = &grid[(y+1)*gridsize + x];
- if(x > 0) {
+ if (x > 0) {
const DMGridData *c = &grid[y*gridsize + x-1];
const DMGridData *d = &grid[(y+1)*gridsize + x-1];
float fno[3];
@@ -1771,34 +1772,34 @@ void GPU_draw_buffers(GPU_Buffers *buffers, DMSetMaterial setMaterial)
{
int smooth = 0;
- if(buffers->totface) {
+ if (buffers->totface) {
const MFace *f = &buffers->mface[buffers->face_indices[0]];
- if(!setMaterial(f->mat_nr+1, NULL))
+ if (!setMaterial(f->mat_nr+1, NULL))
return;
smooth = f->flag & ME_SMOOTH;
glShadeModel(smooth ? GL_SMOOTH: GL_FLAT);
}
- else if(buffers->totgrid) {
+ else if (buffers->totgrid) {
const DMFlagMat *f = &buffers->grid_flag_mats[buffers->grid_indices[0]];
- if(!setMaterial(f->mat_nr+1, NULL))
+ if (!setMaterial(f->mat_nr+1, NULL))
return;
smooth = f->flag & ME_SMOOTH;
glShadeModel(smooth ? GL_SMOOTH: GL_FLAT);
}
- if(buffers->vert_buf && buffers->index_buf) {
+ if (buffers->vert_buf && buffers->index_buf) {
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, buffers->vert_buf);
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, buffers->index_buf);
- if(buffers->tot_quad) {
+ if (buffers->tot_quad) {
unsigned offset = 0;
int i, last = buffers->has_hidden ? 1 : buffers->totgrid;
- for(i = 0; i < last; i++) {
+ for (i = 0; i < last; i++) {
glVertexPointer(3, GL_FLOAT, sizeof(DMGridData), offset + (char*)offsetof(DMGridData, co));
glNormalPointer(GL_FLOAT, sizeof(DMGridData), offset + (char*)offsetof(DMGridData, no));
@@ -1821,20 +1822,20 @@ void GPU_draw_buffers(GPU_Buffers *buffers, DMSetMaterial setMaterial)
glDisableClientState(GL_NORMAL_ARRAY);
}
/* fallbacks if we are out of memory or VBO is disabled */
- else if(buffers->totface) {
+ else if (buffers->totface) {
gpu_draw_buffers_legacy_mesh(buffers, smooth);
}
- else if(buffers->totgrid) {
+ else if (buffers->totgrid) {
gpu_draw_buffers_legacy_grids(buffers, smooth);
}
}
void GPU_free_buffers(GPU_Buffers *buffers)
{
- if(buffers) {
- if(buffers->vert_buf)
+ if (buffers) {
+ if (buffers->vert_buf)
glDeleteBuffersARB(1, &buffers->vert_buf);
- if(buffers->index_buf && (buffers->tot_tri || buffers->has_hidden))
+ if (buffers->index_buf && (buffers->tot_tri || buffers->has_hidden))
glDeleteBuffersARB(1, &buffers->index_buf);
MEM_freeN(buffers);
diff --git a/source/blender/gpu/intern/gpu_codegen.c b/source/blender/gpu/intern/gpu_codegen.c
index 07d7568ab95..76291aef584 100644
--- a/source/blender/gpu/intern/gpu_codegen.c
+++ b/source/blender/gpu/intern/gpu_codegen.c
@@ -77,8 +77,8 @@ static GHash *FUNCTION_HASH= NULL;
static int gpu_str_prefix(const char *str, const char *prefix)
{
- while(*str && *prefix) {
- if(*str != *prefix)
+ while (*str && *prefix) {
+ if (*str != *prefix)
return 0;
str++;
@@ -93,11 +93,11 @@ static char *gpu_str_skip_token(char *str, char *token, int max)
int len = 0;
/* skip a variable/function name */
- while(*str) {
- if(ELEM7(*str, ' ', '(', ')', ',', '\t', '\n', '\r'))
+ while (*str) {
+ if (ELEM7(*str, ' ', '(', ')', ',', '\t', '\n', '\r'))
break;
else {
- if(token && len < max-1) {
+ if (token && len < max-1) {
*token= *str;
token++;
len++;
@@ -106,13 +106,13 @@ static char *gpu_str_skip_token(char *str, char *token, int max)
}
}
- if(token)
+ if (token)
*token= '\0';
/* skip the next special characters:
* note the missing ')' */
- while(*str) {
- if(ELEM6(*str, ' ', '(', ',', '\t', '\n', '\r'))
+ while (*str) {
+ if (ELEM6(*str, ' ', '(', ',', '\t', '\n', '\r'))
str++;
else
break;
@@ -126,38 +126,38 @@ static void gpu_parse_functions_string(GHash *hash, char *code)
GPUFunction *function;
int i, type, qual;
- while((code = strstr(code, "void "))) {
+ while ((code = strstr(code, "void "))) {
function = MEM_callocN(sizeof(GPUFunction), "GPUFunction");
code = gpu_str_skip_token(code, NULL, 0);
code = gpu_str_skip_token(code, function->name, MAX_FUNCTION_NAME);
/* get parameters */
- while(*code && *code != ')') {
+ while (*code && *code != ')') {
/* test if it's an input or output */
qual = FUNCTION_QUAL_IN;
- if(gpu_str_prefix(code, "out "))
+ if (gpu_str_prefix(code, "out "))
qual = FUNCTION_QUAL_OUT;
- if(gpu_str_prefix(code, "inout "))
+ if (gpu_str_prefix(code, "inout "))
qual = FUNCTION_QUAL_INOUT;
- if((qual != FUNCTION_QUAL_IN) || gpu_str_prefix(code, "in "))
+ if ((qual != FUNCTION_QUAL_IN) || gpu_str_prefix(code, "in "))
code = gpu_str_skip_token(code, NULL, 0);
/* test for type */
type= 0;
- for(i=1; i<=16; i++) {
- if(GPU_DATATYPE_STR[i] && gpu_str_prefix(code, GPU_DATATYPE_STR[i])) {
+ for (i=1; i<=16; i++) {
+ if (GPU_DATATYPE_STR[i] && gpu_str_prefix(code, GPU_DATATYPE_STR[i])) {
type= i;
break;
}
}
- if(!type && gpu_str_prefix(code, "sampler2DShadow"))
+ if (!type && gpu_str_prefix(code, "sampler2DShadow"))
type= GPU_SHADOW2D;
- if(!type && gpu_str_prefix(code, "sampler2D"))
+ if (!type && gpu_str_prefix(code, "sampler2D"))
type= GPU_TEX2D;
- if(type) {
+ if (type) {
/* add paramater */
code = gpu_str_skip_token(code, NULL, 0);
code = gpu_str_skip_token(code, NULL, 0);
@@ -171,7 +171,7 @@ static void gpu_parse_functions_string(GHash *hash, char *code)
}
}
- if(function->name[0] == '\0' || function->totparam == 0) {
+ if (function->name[0] == '\0' || function->totparam == 0) {
fprintf(stderr, "GPU functions parse error.\n");
MEM_freeN(function);
break;
@@ -194,27 +194,27 @@ static char *gpu_generate_function_prototyps(GHash *hash)
* generated code, to avoid have to add the actual code & recompile all */
ghi = BLI_ghashIterator_new(hash);
- for(; !BLI_ghashIterator_isDone(ghi); BLI_ghashIterator_step(ghi)) {
+ for (; !BLI_ghashIterator_isDone(ghi); BLI_ghashIterator_step(ghi)) {
name = BLI_ghashIterator_getValue(ghi);
function = BLI_ghashIterator_getValue(ghi);
BLI_dynstr_appendf(ds, "void %s(", name);
- for(a=0; a<function->totparam; a++) {
- if(function->paramqual[a] == FUNCTION_QUAL_OUT)
+ 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)
+ else if (function->paramqual[a] == FUNCTION_QUAL_INOUT)
BLI_dynstr_append(ds, "inout ");
- if(function->paramtype[a] == GPU_TEX2D)
+ if (function->paramtype[a] == GPU_TEX2D)
BLI_dynstr_append(ds, "sampler2D");
- else if(function->paramtype[a] == GPU_SHADOW2D)
+ else if (function->paramtype[a] == GPU_SHADOW2D)
BLI_dynstr_append(ds, "sampler2DShadow");
else
BLI_dynstr_append(ds, GPU_DATATYPE_STR[function->paramtype[a]]);
//BLI_dynstr_appendf(ds, " param%d", a);
- if(a != function->totparam-1)
+ if (a != function->totparam-1)
BLI_dynstr_append(ds, ", ");
}
BLI_dynstr_append(ds, ");\n");
@@ -231,7 +231,7 @@ static char *gpu_generate_function_prototyps(GHash *hash)
GPUFunction *GPU_lookup_function(const char *name)
{
- if(!FUNCTION_HASH) {
+ if (!FUNCTION_HASH) {
FUNCTION_HASH = BLI_ghash_new(BLI_ghashutil_strhash, BLI_ghashutil_strcmp, "GPU_lookup_function gh");
gpu_parse_functions_string(FUNCTION_HASH, glsl_material_library);
/*FUNCTION_PROTOTYPES = gpu_generate_function_prototyps(FUNCTION_HASH);
@@ -250,15 +250,15 @@ void GPU_codegen_exit(void)
{
extern Material defmaterial; // render module abuse...
- if(defmaterial.gpumaterial.first)
+ if (defmaterial.gpumaterial.first)
GPU_material_free(&defmaterial);
- if(FUNCTION_HASH) {
+ if (FUNCTION_HASH) {
BLI_ghash_free(FUNCTION_HASH, NULL, (GHashValFreeFP)MEM_freeN);
FUNCTION_HASH = NULL;
}
- if(glsl_material_library) {
+ if (glsl_material_library) {
MEM_freeN(glsl_material_library);
glsl_material_library = NULL;
}
@@ -324,9 +324,9 @@ static void codegen_print_datatype(DynStr *ds, int 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, ", ");
@@ -337,7 +337,7 @@ static int codegen_input_has_texture(GPUInput *input)
{
if (input->link)
return 0;
- else if(input->ima)
+ else if (input->ima)
return 1;
else
return input->tex != NULL;
@@ -345,21 +345,21 @@ static int codegen_input_has_texture(GPUInput *input)
const char *GPU_builtin_name(GPUBuiltin builtin)
{
- if(builtin == GPU_VIEW_MATRIX)
+ if (builtin == GPU_VIEW_MATRIX)
return "unfviewmat";
- else if(builtin == GPU_OBJECT_MATRIX)
+ else if (builtin == GPU_OBJECT_MATRIX)
return "unfobmat";
- else if(builtin == GPU_INVERSE_VIEW_MATRIX)
+ else if (builtin == GPU_INVERSE_VIEW_MATRIX)
return "unfinvviewmat";
- else if(builtin == GPU_INVERSE_OBJECT_MATRIX)
+ else if (builtin == GPU_INVERSE_OBJECT_MATRIX)
return "unfinvobmat";
- else if(builtin == GPU_VIEW_POSITION)
+ else if (builtin == GPU_VIEW_POSITION)
return "varposition";
- else if(builtin == GPU_VIEW_NORMAL)
+ else if (builtin == GPU_VIEW_NORMAL)
return "varnormal";
- else if(builtin == GPU_OBCOLOR)
+ else if (builtin == GPU_OBCOLOR)
return "unfobcolor";
- else if(builtin == GPU_AUTO_BUMPSCALE)
+ else if (builtin == GPU_AUTO_BUMPSCALE)
return "unfobautobumpscale";
else
return "";
@@ -397,7 +397,7 @@ static void codegen_set_unique_ids(ListBase *nodes)
else
input->texid = GET_INT_FROM_POINTER(BLI_ghash_lookup(bindhash, input->link));
}
- else if(input->ima) {
+ else if (input->ima) {
/* input is texture from image, assign only one texid per
buffer to avoid sampling the same texture twice */
if (!BLI_ghash_haskey(bindhash, input->ima)) {
@@ -421,7 +421,7 @@ static void codegen_set_unique_ids(ListBase *nodes)
/* make sure this pixel is defined exactly once */
if (input->source == GPU_SOURCE_TEX_PIXEL) {
- if(input->ima) {
+ if (input->ima) {
if (!BLI_ghash_haskey(definehash, input->ima)) {
input->definetex = 1;
BLI_ghash_insert(definehash, input->ima, SET_INT_IN_POINTER(input->texid));
@@ -463,13 +463,13 @@ static void codegen_print_uniforms_functions(DynStr *ds, ListBase *nodes)
(input->textype == GPU_TEX2D)? "sampler2D": "sampler2DShadow",
input->texid);
}
- else if(input->source == GPU_SOURCE_BUILTIN) {
+ else if (input->source == GPU_SOURCE_BUILTIN) {
/* only define each builting uniform/varying once */
- if(!(builtins & input->builtin)) {
+ if (!(builtins & input->builtin)) {
builtins |= input->builtin;
name = GPU_builtin_name(input->builtin);
- if(gpu_str_prefix(name, "unf")) {
+ if (gpu_str_prefix(name, "unf")) {
BLI_dynstr_appendf(ds, "uniform %s %s;\n",
GPU_DATATYPE_STR[input->type], name);
}
@@ -480,7 +480,7 @@ static void codegen_print_uniforms_functions(DynStr *ds, ListBase *nodes)
}
}
else if (input->source == GPU_SOURCE_VEC_UNIFORM) {
- if(input->dynamicvec) {
+ if (input->dynamicvec) {
/* only create uniforms for dynamic vectors */
BLI_dynstr_appendf(ds, "uniform %s unf%d;\n",
GPU_DATATYPE_STR[input->type], input->id);
@@ -549,10 +549,10 @@ static void codegen_call_functions(DynStr *ds, ListBase *nodes, GPUOutput *final
codegen_convert_datatype(ds, input->link->output->type, input->type,
"tmp", input->link->output->id);
}
- else if(input->source == GPU_SOURCE_BUILTIN)
+ else if (input->source == GPU_SOURCE_BUILTIN)
BLI_dynstr_appendf(ds, "%s", GPU_builtin_name(input->builtin));
- else if(input->source == GPU_SOURCE_VEC_UNIFORM) {
- if(input->dynamicvec)
+ else if (input->source == GPU_SOURCE_VEC_UNIFORM) {
+ if (input->dynamicvec)
BLI_dynstr_appendf(ds, "unf%d", input->id);
else
BLI_dynstr_appendf(ds, "cons%d", input->id);
@@ -631,7 +631,7 @@ static char *code_generate_vertex(ListBase *nodes)
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 */
+ if (input->attribtype == CD_TANGENT) { /* silly exception */
BLI_dynstr_appendf(ds, "\tvar%d.xyz = normalize((gl_ModelViewMatrix * vec4(att%d.xyz, 0)).xyz);\n", input->attribid, input->attribid);
BLI_dynstr_appendf(ds, "\tvar%d.w = att%d.w;\n", input->attribid, input->attribid);
}
@@ -660,12 +660,12 @@ void GPU_code_generate_glsl_lib(void)
DynStr *ds;
/* only initialize the library once */
- if(glsl_material_library)
+ if (glsl_material_library)
return;
ds = BLI_dynstr_new();
- if(GPU_bicubic_bump_support()){
+ if (GPU_bicubic_bump_support()) {
BLI_dynstr_append(ds, "/* These are needed for high quality bump mapping */\n"
"#version 130\n"
"#extension GL_ARB_texture_query_lod: enable\n"
@@ -697,7 +697,7 @@ static void GPU_nodes_extract_dynamic_inputs(GPUPass *pass, ListBase *nodes)
memset(inputs, 0, sizeof(*inputs));
- if(!shader)
+ if (!shader)
return;
GPU_shader_bind(shader);
@@ -709,7 +709,7 @@ static void GPU_nodes_extract_dynamic_inputs(GPUPass *pass, ListBase *nodes)
/* attributes don't need to be bound, they already have
* an id that the drawing functions will use */
- if(input->source == GPU_SOURCE_ATTRIB ||
+ if (input->source == GPU_SOURCE_ATTRIB ||
input->source == GPU_SOURCE_BUILTIN)
continue;
@@ -721,18 +721,18 @@ static void GPU_nodes_extract_dynamic_inputs(GPUPass *pass, ListBase *nodes)
/* pass non-dynamic uniforms to opengl */
extract = 0;
- if(input->ima || input->tex) {
+ if (input->ima || input->tex) {
if (input->bindtex)
extract = 1;
}
- else if(input->dynamicvec)
+ else if (input->dynamicvec)
extract = 1;
- if(extract)
+ if (extract)
input->shaderloc = GPU_shader_get_uniform(shader, input->shadername);
/* extract nodes */
- if(extract) {
+ if (extract) {
BLI_remlink(&node->inputs, input);
BLI_addtail(inputs, input);
}
@@ -758,7 +758,7 @@ void GPU_pass_bind(GPUPass *pass, double time, int mipmap)
if (input->ima)
input->tex = GPU_texture_from_blender(input->ima, input->iuser, time, mipmap);
- if(input->tex && input->bindtex) {
+ if (input->tex && input->bindtex) {
GPU_texture_bind(input->tex, input->texid);
GPU_shader_uniform_texture(shader, input->shaderloc, input->tex);
}
@@ -776,7 +776,7 @@ void GPU_pass_update_uniforms(GPUPass *pass)
/* pass dynamic inputs to opengl, others were removed */
for (input=inputs->first; input; input=input->next)
- if(!(input->ima || input->tex))
+ if (!(input->ima || input->tex))
GPU_shader_uniform_vector(shader, input->shaderloc, input->type, 1,
input->dynamicvec);
}
@@ -791,7 +791,7 @@ void GPU_pass_unbind(GPUPass *pass)
return;
for (input=inputs->first; input; input=input->next) {
- if(input->tex && input->bindtex)
+ if (input->tex && input->bindtex)
GPU_texture_unbind(input->tex);
if (input->ima)
@@ -848,14 +848,14 @@ static void gpu_node_input_link(GPUNode *node, GPUNodeLink *link, int type)
GPUNode *outnode;
const char *name;
- if(link->output) {
+ if (link->output) {
outnode = link->output->node;
name = outnode->name;
- if(strcmp(name, "set_value")==0 || strcmp(name, "set_rgb")==0) {
+ if (strcmp(name, "set_value")==0 || strcmp(name, "set_rgb")==0) {
input = MEM_dupallocN(outnode->inputs.first);
input->type = type;
- if(input->link)
+ if (input->link)
input->link->users++;
BLI_addtail(&node->inputs, input);
return;
@@ -865,7 +865,7 @@ static void gpu_node_input_link(GPUNode *node, GPUNodeLink *link, int type)
input = MEM_callocN(sizeof(GPUInput), "GPUInput");
input->node = node;
- if(link->builtin) {
+ if (link->builtin) {
/* builtin uniform */
input->type = type;
input->source = GPU_SOURCE_BUILTIN;
@@ -873,14 +873,14 @@ static void gpu_node_input_link(GPUNode *node, GPUNodeLink *link, int type)
MEM_freeN(link);
}
- else if(link->output) {
+ else if (link->output) {
/* link to a node output */
input->type = type;
input->source = GPU_SOURCE_TEX_PIXEL;
input->link = link;
link->users++;
}
- else if(link->dynamictex) {
+ else if (link->dynamictex) {
/* dynamic texture, GPUTexture is updated/deleted externally */
input->type = type;
input->source = GPU_SOURCE_TEX;
@@ -892,7 +892,7 @@ static void gpu_node_input_link(GPUNode *node, GPUNodeLink *link, int type)
input->dynamicdata = link->ptr2;
MEM_freeN(link);
}
- else if(link->texture) {
+ else if (link->texture) {
/* small texture created on the fly, like for colorbands */
input->type = GPU_VEC4;
input->source = GPU_SOURCE_TEX;
@@ -905,7 +905,7 @@ static void gpu_node_input_link(GPUNode *node, GPUNodeLink *link, int type)
MEM_freeN(link->ptr1);
MEM_freeN(link);
}
- else if(link->image) {
+ else if (link->image) {
/* blender image */
input->type = GPU_VEC4;
input->source = GPU_SOURCE_TEX;
@@ -916,7 +916,7 @@ static void gpu_node_input_link(GPUNode *node, GPUNodeLink *link, int type)
input->textype = GPU_TEX2D;
MEM_freeN(link);
}
- else if(link->attribtype) {
+ else if (link->attribtype) {
/* vertex attribute */
input->type = type;
input->source = GPU_SOURCE_ATTRIB;
@@ -931,7 +931,7 @@ static void gpu_node_input_link(GPUNode *node, GPUNodeLink *link, int type)
input->source = GPU_SOURCE_VEC_UNIFORM;
memcpy(input->vec, link->ptr1, type*sizeof(float));
- if(link->dynamic) {
+ if (link->dynamic) {
input->dynamicvec= link->ptr1;
input->dynamictype= link->dynamictype;
input->dynamicdata= link->ptr2;
@@ -946,7 +946,7 @@ static void gpu_node_input_socket(GPUNode *node, GPUNodeStack *sock)
{
GPUNodeLink *link;
- if(sock->link) {
+ if (sock->link) {
gpu_node_input_link(node, sock->link, sock->type);
}
else {
@@ -979,10 +979,10 @@ static void GPU_inputs_free(ListBase *inputs)
{
GPUInput *input;
- for(input=inputs->first; input; input=input->next) {
- if(input->link)
+ for (input=inputs->first; input; input=input->next) {
+ if (input->link)
GPU_node_link_free(input->link);
- else if(input->tex && !input->dynamictex)
+ else if (input->tex && !input->dynamictex)
GPU_texture_free(input->tex);
}
@@ -1029,16 +1029,16 @@ 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) {
- if(input->source == GPU_SOURCE_ATTRIB) {
- for(a=0; a<attribs->totlayer; a++) {
- if(attribs->layer[a].type == input->attribtype &&
+ 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++) {
+ if (attribs->layer[a].type == input->attribtype &&
strcmp(attribs->layer[a].name, input->attribname) == 0)
break;
}
- if(a == attribs->totlayer && a < GPU_MAX_ATTRIB) {
+ if (a == attribs->totlayer && a < GPU_MAX_ATTRIB) {
input->attribid = attribs->totlayer++;
input->attribfirst = 1;
@@ -1061,9 +1061,9 @@ static void gpu_nodes_get_builtin_flag(ListBase *nodes, int *builtin)
*builtin= 0;
- for(node=nodes->first; node; node=node->next)
- for(input=node->inputs.first; input; input=input->next)
- if(input->source == GPU_SOURCE_BUILTIN)
+ 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;
}
@@ -1163,7 +1163,7 @@ int GPU_link(GPUMaterial *mat, const char *name, ...)
int i;
function = GPU_lookup_function(name);
- if(!function) {
+ if (!function) {
fprintf(stderr, "GPU failed to find function %s\n", name);
return 0;
}
@@ -1171,8 +1171,8 @@ int GPU_link(GPUMaterial *mat, const char *name, ...)
node = GPU_node_begin(name);
va_start(params, name);
- for(i=0; i<function->totparam; i++) {
- if(function->paramqual[i] != FUNCTION_QUAL_IN) {
+ for (i=0; i<function->totparam; i++) {
+ if (function->paramqual[i] != FUNCTION_QUAL_IN) {
linkptr= va_arg(params, GPUNodeLink**);
GPU_node_output(node, function->paramtype[i], "", linkptr);
}
@@ -1199,7 +1199,7 @@ int GPU_stack_link(GPUMaterial *mat, const char *name, GPUNodeStack *in, GPUNode
int i, totin, totout;
function = GPU_lookup_function(name);
- if(!function) {
+ if (!function) {
fprintf(stderr, "GPU failed to find function %s\n", name);
return 0;
}
@@ -1208,24 +1208,24 @@ int GPU_stack_link(GPUMaterial *mat, const char *name, GPUNodeStack *in, GPUNode
totin = 0;
totout = 0;
- if(in) {
- for(i = 0; in[i].type != GPU_NONE; i++) {
+ if (in) {
+ for (i = 0; in[i].type != GPU_NONE; i++) {
gpu_node_input_socket(node, &in[i]);
totin++;
}
}
- if(out) {
- for(i = 0; out[i].type != GPU_NONE; i++) {
+ if (out) {
+ for (i = 0; out[i].type != GPU_NONE; i++) {
GPU_node_output(node, out[i].type, out[i].name, &out[i].link);
totout++;
}
}
va_start(params, out);
- for(i=0; i<function->totparam; i++) {
- if(function->paramqual[i] != FUNCTION_QUAL_IN) {
- if(totout == 0) {
+ for (i=0; i<function->totparam; i++) {
+ if (function->paramqual[i] != FUNCTION_QUAL_IN) {
+ if (totout == 0) {
linkptr= va_arg(params, GPUNodeLink**);
GPU_node_output(node, function->paramtype[i], "", linkptr);
}
@@ -1233,9 +1233,9 @@ int GPU_stack_link(GPUMaterial *mat, const char *name, GPUNodeStack *in, GPUNode
totout--;
}
else {
- if(totin == 0) {
+ if (totin == 0) {
link= va_arg(params, GPUNodeLink*);
- if(link->socket)
+ if (link->socket)
gpu_node_input_socket(node, link->socket);
else
gpu_node_input_link(node, link, function->paramtype[i]);
@@ -1259,11 +1259,11 @@ int GPU_link_changed(GPUNodeLink *link)
GPUInput *input;
const char *name;
- if(link->output) {
+ if (link->output) {
node = link->output->node;
name = node->name;
- if(strcmp(name, "set_value")==0 || strcmp(name, "set_rgb")==0) {
+ if (strcmp(name, "set_value")==0 || strcmp(name, "set_rgb")==0) {
input = node->inputs.first;
return (input->link != NULL);
}
@@ -1281,16 +1281,16 @@ static void gpu_nodes_tag(GPUNodeLink *link)
GPUNode *node;
GPUInput *input;
- if(!link->output)
+ if (!link->output)
return;
node = link->output->node;
- if(node->tag)
+ if (node->tag)
return;
node->tag= 1;
- for(input=node->inputs.first; input; input=input->next)
- if(input->link)
+ for (input=node->inputs.first; input; input=input->next)
+ if (input->link)
gpu_nodes_tag(input->link);
}
@@ -1298,15 +1298,15 @@ 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= 0;
gpu_nodes_tag(outlink);
- for(node=nodes->first; node; node=next) {
+ for (node=nodes->first; node; node=next) {
next = node->next;
- if(!node->tag) {
+ if (!node->tag) {
BLI_remlink(nodes, node);
GPU_node_free(node);
}
diff --git a/source/blender/gpu/intern/gpu_draw.c b/source/blender/gpu/intern/gpu_draw.c
index a5d6c374a42..01f000e3314 100644
--- a/source/blender/gpu/intern/gpu_draw.c
+++ b/source/blender/gpu/intern/gpu_draw.c
@@ -154,28 +154,28 @@ void GPU_render_text(MTFace *tface, int mode,
uv[2][1] = (tface->uv[2][1] - centery) * sizey + transy;
glBegin(GL_POLYGON);
- if(glattrib >= 0) glVertexAttrib2fvARB(glattrib, uv[0]);
+ if (glattrib >= 0) glVertexAttrib2fvARB(glattrib, uv[0]);
else glTexCoord2fv(uv[0]);
- if(col) gpu_mcol(col[0]);
+ if (col) gpu_mcol(col[0]);
glVertex3f(sizex * v1[0] + movex, sizey * v1[1] + movey, v1[2]);
- if(glattrib >= 0) glVertexAttrib2fvARB(glattrib, uv[1]);
+ if (glattrib >= 0) glVertexAttrib2fvARB(glattrib, uv[1]);
else glTexCoord2fv(uv[1]);
- if(col) gpu_mcol(col[1]);
+ if (col) gpu_mcol(col[1]);
glVertex3f(sizex * v2[0] + movex, sizey * v2[1] + movey, v2[2]);
- if(glattrib >= 0) glVertexAttrib2fvARB(glattrib, uv[2]);
+ if (glattrib >= 0) glVertexAttrib2fvARB(glattrib, uv[2]);
else glTexCoord2fv(uv[2]);
- if(col) gpu_mcol(col[2]);
+ if (col) gpu_mcol(col[2]);
glVertex3f(sizex * v3[0] + movex, sizey * v3[1] + movey, v3[2]);
- if(v4) {
+ if (v4) {
uv[3][0] = (tface->uv[3][0] - centerx) * sizex + transx;
uv[3][1] = (tface->uv[3][1] - centery) * sizey + transy;
- if(glattrib >= 0) glVertexAttrib2fvARB(glattrib, uv[3]);
+ if (glattrib >= 0) glVertexAttrib2fvARB(glattrib, uv[3]);
else glTexCoord2fv(uv[3]);
- if(col) gpu_mcol(col[3]);
+ if (col) gpu_mcol(col[3]);
glVertex3f(sizex * v4[0] + movex, sizey * v4[1] + movey, v4[2]);
}
glEnd();
@@ -263,16 +263,16 @@ static GLenum gpu_get_mipmap_filter(int mag)
{
/* linearmipmap is off by default *when mipmapping is off,
* use unfiltered display */
- if(mag) {
- if(GTS.linearmipmap || GTS.domipmap)
+ if (mag) {
+ if (GTS.linearmipmap || GTS.domipmap)
return GL_LINEAR;
else
return GL_NEAREST;
}
else {
- if(GTS.linearmipmap)
+ if (GTS.linearmipmap)
return GL_LINEAR_MIPMAP_LINEAR;
- else if(GTS.domipmap)
+ else if (GTS.domipmap)
return GL_LINEAR_MIPMAP_NEAREST;
else
return GL_NEAREST;
@@ -305,10 +305,10 @@ static void gpu_make_repbind(Image *ima)
ImBuf *ibuf;
ibuf = BKE_image_get_ibuf(ima, NULL);
- if(ibuf==NULL)
+ if (ibuf==NULL)
return;
- if(ima->repbind) {
+ if (ima->repbind) {
glDeleteTextures(ima->totbind, (GLuint *)ima->repbind);
MEM_freeN(ima->repbind);
ima->repbind= NULL;
@@ -317,19 +317,19 @@ static void gpu_make_repbind(Image *ima)
ima->totbind= ima->xrep*ima->yrep;
- if(ima->totbind>1)
+ if (ima->totbind>1)
ima->repbind= MEM_callocN(sizeof(int)*ima->totbind, "repbind");
}
static void gpu_clear_tpage(void)
{
- if(GTS.lasttface==NULL)
+ if (GTS.lasttface==NULL)
return;
GTS.lasttface= NULL;
GTS.curtile= 0;
GTS.curima= NULL;
- if(GTS.curtilemode!=0) {
+ if (GTS.curtilemode!=0) {
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
@@ -348,17 +348,17 @@ static void gpu_clear_tpage(void)
static void gpu_set_alpha_blend(GPUBlendMode alphablend)
{
- if(alphablend == GPU_BLEND_SOLID) {
+ if (alphablend == GPU_BLEND_SOLID) {
glDisable(GL_BLEND);
glDisable(GL_ALPHA_TEST);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
- else if(alphablend==GPU_BLEND_ADD) {
+ else if (alphablend==GPU_BLEND_ADD) {
glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE);
glDisable(GL_ALPHA_TEST);
}
- else if(ELEM(alphablend, GPU_BLEND_ALPHA, GPU_BLEND_ALPHA_SORT)) {
+ else if (ELEM(alphablend, GPU_BLEND_ALPHA, GPU_BLEND_ALPHA_SORT)) {
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@@ -366,7 +366,7 @@ static void gpu_set_alpha_blend(GPUBlendMode alphablend)
* turn off alpha test in this case */
/* added after 2.45 to clip alpha */
- if(U.glalphaclip == 1.0f) {
+ if (U.glalphaclip == 1.0f) {
glDisable(GL_ALPHA_TEST);
}
else {
@@ -374,7 +374,7 @@ static void gpu_set_alpha_blend(GPUBlendMode alphablend)
glAlphaFunc(GL_GREATER, U.glalphaclip);
}
}
- else if(alphablend==GPU_BLEND_CLIP) {
+ else if (alphablend==GPU_BLEND_CLIP) {
glDisable(GL_BLEND);
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, 0.5f);
@@ -384,7 +384,7 @@ static void gpu_set_alpha_blend(GPUBlendMode alphablend)
static void gpu_verify_alpha_blend(int alphablend)
{
/* verify alpha blending modes */
- if(GTS.alphablend == alphablend)
+ if (GTS.alphablend == alphablend)
return;
gpu_set_alpha_blend(alphablend);
@@ -427,83 +427,83 @@ int GPU_verify_image(Image *ima, ImageUser *iuser, int tftile, int compare, int
GTS.tileYRep = 0;
/* setting current tile according to frame */
- if(ima && (ima->tpageflag & IMA_TWINANIM))
+ if (ima && (ima->tpageflag & IMA_TWINANIM))
GTS.tile= ima->lastframe;
else
GTS.tile= tftile;
GTS.tile = MAX2(0, GTS.tile);
- if(ima) {
+ if (ima) {
GTS.tileXRep = ima->xrep;
GTS.tileYRep = ima->yrep;
}
/* if same image & tile, we're done */
- if(compare && ima == GTS.curima && GTS.curtile == GTS.tile &&
+ if (compare && ima == GTS.curima && GTS.curtile == GTS.tile &&
GTS.tilemode == GTS.curtilemode && GTS.curtileXRep == GTS.tileXRep &&
GTS.curtileYRep == GTS.tileYRep)
return (ima != NULL);
/* if tiling mode or repeat changed, change texture matrix to fit */
- if(GTS.tilemode!=GTS.curtilemode || GTS.curtileXRep!=GTS.tileXRep ||
+ if (GTS.tilemode!=GTS.curtilemode || GTS.curtileXRep!=GTS.tileXRep ||
GTS.curtileYRep != GTS.tileYRep) {
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
- if(ima && (ima->tpageflag & IMA_TILES))
+ if (ima && (ima->tpageflag & IMA_TILES))
glScalef(ima->xrep, ima->yrep, 1.0);
glMatrixMode(GL_MODELVIEW);
}
/* check if we have a valid image */
- if(ima==NULL || ima->ok==0)
+ if (ima==NULL || ima->ok==0)
return 0;
/* check if we have a valid image buffer */
ibuf= BKE_image_get_ibuf(ima, iuser);
- if(ibuf==NULL)
+ if (ibuf==NULL)
return 0;
- if(ibuf->rect_float) {
- if(U.use_16bit_textures) {
+ if (ibuf->rect_float) {
+ if (U.use_16bit_textures) {
/* use high precision textures. This is relatively harmless because OpenGL gives us
* a high precision format only if it is available */
use_high_bit_depth = TRUE;
}
/* TODO unneeded when float images are correctly treated as linear always */
- if(ibuf->profile == IB_PROFILE_LINEAR_RGB)
+ if (ibuf->profile == IB_PROFILE_LINEAR_RGB)
do_color_management = TRUE;
- if(ibuf->rect==NULL)
+ if (ibuf->rect==NULL)
IMB_rect_from_float(ibuf);
}
/* currently, tpage refresh is used by ima sequences */
- if(ima->tpageflag & IMA_TPAGE_REFRESH) {
+ if (ima->tpageflag & IMA_TPAGE_REFRESH) {
GPU_free_image(ima);
ima->tpageflag &= ~IMA_TPAGE_REFRESH;
}
- if(GTS.tilemode) {
+ if (GTS.tilemode) {
/* tiled mode */
- if(ima->repbind==NULL) gpu_make_repbind(ima);
- if(GTS.tile>=ima->totbind) GTS.tile= 0;
+ if (ima->repbind==NULL) gpu_make_repbind(ima);
+ if (GTS.tile>=ima->totbind) GTS.tile= 0;
/* this happens when you change repeat buttons */
- if(ima->repbind) bind= &ima->repbind[GTS.tile];
+ if (ima->repbind) bind= &ima->repbind[GTS.tile];
else bind= &ima->bindcode;
- if(*bind==0) {
+ if (*bind==0) {
texwindx= ibuf->x/ima->xrep;
texwindy= ibuf->y/ima->yrep;
- if(GTS.tile>=ima->xrep*ima->yrep)
+ if (GTS.tile>=ima->xrep*ima->yrep)
GTS.tile= ima->xrep*ima->yrep-1;
texwinsy= GTS.tile / ima->xrep;
@@ -515,8 +515,8 @@ int GPU_verify_image(Image *ima, ImageUser *iuser, int tftile, int compare, int
tpx= texwindx;
tpy= texwindy;
- if(use_high_bit_depth) {
- if(do_color_management) {
+ if (use_high_bit_depth) {
+ if (do_color_management) {
srgb_frect = MEM_mallocN(ibuf->x*ibuf->y*sizeof(float)*4, "floar_buf_col_cor");
IMB_buffer_float_from_float(srgb_frect, ibuf->rect_float,
ibuf->channels, IB_PROFILE_SRGB, ibuf->profile, 0,
@@ -536,12 +536,12 @@ int GPU_verify_image(Image *ima, ImageUser *iuser, int tftile, int compare, int
/* regular image mode */
bind= &ima->bindcode;
- if(*bind==0) {
+ if (*bind==0) {
tpx= ibuf->x;
tpy= ibuf->y;
rect= ibuf->rect;
- if(use_high_bit_depth) {
- if(do_color_management) {
+ if (use_high_bit_depth) {
+ if (do_color_management) {
frect = srgb_frect = MEM_mallocN(ibuf->x*ibuf->y*sizeof(*srgb_frect)*4, "floar_buf_col_cor");
IMB_buffer_float_from_float(srgb_frect, ibuf->rect_float,
ibuf->channels, IB_PROFILE_SRGB, ibuf->profile, 0,
@@ -555,7 +555,7 @@ int GPU_verify_image(Image *ima, ImageUser *iuser, int tftile, int compare, int
}
}
- if(*bind != 0) {
+ if (*bind != 0) {
/* enable opengl drawing with textures */
glBindTexture(GL_TEXTURE_2D, *bind);
return *bind;
@@ -566,7 +566,7 @@ int GPU_verify_image(Image *ima, ImageUser *iuser, int tftile, int compare, int
/* for tiles, copy only part of image into buffer */
if (GTS.tilemode) {
- if(use_high_bit_depth) {
+ if (use_high_bit_depth) {
float *frectrow, *ftilerectrow;
ftilerect= MEM_mallocN(rectw*recth*sizeof(*ftilerect), "tilerect");
@@ -602,7 +602,7 @@ int GPU_verify_image(Image *ima, ImageUser *iuser, int tftile, int compare, int
rectw= smaller_pow2_limit(rectw);
recth= smaller_pow2_limit(recth);
- if(use_high_bit_depth) {
+ if (use_high_bit_depth) {
fscalerect= MEM_mallocN(rectw*recth*sizeof(*fscalerect)*4, "fscalerect");
gluScaleImage(GL_RGBA, tpx, tpy, GL_FLOAT, frect, rectw, recth, GL_FLOAT, fscalerect);
@@ -621,7 +621,7 @@ int GPU_verify_image(Image *ima, ImageUser *iuser, int tftile, int compare, int
glBindTexture( GL_TEXTURE_2D, *bind);
if (!(gpu_get_mipmap() && mipmap)) {
- if(use_high_bit_depth)
+ if (use_high_bit_depth)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16, rectw, recth, 0, GL_RGBA, GL_FLOAT, frect);
else
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, rectw, recth, 0, GL_RGBA, GL_UNSIGNED_BYTE, rect);
@@ -629,7 +629,7 @@ int GPU_verify_image(Image *ima, ImageUser *iuser, int tftile, int compare, int
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gpu_get_mipmap_filter(1));
}
else {
- if(use_high_bit_depth)
+ if (use_high_bit_depth)
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA16, rectw, recth, GL_RGBA, GL_FLOAT, frect);
else
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, rectw, recth, GL_RGBA, GL_UNSIGNED_BYTE, rect);
@@ -677,7 +677,7 @@ int GPU_set_tpage(MTFace *tface, int mipmap, int alphablend)
Image *ima;
/* check if we need to clear the state */
- if(tface==NULL) {
+ if (tface==NULL) {
gpu_clear_tpage();
return 0;
}
@@ -688,7 +688,7 @@ int GPU_set_tpage(MTFace *tface, int mipmap, int alphablend)
gpu_verify_alpha_blend(alphablend);
gpu_verify_reflection(ima);
- if(GPU_verify_image(ima, NULL, tface->tile, 1, mipmap)) {
+ if (GPU_verify_image(ima, NULL, tface->tile, 1, mipmap)) {
GTS.curtile= GTS.tile;
GTS.curima= GTS.ima;
GTS.curtilemode= GTS.tilemode;
@@ -725,13 +725,13 @@ void GPU_paint_set_mipmap(int mipmap)
{
Image* ima;
- if(!GTS.domipmap)
+ if (!GTS.domipmap)
return;
- if(mipmap) {
- for(ima=G.main->image.first; ima; ima=ima->id.next) {
- if(ima->bindcode) {
- if(ima->tpageflag & IMA_MIPMAP_COMPLETE) {
+ if (mipmap) {
+ for (ima=G.main->image.first; ima; ima=ima->id.next) {
+ if (ima->bindcode) {
+ if (ima->tpageflag & IMA_MIPMAP_COMPLETE) {
glBindTexture(GL_TEXTURE_2D, ima->bindcode);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gpu_get_mipmap_filter(0));
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gpu_get_mipmap_filter(1));
@@ -745,8 +745,8 @@ void GPU_paint_set_mipmap(int mipmap)
}
else {
- for(ima=G.main->image.first; ima; ima=ima->id.next) {
- if(ima->bindcode) {
+ for (ima=G.main->image.first; ima; ima=ima->id.next) {
+ if (ima->bindcode) {
glBindTexture(GL_TEXTURE_2D, ima->bindcode);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gpu_get_mipmap_filter(1));
@@ -779,7 +779,7 @@ void GPU_paint_update_image(Image *ima, int x, int y, int w, int h, int mipmap)
glGetIntegerv(GL_UNPACK_SKIP_ROWS, &skip_rows);
/* if color correction is needed, we must update the part that needs updating. */
- if(ibuf->rect_float && (!U.use_16bit_textures || (ibuf->profile == IB_PROFILE_LINEAR_RGB))) {
+ if (ibuf->rect_float && (!U.use_16bit_textures || (ibuf->profile == IB_PROFILE_LINEAR_RGB))) {
float *buffer = MEM_mallocN(w*h*sizeof(float)*4, "temp_texpaint_float_buf");
IMB_partial_rect_from_float(ibuf, buffer, x, y, w, h);
@@ -789,7 +789,7 @@ void GPU_paint_update_image(Image *ima, int x, int y, int w, int h, int mipmap)
MEM_freeN(buffer);
- if(ima->tpageflag & IMA_MIPMAP_COMPLETE)
+ if (ima->tpageflag & IMA_MIPMAP_COMPLETE)
ima->tpageflag &= ~IMA_MIPMAP_COMPLETE;
return;
@@ -801,7 +801,7 @@ void GPU_paint_update_image(Image *ima, int x, int y, int w, int h, int mipmap)
glPixelStorei(GL_UNPACK_SKIP_PIXELS, x);
glPixelStorei(GL_UNPACK_SKIP_ROWS, y);
- if(ibuf->rect_float)
+ if (ibuf->rect_float)
glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, w, h, GL_RGBA,
GL_FLOAT, ibuf->rect_float);
else
@@ -812,7 +812,7 @@ void GPU_paint_update_image(Image *ima, int x, int y, int w, int h, int mipmap)
glPixelStorei(GL_UNPACK_SKIP_PIXELS, skip_pixels);
glPixelStorei(GL_UNPACK_SKIP_ROWS, skip_rows);
- if(ima->tpageflag & IMA_MIPMAP_COMPLETE)
+ if (ima->tpageflag & IMA_MIPMAP_COMPLETE)
ima->tpageflag &= ~IMA_MIPMAP_COMPLETE;
}
}
@@ -821,15 +821,15 @@ void GPU_update_images_framechange(void)
{
Image *ima;
- for(ima=G.main->image.first; ima; ima=ima->id.next) {
- if(ima->tpageflag & IMA_TWINANIM) {
- if(ima->twend >= ima->xrep*ima->yrep)
+ for (ima=G.main->image.first; ima; ima=ima->id.next) {
+ if (ima->tpageflag & IMA_TWINANIM) {
+ if (ima->twend >= ima->xrep*ima->yrep)
ima->twend= ima->xrep*ima->yrep-1;
/* check: is bindcode not in the array? free. (to do) */
ima->lastframe++;
- if(ima->lastframe > ima->twend)
+ if (ima->lastframe > ima->twend)
ima->lastframe= ima->twsta;
}
}
@@ -850,8 +850,8 @@ int GPU_update_image_time(Image *ima, double time)
if (ima->lastupdate > (float)time)
ima->lastupdate=(float)time;
- if(ima->tpageflag & IMA_TWINANIM) {
- if(ima->twend >= ima->xrep*ima->yrep) ima->twend= ima->xrep*ima->yrep-1;
+ if (ima->tpageflag & IMA_TWINANIM) {
+ if (ima->twend >= ima->xrep*ima->yrep) ima->twend= ima->xrep*ima->yrep-1;
/* check: is the bindcode not in the array? Then free. (still to do) */
@@ -862,8 +862,8 @@ int GPU_update_image_time(Image *ima, double time)
newframe = ima->lastframe+inc;
- if(newframe > (int)ima->twend) {
- if(ima->twend-ima->twsta != 0)
+ if (newframe > (int)ima->twend) {
+ if (ima->twend-ima->twsta != 0)
newframe = (int)ima->twsta-1 + (newframe-ima->twend)%(ima->twend-ima->twsta);
else
newframe = ima->twsta;
@@ -878,12 +878,12 @@ int GPU_update_image_time(Image *ima, double time)
void GPU_free_smoke(SmokeModifierData *smd)
{
- if(smd->type & MOD_SMOKE_TYPE_DOMAIN && smd->domain) {
- if(smd->domain->tex)
+ if (smd->type & MOD_SMOKE_TYPE_DOMAIN && smd->domain) {
+ if (smd->domain->tex)
GPU_texture_free(smd->domain->tex);
smd->domain->tex = NULL;
- if(smd->domain->tex_shadow)
+ if (smd->domain->tex_shadow)
GPU_texture_free(smd->domain->tex_shadow);
smd->domain->tex_shadow = NULL;
}
@@ -892,9 +892,9 @@ void GPU_free_smoke(SmokeModifierData *smd)
void GPU_create_smoke(SmokeModifierData *smd, int highres)
{
#ifdef WITH_SMOKE
- if(smd->type & MOD_SMOKE_TYPE_DOMAIN && !smd->domain->tex && !highres)
+ if (smd->type & MOD_SMOKE_TYPE_DOMAIN && !smd->domain->tex && !highres)
smd->domain->tex = GPU_texture_create_3D(smd->domain->res[0], smd->domain->res[1], smd->domain->res[2], smoke_get_density(smd->domain->fluid));
- else if(smd->type & MOD_SMOKE_TYPE_DOMAIN && !smd->domain->tex && highres)
+ else if (smd->type & MOD_SMOKE_TYPE_DOMAIN && !smd->domain->tex && highres)
smd->domain->tex = GPU_texture_create_3D(smd->domain->res_wt[0], smd->domain->res_wt[1], smd->domain->res_wt[2], smoke_turbulence_get_density(smd->domain->wt));
smd->domain->tex_shadow = GPU_texture_create_3D(smd->domain->res[0], smd->domain->res[1], smd->domain->res[2], smd->domain->shadow);
@@ -920,13 +920,13 @@ void GPU_free_unused_buffers(void)
{
Image *ima;
- if(!BLI_thread_is_main())
+ if (!BLI_thread_is_main())
return;
BLI_lock_thread(LOCK_OPENGL);
/* images */
- for(ima=image_free_queue.first; ima; ima=ima->id.next)
+ for (ima=image_free_queue.first; ima; ima=ima->id.next)
GPU_free_image(ima);
BLI_freelistN(&image_free_queue);
@@ -940,25 +940,25 @@ void GPU_free_unused_buffers(void)
void GPU_free_image(Image *ima)
{
- if(!BLI_thread_is_main()) {
+ if (!BLI_thread_is_main()) {
gpu_queue_image_for_free(ima);
return;
}
/* free regular image binding */
- if(ima->bindcode) {
+ if (ima->bindcode) {
glDeleteTextures(1, (GLuint *)&ima->bindcode);
ima->bindcode= 0;
}
/* free glsl image binding */
- if(ima->gputexture) {
+ if (ima->gputexture) {
GPU_texture_free(ima->gputexture);
ima->gputexture= NULL;
}
/* free repeated image binding */
- if(ima->repbind) {
+ if (ima->repbind) {
glDeleteTextures(ima->totbind, (GLuint *)ima->repbind);
MEM_freeN(ima->repbind);
@@ -972,8 +972,8 @@ void GPU_free_images(void)
{
Image* ima;
- if(G.main)
- for(ima=G.main->image.first; ima; ima=ima->id.next)
+ if (G.main)
+ for (ima=G.main->image.first; ima; ima=ima->id.next)
GPU_free_image(ima);
}
@@ -982,9 +982,9 @@ void GPU_free_images_anim(void)
{
Image* ima;
- if(G.main)
- for(ima=G.main->image.first; ima; ima=ima->id.next)
- if(ELEM(ima->source, IMA_SRC_SEQUENCE, IMA_SRC_MOVIE))
+ if (G.main)
+ for (ima=G.main->image.first; ima; ima=ima->id.next)
+ if (ELEM(ima->source, IMA_SRC_SEQUENCE, IMA_SRC_MOVIE))
GPU_free_image(ima);
}
@@ -1025,11 +1025,11 @@ static struct GPUMaterialState {
/* fixed function material, alpha handed by caller */
static void gpu_material_to_fixed(GPUMaterialFixed *smat, const Material *bmat, const int gamma, const Object *ob, const int new_shading_nodes)
{
- if(new_shading_nodes || bmat->mode & MA_SHLESS) {
+ if (new_shading_nodes || bmat->mode & MA_SHLESS) {
copy_v3_v3(smat->diff, &bmat->r);
smat->diff[3]= 1.0;
- if(gamma)
+ if (gamma)
linearrgb_to_srgb_v3_v3(smat->diff, smat->diff);
zero_v4(smat->spec);
@@ -1039,14 +1039,14 @@ static void gpu_material_to_fixed(GPUMaterialFixed *smat, const Material *bmat,
mul_v3_v3fl(smat->diff, &bmat->r, bmat->ref + bmat->emit);
smat->diff[3]= 1.0; /* caller may set this to bmat->alpha */
- if(bmat->shade_flag & MA_OBCOLOR)
+ if (bmat->shade_flag & MA_OBCOLOR)
mul_v3_v3(smat->diff, ob->col);
mul_v3_v3fl(smat->spec, &bmat->specr, bmat->spec);
smat->spec[3]= 1.0; /* always 1 */
smat->hard= CLAMPIS(bmat->har, 0, 128);
- if(gamma) {
+ if (gamma) {
linearrgb_to_srgb_v3_v3(smat->diff, smat->diff);
linearrgb_to_srgb_v3_v3(smat->spec, smat->spec);
}
@@ -1055,10 +1055,10 @@ static void gpu_material_to_fixed(GPUMaterialFixed *smat, const Material *bmat,
static Material *gpu_active_node_material(Material *ma)
{
- if(ma && ma->use_nodes && ma->nodetree) {
+ if (ma && ma->use_nodes && ma->nodetree) {
bNode *node= nodeGetActiveID(ma->nodetree, ID_MA);
- if(node)
+ if (node)
return (Material *)node->id;
else
return NULL;
@@ -1096,10 +1096,10 @@ void GPU_begin_object_materials(View3D *v3d, RegionView3D *rv3d, Scene *scene, O
* for solid we don't use transparency at all. */
GMS.use_alpha_pass = (do_alpha_after != NULL);
GMS.is_alpha_pass = (v3d && v3d->transp);
- if(GMS.use_alpha_pass)
+ if (GMS.use_alpha_pass)
*do_alpha_after = 0;
- if(GMS.totmat > FIXEDMAT) {
+ if (GMS.totmat > FIXEDMAT) {
GMS.matbuf= MEM_callocN(sizeof(GPUMaterialFixed)*GMS.totmat, "GMS.matbuf");
GMS.gmatbuf= MEM_callocN(sizeof(*GMS.gmatbuf)*GMS.totmat, "GMS.matbuf");
GMS.alphablend= MEM_callocN(sizeof(*GMS.alphablend)*GMS.totmat, "GMS.matbuf");
@@ -1111,13 +1111,13 @@ void GPU_begin_object_materials(View3D *v3d, RegionView3D *rv3d, Scene *scene, O
}
/* no materials assigned? */
- if(ob->totcol==0) {
+ if (ob->totcol==0) {
gpu_material_to_fixed(&GMS.matbuf[0], &defmaterial, 0, ob, new_shading_nodes);
/* do material 1 too, for displists! */
memcpy(&GMS.matbuf[1], &GMS.matbuf[0], sizeof(GPUMaterialFixed));
- if(glsl) {
+ if (glsl) {
GMS.gmatbuf[0]= &defmaterial;
GPU_material_from_blender(GMS.gscene, &defmaterial);
}
@@ -1126,16 +1126,16 @@ void GPU_begin_object_materials(View3D *v3d, RegionView3D *rv3d, Scene *scene, O
}
/* setup materials */
- for(a=1; a<=ob->totcol; a++) {
+ for (a=1; a<=ob->totcol; a++) {
/* find a suitable material */
ma= give_current_material(ob, a);
- if(!glsl && !new_shading_nodes) ma= gpu_active_node_material(ma);
- if(ma==NULL) ma= &defmaterial;
+ if (!glsl && !new_shading_nodes) ma= gpu_active_node_material(ma);
+ if (ma==NULL) ma= &defmaterial;
/* create glsl material if requested */
gpumat = (glsl)? GPU_material_from_blender(GMS.gscene, ma): NULL;
- if(gpumat) {
+ if (gpumat) {
/* do glsl only if creating it succeed, else fallback */
GMS.gmatbuf[a]= ma;
alphablend = GPU_material_alpha_blend(gpumat, ob->col);
@@ -1144,7 +1144,7 @@ void GPU_begin_object_materials(View3D *v3d, RegionView3D *rv3d, Scene *scene, O
/* fixed function opengl materials */
gpu_material_to_fixed(&GMS.matbuf[a], ma, gamma, ob, new_shading_nodes);
- if(GMS.use_alpha_pass) {
+ if (GMS.use_alpha_pass) {
GMS.matbuf[a].diff[3]= ma->alpha;
alphablend = (ma->alpha == 1.0f)? GPU_BLEND_SOLID: GPU_BLEND_ALPHA;
}
@@ -1156,8 +1156,8 @@ void GPU_begin_object_materials(View3D *v3d, RegionView3D *rv3d, Scene *scene, O
/* setting do_alpha_after = 1 indicates this object needs to be
* drawn in a second alpha pass for improved blending */
- if(do_alpha_after && !GMS.is_alpha_pass)
- if(ELEM3(alphablend, GPU_BLEND_ALPHA, GPU_BLEND_ADD, GPU_BLEND_ALPHA_SORT))
+ if (do_alpha_after && !GMS.is_alpha_pass)
+ if (ELEM3(alphablend, GPU_BLEND_ALPHA, GPU_BLEND_ADD, GPU_BLEND_ALPHA_SORT))
*do_alpha_after= 1;
GMS.alphablend[a]= alphablend;
@@ -1174,7 +1174,7 @@ int GPU_enable_material(int nr, void *attribs)
GPUBlendMode alphablend;
/* no GPU_begin_object_materials, use default material */
- if(!GMS.matbuf) {
+ if (!GMS.matbuf) {
float diff[4], spec[4];
memset(&GMS, 0, sizeof(GMS));
@@ -1193,19 +1193,19 @@ int GPU_enable_material(int nr, void *attribs)
}
/* prevent index to use un-initialized array items */
- if(nr>=GMS.totmat)
+ if (nr>=GMS.totmat)
nr= 0;
- if(gattribs)
+ if (gattribs)
memset(gattribs, 0, sizeof(*gattribs));
/* keep current material */
- if(nr==GMS.lastmatnr)
+ if (nr==GMS.lastmatnr)
return GMS.lastretval;
/* unbind glsl material */
- if(GMS.gboundmat) {
- if(GMS.is_alpha_pass) glDepthMask(0);
+ if (GMS.gboundmat) {
+ if (GMS.is_alpha_pass) glDepthMask(0);
GPU_material_unbind(GPU_material_from_blender(GMS.gscene, GMS.gboundmat));
GMS.gboundmat= NULL;
}
@@ -1214,19 +1214,19 @@ int GPU_enable_material(int nr, void *attribs)
GMS.lastmatnr = nr;
GMS.lastretval = 1;
- if(GMS.use_alpha_pass) {
+ if (GMS.use_alpha_pass) {
GMS.lastretval = ELEM(GMS.alphablend[nr], GPU_BLEND_SOLID, GPU_BLEND_CLIP);
- if(GMS.is_alpha_pass)
+ if (GMS.is_alpha_pass)
GMS.lastretval = !GMS.lastretval;
}
else
GMS.lastretval = !GMS.is_alpha_pass;
- if(GMS.lastretval) {
+ if (GMS.lastretval) {
/* for alpha pass, use alpha blend */
alphablend = GMS.alphablend[nr];
- if(gattribs && GMS.gmatbuf[nr]) {
+ if (gattribs && GMS.gmatbuf[nr]) {
/* bind glsl material and get attributes */
Material *mat = GMS.gmatbuf[nr];
float auto_bump_scale;
@@ -1241,10 +1241,10 @@ int GPU_enable_material(int nr, void *attribs)
/* for glsl use alpha blend mode, unless it's set to solid and
* we are already drawing in an alpha pass */
- if(mat->game.alpha_blend != GPU_BLEND_SOLID)
+ if (mat->game.alpha_blend != GPU_BLEND_SOLID)
alphablend= mat->game.alpha_blend;
- if(GMS.is_alpha_pass) glDepthMask(1);
+ if (GMS.is_alpha_pass) glDepthMask(1);
}
else {
/* or do fixed function opengl material */
@@ -1262,7 +1262,7 @@ int GPU_enable_material(int nr, void *attribs)
void GPU_set_material_alpha_blend(int alphablend)
{
- if(GMS.lastalphablend == alphablend)
+ if (GMS.lastalphablend == alphablend)
return;
gpu_set_alpha_blend(alphablend);
@@ -1279,8 +1279,8 @@ void GPU_disable_material(void)
GMS.lastmatnr= -1;
GMS.lastretval= 1;
- if(GMS.gboundmat) {
- if(GMS.is_alpha_pass) glDepthMask(0);
+ if (GMS.gboundmat) {
+ if (GMS.is_alpha_pass) glDepthMask(0);
GPU_material_unbind(GPU_material_from_blender(GMS.gscene, GMS.gboundmat));
GMS.gboundmat= NULL;
}
@@ -1292,7 +1292,7 @@ void GPU_end_object_materials(void)
{
GPU_disable_material();
- if(GMS.matbuf && GMS.matbuf != GMS.matbuf_fixed) {
+ if (GMS.matbuf && GMS.matbuf != GMS.matbuf_fixed) {
MEM_freeN(GMS.matbuf);
MEM_freeN(GMS.gmatbuf);
MEM_freeN(GMS.alphablend);
@@ -1303,7 +1303,7 @@ void GPU_end_object_materials(void)
GMS.alphablend= NULL;
/* resetting the texture matrix after the glScale needed for tiled textures */
- if(GTS.tilemode) {
+ if (GTS.tilemode) {
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
@@ -1318,7 +1318,7 @@ int GPU_default_lights(void)
int a, count = 0;
/* initialize */
- if(U.light[0].flag==0 && U.light[1].flag==0 && U.light[2].flag==0) {
+ if (U.light[0].flag==0 && U.light[1].flag==0 && U.light[2].flag==0) {
U.light[0].flag= 1;
U.light[0].vec[0]= -0.3; U.light[0].vec[1]= 0.3; U.light[0].vec[2]= 0.9;
U.light[0].col[0]= 0.8; U.light[0].col[1]= 0.8; U.light[0].col[2]= 0.8;
@@ -1340,9 +1340,9 @@ int GPU_default_lights(void)
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_FALSE);
- for(a=0; a<8; a++) {
- if(a<3) {
- if(U.light[a].flag) {
+ for (a=0; a<8; a++) {
+ if (a<3) {
+ if (U.light[a].flag) {
glEnable(GL_LIGHT0+a);
normalize_v3_v3(position, U.light[a].vec);
@@ -1386,7 +1386,7 @@ int GPU_scene_object_lights(Scene *scene, Object *ob, int lay, float viewmat[][4
float position[4], direction[4], energy[4];
/* disable all lights */
- for(count=0; count<8; count++)
+ for (count=0; count<8; count++)
glDisable(GL_LIGHT0+count);
/* view direction for specular is not compute correct by default in
@@ -1395,11 +1395,11 @@ int GPU_scene_object_lights(Scene *scene, Object *ob, int lay, float viewmat[][4
count= 0;
- for(base=scene->base.first; base; base=base->next) {
- if(base->object->type!=OB_LAMP)
+ for (base=scene->base.first; base; base=base->next) {
+ if (base->object->type!=OB_LAMP)
continue;
- if(!(base->lay & lay) || !(base->lay & ob->lay))
+ if (!(base->lay & lay) || !(base->lay & ob->lay))
continue;
la= base->object->data;
@@ -1410,7 +1410,7 @@ int GPU_scene_object_lights(Scene *scene, Object *ob, int lay, float viewmat[][4
where_is_object_simul(scene, base->object);
- if(la->type==LA_SUN) {
+ if (la->type==LA_SUN) {
/* sun lamp */
copy_v3_v3(direction, base->object->obmat[2]);
direction[3]= 0.0;
@@ -1427,7 +1427,7 @@ int GPU_scene_object_lights(Scene *scene, Object *ob, int lay, float viewmat[][4
glLightf(GL_LIGHT0+count, GL_LINEAR_ATTENUATION, la->att1/la->dist);
glLightf(GL_LIGHT0+count, GL_QUADRATIC_ATTENUATION, la->att2/(la->dist*la->dist));
- if(la->type==LA_SPOT) {
+ if (la->type==LA_SPOT) {
/* spot lamp */
negate_v3_v3(direction, base->object->obmat[2]);
glLightfv(GL_LIGHT0+count, GL_SPOT_DIRECTION, direction);
@@ -1449,7 +1449,7 @@ int GPU_scene_object_lights(Scene *scene, Object *ob, int lay, float viewmat[][4
glPopMatrix();
count++;
- if(count==8)
+ if (count==8)
break;
}
@@ -1511,9 +1511,9 @@ void GPU_state_init(void)
glDepthRange(0.0, 1.0);
a= 0;
- for(x=0; x<32; x++) {
- for(y=0; y<4; y++) {
- if( (x) & 1) pat[a++]= 0x88;
+ for (x=0; x<32; x++) {
+ for (y=0; y<4; y++) {
+ if ( (x) & 1) pat[a++]= 0x88;
else pat[a++]= 0x22;
}
}
@@ -1543,7 +1543,7 @@ static void gpu_get_print(const char *name, GLenum type)
glGetFloatv(type, value);
printf("%s: ", name);
- for(a=0; a<16; a++)
+ for (a=0; a<16; a++)
printf("%.2f ", value[a]);
printf("\n");
}
diff --git a/source/blender/gpu/intern/gpu_extensions.c b/source/blender/gpu/intern/gpu_extensions.c
index e1d6f64f661..846ee2850be 100644
--- a/source/blender/gpu/intern/gpu_extensions.c
+++ b/source/blender/gpu/intern/gpu_extensions.c
@@ -99,7 +99,7 @@ void GPU_extensions_init(void)
const char *vendor, *renderer;
/* can't avoid calling this multiple times, see wm_window_add_ghostwindow */
- if(gpu_extensions_init) return;
+ if (gpu_extensions_init) return;
gpu_extensions_init= 1;
glewInit();
@@ -123,38 +123,38 @@ void GPU_extensions_init(void)
vendor = (const char*)glGetString(GL_VENDOR);
renderer = (const char*)glGetString(GL_RENDERER);
- if(strstr(vendor, "ATI")) {
+ if (strstr(vendor, "ATI")) {
GG.device = GPU_DEVICE_ATI;
GG.driver = GPU_DRIVER_OFFICIAL;
}
- else if(strstr(vendor, "NVIDIA")) {
+ else if (strstr(vendor, "NVIDIA")) {
GG.device = GPU_DEVICE_NVIDIA;
GG.driver = GPU_DRIVER_OFFICIAL;
}
- else if(strstr(vendor, "Intel") ||
+ else if (strstr(vendor, "Intel") ||
/* src/mesa/drivers/dri/intel/intel_context.c */
strstr(renderer, "Mesa DRI Intel") ||
strstr(renderer, "Mesa DRI Mobile Intel")) {
GG.device = GPU_DEVICE_INTEL;
GG.driver = GPU_DRIVER_OFFICIAL;
}
- else if(strstr(renderer, "Mesa DRI R") || (strstr(renderer, "Gallium ") && strstr(renderer, " on ATI "))) {
+ else if (strstr(renderer, "Mesa DRI R") || (strstr(renderer, "Gallium ") && strstr(renderer, " on ATI "))) {
GG.device = GPU_DEVICE_ATI;
GG.driver = GPU_DRIVER_OPENSOURCE;
}
- else if(strstr(renderer, "Nouveau") || strstr(vendor, "nouveau")) {
+ else if (strstr(renderer, "Nouveau") || strstr(vendor, "nouveau")) {
GG.device = GPU_DEVICE_NVIDIA;
GG.driver = GPU_DRIVER_OPENSOURCE;
}
- else if(strstr(vendor, "Mesa")) {
+ else if (strstr(vendor, "Mesa")) {
GG.device = GPU_DEVICE_SOFTWARE;
GG.driver = GPU_DRIVER_SOFTWARE;
}
- else if(strstr(vendor, "Microsoft")) {
+ else if (strstr(vendor, "Microsoft")) {
GG.device = GPU_DEVICE_SOFTWARE;
GG.driver = GPU_DRIVER_SOFTWARE;
}
- else if(strstr(renderer, "Apple Software Renderer")) {
+ else if (strstr(renderer, "Apple Software Renderer")) {
GG.device = GPU_DEVICE_SOFTWARE;
GG.driver = GPU_DRIVER_SOFTWARE;
}
@@ -163,12 +163,12 @@ void GPU_extensions_init(void)
GG.driver = GPU_DRIVER_ANY;
}
- if(GG.device == GPU_DEVICE_ATI) {
+ if (GG.device == GPU_DEVICE_ATI) {
/* ATI 9500 to X2300 cards support NPoT textures poorly
* Incomplete list http://dri.freedesktop.org/wiki/ATIRadeon
* New IDs from MESA's src/gallium/drivers/r300/r300_screen.c
*/
- if(strstr(renderer, "R3") || strstr(renderer, "RV3") ||
+ if (strstr(renderer, "R3") || strstr(renderer, "RV3") ||
strstr(renderer, "R4") || strstr(renderer, "RV4") ||
strstr(renderer, "RS4") || strstr(renderer, "RC4") ||
strstr(renderer, "R5") || strstr(renderer, "RV5") ||
@@ -205,7 +205,7 @@ int GPU_glsl_support(void)
int GPU_non_power_of_two_support(void)
{
- if(GG.npotdisabled)
+ if (GG.npotdisabled)
return 0;
return GLEW_ARB_texture_non_power_of_two;
@@ -260,7 +260,7 @@ static void GPU_print_framebuffer_error(GLenum status, char err_out[256])
break;
}
- if(err_out) {
+ if (err_out) {
BLI_snprintf(err_out, 256, "GPUFrameBuffer: framebuffer incomplete error %d '%s'",
(int)status, err);
}
@@ -318,7 +318,7 @@ static GPUTexture *GPU_texture_create_nD(int w, int h, int n, float *fpixels, in
GLenum type, format, internalformat;
void *pixels = NULL;
- if(depth && !GLEW_ARB_depth_texture)
+ if (depth && !GLEW_ARB_depth_texture)
return NULL;
tex = MEM_callocN(sizeof(GPUTexture), "GPUTexture");
@@ -332,7 +332,7 @@ static GPUTexture *GPU_texture_create_nD(int w, int h, int n, float *fpixels, in
glGenTextures(1, &tex->bindcode);
if (!tex->bindcode) {
- if(err_out) {
+ if (err_out) {
BLI_snprintf(err_out, 256, "GPUTexture: texture create failed: %d",
(int)glGetError());
}
@@ -352,7 +352,7 @@ static GPUTexture *GPU_texture_create_nD(int w, int h, int n, float *fpixels, in
tex->number = 0;
glBindTexture(tex->target, tex->bindcode);
- if(depth) {
+ if (depth) {
type = GL_UNSIGNED_BYTE;
format = GL_DEPTH_COMPONENT;
internalformat = GL_DEPTH_COMPONENT;
@@ -396,7 +396,7 @@ static GPUTexture *GPU_texture_create_nD(int w, int h, int n, float *fpixels, in
if (pixels)
MEM_freeN(pixels);
- if(depth) {
+ if (depth) {
glTexParameteri(tex->target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(tex->target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(tex->target, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE);
@@ -433,7 +433,7 @@ GPUTexture *GPU_texture_create_3D(int w, int h, int depth, float *fpixels)
void *pixels = NULL;
float vfBorderColor[4] = {0.0f, 0.0f, 0.0f, 0.0f};
- if(!GLEW_VERSION_1_2)
+ if (!GLEW_VERSION_1_2)
return NULL;
tex = MEM_callocN(sizeof(GPUTexture), "GPUTexture");
@@ -476,7 +476,7 @@ GPUTexture *GPU_texture_create_3D(int w, int h, int depth, float *fpixels)
GPU_print_error("3D glTexImage3D");
if (fpixels) {
- if(!GPU_non_power_of_two_support() && (w != tex->w || h != tex->h || depth != tex->depth)) {
+ if (!GPU_non_power_of_two_support() && (w != tex->w || h != tex->h || depth != tex->depth)) {
/* clear first to avoid unitialized pixels */
float *zero= MEM_callocN(sizeof(float)*tex->w*tex->h*tex->depth, "zero");
glTexSubImage3D(tex->target, 0, 0, 0, 0, tex->w, tex->h, tex->depth, format, type, zero);
@@ -516,13 +516,13 @@ GPUTexture *GPU_texture_from_blender(Image *ima, ImageUser *iuser, double time,
GPU_update_image_time(ima, time);
bindcode = GPU_verify_image(ima, iuser, 0, 0, mipmap);
- if(ima->gputexture) {
+ if (ima->gputexture) {
ima->gputexture->bindcode = bindcode;
glBindTexture(GL_TEXTURE_2D, lastbindcode);
return ima->gputexture;
}
- if(!bindcode) {
+ if (!bindcode) {
glBindTexture(GL_TEXTURE_2D, lastbindcode);
return NULL;
}
@@ -593,7 +593,7 @@ void GPU_texture_bind(GPUTexture *tex, int number)
return;
}
- if(number == -1)
+ if (number == -1)
return;
GPU_print_error("Pre Texture Bind");
@@ -618,7 +618,7 @@ void GPU_texture_unbind(GPUTexture *tex)
return;
}
- if(tex->number == -1)
+ if (tex->number == -1)
return;
GPU_print_error("Pre Texture Unbind");
@@ -714,7 +714,7 @@ int GPU_framebuffer_texture_attach(GPUFrameBuffer *fb, GPUTexture *tex, char err
GLenum status;
GLenum attachment;
- if(tex->depth)
+ if (tex->depth)
attachment = GL_DEPTH_ATTACHMENT_EXT;
else
attachment = GL_COLOR_ATTACHMENT0_EXT;
@@ -725,7 +725,7 @@ int GPU_framebuffer_texture_attach(GPUFrameBuffer *fb, GPUTexture *tex, char err
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, attachment,
tex->target, tex->bindcode, 0);
- if(tex->depth) {
+ if (tex->depth) {
glDrawBuffer(GL_NONE);
glReadBuffer(GL_NONE);
}
@@ -742,7 +742,7 @@ int GPU_framebuffer_texture_attach(GPUFrameBuffer *fb, GPUTexture *tex, char err
return 0;
}
- if(tex->depth)
+ if (tex->depth)
fb->depthtex = tex;
else
fb->colortex = tex;
@@ -756,15 +756,15 @@ void GPU_framebuffer_texture_detach(GPUFrameBuffer *fb, GPUTexture *tex)
{
GLenum attachment;
- if(!tex->fb)
+ if (!tex->fb)
return;
- if(GG.currentfb != tex->fb->object) {
+ if (GG.currentfb != tex->fb->object) {
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, tex->fb->object);
GG.currentfb = tex->fb->object;
}
- if(tex->depth) {
+ if (tex->depth) {
fb->depthtex = NULL;
attachment = GL_DEPTH_ATTACHMENT_EXT;
}
@@ -817,12 +817,12 @@ void GPU_framebuffer_texture_unbind(GPUFrameBuffer *UNUSED(fb), GPUTexture *UNUS
void GPU_framebuffer_free(GPUFrameBuffer *fb)
{
- if(fb->depthtex)
+ if (fb->depthtex)
GPU_framebuffer_texture_detach(fb, fb->depthtex);
- if(fb->colortex)
+ if (fb->colortex)
GPU_framebuffer_texture_detach(fb, fb->colortex);
- if(fb->object) {
+ if (fb->object) {
glDeleteFramebuffersEXT(1, &fb->object);
if (GG.currentfb == fb->object) {
@@ -863,29 +863,29 @@ GPUOffScreen *GPU_offscreen_create(int width, int height, char err_out[256])
ofs->h= height;
ofs->fb = GPU_framebuffer_create();
- if(!ofs->fb) {
+ if (!ofs->fb) {
GPU_offscreen_free(ofs);
return NULL;
}
ofs->depth = GPU_texture_create_depth(width, height, err_out);
- if(!ofs->depth) {
+ if (!ofs->depth) {
GPU_offscreen_free(ofs);
return NULL;
}
- if(!GPU_framebuffer_texture_attach(ofs->fb, ofs->depth, err_out)) {
+ if (!GPU_framebuffer_texture_attach(ofs->fb, ofs->depth, err_out)) {
GPU_offscreen_free(ofs);
return NULL;
}
ofs->color = GPU_texture_create_2D(width, height, NULL, err_out);
- if(!ofs->color) {
+ if (!ofs->color) {
GPU_offscreen_free(ofs);
return NULL;
}
- if(!GPU_framebuffer_texture_attach(ofs->fb, ofs->color, err_out)) {
+ if (!GPU_framebuffer_texture_attach(ofs->fb, ofs->color, err_out)) {
GPU_offscreen_free(ofs);
return NULL;
}
@@ -897,11 +897,11 @@ GPUOffScreen *GPU_offscreen_create(int width, int height, char err_out[256])
void GPU_offscreen_free(GPUOffScreen *ofs)
{
- if(ofs->fb)
+ if (ofs->fb)
GPU_framebuffer_free(ofs->fb);
- if(ofs->color)
+ if (ofs->color)
GPU_texture_free(ofs->color);
- if(ofs->depth)
+ if (ofs->depth)
GPU_texture_free(ofs->depth);
MEM_freeN(ofs);
@@ -942,7 +942,7 @@ static void shader_print_errors(const char *task, char *log, const char *code)
fprintf(stderr, "GPUShader: %s error:\n", task);
- if(G.f & G_DEBUG) {
+ if (G.f & G_DEBUG) {
c = code;
while ((c < end) && (pos = strchr(c, '\n'))) {
fprintf(stderr, "%2d ", line);
@@ -971,9 +971,9 @@ GPUShader *GPU_shader_create(const char *vertexcode, const char *fragcode, /*GPU
shader = MEM_callocN(sizeof(GPUShader), "GPUShader");
- if(vertexcode)
+ if (vertexcode)
shader->vertex = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB);
- if(fragcode)
+ if (fragcode)
shader->fragment = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);
shader->object = glCreateProgramObjectARB();
@@ -985,7 +985,7 @@ GPUShader *GPU_shader_create(const char *vertexcode, const char *fragcode, /*GPU
return NULL;
}
- if(vertexcode) {
+ if (vertexcode) {
glAttachObjectARB(shader->object, shader->vertex);
glShaderSourceARB(shader->vertex, 1, (const char**)&vertexcode, NULL);
@@ -1001,10 +1001,10 @@ GPUShader *GPU_shader_create(const char *vertexcode, const char *fragcode, /*GPU
}
}
- if(fragcode) {
+ if (fragcode) {
count = 0;
- if(libcode) fragsource[count++] = libcode;
- if(fragcode) fragsource[count++] = fragcode;
+ if (libcode) fragsource[count++] = libcode;
+ if (fragcode) fragsource[count++] = fragcode;
glAttachObjectARB(shader->object, shader->fragment);
glShaderSourceARB(shader->fragment, count, fragsource, NULL);
@@ -1022,7 +1022,7 @@ GPUShader *GPU_shader_create(const char *vertexcode, const char *fragcode, /*GPU
}
#if 0
- if(lib && lib->lib)
+ if (lib && lib->lib)
glAttachObjectARB(shader->object, lib->lib);
#endif
@@ -1113,7 +1113,7 @@ int GPU_shader_get_uniform(GPUShader *shader, const char *name)
void GPU_shader_uniform_vector(GPUShader *UNUSED(shader), int location, int length, int arraysize, float *value)
{
- if(location == -1)
+ if (location == -1)
return;
GPU_print_error("Pre Uniform Vector");
@@ -1137,10 +1137,10 @@ void GPU_shader_uniform_texture(GPUShader *UNUSED(shader), int location, GPUText
return;
}
- if(tex->number == -1)
+ if (tex->number == -1)
return;
- if(location == -1)
+ if (location == -1)
return;
GPU_print_error("Pre Uniform Texture");
diff --git a/source/blender/gpu/intern/gpu_material.c b/source/blender/gpu/intern/gpu_material.c
index 89b3a7d5f3f..efb931bf8e5 100644
--- a/source/blender/gpu/intern/gpu_material.c
+++ b/source/blender/gpu/intern/gpu_material.c
@@ -157,13 +157,13 @@ static void gpu_material_set_attrib_id(GPUMaterial *material)
attribs= &material->attribs;
pass= material->pass;
- if(!pass) {
+ if (!pass) {
attribs->totlayer = 0;
return;
}
shader= GPU_pass_shader(pass);
- if(!shader) {
+ if (!shader) {
attribs->totlayer = 0;
return;
}
@@ -172,11 +172,11 @@ 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);
- if(attribs->layer[a].glindex >= 0) {
+ if (attribs->layer[a].glindex >= 0) {
attribs->layer[b] = attribs->layer[a];
b++;
}
@@ -195,24 +195,24 @@ static int GPU_material_construct_end(GPUMaterial *material)
material->pass = GPU_generate_pass(&material->nodes, outlink,
&material->attribs, &material->builtins, material->ma->id.name);
- if(!material->pass)
+ if (!material->pass)
return 0;
gpu_material_set_attrib_id(material);
shader = GPU_pass_shader(material->pass);
- if(material->builtins & GPU_VIEW_MATRIX)
+ if (material->builtins & GPU_VIEW_MATRIX)
material->viewmatloc = GPU_shader_get_uniform(shader, GPU_builtin_name(GPU_VIEW_MATRIX));
- if(material->builtins & GPU_INVERSE_VIEW_MATRIX)
+ if (material->builtins & GPU_INVERSE_VIEW_MATRIX)
material->invviewmatloc = GPU_shader_get_uniform(shader, GPU_builtin_name(GPU_INVERSE_VIEW_MATRIX));
- if(material->builtins & GPU_OBJECT_MATRIX)
+ if (material->builtins & GPU_OBJECT_MATRIX)
material->obmatloc = GPU_shader_get_uniform(shader, GPU_builtin_name(GPU_OBJECT_MATRIX));
- if(material->builtins & GPU_INVERSE_OBJECT_MATRIX)
+ if (material->builtins & GPU_INVERSE_OBJECT_MATRIX)
material->invobmatloc = GPU_shader_get_uniform(shader, GPU_builtin_name(GPU_INVERSE_OBJECT_MATRIX));
- if(material->builtins & GPU_OBCOLOR)
+ if (material->builtins & GPU_OBCOLOR)
material->obcolloc = GPU_shader_get_uniform(shader, GPU_builtin_name(GPU_OBCOLOR));
- if(material->builtins & GPU_AUTO_BUMPSCALE)
+ if (material->builtins & GPU_AUTO_BUMPSCALE)
material->obautobumpscaleloc = GPU_shader_get_uniform(shader, GPU_builtin_name(GPU_AUTO_BUMPSCALE));
return 1;
}
@@ -225,18 +225,18 @@ void GPU_material_free(Material *ma)
LinkData *link;
LinkData *nlink, *mlink, *next;
- for(link=ma->gpumaterial.first; link; link=link->next) {
+ for (link=ma->gpumaterial.first; link; link=link->next) {
GPUMaterial *material = link->data;
- if(material->pass)
+ 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;
- for(mlink=lamp->materials.first; mlink; mlink=next) {
+ for (mlink=lamp->materials.first; mlink; mlink=next) {
next = mlink->next;
- if(mlink->data == ma)
+ if (mlink->data == ma)
BLI_freelinkN(&lamp->materials, mlink);
}
}
@@ -251,15 +251,15 @@ void GPU_material_free(Material *ma)
void GPU_material_bind(GPUMaterial *material, int oblay, int viewlay, double time, int mipmap)
{
- if(material->pass) {
+ if (material->pass) {
LinkData *nlink;
GPULamp *lamp;
/* handle layer lamps */
- for(nlink=material->lamps.first; nlink; nlink=nlink->next) {
+ 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))) {
+ if (!lamp->hide && (lamp->lay & viewlay) && (!(lamp->mode & LA_LAYER) || (lamp->lay & oblay))) {
lamp->dynenergy = lamp->energy;
copy_v3_v3(lamp->dyncol, lamp->col);
}
@@ -276,53 +276,53 @@ void GPU_material_bind(GPUMaterial *material, int oblay, int viewlay, double tim
void GPU_material_bind_uniforms(GPUMaterial *material, float obmat[][4], float viewmat[][4], float viewinv[][4], float obcol[4], float autobumpscale)
{
- if(material->pass) {
+ if (material->pass) {
GPUShader *shader = GPU_pass_shader(material->pass);
LinkData *nlink;
GPULamp *lamp;
float invmat[4][4], col[4];
/* handle builtins */
- if(material->builtins & GPU_VIEW_MATRIX) {
+ if (material->builtins & GPU_VIEW_MATRIX) {
GPU_shader_uniform_vector(shader, material->viewmatloc, 16, 1, (float*)viewmat);
}
- if(material->builtins & GPU_INVERSE_VIEW_MATRIX) {
+ if (material->builtins & GPU_INVERSE_VIEW_MATRIX) {
GPU_shader_uniform_vector(shader, material->invviewmatloc, 16, 1, (float*)viewinv);
}
- if(material->builtins & GPU_OBJECT_MATRIX) {
+ if (material->builtins & GPU_OBJECT_MATRIX) {
GPU_shader_uniform_vector(shader, material->obmatloc, 16, 1, (float*)obmat);
}
- if(material->builtins & GPU_INVERSE_OBJECT_MATRIX) {
+ if (material->builtins & GPU_INVERSE_OBJECT_MATRIX) {
invert_m4_m4(invmat, obmat);
GPU_shader_uniform_vector(shader, material->invobmatloc, 16, 1, (float*)invmat);
}
- if(material->builtins & GPU_OBCOLOR) {
+ if (material->builtins & GPU_OBCOLOR) {
copy_v4_v4(col, obcol);
CLAMP(col[3], 0.0f, 1.0f);
GPU_shader_uniform_vector(shader, material->obcolloc, 4, 1, col);
}
- if(material->builtins & GPU_AUTO_BUMPSCALE) {
+ if (material->builtins & GPU_AUTO_BUMPSCALE) {
GPU_shader_uniform_vector(shader, material->obautobumpscaleloc, 1, 1, &autobumpscale);
}
/* update lamps */
- for(nlink=material->lamps.first; nlink; nlink=nlink->next) {
+ for (nlink=material->lamps.first; nlink; nlink=nlink->next) {
lamp= nlink->data;
- if(material->dynproperty & DYN_LAMP_VEC) {
+ if (material->dynproperty & DYN_LAMP_VEC) {
copy_v3_v3(lamp->dynvec, lamp->vec);
normalize_v3(lamp->dynvec);
negate_v3(lamp->dynvec);
mul_mat3_m4_v3(viewmat, lamp->dynvec);
}
- if(material->dynproperty & DYN_LAMP_CO) {
+ if (material->dynproperty & DYN_LAMP_CO) {
copy_v3_v3(lamp->dynco, lamp->co);
mul_m4_v3(viewmat, lamp->dynco);
}
- if(material->dynproperty & DYN_LAMP_IMAT)
+ if (material->dynproperty & DYN_LAMP_IMAT)
mult_m4_m4m4(lamp->dynimat, lamp->imat, viewinv);
- if(material->dynproperty & DYN_LAMP_PERSMAT)
+ if (material->dynproperty & DYN_LAMP_PERSMAT)
mult_m4_m4m4(lamp->dynpersmat, lamp->persmat, viewinv);
}
@@ -350,7 +350,7 @@ void GPU_material_vertex_attributes(GPUMaterial *material, GPUVertexAttribs *att
void GPU_material_output_link(GPUMaterial *material, GPUNodeLink *link)
{
- if(!material->outlink)
+ if (!material->outlink)
material->outlink= link;
}
@@ -361,7 +361,7 @@ void GPU_material_enable_alpha(GPUMaterial *material)
GPUBlendMode GPU_material_alpha_blend(GPUMaterial *material, float obcol[4])
{
- if(material->alpha || (material->obcolalpha && obcol[3] < 1.0f))
+ if (material->alpha || (material->obcolalpha && obcol[3] < 1.0f))
return GPU_BLEND_ALPHA;
else
return GPU_BLEND_SOLID;
@@ -385,7 +385,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;
@@ -394,7 +394,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)
@@ -421,11 +421,11 @@ static GPUNodeLink *lamp_get_visibility(GPUMaterial *mat, GPULamp *lamp, GPUNode
break;
}
- if(lamp->mode & LA_SPHERE)
+ if (lamp->mode & LA_SPHERE)
GPU_link(mat, "lamp_visibility_sphere", GPU_uniform(&lamp->dist), *dist, visifac, &visifac);
- if(lamp->type == LA_SPOT) {
- if(lamp->mode & LA_SQUARE) {
+ if (lamp->type == LA_SPOT) {
+ if (lamp->mode & LA_SQUARE) {
mat->dynproperty |= DYN_LAMP_VEC|DYN_LAMP_IMAT;
GPU_link(mat, "lamp_visibility_spot_square", GPU_dynamic_uniform(lamp->dynvec, GPU_DYNAMIC_LAMP_DYNVEC, lamp->ob), GPU_dynamic_uniform((float*)lamp->dynimat, GPU_DYNAMIC_LAMP_DYNIMAT, lamp->ob), *lv, &inpr);
}
@@ -511,9 +511,9 @@ static void ramp_diffuse_result(GPUShadeInput *shi, GPUNodeLink **diff)
GPUMaterial *mat= shi->gpumat;
GPUNodeLink *fac;
- if(!(mat->scene->gm.flag & GAME_GLSL_NO_RAMPS)) {
- if(ma->ramp_col) {
- if(ma->rampin_col==MA_RAMP_IN_RESULT) {
+ if (!(mat->scene->gm.flag & GAME_GLSL_NO_RAMPS)) {
+ if (ma->ramp_col) {
+ if (ma->rampin_col==MA_RAMP_IN_RESULT) {
GPU_link(mat, "ramp_rgbtobw", *diff, &fac);
/* colorband + blend */
@@ -527,10 +527,10 @@ static void add_to_diffuse(GPUMaterial *mat, Material *ma, GPUShadeInput *shi, G
{
GPUNodeLink *fac, *tmp, *addcol;
- if(!(mat->scene->gm.flag & GAME_GLSL_NO_RAMPS) &&
+ if (!(mat->scene->gm.flag & GAME_GLSL_NO_RAMPS) &&
ma->ramp_col && (ma->mode & MA_RAMP_COL)) {
/* MA_RAMP_IN_RESULT is exceptional */
- if(ma->rampin_col==MA_RAMP_IN_RESULT) {
+ if (ma->rampin_col==MA_RAMP_IN_RESULT) {
addcol = shi->rgb;
}
else {
@@ -567,7 +567,7 @@ static void ramp_spec_result(GPUShadeInput *shi, GPUNodeLink **spec)
GPUMaterial *mat= shi->gpumat;
GPUNodeLink *fac;
- if(!(mat->scene->gm.flag & GAME_GLSL_NO_RAMPS) &&
+ if (!(mat->scene->gm.flag & GAME_GLSL_NO_RAMPS) &&
ma->ramp_spec && ma->rampin_spec==MA_RAMP_IN_RESULT) {
GPU_link(mat, "ramp_rgbtobw", *spec, &fac);
@@ -585,7 +585,7 @@ static void do_specular_ramp(GPUShadeInput *shi, GPUNodeLink *is, GPUNodeLink *t
*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) {
@@ -623,7 +623,7 @@ static void shade_one_light(GPUShadeInput *shi, GPUShadeResult *shr, GPULamp *la
GPUNodeLink *outcol, *specfac, *t, *shadfac= NULL;
float one = 1.0f;
- if((lamp->mode & LA_ONLYSHADOW) && !(ma->mode & MA_SHADOW))
+ if ((lamp->mode & LA_ONLYSHADOW) && !(ma->mode & MA_SHADOW))
return;
vn= shi->vn;
@@ -636,14 +636,14 @@ static void shade_one_light(GPUShadeInput *shi, GPUShadeResult *shr, GPULamp *la
GPU_link(mat, "shade_inp", vn, lv, &inp);
- if(lamp->mode & LA_NO_DIFF) {
+ if (lamp->mode & LA_NO_DIFF) {
GPU_link(mat, "shade_is_no_diffuse", &is);
}
- else if(lamp->type == LA_HEMI) {
+ else if (lamp->type == LA_HEMI) {
GPU_link(mat, "shade_is_hemi", inp, &is);
}
else {
- if(lamp->type == LA_AREA) {
+ if (lamp->type == LA_AREA) {
float area[4][4]= {{0.0f}}, areasize= 0.0f;
mat->dynproperty |= DYN_LAMP_VEC|DYN_LAMP_CO;
@@ -653,35 +653,35 @@ static void shade_one_light(GPUShadeInput *shi, GPUShadeResult *shr, GPULamp *la
is= inp; /* Lambert */
- if(!(mat->scene->gm.flag & GAME_GLSL_NO_SHADERS)) {
- if(ma->diff_shader==MA_DIFF_ORENNAYAR)
+ if (!(mat->scene->gm.flag & GAME_GLSL_NO_SHADERS)) {
+ 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);
}
}
- if(!(mat->scene->gm.flag & GAME_GLSL_NO_SHADERS))
- if(ma->shade_flag & MA_CUBIC)
+ if (!(mat->scene->gm.flag & GAME_GLSL_NO_SHADERS))
+ if (ma->shade_flag & MA_CUBIC)
GPU_link(mat, "shade_cubic", is, &is);
i = is;
GPU_link(mat, "shade_visifac", i, visifac, shi->refl, &i);
#if 0
- if(ma->mode & MA_TANGENT_VN)
+ if (ma->mode & MA_TANGENT_VN)
GPU_link(mat, "shade_tangent_v_spec", GPU_attribute(CD_TANGENT, ""), &vn);
#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);
- if((ma->mode & MA_SHADOW) && GPU_lamp_has_shadow_buffer(lamp)) {
- if(!(mat->scene->gm.flag & GAME_GLSL_NO_SHADOWS)) {
+ if ((ma->mode & MA_SHADOW) && GPU_lamp_has_shadow_buffer(lamp)) {
+ if (!(mat->scene->gm.flag & GAME_GLSL_NO_SHADOWS)) {
mat->dynproperty |= DYN_LAMP_PERSMAT;
GPU_link(mat, "test_shadowbuf",
@@ -690,15 +690,15 @@ static void shade_one_light(GPUShadeInput *shi, GPUShadeResult *shr, GPULamp *la
GPU_dynamic_uniform((float*)lamp->dynpersmat, GPU_DYNAMIC_LAMP_DYNPERSMAT, lamp->ob),
GPU_uniform(&lamp->bias), inp, &shadfac);
- if(lamp->mode & LA_ONLYSHADOW) {
+ if (lamp->mode & LA_ONLYSHADOW) {
GPU_link(mat, "shade_only_shadow", i, shadfac,
GPU_dynamic_uniform(&lamp->dynenergy, GPU_DYNAMIC_LAMP_DYNENERGY, lamp->ob), &shadfac);
- if(!(lamp->mode & LA_NO_DIFF))
+ if (!(lamp->mode & LA_NO_DIFF))
GPU_link(mat, "shade_only_shadow_diffuse", shadfac, shi->rgb,
shr->diff, &shr->diff);
- if(!(lamp->mode & LA_NO_SPEC))
+ if (!(lamp->mode & LA_NO_SPEC))
GPU_link(mat, "shade_only_shadow_specular", shadfac, shi->specrgb,
shr->spec, &shr->spec);
@@ -710,7 +710,7 @@ static void shade_one_light(GPUShadeInput *shi, GPUShadeResult *shr, GPULamp *la
GPU_link(mat, "math_multiply", i, shadfac, &i);
}
}
- else if((mat->scene->gm.flag & GAME_GLSL_NO_SHADOWS) && (lamp->mode & LA_ONLYSHADOW)) {
+ else if ((mat->scene->gm.flag & GAME_GLSL_NO_SHADOWS) && (lamp->mode & LA_ONLYSHADOW)) {
add_user_list(&mat->lamps, lamp);
add_user_list(&lamp->materials, shi->gpumat->ma);
return;
@@ -718,40 +718,40 @@ static void shade_one_light(GPUShadeInput *shi, GPUShadeResult *shr, GPULamp *la
else
GPU_link(mat, "set_value", GPU_uniform(&one), &shadfac);
- if(GPU_link_changed(shi->refl) || ma->ref != 0.0f) {
- if(!(lamp->mode & LA_NO_DIFF)) {
+ if (GPU_link_changed(shi->refl) || ma->ref != 0.0f) {
+ if (!(lamp->mode & LA_NO_DIFF)) {
GPUNodeLink *rgb;
GPU_link(mat, "shade_mul_value", i, GPU_dynamic_uniform(lamp->dyncol, GPU_DYNAMIC_LAMP_DYNCOL, lamp->ob), &rgb);
add_to_diffuse(mat, ma, shi, is, rgb, &shr->diff);
}
}
- if(mat->scene->gm.flag & GAME_GLSL_NO_SHADERS);
- else if(!(lamp->mode & LA_NO_SPEC) && !(lamp->mode & LA_ONLYSHADOW) &&
+ if (mat->scene->gm.flag & GAME_GLSL_NO_SHADERS);
+ else if (!(lamp->mode & LA_NO_SPEC) && !(lamp->mode & LA_ONLYSHADOW) &&
(GPU_link_changed(shi->spec) || ma->spec != 0.0f)) {
- if(lamp->type == LA_HEMI) {
+ if (lamp->type == LA_HEMI) {
GPU_link(mat, "shade_hemi_spec", vn, lv, view, GPU_uniform(&ma->spec), shi->har, visifac, &t);
GPU_link(mat, "shade_add_spec", t, GPU_dynamic_uniform(lamp->dyncol, GPU_DYNAMIC_LAMP_DYNCOL, lamp->ob), shi->specrgb, &outcol);
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);
- if(ma->mode & MA_RAMP_SPEC) {
+ if (ma->mode & MA_RAMP_SPEC) {
GPUNodeLink *spec;
do_specular_ramp(shi, specfac, t, &spec);
GPU_link(mat, "shade_add_spec", t, GPU_dynamic_uniform(lamp->dyncol, GPU_DYNAMIC_LAMP_DYNCOL, lamp->ob), spec, &outcol);
@@ -775,12 +775,12 @@ static void material_lights(GPUShadeInput *shi, GPUShadeResult *shr)
Scene *sce_iter;
GPULamp *lamp;
- for(SETLOOPER(shi->gpumat->scene, sce_iter, base)) {
+ for (SETLOOPER(shi->gpumat->scene, sce_iter, base)) {
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)
+ if (lamp)
shade_one_light(shi, shr, lamp);
}
@@ -788,14 +788,14 @@ static void material_lights(GPUShadeInput *shi, GPUShadeResult *shr)
DupliObject *dob;
ListBase *lb = object_duplilist(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) {
copy_m4_m4(ob_iter->obmat, dob->mat);
lamp = GPU_lamp_from_blender(shi->gpumat->scene, ob_iter, ob);
- if(lamp)
+ if (lamp)
shade_one_light(shi, shr, lamp);
}
}
@@ -924,33 +924,33 @@ static void do_material_tex(GPUShadeInput *shi)
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]) {
+ if (ma->mtex[tex_nr]) {
mtex= ma->mtex[tex_nr];
tex= mtex->tex;
- if(tex == NULL) continue;
+ if (tex == NULL) continue;
/* which coords */
- if(mtex->texco==TEXCO_ORCO)
+ if (mtex->texco==TEXCO_ORCO)
texco= texco_orco;
- else if(mtex->texco==TEXCO_OBJECT)
+ else if (mtex->texco==TEXCO_OBJECT)
texco= texco_object;
- else if(mtex->texco==TEXCO_NORM)
+ else if (mtex->texco==TEXCO_NORM)
texco= orn;
- else if(mtex->texco==TEXCO_TANGENT)
+ else if (mtex->texco==TEXCO_TANGENT)
texco= texco_object;
- else if(mtex->texco==TEXCO_GLOB)
+ else if (mtex->texco==TEXCO_GLOB)
texco= texco_global;
- else if(mtex->texco==TEXCO_REFL) {
+ else if (mtex->texco==TEXCO_REFL) {
GPU_link(mat, "texco_refl", shi->vn, shi->view, &shi->ref);
texco= shi->ref;
}
- else if(mtex->texco==TEXCO_UV) {
- if(1) { //!(texco_uv && strcmp(mtex->uvname, lastuvname) == 0)) {
+ 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*/
}
@@ -960,98 +960,98 @@ static void do_material_tex(GPUShadeInput *shi)
continue;
/* in case of uv, this would just undo a multiplication in texco_uv */
- if(mtex->texco != TEXCO_UV)
+ if (mtex->texco != TEXCO_UV)
GPU_link(mat, "mtex_2d_mapping", texco, &texco);
- if(mtex->size[0] != 1.0f || mtex->size[1] != 1.0f || mtex->size[2] != 1.0f)
+ if (mtex->size[0] != 1.0f || mtex->size[1] != 1.0f || mtex->size[2] != 1.0f)
GPU_link(mat, "mtex_mapping_size", texco, GPU_uniform(mtex->size), &texco);
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)
+ if (ofs[0] != 0.0f || ofs[1] != 0.0f || ofs[2] != 0.0f)
GPU_link(mat, "mtex_mapping_ofs", texco, GPU_uniform(ofs), &texco);
talpha = 0;
- if(tex && tex->type == TEX_IMAGE && tex->ima) {
+ if (tex && tex->type == TEX_IMAGE && tex->ima) {
GPU_link(mat, "mtex_image", texco, GPU_image(tex->ima, &tex->iuser), &tin, &trgb);
rgbnor= TEX_RGB;
- if(tex->imaflag & TEX_USEALPHA)
+ if (tex->imaflag & TEX_USEALPHA)
talpha= 1;
}
else continue;
/* texture output */
- if((rgbnor & TEX_RGB) && (mtex->texflag & MTEX_RGBTOINT)) {
+ if ((rgbnor & TEX_RGB) && (mtex->texflag & MTEX_RGBTOINT)) {
GPU_link(mat, "mtex_rgbtoint", trgb, &tin);
rgbnor -= TEX_RGB;
}
- if(mtex->texflag & MTEX_NEGATIVE) {
- if(rgbnor & TEX_RGB)
+ if (mtex->texflag & MTEX_NEGATIVE) {
+ if (rgbnor & TEX_RGB)
GPU_link(mat, "mtex_rgb_invert", trgb, &trgb);
else
GPU_link(mat, "mtex_value_invert", tin, &tin);
}
- if(mtex->texflag & MTEX_STENCIL) {
- if(rgbnor & TEX_RGB)
+ if (mtex->texflag & MTEX_STENCIL) {
+ if (rgbnor & TEX_RGB)
GPU_link(mat, "mtex_rgb_stencil", stencil, trgb, &stencil, &trgb);
else
GPU_link(mat, "mtex_value_stencil", stencil, tin, &stencil, &tin);
}
/* mapping */
- if(mtex->mapto & (MAP_COL+MAP_COLSPEC)) {
+ if (mtex->mapto & (MAP_COL+MAP_COLSPEC)) {
/* stencil maps on the texture control slider, not texture intensity value */
- if((rgbnor & TEX_RGB)==0) {
+ if ((rgbnor & TEX_RGB)==0) {
GPU_link(mat, "set_rgb", GPU_uniform(&mtex->r), &tcol);
}
else {
GPU_link(mat, "set_rgba", trgb, &tcol);
- if(mtex->mapto & MAP_ALPHA)
+ if (mtex->mapto & MAP_ALPHA)
GPU_link(mat, "set_value", stencil, &tin);
- else if(talpha)
+ else if (talpha)
GPU_link(mat, "mtex_alpha_from_col", trgb, &tin);
else
GPU_link(mat, "set_value_one", &tin);
}
- if(tex->type==TEX_IMAGE)
- if(gpu_do_color_management(mat))
+ if (tex->type==TEX_IMAGE)
+ if (gpu_do_color_management(mat))
GPU_link(mat, "srgb_to_linearrgb", tcol, &tcol);
- if(mtex->mapto & MAP_COL) {
+ if (mtex->mapto & MAP_COL) {
GPUNodeLink *colfac;
- if(mtex->colfac == 1.0f) colfac = stencil;
+ if (mtex->colfac == 1.0f) colfac = stencil;
else GPU_link(mat, "math_multiply", GPU_uniform(&mtex->colfac), stencil, &colfac);
texture_rgb_blend(mat, tcol, shi->rgb, tin, colfac, mtex->blendtype, &shi->rgb);
}
- if(!(mat->scene->gm.flag & GAME_GLSL_NO_EXTRA_TEX) && (mtex->mapto & MAP_COLSPEC)) {
+ if (!(mat->scene->gm.flag & GAME_GLSL_NO_EXTRA_TEX) && (mtex->mapto & MAP_COLSPEC)) {
GPUNodeLink *colspecfac;
- if(mtex->colspecfac == 1.0f) colspecfac = stencil;
+ if (mtex->colspecfac == 1.0f) colspecfac = stencil;
else GPU_link(mat, "math_multiply", GPU_uniform(&mtex->colspecfac), stencil, &colspecfac);
texture_rgb_blend(mat, tcol, shi->specrgb, tin, colspecfac, mtex->blendtype, &shi->specrgb);
}
}
- if(!(mat->scene->gm.flag & GAME_GLSL_NO_EXTRA_TEX) && (mtex->mapto & MAP_NORM)) {
- if(tex->type==TEX_IMAGE) {
+ if (!(mat->scene->gm.flag & GAME_GLSL_NO_EXTRA_TEX) && (mtex->mapto & MAP_NORM)) {
+ if (tex->type==TEX_IMAGE) {
found_deriv_map = tex->imaflag & TEX_DERIVATIVEMAP;
- if(tex->imaflag & TEX_NORMALMAP) {
+ if (tex->imaflag & TEX_NORMALMAP) {
/* normalmap image */
GPU_link(mat, "mtex_normal", texco, GPU_image(tex->ima, &tex->iuser), &tnor );
- if(mtex->norfac < 0.0f)
+ if (mtex->norfac < 0.0f)
GPU_link(mat, "mtex_negate_texnormal", tnor, &tnor);
if (mtex->normapspace == MTEX_NSPACE_TANGENT) {
@@ -1072,20 +1072,20 @@ static void do_material_tex(GPUShadeInput *shi)
norfac = minf(fabsf(mtex->norfac), 1.0f);
- if(norfac == 1.0f && !GPU_link_changed(stencil)) {
+ if (norfac == 1.0f && !GPU_link_changed(stencil)) {
shi->vn = newnor;
}
else {
tnorfac = GPU_uniform(&norfac);
- if(GPU_link_changed(stencil))
+ if (GPU_link_changed(stencil))
GPU_link(mat, "math_multiply", tnorfac, stencil, &tnorfac);
GPU_link(mat, "mtex_blend_normal", tnorfac, shi->vn, newnor, &shi->vn);
}
}
- 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;
@@ -1099,16 +1099,16 @@ static void do_material_tex(GPUShadeInput *shi)
GPUNodeLink *dBs, *dBt, *fDet;
hScale = 0.1; // compatibility adjustment factor for all bumpspace types
- if( mtex->texflag & MTEX_BUMP_TEXTURESPACE )
+ if ( mtex->texflag & MTEX_BUMP_TEXTURESPACE )
hScale = 13.0f; // factor for scaling texspace bumps
- else if(found_deriv_map!=0)
+ else if (found_deriv_map!=0)
hScale = 1.0f;
// resolve texture resolution
- if( (mtex->texflag & MTEX_BUMP_TEXTURESPACE) || found_deriv_map ) {
+ if ( (mtex->texflag & MTEX_BUMP_TEXTURESPACE) || found_deriv_map ) {
ImBuf *ibuf= BKE_image_get_ibuf(tex->ima, &tex->iuser);
ima_x= 512.0f; ima_y= 512.f; // prevent calling textureSize, glsl 1.3 only
- if(ibuf) {
+ if (ibuf) {
ima_x= ibuf->x;
ima_y= ibuf->y;
aspect = ((float) ima_y) / ima_x;
@@ -1127,13 +1127,13 @@ static void do_material_tex(GPUShadeInput *shi)
tnorfac = GPU_uniform(&norfac);
- if(found_deriv_map)
+ if (found_deriv_map)
GPU_link(mat, "math_multiply", tnorfac, GPU_builtin(GPU_AUTO_BUMPSCALE), &tnorfac);
- if(GPU_link_changed(stencil))
+ if (GPU_link_changed(stencil))
GPU_link(mat, "math_multiply", tnorfac, stencil, &tnorfac);
- if( !init_done ) {
+ if ( !init_done ) {
// copy shi->vn to vNorg and vNacc, set magnitude to 1
GPU_link(mat, "mtex_bump_normals_init", shi->vn, &vNorg, &vNacc, &fPrevMagnitude);
iBumpSpacePrev = 0;
@@ -1141,17 +1141,17 @@ static void do_material_tex(GPUShadeInput *shi)
}
// 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
// re-initialize if bump space changed
- if( iBumpSpacePrev != iBumpSpace ) {
+ if ( iBumpSpacePrev != iBumpSpace ) {
- 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),
@@ -1159,7 +1159,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,
@@ -1177,25 +1177,26 @@ static void do_material_tex(GPUShadeInput *shi)
}
- if(found_deriv_map) {
+ if (found_deriv_map) {
GPU_link( mat, "mtex_bump_deriv",
texco, GPU_image(tex->ima, &tex->iuser), GPU_uniform(&ima_x), GPU_uniform(&ima_y), tnorfac,
&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), tnorfac,
&dBs, &dBt );
- else if( mtex->texflag & MTEX_5TAP_BUMP )
+ else if ( mtex->texflag & MTEX_5TAP_BUMP )
GPU_link( mat, "mtex_bump_tap5",
texco, GPU_image(tex->ima, &tex->iuser), tnorfac,
&dBs, &dBt );
- else if( mtex->texflag & MTEX_BICUBIC_BUMP ){
- if(GPU_bicubic_bump_support()){
+ 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), tnorfac,
&dBs, &dBt );
- }else{
+ }
+ else {
GPU_link( mat, "mtex_bump_tap5",
texco, GPU_image(tex->ima, &tex->iuser), tnorfac,
&dBs, &dBt );
@@ -1203,14 +1204,15 @@ static void do_material_tex(GPUShadeInput *shi)
}
- if( mtex->texflag & MTEX_BUMP_TEXTURESPACE ) {
+ if ( mtex->texflag & MTEX_BUMP_TEXTURESPACE ) {
float imag_tspace_dimension_y = aspect*imag_tspace_dimension_x;
GPU_link( mat, "mtex_bump_apply_texspace",
fDet, dBs, dBt, vR1, vR2,
GPU_image(tex->ima, &tex->iuser), texco,
GPU_uniform(&imag_tspace_dimension_x), GPU_uniform(&imag_tspace_dimension_y), vNacc,
&vNacc, &shi->vn );
- } else
+ }
+ else
GPU_link( mat, "mtex_bump_apply",
fDet, dBs, dBt, vR1, vR2, vNacc,
&vNacc, &shi->vn );
@@ -1221,64 +1223,64 @@ static void do_material_tex(GPUShadeInput *shi)
GPU_link(mat, "vec_math_negate", shi->vn, &orn);
}
- if((mtex->mapto & MAP_VARS)) {
- if(rgbnor & TEX_RGB) {
- if(talpha)
+ if ((mtex->mapto & MAP_VARS)) {
+ if (rgbnor & TEX_RGB) {
+ if (talpha)
GPU_link(mat, "mtex_alpha_from_col", trgb, &tin);
else
GPU_link(mat, "mtex_rgbtoint", trgb, &tin);
}
- if(!(mat->scene->gm.flag & GAME_GLSL_NO_EXTRA_TEX) && mtex->mapto & MAP_REF) {
+ if (!(mat->scene->gm.flag & GAME_GLSL_NO_EXTRA_TEX) && mtex->mapto & MAP_REF) {
GPUNodeLink *difffac;
- if(mtex->difffac == 1.0f) difffac = stencil;
+ if (mtex->difffac == 1.0f) difffac = stencil;
else GPU_link(mat, "math_multiply", GPU_uniform(&mtex->difffac), stencil, &difffac);
texture_value_blend(mat, GPU_uniform(&mtex->def_var), shi->refl, tin, difffac, mtex->blendtype, &shi->refl);
GPU_link(mat, "mtex_value_clamp_positive", shi->refl, &shi->refl);
}
- if(!(mat->scene->gm.flag & GAME_GLSL_NO_EXTRA_TEX) && mtex->mapto & MAP_SPEC) {
+ if (!(mat->scene->gm.flag & GAME_GLSL_NO_EXTRA_TEX) && mtex->mapto & MAP_SPEC) {
GPUNodeLink *specfac;
- if(mtex->specfac == 1.0f) specfac = stencil;
+ if (mtex->specfac == 1.0f) specfac = stencil;
else GPU_link(mat, "math_multiply", GPU_uniform(&mtex->specfac), stencil, &specfac);
texture_value_blend(mat, GPU_uniform(&mtex->def_var), shi->spec, tin, specfac, mtex->blendtype, &shi->spec);
GPU_link(mat, "mtex_value_clamp_positive", shi->spec, &shi->spec);
}
- if(!(mat->scene->gm.flag & GAME_GLSL_NO_EXTRA_TEX) && mtex->mapto & MAP_EMIT) {
+ if (!(mat->scene->gm.flag & GAME_GLSL_NO_EXTRA_TEX) && mtex->mapto & MAP_EMIT) {
GPUNodeLink *emitfac;
- if(mtex->emitfac == 1.0f) emitfac = stencil;
+ if (mtex->emitfac == 1.0f) emitfac = stencil;
else GPU_link(mat, "math_multiply", GPU_uniform(&mtex->emitfac), stencil, &emitfac);
texture_value_blend(mat, GPU_uniform(&mtex->def_var), shi->emit, tin, emitfac, mtex->blendtype, &shi->emit);
GPU_link(mat, "mtex_value_clamp_positive", shi->emit, &shi->emit);
}
- if(!(mat->scene->gm.flag & GAME_GLSL_NO_EXTRA_TEX) && mtex->mapto & MAP_HAR) {
+ if (!(mat->scene->gm.flag & GAME_GLSL_NO_EXTRA_TEX) && mtex->mapto & MAP_HAR) {
GPUNodeLink *hardfac;
- if(mtex->hardfac == 1.0f) hardfac = stencil;
+ if (mtex->hardfac == 1.0f) hardfac = stencil;
else GPU_link(mat, "math_multiply", GPU_uniform(&mtex->hardfac), stencil, &hardfac);
GPU_link(mat, "mtex_har_divide", shi->har, &shi->har);
texture_value_blend(mat, GPU_uniform(&mtex->def_var), shi->har, tin, hardfac, mtex->blendtype, &shi->har);
GPU_link(mat, "mtex_har_multiply_clamp", shi->har, &shi->har);
}
- if(mtex->mapto & MAP_ALPHA) {
+ if (mtex->mapto & MAP_ALPHA) {
GPUNodeLink *alphafac;
- if(mtex->alphafac == 1.0f) alphafac = stencil;
+ if (mtex->alphafac == 1.0f) alphafac = stencil;
else GPU_link(mat, "math_multiply", GPU_uniform(&mtex->alphafac), stencil, &alphafac);
texture_value_blend(mat, GPU_uniform(&mtex->def_var), shi->alpha, tin, alphafac, mtex->blendtype, &shi->alpha);
GPU_link(mat, "mtex_value_clamp", shi->alpha, &shi->alpha);
}
- if(!(mat->scene->gm.flag & GAME_GLSL_NO_EXTRA_TEX) && mtex->mapto & MAP_AMB) {
+ if (!(mat->scene->gm.flag & GAME_GLSL_NO_EXTRA_TEX) && mtex->mapto & MAP_AMB) {
GPUNodeLink *ambfac;
- if(mtex->ambfac == 1.0f) ambfac = stencil;
+ if (mtex->ambfac == 1.0f) ambfac = stencil;
else GPU_link(mat, "math_multiply", GPU_uniform(&mtex->ambfac), stencil, &ambfac);
texture_value_blend(mat, GPU_uniform(&mtex->def_var), shi->amb, tin, ambfac, mtex->blendtype, &shi->amb);
@@ -1309,7 +1311,7 @@ void GPU_shadeinput_set(GPUMaterial *mat, Material *ma, GPUShadeInput *shi)
GPU_link(mat, "set_value", GPU_uniform(&ma->amb), &shi->amb);
GPU_link(mat, "shade_view", GPU_builtin(GPU_VIEW_POSITION), &shi->view);
GPU_link(mat, "vcol_attribute", GPU_attribute(CD_MCOL, ""), &shi->vcol);
- if(gpu_do_color_management(mat))
+ if (gpu_do_color_management(mat))
GPU_link(mat, "srgb_to_linearrgb", shi->vcol, &shi->vcol);
GPU_link(mat, "texco_refl", shi->vn, shi->view, &shi->ref);
}
@@ -1324,23 +1326,23 @@ void GPU_shaderesult_set(GPUShadeInput *shi, GPUShadeResult *shr)
memset(shr, 0, sizeof(*shr));
- if(ma->mode & MA_VERTEXCOLP)
+ if (ma->mode & MA_VERTEXCOLP)
shi->rgb = shi->vcol;
do_material_tex(shi);
- if((ma->mode & MA_TRANSP) && (ma->mode & MA_ZTRANSP))
+ if ((ma->mode & MA_TRANSP) && (ma->mode & MA_ZTRANSP))
GPU_material_enable_alpha(mat);
- if((mat->scene->gm.flag & GAME_GLSL_NO_LIGHTS) || (ma->mode & MA_SHLESS)) {
+ if ((mat->scene->gm.flag & GAME_GLSL_NO_LIGHTS) || (ma->mode & MA_SHLESS)) {
shr->combined = shi->rgb;
shr->alpha = shi->alpha;
GPU_link(mat, "set_rgb", shi->rgb, &shr->diff);
GPU_link(mat, "set_rgb_zero", &shr->spec);
}
else {
- if(GPU_link_changed(shi->emit) || ma->emit != 0.0f) {
- if((ma->mode & (MA_VERTEXCOL|MA_VERTEXCOLP))== MA_VERTEXCOL) {
+ if (GPU_link_changed(shi->emit) || ma->emit != 0.0f) {
+ 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);
}
@@ -1357,9 +1359,9 @@ void GPU_shaderesult_set(GPUShadeInput *shi, GPUShadeResult *shr)
shr->combined = shr->diff;
shr->alpha = shi->alpha;
- if(world) {
+ if (world) {
/* exposure correction */
- if(world->exp!=0.0f || world->range!=1.0f) {
+ if (world->exp!=0.0f || world->range!=1.0f) {
linfac= 1.0f + powf((2.0f*world->exp + 0.5f), -10);
logfac= logf((linfac-1.0f)/linfac)/world->range;
@@ -1373,26 +1375,26 @@ void GPU_shaderesult_set(GPUShadeInput *shi, GPUShadeResult *shr)
}
/* ambient color */
- if(world->ambr!=0.0f || world->ambg!=0.0f || world->ambb!=0.0f) {
- if(GPU_link_changed(shi->amb) || ma->amb != 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);
}
}
- if(ma->mode & MA_RAMP_COL) ramp_diffuse_result(shi, &shr->combined);
- if(ma->mode & MA_RAMP_SPEC) ramp_spec_result(shi, &shr->spec);
+ if (ma->mode & MA_RAMP_COL) ramp_diffuse_result(shi, &shr->combined);
+ if (ma->mode & MA_RAMP_SPEC) ramp_spec_result(shi, &shr->spec);
- if(GPU_link_changed(shi->spec) || ma->spec != 0.0f)
+ if (GPU_link_changed(shi->spec) || ma->spec != 0.0f)
GPU_link(mat, "shade_add", shr->combined, shr->spec, &shr->combined);
}
GPU_link(mat, "mtex_alpha_to_col", shr->combined, shr->alpha, &shr->combined);
- if(ma->shade_flag & MA_OBCOLOR)
+ if (ma->shade_flag & MA_OBCOLOR)
GPU_link(mat, "shade_obcolor", shr->combined, GPU_builtin(GPU_OBCOLOR), &shr->combined);
- if(world && (world->mode & WO_MIST) && !(ma->mode & MA_NOMIST)) {
+ if (world && (world->mode & WO_MIST) && !(ma->mode & MA_NOMIST)) {
misttype = world->mistype;
GPU_link(mat, "shade_mist_factor", GPU_builtin(GPU_VIEW_POSITION),
@@ -1403,15 +1405,15 @@ void GPU_shaderesult_set(GPUShadeInput *shi, GPUShadeResult *shr)
GPU_uniform(&world->horr), &shr->combined);
}
- if(!((ma->mode & MA_TRANSP) && (ma->mode & MA_ZTRANSP))) {
- if(world && (GPU_link_changed(shr->alpha) || ma->alpha != 1.0f))
+ if (!((ma->mode & MA_TRANSP) && (ma->mode & MA_ZTRANSP))) {
+ if (world && (GPU_link_changed(shr->alpha) || ma->alpha != 1.0f))
GPU_link(mat, "shade_world_mix", GPU_uniform(&world->horr),
shr->combined, &shr->combined);
GPU_link(mat, "shade_alpha_opaque", shr->combined, &shr->combined);
}
- if(ma->shade_flag & MA_OBCOLOR) {
+ if (ma->shade_flag & MA_OBCOLOR) {
mat->obcolalpha = 1;
GPU_link(mat, "shade_alpha_obcolor", shr->combined, GPU_builtin(GPU_OBCOLOR), &shr->combined);
}
@@ -1434,15 +1436,15 @@ GPUMaterial *GPU_material_from_blender(Scene *scene, Material *ma)
GPUNodeLink *outlink;
LinkData *link;
- for(link=ma->gpumaterial.first; link; link=link->next)
- if(((GPUMaterial*)link->data)->scene == scene)
+ for (link=ma->gpumaterial.first; link; link=link->next)
+ if (((GPUMaterial*)link->data)->scene == scene)
return link->data;
/* allocate material */
mat = GPU_material_construct_begin(ma);
mat->scene = scene;
- if(!(scene->gm.flag & GAME_GLSL_NO_NODES) && ma->nodetree && ma->use_nodes) {
+ if (!(scene->gm.flag & GAME_GLSL_NO_NODES) && ma->nodetree && ma->use_nodes) {
/* create nodes */
ntreeGPUMaterialNodes(ma->nodetree, mat);
}
@@ -1452,9 +1454,9 @@ GPUMaterial *GPU_material_from_blender(Scene *scene, Material *ma)
GPU_material_output_link(mat, outlink);
}
- if(!scene_use_new_shading_nodes(scene)) {
- if(gpu_do_color_management(mat))
- if(mat->outlink)
+ if (!scene_use_new_shading_nodes(scene)) {
+ if (gpu_do_color_management(mat))
+ if (mat->outlink)
GPU_link(mat, "linearrgb_to_srgb", mat->outlink, &mat->outlink);
}
@@ -1478,12 +1480,12 @@ void GPU_materials_free(void)
Material *ma;
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);
GPU_material_free(&defmaterial);
- 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);
}
@@ -1508,7 +1510,7 @@ void GPU_lamp_update(GPULamp *lamp, int lay, int hide, float obmat[][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->energy;
lamp->col[1]= g* lamp->energy;
@@ -1529,7 +1531,7 @@ 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->energy;
lamp->col[1]= la->g*lamp->energy;
@@ -1538,8 +1540,8 @@ static void gpu_lamp_from_blender(Scene *scene, Object *ob, Object *par, Lamp *l
GPU_lamp_update(lamp, ob->lay, (ob->restrictflag & OB_RESTRICT_RENDER), ob->obmat);
lamp->spotsi= la->spotsize;
- if(lamp->mode & LA_HALO)
- if(lamp->spotsi > 170.0f)
+ if (lamp->mode & LA_HALO)
+ if (lamp->spotsi > 170.0f)
lamp->spotsi = 170.0f;
lamp->spotsi= cosf((float)M_PI*lamp->spotsi/360.0f);
lamp->spotbl= (1.0f - lamp->spotsi)*la->spotblend;
@@ -1571,11 +1573,11 @@ static void gpu_lamp_from_blender(Scene *scene, Object *ob, Object *par, Lamp *l
static void gpu_lamp_shadow_free(GPULamp *lamp)
{
- if(lamp->tex) {
+ if (lamp->tex) {
GPU_texture_free(lamp->tex);
lamp->tex= NULL;
}
- if(lamp->fb) {
+ if (lamp->fb) {
GPU_framebuffer_free(lamp->fb);
lamp->fb= NULL;
}
@@ -1587,10 +1589,10 @@ 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)
+ if (lamp->par == par && lamp->scene == scene)
return link->data;
}
@@ -1603,21 +1605,21 @@ 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)) {
+ if (la->type==LA_SPOT && (la->mode & LA_SHAD_BUF)) {
/* opengl */
lamp->fb = GPU_framebuffer_create();
- if(!lamp->fb) {
+ if (!lamp->fb) {
gpu_lamp_shadow_free(lamp);
return lamp;
}
lamp->tex = GPU_texture_create_depth(lamp->size, lamp->size, NULL);
- if(!lamp->tex) {
+ if (!lamp->tex) {
gpu_lamp_shadow_free(lamp);
return lamp;
}
- if(!GPU_framebuffer_texture_attach(lamp->fb, lamp->tex, NULL)) {
+ if (!GPU_framebuffer_texture_attach(lamp->fb, lamp->tex, NULL)) {
gpu_lamp_shadow_free(lamp);
return lamp;
}
@@ -1635,7 +1637,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) {
@@ -1643,7 +1645,7 @@ void GPU_lamp_free(Object *ob)
ma = nlink->data;
BLI_freelinkN(&lamp->materials, nlink);
- if(ma->gpumaterial.first)
+ if (ma->gpumaterial.first)
GPU_material_free(ma);
}
@@ -1706,7 +1708,7 @@ void GPU_lamp_shadow_buffer_unbind(GPULamp *lamp)
int GPU_lamp_shadow_layer(GPULamp *lamp)
{
- if(lamp->fb && lamp->tex && (lamp->mode & (LA_LAYER|LA_LAYER_SHADOW)))
+ if (lamp->fb && lamp->tex && (lamp->mode & (LA_LAYER|LA_LAYER_SHADOW)))
return lamp->lay;
else
return -1;
@@ -1739,19 +1741,19 @@ GPUShaderExport *GPU_shader_export(struct Scene *scene, struct Material *ma)
GLint lastbindcode;
int i, liblen, fraglen;
- if(!GPU_glsl_support())
+ if (!GPU_glsl_support())
return NULL;
mat = GPU_material_from_blender(scene, ma);
pass = (mat)? mat->pass: NULL;
- if(pass && pass->fragmentcode && pass->vertexcode) {
+ if (pass && pass->fragmentcode && pass->vertexcode) {
shader = MEM_callocN(sizeof(GPUShaderExport), "GPUShaderExport");
- for(input = pass->inputs.first; input; input = input->next) {
+ for (input = pass->inputs.first; input; input = input->next) {
uniform = MEM_callocN(sizeof(GPUInputUniform), "GPUInputUniform");
- if(input->ima) {
+ if (input->ima) {
/* image sampler uniform */
uniform->type = GPU_DYNAMIC_SAMPLER_2DIMAGE;
uniform->datatype = GPU_DATA_1I;
@@ -1759,7 +1761,7 @@ GPUShaderExport *GPU_shader_export(struct Scene *scene, struct Material *ma)
uniform->texnumber = input->texid;
BLI_strncpy(uniform->varname, input->shadername, sizeof(uniform->varname));
}
- else if(input->tex) {
+ else if (input->tex) {
/* generated buffer */
uniform->texnumber = input->texid;
uniform->datatype = GPU_DATA_1I;
@@ -1771,7 +1773,7 @@ GPUShaderExport *GPU_shader_export(struct Scene *scene, struct Material *ma)
uniform->lamp = input->dynamicdata;
break;
case GPU_TEX2D:
- if(GPU_texture_opengl_bindcode(input->tex)) {
+ if (GPU_texture_opengl_bindcode(input->tex)) {
uniform->type = GPU_DYNAMIC_SAMPLER_2DBUFFER;
glGetIntegerv(GL_TEXTURE_BINDING_2D, &lastbindcode);
glBindTexture(GL_TEXTURE_2D, GPU_texture_opengl_bindcode(input->tex));
@@ -1807,19 +1809,19 @@ GPUShaderExport *GPU_shader_export(struct Scene *scene, struct Material *ma)
break;
}
- if(uniform->type >= GPU_DYNAMIC_LAMP_FIRST && uniform->type <= GPU_DYNAMIC_LAMP_LAST)
+ if (uniform->type >= GPU_DYNAMIC_LAMP_FIRST && uniform->type <= GPU_DYNAMIC_LAMP_LAST)
uniform->lamp = input->dynamicdata;
}
- if(uniform->type != GPU_DYNAMIC_NONE)
+ if (uniform->type != GPU_DYNAMIC_NONE)
BLI_addtail(&shader->uniforms, uniform);
else
MEM_freeN(uniform);
}
/* process builtin uniform */
- for(i=0; builtins[i].gputype; i++) {
- if(mat->builtins & builtins[i].gputype) {
+ for (i=0; builtins[i].gputype; i++) {
+ if (mat->builtins & builtins[i].gputype) {
uniform = MEM_callocN(sizeof(GPUInputUniform), "GPUInputUniform");
uniform->type = builtins[i].dynamictype;
uniform->datatype = builtins[i].datatype;
@@ -1833,13 +1835,13 @@ GPUShaderExport *GPU_shader_export(struct Scene *scene, struct Material *ma)
liblen = (pass->libcode) ? strlen(pass->libcode) : 0;
fraglen = strlen(pass->fragmentcode);
shader->fragment = (char *)MEM_mallocN(liblen+fraglen+1, "GPUFragShader");
- if(pass->libcode)
+ if (pass->libcode)
memcpy(shader->fragment, pass->libcode, liblen);
memcpy(&shader->fragment[liblen], pass->fragmentcode, fraglen);
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;
@@ -1862,7 +1864,7 @@ GPUShaderExport *GPU_shader_export(struct Scene *scene, struct Material *ma)
break;
}
- if(attribute->datatype != GPU_DATA_NONE)
+ if (attribute->datatype != GPU_DATA_NONE)
BLI_addtail(&shader->attributes, attribute);
else
MEM_freeN(attribute);
@@ -1879,19 +1881,19 @@ void GPU_free_shader_export(GPUShaderExport *shader)
{
GPUInputUniform *uniform;
- if(shader == NULL)
+ if (shader == NULL)
return;
- for(uniform = shader->uniforms.first; uniform; uniform=uniform->next)
- if(uniform->texpixels)
+ for (uniform = shader->uniforms.first; uniform; uniform=uniform->next)
+ if (uniform->texpixels)
MEM_freeN(uniform->texpixels);
BLI_freelistN(&shader->uniforms);
BLI_freelistN(&shader->attributes);
- if(shader->vertex)
+ if (shader->vertex)
MEM_freeN(shader->vertex);
- if(shader->fragment)
+ if (shader->fragment)
MEM_freeN(shader->fragment);
MEM_freeN(shader);