Prechádzať zdrojové kódy

Removing exceptions

Panagiotis Christopoulos Charitos 11 rokov pred
rodič
commit
2d0d229ada

+ 6 - 6
include/anki/gl/GlProgramPipelineHandle.h

@@ -26,21 +26,21 @@ public:
 
 	GlProgramPipelineHandle();
 
+	~GlProgramPipelineHandle();
+
 	/// Create a pipeline
-	explicit GlProgramPipelineHandle(
+	ANKI_USE_RESULT Error create(
 		GlCommandBufferHandle& commands,
 		const GlProgramHandle* progsBegin, const GlProgramHandle* progsEnd)
 	{
-		commonConstructor(commands, progsBegin, progsEnd);
+		return commonConstructor(commands, progsBegin, progsEnd);
 	}
 
 	/// Create using initializer list
-	explicit GlProgramPipelineHandle(
+	ANKI_USE_RESULT Error create(
 		GlCommandBufferHandle& commands,
 		std::initializer_list<GlProgramHandle> progs);
 
-	~GlProgramPipelineHandle();
-
 	/// Bind it to the state
 	void bind(GlCommandBufferHandle& commands);
 
@@ -48,7 +48,7 @@ public:
 	GlProgramHandle getAttachedProgram(GLenum type) const;
 
 public:
-	void commonConstructor(GlCommandBufferHandle& commands,
+	ANKI_USE_RESULT Error commonConstructor(GlCommandBufferHandle& commands,
 		const GlProgramHandle* progsBegin, const GlProgramHandle* progsEnd);
 };
 

+ 2 - 2
include/anki/gl/GlSyncHandles.h

@@ -25,10 +25,10 @@ public:
 
 	GlClientSyncHandle();
 
-	GlClientSyncHandle(GlCommandBufferHandle& commands);
-
 	~GlClientSyncHandle();
 
+	ANKI_USE_RESULT Error create(GlCommandBufferHandle& commands);
+
 	/// Fire a command that adds a waits for the client. The client should call 
 	/// wait some time after this call or the server will keep waiting forever
 	void sync(GlCommandBufferHandle& commands);

+ 6 - 11
include/anki/gl/GlTextureHandle.h

@@ -37,12 +37,11 @@ public:
 	/// Create husk
 	GlTextureHandle();
 
-	/// Create the texture
-	explicit GlTextureHandle(GlCommandBufferHandle& commands, 
-		const Initializer& init);
-
 	~GlTextureHandle();
 
+	/// Create the texture
+	Error create(GlCommandBufferHandle& commands, const Initializer& init);
+
 	/// Bind to a unit
 	void bind(GlCommandBufferHandle& commands, U32 unit);
 
@@ -74,17 +73,13 @@ public:
 
 	using Filter = GlTextureFilter;
 
-	/// @name Constructors/Destructor
-	/// @{
-
 	/// Create husk
 	GlSamplerHandle();
 
-	/// Create the sampler
-	explicit GlSamplerHandle(GlCommandBufferHandle& commands);
-
 	~GlSamplerHandle();
-	/// @}
+
+	/// Create the sampler
+	ANKI_USE_RESULT Error create(GlCommandBufferHandle& commands);
 
 	/// Bind to a unit
 	void bind(GlCommandBufferHandle& commands, U32 unit);

+ 16 - 10
src/gl/GlProgramPipelineHandle.cpp

@@ -14,7 +14,11 @@ GlProgramPipelineHandle::GlProgramPipelineHandle()
 {}
 
 //==============================================================================
-GlProgramPipelineHandle::GlProgramPipelineHandle(
+GlProgramPipelineHandle::~GlProgramPipelineHandle()
+{}
+
+//==============================================================================
+Error GlProgramPipelineHandle::create(
 	GlCommandBufferHandle& commands,
 	std::initializer_list<GlProgramHandle> iprogs)
 {
@@ -26,15 +30,11 @@ GlProgramPipelineHandle::GlProgramPipelineHandle(
 		progs[count++] = prog;
 	}
 
-	commonConstructor(commands, &progs[0], &progs[0] + count);
+	return commonConstructor(commands, &progs[0], &progs[0] + count);
 }
 
 //==============================================================================
-GlProgramPipelineHandle::~GlProgramPipelineHandle()
-{}
-
-//==============================================================================
-void GlProgramPipelineHandle::commonConstructor(
+Error GlProgramPipelineHandle::commonConstructor(
 	GlCommandBufferHandle& commands,
 	const GlProgramHandle* progsBegin, const GlProgramHandle* progsEnd)
 {
@@ -74,13 +74,19 @@ void GlProgramPipelineHandle::commonConstructor(
 	using Deleter = 
 		GlHandleDeferredDeleter<GlProgramPipeline, Alloc, DeleteCommand>;
 
-	*static_cast<Base::Base*>(this) = Base::Base(
+	Error err = _createAdvanced(
 		&commands._get().getQueue().getDevice(),
 		commands._get().getGlobalAllocator(), 
 		Deleter());
-	_setState(GlHandleState::TO_BE_CREATED);
 
-	commands._pushBackNewCommand<Command>(*this, progsBegin, progsEnd);
+	if(!err)
+	{
+		_setState(GlHandleState::TO_BE_CREATED);
+
+		commands._pushBackNewCommand<Command>(*this, progsBegin, progsEnd);
+	}
+
+	return err;
 }
 
 //==============================================================================

+ 3 - 3
src/gl/GlQueue.cpp

@@ -93,7 +93,7 @@ void GlQueue::start(
 	ANKI_ASSERT(swapBuffersCallback != nullptr);
 	m_swapBuffersCallback = swapBuffersCallback;
 	m_swapBuffersCbData = swapBuffersCbData;
-	m_swapBuffersCommands = GlCommandBufferHandle(m_device);
+	m_swapBuffersCommands.create(m_device);
 	m_swapBuffersCommands.pushBackUserCommand(swapBuffersInternal, this);
 
 #if !ANKI_QUEUE_DISABLE_ASYNC
@@ -101,8 +101,8 @@ void GlQueue::start(
 	m_thread.start(this, threadCallback);
 
 	// Create sync command buffer
-	m_syncCommands = GlCommandBufferHandle(m_device);
-	m_sync = GlClientSyncHandle(m_syncCommands);
+	m_syncCommands.create(m_device);
+	m_sync.create(m_syncCommands);
 	m_sync.sync(m_syncCommands);
 #else
 	prepare();

+ 6 - 6
src/gl/GlSyncHandles.cpp

@@ -36,21 +36,21 @@ GlClientSyncHandle::GlClientSyncHandle()
 {}
 
 //==============================================================================
-GlClientSyncHandle::GlClientSyncHandle(GlCommandBufferHandle& commands)
+GlClientSyncHandle::~GlClientSyncHandle()
+{}
+
+//==============================================================================
+Error GlClientSyncHandle::create(GlCommandBufferHandle& commands)
 {
 	auto alloc = commands._getGlobalAllocator();
 
 	using Deleter = 
 		GlHandleDefaultDeleter<GlClientSync, GlAllocator<U8>>;
 
-	*static_cast<Base*>(this) = Base(
+	return _createAdvanced(
 		&commands._getQueue().getDevice(), alloc, Deleter());
 }
 
-//==============================================================================
-GlClientSyncHandle::~GlClientSyncHandle()
-{}
-
 //==============================================================================
 void GlClientSyncHandle::sync(GlCommandBufferHandle& commands)
 {

+ 28 - 17
src/gl/GlTextureHandle.cpp

@@ -19,7 +19,11 @@ GlTextureHandle::GlTextureHandle()
 {}
 
 //==============================================================================
-GlTextureHandle::GlTextureHandle(
+GlTextureHandle::~GlTextureHandle()
+{}
+
+//==============================================================================
+Error GlTextureHandle::create(
 	GlCommandBufferHandle& commands, const Initializer& init)
 {
 	class Command: public GlCommand
@@ -100,19 +104,21 @@ GlTextureHandle::GlTextureHandle(
 
 	using Deleter = GlHandleDeferredDeleter<GlTexture, Alloc, DeleteCommand>;
 
-	*static_cast<Base::Base*>(this) = Base::Base(
+	Error err = _createAdvanced(
 		&commands._getQueue().getDevice(),
 		commands._getQueue().getDevice()._getAllocator(), 
 		Deleter());
-	_setState(GlHandleState::TO_BE_CREATED);
 
-	// Fire the command
-	commands._pushBackNewCommand<Command>(*this, init);
-}
+	if(!err)
+	{
+		_setState(GlHandleState::TO_BE_CREATED);
 
-//==============================================================================
-GlTextureHandle::~GlTextureHandle()
-{}
+		// Fire the command
+		commands._pushBackNewCommand<Command>(*this, init);
+	}
+
+	return err;
+}
 
 //==============================================================================
 void GlTextureHandle::bind(GlCommandBufferHandle& commands, U32 unit)
@@ -243,7 +249,11 @@ GlSamplerHandle::GlSamplerHandle()
 {}
 
 //==============================================================================
-GlSamplerHandle::GlSamplerHandle(GlCommandBufferHandle& commands)
+GlSamplerHandle::~GlSamplerHandle()
+{}
+
+//==============================================================================
+Error GlSamplerHandle::create(GlCommandBufferHandle& commands)
 {
 	class Command: public GlCommand
 	{
@@ -274,18 +284,19 @@ GlSamplerHandle::GlSamplerHandle(GlCommandBufferHandle& commands)
 
 	using Deleter = GlHandleDeferredDeleter<GlSampler, Alloc, DeleteCommand>;
 
-	*static_cast<Base::Base*>(this) = Base::Base(
+	Error err = _createAdvanced(
 		&commands._getQueue().getDevice(),
 		commands._getQueue().getDevice()._getAllocator(), 
 		Deleter());
-	_setState(GlHandleState::TO_BE_CREATED);
 
-	commands._pushBackNewCommand<Command>(*this);
-}
+	if(!err)
+	{
+		_setState(GlHandleState::TO_BE_CREATED);
+		commands._pushBackNewCommand<Command>(*this);
+	}
 
-//==============================================================================
-GlSamplerHandle::~GlSamplerHandle()
-{}
+	return err;
+}
 
 //==============================================================================
 void GlSamplerHandle::bind(GlCommandBufferHandle& commands, U32 unit)