CUGL 4.0
Cornell University Game Library
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
cugl::scene3::ObjShader Class Reference

#include <CUObjShader.h>

Inheritance diagram for cugl::scene3::ObjShader:
cugl::graphics::GraphicsShader

Public Member Functions

 ObjShader ()
 
 ~ObjShader ()
 
void dispose () override
 
bool init ()
 
bool init (const graphics::ShaderSource &vsource, const graphics::ShaderSource &fsource) override
 
void setPerspective (const Mat4 &matrix)
 
void setModelMatrix (const Mat4 &matrix)
 
void setNormalMatrix (const Mat4 &matrix)
 
void setLightPosition (const Vec3 &pos)
 
void setIllum (int value)
 
void setAmbientColor (const Color4f color)
 
void setDiffuseColor (const Color4f color)
 
void setSpecularColor (const Color4f color)
 
void setSpecularExponent (float value)
 
void setAmbientTexture (const std::shared_ptr< graphics::Texture > &texture)
 
void setDiffuseTexture (const std::shared_ptr< graphics::Texture > &texture)
 
void setSpecularTexture (const std::shared_ptr< graphics::Texture > &texture)
 
void setNormalTexture (const std::shared_ptr< graphics::Texture > &texture)
 
- Public Member Functions inherited from cugl::graphics::GraphicsShader
 GraphicsShader ()
 
 ~GraphicsShader ()
 
virtual void dispose ()
 
virtual bool init (const ShaderSource &vsource, const ShaderSource &fsource)
 
bool declareAttribute (const std::string name, const AttributeDef &def)
 
const AttributeDefgetAttributeDef (const std::string name) const
 
void setInstanced (Uint32 group, bool instanced)
 
void setAttributeStride (Uint32 group, size_t stride)
 
bool declareUniform (const std::string name, const UniformDef &def)
 
const UniformDefgetUniformDef (const std::string name) const
 
bool declareResource (const std::string name, const ResourceDef &def)
 
const ResourceDefgetResourceDef (const std::string name) const
 
void setRenderPass (const std::shared_ptr< RenderPass > &pass)
 
const std::shared_ptr< RenderPass > & getRenderPass () const
 
bool compile ()
 
bool isReady () const
 
void enableViewScissor (bool enable)
 
bool usesViewScissor () const
 
void setViewScissor (Uint32 x, Uint32 y, Uint32 w, Uint32 h)
 
void setViewScissor (const Rect &scissor)
 
Rect getViewScissor ()
 
void enableBlending (bool enable)
 
bool usesBlending () const
 
void enableDepthTest (bool enable)
 
bool usesDepthTest () const
 
void enableDepthWrite (bool enable)
 
bool usesDepthWrite () const
 
void enableStencilTest (bool enable)
 
bool usesStencilTest () const
 
void setDrawMode (DrawMode mode)
 
DrawMode getDrawMode () const
 
void setFrontFace (FrontFace face)
 
FrontFace getFrontFace () const
 
void setCullMode (CullMode mode)
 
CullMode getCullMode () const
 
void setDepthFunc (CompareOp func)
 
CompareOp getDepthFunc () const
 
void setStencilState (const StencilState &stencil)
 
void setFrontStencilState (const StencilState &stencil)
 
void setBackStencilState (const StencilState &stencil)
 
const StencilStategetFrontStencilState () const
 
const StencilStategetBackStencilState () const
 
void setColorMask (Uint8 mask)
 
Uint8 getColorMask () const
 
void setStencilMode (StencilMode mode)
 
void setBlendState (const BlendState &blend)
 
const BlendStategetBlendState () const
 
void setBlendMode (BlendMode mode)
 
void setLineWidth (float width)
 
float getLineWidth () const
 
void setVertices (Uint32 group, const std::shared_ptr< VertexBuffer > &vertices)
 
const std::shared_ptr< VertexBuffergetVertices (Uint32 group) const
 
void setIndices (const std::shared_ptr< IndexBuffer > &indices)
 
const std::shared_ptr< IndexBuffergetIndices () const
 
void setUniformBuffer (const std::string name, const std::shared_ptr< UniformBuffer > &buffer)
 
void setUniformBuffers (const std::string name, const std::vector< std::shared_ptr< UniformBuffer > > &buffers)
 
