Browse Source

GL refactoring

Panagiotis Christopoulos Charitos 10 years ago
parent
commit
35c73f5a1f

+ 41 - 77
include/anki/gr/Common.h

@@ -3,15 +3,14 @@
 // Code licensed under the BSD License.
 // http://www.anki3d.org/LICENSE
 
-#ifndef ANKI_GL_COMMON_H
-#define ANKI_GL_COMMON_H
+#ifndef ANKI_GR_COMMON_H
+#define ANKI_GR_COMMON_H
 
-#include "anki/Config.h"
+#include "anki/gr/Enums.h"
 #include "anki/util/Allocator.h"
 #include "anki/util/NonCopyable.h"
 #include "anki/util/Assert.h"
 #include "anki/util/Array.h"
-#include "anki/util/Enum.h"
 #include "anki/Math.h"
 
 #if ANKI_GL == ANKI_GL_DESKTOP
@@ -47,11 +46,8 @@ class SamplerImpl;
 class SamplerHandle;
 class OcclusionQueryImpl;
 class OcclusionQueryHandle;
-class ClientBufferImpl;
-class ClientBufferHandle;
 class CommandBufferImpl;
 class CommandBufferHandle;
-class RenderingThread;
 class GrManager;
 class GrManagerImpl;
 
@@ -88,6 +84,44 @@ private:
 
 	PtrSize m_chunkSize = 1024;
 };
+
+struct SurfaceData
+{
+	void* m_ptr = nullptr;
+	PtrSize m_size = 0;
+};
+
+/// Texture initializer.
+struct TextureInitializer
+{
+	U32 m_width = 0;
+	U32 m_height = 0;
+	U32 m_depth = 0; ///< Relevant only for 3D and 2DArray textures
+	GLenum m_target = GL_TEXTURE_2D;
+	GLenum m_internalFormat = GL_NONE;
+	U32 m_mipmapsCount = 0;
+	TextureFilter m_filterType = TextureFilter::NEAREST;
+	Bool8 m_repeat = false;
+	I32 m_anisotropyLevel = 0;
+	U32 m_samples = 1;
+
+	/// [level][slice]
+	SArray<SArray<SurfaceData>> m_data;
+};
+
+struct Attachment
+{
+	TextureHandle* m_texture = nullptr;
+	GLenum m_point;
+	U32 m_layer = 0;
+	U32 m_mipmap = 0;
+};
+
+/// Framebuffer initializer.
+struct FramebufferInitializer
+{
+	SArray<Attachment> m_attachments;
+};
 /// @}
 
 /// @addtogroup opengl_containers
@@ -108,50 +142,6 @@ enum class GlAttachmentStoreOperation: U8
 	DONT_CARE
 };
 
-/// Texture filtering method
-enum class GlTextureFilter: U8
-{
-	NEAREST,
-	LINEAR,
-	TRILINEAR
-};
-
-/// Shader type
-enum class ShaderType: U8
-{
-	VERTEX,
-	TESSELLATION_CONTROL,
-	TESSELLATION_EVALUATION,
-	GEOMETRY,
-	FRAGMENT,
-	COMPUTE,
-	COUNT
-};
-ANKI_ENUM_ALLOW_NUMERIC_OPERATIONS(ShaderType, inline)
-
-/// Shader variable type.
-enum class ShaderVariableDataType: U8
-{
-	NONE,
-	FLOAT,
-	VEC2,
-	VEC3,
-	VEC4,
-	MAT3,
-	MAT4,
-	SAMPLER_2D,
-	SAMPLER_3D,
-	SAMPLER_2D_ARRAY,
-	SAMPLER_CUBE,
-
-	NUMERICS_FIRST = FLOAT,
-	NUMERICS_LAST = MAT4,
-
-	SAMPLERS_FIRST = SAMPLER_2D,
-	SAMPLERS_LAST = SAMPLER_CUBE
-};
-ANKI_ENUM_ALLOW_NUMERIC_OPERATIONS(ShaderVariableDataType, inline)
-
 /// Using an AnKi typename get the ShaderVariableDataType. Used for debugging.
 template<typename T>
 ShaderVariableDataType getShaderVariableTypeFromTypename();
@@ -172,22 +162,6 @@ ANKI_SPECIALIZE_SHADER_VAR_TYPE_GET(Mat4, MAT4)
 
 #undef ANKI_SPECIALIZE_SHADER_VAR_TYPE_GET
 
