|
|
@@ -30,6 +30,7 @@ OTHER DEALINGS IN THE SOFTWARE.
|
|
|
#include "Renderer.h"
|
|
|
#include "Allocator.h"
|
|
|
#include "Camera.h"
|
|
|
+#include "Resource.h"
|
|
|
|
|
|
namespace crown
|
|
|
{
|
|
|
@@ -87,6 +88,7 @@ static const char* texture_fragment =
|
|
|
//-----------------------------------------------------------------------------
|
|
|
RenderWorld::RenderWorld()
|
|
|
: m_mesh(default_allocator())
|
|
|
+ , m_sprite(default_allocator())
|
|
|
{
|
|
|
Renderer* r = device()->renderer();
|
|
|
|
|
|
@@ -165,12 +167,31 @@ void RenderWorld::update(Camera& camera, float /*dt*/)
|
|
|
r->set_vertex_buffer(mesh.m_vbuffer);
|
|
|
r->set_index_buffer(mesh.m_ibuffer);
|
|
|
r->set_program(default_program);
|
|
|
-/* r->set_texture(0, u_albedo_0, grass_texture, TEXTURE_FILTER_LINEAR | TEXTURE_WRAP_CLAMP_EDGE);
|
|
|
+ /*r->set_texture(0, u_albedo_0, grass_texture, TEXTURE_FILTER_LINEAR | TEXTURE_WRAP_CLAMP_EDGE);
|
|
|
r->set_uniform(u_brightness, UNIFORM_FLOAT_1, &brightness, 1);*/
|
|
|
|
|
|
r->set_pose(mesh.m_local_pose);
|
|
|
r->commit(0);
|
|
|
}
|
|
|
+
|
|
|
+ r->set_layer_view(0, camera_view);
|
|
|
+ r->set_layer_projection(0, camera.m_projection);
|
|
|
+ r->set_layer_viewport(0, 0, 0, 1000, 625);
|
|
|
+ r->set_layer_clear(0, CLEAR_COLOR | CLEAR_DEPTH, Color4::LIGHTBLUE, 1.0f);
|
|
|
+
|
|
|
+ for (uint32_t s = 0; s < m_sprite.size(); s++)
|
|
|
+ {
|
|
|
+ const Sprite& sprite = m_sprite[s];
|
|
|
+
|
|
|
+ r->set_state(STATE_DEPTH_WRITE | STATE_COLOR_WRITE | STATE_ALPHA_WRITE | STATE_CULL_CW);
|
|
|
+ r->set_vertex_buffer(sprite.m_vb);
|
|
|
+ r->set_index_buffer(sprite.m_ib);
|
|
|
+ r->set_program(sprite.m_prog);
|
|
|
+ r->set_texture(0, sprite.m_albedo, sprite.m_texture, TEXTURE_FILTER_LINEAR | TEXTURE_WRAP_CLAMP_EDGE);
|
|
|
+
|
|
|
+ r->set_pose(sprite.m_local_pose);
|
|
|
+ r->commit(0);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
@@ -192,4 +213,46 @@ void RenderWorld::deallocate_mesh(MeshId /*id*/)
|
|
|
{
|
|
|
}
|
|
|
|
|
|
+//-----------------------------------------------------------------------------
|
|
|
+SpriteId RenderWorld::create_sprite(const char* name, int32_t node, const Vector3& pos, const Quaternion& rot)
|
|
|
+{
|
|
|
+ TextureResource* tr = (TextureResource*) device()->resource_manager()->lookup(TEXTURE_EXTENSION, name);
|
|
|
+
|
|
|
+ SpriteId sprite = allocate_sprite(tr, node, pos, rot);
|
|
|
+
|
|
|
+ return sprite;
|
|
|
+}
|
|
|
+
|
|
|
+//-----------------------------------------------------------------------------
|
|
|
+void RenderWorld::destroy_sprite(SpriteId /*id*/)
|
|
|
+{
|
|
|
+ // Stub
|
|
|
+}
|
|
|
+
|
|
|
+//-----------------------------------------------------------------------------
|
|
|
+Sprite* RenderWorld::lookup_sprite(SpriteId id)
|
|
|
+{
|
|
|
+ return &m_sprite[m_sprite_sparse_to_packed[id.index]];
|
|
|
+}
|
|
|
+
|
|
|
+//-----------------------------------------------------------------------------
|
|
|
+SpriteId RenderWorld::allocate_sprite(TextureResource* tr, int32_t node, const Vector3& pos, const Quaternion& rot)
|
|
|
+{
|
|
|
+ SpriteId id = m_sprite_table.create();
|
|
|
+
|
|
|
+ Sprite sprite;
|
|
|
+ sprite.create(tr, node, pos, rot);
|
|
|
+
|
|
|
+ uint32_t index = m_sprite.push_back(sprite);
|
|
|
+ m_sprite_sparse_to_packed[id.index] = index;
|
|
|
+
|
|
|
+ return id;
|
|
|
+}
|
|
|
+
|
|
|
+//-----------------------------------------------------------------------------
|
|
|
+void RenderWorld::deallocate_sprite(SpriteId /*id*/)
|
|
|
+{
|
|
|
+ // Stub
|
|
|
+}
|
|
|
+
|
|
|
} // namespace crown
|