1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-10 13:00:37 +00:00

2D Rewrite Step [1]

-=-=-=-=-=-=-=-=-=-

-Moved drawing code to a single function that takes linked list (should make it easier to optimize in the future).
-Implemented Z ordering of 2D nodes. Node2D and those that inherit have a visibility/Z property that affects drawing order (besides the tree order)
-Removed OpenGL ES 1.x support. Good riddance!
This commit is contained in:
Juan Linietsky
2015-01-10 17:35:26 -03:00
parent 78f4b93703
commit 8997084831
35 changed files with 653 additions and 7694 deletions

View File

@@ -372,139 +372,28 @@ 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 sort_y;
float opacity;
float self_opacity;
MaterialBlendMode blend_mode;
RID viewport;
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=CANVAS_ITEM_Z_MAX/2;
opacity=1;
self_opacity=1;
sort_y=false;
}
};
@@ -706,7 +595,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,Rasterizer::CanvasItem **z_list,Rasterizer::CanvasItem **z_last_list,CanvasItem *p_canvas_clip);
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 +1108,8 @@ 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_clear(RID p_item);
virtual void canvas_item_raise(RID p_item);