Browse Source

Added some skeletons for UI

Panagiotis Christopoulos Charitos 8 years ago
parent
commit
e8dc4a11f2

+ 6 - 0
CMakeLists.txt

@@ -314,6 +314,12 @@ else()
 	message(FATAL_ERROR "Wrong CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
 	message(FATAL_ERROR "Wrong CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
 endif()
 endif()
 
 
+if(ANKI_BUILD_TESTS)
+	set(ANKI_TESTS 1)
+else()
+	set(ANKI_TESTS 0)
+endif()
+
 configure_file("src/anki/Config.h.cmake" "${CMAKE_CURRENT_BINARY_DIR}/anki/Config.h")
 configure_file("src/anki/Config.h.cmake" "${CMAKE_CURRENT_BINARY_DIR}/anki/Config.h")
 install(FILES "${CMAKE_CURRENT_BINARY_DIR}/anki/Config.h" DESTINATION "${INCLUDE_INSTALL_DIR}/anki")
 install(FILES "${CMAKE_CURRENT_BINARY_DIR}/anki/Config.h" DESTINATION "${INCLUDE_INSTALL_DIR}/anki")
 
 

+ 1 - 0
src/anki/Config.h.cmake

@@ -15,6 +15,7 @@
 #define ANKI_EXTRA_CHECKS ${_ANKI_EXTRA_CHECKS}
 #define ANKI_EXTRA_CHECKS ${_ANKI_EXTRA_CHECKS}
 #define ANKI_DEBUG_SYMBOLS ${ANKI_DEBUG_SYMBOLS}
 #define ANKI_DEBUG_SYMBOLS ${ANKI_DEBUG_SYMBOLS}
 #define ANKI_OPTIMIZE ${ANKI_OPTIMIZE}
 #define ANKI_OPTIMIZE ${ANKI_OPTIMIZE}
+#define ANKI_TESTS ${ANKI_TESTS}
 
 
 // Operating system
 // Operating system
 #define ANKI_OS_LINUX 1
 #define ANKI_OS_LINUX 1

+ 1 - 0
src/anki/Core.h

@@ -7,3 +7,4 @@
 
 
 #include <anki/core/App.h>
 #include <anki/core/App.h>
 #include <anki/core/Config.h>
 #include <anki/core/Config.h>
+#include <anki/core/NativeWindow.h>

+ 2 - 0
src/anki/resource/ResourceFilesystem.h

@@ -89,7 +89,9 @@ public:
 	/// Search the path list to find the file. Then open the file for reading.
 	/// Search the path list to find the file. Then open the file for reading.
 	ANKI_USE_RESULT Error openFile(const ResourceFilename& filename, ResourceFilePtr& file);
 	ANKI_USE_RESULT Error openFile(const ResourceFilename& filename, ResourceFilePtr& file);
 
 
+#if !ANKI_TESTS
 private:
 private:
+#endif
 	class Path : public NonCopyable
 	class Path : public NonCopyable
 	{
 	{
 	public:
 	public:

+ 20 - 0
src/anki/ui/Canvas.h

@@ -0,0 +1,20 @@
+// Copyright (C) 2009-2017, Panagiotis Christopoulos Charitos and contributors.
+// All rights reserved.
+// Code licensed under the BSD License.
+// http://www.anki3d.org/LICENSE
+
+#pragma once
+
+#include <anki/ui/Common.h>
+
+namespace anki
+{
+
+/// @addtogroup ui
+/// @{
+
+// TODO
+
+/// @}
+
+} // end namespace anki

+ 20 - 0
src/anki/ui/UiImmediateModeBuilder.h

@@ -0,0 +1,20 @@
+// Copyright (C) 2009-2017, Panagiotis Christopoulos Charitos and contributors.
+// All rights reserved.
+// Code licensed under the BSD License.
+// http://www.anki3d.org/LICENSE
+
+#pragma once
+
+#include <anki/ui/Common.h>
+
+namespace anki
+{
+
+/// @addtogroup ui
+/// @{
+
+// TODO
+
+/// @}
+
+} // end namespace anki

+ 8 - 0
src/anki/ui/UiManager.cpp

@@ -8,6 +8,14 @@
 namespace anki
 namespace anki
 {
 {
 
 
+UiManager::UiManager()
+{
+}
+
+UiManager::~UiManager()
+{
+}
+
 Error UiManager::init(HeapAllocator<U8> alloc, ResourceManager* resources, GrManager* gr)
 Error UiManager::init(HeapAllocator<U8> alloc, ResourceManager* resources, GrManager* gr)
 {
 {
 	ANKI_ASSERT(resources);
 	ANKI_ASSERT(resources);

+ 59 - 0
tests/framework/Framework.cpp

@@ -223,4 +223,63 @@ void deleteTesterSingleton()
 	}
 	}
 }
 }
 
 
+NativeWindow* createWindow(U width, U height)
+{
+	HeapAllocator<U8> alloc(allocAligned, nullptr);
+
+	NativeWindowInitInfo inf;
+	inf.m_width = width;
+	inf.m_height = height;
+	inf.m_title = "AnKi unit tests";
+	NativeWindow* win = new NativeWindow();
+
+	ANKI_TEST_EXPECT_NO_ERR(win->init(inf, alloc));
+
+	return win;
+}
+
+GrManager* createGrManager(NativeWindow* win)
+{
+	GrManager* gr = new GrManager();
+
+	Config cfg;
+	cfg.set("debugContext", true);
+	cfg.set("vsync", false);
+	GrManagerInitInfo inf;
+	inf.m_allocCallback = allocAligned;
+	inf.m_cacheDirectory = "./";
+	inf.m_config = &cfg;
+	inf.m_window = win;
+	ANKI_TEST_EXPECT_NO_ERR(gr->init(inf));
+
+	return gr;
+}
+
+ResourceManager* createResourceManager(GrManager* gr, PhysicsWorld*& physics, ResourceFilesystem*& resourceFs)
+{
+	HeapAllocator<U8> alloc(allocAligned, nullptr);
+
+	physics = new PhysicsWorld();
+
+	ANKI_TEST_EXPECT_NO_ERR(physics->create(allocAligned, nullptr));
+
+	resourceFs = new ResourceFilesystem(alloc);
+	Config cfg;
+	ANKI_TEST_EXPECT_NO_ERR(resourceFs->init(cfg, "./"));
+
+	ResourceManagerInitInfo rinit;
+	rinit.m_gr = gr;
+	rinit.m_physics = physics;
+	rinit.m_resourceFs = resourceFs;
+	rinit.m_config = &cfg;
+	rinit.m_cacheDir = "./";
+	rinit.m_allocCallback = allocAligned;
+	rinit.m_allocCallbackData = nullptr;
+	ResourceManager* resources = new ResourceManager();
+
+	ANKI_TEST_EXPECT_NO_ERR(resources->init(rinit));
+
+	return resources;
+}
+
 } // end namespace anki
 } // end namespace anki

+ 10 - 0
tests/framework/Framework.h

@@ -8,6 +8,10 @@
 #include <anki/util/Singleton.h>
 #include <anki/util/Singleton.h>
 #include <anki/Math.h>
 #include <anki/Math.h>
 #include <anki/util/Logger.h>
 #include <anki/util/Logger.h>
+#include <anki/Core.h>
+#include <anki/Gr.h>
+#include <anki/Resource.h>
+#include <anki/Physics.h>
 #include <stdexcept>
 #include <stdexcept>
 #include <vector>
 #include <vector>
 #include <string>
 #include <string>
@@ -216,4 +220,10 @@ extern void deleteTesterSingleton();
 /// Check error code.
 /// Check error code.
 #define ANKI_TEST_EXPECT_ERR(x_, y_) ANKI_TEST_EXPECT_EQ_IMPL(__FILE__, __LINE__, __func__, x_, y_)
 #define ANKI_TEST_EXPECT_ERR(x_, y_) ANKI_TEST_EXPECT_EQ_IMPL(__FILE__, __LINE__, __func__, x_, y_)
 
 
+NativeWindow* createWindow(U width, U height);
+
+GrManager* createGrManager(NativeWindow* win);
+
+ResourceManager* createResourceManager(GrManager* gr, PhysicsWorld*& physics, ResourceFilesystem*& resourceFs);
+
 } // end namespace anki
 } // end namespace anki

