root/OpenSceneGraph/trunk/include/osg/BufferIndexBinding @ 13041

Revision 13041, 4.9 kB (checked in by robert, 3 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 * Copyright (C) 2010 Tim Moore
3 *
4 * This library is open source and may be redistributed and/or modified under
5 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
6 * (at your option) any later version.  The full license is in LICENSE file
7 * included with this distribution, and on the openscenegraph.org website.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * OpenSceneGraph Public License for more details.
13*/
14
15#ifndef OSG_BUFFERINDEXBINDING
16#define OSG_BUFFERINDEXBINDING 1
17
18#include <osg/Export>
19#include <osg/BufferObject>
20#include <osg/StateAttribute>
21
22#ifndef GL_TRANSFORM_FEEDBACK_BUFFER
23    #define GL_TRANSFORM_FEEDBACK_BUFFER      0x8C8E
24#endif
25
26namespace osg {
27
28class State;
29
30/** Encapsulate binding buffer objects to index targets. This
31 * specifically supports the uniform buffer and transform feedback
32 * targets.
33 */
34
35// Common implementation superclass
36class OSG_EXPORT BufferIndexBinding : public StateAttribute
37{
38 protected:
39    BufferIndexBinding(GLenum target, GLuint index);
40    BufferIndexBinding(GLenum target, GLuint index, BufferObject* bo, GLintptr offset,
41                       GLsizeiptr size);
42    BufferIndexBinding(const BufferIndexBinding& rhs, const CopyOp& copyop=CopyOp::SHALLOW_COPY);
43 public:
44    // The member value is part of the key to this state attribute in
45    // the State class. Using the index target, we can seperately
46    // track the bindings for many different index targets.
47    virtual unsigned getMember() const { return static_cast<unsigned int>(_index); }
48
49    GLenum getTarget() const { return _target; }
50    /** Get the index target.
51     */
52    GLuint getIndex() const { return _index; }
53    /** Set the buffer object that will be bound to the index target.
54     */
55    void setBufferObject(BufferObject *bo) { _bufferObject = bo; }
56    /** Get the buffer object to be bound.
57     */
58    BufferObject* getBufferObject() const { return _bufferObject.get(); }
59    /** Set the starting offset into the buffer object for data for
60    the indexed target. Note: the required  alignment on the offset
61    may be quite large (e.g., 256 bytes on NVidia 8600M). This
62    should be checked with glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT...).
63    */
64    void setOffset(GLintptr offset) { _offset = offset; }
65    GLintptr getOffset() const { return _offset; }
66    /** Set the size of data for the indexed target.
67     */
68    void setSize(GLsizeiptr size) { _size = size; }
69    GLsizeiptr getSize() const { return _size; }
70    virtual void apply(State& state) const;
71 protected:
72    virtual ~BufferIndexBinding();
73    const GLenum _target;
74    const GLuint _index;
75    ref_ptr<BufferObject> _bufferObject;
76    GLintptr _offset;
77    GLsizeiptr _size;
78};
79
80/** StateAttribute for binding a uniform buffer index target.
81 */
82class OSG_EXPORT UniformBufferBinding : public BufferIndexBinding
83{
84 public:
85    UniformBufferBinding();
86    UniformBufferBinding(GLuint index);
87    /** Create a binding for a uniform buffer index target.
88     *  @param index the index target
89     *  @param bo associated buffer object
90     *  @param offset offset into buffer object
91     *  @param size size of data in buffer object
92     */
93    UniformBufferBinding(GLuint index, BufferObject* bo, GLintptr offset, GLsizeiptr size);
94    UniformBufferBinding(const UniformBufferBinding& rhs, const CopyOp& copyop=CopyOp::SHALLOW_COPY);
95    META_StateAttribute(osg, UniformBufferBinding, UNIFORMBUFFERBINDING);
96
97    virtual int compare(const StateAttribute& bb) const
98    {
99        COMPARE_StateAttribute_Types(UniformBufferBinding, bb)
100
101        COMPARE_StateAttribute_Parameter(_target)
102        COMPARE_StateAttribute_Parameter(_index)
103        COMPARE_StateAttribute_Parameter(_bufferObject)
104        COMPARE_StateAttribute_Parameter(_offset)
105        COMPARE_StateAttribute_Parameter(_size)
106        return 0;
107    }
108};
109
110/** StateAttribute for binding a transform feedback index target.
111 */
112class OSG_EXPORT TransformFeedbackBufferBinding : public BufferIndexBinding
113{
114 public:
115    TransformFeedbackBufferBinding(GLuint index = 0);
116    TransformFeedbackBufferBinding(GLuint index, BufferObject* bo, GLintptr offset, GLsizeiptr size);
117    TransformFeedbackBufferBinding(const TransformFeedbackBufferBinding& rhs, const CopyOp& copyop=CopyOp::SHALLOW_COPY);
118    META_StateAttribute(osg, TransformFeedbackBufferBinding, TRANSFORMFEEDBACKBUFFERBINDING);
119
120    virtual int compare(const StateAttribute& bb) const
121    {
122        COMPARE_StateAttribute_Types(TransformFeedbackBufferBinding, bb)
123
124        COMPARE_StateAttribute_Parameter(_target)
125        COMPARE_StateAttribute_Parameter(_index)
126        COMPARE_StateAttribute_Parameter(_bufferObject)
127        COMPARE_StateAttribute_Parameter(_offset)
128        COMPARE_StateAttribute_Parameter(_size)
129        return 0;
130    }
131};
132}
133
134#endif
Note: See TracBrowser for help on using the browser.