Browse Source

Fix warnings in JUCE OpenGLAppExample

tags/2021-05-28
hogliux 10 years ago
parent
commit
502ab06213
1 changed files with 22 additions and 20 deletions
  1. +22
    -20
      examples/OpenGLAppExample/Source/MainComponent.cpp

+ 22
- 20
examples/OpenGLAppExample/Source/MainComponent.cpp View File

@@ -187,12 +187,12 @@ private:
// This class just manages the attributes that the shaders use. // This class just manages the attributes that the shaders use.
struct Attributes struct Attributes
{ {
Attributes (OpenGLContext& openGLContext, OpenGLShaderProgram& shader)
Attributes (OpenGLContext& openGLContext, OpenGLShaderProgram& shaderProgram)
{ {
position = createAttribute (openGLContext, shader, "position");
normal = createAttribute (openGLContext, shader, "normal");
sourceColour = createAttribute (openGLContext, shader, "sourceColour");
texureCoordIn = createAttribute (openGLContext, shader, "texureCoordIn");
position = createAttribute (openGLContext, shaderProgram, "position");
normal = createAttribute (openGLContext, shaderProgram, "normal");
sourceColour = createAttribute (openGLContext, shaderProgram, "sourceColour");
texureCoordIn = createAttribute (openGLContext, shaderProgram, "texureCoordIn");
} }
void enable (OpenGLContext& openGLContext) void enable (OpenGLContext& openGLContext)
@@ -248,23 +248,23 @@ private:
// This class just manages the uniform values that the demo shaders use. // This class just manages the uniform values that the demo shaders use.
struct Uniforms struct Uniforms
{ {
Uniforms (OpenGLContext& openGLContext, OpenGLShaderProgram& shader)
Uniforms (OpenGLContext& openGLContext, OpenGLShaderProgram& shaderProgram)
{ {
projectionMatrix = createUniform (openGLContext, shader, "projectionMatrix");
viewMatrix = createUniform (openGLContext, shader, "viewMatrix");
projectionMatrix = createUniform (openGLContext, shaderProgram, "projectionMatrix");
viewMatrix = createUniform (openGLContext, shaderProgram, "viewMatrix");
} }
ScopedPointer<OpenGLShaderProgram::Uniform> projectionMatrix, viewMatrix; ScopedPointer<OpenGLShaderProgram::Uniform> projectionMatrix, viewMatrix;
private: private:
static OpenGLShaderProgram::Uniform* createUniform (OpenGLContext& openGLContext, static OpenGLShaderProgram::Uniform* createUniform (OpenGLContext& openGLContext,
OpenGLShaderProgram& shader,
OpenGLShaderProgram& shaderProgram,
const char* uniformName) const char* uniformName)
{ {
if (openGLContext.extensions.glGetUniformLocation (shader.getProgramID(), uniformName) < 0)
if (openGLContext.extensions.glGetUniformLocation (shaderProgram.getProgramID(), uniformName) < 0)
return nullptr; return nullptr;
return new OpenGLShaderProgram::Uniform (shader, uniformName);
return new OpenGLShaderProgram::Uniform (shaderProgram, uniformName);
} }
}; };
@@ -282,39 +282,41 @@ private:
} }
void draw (OpenGLContext& openGLContext, Attributes& attributes)
void draw (OpenGLContext& openGLContext, Attributes& glAttributes)
{ {
for (int i = 0; i < vertexBuffers.size(); ++i) for (int i = 0; i < vertexBuffers.size(); ++i)
{ {
VertexBuffer& vertexBuffer = *vertexBuffers.getUnchecked (i); VertexBuffer& vertexBuffer = *vertexBuffers.getUnchecked (i);
vertexBuffer.bind(); vertexBuffer.bind();
attributes.enable (openGLContext);
glAttributes.enable (openGLContext);
glDrawElements (GL_TRIANGLES, vertexBuffer.numIndices, GL_UNSIGNED_INT, 0); glDrawElements (GL_TRIANGLES, vertexBuffer.numIndices, GL_UNSIGNED_INT, 0);
attributes.disable (openGLContext);
glAttributes.disable (openGLContext);
} }
} }
private: private:
struct VertexBuffer struct VertexBuffer
{ {
VertexBuffer (OpenGLContext& context, WavefrontObjFile::Shape& shape) : openGLContext (context)
VertexBuffer (OpenGLContext& context, WavefrontObjFile::Shape& aShape) : openGLContext (context)
{ {
numIndices = shape.mesh.indices.size();
numIndices = aShape.mesh.indices.size();
openGLContext.extensions.glGenBuffers (1, &vertexBuffer); openGLContext.extensions.glGenBuffers (1, &vertexBuffer);
openGLContext.extensions.glBindBuffer (GL_ARRAY_BUFFER, vertexBuffer); openGLContext.extensions.glBindBuffer (GL_ARRAY_BUFFER, vertexBuffer);
Array<Vertex> vertices; Array<Vertex> vertices;
createVertexListFromMesh (shape.mesh, vertices, Colours::green);
createVertexListFromMesh (aShape.mesh, vertices, Colours::green);
openGLContext.extensions.glBufferData (GL_ARRAY_BUFFER, vertices.size() * sizeof (Vertex),
openGLContext.extensions.glBufferData (GL_ARRAY_BUFFER,
static_cast<GLsizeiptr> (static_cast<size_t> (vertices.size()) * sizeof (Vertex)),
vertices.getRawDataPointer(), GL_STATIC_DRAW); vertices.getRawDataPointer(), GL_STATIC_DRAW);
openGLContext.extensions.glGenBuffers (1, &indexBuffer); openGLContext.extensions.glGenBuffers (1, &indexBuffer);
openGLContext.extensions.glBindBuffer (GL_ELEMENT_ARRAY_BUFFER, indexBuffer); openGLContext.extensions.glBindBuffer (GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
openGLContext.extensions.glBufferData (GL_ELEMENT_ARRAY_BUFFER, numIndices * sizeof (juce::uint32),
shape.mesh.indices.getRawDataPointer(), GL_STATIC_DRAW);
openGLContext.extensions.glBufferData (GL_ELEMENT_ARRAY_BUFFER,
static_cast<GLsizeiptr> (static_cast<size_t> (numIndices) * sizeof (juce::uint32)),
aShape.mesh.indices.getRawDataPointer(), GL_STATIC_DRAW);
} }
~VertexBuffer() ~VertexBuffer()


Loading…
Cancel
Save