Merge branch 'master' of github.com:okamstudio/godot

Conflicts:
	platform/x11/detect.py
This commit is contained in:
Anton Yabchinskiy 2015-01-14 23:17:15 +03:00
commit d6998995b5
78 changed files with 2516 additions and 8027 deletions

View File

@ -847,8 +847,15 @@ void ObjectTypeDB::set_type_enabled(StringName p_type,bool p_enable) {
bool ObjectTypeDB::is_type_enabled(StringName p_type) {
ERR_FAIL_COND_V(!types.has(p_type),false);
return !types[p_type].disabled;
TypeInfo *ti=types.getptr(p_type);
if (!ti || !ti->creation_func) {
if (compat_types.has(p_type)) {
ti=types.getptr(compat_types[p_type]);
}
}
ERR_FAIL_COND_V(!ti,false);
return !ti->disabled;
}
StringName ObjectTypeDB::get_category(const StringName& p_node) {

Binary file not shown.

View File

@ -15,6 +15,7 @@ const GRAVITY = 500.0
#consider "floor".
const FLOOR_ANGLE_TOLERANCE = 40
const WALK_FORCE = 600
const WALK_MIN_SPEED=10
const WALK_MAX_SPEED = 200
const STOP_FORCE = 1300
const JUMP_SPEED = 200
@ -40,12 +41,12 @@ func _fixed_process(delta):
var stop=true
if (walk_left):
if (velocity.x<=0 and velocity.x > -WALK_MAX_SPEED):
if (velocity.x<=WALK_MIN_SPEED and velocity.x > -WALK_MAX_SPEED):
force.x-=WALK_FORCE
stop=false
elif (walk_right):
if (velocity.x>=0 and velocity.x < WALK_MAX_SPEED):
if (velocity.x>=-WALK_MIN_SPEED and velocity.x < WALK_MAX_SPEED):
force.x+=WALK_FORCE
stop=false

Binary file not shown.

File diff suppressed because one or more lines are too long

View File

@ -12,7 +12,7 @@
#include "context_gl.h"
#if defined(OPENGL_ENABLED) || defined(LEGACYGL_ENABLED) || defined(GLES2_ENABLED) || defined(GLES1_ENABLED)
#if defined(OPENGL_ENABLED) || defined(GLES2_ENABLED)

View File

@ -29,7 +29,7 @@
#ifndef CONTEXT_GL_H
#define CONTEXT_GL_H
#if defined(OPENGL_ENABLED) || defined(LEGACYGL_ENABLED) || defined(GLES2_ENABLED) || defined(GLES1_ENABLED)
#if defined(OPENGL_ENABLED) || defined(GLES2_ENABLED)
#include "typedefs.h"

View File

@ -1,5 +0,0 @@
Import('env')
Export('env');
env.add_source_files(env.drivers_sources,"*.cpp")

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1411,6 +1411,9 @@ void RasterizerGLES2::shader_set_mode(RID p_shader,VS::ShaderMode p_mode) {
case VS::SHADER_MATERIAL: {
material_shader.free_custom_shader(shader->custom_code_id);
} break;
case VS::SHADER_CANVAS_ITEM: {
canvas_shader.free_custom_shader(shader->custom_code_id);
} break;
}
shader->custom_code_id=0;
@ -1422,6 +1425,9 @@ void RasterizerGLES2::shader_set_mode(RID p_shader,VS::ShaderMode p_mode) {
case VS::SHADER_MATERIAL: {
shader->custom_code_id=material_shader.create_custom_shader();
} break;
case VS::SHADER_CANVAS_ITEM: {
shader->custom_code_id=canvas_shader.create_custom_shader();
} break;
}
_shader_make_dirty(shader);
@ -1558,6 +1564,7 @@ void RasterizerGLES2::shader_set_default_texture_param(RID p_shader, const Strin
RID RasterizerGLES2::shader_get_default_texture_param(RID p_shader, const StringName& p_name) const{
const Shader *shader=shader_owner.get(p_shader);
ERR_FAIL_COND_V(!shader,RID());
const Map<StringName,RID>::Element *E=shader->default_textures.find(p_name);
if (!E)
@ -1565,6 +1572,22 @@ RID RasterizerGLES2::shader_get_default_texture_param(RID p_shader, const String
return E->get();
}
Variant RasterizerGLES2::shader_get_default_param(RID p_shader, const StringName& p_name) {
Shader *shader=shader_owner.get(p_shader);
ERR_FAIL_COND_V(!shader,Variant());
//update shader params if necesary
//make sure the shader is compiled and everything
//so the actual parameters can be properly retrieved!
if (shader->dirty_list.in_list()) {
_update_shader(shader);
}
if (shader->valid && shader->uniforms.has(p_name))
return shader->uniforms[p_name].default_value;
return Variant();
}
/* COMMON MATERIAL API */
@ -4434,6 +4457,13 @@ void RasterizerGLES2::_update_shader( Shader* p_shader) const {
if (err) {
return; //invalid
}
} else if (p_shader->mode==VS::SHADER_CANVAS_ITEM) {
Error err = shader_precompiler.compile(p_shader->vertex_code,ShaderLanguage::SHADER_CANVAS_ITEM_VERTEX,vertex_code,vertex_globals,vertex_flags,&p_shader->uniforms);
if (err) {
return; //invalid
}
}
//print_line("compiled vertex: "+vertex_code);
@ -4443,9 +4473,16 @@ void RasterizerGLES2::_update_shader( Shader* p_shader) const {
String fragment_code;
String fragment_globals;
Error err = shader_precompiler.compile(p_shader->fragment_code,(p_shader->mode==VS::SHADER_MATERIAL?ShaderLanguage::SHADER_MATERIAL_FRAGMENT:ShaderLanguage::SHADER_POST_PROCESS),fragment_code,fragment_globals,fragment_flags,&p_shader->uniforms);
if (err) {
return; //invalid
if (p_shader->mode==VS::SHADER_MATERIAL) {
Error err = shader_precompiler.compile(p_shader->fragment_code,ShaderLanguage::SHADER_MATERIAL_FRAGMENT,fragment_code,fragment_globals,fragment_flags,&p_shader->uniforms);
if (err) {
return; //invalid
}
} else if (p_shader->mode==VS::SHADER_CANVAS_ITEM) {
Error err = shader_precompiler.compile(p_shader->fragment_code,ShaderLanguage::SHADER_CANVAS_ITEM_FRAGMENT,fragment_code,fragment_globals,fragment_flags,&p_shader->uniforms);
if (err) {
return; //invalid
}
}
@ -4458,6 +4495,11 @@ void RasterizerGLES2::_update_shader( Shader* p_shader) const {
if (err) {
return; //invalid
}
} else if (p_shader->mode==VS::SHADER_CANVAS_ITEM) {
Error err = shader_precompiler.compile(p_shader->light_code,(ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT),light_code,light_globals,light_flags,&p_shader->uniforms);
if (err) {
return; //invalid
}
}
fragment_globals+=light_globals; //both fragment anyway
@ -4518,7 +4560,36 @@ void RasterizerGLES2::_update_shader( Shader* p_shader) const {
}
material_shader.set_custom_shader_code(p_shader->custom_code_id,vertex_code, vertex_globals,fragment_code, light_code, fragment_globals,uniform_names,enablers);
} else {
} else if (p_shader->mode==VS::SHADER_CANVAS_ITEM) {
Vector<const char*> enablers;
if (light_flags.uses_time || fragment_flags.uses_time || vertex_flags.uses_time) {
enablers.push_back("#define USE_TIME\n");
uses_time=true;
}
if (fragment_flags.uses_normal) {
enablers.push_back("#define NORMAL_USED\n");
}
if (light_flags.uses_light) {
enablers.push_back("#define USE_LIGHT_SHADER_CODE\n");
}
if (fragment_flags.use_var1_interp || vertex_flags.use_var1_interp)
enablers.push_back("#define ENABLE_VAR1_INTERP\n");
if (fragment_flags.use_var2_interp || vertex_flags.use_var2_interp)
enablers.push_back("#define ENABLE_VAR2_INTERP\n");
if (fragment_flags.uses_texscreen) {
enablers.push_back("#define ENABLE_TEXSCREEN\n");
}
if (fragment_flags.uses_screen_uv) {
enablers.push_back("#define ENABLE_SCREEN_UV\n");
}
if (fragment_flags.uses_texpixel_size) {
enablers.push_back("#define USE_TEXPIXEL_SIZE\n");
}
canvas_shader.set_custom_shader_code(p_shader->custom_code_id,vertex_code, vertex_globals,fragment_code, light_code, fragment_globals,uniform_names,enablers);
//postprocess_shader.set_custom_shader_code(p_shader->custom_code_id,vertex_code, vertex_globals,fragment_code, fragment_globals,uniform_names);
}
@ -4529,7 +4600,9 @@ void RasterizerGLES2::_update_shader( Shader* p_shader) const {
p_shader->has_texscreen=fragment_flags.uses_texscreen;
p_shader->has_screen_uv=fragment_flags.uses_screen_uv;
p_shader->can_zpass=!fragment_flags.uses_discard && !vertex_flags.vertex_code_writes_vertex;
p_shader->uses_normal=fragment_flags.uses_normal || light_flags.uses_normal;
p_shader->uses_time=uses_time;
p_shader->uses_texpixel_size=fragment_flags.uses_texpixel_size;
p_shader->version++;
}
@ -4888,7 +4961,7 @@ _FORCE_INLINE_ void RasterizerGLES2::_update_material_shader_params(Material *p_
keep=false;
else if (old_mparams[E->key()].value.get_type()!=E->value().default_value.get_type()) {
//type changed between old and new
/*if (old_mparams[E->key()].value.get_type()==Variant::OBJECT) {
/* if (old_mparams[E->key()].value.get_type()==Variant::OBJECT) {
if (E->value().default_value.get_type()!=Variant::_RID) //hackfor textures
keep=false;
} else if (!old_mparams[E->key()].value.is_num() || !E->value().default_value.get_type())
@ -5068,6 +5141,7 @@ bool RasterizerGLES2::_setup_material(const Geometry *p_geometry,const Material
if (p_material->shader_cache->has_texscreen && framebuffer.active) {
material_shader.set_uniform(MaterialShaderGLES2::TEXSCREEN_SCREEN_MULT,Vector2(float(viewport.width)/framebuffer.width,float(viewport.height)/framebuffer.height));
material_shader.set_uniform(MaterialShaderGLES2::TEXSCREEN_SCREEN_CLAMP,Color(0,0,float(viewport.width)/framebuffer.width,float(viewport.height)/framebuffer.height));
material_shader.set_uniform(MaterialShaderGLES2::TEXSCREEN_TEX,texcoord);
glActiveTexture(GL_TEXTURE0+texcoord);
glBindTexture(GL_TEXTURE_2D,framebuffer.sample_color);
@ -7722,10 +7796,11 @@ void RasterizerGLES2::canvas_begin() {
canvas_tex=RID();
//material_shader.unbind();
canvas_shader.unbind();
canvas_shader.set_custom_shader(0);
canvas_shader.bind();
canvas_shader.set_uniform(CanvasShaderGLES2::TEXTURE, 0);
_set_color_attrib(Color(1,1,1));
Transform canvas_transform;
canvas_transform=Transform();
canvas_transform.translate(-(viewport.width / 2.0f), -(viewport.height / 2.0f), 0.0f);
float csy = 1.0;
if (current_rt && current_rt_vflip)
@ -7739,6 +7814,9 @@ void RasterizerGLES2::canvas_begin() {
canvas_opacity=1.0;
canvas_blend_mode=VS::MATERIAL_BLEND_MODE_MIX;
canvas_texscreen_used=false;
uses_texpixel_size=false;
canvas_last_shader=RID();
}
@ -7821,7 +7899,7 @@ void RasterizerGLES2::canvas_end_rect() {
RasterizerGLES2::Texture* RasterizerGLES2::_bind_canvas_texture(const RID& p_texture) {
if (p_texture==canvas_tex) {
if (p_texture==canvas_tex && !rebind_texpixel_size) {
if (canvas_tex.is_valid()) {
Texture*texture=texture_owner.get(p_texture);
return texture;
@ -7829,14 +7907,16 @@ RasterizerGLES2::Texture* RasterizerGLES2::_bind_canvas_texture(const RID& p_tex
return NULL;
}
rebind_texpixel_size=false;
if (p_texture.is_valid()) {
Texture*texture=texture_owner.get(p_texture);
if (!texture) {
canvas_tex=RID();
glBindTexture(GL_TEXTURE_2D,white_tex);
return NULL;
}
@ -7845,6 +7925,9 @@ RasterizerGLES2::Texture* RasterizerGLES2::_bind_canvas_texture(const RID& p_tex
glBindTexture(GL_TEXTURE_2D,texture->tex_id);
canvas_tex=p_texture;
if (uses_texpixel_size) {
canvas_shader.set_uniform(CanvasShaderGLES2::TEXPIXEL_SIZE,Size2(1.0/texture->width,1.0/texture->height));
}
return texture;
@ -8215,6 +8298,327 @@ void RasterizerGLES2::canvas_set_transform(const Matrix32& p_transform) {
//canvas_transform = Variant(p_transform);
}
void RasterizerGLES2::canvas_render_items(CanvasItem *p_item_list) {
CanvasItem *current_clip=NULL;
canvas_opacity=1.0;
while(p_item_list) {
CanvasItem *ci=p_item_list;
if (ci->vp_render) {
if (draw_viewport_func) {
draw_viewport_func(ci->vp_render->owner,ci->vp_render->udata,ci->vp_render->rect);
}
memdelete(ci->vp_render);
ci->vp_render=NULL;
canvas_last_shader=RID();
}
if (current_clip!=ci->final_clip_owner) {
current_clip=ci->final_clip_owner;
//setup clip
if (current_clip) {
glEnable(GL_SCISSOR_TEST);
glScissor(viewport.x+current_clip->final_clip_rect.pos.x,viewport.y+ (viewport.height-(current_clip->final_clip_rect.pos.y+current_clip->final_clip_rect.size.height)),
current_clip->final_clip_rect.size.width,current_clip->final_clip_rect.size.height);
} else {
glDisable(GL_SCISSOR_TEST);
}
}
//begin rect
CanvasItem *shader_owner = ci->shader_owner?ci->shader_owner:ci;
if (shader_owner->shader!=canvas_last_shader) {
Shader *shader = NULL;
if (shader_owner->shader.is_valid()) {
shader = this->shader_owner.get(shader_owner->shader);
if (shader && !shader->valid) {
shader=NULL;
}
}
if (shader) {
canvas_shader.set_custom_shader(shader->custom_code_id);
if (canvas_shader.bind())
rebind_texpixel_size=true;
if (shader_owner->shader_version!=shader->version) {
//todo optimize uniforms
shader_owner->shader_version=shader->version;
}
//this can be optimized..
int tex_id=1;
int idx=0;
for(Map<StringName,ShaderLanguage::Uniform>::Element *E=shader->uniforms.front();E;E=E->next()) {
Map<StringName,Variant>::Element *F=shader_owner->shader_param.find(E->key());
Variant &v=F?F->get():E->get().default_value;
if (v.get_type()==Variant::_RID || v.get_type()==Variant::OBJECT) {
int loc = canvas_shader.get_custom_uniform_location(idx); //should be automatic..
glActiveTexture(GL_TEXTURE0+tex_id);
RID tex = v;
Texture *t=texture_owner.get(tex);
if (!t)
glBindTexture(GL_TEXTURE_2D,white_tex);
else
glBindTexture(t->target,t->tex_id);
glUniform1i(loc,tex_id);
tex_id++;
} else {
canvas_shader.set_custom_uniform(idx,v);
}
idx++;
}
if (shader->has_texscreen && framebuffer.active) {
int x = viewport.x;
int y = window_size.height-(viewport.height+viewport.y);
canvas_shader.set_uniform(CanvasShaderGLES2::TEXSCREEN_SCREEN_MULT,Vector2(float(viewport.width)/framebuffer.width,float(viewport.height)/framebuffer.height));
canvas_shader.set_uniform(CanvasShaderGLES2::TEXSCREEN_SCREEN_CLAMP,Color(float(x)/framebuffer.width,float(y)/framebuffer.height,float(x+viewport.width)/framebuffer.width,float(y+viewport.height)/framebuffer.height));
canvas_shader.set_uniform(CanvasShaderGLES2::TEXSCREEN_TEX,tex_id);
glActiveTexture(GL_TEXTURE0+tex_id);
glBindTexture(GL_TEXTURE_2D,framebuffer.sample_color);
if (framebuffer.scale==1 && !canvas_texscreen_used) {
#ifdef GLEW_ENABLED
glReadBuffer(GL_COLOR_ATTACHMENT0);
#endif
glCopyTexSubImage2D(GL_TEXTURE_2D,0,x,y,x,y,viewport.width,viewport.height);
if (current_clip) {
print_line(" a clip ");
}
canvas_texscreen_used=true;
}
tex_id++;
}
if (tex_id>1) {
glActiveTexture(GL_TEXTURE0);
}
if (shader->has_screen_uv) {
canvas_shader.set_uniform(CanvasShaderGLES2::SCREEN_UV_MULT,Vector2(1.0/viewport.width,1.0/viewport.height));
}
if (shader->uses_time) {
canvas_shader.set_uniform(CanvasShaderGLES2::TIME,Math::fmod(last_time,300.0));
draw_next_frame=true;
}
//if uses TIME - draw_next_frame=true
uses_texpixel_size=shader->uses_texpixel_size;
} else {
canvas_shader.set_custom_shader(0);
canvas_shader.bind();
uses_texpixel_size=false;
}
canvas_shader.set_uniform(CanvasShaderGLES2::PROJECTION_MATRIX,canvas_transform);
canvas_last_shader=shader_owner->shader;
}
canvas_shader.set_uniform(CanvasShaderGLES2::MODELVIEW_MATRIX,ci->final_transform);
canvas_shader.set_uniform(CanvasShaderGLES2::EXTRA_MATRIX,Matrix32());
bool reclip=false;
if (ci==p_item_list || ci->blend_mode!=canvas_blend_mode) {
switch(ci->blend_mode) {
case VS::MATERIAL_BLEND_MODE_MIX: {
glBlendEquation(GL_FUNC_ADD);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
} break;
case VS::MATERIAL_BLEND_MODE_ADD: {
glBlendEquation(GL_FUNC_ADD);
glBlendFunc(GL_SRC_ALPHA,GL_ONE);
} break;
case VS::MATERIAL_BLEND_MODE_SUB: {
glBlendEquation(GL_FUNC_SUBTRACT);
glBlendFunc(GL_SRC_ALPHA,GL_ONE);
} break;
case VS::MATERIAL_BLEND_MODE_MUL: {
glBlendEquation(GL_FUNC_ADD);
glBlendFunc(GL_DST_COLOR,GL_ZERO);
} break;
case VS::MATERIAL_BLEND_MODE_PREMULT_ALPHA: {
glBlendEquation(GL_FUNC_ADD);
glBlendFunc(GL_ONE,GL_ONE_MINUS_SRC_ALPHA);
} break;
}
canvas_blend_mode=ci->blend_mode;
}
int cc=ci->commands.size();
CanvasItem::Command **commands = ci->commands.ptr();
canvas_opacity = ci->final_opacity;
for(int i=0;i<cc;i++) {
CanvasItem::Command *c=commands[i];
switch(c->type) {
case CanvasItem::Command::TYPE_LINE: {
CanvasItem::CommandLine* line = static_cast<CanvasItem::CommandLine*>(c);
canvas_draw_line(line->from,line->to,line->color,line->width);
} break;
case CanvasItem::Command::TYPE_RECT: {
CanvasItem::CommandRect* rect = static_cast<CanvasItem::CommandRect*>(c);
// canvas_draw_rect(rect->rect,rect->region,rect->source,rect->flags&CanvasItem::CommandRect::FLAG_TILE,rect->flags&CanvasItem::CommandRect::FLAG_FLIP_H,rect->flags&CanvasItem::CommandRect::FLAG_FLIP_V,rect->texture,rect->modulate);
#if 0
int flags=0;
if (rect->flags&CanvasItem::CommandRect::FLAG_REGION) {
flags|=Rasterizer::CANVAS_RECT_REGION;
}
if (rect->flags&CanvasItem::CommandRect::FLAG_TILE) {
flags|=Rasterizer::CANVAS_RECT_TILE;
}
if (rect->flags&CanvasItem::CommandRect::FLAG_FLIP_H) {
flags|=Rasterizer::CANVAS_RECT_FLIP_H;
}
if (rect->flags&CanvasItem::CommandRect::FLAG_FLIP_V) {
flags|=Rasterizer::CANVAS_RECT_FLIP_V;
}
#else
int flags=rect->flags;
#endif
canvas_draw_rect(rect->rect,flags,rect->source,rect->texture,rect->modulate);
} break;
case CanvasItem::Command::TYPE_STYLE: {
CanvasItem::CommandStyle* style = static_cast<CanvasItem::CommandStyle*>(c);
canvas_draw_style_box(style->rect,style->texture,style->margin,style->draw_center,style->color);
} break;
case CanvasItem::Command::TYPE_PRIMITIVE: {
CanvasItem::CommandPrimitive* primitive = static_cast<CanvasItem::CommandPrimitive*>(c);
canvas_draw_primitive(primitive->points,primitive->colors,primitive->uvs,primitive->texture,primitive->width);
} break;
case CanvasItem::Command::TYPE_POLYGON: {
CanvasItem::CommandPolygon* polygon = static_cast<CanvasItem::CommandPolygon*>(c);
canvas_draw_polygon(polygon->count,polygon->indices.ptr(),polygon->points.ptr(),polygon->uvs.ptr(),polygon->colors.ptr(),polygon->texture,polygon->colors.size()==1);
} break;
case CanvasItem::Command::TYPE_POLYGON_PTR: {
CanvasItem::CommandPolygonPtr* polygon = static_cast<CanvasItem::CommandPolygonPtr*>(c);
canvas_draw_polygon(polygon->count,polygon->indices,polygon->points,polygon->uvs,polygon->colors,polygon->texture,false);
} break;
case CanvasItem::Command::TYPE_CIRCLE: {
CanvasItem::CommandCircle* circle = static_cast<CanvasItem::CommandCircle*>(c);
static const int numpoints=32;
Vector2 points[numpoints+1];
points[numpoints]=circle->pos;
int indices[numpoints*3];
for(int i=0;i<numpoints;i++) {
points[i]=circle->pos+Vector2( Math::sin(i*Math_PI*2.0/numpoints),Math::cos(i*Math_PI*2.0/numpoints) )*circle->radius;
indices[i*3+0]=i;
indices[i*3+1]=(i+1)%numpoints;
indices[i*3+2]=numpoints;
}
canvas_draw_polygon(numpoints*3,indices,points,NULL,&circle->color,RID(),true);
//canvas_draw_circle(circle->indices.size(),circle->indices.ptr(),circle->points.ptr(),circle->uvs.ptr(),circle->colors.ptr(),circle->texture,circle->colors.size()==1);
} break;
case CanvasItem::Command::TYPE_TRANSFORM: {
CanvasItem::CommandTransform* transform = static_cast<CanvasItem::CommandTransform*>(c);
canvas_set_transform(transform->xform);
} break;
case CanvasItem::Command::TYPE_BLEND_MODE: {
CanvasItem::CommandBlendMode* bm = static_cast<CanvasItem::CommandBlendMode*>(c);
canvas_set_blend_mode(bm->blend_mode);
} break;
case CanvasItem::Command::TYPE_CLIP_IGNORE: {
CanvasItem::CommandClipIgnore* ci = static_cast<CanvasItem::CommandClipIgnore*>(c);
if (current_clip) {
if (ci->ignore!=reclip) {
if (ci->ignore) {
glDisable(GL_SCISSOR_TEST);
reclip=true;
} else {
glEnable(GL_SCISSOR_TEST);
glScissor(viewport.x+current_clip->final_clip_rect.pos.x,viewport.y+ (viewport.height-(current_clip->final_clip_rect.pos.y+current_clip->final_clip_rect.size.height)),
current_clip->final_clip_rect.size.width,current_clip->final_clip_rect.size.height);
reclip=false;
}
}
}
} break;
}
}
if (reclip) {
glEnable(GL_SCISSOR_TEST);
glScissor(viewport.x+current_clip->final_clip_rect.pos.x,viewport.y+ (viewport.height-(current_clip->final_clip_rect.pos.y+current_clip->final_clip_rect.size.height)),
current_clip->final_clip_rect.size.width,current_clip->final_clip_rect.size.height);
}
p_item_list=p_item_list->next;
}
if (current_clip) {
glDisable(GL_SCISSOR_TEST);
}
}
/* ENVIRONMENT */
RID RasterizerGLES2::environment_create() {

View File

@ -191,6 +191,8 @@ class RasterizerGLES2 : public Rasterizer {
bool writes_vertex;
bool uses_discard;
bool uses_time;
bool uses_normal;
bool uses_texpixel_size;
Map<StringName,ShaderLanguage::Uniform> uniforms;
StringName first_texture;
@ -214,6 +216,7 @@ class RasterizerGLES2 : public Rasterizer {
writes_vertex=false;
uses_discard=false;
uses_time=false;
uses_normal=false;
}
@ -1169,6 +1172,13 @@ class RasterizerGLES2 : public Rasterizer {
GLuint white_tex;
RID canvas_tex;
float canvas_opacity;
bool uses_texpixel_size;
bool rebind_texpixel_size;
Transform canvas_transform;
RID canvas_last_shader;
bool canvas_texscreen_used;
_FORCE_INLINE_ Texture* _bind_canvas_texture(const RID& p_texture);
VS::MaterialBlendMode canvas_blend_mode;
@ -1199,7 +1209,7 @@ class RasterizerGLES2 : public Rasterizer {
RID overdraw_material;
mutable MaterialShaderGLES2 material_shader;
CanvasShaderGLES2 canvas_shader;
mutable CanvasShaderGLES2 canvas_shader;
BlurShaderGLES2 blur_shader;
CopyShaderGLES2 copy_shader;
@ -1260,6 +1270,8 @@ public:
virtual void shader_set_default_texture_param(RID p_shader, const StringName& p_name, RID p_texture);
virtual RID shader_get_default_texture_param(RID p_shader, const StringName& p_name) const;
virtual Variant shader_get_default_param(RID p_shader, const StringName& p_name);
/* COMMON MATERIAL API */
virtual RID material_create();
@ -1536,6 +1548,8 @@ public:
virtual void canvas_draw_polygon(int p_vertex_count, const int* p_indices, const Vector2* p_vertices, const Vector2* p_uvs, const Color* p_colors,const RID& p_texture,bool p_singlecolor);
virtual void canvas_set_transform(const Matrix32& p_transform);
virtual void canvas_render_items(CanvasItem *p_item_list);
/* ENVIRONMENT */

View File

@ -147,6 +147,7 @@ String ShaderCompilerGLES2::dump_node_code(SL::Node *p_node,int p_level,bool p_a
} break;
case SL::Node::TYPE_VARIABLE: {
SL::VariableNode *vnode=(SL::VariableNode*)p_node;
if (type==ShaderLanguage::SHADER_MATERIAL_VERTEX) {
if (vnode->name==vname_vertex && p_assign_left) {
@ -173,6 +174,9 @@ String ShaderCompilerGLES2::dump_node_code(SL::Node *p_node,int p_level,bool p_a
}
if (type==ShaderLanguage::SHADER_MATERIAL_FRAGMENT) {
if (vnode->name==vname_discard) {
@ -213,6 +217,47 @@ String ShaderCompilerGLES2::dump_node_code(SL::Node *p_node,int p_level,bool p_a
uses_light=true;
}
}
if (type==ShaderLanguage::SHADER_CANVAS_ITEM_VERTEX) {
if (vnode->name==vname_var1_interp) {
flags->use_var1_interp=true;
}
if (vnode->name==vname_var2_interp) {
flags->use_var2_interp=true;
}
}
if (type==ShaderLanguage::SHADER_CANVAS_ITEM_FRAGMENT) {
if (vnode->name==vname_texpixel_size) {
uses_texpixel_size=true;
}
if (vnode->name==vname_normal) {
uses_normal=true;
}
if (vnode->name==vname_screen_uv) {
uses_screen_uv=true;
}
if (vnode->name==vname_var1_interp) {
flags->use_var1_interp=true;
}
if (vnode->name==vname_var2_interp) {
flags->use_var2_interp=true;
}
}
if (type==ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT) {
if (vnode->name==vname_light) {
uses_light=true;
}
}
if (vnode->name==vname_time) {
@ -359,7 +404,7 @@ String ShaderCompilerGLES2::dump_node_code(SL::Node *p_node,int p_level,bool p_a
} else if (callfunc=="texscreen") {
//create the call to sample the screen, and clamp it
uses_texscreen=true;
code="(texture2D( texscreen_tex, min(("+dump_node_code(onode->arguments[1],p_level)+").xy*texscreen_screen_mult,texscreen_screen_mult))).rgb";
code="(texture2D( texscreen_tex, clamp(("+dump_node_code(onode->arguments[1],p_level)+").xy*texscreen_screen_mult,texscreen_screen_clamp.xy,texscreen_screen_clamp.zw))).rgb";
//code="(texture2D( screen_texture, ("+dump_node_code(onode->arguments[1],p_level)+").xy).rgb";
break;
} else if (callfunc=="texpos") {
@ -552,6 +597,8 @@ Error ShaderCompilerGLES2::compile(const String& p_code, ShaderLanguage::ShaderT
uses_light=false;
uses_time=false;
uses_normalmap=false;
uses_normal=false;
uses_texpixel_size=false;
vertex_code_writes_vertex=false;
uniforms=r_uniforms;
flags=&r_flags;
@ -562,6 +609,7 @@ Error ShaderCompilerGLES2::compile(const String& p_code, ShaderLanguage::ShaderT
r_flags.use_var1_interp=false;
r_flags.use_var2_interp=false;
r_flags.uses_normalmap=false;
r_flags.uses_normal=false;
String error;
int errline,errcol;
@ -584,6 +632,8 @@ Error ShaderCompilerGLES2::compile(const String& p_code, ShaderLanguage::ShaderT
r_flags.uses_light=uses_light;
r_flags.uses_time=uses_time;
r_flags.uses_normalmap=uses_normalmap;
r_flags.uses_normal=uses_normalmap;
r_flags.uses_texpixel_size=uses_texpixel_size;
r_code_line=code;
r_globals_line=global_code;
@ -640,6 +690,7 @@ ShaderCompilerGLES2::ShaderCompilerGLES2() {
replace_table["cross" ]="cross";
replace_table["normalize"]= "normalize";
replace_table["reflect"]= "reflect";
replace_table["refract"]= "refract";
replace_table["tex"]= "tex";
replace_table["texa"]= "texa";
replace_table["tex2"]= "tex2";
@ -721,6 +772,42 @@ ShaderCompilerGLES2::ShaderCompilerGLES2() {
mode_replace_table[2]["POINT_COORD"]="gl_PointCoord";
mode_replace_table[2]["TIME"]="time";
mode_replace_table[3]["SRC_VERTEX"]="src_vtx";
mode_replace_table[3]["VERTEX"]="outvec.xy";
mode_replace_table[3]["UV"]="uv_interp";
mode_replace_table[3]["COLOR"]="color_interp";
mode_replace_table[3]["VAR1"]="var1_interp";
mode_replace_table[3]["VAR2"]="var2_interp";
mode_replace_table[3]["POINT_SIZE"]="gl_PointSize";
mode_replace_table[3]["WORLD_MATRIX"]="modelview_matrix";
mode_replace_table[3]["PROJECTION_MATRIX"]="projection_matrix";
mode_replace_table[3]["EXTRA_MATRIX"]="extra_matrix";
mode_replace_table[3]["TIME"]="time";
mode_replace_table[4]["POSITION"]="gl_Position";
mode_replace_table[4]["NORMAL"]="normal";
mode_replace_table[4]["UV"]="uv_interp";
mode_replace_table[4]["SRC_COLOR"]="color_interp";
mode_replace_table[4]["COLOR"]="color";
mode_replace_table[4]["TEXTURE"]="texture";
mode_replace_table[4]["TEXTURE_PIXEL_SIZE"]="texpixel_size";
mode_replace_table[4]["VAR1"]="var1_interp";
mode_replace_table[4]["VAR2"]="var2_interp";
mode_replace_table[4]["SCREEN_UV"]="screen_uv";
mode_replace_table[4]["POINT_COORD"]="gl_PointCoord";
mode_replace_table[4]["TIME"]="time";
mode_replace_table[5]["SRC_COLOR"]="color";
mode_replace_table[5]["COLOR"]="color";
mode_replace_table[5]["NORMAL"]="normal";
mode_replace_table[5]["LIGHT_DIR"]="light_dir";
mode_replace_table[5]["LIGHT_DISTANCE"]="light_distance";
mode_replace_table[5]["LIGHT"]="light";
mode_replace_table[5]["POINT_COORD"]="gl_PointCoord";
mode_replace_table[5]["TIME"]="time";
//mode_replace_table[2]["SCREEN_POS"]="SCREEN_POS";
//mode_replace_table[2]["SCREEN_TEXEL_SIZE"]="SCREEN_TEXEL_SIZE";
@ -741,5 +828,7 @@ ShaderCompilerGLES2::ShaderCompilerGLES2() {
vname_light="LIGHT";
vname_time="TIME";
vname_normalmap="NORMALMAP";
vname_normal="NORMAL";
vname_texpixel_size="TEXTURE_PIXEL_SIZE";
}

View File

@ -51,6 +51,8 @@ private:
bool uses_time;
bool uses_screen_uv;
bool uses_normalmap;
bool uses_normal;
bool uses_texpixel_size;
bool vertex_code_writes_vertex;
Flags *flags;
@ -68,6 +70,8 @@ private:
StringName vname_light;
StringName vname_time;
StringName vname_normalmap;
StringName vname_normal;
StringName vname_texpixel_size;
Map<StringName,ShaderLanguage::Uniform> *uniforms;
@ -79,7 +83,7 @@ private:
String replace_string(const StringName& p_string);
Map<StringName,StringName> mode_replace_table[3];
Map<StringName,StringName> mode_replace_table[9];
Map<StringName,StringName> replace_table;
public:
@ -101,6 +105,8 @@ public:
bool use_var2_interp;
bool uses_light;
bool uses_time;
bool uses_normal;
bool uses_texpixel_size;
};
Error compile(const String& p_code, ShaderLanguage::ShaderType p_type, String& r_code_line, String& r_globals_line, Flags& r_flags, Map<StringName,ShaderLanguage::Uniform> *r_uniforms=NULL);

View File

@ -18,19 +18,56 @@ attribute highp vec2 uv_attrib; // attrib:4
varying vec2 uv_interp;
varying vec4 color_interp;
#if defined(USE_TIME)
uniform float time;
#endif
#ifdef USE_LIGHTING
uniform highp mat4 light_matrix;
varying vec4 light_tex_pos;
#endif
#if defined(ENABLE_VAR1_INTERP)
varying vec4 var1_interp;
#endif
#if defined(ENABLE_VAR2_INTERP)
varying vec4 var2_interp;
#endif
//uniform bool snap_pixels;
VERTEX_SHADER_GLOBALS
void main() {
color_interp = color_attrib;
uv_interp = uv_attrib;
highp vec4 outvec = vec4(vertex, 1.0);
{
vec2 src_vtx=outvec.xy;
VERTEX_SHADER_CODE
}
outvec = extra_matrix * outvec;
outvec = modelview_matrix * outvec;
#ifdef USE_PIXEL_SNAP
outvec.xy=floor(outvec.xy+0.5);
outvec.xy=floor(outvec.xy+0.5);
#endif
#ifdef USE_LIGHTING
light_tex_pos.xy = light_matrix * outvec;
light_tex_pos.zw=outvec.xy - light_matrix[4].xy; //likely wrong
#endif
gl_Position = projection_matrix * outvec;
}
@ -54,17 +91,112 @@ varying vec4 color_interp;
#endif
#if defined(ENABLE_SCREEN_UV)
uniform vec2 screen_uv_mult;
#endif
#if defined(ENABLE_TEXSCREEN)
uniform vec2 texscreen_screen_mult;
uniform vec4 texscreen_screen_clamp;
uniform sampler2D texscreen_tex;
#endif
#if defined(ENABLE_VAR1_INTERP)
varying vec4 var1_interp;
#endif
#if defined(ENABLE_VAR2_INTERP)
varying vec4 var2_interp;
#endif
#if defined(USE_TIME)
uniform float time;
#endif
#ifdef USE_LIGHTING
uniform sampler2D light_texture;
varying vec4 light_tex_pos;
#ifdef USE_SHADOWS
uniform sampler2D shadow_texture;
uniform float shadow_attenuation;
#endif
#endif
#if defined(USE_TEXPIXEL_SIZE)
uniform vec2 texpixel_size;
#endif
FRAGMENT_SHADER_GLOBALS
void main() {
vec4 color = color_interp;
color *= texture2D( texture, uv_interp );
#if defined(NORMAL_USED)
vec3 normal = vec3(0,0,1);
#endif
color *= texture2D( texture, uv_interp );
#if defined(ENABLE_SCREEN_UV)
vec2 screen_uv = gl_FragCoord.xy*screen_uv_mult;
#endif
{
FRAGMENT_SHADER_CODE
}
#ifdef DEBUG_ENCODED_32
highp float enc32 = dot( color,highp vec4(1.0 / (256.0 * 256.0 * 256.0),1.0 / (256.0 * 256.0),1.0 / 256.0,1) );
color = vec4(vec3(enc32),1.0);
#endif
#ifdef USE_LIGHTING
float att=1.0;
vec3 light = texture2D(light_texture,light_tex_pos).rgb;
#ifdef USE_SHADOWS
//this might not be that great on mobile?
float light_dist = length(light_texture.zw);
float light_angle = atan2(light_texture.x,light_texture.z) + 1.0 * 0.5;
float shadow_dist = texture2D(shadow_texture,vec2(light_angle,0));
if (light_dist>shadow_dist) {
light*=shadow_attenuation;
}
//use shadows
#endif
#if defined(USE_LIGHT_SHADER_CODE)
//light is written by the light shader
{
vec2 light_dir = normalize(light_tex_pos.zw);
float light_distance = length(light_tex_pos.zw);
LIGHT_SHADER_CODE
}
#else
#if defined(NORMAL_USED)
vec2 light_normal = normalize(light_tex_pos.zw);
light = color.rgb * light * max(dot(light_normal,normal),0);
#endif
color.rgb=light;
//light shader code
#endif
//use lighting
#endif
// color.rgb*=color.a;
gl_FragColor = color;

View File

@ -779,6 +779,7 @@ uniform highp mat4 camera_inverse_transform;
#if defined(ENABLE_TEXSCREEN)
uniform vec2 texscreen_screen_mult;
uniform vec4 texscreen_screen_clamp;
uniform sampler2D texscreen_tex;
#endif

View File

@ -1661,7 +1661,7 @@ Error GDScriptLanguage::complete_code(const String& p_code, const String& p_base
//print_line( p_code.replace(String::chr(0xFFFF),"<cursor>"));
GDParser p;
Error err = p.parse(p_code,p_base_path);
Error err = p.parse(p_code,p_base_path,true);
bool isfunction=false;
Set<String> options;

View File

@ -124,11 +124,11 @@ def configure(env):
# env['CCFLAGS'] = string.split('-DNO_THREADS -MMD -MP -MF -fpic -ffunction-sections -funwind-tables -fstack-protector -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__ -Wno-psabi -march=armv5te -mtune=xscale -msoft-float -fno-exceptions -mthumb -fno-strict-aliasing -DANDROID -Wa,--noexecstack -DGLES2_ENABLED ')
if env['x86']=='yes':
env['CCFLAGS'] = string.split('-DNO_STATVFS -MMD -MP -MF -fpic -ffunction-sections -funwind-tables -fstack-protector -fvisibility=hidden -D__GLIBC__ -Wno-psabi -ftree-vectorize -funsafe-math-optimizations -fno-strict-aliasing -DANDROID -Wa,--noexecstack -DGLES2_ENABLED -DGLES1_ENABLED')
env['CCFLAGS'] = string.split('-DNO_STATVFS -MMD -MP -MF -fpic -ffunction-sections -funwind-tables -fstack-protector -fvisibility=hidden -D__GLIBC__ -Wno-psabi -ftree-vectorize -funsafe-math-optimizations -fno-strict-aliasing -DANDROID -Wa,--noexecstack -DGLES2_ENABLED')
elif env["armv6"]!="no":
env['CCFLAGS'] = string.split('-DNO_STATVFS -MMD -MP -MF -fpic -ffunction-sections -funwind-tables -fstack-protector -fvisibility=hidden -D__ARM_ARCH_6__ -D__GLIBC__ -Wno-psabi -march=armv6 -mfpu=vfp -mfloat-abi=softfp -funsafe-math-optimizations -fno-strict-aliasing -DANDROID -Wa,--noexecstack -DGLES2_ENABLED -DGLES1_ENABLED')
env['CCFLAGS'] = string.split('-DNO_STATVFS -MMD -MP -MF -fpic -ffunction-sections -funwind-tables -fstack-protector -fvisibility=hidden -D__ARM_ARCH_6__ -D__GLIBC__ -Wno-psabi -march=armv6 -mfpu=vfp -mfloat-abi=softfp -funsafe-math-optimizations -fno-strict-aliasing -DANDROID -Wa,--noexecstack -DGLES2_ENABLED')
else:
env['CCFLAGS'] = string.split('-DNO_STATVFS -MMD -MP -MF -fpic -ffunction-sections -funwind-tables -fstack-protector -fvisibility=hidden -D__ARM_ARCH_7__ -D__GLIBC__ -Wno-psabi -march=armv6 -mfpu=neon -mfloat-abi=softfp -ftree-vectorize -funsafe-math-optimizations -fno-strict-aliasing -DANDROID -Wa,--noexecstack -DGLES2_ENABLED -DGLES1_ENABLED')
env['CCFLAGS'] = string.split('-DNO_STATVFS -MMD -MP -MF -fpic -ffunction-sections -funwind-tables -fstack-protector -fvisibility=hidden -D__ARM_ARCH_7__ -D__GLIBC__ -Wno-psabi -march=armv6 -mfpu=neon -mfloat-abi=softfp -ftree-vectorize -funsafe-math-optimizations -fno-strict-aliasing -DANDROID -Wa,--noexecstack -DGLES2_ENABLED')
env.Append(LDPATH=[ld_path])
env.Append(LIBS=['OpenSLES'])

View File

@ -10,5 +10,5 @@ void register_android_global_defaults() {
GLOBAL_DEF("display.Android/driver","GLES2");
// GLOBAL_DEF("rasterizer.Android/trilinear_mipmap_filter",false);
Globals::get_singleton()->set_custom_property_info("display.Android/driver",PropertyInfo(Variant::STRING,"display.Android/driver",PROPERTY_HINT_ENUM,"GLES1,GLES2"));
Globals::get_singleton()->set_custom_property_info("display.Android/driver",PropertyInfo(Variant::STRING,"display.Android/driver",PROPERTY_HINT_ENUM,"GLES2"));
}

View File

@ -205,6 +205,7 @@ Variant _jobject_to_variant(JNIEnv * env, jobject obj) {
String name = _get_class_name(env, c, &array);
//print_line("name is " + name + ", array "+Variant(array));
print_line("ARGNAME: "+name);
if (name == "java.lang.String") {
return String::utf8(env->GetStringUTFChars( (jstring)obj, NULL ));
@ -821,10 +822,7 @@ JNIEXPORT void JNICALL Java_com_android_godot_GodotLib_initialize(JNIEnv * env,
String vd = Globals::get_singleton()->get("display/driver");
if (vd.to_upper()=="GLES1")
env->CallVoidMethod(_godot_instance, _on_video_init, (jboolean)false);
else
env->CallVoidMethod(_godot_instance, _on_video_init, (jboolean)true);
env->CallVoidMethod(_godot_instance, _on_video_init, (jboolean)true);
__android_log_print(ANDROID_LOG_INFO,"godot","**START");

View File

@ -28,7 +28,7 @@
/*************************************************************************/
#include "os_android.h"
#include "drivers/gles2/rasterizer_gles2.h"
#include "drivers/gles1/rasterizer_gles1.h"
#include "core/io/file_access_buffered_fa.h"
#include "drivers/unix/file_access_unix.h"
#include "drivers/unix/dir_access_unix.h"
@ -49,11 +49,11 @@
int OS_Android::get_video_driver_count() const {
return 2;
return 1;
}
const char * OS_Android::get_video_driver_name(int p_driver) const {
return p_driver==0?"GLES2":"GLES1";
return "GLES2";
}
OS::VideoMode OS_Android::get_default_video_mode() const {
@ -123,13 +123,13 @@ void OS_Android::initialize(const VideoMode& p_desired,int p_video_driver,int p_
AudioDriverManagerSW::add_driver(&audio_driver_android);
if (use_gl2) {
if (true) {
RasterizerGLES2 *rasterizer_gles22=memnew( RasterizerGLES2(false,use_reload_hooks,false,use_reload_hooks ) );
if (gl_extensions)
rasterizer_gles22->set_extensions(gl_extensions);
rasterizer = rasterizer_gles22;
} else {
rasterizer = memnew( RasterizerGLES1(use_reload_hooks, use_reload_hooks) );
//rasterizer = memnew( RasterizerGLES1(use_reload_hooks, use_reload_hooks) );
}

View File

@ -25,8 +25,6 @@ env_ios = env.Clone();
if env['ios_gles22_override'] == "yes":
env_ios.Append(CPPFLAGS=['-DGLES2_OVERRIDE'])
if env['ios_GLES1_override'] == "yes":
env_ios.Append(CPPFLAGS=['-DGLES1_OVERRIDE'])
if env['ios_appirater'] == "yes":
env_ios.Append(CPPFLAGS=['-DAPPIRATER_ENABLED'])

View File

@ -26,7 +26,6 @@ def get_opts():
('game_center', 'Support for game center', 'yes'),
('store_kit', 'Support for in-app store', 'yes'),
('ios_gles22_override', 'Force GLES2.0 on iOS', 'yes'),
('ios_GLES1_override', 'Force legacy GLES (1.1) on iOS', 'no'),
('ios_appirater', 'Enable Appirater', 'no'),
('ios_exceptions', 'Use exceptions when compiling on playbook', 'yes'),
]
@ -130,7 +129,7 @@ def configure(env):
env['ENV']['CODESIGN_ALLOCATE'] = '/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate'
env.Append(CPPFLAGS=['-DIPHONE_ENABLED', '-DUNIX_ENABLED', '-DGLES2_ENABLED', '-DGLES1_ENABLED', '-DMPC_FIXED_POINT'])
env.Append(CPPFLAGS=['-DIPHONE_ENABLED', '-DUNIX_ENABLED', '-DGLES2_ENABLED', '-DMPC_FIXED_POINT'])
if env['ios_exceptions'] == 'yes':
env.Append(CPPFLAGS=['-fexceptions'])
else:

View File

@ -307,11 +307,7 @@ static void clear_touches() {
nil];
// Create our EAGLContext, and if successful make it current and create our framebuffer.
#ifdef GLES1_OVERRIDE
context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1];
#else
context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
#endif
if(!context || ![EAGLContext setCurrentContext:context] || ![self createFramebuffer])
{

View File

@ -31,7 +31,7 @@
#include "os_iphone.h"
#include "drivers/gles2/rasterizer_gles2.h"
#include "drivers/gles1/rasterizer_gles1.h"
#include "servers/visual/visual_server_raster.h"
#include "servers/visual/visual_server_wrap_mt.h"
@ -52,7 +52,7 @@ int OSIPhone::get_video_driver_count() const {
const char * OSIPhone::get_video_driver_name(int p_driver) const {
return "openglES";
return "GLES2";
};
OSIPhone* OSIPhone::get_singleton() {
@ -106,13 +106,9 @@ void OSIPhone::initialize(const VideoMode& p_desired,int p_video_driver,int p_au
supported_orientations |= ((GLOBAL_DEF("video_mode/allow_vertical", false)?1:0) << PortraitDown);
supported_orientations |= ((GLOBAL_DEF("video_mode/allow_vertical_flipped", false)?1:0) << PortraitUp);
#ifdef GLES1_OVERRIDE
rasterizer = memnew( RasterizerGLES1 );
#else
rasterizer_gles22 = memnew( RasterizerGLES2(false, false, false) );
rasterizer = rasterizer_gles22;
rasterizer_gles22->set_base_framebuffer(gl_view_base_fb);
#endif
visual_server = memnew( VisualServerRaster(rasterizer) );
if (get_render_thread_mode() != RENDER_THREAD_UNSAFE) {

View File

@ -28,6 +28,6 @@
/*************************************************************************/
#include <alloca.h>
#define GLES2_INCLUDE_H <ES2/gl.h>
#define GLES1_INCLUDE_H <ES1/gl.h>
#define PLATFORM_REFCOUNT

View File

@ -25,8 +25,6 @@ env_ios = env.Clone();
if env['ios_gles22_override'] == "yes":
env_ios.Append(CPPFLAGS=['-DGLES2_OVERRIDE'])
if env['ios_GLES1_override'] == "yes":
env_ios.Append(CPPFLAGS=['-DGLES1_OVERRIDE'])
if env['ios_appirater'] == "yes":
env_ios.Append(CPPFLAGS=['-DAPPIRATER_ENABLED'])

View File

@ -64,7 +64,7 @@ int OSNacl::get_video_driver_count() const {
};
const char * OSNacl::get_video_driver_name(int p_driver) const {
return "gles2";
return "GLES2";
};
OS::VideoMode OSNacl::get_default_video_mode() const {

View File

@ -113,7 +113,7 @@ def configure(env):
env.Append(CCFLAGS=['/DTYPED_METHOD_BIND'])
env.Append(CCFLAGS=['/DGLES2_ENABLED'])
env.Append(CCFLAGS=['/DGLES1_ENABLED'])
env.Append(CCFLAGS=['/DGLEW_ENABLED'])
LIBS=['winmm','opengl32','dsound','kernel32','ole32','user32','gdi32', 'IPHLPAPI', 'wsock32', 'shell32','advapi32']
env.Append(LINKFLAGS=[p+env["LIBSUFFIX"] for p in LIBS])
@ -228,7 +228,7 @@ def configure(env):
env.Append(CCFLAGS=['-DWINDOWS_ENABLED','-mwindows'])
env.Append(CPPFLAGS=['-DRTAUDIO_ENABLED'])
env.Append(CCFLAGS=['-DGLES2_ENABLED','-DGLES1_ENABLED','-DGLEW_ENABLED'])
env.Append(CCFLAGS=['-DGLES2_ENABLED','-DGLEW_ENABLED'])
env.Append(LIBS=['mingw32','opengl32', 'dsound', 'ole32', 'd3d9','winmm','gdi32','iphlpapi','wsock32','kernel32'])
if (env["bits"]=="32" and env["mingw64_for_32"]!="yes"):

View File

@ -27,7 +27,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "drivers/gles2/rasterizer_gles2.h"
#include "drivers/gles1/rasterizer_gles1.h"
#include "os_windows.h"
#include "drivers/nedmalloc/memory_pool_static_nedmalloc.h"
#include "drivers/unix/memory_pool_static_malloc.h"
@ -130,11 +130,11 @@ void RedirectIOToConsole() {
int OS_Windows::get_video_driver_count() const {
return 2;
return 1;
}
const char * OS_Windows::get_video_driver_name(int p_driver) const {
return p_driver==0?"GLES2":"GLES1";
return "GLES2";
}
OS::VideoMode OS_Windows::get_default_video_mode() const {

View File

@ -31,5 +31,5 @@
//#include <alloca.h>
//#endif
#define GLES2_INCLUDE_H "gl_context/glew.h"
#define GLES1_INCLUDE_H "gl_context/glew.h"

View File

@ -48,6 +48,7 @@ def get_opts():
return [
('use_llvm','Use llvm compiler','no'),
('use_sanitizer','Use llvm compiler sanitize address','no'),
('pulseaudio','Detect & Use pulseaudio','yes'),
]
def get_flags():
@ -113,23 +114,22 @@ def configure(env):
env.Append(CCFLAGS=['-DFREETYPE_ENABLED'])
if env['ao'] == 'yes':
env.ParseConfig('pkg-config ao --cflags --libs')
env.Append(CPPFLAGS=['-DAO_ENABLED'])
env.Append(CPPFLAGS=['-DOPENGL_ENABLED','-DGLEW_ENABLED'])
if platform.platform() == 'Linux':
env.Append(CPPFLAGS=["-DALSA_ENABLED"])
env.Append(LIBS=['asound'])
if not os.system("pkg-config --exists libpulse-simple"):
print("Enabling PulseAudio")
env.Append(CPPFLAGS=["-DPULSEAUDIO_ENABLED"])
env.ParseConfig('pkg-config --cflags --libs libpulse-simple')
else:
print("PulseAudio development libraries not found, disabling driver")
if env['ao'] == 'yes':
env.ParseConfig('pkg-config ao --cflags --libs')
env.Append(CPPFLAGS=['-DAO_ENABLED'])
if (env["pulseaudio"]=="yes"):
if not os.system("pkg-config --exists libpulse-simple"):
print("Enabling PulseAudio")
env.Append(CPPFLAGS=["-DPULSEAUDIO_ENABLED"])
env.ParseConfig('pkg-config --cflags --libs libpulse-simple')
else:
print("PulseAudio development libraries not found, disabling driver")
env.Append(CPPFLAGS=['-DX11_ENABLED','-DUNIX_ENABLED','-DGLES2_ENABLED','-DGLES1_ENABLED','-DGLES_OVER_GL'])
env.Append(CPPFLAGS=['-DX11_ENABLED','-DUNIX_ENABLED','-DGLES2_ENABLED','-DGLES_OVER_GL'])
env.Append(LIBS=['GL', 'GLU', 'pthread', 'z'])
#env.Append(CPPFLAGS=['-DMPC_FIXED_POINT'])

View File

@ -28,7 +28,6 @@
/*************************************************************************/
#include "servers/visual/visual_server_raster.h"
#include "drivers/gles2/rasterizer_gles2.h"
#include "drivers/gles1/rasterizer_gles1.h"
#include "os_x11.h"
#include "key_mapping_x11.h"
#include <stdio.h>
@ -64,11 +63,11 @@
int OS_X11::get_video_driver_count() const {
return 2;
return 1;
}
const char * OS_X11::get_video_driver_name(int p_driver) const {
return p_driver==0?"GLES2":"GLES1";
return "GLES2";
}
OS::VideoMode OS_X11::get_default_video_mode() const {
@ -167,10 +166,10 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi
context_gl = memnew( ContextGL_X11( x11_display, x11_window,current_videomode, false ) );
context_gl->initialize();
if (p_video_driver == 0) {
if (true) {
rasterizer = memnew( RasterizerGLES2 );
} else {
rasterizer = memnew( RasterizerGLES1 );
//rasterizer = memnew( RasterizerGLES1 );
};
#endif

View File

@ -34,5 +34,5 @@
#endif
#define GLES2_INCLUDE_H "gl_context/glew.h"
#define GLES1_INCLUDE_H "gl_context/glew.h"

View File

@ -720,6 +720,95 @@ bool CanvasItem::is_draw_behind_parent_enabled() const{
return behind;
}
void CanvasItem::set_shader(const Ref<Shader>& p_shader) {
ERR_FAIL_COND(p_shader.is_valid() && p_shader->get_mode()!=Shader::MODE_CANVAS_ITEM);
#ifdef TOOLS_ENABLED
if (shader.is_valid()) {
shader->disconnect("changed",this,"_shader_changed");
}
#endif
shader=p_shader;
#ifdef TOOLS_ENABLED
if (shader.is_valid()) {
shader->connect("changed",this,"_shader_changed");
}
#endif
RID rid;
if (shader.is_valid())
rid=shader->get_rid();
VS::get_singleton()->canvas_item_set_shader(canvas_item,rid);
_change_notify(); //properties for shader exposed
}
void CanvasItem::set_use_parent_shader(bool p_use_parent_shader) {
use_parent_shader=p_use_parent_shader;
VS::get_singleton()->canvas_item_set_use_parent_shader(canvas_item,p_use_parent_shader);
}
bool CanvasItem::get_use_parent_shader() const{
return use_parent_shader;
}
Ref<Shader> CanvasItem::get_shader() const{
return shader;
}
void CanvasItem::set_shader_param(const StringName& p_param,const Variant& p_value) {
VS::get_singleton()->canvas_item_set_shader_param(canvas_item,p_param,p_value);
}
Variant CanvasItem::get_shader_param(const StringName& p_param) const {
return VS::get_singleton()->canvas_item_get_shader_param(canvas_item,p_param);
}
bool CanvasItem::_set(const StringName& p_name, const Variant& p_value) {
if (shader.is_valid()) {
StringName pr = shader->remap_param(p_name);
if (pr) {
set_shader_param(pr,p_value);
return true;
}
}
return false;
}
bool CanvasItem::_get(const StringName& p_name,Variant &r_ret) const{
if (shader.is_valid()) {
StringName pr = shader->remap_param(p_name);
if (pr) {
r_ret=get_shader_param(pr);
return true;
}
}
return false;
}
void CanvasItem::_get_property_list( List<PropertyInfo> *p_list) const{
if (shader.is_valid()) {
shader->get_param_list(p_list);
}
}
#ifdef TOOLS_ENABLED
void CanvasItem::_shader_changed() {
_change_notify();
}
#endif
void CanvasItem::_bind_methods() {
@ -761,7 +850,9 @@ void CanvasItem::_bind_methods() {
ObjectTypeDB::bind_method(_MD("_set_on_top","on_top"),&CanvasItem::_set_on_top);
ObjectTypeDB::bind_method(_MD("_is_on_top"),&CanvasItem::_is_on_top);
#ifdef TOOLS_ENABLED
ObjectTypeDB::bind_method(_MD("_shader_changed"),&CanvasItem::_shader_changed);
#endif
//ObjectTypeDB::bind_method(_MD("get_transform"),&CanvasItem::get_transform);
ObjectTypeDB::bind_method(_MD("draw_line","from","to","color","width"),&CanvasItem::draw_line,DEFVAL(1.0));
@ -786,15 +877,22 @@ void CanvasItem::_bind_methods() {
ObjectTypeDB::bind_method(_MD("get_world_2d"),&CanvasItem::get_world_2d);
//ObjectTypeDB::bind_method(_MD("get_viewport"),&CanvasItem::get_viewport);
ObjectTypeDB::bind_method(_MD("set_shader","shader"),&CanvasItem::set_shader);
ObjectTypeDB::bind_method(_MD("get_shader"),&CanvasItem::get_shader);
ObjectTypeDB::bind_method(_MD("set_use_parent_shader","enable"),&CanvasItem::set_use_parent_shader);
ObjectTypeDB::bind_method(_MD("get_use_parent_shader"),&CanvasItem::get_use_parent_shader);
BIND_VMETHOD(MethodInfo("_draw"));
ADD_PROPERTY( PropertyInfo(Variant::BOOL,"visibility/visible"), _SCS("_set_visible_"),_SCS("_is_visible_") );
ADD_PROPERTY( PropertyInfo(Variant::REAL,"visibility/opacity",PROPERTY_HINT_RANGE, "0,1,0.01"), _SCS("set_opacity"),_SCS("get_opacity") );
ADD_PROPERTY( PropertyInfo(Variant::REAL,"visibility/self_opacity",PROPERTY_HINT_RANGE, "0,1,0.01"), _SCS("set_self_opacity"),_SCS("get_self_opacity") );
ADD_PROPERTY( PropertyInfo(Variant::BOOL,"visibility/behind_parent"), _SCS("set_draw_behind_parent"),_SCS("is_draw_behind_parent_enabled") );
ADD_PROPERTYNZ( PropertyInfo(Variant::BOOL,"visibility/behind_parent"), _SCS("set_draw_behind_parent"),_SCS("is_draw_behind_parent_enabled") );
ADD_PROPERTY( PropertyInfo(Variant::BOOL,"visibility/on_top",PROPERTY_HINT_NONE,"",0), _SCS("_set_on_top"),_SCS("_is_on_top") ); //compatibility
ADD_PROPERTYNZ( PropertyInfo(Variant::INT,"visibility/blend_mode",PROPERTY_HINT_ENUM, "Mix,Add,Sub,Mul,PMAlpha"), _SCS("set_blend_mode"),_SCS("get_blend_mode") );
ADD_PROPERTYNZ( PropertyInfo(Variant::OBJECT,"shader/shader",PROPERTY_HINT_RESOURCE_TYPE, "CanvasItemShader,CanvasItemShaderGraph"), _SCS("set_shader"),_SCS("get_shader") );
ADD_PROPERTYNZ( PropertyInfo(Variant::BOOL,"shader/use_parent"), _SCS("set_use_parent_shader"),_SCS("get_use_parent_shader") );
//exporting these two things doesn't really make much sense i think
//ADD_PROPERTY( PropertyInfo(Variant::BOOL,"transform/toplevel"), _SCS("set_as_toplevel"),_SCS("is_set_as_toplevel") );
//ADD_PROPERTY(PropertyInfo(Variant::BOOL,"transform/notify"),_SCS("set_transform_notify"),_SCS("is_transform_notify_enabled"));
@ -871,6 +969,7 @@ CanvasItem::CanvasItem() : xform_change(this) {
block_transform_notify=false;
// viewport=NULL;
canvas_layer=NULL;
use_parent_shader;
global_invalid=true;
C=NULL;

View File

@ -32,6 +32,7 @@
#include "scene/main/node.h"
#include "scene/resources/texture.h"
#include "scene/main/scene_main_loop.h"
#include "scene/resources/shader.h"
class CanvasLayer;
class Viewport;
@ -80,6 +81,9 @@ private:
bool block_transform_notify;
bool behind;
bool use_parent_shader;
Ref<Shader> shader;
mutable Matrix32 global_transform;
mutable bool global_invalid;
@ -99,8 +103,9 @@ private:
void _queue_sort_children();
void _sort_children();
#ifdef TOOLS_ENABLED
void _shader_changed();
#endif
void _notify_transform(CanvasItem *p_node);
void _set_on_top(bool p_on_top) { set_draw_behind_parent(!p_on_top); }
@ -108,6 +113,9 @@ private:
protected:
bool _set(const StringName& p_name, const Variant& p_value);
bool _get(const StringName& p_name,Variant &r_ret) const;
void _get_property_list( List<PropertyInfo> *p_list) const;
_FORCE_INLINE_ void _notify_transform() { if (!is_inside_tree()) return; _notify_transform(this); if (!block_transform_notify) notification(NOTIFICATION_LOCAL_TRANSFORM_CHANGED); }
@ -204,7 +212,14 @@ public:
RID get_canvas() const;
Ref<World2D> get_world_2d() const;
void set_shader(const Ref<Shader>& p_shader);
Ref<Shader> get_shader() const;
void set_use_parent_shader(bool p_use_parent_shader);
bool get_use_parent_shader() const;
void set_shader_param(const StringName& p_param,const Variant& p_value);
Variant get_shader_param(const StringName& p_param) const;
CanvasItem();
~CanvasItem();

View File

@ -289,6 +289,35 @@ void Node2D::set_global_transform(const Matrix32& p_transform) {
}
void Node2D::set_z(int p_z) {
ERR_FAIL_COND(p_z<VS::CANVAS_ITEM_Z_MIN);
ERR_FAIL_COND(p_z>VS::CANVAS_ITEM_Z_MAX);
z=p_z;
VS::get_singleton()->canvas_item_set_z(get_canvas_item(),z);
}
void Node2D::set_z_as_relative(bool p_enabled) {
if (z_relative==p_enabled)
return;
z_relative=p_enabled;
VS::get_singleton()->canvas_item_set_z_as_relative_to_parent(get_canvas_item(),p_enabled);
}
bool Node2D::is_z_relative() const {
return z_relative;
}
int Node2D::get_z() const{
return z;
}
void Node2D::_bind_methods() {
@ -308,18 +337,25 @@ void Node2D::_bind_methods() {
ObjectTypeDB::bind_method(_MD("move_local_x","delta","scaled"),&Node2D::move_x,DEFVAL(false));
ObjectTypeDB::bind_method(_MD("move_local_y","delta","scaled"),&Node2D::move_y,DEFVAL(false));
ObjectTypeDB::bind_method(_MD("set_global_pos","pos"),&Node2D::set_global_pos);
ObjectTypeDB::bind_method(_MD("get_global_pos"),&Node2D::get_global_pos);
ObjectTypeDB::bind_method(_MD("set_global_pos"),&Node2D::set_global_pos);
ObjectTypeDB::bind_method(_MD("set_transform","xform"),&Node2D::set_transform);
ObjectTypeDB::bind_method(_MD("set_global_transform","xform"),&Node2D::set_global_transform);
ObjectTypeDB::bind_method(_MD("set_z","z"),&Node2D::set_z);
ObjectTypeDB::bind_method(_MD("get_z"),&Node2D::get_z);
ObjectTypeDB::bind_method(_MD("set_z_as_relative","enable"),&Node2D::set_z_as_relative);
ObjectTypeDB::bind_method(_MD("is_z_relative"),&Node2D::is_z_relative);
ObjectTypeDB::bind_method(_MD("edit_set_pivot"),&Node2D::edit_set_pivot);
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2,"transform/pos"),_SCS("set_pos"),_SCS("get_pos"));
ADD_PROPERTY(PropertyInfo(Variant::REAL,"transform/rot",PROPERTY_HINT_RANGE,"-1440,1440,0.1"),_SCS("_set_rotd"),_SCS("_get_rotd"));
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2,"transform/scale"),_SCS("set_scale"),_SCS("get_scale"));
ADD_PROPERTY(PropertyInfo(Variant::INT,"z/z",PROPERTY_HINT_RANGE,itos(VS::CANVAS_ITEM_Z_MIN)+","+itos(VS::CANVAS_ITEM_Z_MAX)+",1"),_SCS("set_z"),_SCS("get_z"));
ADD_PROPERTY(PropertyInfo(Variant::BOOL,"z/relative"),_SCS("set_z_as_relative"),_SCS("is_z_relative"));
}
@ -331,6 +367,8 @@ Node2D::Node2D() {
angle=0;
scale=Vector2(1,1);
_xform_dirty=false;
z=0;
z_relative=true;
}

View File

@ -38,6 +38,8 @@ class Node2D : public CanvasItem {
Point2 pos;
float angle;
Size2 scale;
int z;
bool z_relative;
Matrix32 _mat;
@ -85,6 +87,11 @@ public:
void set_global_transform(const Matrix32& p_transform);
void set_global_pos(const Point2& p_pos);
void set_z(int p_z);
int get_z() const;
void set_z_as_relative(bool p_enabled);
bool is_z_relative() const;
Matrix32 get_transform() const;

View File

@ -43,13 +43,44 @@ void PhysicsBody2D::_notification(int p_what) {
*/
}
void PhysicsBody2D::set_one_way_collision_direction(const Vector2& p_dir) {
one_way_collision_direction=p_dir;
Physics2DServer::get_singleton()->body_set_one_way_collision_direction(get_rid(),p_dir);
}
Vector2 PhysicsBody2D::get_one_way_collision_direction() const{
return one_way_collision_direction;
}
void PhysicsBody2D::set_one_way_collision_max_depth(float p_depth) {
one_way_collision_max_depth=p_depth;
Physics2DServer::get_singleton()->body_set_one_way_collision_max_depth(get_rid(),p_depth);
}
float PhysicsBody2D::get_one_way_collision_max_depth() const{
return one_way_collision_max_depth;
}
void PhysicsBody2D::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_layer_mask","mask"),&PhysicsBody2D::set_layer_mask);
ObjectTypeDB::bind_method(_MD("get_layer_mask"),&PhysicsBody2D::get_layer_mask);
ObjectTypeDB::bind_method(_MD("set_one_way_collision_direction","dir"),&PhysicsBody2D::set_one_way_collision_direction);
ObjectTypeDB::bind_method(_MD("get_one_way_collision_direction"),&PhysicsBody2D::get_one_way_collision_direction);
ObjectTypeDB::bind_method(_MD("set_one_way_collision_max_depth","depth"),&PhysicsBody2D::set_one_way_collision_max_depth);
ObjectTypeDB::bind_method(_MD("get_one_way_collision_max_depth"),&PhysicsBody2D::get_one_way_collision_max_depth);
ObjectTypeDB::bind_method(_MD("add_collision_exception_with","body:PhysicsBody2D"),&PhysicsBody2D::add_collision_exception_with);
ObjectTypeDB::bind_method(_MD("remove_collision_exception_with","body:PhysicsBody2D"),&PhysicsBody2D::remove_collision_exception_with);
ADD_PROPERTY(PropertyInfo(Variant::INT,"layers",PROPERTY_HINT_ALL_FLAGS),_SCS("set_layer_mask"),_SCS("get_layer_mask"));
ADD_PROPERTYNZ(PropertyInfo(Variant::VECTOR2,"one_way_collision/direction"),_SCS("set_one_way_collision_direction"),_SCS("get_one_way_collision_direction"));
ADD_PROPERTYNZ(PropertyInfo(Variant::REAL,"one_way_collision/max_depth"),_SCS("set_one_way_collision_max_depth"),_SCS("get_one_way_collision_max_depth"));
}
void PhysicsBody2D::set_layer_mask(uint32_t p_mask) {
@ -66,6 +97,7 @@ uint32_t PhysicsBody2D::get_layer_mask() const {
PhysicsBody2D::PhysicsBody2D(Physics2DServer::BodyMode p_mode) : CollisionObject2D( Physics2DServer::get_singleton()->body_create(p_mode), false) {
mask=1;
set_one_way_collision_max_depth(0);
}
@ -932,7 +964,7 @@ Vector2 KinematicBody2D::move(const Vector2& p_motion) {
//if (d<margin)
/// continue;
recover_motion+=(b-a)*0.2;
recover_motion+=(b-a)*0.4;
}
if (recover_motion==Vector2()) {
@ -963,6 +995,7 @@ Vector2 KinematicBody2D::move(const Vector2& p_motion) {
bool valid = dss->cast_motion(get_shape(i)->get_rid(), get_global_transform() * get_shape_transform(i), p_motion, 0,lsafe,lunsafe,exclude,get_layer_mask(),mask);
//print_line("shape: "+itos(i)+" travel:"+rtos(ltravel));
if (!valid) {
safe=0;
unsafe=0;
best_shape=i; //sadly it's the best
@ -994,9 +1027,11 @@ Vector2 KinematicBody2D::move(const Vector2& p_motion) {
bool c2 = dss->rest_info(get_shape(best_shape)->get_rid(), ugt*get_shape_transform(best_shape), Vector2(), margin,&rest_info,exclude,get_layer_mask(),mask);
if (!c2) {
//should not happen, but floating point precision is so weird..
colliding=false;
} else {
//print_line("Travel: "+rtos(travel));
colliding=true;
collision=rest_info.point;

View File

@ -39,6 +39,8 @@ class PhysicsBody2D : public CollisionObject2D {
OBJ_TYPE(PhysicsBody2D,CollisionObject2D);
uint32_t mask;
Vector2 one_way_collision_direction;
float one_way_collision_max_depth;
protected:
void _notification(int p_what);
@ -53,6 +55,12 @@ public:
void add_collision_exception_with(Node* p_node); //must be physicsbody
void remove_collision_exception_with(Node* p_node);
void set_one_way_collision_direction(const Vector2& p_dir);
Vector2 get_one_way_collision_direction() const;
void set_one_way_collision_max_depth(float p_dir);
float get_one_way_collision_max_depth() const;
PhysicsBody2D();
};

View File

@ -92,6 +92,7 @@ void PhysicsBody::remove_collision_exception_with(Node* p_node) {
PhysicsServer::get_singleton()->body_remove_collision_exception(get_rid(),physics_body->get_rid());
}
void PhysicsBody::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_layer_mask","mask"),&PhysicsBody::set_layer_mask);
ObjectTypeDB::bind_method(_MD("get_layer_mask"),&PhysicsBody::get_layer_mask);

View File

@ -56,6 +56,8 @@ public:
void add_collision_exception_with(Node* p_node); //must be physicsbody
void remove_collision_exception_with(Node* p_node);
PhysicsBody();
};

View File

@ -226,5 +226,6 @@ Size2 GridContainer::get_minimum_size() const {
GridContainer::GridContainer() {
set_stop_mouse(false);
columns=1;
}

View File

@ -298,7 +298,7 @@ void TextEdit::_update_scrollbars() {
int hscroll_rows = ((hmin.height-1)/get_row_height())+1;
int visible_rows = get_visible_rows();
int total_rows = text.size() * cache.line_spacing;
int total_rows = text.size();
int vscroll_pixels = v_scroll->get_combined_minimum_size().width;
int visible_width = size.width - cache.style_normal->get_minimum_size().width;

View File

@ -272,7 +272,7 @@ void register_scene_types() {
ObjectTypeDB::register_type<Control>();
// ObjectTypeDB::register_type<EmptyControl>();
ObjectTypeDB::add_compatibility_type("EmptyControl","control");
ObjectTypeDB::add_compatibility_type("EmptyControl","Control");
ObjectTypeDB::register_type<Button>();
ObjectTypeDB::register_type<Label>();
ObjectTypeDB::register_type<HScrollBar>();
@ -500,14 +500,13 @@ void register_scene_types() {
ObjectTypeDB::register_type<Mesh>();
ObjectTypeDB::register_virtual_type<Material>();
ObjectTypeDB::register_type<FixedMaterial>();
//ObjectTypeDB::register_type<ParticleSystemMaterial>();
//ObjectTypeDB::register_type<UnshadedMaterial>();
ObjectTypeDB::register_type<ShaderMaterial>();
ObjectTypeDB::register_type<RoomBounds>();
ObjectTypeDB::register_virtual_type<Shader>();
ObjectTypeDB::register_virtual_type<ShaderGraph>();
ObjectTypeDB::register_type<MaterialShaderGraph>();
ObjectTypeDB::register_type<MaterialShader>();
ObjectTypeDB::register_type<CanvasItemShader>();
ObjectTypeDB::add_compatibility_type("Shader","MaterialShader");
ObjectTypeDB::add_compatibility_type("ParticleSystemMaterial","FixedMaterial");
ObjectTypeDB::add_compatibility_type("UnshadedMaterial","FixedMaterial");

View File

@ -467,10 +467,20 @@ bool ShaderMaterial::_set(const StringName& p_name, const Variant& p_value) {
return true;
} else {
String n = p_name;
if (n.begins_with("param/")) {
VisualServer::get_singleton()->material_set_param(material,String(n.ptr()+6),p_value);
return true;
if (shader.is_valid()) {
StringName pr = shader->remap_param(p_name);
if (!pr) {
String n = p_name;
if (n.find("param/")==0) { //backwards compatibility
pr = n.substr(6,n.length());
}
}
if (pr) {
VisualServer::get_singleton()->material_set_param(material,pr,p_value);
return true;
}
}
}
@ -486,10 +496,13 @@ bool ShaderMaterial::_get(const StringName& p_name,Variant &r_ret) const {
return true;
} else {
String n = p_name;
if (n.begins_with("param/")) {
r_ret=VisualServer::get_singleton()->material_get_param(material,String(n.ptr()+6));
return true;
if (shader.is_valid()) {
StringName pr = shader->remap_param(p_name);
if (pr) {
r_ret=VisualServer::get_singleton()->material_get_param(material,pr);
return true;
}
}
}
@ -569,7 +582,7 @@ void ShaderMaterial::get_argument_options(const StringName& p_function,int p_idx
List<PropertyInfo> pl;
shader->get_param_list(&pl);
for (List<PropertyInfo>::Element *E=pl.front();E;E=E->next()) {
r_options->push_back(E->get().name);
r_options->push_back("\""+E->get().name.replace("shader_param/","")+"\"");
}
}
}
@ -583,115 +596,3 @@ ShaderMaterial::ShaderMaterial() :Material(VisualServer::get_singleton()->materi
/////////////////////////////////
void ParticleSystemMaterial::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_texture","texture"),&ParticleSystemMaterial::set_texture);
ObjectTypeDB::bind_method(_MD("get_texture:Texture"),&ParticleSystemMaterial::get_texture);
ADD_PROPERTY( PropertyInfo( Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE,"Texture" ), _SCS("set_texture"), _SCS("get_texture"));
}
void ParticleSystemMaterial::set_texture(const Ref<Texture>& p_texture) {
texture=p_texture;
RID rid;
if (texture.is_valid())
rid=texture->get_rid();
VS::get_singleton()->fixed_material_set_texture(material,VS::FIXED_MATERIAL_PARAM_DIFFUSE,rid);
}
Ref<Texture> ParticleSystemMaterial::get_texture() const {
return texture;
}
ParticleSystemMaterial::ParticleSystemMaterial() :Material(VisualServer::get_singleton()->fixed_material_create()){
set_flag(FLAG_DOUBLE_SIDED,true);
set_flag(FLAG_UNSHADED,true);
set_depth_draw_mode(DEPTH_DRAW_NEVER);
VisualServer::get_singleton()->fixed_material_set_flag(material,VS::FIXED_MATERIAL_FLAG_USE_ALPHA,true);
VisualServer::get_singleton()->fixed_material_set_flag(material,VS::FIXED_MATERIAL_FLAG_USE_COLOR_ARRAY,true);
set_flag(FLAG_COLOR_ARRAY_SRGB,true);
}
ParticleSystemMaterial::~ParticleSystemMaterial() {
}
//////////////////////////////
void UnshadedMaterial::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_texture","texture"),&UnshadedMaterial::set_texture);
ObjectTypeDB::bind_method(_MD("get_texture:Texture"),&UnshadedMaterial::get_texture);
ObjectTypeDB::bind_method(_MD("set_use_alpha","enable"),&UnshadedMaterial::set_use_alpha);
ObjectTypeDB::bind_method(_MD("is_using_alpha"),&UnshadedMaterial::is_using_alpha);
ObjectTypeDB::bind_method(_MD("set_use_color_array","enable"),&UnshadedMaterial::set_use_color_array);
ObjectTypeDB::bind_method(_MD("is_using_color_array"),&UnshadedMaterial::is_using_color_array);
ADD_PROPERTY( PropertyInfo( Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE,"Texture" ), _SCS("set_texture"), _SCS("get_texture"));
ADD_PROPERTY( PropertyInfo( Variant::BOOL, "alpha" ), _SCS("set_use_alpha"), _SCS("is_using_alpha"));
ADD_PROPERTY( PropertyInfo( Variant::BOOL, "color_array" ), _SCS("set_use_color_array"), _SCS("is_using_color_array"));
}
void UnshadedMaterial::set_texture(const Ref<Texture>& p_texture) {
RID rid;
if (texture.is_valid())
rid=texture->get_rid();
VS::get_singleton()->fixed_material_set_texture(material,VS::FIXED_MATERIAL_PARAM_DIFFUSE,rid);
}
Ref<Texture> UnshadedMaterial::get_texture() const {
return texture;
}
void UnshadedMaterial::set_use_alpha(bool p_use_alpha) {
alpha=p_use_alpha;
VS::get_singleton()->fixed_material_set_flag(material,VS::FIXED_MATERIAL_FLAG_USE_ALPHA,p_use_alpha);
//set_depth_draw_mode();
//set_hint(HINT,p_use_alpha);
}
bool UnshadedMaterial::is_using_alpha() const{
return alpha;
}
void UnshadedMaterial::set_use_color_array(bool p_use_color_array){
color_array=p_use_color_array;
VS::get_singleton()->fixed_material_set_flag(material,VS::FIXED_MATERIAL_FLAG_USE_COLOR_ARRAY,p_use_color_array);
}
bool UnshadedMaterial::is_using_color_array() const{
return color_array;
}
UnshadedMaterial::UnshadedMaterial() :Material(VisualServer::get_singleton()->fixed_material_create()){
set_flag(FLAG_UNSHADED,true);
set_use_alpha(true);
set_flag(FLAG_COLOR_ARRAY_SRGB,true);
}
UnshadedMaterial::~UnshadedMaterial() {
}

View File

@ -253,68 +253,6 @@ public:
class ParticleSystemMaterial : public Material {
OBJ_TYPE( ParticleSystemMaterial, Material );
REVERSE_GET_PROPERTY_LIST
private:
Ref<Texture> texture;
protected:
static void _bind_methods();
public:
void set_texture(const Ref<Texture>& p_texture);
Ref<Texture> get_texture() const;
ParticleSystemMaterial();
~ParticleSystemMaterial();
};
///////////////////////////////////////////
class UnshadedMaterial : public Material {
OBJ_TYPE( UnshadedMaterial, Material );
REVERSE_GET_PROPERTY_LIST
private:
bool alpha;
bool color_array;
Ref<Texture> texture;
protected:
static void _bind_methods();
public:
void set_texture(const Ref<Texture>& p_texture);
Ref<Texture> get_texture() const;
void set_use_alpha(bool p_use_alpha);
bool is_using_alpha() const;
void set_use_color_array(bool p_use_color_array);
bool is_using_color_array() const;
UnshadedMaterial();
~UnshadedMaterial();
};
#endif

View File

@ -84,7 +84,7 @@ void Shader::get_param_list(List<PropertyInfo> *p_params) const {
for(List<PropertyInfo>::Element *E=local.front();E;E=E->next()) {
PropertyInfo pi=E->get();
pi.name="param/"+pi.name;
pi.name="shader_param/"+pi.name;
params_cache[pi.name]=E->get().name;
if (p_params) {

View File

@ -80,6 +80,16 @@ public:
Ref<Texture> get_default_texture_param(const StringName& p_param) const;
void get_default_texture_param_list(List<StringName>* r_textures) const;
_FORCE_INLINE_ StringName remap_param(const StringName& p_param) const {
if (params_cache_dirty)
get_param_list(NULL);
const Map<StringName,StringName>::Element *E=params_cache.find(p_param);
if (E)
return E->get();
return StringName();
}
virtual RID get_rid() const;
Shader(Mode p_mode);
@ -98,6 +108,15 @@ public:
MaterialShader() : Shader(MODE_MATERIAL) {};
};
class CanvasItemShader : public Shader {
OBJ_TYPE(CanvasItemShader,Shader);
public:
CanvasItemShader() : Shader(MODE_CANVAS_ITEM) {};
};
class ResourceFormatLoaderShader : public ResourceFormatLoader {

View File

@ -28,9 +28,6 @@
/*************************************************************************/
#include "shader_graph.h"
#include "scene/scene_string_names.h"
//todo
//-RGB ops
//-mostrar error de conexion
Array ShaderGraph::_get_node_list(ShaderType p_type) const {

View File

@ -647,6 +647,7 @@ Body2DSW::Body2DSW() : CollisionObject2DSW(TYPE_BODY), active_list(this), inerti
area_linear_damp=0;
contact_count=0;
gravity_scale=1.0;
one_way_collision_max_depth=0.1;
still_time=0;
continuous_cd_mode=Physics2DServer::CCD_MODE_DISABLED;

View File

@ -67,6 +67,9 @@ class Body2DSW : public CollisionObject2DSW {
Vector2 applied_force;
real_t applied_torque;
Vector2 one_way_collision_direction;
float one_way_collision_max_depth;
SelfList<Body2DSW> active_list;
SelfList<Body2DSW> inertia_update_list;
@ -216,6 +219,12 @@ public:
_FORCE_INLINE_ void set_continuous_collision_detection_mode(Physics2DServer::CCDMode p_mode) { continuous_cd_mode=p_mode; }
_FORCE_INLINE_ Physics2DServer::CCDMode get_continuous_collision_detection_mode() const { return continuous_cd_mode; }
void set_one_way_collision_direction(const Vector2& p_dir) { one_way_collision_direction=p_dir; }
Vector2 get_one_way_collision_direction() const { return one_way_collision_direction; }
void set_one_way_collision_max_depth(float p_depth) { one_way_collision_max_depth=p_depth; }
float get_one_way_collision_max_depth() const { return one_way_collision_max_depth; }
void set_space(Space2DSW *p_space);
void update_inertias();

View File

@ -138,6 +138,21 @@ void Physics2DServerSW::_shape_col_cbk(const Vector2& p_point_A,const Vector2& p
if (cbk->max==0)
return;
if (cbk->valid_dir!=Vector2()) {
if (p_point_A.distance_squared_to(p_point_B)>cbk->valid_depth*cbk->valid_depth) {
return;
}
if (cbk->valid_dir.dot((p_point_A-p_point_B).normalized())<0.7071) {
/* print_line("A: "+p_point_A);
print_line("B: "+p_point_B);
print_line("discard too angled "+rtos(cbk->valid_dir.dot((p_point_A-p_point_B))));
print_line("resnorm: "+(p_point_A-p_point_B).normalized());
print_line("distance: "+rtos(p_point_A.distance_to(p_point_B)));
*/
return;
}
}
if (cbk->amount == cbk->max) {
//find least deep
float min_depth=1e20;
@ -860,6 +875,37 @@ int Physics2DServerSW::body_get_max_contacts_reported(RID p_body) const {
return body->get_max_contacts_reported();
}
void Physics2DServerSW::body_set_one_way_collision_direction(RID p_body,const Vector2& p_direction) {
Body2DSW *body = body_owner.get(p_body);
ERR_FAIL_COND(!body);
body->set_one_way_collision_direction(p_direction);
}
Vector2 Physics2DServerSW::body_get_one_way_collision_direction(RID p_body) const{
Body2DSW *body = body_owner.get(p_body);
ERR_FAIL_COND_V(!body,Vector2());
return body->get_one_way_collision_direction();
}
void Physics2DServerSW::body_set_one_way_collision_max_depth(RID p_body,float p_max_depth) {
Body2DSW *body = body_owner.get(p_body);
ERR_FAIL_COND(!body);
body->set_one_way_collision_max_depth(p_max_depth);
}
float Physics2DServerSW::body_get_one_way_collision_max_depth(RID p_body) const {
Body2DSW *body = body_owner.get(p_body);
ERR_FAIL_COND_V(!body,0);
return body->get_one_way_collision_max_depth();
}
void Physics2DServerSW::body_set_force_integration_callback(RID p_body,Object *p_receiver,const StringName& p_method,const Variant& p_udata) {

View File

@ -71,6 +71,8 @@ public:
struct CollCbkData {
Vector2 valid_dir;
float valid_depth;
int max;
int amount;
Vector2 *ptr;
@ -205,6 +207,13 @@ public:
virtual void body_set_max_contacts_reported(RID p_body, int p_contacts);
virtual int body_get_max_contacts_reported(RID p_body) const;
virtual void body_set_one_way_collision_direction(RID p_body,const Vector2& p_direction);
virtual Vector2 body_get_one_way_collision_direction(RID p_body) const;
virtual void body_set_one_way_collision_max_depth(RID p_body,float p_max_depth);
virtual float body_get_one_way_collision_max_depth(RID p_body) const;
virtual void body_set_force_integration_callback(RID p_body,Object *p_receiver,const StringName& p_method,const Variant& p_udata=Variant());
virtual bool body_collide_shape(RID p_body, int p_body_shape,RID p_shape, const Matrix32& p_shape_xform,const Vector2& p_motion,Vector2 *r_results,int p_result_max,int &r_result_count);

View File

@ -98,7 +98,7 @@ bool Physics2DDirectSpaceStateSW::intersect_ray(const Vector2& p_from, const Vec
if (shape->intersect_segment(local_from,local_to,shape_point,shape_normal)) {
//print_line("inters sgment!");
Matrix32 xform = col_obj->get_transform() * col_obj->get_shape_transform(shape_idx);
shape_point=xform.xform(shape_point);
@ -217,6 +217,16 @@ bool Physics2DDirectSpaceStateSW::cast_motion(const RID& p_shape, const Matrix32
int shape_idx=space->intersection_query_subindex_results[i];
/*if (col_obj->get_type()==CollisionObject2DSW::TYPE_BODY) {
const Body2DSW *body=static_cast<const Body2DSW*>(col_obj);
if (body->get_one_way_collision_direction()!=Vector2() && p_motion.dot(body->get_one_way_collision_direction())<=CMP_EPSILON) {
print_line("failed in motion dir");
continue;
}
}*/
Matrix32 col_obj_xform = col_obj->get_transform() * col_obj->get_shape_transform(shape_idx);
//test initial overlap, does it collide if going all the way?
if (!CollisionSolver2DSW::solve(shape,p_xform,p_motion,col_obj->get_shape(shape_idx),col_obj_xform,Vector2() ,NULL,NULL,NULL,p_margin)) {
@ -227,6 +237,14 @@ bool Physics2DDirectSpaceStateSW::cast_motion(const RID& p_shape, const Matrix32
//test initial overlap
if (CollisionSolver2DSW::solve(shape,p_xform,Vector2(),col_obj->get_shape(shape_idx),col_obj_xform,Vector2() ,NULL,NULL,NULL,p_margin)) {
if (col_obj->get_type()==CollisionObject2DSW::TYPE_BODY) {
//if one way collision direction ignore initial overlap
const Body2DSW *body=static_cast<const Body2DSW*>(col_obj);
if (body->get_one_way_collision_direction()!=Vector2()) {
continue;
}
}
return false;
}
@ -253,6 +271,29 @@ bool Physics2DDirectSpaceStateSW::cast_motion(const RID& p_shape, const Matrix32
}
}
if (col_obj->get_type()==CollisionObject2DSW::TYPE_BODY) {
const Body2DSW *body=static_cast<const Body2DSW*>(col_obj);
if (body->get_one_way_collision_direction()!=Vector2()) {
Vector2 cd[2];
Physics2DServerSW::CollCbkData cbk;
cbk.max=1;
cbk.amount=0;
cbk.ptr=cd;
cbk.valid_dir=body->get_one_way_collision_direction();
cbk.valid_depth=body->get_one_way_collision_max_depth();
Vector2 sep=mnormal; //important optimization for this to work fast enough
bool collided = CollisionSolver2DSW::solve(shape,p_xform,p_motion*(hi+space->contact_max_allowed_penetration),col_obj->get_shape(shape_idx),col_obj_xform,Vector2(),Physics2DServerSW::_shape_col_cbk,&cbk,&sep,p_margin);
if (!collided || cbk.amount==0) {
continue;
}
}
}
if (low<best_safe) {
best_safe=low;
best_unsafe=hi;
@ -311,14 +352,23 @@ bool Physics2DDirectSpaceStateSW::collide_shape(RID p_shape, const Matrix32& p_s
if (p_exclude.has( col_obj->get_self() ))
continue;
if (col_obj->get_type()==CollisionObject2DSW::TYPE_BODY) {
const Body2DSW *body=static_cast<const Body2DSW*>(col_obj);
cbk.valid_dir=body->get_one_way_collision_direction();
cbk.valid_depth=body->get_one_way_collision_max_depth();
} else {
cbk.valid_dir=Vector2();
cbk.valid_depth=0;
}
if (CollisionSolver2DSW::solve(shape,p_shape_xform,p_motion,col_obj->get_shape(shape_idx),col_obj->get_transform() * col_obj->get_shape_transform(shape_idx),Vector2(),cbkres,cbkptr,NULL,p_margin)) {
collided=true;
collided=p_result_max==0 || cbk.amount>0;
}
}
r_result_count=cbk.amount;
return collided;
@ -334,6 +384,8 @@ struct _RestCallbackData2D {
Vector2 best_contact;
Vector2 best_normal;
float best_len;
Vector2 valid_dir;
float valid_depth;
};
static void _rest_cbk_result(const Vector2& p_point_A,const Vector2& p_point_B,void *p_userdata) {
@ -341,11 +393,23 @@ static void _rest_cbk_result(const Vector2& p_point_A,const Vector2& p_point_B,v
_RestCallbackData2D *rd=(_RestCallbackData2D*)p_userdata;
if (rd->valid_dir!=Vector2()) {
if (rd->valid_dir!=Vector2()) {
if (p_point_A.distance_squared_to(p_point_B)>rd->valid_depth*rd->valid_depth)
return;
if (rd->valid_dir.dot((p_point_A-p_point_B).normalized())<Math_PI*0.25)
return;
}
}
Vector2 contact_rel = p_point_B - p_point_A;
float len = contact_rel.length();
if (len <= rd->best_len)
return;
rd->best_len=len;
rd->best_contact=p_point_B;
rd->best_normal=contact_rel/len;
@ -385,6 +449,17 @@ bool Physics2DDirectSpaceStateSW::rest_info(RID p_shape, const Matrix32& p_shape
if (p_exclude.has( col_obj->get_self() ))
continue;
if (col_obj->get_type()==CollisionObject2DSW::TYPE_BODY) {
const Body2DSW *body=static_cast<const Body2DSW*>(col_obj);
rcd.valid_dir=body->get_one_way_collision_direction();
rcd.valid_depth=body->get_one_way_collision_max_depth();
} else {
rcd.valid_dir=Vector2();
rcd.valid_depth=0;
}
rcd.object=col_obj;
rcd.shape=shape_idx;
bool sc = CollisionSolver2DSW::solve(shape,p_shape_xform,p_motion,col_obj->get_shape(shape_idx),col_obj->get_transform() * col_obj->get_shape_transform(shape_idx),Vector2() ,_rest_cbk_result,&rcd,NULL,p_margin);

View File

@ -500,6 +500,13 @@ void Physics2DServer::_bind_methods() {
ObjectTypeDB::bind_method(_MD("body_set_max_contacts_reported","body","amount"),&Physics2DServer::body_set_max_contacts_reported);
ObjectTypeDB::bind_method(_MD("body_get_max_contacts_reported","body"),&Physics2DServer::body_get_max_contacts_reported);
ObjectTypeDB::bind_method(_MD("body_set_one_way_collision_direction","normal"),&Physics2DServer::body_set_one_way_collision_direction);
ObjectTypeDB::bind_method(_MD("body_get_one_way_collision_direction"),&Physics2DServer::body_get_one_way_collision_direction);
ObjectTypeDB::bind_method(_MD("body_set_one_way_collision_max_depth","normal"),&Physics2DServer::body_set_one_way_collision_max_depth);
ObjectTypeDB::bind_method(_MD("body_get_one_way_collision_max_depth"),&Physics2DServer::body_get_one_way_collision_max_depth);
ObjectTypeDB::bind_method(_MD("body_set_omit_force_integration","body","enable"),&Physics2DServer::body_set_omit_force_integration);
ObjectTypeDB::bind_method(_MD("body_is_omitting_force_integration","body"),&Physics2DServer::body_is_omitting_force_integration);

View File

@ -442,6 +442,12 @@ public:
virtual void body_set_max_contacts_reported(RID p_body, int p_contacts)=0;
virtual int body_get_max_contacts_reported(RID p_body) const=0;
virtual void body_set_one_way_collision_direction(RID p_body,const Vector2& p_direction)=0;
virtual Vector2 body_get_one_way_collision_direction(RID p_body) const=0;
virtual void body_set_one_way_collision_max_depth(RID p_body,float p_max_depth)=0;
virtual float body_get_one_way_collision_max_depth(RID p_body) const=0;
//missing remove
virtual void body_set_contacts_reported_depth_treshold(RID p_body, float p_treshold)=0;
virtual float body_get_contacts_reported_depth_treshold(RID p_body) const=0;

View File

@ -568,8 +568,9 @@ void Rasterizer::_update_fixed_materials() {
}
material_set_param(fm.self,_fixed_material_uv_xform_name,fm.uv_xform);
if (fm.use_pointsize)
if (fm.use_pointsize) {
material_set_param(fm.self,_fixed_material_point_size_name,fm.point_size);
}
}
fixed_material_dirty_list.remove(fixed_material_dirty_list.first());
@ -620,6 +621,8 @@ Rasterizer::Rasterizer() {
_fixed_material_uv_xform_name="fmp_uv_xform";
_fixed_material_point_size_name="fmp_point_size";
draw_viewport_func=NULL;
ERR_FAIL_COND( sizeof(FixedMaterialShaderKey)!=4);
}

View File

@ -40,6 +40,9 @@
class Rasterizer {
protected:
typedef void (*CanvasItemDrawViewportFunc)(VisualServer*owner,void*ud,const Rect2& p_rect);
RID create_default_material();
RID create_overdraw_debug_material();
@ -207,6 +210,8 @@ public:
virtual void shader_set_default_texture_param(RID p_shader, const StringName& p_name, RID p_texture)=0;
virtual RID shader_get_default_texture_param(RID p_shader, const StringName& p_name) const=0;
virtual Variant shader_get_default_param(RID p_shader, const StringName& p_name)=0;
/* COMMON MATERIAL API */
virtual RID material_create()=0;
@ -561,7 +566,279 @@ public:
CANVAS_RECT_FLIP_H=4,
CANVAS_RECT_FLIP_V=8
};
struct CanvasItem {
struct Command {
enum Type {
TYPE_LINE,
TYPE_RECT,
TYPE_STYLE,
TYPE_PRIMITIVE,
TYPE_POLYGON,
TYPE_POLYGON_PTR,
TYPE_CIRCLE,
TYPE_TRANSFORM,
TYPE_BLEND_MODE,
TYPE_CLIP_IGNORE,
};
Type type;
};
struct CommandLine : public Command {
Point2 from,to;
Color color;
float width;
CommandLine() { type = TYPE_LINE; }
};
struct CommandRect : public Command {
Rect2 rect;
RID texture;
Color modulate;
Rect2 source;
uint8_t flags;
CommandRect() { flags=0; type = TYPE_RECT; }
};
struct CommandStyle : public Command {
Rect2 rect;
RID texture;
float margin[4];
float draw_center;
Color color;
CommandStyle() { draw_center=true; type = TYPE_STYLE; }
};
struct CommandPrimitive : public Command {
Vector<Point2> points;
Vector<Point2> uvs;
Vector<Color> colors;
RID texture;
float width;
CommandPrimitive() { type = TYPE_PRIMITIVE; width=1;}
};
struct CommandPolygon : public Command {
Vector<int> indices;
Vector<Point2> points;
Vector<Point2> uvs;
Vector<Color> colors;
RID texture;
int count;
CommandPolygon() { type = TYPE_POLYGON; count = 0; }
};
struct CommandPolygonPtr : public Command {
const int* indices;
const Point2* points;
const Point2* uvs;
const Color* colors;
RID texture;
int count;
CommandPolygonPtr() { type = TYPE_POLYGON_PTR; count = 0; }
};
struct CommandCircle : public Command {
Point2 pos;
float radius;
Color color;
CommandCircle() { type = TYPE_CIRCLE; }
};
struct CommandTransform : public Command {
Matrix32 xform;
CommandTransform() { type = TYPE_TRANSFORM; }
};
struct CommandBlendMode : public Command {
VS::MaterialBlendMode blend_mode;
CommandBlendMode() { type = TYPE_BLEND_MODE; blend_mode = VS::MATERIAL_BLEND_MODE_MIX; }
};
struct CommandClipIgnore : public Command {
bool ignore;
CommandClipIgnore() { type = TYPE_CLIP_IGNORE; ignore=false; }
};
struct ViewportRender {
VisualServer*owner;
void* udata;
Rect2 rect;
};
Matrix32 xform;
bool clip;
bool visible;
bool ontop;
VS::MaterialBlendMode blend_mode;
Vector<Command*> commands;
mutable bool custom_rect;
mutable bool rect_dirty;
mutable Rect2 rect;
CanvasItem*next;
RID shader;
Map<StringName,Variant> shader_param;
uint32_t shader_version;
float final_opacity;
Matrix32 final_transform;
Rect2 final_clip_rect;
CanvasItem* final_clip_owner;
CanvasItem* shader_owner;
ViewportRender *vp_render;
const Rect2& get_rect() const {
if (custom_rect || !rect_dirty)
return rect;
//must update rect
int s=commands.size();
if (s==0) {
rect=Rect2();
rect_dirty=false;
return rect;
}
Matrix32 xf;
bool found_xform=false;
bool first=true;
const CanvasItem::Command * const *cmd = &commands[0];
for (int i=0;i<s;i++) {
const CanvasItem::Command *c=cmd[i];
Rect2 r;
switch(c->type) {
case CanvasItem::Command::TYPE_LINE: {
const CanvasItem::CommandLine* line = static_cast< const CanvasItem::CommandLine*>(c);
r.pos=line->from;
r.expand_to(line->to);
} break;
case CanvasItem::Command::TYPE_RECT: {
const CanvasItem::CommandRect* crect = static_cast< const CanvasItem::CommandRect*>(c);
r=crect->rect;
} break;
case CanvasItem::Command::TYPE_STYLE: {
const CanvasItem::CommandStyle* style = static_cast< const CanvasItem::CommandStyle*>(c);
r=style->rect;
} break;
case CanvasItem::Command::TYPE_PRIMITIVE: {
const CanvasItem::CommandPrimitive* primitive = static_cast< const CanvasItem::CommandPrimitive*>(c);
r.pos=primitive->points[0];
for(int i=1;i<primitive->points.size();i++) {
r.expand_to(primitive->points[i]);
}
} break;
case CanvasItem::Command::TYPE_POLYGON: {
const CanvasItem::CommandPolygon* polygon = static_cast< const CanvasItem::CommandPolygon*>(c);
int l = polygon->points.size();
const Point2*pp=&polygon->points[0];
r.pos=pp[0];
for(int i=1;i<l;i++) {
r.expand_to(pp[i]);
}
} break;
case CanvasItem::Command::TYPE_POLYGON_PTR: {
const CanvasItem::CommandPolygonPtr* polygon = static_cast< const CanvasItem::CommandPolygonPtr*>(c);
int l = polygon->count;
if (polygon->indices != NULL) {
r.pos=polygon->points[polygon->indices[0]];
for (int i=1; i<polygon->count; i++) {
r.expand_to(polygon->points[polygon->indices[i]]);
};
} else {
r.pos=polygon->points[0];
for (int i=1; i<polygon->count; i++) {
r.expand_to(polygon->points[i]);
};
};
} break;
case CanvasItem::Command::TYPE_CIRCLE: {
const CanvasItem::CommandCircle* circle = static_cast< const CanvasItem::CommandCircle*>(c);
r.pos=Point2(-circle->radius,-circle->radius)+circle->pos;
r.size=Point2(circle->radius*2.0,circle->radius*2.0);
} break;
case CanvasItem::Command::TYPE_TRANSFORM: {
const CanvasItem::CommandTransform* transform = static_cast<const CanvasItem::CommandTransform*>(c);
xf=transform->xform;
found_xform=true;
continue;
} break;
case CanvasItem::Command::TYPE_BLEND_MODE: {
} break;
case CanvasItem::Command::TYPE_CLIP_IGNORE: {
} break;
}
if (found_xform) {
r = xf.xform(r);
found_xform=false;
}
if (first) {
rect=r;
first=false;
} else
rect=rect.merge(r);
}
rect_dirty=false;
return rect;
}
void clear() { for (int i=0;i<commands.size();i++) memdelete( commands[i] ); commands.clear(); clip=false; rect_dirty=true; final_clip_owner=NULL; shader_owner=NULL;}
CanvasItem() { vp_render=NULL; next=NULL; final_clip_owner=NULL; clip=false; final_opacity=1; blend_mode=VS::MATERIAL_BLEND_MODE_MIX; visible=true; rect_dirty=true; custom_rect=false; ontop=true; shader_version=0; shader_owner=NULL;}
virtual ~CanvasItem() { clear(); }
};
CanvasItemDrawViewportFunc draw_viewport_func;
virtual void canvas_begin()=0;
virtual void canvas_disable_blending()=0;
virtual void canvas_set_opacity(float p_opacity)=0;
@ -575,7 +852,10 @@ public:
virtual void canvas_draw_primitive(const Vector<Point2>& p_points, const Vector<Color>& p_colors,const Vector<Point2>& p_uvs, RID p_texture,float p_width)=0;
virtual void canvas_draw_polygon(int p_vertex_count, const int* p_indices, const Vector2* p_vertices, const Vector2* p_uvs, const Color* p_colors,const RID& p_texture,bool p_singlecolor)=0;
virtual void canvas_set_transform(const Matrix32& p_transform)=0;
virtual void canvas_render_items(CanvasItem *p_item_list)=0;
/* ENVIRONMENT */

View File

@ -231,6 +231,11 @@ RID RasterizerDummy::shader_get_default_texture_param(RID p_shader, const String
return RID();
}
Variant RasterizerDummy::shader_get_default_param(RID p_shader, const StringName& p_name) {
return Variant();
}
/* COMMON MATERIAL API */
@ -1615,6 +1620,11 @@ void RasterizerDummy::canvas_draw_polygon(int p_vertex_count, const int* p_indic
void RasterizerDummy::canvas_set_transform(const Matrix32& p_transform) {
}
void RasterizerDummy::canvas_render_items(CanvasItem *p_item_list) {
}
/* ENVIRONMENT */

View File

@ -433,6 +433,8 @@ public:
virtual void shader_set_default_texture_param(RID p_shader, const StringName& p_name, RID p_texture);
virtual RID shader_get_default_texture_param(RID p_shader, const StringName& p_name) const;
virtual Variant shader_get_default_param(RID p_shader, const StringName& p_name);
/* COMMON MATERIAL API */
virtual RID material_create();
@ -708,6 +710,8 @@ public:
virtual void canvas_draw_polygon(int p_vertex_count, const int* p_indices, const Vector2* p_vertices, const Vector2* p_uvs, const Color* p_colors,const RID& p_texture,bool p_singlecolor);
virtual void canvas_set_transform(const Matrix32& p_transform);
virtual void canvas_render_items(CanvasItem *p_item_list);
/* ENVIRONMENT */
virtual RID environment_create();

View File

@ -900,6 +900,7 @@ const ShaderLanguage::IntrinsicFuncDef ShaderLanguage::intrinsic_func_defs[]={
{"normalize",TYPE_VEC3,{TYPE_VEC3,TYPE_VOID}},
{"normalize",TYPE_VEC4,{TYPE_VEC4,TYPE_VOID}},
{"reflect",TYPE_VEC3,{TYPE_VEC3,TYPE_VEC3,TYPE_VOID}},
{"refract",TYPE_VEC3,{TYPE_VEC3,TYPE_VEC3,TYPE_FLOAT,TYPE_VOID}},
//intrinsics - texture
{"tex",TYPE_VEC4,{TYPE_TEXTURE,TYPE_VEC2,TYPE_VOID}},
{"texcube",TYPE_VEC4,{TYPE_CUBEMAP,TYPE_VEC3,TYPE_VOID}},
@ -1105,6 +1106,61 @@ const ShaderLanguage::BuiltinsDef ShaderLanguage::light_builtins_defs[]={
};
const ShaderLanguage::BuiltinsDef ShaderLanguage::ci_vertex_builtins_defs[]={
{ "SRC_VERTEX", TYPE_VEC2},
{ "VERTEX", TYPE_VEC2},
{ "UV", TYPE_VEC2},
{ "COLOR", TYPE_VEC4},
{ "VAR1", TYPE_VEC4},
{ "VAR2", TYPE_VEC4},
{ "POINT_SIZE", TYPE_FLOAT},
//builtins
{ "WORLD_MATRIX", TYPE_MAT4},
{ "PROJECTION_MATRIX", TYPE_MAT4},
{ "EXTRA_MATRIX", TYPE_MAT4},
{ "TIME", TYPE_FLOAT},
{ NULL, TYPE_VOID},
};
const ShaderLanguage::BuiltinsDef ShaderLanguage::ci_fragment_builtins_defs[]={
{ "SRC_COLOR", TYPE_VEC4},
{ "POSITION", TYPE_VEC4},
{ "NORMAL", TYPE_VEC3},
{ "UV", TYPE_VEC2},
{ "COLOR", TYPE_VEC4},
{ "TEXTURE", TYPE_TEXTURE},
{ "TEXTURE_PIXEL_SIZE", TYPE_VEC2},
{ "VAR1", TYPE_VEC4},
{ "VAR2", TYPE_VEC4},
{ "SCREEN_UV", TYPE_VEC2},
{ "POINT_COORD", TYPE_VEC2},
// { "SCREEN_POS", TYPE_VEC2},
// { "SCREEN_TEXEL_SIZE", TYPE_VEC2},
{ "TIME", TYPE_FLOAT},
{ NULL, TYPE_VOID}
};
const ShaderLanguage::BuiltinsDef ShaderLanguage::ci_light_builtins_defs[]={
{ "COLOR", TYPE_VEC4},
{ "NORMAL", TYPE_VEC3},
{ "LIGHT_DIR", TYPE_VEC2},
{ "LIGHT_DISTANCE", TYPE_FLOAT},
{ "LIGHT", TYPE_VEC3},
{ "POINT_COORD", TYPE_VEC2},
// { "SCREEN_POS", TYPE_VEC2},
// { "SCREEN_TEXEL_SIZE", TYPE_VEC2},
{ "TIME", TYPE_FLOAT},
{ NULL, TYPE_VOID}
};
const ShaderLanguage::BuiltinsDef ShaderLanguage::postprocess_fragment_builtins_defs[]={
{ "IN_COLOR", TYPE_VEC3},
@ -2471,6 +2527,27 @@ Error ShaderLanguage::parse(const Vector<Token>& p_tokens,ShaderType p_type,Comp
idx++;
}
} break;
case SHADER_CANVAS_ITEM_VERTEX: {
int idx=0;
while (ci_vertex_builtins_defs[idx].name) {
parser.program->builtin_variables[ci_vertex_builtins_defs[idx].name]=ci_vertex_builtins_defs[idx].type;
idx++;
}
} break;
case SHADER_CANVAS_ITEM_FRAGMENT: {
int idx=0;
while (ci_fragment_builtins_defs[idx].name) {
parser.program->builtin_variables[ci_fragment_builtins_defs[idx].name]=ci_fragment_builtins_defs[idx].type;
idx++;
}
} break;
case SHADER_CANVAS_ITEM_LIGHT: {
int idx=0;
while (ci_light_builtins_defs[idx].name) {
parser.program->builtin_variables[ci_light_builtins_defs[idx].name]=ci_light_builtins_defs[idx].type;
idx++;
}
} break;
case SHADER_POST_PROCESS: {
int idx=0;
while (postprocess_fragment_builtins_defs[idx].name) {
@ -2568,6 +2645,28 @@ void ShaderLanguage::get_keyword_list(ShaderType p_type, List<String> *p_keyword
idx++;
}
} break;
case SHADER_CANVAS_ITEM_VERTEX: {
idx=0;
while (ci_vertex_builtins_defs[idx].name) {
p_keywords->push_back(ci_vertex_builtins_defs[idx].name);
idx++;
}
} break;
case SHADER_CANVAS_ITEM_FRAGMENT: {
idx=0;
while (ci_fragment_builtins_defs[idx].name) {
p_keywords->push_back(ci_fragment_builtins_defs[idx].name);
idx++;
}
} break;
case SHADER_CANVAS_ITEM_LIGHT: {
idx=0;
while (ci_light_builtins_defs[idx].name) {
p_keywords->push_back(ci_light_builtins_defs[idx].name);
idx++;
}
} break;
case SHADER_POST_PROCESS: {
idx=0;
while (postprocess_fragment_builtins_defs[idx].name) {

View File

@ -105,6 +105,9 @@ public:
SHADER_MATERIAL_VERTEX,
SHADER_MATERIAL_FRAGMENT,
SHADER_MATERIAL_LIGHT,
SHADER_CANVAS_ITEM_VERTEX,
SHADER_CANVAS_ITEM_FRAGMENT,
SHADER_CANVAS_ITEM_LIGHT,
SHADER_POST_PROCESS,
};
@ -376,6 +379,12 @@ private:
static const BuiltinsDef vertex_builtins_defs[];
static const BuiltinsDef fragment_builtins_defs[];
static const BuiltinsDef light_builtins_defs[];
static const BuiltinsDef ci_vertex_builtins_defs[];
static const BuiltinsDef ci_fragment_builtins_defs[];
static const BuiltinsDef ci_light_builtins_defs[];
static const BuiltinsDef postprocess_fragment_builtins_defs[];
static DataType get_token_datatype(TokenType p_type);

View File

@ -3352,129 +3352,6 @@ void VisualServerRaster::canvas_item_set_clip(RID p_item, bool p_clip) {
canvas_item->clip=p_clip;
}
const Rect2& VisualServerRaster::CanvasItem::get_rect() const {
if (custom_rect || !rect_dirty)
return rect;
//must update rect
int s=commands.size();
if (s==0) {
rect=Rect2();
rect_dirty=false;
return rect;
}
Matrix32 xf;
bool found_xform=false;
bool first=true;
const CanvasItem::Command * const *cmd = &commands[0];
for (int i=0;i<s;i++) {
const CanvasItem::Command *c=cmd[i];
Rect2 r;
switch(c->type) {
case CanvasItem::Command::TYPE_LINE: {
const CanvasItem::CommandLine* line = static_cast< const CanvasItem::CommandLine*>(c);
r.pos=line->from;
r.expand_to(line->to);
} break;
case CanvasItem::Command::TYPE_RECT: {
const CanvasItem::CommandRect* crect = static_cast< const CanvasItem::CommandRect*>(c);
r=crect->rect;
} break;
case CanvasItem::Command::TYPE_STYLE: {
const CanvasItem::CommandStyle* style = static_cast< const CanvasItem::CommandStyle*>(c);
r=style->rect;
} break;
case CanvasItem::Command::TYPE_PRIMITIVE: {
const CanvasItem::CommandPrimitive* primitive = static_cast< const CanvasItem::CommandPrimitive*>(c);
r.pos=primitive->points[0];
for(int i=1;i<primitive->points.size();i++) {
r.expand_to(primitive->points[i]);
}
} break;
case CanvasItem::Command::TYPE_POLYGON: {
const CanvasItem::CommandPolygon* polygon = static_cast< const CanvasItem::CommandPolygon*>(c);
int l = polygon->points.size();
const Point2*pp=&polygon->points[0];
r.pos=pp[0];
for(int i=1;i<l;i++) {
r.expand_to(pp[i]);
}
} break;
case CanvasItem::Command::TYPE_POLYGON_PTR: {
const CanvasItem::CommandPolygonPtr* polygon = static_cast< const CanvasItem::CommandPolygonPtr*>(c);
int l = polygon->count;
if (polygon->indices != NULL) {
r.pos=polygon->points[polygon->indices[0]];
for (int i=1; i<polygon->count; i++) {
r.expand_to(polygon->points[polygon->indices[i]]);
};
} else {
r.pos=polygon->points[0];
for (int i=1; i<polygon->count; i++) {
r.expand_to(polygon->points[i]);
};
};
} break;
case CanvasItem::Command::TYPE_CIRCLE: {
const CanvasItem::CommandCircle* circle = static_cast< const CanvasItem::CommandCircle*>(c);
r.pos=Point2(-circle->radius,-circle->radius)+circle->pos;
r.size=Point2(circle->radius*2.0,circle->radius*2.0);
} break;
case CanvasItem::Command::TYPE_TRANSFORM: {
const CanvasItem::CommandTransform* transform = static_cast<const CanvasItem::CommandTransform*>(c);
xf=transform->xform;
found_xform=true;
continue;
} break;
case CanvasItem::Command::TYPE_BLEND_MODE: {
} break;
case CanvasItem::Command::TYPE_CLIP_IGNORE: {
} break;
}
if (found_xform) {
r = xf.xform(r);
found_xform=false;
}
if (first) {
rect=r;
first=false;
} else
rect=rect.merge(r);
}
rect_dirty=false;
return rect;
}
void VisualServerRaster::canvas_item_set_transform(RID p_item, const Matrix32& p_transform) {
@ -3812,6 +3689,74 @@ void VisualServerRaster::canvas_item_add_set_blend_mode(RID p_item, MaterialBlen
canvas_item->commands.push_back(bm);
};
void VisualServerRaster::canvas_item_set_z(RID p_item, int p_z) {
ERR_FAIL_COND(p_z<CANVAS_ITEM_Z_MIN || p_z>CANVAS_ITEM_Z_MAX);
VS_CHANGED;
CanvasItem *canvas_item = canvas_item_owner.get( p_item );
ERR_FAIL_COND(!canvas_item);
canvas_item->z=p_z;
}
void VisualServerRaster::canvas_item_set_z_as_relative_to_parent(RID p_item, bool p_enable) {
VS_CHANGED;
CanvasItem *canvas_item = canvas_item_owner.get( p_item );
ERR_FAIL_COND(!canvas_item);
canvas_item->z_relative=p_enable;
}
void VisualServerRaster::canvas_item_set_use_parent_shader(RID p_item, bool p_enable) {
VS_CHANGED;
CanvasItem *canvas_item = canvas_item_owner.get( p_item );
ERR_FAIL_COND(!canvas_item);
canvas_item->use_parent_shader=p_enable;
}
void VisualServerRaster::canvas_item_set_shader(RID p_item, RID p_shader) {
VS_CHANGED;
CanvasItem *canvas_item = canvas_item_owner.get( p_item );
ERR_FAIL_COND(!canvas_item);
canvas_item->shader=p_shader;
}
RID VisualServerRaster::canvas_item_get_shader(RID p_item) const{
CanvasItem *canvas_item = canvas_item_owner.get( p_item );
ERR_FAIL_COND_V(!canvas_item,RID());
return canvas_item->shader;
}
void VisualServerRaster::canvas_item_set_shader_param(RID p_canvas_item, const StringName& p_param, const Variant& p_value){
VS_CHANGED;
CanvasItem *canvas_item = canvas_item_owner.get( p_canvas_item );
ERR_FAIL_COND(!canvas_item);
if (p_value.get_type()==Variant::NIL)
canvas_item->shader_param.erase(p_param);
else
canvas_item->shader_param[p_param]=p_value;
}
Variant VisualServerRaster::canvas_item_get_shader_param(RID p_canvas_item, const StringName& p_param) const{
CanvasItem *canvas_item = canvas_item_owner.get( p_canvas_item );
ERR_FAIL_COND_V(!canvas_item,Variant());
if (!canvas_item->shader_param.has(p_param)) {
ERR_FAIL_COND_V(!canvas_item->shader.is_valid(),Variant());
return rasterizer->shader_get_default_param(canvas_item->shader,p_param);
}
return canvas_item->shader_param[p_param];
}
void VisualServerRaster::canvas_item_set_sort_children_by_y(RID p_item, bool p_enable) {
VS_CHANGED;
@ -6200,7 +6145,41 @@ void VisualServerRaster::_render_camera(Viewport *p_viewport,Camera *p_camera, S
rasterizer->end_scene();
}
void VisualServerRaster::_render_canvas_item(CanvasItem *p_canvas_item,const Matrix32& p_transform,const Rect2& p_clip_rect, float p_opacity) {
void VisualServerRaster::_render_canvas_item_tree(CanvasItem *p_canvas_item,const Matrix32& p_transform,const Rect2& p_clip_rect) {
static const int z_range = CANVAS_ITEM_Z_MAX-CANVAS_ITEM_Z_MIN+1;
Rasterizer::CanvasItem *z_list[z_range];
Rasterizer::CanvasItem *z_last_list[z_range];
for(int i=0;i<z_range;i++) {
z_list[i]=NULL;
z_last_list[i]=NULL;
}
_render_canvas_item(p_canvas_item,p_transform,p_clip_rect,1.0,0,z_list,z_last_list,NULL,NULL);
for(int i=0;i<z_range;i++) {
if (!z_list[i])
continue;
rasterizer->canvas_render_items(z_list[i]);
}
}
void VisualServerRaster::_render_canvas_item_viewport(VisualServer* p_self,void *p_vp,const Rect2& p_rect) {
VisualServerRaster *self=(VisualServerRaster*)(p_self);
Viewport *vp=(Viewport*)p_vp;
self->_draw_viewport(vp,p_rect.pos.x,p_rect.pos.y,p_rect.size.x,p_rect.size.y);
self->rasterizer->canvas_begin();
}
void VisualServerRaster::_render_canvas_item(CanvasItem *p_canvas_item,const Matrix32& p_transform,const Rect2& p_clip_rect, float p_opacity,int p_z,Rasterizer::CanvasItem **z_list,Rasterizer::CanvasItem **z_last_list,CanvasItem *p_canvas_clip,CanvasItem *p_shader_owner) {
CanvasItem *ci = p_canvas_item;
@ -6219,24 +6198,39 @@ void VisualServerRaster::_render_canvas_item(CanvasItem *p_canvas_item,const Mat
if (global_rect.intersects(p_clip_rect) && ci->viewport.is_valid() && viewport_owner.owns(ci->viewport)) {
Viewport *vp = viewport_owner.get(ci->viewport);
Viewport *vp = viewport_owner.get(ci->viewport);
Point2i from = xform.get_origin() + Point2(viewport_rect.x,viewport_rect.y);
Point2i size = rect.size;
size.x *= xform[0].length();
size.y *= xform[1].length();
ci->vp_render = memnew( Rasterizer::CanvasItem::ViewportRender );
ci->vp_render->owner=this;
ci->vp_render->udata=vp;
ci->vp_render->rect=Rect2(from.x,
from.y,
size.x,
size.y);
/*
_draw_viewport(vp,
from.x,
from.y,
size.x,
size.y);
rasterizer->canvas_begin();
*/
//rasterizer->canvas_begin();
} else {
ci->vp_render=NULL;
}
if (ci->use_parent_shader && p_shader_owner)
ci->shader_owner=p_shader_owner;
else {
p_shader_owner=ci;
ci->shader_owner=NULL;
}
int s = ci->commands.size();
bool reclip=false;
float opacity = ci->opacity * p_opacity;
@ -6246,8 +6240,11 @@ void VisualServerRaster::_render_canvas_item(CanvasItem *p_canvas_item,const Mat
copymem(child_items,ci->child_items.ptr(),child_item_count*sizeof(CanvasItem*));
if (ci->clip) {
rasterizer->canvas_set_clip(true,global_rect);
canvas_clip=global_rect;
ci->final_clip_rect=global_rect;
ci->final_clip_owner=ci;
} else {
ci->final_clip_owner=p_canvas_clip;
}
if (ci->sort_y) {
@ -6256,160 +6253,45 @@ void VisualServerRaster::_render_canvas_item(CanvasItem *p_canvas_item,const Mat
sorter.sort(child_items,child_item_count);
}
if (ci->z_relative)
p_z=CLAMP(p_z+ci->z,CANVAS_ITEM_Z_MIN,CANVAS_ITEM_Z_MAX);
else
p_z=ci->z;
for(int i=0;i<child_item_count;i++) {
if (child_items[i]->ontop)
continue;
_render_canvas_item(child_items[i],xform,p_clip_rect,opacity);
_render_canvas_item(child_items[i],xform,p_clip_rect,opacity,p_z,z_list,z_last_list,(CanvasItem*)ci->final_clip_owner,p_shader_owner);
}
if (s!=0) {
//Rect2 rect( ci->rect.pos + p_ofs, ci->rect.size);
if (p_clip_rect.intersects(global_rect)) {
rasterizer->canvas_begin_rect(xform);
rasterizer->canvas_set_opacity( opacity * ci->self_opacity );
rasterizer->canvas_set_blend_mode( ci->blend_mode );
CanvasItem::Command **commands = &ci->commands[0];
for (int i=0;i<s;i++) {
CanvasItem::Command *c=commands[i];
switch(c->type) {
case CanvasItem::Command::TYPE_LINE: {
CanvasItem::CommandLine* line = static_cast<CanvasItem::CommandLine*>(c);
rasterizer->canvas_draw_line(line->from,line->to,line->color,line->width);
} break;
case CanvasItem::Command::TYPE_RECT: {
CanvasItem::CommandRect* rect = static_cast<CanvasItem::CommandRect*>(c);
// rasterizer->canvas_draw_rect(rect->rect,rect->region,rect->source,rect->flags&CanvasItem::CommandRect::FLAG_TILE,rect->flags&CanvasItem::CommandRect::FLAG_FLIP_H,rect->flags&CanvasItem::CommandRect::FLAG_FLIP_V,rect->texture,rect->modulate);
#if 0
int flags=0;
if (rect->flags&CanvasItem::CommandRect::FLAG_REGION) {
flags|=Rasterizer::CANVAS_RECT_REGION;
}
if (rect->flags&CanvasItem::CommandRect::FLAG_TILE) {
flags|=Rasterizer::CANVAS_RECT_TILE;
}
if (rect->flags&CanvasItem::CommandRect::FLAG_FLIP_H) {
flags|=Rasterizer::CANVAS_RECT_FLIP_H;
}
if (rect->flags&CanvasItem::CommandRect::FLAG_FLIP_V) {
flags|=Rasterizer::CANVAS_RECT_FLIP_V;
}
#else
int flags=rect->flags;
#endif
rasterizer->canvas_draw_rect(rect->rect,flags,rect->source,rect->texture,rect->modulate);
} break;
case CanvasItem::Command::TYPE_STYLE: {
CanvasItem::CommandStyle* style = static_cast<CanvasItem::CommandStyle*>(c);
rasterizer->canvas_draw_style_box(style->rect,style->texture,style->margin,style->draw_center,style->color);
} break;
case CanvasItem::Command::TYPE_PRIMITIVE: {
CanvasItem::CommandPrimitive* primitive = static_cast<CanvasItem::CommandPrimitive*>(c);
rasterizer->canvas_draw_primitive(primitive->points,primitive->colors,primitive->uvs,primitive->texture,primitive->width);
} break;
case CanvasItem::Command::TYPE_POLYGON: {
CanvasItem::CommandPolygon* polygon = static_cast<CanvasItem::CommandPolygon*>(c);
rasterizer->canvas_draw_polygon(polygon->count,polygon->indices.ptr(),polygon->points.ptr(),polygon->uvs.ptr(),polygon->colors.ptr(),polygon->texture,polygon->colors.size()==1);
} break;
case CanvasItem::Command::TYPE_POLYGON_PTR: {
CanvasItem::CommandPolygonPtr* polygon = static_cast<CanvasItem::CommandPolygonPtr*>(c);
rasterizer->canvas_draw_polygon(polygon->count,polygon->indices,polygon->points,polygon->uvs,polygon->colors,polygon->texture,false);
} break;
case CanvasItem::Command::TYPE_CIRCLE: {
CanvasItem::CommandCircle* circle = static_cast<CanvasItem::CommandCircle*>(c);
static const int numpoints=32;
Vector2 points[numpoints+1];
points[numpoints]=circle->pos;
int indices[numpoints*3];
for(int i=0;i<numpoints;i++) {
points[i]=circle->pos+Vector2( Math::sin(i*Math_PI*2.0/numpoints),Math::cos(i*Math_PI*2.0/numpoints) )*circle->radius;
indices[i*3+0]=i;
indices[i*3+1]=(i+1)%numpoints;
indices[i*3+2]=numpoints;
}
rasterizer->canvas_draw_polygon(numpoints*3,indices,points,NULL,&circle->color,RID(),true);
//rasterizer->canvas_draw_circle(circle->indices.size(),circle->indices.ptr(),circle->points.ptr(),circle->uvs.ptr(),circle->colors.ptr(),circle->texture,circle->colors.size()==1);
} break;
case CanvasItem::Command::TYPE_TRANSFORM: {
CanvasItem::CommandTransform* transform = static_cast<CanvasItem::CommandTransform*>(c);
rasterizer->canvas_set_transform(transform->xform);
} break;
case CanvasItem::Command::TYPE_BLEND_MODE: {
CanvasItem::CommandBlendMode* bm = static_cast<CanvasItem::CommandBlendMode*>(c);
rasterizer->canvas_set_blend_mode(bm->blend_mode);
} break;
case CanvasItem::Command::TYPE_CLIP_IGNORE: {
CanvasItem::CommandClipIgnore* ci = static_cast<CanvasItem::CommandClipIgnore*>(c);
if (canvas_clip!=Rect2()) {
if (ci->ignore!=reclip) {
if (ci->ignore) {
rasterizer->canvas_set_clip(false,Rect2());
reclip=true;
} else {
rasterizer->canvas_set_clip(true,canvas_clip);
reclip=false;
}
}
}
if ((!ci->commands.empty() && p_clip_rect.intersects(global_rect)) || ci->vp_render) {
//something to draw?
ci->final_transform=xform;
ci->final_opacity=opacity * ci->self_opacity;
int zidx = p_z-CANVAS_ITEM_Z_MIN;
} break;
}
}
rasterizer->canvas_end_rect();
if (z_last_list[zidx]) {
z_last_list[zidx]->next=ci;
z_last_list[zidx]=ci;
} else {
z_list[zidx]=ci;
z_last_list[zidx]=ci;
}
}
ci->next=NULL;
if (reclip) {
rasterizer->canvas_set_clip(true,canvas_clip);
}
for(int i=0;i<child_item_count;i++) {
if (!child_items[i]->ontop)
continue;
_render_canvas_item(child_items[i],xform,p_clip_rect,opacity);
}
if (ci->clip) {
rasterizer->canvas_set_clip(false,Rect2());
canvas_clip=Rect2();
_render_canvas_item(child_items[i],xform,p_clip_rect,opacity,p_z,z_list,z_last_list,(CanvasItem*)ci->final_clip_owner,p_shader_owner);
}
}
@ -6419,29 +6301,61 @@ void VisualServerRaster::_render_canvas(Canvas *p_canvas,const Matrix32 &p_trans
rasterizer->canvas_begin();
int l = p_canvas->child_items.size();
Canvas::ChildItem *ci=p_canvas->child_items.ptr();
bool has_mirror=false;
for(int i=0;i<l;i++) {
Canvas::ChildItem& ci=p_canvas->child_items[i];
_render_canvas_item(ci.item,p_transform,Rect2(viewport_rect.x,viewport_rect.y,viewport_rect.width,viewport_rect.height),1);
//mirroring (useful for scrolling backgrounds)
if (ci.mirror.x!=0) {
Matrix32 xform2 = p_transform * Matrix32(0,Vector2(ci.mirror.x,0));
_render_canvas_item(ci.item,xform2,Rect2(viewport_rect.x,viewport_rect.y,viewport_rect.width,viewport_rect.height),1);
if (ci[i].mirror.x || ci[i].mirror.y) {
has_mirror=true;
break;
}
if (ci.mirror.y!=0) {
}
Matrix32 xform2 = p_transform * Matrix32(0,Vector2(0,ci.mirror.y));
_render_canvas_item(ci.item,xform2,Rect2(viewport_rect.x,viewport_rect.y,viewport_rect.width,viewport_rect.height),1);
Rect2 clip_rect(viewport_rect.x,viewport_rect.y,viewport_rect.width,viewport_rect.height);
if (!has_mirror) {
static const int z_range = CANVAS_ITEM_Z_MAX-CANVAS_ITEM_Z_MIN+1;
Rasterizer::CanvasItem *z_list[z_range];
Rasterizer::CanvasItem *z_last_list[z_range];
for(int i=0;i<z_range;i++) {
z_list[i]=NULL;
z_last_list[i]=NULL;
}
if (ci.mirror.y!=0 && ci.mirror.x!=0) {
Matrix32 xform2 = p_transform * Matrix32(0,ci.mirror);
_render_canvas_item(ci.item,xform2,Rect2(viewport_rect.x,viewport_rect.y,viewport_rect.width,viewport_rect.height),1);
for(int i=0;i<l;i++) {
_render_canvas_item(ci[i].item,p_transform,clip_rect,1.0,0,z_list,z_last_list,NULL,NULL);
}
for(int i=0;i<z_range;i++) {
if (!z_list[i])
continue;
rasterizer->canvas_render_items(z_list[i]);
}
} else {
for(int i=0;i<l;i++) {
Canvas::ChildItem& ci=p_canvas->child_items[i];
_render_canvas_item_tree(ci.item,p_transform,clip_rect);
//mirroring (useful for scrolling backgrounds)
if (ci.mirror.x!=0) {
Matrix32 xform2 = p_transform * Matrix32(0,Vector2(ci.mirror.x,0));
_render_canvas_item_tree(ci.item,xform2,clip_rect);
}
if (ci.mirror.y!=0) {
Matrix32 xform2 = p_transform * Matrix32(0,Vector2(0,ci.mirror.y));
_render_canvas_item_tree(ci.item,xform2,clip_rect);
}
if (ci.mirror.y!=0 && ci.mirror.x!=0) {
Matrix32 xform2 = p_transform * Matrix32(0,ci.mirror);
_render_canvas_item_tree(ci.item,xform2,clip_rect);
}
}
}
}
@ -6604,7 +6518,7 @@ void VisualServerRaster::_draw_viewports() {
rasterizer->set_viewport(viewport_rect);
}
rasterizer->canvas_begin();
rasterizer->canvas_begin();
rasterizer->canvas_disable_blending();
rasterizer->canvas_begin_rect(Matrix32());
rasterizer->canvas_draw_rect(E->get()->rt_to_screen_rect,0,Rect2(Point2(),E->get()->rt_to_screen_rect.size),E->get()->render_target_texture,Color(1,1,1));
@ -6859,6 +6773,7 @@ RID VisualServerRaster::get_test_cube() {
VisualServerRaster::VisualServerRaster(Rasterizer *p_rasterizer) {
rasterizer=p_rasterizer;
rasterizer->draw_viewport_func=_render_canvas_item_viewport;
instance_update_list=NULL;
render_pass=0;
clear_color=Color(0.3,0.3,0.3,1.0);

View File

@ -85,6 +85,7 @@ class VisualServerRaster : public VisualServer {
Vector<Point2> shape;
Rect2 bounds;
Portal() { enabled=true; disable_distance=50; disable_color=Color(); connect_range=0.8; }
};
@ -372,139 +373,32 @@ class VisualServerRaster : public VisualServer {
struct CanvasItem {
struct Command {
enum Type {
TYPE_LINE,
TYPE_RECT,
TYPE_STYLE,
TYPE_PRIMITIVE,
TYPE_POLYGON,
TYPE_POLYGON_PTR,
TYPE_CIRCLE,
TYPE_TRANSFORM,
TYPE_BLEND_MODE,
TYPE_CLIP_IGNORE,
};
Type type;
};
struct CommandLine : public Command {
Point2 from,to;
Color color;
float width;
CommandLine() { type = TYPE_LINE; }
};
struct CommandRect : public Command {
Rect2 rect;
RID texture;
Color modulate;
Rect2 source;
uint8_t flags;
CommandRect() { flags=0; type = TYPE_RECT; }
};
struct CommandStyle : public Command {
Rect2 rect;
RID texture;
float margin[4];
float draw_center;
Color color;
CommandStyle() { draw_center=true; type = TYPE_STYLE; }
};
struct CommandPrimitive : public Command {
Vector<Point2> points;
Vector<Point2> uvs;
Vector<Color> colors;
RID texture;
float width;
CommandPrimitive() { type = TYPE_PRIMITIVE; width=1;}
};
struct CanvasItem : public Rasterizer::CanvasItem {
struct CommandPolygon : public Command {
Vector<int> indices;
Vector<Point2> points;
Vector<Point2> uvs;
Vector<Color> colors;
RID texture;
int count;
CommandPolygon() { type = TYPE_POLYGON; count = 0; }
};
struct CommandPolygonPtr : public Command {
const int* indices;
const Point2* points;
const Point2* uvs;
const Color* colors;
RID texture;
int count;
CommandPolygonPtr() { type = TYPE_POLYGON_PTR; count = 0; }
};
struct CommandCircle : public Command {
Point2 pos;
float radius;
Color color;
CommandCircle() { type = TYPE_CIRCLE; }
};
struct CommandTransform : public Command {
Matrix32 xform;
CommandTransform() { type = TYPE_TRANSFORM; }
};
struct CommandBlendMode : public Command {
MaterialBlendMode blend_mode;
CommandBlendMode() { type = TYPE_BLEND_MODE; blend_mode = MATERIAL_BLEND_MODE_MIX; };
};
struct CommandClipIgnore : public Command {
bool ignore;
CommandClipIgnore() { type = TYPE_CLIP_IGNORE; ignore=false; };
};
RID parent; // canvas it belongs to
List<CanvasItem*>::Element *E;
Matrix32 xform;
bool clip;
bool visible;
bool ontop;
RID viewport;
int z;
bool z_relative;
bool sort_y;
float opacity;
float self_opacity;
MaterialBlendMode blend_mode;
RID viewport;
bool use_parent_shader;
mutable bool custom_rect;
mutable bool rect_dirty;
mutable Rect2 rect;
Vector<Command*> commands;
Vector<CanvasItem*> child_items;
const Rect2& get_rect() const;
void clear() { for (int i=0;i<commands.size();i++) memdelete( commands[i] ); commands.clear(); clip=false; rect_dirty=true;};
CanvasItem() { clip=false; E=NULL; opacity=1; self_opacity=1; blend_mode=MATERIAL_BLEND_MODE_MIX; visible=true; rect_dirty=true; custom_rect=false; ontop=true; sort_y=false;}
~CanvasItem() { clear(); }
CanvasItem() {
E=NULL;
z=0;
opacity=1;
self_opacity=1;
sort_y=false;
use_parent_shader=false;
z_relative=true;
}
};
@ -706,7 +600,9 @@ class VisualServerRaster : public VisualServer {
void _process_sampled_light(const Transform &p_camera, Instance *p_sampled_light, bool p_linear_colorspace);
void _render_camera(Viewport *p_viewport,Camera *p_camera, Scenario *p_scenario);
void _render_canvas_item(CanvasItem *p_canvas_item,const Matrix32& p_transform,const Rect2& p_clip_rect,float p_opacity);
static void _render_canvas_item_viewport(VisualServer* p_self,void *p_vp,const Rect2& p_rect);
void _render_canvas_item_tree(CanvasItem *p_canvas_item,const Matrix32& p_transform,const Rect2& p_clip_rect);
void _render_canvas_item(CanvasItem *p_canvas_item,const Matrix32& p_transform,const Rect2& p_clip_rect, float p_opacity,int p_z,Rasterizer::CanvasItem **z_list,Rasterizer::CanvasItem **z_last_list,CanvasItem *p_canvas_clip,CanvasItem *p_shader_owner);
void _render_canvas(Canvas *p_canvas,const Matrix32 &p_transform);
Vector<Vector3> _camera_generate_endpoints(Instance *p_light,Camera *p_camera,float p_range_min, float p_range_max);
Vector<Plane> _camera_generate_orthogonal_planes(Instance *p_light,Camera *p_camera,float p_range_min, float p_range_max);
@ -1217,6 +1113,17 @@ public:
virtual void canvas_item_add_set_blend_mode(RID p_item, MaterialBlendMode p_blend);
virtual void canvas_item_add_clip_ignore(RID p_item, bool p_ignore);
virtual void canvas_item_set_sort_children_by_y(RID p_item, bool p_enable);
virtual void canvas_item_set_z(RID p_item, int p_z);
virtual void canvas_item_set_z_as_relative_to_parent(RID p_item, bool p_enable);
virtual void canvas_item_set_shader(RID p_item, RID p_shader);
virtual RID canvas_item_get_shader(RID p_item) const;
virtual void canvas_item_set_use_parent_shader(RID p_item, bool p_enable);
virtual void canvas_item_set_shader_param(RID p_canvas_item, const StringName& p_param, const Variant& p_value);
virtual Variant canvas_item_get_shader_param(RID p_canvas_item, const StringName& p_param) const;
virtual void canvas_item_clear(RID p_item);
virtual void canvas_item_raise(RID p_item);

View File

@ -1131,6 +1131,17 @@ public:
FUNC2(canvas_item_add_clip_ignore,RID, bool );
FUNC2(canvas_item_set_sort_children_by_y,RID,bool);
FUNC2(canvas_item_set_z,RID,int);
FUNC2(canvas_item_set_z_as_relative_to_parent,RID,bool);
FUNC2(canvas_item_set_shader,RID, RID );
FUNC1RC(RID,canvas_item_get_shader,RID );
FUNC2(canvas_item_set_use_parent_shader,RID, bool );
FUNC3(canvas_item_set_shader_param,RID,const StringName&,const Variant&);
FUNC2RC(Variant,canvas_item_get_shader_param,RID,const StringName&);
FUNC1(canvas_item_clear,RID);
FUNC1(canvas_item_raise,RID);

View File

@ -86,6 +86,9 @@ public:
ARRAY_WEIGHTS_SIZE=4,
MAX_PARTICLE_COLOR_PHASES=4,
MAX_PARTICLE_ATTRACTORS=4,
CANVAS_ITEM_Z_MIN=-4096,
CANVAS_ITEM_Z_MAX=4096,
MAX_CURSORS = 8,
@ -982,10 +985,20 @@ public:
virtual void canvas_item_add_set_blend_mode(RID p_item, MaterialBlendMode p_blend)=0;
virtual void canvas_item_add_clip_ignore(RID p_item, bool p_ignore)=0;
virtual void canvas_item_set_sort_children_by_y(RID p_item, bool p_enable)=0;
virtual void canvas_item_set_z(RID p_item, int p_z)=0;
virtual void canvas_item_set_z_as_relative_to_parent(RID p_item, bool p_enable)=0;
virtual void canvas_item_clear(RID p_item)=0;
virtual void canvas_item_raise(RID p_item)=0;
virtual void canvas_item_set_shader(RID p_item, RID p_shader)=0;
virtual RID canvas_item_get_shader(RID p_item) const=0;
virtual void canvas_item_set_use_parent_shader(RID p_item, bool p_enable)=0;
virtual void canvas_item_set_shader_param(RID p_canvas_item, const StringName& p_param, const Variant& p_value)=0;
virtual Variant canvas_item_get_shader_param(RID p_canvas_item, const StringName& p_param) const=0;
/* CURSOR */
virtual void cursor_set_rotation(float p_rotation, int p_cursor = 0)=0; // radians
virtual void cursor_set_texture(RID p_texture, const Point2 &p_center_offset = Point2(0, 0), int p_cursor=0)=0;

View File

@ -4036,7 +4036,8 @@ EditorNode::EditorNode() {
add_editor_plugin( memnew( EditorHelpPlugin(this) ) );
add_editor_plugin( memnew( AnimationPlayerEditorPlugin(this) ) );
add_editor_plugin( memnew( ShaderGraphEditorPlugin(this) ) );
add_editor_plugin( memnew( ShaderEditorPlugin(this) ) );
add_editor_plugin( memnew( ShaderEditorPlugin(this,true) ) );
add_editor_plugin( memnew( ShaderEditorPlugin(this,false) ) );
add_editor_plugin( memnew( CameraEditorPlugin(this) ) );
add_editor_plugin( memnew( SampleEditorPlugin(this) ) );
add_editor_plugin( memnew( SampleLibraryEditorPlugin(this) ) );

View File

@ -73,6 +73,12 @@ void EditorPlugin::add_custom_control(CustomControlContainer p_location,Control
} break;
case CONTAINER_CANVAS_EDITOR_SIDE: {
CanvasItemEditor::get_singleton()->get_palette_split()->add_child(p_control);
} break;
case CONTAINER_CANVAS_EDITOR_BOTTOM: {
CanvasItemEditor::get_singleton()->get_bottom_split()->add_child(p_control);
} break;

View File

@ -66,7 +66,8 @@ public:
CONTAINER_SPATIAL_EDITOR_SIDE,
CONTAINER_SPATIAL_EDITOR_BOTTOM,
CONTAINER_CANVAS_EDITOR_MENU,
CONTAINER_CANVAS_EDITOR_SIDE
CONTAINER_CANVAS_EDITOR_SIDE,
CONTAINER_CANVAS_EDITOR_BOTTOM
};
//TODO: send a resoucre for editing to the editor node?

View File

@ -499,7 +499,7 @@ class EditorFontImportDialog : public ConfirmationDialog {
Error err = plugin->import(dest->get_line_edit()->get_text(),rimd);
if (err!=OK) {
error_dialog->set_text("Could't save font.");
error_dialog->set_text("Couldn't save font.");
error_dialog->popup_centered(Size2(200,100));
return;
}

View File

@ -411,7 +411,11 @@ void EditorTextureImportDialog::popup_import(const String& p_from) {
Ref<ResourceImportMetadata> rimd = ResourceLoader::load_import_metadata(p_from);
ERR_FAIL_COND(!rimd.is_valid());
save_path->set_text(p_from.get_base_dir());
if (plugin->get_mode()==EditorTextureImportPlugin::MODE_ATLAS)
save_path->set_text(p_from);
else
save_path->set_text(p_from.get_base_dir());
texture_options->set_format(EditorTextureImportPlugin::ImageFormat(int(rimd->get_option("format"))));
texture_options->set_flags(rimd->get_option("flags"));
texture_options->set_quality(rimd->get_option("quality"));

View File

@ -98,6 +98,7 @@ public:
IMAGE_FLAG_USE_ANISOTROPY=1024, //convert image to linear
};
Mode get_mode() const { return mode; }
virtual String get_name() const;
virtual String get_visible_name() const;
virtual void import_dialog(const String& p_from="");

View File

@ -2688,6 +2688,11 @@ HSplitContainer *CanvasItemEditor::get_palette_split() {
return palette_split;
}
VSplitContainer *CanvasItemEditor::get_bottom_split() {
return bottom_split;
}
CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) {
tool = TOOL_SELECT;
@ -2702,9 +2707,13 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) {
add_child( hb );
hb->set_area_as_parent_rect();
bottom_split = memnew( VSplitContainer );
bottom_split->set_v_size_flags(SIZE_EXPAND_FILL);
add_child(bottom_split);
palette_split = memnew( HSplitContainer);
palette_split->set_v_size_flags(SIZE_EXPAND_FILL);
add_child(palette_split);
bottom_split->add_child(palette_split);
Control *vp_base = memnew (Control);
vp_base->set_v_size_flags(SIZE_EXPAND_FILL);

View File

@ -290,8 +290,8 @@ class CanvasItemEditor : public VBoxContainer {
void _viewport_input_event(const InputEvent& p_event);
void _viewport_draw();
private:
HSplitContainer *palette_split;
VSplitContainer *bottom_split;
friend class CanvasItemEditorPlugin;
protected:
@ -346,6 +346,7 @@ public:
void add_control_to_menu_panel(Control *p_control);
HSplitContainer *get_palette_split();
VSplitContainer *get_bottom_split();
Control *get_viewport_control() { return viewport; }

View File

@ -195,7 +195,7 @@ bool Path2DEditor::forward_input_event(const InputEvent& p_event) {
Ref<Curve2D> curve = node->get_curve();
Vector2 new_pos = moving_from + xform.basis_xform( gpoint - moving_screen_from );
Vector2 new_pos = moving_from + xform.affine_inverse().basis_xform(gpoint - moving_screen_from);
switch(action) {
case ACTION_MOVING_POINT: {
@ -439,7 +439,7 @@ bool Path2DEditor::forward_input_event(const InputEvent& p_event) {
Ref<Curve2D> curve = node->get_curve();
Vector2 new_pos = moving_from + xform.basis_xform( gpoint - moving_screen_from );
Vector2 new_pos = moving_from + xform.affine_inverse().basis_xform(gpoint - moving_screen_from);
switch(action) {

View File

@ -57,9 +57,9 @@ void ShaderTextEditor::set_edited_shader(const Ref<Shader>& p_shader,ShaderLangu
_load_theme_settings();
if (p_type==ShaderLanguage::SHADER_MATERIAL_LIGHT)
if (p_type==ShaderLanguage::SHADER_MATERIAL_LIGHT || p_type==ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT)
get_text_edit()->set_text(shader->get_light_code());
else if (p_type==ShaderLanguage::SHADER_MATERIAL_VERTEX)
else if (p_type==ShaderLanguage::SHADER_MATERIAL_VERTEX || p_type==ShaderLanguage::SHADER_CANVAS_ITEM_VERTEX)
get_text_edit()->set_text(shader->get_vertex_code());
else
get_text_edit()->set_text(shader->get_fragment_code());
@ -131,17 +131,12 @@ void ShaderTextEditor::_validate_script() {
String errortxt;
int line,col;
String code;
if (type==ShaderLanguage::SHADER_MATERIAL_LIGHT)
code=get_text_edit()->get_text();
else if (type==ShaderLanguage::SHADER_MATERIAL_VERTEX)
code=get_text_edit()->get_text();
else
code=get_text_edit()->get_text();
String code=get_text_edit()->get_text();
//List<StringName> params;
//shader->get_param_list(&params);
print_line("compile: type: "+itos(type)+" code:\n"+code);
Error err = ShaderLanguage::compile(code,type,NULL,NULL,&errortxt,&line,&col);
if (err!=OK) {
@ -233,25 +228,7 @@ void ShaderEditor::_menu_option(int p_option) {
goto_line_dialog->popup_find_line(current->get_text_edit());
} break;
case SHADER_POST_PROCESS_MODE:{
fragment_editor->set_edited_shader(shader,ShaderLanguage::SHADER_POST_PROCESS);
fragment_editor->_validate_script();
apply_shaders();
settings_menu->get_popup()->set_item_checked( settings_menu->get_popup()->get_item_index(SHADER_MATERIAL_MODE), false);
settings_menu->get_popup()->set_item_checked( settings_menu->get_popup()->get_item_index(SHADER_POST_PROCESS_MODE), true);
} break;
case SHADER_MATERIAL_MODE: {
fragment_editor->set_edited_shader(shader,ShaderLanguage::SHADER_MATERIAL_FRAGMENT);
fragment_editor->_validate_script();
apply_shaders();
settings_menu->get_popup()->set_item_checked( settings_menu->get_popup()->get_item_index(SHADER_MATERIAL_MODE), true);
settings_menu->get_popup()->set_item_checked( settings_menu->get_popup()->get_item_index(SHADER_POST_PROCESS_MODE), false);
} break;
}
}
@ -408,15 +385,14 @@ void ShaderEditor::edit(const Ref<Shader>& p_shader) {
shader=p_shader;
if (shader->get_mode()==Shader::MODE_MATERIAL) {
vertex_editor->set_edited_shader(p_shader,ShaderLanguage::SHADER_MATERIAL_VERTEX);
fragment_editor->set_edited_shader(p_shader,ShaderLanguage::SHADER_MATERIAL_FRAGMENT);
light_editor->set_edited_shader(shader,ShaderLanguage::SHADER_MATERIAL_LIGHT);
settings_menu->get_popup()->set_item_checked( settings_menu->get_popup()->get_item_index(SHADER_MATERIAL_MODE), true);
settings_menu->get_popup()->set_item_checked( settings_menu->get_popup()->get_item_index(SHADER_POST_PROCESS_MODE), false);
} else {
} else if (shader->get_mode()==Shader::MODE_CANVAS_ITEM) {
fragment_editor->set_edited_shader(p_shader,ShaderLanguage::SHADER_POST_PROCESS);
settings_menu->get_popup()->set_item_checked( settings_menu->get_popup()->get_item_index(SHADER_MATERIAL_MODE), false);
settings_menu->get_popup()->set_item_checked( settings_menu->get_popup()->get_item_index(SHADER_POST_PROCESS_MODE), true);
vertex_editor->set_edited_shader(p_shader,ShaderLanguage::SHADER_CANVAS_ITEM_VERTEX);
fragment_editor->set_edited_shader(p_shader,ShaderLanguage::SHADER_CANVAS_ITEM_FRAGMENT);
light_editor->set_edited_shader(shader,ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT);
}
vertex_editor->set_edited_shader(shader,ShaderLanguage::SHADER_MATERIAL_VERTEX);
@ -495,15 +471,6 @@ ShaderEditor::ShaderEditor() {
search_menu->get_popup()->add_item("Goto Line..",SEARCH_GOTO_LINE,KEY_MASK_CMD|KEY_G);
search_menu->get_popup()->connect("item_pressed", this,"_menu_option");
settings_menu = memnew( MenuButton );
add_child(settings_menu);
settings_menu->set_pos(Point2(90,-1));
settings_menu->set_text("Shader");
settings_menu->get_popup()->add_check_item("Material Mode",SHADER_MATERIAL_MODE);
settings_menu->get_popup()->set_item_checked(settings_menu->get_popup()->get_item_index(SHADER_MATERIAL_MODE),true);
settings_menu->get_popup()->add_check_item("Post Process Mode",SHADER_POST_PROCESS_MODE);
settings_menu->get_popup()->connect("item_pressed", this,"_menu_option");
tab_container->connect("tab_changed", this,"_tab_changed");
@ -550,7 +517,13 @@ void ShaderEditorPlugin::edit(Object *p_object) {
bool ShaderEditorPlugin::handles(Object *p_object) const {
return p_object->is_type("Shader");
Shader *shader=p_object->cast_to<Shader>();
if (!shader)
return false;
if (_2d)
return shader->get_mode()==Shader::MODE_CANVAS_ITEM;
else
return shader->get_mode()==Shader::MODE_MATERIAL;
}
void ShaderEditorPlugin::make_visible(bool p_visible) {
@ -596,12 +569,15 @@ void ShaderEditorPlugin::apply_changes() {
shader_editor->apply_shaders();
}
ShaderEditorPlugin::ShaderEditorPlugin(EditorNode *p_node) {
ShaderEditorPlugin::ShaderEditorPlugin(EditorNode *p_node, bool p_2d) {
editor=p_node;
shader_editor = memnew( ShaderEditor );
SpatialEditor::get_singleton()->get_shader_split()->add_child(shader_editor);
_2d=p_2d;
if (p_2d)
add_custom_control(CONTAINER_CANVAS_EDITOR_BOTTOM,shader_editor);
else
add_custom_control(CONTAINER_SPATIAL_EDITOR_BOTTOM,shader_editor);
// editor->get_viewport()->add_child(shader_editor);
// shader_editor->set_area_as_parent_rect();

View File

@ -79,9 +79,6 @@ class ShaderEditor : public Control {
SEARCH_REPLACE,
//SEARCH_LOCATE_SYMBOL,
SEARCH_GOTO_LINE,
SHADER_MATERIAL_MODE,
SHADER_POST_PROCESS_MODE,
SHADER_SHADE_MODEL_MODE,
};
@ -134,6 +131,7 @@ class ShaderEditorPlugin : public EditorPlugin {
OBJ_TYPE( ShaderEditorPlugin, EditorPlugin );
bool _2d;
ShaderEditor *shader_editor;
EditorNode *editor;
public:
@ -152,7 +150,7 @@ public:
virtual void save_external_data();
virtual void apply_changes();
ShaderEditorPlugin(EditorNode *p_node);
ShaderEditorPlugin(EditorNode *p_node,bool p_2d);
~ShaderEditorPlugin();
};