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 @@ ...@@ -377,6 +377,8 @@
'libGLESv2/Texture.h', 'libGLESv2/Texture.h',
'libGLESv2/Uniform.cpp', 'libGLESv2/Uniform.cpp',
'libGLESv2/Uniform.h', 'libGLESv2/Uniform.h',
'libGLESv2/VertexArray.cpp',
'libGLESv2/VertexArray.h',
'libGLESv2/VertexAttribute.h', 'libGLESv2/VertexAttribute.h',
], ],
# TODO(jschuh): http://crbug.com/167187 size_t -> int # TODO(jschuh): http://crbug.com/167187 size_t -> int
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "libGLESv2/renderer/IndexDataManager.h" #include "libGLESv2/renderer/IndexDataManager.h"
#include "libGLESv2/renderer/RenderTarget.h" #include "libGLESv2/renderer/RenderTarget.h"
#include "libGLESv2/renderer/Renderer.h" #include "libGLESv2/renderer/Renderer.h"
#include "libGLESv2/VertexArray.h"
#include "libEGL/Surface.h" #include "libEGL/Surface.h"
...@@ -147,6 +148,7 @@ Context::Context(int clientVersion, const gl::Context *shareContext, rx::Rendere ...@@ -147,6 +148,7 @@ Context::Context(int clientVersion, const gl::Context *shareContext, rx::Rendere
mTexture2DArrayZero.set(new Texture2DArray(mRenderer, 0)); mTexture2DArrayZero.set(new Texture2DArray(mRenderer, 0));
mState.activeSampler = 0; mState.activeSampler = 0;
bindVertexArray(0);
bindArrayBuffer(0); bindArrayBuffer(0);
bindElementArrayBuffer(0); bindElementArrayBuffer(0);
bindTextureCubeMap(0); bindTextureCubeMap(0);
...@@ -231,6 +233,11 @@ Context::~Context() ...@@ -231,6 +233,11 @@ Context::~Context()
deleteQuery(mQueryMap.begin()->first); deleteQuery(mQueryMap.begin()->first);
} }
while (!mVertexArrayMap.empty())
{
deleteVertexArray(mVertexArrayMap.begin()->first);
}
for (int type = 0; type < TEXTURE_TYPE_COUNT; type++) for (int type = 0; type < TEXTURE_TYPE_COUNT; type++)
{ {
for (int sampler = 0; sampler < IMPLEMENTATION_MAX_COMBINED_TEXTURE_IMAGE_UNITS; sampler++) for (int sampler = 0; sampler < IMPLEMENTATION_MAX_COMBINED_TEXTURE_IMAGE_UNITS; sampler++)
...@@ -248,7 +255,6 @@ Context::~Context() ...@@ -248,7 +255,6 @@ Context::~Context()
for (int attribIndex = 0; attribIndex < MAX_VERTEX_ATTRIBS; attribIndex++) for (int attribIndex = 0; attribIndex < MAX_VERTEX_ATTRIBS; attribIndex++)
{ {
mState.vertexAttribCurrentValues[attribIndex].setFloatValues(defaultFloatValues); mState.vertexAttribCurrentValues[attribIndex].setFloatValues(defaultFloatValues);
mState.vertexAttribute[attribIndex].mBoundBuffer.set(NULL);
} }
for (int i = 0; i < QUERY_TYPE_COUNT; i++) for (int i = 0; i < QUERY_TYPE_COUNT; i++)
...@@ -257,7 +263,6 @@ Context::~Context() ...@@ -257,7 +263,6 @@ Context::~Context()
} }
mState.arrayBuffer.set(NULL); mState.arrayBuffer.set(NULL);
mState.elementArrayBuffer.set(NULL);
mState.renderbuffer.set(NULL); mState.renderbuffer.set(NULL);
mTexture2DZero.set(NULL); mTexture2DZero.set(NULL);
...@@ -687,14 +692,12 @@ GLuint Context::getActiveQuery(GLenum target) const ...@@ -687,14 +692,12 @@ GLuint Context::getActiveQuery(GLenum target) const
void Context::setEnableVertexAttribArray(unsigned int attribNum, bool enabled) void Context::setEnableVertexAttribArray(unsigned int attribNum, bool enabled)
{ {
ASSERT(attribNum < MAX_VERTEX_ATTRIBS); getCurrentVertexArray()->enableAttribute(attribNum, enabled);
mState.vertexAttribute[attribNum].mArrayEnabled = enabled;
} }
const VertexAttribute &Context::getVertexAttribState(unsigned int attribNum) const const VertexAttribute &Context::getVertexAttribState(unsigned int attribNum) const
{ {
ASSERT(attribNum < MAX_VERTEX_ATTRIBS); return getCurrentVertexArray()->getVertexAttribute(attribNum);
return mState.vertexAttribute[attribNum];
} }
const VertexAttribCurrentValueData &Context::getVertexAttribCurrentValue(unsigned int attribNum) const const VertexAttribCurrentValueData &Context::getVertexAttribCurrentValue(unsigned int attribNum) const
...@@ -706,18 +709,12 @@ const VertexAttribCurrentValueData &Context::getVertexAttribCurrentValue(unsigne ...@@ -706,18 +709,12 @@ const VertexAttribCurrentValueData &Context::getVertexAttribCurrentValue(unsigne
void Context::setVertexAttribState(unsigned int attribNum, Buffer *boundBuffer, GLint size, GLenum type, bool normalized, void Context::setVertexAttribState(unsigned int attribNum, Buffer *boundBuffer, GLint size, GLenum type, bool normalized,
bool pureInteger, GLsizei stride, const void *pointer) bool pureInteger, GLsizei stride, const void *pointer)
{ {
mState.vertexAttribute[attribNum].mBoundBuffer.set(boundBuffer); getCurrentVertexArray()->setAttributeState(attribNum, boundBuffer, size, type, normalized, pureInteger, stride, pointer);
mState.vertexAttribute[attribNum].mSize = size;
mState.vertexAttribute[attribNum].mType = type;
mState.vertexAttribute[attribNum].mNormalized = normalized;
mState.vertexAttribute[attribNum].mPureInteger = pureInteger;
mState.vertexAttribute[attribNum].mStride = stride;
mState.vertexAttribute[attribNum].mPointer = pointer;
} }
const void *Context::getVertexAttribPointer(unsigned int attribNum) const const void *Context::getVertexAttribPointer(unsigned int attribNum) const
{ {
return mState.vertexAttribute[attribNum].mPointer; return getCurrentVertexArray()->getVertexAttribute(attribNum).mPointer;
} }
void Context::setPackAlignment(GLint alignment) void Context::setPackAlignment(GLint alignment)
...@@ -775,6 +772,15 @@ GLuint Context::createRenderbuffer() ...@@ -775,6 +772,15 @@ GLuint Context::createRenderbuffer()
return mResourceManager->createRenderbuffer(); return mResourceManager->createRenderbuffer();
} }
GLuint Context::createVertexArray()
{
GLuint handle = mVertexArrayHandleAllocator.allocate();
mVertexArrayMap[handle] = new VertexArray(mRenderer, handle);
return handle;
}
// Returns an unused framebuffer name // Returns an unused framebuffer name
GLuint Context::createFramebuffer() GLuint Context::createFramebuffer()
{ {
...@@ -844,6 +850,20 @@ void Context::deleteRenderbuffer(GLuint renderbuffer) ...@@ -844,6 +850,20 @@ void Context::deleteRenderbuffer(GLuint renderbuffer)
mResourceManager->deleteRenderbuffer(renderbuffer); mResourceManager->deleteRenderbuffer(renderbuffer);
} }
void Context::deleteVertexArray(GLuint vertexArray)
{
auto vertexArrayObject = mVertexArrayMap.find(vertexArray);
if (vertexArrayObject != mVertexArrayMap.end())
{
detachVertexArray(vertexArray);
mVertexArrayHandleAllocator.release(vertexArrayObject->first);
delete vertexArrayObject->second;
mVertexArrayMap.erase(vertexArrayObject);
}
}
void Context::deleteFramebuffer(GLuint framebuffer) void Context::deleteFramebuffer(GLuint framebuffer)
{ {
FramebufferMap::iterator framebufferObject = mFramebufferMap.find(framebuffer); FramebufferMap::iterator framebufferObject = mFramebufferMap.find(framebuffer);
...@@ -909,6 +929,20 @@ Renderbuffer *Context::getRenderbuffer(GLuint handle) ...@@ -909,6 +929,20 @@ Renderbuffer *Context::getRenderbuffer(GLuint handle)
return mResourceManager->getRenderbuffer(handle); return mResourceManager->getRenderbuffer(handle);
} }
VertexArray *Context::getVertexArray(GLuint handle) const
{
auto vertexArray = mVertexArrayMap.find(handle);
if (vertexArray == mVertexArrayMap.end())
{
return NULL;
}
else
{
return vertexArray->second;
}
}
Framebuffer *Context::getReadFramebuffer() Framebuffer *Context::getReadFramebuffer()
{ {
return getFramebuffer(mState.readFramebuffer); return getFramebuffer(mState.readFramebuffer);
...@@ -919,6 +953,13 @@ Framebuffer *Context::getDrawFramebuffer() ...@@ -919,6 +953,13 @@ Framebuffer *Context::getDrawFramebuffer()
return mBoundDrawFramebuffer; return mBoundDrawFramebuffer;
} }
VertexArray *Context::getCurrentVertexArray() const
{
VertexArray *vao = getVertexArray(mState.vertexArray);
ASSERT(vao != NULL);
return vao;
}
void Context::bindArrayBuffer(unsigned int buffer) void Context::bindArrayBuffer(unsigned int buffer)
{ {
mResourceManager->checkBufferAllocation(buffer); mResourceManager->checkBufferAllocation(buffer);
...@@ -930,7 +971,7 @@ void Context::bindElementArrayBuffer(unsigned int buffer) ...@@ -930,7 +971,7 @@ void Context::bindElementArrayBuffer(unsigned int buffer)
{ {
mResourceManager->checkBufferAllocation(buffer); mResourceManager->checkBufferAllocation(buffer);
mState.elementArrayBuffer.set(getBuffer(buffer)); getCurrentVertexArray()->setElementArrayBuffer(getBuffer(buffer));
} }
void Context::bindTexture2D(GLuint texture) void Context::bindTexture2D(GLuint texture)
...@@ -990,6 +1031,16 @@ void Context::bindRenderbuffer(GLuint renderbuffer) ...@@ -990,6 +1031,16 @@ void Context::bindRenderbuffer(GLuint renderbuffer)
mState.renderbuffer.set(getRenderbuffer(renderbuffer)); mState.renderbuffer.set(getRenderbuffer(renderbuffer));
} }
void Context::bindVertexArray(GLuint vertexArray)
{
if (!getVertexArray(vertexArray))
{
mVertexArrayMap[vertexArray] = new VertexArray(mRenderer, vertexArray);
}
mState.vertexArray = vertexArray;
}
void Context::bindGenericUniformBuffer(GLuint buffer) void Context::bindGenericUniformBuffer(GLuint buffer)
{ {
mResourceManager->checkBufferAllocation(buffer); mResourceManager->checkBufferAllocation(buffer);
...@@ -1286,7 +1337,7 @@ Buffer *Context::getArrayBuffer() ...@@ -1286,7 +1337,7 @@ Buffer *Context::getArrayBuffer()
Buffer *Context::getElementArrayBuffer() Buffer *Context::getElementArrayBuffer()
{ {
return mState.elementArrayBuffer.get(); return getCurrentVertexArray()->getElementArrayBuffer();
} }
ProgramBinary *Context::getCurrentProgramBinary() ProgramBinary *Context::getCurrentProgramBinary()
...@@ -1483,7 +1534,7 @@ bool Context::getIntegerv(GLenum pname, GLint *params) ...@@ -1483,7 +1534,7 @@ bool Context::getIntegerv(GLenum pname, GLint *params)
case GL_NUM_SHADER_BINARY_FORMATS: *params = 0; break; case GL_NUM_SHADER_BINARY_FORMATS: *params = 0; break;
case GL_SHADER_BINARY_FORMATS: /* no shader binary formats are supported */ break; case GL_SHADER_BINARY_FORMATS: /* no shader binary formats are supported */ break;
case GL_ARRAY_BUFFER_BINDING: *params = mState.arrayBuffer.id(); break; case GL_ARRAY_BUFFER_BINDING: *params = mState.arrayBuffer.id(); break;
case GL_ELEMENT_ARRAY_BUFFER_BINDING: *params = mState.elementArrayBuffer.id(); break; case GL_ELEMENT_ARRAY_BUFFER_BINDING: *params = getCurrentVertexArray()->getElementArrayBufferId(); break;
//case GL_FRAMEBUFFER_BINDING: // now equivalent to GL_DRAW_FRAMEBUFFER_BINDING_ANGLE //case GL_FRAMEBUFFER_BINDING: // now equivalent to GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE: *params = mState.drawFramebuffer; break; case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE: *params = mState.drawFramebuffer; break;
case GL_READ_FRAMEBUFFER_BINDING_ANGLE: *params = mState.readFramebuffer; break; case GL_READ_FRAMEBUFFER_BINDING_ANGLE: *params = mState.readFramebuffer; break;
...@@ -2266,7 +2317,7 @@ void Context::drawArrays(GLenum mode, GLint first, GLsizei count, GLsizei instan ...@@ -2266,7 +2317,7 @@ void Context::drawArrays(GLenum mode, GLint first, GLsizei count, GLsizei instan
ProgramBinary *programBinary = getCurrentProgramBinary(); ProgramBinary *programBinary = getCurrentProgramBinary();
GLenum err = mRenderer->applyVertexBuffer(programBinary, mState.vertexAttribute, mState.vertexAttribCurrentValues, first, count, instances); GLenum err = mRenderer->applyVertexBuffer(programBinary, getCurrentVertexArray()->getVertexAttributes(), mState.vertexAttribCurrentValues, first, count, instances);
if (err != GL_NO_ERROR) if (err != GL_NO_ERROR)
{ {
return gl::error(err); return gl::error(err);
...@@ -2298,7 +2349,8 @@ void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid ...@@ -2298,7 +2349,8 @@ void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid
return gl::error(GL_INVALID_OPERATION); return gl::error(GL_INVALID_OPERATION);
} }
if (!indices && !mState.elementArrayBuffer) VertexArray *vao = getCurrentVertexArray();
if (!indices && !vao->getElementArrayBuffer())
{ {
return gl::error(GL_INVALID_OPERATION); return gl::error(GL_INVALID_OPERATION);
} }
...@@ -2316,7 +2368,7 @@ void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid ...@@ -2316,7 +2368,7 @@ void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid
applyState(mode); applyState(mode);
rx::TranslatedIndexData indexInfo; rx::TranslatedIndexData indexInfo;
GLenum err = mRenderer->applyIndexBuffer(indices, mState.elementArrayBuffer.get(), count, mode, type, &indexInfo); GLenum err = mRenderer->applyIndexBuffer(indices, vao->getElementArrayBuffer(), count, mode, type, &indexInfo);
if (err != GL_NO_ERROR) if (err != GL_NO_ERROR)
{ {
return gl::error(err); return gl::error(err);
...@@ -2325,7 +2377,7 @@ void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid ...@@ -2325,7 +2377,7 @@ void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid
ProgramBinary *programBinary = getCurrentProgramBinary(); ProgramBinary *programBinary = getCurrentProgramBinary();
GLsizei vertexCount = indexInfo.maxIndex - indexInfo.minIndex + 1; GLsizei vertexCount = indexInfo.maxIndex - indexInfo.minIndex + 1;
err = mRenderer->applyVertexBuffer(programBinary, mState.vertexAttribute, mState.vertexAttribCurrentValues, indexInfo.minIndex, vertexCount, instances); err = mRenderer->applyVertexBuffer(programBinary, vao->getVertexAttributes(), mState.vertexAttribCurrentValues, indexInfo.minIndex, vertexCount, instances);
if (err != GL_NO_ERROR) if (err != GL_NO_ERROR)
{ {
return gl::error(err); return gl::error(err);
...@@ -2346,7 +2398,7 @@ void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid ...@@ -2346,7 +2398,7 @@ void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid
if (!skipDraw(mode)) if (!skipDraw(mode))
{ {
mRenderer->drawElements(mode, count, type, indices, mState.elementArrayBuffer.get(), indexInfo, instances); mRenderer->drawElements(mode, count, type, indices, vao->getElementArrayBuffer(), indexInfo, instances);
} }
} }
...@@ -2666,17 +2718,10 @@ void Context::detachBuffer(GLuint buffer) ...@@ -2666,17 +2718,10 @@ void Context::detachBuffer(GLuint buffer)
mState.arrayBuffer.set(NULL); mState.arrayBuffer.set(NULL);
} }
if (mState.elementArrayBuffer.id() == buffer) // mark as freed among the vertex array objects
for (auto vaoIt = mVertexArrayMap.begin(); vaoIt != mVertexArrayMap.end(); vaoIt++)
{ {
mState.elementArrayBuffer.set(NULL); vaoIt->second->detachBuffer(buffer);
}
for (int attribute = 0; attribute < MAX_VERTEX_ATTRIBS; attribute++)
{
if (mState.vertexAttribute[attribute].mBoundBuffer.id() == buffer)
{
mState.vertexAttribute[attribute].mBoundBuffer.set(NULL);
}
} }
} }
...@@ -2763,6 +2808,17 @@ void Context::detachRenderbuffer(GLuint renderbuffer) ...@@ -2763,6 +2808,17 @@ void Context::detachRenderbuffer(GLuint renderbuffer)
} }
} }
void Context::detachVertexArray(GLuint vertexArray)
{
// [OpenGL ES 3.0.2] section 2.10 page 43:
// If a vertex array object that is currently bound is deleted, the binding
// for that object reverts to zero and the default vertex array becomes current.
if (mState.vertexArray == vertexArray)
{
bindVertexArray(0);
}
}
Texture *Context::getIncompleteTexture(TextureType type) Texture *Context::getIncompleteTexture(TextureType type)
{ {
Texture *t = mIncompleteTextures[type].get(); Texture *t = mIncompleteTextures[type].get();
...@@ -2872,9 +2928,7 @@ void Context::setVertexAttribi(GLuint index, const GLint values[4]) ...@@ -2872,9 +2928,7 @@ void Context::setVertexAttribi(GLuint index, const GLint values[4])
void Context::setVertexAttribDivisor(GLuint index, GLuint divisor) void Context::setVertexAttribDivisor(GLuint index, GLuint divisor)
{ {
ASSERT(index < gl::MAX_VERTEX_ATTRIBS); getCurrentVertexArray()->setVertexAttribDivisor(index, divisor);
mState.vertexAttribute[index].mDivisor = divisor;
} }
// keep list sorted in following order // keep list sorted in following order
......
...@@ -67,6 +67,8 @@ class Fence; ...@@ -67,6 +67,8 @@ class Fence;
class Query; class Query;
class ResourceManager; class ResourceManager;
class Buffer; class Buffer;
class VertexAttribute;
class VertexArray;
enum QueryType enum QueryType
{ {
...@@ -108,14 +110,13 @@ struct State ...@@ -108,14 +110,13 @@ struct State
unsigned int activeSampler; // Active texture unit selector - GL_TEXTURE0 unsigned int activeSampler; // Active texture unit selector - GL_TEXTURE0
BindingPointer<Buffer> arrayBuffer; BindingPointer<Buffer> arrayBuffer;
BindingPointer<Buffer> elementArrayBuffer;
GLuint readFramebuffer; GLuint readFramebuffer;
GLuint drawFramebuffer; GLuint drawFramebuffer;
BindingPointer<Renderbuffer> renderbuffer; BindingPointer<Renderbuffer> renderbuffer;
GLuint currentProgram; GLuint currentProgram;
VertexAttribCurrentValueData vertexAttribCurrentValues[MAX_VERTEX_ATTRIBS]; // From glVertexAttrib 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<Texture> samplerTexture[TEXTURE_TYPE_COUNT][IMPLEMENTATION_MAX_COMBINED_TEXTURE_IMAGE_UNITS];
BindingPointer<Query> activeQuery[QUERY_TYPE_COUNT]; BindingPointer<Query> activeQuery[QUERY_TYPE_COUNT];
...@@ -251,12 +252,14 @@ class Context ...@@ -251,12 +252,14 @@ class Context
GLuint createProgram(); GLuint createProgram();
GLuint createTexture(); GLuint createTexture();
GLuint createRenderbuffer(); GLuint createRenderbuffer();
GLuint createVertexArray();
void deleteBuffer(GLuint buffer); void deleteBuffer(GLuint buffer);
void deleteShader(GLuint shader); void deleteShader(GLuint shader);
void deleteProgram(GLuint program); void deleteProgram(GLuint program);
void deleteTexture(GLuint texture); void deleteTexture(GLuint texture);
void deleteRenderbuffer(GLuint renderbuffer); void deleteRenderbuffer(GLuint renderbuffer);
void deleteVertexArray(GLuint vertexArray);
// Framebuffers are owned by the Context, so these methods do not pass through // Framebuffers are owned by the Context, so these methods do not pass through
GLuint createFramebuffer(); GLuint createFramebuffer();
...@@ -279,6 +282,7 @@ class Context ...@@ -279,6 +282,7 @@ class Context
void bindReadFramebuffer(GLuint framebuffer); void bindReadFramebuffer(GLuint framebuffer);
void bindDrawFramebuffer(GLuint framebuffer); void bindDrawFramebuffer(GLuint framebuffer);
void bindRenderbuffer(GLuint renderbuffer); void bindRenderbuffer(GLuint renderbuffer);
void bindVertexArray(GLuint vertexArray);
void bindGenericUniformBuffer(GLuint buffer); void bindGenericUniformBuffer(GLuint buffer);
void bindIndexedUniformBuffer(GLuint buffer, GLuint index, GLintptr offset, GLsizeiptr size); void bindIndexedUniformBuffer(GLuint buffer, GLuint index, GLintptr offset, GLsizeiptr size);
void bindGenericTransformFeedbackBuffer(GLuint buffer); void bindGenericTransformFeedbackBuffer(GLuint buffer);
...@@ -310,6 +314,7 @@ class Context ...@@ -310,6 +314,7 @@ class Context
Texture *getTexture(GLuint handle); Texture *getTexture(GLuint handle);
Framebuffer *getFramebuffer(GLuint handle); Framebuffer *getFramebuffer(GLuint handle);
Renderbuffer *getRenderbuffer(GLuint handle); Renderbuffer *getRenderbuffer(GLuint handle);
VertexArray *getVertexArray(GLuint handle) const;
Query *getQuery(GLuint handle, bool create, GLenum type); Query *getQuery(GLuint handle, bool create, GLenum type);
Buffer *getArrayBuffer(); Buffer *getArrayBuffer();
...@@ -328,6 +333,7 @@ class Context ...@@ -328,6 +333,7 @@ class Context
Texture *getSamplerTexture(unsigned int sampler, TextureType type); Texture *getSamplerTexture(unsigned int sampler, TextureType type);
Framebuffer *getReadFramebuffer(); Framebuffer *getReadFramebuffer();
Framebuffer *getDrawFramebuffer(); Framebuffer *getDrawFramebuffer();
VertexArray *getCurrentVertexArray() const;
bool getFloatv(GLenum pname, GLfloat *params); bool getFloatv(GLenum pname, GLfloat *params);
bool getIntegerv(GLenum pname, GLint *params); bool getIntegerv(GLenum pname, GLint *params);
...@@ -421,6 +427,7 @@ class Context ...@@ -421,6 +427,7 @@ class Context
void detachTexture(GLuint texture); void detachTexture(GLuint texture);
void detachFramebuffer(GLuint framebuffer); void detachFramebuffer(GLuint framebuffer);
void detachRenderbuffer(GLuint renderbuffer); void detachRenderbuffer(GLuint renderbuffer);
void detachVertexArray(GLuint vertexArray);
Texture *getIncompleteTexture(TextureType type); Texture *getIncompleteTexture(TextureType type);
...@@ -460,6 +467,10 @@ class Context ...@@ -460,6 +467,10 @@ class Context
QueryMap mQueryMap; QueryMap mQueryMap;
HandleAllocator mQueryHandleAllocator; HandleAllocator mQueryHandleAllocator;
typedef HASH_MAP<GLuint, VertexArray*> VertexArrayMap;
VertexArrayMap mVertexArrayMap;
HandleAllocator mVertexArrayHandleAllocator;
std::vector<std::string> mExtensionStringList; std::vector<std::string> mExtensionStringList;
const char *mCombinedExtensionsString; const char *mCombinedExtensionsString;
const char *mRendererString; 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 @@ ...@@ -9,11 +9,10 @@
#ifndef LIBGLESV2_VERTEXATTRIBUTE_H_ #ifndef LIBGLESV2_VERTEXATTRIBUTE_H_
#define LIBGLESV2_VERTEXATTRIBUTE_H_ #define LIBGLESV2_VERTEXATTRIBUTE_H_
#include "common/RefCountObject.h" #include "libGLESv2/Buffer.h"
namespace gl namespace gl
{ {
class Buffer;
class VertexAttribute class VertexAttribute
{ {
...@@ -47,6 +46,18 @@ class VertexAttribute ...@@ -47,6 +46,18 @@ class VertexAttribute
return mStride ? mStride : typeSize(); 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 // From glVertexAttribPointer
GLenum mType; GLenum mType;
GLint mSize; GLint mSize;
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "libGLESv2/Texture.h" #include "libGLESv2/Texture.h"
#include "libGLESv2/Query.h" #include "libGLESv2/Query.h"
#include "libGLESv2/Context.h" #include "libGLESv2/Context.h"
#include "libGLESv2/VertexArray.h"
bool validImageSize(const gl::Context *context, GLint level, GLsizei width, GLsizei height, GLsizei depth) 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)\" ...@@ -313,6 +313,7 @@ copy "$(OutDir)libGLESv2.lib" "$(ProjectDir)..\..\lib\$(Configuration)\"
<ClCompile Include="Shader.cpp" /> <ClCompile Include="Shader.cpp" />
<ClCompile Include="Texture.cpp" /> <ClCompile Include="Texture.cpp" />
<ClCompile Include="Uniform.cpp" /> <ClCompile Include="Uniform.cpp" />
<ClCompile Include="VertexArray.cpp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="..\..\include\GLES2\gl2.h" /> <ClInclude Include="..\..\include\GLES2\gl2.h" />
...@@ -439,6 +440,7 @@ copy "$(OutDir)libGLESv2.lib" "$(ProjectDir)..\..\lib\$(Configuration)\" ...@@ -439,6 +440,7 @@ copy "$(OutDir)libGLESv2.lib" "$(ProjectDir)..\..\lib\$(Configuration)\"
<ClInclude Include="Uniform.h" /> <ClInclude Include="Uniform.h" />
<ClInclude Include="..\common\version.h" /> <ClInclude Include="..\common\version.h" />
<ClInclude Include="VertexAttribute.h" /> <ClInclude Include="VertexAttribute.h" />
<ClInclude Include="VertexArray.h" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="libGLESv2.def" /> <None Include="libGLESv2.def" />
......
...@@ -239,6 +239,9 @@ ...@@ -239,6 +239,9 @@
<ClCompile Include="renderer\Blit11.cpp"> <ClCompile Include="renderer\Blit11.cpp">
<Filter>Source Files\Renderer11</Filter> <Filter>Source Files\Renderer11</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="VertexArray.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="BinaryStream.h"> <ClInclude Include="BinaryStream.h">
...@@ -619,6 +622,9 @@ ...@@ -619,6 +622,9 @@
<ClInclude Include="VertexAttribute.h"> <ClInclude Include="VertexAttribute.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="VertexArray.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="renderer\shaders\Blit.ps"> <None Include="renderer\shaders\Blit.ps">
......
...@@ -131,7 +131,7 @@ class Renderer ...@@ -131,7 +131,7 @@ class Renderer
virtual void applyShaders(gl::ProgramBinary *programBinary) = 0; virtual void applyShaders(gl::ProgramBinary *programBinary) = 0;
virtual void applyUniforms(gl::ProgramBinary *programBinary, gl::UniformArray *uniformArray) = 0; virtual void applyUniforms(gl::ProgramBinary *programBinary, gl::UniformArray *uniformArray) = 0;
virtual bool applyPrimitiveType(GLenum primitiveType, GLsizei elementCount) = 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; 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; 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) ...@@ -1034,7 +1034,7 @@ bool Renderer11::applyRenderTarget(gl::Framebuffer *framebuffer)
return true; 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) GLint first, GLsizei count, GLsizei instances)
{ {
TranslatedAttribute attributes[gl::MAX_VERTEX_ATTRIBS]; TranslatedAttribute attributes[gl::MAX_VERTEX_ATTRIBS];
......
...@@ -74,7 +74,7 @@ class Renderer11 : public Renderer ...@@ -74,7 +74,7 @@ class Renderer11 : public Renderer
virtual bool applyRenderTarget(gl::Framebuffer *frameBuffer); virtual bool applyRenderTarget(gl::Framebuffer *frameBuffer);
virtual void applyShaders(gl::ProgramBinary *programBinary); virtual void applyShaders(gl::ProgramBinary *programBinary);
virtual void applyUniforms(gl::ProgramBinary *programBinary, gl::UniformArray *uniformArray); 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); GLint first, GLsizei count, GLsizei instances);
virtual GLenum applyIndexBuffer(const GLvoid *indices, gl::Buffer *elementArrayBuffer, GLsizei count, GLenum mode, GLenum type, TranslatedIndexData *indexInfo); 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) ...@@ -1338,7 +1338,7 @@ bool Renderer9::applyRenderTarget(gl::Framebuffer *framebuffer)
return true; 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) GLint first, GLsizei count, GLsizei instances)
{ {
TranslatedAttribute attributes[gl::MAX_VERTEX_ATTRIBS]; TranslatedAttribute attributes[gl::MAX_VERTEX_ATTRIBS];
......
...@@ -88,7 +88,7 @@ class Renderer9 : public Renderer ...@@ -88,7 +88,7 @@ class Renderer9 : public Renderer
virtual void applyShaders(gl::ProgramBinary *programBinary); virtual void applyShaders(gl::ProgramBinary *programBinary);
virtual void applyUniforms(gl::ProgramBinary *programBinary, gl::UniformArray *uniformArray); virtual void applyUniforms(gl::ProgramBinary *programBinary, gl::UniformArray *uniformArray);
virtual bool applyPrimitiveType(GLenum primitiveType, GLsizei elementCount); 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); GLint first, GLsizei count, GLsizei instances);
virtual GLenum applyIndexBuffer(const GLvoid *indices, gl::Buffer *elementArrayBuffer, GLsizei count, GLenum mode, GLenum type, TranslatedIndexData *indexInfo); virtual GLenum applyIndexBuffer(const GLvoid *indices, gl::Buffer *elementArrayBuffer, GLsizei count, GLenum mode, GLenum type, TranslatedIndexData *indexInfo);
......
...@@ -18,6 +18,7 @@ namespace gl ...@@ -18,6 +18,7 @@ namespace gl
{ {
class VertexAttribute; class VertexAttribute;
class ProgramBinary; class ProgramBinary;
struct VertexAttribCurrentValueData;
} }
namespace rx 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