const std::shared_ptr< UniformBuffergetUniformBuffer (const std::string name) const
 
const std::vector< std::shared_ptr< UniformBuffer > > getUniformBuffers (const std::string name) const
 
void setStorageBuffer (const std::string name, const std::shared_ptr< StorageBuffer > &buffer)
 
void setStorageBuffers (const std::string name, const std::vector< std::shared_ptr< StorageBuffer > > &buffers)
 
const std::shared_ptr< StorageBuffergetStorageBuffer (const std::string name) const
 
const std::vector< std::shared_ptr< StorageBuffer > > getStorageBuffers (const std::string name) const
 
void setBlock (const std::string name, Uint32 block)
 
Uint32 getBlock (const std::string name)
 
void setTexture (const std::string name, const std::shared_ptr< Texture > &texture)
 
void setTextures (const std::string name, const std::vector< std::shared_ptr< Texture > > &textures)
 
const std::shared_ptr< TexturegetTexture (const std::string name) const
 
const std::vector< std::shared_ptr< Texture > > getTextures (const std::string name) const
 
void setTextureArray (const std::string name, const std::shared_ptr< TextureArray > &array)
 
void setTextureArrays (const std::string name, const std::vector< std::shared_ptr< TextureArray > > &arrays)
 
const std::shared_ptr< TextureArraygetTextureArray (const std::string name) const
 
const std::vector< std::shared_ptr< TextureArray > > getTextureArrays (const std::string name) const
 
void setImage (const std::string name, const std::shared_ptr< Image > &image)
 
void setImages (const std::string name, const std::vector< std::shared_ptr< Image > > &images)
 
const std::shared_ptr< ImagegetImage (const std::string name) const
 
const std::vector< std::shared_ptr< Image > > getImages (const std::string name) const
 
void setImageArray (const std::string name, const std::shared_ptr< ImageArray > &array)
 
void setImageArrays (const std::string name, const std::vector< std::shared_ptr< ImageArray > > &arrays)
 
const std::shared_ptr< ImageArraygetImageArray (const std::string name) const
 
const std::vector< std::shared_ptr< ImageArray > > getImageArrays (const std::string name) const
 
void setSampler (const std::string name, const std::shared_ptr< Sampler > &sampler)
 
void setSamplers (const std::string name, const std::vector< std::shared_ptr< Sampler > > &samplers)
 
const std::shared_ptr< SamplergetSampler (const std::string name) const
 
const std::vector< std::shared_ptr< Sampler > > getSamplers (const std::string name) const
 
void pushInt (const std::string name, Sint32 value)
 
void pushUInt (const std::string name, Uint32 value)
 
void pushFloat (const std::string name, float value)
 
void pushVec2 (const std::string name, const Vec2 &vec)
 
void pushVec2 (const std::string name, float x, float y)
 
void pushVec3 (const std::string name, const Vec3 &vec)
 
void pushVec3 (const std::string name, float x, float y, float z)
 
void pushVec4 (const std::string name, const Vec4 &vec)
 
void pushVec4 (const std::string name, const Quaternion &quat)
 
void pushVec4 (const std::string name, float x, float y, float z, float w)
 
void pushIVec2 (const std::string name, Sint32 x, Sint32 y)
 
void pushIVec3 (const std::string name, Sint32 x, Sint32 y, Sint32 z)
 
void pushIVec4 (const std::string name, Sint32 x, Sint32 y, Sint32 z, Sint32 w)
 
void pushUVec2 (const std::string name, Uint32 x, Uint32 y)
 
void pushUVec3 (const std::string name, Uint32 x, Uint32 y, Uint32 z)
 
void pushUVec4 (const std::string name, Uint32 x, Uint32 y, Uint32 z, Uint32 w)
 
void pushColor4f (const std::string name, const Color4f &color)
 
void pushColor4f (const std::string name, float red, float green, float blue, float alpha)
 
void pushColor4 (const std::string name, const Color4 color)
 
void pushColor4 (const std::string name, Uint8 red, Uint8 green, Uint8 blue, Uint8 alpha)
 
void pushMat2 (const std::string name, const Affine2 &mat)
 
void pushMat2 (const std::string name, const float *array)
 
void pushMat3 (const std::string name, const Affine2 &mat)
 
