|
AGX Dynamics 2.42.1.1
|
Empty geometry which can load vertex, geometry and fragment shaders, or create a custom osg::Program. More...
#include <ShaderGeometry.h>
Inheritance diagram for agxOSG::ShaderGeometry:Classes | |
| struct | RenderOrder |
| This will determine the render order of the shaders, e.g., render faces before edges. More... | |
Public Types | |
| using | OsgShaderRef = osg::ref_ptr< osg::Shader > |
| using | OsgVec3ArrayRef = osg::ref_ptr< osg::Vec3Array > |
| using | OsgVec4ArrayRef = osg::ref_ptr< osg::Vec4Array > |
Public Member Functions | |
| bool | bind (size_t location, osg::Array *array, std::string name="") |
Bind array to location. | |
| void | createVertexBuffer (size_t size, int renderMode=-1) |
| Creates the vertex buffer and binds it to: layout(location = 0) in vec3 in_vertex. | |
| template<typename VertexArrayType > | |
| VertexArrayType * | getVertexAttributeArray (std::string name="") const |
| Finds the vertex attribute array of the given type and name. | |
| virtual bool | initialize () |
| Initialize shaders and attributes. | |
| 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 in "data/shaders". | |
| virtual void | update () |
| Called on frame update when the deformable data is dirty. | |
Static Public Member Functions | |
| static OsgShaderGeometryRefVector | getSorted (const OsgShaderGeometryRefVector &in) |
Sort in given render priority EARLY -> LATE. | |
| static void | insertSorted (OsgShaderGeometryRefVector &v, OsgShaderGeometryRef shaderGeometry) |
Inserts shaderGeometry such that v is still sorted on render order. | |
Public Attributes | |
| OsgVec3ArrayRef | vertices {} |
Protected Member Functions | |
| ShaderGeometry (agx::UInt16 renderOrder) | |
| virtual | ~ShaderGeometry ()=default |
Empty geometry which can load vertex, geometry and fragment shaders, or create a custom osg::Program.
Just override initialize, create shaders and create vertex, and other buffers. E.g., a triangle created in a geometry shader:
bool initialize() override
{
if ( !ShaderGeometry::loadShaders( "myShaders/foo" ) )
return false;
TRIANGLES means three vertices input to the geometry shader, LINES -> two, and POINTS one. ShaderGeometry::createVertexBuffer( 3u, osg::PrimitiveSet::TRIANGLES );
(*vertices)[ 0 ].set( -0.5f, 0.0f, 0.0f ); (*vertices)[ 1 ].set( 0.5f, 0.0f, 0.0f ); (*vertices)[ 2 ].set( 0.0f, 0.0f, 0.5f );
auto colors = new osg::Vec4Array( (unsigned)3u ); The vertex buffer is at location=0, location=1 and above are available. ShaderGeometry::bind( 1, colors );
(*colors)[ 0 ].set( 1, 0, 0, 1 ); (*colors)[ 1 ].set( 0, 1, 0, 1 ); (*colors)[ 2 ].set( 0, 0, 1, 1 ); }
foo.vert: -------------------------------------------------—
#version 400 compatibility
layout(location=0) in vec3 in_position;
layout(location=1) in vec4 in_color;
out vec3 vs_position;
out vec4 vs_color;
void main()
{
vs_position = in_position;
vs_color = in_color;
(gl_Position is set in foo.geom) }
foo.geom: -------------------------------------------------—
#version 400 compatibility
layout(triangles) in;
layout(triangle_strip, max_vertices=3) out;
in vec3 vs_position[];
in vec4 vs_color[];
out vec4 gs_color;
void main()
{
for (int i = 0; i < 3; ++i) {
gl_Position = gl_ModelViewProjectionMatrix * vec4(vs_position[i], 1.0);
gs_color = vs_color[i];
EmitVertex();
}
EndPrimitive();
}
foo.frag: -------------------------------------------------—
#version 400 compatibility
in vec4 gs_color;
out vec4 fragColor;
void main()
{
fragColor = gs_color;
}
Definition at line 118 of file ShaderGeometry.h.
| using agxOSG::ShaderGeometry::OsgShaderRef = osg::ref_ptr<osg::Shader> |
Definition at line 122 of file ShaderGeometry.h.
| using agxOSG::ShaderGeometry::OsgVec3ArrayRef = osg::ref_ptr<osg::Vec3Array> |
Definition at line 120 of file ShaderGeometry.h.
| using agxOSG::ShaderGeometry::OsgVec4ArrayRef = osg::ref_ptr<osg::Vec4Array> |
Definition at line 121 of file ShaderGeometry.h.
|
protected |
|
protectedvirtualdefault |
| bool agxOSG::ShaderGeometry::bind | ( | size_t | location, |
| osg::Array * | array, | ||
| std::string | name = "" |
||
| ) |
Bind array to location.
If there's an array at location, false is retuned. The array is implicitly per vertex bound.
| location | - vertex shader layout(location = location) > 0 for the array |
| array | - array to bind |
| name | - optional name of the array to be found using getVertexAttributeArray |
location is available and array is of correct size, otherwise false | void agxOSG::ShaderGeometry::createVertexBuffer | ( | size_t | size, |
| int | renderMode = -1 |
||
| ) |
Creates the vertex buffer and binds it to: layout(location = 0) in vec3 in_vertex.
| size | - number of vertices |
| renderMode | - render mode (osg::PrimitiveSet::Mode) that should match the geometry shader layout, -1 to not set this |
|
static |
Sort in given render priority EARLY -> LATE.
| in | - input vector to be sorted (not touched) |
in | VertexArrayType * agxOSG::ShaderGeometry::getVertexAttributeArray | ( | std::string | name = "" | ) | const |
Finds the vertex attribute array of the given type and name.
| name | - name of the vertex attribute array |
Definition at line 206 of file ShaderGeometry.h.
|
virtual |
Initialize shaders and attributes.
Reimplemented in agxOSG::DeformableEdgeShader, and agxOSG::DeformableFaceShader.
|
static |
Inserts shaderGeometry such that v is still sorted on render order.
| bool agxOSG::ShaderGeometry::loadShaders | ( | std::string_view | sourcePath | ) |
Path and name, e.g., "data/shaders/foo" and "foo.vert", "foo.geom", "foo.frag" will be searched for in "data/shaders".
| sourcePath | - path to shader files including common name of the shaders |
sourcePath exists and at least one shader is loaded, otherwise false
|
virtual |
Called on frame update when the deformable data is dirty.
Reimplemented in agxOSG::DeformableEdgeShader, and agxOSG::DeformableFaceShader.
| OsgVec3ArrayRef agxOSG::ShaderGeometry::vertices {} |
Definition at line 180 of file ShaderGeometry.h.