Added support for animated texture draw, GLSL textures.

Note, this is not like GE ffmpg, but Blender Image Texture
display for GLSL materials. Speed can be disappointing,
use smaller images for realtime edits.
This commit is contained in:
Ton Roosendaal
2010-02-13 13:09:30 +00:00
parent c1ee920db6
commit b673f7318c
11 changed files with 56 additions and 20 deletions

View File

@@ -1656,6 +1656,10 @@ static ImBuf *image_load_sequence_file(Image *ima, ImageUser *iuser, int frame)
unsigned short numlen;
char name[FILE_MAX], head[FILE_MAX], tail[FILE_MAX];
/* XXX temp stuff? */
if(ima->lastframe != frame)
ima->tpageflag |= IMA_TPAGE_REFRESH;
ima->lastframe= frame;
BLI_stringdec(ima->name, head, tail, &numlen);
@@ -2034,6 +2038,11 @@ static ImBuf *image_get_ibuf_threadsafe(Image *ima, ImageUser *iuser, int *frame
if(ima->type==IMA_TYPE_IMAGE) {
frame= iuser?iuser->framenr:ima->lastframe;
ibuf= image_get_ibuf(ima, 0, frame);
/* XXX temp stuff? */
if(ima->lastframe != frame)
ima->tpageflag |= IMA_TPAGE_REFRESH;
ima->lastframe = frame;
}
else if(ima->type==IMA_TYPE_MULTILAYER) {
frame= iuser?iuser->framenr:ima->lastframe;

View File

@@ -56,6 +56,9 @@ int ED_space_image_show_paint(struct SpaceImage *sima);
int ED_space_image_show_uvedit(struct SpaceImage *sima, struct Object *obedit);
int ED_space_image_show_uvshadow(struct SpaceImage *sima, struct Object *obedit);
/* UI level image (texture) updating... render calls own stuff (too) */
void ED_image_update_frame(const struct bContext *C);
/* image_render.c, export for screen_ops.c, render operator */
void ED_space_image_output(struct bContext *C);

View File

@@ -51,6 +51,7 @@
#include "WM_api.h"
#include "WM_types.h"
#include "ED_image.h"
#include "ED_screen.h"
#include "ED_screen_types.h"
@@ -1761,6 +1762,9 @@ void ED_update_for_newframe(const bContext *C, int mute)
if(scene->use_nodes && scene->nodetree)
ntreeCompositTagAnimated(scene->nodetree);
/* update animated image textures for gpu, etc */
ED_image_update_frame(C);
/* update animated texture nodes */
{
Tex *tex;
@@ -1769,6 +1773,7 @@ void ED_update_for_newframe(const bContext *C, int mute)
ntreeTexTagAnimated( tex->nodetree );
}
}
}

View File

@@ -37,6 +37,7 @@
#include "DNA_space_types.h"
#include "DNA_scene_types.h"
#include "DNA_screen_types.h"
#include "DNA_texture_types.h"
#include "DNA_userdef_types.h"
#include "DNA_windowmanager_types.h"
@@ -44,7 +45,9 @@
#include "BKE_context.h"
#include "BKE_image.h"
#include "BKE_global.h"
#include "BKE_image.h"
#include "BKE_library.h"
#include "BKE_main.h"
#include "BKE_node.h"
#include "BKE_packedFile.h"
#include "BKE_report.h"
@@ -1839,20 +1842,26 @@ void IMAGE_OT_cycle_render_slot(wmOperatorType *ot)
/******************** TODO ********************/
/* XXX notifier? */
#if 0
/* goes over all ImageUsers, and sets frame numbers if auto-refresh is set */
void BIF_image_update_frame(void)
void ED_image_update_frame(const bContext *C)
{
Main *mainp = CTX_data_main(C);
Scene *scene= CTX_data_scene(C);
Tex *tex;
/* texture users */
for(tex= G.main->tex.first; tex; tex= tex->id.next) {
if(tex->type==TEX_IMAGE && tex->ima)
if(ELEM(tex->ima->source, IMA_SRC_MOVIE, IMA_SRC_SEQUENCE))
for(tex= mainp->tex.first; tex; tex= tex->id.next) {
if(tex->type==TEX_IMAGE && tex->ima) {
if(ELEM(tex->ima->source, IMA_SRC_MOVIE, IMA_SRC_SEQUENCE)) {
if(tex->iuser.flag & IMA_ANIM_ALWAYS)
BKE_image_user_calc_imanr(&tex->iuser, scene->r.cfra, 0);
BKE_image_user_calc_frame(&tex->iuser, scene->r.cfra, 0);
}
}
}
#if 0
/* image window, compo node users */
if(G.curscreen) {
ScrArea *sa;
@@ -1861,12 +1870,12 @@ void BIF_image_update_frame(void)
View3D *v3d= sa->spacedata.first;
if(v3d->bgpic)
if(v3d->bgpic->iuser.flag & IMA_ANIM_ALWAYS)
BKE_image_user_calc_imanr(&v3d->bgpic->iuser, scene->r.cfra, 0);
BKE_image_user_calc_frame(&v3d->bgpic->iuser, scene->r.cfra, 0);
}
else if(sa->spacetype==SPACE_IMAGE) {
SpaceImage *sima= sa->spacedata.first;
if(sima->iuser.flag & IMA_ANIM_ALWAYS)
BKE_image_user_calc_imanr(&sima->iuser, scene->r.cfra, 0);
BKE_image_user_calc_frame(&sima->iuser, scene->r.cfra, 0);
}
else if(sa->spacetype==SPACE_NODE) {
SpaceNode *snode= sa->spacedata.first;
@@ -1878,14 +1887,15 @@ void BIF_image_update_frame(void)
ImageUser *iuser= node->storage;
if(ELEM(ima->source, IMA_SRC_MOVIE, IMA_SRC_SEQUENCE))
if(iuser->flag & IMA_ANIM_ALWAYS)
BKE_image_user_calc_imanr(iuser, scene->r.cfra, 0);
BKE_image_user_calc_frame(iuser, scene->r.cfra, 0);
}
}
}
}
}
}
}
#endif
}

