TRAC #11878

Signed-off-by: Nicolas Capens
Signed-off-by: Daniel Koch

Author:    Andrew Lewycky

git-svn-id: https://angleproject.googlecode.com/svn/trunk@174 736b8ea6-26fd-11df-bfd4-992fa37f6226
This commit is contained in:
daniel@transgaming.com 2010-04-20 18:53:06 +00:00
Родитель bf2b52a313
Коммит e4b08c8cf8
7 изменённых файлов: 123 добавлений и 10 удалений

Просмотреть файл

@ -2217,6 +2217,19 @@ bool Context::isTriangleMode(GLenum drawMode)
return false;
}
void Context::setVertexAttrib(GLuint index, const GLfloat *values)
{
ASSERT(index < gl::MAX_VERTEX_ATTRIBS);
vertexAttribute[index].mCurrentValue[0] = values[0];
vertexAttribute[index].mCurrentValue[1] = values[1];
vertexAttribute[index].mCurrentValue[2] = values[2];
vertexAttribute[index].mCurrentValue[3] = values[3];
mVertexDataManager->dirtyCurrentValues();
}
}
extern "C"

Просмотреть файл

@ -239,6 +239,8 @@ class Context : public State
void setStencilbufferZero(Stencilbuffer *stencilBuffer);
void setRenderbuffer(Renderbuffer *renderbuffer);
void setVertexAttrib(GLuint index, const GLfloat *values);
Buffer *getBuffer(GLuint handle);
Shader *getShader(GLuint handle);
Program *getProgram(GLuint handle);

Просмотреть файл

