|
|
@@ -35,6 +35,8 @@ OTHER DEALINGS IN THE SOFTWARE.
|
|
|
#include "Mesh.h"
|
|
|
#include "Sprite.h"
|
|
|
#include "Material.h"
|
|
|
+#include "Gui.h"
|
|
|
+#include "GuiResource.h"
|
|
|
|
|
|
namespace crown
|
|
|
{
|
|
|
@@ -75,7 +77,7 @@ static const char* default_fragment =
|
|
|
" gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);"
|
|
|
"}";
|
|
|
|
|
|
-static const char* texture_fragment =
|
|
|
+static const char* texture_fragment =
|
|
|
"in vec2 tex_coord0;"
|
|
|
"in vec4 color;"
|
|
|
|
|
|
@@ -91,6 +93,7 @@ RenderWorld::RenderWorld()
|
|
|
: m_mesh_pool(default_allocator(), MAX_MESHES, sizeof(Mesh), CE_ALIGNOF(Mesh))
|
|
|
, m_sprite_pool(default_allocator(), MAX_SPRITES, sizeof(Sprite), CE_ALIGNOF(Sprite))
|
|
|
, m_material_pool(default_allocator(), MAX_MATERIALS, sizeof(Material), CE_ALIGNOF(Material))
|
|
|
+ , m_gui_pool(default_allocator(), MAX_GUIS, sizeof(Gui), CE_ALIGNOF(Gui))
|
|
|
{
|
|
|
Renderer* r = device()->renderer();
|
|
|
|
|
|
@@ -187,6 +190,31 @@ Material* RenderWorld::lookup_material(MaterialId id)
|
|
|
return m_materials.lookup(id);
|
|
|
}
|
|
|
|
|
|
+//-----------------------------------------------------------------------------
|
|
|
+GuiId RenderWorld::create_gui(GuiResource* gr)
|
|
|
+{
|
|
|
+ Renderer* r = device()->renderer();
|
|
|
+ Gui* gui = CE_NEW(m_gui_pool, Gui)(*this, gr, *r);
|
|
|
+ return m_guis.create(gui);
|
|
|
+}
|
|
|
+
|
|
|
+//-----------------------------------------------------------------------------
|
|
|
+void RenderWorld::destroy_gui(GuiId id)
|
|
|
+{
|
|
|
+ CE_ASSERT(m_guis.has(id), "Gui does not exist");
|
|
|
+
|
|
|
+ CE_DELETE(m_gui_pool, m_guis.lookup(id));
|
|
|
+ m_guis.destroy(id);
|
|
|
+}
|
|
|
+
|
|
|
+//-----------------------------------------------------------------------------
|
|
|
+Gui* RenderWorld::lookup_gui(GuiId id)
|
|
|
+{
|
|
|
+ CE_ASSERT(m_guis.has(id), "Gui does not exist");
|
|
|
+
|
|
|
+ return m_guis.lookup(id);
|
|
|
+}
|
|
|
+
|
|
|
//-----------------------------------------------------------------------------
|
|
|
void RenderWorld::update(const Matrix4x4& view, const Matrix4x4& projection, uint16_t x, uint16_t y, uint16_t width, uint16_t height)
|
|
|
{
|
|
|
@@ -212,18 +240,25 @@ void RenderWorld::update(const Matrix4x4& view, const Matrix4x4& projection, uin
|
|
|
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_uniform(u_brightness, UNIFORM_FLOAT_1, &brightness, 1);*/
|
|
|
+ // 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->world_pose());
|
|
|
r->commit(0);
|
|
|
}
|
|
|
|
|
|
+ // Draw all sprites
|
|
|
for (uint32_t s = 0; s < m_sprite.size(); s++)
|
|
|
{
|
|
|
r->set_program(texture_program);
|
|
|
m_sprite[s]->render(*r, u_albedo_0);
|
|
|
}
|
|
|
+
|
|
|
+ // Draw all guis
|
|
|
+ for (uint32_t g = 0; g < m_guis.size(); g++)
|
|
|
+ {
|
|
|
+ m_guis[g]->render(*r, u_albedo_0);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
} // namespace crown
|