Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
Renderer::Backend::GL::CShaderProgram Class Referencefinal

A compiled vertex+fragment shader program. More...

#include <ShaderProgram.h>

Inheritance diagram for Renderer::Backend::GL::CShaderProgram:
Collaboration diagram for Renderer::Backend::GL::CShaderProgram:

Classes

struct  BindingSlot
 
struct  ShaderStage
 
struct  TextureUnit
 

Public Types

typedef CStrIntern attrib_id_t
 

Public Member Functions

 ~CShaderProgram () override
 
void Bind (CShaderProgram *previousShaderProgram)
 Binds the shader into the GL context. More...
 
void Unbind ()
 Unbinds the shader from the GL context. More...
 
int32_t GetBindingSlot (const CStrIntern name) const override
 
TextureUnit GetTextureUnit (const int32_t bindingSlot)
 
GLuint GetStorageBuffer (const int32_t bindingSlot)
 
void SetUniform (const int32_t bindingSlot, const float value)
 
void SetUniform (const int32_t bindingSlot, const float valueX, const float valueY)
 
void SetUniform (const int32_t bindingSlot, const float valueX, const float valueY, const float valueZ)
 
void SetUniform (const int32_t bindingSlot, const float valueX, const float valueY, const float valueZ, const float valueW)
 
void SetUniform (const int32_t bindingSlot, std::span< const float > values)
 
void VertexAttribPointer (const VertexAttributeStream stream, const Format format, const uint32_t offset, const uint32_t stride, const VertexAttributeRate rate, const void *data)
 
bool IsStreamActive (const VertexAttributeStream stream) const
 
bool HasImageUniforms () const
 
IDevice * GetDevice () override
 
std::vector< VfsPath > GetFileDependencies () const override
 
void AssertPointersBound ()
 Checks that all the required vertex attributes have been set. More...
 
virtual int32_t GetBindingSlot (const CStrIntern name) const =0
 
virtual std::vector< VfsPath > GetFileDependencies () const =0
 
- Public Member Functions inherited from Renderer::Backend::IDeviceObject< IShaderProgram >
virtual ~IDeviceObject ()
 
virtual IDevice * GetDevice ()=0
 
T * As ()
 

Static Public Member Functions

static std::unique_ptr< CShaderProgram > Create (CDevice *device, const CStr &name, const CShaderDefines &baseDefines)
 

Private Member Functions

 NONCOPYABLE (CShaderProgram)
 
 CShaderProgram (CDevice *device, const CStr &name, const VfsPath &programPath, std::span< const std::tuple< VfsPath, GLenum > > shaderStages, const CShaderDefines &defines, const std::map< CStrIntern, int > &vertexAttribs, int streamflags)
 
bool Link (const VfsPath &path)
 

Private Attributes

int m_StreamFlags
 
int m_ValidStreams
 
bool m_HasImageUniforms {false}
 
CDevice * m_Device {nullptr}
 
CStr m_Name
 
std::vector< VfsPath > m_FileDependencies
 
std::map< CStrIntern, int > m_VertexAttribs
 
std::vector< int > m_ActiveVertexAttributes
 
GLuint m_Program
 
PS::StaticVector< ShaderStage, 5 > m_ShaderStages
 
std::vector< BindingSlot > m_BindingSlots
 
std::unordered_map< CStrIntern, int32_t > m_BindingSlotsMapping
 
GLint m_UniformBufferLocation {-1}
 
uint32_t m_UniformBufferSize {0}
 
std::unique_ptr< IBuffer > m_UniformBuffer
 

Detailed Description

A compiled vertex+fragment shader program.

Setting uniforms that the shader doesn't support is harmless.

Member Typedef Documentation

◆ attrib_id_t

Constructor & Destructor Documentation

◆ ~CShaderProgram()

CShaderProgram::~CShaderProgram ( )
override

◆ CShaderProgram()

CShaderProgram::CShaderProgram ( CDevice *  device,
const CStr &  name,
const VfsPath &  programPath,
std::span< const std::tuple< VfsPath, GLenum > >  shaderStages,
const CShaderDefines &  defines,
const std::map< CStrIntern, int > &  vertexAttribs,
int  streamflags 
)
private

Member Function Documentation

◆ AssertPointersBound()

void CShaderProgram::AssertPointersBound ( )

Checks that all the required vertex attributes have been set.

Call this before calling Draw/DrawIndexed etc to avoid potential crashes.

◆ Bind()

void CShaderProgram::Bind ( CShaderProgram *  previousShaderProgram)

Binds the shader into the GL context.

Call this before calling Uniform() or trying to render with it.

