소스 검색

- Grouping globals
- UI

Panagiotis Christopoulos Charitos 14 년 전
부모
커밋
f55580f25f

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 1 - 2
build/debug/Makefile


+ 3 - 4
shaders/Ui.glsl

@@ -1,6 +1,6 @@
 #pragma anki vertShaderBegins
 
-in vec2 position;
+layout(location = 0) in vec2 position;
 
 uniform mat3 tranformation; ///< Position transformation
 uniform mat3 textureTranformation; ///< Texture transformation
@@ -10,9 +10,8 @@ out vec2 vTexCoords;
 
 void main(void)
 {
-	vec3 pos3d = vec3(position, 0.0);
-	vTexCoords = (textureTranformation * pos3d).xy;
-	gl_Position = vec4(tranformation * pos3d, 1.0);
+	vTexCoords = (textureTranformation * vec3(position, 1.0)).xy;
+	gl_Position = vec4(tranformation * position, 1.0);
 }
 
 #pragma anki fragShaderBegins

+ 2 - 0
src/Core/App.cpp

@@ -12,6 +12,7 @@
 #include "StdinListener.h"
 #include "Input.h"
 #include "Logger.h"
+#include "Globals.h"
 
 
 //======================================================================================================================
@@ -219,6 +220,7 @@ void App::initRenderer()
 	initializer.pps.blurringEnabled = true;
 	initializer.pps.blurringIterationsNum = 2;
 	initializer.mainRendererQuality = 1.0;
+
 	MainRendererSingleton::getInstance().init(initializer);
 }
 

+ 0 - 3
src/Core/App.h

@@ -92,7 +92,4 @@ class App
 };
 
 
-typedef Singleton<App> AppSingleton;
-
-
 #endif

+ 1 - 0
src/Core/AsyncLoader.cpp

@@ -1,6 +1,7 @@
 #include "AsyncLoader.h"
 #include "Logger.h"
 #include "App.h"
+#include "Globals.h"
 
 
 //======================================================================================================================

+ 0 - 3
src/Core/Globals.cpp

@@ -1,3 +0,0 @@
-#include "Globals.h"
-
-Ui* gUi;

+ 13 - 1
src/Core/Globals.h

@@ -1,6 +1,18 @@
 #ifndef GLOBALS_H
 #define GLOBALS_H
 
-extern class Ui* gUi;
+#include "Singleton.h"
+
+
+typedef Singleton<class Logger> LoggerSingleton;
+typedef Singleton<class MainRenderer> MainRendererSingleton;
+typedef Singleton<class Input> InputSingleton;
+typedef Singleton<class ResourceManager> ResourceManagerSingleton;
+typedef Singleton<class Scene> SceneSingleton;
+typedef Singleton<class App> AppSingleton;
+typedef Singleton<class StdinListener> StdinListenerSingleton;
+typedef Singleton<class GlStateMachine> GlStateMachineSingleton;
+typedef Singleton<class ScriptingEngine> ScriptingEngineSingleton;
+
 
 #endif

+ 0 - 7
src/Core/Logger.h

@@ -147,11 +147,4 @@ Logger& Logger::appendUsingLexicalCast(const Type& val)
 #define ERROR(x) LOGGER_MESSAGE("Error: " << x)
 
 
-//======================================================================================================================
-// Singleton                                                                                                           =
-//======================================================================================================================
-
-typedef Singleton<Logger> LoggerSingleton;
-
-
 #endif

+ 0 - 3
src/Core/StdinListener.h

@@ -28,7 +28,4 @@ class StdinListener
 };
 
 
-typedef Singleton<StdinListener> StdinListenerSingleton;
-
-
 #endif

+ 1 - 0
src/Input/Input.cpp

@@ -2,6 +2,7 @@
 #include <SDL/SDL.h>
 #include "App.h"
 #include "Logger.h"
+#include "Globals.h"
 
 
 //======================================================================================================================

+ 0 - 3
src/Input/Input.h

@@ -49,7 +49,4 @@ class Input
 };
 
 
-typedef Singleton<Input> InputSingleton;
-
-
 #endif

+ 1 - 4
src/Main.cpp

@@ -7,7 +7,7 @@
 #include "OrthographicCamera.h"
 #include "Math.h"
 #include "Renderer.h"
-#include "Ui.h"
+#include "UiPainter.h"
 #include "App.h"
 #include "Mesh.h"
 #include "Light.h"
@@ -39,7 +39,6 @@
 #include "SkinNode.h"
 #include "Skin.h"
 #include "MaterialRuntime.h"
-#include "Ui.h"
 #include "Globals.h"
 
 
@@ -121,8 +120,6 @@ void init()
 
 	srand(unsigned(time(NULL)));
 
-	gUi = new Ui;
-
 	//Ui::init();
 
 	// camera

+ 1 - 0
src/Renderer/Drawers/PhyDbgDrawer.cpp

@@ -2,6 +2,7 @@
 #include "MainRenderer.h"
 #include "BtAndAnkiConvertors.h"
 #include "Logger.h"
+#include "Globals.h"
 
 
 //======================================================================================================================

+ 2 - 8
src/Renderer/GlStateMachine.h

@@ -19,7 +19,8 @@ class GlStateMachine
 
 		/// @name Set the Fixed Function Pipeline, Call the OpenGL functions only when needed
 		/// @{
-		void enable(GLenum flag, bool enable);
+		void enable(GLenum flag, bool enable = true);
+		void disable(GLenum flag) {enable(flag, false);}
 		bool isEnabled(GLenum flag);
 
 		void useShaderProg(GLuint id);
@@ -62,11 +63,4 @@ inline GLuint GlStateMachine::getCurrentProgramGlId()
 }
 
 
-//======================================================================================================================
-// Other                                                                                                               =
-//======================================================================================================================
-
-typedef Singleton<GlStateMachine> GlStateMachineSingleton; ///< Make the GlStateMachine singleton class
-
-
 #endif

+ 0 - 3
src/Renderer/MainRenderer.h

@@ -56,7 +56,4 @@ inline MainRenderer::MainRenderer():
 {}
 
 
-typedef Singleton<MainRenderer> MainRendererSingleton; ///< Make the MainRenderer singleton class
-
-
 #endif

+ 0 - 3
src/Resources/Core/ResourceManager.h

@@ -116,7 +116,4 @@ inline void ResourceManager::postProcessFinishedLoadingRequests(uint maxTime)
 #include "ResourceManager.inl.h"
 
 
-typedef Singleton<ResourceManager> ResourceManagerSingleton;
-
-
 #endif

+ 1 - 0
src/Resources/Core/ResourceManager.inl.h

@@ -1,4 +1,5 @@
 #include "Exception.h"
+#include "Globals.h"
 #include "Logger.h"
 #include "Assert.h"
 

+ 1 - 0
src/Resources/Core/RsrcAsyncLoadingReqsHandler.cpp

@@ -3,6 +3,7 @@
 #include "Logger.h"
 #include "HighRezTimer.h"
 #include "Assert.h"
+#include "Globals.h"
 
 
 //======================================================================================================================

+ 1 - 0
src/Resources/ShaderProg/ShaderProg.cpp

@@ -9,6 +9,7 @@
 #include "GlException.h"
 #include "Logger.h"
 #include "Util.h"
+#include "Globals.h"
 
 
 #define SPROG_EXCEPTION(x) EXCEPTION("Shader prog \"" + rsrcFilename + "\": " + x)

+ 1 - 0
src/Resources/ShaderProg/ShaderProg.h

@@ -10,6 +10,7 @@
 #include "SProgAttribVar.h"
 #include "Vec.h"
 #include "GlStateMachine.h"
+#include "Globals.h"
 
 
 /// Shader program @ref Resource

+ 1 - 0
src/Scene/Controllers/Controller.cpp

@@ -1,6 +1,7 @@
 #include "Controller.h"
 #include "Scene.h"
 #include "App.h"
+#include "Globals.h"
 
 
 //======================================================================================================================

+ 1 - 0
src/Scene/Controllers/SkelAnimModelNodeCtrl.cpp

@@ -6,6 +6,7 @@
 #include "Model.h"
 #include "MainRenderer.h"
 #include "Skin.h"
+#include "Globals.h"
 
 
 //======================================================================================================================

+ 0 - 6
src/Scene/Scene.h

@@ -103,10 +103,4 @@ inline void Scene::eraseNode(ContainerType& container, Type* x)
 }
 
 
-//======================================================================================================================
-// Singleton                                                                                                           =
-//======================================================================================================================
-typedef Singleton<Scene> SceneSingleton;
-
-
 #endif

+ 1 - 0
src/Scene/SceneNode.cpp

@@ -2,6 +2,7 @@
 #include <boost/lexical_cast.hpp>
 #include "SceneNode.h"
 #include "Scene.h"
+#include "Globals.h"
 
 
 //======================================================================================================================

+ 4 - 8
src/Scripting/BoostPythonInterfaces.cpp

@@ -1,10 +1,8 @@
 #include <boost/python.hpp>
+#include "ScriptingCommon.h"
 #include "App.h"
 
 
-#define CALL_WRAP(x) extern void boostPythonWrap##x(); boostPythonWrap##x()
-
-
 BOOST_PYTHON_MODULE(Anki)
 {
 	CALL_WRAP(Vec2);
@@ -12,7 +10,6 @@ BOOST_PYTHON_MODULE(Anki)
 	CALL_WRAP(Vec4);
 
 	CALL_WRAP(Logger);
-	CALL_WRAP(LoggerSingleton);
 
 	CALL_WRAP(SceneNode);
 	CALL_WRAP(Camera);
@@ -21,18 +18,17 @@ BOOST_PYTHON_MODULE(Anki)
 	CALL_WRAP(ModelPatchNode);
 	CALL_WRAP(ModelNode);
 	CALL_WRAP(Scene);
-	CALL_WRAP(SceneSingleton);
 
 	CALL_WRAP(Hdr);
 	CALL_WRAP(Pps);
 	CALL_WRAP(Renderer);
 	CALL_WRAP(Dbg);
 	CALL_WRAP(MainRenderer);
-	CALL_WRAP(MainRendererSingleton);
 
 	CALL_WRAP(App);
-	CALL_WRAP(AppSingleton);
 
 	CALL_WRAP(Input);
-	CALL_WRAP(InputSingleton);
+
+	extern void wrapAllGlobals();
+	wrapAllGlobals();
 }

+ 0 - 3
src/Scripting/Core/App.bpi.cpp

@@ -8,6 +8,3 @@ WRAP(App)
 		.def("quit", &App::quit)
 	;
 }
-
-
-WRAP_SINGLETON(AppSingleton)

+ 24 - 0
src/Scripting/Core/Globals.bpi.cpp

@@ -0,0 +1,24 @@
+#include "ScriptingCommon.h"
+#include "Globals.h"
+#include "Logger.h"
+#include "MainRenderer.h"
+#include "Input.h"
+#include "Scene.h"
+#include "App.h"
+
+
+WRAP_SINGLETON(LoggerSingleton)
+WRAP_SINGLETON(MainRendererSingleton)
+WRAP_SINGLETON(InputSingleton)
+WRAP_SINGLETON(SceneSingleton)
+WRAP_SINGLETON(AppSingleton)
+
+
+void wrapAllGlobals()
+{
+	CALL_WRAP(LoggerSingleton);
+	CALL_WRAP(MainRendererSingleton);
+	CALL_WRAP(InputSingleton);
+	CALL_WRAP(SceneSingleton);
+	CALL_WRAP(AppSingleton);
+}

+ 0 - 3
src/Scripting/Core/Logger.bpi.cpp

@@ -8,6 +8,3 @@ WRAP(Logger)
 		.def("write", &Logger::write)
 	;
 }