@ -31,7 +31,7 @@ VertexDataManager::VertexDataManager(Context *context, BufferBackEnd *backend)
mStreamBuffer = mBackend->createVertexBuffer(INITIAL_STREAM_BUFFER_SIZE);
try
{
mCurrentValueBuffer = mBackend->createVertexBuffer(4*sizeof(float)*MAX_VERTEX_ATTRIBS);
mCurrentValueBuffer = mBackend->createVertexBufferForStrideZero(4*sizeof(float)*MAX_VERTEX_ATTRIBS);
}
catch (...)
{

Просмотреть файл

@ -54,6 +54,7 @@ class BufferBackEnd
virtual ~BufferBackEnd() { }
virtual TranslatedVertexBuffer *createVertexBuffer(std::size_t size) = 0;
virtual TranslatedVertexBuffer *createVertexBufferForStrideZero(std::size_t size) = 0;
virtual TranslatedIndexBuffer *createIndexBuffer(std::size_t size) = 0;
virtual FormatConverter getFormatConverter(GLenum type, std::size_t size, bool normalize) = 0;

Просмотреть файл

@ -55,7 +55,6 @@ class FormatConverterFactory
namespace gl
{
Dx9BackEnd::Dx9BackEnd(IDirect3DDevice9 *d3ddevice)
: mDevice(d3ddevice)
{
@ -72,6 +71,11 @@ TranslatedVertexBuffer *Dx9BackEnd::createVertexBuffer(std::size_t size)
return new Dx9VertexBuffer(mDevice, size);
}
TranslatedVertexBuffer *Dx9BackEnd::createVertexBufferForStrideZero(std::size_t size)
{
return new Dx9VertexBufferZeroStrideWorkaround(mDevice, size);
}
TranslatedIndexBuffer *Dx9BackEnd::createIndexBuffer(std::size_t size)
{
return new Dx9IndexBuffer(mDevice, size);
@ -248,6 +252,18 @@ Dx9BackEnd::Dx9VertexBuffer::Dx9VertexBuffer(IDirect3DDevice9 *device, std::size
}
}
Dx9BackEnd::Dx9VertexBuffer::Dx9VertexBuffer(IDirect3DDevice9 *device, std::size_t size, DWORD usageFlags)
: TranslatedVertexBuffer(size)
{
HRESULT hr = device->CreateVertexBuffer(size, usageFlags, 0, D3DPOOL_DEFAULT, &mVertexBuffer, NULL);
if (hr != S_OK)
{
ERR("Out of memory allocating a vertex buffer of size %lu.", size);
throw std::bad_alloc();
}
}
Dx9BackEnd::Dx9VertexBuffer::~Dx9VertexBuffer()
{
mVertexBuffer->Release();
@ -288,6 +304,27 @@ void *Dx9BackEnd::Dx9VertexBuffer::streamingMap(std::size_t offset, std::size_t
return mapPtr;
}
// Normally VBs are created with D3DUSAGE_WRITEONLY | D3DUSAGE_DYNAMIC, but some hardware & drivers won't render
// if any stride-zero streams are in D3DUSAGE_DYNAMIC VBs, so this provides a way to create such VBs with only D3DUSAGE_WRITEONLY set.
// D3DLOCK_DISCARD and D3DLOCK_NOOVERWRITE are only available on D3DUSAGE_DYNAMIC VBs, so we override methods to avoid using these flags.
Dx9BackEnd::Dx9VertexBufferZeroStrideWorkaround::Dx9VertexBufferZeroStrideWorkaround(IDirect3DDevice9 *device, std::size_t size)
: Dx9VertexBuffer(device, size, D3DUSAGE_WRITEONLY)
{
}
void Dx9BackEnd::Dx9VertexBufferZeroStrideWorkaround::recycle()
{
}
void *Dx9BackEnd::Dx9VertexBufferZeroStrideWorkaround::streamingMap(std::size_t offset, std::size_t size)
{
void *mapPtr;
getBuffer()->Lock(offset, size, &mapPtr, 0);
return mapPtr;
}
Dx9BackEnd::Dx9IndexBuffer::Dx9IndexBuffer(IDirect3DDevice9 *device, std::size_t size)
: TranslatedIndexBuffer(size)
{

Просмотреть файл

@ -24,6 +24,7 @@ class Dx9BackEnd : public BufferBackEnd
~Dx9BackEnd();
virtual TranslatedVertexBuffer *createVertexBuffer(std::size_t size);
virtual TranslatedVertexBuffer *createVertexBufferForStrideZero(std::size_t size);
virtual TranslatedIndexBuffer *createIndexBuffer(std::size_t size);
virtual FormatConverter getFormatConverter(GLenum type, std::size_t size, bool normalize);
@ -44,6 +45,8 @@ class Dx9BackEnd : public BufferBackEnd
IDirect3DVertexBuffer9 *getBuffer() const;
protected:
Dx9VertexBuffer(IDirect3DDevice9 *device, std::size_t size, DWORD usageFlags);
virtual void *map();
virtual void unmap();
@ -54,6 +57,16 @@ class Dx9BackEnd : public BufferBackEnd
IDirect3DVertexBuffer9 *mVertexBuffer;
};
class Dx9VertexBufferZeroStrideWorkaround : public Dx9VertexBuffer
{
public:
Dx9VertexBufferZeroStrideWorkaround(IDirect3DDevice9 *device, std::size_t size);
protected:
virtual void recycle();
virtual void *streamingMap(std::size_t offset, std::size_t size);
};
class Dx9IndexBuffer : public TranslatedIndexBuffer
{
public:

Просмотреть файл

@ -4614,7 +4614,13 @@ void __stdcall glVertexAttrib1f(GLuint index, GLfloat x)
return error(GL_INVALID_VALUE);
}
UNIMPLEMENTED(); // FIXME
gl::Context *context = gl::getContext();
if (context)
{
GLfloat vals[4] = { x, 0, 0, 1 };
context->setVertexAttrib(index, vals);
}
}
catch(std::bad_alloc&)
{
@ -4633,7 +4639,13 @@ void __stdcall glVertexAttrib1fv(GLuint index, const GLfloat* values)
return error(GL_INVALID_VALUE);
}
UNIMPLEMENTED(); // FIXME
gl::Context *context = gl::getContext();
if (context)
{
GLfloat vals[4] = { values[0], 0, 0, 1 };
context->setVertexAttrib(index, vals);
}
}
catch(std::bad_alloc&)
{
@ -4652,7 +4664,13 @@ void __stdcall glVertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
return error(GL_INVALID_VALUE);
}
UNIMPLEMENTED(); // FIXME
gl::Context *context = gl::getContext();
if (context)
{
GLfloat vals[4] = { x, y, 0, 1 };
context->setVertexAttrib(index, vals);
}
}
catch(std::bad_alloc&)
{
@ -4671,7 +4689,13 @@ void __stdcall glVertexAttrib2fv(GLuint index, const GLfloat* values)
return error(GL_INVALID_VALUE);
}
UNIMPLEMENTED(); // FIXME
gl::Context *context = gl::getContext();
if (context)
{
GLfloat vals[4] = { values[0], values[1], 0, 1 };
context->setVertexAttrib(index, vals);
}
}
catch(std::bad_alloc&)
{
@ -4690,7 +4714,13 @@ void __stdcall glVertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
return error(GL_INVALID_VALUE);
}
UNIMPLEMENTED(); // FIXME
gl::Context *context = gl::getContext();
if (context)
{
GLfloat vals[4] = { x, y, z, 1 };
context->setVertexAttrib(index, vals);
}
}
catch(std::bad_alloc&)
{
@ -4709,7 +4739,13 @@ void __stdcall glVertexAttrib3fv(GLuint index, const GLfloat* values)
return error(GL_INVALID_VALUE);
}
UNIMPLEMENTED(); // FIXME
gl::Context *context = gl::getContext();
if (context)
{
GLfloat vals[4] = { values[0], values[1], values[2], 1 };
context->setVertexAttrib(index, vals);
}
}
catch(std::bad_alloc&)
{
@ -4728,7 +4764,13 @@ void __stdcall glVertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, G
return error(GL_INVALID_VALUE);
}
UNIMPLEMENTED(); // FIXME
gl::Context *context = gl::getContext();
if (context)
{
GLfloat vals[4] = { x, y, z, w };
context->setVertexAttrib(index, vals);
}
}
catch(std::bad_alloc&)
{
@ -4747,7 +4789,12 @@ void __stdcall glVertexAttrib4fv(GLuint index, const GLfloat* values)
return error(GL_INVALID_VALUE);
}
UNIMPLEMENTED(); // FIXME
gl::Context *context = gl::getContext();
if (context)
{
context->setVertexAttrib(index, values);
}
}
catch(std::bad_alloc&)
{