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

Use pos.z to control rendering depth of GUI objects

Daniele Bartolini 11 лет назад
Родитель
Сommit
aa86e55f64
2 измененных файлов с 14 добавлено и 21 удалено
  1. 3 16
      engine/renderers/Gui.cpp
  2. 11 5
      engine/renderers/Gui.h

+ 3 - 16
engine/renderers/Gui.cpp

@@ -106,7 +106,6 @@ Gui::Gui(RenderWorld& render_world, uint16_t width, uint16_t height)
 	, m_width(width)
 	, m_height(height)
 	, m_pose(matrix4x4::IDENTITY)
-	, m_visible(true)
 {
 	set_orthographic_rh(m_projection, 0, width, 0, height, -0.01f, 100.0f);
 }
@@ -142,18 +141,6 @@ Vector2 Gui::screen_to_gui(const Vector2& pos)
 	return Vector2(pos.x, m_height - pos.y);
 }
 
-//-----------------------------------------------------------------------------
-void Gui::show()
-{
-	m_visible = true;
-}
-
-//-----------------------------------------------------------------------------
-void Gui::hide()
-{
-	m_visible = false;
-}
-
 //-----------------------------------------------------------------------------
 void Gui::draw_rectangle(const Vector3& pos, const Vector2& size, const Color4& color)
 {
@@ -197,7 +184,7 @@ void Gui::draw_rectangle(const Vector3& pos, const Vector2& size, const Color4&
 	r->set_uniform(render_world_globals::default_color_uniform(), UniformType::FLOAT_4, color4::to_float_ptr(color), 1);
 	r->set_vertex_buffer(tvb);
 	r->set_index_buffer(tib);
-	r->commit(1);
+	r->commit(1, (int32_t) pos.z);
 }
 
 //-----------------------------------------------------------------------------
@@ -256,7 +243,7 @@ void Gui::draw_image(const char* material, const Vector3& pos, const Vector2& si
 	r->set_uniform(render_world_globals::default_color_uniform(), UniformType::FLOAT_4, color4::to_float_ptr(color), 1);
 	r->set_vertex_buffer(tvb);
 	r->set_index_buffer(tib);
-	r->commit(1);
+	r->commit(1, (int32_t) pos.z);
 }
 
 //-----------------------------------------------------------------------------
@@ -383,7 +370,7 @@ void Gui::draw_text(const char* str, const char* font, uint32_t font_size, const
 	r->set_uniform(render_world_globals::default_color_uniform(), UniformType::FLOAT_4, color4::to_float_ptr(color), 1);
 	r->set_vertex_buffer(vb);
 	r->set_index_buffer(ib);
-	r->commit(1);
+	r->commit(1, (int32_t) pos.z);
 }
 
 } // namespace crown

+ 11 - 5
engine/renderers/Gui.h

@@ -35,6 +35,9 @@ namespace crown
 
 class RenderWorld;
 
+/// Manages the rendering of GUI objects.
+///
+/// @ingroup Graphics
 struct Gui
 {
 	Gui(RenderWorld& render_world, uint16_t width, uint16_t height);
@@ -47,11 +50,16 @@ struct Gui
 
 	Vector2 screen_to_gui(const Vector2& pos);
 
-	void show();
-	void hide();
-
+	/// Draws a rectangle of size @a size at @a pos.
+	/// @note Higher values of pos.z make the object appear in front of other objects.
 	void draw_rectangle(const Vector3& pos, const Vector2& size, const Color4& color = Color4::WHITE);
+
+	/// Draws an image with the given @a material.
+	/// @note Higher values of pos.z make the object appear in front of other objects.
 	void draw_image(const char* material, const Vector3& pos, const Vector2& size, const Color4& color = Color4::WHITE);
+
+	/// Draws the text @a str with the given @a font and @a font_size.
+	/// @note Higher values of pos.z make the object appear in front of other objects.
 	void draw_text(const char* str, const char* font, uint32_t font_size, const Vector3& pos, const Color4& color = Color4::WHITE);
 
 public:
@@ -64,8 +72,6 @@ public:
 
 	Matrix4x4 m_projection;
 	Matrix4x4 m_pose;
-
-	bool m_visible;
 };
 
 } // namespace crown