osg.DrawElementsIndirectUByte
使用间接数组进行渲染的无符号字节索引绘制元素。
osg.DrawElementsIndirectUByte
是OpenSceneGraph 中的一个类,用于使用间接索引数组来进行绘制。
绘制元素使用一个固定的基本类型,无符号字节,长度为1个字节。
osg::DrawElementsUByte
-> osg::PrimitiveSet
-> osg::Object
-> osg::Referenced
-> osg::Drawable
-> osg::Geode
-> osg::Group
-> osg::Node
-> osg::Object
-> osg::Referenced
#include <osg/DrawElementsIndirectUByte>
class DrawElementsIndirectUByte : public DrawElementsUByte
函数 | 描述 |
---|---|
DrawElementsIndirectUByte(const GLenum mode, const GLenum type = GL_UNSIGNED_BYTE) |
构造函数,创建一个使用间接索引的绘制元素对象 |
DrawElementsIndirectUByte(const DrawElementsIndirectUByte& rhs, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY) |
拷贝构造函数 |
void draw(osg::State& state, bool useVertexBufferObjects) const |
渲染函数,绘制图形 |
void setDrawElementsIndirectBufferObject(BufferObject* drawElementsIndirectBufferObject) |
设置间接索引缓冲区对象 |
const BufferObject* getDrawElementsIndirectBufferObject() const |
获得间接索引缓冲区对象 |
BufferObject* getDrawElementsIndirectBufferObject() |
获得间接索引缓冲区对象 |
void setDrawElementsIndirectBufferOffset(const GLuint offset) |
设置间接索引在缓冲区中的偏移量 |
void setDrawElementsIndirect(const osg::DrawElementsIndirectUByte::Command& command) |
设置绘制命令,方便使用 |
void setDrawElementsIndirect(GLenum mode, GLenum type, GLsizei count, GLuint byteOffset, GLuint instanceCount, GLuint baseInstance) |
设置绘制命令,详细控制 |
const osg::DrawElementsIndirectUByte::Command& getDrawElementsIndirect() const |
获得绘制命令 |
osg::DrawElementsIndirectUByte::Command& getDrawElementsIndirect() |
获得绘制命令 |
GLuint getDrawElementsIndirectOffset() const |
获得间接索引在缓冲区中的偏移量 |
GLsizei getDrawElementsIndirectStride() const |
获得绘制命令结构体的字节宽度,默认为20字节 |
void setInstanceCount(GLuint instanceCount) |
设置实例数,非实例化绘制时为0 |
GLuint getInstanceCount() const |
获得实例数,非实例化绘制时返回0 |
void setBaseInstance(GLuint baseInstance) |
设置基础实例,GLSL中使用 |
GLuint getBaseInstance() const |
返回基础实例 |
DrawElementsUByte* getDrawElements() const |
返回使用的绘制元素 |
class DrawElementsIndirectUByte : public DrawElementsUByte
{
public:
struct Command
{
GLuint count; // number of indexs to be rendered
GLuint instanceCount; // number of instances to be rendered
GLuint firstIndex; // base index into the element buffer
GLuint baseVertex; // offsets added to vertex index
GLuint baseInstance; // instance id offset
};
DrawElementsIndirectUByte(const GLenum mode, const GLenum type = GL_UNSIGNED_BYTE);
DrawElementsIndirectUByte(const DrawElementsIndirectUByte& rhs, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
META_Drawable(osg, DrawElementsIndirectUByte, OSG_EXPORT);
virtual void draw(osg::State& state, bool useVertexBufferObjects) const;
void setDrawElementsIndirectBufferObject(BufferObject* drawElementsIndirectBufferObject);
const BufferObject* getDrawElementsIndirectBufferObject() const;
BufferObject* getDrawElementsIndirectBufferObject();
void setDrawElementsIndirectBufferOffset(const GLuint offset) { _indirectByteOffset = offset; }
GLuint getDrawElementsIndirectOffset() const { return _indirectByteOffset; }
GLsizei getDrawElementsIndirectStride() const { return _stride; }
void setInstanceCount(GLuint instanceCount) { _instanceCount = instanceCount; }
GLuint getInstanceCount() const { return _instanceCount; }
void setBaseInstance(GLuint baseInstance) { _baseInstance = baseInstance; }
GLuint getBaseInstance() const { return _baseInstance; }
void setDrawElementsIndirect(const osg::DrawElementsIndirectUByte::Command& command);
void setDrawElementsIndirect(GLenum mode, GLenum type, GLsizei count, GLuint byteOffset, GLuint instanceCount, GLuint baseInstance);
const osg::DrawElementsIndirectUByte::Command& getDrawElementsIndirect() const;
osg::DrawElementsIndirectUByte::Command& getDrawElementsIndirect();
DrawElementsUByte* getDrawElements() const { return _drawElements.get(); }
protected:
virtual ~DrawElementsIndirectUByte() {}
osg::ref_ptr<DrawElementsUByte> _drawElements;
GLuint _indirectByteOffset;
GLsizei _stride;
GLuint _instanceCount;
GLuint _baseInstance;
bool _locked;
osg::DrawElementsIndirectUByte::Command _command;
};
// 创建一个 DrawElementsIndirectUByte 对象
osg::ref_ptr<osg::DrawElementsIndirectUByte> drawElementsIndirectUByte = new osg::DrawElementsIndirectUByte(GL_TRIANGLES, GL_UNSIGNED_BYTE);
// 创建数据
GLubyte indices[] = { 0, 1, 2, 3, 4, 5 };
unsigned int numIndices = sizeof(indices) / sizeof(GLubyte);
osg::ref_ptr<osg::ByteArray> indexArray = new osg::ByteArray(reinterpret_cast<char*>(indices), sizeof(indices));
osg::ref_ptr<osg::BufferObject> indexBufferObject = new osg::BufferObject;
indexBufferObject->setUsage(osg::BufferObject::STATIC_DRAW);
indexBufferObject->setTarget(osg::BufferObject::ELEMENT_ARRAY_BUFFER);
indexBufferObject->setDataVariance(osg::Object::STATIC);
indexBufferObject->setData(indexArray);
osg::DrawElementsIndirectUByte::Command command;
command.count = numIndices;
command.instanceCount = 1;
command.firstIndex = 0;
command.baseVertex = 0;
command.baseInstance = 0;
drawElementsIndirectUByte->setDrawElementsIndirect(command);
drawElementsIndirectUByte->setDrawElements(indexArray->getArray(), osg::PrimitiveSet::TRIANGLES);
DrawElements* drawElements = drawElementsIndirectUByte->getDrawElements();
if (drawElements)
{
// ...
}