LightsprintSDK 2021.08.08
rr::RRBuffer Class Referenceabstract

#include <RRBuffer.h>

Inheritance diagram for rr::RRBuffer:
rr::RRUniformlyAllocatedNonCopyable rr::RRUniformlyAllocated

Classes

struct  SaveParameters
 

Public Types

typedef RRBuffer *() Loader(const RRString &filename, const char *cubeSideName[6])
 
typedef bool() Saver(RRBuffer *buffer, const RRString &filenameMask, const char *cubeSideName[6], const SaveParameters *parameters)
 

Public Member Functions

virtual bool reset (RRBufferType type, unsigned width, unsigned height, unsigned depth, RRBufferFormat format, bool scaled, const unsigned char *data)=0
 
virtual void setElement (unsigned index, const RRVec4 &element, const RRColorSpace *colorSpace)
 
virtual RRBufferType getType () const =0
 
virtual unsigned getWidth () const =0
 
virtual unsigned getHeight () const =0
 
virtual unsigned getDepth () const =0
 
unsigned getNumElements () const
 
virtual RRBufferFormat getFormat () const =0
 
virtual bool getScaled () const =0
 
virtual size_t getBufferBytes () const
 
virtual unsigned getElementBits () const
 
virtual RRVec4 getElement (unsigned index, const RRColorSpace *colorSpace) const
 
virtual RRVec4 getElementAtPosition (const RRVec3 &position, const RRColorSpace *colorSpace, bool interpolated) const
 
virtual RRVec4 getElementAtDirection (const RRVec3 &direction, const RRColorSpace *colorSpace) const
 
virtual unsigned char * lock (RRBufferLock lock)
 
virtual void unlock ()
 
virtual bool update ()
 
virtual void play ()
 
virtual void stop ()
 
virtual void pause ()
 
virtual void seek (float secondsFromStart)
 
virtual float getDuration () const
 
 RRBuffer ()
 
virtual ~RRBuffer ()
 
virtual bool isStub ()
 
virtual RRBuffercreateReference ()=0
 
virtual unsigned getReferenceCount ()=0
 
RRBuffercreateCopy ()
 
RRBuffercreateCopy (RRBufferFormat format, bool scaled, const RRColorSpace *colorSpace) const
 
bool copyElementsTo (RRBuffer *destination, const RRColorSpace *colorSpace) const
 
RRBuffercreateEquirectangular ()
 
virtual bool reload (const RRString &filename, const char *cubeSideName[6], const RRFileLocator *fileLocator)
 
bool save (const RRString &filenameMask, const char *cubeSideName[6]=nullptr, const SaveParameters *saveParameters=nullptr)
 
virtual void setFormat (RRBufferFormat newFormat)
 
virtual void setFormatFloats ()
 
virtual void clear (RRVec4 clearColor=RRVec4(0))
 
virtual void invert ()
 
virtual void multiplyAdd (RRVec4 multiplier, RRVec4 addend)
 
virtual void flip (bool flipX, bool flipY, bool flipZ)
 
virtual void rotate (int degrees, unsigned depthLayer=0)
 
virtual void brightnessGamma (RRVec4 brightness, RRVec4 gamma)
 
virtual void getMinMax (RRVec4 *mini, RRVec4 *maxi)
 
virtual bool lightmapSmooth (float sigma, bool wrap, const class RRObject *object)
 
virtual bool lightmapGrowForBilinearInterpolation (bool wrap)
 
virtual bool lightmapGrow (unsigned distance, bool wrap, bool &aborting)
 
virtual bool lightmapFillBackground (RRVec4 backgroundColor)
 
- 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 RRBuffercreate (RRBufferType type, unsigned width, unsigned height, unsigned depth, RRBufferFormat format, bool scaled, const unsigned char *data)
 
static RRBuffercreateSky (const RRVec4 &upper=RRVec4(1), const RRVec4 &lower=RRVec4(1), bool scaled=true)
 
static RRBuffercreateEnvironmentBlend (RRBuffer *environment0, RRBuffer *environment1, RRReal angleRad0, RRReal angleRad1, RRReal blendFactor)
 
static RRBufferload (const RRString &filename, const char *cubeSideName[6]=nullptr, const RRFileLocator *fileLocator=nullptr)
 
