gl::Buffer now uses an rx::BufferStorage to store the data.

TRAC #22297 Signed-off-by: Jamie Madill Signed-off-by: Nicolas Capens Author: Geoff Lang git-svn-id: https://angleproject.googlecode.com/svn/branches/dx11proto@1883 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 4e52b635
// //
// Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved. // Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// //
...@@ -18,10 +18,9 @@ namespace gl ...@@ -18,10 +18,9 @@ namespace gl
Buffer::Buffer(rx::Renderer *renderer, GLuint id) : RefCountObject(id) Buffer::Buffer(rx::Renderer *renderer, GLuint id) : RefCountObject(id)
{ {
mRenderer = renderer; mRenderer = renderer;
mContents = NULL;
mSize = 0;
mUsage = GL_DYNAMIC_DRAW; mUsage = GL_DYNAMIC_DRAW;
mBufferStorage = renderer->createBufferStorage();
mStaticVertexBuffer = NULL; mStaticVertexBuffer = NULL;
mStaticIndexBuffer = NULL; mStaticIndexBuffer = NULL;
mUnmodifiedDataUse = 0; mUnmodifiedDataUse = 0;
...@@ -29,31 +28,16 @@ Buffer::Buffer(rx::Renderer *renderer, GLuint id) : RefCountObject(id) ...@@ -29,31 +28,16 @@ Buffer::Buffer(rx::Renderer *renderer, GLuint id) : RefCountObject(id)
Buffer::~Buffer() Buffer::~Buffer()
{ {
delete[] mContents; delete mBufferStorage;
delete mStaticVertexBuffer; delete mStaticVertexBuffer;
delete mStaticIndexBuffer; delete mStaticIndexBuffer;
} }
void Buffer::bufferData(const void *data, GLsizeiptr size, GLenum usage) void Buffer::bufferData(const void *data, GLsizeiptr size, GLenum usage)
{ {
if (size == 0) mBufferStorage->clear();
{ mBufferStorage->setData(data, size, 0);
delete[] mContents;
mContents = NULL;
}
else if (size != mSize)
{
delete[] mContents;
mContents = new GLubyte[size];
memset(mContents, 0, size);
}
if (data != NULL && size > 0)
{
memcpy(mContents, data, size);
}
mSize = size;
mUsage = usage; mUsage = usage;
invalidateStaticData(); invalidateStaticData();
...@@ -67,7 +51,7 @@ void Buffer::bufferData(const void *data, GLsizeiptr size, GLenum usage) ...@@ -67,7 +51,7 @@ void Buffer::bufferData(const void *data, GLsizeiptr size, GLenum usage)
void Buffer::bufferSubData(const void *data, GLsizeiptr size, GLintptr offset) void Buffer::bufferSubData(const void *data, GLsizeiptr size, GLintptr offset)
{ {
memcpy(mContents + offset, data, size); mBufferStorage->setData(data, size, offset);
if ((mStaticVertexBuffer && mStaticVertexBuffer->getBufferSize() != 0) || (mStaticIndexBuffer && mStaticIndexBuffer->getBufferSize() != 0)) if ((mStaticVertexBuffer && mStaticVertexBuffer->getBufferSize() != 0) || (mStaticIndexBuffer && mStaticIndexBuffer->getBufferSize() != 0))
{ {
...@@ -77,6 +61,21 @@ void Buffer::bufferSubData(const void *data, GLsizeiptr size, GLintptr offset) ...@@ -77,6 +61,21 @@ void Buffer::bufferSubData(const void *data, GLsizeiptr size, GLintptr offset)
mUnmodifiedDataUse = 0; mUnmodifiedDataUse = 0;
} }
rx::BufferStorage *Buffer::getStorage() const
{
return mBufferStorage;
}
unsigned int Buffer::size()
{
return mBufferStorage->getSize();
}
GLenum Buffer::usage() const
{
return mUsage;
}
rx::StaticVertexBufferInterface *Buffer::getStaticVertexBuffer() rx::StaticVertexBufferInterface *Buffer::getStaticVertexBuffer()
{ {
return mStaticVertexBuffer; return mStaticVertexBuffer;
...@@ -105,7 +104,7 @@ void Buffer::promoteStaticUsage(int dataSize) ...@@ -105,7 +104,7 @@ void Buffer::promoteStaticUsage(int dataSize)
{ {
mUnmodifiedDataUse += dataSize; mUnmodifiedDataUse += dataSize;
if (mUnmodifiedDataUse > 3 * mSize) if (mUnmodifiedDataUse > 3 * mBufferStorage->getSize())
{ {
mStaticVertexBuffer = new rx::StaticVertexBufferInterface(mRenderer); mStaticVertexBuffer = new rx::StaticVertexBufferInterface(mRenderer);
mStaticIndexBuffer = new rx::StaticIndexBufferInterface(mRenderer); mStaticIndexBuffer = new rx::StaticIndexBufferInterface(mRenderer);
......
// //
// Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved. // Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// //
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "libGLESv2/renderer/IndexBuffer.h" #include "libGLESv2/renderer/IndexBuffer.h"
#include "libGLESv2/renderer/Renderer.h" #include "libGLESv2/renderer/Renderer.h"
#include "libGLESv2/renderer/VertexBuffer.h" #include "libGLESv2/renderer/VertexBuffer.h"
#include "libGLESv2/renderer/BufferStorage.h"
namespace gl namespace gl
{ {
...@@ -36,9 +37,10 @@ class Buffer : public RefCountObject ...@@ -36,9 +37,10 @@ class Buffer : public RefCountObject
void bufferData(const void *data, GLsizeiptr size, GLenum usage); void bufferData(const void *data, GLsizeiptr size, GLenum usage);
void bufferSubData(const void *data, GLsizeiptr size, GLintptr offset); void bufferSubData(const void *data, GLsizeiptr size, GLintptr offset);
void *data() { return mContents; } GLenum usage() const;
size_t size() const { return mSize; }
GLenum usage() const { return mUsage; } rx::BufferStorage *getStorage() const;
unsigned int size();
rx::StaticVertexBufferInterface *getStaticVertexBuffer(); rx::StaticVertexBufferInterface *getStaticVertexBuffer();
rx::StaticIndexBufferInterface *getStaticIndexBuffer(); rx::StaticIndexBufferInterface *getStaticIndexBuffer();
...@@ -49,13 +51,13 @@ class Buffer : public RefCountObject ...@@ -49,13 +51,13 @@ class Buffer : public RefCountObject
DISALLOW_COPY_AND_ASSIGN(Buffer); DISALLOW_COPY_AND_ASSIGN(Buffer);
rx::Renderer *mRenderer; rx::Renderer *mRenderer;
GLubyte *mContents;
GLsizeiptr mSize;
GLenum mUsage; GLenum mUsage;
rx::BufferStorage *mBufferStorage;
rx::StaticVertexBufferInterface *mStaticVertexBuffer; rx::StaticVertexBufferInterface *mStaticVertexBuffer;
rx::StaticIndexBufferInterface *mStaticIndexBuffer; rx::StaticIndexBufferInterface *mStaticIndexBuffer;
GLsizeiptr mUnmodifiedDataUse; unsigned int mUnmodifiedDataUse;
}; };
} }
......
...@@ -130,6 +130,8 @@ GLenum IndexDataManager::prepareIndexData(GLenum type, GLsizei count, gl::Buffer ...@@ -130,6 +130,8 @@ GLenum IndexDataManager::prepareIndexData(GLenum type, GLsizei count, gl::Buffer
if (buffer != NULL) if (buffer != NULL)
{ {
BufferStorage *storage = buffer->getStorage();
switch (type) switch (type)
{ {
case GL_UNSIGNED_BYTE: alignedOffset = (offset % sizeof(GLubyte) == 0); break; case GL_UNSIGNED_BYTE: alignedOffset = (offset % sizeof(GLubyte) == 0); break;
...@@ -138,18 +140,19 @@ GLenum IndexDataManager::prepareIndexData(GLenum type, GLsizei count, gl::Buffer ...@@ -138,18 +140,19 @@ GLenum IndexDataManager::prepareIndexData(GLenum type, GLsizei count, gl::Buffer
default: UNREACHABLE(); alignedOffset = false; default: UNREACHABLE(); alignedOffset = false;
} }
if (indexTypeSize(type) * count + offset > static_cast<std::size_t>(buffer->size())) if (indexTypeSize(type) * count + offset > storage->getSize())
{ {
return GL_INVALID_OPERATION; return GL_INVALID_OPERATION;
} }
indices = static_cast<const GLubyte*>(buffer->data()) + offset; indices = static_cast<const GLubyte*>(storage->getData()) + offset;
} }
StreamingIndexBufferInterface *streamingBuffer = (type == GL_UNSIGNED_INT) ? mStreamingBufferInt : mStreamingBufferShort; StreamingIndexBufferInterface *streamingBuffer = (type == GL_UNSIGNED_INT) ? mStreamingBufferInt : mStreamingBufferShort;
StaticIndexBufferInterface *staticBuffer = buffer ? buffer->getStaticIndexBuffer() : NULL; StaticIndexBufferInterface *staticBuffer = buffer ? buffer->getStaticIndexBuffer() : NULL;
IndexBufferInterface *indexBuffer = streamingBuffer; IndexBufferInterface *indexBuffer = streamingBuffer;
BufferStorage *storage = buffer ? buffer->getStorage() : NULL;
UINT streamOffset = 0; UINT streamOffset = 0;
if (staticBuffer && staticBuffer->getIndexType() == type && alignedOffset) if (staticBuffer && staticBuffer->getIndexType() == type && alignedOffset)
...@@ -173,7 +176,7 @@ GLenum IndexDataManager::prepareIndexData(GLenum type, GLsizei count, gl::Buffer ...@@ -173,7 +176,7 @@ GLenum IndexDataManager::prepareIndexData(GLenum type, GLsizei count, gl::Buffer
if (staticBuffer->getBufferSize() == 0 && alignedOffset) if (staticBuffer->getBufferSize() == 0 && alignedOffset)
{ {
indexBuffer = staticBuffer; indexBuffer = staticBuffer;
convertCount = buffer->size() / indexTypeSize(type); convertCount = storage->getSize() / indexTypeSize(type);
} }
else else
{ {
...@@ -199,7 +202,7 @@ GLenum IndexDataManager::prepareIndexData(GLenum type, GLsizei count, gl::Buffer ...@@ -199,7 +202,7 @@ GLenum IndexDataManager::prepareIndexData(GLenum type, GLsizei count, gl::Buffer
return GL_OUT_OF_MEMORY; return GL_OUT_OF_MEMORY;
} }
convertIndices(type, staticBuffer ? buffer->data() : indices, convertCount, output); convertIndices(type, staticBuffer ? storage->getData() : indices, convertCount, output);
if (!indexBuffer->unmapBuffer()) if (!indexBuffer->unmapBuffer())
{ {
......
...@@ -965,8 +965,9 @@ void Renderer11::drawLineLoop(GLsizei count, GLenum type, const GLvoid *indices, ...@@ -965,8 +965,9 @@ void Renderer11::drawLineLoop(GLsizei count, GLenum type, const GLvoid *indices,
if (type != GL_NONE && elementArrayBuffer) if (type != GL_NONE && elementArrayBuffer)
{ {
gl::Buffer *indexBuffer = elementArrayBuffer; gl::Buffer *indexBuffer = elementArrayBuffer;
BufferStorage *storage = indexBuffer->getStorage();
intptr_t offset = reinterpret_cast<intptr_t>(indices); intptr_t offset = reinterpret_cast<intptr_t>(indices);
indices = static_cast<const GLubyte*>(indexBuffer->data()) + offset; indices = static_cast<const GLubyte*>(storage->getData()) + offset;
} }
if (!mLineLoopIB) if (!mLineLoopIB)
...@@ -1057,8 +1058,9 @@ void Renderer11::drawTriangleFan(GLsizei count, GLenum type, const GLvoid *indic ...@@ -1057,8 +1058,9 @@ void Renderer11::drawTriangleFan(GLsizei count, GLenum type, const GLvoid *indic
if (type != GL_NONE && elementArrayBuffer) if (type != GL_NONE && elementArrayBuffer)
{ {
gl::Buffer *indexBuffer = elementArrayBuffer; gl::Buffer *indexBuffer = elementArrayBuffer;
BufferStorage *storage = indexBuffer->getStorage();
intptr_t offset = reinterpret_cast<intptr_t>(indices); intptr_t offset = reinterpret_cast<intptr_t>(indices);
indices = static_cast<const GLubyte*>(indexBuffer->data()) + offset; indices = static_cast<const GLubyte*>(storage->getData()) + offset;
} }
if (!mTriangleFanIB) if (!mTriangleFanIB)
......
...@@ -1436,8 +1436,9 @@ void Renderer9::drawLineLoop(GLsizei count, GLenum type, const GLvoid *indices, ...@@ -1436,8 +1436,9 @@ void Renderer9::drawLineLoop(GLsizei count, GLenum type, const GLvoid *indices,
if (type != GL_NONE && elementArrayBuffer) if (type != GL_NONE && elementArrayBuffer)
{ {
gl::Buffer *indexBuffer = elementArrayBuffer; gl::Buffer *indexBuffer = elementArrayBuffer;
BufferStorage *storage = indexBuffer->getStorage();
intptr_t offset = reinterpret_cast<intptr_t>(indices); intptr_t offset = reinterpret_cast<intptr_t>(indices);
indices = static_cast<const GLubyte*>(indexBuffer->data()) + offset; indices = static_cast<const GLubyte*>(storage->getData()) + offset;
} }
UINT startIndex = 0; UINT startIndex = 0;
......
...@@ -94,7 +94,8 @@ bool VertexBuffer11::storeVertexAttributes(const gl::VertexAttribute &attrib, GL ...@@ -94,7 +94,8 @@ bool VertexBuffer11::storeVertexAttributes(const gl::VertexAttribute &attrib, GL
const char *input = NULL; const char *input = NULL;
if (buffer) if (buffer)
{ {
input = static_cast<const char*>(buffer->data()) + static_cast<int>(attrib.mOffset); BufferStorage *storage = buffer->getStorage();
input = static_cast<const char*>(storage->getData()) + static_cast<int>(attrib.mOffset);
} }
else else
{ {
......
...@@ -104,7 +104,8 @@ bool VertexBuffer9::storeVertexAttributes(const gl::VertexAttribute &attrib, GLi ...@@ -104,7 +104,8 @@ bool VertexBuffer9::storeVertexAttributes(const gl::VertexAttribute &attrib, GLi
const char *input = NULL; const char *input = NULL;
if (buffer) if (buffer)
{ {
input = static_cast<const char*>(buffer->data()) + static_cast<int>(attrib.mOffset); BufferStorage *storage = buffer->getStorage();
input = static_cast<const char*>(storage->getData()) + static_cast<int>(attrib.mOffset);
} }
else else
{ {
......
...@@ -87,11 +87,12 @@ GLenum VertexDataManager::prepareVertexData(const gl::VertexAttribute attribs[], ...@@ -87,11 +87,12 @@ GLenum VertexDataManager::prepareVertexData(const gl::VertexAttribute attribs[],
gl::Buffer *buffer = attribs[i].mBoundBuffer.get(); gl::Buffer *buffer = attribs[i].mBoundBuffer.get();
StaticVertexBufferInterface *staticBuffer = buffer ? buffer->getStaticVertexBuffer() : NULL; StaticVertexBufferInterface *staticBuffer = buffer ? buffer->getStaticVertexBuffer() : NULL;
BufferStorage *storage = buffer ? buffer->getStorage() : NULL;
if (staticBuffer) if (staticBuffer)
{ {
if (staticBuffer->getBufferSize() == 0) if (staticBuffer->getBufferSize() == 0)
{ {
int totalCount = elementsInBuffer(attribs[i], buffer->size()); int totalCount = elementsInBuffer(attribs[i], storage->getSize());
staticBuffer->reserveVertexSpace(attribs[i], totalCount, 0); staticBuffer->reserveVertexSpace(attribs[i], totalCount, 0);
} }
else if (staticBuffer->lookupAttribute(attribs[i]) == -1) else if (staticBuffer->lookupAttribute(attribs[i]) == -1)
...@@ -126,6 +127,8 @@ GLenum VertexDataManager::prepareVertexData(const gl::VertexAttribute attribs[], ...@@ -126,6 +127,8 @@ GLenum VertexDataManager::prepareVertexData(const gl::VertexAttribute attribs[],
StaticVertexBufferInterface *staticBuffer = buffer ? buffer->getStaticVertexBuffer() : NULL; StaticVertexBufferInterface *staticBuffer = buffer ? buffer->getStaticVertexBuffer() : NULL;
VertexBufferInterface *vertexBuffer = staticBuffer ? staticBuffer : static_cast<VertexBufferInterface*>(mStreamingBuffer); VertexBufferInterface *vertexBuffer = staticBuffer ? staticBuffer : static_cast<VertexBufferInterface*>(mStreamingBuffer);
BufferStorage *storage = buffer ? buffer->getStorage() : NULL;
std::size_t streamOffset = -1; std::size_t streamOffset = -1;
unsigned int outputElementSize = 0; unsigned int outputElementSize = 0;
...@@ -137,7 +140,7 @@ GLenum VertexDataManager::prepareVertexData(const gl::VertexAttribute attribs[], ...@@ -137,7 +140,7 @@ GLenum VertexDataManager::prepareVertexData(const gl::VertexAttribute attribs[],
if (streamOffset == -1) if (streamOffset == -1)
{ {
// Convert the entire buffer // Convert the entire buffer
int totalCount = elementsInBuffer(attribs[i], buffer->size()); int totalCount = elementsInBuffer(attribs[i], storage->getSize());
int startIndex = attribs[i].mOffset / attribs[i].stride(); int startIndex = attribs[i].mOffset / attribs[i].stride();
streamOffset = staticBuffer->storeVertexAttributes(attribs[i], -startIndex, totalCount, 0); streamOffset = staticBuffer->storeVertexAttributes(attribs[i], -startIndex, totalCount, 0);
......
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