Panagiotis Christopoulos Charitos 13 лет назад
Родитель
Сommit
700de13da9
4 измененных файлов с 19 добавлено и 42 удалено
  1. 6 11
      include/anki/gl/BufferObject.h
  2. 0 1
      include/anki/math/Mat4.h
  3. 10 27
      src/gl/BufferObject.cpp
  4. 3 3
      src/gl/Fbo.cpp

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

@@ -62,11 +62,7 @@ public:
 	void bind() const
 	{
 		ANKI_ASSERT(isCreated());
-		//if(lastBindedBo != this)
-		{
-			glBindBuffer(target, glId);
-			//lastBindedBo = this;
-		}
+		glBindBuffer(target, glId);
 	}
 
 	/// Unbind BO
@@ -74,7 +70,6 @@ public:
 	{
 		ANKI_ASSERT(isCreated());
 		glBindBuffer(target, 0);
-		//lastBindedBo = nullptr;
 	}
 
 	/// Creates a new BO with the given parameters and checks if everything
@@ -103,7 +98,10 @@ public:
 	/// given size and the BO size are not equal. It throws an exception if
 	/// the usage is GL_STATIC_DRAW
 	/// @param[in] buff The buffer to copy to BO
-	void write(void* buff);
+	void write(void* buff)
+	{
+		write(buff, 0, sizeInBytes);
+	}
 
 	/// The same as the other write but it maps only a subset of the data
 	/// @param[in] buff The buffer to copy to BO
@@ -138,9 +136,6 @@ public:
 	}
 
 private:
-	/// Opt to save a few glBindBuffer calls
-	static const thread_local BufferObject* lastBindedBo; 
-
 	GLuint glId = 0; ///< The OpenGL id of the BO
 
 	/// Used in glBindBuffer(target, glId) and its for easy access so we
@@ -152,7 +147,7 @@ private:
 	U32 sizeInBytes; ///< The size of the buffer
 
 #if !NDEBUG
-	Bool mapped = false;
+	Bool mapped = false; ///< Only in debug
 #endif
 };
 /// @}

+ 0 - 1
include/anki/math/Mat4.h

@@ -5,7 +5,6 @@
 
 namespace anki {
 
-
 /// @addtogroup Math
 /// @{
 

+ 10 - 27
src/gl/BufferObject.cpp

@@ -5,10 +5,6 @@
 
 namespace anki {
 
-//==============================================================================
-
-const thread_local BufferObject* BufferObject::lastBindedBo = nullptr;
-
 //==============================================================================
 BufferObject::~BufferObject()
 {
@@ -35,14 +31,14 @@ void BufferObject::create(GLenum target_, U32 sizeInBytes_,
 	sizeInBytes = sizeInBytes_;
 
 	glGenBuffers(1, &glId);
-	// XXX Check if zero
+	ANKI_ASSERT(glId != 0);
 	bind();
 	glBufferData(target, sizeInBytes, dataPtr, usage);
 
 	// make a check
-	int bufferSize = 0;
+	GLint bufferSize = 0;
 	glGetBufferParameteriv(target, GL_BUFFER_SIZE, &bufferSize);
-	if(sizeInBytes != (uint)bufferSize)
+	if(sizeInBytes != (U32)bufferSize)
 	{
 		destroy();
 		throw ANKI_EXCEPTION("Data size mismatch");
@@ -55,6 +51,7 @@ void BufferObject::create(GLenum target_, U32 sizeInBytes_,
 //==============================================================================
 void* BufferObject::map(U32 offset, U32 length, GLuint flags)
 {
+	ANKI_ASSERT(isCreated());
 	ANKI_ASSERT(mapped == false);
 	bind();
 	ANKI_ASSERT(offset + length <= sizeInBytes);
@@ -69,6 +66,7 @@ void* BufferObject::map(U32 offset, U32 length, GLuint flags)
 //==============================================================================
 void BufferObject::unmap()
 {
+	ANKI_ASSERT(isCreated());
 	ANKI_ASSERT(mapped == true);
 	bind();
 	glUnmapBuffer(target);
@@ -77,21 +75,6 @@ void BufferObject::unmap()
 #endif
 }
 
-//==============================================================================
-void BufferObject::write(void* buff)
-{
-	ANKI_ASSERT(isCreated());
-	ANKI_ASSERT(usage != GL_STATIC_DRAW);
-	bind();
-#if 0
-	void* mapped = glMapBuffer(target, GL_WRITE_ONLY);
-	memcpy(mapped, buff, sizeInBytes);
-	glUnmapBuffer(target);
-#else
-	glBufferData(target, sizeInBytes, buff, usage);
-#endif
-}
-
 //==============================================================================
 void BufferObject::write(void* buff, U32 offset, U32 size)
 {
@@ -99,12 +82,12 @@ void BufferObject::write(void* buff, U32 offset, U32 size)
 	ANKI_ASSERT(usage != GL_STATIC_DRAW);
 	ANKI_ASSERT(offset + size <= sizeInBytes);
 	bind();
-	void* mapped = glMapBufferRange(target, offset, size,
-		GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_RANGE_BIT/*
-		| GL_MAP_FLUSH_EXPLICIT_BIT*/);
-	ANKI_ASSERT(mapped != nullptr);
+
+	void* mapped = map(offset, size, 
+		GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_RANGE_BIT);
+	
 	memcpy(mapped, buff, size);
-	glUnmapBuffer(target);
+	unmap();
 }
 
 } // end namespace anki

+ 3 - 3
src/gl/Fbo.cpp

@@ -1,6 +1,6 @@
 #include "anki/gl/Fbo.h"
 #include "anki/gl/Texture.h"
-#include <array>
+#include "anki/util/Array.h"
 
 namespace anki {
 
@@ -8,7 +8,7 @@ namespace anki {
 
 thread_local const Fbo* Fbo::current = nullptr;
 
-static const std::array<GLenum, 8> colorAttachments = {{
+static const Array<GLenum, 8> colorAttachments = {{
 	GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2,
 	GL_COLOR_ATTACHMENT3, GL_COLOR_ATTACHMENT4, GL_COLOR_ATTACHMENT5,
 	GL_COLOR_ATTACHMENT6, GL_COLOR_ATTACHMENT7}};
@@ -115,4 +115,4 @@ void Fbo::setOtherAttachment(GLenum attachment, const Texture& tex)
 		GL_TEXTURE_2D, tex.getGlId(), 0);
 }
 
-} // end namespace
+} // end namespace anki