View File

@@ -883,7 +883,7 @@ void space_view3d_listener(struct ScrArea *area, struct wmNotifier *wmn)
for (; bgpic; bgpic = bgpic->next) {
if (bgpic->ima) {
Scene *scene = wmn->reference;
BKE_image_user_calc_imanr(&bgpic->iuser, scene->r.cfra, 0);
BKE_image_user_calc_frame(&bgpic->iuser, scene->r.cfra, 0);
}
}
}

View File

@@ -38,6 +38,7 @@ extern "C" {
#endif
struct Image;
struct ImageUser;
struct MTFace;
struct Object;
struct Scene;
@@ -113,7 +114,7 @@ void GPU_paint_set_mipmap(int mipmap);
void GPU_paint_update_image(struct Image *ima, int x, int y, int w, int h, int mipmap);
void GPU_update_images_framechange(void);
int GPU_update_image_time(struct Image *ima, double time);
int GPU_verify_image(struct Image *ima, int tftile, int tfmode, int compare, int mipmap);
int GPU_verify_image(struct Image *ima, struct ImageUser *iuser, int tftile, int tfmode, int compare, int mipmap);
void GPU_free_image(struct Image *ima);
void GPU_free_images(void);

View File

@@ -997,6 +997,7 @@ static void gpu_node_input_link(GPUNode *node, GPUNodeLink *link, int type)
input->source = GPU_SOURCE_TEX;
input->ima = link->ptr1;
input->iuser = link->ptr2;
input->textarget = GL_TEXTURE_2D;
input->textype = GPU_TEX2D;
MEM_freeN(link);

View File

@@ -392,7 +392,7 @@ static void gpu_verify_reflection(Image *ima)
}
}
int GPU_verify_image(Image *ima, int tftile, int tfmode, int compare, int mipmap)
int GPU_verify_image(Image *ima, ImageUser *iuser, int tftile, int tfmode, int compare, int mipmap)
{
ImBuf *ibuf = NULL;
unsigned int *bind = NULL;
@@ -444,7 +444,7 @@ int GPU_verify_image(Image *ima, int tftile, int tfmode, int compare, int mipmap
return 0;
/* check if we have a valid image buffer */
ibuf= BKE_image_get_ibuf(ima, NULL);
ibuf= BKE_image_get_ibuf(ima, iuser);
if(ibuf==NULL)
return 0;
@@ -453,6 +453,12 @@ int GPU_verify_image(Image *ima, int tftile, int tfmode, int compare, int mipmap
if ((ibuf->rect==NULL) && ibuf->rect_float)
IMB_rect_from_float(ibuf);
/* currently, tpage refresh is used by ima sequences */
if(ima->tpageflag & IMA_TPAGE_REFRESH) {
GPU_free_image(ima);
ima->tpageflag &= ~IMA_TPAGE_REFRESH;
}
if(GTS.tilemode) {
/* tiled mode */
if(ima->repbind==0) gpu_make_repbind(ima);
@@ -585,7 +591,7 @@ int GPU_set_tpage(MTFace *tface, int mipmap)
gpu_verify_alpha_mode(tface);
gpu_verify_reflection(ima);
if(GPU_verify_image(ima, tface->tile, tface->mode, 1, mipmap)) {
if(GPU_verify_image(ima, NULL, tface->tile, tface->mode, 1, mipmap)) {
GTS.curtile= GTS.tile;
GTS.curima= GTS.ima;
GTS.curtilemode= GTS.tilemode;

View File

@@ -471,7 +471,7 @@ GPUTexture *GPU_texture_from_blender(Image *ima, ImageUser *iuser, double time,
glGetIntegerv(GL_TEXTURE_BINDING_2D, &lastbindcode);
GPU_update_image_time(ima, time);
bindcode = GPU_verify_image(ima, 0, 0, 0, mipmap);
bindcode = GPU_verify_image(ima, iuser, 0, 0, 0, mipmap);
if(ima->gputexture) {
ima->gputexture->bindcode = bindcode;

View File

@@ -960,7 +960,7 @@ static void do_material_tex(GPUShadeInput *shi)
rgbnor = 0;
if(tex && tex->type == TEX_IMAGE && tex->ima) {
GPU_link(mat, "mtex_image", texco, GPU_image(tex->ima, NULL), &tin, &trgb, &tnor);
GPU_link(mat, "mtex_image", texco, GPU_image(tex->ima, &tex->iuser), &tin, &trgb, &tnor);
rgbnor= TEX_RGB;
if(tex->imaflag & TEX_USEALPHA)

View File

@@ -118,8 +118,9 @@ typedef struct Image {
#define IMA_TWINANIM 2
#define IMA_COLCYCLE 4 /* Depreciated */
#define IMA_MIPMAP_COMPLETE 8 /* all mipmap levels in OpenGL texture set? */
#define IMA_CLAMP_U 16
#define IMA_CLAMP_V 32
#define IMA_CLAMP_U 16
#define IMA_CLAMP_V 32
#define IMA_TPAGE_REFRESH 64
/* ima->type and ima->source moved to BKE_image.h, for API */