Browse Source

- Changes in the GrManager interface
- Adding anki_internal tag
- Fixing omni light shdows

Panagiotis Christopoulos Charitos 10 years ago
parent
commit
05eda49a17

+ 6 - 0
include/anki/Config.h.cmake

@@ -155,4 +155,10 @@
 #endif
 /// @}
 
+#ifdef ANKI_BUILD
+#	define anki_internal public
+#else
+#	define anki_internal protected
+#endif
+
 #endif

+ 5 - 1
include/anki/core/App.h

@@ -8,6 +8,7 @@
 
 #include "anki/util/Allocator.h"
 #include "anki/util/String.h"
+#include "anki/util/Ptr.h"
 #include "anki/core/Timestamp.h"
 #if ANKI_OS == ANKI_OS_ANDROID
 #	include <android_native_app_glue.h>
@@ -31,10 +32,13 @@ class SceneGraph;
 class ScriptManager;
 class ResourceManager;
 class ResourceFilesystem;
+class GrManagerInterfaceImpl;
 
 /// The core class of the engine.
 class App
 {
+	friend class GrManagerInterfaceImpl;
+
 public:
 	/// User callback of main loop
 	using UserMainLoopCallback = Error(*)(App& app, void* userData, Bool& quit);
@@ -141,6 +145,7 @@ private:
 	// Sybsystems
 	NativeWindow* m_window = nullptr;
 	Input* m_input = nullptr;
+	WeakPtr<GrManagerInterfaceImpl> m_grInterface;
 	GrManager* m_gr = nullptr;
 	PhysicsWorld* m_physics = nullptr;
 	ResourceFilesystem* m_resourceFs = nullptr;
@@ -151,7 +156,6 @@ private:
 
 	// Misc
 	Timestamp m_globalTimestamp = 0;
-	void* m_ctx = nullptr;
 	Threadpool* m_threadpool = nullptr;
 	String m_settingsDir; ///< The path that holds the configuration
 	String m_cacheDir; ///< This is used as a cache

+ 0 - 4
include/anki/gr/Common.h

@@ -51,10 +51,6 @@ const U MAX_TEXTURE_BINDINGS = 8;
 const U MAX_UNIFORM_BUFFER_BINDINGS = 8;
 const U MAX_STORAGE_BUFFER_BINDINGS = 8;
 const U MAX_FRAMES_IN_FLIGHT = 3;
-
-/// GL generic callback
-using SwapBuffersCallback = void(*)(void*);
-using MakeCurrentCallback = void(*)(void*, void*);
 /// @}
 
 } // end namespace anki

+ 24 - 8
include/anki/gr/GrManager.h

