LightsprintSDK 2021.08.08
rr_gl::TextureRenderer Class Reference

#include <TextureRenderer.h>

Public Member Functions

 TextureRenderer (const rr::RRString &pathToShaders)
 
 ~TextureRenderer ()
 
bool renderEnvironment (const rr::RRCamera &camera, const Texture *texture0, float angleRad0, const Texture *texture1, float angleRad1, float blendFactor, const rr::RRVec4 *brightness, float gamma, bool allowDepthTest)
 
void render2D (const Texture *texture, const ToneParameters *tp, float x, float y, float w, float h, float z=-1, const char *extraDefines=nullptr, float fisheyeFovDeg=180)
 
Programrender2dBegin (const ToneParameters *tp, const char *extraDefines=nullptr, float fisheyeFovDeg=180)
 
void render2dQuad (const Texture *texture, float x, float y, float w, float h, float z=-1)
 
void render2dEnd ()
 

Static Public Member Functions

static void renderQuad (const float *positions=nullptr)
 

Public Attributes

UberProgramskyProgram
 
UberProgramtwodProgram
 

Detailed Description

Helper for render of 2D or cube (skybox) texture.

It handles resource (shader) allocation/freeing. Needs sky.vs/fs and texture.vs/fs shaders on disk.

Constructor & Destructor Documentation

◆ TextureRenderer()

rr_gl::TextureRenderer::TextureRenderer ( const rr::RRString pathToShaders)

Initializes renderer, loading shaders from disk.

Parameters
pathToShadersPath to directory with shaders. Must be terminated with slash (or be empty for current dir).

◆ ~TextureRenderer()

rr_gl::TextureRenderer::~TextureRenderer ( )

Shutdowns renderer, freeing shaders.

Member Function Documentation

◆ renderEnvironment()

bool rr_gl::TextureRenderer::renderEnvironment ( const rr::RRCamera camera,
const Texture texture0,
float  angleRad0,
const Texture texture1,
float  angleRad1,
float  blendFactor,
const rr::RRVec4 brightness,
float  gamma,
bool  allowDepthTest 
)

Renders cubemap, equirectangular 2d texture or blend of two such maps as if camera is in center.

Use blendFactor=0 to render only texture0, texture1 then may be nullptr. For non-nullptr color, texture color is multiplied by color. Color is finally gamma corrected by gamma, 1 = no correction. Angles rotate environments around top/down axis.

◆ render2D()

void rr_gl::TextureRenderer::render2D ( const Texture texture,
const ToneParameters tp,
float  x,
float  y,
float  w,
float  h,
float  z = -1,
const char *  extraDefines = nullptr,
float  fisheyeFovDeg = 180 
)

Renders 2d texture into rectangle, using current blending/alpha testing/depth testing/masking etc modes.

render2D() internally calls render2dBegin() + render2dQuad() + render2dEnd(). For rendering N textures, it's possible to simply call render2D() N times, but render2dBegin() + N*render2dQuad() + render2dEnd() is slightly faster.

Parameters
textureTexture (2d or cube) to be rendered. Cube textures are rendered in equirectangular projection. It is legal to pass nullptr texture as long as you glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D,id); ahead of rendering.
tpFor non-nullptr tp, output is tonemapped using given parameters.
xPosition of texture's left side in viewport, 0=leftmost, 1=rightmost.
yPosition of texture's bottom side in viewport, 0=bottom, 1=top.
wx+w is position of texture's right side in viewport, 0=leftmost, 1=rightmost. Negative w is supported.
hy+h is position of texture's top side in viewport, 0=bottom, 1=top. Negative h is supported.
zDepth in 0..1 range to be assigned to all rendered fragments. Additional effect of z in render2D() (not in render2dQuad()) is: "if (z<0) temporarily disable GL_DEPTH_TEST"
extraDefinesUsually nullptr, may be additional glsl code inserted at the beginning of shader, to enable special rendering paths.
fisheyeFovDegFor internal use.

◆ render2dBegin()

Program * rr_gl::TextureRenderer::render2dBegin ( const ToneParameters tp,
const char *  extraDefines = nullptr,
float  fisheyeFovDeg = 180 
)

Component of render2D(), initializes pipeline.

◆ render2dQuad()

void rr_gl::TextureRenderer::render2dQuad ( const Texture texture,
float  x,
float  y,
float  w,
float  h,
float  z = -1 
)

Component of render2D(), renders textured quad. May be called multiple times between render2dBegin() and render2dEnd().

◆ render2dEnd()

void rr_gl::TextureRenderer::render2dEnd ( )

Component of render2D(), restores pipeline.

◆ renderQuad()

static void rr_gl::TextureRenderer::renderQuad ( const float *  positions = nullptr)
static

Helper, renders quad, identical to glBegin();4x glVertex();glEnd(); with coordinates from -1,-1 to 1,1. Optional parameter lets you provide your own coordinates.

Member Data Documentation

◆ skyProgram

UberProgram* rr_gl::TextureRenderer::skyProgram

sky.* uberprogram, only for reading, feel free to render with it directly.

◆ twodProgram

UberProgram* rr_gl::TextureRenderer::twodProgram

texture.* uberprogram, only for reading, feel free to render with it directly.