+ 3 - 16
tests/gr/Gr.cpp

@@ -263,7 +263,8 @@ static StagingGpuMemoryManager* stagingMem = nullptr;
 
 
 #define COMMON_BEGIN()                                                                                                 \
 #define COMMON_BEGIN()                                                                                                 \
 	stagingMem = new StagingGpuMemoryManager();                                                                        \
 	stagingMem = new StagingGpuMemoryManager();                                                                        \
-	createGrManager(win, gr);                                                                                          \
+	win = createWindow(WIDTH, HEIGHT);                                                                                 \
+	gr = createGrManager(win);                                                                                         \
 	ANKI_TEST_EXPECT_NO_ERR(stagingMem->init(gr, Config()));                                                           \
 	ANKI_TEST_EXPECT_NO_ERR(stagingMem->init(gr, Config()));                                                           \
 	TransferGpuAllocator transfAlloc;                                                                                  \
 	TransferGpuAllocator transfAlloc;                                                                                  \
 	ANKI_TEST_EXPECT_NO_ERR(transfAlloc.init(128_MB, gr, gr->getAllocator()));                                         \
 	ANKI_TEST_EXPECT_NO_ERR(transfAlloc.init(128_MB, gr, gr->getAllocator()));                                         \
@@ -317,23 +318,9 @@ static void* setStorage(PtrSize size, CommandBufferPtr& cmdb, U set, U binding)
 
 
 const PixelFormat DS_FORMAT = PixelFormat(ComponentFormat::D24S8, TransformFormat::UNORM);
 const PixelFormat DS_FORMAT = PixelFormat(ComponentFormat::D24S8, TransformFormat::UNORM);
 
 
