Commit 399c35f9 by jbauman@chromium.org

Don't constantly recreate index buffers.

Recreating index buffers for closing loops can take a long time, so use a streaming index buffer instead. BUG= TEST= Review URL: http://codereview.appspot.com/4438080 git-svn-id: https://angleproject.googlecode.com/svn/trunk@625 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent a9d0b768
#define MAJOR_VERSION 0 #define MAJOR_VERSION 0
#define MINOR_VERSION 0 #define MINOR_VERSION 0
#define BUILD_VERSION 0 #define BUILD_VERSION 0
#define BUILD_REVISION 624 #define BUILD_REVISION 625
#define STRINGIFY(x) #x #define STRINGIFY(x) #x
#define MACRO_STRINGIFY(x) STRINGIFY(x) #define MACRO_STRINGIFY(x) STRINGIFY(x)
......
...@@ -31,6 +31,11 @@ ...@@ -31,6 +31,11 @@
#undef near #undef near
#undef far #undef far
namespace
{
enum { CLOSING_INDEX_BUFFER_SIZE = 4096 };
}
namespace gl namespace gl
{ {
Context::Context(const egl::Config *config, const gl::Context *shareContext) : mConfig(config) Context::Context(const egl::Config *config, const gl::Context *shareContext) : mConfig(config)
...@@ -141,6 +146,7 @@ Context::Context(const egl::Config *config, const gl::Context *shareContext) : m ...@@ -141,6 +146,7 @@ Context::Context(const egl::Config *config, const gl::Context *shareContext) : m
mVertexDataManager = NULL; mVertexDataManager = NULL;
mIndexDataManager = NULL; mIndexDataManager = NULL;
mBlit = NULL; mBlit = NULL;
mClosingIB = NULL;
mInvalidEnum = false; mInvalidEnum = false;
mInvalidValue = false; mInvalidValue = false;
...@@ -213,6 +219,7 @@ Context::~Context() ...@@ -213,6 +219,7 @@ Context::~Context()
delete mVertexDataManager; delete mVertexDataManager;
delete mIndexDataManager; delete mIndexDataManager;
delete mBlit; delete mBlit;
delete mClosingIB;
if (mMaskedClearSavedState) if (mMaskedClearSavedState)
{ {
...@@ -2744,49 +2751,57 @@ void Context::drawClosingLine(unsigned int first, unsigned int last) ...@@ -2744,49 +2751,57 @@ void Context::drawClosingLine(unsigned int first, unsigned int last)
{ {
IDirect3DDevice9 *device = getDevice(); IDirect3DDevice9 *device = getDevice();
IDirect3DIndexBuffer9 *indexBuffer = NULL; IDirect3DIndexBuffer9 *indexBuffer = NULL;
HRESULT result = D3DERR_INVALIDCALL; bool succeeded = false;
UINT offset;
if (supports32bitIndices()) if (supports32bitIndices())
{ {
result = device->CreateIndexBuffer(8, D3DUSAGE_WRITEONLY, D3DFMT_INDEX32, D3DPOOL_DEFAULT, &indexBuffer, 0); const int spaceNeeded = 2 * sizeof(unsigned int);
if (SUCCEEDED(result)) if (!mClosingIB)
{ {
unsigned int *data; mClosingIB = new StreamingIndexBuffer(device, CLOSING_INDEX_BUFFER_SIZE, D3DFMT_INDEX32);
result = indexBuffer->Lock(0, 0, (void**)&data, 0); }
if (SUCCEEDED(result)) mClosingIB->reserveSpace(spaceNeeded, GL_UNSIGNED_INT);
{
data[0] = last; unsigned int *data = static_cast<unsigned int*>(mClosingIB->map(spaceNeeded, &offset));
data[1] = first; if (data)
} {
data[0] = last;
data[1] = first;
mClosingIB->unmap();
offset /= 4;
succeeded = true;
} }
} }
else else
{ {
result = device->CreateIndexBuffer(4, D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_DEFAULT, &indexBuffer, 0); const int spaceNeeded = 2 * sizeof(unsigned short);
if (SUCCEEDED(result)) if (!mClosingIB)
{ {
unsigned short *data; mClosingIB = new StreamingIndexBuffer(device, CLOSING_INDEX_BUFFER_SIZE, D3DFMT_INDEX16);
result = indexBuffer->Lock(0, 0, (void**)&data, 0); }
if (SUCCEEDED(result)) mClosingIB->reserveSpace(spaceNeeded, GL_UNSIGNED_SHORT);
{
data[0] = last; unsigned short *data = static_cast<unsigned short*>(mClosingIB->map(spaceNeeded, &offset));
data[1] = first; if (data)
} {
data[0] = last;
data[1] = first;
mClosingIB->unmap();
offset /= 2;
succeeded = true;
} }
} }
if (SUCCEEDED(result)) if (succeeded)
{ {
indexBuffer->Unlock(); device->SetIndices(mClosingIB->getBuffer());
device->SetIndices(indexBuffer);
device->DrawIndexedPrimitive(D3DPT_LINELIST, 0, 0, 2, 0, 1);
indexBuffer->Release(); device->DrawIndexedPrimitive(D3DPT_LINELIST, 0, 0, 2, offset, 1);
} }
else else
{ {
......
...@@ -48,6 +48,7 @@ class Renderbuffer; ...@@ -48,6 +48,7 @@ class Renderbuffer;
class RenderbufferStorage; class RenderbufferStorage;
class Colorbuffer; class Colorbuffer;
class Depthbuffer; class Depthbuffer;
class StreamingIndexBuffer;
class Stencilbuffer; class Stencilbuffer;
class DepthStencilbuffer; class DepthStencilbuffer;
class VertexDataManager; class VertexDataManager;
...@@ -495,6 +496,8 @@ class Context ...@@ -495,6 +496,8 @@ class Context
IndexDataManager *mIndexDataManager; IndexDataManager *mIndexDataManager;
Blit *mBlit; Blit *mBlit;
StreamingIndexBuffer *mClosingIB;
BindingPointer<Texture> mIncompleteTextures[SAMPLER_TYPE_COUNT]; BindingPointer<Texture> mIncompleteTextures[SAMPLER_TYPE_COUNT];
......
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