-
-
-WRAP_SINGLETON(LoggerSingleton)

+ 0 - 3
src/Scripting/Input/Input.bpi.cpp

@@ -9,6 +9,3 @@ WRAP(Input)
 		.def("setWarpMouse", &Input::setWarpMouse)
 	;
 }
-
-
-WRAP_SINGLETON(InputSingleton)

+ 0 - 3
src/Scripting/Renderer/MainRenderer.bpi.cpp

@@ -10,6 +10,3 @@ WRAP(MainRenderer)
 		     return_value_policy<reference_existing_object>())
 	;
 }
-
-
-WRAP_SINGLETON(MainRendererSingleton)

+ 0 - 3
src/Scripting/Scene/Scene.bpi.cpp

@@ -20,6 +20,3 @@ WRAP(Scene)
 		     return_value_policy<reference_existing_object>())
 	;
 }
-
-
-WRAP_SINGLETON(SceneSingleton)

+ 3 - 0
src/Scripting/ScriptingCommon.h

@@ -29,6 +29,9 @@ using namespace boost::python;
 	;
 
 
+#define CALL_WRAP(x) extern void boostPythonWrap##x(); boostPythonWrap##x()
+
+
 //======================================================================================================================
 // Property for simple types                                                                                           =
 //======================================================================================================================

+ 1 - 0
src/Scripting/ScriptingEngine.cpp

@@ -2,6 +2,7 @@
 #include "ScriptingEngine.h"
 #include "Exception.h"
 #include "Logger.h"
+#include "Globals.h"
 
 
 extern "C" void initAnki(); /// Defined in BoostPythonInterfaces.cpp by boost::python

+ 0 - 3
src/Scripting/ScriptingEngine.h

@@ -38,7 +38,4 @@ inline void ScriptingEngine::exposeVar(const char* varName, Type* var)
 }
 
 
-typedef Singleton<ScriptingEngine> ScriptingEngineSingleton;
-
-
 #endif

+ 0 - 27
src/Ui/Ui.cpp

@@ -1,27 +0,0 @@
-#include <cstdarg>
-#include "Ui.h"
-#include "GlStateMachine.h"
-#include "Texture.h"
-#include "Logger.h"
-
-
-//======================================================================================================================
-// Constructor                                                                                                         =
-//======================================================================================================================
-Ui::Ui()
-{
-	fontMap.loadRsrc("engine-rsrc/fontmap.png");
-	columns = 16;
-	rows = 8;
-
-	sProg.loadRsrc("shaders/Ui.glsl");
-}
-
-
-//======================================================================================================================
-// Destructor                                                                                                          =
-//======================================================================================================================
-Ui::~Ui()
-{
-	INFO("Deleting Ui");
-}

+ 92 - 0
src/Ui/UiPainter.cpp