-static NativeWindow* createWindow()
-{
-	HeapAllocator<U8> alloc(allocAligned, nullptr);
-
-	NativeWindowInitInfo inf;
-	inf.m_width = WIDTH;
-	inf.m_height = HEIGHT;
-	NativeWindow* win = new NativeWindow();
-
-	ANKI_TEST_EXPECT_NO_ERR(win->init(inf, alloc));
-
-	return win;
-}
-
 static void createGrManager(NativeWindow*& win, GrManager*& gr)
 static void createGrManager(NativeWindow*& win, GrManager*& gr)
 {
 {
-	win = createWindow();
+	win = createWindow(WIDTH, HEIGHT);
 	gr = new GrManager();
 	gr = new GrManager();
 
 
 	Config cfg;
 	Config cfg;

+ 0 - 1
tests/resource/ResourceFilesystem.cpp

@@ -4,7 +4,6 @@
 // http://www.anki3d.org/LICENSE
 // http://www.anki3d.org/LICENSE
 
 
 #include "tests/framework/Framework.h"
 #include "tests/framework/Framework.h"
-#define private public
 #include "anki/resource/ResourceFilesystem.h"
 #include "anki/resource/ResourceFilesystem.h"
 
 
 namespace anki
 namespace anki

+ 62 - 3
tests/ui/Ui.cpp

@@ -4,14 +4,73 @@
 // http://www.anki3d.org/LICENSE
 // http://www.anki3d.org/LICENSE
 
 
 #include <tests/framework/Framework.h>
 #include <tests/framework/Framework.h>
-#include <anki/core/App.h>
 #include <anki/core/Config.h>
 #include <anki/core/Config.h>
+#include <anki/util/HighRezTimer.h>
+#include <anki/Ui.h>
 
 
 namespace anki
 namespace anki
 {
 {
 
 
+static const U WIDTH = 1920;
+static const U HEIGHT = 1080;
+
+static FramebufferPtr createDefaultFb(GrManager& gr)
+{
+	FramebufferInitInfo fbinit;
+	fbinit.m_colorAttachmentCount = 1;
+	fbinit.m_colorAttachments[0].m_clearValue.m_colorf = {{1.0, 0.0, 1.0, 1.0}};
+
+	return gr.newInstance<Framebuffer>(fbinit);
+}
+
 ANKI_TEST(Ui, Ui)
 ANKI_TEST(Ui, Ui)
 {
 {
-	// TODO
+	NativeWindow* win = createWindow(WIDTH, HEIGHT);
+	GrManager* gr = createGrManager(win);
+	PhysicsWorld* physics;
+	ResourceFilesystem* fs;
+	ResourceManager* resource = createResourceManager(gr, physics, fs);
+	UiManager* ui = new UiManager();
+
+	HeapAllocator<U8> alloc(allocAligned, nullptr);
+	ANKI_TEST_EXPECT_NO_ERR(ui->init(alloc, resource, gr));
+
+	{
+		FramebufferPtr fb = createDefaultFb(*gr);
+
+		U iterations = 100;
+		while(iterations--)
+		{
+			HighRezTimer timer;
+			timer.start();
+
+			gr->beginFrame();
+
+			CommandBufferInitInfo cinit;
+			cinit.m_flags = CommandBufferFlag::GRAPHICS_WORK | CommandBufferFlag::SMALL_BATCH;
+			CommandBufferPtr cmdb = gr->newInstance<CommandBuffer>(cinit);
+
+			cmdb->beginRenderPass(fb);
+			cmdb->endRenderPass();
+			cmdb->flush();
+
+			gr->swapBuffers();
+
+			timer.stop();
+			const F32 TICK = 1.0 / 30.0;
+			if(timer.getElapsedTime() < TICK)
+			{
+				HighRezTimer::sleep(TICK - timer.getElapsedTime());
+			}
+		}
+	}
+
+	delete ui;
+	delete resource;
+	delete physics;
+	delete fs;
+	delete gr;
+	delete win;
 }
 }
-}
+
+} // end namespace anki