فهرست منبع

Minor refactoring

Panagiotis Christopoulos Charitos 12 سال پیش
والد
کامیت
07b44234a7

+ 1 - 1
include/anki/Config.h.cmake

@@ -140,7 +140,7 @@ inline int stoi(const string& str)
 #define ANKI_RENDERER_TILES_X_COUNT 16
 #define ANKI_RENDERER_TILES_Y_COUNT 16
 
-#define ANKI_MAX_MULTIDRAW_PRIMITIVES 32
+#define ANKI_MAX_MULTIDRAW_PRIMITIVES 64
 #define ANKI_MAX_INSTANCES 16
 
 #define ANKI_SCENE_OPTIMAL_SCENE_NODES_COUNT 1024

+ 19 - 0
include/anki/core/Instrumentation.h

@@ -0,0 +1,19 @@
+#include "anki/util/StdTypes.h"
+
+namespace anki {
+
+enum InstrumentationCounter
+{
+	IC_RENDERER_MS_TIME,
+	IC_RENDERER_IS_TIME,
+	IC_RENDERER_PPS_TIME,
+	IC_RENDERER_DRAWCALLS_COUNT,
+	IC_SCENE_UPDATE_TIME,
+	IC_SWAP_BUFFERS_TIME,
+
+	IC_COUNT
+};
+
+#define ANKI_INSTR_UPDATE_COUNTER(counter, val)
+
+} // end namespace anki

+ 4 - 0
include/anki/core/NativeWindow.h

@@ -9,6 +9,7 @@
 namespace anki {
 
 struct NativeWindowImpl;
+struct ContextImpl;
 
 /// Window initializer
 struct NativeWindowInitializer
@@ -23,6 +24,7 @@ struct NativeWindowInitializer
 	U32 minorVersion = 0;
 	U32 majorVersion = 0;
 	Bool useGles = false; ///< Use OpenGL ES
+	Bool debugContext = false; ///< Enables KHR_debug
 
 	U32 width = 640;
 	U32 height = 768;
@@ -61,6 +63,8 @@ public:
 	void create(NativeWindowInitializer& initializer);
 	void destroy();
 	void swapBuffers();
+	ContextImpl* createSharedContext();
+	void contextMakeCurrent(ContextImpl& ctx);
 	/// @}
 
 private:

+ 14 - 15
include/anki/core/Timestamp.h

@@ -5,24 +5,23 @@
 
 namespace anki {
 
+/// Timestamp type
+typedef U32 Timestamp;
+
+/// Increase the current timestamp. Should be called in the main loop
+inline void increaseGlobTimestamp()
+{
+	extern Timestamp globTimestamp;
+	++globTimestamp;
+}
+
 /// Give the current timestamp. It actually gives the current frame. Used to
 /// indicate updates. It is actually returning the current frame
-class Timestamp
+inline Timestamp getGlobTimestamp()
 {
-public:
-	static void increaseTimestamp()
-	{
-		++timestamp;
-	}
-
-	static U32 getTimestamp()
-	{
-		return timestamp;
-	}
-
-private:
-	static U32 timestamp;
-};
+	extern Timestamp globTimestamp;
+	return globTimestamp;
+}
 
 } // end namespace anki
 

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

@@ -35,7 +35,7 @@ public:
 	void setExposure(const F32 x)
 	{
 		exposure = x;
-		parameterUpdateTimestamp = Timestamp::getTimestamp();
+		parameterUpdateTimestamp = getGlobTimestamp();
 	}
 
 	U32 getBlurringIterationsCount() const
@@ -66,9 +66,9 @@ private:
 	Texture hblurFai; ///< pass0Fai with the horizontal blur FAI
 	Texture vblurFai; ///< The final FAI
 	/// When a parameter changed by the setters
-	U32 parameterUpdateTimestamp = Timestamp::getTimestamp();
+	Timestamp parameterUpdateTimestamp = getGlobTimestamp();
 	/// When the commonUbo got updated
