فهرست منبع

Porting to 3.3 core

Panagiotis Christopoulos Charitos 15 سال پیش
والد
کامیت
68c3ff01ed

+ 0 - 1
src/Renderer/BufferObjects/BufferObject.cpp

@@ -7,7 +7,6 @@
 //======================================================================================================================
 void BufferObject::create(GLenum target_, uint sizeInBytes, const void* dataPtr, GLenum usage_)
 {
-	RASSERT_THROW_EXCEPTION(isCreated()); // BO already initialized
 	// unacceptable usage_
 	RASSERT_THROW_EXCEPTION(usage_ != GL_STREAM_DRAW && usage_ != GL_STATIC_DRAW && usage_ != GL_DYNAMIC_DRAW);
 	RASSERT_THROW_EXCEPTION(sizeInBytes < 1); // unacceptable sizeInBytes

+ 21 - 72
src/Renderer/BufferObjects/BufferObject.h

@@ -2,40 +2,39 @@
 #define BUFFER_OBJECT_H
 
 #include <GL/glew.h>
-#include <limits>
 #include "Exception.h"
 #include "StdTypes.h"
 #include "Object.h"
+#include "Properties.h"
 
 
 /// A wrapper for OpenGL buffer objects (vertex arrays, texture buffers etc) to prevent us from making idiotic errors
 class BufferObject: public Object
 {
-	public:
-		/// Default constructor
-		BufferObject(Object* parent = NULL);
+	PROPERTY_R(uint, glId, getGlId) ///< The OpenGL id of the BO
 
-		virtual ~BufferObject();
+	/// Used in glBindBuffer(target, glId) and its for easy access so we wont have to query the GL driver. Its the type
+	/// of the buffer eg GL_TEXTURE_BUFFER or GL_ELEMENT_ARRAY_BUFFER etc
+	PROPERTY_R(GLenum, target, getBufferTarget)
 
-		/// Safe accessor. Throws exception if BO is not created
-		/// @return The OpenGL ID of the buffer
-		/// @exception Exception
-		uint getGlId() const;
+	PROPERTY_R(GLenum, usage, getBufferUsage) ///< GL_STREAM_DRAW or GL_STATIC_DRAW or GL_DYNAMIC_DRAW
 
-		/// Safe accessor. Throws exception if BO is not created
-		/// @return OpenGL target
-		/// @exception Exception
-		GLenum getBufferTarget() const;
+	public:
+		/// Default constructor @see create
+		BufferObject(GLenum target, uint sizeInBytes, const void* dataPtr, GLenum usage, Object* parent = NULL);
+
+		/// It deletes the BO from the GL context
+		virtual ~BufferObject() {deleteBuff();}
 
-		/// Safe accessor. Throws exception if BO is not created
-		/// @return GL_STREAM_DRAW or GL_STATIC_DRAW or GL_DYNAMIC_DRAW
+		/// Bind BO. Throws exception if BO is not created
 		/// @exception Exception
-		GLenum getBufferUsage() const;
+		void bind() const;
 
-		/// Checks if BO is created
-		/// @return True if BO is already created
-		bool isCreated() const throw() {return glId != std::numeric_limits<uint>::max();}
+		/// Unbind BO. Throws exception if BO is not created
+		/// @exception Exception
+		void unbind() const;
 
+	private:
 		/// Creates a new BO with the given parameters and checks if everything went OK. Throws exception if fails
 		/// @param target Depends on the BO
 		/// @param sizeInBytes The size of the buffer that we will allocate in bytes
@@ -44,24 +43,6 @@ class BufferObject: public Object
 		/// @exception Exception
 		void create(GLenum target, uint sizeInBytes, const void* dataPtr, GLenum usage);
 
-		/// Bind BO. Throws exception if BO is not created
-		/// @exception Exception
-		void bind() const;
-
-		/// Unbind BO. Throws exception if BO is not created
-		/// @exception Exception
-		void unbind() const;
-
-	protected:
-		uint glId; ///< The OpenGL id of the BO
-
-		/// Used in glBindBuffer(target, glId) and its for easy access so we wont have to query the GL driver. Its the type
-		/// of the buffer eg GL_TEXTURE_BUFFER or GL_ELEMENT_ARRAY_BUFFER etc
-		GLenum target;
-
-		GLenum usage; ///< GL_STREAM_DRAW or GL_STATIC_DRAW or GL_DYNAMIC_DRAW
-
-	private:
 		/// Delete the BO
 		/// @exception Exception
 		void deleteBuff();
@@ -72,59 +53,27 @@ class BufferObject: public Object
 // Inlines                                                                                                             =
 //======================================================================================================================
 
-inline BufferObject::BufferObject(Object* parent):
-	Object(parent),
-	glId(std::numeric_limits<uint>::max())
-{}
-
-
-inline BufferObject::~BufferObject()
-{
-	if(isCreated())
-	{
-		deleteBuff();
-	}
-}
-
-
-inline uint BufferObject::getGlId() const
-{
-	RASSERT_THROW_EXCEPTION(!isCreated());
-	return glId;
-}
-
-
-inline GLenum BufferObject::getBufferTarget() const
-{
-	RASSERT_THROW_EXCEPTION(!isCreated());
-	return target;
-}
-
-
-inline GLenum BufferObject::getBufferUsage() const
+inline BufferObject::BufferObject(GLenum target, uint sizeInBytes, const void* dataPtr, GLenum usage, Object* parent):
+	Object(parent)
 {
-	RASSERT_THROW_EXCEPTION(!isCreated());
-	return usage;
+	create(target, sizeInBytes, dataPtr, usage);
 }
 
 
 inline void BufferObject::bind() const
 {
-	RASSERT_THROW_EXCEPTION(!isCreated());
 	glBindBuffer(target, glId);
 }
 
 
 inline void BufferObject::unbind() const
 {
-	RASSERT_THROW_EXCEPTION(!isCreated());
 	glBindBuffer(target, 0);
 }
 
 
 inline void BufferObject::deleteBuff()
 {
-	RASSERT_THROW_EXCEPTION(!isCreated());
 	glDeleteBuffers(1, &glId);
 	glId = 0;
 }

+ 4 - 6
src/Renderer/BufferObjects/Vbo.h

@@ -8,20 +8,18 @@
 class Vbo: public BufferObject
 {
 	public:
-		Vbo(Object* parent = NULL): BufferObject(parent) {}
-
-		/// It adds an extra check over @ref BufferObject::create. @see @ref BufferObject::create
-		void create(GLenum target_, uint sizeInBytes, const void* dataPtr, GLenum usage_);
+		/// Adds an extra check in target_ @see BufferObject::BufferObject
+		Vbo(GLenum target_, uint sizeInBytes, const void* dataPtr, GLenum usage_, Object* parent = NULL);
 
 		/// Unbinds all VBOs, meaning both GL_ARRAY_BUFFER and GL_ELEMENT_ARRAY_BUFFER targets
 		static void unbindAllTargets();
 };
 
 
-inline void Vbo::create(GLenum target_, uint sizeInBytes, const void* dataPtr, GLenum usage_)
+inline Vbo::Vbo(GLenum target_, uint sizeInBytes, const void* dataPtr, GLenum usage_, Object* parent):
+	BufferObject(target_, sizeInBytes, dataPtr, usage_, parent)
 {
 	RASSERT_THROW_EXCEPTION(target_ != GL_ARRAY_BUFFER && target_ != GL_ELEMENT_ARRAY_BUFFER); // unacceptable target_
-	BufferObject::create(target_, sizeInBytes, dataPtr, usage_);
 }
 
 

+ 12 - 17
src/Renderer/Renderer.cpp

@@ -13,6 +13,9 @@
 float Renderer::quadVertCoords [][2] = { {1.0, 1.0}, {0.0, 1.0}, {0.0, 0.0}, {1.0, 0.0} };
 int Renderer::maxColorAtachments = -1;
 
+Vbo* Renderer::quadPositionsVbo = NULL;
+Vao* Renderer::globalVao = NULL;
+
 
 //======================================================================================================================
 // Constructor                                                                                                         =
@@ -51,6 +54,13 @@ void Renderer::init(const RendererInitializer& initializer)
 	/*is.init(initializer);
 	pps.init(initializer);
 	bs.init(initializer);*/
+
+	// VBOs
+	if(quadPositionsVbo == NULL)
+	{
+		float quadVertCoords[][2] = {{1.0, 1.0}, {0.0, 1.0}, {0.0, 0.0}, {1.0, 0.0}};
+		quadPositionsVbo = new Vbo(GL_ARRAY_BUFFER, sizeof(quadVertCoords), quadVertCoords, GL_STATIC_DRAW);
+	}
 }
 
 
@@ -72,32 +82,17 @@ void Renderer::render(Camera& cam_)
 }
 
 
-//======================================================================================================================
-// initQuad                                                                                                            =
-//======================================================================================================================
-void Renderer::initQuad()
-{
-	float quadVertCoords[][2] = {{1.0, 1.0}, {0.0, 1.0}, {0.0, 0.0}, {1.0, 0.0}};
-	quadPositionsVbo.create(GL_ARRAY_BUFFER, sizeof(quadVertCoords), quadVertCoords, GL_STATIC_DRAW);
-
-}
-
-
 //======================================================================================================================
 // drawQuad                                                                                                            =
 //======================================================================================================================
 void Renderer::drawQuad(int vertCoordsAttribLoc)
 {
 	RASSERT_THROW_EXCEPTION(vertCoordsAttribLoc == -1);
-ON_GL_FAIL_THROW_EXCEPTION();
+	quadPositionsVbo->bind();
 	glEnableVertexAttribArray(vertCoordsAttribLoc);
-ON_GL_FAIL_THROW_EXCEPTION();
-	glVertexAttribPointer(vertCoordsAttribLoc, 2, GL_FLOAT, false, 0, quadVertCoords);
-ON_GL_FAIL_THROW_EXCEPTION();
+	glVertexAttribPointer(vertCoordsAttribLoc, 2, GL_FLOAT, false, 0, NULL);
 	glDrawArrays(GL_QUADS, 0, 4);
-ON_GL_FAIL_THROW_EXCEPTION();
 	glDisableVertexAttribArray(vertCoordsAttribLoc);
-ON_GL_FAIL_THROW_EXCEPTION();
 }
 
 