-/// Split the initializer for re-using parts of it
-class GlTextureInitializerBase
-{
-public:
-	U32 m_width = 0;
-	U32 m_height = 0;
-	U32 m_depth = 0; ///< Relevant only for 3D and 2DArray textures
-	GLenum m_target = GL_TEXTURE_2D;
-	GLenum m_internalFormat = GL_NONE;
-	U32 m_mipmapsCount = 0;
-	GlTextureFilter m_filterType = GlTextureFilter::NEAREST;
-	Bool8 m_repeat = false;
-	I32 m_anisotropyLevel = 0;
-	U32 m_samples = 1;
-};
-
 /// Shader block information.
 struct ShaderVariableBlockInfo
 {
@@ -274,16 +248,6 @@ ShaderType computeShaderTypeIndex(const GLenum glType);
 
 /// A function that returns a GLenum from an index
 GLenum computeGlShaderType(const ShaderType idx, GLbitfield* bit = nullptr);
-
-/// Occlusion query result bit.
-enum class GlOcclusionQueryResultBit: U8
-{
-	NOT_AVAILABLE = 1 << 0,
-	VISIBLE = 1 << 1,
-	NOT_VISIBLE = 1 << 2 
-};
-ANKI_ENUM_ALLOW_NUMERIC_OPERATIONS(GlOcclusionQueryResultBit, inline)
-
 /// @}
 
 } // end namespace anki

+ 23 - 3
include/anki/gr/Enums.h

@@ -3,14 +3,15 @@
 // Code licensed under the BSD License.
 // http://www.anki3d.org/LICENSE
 
-#ifndef ANKI_GL_ENUMS_H
-#define ANKI_GL_ENUMS_H
+#ifndef ANKI_GR_ENUMS_H
+#define ANKI_GR_ENUMS_H
 
 #include "anki/util/StdTypes.h"
+#include "anki/util/Enum.h"
 
 namespace anki {
 
-/// @addtogroup opengl_other
+/// @addtogroup graphics
 /// @{
 
 // Some constants
@@ -153,6 +154,7 @@ enum class ShaderType: U8
 	FRAGMENT,
 	COMPUTE
 };
+ANKI_ENUM_ALLOW_NUMERIC_OPERATIONS(ShaderType, inline)
 
 enum class ShaderVariableDataType: U8
 {
@@ -173,6 +175,7 @@ enum class ShaderVariableDataType: U8
 	SAMPLERS_FIRST = SAMPLER_2D,
 	SAMPLERS_LAST = SAMPLER_CUBE
 };
+ANKI_ENUM_ALLOW_NUMERIC_OPERATIONS(ShaderVariableDataType, inline)
 
 /// Format for images and vertex attributes.
 struct PixelFormat
@@ -181,6 +184,23 @@ struct PixelFormat
 	TransformFormat m_transform = TransformFormat::UNORM;
 	Bool8 m_srgb = false;
 };
+
+/// Occlusion query result bit.
+enum class OcclusionQueryResultBit: U8
+{
+	NOT_AVAILABLE = 1 << 0,
+	VISIBLE = 1 << 1,
+	NOT_VISIBLE = 1 << 2 
+};
+ANKI_ENUM_ALLOW_NUMERIC_OPERATIONS(OcclusionQueryResultBit, inline)
+
+/// Occlusion query result.
+enum class OcclusionQueryResult: U8
+{
+	NOT_AVAILABLE,
+	VISIBLE,
+	NOT_VISIBLE
+};
 /// @}
 
 } // end namespace anki

+ 3 - 2
include/anki/gr/GrHandle.h

@@ -7,6 +7,7 @@
 #define ANKI_GR_GR_HANDLE_H
 
 #include "anki/gr/GrObject.h"
