SilverLining
|
This class is the main interface to thread safe rendering with SilverLining. More...
#include <ThreadCameraStreamData.h>
Public Member Functions | |
ThreadCameraStreamData (bool rightHanded, double unitScale, bool deferred) | |
constructor | |
virtual | ~ThreadCameraStreamData () |
destructor | |
const Camera * | GetCamera (void) const |
These are the only public methods you need to use to render multiple views using multiple threads with/without command lists. | |
Camera * | GetCamera (void) |
get the associated camera (non-const) | |
int | Initialize (int rendererType, bool rightHanded, void *environment, bool avoidStalls) |
Initialize the ThreadCameraStreamData (call first) | |
int | Initialize (int rendererType, bool rightHanded, void *environment, bool avoidStalls, const SL_VECTOR(unsigned int)&userShaders) |
OpenGL-only variant of ThreadCameraStreamData::Initialize() that takes in a list of user-compiled shader objects that will be linked into all subsequently linked shader program objects. | |
void | Initialize (const Atmosphere &atmosphere) |
Initialize the ThreadCameraStreamData for a given Atmosphere object (call 2nd) | |
bool | IsInitialized (void) const |
Whether initialized. | |
void | ExecuteStream (void) |
For OpenGL: Execute the command list for this object. | |
void | SetStream (void *stream, int frameIndex=-1) |
Set the current command buffer that we are recording to (only for Vulkan renderer). | |
void | SetRandomNumberGenerator (RandomNumberGenerator *rng) |
Some effects (like lightning) need to be synchronized across multiple views. | |
RandomNumberGenerator * | GetRandomNumberGenerator () const |
Get the random number generator. | |
void | SetEnvironmentMapFormat (ColorFormat format) |
Vulkan only. | |
void | SetUseShadowMap (bool val) |
Vulkan only. | |
void | SettingsChanged (void *environment) |
Vulkan only. | |
void | SetUserData (const void *userPointer, TcsUserData *userData) |
!!!!Do Not Use!!!! !!!!Internal methods!!!! These should not be used by application developers!! | |
TcsUserData * | GetUserData (const void *userPointer) |
get a user pointer and the user data associated with it, if it exists null otherwise | |
bool | UserDataExists (const void *userPointer) const |
whether user data exists for a user pointer | |
void | EraseUserData (const void *userPointer) |
erase user data associated with this layer (just erases the entry) | |
void | SetCloudLayerTcsUserData (const CloudLayer *cloudLayer, TcsUserData *userData) |
These are named variations of the 3 functions above. | |
TcsUserData * | GetCloudLayerTcsUserData (const CloudLayer *cloudLayer) |
get the name with userDataName as the key | |
bool | CloudLayerTcsUserDataExists (const CloudLayer *cloudLayer) |
exists? | |
void | EraseCloudLayerTcsUserData (const CloudLayer *cloudLayer) |
erase user data associated with this layer (just erases the entry) | |
Renderer * | GetRenderer (void) |
internal. do not use directly | |
const Renderer * | GetRenderer (void) const |
internal. do not use directly | |
const BillboardRenderingParameters * | GetBillboardRenderingParams (void) const |
internal. Do not use directly. Get the parameters, const version | |
BillboardRenderingParameters * | GetBillboardRenderingParams (void) |
internal. Do not use directly. Get the parameters, non-const version | |
const MetaballRenderingParameters * | GetMetaballRenderingParams (void) const |
internal. Do not use directly. Get the parameters, const version | |
MetaballRenderingParameters * | GetMetaballRenderingParams (void) |
internal. Do not use directly. Get the parameters, non-const version | |
const BillboardRenderer * | GetBillboardRenderer (void) const |
internal. Do not use directly. Get the billboard renderer, const version | |
BillboardRenderer * | GetBillboardRenderer (void) |
internal. Do not use directly. Get the billboard renderer, non-const version | |
const CloudRenderingParameters * | GetCloudRenderingParams (void) const |
internal. Do not use directly. Get the parameters, const version | |
CloudRenderingParameters * | GetCloudRenderingParams (void) |
internal. Do not use directly. Get the parameters, non-const version | |
const CumulusCloudRenderingParameters * | GetCumulusCloudRenderingParams (void) const |
internal. Do not use directly. Get the parameters, const version | |
CumulusCloudRenderingParameters * | GetCumulusCloudRenderingParams (void) |
internal. Do not use directly. Get the parameters, non-const version | |
const LuminanceMapper * | GetLuminanceMappper (void) const |
internal. Do not use directly. Get the parameters, const version | |
LuminanceMapper * | GetLuminanceMappper (void) |
internal. Do not use directly. Get the parameters, non-const version | |
bool | GetIsDrawingEnvMap () const |
internal. Do not use directly. Whether drawing env map currently | |
void | SetIsDrawingEnvMap (bool val) |
internal. Do not use directly. Set drawing env map to true/false | |
bool | GetIsDrawingShadowMap () const |
internal. Do not use directly. Whether drawing shadow map currently | |
void | SetIsDrawingShadowMap (bool val) |
internal. Do not use directly. Set drawing shadow map to true/false | |
bool | GetSortByScreenDepth (void) const |
internal. Do not use directly. Get sort screen depth | |
void | SetSortByScreenDepth (bool val) |
internal. Do not use directly. Set sort screen depth | |
const BillboardShader * | GetBillboardShader (void) const |
internal. do not use! | |
const BillboardShader * | GetBillboardShaderInstanced (void) const |
internal. do not use! | |
void | ReloadShaders (void) |
internal. do not use! | |
void | Shutdown (void) |
internal. do not use! | |
void | DeviceLost (void) |
internal. do not use! | |
void | DeviceReset (void) |
internal. do not use! | |
void | FrameStarted () |
internal. do not use! | |
void | SetContext () |
internal. do not use! | |
void | ReloadBillboardShader (void) |
internal. do not use! | |
const SkyShaders * | GetSkyShaders (bool simpleShader) const |
internal. do not use! | |
void | ReloadSkyShaders (void) |
internal. do not use! | |
const StratocumulusShaders * | GetStratocumulusShaders (void) const |
internal. do not use! | |
void | ReloadStratocumulusShaders (void) |
internal. do not use! | |
const FlareShader * | GetFlareShader (void) const |
internal. do not use! | |
const CirrusShader * | GetCirrusShader (void) const |
internal. do not use! | |
void | ReloadCirrusShader (void) |
internal. do not use! | |
const StratusShader * | GetStratusShader (void) const |
internal. do not use! | |
void | ReloadStratusShader (void) |
internal. do not use! | |
const StarShader * | GetStarShader (void) const |
internal. do not use! | |
void | ReloadStarShader (void) |
internal. do not use! | |
const GlareShader * | GetGlareShader (void) const |
internal. do not use! | |
GlareShader * | GetGlareShader (void) |
internal. do not use! | |
const AtmosphereFromSpaceShader * | GetAtmosphereFromSpaceShader (bool doShadow) const |
internal. do not use! | |
bool | GetDeferred (void) const |
get whether internal stream/context is a deferred stream call before initialize! | |
CrepuscularRays * | GetCrepuscularRays (void) |
internal. do not use! | |
const CrepuscularRays * | GetCrepuscularRays (void) const |
internal. do not use! | |
Sky * | GetSky (void) |
internal. do not use! | |
const Sky * | GetSky (void) const |
internal. do not use! | |
LensFlare * | GetLensFlare (void) |
internal. do not use! | |
const LensFlare * | GetLensFlare (void) const |
internal. do not use! | |
bool | GetIsDrawingSky (void) const |
internal. do not use! | |
bool | GetIsDrawingObjects (void) const |
internal. do not use! | |
void | SetIsDrawingSky (bool val) |
internal. do not use! | |
void | SetIsDrawingObjects (bool val) |
internal. do not use! | |
void | SetForceImmediate (bool val) |
internal. do not use! | |
bool | GetForceImmediate (void) const |
internal. do not use! | |
const PrecipitationShaders * | GetPrecipitationShaders (void) const |
internal. do not use! | |
PrecipitationShaders * | GetPrecipitationShaders (void) |
internal. do not use! | |
void | SetUpAndRightVector (const Vector3 &upVector, const Vector3 &rightVector) |
Helper function to set up the up and right vector on the Camera of this tcs data. | |
const PrecipitationManager * | GetPrecipitationManager (void) const |
internal. do not use! | |
PrecipitationManager * | GetPrecipitationManager (void) |
internal. do not use! | |
void | InitializePrecipitationManager (const Atmosphere &atmosphere) |
internal. do not use! | |
bool | GetPrecipitationEnabled (void) const |
internal. do not use! | |
const ShadowMap * | GetOrCreateShadowMap (const Atmosphere &atmosphere) const |
internal. do not use! | |
ShadowMap * | GetOrCreateShadowMap (const Atmosphere &atmosphere) |
internal. do not use! | |
const ShadowMap * | GetShadowMapObject (void) const |
internal. do not use! | |
int | GetShadowMapDim () const |
internal. do not use! | |
void | DeleteShadowMap (void) |
internal. do not use! | |
void | DeleteEnvironmentMaps (void) |
internal. do not use! | |
const TextureManager * | GetTextureManager (void) const |
internal. do not use! | |
void | setCreateTextures (bool create) |
internal. do not use! | |
bool | GetEnvironmentMap (EnvironmentMap *&environmentMap, Atmosphere &atmosphere, void *&texture, int facesToRender=6, bool floatingPoint=false, CameraHandle cameraID=0, bool drawClouds=true, bool drawSunAndMoon=true, bool geocentricMode=false) |
internal. do not use! | |
bool | DrawIndirect () const |
internal. do not use! | |
void | SetInfraRedMode (bool bInfraRed) |
set infra red mode | |
bool | GetInfraRedMode () const |
whether infra red model | |
void | SetTime (const LocalTime &pTime, unsigned long timerMilliseconds) |
internal. do not use! | |
const LocalTime & | GetTime (unsigned long timerMilliseconds) |
internal. do not use! | |
void | SetLocation (const Location &_location) |
internal. do not use! | |
const Location & | GetLocation () const |
internal. do not use! | |
Location & | GetLocation () |
internal. do not use! | |
void | SetBaseTimeMS (unsigned long val) |
internal. do not use! | |
unsigned long | GetBaseTimeMS (void) const |
internal. do not use! | |
void | EnableTimePassage (bool enabled, long relightFrequencyMS, unsigned long timerMilliseconds) |
internal. do not use! | |
LocalTime & | GetTime () |
internal. These are used for serialization only | |
bool | GetHDREnabled () const |
internal helper | |
const float * | GetStratusMieLookupPixels (int &width) |
internal. | |
const unsigned char * | GetStratusNoisePixels (int &width, int &height) |
internal. | |
std::ostream & | log (LogLevel level) |
logging //! internal. | |
Protected Member Functions | |
void | CreateStratusMieLookupPixels (void) |
internal | |
This class is the main interface to thread safe rendering with SilverLining.
The class represents the concept of thread local storage: https://en.wikipedia.org/wiki/Thread-local_storage
The 'thread' part of the name represents each separate thread (and hence each instance of this class) that we wish to render from in a thread safe fashion.
The 'camera' part of the name represents each view(e.g. window/offscreen view) that you wish to render from in a thread safe fashion in the corresponding thread.
This typically also corresponds to an OpenGL context (you can share OpenGL contexts or not) or an immediate/deferred DirectX context.
The 'stream' part of the name represents the command stream (OpenGL/Vulkan) or the immediate/deferred context commands (DX 11, 11.1) being generated for a given thread, view.
As an example, to render 3 views (one main view, and 2 offscreen views).
Below are then the steps you follow to render everything in a thread safe fashion:
A few notes:
So make sure to pass the pointer to the object of the thread/camera(view)/stream in question in the same order/position/context of which thread/camera(view)/stream is in question.
Multi-Threading:
Deferred Rendering:
!!NOTE!!
SilverLining::ThreadCameraStreamData::ThreadCameraStreamData | ( | bool | rightHanded, |
double | unitScale, | ||
bool | deferred | ||
) |
constructor
rightHanded | Set this the same as the initialized Atmosphere. |
unitScale | Set this the same as the initialized Atmosphere. |
deferred | Set whether this tcsData uses deferred rendering. |
void SilverLining::ThreadCameraStreamData::ExecuteStream | ( | void | ) |
For OpenGL: Execute the command list for this object.
See documentation above on 'deferred rendering'. For Vulkan: Execute one time/internal bookkeeping commands, if any, outside of the rendering/command buffer recording in a thread safe fashion (e.g. main thread), just before the submission of silverlining command buffers. See SilverLiningVulkanExample.
const Camera * SilverLining::ThreadCameraStreamData::GetCamera | ( | void | ) | const |
These are the only public methods you need to use to render multiple views using multiple threads with/without command lists.
get the associated camera
RandomNumberGenerator * SilverLining::ThreadCameraStreamData::GetRandomNumberGenerator | ( | ) | const |
Get the random number generator.
See SetRandomNumberGenerator
const float * SilverLining::ThreadCameraStreamData::GetStratusMieLookupPixels | ( | int & | width | ) |
internal.
do not use! creates if necessary
const unsigned char * SilverLining::ThreadCameraStreamData::GetStratusNoisePixels | ( | int & | width, |
int & | height | ||
) |
internal.
do not use! creates if necessary
void SilverLining::ThreadCameraStreamData::Initialize | ( | const Atmosphere & | atmosphere | ) |
Initialize the ThreadCameraStreamData for a given Atmosphere object (call 2nd)
environment | The atmosphere against which this tcsData is being initialized |
int SilverLining::ThreadCameraStreamData::Initialize | ( | int | rendererType, |
bool | rightHanded, | ||
void * | environment, | ||
bool | avoidStalls | ||
) |
Initialize the ThreadCameraStreamData (call first)
rendererType | The renderer type. The same as the type passed in to Atmosphere::Initialize |
rightHanded | right handed or left handed system. The same as the type passed in to Atmosphere |
environment | The same value as the one passed in to Atmosphere::Initialize |
avoidStalls | If you with to do any combination of multi-threaded rendering and deferred you need to set this config option on the Atmosphere: atmosphere->SetConfigOption("avoid-opengl-stalls", "yes"); and pass the same value (true) |
int SilverLining::ThreadCameraStreamData::Initialize | ( | int | rendererType, |
bool | rightHanded, | ||
void * | environment, | ||
bool | avoidStalls, | ||
const SL_VECTOR(unsigned int)& | userShaders | ||
) |
OpenGL-only variant of ThreadCameraStreamData::Initialize() that takes in a list of user-compiled shader objects that will be linked into all subsequently linked shader program objects.
This allows you to inject your own shader functions into our shaders without copying the source.
rendererType | The renderer type. The same as the type passed in to Atmosphere::Initialize |
rightHanded | right handed or left handed system. The same as the type passed in to Atmosphere |
environment | The same value as the one passed in to Atmosphere::Initialize |
avoidStalls | If you with to do any combination of multi-threaded rendering and deferred you need to set this config option on the Atmosphere: atmosphere->SetConfigOption("avoid-opengl-stalls", "yes"); and pass the same value (true) |
userShaders | A list of user shaders, if any, to link into all shaders loaded by SilverLining. |
std::ostream & SilverLining::ThreadCameraStreamData::log | ( | LogLevel | level | ) |
logging //! internal.
do not use!
void SilverLining::ThreadCameraStreamData::SetCloudLayerTcsUserData | ( | const CloudLayer * | cloudLayer, |
TcsUserData * | userData | ||
) |
These are named variations of the 3 functions above.
set the name with userDataName as the key
void SilverLining::ThreadCameraStreamData::SetEnvironmentMapFormat | ( | ColorFormat | format | ) |
Vulkan only.
If you intend to use environment maps via ThreadCameraStreamData::GetEnvironmentMap, this needs to be specified before initializing ThreadCameraStreamData.
void SilverLining::ThreadCameraStreamData::SetRandomNumberGenerator | ( | RandomNumberGenerator * | rng | ) |
Some effects (like lightning) need to be synchronized across multiple views.
Re-seeding the atmosphere random number in these cases per view doesn't quite work right for those. To avoid this, set the value of tcs-data-effects-rng-unique to yes. Then, the tcs datas will use their own internal random generators in this case (which if seeded/reset the same, will synchronize the effects across the views.
If an rng is not set via this call (and the tcs-data-effects-rng-unique is 'yes', the tcs data will use its own internal rng.
void SilverLining::ThreadCameraStreamData::SetSortByScreenDepth | ( | bool | val | ) |
internal. Do not use directly. Set sort screen depth
Set whether objects should be sorted by screen depth or distance from the view
void SilverLining::ThreadCameraStreamData::SetStream | ( | void * | stream, |
int | frameIndex = -1 |
||
) |
Set the current command buffer that we are recording to (only for Vulkan renderer).
frameIndex is the image index/swap chain image index associated with the command buffer being recorded. If it is not provided, SilverLining has to do some extra work for internal book keeping.
void SilverLining::ThreadCameraStreamData::SettingsChanged | ( | void * | environment | ) |
Vulkan only.
environment | This must contain a pointer to a VulkanInitInfo structure, as defined in the VulkanInitInfo.h header. Only the parameters: renderPass, sampleCount, colorFormat and depthFormat are considered for the change. Other parameters are ignored. |
void SilverLining::ThreadCameraStreamData::SetUserData | ( | const void * | userPointer, |
TcsUserData * | userData | ||
) |
!!!!Do Not Use!!!! !!!!Internal methods!!!! These should not be used by application developers!!
set a user pointer and the user data associated with it
void SilverLining::ThreadCameraStreamData::SetUseShadowMap | ( | bool | val | ) |
Vulkan only.
If you intend to use shadow maps via ThreadCameraStreamData::GetShadowMap, this needs to be specified before initializing ThreadCameraStreamData.