LightsprintSDK 2021.08.08
|
#include <RRBuffer.h>
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 RRBuffer * | createReference ()=0 |
virtual unsigned | getReferenceCount ()=0 |
RRBuffer * | createCopy () |
RRBuffer * | createCopy (RRBufferFormat format, bool scaled, const RRColorSpace *colorSpace) const |
bool | copyElementsTo (RRBuffer *destination, const RRColorSpace *colorSpace) const |
RRBuffer * | createEquirectangular () |
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 RRBuffer * | create (RRBufferType type, unsigned width, unsigned height, unsigned depth, RRBufferFormat format, bool scaled, const unsigned char *data) |
static RRBuffer * | createSky (const RRVec4 &upper=RRVec4(1), const RRVec4 &lower=RRVec4(1), bool scaled=true) |
static RRBuffer * | createEnvironmentBlend (RRBuffer *environment0, RRBuffer *environment1, RRReal angleRad0, RRReal angleRad1, RRReal blendFactor) |
static RRBuffer * | load (const RRString &filename, const char *cubeSideName[6]=nullptr, const RRFileLocator *fileLocator=nullptr) |
static RRBuffer * | loadCube (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 () | |
Buffer, array of elements.
Two approaches exist for using buffers in DirectX/OpenGL renderer
When implementing custom RRBuffer subclass, it may help to know how solvers update buffers
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:
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".
Type of user defined function that loads content from file into new buffer.
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.
rr::RRBuffer::RRBuffer | ( | ) |
|
inlinevirtual |
|
pure virtual |
Sets size and contents of buffer.
type | Requested type of buffer. |
width | Requested width of buffer. Set to number of vertices for BT_VERTEX_BUFFER. |
height | Requested height of buffer. Set 1 for BT_VERTEX_BUFFER. Set equal to width for BT_CUBE_TEXTURE. |
depth | Requested depth of buffer. Set 1 for BT_VERTEX_BUFFER and BT_2D_TEXTURE. Set 6 for BT_CUBE_TEXTURE. |
format | Format 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. |
scaled | True 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). |
data | Data 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). |
|
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.
|
pure virtual |
|
pure virtual |
|
pure virtual |
|
pure virtual |
unsigned rr::RRBuffer::getNumElements | ( | ) | const |
|
pure virtual |
|
pure virtual |
|
virtual |
|
virtual |
|
virtual |
Returns value addressed by given integer coordinate.
index | Index is index into array of all elements, x+y*width+z*width*height. Out of range indices are reported as error. |
colorSpace | If nullptr, color is returned in native color space. With colorSpace set, RGB is returned in linear space, alpha in native space. |
|
virtual |
Returns value addressed by given float coordinates.
position | Coordinates are array indices in 0..1 range covering whole buffer. Out of range indices are wrapped to 0..1. |
colorSpace | If nullptr, color is returned in native color space. With colorSpace set, RGB is returned in linear space, alpha in native space. |
interpolated | Switches from nearest element selection to linear interpolation of 4 elements. |
|
virtual |
Returns environment sample addressed by given direction (not necessarily normalized).
direction | Direction from center in which we look for element. 2d texture is interpreted as 360*180 degree panorama. Cube texture is interpreted as standard cube. |
colorSpace | If nullptr, color is returned in native color space. With colorSpace set, RGB is returned in linear space, alpha in native space. |
|
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.
|
virtual |
Unlocks previously locked buffer.
|
inlinevirtual |
For video/capture/animated buffers, returns true if buffer content was updated and version changed.
|
inlinevirtual |
For video buffers, starts playing buffer. To update content of playing buffer, call update().
|
inlinevirtual |
For video buffers, stops playing buffer and rewinds to the beginning.
|
inlinevirtual |
For video buffers, pauses playing buffer.
|
inlinevirtual |
For video buffers, seeks to given number of seconds from start.
|
inlinevirtual |
|
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
|
static |
Creates buffer in system memory. See reset() for parameter details. Returns nullptr when parameters are invalid or allocation fails.
|
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.
|
pure virtual |
Returns number of references to this instance, for debugging only.
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.
RRBuffer * rr::RRBuffer::createCopy | ( | RRBufferFormat | format, |
bool | scaled, | ||
const RRColorSpace * | colorSpace | ||
) | const |
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.
destination | Destination buffer. Must have the same width, height, depth, may differ in format, scale. |
colorSpace | Color space used if one buffer is linear. nullptr for no color space conversion. |
|
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.
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().
|
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.
|
static |
Loads buffer from disk to system memory.
Examples:
filename | Filename 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. |
cubeSideName | 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"}. Must be nullptr for vertex buffers and 2d textures, non-nullptr for cubemaps (even cubemaps in 1 file). |
fileLocator | nullptr = 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,...). |
|
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.
filename | It could be one of
|
fileLocator | nullptr = load will be attempted only from filename. Non-nullptr = load will be attempted from paths offered by fileLocator. |
|
virtual |
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.
filenameMask | Filename 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). |
cubeSideName | When 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"}. |
saveParameters | Rarely used additional parameters, keep nullptr for defaults. |
|
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.
|
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.
|
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.
|
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.
|
virtual |
Changes buffer format.
|
virtual |
Changes buffer format to floats, RGB to RGBF, RGBA to RGBAF.
Clears buffer to clearColor.
|
virtual |
Changes all colors in buffer to 1-color.
Preserves buffer format. This operation is lossless for all formats.
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.
|
virtual |
Flips buffer in x, y and/or z dimension.
|
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.
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.
Fills mini and maxi with extreme values found in buffer.
|
virtual |
Applies gaussian blur to lightmap, even across seams in unwrap.
Reads and preserves connectivity information stored by lightmap baker to alpha channel.
sigma | Amount of smoothing, reasonable values are around 1. |
wrap | True = smooth through lightmap boundaries. |
object | Object 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. |
|
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.
wrap | True = grow through lightmap boundaries. |
|
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.
distance | Distance in pixels, how deep into unused regions to grow used colors. |
wrap | True = grow through lightmap boundaries. |
aborting | Can be set asynchronously to abort work in progress. When aborted, results are identical to call with lower distance. |
|
virtual |
Fills unused texels in lightmap by backgroundColor.
Expects used texels to have alpha>0.
backgroundColor | Color (and alpha) to set to all unused texels. |
|
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.
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.
unsigned rr::RRBuffer::version |
Version of data in buffer, modified each time buffer content changes.
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*.