static RRBufferloadCube (const RRString &filename, const RRFileLocator *fileLocator=nullptr)
 
static void registerLoader (const char *extensions, Loader *loader)
 
static void registerSaver (const char *extensions, Saver *saver)
 
static const char * getSupportedLoaderExtensions ()
 
static const char * getSupportedSaverExtensions ()
 

Public Attributes

RRString filename
 
unsigned version
 
void * customData
 

Protected Member Functions

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

Detailed Description

Buffer, array of elements.

Buffer types

  • 1-dimensional buffers are used for vertex buffers.
  • 2-dimensional buffers are used for 2d textures and videos.
  • 3-dimensional buffers are used for cube textures.

Using buffers in OpenGL/DirectX

Two approaches exist for using buffers in DirectX/OpenGL renderer

  1. Use existing RRBuffer that stores data in system memory. Each time buffer version changes, copy data from buffer to DirectX/OpenGL texture. rr_gl::getTexture() implements this behaviour, it is flexible and fast.
  2. Subclass RRBuffer, make it store data directly in DirectX/OpenGL texture. It is less flexible, but it saves system memory and it could be faster if used with care. For an example of RRBuffer subclass, see e.g. RRBufferDirectShow implemented in LightsprintIO.

How solvers update buffers

When implementing custom RRBuffer subclass, it may help to know how solvers update buffers

  • vertex buffers are updated by lock(BL_DISCARD_AND_WRITE), with fallback to setElement() if lock() fails
  • cube maps are updated by lock(BL_DISCARD_AND_WRITE), with fallback to setElement() if lock() fails
  • lightmaps are updated by setElement()
  • reset() is never called, so your type, size, format and scale are preserved

How buffers are cached/shared

Buffers loaded from disk may be shared to save memory and time. Sharing is automatic, you mostly don't have to care about it, but it's still good to know the rules, they are shown by example:

a = RRBuffer::load("foo/bar.avi"); // a loaded from disk
b = RRBuffer::load("foo/bar.avi"); // b found in cache, b==a
c = RRBuffer::load("foo\\bar.avi"); // c loaded from disk, because filename differs
a->setElement(0,RRVec4(0)); // modifies content of a==b
d = RRBuffer::load("foo/bar.avi"); // d loaded from disk, a==b removed from cache, because content differs
delete a; // no memory freed, it's still in use by b
delete b; // memory freed
delete d; // no memory freed, d stays in cache
e = RRBuffer::load("foo/bar.avi"); // e found in cache, e==d
e->play(); // starts playing image to buffer, audio to speakers
//e->stop(); // here we forget to stop
delete e; // no memory freed, e stays in cache, still playing to speakers
// someone overwrites foo/bar.avi
f = RRBuffer::load("foo/bar.avi"); // f loaded from disk, e deleted from cache, memory freed, stops playing, because file's write time did change
// (note that file's write time is not tracked for cubemaps stored in 6 files, they are assumed to never change on disk, let us know if it is a problem)
static RRBuffer * load(const RRString &filename, const char *cubeSideName[6]=nullptr, const RRFileLocator *fileLocator=nullptr)
Loads buffer from disk to system memory.
Vector of 4 real numbers. Operators use all 4 components.
Definition RRMath.h:208

Live video capture

LightsprintIO implements support for live video capture into 2d buffer. With LightsprintIO callbacks registered, live video capture is started by opening imaginary file "c\@pture".

Member Typedef Documentation

◆ Loader

typedef RRBuffer *() rr::RRBuffer::Loader(const RRString &filename, const char *cubeSideName[6])

Type of user defined function that loads content from file into new buffer.

◆ Saver

typedef bool() rr::RRBuffer::Saver(RRBuffer *buffer, const RRString &filenameMask, const char *cubeSideName[6], const SaveParameters *parameters)

Type of user defined function that saves buffer contents to file.

Constructor & Destructor Documentation

◆ RRBuffer()

rr::RRBuffer::RRBuffer ( )

◆ ~RRBuffer()

virtual rr::RRBuffer::~RRBuffer ( )
inlinevirtual

Member Function Documentation

◆ reset()

virtual bool rr::RRBuffer::reset ( RRBufferType  type,
unsigned  width,
unsigned  height,
unsigned  depth,
RRBufferFormat  format,
bool  scaled,
const unsigned char *  data 
)
pure virtual