-	U32 commonUboUpdateTimestamp = Timestamp::getTimestamp();
+	Timestamp commonUboUpdateTimestamp = getGlobTimestamp();
 	Ubo commonUbo;
 
 	void initFbo(Fbo& fbo, Texture& fai);

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

@@ -60,7 +60,7 @@ private:
 	Ubo commonUbo;
 
 	/// Track the updates of commonUbo
-	U32 commonUboUpdateTimestamp = Timestamp::getTimestamp();
+	Timestamp commonUboUpdateTimestamp = getGlobTimestamp();
 
 	/// Contains all the lights
 	Ubo lightsUbo;

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

@@ -217,7 +217,7 @@ public:
 	{
 		return limitsOfNearPlane2;
 	}
-	U32 getPlanesUpdateTimestamp() const
+	Timestamp getPlanesUpdateTimestamp() const
 	{
 		return planesUpdateTimestamp;
 	}
@@ -307,7 +307,7 @@ protected:
 	/// @name Optimization vars
 	/// Used in other stages
 	/// @{
-	U32 planesUpdateTimestamp = Timestamp::getTimestamp();
+	Timestamp planesUpdateTimestamp = getGlobTimestamp();
 
 	/// Used to to calculate the frag pos in view space inside a few shader
 	/// programs

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

@@ -51,7 +51,7 @@ private:
 	ShaderProgramResourcePointer vblurSProg;
 	U32 bWidth, bHeight; ///< Blur passes size
 	U32 mpWidth, mpHeight; ///< Main pass size
-	U32 commonUboUpdateTimestamp = Timestamp::getTimestamp();
+	Timestamp commonUboUpdateTimestamp = getGlobTimestamp();
 	Ubo commonUbo;
 
 	static void createFbo(Fbo& fbo, Texture& fai, F32 width, F32 height);

+ 1 - 1
include/anki/renderer/Tiler.h

@@ -54,7 +54,7 @@ private:
 	Plane* farPlanesW = nullptr;
 
 	/// The timestamp of the 4 planes update
-	U32 planes4UpdateTimestamp = Timestamp::getTimestamp();
+	Timestamp planes4UpdateTimestamp = getGlobTimestamp();
 
 	/// A texture of TILES_X_COUNT*TILES_Y_COUNT size and format XXX. Used to
 	/// calculate the near and far planes of the tiles

+ 3 - 3
include/anki/scene/Frustumable.h

@@ -38,7 +38,7 @@ public:
 		return *frustum;
 	}
 
-	U32 getFrustumableTimestamp() const
+	Timestamp getFrustumableTimestamp() const
 	{
 		return timestamp;
 	}
@@ -82,7 +82,7 @@ public:
 
 	void frustumableMarkUpdated()
 	{
-		timestamp = Timestamp::getTimestamp();
+		timestamp = getGlobTimestamp();
 	}
 
 	/// Is a spatial inside the frustum?
@@ -109,7 +109,7 @@ protected:
 	Mat4 viewProjectionMat = Mat4::getIdentity();
 
 private:
-	U32 timestamp = Timestamp::getTimestamp();
+	Timestamp timestamp = getGlobTimestamp();
 
 	/// Visibility stuff. It's per frame so the pointer is invalid on the next 
 	/// frame and before any visibility tests are run

+ 5 - 0
include/anki/scene/ModelNode.h

@@ -14,6 +14,11 @@ namespace anki {
 /// @addtogroup Scene
 /// @{
 
+/// XXX
+class ModelPatchNodeInstance: public Spatial, public Movable
+{
+};
+
 /// A fragment of the ModelNode
 class ModelPatchNode: public SceneNode, public Movable, public Renderable,
 	public Spatial

+ 3 - 3
include/anki/scene/Movable.h

@@ -81,7 +81,7 @@ public:
 		return prevWTrf;
 	}
 