void pushMat3 (const std::string name, const float *array)
 
void pushMat4 (const std::string name, const Mat4 &mat)
 
void pushMat4 (const std::string name, const float *array)
 
void push (const std::string name, Uint8 *data)
 
template<typename T >
void push (const std::string name, T value)
 
void begin ()
 
void begin (const std::shared_ptr< FrameBuffer > &framebuffer)
 
void end ()
 
void draw (Uint32 count, Uint32 offset=0)
 
void drawIndexed (Uint32 count, Uint32 offset=0)
 
void drawInstances (Uint32 count, Uint32 instances, Uint32 vtxoff=0, Uint32 insoff=0)
 
void drawInstancesIndexed (Uint32 count, Uint32 instances, Uint32 idxoff=0, Uint32 insoff=0)
 

Static Public Member Functions

static std::shared_ptr< ObjShaderalloc ()
 
static std::shared_ptr< ObjShaderalloc (const graphics::ShaderSource &vsource, const graphics::ShaderSource &fsource)
 
- Static Public Member Functions inherited from cugl::graphics::GraphicsShader
static std::shared_ptr< GraphicsShaderalloc (const ShaderSource &vsource, ShaderSource &fsource)
 

Additional Inherited Members

- Protected Member Functions inherited from cugl::graphics::GraphicsShader
bool validate ()
 
bool isCompatible (const std::shared_ptr< FrameBuffer > &framebuffer)
 
void flush ()
 
- Protected Attributes inherited from cugl::graphics::GraphicsShader
GraphicsShaderData * _data
 
ShaderSource _vertModule
 
ShaderSource _fragModule
 
size_t _attachments
 
std::unordered_map< std::string, AttributeDef_attributes
 
std::vector< Uint32 > _attrStride
 
std::unordered_map< std::string, UniformDef_uniforms
 
std::unordered_map< std::string, ResourceDef_resources
 
std::unordered_set< Uint32 > _instances
 
Uint32 _initialGroup
 
std::vector< std::shared_ptr< VertexBuffer > > _vertices
 
std::shared_ptr< IndexBuffer_indices
 
std::unordered_map< std::string, ResourceData * > _values
 
std::shared_ptr< RenderPass_renderpass
 
std::shared_ptr< FrameBuffer_framebuffer
 
- Static Protected Attributes inherited from cugl::graphics::GraphicsShader
static std::shared_ptr< GraphicsShaderg_shader
 

Detailed Description

This class is a shader for rendering ObjModel objects.

This class is a very lighweight subclass of GraphicsShader. It exists mainly to simplify the compilation process.

Constructor & Destructor Documentation

◆ ObjShader()

cugl::scene3::ObjShader::ObjShader ( )

Creates an uninitialized shader with no source.

You must initialize the shader for it to be compiled.

◆ ~ObjShader()

cugl::scene3::ObjShader::~ObjShader ( )
inline

Deletes this shader, disposing all resources.

Member Function Documentation

◆ alloc() [1/2]

static std::shared_ptr< ObjShader > cugl::scene3::ObjShader::alloc ( )
inlinestatic

Returns a newly allocated shader with the standard vertex and fragment source.

The shader will compile the vertex and fragment sources and link them together. When compilation is complete, the shader will be bound and active. In addition, all uniforms will be validated.

Returns
a newly allocated shader with the standard vertex and fragment source.

◆ alloc() [2/2]

static std::shared_ptr< ObjShader > cugl::scene3::ObjShader::alloc ( const graphics::ShaderSource vsource,
const graphics::ShaderSource fsource 
)
inlinestatic

Returns a newly allocated shader with the given vertex and fragment source.

The shader will compile the vertex and fragment sources and link them together. When compilation is complete, the shader will be bound and active. In addition, all uniforms will be validated.

Parameters
vsourceThe source for the vertex shader.
fsourceThe source for the fragment shader.
Returns
a newly allocated shader with the given vertex and fragment source.

◆ dispose()

void cugl::scene3::ObjShader::dispose ( )
overridevirtual

Deletes the shader program and resets all attributes.

You must reinitialize the shader to use it.

Reimplemented from cugl::graphics::GraphicsShader.

◆ init() [1/2]

bool cugl::scene3::ObjShader::init ( )