Sets size and contents of buffer.

Parameters
typeRequested type of buffer.
widthRequested width of buffer. Set to number of vertices for BT_VERTEX_BUFFER.
heightRequested height of buffer. Set 1 for BT_VERTEX_BUFFER. Set equal to width for BT_CUBE_TEXTURE.
depthRequested depth of buffer. Set 1 for BT_VERTEX_BUFFER and BT_2D_TEXTURE. Set 6 for BT_CUBE_TEXTURE.
formatFormat of data. Implementation is not required to support all data formats.
For linear colors, it's recommended to use floating point format to avoid clamping. For sRGB colors, more compact 8bit format is usually sufficient, although it clamps values to 0..1 range.
scaledTrue for buffer data in custom color space (usually screen colors, sRGB), false for linear colors. When buffer is updated or rendered later, this setting is respected.

In greater detail: GI is internally calculated in linear colors, while displays work in sRGB, so data must be converted at some point in pipeline. True = data are scaled by RRSolver::updateLightmaps(), increasing CPU load; positive sideeffect is that scaled data are suitable even for smaller RGB/RGBA buffers. False = data should be scaled later, for example in shader, thus increasing GPU load. In both cases, scaling to sRGB is simple x=pow(x,0.45) operation. If you precompute lightmaps once and render them many times, you can save time by setting true, data are scaled once. In case of realtime GI where lightmaps are computed once and rendered once, you should save time by setting false and scaling data in renderer/shader (GPU is usually faster).
dataData to be copied into texture. When set to nullptr, contents of texture stays uninitialized. Format of data is specified by format, interpretation of data is partially specified by scaled. Special value RR_GHOST_BUFFER creates buffer without any memory allocated for elements (it's good when buffer is needed, but its contents is never accessed, e.g. when creating uninitialized texture in rr_gl::Texture).
Returns
True on success, false on failure (invalid parameters).

◆ setElement()

virtual void rr::RRBuffer::setElement ( unsigned  index,
const RRVec4 element,
const RRColorSpace colorSpace 
)
virtual

Sets single element in buffer. Value is converted to current buffer format.

Index is index into array of all elements, x+y*width+z*width*height.
Not mandatory, implementation may be empty.

◆ getType()

virtual RRBufferType rr::RRBuffer::getType ( ) const
pure virtual
Returns
Type of buffer, e.g. BT_VERTEX_BUFFER.

◆ getWidth()

virtual unsigned rr::RRBuffer::getWidth ( ) const
pure virtual
Returns
Width of buffer: number of vertices for vertex buffer, width in pixels for texture.

◆ getHeight()

virtual unsigned rr::RRBuffer::getHeight ( ) const
pure virtual
Returns
Height of buffer: 1 for vertex buffer, height in pixels for texture.

◆ getDepth()

virtual unsigned rr::RRBuffer::getDepth ( ) const
pure virtual
Returns
Depth of buffer: 1 for vertex buffer, 1 for 2d texture, 6 for cube texture.

◆ getNumElements()

unsigned rr::RRBuffer::getNumElements ( ) const
Returns
Width*height*depth.

◆ getFormat()

virtual RRBufferFormat rr::RRBuffer::getFormat ( ) const
pure virtual
Returns
Format of buffer, e.g. BF_RGBF.

◆ getScaled()

virtual bool rr::RRBuffer::getScaled ( ) const
pure virtual
Returns
True for buffer in custom color space (usually sRGB), false for linear colors.

◆ getBufferBytes()

virtual size_t rr::RRBuffer::getBufferBytes ( ) const
virtual
Returns
Size of buffer in bytes, pure buffer size without several fixed bytes of class size. In case of video, size of one uncompressed frame is calculated. In case of RR_GHOST_BUFFER, 0 is returned as no memory is allocated.

◆ getElementBits()

virtual unsigned rr::RRBuffer::getElementBits ( ) const
virtual
Returns
Number of bits in one element, e.g. 96 for BF_RGBF, implementation defined for BF_DEPTH.

◆ getElement()

virtual RRVec4 rr::RRBuffer::getElement ( unsigned  index,
const RRColorSpace colorSpace 
) const
virtual

Returns value addressed by given integer coordinate.

Parameters
indexIndex is index into array of all elements, x+y*width+z*width*height. Out of range indices are reported as error.
colorSpaceIf nullptr, color is returned in native color space. With colorSpace set, RGB is returned in linear space, alpha in native space.

◆ getElementAtPosition()

virtual RRVec4 rr::RRBuffer::getElementAtPosition ( const RRVec3 position,
const RRColorSpace colorSpace,
bool  interpolated 
) const
virtual

Returns value addressed by given float coordinates.

Parameters
positionCoordinates are array indices in 0..1 range covering whole buffer. Out of range indices are wrapped to 0..1.
colorSpaceIf nullptr, color is returned in native color space. With colorSpace set, RGB is returned in linear space, alpha in native space.
interpolatedSwitches from nearest element selection to linear interpolation of 4 elements.

◆ getElementAtDirection()

virtual RRVec4 rr::RRBuffer::getElementAtDirection ( const RRVec3 direction,
const RRColorSpace colorSpace 
) const
virtual

Returns environment sample addressed by given direction (not necessarily normalized).

Parameters
directionDirection from center in which we look for element. 2d texture is interpreted as 360*180 degree panorama. Cube texture is interpreted as standard cube.
colorSpaceIf nullptr, color is returned in native color space. With colorSpace set, RGB is returned in linear space, alpha in native space.

◆ lock()

virtual unsigned char * rr::RRBuffer::lock ( RRBufferLock  lock)
virtual

Locks the buffer for accessing array of all elements at once. Not mandatory, may return nullptr.

Behaviour of lock is not defined when buffer is already locked.

Returns
Pointer to array of all width*height*depth elements, in format specified by getFormat().

◆ unlock()

virtual void rr::RRBuffer::unlock ( )
virtual

Unlocks previously locked buffer.

◆ update()

virtual bool rr::RRBuffer::update ( )
inlinevirtual

For video/capture/animated buffers, returns true if buffer content was updated and version changed.

◆ play()

virtual void rr::RRBuffer::play ( )
inlinevirtual

For video buffers, starts playing buffer. To update content of playing buffer, call update().

◆ stop()

virtual void rr::RRBuffer::stop ( )
inlinevirtual

For video buffers, stops playing buffer and rewinds to the beginning.

◆ pause()

virtual void rr::RRBuffer::pause ( )
inlinevirtual

For video buffers, pauses playing buffer.

◆ seek()

virtual void rr::RRBuffer::seek ( float  secondsFromStart)
inlinevirtual

For video buffers, seeks to given number of seconds from start.

◆ getDuration()

virtual float rr::RRBuffer::getDuration ( ) const
inlinevirtual
Returns
Duration of dynamic content (video) in seconds, 0 for static content (image, vertex colors), -1 for unlimited dynamic content (video capture).

◆ isStub()

virtual bool rr::RRBuffer::isStub ( )
inlinevirtual

Returns true if buffer is a stub. When asked to, RRBuffer::load() returns stubs instead of nullptr for missing textures.

Stubs are designed to work like other buffers, ideally you won't need this function. We need it only

◆ create()

static RRBuffer * rr::RRBuffer::create ( RRBufferType  type,
unsigned  width,
unsigned  height,
unsigned  depth,
RRBufferFormat  format,
bool  scaled,
const unsigned char *  data 
)
static

Creates buffer in system memory. See reset() for parameter details. Returns nullptr when parameters are invalid or allocation fails.

◆ createReference()

virtual RRBuffer * rr::RRBuffer::createReference ( )
pure virtual

Creates reference to the same buffer. Both buffer and reference must be deleted (in any order).

It is not thread safe, must not be called concurrently for one buffer. It may be called concurrently for different buffers.

◆ getReferenceCount()

virtual unsigned rr::RRBuffer::getReferenceCount ( )
pure virtual

Returns number of references to this instance, for debugging only.

◆ createCopy() [1/2]

RRBuffer * rr::RRBuffer::createCopy ( )

Creates copy of buffer. Copy is located in system memory and is completely separated, both buffers may contain different data. Copy of video contains single frame.

◆ createCopy() [2/2]

RRBuffer * rr::RRBuffer::createCopy ( RRBufferFormat  format,
bool  scaled,
const RRColorSpace colorSpace 
) const

◆ copyElementsTo()

bool rr::RRBuffer::copyElementsTo ( RRBuffer destination,
const RRColorSpace colorSpace 
) const

Copies contents of buffer. Destination buffer format and scale are preserved, data are converted as necessary.

Parameters
destinationDestination buffer. Must have the same width, height, depth, may differ in format, scale.
colorSpaceColor space used if one buffer is linear. nullptr for no color space conversion.
Returns
True on success.

◆ createSky()

static RRBuffer * rr::RRBuffer::createSky ( const RRVec4 upper = RRVec4(1),
const RRVec4 lower = RRVec4(1),
bool  scaled = true 
)
static

Creates cube texture with specified colors of upper and lower hemisphere.

Set scaled true for colors in custom color space (usually sRGB), false for linear colors. By default, white cube for ambient occlusion is created.

◆ createEquirectangular()

RRBuffer * rr::RRBuffer::createEquirectangular ( )

Creates equirectangular 360 degree panorama (2d texture) from texture loaded with loadCube().

When called on cubemap, it creates new 2d texture with the same number of pixels. When called on 2d texture, it already is equirectangular, so it returns new reference to the same texture. When called on other buffer type (vertex buffer), it returns nullptr.

In other words, this function returns environment rendered with equirectangular camera. For rendering with other camera types, you can use RRSolver::pathTraceFrame().

◆ createEnvironmentBlend()

static RRBuffer * rr::RRBuffer::createEnvironmentBlend ( RRBuffer environment0,
RRBuffer environment1,
RRReal  angleRad0,
RRReal  angleRad1,
RRReal  blendFactor 
)
static

Creates blend of two rotated environments (2d or cubemaps), as in RRSolver's environment.

Parameters are identical to RRSolver::setEnvironment() and RRSolver::setEnvironmentBlendFactor(). Created buffer is suitable only for pathtracing and for createEquirectangular(), because it has only getElementAtDirection() and some basic getWidth/Height() implemented, other functions are not available. It is cheap to create, as it doesn't copy any data, it accesses original buffers when needed.

◆ load()

static RRBuffer * rr::RRBuffer::load ( const RRString filename,
const char *  cubeSideName[6] = nullptr,
const RRFileLocator fileLocator = nullptr 
)
static

Loads buffer from disk to system memory.

Examples:

  • load("path/lightmap.png") - loads 2d texture (jpg, gif, dds etc)
  • load("path/lightmap.rrbuffer") - loads e.g. vertex buffer
  • load("path/cube_%%s.png", {"bk","ft","dn","up","rt","lf"}) - loads cubemap from 6 files
  • load("path/cube.hdr", non-nullptr) - loads cubemap from 1 file, expects cross-shaped image with aspect 3:4 or 4:3
  • load("path/cube.hdr", nullptr) - loads the same file as 2d texture
  • load("path/video.avi") - initializes video streamed to 2d texture, streaming is started by play()
  • load("c@pture") - initializes live video capture to 2d texture, capturing is started by play()
    Parameters
    filenameFilename of 2d image or vertexbuffer or cubemap or mask of 6 images (sides of cubemap) to be loaded from disk. All common file formats are supported. Proprietary .vbu format is used for vertex buffers.
    cubeSideNameArray of six unique names of cube sides in following order: x+ side, x- side, y+ side, y- side, z+ side, z- side.
    Examples: {"0","1","2","3","4","5"}, {"bk","ft","dn","up","rt","lf"}.
    Must be nullptr for vertex buffers and 2d textures, non-nullptr for cubemaps (even cubemaps in 1 file).
    fileLocatornullptr = load will be attempted only from filename. Non-nullptr = load will be attempted from paths offered by fileLocator. When load fails, fileLocator is asked whether stub buffer with original filename should be created, see RRFileLocator::setAttempt(RRFileLocator::ATTEMPT_STUB,...).
    Returns
    Returns newly created buffer. In case of failure, nullptr is returned and details logged via RRReporter.
    Remarks
    Image load/save is implemented outside LightsprintCore. Make samples/Import/ImportFreeImage.cpp part of your project to enable save/load or use registerLoader() to assign custom code.

◆ loadCube()

static RRBuffer * rr::RRBuffer::loadCube ( const RRString filename,
const RRFileLocator fileLocator = nullptr 
)
static

Loads texture from 1 or 6 files to system memory, converting it to cubemap if possible.

This is convenience function working with incomplete information, it attempts to guess whether you want to load texture from 1 file or from 6 files. It calls load() with guessed parameters. If you know exactly what to load, call load() yourself and avoid any guesswork.

Parameters
filenameIt could be one of
  • one of 6 images that make cube map; they are loaded into cubemap
  • cross shaped 4:3 or 3:4 image; is loaded into cubemap
  • any other 2d image; is loaded into 2d map It should be full filename, e.g. cube_ft.jpg rather than cube_%s.jpg.
fileLocatornullptr = load will be attempted only from filename. Non-nullptr = load will be attempted from paths offered by fileLocator.

◆ reload()

virtual bool rr::RRBuffer::reload ( const RRString filename,
const char *  cubeSideName[6],
const RRFileLocator fileLocator 
)
virtual

Similar to load(), but loads from disk into existing buffer.

Default implementation uses buffer's load() and reset() to load and copy single static frame, it does not work for videos.

◆ save()

bool rr::RRBuffer::save ( const RRString filenameMask,
const char *  cubeSideName[6] = nullptr,
const SaveParameters saveParameters = nullptr 
)

Saves buffer to disk.

It is not "const" function because it changes RRBuffer::filename to given filename. Save parameters are similar to load, see load() for examples.

Parameters
filenameMaskFilename of 1 image/vertexbuffer or mask of 6 images (sides of cubemap) to be saved to disk. All common file formats are supported. Proprietary .vbu format is used for vertex buffers (it consists of 2 bytes RRBufferFormat, 2 bytes bool scaled, 4 bytes num_vertices, data from buffer).
cubeSideNameWhen cubemap is saved, array of six unique names of cube sides in following order: x+ side, x- side, y+ side, y- side, z+ side, z- side. Examples: {"0","1","2","3","4","5"}, {"bk","ft","dn","up","rt","lf"}.
saveParametersRarely used additional parameters, keep nullptr for defaults.
Returns
True on successful save of complete buffer.
Remarks
Image load/save is implemented outside LightsprintCore. Make samples/Import/ImportFreeImage.cpp part of your project to enable save/load or use registerLoader() to assign custom code.

◆ registerLoader()

static void rr::RRBuffer::registerLoader ( const char *  extensions,
Loader loader 
)
static

Hooks external code that handles loading content from files into new buffers.

Usually called from rr_io::registerIO(). Initial state is no code hooked, attempts to load buffer are ignored, load() returns nullptr.

◆ registerSaver()

static void rr::RRBuffer::registerSaver ( const char *  extensions,
Saver saver 
)
static

Hooks external code that handles saving images to disk.

Usually called from rr_io::registerIO(). Initial state is no code hooked, attempts to save buffer are ignored, save() returns false.

◆ getSupportedLoaderExtensions()

static const char * rr::RRBuffer::getSupportedLoaderExtensions ( )
static

Returns list of supported loader extensions in "*.jpg;*.png" format.

All extensions of registered loaders are returned in one static string, don't free() it. nullptr is returned if no loaders were registered.

◆ getSupportedSaverExtensions()

static const char * rr::RRBuffer::getSupportedSaverExtensions ( )
static

Returns list of supported saver extensions in "*.jpg;*.png" format.

All extensions of registered savers are returned in one static string, don't free() it. nullptr is returned if no savers were registered.

◆ setFormat()

virtual void rr::RRBuffer::setFormat ( RRBufferFormat  newFormat)
virtual

Changes buffer format.

◆ setFormatFloats()

virtual void rr::RRBuffer::setFormatFloats ( )
virtual

Changes buffer format to floats, RGB to RGBF, RGBA to RGBAF.

◆ clear()

virtual void rr::RRBuffer::clear ( RRVec4  clearColor = RRVec4(0))
virtual

Clears buffer to clearColor.

◆ invert()

virtual void rr::RRBuffer::invert ( )
virtual

Changes all colors in buffer to 1-color.

Preserves buffer format. This operation is lossless for all formats.

◆ multiplyAdd()

virtual void rr::RRBuffer::multiplyAdd ( RRVec4  multiplier,
RRVec4  addend 
)
virtual

Changes all colors in buffer to color*multiplier+addend.

Preserves buffer format. This operation may be lossy for byte formats (clamped to 0..1 range), use setFormatFloats() for higher precision.

◆ flip()

virtual void rr::RRBuffer::flip ( bool  flipX,
bool  flipY,
bool  flipZ 
)
virtual

Flips buffer in x, y and/or z dimension.

◆ rotate()

virtual void rr::RRBuffer::rotate ( int  degrees,
unsigned  depthLayer = 0 
)
virtual

Rotates single 2d layer of buffer in multiples of 90 degrees.

In case of cubemap, dapthLayer selects side. Contents of buffer is undefined after +90/-90 degree rotation if width!=height.

◆ brightnessGamma()

virtual void rr::RRBuffer::brightnessGamma ( RRVec4  brightness,
RRVec4  gamma 
)
virtual

Changes all colors in buffer to pow(color*brightness,gamma).

Preserves buffer format. This operation may be lossy for byte formats (clamped to 0..1 range), use setFormatFloats() for higher precision.

◆ getMinMax()

virtual void rr::RRBuffer::getMinMax ( RRVec4 mini,
RRVec4 maxi 
)
virtual

Fills mini and maxi with extreme values found in buffer.

◆ lightmapSmooth()

virtual bool rr::RRBuffer::lightmapSmooth ( float  sigma,
bool  wrap,
const class RRObject object 
)
virtual

Applies gaussian blur to lightmap, even across seams in unwrap.

Reads and preserves connectivity information stored by lightmap baker to alpha channel.

Parameters
sigmaAmount of smoothing, reasonable values are around 1.
wrapTrue = smooth through lightmap boundaries.
objectObject this lightmap is for, used only for smoothing across unwrap seams. When nullptr, separated unwrap regions are smoothed separately, unwrap seams stay visible in lightmap.
Returns
True on success, may fail when allocation fails or buffer is not 2d texture.

◆ lightmapGrowForBilinearInterpolation()

virtual bool rr::RRBuffer::lightmapGrowForBilinearInterpolation ( bool  wrap)
virtual

Fills in unused lightmap texels relevant when bilinearly interpolating lightmap.

Reads connectivity information stored by lightmap baker to alpha channel. Sets alpha in newly colored texels to 0.001f.

Parameters
wrapTrue = grow through lightmap boundaries.
Returns
False when lightmap is empty (all texels have alpha<0.002) or not 2d texture.

◆ lightmapGrow()

virtual bool rr::RRBuffer::lightmapGrow ( unsigned  distance,
bool  wrap,
bool &  aborting 
)
virtual

Fills in unused lightmap texels in proximity of used ones, may help when mipmapping or compressing lightmap.

Expects used texels to have alpha>0. Sets alpha in newly colored texels to 0.001f.

Parameters
distanceDistance in pixels, how deep into unused regions to grow used colors.
wrapTrue = grow through lightmap boundaries.
abortingCan be set asynchronously to abort work in progress. When aborted, results are identical to call with lower distance.
Returns
True on success, may fail when allocation fails or buffer is not 2d texture.

◆ lightmapFillBackground()

virtual bool rr::RRBuffer::lightmapFillBackground ( RRVec4  backgroundColor)
virtual

Fills unused texels in lightmap by backgroundColor.

Expects used texels to have alpha>0.

Parameters
backgroundColorColor (and alpha) to set to all unused texels.
Returns
True on success, may fail when buffer is not 2d texture.

◆ deleteFromCache()

void rr::RRBuffer::deleteFromCache ( )
protected

Deletes last reference to buffer from cache.

To be called from delete operator of all RRBuffer implementations when refCount is 1. Without this function, deleted images would stay in cache and next load from the same filename would be super fast. This is however rarely needed, freeing memory is more important, so we explicitly delete buffer from cache.

Member Data Documentation

◆ filename

RRString rr::RRBuffer::filename

Optional filename, automatically set when load/save succeeds.

When RRFileLocator is in use and it locates requested file in different place, this is the name of file actually opened. When RRFileLocator fails to locate requested file, but it generates or loads stub image, this is name of file requested. Path can be relative or absolute, anything supported by operating system, we don't restrict its format.

◆ version

unsigned rr::RRBuffer::version

Version of data in buffer, modified each time buffer content changes.

◆ customData

void* rr::RRBuffer::customData

For your private use, not accessed by LightsprintCore. Initialized to nullptr.

If you use LightsprintGL, you should not modify it, it is set to Texture*.