+ 2 - 3
src/Renderer/Renderer.h

@@ -115,9 +115,8 @@ class Renderer: public Object
 	// Protected                                                                                                         =
 	//====================================================================================================================
 	private:
-		static Vbo quadPositionsVbo;
-		static Vao quadVao;
-		static void initQuad();
+		static Vbo* quadPositionsVbo;
+		static Vao* globalVao;
 
 	// to be removed
 	public:

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 0 - 0
src/Renderer/Smo.cpp


+ 1 - 1
src/Renderer/Smo.h

@@ -25,7 +25,7 @@ class Smo: public RenderingStage
 
 	private:
 		static float sMOUvSCoords[]; ///< Illumination stage stencil masking optimizations UV sphere vertex positions
-		static Vbo sMOUvSVbo; ///< Illumination stage stencil masking optimizations UV sphere VBO
+		static Vbo* sMOUvSVbo; ///< Illumination stage stencil masking optimizations UV sphere VBO
 		RsrcPtr<ShaderProg> sProg;
 };
 

+ 20 - 20
src/Resources/Mesh.cpp

@@ -64,29 +64,29 @@ void Mesh::load(const char* filename)
 //======================================================================================================================
 void Mesh::createVbos(const MeshData& meshData)
 {
-	vbos.vertIndeces.create(GL_ELEMENT_ARRAY_BUFFER, meshData.getVertIndeces().getSizeInBytes(),
-	                        &meshData.getVertIndeces()[0], GL_STATIC_DRAW);
-	vbos.vertCoords.create(GL_ARRAY_BUFFER, meshData.getVertCoords().getSizeInBytes(),
-	                       &meshData.getVertCoords()[0], GL_STATIC_DRAW);
-	vbos.vertNormals.create(GL_ARRAY_BUFFER, meshData.getVertNormals().getSizeInBytes(),
-	                        &meshData.getVertNormals()[0], GL_STATIC_DRAW);
+	vbos.vertIndeces = new Vbo(GL_ELEMENT_ARRAY_BUFFER, meshData.getVertIndeces().getSizeInBytes(),
+	                           &meshData.getVertIndeces()[0], GL_STATIC_DRAW);
+	vbos.vertCoords = new Vbo(GL_ARRAY_BUFFER, meshData.getVertCoords().getSizeInBytes(),
+	                          &meshData.getVertCoords()[0], GL_STATIC_DRAW);
+	vbos.vertNormals = new Vbo(GL_ARRAY_BUFFER, meshData.getVertNormals().getSizeInBytes(),
+	                           &meshData.getVertNormals()[0], GL_STATIC_DRAW);
 
 	if(meshData.getVertTangents().size() > 1)
 	{
-		vbos.vertTangents.create(GL_ARRAY_BUFFER, meshData.getVertTangents().getSizeInBytes(),
-		                         &meshData.getVertTangents()[0], GL_STATIC_DRAW);
+		vbos.vertTangents = new Vbo(GL_ARRAY_BUFFER, meshData.getVertTangents().getSizeInBytes(),
+		                            &meshData.getVertTangents()[0], GL_STATIC_DRAW);
 	}
 
 	if(meshData.getTexCoords().size() > 1)
 	{
-		vbos.texCoords.create(GL_ARRAY_BUFFER, meshData.getTexCoords().getSizeInBytes(),
-		                      &meshData.getTexCoords()[0], GL_STATIC_DRAW);
+		vbos.texCoords = new Vbo(GL_ARRAY_BUFFER, meshData.getTexCoords().getSizeInBytes(),
+		                         &meshData.getTexCoords()[0], GL_STATIC_DRAW);
 	}
 
 	if(meshData.getVertWeights().size() > 1)
 	{
-		vbos.vertWeights.create(GL_ARRAY_BUFFER, meshData.getVertWeights().getSizeInBytes(),
-		                        &meshData.getVertWeights()[0], GL_STATIC_DRAW);
+		vbos.vertWeights = new Vbo(GL_ARRAY_BUFFER, meshData.getVertWeights().getSizeInBytes(),
+		                           &meshData.getVertWeights()[0], GL_STATIC_DRAW);
 	}
 }
 
