diff --git a/Engine/Rendering/Renderables/Cubemap.cpp b/Engine/Rendering/Renderables/Cubemap.cpp index 49af3076..189e7d61 100644 --- a/Engine/Rendering/Renderables/Cubemap.cpp +++ b/Engine/Rendering/Renderables/Cubemap.cpp @@ -4,9 +4,9 @@ namespace Engine { // ----- Private ----- - Ref Cubemap::CreateVao() + void Cubemap::InitGpuStorage() { - float skyboxVertices[] = + static const float skyboxVertices[] = { -1.0f, 1.0f, -1.0f, -1.0f, -1.0f, -1.0f, @@ -52,49 +52,58 @@ namespace Engine }; //Create and bind vao - Ref vao = MakeRef(); - vao->Bind(); + _vao = MakeScope(); + _vao->Bind(); //Create vbo, send it data and configure vao - VertexBuffer vbo(&skyboxVertices, sizeof(skyboxVertices), GL_STATIC_DRAW); - vao->DefineAttributes(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), nullptr); + _vboVert = MakeScope(&skyboxVertices, sizeof(skyboxVertices), GL_STATIC_DRAW); + _vao->DefineAttributes(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), nullptr); //Unbind vao - vao->Unbind(); - - return vao; + _vao->Unbind(); } // ----- Public ----- Cubemap::Cubemap(const std::array& faces, Shader* shader) - : _vao(CreateVao()), - _cubemapTexture(MakeScope(faces)), + : _cubemapTexture(MakeScope(faces)), _shader(shader), _verticeCount(36) - {} + { + InitGpuStorage(); + } uint32 Cubemap::Draw(const glm::mat4& projMatrix, const glm::mat4& viewMatrix) const { - _shader->Bind(); - //Remove translation section glm::mat4 view = glm::mat4(glm::mat3(viewMatrix)); + //Bind shader + _shader->Bind(); + + //Bind texture + _cubemapTexture->Bind(); + + //Bind vao and vbo + _vao->Bind(); + _vboVert->Bind(); + //Set uniforms _shader->SetUniformMat4f("view", view); _shader->SetUniformMat4f("projection", projMatrix); _shader->SetUniform1i("textureSampler", 0); - //Set texture - _cubemapTexture->Bind(); - _vao->Bind(); - //Render GLCall(glDrawArrays(GL_TRIANGLES, 0, _verticeCount)); + //Unbind vao and vbo + _vboVert->Unbind(); _vao->Unbind(); + + //Unbind texture _cubemapTexture->Unbind(); + + //Unbind shader _shader->Unbind(); //Return rendered vertices diff --git a/Engine/Rendering/Renderables/Cubemap.hpp b/Engine/Rendering/Renderables/Cubemap.hpp index e9170528..06546fe4 100644 --- a/Engine/Rendering/Renderables/Cubemap.hpp +++ b/Engine/Rendering/Renderables/Cubemap.hpp @@ -12,12 +12,13 @@ namespace Engine class Cubemap { private: - Ref _vao; + Scope _vao; + Scope _vboVert; Scope _cubemapTexture; Shader* _shader; uint32 _verticeCount; - static Ref CreateVao(); + void InitGpuStorage(); public: Cubemap(const std::array& faces, Shader* shader); diff --git a/Engine/Rendering/Renderables/CubemapTexture.cpp b/Engine/Rendering/Renderables/CubemapTexture.cpp index dca3363a..fa09a69c 100644 --- a/Engine/Rendering/Renderables/CubemapTexture.cpp +++ b/Engine/Rendering/Renderables/CubemapTexture.cpp @@ -32,7 +32,7 @@ namespace Engine GLCall(glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, format, width, height, 0, format, GL_UNSIGNED_BYTE, localBuffer)); std::string cubemapInfo = "(X: " + std::to_string(width) + ", Y: " + std::to_string(height) + ", Channels: " + std::to_string(nrChannels) + ")"; - Logger::Info("Loaded", "Heightmap", faces[i]); + Logger::Info("Loaded", "Cubemap", faces[i]); Logger::Info("", "", cubemapInfo); } } diff --git a/Engine/Rendering/Renderables/Model.cpp b/Engine/Rendering/Renderables/Model.cpp index aa269d59..eb2f4ce0 100644 --- a/Engine/Rendering/Renderables/Model.cpp +++ b/Engine/Rendering/Renderables/Model.cpp @@ -4,32 +4,30 @@ namespace Engine { // ----- Private ----- - Ref Model::CreateVaoFromMesh(Mesh* mesh) + void Model::InitGpuStorage(Mesh* mesh) { //Create and bind vao - Ref vao = MakeRef(); - vao->Bind(); + _vao = MakeScope(); + _vao->Bind(); //Create vbo's, send it data and configure vao - VertexBuffer vbo1(&mesh->vertices[0], mesh->vertices.size() * sizeof(glm::vec3), GL_STATIC_DRAW); - vao->DefineAttributes(0, 3, GL_FLOAT, GL_FALSE, sizeof(glm::vec3), nullptr); + _vboVert = MakeScope(&mesh->vertices[0], mesh->vertices.size() * sizeof(glm::vec3), GL_STATIC_DRAW); + _vao->DefineAttributes(0, 3, GL_FLOAT, GL_FALSE, sizeof(glm::vec3), nullptr); - VertexBuffer vbo2(&mesh->texCoords[0], mesh->texCoords.size() * sizeof(glm::vec2), GL_STATIC_DRAW); - vao->DefineAttributes(1, 2, GL_FLOAT, GL_FALSE, sizeof(glm::vec2), nullptr); + _vboTex = MakeScope(&mesh->texCoords[0], mesh->texCoords.size() * sizeof(glm::vec2), GL_STATIC_DRAW); + _vao->DefineAttributes(1, 2, GL_FLOAT, GL_FALSE, sizeof(glm::vec2), nullptr); - VertexBuffer vbo3(&mesh->normals[0], mesh->normals.size() * sizeof(glm::vec3), GL_STATIC_DRAW); - vao->DefineAttributes(2, 3, GL_FLOAT, GL_FALSE, sizeof(glm::vec3), nullptr); + _vboNorm = MakeScope(&mesh->normals[0], mesh->normals.size() * sizeof(glm::vec3), GL_STATIC_DRAW); + _vao->DefineAttributes(2, 3, GL_FLOAT, GL_FALSE, sizeof(glm::vec3), nullptr); - VertexBuffer vbo4(&mesh->tangents[0], mesh->tangents.size() * sizeof(glm::vec3), GL_STATIC_DRAW); - vao->DefineAttributes(3, 3, GL_FLOAT, GL_FALSE, sizeof(glm::vec3), nullptr); + _vboTang = MakeScope(&mesh->tangents[0], mesh->tangents.size() * sizeof(glm::vec3), GL_STATIC_DRAW); + _vao->DefineAttributes(3, 3, GL_FLOAT, GL_FALSE, sizeof(glm::vec3), nullptr); //Create ibo - IndexBuffer ibo(&mesh->indices[0], mesh->indices.size() * sizeof(uint32)); + _ibo = MakeScope(&mesh->indices[0], mesh->indices.size() * sizeof(uint32)); //Unbind vao - vao->Unbind(); - - return vao; + _vao->Unbind(); } void Model::SetModelMatrix() @@ -53,8 +51,7 @@ namespace Engine // ----- Public ----- Model::Model(Mesh* mesh) - : _vao(CreateVaoFromMesh(mesh)), - _model(glm::mat4(1.0f)), + : _model(glm::mat4(1.0f)), _position(0.0f), _texture1(mesh->texture1), _texture2(mesh->texture2), @@ -65,11 +62,8 @@ namespace Engine _gotNormalMap(mesh->gotNormalMap), _rotationX(0.0f), _rotationY(0.0f), _rotationZ(0.0f), _size(1.0f) - {} - - VertexArray* Model::GetVAO() const { - return _vao.get(); + InitGpuStorage(mesh); } glm::mat4 Model::GetModelMatrix() const @@ -87,6 +81,24 @@ namespace Engine return _gotNormalMap; } + void Model::BindBuffers() const + { + _vao->Bind(); + _vboVert->Bind(); + _vboTex->Bind(); + _vboNorm->Bind(); + _vboTang->Bind(); + } + + void Model::UnbindBuffers() const + { + _vboTang->Unbind(); + _vboNorm->Unbind(); + _vboTex->Unbind(); + _vboVert->Unbind(); + _vao->Unbind(); + } + void Model::ChangePosition(const glm::vec3& position) { _position += position; diff --git a/Engine/Rendering/Renderables/Model.hpp b/Engine/Rendering/Renderables/Model.hpp index cb1acfcc..86a6dd23 100644 --- a/Engine/Rendering/Renderables/Model.hpp +++ b/Engine/Rendering/Renderables/Model.hpp @@ -16,7 +16,9 @@ namespace Engine class Model { private: - Ref _vao; + Scope _vao; + Scope _vboVert, _vboTex, _vboNorm, _vboTang; + Scope _ibo; glm::mat4 _model; glm::vec3 _position; Texture *_texture1, *_texture2, *_texture3, *_texture4, *_texture5; @@ -25,16 +27,17 @@ namespace Engine float _rotationX, _rotationY, _rotationZ; float _size; - static Ref CreateVaoFromMesh(Mesh* mesh); - void SetModelMatrix(); + void InitGpuStorage(Mesh* mesh); + void SetModelMatrix(); public: explicit Model(Mesh* mesh); - [[nodiscard]] VertexArray* GetVAO() const; [[nodiscard]] glm::mat4 GetModelMatrix() const; [[nodiscard]] uint32 GetVerticeCount() const; [[nodiscard]] int32 GotNormalMap() const; + void BindBuffers() const; + void UnbindBuffers() const; void ChangePosition(const glm::vec3& position); void ChangeRotation(float rotX, float rotY, float rotZ); void ChangeSize(float size); diff --git a/Engine/Rendering/Renderables/Sprite.cpp b/Engine/Rendering/Renderables/Sprite.cpp index bb08418c..f7c55783 100644 --- a/Engine/Rendering/Renderables/Sprite.cpp +++ b/Engine/Rendering/Renderables/Sprite.cpp @@ -4,12 +4,8 @@ namespace Engine { // ----- Private ----- - Ref Sprite::CreateSpriteVao() + void Sprite::InitGpuStorage() { - //Create and bind vao - Ref vao = MakeRef(); - vao->Bind(); - //Create data static const float vertices[] = { @@ -23,14 +19,17 @@ namespace Engine 1.0f, 0.0f, 1.0f, 0.0f }; + //Create and bind vao + _vao = MakeScope(); + _vao->Bind(); + //Create vbo, send it data and configure vao - VertexBuffer vbo(vertices, sizeof(vertices), GL_STATIC_DRAW); - vao->DefineAttributes(0, 4, GL_FLOAT, GL_FALSE, 4 * sizeof(float), nullptr); + _vboVert = MakeScope(vertices, sizeof(vertices), GL_STATIC_DRAW); + _vao->DefineAttributes(0, 4, GL_FLOAT, GL_FALSE, 4 * sizeof(float), nullptr); //Unbind vao - vao->Unbind(); - - return vao; + _vao->Unbind(); + _vboVert->Unbind(); } void Sprite::SetModelMatrix() @@ -55,8 +54,7 @@ namespace Engine // ----- Public ----- Sprite::Sprite(Texture* texture, Shader* shader, glm::vec3 color) - : _vao(CreateSpriteVao()), - _model(glm::mat4(1.0f)), + : _model(glm::mat4(1.0f)), _color(color), _texture(texture), _shader(shader), @@ -64,25 +62,38 @@ namespace Engine _size(glm::vec2(1.0f)), _rotation(0.0f), _verticeCount(6) - {} + { + InitGpuStorage(); + } uint32 Sprite::Draw(const glm::mat4& projMatrix) const { + //Bind shader _shader->Bind(); - + + //Bind texture + _texture->Bind(); + + //Bind vao and vbo + _vao->Bind(); + _vboVert->Bind(); + //Set uniforms _shader->SetUniformVec3f("color", _color); _shader->SetUniformMat4f("model", _model); _shader->SetUniformMat4f("projection", projMatrix); - _texture->Bind(); - _vao->Bind(); - //Render quad GLCall(glDrawArrays(GL_TRIANGLES, 0, _verticeCount)); + //Unbind vao and vbo + _vboVert->Unbind(); _vao->Unbind(); + + //Unbind texture _texture->Unbind(); + + //Unbind shader _shader->Unbind(); //Return rendered vertices diff --git a/Engine/Rendering/Renderables/Sprite.hpp b/Engine/Rendering/Renderables/Sprite.hpp index ba93c89b..d0fd4561 100644 --- a/Engine/Rendering/Renderables/Sprite.hpp +++ b/Engine/Rendering/Renderables/Sprite.hpp @@ -14,7 +14,8 @@ namespace Engine class Sprite { private: - Ref _vao; + Scope _vao; + Scope _vboVert; glm::mat4 _model; glm::vec3 _color; Texture* _texture; @@ -24,8 +25,8 @@ namespace Engine float _rotation; uint32 _verticeCount; - static Ref CreateSpriteVao(); - void SetModelMatrix(); + void InitGpuStorage(); + void SetModelMatrix(); public: Sprite(Texture* texture, Shader* shader, glm::vec3 color); diff --git a/Engine/Rendering/Renderer/ParticleRenderer.cpp b/Engine/Rendering/Renderer/ParticleRenderer.cpp index 09eed2fc..c7fbdb78 100644 --- a/Engine/Rendering/Renderer/ParticleRenderer.cpp +++ b/Engine/Rendering/Renderer/ParticleRenderer.cpp @@ -6,10 +6,6 @@ namespace Engine void ParticleRenderer::InitGpuStorage() { - //Create and bind vao - _vao = MakeRef(); - _vao->Bind(); - //Create data static const float vertices[] = { @@ -19,23 +15,27 @@ namespace Engine 0.5f, -0.5f }; + //Create and bind vao + _vao = MakeScope(); + _vao->Bind(); + //Create vbo's, send it data and configure vao - VertexBuffer vboVertices(vertices, sizeof(vertices), GL_STATIC_DRAW); + _vboVert = MakeScope(vertices, sizeof(vertices), GL_STATIC_DRAW); _vao->DefineAttributes(0, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(float), nullptr); - _vboModel = MakeRef(&_modelViewStorage[0], _modelViewStorage.size() * 16 * sizeof(float), GL_DYNAMIC_DRAW); + _vboModel = MakeScope(&_modelViewStorage[0], _modelViewStorage.size() * 16 * sizeof(float), GL_DYNAMIC_DRAW); _vao->DefineAttributes(1, 4, GL_FLOAT, GL_FALSE, 16 * sizeof(float), nullptr); _vao->DefineAttributes(2, 4, GL_FLOAT, GL_FALSE, 16 * sizeof(float), (void*)(4 * sizeof(float))); _vao->DefineAttributes(3, 4, GL_FLOAT, GL_FALSE, 16 * sizeof(float), (void*)(8 * sizeof(float))); _vao->DefineAttributes(4, 4, GL_FLOAT, GL_FALSE, 16 * sizeof(float), (void*)(12 * sizeof(float))); - _vboTex = MakeRef(&_texOffsetStorage[0], _texOffsetStorage.size() * 4 * sizeof(float), GL_DYNAMIC_DRAW); + _vboTex = MakeScope(&_texOffsetStorage[0], _texOffsetStorage.size() * 4 * sizeof(float), GL_DYNAMIC_DRAW); _vao->DefineAttributes(5, 4, GL_FLOAT, GL_FALSE, 4 * sizeof(float), nullptr); - _vboBlend = MakeRef(&_blendFactorStorage[0], _blendFactorStorage.size() * sizeof(float), GL_DYNAMIC_DRAW); + _vboBlend = MakeScope(&_blendFactorStorage[0], _blendFactorStorage.size() * sizeof(float), GL_DYNAMIC_DRAW); _vao->DefineAttributes(6, 1, GL_FLOAT, GL_FALSE, sizeof(float), nullptr); - //Set attribute divisors + //Set attribute divisors for per instance data _vao->AttributeDivisor(1, 1); _vao->AttributeDivisor(2, 1); _vao->AttributeDivisor(3, 1); @@ -45,6 +45,7 @@ namespace Engine //Unbind everything _vao->Unbind(); + _vboVert->Unbind(); _vboModel->Unbind(); _vboTex->Unbind(); _vboBlend->Unbind(); @@ -162,6 +163,7 @@ namespace Engine //Bind vao and vbo's _vao->Bind(); + _vboVert->Bind(); _vboModel->Bind(); _vboTex->Bind(); _vboBlend->Bind(); @@ -202,8 +204,12 @@ namespace Engine _vboBlend->Unbind(); _vboTex->Unbind(); _vboModel->Unbind(); + _vboVert->Unbind(); _vao->Unbind(); + //Unbind texture + _textureAtlas->Unbind(); + //Unbind shader _shader->Unbind(); diff --git a/Engine/Rendering/Renderer/ParticleRenderer.hpp b/Engine/Rendering/Renderer/ParticleRenderer.hpp index 59e7eef0..2b5a4f01 100644 --- a/Engine/Rendering/Renderer/ParticleRenderer.hpp +++ b/Engine/Rendering/Renderer/ParticleRenderer.hpp @@ -18,8 +18,8 @@ namespace Engine class ParticleRenderer { private: - Ref _vao; - Ref _vboModel, _vboTex, _vboBlend; + Scope _vao; + Scope _vboVert, _vboModel, _vboTex, _vboBlend; Texture *_textureAtlas; Shader *_shader; glm::vec3 _position; diff --git a/Engine/Rendering/Renderer/Renderer.cpp b/Engine/Rendering/Renderer/Renderer.cpp index 478b18ce..153607b6 100644 --- a/Engine/Rendering/Renderer/Renderer.cpp +++ b/Engine/Rendering/Renderer/Renderer.cpp @@ -6,23 +6,10 @@ namespace Engine uint32 Renderer::DrawModel(Shader* modelShader, const Model* model) { + //Bind shader modelShader->Bind(); - bool gotNormalMap = model->GotNormalMap(); - //Set uniforms - modelShader->SetUniformMat4f("view", Camera::GetViewMatrix()); - modelShader->SetUniformMat4f("model", model->GetModelMatrix()); - modelShader->SetUniformMat4f("projection", _perspProjection); - modelShader->SetUniformVec3f("viewPos", Camera::GetPosition()); - modelShader->SetUniformVec3f("lightPos", _lightPosition); - modelShader->SetUniformVec3f("lightColor", _lightColor); - modelShader->SetUniformMat4f("lightProjection", _lightProjection); - modelShader->SetUniform1i("diffuseTexture", 0); - modelShader->SetUniform1i("normalMap", 1); - modelShader->SetUniform1i("shadowMap", 2); - modelShader->SetUniform1i("gotNormalMap", gotNormalMap); - - //Get textures + //Get textures and bind depending on existence Texture* texture1 = model->GetTexture1(); Texture* texture2 = model->GetTexture2(); Texture* texture3 = model->GetTexture3(); @@ -39,15 +26,40 @@ namespace Engine if(texture3) texture3->BindToSlot(2); - //Get rendering data - VertexArray* vao = model->GetVAO(); + //Bind buffers and get vertice count + model->BindBuffers(); uint32 verticeCount = model->GetVerticeCount(); + //Set uniforms + modelShader->SetUniformMat4f("view", Camera::GetViewMatrix()); + modelShader->SetUniformMat4f("model", model->GetModelMatrix()); + modelShader->SetUniformMat4f("projection", _perspProjection); + modelShader->SetUniformVec3f("viewPos", Camera::GetPosition()); + modelShader->SetUniformVec3f("lightPos", _lightPosition); + modelShader->SetUniformVec3f("lightColor", _lightColor); + modelShader->SetUniformMat4f("lightProjection", _lightProjection); + modelShader->SetUniform1i("diffuseTexture", 0); + modelShader->SetUniform1i("normalMap", 1); + modelShader->SetUniform1i("shadowMap", 2); + modelShader->SetUniform1i("gotNormalMap", model->GotNormalMap()); + //Render model - vao->Bind(); GLCall(glDrawElements(GL_TRIANGLES, verticeCount, GL_UNSIGNED_INT, nullptr)); - vao->Unbind(); + //Unbind buffers + modelShader->Unbind(); + + //Unbind textures + if(texture1) + texture1->Unbind(); + + if(texture2) + texture2->Unbind(); + + if(texture3) + texture3->Unbind(); + + //Unbind shader modelShader->Unbind(); //Return rendered vertices @@ -56,21 +68,10 @@ namespace Engine uint32 Renderer::DrawTerrain(Shader* terrainShader) { + //Bind shader terrainShader->Bind(); - //Set uniforms - terrainShader->SetUniformMat4f("view", Camera::GetViewMatrix()); - terrainShader->SetUniformMat4f("model", _terrainModel->GetModelMatrix()); - terrainShader->SetUniformMat4f("projection", _perspProjection); - terrainShader->SetUniformVec3f("viewPos", Camera::GetPosition()); - terrainShader->SetUniformVec3f("lightPos", _lightPosition); - terrainShader->SetUniformVec3f("lightColor", _lightColor); - terrainShader->SetUniformMat4f("lightProjection", _lightProjection); - terrainShader->SetUniform1i("diffuseTexture", 0); - terrainShader->SetUniform1i("colorMap", 1); - terrainShader->SetUniform1i("shadowMap", 2); - - //Get textures + //Get textures and bind depending on existence Texture* texture1 = _terrainModel->GetTexture1(); Texture* texture2 = _terrainModel->GetTexture2(); Texture* texture3 = _terrainModel->GetTexture3(); @@ -87,15 +88,39 @@ namespace Engine if(texture3) texture3->BindToSlot(2); - //Get rendering data - VertexArray* vao = _terrainModel->GetVAO(); + //Bind buffers and get vertice count + _terrainModel->BindBuffers(); uint32 verticeCount = _terrainModel->GetVerticeCount(); + //Set uniforms + terrainShader->SetUniformMat4f("view", Camera::GetViewMatrix()); + terrainShader->SetUniformMat4f("model", _terrainModel->GetModelMatrix()); + terrainShader->SetUniformMat4f("projection", _perspProjection); + terrainShader->SetUniformVec3f("viewPos", Camera::GetPosition()); + terrainShader->SetUniformVec3f("lightPos", _lightPosition); + terrainShader->SetUniformVec3f("lightColor", _lightColor); + terrainShader->SetUniformMat4f("lightProjection", _lightProjection); + terrainShader->SetUniform1i("diffuseTexture", 0); + terrainShader->SetUniform1i("colorMap", 1); + terrainShader->SetUniform1i("shadowMap", 2); + //Render model - vao->Bind(); GLCall(glDrawElements(GL_TRIANGLES, verticeCount, GL_UNSIGNED_INT, nullptr)); - vao->Unbind(); + //Unbind buffers + _terrainModel->UnbindBuffers(); + + //Unbind textures + if(texture1) + texture1->Unbind(); + + if(texture2) + texture2->Unbind(); + + if(texture3) + texture3->Unbind(); + + //Unbind shader terrainShader->Unbind(); //Return rendered vertices @@ -104,25 +129,10 @@ namespace Engine uint32 Renderer::DrawWater(Shader* waterShader, float moveFactor) { + //Bind shader waterShader->Bind(); - //Set uniforms - waterShader->SetUniformMat4f("view", Camera::GetViewMatrix()); - waterShader->SetUniformMat4f("model", _waterModel->GetModelMatrix()); - waterShader->SetUniformMat4f("projection", _perspProjection); - waterShader->SetUniformVec3f("viewPos", Camera::GetPosition()); - waterShader->SetUniformVec3f("lightPos", _lightPosition); - waterShader->SetUniformVec3f("lightColor", _lightColor); - waterShader->SetUniform1i("reflectionTexture", 0); - waterShader->SetUniform1i("refractionTexture", 1); - waterShader->SetUniform1i("dudvMap", 2); - waterShader->SetUniform1i("normalMap", 3); - waterShader->SetUniform1i("depthMap", 4); - waterShader->SetUniform1f("moveFactor", moveFactor); - waterShader->SetUniform1f("nearPlane", _nearPlane); - waterShader->SetUniform1f("farPlane", _farPlane); - - //Get textures + //Get textures and bind depending on existence Texture* texture1 = _waterModel->GetTexture1(); Texture* texture2 = _waterModel->GetTexture2(); Texture* texture3 = _waterModel->GetTexture3(); @@ -149,15 +159,49 @@ namespace Engine if(texture5) texture5->BindToSlot(4); - //Get rendering data - VertexArray* vao = _waterModel->GetVAO(); + //Bind buffers and get vertice count + _waterModel->BindBuffers(); uint32 verticeCount = _waterModel->GetVerticeCount(); + //Set uniforms + waterShader->SetUniformMat4f("view", Camera::GetViewMatrix()); + waterShader->SetUniformMat4f("model", _waterModel->GetModelMatrix()); + waterShader->SetUniformMat4f("projection", _perspProjection); + waterShader->SetUniformVec3f("viewPos", Camera::GetPosition()); + waterShader->SetUniformVec3f("lightPos", _lightPosition); + waterShader->SetUniformVec3f("lightColor", _lightColor); + waterShader->SetUniform1i("reflectionTexture", 0); + waterShader->SetUniform1i("refractionTexture", 1); + waterShader->SetUniform1i("dudvMap", 2); + waterShader->SetUniform1i("normalMap", 3); + waterShader->SetUniform1i("depthMap", 4); + waterShader->SetUniform1f("moveFactor", moveFactor); + waterShader->SetUniform1f("nearPlane", _nearPlane); + waterShader->SetUniform1f("farPlane", _farPlane); + //Render model - vao->Bind(); GLCall(glDrawElements(GL_TRIANGLES, verticeCount, GL_UNSIGNED_INT, nullptr)); - vao->Unbind(); + //Unbind buffers + _waterModel->UnbindBuffers(); + + //Unbind textures + if(texture1) + texture1->Unbind(); + + if(texture2) + texture2->Unbind(); + + if(texture3) + texture3->Unbind(); + + if(texture4) + texture4->Unbind(); + + if(texture5) + texture5->Unbind(); + + //Unbind shader waterShader->Unbind(); //Return rendered vertices