◆ Create()

std::unique_ptr< CShaderProgram > CShaderProgram::Create ( CDevice *  device,
const CStr &  name,
const CShaderDefines &  baseDefines 
)
static

◆ GetBindingSlot()

int32_t CShaderProgram::GetBindingSlot ( const CStrIntern  name) const
overridevirtual

◆ GetDevice()

IDevice * Renderer::Backend::GL::CShaderProgram::GetDevice ( )
inlineoverridevirtual

◆ GetFileDependencies()

std::vector< VfsPath > CShaderProgram::GetFileDependencies ( ) const
overridevirtual

◆ GetStorageBuffer()

GLuint CShaderProgram::GetStorageBuffer ( const int32_t  bindingSlot)

◆ GetTextureUnit()

CShaderProgram::TextureUnit CShaderProgram::GetTextureUnit ( const int32_t  bindingSlot)

◆ HasImageUniforms()

bool Renderer::Backend::GL::CShaderProgram::HasImageUniforms ( ) const
inline

◆ IsStreamActive()

bool CShaderProgram::IsStreamActive ( const VertexAttributeStream  stream) const

◆ Link()

bool CShaderProgram::Link ( const VfsPath &  path)
private

◆ NONCOPYABLE()

Renderer::Backend::GL::CShaderProgram::NONCOPYABLE ( CShaderProgram  )
private

◆ SetUniform() [1/5]

void CShaderProgram::SetUniform ( const int32_t  bindingSlot,
const float  value 
)

◆ SetUniform() [2/5]

void CShaderProgram::SetUniform ( const int32_t  bindingSlot,
const float  valueX,
const float  valueY 
)

◆ SetUniform() [3/5]

void CShaderProgram::SetUniform ( const int32_t  bindingSlot,
const float  valueX,
const float  valueY,
const float  valueZ 
)

◆ SetUniform() [4/5]

void CShaderProgram::SetUniform ( const int32_t  bindingSlot,
const float  valueX,
const float  valueY,
const float  valueZ,
const float  valueW 
)

◆ SetUniform() [5/5]

void CShaderProgram::SetUniform ( const int32_t  bindingSlot,
std::span< const float >  values 
)

◆ Unbind()

void CShaderProgram::Unbind ( )

Unbinds the shader from the GL context.

Call this after rendering with it.

◆ VertexAttribPointer()

void CShaderProgram::VertexAttribPointer ( const VertexAttributeStream  stream,
const Format  format,
const uint32_t  offset,
const uint32_t  stride,
const VertexAttributeRate  rate,
const void *  data 
)

Member Data Documentation

◆ m_ActiveVertexAttributes

std::vector<int> Renderer::Backend::GL::CShaderProgram::m_ActiveVertexAttributes
private

◆ m_BindingSlots

std::vector<BindingSlot> Renderer::Backend::GL::CShaderProgram::m_BindingSlots
private

◆ m_BindingSlotsMapping

std::unordered_map<CStrIntern, int32_t> Renderer::Backend::GL::CShaderProgram::m_BindingSlotsMapping
private

◆ m_Device

CDevice* Renderer::Backend::GL::CShaderProgram::m_Device {nullptr}
private

◆ m_FileDependencies

std::vector<VfsPath> Renderer::Backend::GL::CShaderProgram::m_FileDependencies
private

◆ m_HasImageUniforms

bool Renderer::Backend::GL::CShaderProgram::m_HasImageUniforms {false}
private

◆ m_Name

CStr Renderer::Backend::GL::CShaderProgram::m_Name
private

◆ m_Program

GLuint Renderer::Backend::GL::CShaderProgram::m_Program
private

◆ m_ShaderStages

PS::StaticVector<ShaderStage, 5> Renderer::Backend::GL::CShaderProgram::m_ShaderStages
private

◆ m_StreamFlags

int Renderer::Backend::GL::CShaderProgram::m_StreamFlags
private

◆ m_UniformBuffer

std::unique_ptr<IBuffer> Renderer::Backend::GL::CShaderProgram::m_UniformBuffer
private

◆ m_UniformBufferLocation

GLint Renderer::Backend::GL::CShaderProgram::m_UniformBufferLocation {-1}
private

◆ m_UniformBufferSize

uint32_t Renderer::Backend::GL::CShaderProgram::m_UniformBufferSize {0}
private

◆ m_ValidStreams

int Renderer::Backend::GL::CShaderProgram::m_ValidStreams
private

◆ m_VertexAttribs

std::map<CStrIntern, int> Renderer::Backend::GL::CShaderProgram::m_VertexAttribs
private

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