LightsprintSDK 2021.08.08
rr_gl::Program Class Reference

#include <Program.h>

Inheritance diagram for rr_gl::Program:
rr::RRUniformlyAllocatedNonCopyable rr::RRUniformlyAllocated

Public Member Functions

 ~Program ()
 
bool isValid ()
 
void useIt ()
 
unsigned sendTexture (const char *name, const class Texture *t, int code=-1)
 
void unsendTexture (int code)
 
void sendUniform (const char *name, float x)
 
void sendUniform (const char *name, float x, float y)
 
void sendUniform (const char *name, const rr::RRVec3 &xyz)
 
void sendUniform (const char *name, const rr::RRVec4 &xyzw)
 
void sendUniform (const char *name, int x)
 
void sendUniform (const char *name, int x, int y)
 
void sendUniform (const char *name, const float *m, bool transp=false, int size=4)
 
void sendUniformArray (const char *name, int count, const GLint *x)
 
void sendUniformArray (const char *name, int count, const GLfloat *x)
 
void sendUniformArray (const char *name, int count, const rr::RRVec2 *x)
 
void sendUniformArray (const char *name, int count, const rr::RRVec3 *x)
 
void sendUniformArray (const char *name, int count, const rr::RRVec4 *x)
 
bool uniformExists (const char *uniformName)
 
- Public Member Functions inherited from rr::RRUniformlyAllocated
void * operator new (std::size_t n)
 
void * operator new[] (std::size_t n)
 
void operator delete (void *p, std::size_t n)
 
void operator delete[] (void *p, std::size_t n)
 

Static Public Member Functions

static Programcreate (const char *defines, const rr::RRString &vertexShader, const rr::RRString &fragmentShader)
 
static void logMessages (bool enable)
 

Additional Inherited Members

- Protected Member Functions inherited from rr::RRUniformlyAllocatedNonCopyable
 RRUniformlyAllocatedNonCopyable ()
 
 ~RRUniformlyAllocatedNonCopyable ()
 

Detailed Description

GLSL program.

GLSL is language used by OpenGL API for writing shaders. Program is one or more shaders linked together, see OpenGL for more details.

Constructor & Destructor Documentation

◆ ~Program()

rr_gl::Program::~Program ( )

Member Function Documentation

◆ create()

static Program * rr_gl::Program::create ( const char *  defines,
const rr::RRString vertexShader,
const rr::RRString fragmentShader 
)
static

Creates GLSL program by linking one vertex and one fragment shader together. Shaders are created by concatenating string defines and contents of file vertexShader / fragmentShader.

Parameters
definesString inserted before compilation at the beginning of shader source code. May be nullptr.
vertexShaderName of text file with GLSL vertex shader. May be empty for fixed pipeline.
fragmentShaderName of text file with GLSL fragment shader. May be empty for fixed pipeline.

◆ isValid()

bool rr_gl::Program::isValid ( )

Validates program and returns true only when it was successful, see OpenGL for more details on validation. Validation is optional process used mainly for debugging.

◆ useIt()

void rr_gl::Program::useIt ( )

Sets rendering pipeline so that program will be used for following primitives rendered. Program must be linked before use.

◆ sendTexture()

unsigned rr_gl::Program::sendTexture ( const char *  name,
const class Texture t,
int  code = -1 
)

Sets uniform texture (activates texture unit, binds texture), returns texture unit used.

First call after useIt() uses texture unit 0, next one uses unit 1 etc. If code in range 0..15 is entered, all textures with the same code are sent to the same unit.

Following fragments of code do the same

  • sendTexture(name,tex);
  • sendTexture(name,nullptr); tex->bindTexture();
  • unsigned unit = sendTexture(name,nullptr); glActiveTexture(GL_TEXTURE0+unit); tex->bindTexture();

When doing multiple renders that differ only in textures, use codes

  • useIt(); for (int i=0;i<100;i++) { sendTexture(name1,...,1); sendTexture(name2,...,2); draw(); } With codes, the same 2 texture units are used 100 times. Without codes, 200 texture units would be allocated.

◆ unsendTexture()

void rr_gl::Program::unsendTexture ( int  code)

Unbinds texture previously sent via sendTexture(,,code);.

◆ sendUniform() [1/7]

void rr_gl::Program::sendUniform ( const char *  name,
float  x 
)

Sets uniform of type float.

◆ sendUniform() [2/7]

void rr_gl::Program::sendUniform ( const char *  name,
float  x,
float  y 
)

Sets uniform of type vec2.

◆ sendUniform() [3/7]

void rr_gl::Program::sendUniform ( const char *  name,
const rr::RRVec3 xyz 
)

Sets uniform of type vec3.

◆ sendUniform() [4/7]

void rr_gl::Program::sendUniform ( const char *  name,
const rr::RRVec4 xyzw 
)

Sets uniform of type vec4.

◆ sendUniform() [5/7]

void rr_gl::Program::sendUniform ( const char *  name,
int  x 
)

Sets uniform of type int or sampler2D or samplerCube or sampler2DShadow.

◆ sendUniform() [6/7]

void rr_gl::Program::sendUniform ( const char *  name,
int  x,
int  y 
)

Sets uniform of type int2.

◆ sendUniform() [7/7]

void rr_gl::Program::sendUniform ( const char *  name,
const float *  m,
bool  transp = false,
int  size = 4 
)

Sets uniform of type mat2, mat3 or mat4.

◆ sendUniformArray() [1/5]

void rr_gl::Program::sendUniformArray ( const char *  name,
int  count,
const GLint *  x 
)

Sets array of uniforms of type int or sampler2D or samplerCube or sampler2DShadow.

◆ sendUniformArray() [2/5]

void rr_gl::Program::sendUniformArray ( const char *  name,
int  count,
const GLfloat *  x 
)

◆ sendUniformArray() [3/5]

void rr_gl::Program::sendUniformArray ( const char *  name,
int  count,
const rr::RRVec2 x 
)

◆ sendUniformArray() [4/5]

void rr_gl::Program::sendUniformArray ( const char *  name,
int  count,
const rr::RRVec3 x 
)

◆ sendUniformArray() [5/5]

void rr_gl::Program::sendUniformArray ( const char *  name,
int  count,
const rr::RRVec4 x 
)

◆ uniformExists()

bool rr_gl::Program::uniformExists ( const char *  uniformName)

Does uniform exist in program?

◆ logMessages()

static void rr_gl::Program::logMessages ( bool  enable)
static

Print OpenGL log to console. False by default. Set true for debugging.