Initializes this shader with the standard vertex and fragment source.

The shader will compile the vertex and fragment sources and link them together. When compilation is complete, the shader will be bound and active. In addition, all uniforms will be validated.

Returns
true if initialization was successful.

◆ init() [2/2]

bool cugl::scene3::ObjShader::init ( const graphics::ShaderSource vsource,
const graphics::ShaderSource fsource 
)
overridevirtual

Initializes this shader with the given vertex and fragment source.

The shader will compile the vertex and fragment sources and link them together. When compilation is complete, the shader will be bound and active. In addition, all uniforms will be validated.

Parameters
vsourceThe source for the vertex shader.
fsourceThe source for the fragment shader.
Returns
true if initialization was successful.

Reimplemented from cugl::graphics::GraphicsShader.

◆ setAmbientColor()

void cugl::scene3::ObjShader::setAmbientColor ( const Color4f  color)
inline

Sets the ambient color for this shader.

This method will only succeed if the shader is an active drawing pass.

Parameters
colorThe ambient color

◆ setAmbientTexture()

void cugl::scene3::ObjShader::setAmbientTexture ( const std::shared_ptr< graphics::Texture > &  texture)

Sets the ambient texture for this shader.

This method will only succeed if the shader is an active drawing pass.

Parameters
textureThe ambient texture

◆ setDiffuseColor()

void cugl::scene3::ObjShader::setDiffuseColor ( const Color4f  color)
inline

Sets the diffuse color for this shader.

This method will only succeed if the shader is an active drawing pass.

Parameters
colorThe diffuse color

◆ setDiffuseTexture()

void cugl::scene3::ObjShader::setDiffuseTexture ( const std::shared_ptr< graphics::Texture > &  texture)

Sets the diffuse texture for this shader.

This method will only succeed if the shader is an active drawing pass.

Parameters
textureThe diffuse texture

◆ setIllum()

void cugl::scene3::ObjShader::setIllum ( int  value)
inline

Sets the illumination level of this shader.

The values are as follows:

0: Color with no reflection (ambient only)
1: Diffuse reflection
2: Specular reflection

This method will only succeed if the shader is an active drawing pass.

Parameters
valueThe illumination value

◆ setLightPosition()

void cugl::scene3::ObjShader::setLightPosition ( const Vec3 pos)
inline

Sets the light position for this shader.

This method will only succeed if the shader is an active drawing pass.

Parameters
posThe light position

◆ setModelMatrix()

void cugl::scene3::ObjShader::setModelMatrix ( const Mat4 matrix)
inline

Sets the model matrix for this shader.

This method will only succeed if the shader is an active drawing pass.

Parameters
matrixThe model matrix

◆ setNormalMatrix()

void cugl::scene3::ObjShader::setNormalMatrix ( const Mat4 matrix)
inline

Sets the normal matrix for this shader.

This method will only succeed if the shader is an active drawing pass.

Parameters
matrixThe normal matrix

◆ setNormalTexture()

void cugl::scene3::ObjShader::setNormalTexture ( const std::shared_ptr< graphics::Texture > &  texture)

Sets the normal (bump) texture for this shader.

This method will only succeed if the shader is an active drawing pass.

Parameters
textureThe normal texture

◆ setPerspective()

void cugl::scene3::ObjShader::setPerspective ( const Mat4 matrix)
inline

Sets the perspective matrix for this shader.

This method will only succeed if the shader is an active drawing pass.

Parameters
matrixThe perspective matrix

◆ setSpecularColor()

void cugl::scene3::ObjShader::setSpecularColor ( const Color4f  color)
inline

Sets the specular color for this shader.

This method will only succeed if the shader is an active drawing pass.

Parameters
colorThe specular color

◆ setSpecularExponent()

void cugl::scene3::ObjShader::setSpecularExponent ( float  value)
inline

Sets the specular exponent for this shader.

This method will only succeed if the shader is an active drawing pass.

Parameters
valueThe specular exponent

◆ setSpecularTexture()

void cugl::scene3::ObjShader::setSpecularTexture ( const std::shared_ptr< graphics::Texture > &  texture)

Sets the specular texture for this shader.

This method will only succeed if the shader is an active drawing pass.

Parameters
textureThe specular texture

The documentation for this class was generated from the following file: