diff options
Diffstat (limited to 'source/blender/gpu/intern')
-rw-r--r-- | source/blender/gpu/intern/gpu_texture.c | 15 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_texture_image.cc | 27 |
2 files changed, 23 insertions, 19 deletions
diff --git a/source/blender/gpu/intern/gpu_texture.c b/source/blender/gpu/intern/gpu_texture.c index 4456229c1ee..2eac3c6f64d 100644 --- a/source/blender/gpu/intern/gpu_texture.c +++ b/source/blender/gpu/intern/gpu_texture.c @@ -1186,8 +1186,21 @@ GPUTexture *GPU_texture_create_buffer(eGPUTextureFormat tex_format, const GLuint return tex; } -GPUTexture *GPU_texture_from_bindcode(int textarget, int bindcode) +static GLenum convert_target_to_gl(int target) { + static const GLenum table[] = { + [TEXTARGET_TEXTURE_2D] = GL_TEXTURE_2D, + [TEXTARGET_TEXTURE_CUBE_MAP] = GL_TEXTURE_CUBE_MAP, + [TEXTARGET_TEXTURE_2D_ARRAY] = GL_TEXTURE_2D_ARRAY, + [TEXTARGET_TEXTURE_TILE_MAPPING] = GL_TEXTURE_1D_ARRAY, + }; + return table[target]; +} + +GPUTexture *GPU_texture_from_bindcode(int target, int bindcode) +{ + GLenum textarget = convert_target_to_gl(target); + GPUTexture *tex = MEM_callocN(sizeof(GPUTexture), "GPUTexture"); tex->bindcode = bindcode; tex->refcount = 1; diff --git a/source/blender/gpu/intern/gpu_texture_image.cc b/source/blender/gpu/intern/gpu_texture_image.cc index 480a8fc24d7..4b091ecc618 100644 --- a/source/blender/gpu/intern/gpu_texture_image.cc +++ b/source/blender/gpu/intern/gpu_texture_image.cc @@ -182,23 +182,14 @@ float GPU_get_anisotropic(void) return GTS.anisotropic; } -/* Set OpenGL state for an MTFace */ - -static GPUTexture **gpu_get_image_gputexture(Image *ima, GLenum textarget, const int multiview_eye) +static GPUTexture **gpu_get_image_gputexture(Image *ima, int textarget, const int multiview_eye) { - if (textarget == GL_TEXTURE_2D) { - return &(ima->gputexture[TEXTARGET_TEXTURE_2D][multiview_eye]); - } - else if (textarget == GL_TEXTURE_CUBE_MAP) { - return &(ima->gputexture[TEXTARGET_TEXTURE_CUBE_MAP][multiview_eye]); - } - else if (textarget == GL_TEXTURE_2D_ARRAY) { - return &(ima->gputexture[TEXTARGET_TEXTURE_2D_ARRAY][multiview_eye]); - } - else if (textarget == GL_TEXTURE_1D_ARRAY) { - return &(ima->gputexture[TEXTARGET_TEXTURE_TILE_MAPPING][multiview_eye]); - } + const bool in_range = (textarget >= 0) && (textarget < TEXTARGET_COUNT); + BLI_assert(in_range); + if (in_range) { + return &(ima->gputexture[textarget][multiview_eye]); + } return NULL; } @@ -895,10 +886,10 @@ GPUTexture *GPU_texture_from_blender(Image *ima, ImageUser *iuser, ImBuf *ibuf, } } - if (textarget == GL_TEXTURE_2D_ARRAY) { + if (textarget == TEXTARGET_TEXTURE_2D_ARRAY) { bindcode = gpu_texture_create_tile_array(ima, ibuf_intern); } - else if (textarget == GL_TEXTURE_1D_ARRAY) { + else if (textarget == TEXTARGET_TEXTURE_TILE_MAPPING) { bindcode = gpu_texture_create_tile_mapping(ima, iuser ? iuser->multiview_eye : 0); } else { @@ -914,7 +905,7 @@ GPUTexture *GPU_texture_from_blender(Image *ima, ImageUser *iuser, ImBuf *ibuf, GPU_texture_orig_size_set(*tex, ibuf_intern->x, ibuf_intern->y); - if (textarget == GL_TEXTURE_1D_ARRAY) { + if (textarget == TEXTARGET_TEXTURE_TILE_MAPPING) { /* Special for tile mapping. */ GPU_texture_mipmap_mode(*tex, false, false); } |