Browse Source

Porting to GL 3.3 core

Panagiotis Christopoulos Charitos 15 years ago
parent
commit
8bf8ef2b6c

File diff suppressed because it is too large
+ 1 - 2
build/debug/Makefile


+ 13 - 3
src/Renderer/BufferObjects/Vao.cpp

@@ -5,7 +5,7 @@
 //======================================================================================================================
 // attachArrayBufferVbo                                                                                                =
 //======================================================================================================================
-void Vao::attachArrayBufferVbo(const Vbo& vbo, const ShaderProg::AttribVar& attribVar, GLint size, GLenum type,
+void Vao::attachArrayBufferVbo(const Vbo& vbo, uint attribVarLocation, GLint size, GLenum type,
 		                           GLboolean normalized, GLsizei stride, const GLvoid* pointer)
 {
 	if(vbo.getBufferTarget() != GL_ARRAY_BUFFER)
@@ -15,14 +15,24 @@ void Vao::attachArrayBufferVbo(const Vbo& vbo, const ShaderProg::AttribVar& attr
 
 	bind();
 	vbo.bind();
-	glVertexAttribPointer(attribVar.getLoc(), size, type, normalized, stride, pointer);
-	glEnableVertexAttribArray(attribVar.getLoc());
+	glVertexAttribPointer(attribVarLocation, size, type, normalized, stride, pointer);
+	glEnableVertexAttribArray(attribVarLocation);
 	unbind();
 
 	ON_GL_FAIL_THROW_EXCEPTION();
 }
 
 
+//======================================================================================================================
+// attachArrayBufferVbo                                                                                                =
+//======================================================================================================================
+void Vao::attachArrayBufferVbo(const Vbo& vbo, const ShaderProg::AttribVar& attribVar, GLint size, GLenum type,
+		                           GLboolean normalized, GLsizei stride, const GLvoid* pointer)
+{
+	attachArrayBufferVbo(vbo, attribVar.getLoc(), size, type, normalized, stride, pointer);
+}
+
+
 //======================================================================================================================
 // attachElementArrayBufferVbo                                                                                         =
 //======================================================================================================================

+ 21 - 4
src/Renderer/BufferObjects/Vao.h

@@ -2,7 +2,6 @@
 #define VAO_H
 
 #include <GL/glew.h>
-#include "Exception.h"
 #include "StdTypes.h"
 #include "ShaderProg.h"
 #include "Object.h"
@@ -22,14 +21,32 @@ class Vao: public Object
 		/// Default constructor
 		Vao(Object* parent = NULL);
 
-		/// Destroy VAO fro the OpenGL context
+		/// Destroy VAO from the OpenGL context
 		~Vao() {glDeleteVertexArrays(1, &glId);}
 
-		/// @todo
+		/// Attach an array buffer VBO. See @link http://www.opengl.org/sdk/docs/man3/xhtml/glVertexAttribPointer.xml
+		/// @param vbo The VBO to attach
+		/// @param attribVar For the shader attribute location
+		/// @param size Specifies the number of components per generic vertex attribute. Must be 1, 2, 3, 4
+		/// @param type GL_BYTE, GL_UNSIGNED_BYTE, GL_SHORT etc
+		/// @param normalized Specifies whether fixed-point data values should be normalized
+		/// @param stride Specifies the byte offset between consecutive generic vertex attributes
+		/// @param pointer Specifies a offset of the first component of the first generic vertex attribute in the array
 		void attachArrayBufferVbo(const Vbo& vbo, const ShaderProg::AttribVar& attribVar, GLint size, GLenum type,
 		                          GLboolean normalized, GLsizei stride, const GLvoid* pointer);
 
-		/// @todo
+		/// Attach an array buffer VBO. See @link http://www.opengl.org/sdk/docs/man3/xhtml/glVertexAttribPointer.xml
+		/// @param vbo The VBO to attach
+		/// @param attribVarLocation Shader attribute location
+		/// @param size Specifies the number of components per generic vertex attribute. Must be 1, 2, 3, 4
+		/// @param type GL_BYTE, GL_UNSIGNED_BYTE, GL_SHORT etc
+		/// @param normalized Specifies whether fixed-point data values should be normalized
+		/// @param stride Specifies the byte offset between consecutive generic vertex attributes
+		/// @param pointer Specifies a offset of the first component of the first generic vertex attribute in the array
+		void attachArrayBufferVbo(const Vbo& vbo, uint attribVarLocation, GLint size, GLenum type,
+		                          GLboolean normalized, GLsizei stride, const GLvoid* pointer);
+
+		/// Attach an element array buffer VBO
 		void attachElementArrayBufferVbo(const Vbo& vbo);
 
 		/// Bind it

+ 0 - 2
src/Renderer/MainRenderer.cpp

@@ -104,9 +104,7 @@ void MainRenderer::render(Camera& cam_)
 	sProg->bind();
 	sProg->findUniVar("rasterImage")->setTexture(ms.diffuseFai, 0);
 	//sProg->findUniVar("rasterImage")->setTexture(pps.postPassFai, 0);
-ON_GL_FAIL_THROW_EXCEPTION();
 	drawQuad(0);
-ON_GL_FAIL_THROW_EXCEPTION();
 }
 
 

+ 31 - 0
src/Renderer/Renderer.cpp

@@ -60,6 +60,8 @@ void Renderer::init(const RendererInitializer& initializer)
 	{
 		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);
+		globalVao = new Vao();
+		globalVao->attachArrayBufferVbo(*quadPositionsVbo, 0, 4, GL_FLOAT, false, 0, 0);
 	}
 }
 
