diff options
author | Mike Erwin <significant.bit@gmail.com> | 2016-01-08 00:32:02 +0300 |
---|---|---|
committer | Mike Erwin <significant.bit@gmail.com> | 2016-01-08 00:32:36 +0300 |
commit | 0e695f671af016a3e4277d0b9d3bfe7ee3ada440 (patch) | |
tree | bcf260572540eb74c1d2b84a44568753bd55a301 /source/blender/gpu | |
parent | f01f74d5dd2674eb29e585a33945fc862d24fe05 (diff) |
cleanup: C99
- tighter scoping
- declare vars closer to where they’re used
- use more bool
Diffstat (limited to 'source/blender/gpu')
-rw-r--r-- | source/blender/gpu/intern/gpu_material.c | 141 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_texture.c | 49 |
2 files changed, 82 insertions, 108 deletions
diff --git a/source/blender/gpu/intern/gpu_material.c b/source/blender/gpu/intern/gpu_material.c index 464bec118fb..6fc6331b9b6 100644 --- a/source/blender/gpu/intern/gpu_material.c +++ b/source/blender/gpu/intern/gpu_material.c @@ -185,20 +185,14 @@ static GPUMaterial *GPU_material_construct_begin(Material *ma) static void gpu_material_set_attrib_id(GPUMaterial *material) { - GPUVertexAttribs *attribs; - GPUShader *shader; - GPUPass *pass; - char name[32]; - int a, b; - - attribs = &material->attribs; - pass = material->pass; + GPUVertexAttribs *attribs = &material->attribs; + GPUPass *pass = material->pass; if (!pass) { attribs->totlayer = 0; return; } - shader = GPU_pass_shader(pass); + GPUShader *shader = GPU_pass_shader(pass); if (!shader) { attribs->totlayer = 0; return; @@ -208,7 +202,9 @@ 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++) { + int b = 0; + for (int a = 0; a < attribs->totlayer; a++) { + char name[32]; BLI_snprintf(name, sizeof(name), "att%d", attribs->layer[a].attribid); attribs->layer[a].glindex = GPU_shader_get_attribute(shader, name); @@ -224,10 +220,7 @@ static void gpu_material_set_attrib_id(GPUMaterial *material) static int GPU_material_construct_end(GPUMaterial *material, const char *passname) { if (material->outlink) { - GPUNodeLink *outlink; - GPUShader *shader; - - outlink = material->outlink; + GPUNodeLink *outlink = material->outlink; material->pass = GPU_generate_pass(&material->nodes, outlink, &material->attribs, &material->builtins, material->type, passname, material->is_opensubdiv); @@ -237,7 +230,7 @@ static int GPU_material_construct_end(GPUMaterial *material, const char *passnam gpu_material_set_attrib_id(material); - shader = GPU_pass_shader(material->pass); + GPUShader *shader = GPU_pass_shader(material->pass); if (material->builtins & GPU_VIEW_MATRIX) material->viewmatloc = GPU_shader_get_uniform(shader, GPU_builtin_name(GPU_VIEW_MATRIX)); @@ -269,22 +262,20 @@ static int GPU_material_construct_end(GPUMaterial *material, const char *passnam void GPU_material_free(ListBase *gpumaterial) { - LinkData *link; - LinkData *nlink, *mlink, *next; - - for (link = gpumaterial->first; link; link = link->next) { + for (LinkData *link = gpumaterial->first; link; link = link->next) { GPUMaterial *material = link->data; if (material->pass) GPU_pass_free(material->pass); - for (nlink = material->lamps.first; nlink; nlink = nlink->next) { + for (LinkData *nlink = material->lamps.first; nlink; nlink = nlink->next) { GPULamp *lamp = nlink->data; if (material->ma) { Material *ma = material->ma; - for (mlink = lamp->materials.first; mlink; mlink = next) { + LinkData *next = NULL; + for (LinkData *mlink = lamp->materials.first; mlink; mlink = next) { next = mlink->next; if (mlink->data == ma) BLI_freelinkN(&lamp->materials, mlink); @@ -313,8 +304,6 @@ bool GPU_lamp_override_visible(GPULamp *lamp, SceneRenderLayer *srl, Material *m void GPU_material_bind(GPUMaterial *material, int oblay, int viewlay, double time, int mipmap, float viewmat[4][4], float viewinv[4][4], float camerafactors[4], bool scenelock) { if (material->pass) { - LinkData *nlink; - GPULamp *lamp; GPUShader *shader = GPU_pass_shader(material->pass); SceneRenderLayer *srl = scenelock ? BLI_findlink(&material->scene->r.layers, material->scene->r.actlay) : NULL; @@ -323,8 +312,8 @@ void GPU_material_bind(GPUMaterial *material, int oblay, int viewlay, double tim /* handle layer lamps */ if (material->type == GPU_MATERIAL_TYPE_MESH) { - for (nlink = material->lamps.first; nlink; nlink = nlink->next) { - lamp = nlink->data; + for (LinkData *nlink = material->lamps.first; nlink; nlink = nlink->next) { + GPULamp *lamp = nlink->data; if (!lamp->hide && (lamp->lay & viewlay) && (!(lamp->mode & LA_LAYER) || (lamp->lay & oblay)) && GPU_lamp_override_visible(lamp, srl, material->ma)) { @@ -495,7 +484,7 @@ bool GPU_material_use_new_shading_nodes(GPUMaterial *mat) static GPUNodeLink *lamp_get_visibility(GPUMaterial *mat, GPULamp *lamp, GPUNodeLink **lv, GPUNodeLink **dist) { - GPUNodeLink *visifac, *inpr; + GPUNodeLink *visifac; /* from get_lamp_visibility */ if (lamp->type == LA_SUN || lamp->type == LA_HEMI) { @@ -539,6 +528,8 @@ static GPUNodeLink *lamp_get_visibility(GPUMaterial *mat, GPULamp *lamp, GPUNode GPU_link(mat, "lamp_visibility_sphere", GPU_dynamic_uniform(&lamp->dist, GPU_DYNAMIC_LAMP_DISTANCE, lamp->ob), *dist, visifac, &visifac); if (lamp->type == LA_SPOT) { + GPUNodeLink *inpr; + 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), @@ -563,10 +554,10 @@ static GPUNodeLink *lamp_get_visibility(GPUMaterial *mat, GPULamp *lamp, GPUNode #if 0 static void area_lamp_vectors(LampRen *lar) { - float xsize = 0.5f * lar->area_size, ysize = 0.5f * lar->area_sizey, multifac; + float xsize = 0.5f * lar->area_size, ysize = 0.5f * lar->area_sizey; /* make it smaller, so area light can be multisampled */ - multifac = 1.0f / sqrtf((float)lar->ray_totsamp); + float multifac = 1.0f / sqrtf((float)lar->ray_totsamp); xsize *= multifac; ysize *= multifac; @@ -626,11 +617,11 @@ static void ramp_diffuse_result(GPUShadeInput *shi, GPUNodeLink **diff) { Material *ma = shi->mat; 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) { + GPUNodeLink *fac; GPU_link(mat, "ramp_rgbtobw", *diff, &fac); /* colorband + blend */ @@ -683,11 +674,11 @@ static void ramp_spec_result(GPUShadeInput *shi, GPUNodeLink **spec) { Material *ma = shi->mat; GPUMaterial *mat = shi->gpumat; - GPUNodeLink *fac; if (!(mat->scene->gm.flag & GAME_GLSL_NO_RAMPS) && ma->ramp_spec && ma->rampin_spec == MA_RAMP_IN_RESULT) { + GPUNodeLink *fac; GPU_link(mat, "ramp_rgbtobw", *spec, &fac); /* colorband + blend */ @@ -736,17 +727,15 @@ static void add_user_list(ListBase *list, void *data) static void shade_light_textures(GPUMaterial *mat, GPULamp *lamp, GPUNodeLink **rgb) { - GPUNodeLink *tex_rgb; - MTex *mtex = NULL; - int i; - float one = 1.f; - - for (i = 0; i < MAX_MTEX; ++i) { - mtex = lamp->la->mtex[i]; + for (int i = 0; i < MAX_MTEX; ++i) { + MTex *mtex = lamp->la->mtex[i]; if (mtex && mtex->tex->type & TEX_IMAGE && mtex->tex->ima) { mat->dynproperty |= DYN_LAMP_PERSMAT; + const float one = 1.0f; + GPUNodeLink *tex_rgb; + GPU_link(mat, "shade_light_texture", GPU_builtin(GPU_VIEW_POSITION), GPU_image(mtex->tex->ima, &mtex->tex->iuser, false), @@ -761,17 +750,17 @@ static void shade_one_light(GPUShadeInput *shi, GPUShadeResult *shr, GPULamp *la { Material *ma = shi->mat; GPUMaterial *mat = shi->gpumat; - GPUNodeLink *lv, *dist, *visifac, *is, *inp, *i, *vn, *view; + GPUNodeLink *lv, *dist, *is, *inp, *i; GPUNodeLink *outcol, *specfac, *t, *shadfac = NULL, *lcol; - float one = 1.0f; + const float one = 1.0f; if ((lamp->mode & LA_ONLYSHADOW) && !(ma->mode & MA_SHADOW)) return; - vn = shi->vn; - view = shi->view; + GPUNodeLink *vn = shi->vn; + GPUNodeLink *view = shi->view; - visifac = lamp_get_visibility(mat, lamp, &lv, &dist); + GPUNodeLink *visifac = lamp_get_visibility(mat, lamp, &lv, &dist); #if 0 if (ma->mode & MA_TANGENT_V) @@ -935,24 +924,21 @@ static void shade_one_light(GPUShadeInput *shi, GPUShadeResult *shr, GPULamp *la static void material_lights(GPUShadeInput *shi, GPUShadeResult *shr) { Base *base; - Object *ob; Scene *sce_iter; - GPULamp *lamp; for (SETLOOPER(shi->gpumat->scene, sce_iter, base)) { - ob = base->object; + Object *ob = base->object; if (ob->type == OB_LAMP) { - lamp = GPU_lamp_from_blender(shi->gpumat->scene, ob, NULL); + GPULamp *lamp = GPU_lamp_from_blender(shi->gpumat->scene, ob, NULL); if (lamp) shade_one_light(shi, shr, lamp); } if (ob->transflag & OB_DUPLI) { - DupliObject *dob; ListBase *lb = object_duplilist(G.main->eval_ctx, shi->gpumat->scene, ob); - for (dob = lb->first; dob; dob = dob->next) { + for (DupliObject *dob = lb->first; dob; dob = dob->next) { Object *ob_iter = dob->ob; if (ob_iter->type == OB_LAMP) { @@ -960,7 +946,7 @@ static void material_lights(GPUShadeInput *shi, GPUShadeResult *shr) copy_m4_m4(omat, ob_iter->obmat); copy_m4_m4(ob_iter->obmat, dob->mat); - lamp = GPU_lamp_from_blender(shi->gpumat->scene, ob_iter, ob); + GPULamp *lamp = GPU_lamp_from_blender(shi->gpumat->scene, ob_iter, ob); if (lamp) shade_one_light(shi, shr, lamp); @@ -1080,14 +1066,13 @@ static void do_material_tex(GPUShadeInput *shi) GPUNodeLink *texco_norm, *texco_orco, *texco_object; GPUNodeLink *texco_global, *texco_uv = NULL; GPUNodeLink *newnor, *orn; - /*char *lastuvname = NULL;*/ /*UNUSED*/ - float one = 1.0f, norfac, ofs[3]; - int tex_nr, rgbnor, talpha; + const float one = 1.0f; + int rgbnor, talpha; bool init_done = false; int iBumpSpacePrev = 0; /* Not necessary, quieting gcc warning. */ GPUNodeLink *vNorg, *vNacc, *fPrevMagnitude; int iFirstTimeNMap = 1; - int found_deriv_map = 0; + bool found_deriv_map = false; GPU_link(mat, "set_value", GPU_uniform(&one), &stencil); @@ -1102,10 +1087,10 @@ static void do_material_tex(GPUShadeInput *shi) GPU_link(mat, "texco_global", GPU_builtin(GPU_INVERSE_VIEW_MATRIX), GPU_builtin(GPU_VIEW_POSITION), &texco_global); - orn= texco_norm; + orn = texco_norm; /* go over texture slots */ - for (tex_nr = 0; tex_nr < MAX_MTEX; tex_nr++) { + for (int tex_nr = 0; tex_nr < MAX_MTEX; tex_nr++) { /* separate tex switching */ if (ma->septex & (1 << tex_nr)) continue; @@ -1147,9 +1132,12 @@ static void do_material_tex(GPUShadeInput *shi) if (mtex->size[0] != 1.0f || mtex->size[1] != 1.0f || mtex->size[2] != 1.0f) GPU_link(mat, "mtex_mapping_size", texco, GPU_uniform(mtex->size), &texco); - ofs[0] = mtex->ofs[0] + 0.5f - 0.5f * mtex->size[0]; - ofs[1] = mtex->ofs[1] + 0.5f - 0.5f * mtex->size[1]; - ofs[2] = 0.0f; + const float ofs[3] = { + mtex->ofs[0] + 0.5f - 0.5f * mtex->size[0], + mtex->ofs[1] + 0.5f - 0.5f * mtex->size[1], + 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); @@ -1261,7 +1249,7 @@ static void do_material_tex(GPUShadeInput *shi) newnor = tnor; } - norfac = min_ff(fabsf(mtex->norfac), 1.0f); + float norfac = min_ff(fabsf(mtex->norfac), 1.0f); if (norfac == 1.0f && !GPU_link_changed(stencil)) { shi->vn = newnor; @@ -1280,7 +1268,6 @@ static void do_material_tex(GPUShadeInput *shi) /* ntap bumpmap image */ int iBumpSpace; float ima_x, ima_y; - float hScale; float imag_tspace_dimension_x = 1024.0f; /* only used for texture space variant */ float aspect = 1.0f; @@ -1288,16 +1275,16 @@ static void do_material_tex(GPUShadeInput *shi) GPUNodeLink *vR1, *vR2; GPUNodeLink *dBs, *dBt, *fDet; - hScale = 0.1; /* compatibility adjustment factor for all bumpspace types */ + float hScale = 0.1f; /* compatibility adjustment factor for all bumpspace types */ if (mtex->texflag & MTEX_BUMP_TEXTURESPACE) hScale = 13.0f; /* factor for scaling texspace bumps */ - else if (found_deriv_map!=0) + else if (found_deriv_map) hScale = 1.0f; /* resolve texture resolution */ if ((mtex->texflag & MTEX_BUMP_TEXTURESPACE) || found_deriv_map) { ImBuf *ibuf = BKE_image_acquire_ibuf(tex->ima, &tex->iuser, NULL); - ima_x = 512.0f; ima_y = 512.f; /* prevent calling textureSize, glsl 1.3 only */ + ima_x = 512.0f; ima_y = 512.0f; /* prevent calling textureSize, glsl 1.3 only */ if (ibuf) { ima_x = ibuf->x; ima_y = ibuf->y; @@ -1310,7 +1297,7 @@ static void do_material_tex(GPUShadeInput *shi) * normal in the renderer points inward which corresponds * to inverting the bump map. Should this ever change * this negate must be removed. */ - norfac = -hScale * mtex->norfac; + float norfac = -hScale * mtex->norfac; if (found_deriv_map) { float fVirtDim = sqrtf(fabsf(ima_x * mtex->size[0] * ima_y * mtex->size[1])); norfac /= MAX2(fVirtDim, FLT_EPSILON); @@ -2276,22 +2263,18 @@ GPUShaderExport *GPU_shader_export(struct Scene *scene, struct Material *ma) }; GPUShaderExport *shader = NULL; - GPUPass *pass; GPUInput *input; - GPUMaterial *mat; - GPUInputUniform *uniform; - GPUInputAttribute *attribute; - int i, liblen, fraglen; + int liblen, fraglen; - /* TODO(sergey): How to detemine whether we need OSD or not here? */ - mat = GPU_material_from_blender(scene, ma, false); - pass = (mat)? mat->pass: NULL; + /* TODO(sergey): How to determine whether we need OSD or not here? */ + GPUMaterial *mat = GPU_material_from_blender(scene, ma, false); + GPUPass *pass = (mat)? mat->pass: NULL; if (pass && pass->fragmentcode && pass->vertexcode) { shader = MEM_callocN(sizeof(GPUShaderExport), "GPUShaderExport"); for (input = pass->inputs.first; input; input = input->next) { - uniform = MEM_callocN(sizeof(GPUInputUniform), "GPUInputUniform"); + GPUInputUniform *uniform = MEM_callocN(sizeof(GPUInputUniform), "GPUInputUniform"); if (input->ima) { /* image sampler uniform */ @@ -2375,9 +2358,9 @@ GPUShaderExport *GPU_shader_export(struct Scene *scene, struct Material *ma) } /* process builtin uniform */ - for (i = 0; builtins[i].gputype; i++) { + for (int i = 0; builtins[i].gputype; i++) { if (mat->builtins & builtins[i].gputype) { - uniform = MEM_callocN(sizeof(GPUInputUniform), "GPUInputUniform"); + GPUInputUniform *uniform = MEM_callocN(sizeof(GPUInputUniform), "GPUInputUniform"); uniform->type = builtins[i].dynamictype; uniform->datatype = builtins[i].datatype; BLI_strncpy(uniform->varname, GPU_builtin_name(builtins[i].gputype), sizeof(uniform->varname)); @@ -2396,8 +2379,8 @@ GPUShaderExport *GPU_shader_export(struct Scene *scene, struct Material *ma) shader->fragment[liblen + fraglen] = 0; // export the attribute - for (i = 0; i < mat->attribs.totlayer; i++) { - attribute = MEM_callocN(sizeof(GPUInputAttribute), "GPUInputAttribute"); + for (int i = 0; i < mat->attribs.totlayer; i++) { + GPUInputAttribute *attribute = MEM_callocN(sizeof(GPUInputAttribute), "GPUInputAttribute"); attribute->type = mat->attribs.layer[i].type; attribute->number = mat->attribs.layer[i].glindex; BLI_snprintf(attribute->varname, sizeof(attribute->varname), "att%d", mat->attribs.layer[i].attribid); @@ -2434,12 +2417,10 @@ GPUShaderExport *GPU_shader_export(struct Scene *scene, struct Material *ma) void GPU_free_shader_export(GPUShaderExport *shader) { - GPUInputUniform *uniform; - if (shader == NULL) return; - for (uniform = shader->uniforms.first; uniform; uniform = uniform->next) + for (GPUInputUniform *uniform = shader->uniforms.first; uniform; uniform = uniform->next) if (uniform->texpixels) MEM_freeN(uniform->texpixels); diff --git a/source/blender/gpu/intern/gpu_texture.c b/source/blender/gpu/intern/gpu_texture.c index 7803c0d0a87..5877fc2989d 100644 --- a/source/blender/gpu/intern/gpu_texture.c +++ b/source/blender/gpu/intern/gpu_texture.c @@ -70,11 +70,10 @@ static unsigned char *GPU_texture_convert_pixels(int length, const float *fpixel unsigned char *pixels, *p; const float *fp = fpixels; const int len = 4 * length; - int a; p = pixels = MEM_callocN(sizeof(unsigned char) * len, "GPUTexturePixels"); - for (a = 0; a < len; a++, p++, fp++) + for (int a = 0; a < len; a++, p++, fp++) *p = FTOCHAR((*fp)); return pixels; @@ -97,7 +96,6 @@ static GPUTexture *GPU_texture_create_nD( GPUHDRType hdr_type, int components, int samples, char err_out[256]) { - GPUTexture *tex; GLenum type, format, internalformat; void *pixels = NULL; @@ -105,7 +103,7 @@ static GPUTexture *GPU_texture_create_nD( CLAMP_MAX(samples, GPU_max_color_texture_samples()); } - tex = MEM_callocN(sizeof(GPUTexture), "GPUTexture"); + GPUTexture *tex = MEM_callocN(sizeof(GPUTexture), "GPUTexture"); tex->w = w; tex->h = h; tex->number = -1; @@ -247,16 +245,13 @@ static GPUTexture *GPU_texture_create_nD( GPUTexture *GPU_texture_create_3D(int w, int h, int depth, int channels, const float *fpixels) { - GPUTexture *tex; GLenum type, format, internalformat; void *pixels = NULL; - int r_width; - bool rescale = false; if (!GLEW_VERSION_1_2) return NULL; - tex = MEM_callocN(sizeof(GPUTexture), "GPUTexture"); + GPUTexture *tex = MEM_callocN(sizeof(GPUTexture), "GPUTexture"); tex->w = w; tex->h = h; tex->depth = depth; @@ -291,6 +286,10 @@ GPUTexture *GPU_texture_create_3D(int w, int h, int depth, int channels, const f /* 3D textures are quite heavy, test if it's possible to create them first */ glTexImage3D(GL_PROXY_TEXTURE_3D, 0, internalformat, tex->w, tex->h, tex->depth, 0, format, type, NULL); + + bool rescale = false; + int r_width; + glGetTexLevelParameteriv(GL_PROXY_TEXTURE_3D, 0, GL_TEXTURE_WIDTH, &r_width); while (r_width == 0) { @@ -317,15 +316,15 @@ GPUTexture *GPU_texture_create_3D(int w, int h, int depth, int channels, const f /* hardcore stuff, 3D texture rescaling - warning, this is gonna hurt your performance a lot, but we need it * for gooseberry */ if (rescale && fpixels) { - unsigned int i, j, k; - unsigned int xf = w / tex->w, yf = h / tex->h, zf = depth / tex->depth; + /* FIXME: should these be floating point? */ + const unsigned int xf = w / tex->w, yf = h / tex->h, zf = depth / tex->depth; float *tex3d = MEM_mallocN(channels * sizeof(float)*tex->w*tex->h*tex->depth, "tex3d"); GPU_print_error_debug("You need to scale a 3D texture, feel the pain!"); - for (k = 0; k < tex->depth; k++) { - for (j = 0; j < tex->h; j++) { - for (i = 0; i < tex->w; i++) { + for (unsigned k = 0; k < tex->depth; k++) { + for (unsigned j = 0; j < tex->h; j++) { + for (unsigned i = 0; i < tex->w; i++) { /* obviously doing nearest filtering here, it's going to be slow in any case, let's not make it worse */ float xb = i * xf; float yb = j * yf; @@ -373,12 +372,9 @@ GPUTexture *GPU_texture_create_3D(int w, int h, int depth, int channels, const f GPUTexture *GPU_texture_from_blender(Image *ima, ImageUser *iuser, bool is_data, double time, int mipmap) { - GPUTexture *tex; - GLint w, h, border, bindcode; - GPU_update_image_time(ima, time); /* this binds a texture, so that's why to restore it to 0 */ - bindcode = GPU_verify_image(ima, iuser, 0, 0, mipmap, is_data); + GLint bindcode = GPU_verify_image(ima, iuser, 0, 0, mipmap, is_data); if (ima->gputexture) { ima->gputexture->bindcode = bindcode; @@ -386,7 +382,7 @@ GPUTexture *GPU_texture_from_blender(Image *ima, ImageUser *iuser, bool is_data, return ima->gputexture; } - tex = MEM_callocN(sizeof(GPUTexture), "GPUTexture"); + GPUTexture *tex = MEM_callocN(sizeof(GPUTexture), "GPUTexture"); tex->bindcode = bindcode; tex->number = -1; tex->refcount = 1; @@ -400,6 +396,8 @@ GPUTexture *GPU_texture_from_blender(Image *ima, ImageUser *iuser, bool is_data, GPU_ASSERT_NO_GL_ERRORS("Blender Texture Not Loaded"); } else { + GLint w, h, border; + glBindTexture(GL_TEXTURE_2D, tex->bindcode); glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &w); glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &h); @@ -417,7 +415,6 @@ GPUTexture *GPU_texture_from_blender(Image *ima, ImageUser *iuser, bool is_data, GPUTexture *GPU_texture_from_preview(PreviewImage *prv, int mipmap) { GPUTexture *tex = prv->gputexture[0]; - GLint w, h; GLuint bindcode = 0; if (tex) @@ -446,6 +443,8 @@ GPUTexture *GPU_texture_from_preview(PreviewImage *prv, int mipmap) GPU_ASSERT_NO_GL_ERRORS("Blender Texture Not Loaded"); } else { + GLint w, h; + glBindTexture(GL_TEXTURE_2D, tex->bindcode); glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &w); glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &h); @@ -597,8 +596,6 @@ void GPU_invalid_tex_free(void) void GPU_texture_bind(GPUTexture *tex, int number) { - GLenum arbnumber; - if (number >= GPU_max_textures()) { fprintf(stderr, "Not enough texture slots.\n"); return; @@ -615,7 +612,7 @@ void GPU_texture_bind(GPUTexture *tex, int number) GPU_ASSERT_NO_GL_ERRORS("Pre Texture Bind"); - arbnumber = (GLenum)((GLuint)GL_TEXTURE0 + number); + GLenum arbnumber = (GLenum)((GLuint)GL_TEXTURE0 + number); if (number != 0) glActiveTexture(arbnumber); if (tex->bindcode != 0) { glBindTexture(tex->target, tex->bindcode); @@ -632,8 +629,6 @@ void GPU_texture_bind(GPUTexture *tex, int number) void GPU_texture_unbind(GPUTexture *tex) { - GLenum arbnumber; - if (tex->number >= GPU_max_textures()) { fprintf(stderr, "Not enough texture slots.\n"); return; @@ -644,7 +639,7 @@ void GPU_texture_unbind(GPUTexture *tex) GPU_ASSERT_NO_GL_ERRORS("Pre Texture Unbind"); - arbnumber = (GLenum)((GLuint)GL_TEXTURE0 + tex->number); + GLenum arbnumber = (GLenum)((GLuint)GL_TEXTURE0 + tex->number); if (tex->number != 0) glActiveTexture(arbnumber); glBindTexture(tex->target, 0); glDisable(tex->target_base); @@ -662,8 +657,6 @@ int GPU_texture_bound_number(GPUTexture *tex) void GPU_texture_filter_mode(GPUTexture *tex, bool compare, bool use_filter) { - GLenum arbnumber; - if (tex->number >= GPU_max_textures()) { fprintf(stderr, "Not enough texture slots.\n"); return; @@ -674,7 +667,7 @@ void GPU_texture_filter_mode(GPUTexture *tex, bool compare, bool use_filter) GPU_ASSERT_NO_GL_ERRORS("Pre Texture Unbind"); - arbnumber = (GLenum)((GLuint)GL_TEXTURE0 + tex->number); + GLenum arbnumber = (GLenum)((GLuint)GL_TEXTURE0 + tex->number); if (tex->number != 0) glActiveTexture(arbnumber); if (tex->depth) { |