+#include "anki/gr/GrManager.h"
 
 namespace anki {
 
@@ -157,14 +158,14 @@ public:
 	T& get()
 	{
 		ANKI_ASSERT(m_cb != nullptr && m_cb->m_ptr != nullptr);
-		return *m_cb->m_ptr;
+		return *static_cast<T*>(m_cb->m_ptr);
 	}
 
 	/// Get the immutable pointer
 	const T& get() const
 	{
 		ANKI_ASSERT(m_cb != nullptr && m_cb->m_ptr != nullptr);
-		return *m_cb->m_ptr;
+		return *static_cast<T*>(m_cb->m_ptr);
 	}
 
 private:

+ 8 - 9
include/anki/gr/ShaderHandle.h

@@ -3,21 +3,21 @@
 // Code licensed under the BSD License.
 // http://www.anki3d.org/LICENSE
 
-#ifndef ANKI_GL_GL_SHADER_HANDLE_H
-#define ANKI_GL_GL_SHADER_HANDLE_H
+#ifndef ANKI_GR_SHADER_HANDLE_H
+#define ANKI_GR_SHADER_HANDLE_H
 
-#include "anki/gr/GlContainerHandle.h"
+#include "anki/gr/GrHandle.h"
 
 namespace anki {
 
-/// @addtogroup opengl_containers
+/// @addtogroup graphics
 /// @{
 
-/// Program handle
-class ShaderHandle: public GlContainerHandle<ShaderImpl>
+/// Shader handle.
+class ShaderHandle: public GrHandle<ShaderImpl>
 {
 public:
-	using Base = GlContainerHandle<ShaderImpl>;
+	using Base = GrHandle<ShaderImpl>;
 
 	ShaderHandle();
 
@@ -25,7 +25,7 @@ public:
 
 	/// Create shader program.
 	ANKI_USE_RESULT Error create(CommandBufferHandle& commands, 
-		GLenum shaderType, const ClientBufferHandle& source);
+		GLenum shaderType, const void* source);
 
 	/// @name Accessors
 	/// They will sync client with server.
@@ -33,7 +33,6 @@ public:
 	GLenum getType() const;
 	/// @}
 };
-
 /// @}
 
 } // end namespace anki

+ 11 - 21
include/anki/gr/TextureHandle.h

@@ -3,11 +3,10 @@
 // Code licensed under the BSD License.
 // http://www.anki3d.org/LICENSE
 
-#ifndef ANKI_GL_GL_TEXTURE_HANDLE_H
-#define ANKI_GL_GL_TEXTURE_HANDLE_H
+#ifndef ANKI_GR_TEXTURE_HANDLE_H
+#define ANKI_GR_TEXTURE_HANDLE_H
 
