Selaa lähdekoodia

Working on GL 3.3 core port

Panagiotis Christopoulos Charitos 15 vuotta sitten
vanhempi
sitoutus
c36c3c93dc

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 1 - 2
build/debug/Makefile


+ 11 - 2
src/Renderer/BufferObjects/BufferObject.h

@@ -5,13 +5,16 @@
 #include <limits>
 #include "Exception.h"
 #include "StdTypes.h"
+#include "Object.h"
 
 
 /// A wrapper for OpenGL buffer objects (vertex arrays, texture buffers etc) to prevent us from making idiotic errors
-class BufferObject
+class BufferObject: public Object
 {
 	public:
-		BufferObject(): glId(std::numeric_limits<uint>::max()) {}
+		/// Default constructor
+		BufferObject(Object* parent = NULL);
+
 		virtual ~BufferObject();
 
 		/// Safe accessor. Throws exception if BO is not created
@@ -69,6 +72,12 @@ class BufferObject
 // Inlines                                                                                                             =
 //======================================================================================================================
 
+inline BufferObject::BufferObject(Object* parent):
+	Object(parent),
+	glId(std::numeric_limits<uint>::max())
+{}
+
+
 inline BufferObject::~BufferObject()
 {
 	if(isCreated())

+ 10 - 2
src/Renderer/BufferObjects/Fbo.h

@@ -5,15 +5,17 @@
 #include "Exception.h"
 #include "Properties.h"
 #include "StdTypes.h"
+#include "Object.h"
 
 
 /// The class is actually a wrapper to avoid common mistakes
-class Fbo
+class Fbo: public Object
 {
 	PROPERTY_R(uint, glId, getGlId) ///< OpenGL identification
 
 	public:
-		Fbo(): glId(0) {}
+		/// Constructor
+		Fbo(Object* parent = NULL);
 
 		/// Creates a new FBO
 		void create();
@@ -41,6 +43,12 @@ class Fbo
 // Inlines                                                                                                             =
 //======================================================================================================================
 
+inline Fbo::Fbo(Object* parent):
+	Object(parent),
+	glId(0)
+{}
+
+
 inline void Fbo::create()
 {
 	RASSERT_THROW_EXCEPTION(glId != 0); // FBO already initialized

+ 14 - 11
src/Renderer/BufferObjects/Vao.cpp

@@ -1,5 +1,6 @@
 #include "Vao.h"
 #include "Vbo.h"
+#include "GlException.h"
 
 
 //======================================================================================================================
@@ -24,29 +25,31 @@ Vao::VboInfo::VboInfo(const Vbo* vbo_, const ShaderProg::AttribVar* attribVar_,
 //======================================================================================================================
 // create                                                                                                              =
 //======================================================================================================================
-inline void Vao::create(Vec<VboInfo> arrayBufferVbosInfo, const Vbo* elementArrayBufferVbo)
+void Vao::create(const VboInfo arrayBufferVbosInfo[], uint arrayBufferVbosInfoNum, const Vbo* elementArrayBufferVbo)
 {
 	RASSERT_THROW_EXCEPTION(isCreated());
 	glGenVertexArrays(1, &glId);
 	bind();
 
 	// Attach the GL_ARRAY_BUFFER VBOs
-	Vec<VboInfo>::iterator info = arrayBufferVbosInfo.begin();
-	for(; info != arrayBufferVbosInfo.end(); info++)
+
+	for(uint i = 0; i < arrayBufferVbosInfoNum; i++)
 	{
-		RASSERT_THROW_EXCEPTION(info->vbo == NULL);
-		RASSERT_THROW_EXCEPTION(info->attribVar == NULL);
+		const VboInfo& info = arrayBufferVbosInfo[i];
+
+		RASSERT_THROW_EXCEPTION(info.vbo == NULL);
+		RASSERT_THROW_EXCEPTION(info.attribVar == NULL);
 
-		if(info->vbo->getBufferTarget() != GL_ARRAY_BUFFER)
+		if(info.vbo->getBufferTarget() != GL_ARRAY_BUFFER)
 		{
 			throw EXCEPTION("Only GL_ARRAY_BUFFER is accepted");
 		}
 
-		info->vbo->bind();
-		glVertexAttribPointer(info->attribVar->getLoc(), info->size, info->type, info->normalized,
-		                      info->stride, info->pointer);
-		glEnableVertexAttribArray(info->attribVar->getLoc());
-		info->vbo->unbind();
+		info.vbo->bind();
+		glVertexAttribPointer(info.attribVar->getLoc(), info.size, info.type, info.normalized,
+		                      info.stride, info.pointer);
+		glEnableVertexAttribArray(info.attribVar->getLoc());
+		info.vbo->unbind();
 	}
 
 	// Attach the GL_ELEMENT_ARRAY_BUFFER VBO

+ 9 - 5
src/Renderer/BufferObjects/Vao.h

@@ -4,7 +4,6 @@
 #include <GL/glew.h>
 #include <limits>
 #include "Exception.h"
-#include "GlException.h"
 #include "StdTypes.h"
 #include "ShaderProg.h"
 
@@ -16,7 +15,8 @@ class Vbo;
 class Vao
 {
 	public:
-		/// @todo
+		/// This structs contains information for VAO bind into the VAO. Used by the @ref create method. See
+		/// glVertexAttribPointer for the interpretation of the member variables
 		struct VboInfo
 		{
 			const Vbo* vbo;
@@ -27,6 +27,7 @@ class Vao
 			GLsizei stride;
 			const GLvoid* pointer;
 
+			/// The one and only constructor
 			VboInfo(const Vbo* vbo_, const ShaderProg::AttribVar* attribVar_, GLint size_, GLenum type_,
               GLboolean normalized_, GLsizei stride_, const GLvoid* pointer_);
 
@@ -43,15 +44,18 @@ class Vao
 		/// @exception Exception
 		uint getGlId() const;
 
-		/// Create the VAO. Throws exception if already created
+		/// Create the VAO. Throws exception if already created. It requires an C-style array with size so it can be fast
+		/// @param[in] arrayBufferVbosInfo An array with information per VBO. The VBOs are GL_ARRAY_BUFFER
+		/// @param[in] arrayBufferVbosInfoNum The size of the arrayBufferVbosInfo array
+		/// @param[in] elementArrayBufferVbo The GL_ELEMENT_ARRAY_BUFFER VBO. If NULL then ignored
 		/// @exception Exception
-		void create(Vec<VboInfo> arrayBufferVbosInfo, const Vbo* elementArrayBufferVbo);
+		void create(const VboInfo arrayBufferVbosInfo[], uint arrayBufferVbosInfoNum, const Vbo* elementArrayBufferVbo);
 
 		/// Bind it. Throws exception if not created
 		/// @exception Exception
 		void bind() const;
 
-		/// Unbind the VAO
+		/// Unbind all VAOs
 		static void unbind() {glBindVertexArray(0);}
 
 		/// Destroy it. Throws exception if not created

+ 2 - 0
src/Renderer/BufferObjects/Vbo.h

@@ -8,6 +8,8 @@
 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_);
 

+ 2 - 2
src/Renderer/Renderer.cpp

@@ -25,8 +25,8 @@ Renderer::Renderer(Object* parent):
 	is(*this),
 	pps(*this),
 	bs(*this)
-{
-}
+{}
+
 
 //======================================================================================================================
 // init                                                                                                                =

+ 1 - 0
src/Renderer/Renderer.h

@@ -6,6 +6,7 @@
 #include "Texture.h"
 #include "ShaderProg.h"
 #include "Vbo.h"
+#include "Vao.h"
 #include "RsrcPtr.h"
 #include "Object.h"
 #include "Ms.h"

+ 14 - 17
src/Resources/Mesh.cpp

@@ -101,49 +101,46 @@ 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,
-		                         GL_FALSE, 0, NULL));
+		                                GL_FALSE, 0, NULL));
 	}
 
 	if(mtl.stdAttribVars[Material::SAV_NORMAL] != NULL)
 	{
-		vao.attachArrayBufferVbo(vbos.vertNormals, *mtl.stdAttribVars[Material::SAV_NORMAL], 3, GL_FLOAT,
-		                         GL_FALSE, 0, NULL);
+		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)
 	{
-		vao.attachArrayBufferVbo(vbos.vertTangents, *mtl.stdAttribVars[Material::SAV_TANGENT], 4, GL_FLOAT,
-		                         GL_FALSE, 0, NULL);
+		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)
 	{
-		vao.attachArrayBufferVbo(vbos.texCoords, *mtl.stdAttribVars[Material::SAV_TEX_COORDS], 2, GL_FLOAT,
-		                         GL_FALSE, 0, NULL);
+		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)
 	{
-		vao.attachArrayBufferVbo(vbos.vertWeights, *mtl.stdAttribVars[Material::SAV_VERT_WEIGHT_BONES_NUM], 1, GL_FLOAT,
-		                         GL_FALSE, sizeof(MeshData::VertexWeight), BUFFER_OFFSET(0));
+		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)
 	{
-		vao.attachArrayBufferVbo(vbos.vertWeights, *mtl.stdAttribVars[Material::SAV_VERT_WEIGHT_BONE_IDS], 4, GL_FLOAT,
-		                         GL_FALSE, sizeof(MeshData::VertexWeight), BUFFER_OFFSET(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)
 	{
-		vao.attachArrayBufferVbo(vbos.vertWeights, *mtl.stdAttribVars[Material::SAV_VERT_WEIGHT_WEIGHTS], 4, GL_FLOAT,
-		                         GL_FALSE, sizeof(MeshData::VertexWeight), BUFFER_OFFSET(20));
+		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.attachElementArrayBuffer(vbos.vertIndeces);
-
-	vao.create(&vboInfos[0]);
-	vao.bind();
+	vao.create(&vboInfos[0], vboInfos.size(), &vbos.vertIndeces);
 }
 
 

Kaikkia tiedostoja ei voida näyttää, sillä liian monta tiedostoa muuttui tässä diffissä