@@ -0,0 +1,92 @@
+#include <cstdarg>
+#include "UiPainter.h"
+#include "GlStateMachine.h"
+#include "Texture.h"
+#include "Logger.h"
+
+
+namespace Ui {
+
+
+//======================================================================================================================
+// Constructor                                                                                                         =
+//======================================================================================================================
+Painter::Painter()
+{
+	init();
+}
+
+
+//======================================================================================================================
+// init                                                                                                                =
+//======================================================================================================================
+void Painter::init()
+{
+	// Map
+	fontMap.loadRsrc("engine-rsrc/fontmap.png");
+	columns = 16;
+	rows = 8;
+
+	// SProg
+	sProg.loadRsrc("shaders/Ui.glsl");
+
+	// Geom
+	float quadVertCoords[][2] = {{1.0, 0.0}, {0.0, 0.0}, {0.0, 1.0}, {1.0, 1.0}};
+	qPositionsVbo.create(GL_ARRAY_BUFFER, sizeof(quadVertCoords), quadVertCoords, GL_STATIC_DRAW);
+
+	ushort quadVertIndeces[2][3] = {{0, 1, 3}, {1, 2, 3}}; // 2 triangles
+	qIndecesVbo.create(GL_ELEMENT_ARRAY_BUFFER, sizeof(quadVertIndeces), quadVertIndeces, GL_STATIC_DRAW);
+
+	qVao.create();
+	qVao.attachArrayBufferVbo(qPositionsVbo, 0, 2, GL_FLOAT, false, 0, NULL);
+	qVao.attachElementArrayBufferVbo(qIndecesVbo);
+}
+
+
+//======================================================================================================================
+// drawText                                                                                                            =
+//======================================================================================================================
+void Painter::drawText(const char* text)
+{
+	// Set GL
+	GlStateMachineSingleton::getInstance().enable(GL_BLEND);
+	GlStateMachineSingleton::getInstance().disable(GL_DEPTH);
+
+	// SProg (some)
+	sProg->bind();
+
+	sProg->findUniVar("texture")->set(*fontMap, 0);
+	sProg->findUniVar("color")->set(&col);
+
+	// Vao
+	qVao.bind();
+
+	// Iterate
+	Vec2 p = pos;
+	const char* c = text;
+	while(*c != '\0')
+	{
+		// Pos trf
+		Mat3 trf = Mat3::getIdentity();
+		trf(0, 0) = fontSize.x() * 2.0;
+		trf(1, 1) = fontSize.y() * 2.0;
+		trf(0, 2) = p.x() * 2.0 - 1.0;
+		trf(1, 2) = p.y() * 2.0 - 1.0;
+
+		sProg->findUniVar("transformation")->set(&trf);
+
+		// Tex trf
+		Mat3 texTrf = Mat3::getIdentity();
+		sProg->findUniVar("textureTranformation")->set(&trf);
+
+		// Render
+		glDrawElements(GL_TRIANGLES, 2 * 3, GL_UNSIGNED_SHORT, 0);
+
+		// Inc
+		++c;
+		p.x() += fontSize.x();
+	}
+}
+
+
+} // end namespace

+ 21 - 12
src/Ui/Ui.h → src/Ui/UiPainter.h

@@ -1,5 +1,5 @@
-#ifndef UI_H
-#define UI_H
+#ifndef UI_PAINTER_H
+#define UI_PAINTER_H
 
 #include "RsrcPtr.h"
 #include "Math.h"
@@ -8,37 +8,46 @@
 #include "Vao.h"
 
 
-class Ui
+namespace Ui {
+
+
+class Painter
 {
 	public:
-		Ui();
-		~Ui();
+		Painter();
 
 		/// @name Accessors
 		/// @{
 		GETTER_SETTER(Vec2, pos, getPosition, setPosition)
-		GETTER_SETTER(Vec2, size, getSize, setSize)
+		GETTER_SETTER(Vec2, fontSize, getFontSize, setFontSize)
 		GETTER_SETTER(Vec4, col, getColor, setColor)
 		/// @}
 
-		void print(const char* text);
-
-		void printf(const char* format, ...);
+		void drawText(const char* text);
+		void drawFormatedText(const char* format, ...);
 
 	private:
+		/// @name Data
+		/// @{
 		RsrcPtr<Texture> fontMap;
 		uint columns;
 		uint rows;
 		RsrcPtr<ShaderProg> sProg;
 
 		Vec2 pos;
-		Vec2 size;
+		Vec2 fontSize;
 		Vec4 col;
 
-		Vbo qPositions;
-		Vbo qIndeces;
+		Vbo qPositionsVbo;
+		Vbo qIndecesVbo;
 		Vao qVao;
+		/// @}
+
+		void init();
 };
 
 
+}
+
+
 #endif

+ 4 - 0
src/Util/Singleton.h

@@ -1,6 +1,10 @@
 #ifndef SINGLETON_H
 #define SINGLETON_H
 
+#ifndef NULL
+	#define NULL 0
+#endif
+
 
 /// This template makes a class singleton
 template<typename Type>

이 변경점에서 너무 많은 파일들이 변경되어 몇몇 파일들은 표시되지 않았습니다.