-#include "anki/gr/GlContainerHandle.h"
-#include "anki/gr/ClientBufferHandle.h"
+#include "anki/gr/GrHandle.h"
 
 namespace anki {
 
@@ -15,20 +14,12 @@ namespace anki {
 /// @{
 
 /// Texture handle
-class TextureHandle: public GlContainerHandle<TextureImpl>
+class TextureHandle: public GrHandle<TextureImpl>
 {
 public:
-	using Base = GlContainerHandle<TextureImpl>;
-
-	using Filter = GlTextureFilter;
-
-	/// Texture handle initializer
-	class Initializer: public GlTextureInitializerBase
-	{
-	public:
-		Array2d<ClientBufferHandle, 
-			ANKI_GL_MAX_MIPMAPS, ANKI_GL_MAX_TEXTURE_LAYERS> m_data;
-	};
+	using Base = GrHandle<TextureImpl>;
+	using Filter = TextureFilter;
+	using Initializer = TextureInitializer;
 
 	/// Create husk
 	TextureHandle();
@@ -53,14 +44,13 @@ public:
 };
 
 /// Sampler handle
-class SamplerHandle: public GlContainerHandle<SamplerImpl>
+class SamplerHandle: public GrHandle<SamplerImpl>
 {
 public:
-	using Base = GlContainerHandle<SamplerImpl>;
+	using Base = GrHandle<SamplerImpl>;
+	using Filter = TextureFilter;
 
-	using Filter = GlTextureFilter;
-
-	/// Create husk
+	/// Create husk.
 	SamplerHandle();
 
 	~SamplerHandle();

+ 3 - 3
include/anki/gr/gl/DeferredDeleter.h

@@ -3,15 +3,15 @@
 // Code licensed under the BSD License.
 // http://www.anki3d.org/LICENSE
 
-#ifndef ANKI_GL_DEFERRED_DELETER_H
-#define ANKI_GL_DEFERRED_DELETER_H
+#ifndef ANKI_GR_GL_DEFERRED_DELETER_H
+#define ANKI_GR_GL_DEFERRED_DELETER_H
 
 #include "anki/gr/GlDevice.h"
 #include "anki/gr/CommandBufferHandle.h"
 
 namespace anki {
 
-/// @addtogroup opengl_private
+/// @addtogroup opengl
 /// @{
 
 /// Common deleter for objects that require deferred deletion. Some handles

+ 2 - 2
include/anki/gr/gl/Error.h

@@ -3,8 +3,8 @@
 // Code licensed under the BSD License.
 // http://www.anki3d.org/LICENSE
 
-#ifndef ANKI_GL_ERROR_H
-#define ANKI_GL_ERROR_H
+#ifndef ANKI_GR_GL_ERROR_H
+#define ANKI_GR_GL_ERROR_H
 
 #include "anki/gr/Common.h"
 

+ 7 - 25
include/anki/gr/gl/FramebufferImpl.h

@@ -11,36 +11,19 @@
 
 namespace anki {
 
-/// @addtogroup opengl_private
+/// @addtogroup opengl
 /// @{
 
-/// Framebuffer
+/// Framebuffer implementation.
 class FramebufferImpl: public GlObject
 {
 public:
 	using Base = GlObject;
+	using Initializer = FramebufferInitializer;
 
-	static const U32 MAX_COLOR_ATTACHMENTS = 4;
-
-	/// Used to set the attachments
-	class Attachment
-	{
-	public:
-		Attachment()
-		{}
-
-		Attachment(const TextureHandle& tex, GLenum point, U32 layer = 0)
-		:	m_tex(tex), 
-			m_point(point), 
-			m_layer(layer)
-		{}
-
-		TextureHandle m_tex;
-		GLenum m_point;
-		U32 m_layer;
-	};
-
-	FramebufferImpl() = default;
+	FramebufferImpl(GrManager* manager)
+	:	Base(manager)
+	{}
 
 	~FramebufferImpl()
 	{
@@ -49,8 +32,7 @@ public:
 
 	/// Set all the attachments. It will overwrite the previous state. If the
 	/// initalizer list is empty the it will bind the default framebuffer
-	ANKI_USE_RESULT Error create(
-		Attachment* attachmentsBegin, Attachment* attachmentsEnd);
+	ANKI_USE_RESULT Error create(Initializer& init);
 
 	/// Bind it to the state. Call it in rendering thread
 	/// @param invalidate If true invalidate the FB after binding it

+ 9 - 14
include/anki/gr/gl/OcclusionQueryImpl.h

@@ -3,14 +3,14 @@
 // Code licensed under the BSD License.
 // http://www.anki3d.org/LICENSE
 
-#ifndef ANKI_GR_GL_OCCLUSION_QUERY_H
-#define ANKI_GR_GL_OCCLUSION_QUERY_H
+#ifndef ANKI_GR_GL_OCCLUSION_QUERY_IMPL_H
+#define ANKI_GR_GL_OCCLUSION_QUERY_IMPL_H
 
 #include "anki/gr/gl/GlObject.h"
 
 namespace anki {
 
-/// @addtogroup opengl_private
+/// @addtogroup opengl
 /// @{
 
 /// Occlusion query.
@@ -18,13 +18,8 @@ class OcclusionQueryImpl: public GlObject
 {
 public:
 	using Base = GlObject;
-
-	enum class Result: U
-	{
-		NOT_AVAILABLE,
-		VISIBLE,
-		NOT_VISIBLE
-	};
+	using ResultBit = OcclusionQueryResultBit;
+	using Result = OcclusionQueryResult;
 
 	OcclusionQueryImpl() = default;
 
@@ -37,7 +32,7 @@ public:
 	/// @param condRenderingBit If the query is used in conditional rendering
 	///        the result will be checked against this mask. If the result
 	///        contains any of the bits then the dracall will not be skipped.
-	ANKI_USE_RESULT Error create(GlOcclusionQueryResultBit condRenderingBit);
+	ANKI_USE_RESULT Error create(ResultBit condRenderingBit);
 
 	/// Begin query.
 	void begin();
@@ -51,13 +46,13 @@ public:
 	/// Return true if the drawcall should be skipped.
 	Bool skipDrawcall() const
 	{
-		U resultBit = 1 << static_cast<U>(getResult());
-		U condBit = static_cast<U>(m_condRenderingBit);
+		U resultBit = 1 << U(getResult());
+		U condBit = U(m_condRenderingBit);
 		return !(resultBit & condBit);
 	}
 
 private:
-	GlOcclusionQueryResultBit m_condRenderingBit;
+	ResultBit m_condRenderingBit;
 	void destroy();
 };
 /// @}

+ 7 - 6
include/anki/gr/gl/PipelineImpl.h

@@ -3,15 +3,15 @@
 // Code licensed under the BSD License.
 // http://www.anki3d.org/LICENSE
 
-#ifndef ANKI_GL_GL_PIPELINE_H
-#define ANKI_GL_GL_PIPELINE_H
+#ifndef ANKI_GR_GL_PIPELINE_IMPL_H
+#define ANKI_GR_GL_PIPELINE_IMPL_H
 
 #include "anki/gr/gl/GlObject.h"
 #include "anki/gr/ShaderHandle.h"
 
 namespace anki {
 
-/// @addtogroup opengl_private
+/// @addtogroup opengl
 /// @{
 
 /// Program pipeline
@@ -20,7 +20,9 @@ class PipelineImpl: public GlObject
 public:
 	using Base = GlObject;
 
-	PipelineImpl() = default;
+	PipelineImpl(GrManager* manager)
+	:	Base(manager)
+	{}
 
 	~PipelineImpl()
 	{
@@ -28,8 +30,7 @@ public:
 	}
 
 	ANKI_USE_RESULT Error create(
-		const ShaderHandle* progsBegin, const ShaderHandle* progsEnd,
-		GlAllocator<U8> alloc);
+		const ShaderHandle* progsBegin, const ShaderHandle* progsEnd);
 
 	ShaderHandle getAttachedProgram(GLenum type) const;
 

+ 6 - 8
include/anki/gr/gl/ShaderImpl.h

@@ -10,7 +10,7 @@
 
 namespace anki {
 
-/// @addtogroup opengl_private
+/// @addtogroup opengl
 /// @{
 
 /// Shader program. It only contains a single shader and it can be combined 
@@ -23,7 +23,9 @@ class ShaderImpl: public GlObject
 public:
 	using Base = GlObject;
 
-	ShaderImpl() = default;
+	ShaderImpl(GrManager* manager)
+	:	Base(manager)
+	{}
 
 	~ShaderImpl()
 	{
@@ -33,12 +35,9 @@ public:
 	/// Create the shader.
 	/// @param shaderType The type of the shader in the program
 	/// @param source The shader's source
-	/// @param alloc The allocator to be used for internally
 	ANKI_USE_RESULT Error create(
 		GLenum shaderType, 
-		const CString& source, 
-		GlAllocator<U8>& alloc, 
-		const CString& cacheDir);
+		const CString& source);
 
 	GLenum getType() const
 	{
@@ -51,9 +50,8 @@ private:
 
 	void destroy();
 
-	ANKI_USE_RESULT Error handleError(GlAllocator<U8>& alloc, String& src);
+	ANKI_USE_RESULT Error handleError(String& src);
 };
-
 /// @}
 
 } // end namespace anki

+ 13 - 30
include/anki/gr/gl/TextureImpl.h

@@ -3,15 +3,15 @@
 // Code licensed under the BSD License.
 // http://www.anki3d.org/LICENSE
 
-#ifndef ANKI_GL_GL_TEXTURE_H
-#define ANKI_GL_GL_TEXTURE_H
+#ifndef ANKI_GR_GL_TEXTURE_IMPL_H
+#define ANKI_GR_GL_TEXTURE_IMPL_H
 
 #include "anki/gr/gl/GlObject.h"
 #include "anki/util/Array.h"
 
 namespace anki {
 
-/// @addtogroup opengl_private
+/// @addtogroup opengl
 /// @{
 
 /// Texture container
@@ -19,30 +19,12 @@ class TextureImpl: public GlObject
 {
 public:
 	using Base = GlObject;
+	using Filter = TextureFilter;
+	using Initializer = TextureInitializer;
 
-	using Filter = GlTextureFilter;
-
-	/// Texture handle initializer struct
-	class Initializer: public GlTextureInitializerBase
-	{
-	public:
-		class Data
-		{
-		public:
-			void* m_ptr;
-			PtrSize m_size;
-		};
-
-		/// Array of data in: [mip][layer]
-		Array2d<Data, ANKI_GL_MAX_MIPMAPS, ANKI_GL_MAX_TEXTURE_LAYERS> m_data;
-
-		Initializer()
-		{
-			memset(&m_data[0][0], 0, sizeof(m_data));
-		}
-	};
-
-	TextureImpl() = default;
+	TextureImpl(GrManager* manager)
+	:	Base(manager)
+	{}
 
 	~TextureImpl()
 	{
@@ -50,8 +32,7 @@ public:
 	}
 
 	/// Create a texture
-	ANKI_USE_RESULT Error create(
-		const Initializer& init, GlAllocator<U8>& alloc);
+	ANKI_USE_RESULT Error create(const Initializer& init);
 
 	GLenum getInternalFormat() const
 	{
@@ -132,9 +113,11 @@ class SamplerImpl: public GlObject
 {
 public:
 	using Base = GlObject;
-	using Filter = GlTextureFilter;
+	using Filter = TextureFilter;
 
-	SamplerImpl() = default;
+	SamplerImpl(GrManager* manager)
+	:	Base(manager)
+	{}
 
 	~SamplerImpl()
 	{

+ 102 - 0
src/gr/GrManager.cpp

@@ -0,0 +1,102 @@
+// Copyright (C) 2009-2015, Panagiotis Christopoulos Charitos.
+// All rights reserved.
+// Code licensed under the BSD License.
+// http://www.anki3d.org/LICENSE
+
+#include "anki/gr/GlDevice.h"
+#include "anki/core/Timestamp.h"
+#include <cstring>
+
+namespace anki {
+
+//==============================================================================
+Error GlDevice::create(
+	AllocAlignedCallback alloc, void* allocUserData,
+	const CString& cacheDir)
+{
+	m_alloc = HeapAllocator<U8>(alloc, allocUserData);
+
+	// Allocate cache dir
+	auto len = cacheDir.getLength();
+	m_cacheDir = reinterpret_cast<char*>(m_alloc.allocate(len + 1));
+	std::memcpy(m_cacheDir, &cacheDir[0], len + 1);
+
+	// Create queue
+	m_queue = m_alloc.newInstance<RenderingThread>(
+		this, alloc, allocUserData);
+
+#if ANKI_QUEUE_DISABLE_ASYNC
+	ANKI_LOGW("GL queue works in synchronous mode");
+#endif
+
+	return ErrorCode::NONE;
+}
+
+//==============================================================================
+void GlDevice::destroy()
+{
+	if(m_queue)
+	{
+		if(m_queueStarted)
+		{
+			m_queue->stop();
+		}
+
+		m_alloc.deleteInstance(m_queue);
+	}
+
+	if(m_cacheDir)
+	{
+		m_alloc.deallocate(m_cacheDir, std::strlen(m_cacheDir) + 1);
+	}
+}
+
+//==============================================================================
+Error GlDevice::startServer(
+	GlMakeCurrentCallback makeCurrentCb, void* makeCurrentCbData, void* ctx,
+	GlCallback swapBuffersCallback, void* swapBuffersCbData,
+	Bool registerDebugMessages)
+{
+	Error err = m_queue->start(makeCurrentCb, makeCurrentCbData, ctx, 
+		swapBuffersCallback, swapBuffersCbData, 
+		registerDebugMessages);
+
+	if(!err)
+	{
+		syncClientServer();
+
+		m_queueStarted = true;
+	}
+
+	return err;
+}
+
+//==============================================================================
+void GlDevice::syncClientServer()
+{
+	m_queue->syncClientServer();
+}
+
+//==============================================================================
+void GlDevice::swapBuffers()
+{
+	m_queue->swapBuffers();
+}
+
+//==============================================================================
+PtrSize GlDevice::getBufferOffsetAlignment(GLenum target) const
+{
+	const State& state = m_queue->getState();
+
+	if(target == GL_UNIFORM_BUFFER)
+	{
+		return state.m_uniBuffOffsetAlignment;
+	}
+	else
+	{
+		ANKI_ASSERT(target == GL_SHADER_STORAGE_BUFFER);
+		return state.m_ssBuffOffsetAlignment;
+	}
+}
+
+} // end namespace anki

+ 1 - 1
src/gr/gl/Error.cpp

@@ -3,7 +3,7 @@
 // Code licensed under the BSD License.
 // http://www.anki3d.org/LICENSE
 
-#include "anki/gr/GlError.h"
+#include "anki/gr/gl/Error.h"
 #include "anki/util/Logger.h"
 #include <cstring>
 

+ 9 - 9
src/gr/gl/FramebufferImpl.cpp

@@ -10,10 +10,9 @@
 namespace anki {
 
 //==============================================================================
-Error FramebufferImpl::create(
-	Attachment* attachmentsBegin, Attachment* attachmentsEnd)
+Error FramebufferImpl::create(Initializer& init)
 {
-	if(attachmentsBegin == nullptr || attachmentsEnd == nullptr)
+	if(init.m_attachments.getSize() == 0)
 	{
 		m_bindDefault = true;
 		return ErrorCode::NONE;
@@ -23,7 +22,8 @@ Error FramebufferImpl::create(
 
 	Array<U, MAX_COLOR_ATTACHMENTS + 1> layers;
 	GLenum depthStencilBindingPoint = GL_NONE;
-	Attachment* attachment = attachmentsBegin;
+	Attachment* attachment = init.m_attachments.getBegin();
+	Attachment* attachmentsEnd = init.m_attachments.getEnd();
 	do
 	{
 		if(attachment->m_point >= GL_COLOR_ATTACHMENT0 
@@ -33,14 +33,14 @@ Error FramebufferImpl::create(
 			// Color attachment
 
 			U32 i = attachment->m_point - GL_COLOR_ATTACHMENT0;
-			m_attachments[i] = attachment->m_tex;
+			m_attachments[i] = *attachment->m_texture;
 			layers[i] = attachment->m_layer;
 		}
 		else
 		{
 			// Depth & stencil
 
-			m_attachments[MAX_COLOR_ATTACHMENTS] = attachment->m_tex;
+			m_attachments[MAX_COLOR_ATTACHMENTS] = *attachment->m_texture;
 			layers[MAX_COLOR_ATTACHMENTS] = attachment->m_layer;
 			depthStencilBindingPoint = attachment->m_point;
 		}
@@ -85,7 +85,7 @@ Error FramebufferImpl::createFbo(
 			continue;
 		}
 		
-		const TextureImpl& tex = m_attachments[i]._get();
+		const TextureImpl& tex = m_attachments[i].get();
 		attachTextureInternal(GL_COLOR_ATTACHMENT0 + i, tex, layers[i]);
 	}
 
@@ -94,7 +94,7 @@ Error FramebufferImpl::createFbo(
 	{
 		ANKI_ASSERT(depthStencilBindingPoint != GL_NONE);
 
-		const TextureImpl& tex = m_attachments[MAX_COLOR_ATTACHMENTS]._get();
+		const TextureImpl& tex = m_attachments[MAX_COLOR_ATTACHMENTS].get();
 		attachTextureInternal(depthStencilBindingPoint, tex, 
 			layers[MAX_COLOR_ATTACHMENTS]);
 	}
@@ -174,7 +174,7 @@ void FramebufferImpl::bind(Bool invalidate)
 		// Invalidate
 		if(invalidate)
 		{
-			static const Array<GLenum, FramebufferImpl::MAX_COLOR_ATTACHMENTS + 1>
+			static const Array<GLenum, MAX_COLOR_ATTACHMENTS + 1>
 				ATTACHMENT_TOKENS = {{
 					GL_DEPTH_STENCIL_ATTACHMENT, GL_COLOR_ATTACHMENT0, 
 					GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, 

+ 1 - 1
src/gr/gl/OcclusionQueryImpl.cpp

@@ -8,7 +8,7 @@
 namespace anki {
 
 //==============================================================================
-Error OcclusionQueryImpl::create(GlOcclusionQueryResultBit condRenderingBit)
+Error OcclusionQueryImpl::create(ResultBit condRenderingBit)
 {
 	glGenQueries(1, &m_glName);
 	ANKI_ASSERT(m_glName != 0);

+ 4 - 4
src/gr/gl/PipelineImpl.cpp

@@ -11,8 +11,7 @@ namespace anki {
 
 //==============================================================================
 Error PipelineImpl::create(
-	const ShaderHandle* progsBegin, const ShaderHandle* progsEnd,
-	GlAllocator<U8> alloc)
+	const ShaderHandle* progsBegin, const ShaderHandle* progsEnd)
 {
 	ANKI_ASSERT(progsBegin != nullptr && progsEnd != nullptr);
 	ANKI_ASSERT(progsBegin != progsEnd);
@@ -38,7 +37,7 @@ Error PipelineImpl::create(
 				computeGlShaderType(static_cast<ShaderType>(i), &bit);
 			ANKI_ASSERT(prog.getType() == gltype && "Attached wrong shader");
 			(void)gltype;
-			glUseProgramStages(m_glName, bit, prog._get().getGlName());
+			glUseProgramStages(m_glName, bit, prog.get().getGlName());
 		}
 	}
 
@@ -55,6 +54,7 @@ Error PipelineImpl::create(
 
 		glGetProgramPipelineiv(m_glName, GL_INFO_LOG_LENGTH, &infoLen);
 
+		auto alloc = getAllocator();
 		err = infoLogTxt.create(alloc, infoLen + 1);
 
 		if(!err)
@@ -90,7 +90,7 @@ void PipelineImpl::attachProgramsInternal(
 	while(count-- != 0)
 	{
 		const ShaderHandle& prog = progs[count];
-		ShaderType type = computeShaderTypeIndex(prog._get().getType());
+		ShaderType type = computeShaderTypeIndex(prog.get().getType());
 		U idx = enumToType(type);
 
 		ANKI_ASSERT(!m_shaders[idx].isCreated() && "Attaching the same");

+ 7 - 4
src/gr/gl/ShaderImpl.cpp

@@ -4,6 +4,7 @@
 // http://www.anki3d.org/LICENSE
 
 #include "anki/gr/gl/ShaderImpl.h"
+#include "anki/gr/GrManager.h"
 #include "anki/util/StringList.h"
 #include "anki/util/Logger.h"
 
@@ -16,8 +17,7 @@
 namespace anki {
 
 //==============================================================================
-Error ShaderImpl::create(GLenum type, const CString& source, 
-	GlAllocator<U8>& alloc, const CString& cacheDir)
+Error ShaderImpl::create(GLenum type, const CString& source)
 {
 	ANKI_ASSERT(source);
 	ANKI_ASSERT(!isCreated());
@@ -36,6 +36,7 @@ Error ShaderImpl::create(GLenum type, const CString& source,
 		version = major * 100 + minor * 10;
 	}
 
+	auto alloc = getAllocator();
 	String fullSrc;
 	String::ScopeDestroyer fullSrcd(&fullSrc, alloc); 
 #if ANKI_GL == ANKI_GL_DESKTOP
@@ -88,6 +89,7 @@ Error ShaderImpl::create(GLenum type, const CString& source,
 		}
 
 		String fname;
+		CString cacheDir = getManager().getCacheDirectory();
 		err = fname.sprintf(alloc,
 			"%s/%05u.%s", &cacheDir[0], static_cast<U32>(m_glName), ext);
 
@@ -108,7 +110,7 @@ Error ShaderImpl::create(GLenum type, const CString& source,
 
 		if(status == GL_FALSE)
 		{
-			err = handleError(alloc, fullSrc);
+			err = handleError(fullSrc);
 
 			if(!err)
 			{
@@ -122,10 +124,11 @@ Error ShaderImpl::create(GLenum type, const CString& source,
 }
 
 //==============================================================================
-Error ShaderImpl::handleError(GlAllocator<U8>& alloc, String& src)
+Error ShaderImpl::handleError(String& src)
 {
 	Error err = ErrorCode::NONE;
 
+	auto alloc = getAllocator();
 	GLint compilerLogLen = 0;
 	GLint charsWritten = 0;
 	String compilerLog;

+ 5 - 4
src/gr/gl/TextureImpl.cpp

@@ -4,7 +4,7 @@
 // http://www.anki3d.org/LICENSE
 
 #include "anki/gr/gl/TextureImpl.h"
-#include "anki/gr/GlError.h"
+#include "anki/gr/gl/Error.h"
 #include "anki/util/Functions.h"
 #include "anki/util/DArray.h"
 
@@ -101,9 +101,10 @@ static void getTextureInformation(
 //==============================================================================
 
 //==============================================================================
-Error TextureImpl::create(const Initializer& init, 
-	GlAllocator<U8>& alloc)
+Error TextureImpl::create(const Initializer& init)
 {
+	GrAllocator<U8> alloc = getAllocator();
+
 	// Sanity checks
 	//
 	ANKI_ASSERT(!isCreated());
@@ -246,7 +247,7 @@ Error TextureImpl::create(const Initializer& init,
 					ANKI_ASSERT(m_depth > 0);
 
 					// Gather the data
-					DArrayAuto<U8, GlAllocator<U8>> data(alloc);
+					DArrayAuto<U8, GrAllocator<U8>> data(alloc);
 
 					// Check if there are data
 					if(init.m_data[level][0].m_ptr != nullptr)