Skip to content

Commit

Permalink
Finally figured out how to implement AnimatedTexture properly.
Browse files Browse the repository at this point in the history
  • Loading branch information
reduz committed Jul 16, 2018
1 parent 9eb0820 commit de910f8
Show file tree
Hide file tree
Showing 18 changed files with 483 additions and 3 deletions.
1 change: 1 addition & 0 deletions drivers/dummy/rasterizer_dummy.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ class RasterizerStorageDummy : public RasterizerStorage {
void textures_keep_original(bool p_enable) {}

void texture_set_proxy(RID p_proxy, RID p_base) {}
void texture_set_force_redraw_if_visible(RID p_texture, bool p_enable) {}

/* SKY API */

Expand Down
8 changes: 8 additions & 0 deletions drivers/gles2/rasterizer_canvas_gles2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ RasterizerStorageGLES2::Texture *RasterizerCanvasGLES2::_bind_canvas_texture(con

texture = texture->get_ptr();

if (texture->redraw_if_visible) {
VisualServerRaster::redraw_request();
}

if (texture->render_target) {
texture->render_target->used_in_frame = true;
}
Expand Down Expand Up @@ -909,6 +913,10 @@ void RasterizerCanvasGLES2::canvas_render_items(Item *p_item_list, int p_z, cons

t = t->get_ptr();

if (t->redraw_if_visible) {
VisualServerRaster::redraw_request();
}

glBindTexture(t->target, t->tex_id);
}
} else {
Expand Down
9 changes: 9 additions & 0 deletions drivers/gles2/rasterizer_storage_gles2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,15 @@ void RasterizerStorageGLES2::texture_set_proxy(RID p_texture, RID p_proxy) {
}
}

void RasterizerStorageGLES2::texture_set_force_redraw_if_visible(RID p_texture, bool p_enable) {

Texture *texture = texture_owner.getornull(p_texture);
ERR_FAIL_COND(!texture);

texture->redraw_if_visible = p_enable;

}

void RasterizerStorageGLES2::texture_set_detect_3d_callback(RID p_texture, VisualServer::TextureDetectCallback p_callback, void *p_userdata) {
// TODO
}
Expand Down
7 changes: 7 additions & 0 deletions drivers/gles2/rasterizer_storage_gles2.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,15 @@ class RasterizerStorageGLES2 : public RasterizerStorage {
bool active;
GLenum tex_id;


uint16_t stored_cube_sides;

RenderTarget *render_target;

Ref<Image> images[6];

bool redraw_if_visible;

Texture() {
flags = 0;
width = 0;
Expand All @@ -205,6 +208,8 @@ class RasterizerStorageGLES2 : public RasterizerStorage {
proxy = NULL;

render_target = NULL;

redraw_if_visible = false;
}

_ALWAYS_INLINE_ Texture *get_ptr() {
Expand Down Expand Up @@ -264,6 +269,8 @@ class RasterizerStorageGLES2 : public RasterizerStorage {
virtual void texture_set_detect_srgb_callback(RID p_texture, VisualServer::TextureDetectCallback p_callback, void *p_userdata);
virtual void texture_set_detect_normal_callback(RID p_texture, VisualServer::TextureDetectCallback p_callback, void *p_userdata);

virtual void texture_set_force_redraw_if_visible(RID p_texture, bool p_enable);

/* SKY API */

virtual RID sky_create();
Expand Down
12 changes: 12 additions & 0 deletions drivers/gles3/rasterizer_canvas_gles3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ RasterizerStorageGLES3::Texture *RasterizerCanvasGLES3::_bind_canvas_texture(con

} else {

if (texture->redraw_if_visible) { //check before proxy, because this is usually used with proxies
VisualServerRaster::redraw_request();
}

texture = texture->get_ptr();

if (texture->render_target)
Expand Down Expand Up @@ -248,6 +252,10 @@ RasterizerStorageGLES3::Texture *RasterizerCanvasGLES3::_bind_canvas_texture(con

} else {

if (normal_map->redraw_if_visible) { //check before proxy, because this is usually used with proxies
VisualServerRaster::redraw_request();
}

normal_map = normal_map->get_ptr();
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, normal_map->tex_id);
Expand Down Expand Up @@ -1266,6 +1274,10 @@ void RasterizerCanvasGLES3::canvas_render_items(Item *p_item_list, int p_z, cons
continue;
}

if (t->redraw_if_visible) { //check before proxy, because this is usually used with proxies
VisualServerRaster::redraw_request();
}

t = t->get_ptr();

if (storage->config.srgb_decode_supported && t->using_srgb) {
Expand Down
10 changes: 10 additions & 0 deletions drivers/gles3/rasterizer_scene_gles3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1225,7 +1225,12 @@ bool RasterizerSceneGLES3::_setup_material(RasterizerStorageGLES3::Material *p_m

} else {

if (t->redraw_if_visible) { //must check before proxy because this is often used with proxies
VisualServerRaster::redraw_request();
}

t = t->get_ptr(); //resolve for proxies

#ifdef TOOLS_ENABLED
if (t->detect_3d) {
t->detect_3d(t->detect_3d_ud);
Expand Down Expand Up @@ -1569,6 +1574,11 @@ void RasterizerSceneGLES3::_render_geometry(RenderList::Element *e) {
RasterizerStorageGLES3::Texture *t = storage->texture_owner.get(c.texture);

t = t->get_ptr(); //resolve for proxies

if (t->redraw_if_visible) {
VisualServerRaster::redraw_request();
}

#ifdef TOOLS_ENABLED
if (t->detect_3d) {
t->detect_3d(t->detect_3d_ud);
Expand Down
7 changes: 7 additions & 0 deletions drivers/gles3/rasterizer_storage_gles3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1328,6 +1328,13 @@ void RasterizerStorageGLES3::texture_set_proxy(RID p_texture, RID p_proxy) {
}
}

void RasterizerStorageGLES3::texture_set_force_redraw_if_visible(RID p_texture, bool p_enable) {

Texture *texture = texture_owner.get(p_texture);
ERR_FAIL_COND(!texture);
texture->redraw_if_visible = p_enable;
}

RID RasterizerStorageGLES3::sky_create() {

Sky *sky = memnew(Sky);
Expand Down
3 changes: 3 additions & 0 deletions drivers/gles3/rasterizer_storage_gles3.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ class RasterizerStorageGLES3 : public RasterizerStorage {
GLuint tex_id;

bool using_srgb;
bool redraw_if_visible;

uint16_t stored_cube_sides;

Expand Down Expand Up @@ -306,6 +307,7 @@ class RasterizerStorageGLES3 : public RasterizerStorage {
detect_normal = NULL;
detect_normal_ud = NULL;
proxy = NULL;
redraw_if_visible = false;
}

_ALWAYS_INLINE_ Texture *get_ptr() {
Expand Down Expand Up @@ -366,6 +368,7 @@ class RasterizerStorageGLES3 : public RasterizerStorage {
virtual void texture_set_detect_normal_callback(RID p_texture, VisualServer::TextureDetectCallback p_callback, void *p_userdata);

virtual void texture_set_proxy(RID p_texture, RID p_proxy);
virtual void texture_set_force_redraw_if_visible(RID p_texture, bool p_enable);

/* SKY API */

Expand Down
74 changes: 74 additions & 0 deletions editor/icons/icon_animated_texture.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
69 changes: 69 additions & 0 deletions editor/icons/icon_new_root.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions scene/register_scene_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,7 @@ void register_scene_types() {
ClassDB::register_class<CurveTexture>();
ClassDB::register_class<GradientTexture>();
ClassDB::register_class<ProxyTexture>();
ClassDB::register_class<AnimatedTexture>();
ClassDB::register_class<CubeMap>();
ClassDB::register_class<Animation>();
ClassDB::register_virtual_class<Font>();
Expand Down
Loading

0 comments on commit de910f8

Please sign in to comment.