#ifndef _gpuCacheVBOProxy_h_
#define _gpuCacheVBOProxy_h_
#include "gpuCacheSample.h"
#include <maya/MGLdefinitions.h>
#include <boost/shared_ptr.hpp>
#include <boost/make_shared.hpp>
namespace GPUCache {
class VBOBuffer
{
public:
typedef ArrayBase::Key Key;
typedef ArrayBase::KeyHash KeyHash;
typedef ArrayBase::KeyEqualTo KeyEqualTo;
enum BufferType {
kIndexBufferType,
kVertexBufferType,
kFlippedNormalBufferType,
kNbBufferType
};
static boost::shared_ptr<const VBOBuffer> create(
const boost::shared_ptr<const IndexBuffer>& buffer,
const bool isTemporary = false);
static boost::shared_ptr<const VBOBuffer> create(
const boost::shared_ptr<const VertexBuffer>& buffer,
const bool isTemporary = false);
static boost::shared_ptr<const VBOBuffer> createFlippedNormals(
const boost::shared_ptr<const VertexBuffer>& buffer,
const bool isTemporary = false);
static boost::shared_ptr<const VBOBuffer> lookup(
const boost::shared_ptr<const IndexBuffer>& buffer);
static boost::shared_ptr<const VBOBuffer> lookup(
const boost::shared_ptr<const VertexBuffer>& buffer);
static boost::shared_ptr<const VBOBuffer> lookupFlippedNormals(
const boost::shared_ptr<const VertexBuffer>& buffer);
static size_t nbAllocatedBytes();
static size_t nbIndexAllocatedBytes();
static size_t nbVertexAllocatedBytes();
static size_t nbAllocated();
static size_t nbIndexAllocated();
static size_t nbVertexAllocated();
static size_t nbUploaded();
static size_t nbUploadedBytes();
static size_t nbEvicted();
static size_t nbEvictedBytes();
static void clear();
static void nextRefresh();
virtual ~VBOBuffer();
BufferType bufferType() const { return fBufferType; }
const Key& key() const { return fKey; }
MGLuint name() const { return fVBOName; }
private:
GPUCACHE_DECLARE_MAKE_SHARED_FRIEND_3;
VBOBuffer(BufferType bufferType, const Key& key, const void* buffer);
VBOBuffer(BufferType bufferType, const Key& key, MGLuint vboName);
VBOBuffer(const VBOBuffer&);
const VBOBuffer& operator=(const VBOBuffer&);
static size_t fsTotalVBOSize;
static size_t fsNbAllocated;
static size_t fsNbUploaded;
static size_t fsNbUploadedBytes;
static size_t fsNbEvicted;
static size_t fsNbEvictedBytes;
const BufferType fBufferType;
const ArrayBase::Key fKey;
MGLuint fVBOName;
};
class VBOProxy
{
public:
enum NormalsMode {
kNoNormals,
kFrontNormals,
kBackNormals
};
enum UVsMode {
kNoUVs,
kUVs
};
enum VBOMode {
kUseVBOIfPossible,
kDontUseVBO
};
VBOProxy();
~VBOProxy();
void drawVertices(
const boost::shared_ptr<const ShapeSample>& sample,
const VBOMode vboMode = kUseVBOIfPossible);
void drawWireframe(
const boost::shared_ptr<const ShapeSample>& sample,
const VBOMode vboMode = kUseVBOIfPossible);
void drawTriangles(
const boost::shared_ptr<const ShapeSample>& sample,
const size_t groupId,
const NormalsMode normalsMode, const UVsMode uvsMode,
const VBOMode vboMode = kUseVBOIfPossible);
void drawBoundingBox(
const boost::shared_ptr<const ShapeSample>& sample,
bool overrideShadedState = false);
void drawBoundingBox(
bool overrideShadedState = false);
private:
typedef IndexBuffer::index_t index_t;
enum BindingType {
kPrimitives,
kVertexArrays,
kVBOs
};
VBOProxy(const VBOProxy&);
const VBOProxy& operator=(const VBOProxy&);
BindingType updateBuffers(
const boost::shared_ptr<const IndexBuffer>& indices,
const boost::shared_ptr<const VertexBuffer>& positions,
const boost::shared_ptr<const VertexBuffer>& normals,
const boost::shared_ptr<const VertexBuffer>& uvs,
const bool areNormalsFlipped,
const VBOMode vboMode,
VertexBuffer::ReadInterfacePtr& positionsRead,
VertexBuffer::ReadInterfacePtr& normalsRead,
VertexBuffer::ReadInterfacePtr& uvsRead
);
boost::shared_ptr<const IndexBuffer> fIndices;
boost::shared_ptr<const VertexBuffer> fPositions;
boost::shared_ptr<const VertexBuffer> fNormals;
boost::shared_ptr<const VertexBuffer> fUVs;
boost::shared_ptr<const VBOBuffer> fVBOIndices;
boost::shared_ptr<const VBOBuffer> fVBOPositions;
boost::shared_ptr<const VBOBuffer> fVBONormals;
boost::shared_ptr<const VBOBuffer> fVBOUVs;
bool fAreNormalsFlipped;
BindingType fLastBindingType;
};
}
#endif