@@ -100,47 +100,47 @@ void Mesh::createVao(Vao& vao, Material& mtl)
 
 	if(mtl.stdAttribVars[Material::SAV_POSITION] != NULL)
 	{
-		vboInfos.push_back(Vao::VboInfo(&vbos.vertCoords, mtl.stdAttribVars[Material::SAV_POSITION], 3, GL_FLOAT,
+		vboInfos.push_back(Vao::VboInfo(vbos.vertCoords, mtl.stdAttribVars[Material::SAV_POSITION], 3, GL_FLOAT,
 		                                GL_FALSE, 0, NULL));
 	}
 
 	if(mtl.stdAttribVars[Material::SAV_NORMAL] != NULL)
 	{
-		vboInfos.push_back(Vao::VboInfo(&vbos.vertNormals, mtl.stdAttribVars[Material::SAV_NORMAL], 3, GL_FLOAT,
+		vboInfos.push_back(Vao::VboInfo(vbos.vertNormals, mtl.stdAttribVars[Material::SAV_NORMAL], 3, GL_FLOAT,
 		                                GL_FALSE, 0, NULL));
 	}
 
 	if(mtl.stdAttribVars[Material::SAV_TANGENT] != NULL)
 	{
-		vboInfos.push_back(Vao::VboInfo(&vbos.vertTangents, mtl.stdAttribVars[Material::SAV_TANGENT], 4, GL_FLOAT,
+		vboInfos.push_back(Vao::VboInfo(vbos.vertTangents, mtl.stdAttribVars[Material::SAV_TANGENT], 4, GL_FLOAT,
 		                                GL_FALSE, 0, NULL));
 	}
 
 	if(mtl.stdAttribVars[Material::SAV_TEX_COORDS] != NULL)
 	{
-		vboInfos.push_back(Vao::VboInfo(&vbos.texCoords, mtl.stdAttribVars[Material::SAV_TEX_COORDS], 2, GL_FLOAT,
+		vboInfos.push_back(Vao::VboInfo(vbos.texCoords, mtl.stdAttribVars[Material::SAV_TEX_COORDS], 2, GL_FLOAT,
 		                                GL_FALSE, 0, NULL));
 	}
 
 	if(mtl.stdAttribVars[Material::SAV_VERT_WEIGHT_BONES_NUM] != NULL)
 	{
-		vboInfos.push_back(Vao::VboInfo(&vbos.vertWeights, mtl.stdAttribVars[Material::SAV_VERT_WEIGHT_BONES_NUM], 1,
+		vboInfos.push_back(Vao::VboInfo(vbos.vertWeights, mtl.stdAttribVars[Material::SAV_VERT_WEIGHT_BONES_NUM], 1,
 		                                GL_FLOAT, GL_FALSE, sizeof(MeshData::VertexWeight), BUFFER_OFFSET(0)));
 	}
 
 	if(mtl.stdAttribVars[Material::SAV_VERT_WEIGHT_BONE_IDS] != NULL)
 	{
-		vboInfos.push_back(Vao::VboInfo(&vbos.vertWeights, mtl.stdAttribVars[Material::SAV_VERT_WEIGHT_BONE_IDS], 4,
+		vboInfos.push_back(Vao::VboInfo(vbos.vertWeights, mtl.stdAttribVars[Material::SAV_VERT_WEIGHT_BONE_IDS], 4,
 		                                GL_FLOAT, GL_FALSE, sizeof(MeshData::VertexWeight), BUFFER_OFFSET(4)));
 	}
 
 	if(mtl.stdAttribVars[Material::SAV_VERT_WEIGHT_WEIGHTS] != NULL)
 	{
-		vboInfos.push_back(Vao::VboInfo(&vbos.vertWeights, mtl.stdAttribVars[Material::SAV_VERT_WEIGHT_WEIGHTS], 4,
+		vboInfos.push_back(Vao::VboInfo(vbos.vertWeights, mtl.stdAttribVars[Material::SAV_VERT_WEIGHT_WEIGHTS], 4,
 		                                GL_FLOAT, GL_FALSE, sizeof(MeshData::VertexWeight), BUFFER_OFFSET(20)));
 	}
 
-	vao.create(&vboInfos[0], vboInfos.size(), &vbos.vertIndeces);
+	vao.create(&vboInfos[0], vboInfos.size(), vbos.vertIndeces);
 }
 
 

+ 18 - 6
src/Resources/Mesh.h

@@ -19,12 +19,14 @@ class Mesh: public Resource
 		/// The VBOs in a structure
 		struct Vbos
 		{
-			Vbo vertCoords;
-			Vbo vertNormals;
-			Vbo vertTangents;
-			Vbo texCoords;
-			Vbo vertIndeces;
-			Vbo vertWeights;
+			Vbo* vertCoords;
+			Vbo* vertNormals;
+			Vbo* vertTangents;
+			Vbo* texCoords;
+			Vbo* vertIndeces;
+			Vbo* vertWeights;
+
+			Vbos();
 		};
 
 	PROPERTY_R(uint, vertIdsNum, getVertIdsNum)
@@ -50,4 +52,14 @@ class Mesh: public Resource
 };
 
 
+inline Mesh::Vbos::Vbos():
+	vertCoords(NULL),
+	vertNormals(NULL),
+	vertTangents(NULL),
+	texCoords(NULL),
+	vertIndeces(NULL),
+	vertWeights(NULL)
+{}
+
+
 #endif

+ 2 - 2
src/Scene/Controllers/MeshSkelNodeCtrl.h

@@ -18,12 +18,12 @@ class MeshSkelNodeCtrl: public Controller
 		SkelNode* skelNode;
 		MeshNode* meshNode;
 
-		struct
+		/*struct
 		{
 			Vbo positions;
 			Vbo normals;
 			Vbo tangents;
-		} vbos;
+		} vbos;*/
 
 
 		MeshSkelNodeCtrl(SkelNode* skelNode_, MeshNode* meshNode_):

+ 13 - 3
src/Util/Properties.h

@@ -4,7 +4,7 @@
 
 /// Read write property
 ///
-/// - It creates a unique type so it can work with pointers
+/// - It deliberately does not work with pointers
 /// - The get funcs are coming into two flavors, one const and one non-const. The property is read-write after all so
 ///   the non-const is acceptable
 /// - Dont use it with semicolon at the end (eg PROPERTY_RW(....);) because of a doxygen bug
@@ -17,9 +17,9 @@
 		Type__& getFunc__() {return varName__;}
 
 
-/// Read only property
+/// Read only private property
 ///
-/// - It creates a unique type so it can work with pointers
+/// - It deliberately does not work with pointers
 /// - Dont use it with semicolon at the end (eg PROPERTY_RW(....);) because of a doxygen bug
 #define PROPERTY_R(Type__, varName__, getFunc__) \
 	private: \
@@ -28,4 +28,14 @@
 		const Type__& getFunc__() const { return varName__; }
 
 
+/// Read only protected property
+///
+/// - Dont use it with semicolon at the end (eg PROPERTY_RW(....);) because of a doxygen bug
+#define PROTECTED_PROPERTY_R(Type__, varName__, getFunc__) \
+	protected: \
+		Type__ varName__; \
+	public: \
+		const Type__& getFunc__() const { return varName__; }
+
+
 #endif

برخی فایل ها در این مقایسه diff نمایش داده نمی شوند زیرا تعداد فایل ها بسیار زیاد است