Commit 57a8972e by Jamie Madill Committed by Shannon Woods

Add implementation for Vertex Array Object state.

TRAC #23390 Signed-off-by: Shannon Woods Signed-off-by: Geoff Lang Authored-by: Jamie Madill
parent a857c36b
......@@ -377,6 +377,8 @@
'libGLESv2/Texture.h',
'libGLESv2/Uniform.cpp',
'libGLESv2/Uniform.h',
'libGLESv2/VertexArray.cpp',
'libGLESv2/VertexArray.h',
'libGLESv2/VertexAttribute.h',
],
# TODO(jschuh): http://crbug.com/167187 size_t -> int
......
......@@ -67,6 +67,8 @@ class Fence;
class Query;
class ResourceManager;
class Buffer;
class VertexAttribute;
class VertexArray;
enum QueryType
{
......@@ -108,14 +110,13 @@ struct State
unsigned int activeSampler; // Active texture unit selector - GL_TEXTURE0
BindingPointer<Buffer> arrayBuffer;
BindingPointer<Buffer> elementArrayBuffer;
GLuint readFramebuffer;
GLuint drawFramebuffer;
BindingPointer<Renderbuffer> renderbuffer;
GLuint currentProgram;
VertexAttribCurrentValueData vertexAttribCurrentValues[MAX_VERTEX_ATTRIBS]; // From glVertexAttrib
VertexAttribute vertexAttribute[MAX_VERTEX_ATTRIBS];
unsigned int vertexArray;
BindingPointer<Texture> samplerTexture[TEXTURE_TYPE_COUNT][IMPLEMENTATION_MAX_COMBINED_TEXTURE_IMAGE_UNITS];
BindingPointer<Query> activeQuery[QUERY_TYPE_COUNT];
......@@ -251,12 +252,14 @@ class Context
GLuint createProgram();
GLuint createTexture();
GLuint createRenderbuffer();
GLuint createVertexArray();
void deleteBuffer(GLuint buffer);
void deleteShader(GLuint shader);
void deleteProgram(GLuint program);
void deleteTexture(GLuint texture);
void deleteRenderbuffer(GLuint renderbuffer);
void deleteVertexArray(GLuint vertexArray);
// Framebuffers are owned by the Context, so these methods do not pass through
GLuint createFramebuffer();
......@@ -279,6 +282,7 @@ class Context
void bindReadFramebuffer(GLuint framebuffer);
void bindDrawFramebuffer(GLuint framebuffer);
void bindRenderbuffer(GLuint renderbuffer);
void bindVertexArray(GLuint vertexArray);
void bindGenericUniformBuffer(GLuint buffer);
void bindIndexedUniformBuffer(GLuint buffer, GLuint index, GLintptr offset, GLsizeiptr size);
void bindGenericTransformFeedbackBuffer(GLuint buffer);
......@@ -310,6 +314,7 @@ class Context
Texture *getTexture(GLuint handle);
Framebuffer *getFramebuffer(GLuint handle);
Renderbuffer *getRenderbuffer(GLuint handle);
VertexArray *getVertexArray(GLuint handle) const;
Query *getQuery(GLuint handle, bool create, GLenum type);
Buffer *getArrayBuffer();
......@@ -328,6 +333,7 @@ class Context
Texture *getSamplerTexture(unsigned int sampler, TextureType type);
Framebuffer *getReadFramebuffer();
Framebuffer *getDrawFramebuffer();
VertexArray *getCurrentVertexArray() const;
bool getFloatv(GLenum pname, GLfloat *params);
bool getIntegerv(GLenum pname, GLint *params);
......@@ -421,6 +427,7 @@ class Context
void detachTexture(GLuint texture);
void detachFramebuffer(GLuint framebuffer);
void detachRenderbuffer(GLuint renderbuffer);
void detachVertexArray(GLuint vertexArray);
Texture *getIncompleteTexture(TextureType type);
......@@ -460,6 +467,10 @@ class Context
QueryMap mQueryMap;
HandleAllocator mQueryHandleAllocator;
typedef HASH_MAP<GLuint, VertexArray*> VertexArrayMap;
VertexArrayMap mVertexArrayMap;
HandleAllocator mVertexArrayHandleAllocator;
std::vector<std::string> mExtensionStringList;
const char *mCombinedExtensionsString;
const char *mRendererString;
......
#include "precompiled.h"
//
// Copyright (c) 2013 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Implementation of the state class for mananging GLES 3 Vertex Array Objects.
//
#include "libGLESv2/VertexArray.h"
#include "libGLESv2/Buffer.h"
namespace gl
{
VertexArray::VertexArray(rx::Renderer *renderer, GLuint id)
: RefCountObject(id)
{
for (int i = 0; i < MAX_VERTEX_ATTRIBS; i++)
{
mVertexAttributes[i].mBoundBuffer.set(NULL);
}
mElementArrayBuffer.set(NULL);
}
void VertexArray::detachBuffer(GLuint bufferName)
{
for (int attribute = 0; attribute < MAX_VERTEX_ATTRIBS; attribute++)
{
if (mVertexAttributes[attribute].mBoundBuffer.id() == bufferName)
{
mVertexAttributes[attribute].mBoundBuffer.set(NULL);
}
}
if (mElementArrayBuffer.id() == bufferName)
{
mElementArrayBuffer.set(NULL);
}
}
const VertexAttribute& VertexArray::getVertexAttribute(unsigned int attributeIndex) const
{
ASSERT(attributeIndex < MAX_VERTEX_ATTRIBS);
return mVertexAttributes[attributeIndex];
}
void VertexArray::setVertexAttribDivisor(GLuint index, GLuint divisor)
{
ASSERT(index < gl::MAX_VERTEX_ATTRIBS);
mVertexAttributes[index].mDivisor = divisor;
}
void VertexArray::enableAttribute(unsigned int attributeIndex, bool enabledState)
{
ASSERT(attributeIndex < gl::MAX_VERTEX_ATTRIBS);
mVertexAttributes[attributeIndex].mArrayEnabled = enabledState;
}
void VertexArray::setAttributeState(unsigned int attributeIndex, gl::Buffer *boundBuffer, GLint size, GLenum type,
bool normalized, bool pureInteger, GLsizei stride, const void *pointer)
{
ASSERT(attributeIndex < gl::MAX_VERTEX_ATTRIBS);
mVertexAttributes[attributeIndex].setState(boundBuffer, size, type, normalized, pureInteger, stride, pointer);
}
}
\ No newline at end of file
//
// Copyright (c) 2013 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// This class contains prototypes for representing GLES 3 Vertex Array Objects:
//
// The buffer objects that are to be used by the vertex stage of the GL are collected
// together to form a vertex array object. All state related to the definition of data used
// by the vertex processor is encapsulated in a vertex array object.
//
#ifndef LIBGLESV2_VERTEXARRAY_H_
#define LIBGLESV2_VERTEXARRAY_H_
#include "common/RefCountObject.h"
#include "libGLESv2/constants.h"
#include "libGLESv2/VertexAttribute.h"
namespace rx
{
class Renderer;
}
namespace gl
{
class Buffer;
class VertexArray : public RefCountObject
{
public:
VertexArray(rx::Renderer *renderer, GLuint id);
const VertexAttribute& getVertexAttribute(unsigned int attributeIndex) const;
void detachBuffer(GLuint bufferName);
void setVertexAttribDivisor(GLuint index, GLuint divisor);
void enableAttribute(unsigned int attributeIndex, bool enabledState);
void setAttributeState(unsigned int attributeIndex, gl::Buffer *boundBuffer, GLint size, GLenum type,
bool normalized, bool pureInteger, GLsizei stride, const void *pointer);
const VertexAttribute* getVertexAttributes() const { return mVertexAttributes; }
Buffer *getElementArrayBuffer() const { return mElementArrayBuffer.get(); }
void setElementArrayBuffer(Buffer *elementArrayBuffer) { mElementArrayBuffer.set(elementArrayBuffer); }
GLuint getElementArrayBufferId() const { return mElementArrayBuffer.id(); }
private:
VertexAttribute mVertexAttributes[MAX_VERTEX_ATTRIBS];
BindingPointer<Buffer> mElementArrayBuffer;
};
}
#endif // LIBGLESV2_VERTEXARRAY_H_
......@@ -9,11 +9,10 @@
#ifndef LIBGLESV2_VERTEXATTRIBUTE_H_
#define LIBGLESV2_VERTEXATTRIBUTE_H_
#include "common/RefCountObject.h"
#include "libGLESv2/Buffer.h"
namespace gl
{
class Buffer;
class VertexAttribute
{
......@@ -47,6 +46,18 @@ class VertexAttribute
return mStride ? mStride : typeSize();
}
void setState(gl::Buffer *boundBuffer, GLint size, GLenum type, bool normalized,
bool pureInteger, GLsizei stride, const void *pointer)
{
mBoundBuffer.set(boundBuffer);
mSize = size;
mType = type;
mNormalized = normalized;
mPureInteger = pureInteger;
mStride = stride;
mPointer = pointer;
}
// From glVertexAttribPointer
GLenum mType;
GLint mSize;
......
......@@ -21,6 +21,7 @@
#include "libGLESv2/Texture.h"
#include "libGLESv2/Query.h"
#include "libGLESv2/Context.h"
#include "libGLESv2/VertexArray.h"
bool validImageSize(const gl::Context *context, GLint level, GLsizei width, GLsizei height, GLsizei depth)
{
......
......@@ -313,6 +313,7 @@ copy "$(OutDir)libGLESv2.lib" "$(ProjectDir)..\..\lib\$(Configuration)\"
<ClCompile Include="Shader.cpp" />
<ClCompile Include="Texture.cpp" />
<ClCompile Include="Uniform.cpp" />
<ClCompile Include="VertexArray.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\include\GLES2\gl2.h" />
......@@ -439,6 +440,7 @@ copy "$(OutDir)libGLESv2.lib" "$(ProjectDir)..\..\lib\$(Configuration)\"
<ClInclude Include="Uniform.h" />
<ClInclude Include="..\common\version.h" />
<ClInclude Include="VertexAttribute.h" />
<ClInclude Include="VertexArray.h" />
</ItemGroup>
<ItemGroup>
<None Include="libGLESv2.def" />
......
......@@ -239,6 +239,9 @@
<ClCompile Include="renderer\Blit11.cpp">
<Filter>Source Files\Renderer11</Filter>
</ClCompile>
<ClCompile Include="VertexArray.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="BinaryStream.h">
......@@ -619,6 +622,9 @@
<ClInclude Include="VertexAttribute.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="VertexArray.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="renderer\shaders\Blit.ps">
......
......@@ -131,7 +131,7 @@ class Renderer
virtual void applyShaders(gl::ProgramBinary *programBinary) = 0;
virtual void applyUniforms(gl::ProgramBinary *programBinary, gl::UniformArray *uniformArray) = 0;
virtual bool applyPrimitiveType(GLenum primitiveType, GLsizei elementCount) = 0;
virtual GLenum applyVertexBuffer(gl::ProgramBinary *programBinary, gl::VertexAttribute vertexAttributes[], gl::VertexAttribCurrentValueData currentValues[],
virtual GLenum applyVertexBuffer(gl::ProgramBinary *programBinary, const gl::VertexAttribute vertexAttributes[], gl::VertexAttribCurrentValueData currentValues[],
GLint first, GLsizei count, GLsizei instances) = 0;
virtual GLenum applyIndexBuffer(const GLvoid *indices, gl::Buffer *elementArrayBuffer, GLsizei count, GLenum mode, GLenum type, TranslatedIndexData *indexInfo) = 0;
......
......@@ -1034,7 +1034,7 @@ bool Renderer11::applyRenderTarget(gl::Framebuffer *framebuffer)
return true;
}
GLenum Renderer11::applyVertexBuffer(gl::ProgramBinary *programBinary, gl::VertexAttribute vertexAttributes[], gl::VertexAttribCurrentValueData currentValues[],
GLenum Renderer11::applyVertexBuffer(gl::ProgramBinary *programBinary, const gl::VertexAttribute vertexAttributes[], gl::VertexAttribCurrentValueData currentValues[],
GLint first, GLsizei count, GLsizei instances)
{
TranslatedAttribute attributes[gl::MAX_VERTEX_ATTRIBS];
......
......@@ -74,7 +74,7 @@ class Renderer11 : public Renderer
virtual bool applyRenderTarget(gl::Framebuffer *frameBuffer);
virtual void applyShaders(gl::ProgramBinary *programBinary);
virtual void applyUniforms(gl::ProgramBinary *programBinary, gl::UniformArray *uniformArray);
virtual GLenum applyVertexBuffer(gl::ProgramBinary *programBinary, gl::VertexAttribute vertexAttributes[], gl::VertexAttribCurrentValueData currentValues[],
virtual GLenum applyVertexBuffer(gl::ProgramBinary *programBinary, const gl::VertexAttribute vertexAttributes[], gl::VertexAttribCurrentValueData currentValues[],
GLint first, GLsizei count, GLsizei instances);
virtual GLenum applyIndexBuffer(const GLvoid *indices, gl::Buffer *elementArrayBuffer, GLsizei count, GLenum mode, GLenum type, TranslatedIndexData *indexInfo);
......
......@@ -1338,7 +1338,7 @@ bool Renderer9::applyRenderTarget(gl::Framebuffer *framebuffer)
return true;
}
GLenum Renderer9::applyVertexBuffer(gl::ProgramBinary *programBinary, gl::VertexAttribute vertexAttributes[], gl::VertexAttribCurrentValueData currentValues[],
GLenum Renderer9::applyVertexBuffer(gl::ProgramBinary *programBinary, const gl::VertexAttribute vertexAttributes[], gl::VertexAttribCurrentValueData currentValues[],
GLint first, GLsizei count, GLsizei instances)
{
TranslatedAttribute attributes[gl::MAX_VERTEX_ATTRIBS];
......
......@@ -88,7 +88,7 @@ class Renderer9 : public Renderer
virtual void applyShaders(gl::ProgramBinary *programBinary);
virtual void applyUniforms(gl::ProgramBinary *programBinary, gl::UniformArray *uniformArray);
virtual bool applyPrimitiveType(GLenum primitiveType, GLsizei elementCount);
virtual GLenum applyVertexBuffer(gl::ProgramBinary *programBinary, gl::VertexAttribute vertexAttributes[], gl::VertexAttribCurrentValueData currentValues[],
virtual GLenum applyVertexBuffer(gl::ProgramBinary *programBinary, const gl::VertexAttribute vertexAttributes[], gl::VertexAttribCurrentValueData currentValues[],
GLint first, GLsizei count, GLsizei instances);
virtual GLenum applyIndexBuffer(const GLvoid *indices, gl::Buffer *elementArrayBuffer, GLsizei count, GLenum mode, GLenum type, TranslatedIndexData *indexInfo);
......
......@@ -18,6 +18,7 @@ namespace gl
{
class VertexAttribute;
class ProgramBinary;
struct VertexAttribCurrentValueData;
}
namespace rx
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment