diff --git a/opengl/opengl-model/Source/GL/Attributes.hpp b/opengl/opengl-model/Source/GL/Attributes.hpp index 16ff605..258b2fb 100644 --- a/opengl/opengl-model/Source/GL/Attributes.hpp +++ b/opengl/opengl-model/Source/GL/Attributes.hpp @@ -8,60 +8,58 @@ // This class just manages the attributes that the shaders use. struct Attributes { - Attributes(OpenGLContext& openGLContext, OpenGLShaderProgram& shaderProgram) + Attributes(OpenGLShaderProgram& shaderProgram) { - position.reset(createAttribute(openGLContext, shaderProgram, "position")); - normal.reset(createAttribute(openGLContext, shaderProgram, "normal")); - sourceColour.reset(createAttribute(openGLContext, shaderProgram, "sourceColour")); - textureCoordIn.reset(createAttribute(openGLContext, shaderProgram, "textureCoordIn")); + position.reset(createAttribute(shaderProgram, "position")); + normal.reset(createAttribute(shaderProgram, "normal")); + sourceColour.reset(createAttribute(shaderProgram, "sourceColour")); + textureCoordIn.reset(createAttribute(shaderProgram, "textureCoordIn")); } - void enable(OpenGLContext& context) + void enable() { if (position.get() != nullptr) { - context.extensions.glVertexAttribPointer(position->attributeID, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), 0); - context.extensions.glEnableVertexAttribArray(position->attributeID); + glVertexAttribPointer(position->attributeID, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), 0); + glEnableVertexAttribArray(position->attributeID); } if (normal.get() != nullptr) { - context.extensions.glVertexAttribPointer(normal->attributeID, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), - (GLvoid*)(sizeof(float) * 3)); - context.extensions.glEnableVertexAttribArray(normal->attributeID); + glVertexAttribPointer(normal->attributeID, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), + (GLvoid*)(sizeof(float) * 3)); + glEnableVertexAttribArray(normal->attributeID); } if (sourceColour.get() != nullptr) { - context.extensions.glVertexAttribPointer(sourceColour->attributeID, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), - (GLvoid*)(sizeof(float) * 6)); - context.extensions.glEnableVertexAttribArray(sourceColour->attributeID); + glVertexAttribPointer(sourceColour->attributeID, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), + (GLvoid*)(sizeof(float) * 6)); + glEnableVertexAttribArray(sourceColour->attributeID); } if (textureCoordIn.get() != nullptr) { - context.extensions.glVertexAttribPointer(textureCoordIn->attributeID, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), - (GLvoid*)(sizeof(float) * 10)); - context.extensions.glEnableVertexAttribArray(textureCoordIn->attributeID); + glVertexAttribPointer(textureCoordIn->attributeID, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), + (GLvoid*)(sizeof(float) * 10)); + glEnableVertexAttribArray(textureCoordIn->attributeID); } } - void disable(OpenGLContext& context) + void disable() { - if (position.get() != nullptr) context.extensions.glDisableVertexAttribArray(position->attributeID); - if (normal.get() != nullptr) context.extensions.glDisableVertexAttribArray(normal->attributeID); - if (sourceColour.get() != nullptr) context.extensions.glDisableVertexAttribArray(sourceColour->attributeID); - if (textureCoordIn.get() != nullptr) context.extensions.glDisableVertexAttribArray(textureCoordIn->attributeID); + if (position.get() != nullptr) glDisableVertexAttribArray(position->attributeID); + if (normal.get() != nullptr) glDisableVertexAttribArray(normal->attributeID); + if (sourceColour.get() != nullptr) glDisableVertexAttribArray(sourceColour->attributeID); + if (textureCoordIn.get() != nullptr) glDisableVertexAttribArray(textureCoordIn->attributeID); } std::unique_ptr position, normal, sourceColour, textureCoordIn; private: - static OpenGLShaderProgram::Attribute* createAttribute(OpenGLContext& openGLContext, OpenGLShaderProgram& shader, - const String& attributeName) + static OpenGLShaderProgram::Attribute* createAttribute(OpenGLShaderProgram& shader, const String& attributeName) { - if (openGLContext.extensions.glGetAttribLocation(shader.getProgramID(), attributeName.toRawUTF8()) < 0) - return nullptr; + if (glGetAttribLocation(shader.getProgramID(), attributeName.toRawUTF8()) < 0) return nullptr; return new OpenGLShaderProgram::Attribute(shader, attributeName.toRawUTF8()); } diff --git a/opengl/opengl-model/Source/GL/Uniforms.hpp b/opengl/opengl-model/Source/GL/Uniforms.hpp index 7c545e4..142c90c 100644 --- a/opengl/opengl-model/Source/GL/Uniforms.hpp +++ b/opengl/opengl-model/Source/GL/Uniforms.hpp @@ -2,7 +2,6 @@ #include "core/common.hpp" - // This class just manages the uniform values that the demo shaders use. struct Uniforms { diff --git a/opengl/opengl-model/Source/MainComponent.cpp b/opengl/opengl-model/Source/MainComponent.cpp index 2896978..54dcf3d 100644 --- a/opengl/opengl-model/Source/MainComponent.cpp +++ b/opengl/opengl-model/Source/MainComponent.cpp @@ -105,7 +105,7 @@ void MainComponent::render() m_uniforms->viewMatrix->setMatrix4(getViewMatrix().mat, 1, false); } - m_shape->draw(openGLContext, *m_attributes); + m_shape->draw(*m_attributes); // Reset the element buffers so child Components draw correctly glBindBuffer(GL_ARRAY_BUFFER, 0); @@ -226,8 +226,8 @@ void MainComponent::createShaders() m_shader.reset(newShader.release()); m_shader->use(); - m_shape.reset(new Shape(openGLContext)); - m_attributes.reset(new Attributes(openGLContext, *m_shader)); + m_shape.reset(new Shape()); + m_attributes.reset(new Attributes(*m_shader)); m_uniforms.reset(new Uniforms(openGLContext, *m_shader)); statusText = "GLSL: v" + String(OpenGLShaderProgram::getLanguageVersion(), 2); diff --git a/opengl/opengl-model/Source/OBJ/Shape.hpp b/opengl/opengl-model/Source/OBJ/Shape.hpp index 001ab1e..473682b 100644 --- a/opengl/opengl-model/Source/OBJ/Shape.hpp +++ b/opengl/opengl-model/Source/OBJ/Shape.hpp @@ -12,33 +12,33 @@ */ struct Shape { - Shape(OpenGLContext& openGLContext) + Shape() { if (shapeFile.load(String(BinaryData::teapot_obj)).wasOk()) { for (auto* s : shapeFile.shapes) { - vertexBuffers.add(new VertexBuffer(openGLContext, *s)); + vertexBuffers.add(new VertexBuffer(*s)); } } } - void draw(OpenGLContext& context, Attributes& glAttributes) + void draw(Attributes& glAttributes) { for (auto* vertexBuffer : vertexBuffers) { vertexBuffer->bind(); - glAttributes.enable(context); + glAttributes.enable(); glDrawElements(GL_TRIANGLES, vertexBuffer->numIndices, GL_UNSIGNED_INT, 0); - glAttributes.disable(context); + glAttributes.disable(); } } private: struct VertexBuffer { - VertexBuffer(OpenGLContext& context, WavefrontObjFile::Shape& aShape) : openGLContext(context) + VertexBuffer(WavefrontObjFile::Shape& aShape) { numIndices = aShape.mesh.indices.size(); @@ -73,7 +73,6 @@ struct Shape GLuint vertexBuffer, indexBuffer; int numIndices; - OpenGLContext& openGLContext; JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(VertexBuffer) }; @@ -84,8 +83,8 @@ struct Shape static void createVertexListFromMesh(const WavefrontObjFile::Mesh& mesh, Array& list, Colour colour) { auto scale = 0.2f; - WavefrontObjFile::TextureCoord defaultTexCoord{0.5f, 0.5f}; - WavefrontObjFile::Vertex defaultNormal{0.5f, 0.5f, 0.5f}; + WavefrontObjFile::TextureCoord defaultTexCoord {0.5f, 0.5f}; + WavefrontObjFile::Vertex defaultNormal {0.5f, 0.5f, 0.5f}; for (auto i = 0; i < mesh.vertices.size(); ++i) { diff --git a/opengl/opengl-model/Source/OBJ/WavefrontObject.hpp b/opengl/opengl-model/Source/OBJ/WavefrontObject.hpp index d6277b3..55d7679 100644 --- a/opengl/opengl-model/Source/OBJ/WavefrontObject.hpp +++ b/opengl/opengl-model/Source/OBJ/WavefrontObject.hpp @@ -4,7 +4,6 @@ #include "../core/common.hpp" - //============================================================================== /** This is a quick-and-dirty parser for the 3D OBJ file format.