@@ -13,6 +13,22 @@ namespace anki {
 /// @addtogroup graphics
 /// @{
 
+/// A collection of functions that some backends need from other libraries.
+class GrManagerInterface
+{
+public:
+	virtual ~GrManagerInterface()
+	{}
+
+	/// Swap buffers.
+	virtual void swapBuffersCommand() = 0;
+
+	/// Make a context current.
+	/// @param bind If true make a context current to this thread, if false
+	///        make no contexts current to a thread.
+	virtual void makeCurrentCommand(Bool bind) = 0;
+};
+
 /// Manager initializer.
 class GrManagerInitializer
 {
@@ -20,12 +36,7 @@ public:
 	AllocAlignedCallback m_allocCallback = nullptr;
 	void* m_allocCallbackUserData = nullptr;
 
-	MakeCurrentCallback m_makeCurrentCallback = nullptr;
-	void* m_makeCurrentCallbackData = nullptr;
-	void* m_ctx = nullptr;
-
-	SwapBuffersCallback m_swapBuffersCallback = nullptr;
-	void* m_swapBuffersCallbackData = nullptr;
+	WeakPtr<GrManagerInterface> m_interface;
 
 	CString m_cacheDirectory;
 	Bool m_registerDebugMessages = false;
@@ -54,7 +65,7 @@ public:
 	template<typename T, typename... Args>
 	IntrusivePtr<T> newInstance(Args&&... args);
 
-#ifdef ANKI_BUILD
+anki_internal:
 	GrAllocator<U8>& getAllocator()
 	{
 		return m_alloc;
@@ -74,12 +85,17 @@ public:
 	{
 		return m_cacheDir.toCString();
 	}
-#endif
+
+	U64& getUuidIndex()
+	{
+		return m_uuidIndex;
+	}
 
 private:
 	GrAllocator<U8> m_alloc; ///< Keep it first to get deleted last
 	UniquePtr<GrManagerImpl> m_impl;
 	String m_cacheDir;
+	U64 m_uuidIndex = 1;
 };
 
 template<typename T, typename... Args>

+ 8 - 4
include/anki/gr/GrObject.h

@@ -18,10 +18,7 @@ namespace anki {
 class GrObject: public NonCopyable
 {
 public:
-	GrObject(GrManager* manager)
-		: m_refcount(0)
-		, m_manager(manager)
-	{}
+	GrObject(GrManager* manager);
 
 	virtual ~GrObject()
 	{}
@@ -43,9 +40,16 @@ public:
 		return m_refcount;
 	}
 
+	/// A unique identifier for caching objects.
+	U64 getUuid() const
+	{
+		return m_uuid;
+	}
+
 private:
 	Atomic<I32> m_refcount;
 	GrManager* m_manager;
+	U64 m_uuid;
 };
 /// @}
 

+ 1 - 1
include/anki/gr/gl/GlState.h

@@ -72,7 +72,7 @@ public:
 
 	/// Global UBO ring buffer
 	/// @{
-	U32 m_globalUboSize = MAX_UBO_SIZE * 128; ///< 8MB
+	U32 m_globalUboSize = MAX_UBO_SIZE * 256; ///< 16MB
 	DArray<GLuint> m_globalUbos; ///< Multiple cause of the spec's UBO max size.
 	DArray<U8*> m_globalUboAddresses;
 	Atomic<U32> m_globalUboCurrentOffset = {0};

+ 6 - 12
include/anki/gr/gl/RenderingThread.h

@@ -11,10 +11,12 @@
 
 namespace anki {
 
+class GrManagerInterface;
+
 /// @addtogroup opengl
 /// @{
 
-#define ANKI_DISABLE_GL_RENDERING_THREAD 1
+#define ANKI_DISABLE_GL_RENDERING_THREAD 0
 
 /// Command queue. It's essentialy a queue of command buffers waiting for
 /// execution and a server
@@ -40,10 +42,7 @@ public:
 
 	/// Start the working thread
 	/// @note Don't free the context before calling #stop
-	void start(
-		MakeCurrentCallback makeCurrentCb, void* makeCurrentCbData, void* ctx,
-		SwapBuffersCallback swapBuffersCallback, void* swapBuffersCbData,
-		Bool registerMessages);
+	void start(WeakPtr<GrManagerInterface> interface, Bool registerMessages);
 
 	/// Stop the working thread
 	void stop();
@@ -67,7 +66,8 @@ public:
 	void swapBuffers();
 
 private:
-	GrManager* m_manager = nullptr;
+	WeakPtr<GrManager> m_manager;
+	WeakPtr<GrManagerInterface> m_interface;
 
 	static const U QUEUE_SIZE = 512;
 	DArray<CommandBufferPtr> m_queue; ///< Command queue
@@ -78,13 +78,7 @@ private:
 	ConditionVariable m_condVar; ///< To wake up the thread
 	Thread m_thread;
 
-	void* m_makeCurrentCbData = nullptr; ///< Pointer first param of makecurrent
-	void* m_ctx = nullptr; ///< Pointer to the system GL context
-	MakeCurrentCallback m_makeCurrentCb; ///< Making a context current
-
 	CommandBufferPtr m_swapBuffersCommands;
-	SwapBuffersCallback m_swapBuffersCallback;
-	void* m_swapBuffersCbData;
 	ConditionVariable m_frameCondVar;
 	Mutex m_frameMtx;
 	Bool8 m_frameWait = false;

+ 11 - 12
include/anki/renderer/Bloom.h

@@ -22,7 +22,17 @@ class ShaderProgram;
 class Bloom: public RenderingPass
 {
 public:
-#ifdef ANKI_BUILD
+	U32 getBlurringIterationsCount() const
+	{
+		return m_blurringIterationsCount;
+	}
+
+	void setBlurringIterationsCount(const U32 x)
+	{
+		m_blurringIterationsCount = x;
+	}
+
+anki_internal:
 	static const PixelFormat RT_PIXEL_FORMAT;
 
 	Bloom(Renderer* r)
@@ -48,17 +58,6 @@ public:
 	{
 		return m_height;
 	}
-#endif
-
-	U32 getBlurringIterationsCount() const
-	{
-		return m_blurringIterationsCount;
-	}
-
-	void setBlurringIterationsCount(const U32 x)
-	{
-		m_blurringIterationsCount = x;
-	}
 
 private:
 	U32 m_width, m_height;

+ 1 - 3
include/anki/renderer/Fs.h

@@ -15,8 +15,7 @@ namespace anki {
 /// Forward rendering stage. The objects that blend must be handled differently
 class Fs: public RenderingPass
 {
-public:
-#ifdef ANKI_BUILD
+anki_internal:
 	Fs(Renderer* r)
 		: RenderingPass(r)
 	{}
@@ -25,7 +24,6 @@ public:
 
 	ANKI_USE_RESULT Error init(const ConfigSet& initializer);
 	ANKI_USE_RESULT Error run(CommandBufferPtr& cmdb);
-#endif
 
 private:
 	FramebufferPtr m_fb;

+ 2 - 2
include/anki/renderer/Is.h

@@ -39,7 +39,8 @@ class Is: public RenderingPass
 
 public:
 	static const U MIPMAPS_COUNT = 7;
-#ifdef ANKI_BUILD
+
+anki_internal:
 	static const PixelFormat RT_PIXEL_FORMAT;
 
 	Is(Renderer* r);
@@ -64,7 +65,6 @@ public:
 	{
 		m_ambientColor = color;
 	}
-#endif
 
 private:
 	enum

+ 1 - 3
include/anki/renderer/Lf.h

@@ -18,8 +18,7 @@ namespace anki {
 /// Lens flare rendering pass. Part of forward shading.
 class Lf: public RenderingPass
 {
-public:
-#ifdef ANKI_BUILD
+anki_internal:
 	Lf(Renderer* r)
 		: RenderingPass(r)
 	{}
@@ -32,7 +31,6 @@ public:
 	void runOcclusionTests(CommandBufferPtr& cmdb);
 
 	void run(CommandBufferPtr& cmdb);
-#endif
 
 private:
 	// Occlusion query

+ 1 - 3
include/anki/renderer/Ms.h

@@ -16,8 +16,7 @@ namespace anki {
 /// Material stage also known as G buffer stage. It populates the G buffer
 class Ms: public RenderingPass
 {
-public:
-#ifdef ANKI_BUILD
+anki_internal:
 	static const U ATTACHMENT_COUNT = 3;
 	static const Array<PixelFormat, ATTACHMENT_COUNT> RT_PIXEL_FORMATS;
 	static const PixelFormat DEPTH_RT_PIXEL_FORMAT;
@@ -58,7 +57,6 @@ public:
 	}
 
 	void generateMipmaps(CommandBufferPtr& cmdb);
-#endif
 
 private:
 	/// A collection of data

+ 19 - 20
include/anki/renderer/Pps.h

@@ -17,26 +17,6 @@ namespace anki {
 class Pps: public RenderingPass
 {
 public:
-#ifdef ANKI_BUILD
-	static const PixelFormat RT_PIXEL_FORMAT;
-
-	Pps(Renderer* r);
-	~Pps();
-
-	ANKI_USE_RESULT Error init(const ConfigSet& config);
-	void run(CommandBufferPtr& jobs);
-
-	const TexturePtr& getRt() const
-	{
-		return m_rt;
-	}
-
-	TexturePtr& getRt()
-	{
-		return m_rt;
-	}
-#endif
-
 	const Bloom& getBloom() const
 	{
 		return *m_bloom;
@@ -80,6 +60,25 @@ public:
 	/// Load the color grading texture.
 	Error loadColorGradingTexture(CString filename);
 
+anki_internal:
+	static const PixelFormat RT_PIXEL_FORMAT;
+
+	Pps(Renderer* r);
+	~Pps();
+
+	ANKI_USE_RESULT Error init(const ConfigSet& config);
+	void run(CommandBufferPtr& jobs);
+
+	const TexturePtr& getRt() const
+	{
+		return m_rt;
+	}
+
+	TexturePtr& getRt()
+	{
+		return m_rt;
+	}
+
 private:
 	UniquePtr<Ssao> m_ssao;
 	UniquePtr<Sslr> m_sslr;

+ 3 - 6
include/anki/renderer/Renderer.h

@@ -28,10 +28,6 @@ class ResourceManager;
 class Renderer
 {
 public:
-#ifdef ANKI_BUILD
-	const U TILE_SIZE = 64;
-#endif
-
 	Renderer();
 
 	~Renderer();
@@ -123,7 +119,9 @@ public:
 		SceneNode& frustumableNode,
 		Array<CommandBufferPtr, RENDERER_COMMAND_BUFFERS_COUNT>& cmdBuff);
 
-#ifdef ANKI_BUILD
+anki_internal:
+	const U TILE_SIZE = 64;
+
 	void getOutputFramebuffer(FramebufferPtr& outputFb, U32& width, U32& height)
 	{
 		if(m_outputFb.isCreated())
@@ -276,7 +274,6 @@ public:
 	{
 		return *m_globalTimestamp;
 	}
-#endif
 
 private:
 	Threadpool* m_threadpool;

+ 11 - 14
include/anki/renderer/RenderingPass.h

@@ -26,7 +26,17 @@ class ConfigSet;
 class RenderingPass
 {
 public:
-#ifdef ANKI_BUILD
+	Bool getEnabled() const
+	{
+		return m_enabled;
+	}
+
+	void setEnabled(Bool e)
+	{
+		m_enabled = e;
+	}
+
+anki_internal:
 	RenderingPass(Renderer* r)
 		: m_r(r)
 	{}
@@ -39,28 +49,15 @@ public:
 	HeapAllocator<U8> getAllocator() const;
 
 	StackAllocator<U8> getFrameAllocator() const;
-#endif
-
-	Bool getEnabled() const
-	{
-		return m_enabled;
-	}
-
-	void setEnabled(Bool e)
-	{
-		m_enabled = e;
-	}
 
 protected:
 	Bool8 m_enabled = false;
-#ifdef ANKI_BUILD
 	Renderer* m_r; ///< Know your father
 
 	GrManager& getGrManager();
 	const GrManager& getGrManager() const;
 
 	ResourceManager& getResourceManager();
-#endif
 };
 /// @}
 

+ 3 - 3
include/anki/renderer/Sm.h

@@ -22,8 +22,9 @@ class SceneNode;
 class Sm: private RenderingPass
 {
 public:
-	static const U32 MAX_SHADOW_CASTERS = 8;
-#ifdef ANKI_BUILD
+	static const U32 MAX_SHADOW_CASTERS = 16;
+
+anki_internal:
 	static const PixelFormat DEPTH_RT_PIXEL_FORMAT;
 
 	Sm(Renderer* r)
@@ -67,7 +68,6 @@ public:
 	{
 		return m_omniTexArray;
 	}
-#endif
 
 private:
 	TexturePtr m_spotTexArray;

+ 1 - 3
include/anki/renderer/Ssao.h

@@ -19,8 +19,7 @@ namespace anki {
 /// Screen space ambient occlusion pass
 class Ssao: public RenderingPass
 {
-public:
-#ifdef ANKI_BUILD
+anki_internal:
 	static const PixelFormat RT_PIXEL_FORMAT;
 
 	Ssao(Renderer* r)
@@ -39,7 +38,6 @@ public:
 	{
 		return m_uniformsBuff;
 	}
-#endif
 
 private:
 	U32 m_width, m_height; ///< Blur passes size

+ 1 - 3
include/anki/renderer/Sslf.h

@@ -15,8 +15,7 @@ namespace anki {
 /// Screen space lens flare pass.
 class Sslf: public RenderingPass
 {
-public:
-#ifdef ANKI_BUILD
+anki_internal:
 	Sslf(Renderer* r)
 		: RenderingPass(r)
 	{}
@@ -28,7 +27,6 @@ public:
 	{
 		return m_rt;
 	}
-#endif
 
 private:
 	TexturePtr m_rt;

+ 1 - 3
include/anki/renderer/Sslr.h

@@ -16,15 +16,13 @@ namespace anki {
 /// Screen space local reflections pass
 class Sslr: public RenderingPass
 {
-public:
-#ifdef ANKI_BUILD
+anki_internal:
 	Sslr(Renderer* r)
 		: RenderingPass(r)
 	{}
 
 	ANKI_USE_RESULT Error init(const ConfigSet& config);
 	void run(CommandBufferPtr& cmdBuff);
-#endif
 
 private:
 	U32 m_width;

+ 6 - 7
include/anki/renderer/Tiler.h

@@ -78,7 +78,12 @@ public:
 	using TestResult = TilerTestResult;
 	using TestParameters = TilerTestParameters;
 
-#ifdef ANKI_BUILD
+	/// Test against all tiles.
+	/// @param[in, out] params The collision parameters.
+	/// @return If visible return true.
+	Bool test(TestParameters& params) const;
+
+anki_internal:
 	Tiler(Renderer* r);
 	~Tiler();
 
@@ -95,12 +100,6 @@ public:
 		U i = (getGlobalTimestamp() - m_pbos.getSize() + 1) % m_pbos.getSize();
 		return m_pbos[i];
 	}
-#endif
-
-	/// Test against all tiles.
-	/// @param[in, out] params The collision parameters.
-	/// @return If visible return true.
-	Bool test(TestParameters& params) const;
 
 private:
 	/// Tile planes

+ 1 - 3
include/anki/renderer/Tm.h

@@ -15,8 +15,7 @@ namespace anki {
 /// Tonemapping.
 class Tm: public RenderingPass
 {
-public:
-#ifdef ANKI_BUILD
+anki_internal:
 	Tm(Renderer* r)
 		: RenderingPass(r)
 	{}
@@ -29,7 +28,6 @@ public:
 	ANKI_USE_RESULT Error create(const ConfigSet& initializer);
 
 	void run(CommandBufferPtr& cmdb);
-#endif
 
 private:
 	ShaderResourcePtr m_luminanceShader;

+ 1 - 1
include/anki/scene/Light.h

@@ -52,7 +52,7 @@ class PointLight: public Light
 {
 public:
 	/// The near plane on the shadow map frustums.
-	static constexpr F32 FRUSTUM_NEAR_PLANE = 0.1;
+	static constexpr F32 FRUSTUM_NEAR_PLANE = 0.1 / 4.0;
 
 	PointLight(SceneGraph* scene);
 	~PointLight();

+ 1 - 2
include/anki/ui/Font.h

@@ -36,7 +36,7 @@ public:
 	/// Initialize the font.
 	ANKI_USE_RESULT Error init(const CString& filename, U32 fontHeight);
 
-#ifdef ANKI_BUILD
+anki_internal:
 	/// Get info for a character.
 	const FontCharInfo& getCharInfo(char c) const
 	{
@@ -49,7 +49,6 @@ public:
 	{
 		return m_img;
 	}
-#endif
 
 private:
 	static const char FIRST_CHAR = ' ';

+ 0 - 2
include/anki/ui/UiInterface.h

@@ -9,8 +9,6 @@
 
 namespace anki {
 
-class UiImage;
-
 /// @addtogroup ui
 /// @{
 

+ 7 - 0
include/anki/ui/UiInterfaceImpl.h

@@ -84,6 +84,13 @@ private:
 
 	Array<Stage, StageId::COUNT> m_stages;
 
+	class ResourceGroupKey
+	{
+	public:
+		StageId m_stage;
+		U64 m_textureId;
+	};
+
 	// Intermediate
 	U8 m_timestamp = 0; ///< Local timestamp.
 	CommandBufferPtr m_cmdb;

+ 15 - 1
include/anki/util/Allocator.h

@@ -8,6 +8,7 @@
 #include "anki/util/Assert.h"
 #include "anki/util/Memory.h"
 #include "anki/util/Logger.h"
+#include "anki/util/Ptr.h"
 #include <cstddef> // For ptrdiff_t
 #include <utility> // For forward
 
@@ -175,7 +176,7 @@ public:
 	void construct(pointer p, const T& val)
 	{
 		// Placement new
-		new ((T*)p) T(val);
+		::new (p) T(val);
 	}
 
 	/// Call constructor with many arguments
@@ -294,6 +295,19 @@ public:
 		}
 	}
 
+	/// Call the destructor and deallocate an object
+	/// @note This is AnKi specific
+	template<typename Y>
+	void deleteInstance(WeakPtr<Y> ptr)
+	{
+		if(ptr)
+		{
+			typename rebind<Y>::other alloc(*this);
+			alloc.destroy(&ptr[0]);
+			alloc.deallocate(&ptr[0], 1);
+		}
+	}
+
 	/// Call the destructor and deallocate an array of objects
 	/// @note This is AnKi specific
 	template<typename Y>

+ 35 - 4
include/anki/util/Ptr.h

@@ -35,16 +35,16 @@ public:
 		return m_ptr;
 	}
 
-	T& get()
+	T* get()
 	{
 		ANKI_ASSERT(m_ptr);
-		return *m_ptr;
+		return m_ptr;
 	}
 
-	const T& get() const
+	const T* get() const
 	{
 		ANKI_ASSERT(m_ptr);
-		return *m_ptr;
+		return m_ptr;
 	}
 
 	Bool isCreated() const
@@ -106,6 +106,9 @@ protected:
 template<typename T>
 class WeakPtr: public PtrBase<T>
 {
+	template<typename>
+	friend class WeakPtr;
+
 public:
 	using Base = PtrBase<T>;
 
@@ -121,6 +124,11 @@ public:
 		: Base(other.m_ptr)
 	{}
 
+	template<typename Y>
+	WeakPtr(const WeakPtr<Y>& other)
+		: Base(other.m_ptr)
+	{}
+
 	WeakPtr(WeakPtr&& other)
 		: Base(other.m_ptr)
 	{
@@ -140,6 +148,29 @@ public:
 		return *this;
 	}
 
+	/// Copy.
+	template<typename Y>
+	WeakPtr& operator=(const WeakPtr<Y>& other)
+	{
+		Base::m_ptr = other.m_ptr;
+		return *this;
+	}
+
+	/// Copy.
+	WeakPtr& operator=(T* ptr)
+	{
+		Base::m_ptr = ptr;
+		return *this;
+	}
+
+	/// Copy.
+	template<typename Y>
+	WeakPtr& operator=(Y* ptr)
+	{
+		Base::m_ptr = ptr;
+		return *this;
+	}
+
 	/// Move.
 	WeakPtr& operator=(WeakPtr&& other)
 	{

+ 30 - 9
src/core/App.cpp

@@ -29,11 +29,29 @@
 
 namespace anki {
 
+//==============================================================================
 #if ANKI_OS == ANKI_OS_ANDROID
 /// The one and only android hack
 android_app* gAndroidApp = nullptr;
 #endif
 
+class GrManagerInterfaceImpl: public GrManagerInterface
+{
+public:
+	WeakPtr<App> m_app;
+	void* m_ctx;
+
+	void swapBuffersCommand() override
+	{
+		m_app->m_window->swapBuffers();
+	}
+
+	void makeCurrentCommand(Bool bind) override
+	{
+		m_app->m_window->contextMakeCurrent(bind ? m_ctx : nullptr);
+	}
+};
+
 //==============================================================================
 App::App()
 {}
@@ -89,6 +107,11 @@ void App::cleanup()
 		m_gr = nullptr;
 	}
 
+	if(m_grInterface)
+	{
+		m_heapAlloc.deleteInstance(m_grInterface);
+	}
+
 	if(m_threadpool)
 	{
 		m_heapAlloc.deleteInstance(m_threadpool);
@@ -180,9 +203,6 @@ Error App::createInternal(const ConfigSet& config_,
 
 	ANKI_CHECK(m_window->create(nwinit, m_heapAlloc));
 
-	m_ctx = m_window->getCurrentContext();
-	m_window->contextMakeCurrent(nullptr);
-
 	//
 	// Input
 	//
@@ -196,18 +216,19 @@ Error App::createInternal(const ConfigSet& config_,
 	m_threadpool = m_heapAlloc.newInstance<Threadpool>(getCpuCoresCount());
 
 	//
-	// GL
+	// Graphics API
 	//
+	m_grInterface = m_heapAlloc.newInstance<GrManagerInterfaceImpl>();
+	m_grInterface->m_app = this;
+	m_grInterface->m_ctx = m_window->getCurrentContext();
+	m_window->contextMakeCurrent(nullptr);
+
 	m_gr = m_heapAlloc.newInstance<GrManager>();
 
 	GrManagerInitializer grInit;
 	grInit.m_allocCallback = m_allocCb;
 	grInit.m_allocCallbackUserData = m_allocCbData;
-	grInit.m_makeCurrentCallback = makeCurrent;
-	grInit.m_makeCurrentCallbackData = this;
-	grInit.m_ctx = m_ctx;
-	grInit.m_swapBuffersCallback = swapWindow;
-	grInit.m_swapBuffersCallbackData = m_window;
+	grInit.m_interface = m_grInterface;
 	grInit.m_cacheDirectory = m_cacheDir.toCString();
 	grInit.m_registerDebugMessages = nwinit.m_debugContext;
 

+ 7 - 0
src/gr/GrObject.cpp

@@ -8,6 +8,13 @@
 
 namespace anki {
 
+//==============================================================================
+GrObject::GrObject(GrManager* manager)
+	: m_refcount(0)
+	, m_manager(manager)
+	, m_uuid(m_manager->getUuidIndex()++)
+{}
+
 //==============================================================================
 GrAllocator<U8> GrObject::getAllocator() const
 {

+ 1 - 5
src/gr/gl/GrManagerImpl.cpp

@@ -36,11 +36,7 @@ void GrManagerImpl::create(GrManagerInitializer& init)
 		m_manager->getAllocator().newInstance<RenderingThread>(m_manager);
 
 	// Start it
-	m_thread->start(init.m_makeCurrentCallback,
-		init.m_makeCurrentCallbackData, init.m_ctx,
-		init.m_swapBuffersCallback, init.m_swapBuffersCallbackData,
-		init.m_registerDebugMessages);
-
+	m_thread->start(init.m_interface, init.m_registerDebugMessages);
 	m_thread->syncClientServer();
 }
 

+ 6 - 16
src/gr/gl/RenderingThread.cpp

@@ -130,25 +130,16 @@ void RenderingThread::finishCommandBuffer(CommandBufferPtr commands)
 }
 
 //==============================================================================
-void RenderingThread::start(
-	MakeCurrentCallback makeCurrentCb, void* makeCurrentCbData, void* ctx,
-	SwapBuffersCallback swapBuffersCallback, void* swapBuffersCbData,
+void RenderingThread::start(WeakPtr<GrManagerInterface> interface,
 	Bool registerMessages)
 {
 	ANKI_ASSERT(m_tail == 0 && m_head == 0);
+	ANKI_ASSERT(interface);
+	m_interface = interface;
 	m_state.m_registerMessages = registerMessages;
 	m_queue.create(m_manager->getAllocator(), QUEUE_SIZE);
 
-	// Context
-	ANKI_ASSERT(ctx != nullptr && makeCurrentCb != nullptr);
-	m_ctx = ctx;
-	m_makeCurrentCbData = makeCurrentCbData;
-	m_makeCurrentCb = makeCurrentCb;
-
 	// Swap buffers stuff
-	ANKI_ASSERT(swapBuffersCallback != nullptr);
-	m_swapBuffersCallback = swapBuffersCallback;
-	m_swapBuffersCbData = swapBuffersCbData;
 	m_swapBuffersCommands = m_manager->newInstance<CommandBuffer>();
 	m_swapBuffersCommands->getImplementation().
 		pushBackNewCommand<SwapBuffersCommand>(this);
@@ -188,8 +179,7 @@ void RenderingThread::stop()
 //==============================================================================
 void RenderingThread::prepare()
 {
-	ANKI_ASSERT(m_makeCurrentCb && m_ctx);
-	(*m_makeCurrentCb)(m_makeCurrentCbData, m_ctx);
+	m_interface->makeCurrentCommand(true);
 
 	// Ignore the first error
 	glGetError();
@@ -232,7 +222,7 @@ void RenderingThread::finish()
 
 	// Cleanup
 	glFinish();
-	(*m_makeCurrentCb)(m_makeCurrentCbData, nullptr);
+	m_interface->makeCurrentCommand(false);
 }
 
 //==============================================================================
@@ -300,7 +290,7 @@ void RenderingThread::syncClientServer()
 void RenderingThread::swapBuffersInternal()
 {
 	// Do the swap buffers
-	m_swapBuffersCallback(m_swapBuffersCbData);
+	m_interface->swapBuffersCommand();
 
 	// Notify the main thread that we are done
 	{

+ 1 - 1
src/renderer/Dbg.cpp

@@ -117,7 +117,7 @@ Error Dbg::run(CommandBufferPtr& cmdb)
 
 	(void)err;
 
-	if(0)
+	if(1)
 	{
 		PhysicsDebugDrawer phyd(m_drawer);
 

+ 1 - 1
src/renderer/Is.cpp

@@ -139,7 +139,7 @@ Is::~Is()
 {
 	if(m_barrier)
 	{
-		getAllocator().deleteInstance(&m_barrier.get());
+		getAllocator().deleteInstance(m_barrier.get());
 	}
 }
 

+ 6 - 4
src/scene/Light.cpp

@@ -257,13 +257,15 @@ Error PointLight::frameUpdate(F32 prevUpdateTime, F32 crntTime)
 		rot = Mat3(Euler(0.0, 0.0, PI));
 		m_shadowData[5].m_localTrf.setRotation(Mat3x4(rot));
 
-		const Transform& trf =
-			getComponent<MoveComponent>().getWorldTransform();
+		const Vec4& origin =
+			getComponent<MoveComponent>().getWorldTransform().getOrigin();
 		for(U i = 0; i < 6; i++)
 		{
 			m_shadowData[i].m_frustum.setAll(ang, ang, zNear, dist);
-			m_shadowData[i].m_frustum.resetTransform(
-				trf.combineTransformations(m_shadowData[i].m_localTrf));
+
+			Transform trf = m_shadowData[i].m_localTrf;
+			trf.setOrigin(origin);
+			m_shadowData[i].m_frustum.resetTransform(trf);
 
 			FrustumComponent* comp =
 				getSceneAllocator().newInstance<FrustumComponent>(this,

+ 2 - 2
src/scene/Visibility.cpp

@@ -345,10 +345,10 @@ void VisibilityTestTask::combineTestResults(
 
 	visible->prepareMerge();
 
-	if(renderablesSize == 0)
+	/*if(renderablesSize == 0)
 	{
 		ANKI_LOGW("No visible renderables");
-	}
+	}*/
 
 	// Append thread results
 	VisibleNode* renderables = visible->getRenderablesBegin();

+ 9 - 14
testapp/Main.cpp

@@ -43,7 +43,7 @@ App* app;
 ModelNode* horse;
 PerspectiveCamera* cam;
 
-#define NO_PLAYER 1
+#define NO_PLAYER 0
 
 Bool profile = false;
 
@@ -86,7 +86,7 @@ Error init()
 
 #if NO_PLAYER
 	cam->getComponent<MoveComponent>().
-		setLocalTransform(Transform(Vec4(-11.0, 2.5, 15.0, 0.0),
+		setLocalTransform(Transform(Vec4(147.392776, -10.132728, 16.607138, 0.0),
 		Mat3x4(Euler(toRad(0.0), toRad(0.0), toRad(0.0))),
 		1.0));
 #endif
@@ -118,7 +118,7 @@ Error init()
 	}
 #endif
 
-#if 1
+#if 0
 	PointLight* plight;
 	scene.newSceneNode<PointLight>("spot0", plight);
 
@@ -272,7 +272,8 @@ Error init()
 
 #if !NO_PLAYER
 	PlayerNode* pnode;
-	scene.newSceneNode<PlayerNode>("player", pnode, Vec4(1.0, 3.0, 0.0, 0.0));
+	scene.newSceneNode<PlayerNode>("player", pnode,
+		Vec4(147.392776, -11.132728, 16.607138, 0.0));
 
 	pnode->addChild(cam);
 
@@ -375,16 +376,8 @@ Error mainLoopExtra(App& app, void*, Bool& quit)
 
 	if(in.getKey(KeyCode::L) == 1)
 	{
-		/*SceneNode& l = scene.findSceneNode("horse");
-
-		BodyComponent* bodyc = l.tryGetComponent<BodyComponent>();
-		if(bodyc)
-		{
-			Vec4 pos(randRange(-2, 10), 10, randRange(-6, 6), 0);
-
-			bodyc->setTransform(
-				Transform(pos, Mat3x4::getIdentity(), 1.0));
-		}*/
+		Vec3 origin = mover->getWorldTransform().getOrigin().xyz();
+		printf("%f %f %f\n", origin.x(), origin.y(), origin.z());
 	}
 
 	if(in.getKey(KeyCode::F1) == 1)
@@ -480,6 +473,7 @@ Error initSubsystems(int argc, char* argv[])
 	config.set("is.sm.bilinearEnabled", true);
 	config.set("is.groundLightEnabled", false);
 	config.set("is.sm.enabled", true);
+	config.set("is.sm.maxLights", 16);
 	config.set("is.sm.poissonEnabled", true);
 	config.set("is.sm.resolution", 1024);
 	config.set("pps.enabled", true);
@@ -511,6 +505,7 @@ Error initSubsystems(int argc, char* argv[])
 	config.set("fullscreenDesktopResolution", true);
 	config.set("debugContext", false);
 	config.set("dataPaths", "assets");
+	config.set("sceneFrameAllocatorSize", 1024 * 1024 * 10);
 
 	app = new App;
 	err = app->create(config, allocAligned, nullptr);

+ 1 - 1
thirdparty

@@ -1 +1 @@
-Subproject commit a0bc55f01d176f317feb48759ea7462b439e2d80
+Subproject commit 36e4d961fce003ba23af6e31b32b448b5728f0a0

+ 7 - 9
tools/scene/Common.h

@@ -3,17 +3,16 @@
 // Code licensed under the BSD License.
 // http://www.anki3d.org/LICENSE
 
-#ifndef ANKI_TOOLS_SCENE_MISC_H
-#define ANKI_TOOLS_SCENE_MISC_H
+#pragma once
 
 #include <string>
 
 /// Write to log. Don't use it directly.
 void log(
-	const char* file, 
-	int line, 
+	const char* file,
+	int line,
 	unsigned type,
-	const char* fmt, 
+	const char* fmt,
 	...);
 
 // Log and errors
@@ -22,18 +21,17 @@ void log(
 #define ERROR(...) \
 	do { \
 		log(__FILE__, __LINE__, 2, __VA_ARGS__); \
-		abort(); \
+		exit(0); \
 	} while(0)
 
 #define LOGW(...) log(__FILE__, __LINE__, 3, __VA_ARGS__)
 
 /// Replace all @a from substrings in @a str to @a to
 std::string replaceAllString(
-	const std::string& str, 
-	const std::string& from, 
+	const std::string& str,
+	const std::string& from,
 	const std::string& to);
 
 /// From a path return only the filename
 std::string getFilename(const std::string& path);
 
-#endif