Ver Fonte

Tiler additions & designing UI

Panagiotis Christopoulos Charitos há 13 anos atrás
pai
commit
07e48bda22

+ 5 - 0
include/anki/renderer/Tiler.h

@@ -38,6 +38,11 @@ public:
 	/// Test against all tiles
 	Bool testAll(const CollisionShape& cs,
  		const Bool skipNearPlaneCheck = false) const;
+
+	/// Test against all tiles and return affected tiles
+	Bool testAll(const CollisionShape& cs,
+ 		U32* tileIds, U32& tilesCount, 
+		const Bool skipNearPlaneCheck = false) const;
  
 	/// Test on a specific tile
 	Bool test(const CollisionShape& cs, 

+ 38 - 0
include/anki/ui/UiCommon.h

@@ -0,0 +1,38 @@
+#ifndef ANKI_UI_UI_COMMON_H
+#define ANKI_UI_UI_COMMON_H
+
+#include "anki/math/Math.h"
+#include "anki/util/Allocator.h"
+
+namespace anki {
+
+/// @addtogroup ui
+/// @{
+
+/// Color
+typedef Vec4 UiColor;
+
+/// 2D point
+typedef Vec2 UiPoint;
+
+/// 2D position
+typedef Vec2 UiPosition;
+
+/// Rectangle
+struct UiRect
+{
+	UiPosition min;
+	UiPosition max;
+
+	UiRect(UiPosition min_, UiPosition max_)
+		: min(min_), max(max_)
+	{
+		ANKI_ASSERT(min < max);
+	}
+};
+
+/// @}
+
+} // end namespace anki
+
+#endif

+ 16 - 0
include/anki/ui/UiFactory.h

@@ -0,0 +1,16 @@
+#ifndef ANKI_UI_UI_FACTORY_H
+#define ANKI_UI_UI_FACTORY_H
+
+#include "anki/ui/UiCommon.h"
+
+namespace anki {
+
+class UiFactory
+{
+private:
+
+};
+
+} // end namespace anki
+
+#endif

+ 69 - 29
include/anki/ui/UiPainter.h

@@ -1,69 +1,96 @@
 #ifndef ANKI_UI_UI_PAINTER_H
 #define ANKI_UI_UI_PAINTER_H
 
-#include "anki/resource/Resource.h"
-#include "anki/math/Math.h"
-#include "anki/gl/Vbo.h"
-#include "anki/gl/Vao.h"
-#include "anki/resource/ShaderProgramResource.h"
+#include "anki/ui/UiCommon.h"
+#include "anki/gl/Gl.h"
 
 namespace anki {
 
+// Forward
 class UiFont;
 
-/// XXX
+/// Gradient type
+struct UiGrandient
+{
+	enum GradientType
+	{
+		GT_ANGULAR,
+		GT_RADIAL
+	};
+
+	GradientType type = GT_ANGULAR;
+	Array<UiColor, 3> colors = {{UiColor(1.0), UiColor(0.5), UiColor(0.0)}};
+	U8 colorsCount = 2;
+	F32 angle = 0.0; ///< In rad. Default is horizontal
+};
+
+/// UI painer
 class UiPainter
 {
 public:
+	/// Method for coloring
+	enum ColoringMethod
+	{
+		CM_CONSTANT_COLOR,
+		CM_GRADIENT
+	};
+
 	UiPainter(const Vec2& deviceSize);
 
 	/// @name Accessors
 	/// @{
-	const Vec2& getPosition() const
+	const UiPosition& getPosition() const
 	{
 		return pos;
 	}
-	void setPosition(const Vec2& x)
+	void setPosition(const UiPosition& x)
 	{
 		pos = x;
 	}
 
-	const Vec4& getColor() const
+	const UiColor& getColor() const
 	{
 		return col;
 	}
-	void setColor(const Vec4& x)
+	void setColor(const UiColor& x)
 	{
 		col = x;
-		sProg->bind();
-		sProg->findUniformVariable("color").set(col);
 	}
+	/// @}
 
-	void setFont(const char* fontFilename, uint nominalWidth,
-		uint nominalHeight);
-
-	const UiFont& getFont() const
-	{
-		return *font;
-	}
+	/// @name Fill methods
+	/// @{
+	void fillRect(const UiRect& rect);
+	void fillEllipse(const UiRect& rect);
+	void fillRoundedRect(const UiRect& rect, F32 xRadius, F32 yRadius);
 	/// @}
 
+	/// @name Draw methods
+	/// @{
 	void drawText(const char* text);
-	void drawText(const std::string& str)
-	{
-		drawText(str.c_str());
-	}
 	void drawFormatedText(const char* format, ...);
 
+	void drawLines(const UiPosition* positions, U32 positionsCount);
+	void drawRect(const UiRect& rect);
+	void drawEllipse(const UiRect& rect);
+	void drawRoundedRect(const UiRect& rect, F32 xRadius, F32 yRadius);
+	/// @}
+
 private:
+	enum Shader
+	{
+		S_FILL,
+		S_GRADIENT_ANGULAR_COLORS_2,
+		S_GRADIENT_ANGULAR_COLORS_3,
+		S_GRADIENT_RADIAL_COLORS_2,
+		S_GRADIENT_RADIAL_COLORS_3,
+		S_COUNT
+	};
+
 	/// @name Data
 	/// @{
-	std::unique_ptr<UiFont> font;
-	ShaderProgramResourcePointer sProg;
-
-	Vec2 pos;
-	Vec4 col;
-	uint tabSize;
+	UiFont* font = nullptr;
+	Array<ShaderProgram, S_COUNT> progs;
 
 	Vbo qPositionsVbo;
 	Vbo qIndecesVbo;
@@ -72,6 +99,19 @@ private:
 	Vec2 deviceSize; ///< The size of the device in pixels
 	/// @}
 
+	/// @name State machine data
+	/// @{
+	UiPosition pos;
+	UiColor col;
+	Gradient grad;
+	ColoringMethod fillMethod;
+	ColoringMethod linesMethod;
+	/// @}
+
+	/// @name Oprtimizations
+	/// @{
+	/// @}
+
 	void init();
 };
 

+ 3 - 4
shaders/SimpleVert.glsl

@@ -4,14 +4,13 @@
 /// looking in the vertex position. The vertex positions of the quad are from 
 /// 0.0 to 1.0 for both axis.
 
-/// the vert coords are {1.0,1.0}, {0.0,1.0}, {0.0,0.0}, {1.0,0.0}
+/// the vert coords are {{1.0, 1.0}, {-1.0, 1.0}, {-1.0, -1.0}, {1.0, -1.0}}
 layout(location = 0) in vec2 position;
 
 out vec2 vTexCoords;
 
 void main()
 {
-	vTexCoords = position;
-	vec2 vertPosNdc = position * 2.0 - 1.0;
-	gl_Position = vec4(vertPosNdc, 0.0, 1.0);
+	vTexCoords = position * 0.5 + 0.5;
+	gl_Position = vec4(position, 0.0, 1.0);
 }

+ 4 - 3
src/renderer/Renderer.cpp

@@ -39,12 +39,13 @@ void Renderer::init(const RendererInitializer& initializer)
 	bs.init(initializer);
 
 	// quad VBOs and VAO
-	F32 quadVertCoords[][2] = {{1.0, 1.0}, {0.0, 1.0}, {0.0, 0.0},
-		{1.0, 0.0}}; /// XXX change them to NDC
+	static const F32 quadVertCoords[][2] = {{1.0, 1.0}, {-1.0, 1.0}, 
+		{-1.0, -1.0}, {1.0, -1.0}};
 	quadPositionsVbo.create(GL_ARRAY_BUFFER, sizeof(quadVertCoords),
 		quadVertCoords, GL_STATIC_DRAW);
 
-	U16 quadVertIndeces[2][3] = {{0, 1, 3}, {1, 2, 3}}; // 2 triangles
+	static const U16 quadVertIndeces[2][3] = 
+		{{0, 1, 3}, {1, 2, 3}}; // 2 triangles
 	quadVertIndecesVbo.create(GL_ELEMENT_ARRAY_BUFFER, sizeof(quadVertIndeces),
 		quadVertIndeces, GL_STATIC_DRAW);
 

+ 20 - 0
src/renderer/Tiler.cpp

@@ -291,4 +291,24 @@ Bool Tiler::testAll(const CollisionShape& cs,
 	return false;
 }
 
+//==============================================================================
+Bool Tiler::testAll(const CollisionShape& cs,
+ 	U32* tileIds, U32& tilesCount, const Bool skipNearPlaneCheck) const
+{
+	U startPlane = (skipNearPlaneCheck) ? 1 : 0;
+	tilesCount = 0;
+
+	for(U i = 0; i < tiles1d.getSize(); i++)
+	{
+		const Tile& tile = tiles1d[i];
+
+		if(testInternal(cs, tile, startPlane))
+		{
+			tileIds[tilesCount++] = i;
+		}
+	}
+
+	return tilesCount > 0;
+}
+
 } // end namespace anki