-	U32 getMovableTimestamp() const
+	Timestamp getMovableTimestamp() const
 	{
 		return timestamp;
 	}
@@ -153,7 +153,7 @@ protected:
 	Transform prevWTrf = Transform::getIdentity();
 
 	/// The frame where it was last moved
-	U32 timestamp = Timestamp::getTimestamp();
+	Timestamp timestamp = getGlobTimestamp();
 
 	/// Called for every frame. It updates the @a wTrf if @a shouldUpdateWTrf
 	/// is true. Then it moves to the children.
@@ -161,7 +161,7 @@ protected:
 
 	void movableMarkForUpdate()
 	{
-		timestamp = Timestamp::getTimestamp();
+		timestamp = getGlobTimestamp();
 		enableBits(MF_TRANSFORM_DIRTY);
 	}
 };

+ 4 - 4
include/anki/scene/SceneGraph.h

@@ -68,7 +68,7 @@ public:
 	void setAmbientColor(const Vec3& x)
 	{
 		ambientCol = x;
-		ambiendColorUpdateTimestamp = Timestamp::getTimestamp();
+		ambiendColorUpdateTimestamp = getGlobTimestamp();
 	}
 	U32 getAmbientColorUpdateTimestamp() const
 	{
@@ -87,7 +87,7 @@ public:
 	void setActiveCamera(Camera* cam)
 	{
 		mainCam = cam;
-		activeCameraChangeTimestamp = Timestamp::getTimestamp();
+		activeCameraChangeTimestamp = getGlobTimestamp();
 	}
 	U32 getActiveCameraChangeTimestamp() const
 	{
@@ -158,9 +158,9 @@ private:
 	Types<SceneNode>::NameToItemMap nameToNode;
 
 	Vec3 ambientCol = Vec3(1.0); ///< The global ambient color
-	U32 ambiendColorUpdateTimestamp = Timestamp::getTimestamp();
+	Timestamp ambiendColorUpdateTimestamp = getGlobTimestamp();
 	Camera* mainCam = nullptr;
-	U32 activeCameraChangeTimestamp = Timestamp::getTimestamp();
+	Timestamp activeCameraChangeTimestamp = getGlobTimestamp();
 
 	PhysWorld physics;
 

+ 3 - 3
include/anki/scene/Spatial.h

@@ -79,7 +79,7 @@ public:
 		}
 	}
 
-	U32 getSpatialTimestamp() const
+	Timestamp getSpatialTimestamp() const
 	{
 		return timestamp;
 	}
@@ -126,7 +126,7 @@ public:
 	/// updated
 	void spatialMarkForUpdate()
 	{
-		timestamp = Timestamp::getTimestamp();
+		timestamp = getGlobTimestamp();
 
 		for(Spatial* subsp : spatialProtected.subSpatials)
 		{
@@ -171,7 +171,7 @@ private:
 	OctreeNode* octreeNode = nullptr; ///< What octree node includes this
 	Aabb aabb; ///< A faster shape
 	Vec3 origin; ///< Cached value
-	U32 timestamp = Timestamp::getTimestamp();
+	Timestamp timestamp = getGlobTimestamp();
 };
 /// @}
 

+ 1 - 1
src/core/Timestamp.cpp

@@ -3,6 +3,6 @@
 namespace anki {
 
 // WARNING: If you change that prepare for allot of pain
-U32 Timestamp::timestamp = 1;
+Timestamp globTimestamp = 1;
 
 } // end namespace anki

+ 3 - 3
src/renderer/Hdr.cpp

@@ -72,8 +72,8 @@ void Hdr::initInternal(const Renderer::Initializer& initializer)
 		SHADER_FILENAME, pps.c_str()).c_str());
 
 	// Set timestamps
