AGX Dynamics 2.42.1.1
Loading...
Searching...
No Matches
ShaderGeometry.h
Go to the documentation of this file.
1/*
2Copyright 2007-2025. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx Simulation AB.
15*/
16
17#pragma once
18
19#include <osg/MatrixTransform>
20#include <osg/Geometry>
21
22#include <agxOSG/export.h>
23
24#include <agxRender/Color.h>
25
26namespace agxOSG
27{
28 struct ShaderGeometry;
29 using OsgShaderGeometryRef = osg::ref_ptr<ShaderGeometry>;
30 using OsgShaderGeometryRefVector = std::vector<OsgShaderGeometryRef>;
31
118 struct AGXOSG_EXPORT ShaderGeometry : public osg::Geometry
119 {
120 using OsgVec3ArrayRef = osg::ref_ptr<osg::Vec3Array>;
121 using OsgVec4ArrayRef = osg::ref_ptr<osg::Vec4Array>;
122 using OsgShaderRef = osg::ref_ptr<osg::Shader>;
123
130
135
142 bool loadShaders( std::string_view sourcePath );
143
150 void createVertexBuffer( size_t size, int renderMode = -1 );
151
160 bool bind( size_t location, osg::Array* array, std::string name = "" );
161
167 template<typename VertexArrayType>
168 VertexArrayType* getVertexAttributeArray( std::string name = "" ) const;
169
173 virtual bool initialize();
174
178 virtual void update();
179
180 OsgVec3ArrayRef vertices{};
181
182 protected:
188 {
190 {
191 EARLY = 1 << 4,
192 MIDDLE = 1 << 8,
193 LATE = 1 << 12,
194 };
195 };
196
197 protected:
199 virtual ~ShaderGeometry() = default;
200
201 private:
202 agx::UInt16 m_renderOrder = (agx::UInt16)RenderOrder::MIDDLE;
203 };
204
205 template<typename VertexArrayType>
206 VertexArrayType* ShaderGeometry::getVertexAttributeArray( std::string name /*= ""*/ ) const
207 {
208 // 'vertices' is at index 0 and is a member of this instance so that
209 // should be used explicitly.
210 for ( unsigned i = 1u; i < getNumVertexAttribArrays(); ++i ) {
211 auto array = getVertexAttribArray( i );
212 if ( auto arrayOfType = dynamic_cast<const VertexArrayType*>( array ) )
213 if ( arrayOfType->getName() == name )
214 return const_cast<VertexArrayType*>( arrayOfType );
215 }
216
217 return nullptr;
218 }
219}
#define AGXOSG_EXPORT
The agxOSG namespace provides functionality for visualizing AGX simulations with OpenSceneGraph.
osg::ref_ptr< ShaderGeometry > OsgShaderGeometryRef
std::vector< OsgShaderGeometryRef > OsgShaderGeometryRefVector
uint16_t UInt16
Definition: Integer.h:31
This will determine the render order of the shaders, e.g., render faces before edges.
Empty geometry which can load vertex, geometry and fragment shaders, or create a custom osg::Program.
virtual void update()
Called on frame update when the deformable data is dirty.
osg::ref_ptr< osg::Vec3Array > OsgVec3ArrayRef
virtual bool initialize()
Initialize shaders and attributes.
static OsgShaderGeometryRefVector getSorted(const OsgShaderGeometryRefVector &in)
Sort in given render priority EARLY -> LATE.
bool loadShaders(std::string_view sourcePath)
Path and name, e.g., "data/shaders/foo" and "foo.vert", "foo.geom", "foo.frag" will be searched for i...
virtual ~ShaderGeometry()=default
void createVertexBuffer(size_t size, int renderMode=-1)
Creates the vertex buffer and binds it to: layout(location = 0) in vec3 in_vertex.
osg::ref_ptr< osg::Shader > OsgShaderRef
static void insertSorted(OsgShaderGeometryRefVector &v, OsgShaderGeometryRef shaderGeometry)
Inserts shaderGeometry such that v is still sorted on render order.
ShaderGeometry(agx::UInt16 renderOrder)
bool bind(size_t location, osg::Array *array, std::string name="")
Bind array to location.
VertexArrayType * getVertexAttributeArray(std::string name="") const
Finds the vertex attribute array of the given type and name.
osg::ref_ptr< osg::Vec4Array > OsgVec4ArrayRef