diff options
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/draw/engines/gpencil/gpencil_draw_data.c | 2 | ||||
-rw-r--r-- | source/blender/draw/engines/overlay/overlay_image.c | 6 | ||||
-rw-r--r-- | source/blender/draw/engines/overlay/overlay_paint.c | 3 | ||||
-rw-r--r-- | source/blender/draw/engines/workbench/workbench_materials.c | 6 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_texture.c | 15 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_texture_image.cc | 27 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_image_types.h | 8 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_image_api.c | 9 |
8 files changed, 41 insertions, 35 deletions
diff --git a/source/blender/draw/engines/gpencil/gpencil_draw_data.c b/source/blender/draw/engines/gpencil/gpencil_draw_data.c index 6e6b35e19ca..b72ad5a2960 100644 --- a/source/blender/draw/engines/gpencil/gpencil_draw_data.c +++ b/source/blender/draw/engines/gpencil/gpencil_draw_data.c @@ -63,7 +63,7 @@ static struct GPUTexture *gpencil_image_texture_get(Image *image, bool *r_alpha_ ibuf = BKE_image_acquire_ibuf(image, &iuser, &lock); if (ibuf != NULL && ibuf->rect != NULL) { - gpu_tex = GPU_texture_from_blender(image, &iuser, ibuf, GL_TEXTURE_2D); + gpu_tex = GPU_texture_from_blender(image, &iuser, ibuf, TEXTARGET_TEXTURE_2D); *r_alpha_premult = (image->alpha_mode == IMA_ALPHA_PREMUL); } BKE_image_release_ibuf(image, ibuf, lock); diff --git a/source/blender/draw/engines/overlay/overlay_image.c b/source/blender/draw/engines/overlay/overlay_image.c index 67132a9e0ed..8a91bf51c2a 100644 --- a/source/blender/draw/engines/overlay/overlay_image.c +++ b/source/blender/draw/engines/overlay/overlay_image.c @@ -175,7 +175,7 @@ static struct GPUTexture *image_camera_background_texture_get(CameraBGImage *bgp } width = ibuf->x; height = ibuf->y; - tex = GPU_texture_from_blender(image, iuser, ibuf, GL_TEXTURE_2D); + tex = GPU_texture_from_blender(image, iuser, ibuf, TEXTARGET_TEXTURE_2D); BKE_image_release_ibuf(image, ibuf, lock); iuser->scene = NULL; @@ -203,7 +203,7 @@ static struct GPUTexture *image_camera_background_texture_get(CameraBGImage *bgp } BKE_movieclip_user_set_frame(&bgpic->cuser, ctime); - tex = GPU_texture_from_movieclip(clip, &bgpic->cuser, GL_TEXTURE_2D); + tex = GPU_texture_from_movieclip(clip, &bgpic->cuser, TEXTARGET_TEXTURE_2D); if (tex == NULL) { return NULL; } @@ -383,7 +383,7 @@ void OVERLAY_image_empty_cache_populate(OVERLAY_Data *vedata, Object *ob) if (ima != NULL) { ImageUser iuser = *ob->iuser; camera_background_images_stereo_setup(draw_ctx->scene, draw_ctx->v3d, ima, &iuser); - tex = GPU_texture_from_blender(ima, &iuser, NULL, GL_TEXTURE_2D); + tex = GPU_texture_from_blender(ima, &iuser, NULL, TEXTARGET_TEXTURE_2D); if (tex) { size[0] = GPU_texture_orig_width(tex); size[1] = GPU_texture_orig_height(tex); diff --git a/source/blender/draw/engines/overlay/overlay_paint.c b/source/blender/draw/engines/overlay/overlay_paint.c index e94cc820568..d0272050402 100644 --- a/source/blender/draw/engines/overlay/overlay_paint.c +++ b/source/blender/draw/engines/overlay/overlay_paint.c @@ -136,7 +136,8 @@ void OVERLAY_paint_cache_init(OVERLAY_Data *vedata) state = DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_EQUAL | DRW_STATE_BLEND_ALPHA; DRW_PASS_CREATE(psl->paint_color_ps, state | pd->clipping_state); - GPUTexture *tex = GPU_texture_from_blender(imapaint->stencil, NULL, NULL, GL_TEXTURE_2D); + GPUTexture *tex = GPU_texture_from_blender( + imapaint->stencil, NULL, NULL, TEXTARGET_TEXTURE_2D); const bool mask_premult = (imapaint->stencil->alpha_mode == IMA_ALPHA_PREMUL); const bool mask_inverted = (imapaint->flag & IMAGEPAINT_PROJECT_LAYER_STENCIL_INV) != 0; diff --git a/source/blender/draw/engines/workbench/workbench_materials.c b/source/blender/draw/engines/workbench/workbench_materials.c index 3fa2e7ef084..33b0764160f 100644 --- a/source/blender/draw/engines/workbench/workbench_materials.c +++ b/source/blender/draw/engines/workbench/workbench_materials.c @@ -261,11 +261,11 @@ DRWShadingGroup *workbench_image_setup_ex(WORKBENCH_PrivateData *wpd, if (ima) { if (ima->source == IMA_SRC_TILED) { - tex = GPU_texture_from_blender(ima, iuser, NULL, GL_TEXTURE_2D_ARRAY); - tex_tile_data = GPU_texture_from_blender(ima, iuser, NULL, GL_TEXTURE_1D_ARRAY); + tex = GPU_texture_from_blender(ima, iuser, NULL, TEXTARGET_TEXTURE_2D_ARRAY); + tex_tile_data = GPU_texture_from_blender(ima, iuser, NULL, TEXTARGET_TEXTURE_TILE_MAPPING); } else { - tex = GPU_texture_from_blender(ima, iuser, NULL, GL_TEXTURE_2D); + tex = GPU_texture_from_blender(ima, iuser, NULL, TEXTARGET_TEXTURE_2D); } } 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); } diff --git a/source/blender/makesdna/DNA_image_types.h b/source/blender/makesdna/DNA_image_types.h index 0ffb6c8a76a..ba40ef1c2bc 100644 --- a/source/blender/makesdna/DNA_image_types.h +++ b/source/blender/makesdna/DNA_image_types.h @@ -119,10 +119,10 @@ typedef struct ImageTile { enum { TEXTARGET_TEXTURE_2D = 0, - TEXTARGET_TEXTURE_CUBE_MAP = 1, - TEXTARGET_TEXTURE_2D_ARRAY = 2, - TEXTARGET_TEXTURE_TILE_MAPPING = 3, - TEXTARGET_COUNT = 4, + TEXTARGET_TEXTURE_CUBE_MAP, + TEXTARGET_TEXTURE_2D_ARRAY, + TEXTARGET_TEXTURE_TILE_MAPPING, + TEXTARGET_COUNT, }; typedef struct Image { diff --git a/source/blender/makesrna/intern/rna_image_api.c b/source/blender/makesrna/intern/rna_image_api.c index 41c0e724234..fecd364992b 100644 --- a/source/blender/makesrna/intern/rna_image_api.c +++ b/source/blender/makesrna/intern/rna_image_api.c @@ -222,19 +222,20 @@ static int rna_Image_gl_load(Image *image, ReportList *reports, int frame) BKE_imageuser_default(&iuser); iuser.framenr = frame; - GPUTexture *tex = GPU_texture_from_blender(image, &iuser, NULL, GL_TEXTURE_2D); + GPUTexture *tex = GPU_texture_from_blender(image, &iuser, NULL, TEXTARGET_TEXTURE_2D); if (tex == NULL) { BKE_reportf(reports, RPT_ERROR, "Failed to load image texture '%s'", image->id.name + 2); - return (int)GL_INVALID_OPERATION; + /* TODO(fclem) this error code makes no sense for vulkan. */ + return 0x0502; /* GL_INVALID_OPERATION */ } - return GL_NO_ERROR; + return 0; /* GL_NO_ERROR */ } static int rna_Image_gl_touch(Image *image, ReportList *reports, int frame) { - int error = GL_NO_ERROR; + int error = 0; /* GL_NO_ERROR */ BKE_image_tag_time(image); |