-	parameterUpdateTimestamp = Timestamp::getTimestamp();
-	commonUboUpdateTimestamp = Timestamp::getTimestamp();
+	parameterUpdateTimestamp = getGlobTimestamp();
+	commonUboUpdateTimestamp = getGlobTimestamp();
 }
 
 //==============================================================================
@@ -115,7 +115,7 @@ void Hdr::run()
 	{
 		Vec4 block(exposure, 0.0, 0.0, 0.0);
 		commonUbo.write(&block);
-		commonUboUpdateTimestamp = Timestamp::getTimestamp();
+		commonUboUpdateTimestamp = getGlobTimestamp();
 	}
 	commonUbo.setBinding(0);
 	toneSProg->findUniformVariable("fai").set(r->getIs().getFai());

+ 1 - 1
src/renderer/Is.cpp

@@ -834,7 +834,7 @@ void Is::run()
 
 		commonUbo.write(&blk);
 
-		commonUboUpdateTimestamp = Timestamp::getTimestamp();
+		commonUboUpdateTimestamp = getGlobTimestamp();
 	}
 
 	// Do the light pass including the shadow passes

+ 1 - 1
src/renderer/Renderer.cpp

@@ -77,7 +77,7 @@ void Renderer::render(SceneGraph& scene_)
 		calcLimitsOfNearPlane(pcam, limitsOfNearPlane);
 		limitsOfNearPlane2 = limitsOfNearPlane * 2.0;
 
-		planesUpdateTimestamp = Timestamp::getTimestamp();
+		planesUpdateTimestamp = getGlobTimestamp();
 	}
 
 	viewProjectionMat = cam.getViewProjectionMatrix();

+ 1 - 1
src/renderer/Sm.cpp

@@ -192,7 +192,7 @@ Sm::Shadowmap* Sm::doLight(Light& light)
 		return &sm;
 	}
 
-	sm.timestamp = Timestamp::getTimestamp();
+	sm.timestamp = getGlobTimestamp();
 	light.setShadowMapIndex(&sm - &sms[0]);
 
 	//

+ 1 - 1
src/renderer/Ssao.cpp

@@ -159,7 +159,7 @@ void Ssao::run()
 			r->getLimitsOfNearPlane2());
 
 		commonUbo.write(&blk);
-		commonUboUpdateTimestamp = Timestamp::getTimestamp();
+		commonUboUpdateTimestamp = getGlobTimestamp();
 	}
 
 	// msDepthFai

+ 1 - 1
src/renderer/Tiler.cpp

@@ -320,7 +320,7 @@ void Tiler::updateTiles(Camera& cam)
 
 	if(frustumChanged)
 	{
-		planes4UpdateTimestamp = Timestamp::getTimestamp();
+		planes4UpdateTimestamp = getGlobTimestamp();
 	}
 
 	threadPool.waitForAllJobsToFinish();

+ 2 - 2
src/scene/SceneGraph.cpp

@@ -39,13 +39,13 @@ struct UpdateMovablesJob: ThreadJob
 static void updateSceneNode(SceneNode& sn, F32 prevUpdateTime,
 	F32 crntTime, SectorGroup& sectorGroup)
 {
-	sn.frameUpdate(prevUpdateTime, crntTime, Timestamp::getTimestamp());
+	sn.frameUpdate(prevUpdateTime, crntTime, getGlobTimestamp());
 
 	// Do some spatial stuff
 	Spatial* sp = sn.getSpatial();
 	if(sp)
 	{
-		if(sp->getSpatialTimestamp() >= Timestamp::getTimestamp())
+		if(sp->getSpatialTimestamp() >= getGlobTimestamp())
 		{
 			sp->update();
 			//sectorGroup.placeSceneNode(&sn);

+ 1 - 1
testapp/Main.cpp

@@ -481,7 +481,7 @@ void mainLoop()
 			break;
 		}
 #endif
-		Timestamp::increaseTimestamp();
+		increaseGlobTimestamp();
 	}
 
 #if 0