Changeset View
Changeset View
Standalone View
Standalone View
source/blender/gpu/intern/gpu_draw.c
| Show First 20 Lines • Show All 174 Lines • ▼ Show 20 Lines | |||||
| float GPU_get_anisotropic(void) | float GPU_get_anisotropic(void) | ||||
| { | { | ||||
| return GTS.anisotropic; | return GTS.anisotropic; | ||||
| } | } | ||||
| /* Set OpenGL state for an MTFace */ | /* Set OpenGL state for an MTFace */ | ||||
| static GPUTexture **gpu_get_image_gputexture(Image *ima, GLenum textarget) | static GPUTexture **gpu_get_image_gputexture(Image *ima, GLenum textarget, const int multiview_eye) | ||||
| { | { | ||||
| if (textarget == GL_TEXTURE_2D) { | if (textarget == GL_TEXTURE_2D) { | ||||
| return &ima->gputexture[TEXTARGET_TEXTURE_2D]; | return &(ima->gputexture[TEXTARGET_TEXTURE_2D][multiview_eye]); | ||||
| } | } | ||||
| else if (textarget == GL_TEXTURE_CUBE_MAP) { | else if (textarget == GL_TEXTURE_CUBE_MAP) { | ||||
| return &ima->gputexture[TEXTARGET_TEXTURE_CUBE_MAP]; | return &(ima->gputexture[TEXTARGET_TEXTURE_CUBE_MAP][multiview_eye]); | ||||
| } | } | ||||
| else if (textarget == GL_TEXTURE_2D_ARRAY) { | else if (textarget == GL_TEXTURE_2D_ARRAY) { | ||||
| return &ima->gputexture[TEXTARGET_TEXTURE_2D_ARRAY]; | return &(ima->gputexture[TEXTARGET_TEXTURE_2D_ARRAY][multiview_eye]); | ||||
| } | } | ||||
| else if (textarget == GL_TEXTURE_1D_ARRAY) { | else if (textarget == GL_TEXTURE_1D_ARRAY) { | ||||
| return &ima->gputexture[TEXTARGET_TEXTURE_TILE_MAPPING]; | return &(ima->gputexture[TEXTARGET_TEXTURE_TILE_MAPPING][multiview_eye]); | ||||
| } | } | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| static uint gpu_texture_create_tile_mapping(Image *ima) | static uint gpu_texture_create_tile_mapping(Image *ima, const int multiview_eye) | ||||
| { | { | ||||
| GPUTexture *tilearray = ima->gputexture[TEXTARGET_TEXTURE_2D_ARRAY]; | GPUTexture *tilearray = ima->gputexture[TEXTARGET_TEXTURE_2D_ARRAY][multiview_eye]; | ||||
| if (tilearray == NULL) { | if (tilearray == NULL) { | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| float array_w = GPU_texture_width(tilearray); | float array_w = GPU_texture_width(tilearray); | ||||
| float array_h = GPU_texture_height(tilearray); | float array_h = GPU_texture_height(tilearray); | ||||
| ImageTile *last_tile = ima->tiles.last; | ImageTile *last_tile = ima->tiles.last; | ||||
| ▲ Show 20 Lines • Show All 659 Lines • ▼ Show 20 Lines | if (ima->gpuflag & IMA_GPU_REFRESH) { | ||||
| gpu_free_image_immediate(ima); | gpu_free_image_immediate(ima); | ||||
| ima->gpuflag &= ~IMA_GPU_REFRESH; | ima->gpuflag &= ~IMA_GPU_REFRESH; | ||||
| } | } | ||||
| /* Tag as in active use for garbage collector. */ | /* Tag as in active use for garbage collector. */ | ||||
| BKE_image_tag_time(ima); | BKE_image_tag_time(ima); | ||||
| /* Test if we already have a texture. */ | /* Test if we already have a texture. */ | ||||
| GPUTexture **tex = gpu_get_image_gputexture(ima, textarget); | GPUTexture **tex = gpu_get_image_gputexture(ima, textarget, iuser->multiview_eye); | ||||
| if (*tex) { | if (*tex) { | ||||
| return *tex; | return *tex; | ||||
| } | } | ||||
| /* Check if we have a valid image. If not, we return a dummy | /* Check if we have a valid image. If not, we return a dummy | ||||
| * texture with zero bindcode so we don't keep trying. */ | * texture with zero bindcode so we don't keep trying. */ | ||||
| uint bindcode = 0; | uint bindcode = 0; | ||||
| ImageTile *tile = BKE_image_get_tile(ima, 0); | ImageTile *tile = BKE_image_get_tile(ima, 0); | ||||
| Show All 11 Lines | if (ibuf_intern == NULL) { | ||||
| return *tex; | return *tex; | ||||
| } | } | ||||
| } | } | ||||
| if (textarget == GL_TEXTURE_2D_ARRAY) { | if (textarget == GL_TEXTURE_2D_ARRAY) { | ||||
| bindcode = gpu_texture_create_tile_array(ima, ibuf_intern); | bindcode = gpu_texture_create_tile_array(ima, ibuf_intern); | ||||
| } | } | ||||
| else if (textarget == GL_TEXTURE_1D_ARRAY) { | else if (textarget == GL_TEXTURE_1D_ARRAY) { | ||||
| bindcode = gpu_texture_create_tile_mapping(ima); | bindcode = gpu_texture_create_tile_mapping(ima, iuser->multiview_eye); | ||||
| } | } | ||||
| else { | else { | ||||
| bindcode = gpu_texture_create_from_ibuf(ima, ibuf_intern, textarget); | bindcode = gpu_texture_create_from_ibuf(ima, ibuf_intern, textarget); | ||||
| } | } | ||||
| /* if `ibuf` was given, we don't own the `ibuf_intern` */ | /* if `ibuf` was given, we don't own the `ibuf_intern` */ | ||||
| if (ibuf == NULL) { | if (ibuf == NULL) { | ||||
| BKE_image_release_ibuf(ima, ibuf_intern, NULL); | BKE_image_release_ibuf(ima, ibuf_intern, NULL); | ||||
| ▲ Show 20 Lines • Show All 367 Lines • ▼ Show 20 Lines | #ifndef GPU_STANDALONE | ||||
| } | } | ||||
| GTS.texpaint = !mipmap; | GTS.texpaint = !mipmap; | ||||
| if (mipmap) { | if (mipmap) { | ||||
| for (Image *ima = bmain->images.first; ima; ima = ima->id.next) { | for (Image *ima = bmain->images.first; ima; ima = ima->id.next) { | ||||
| if (BKE_image_has_opengl_texture(ima)) { | if (BKE_image_has_opengl_texture(ima)) { | ||||
| if (ima->gpuflag & IMA_GPU_MIPMAP_COMPLETE) { | if (ima->gpuflag & IMA_GPU_MIPMAP_COMPLETE) { | ||||
| for (int eye = 0; eye < 2; eye++) { | |||||
| for (int a = 0; a < TEXTARGET_COUNT; a++) { | for (int a = 0; a < TEXTARGET_COUNT; a++) { | ||||
| if (ELEM(a, TEXTARGET_TEXTURE_2D, TEXTARGET_TEXTURE_2D_ARRAY)) { | if (ELEM(a, TEXTARGET_TEXTURE_2D, TEXTARGET_TEXTURE_2D_ARRAY)) { | ||||
| GPUTexture *tex = ima->gputexture[a]; | GPUTexture *tex = ima->gputexture[a][eye]; | ||||
| if (tex != NULL) { | if (tex != NULL) { | ||||
| GPU_texture_bind(tex, 0); | GPU_texture_bind(tex, 0); | ||||
| glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gpu_get_mipmap_filter(0)); | 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)); | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gpu_get_mipmap_filter(1)); | ||||
| GPU_texture_unbind(tex); | GPU_texture_unbind(tex); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | |||||
| else { | else { | ||||
| GPU_free_image(ima); | GPU_free_image(ima); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| ima->gpuflag &= ~IMA_GPU_MIPMAP_COMPLETE; | ima->gpuflag &= ~IMA_GPU_MIPMAP_COMPLETE; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| for (Image *ima = bmain->images.first; ima; ima = ima->id.next) { | for (Image *ima = bmain->images.first; ima; ima = ima->id.next) { | ||||
| if (BKE_image_has_opengl_texture(ima)) { | if (BKE_image_has_opengl_texture(ima)) { | ||||
| for (int eye = 0; eye < 2; eye++) { | |||||
| for (int a = 0; a < TEXTARGET_COUNT; a++) { | for (int a = 0; a < TEXTARGET_COUNT; a++) { | ||||
| if (ELEM(a, TEXTARGET_TEXTURE_2D, TEXTARGET_TEXTURE_2D_ARRAY)) { | if (ELEM(a, TEXTARGET_TEXTURE_2D, TEXTARGET_TEXTURE_2D_ARRAY)) { | ||||
| GPUTexture *tex = ima->gputexture[a]; | GPUTexture *tex = ima->gputexture[a][eye]; | ||||
| if (tex != NULL) { | if (tex != NULL) { | ||||
| GPU_texture_bind(tex, 0); | GPU_texture_bind(tex, 0); | ||||
| glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | ||||
| glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gpu_get_mipmap_filter(1)); | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gpu_get_mipmap_filter(1)); | ||||
| GPU_texture_unbind(tex); | GPU_texture_unbind(tex); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | |||||
| else { | else { | ||||
| ima->gpuflag &= ~IMA_GPU_MIPMAP_COMPLETE; | ima->gpuflag &= ~IMA_GPU_MIPMAP_COMPLETE; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| #endif /* GPU_STANDALONE */ | #endif /* GPU_STANDALONE */ | ||||
| } | } | ||||
| void GPU_paint_update_image(Image *ima, ImageUser *iuser, int x, int y, int w, int h) | void GPU_paint_update_image(Image *ima, ImageUser *iuser, int x, int y, int w, int h) | ||||
| { | { | ||||
| #ifndef GPU_STANDALONE | #ifndef GPU_STANDALONE | ||||
| ImBuf *ibuf = BKE_image_acquire_ibuf(ima, iuser, NULL); | ImBuf *ibuf = BKE_image_acquire_ibuf(ima, iuser, NULL); | ||||
| ImageTile *tile = BKE_image_get_tile_from_iuser(ima, iuser); | ImageTile *tile = BKE_image_get_tile_from_iuser(ima, iuser); | ||||
| if ((ibuf == NULL) || (w == 0) || (h == 0)) { | if ((ibuf == NULL) || (w == 0) || (h == 0)) { | ||||
| /* Full reload of texture. */ | /* Full reload of texture. */ | ||||
| GPU_free_image(ima); | GPU_free_image(ima); | ||||
| } | } | ||||
| GPUTexture *tex = ima->gputexture[TEXTARGET_TEXTURE_2D]; | GPUTexture *tex = ima->gputexture[TEXTARGET_TEXTURE_2D][0]; | ||||
| /* Check if we need to update the main gputexture. */ | /* Check if we need to update the main gputexture. */ | ||||
| if (tex != NULL && tile == ima->tiles.first) { | if (tex != NULL && tile == ima->tiles.first) { | ||||
| gpu_texture_update_from_ibuf(tex, ima, ibuf, NULL, x, y, w, h); | gpu_texture_update_from_ibuf(tex, ima, ibuf, NULL, x, y, w, h); | ||||
| } | } | ||||
| /* Check if we need to update the array gputexture. */ | /* Check if we need to update the array gputexture. */ | ||||
| tex = ima->gputexture[TEXTARGET_TEXTURE_2D_ARRAY]; | tex = ima->gputexture[TEXTARGET_TEXTURE_2D_ARRAY][0]; | ||||
| if (tex != NULL) { | if (tex != NULL) { | ||||
| gpu_texture_update_from_ibuf(tex, ima, ibuf, tile, x, y, w, h); | gpu_texture_update_from_ibuf(tex, ima, ibuf, tile, x, y, w, h); | ||||
| } | } | ||||
| BKE_image_release_ibuf(ima, ibuf, NULL); | BKE_image_release_ibuf(ima, ibuf, NULL); | ||||
| #endif | #endif | ||||
| } | } | ||||
| Show All 28 Lines | void GPU_free_unused_buffers(Main *bmain) | ||||
| BLI_linklist_free(image_free_queue, NULL); | BLI_linklist_free(image_free_queue, NULL); | ||||
| image_free_queue = NULL; | image_free_queue = NULL; | ||||
| BLI_mutex_unlock(&img_queue_mutex); | BLI_mutex_unlock(&img_queue_mutex); | ||||
| } | } | ||||
| static void gpu_free_image_immediate(Image *ima) | static void gpu_free_image_immediate(Image *ima) | ||||
| { | { | ||||
| for (int eye = 0; eye < 2; eye++) { | |||||
| for (int i = 0; i < TEXTARGET_COUNT; i++) { | for (int i = 0; i < TEXTARGET_COUNT; i++) { | ||||
| /* free glsl image binding */ | /* free glsl image binding */ | ||||
| if (ima->gputexture[i] != NULL) { | if (ima->gputexture[i][eye] != NULL) { | ||||
| GPU_texture_free(ima->gputexture[i]); | GPU_texture_free(ima->gputexture[i][eye]); | ||||
| ima->gputexture[i] = NULL; | ima->gputexture[i][eye] = NULL; | ||||
| } | |||||
| } | } | ||||
| } | } | ||||
| ima->gpuflag &= ~(IMA_GPU_MIPMAP_COMPLETE); | ima->gpuflag &= ~(IMA_GPU_MIPMAP_COMPLETE); | ||||
| } | } | ||||
| void GPU_free_image(Image *ima) | void GPU_free_image(Image *ima) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 129 Lines • Show Last 20 Lines | |||||