Просмотр исходного кода

Change algorithm to compute sprite's vertex positions

Daniele Bartolini 12 лет назад
Родитель
Сommit
a7dc47902f
2 измененных файлов с 30 добавлено и 6 удалено
  1. 19 3
      engine/Sprite.cpp
  2. 11 3
      engine/Sprite.h

+ 19 - 3
engine/Sprite.cpp

@@ -31,19 +31,22 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "Allocator.h"
 #include "SceneGraph.h"
 #include "Unit.h"
+#include "Renderer.h"
+#include "Material.h"
+#include "RenderWorld.h"
 
 namespace crown
 {
 
 //-----------------------------------------------------------------------------
-Sprite::Sprite(SceneGraph& sg, int32_t node, const SpriteResource* sr)
-	: m_scene_graph(sg)
+Sprite::Sprite(RenderWorld& render_world, SceneGraph& sg, int32_t node, const SpriteResource* sr)
+	: m_render_world(render_world)
+	, m_scene_graph(sg)
 	, m_node(node)
 	, m_resource(sr)
 {
 	m_vb = sr->vertex_buffer();
 	m_ib = sr->index_buffer();
-	m_texture = ((TextureResource*)device()->resource_manager()->data(sr->texture()))->texture();
 }
 
 //-----------------------------------------------------------------------------
@@ -105,4 +108,17 @@ void Sprite::set_local_pose(Unit* unit, const Matrix4x4& pose)
 	unit->set_local_pose(m_node, pose);
 }
 
+//-----------------------------------------------------------------------------
+void Sprite::set_material(MaterialId mat)
+{
+	m_material = mat;
+}
+
+//-----------------------------------------------------------------------------
+void Sprite::render(Renderer& r, UniformId uniform)
+{
+	Material* material = m_render_world.lookup_material(m_material);
+	material->bind(r, uniform);
+}
+
 } // namespace crown

+ 11 - 3
engine/Sprite.h

@@ -37,12 +37,17 @@ namespace crown
 class SpriteResource;
 class SpriteAnimator;
 class SceneGraph;
+class Renderer;
+class RenderWorld;
 struct Unit;
 
+typedef Id MaterialId;
+typedef Id UniformId;
+
 //-----------------------------------------------------------------------------
 struct Sprite
 {
-							Sprite(SceneGraph& sg, int32_t node, const SpriteResource* sr);
+							Sprite(RenderWorld& render_world, SceneGraph& sg, int32_t node, const SpriteResource* sr);
 							~Sprite();
 
 	Vector3					local_position() const;
@@ -57,16 +62,19 @@ struct Sprite
 	void					set_local_rotation(Unit* unit, const Quaternion& rot);
 	void					set_local_pose(Unit* unit, const Matrix4x4& pose);
 
+	void					set_material(MaterialId mat);
+	void					render(Renderer& r, UniformId uniform);
+
 public:
 
+	RenderWorld&			m_render_world;
 	SceneGraph&				m_scene_graph;	
 	int32_t					m_node;
 	const SpriteResource*	m_resource;
 
+	MaterialId				m_material;
 	VertexBufferId			m_vb;
 	IndexBufferId			m_ib;
-	TextureId				m_texture;
-
 	SpriteAnimator*			m_animator;
 };