@@ -72,7 +74,10 @@ void Renderer::render(Camera& cam_)
 	cam = &cam_;
 
 	viewProjectionMat = cam->getProjectionMatrix() * cam->getViewMatrix();
+
 	ms.run();
+
+	globalVao->bind();
 	/*is.run();
 	pps.runPrePass();
 	bs.run();
@@ -158,19 +163,29 @@ void Renderer::setupMaterial(const Material& mtl, const SceneNode& sceneNode, co
 
 	// set matrices
 	if(mtl.stdUniVars[Material::SUV_MODEL_MAT])
+	{
 		mtl.stdUniVars[Material::SUV_MODEL_MAT]->setMat4(&modelMat);
+	}
 
 	if(mtl.stdUniVars[Material::SUV_VIEW_MAT])
+	{
 		mtl.stdUniVars[Material::SUV_VIEW_MAT]->setMat4(&viewMat);
+	}
 
 	if(mtl.stdUniVars[Material::SUV_PROJECTION_MAT])
+	{
 		mtl.stdUniVars[Material::SUV_PROJECTION_MAT]->setMat4(&projectionMat);
+	}
 
 	if(mtl.stdUniVars[Material::SUV_MODELVIEW_MAT])
+	{
 		mtl.stdUniVars[Material::SUV_MODELVIEW_MAT]->setMat4(&modelViewMat);
+	}
 
 	if(mtl.stdUniVars[Material::SUV_VIEWPROJECTION_MAT])
+	{
 		mtl.stdUniVars[Material::SUV_VIEWPROJECTION_MAT]->setMat4(&viewProjectionMat);
+	}
 
 	if(mtl.stdUniVars[Material::SUV_NORMAL_MAT])
 	{
@@ -189,25 +204,39 @@ void Renderer::setupMaterial(const Material& mtl, const SceneNode& sceneNode, co
 	// FAis
 	//
 	if(mtl.stdUniVars[Material::SUV_MS_NORMAL_FAI])
+	{
 		mtl.stdUniVars[Material::SUV_MS_NORMAL_FAI]->setTexture(ms.normalFai, textureUnit++);
+	}
 
 	if(mtl.stdUniVars[Material::SUV_MS_DIFFUSE_FAI])
+	{
 		mtl.stdUniVars[Material::SUV_MS_DIFFUSE_FAI]->setTexture(ms.diffuseFai, textureUnit++);
+	}
 
 	if(mtl.stdUniVars[Material::SUV_MS_SPECULAR_FAI])
+	{
 		mtl.stdUniVars[Material::SUV_MS_SPECULAR_FAI]->setTexture(ms.specularFai, textureUnit++);
+	}
 
 	if(mtl.stdUniVars[Material::SUV_MS_DEPTH_FAI])
+	{
 		mtl.stdUniVars[Material::SUV_MS_DEPTH_FAI]->setTexture(ms.depthFai, textureUnit++);
+	}
 
 	if(mtl.stdUniVars[Material::SUV_IS_FAI])
+	{
 		mtl.stdUniVars[Material::SUV_IS_FAI]->setTexture(is.fai, textureUnit++);
+	}
 
 	if(mtl.stdUniVars[Material::SUV_PPS_PRE_PASS_FAI])
+	{
 		mtl.stdUniVars[Material::SUV_PPS_PRE_PASS_FAI]->setTexture(pps.prePassFai, textureUnit++);
+	}
 
 	if(mtl.stdUniVars[Material::SUV_PPS_POST_PASS_FAI])
+	{
 		mtl.stdUniVars[Material::SUV_PPS_POST_PASS_FAI]->setTexture(pps.postPassFai, textureUnit++);
+	}
 
 
 	//
@@ -256,6 +285,8 @@ void Renderer::setupMaterial(const Material& mtl, const SceneNode& sceneNode, co
 				break;
 		}
 	}
+
+	ON_GL_FAIL_THROW_EXCEPTION();
 }
 
 

+ 2 - 2
src/Resources/Mesh.cpp

@@ -48,7 +48,7 @@ void Mesh::load(const char* filename)
 
 
 			createVbos(meshData);
-			createVao(vao, *material.get());
+			createVao(mainVao, *material.get());
 			createVao(depthVao, *material->dpMtl.get());
 		}
 	}
@@ -106,7 +106,7 @@ void Mesh::createVbos(const MeshData& meshData)
 //======================================================================================================================
 // createVao                                                                                                           =
 //======================================================================================================================
-void Mesh::createVao(Vao* vao, Material& mtl)
+void Mesh::createVao(Vao*& vao, const Material& mtl)
 {
 	vao = new Vao(this);
 

+ 9 - 3
src/Resources/Mesh.h

@@ -33,8 +33,12 @@ class Mesh: public Resource, public Object
 
 	public:
 		RsrcPtr<Material> material; ///< Required. If empty then mesh not renderable
-		Vao* vao; ///< Vertex array object
-		Vao* depthVao; ///< Vertex array object for the depth material
+
+		/// Accessor to vao
+		const Vao* getVao() const {return mainVao;}
+
+		/// Accessor to depthVao
+		const Vao* getDepthVao() const {return depthVao;}
 
 		/// Default constructor
 		Mesh(): Resource(RT_MESH), Object(NULL) {}
@@ -50,12 +54,14 @@ class Mesh: public Resource, public Object
 
 	private:
 		Vbo* vbos[VBOS_NUM]; ///< The vertex buffer objects
+		Vao* mainVao; ///< Vertex array object
+		Vao* depthVao; ///< Vertex array object for the depth material
 
 		/// Create the VBOs
 		void createVbos(const MeshData& meshData);
 
 		/// Create a VAO. Called more than one
-		void createVao(Vao* vao, Material& mtl);
+		void createVao(Vao*& vao, const Material& mtl);
 };
 
 

+ 1 - 5
src/Scene/MeshNode.cpp

@@ -26,12 +26,8 @@ void MeshNode::init(const char* filename)
 //======================================================================================================================
 // render                                                                                                              =
 //======================================================================================================================
-void MeshNode::render(Material& mtl, Vao& vao) const
+void MeshNode::render(const Material& mtl, const Vao& vao) const
 {
-	GLint loc;
-	GLint locs[64];
-	int locsNum = 0;
-
 	// if we have skeleton controller
 	if(meshSkelCtrl)
 	{

+ 3 - 3
src/Scene/MeshNode.h

@@ -15,7 +15,7 @@ class Vao;
 class MeshNode: public SceneNode
 {
 	private:
-		void render(Material& mtl, Vao& vao) const; ///< Common code for render() and renderDepth()
+		void render(const Material& mtl, const Vao& vao) const; ///< Common code for render() and renderDepth()
 
 	public:
 		// resources
@@ -24,8 +24,8 @@ class MeshNode: public SceneNode
 		MeshSkelNodeCtrl* meshSkelCtrl;
 		// funcs
 		MeshNode();
-		virtual void render() { render(*mesh->material.get(), *mesh->vao); }
-		virtual void renderDepth() { render(*mesh->material->dpMtl.get(), *mesh->depthVao); }
+		virtual void render() { render(*mesh->material.get(), *mesh->getVao()); }
+		virtual void renderDepth() { render(*mesh->material->dpMtl.get(), *mesh->getDepthVao()); }
 		void init(const char* filename);
 };
 

Some files were not shown because too many files changed in this diff