#include <unordered_set>
#include <unordered_map>
#include <thread>
#include <cstring>
{
public:
: m_renderer(renderer)
{
}
{
m_scenes[sceneId].state = state;
}
{
m_scenes[sceneId].version = sceneVersion;
}
{
{
m_createdOffscreenBuffers.insert(offscreenBufferId);
}
}
{
if (success)
{
}
}
{
waitForElementInSet(offscreenBufferId, m_createdOffscreenBuffers);
}
{
waitUntilOrTimeout([&] {return m_scenesConsumingOffscreenBuffer.count(sceneId) > 0; });
}
{
waitUntilOrTimeout([&] { return m_scenes[sceneId].state == state; });
}
{
return waitUntilOrTimeout([&] { return m_scenes[sceneId].version == sceneVersion; });
}
bool waitUntilOrTimeout(const std::function<bool()>& conditionFunction)
{
const std::chrono::steady_clock::time_point timeoutTS = std::chrono::steady_clock::now() + std::chrono::seconds{ 5 };
while (!conditionFunction() && std::chrono::steady_clock::now() < timeoutTS)
{
std::this_thread::sleep_for(std::chrono::milliseconds{ 5 });
}
return conditionFunction();
}
{
m_windowClosed = true;
}
bool isWindowClosed() const
{
return m_windowClosed;
}
private:
struct SceneInfo
{
};
using SceneSet = std::unordered_map<ramses::sceneId_t, SceneInfo>;
using DataConsumerSet = std::unordered_set<ramses::dataConsumerId_t>;
using OffscreenBufferSet = std::unordered_set<ramses::displayBufferId_t>;
template <typename T>
void waitForElementInSet(const T element, const std::unordered_set<T>& set)
{
while (set.find(element) == set.end())
{
std::this_thread::sleep_for(std::chrono::milliseconds(10u));
}
}
SceneSet m_scenes;
SceneSet m_scenesAssignedToOffscreenBuffer;
SceneSet m_scenesConsumingOffscreenBuffer;
OffscreenBufferSet m_createdOffscreenBuffers;
DataConsumerSet m_dataConsumers;
bool m_windowClosed = false;
};
{
auto now = std::chrono::system_clock::now();
return std::chrono::time_point_cast<std::chrono::milliseconds>(now).time_since_epoch().count();
}
static constexpr uint32_t SampleCount = 4u;
static constexpr uint32_t ObWidth = 200u;
static constexpr uint32_t ObHeight = 200u;
{
{
break;
}
return meshNode;
}
{
}
{
}
{
camera->
setFrustum(-2.f, 2.f, -2.f, 2.f, 0.1f, 100.f);
const uint16_t indicesArray[] = { 0, 1, 2, 2, 1, 3 };
const float vertexPositionsArray[] =
{
-1.f, -1.f, 0.f,
1.f, -1.f, 0.f,
-1.f, 1.f, 0.f,
1.f, 1.f, 0.f
};
const float textureCoordsArray[] = { 0.f, 1.f, 1.f, 1.f, 0.f, 0.f, 1.f, 0.f };
return clientScene;
}
{
camera->
setFrustum ( -2.f, 2.f, -2.f, 2.f, 0.1f, 100.f );
const uint16_t indicesArray[] = { 0, 1, 2, 2, 1, 3 };
const float vertexPositionsArray[] =
{
-1.f, -1.f, 0.f,
1.f, -1.f, 0.f,
-1.f, 1.f, 0.f,
1.f, 1.f, 0.f
};
return clientScene;
}
int main(
int argc,
char* argv[])
{
auto& sceneControlAPI = *renderer.getSceneControlAPI();
framework.connect();
renderer.setMaximumFramerate(60.0f);
renderer.startThread();
renderer.flush();
sceneControlAPI.flush();
sceneControlAPI.setSceneMapping(providerSceneId2, display);
sceneControlAPI.flush();
consumerScene->
flush(versionTagMS);
consumerScene->
flush(versionTag);
renderer.flush();
eventHandler.waitForOffscreenBufferCreated(offscreenBufferMS);
eventHandler.waitForOffscreenBufferCreated(offscreenBuffer);
sceneControlAPI.setSceneDisplayBufferAssignment(
providerSceneId, offscreenBufferMS);
sceneControlAPI.setSceneDisplayBufferAssignment(providerSceneId2, offscreenBuffer);
sceneControlAPI.flush();
sceneControlAPI.linkOffscreenBuffer(offscreenBufferMS,
consumerSceneId, samplerConsumerIdMS);
sceneControlAPI.linkOffscreenBuffer(offscreenBuffer,
consumerSceneId, samplerConsumerId);
sceneControlAPI.flush();
eventHandler.waitForOffscreenBufferLinkedToConsumingScene(
consumerSceneId);
sceneControlAPI.flush();
bool link = false;
uint64_t timeStamp = 1u;
float rotationZ = 0.f;
while (!eventHandler.isWindowClosed())
{
renderer.dispatchEvents(eventHandler);
if (timeStamp % 200 == 0)
{
if (link)
{
sceneControlAPI.linkOffscreenBuffer(offscreenBuffer,
consumerSceneId, samplerConsumerId);
sceneControlAPI.linkOffscreenBuffer(offscreenBufferMS,
consumerSceneId, samplerConsumerIdMS);
}
else
{
}
sceneControlAPI.flush();
link = !link;
}
++rotationZ;
++timeStamp;
std::this_thread::sleep_for(std::chrono::milliseconds{ 15u });
}
renderer.stopThread();
}
SceneStateEventHandler(ramses::RendererSceneControl &sceneControlApi, ramses::RamsesRenderer &renderer)
Definition: main.cpp:50
The Appearance describes how an object should look like. This includes GLSL uniform values,...
Definition: Appearance.h:34
status_t setInputValueVector4f(const UniformInput &input, float x, float y, float z, float w)
Sets value of the input.
status_t setInputValueInt32(const UniformInput &input, int32_t i)
Sets value of the input.
status_t setInputTexture(const UniformInput &input, const TextureSampler &textureSampler)
Sets texture sampler to the input.
The ArrayResource stores a data array of a given type. The data is immutable. The resource can be use...
Definition: ArrayResource.h:26
status_t setViewport(int32_t x, int32_t y, uint32_t width, uint32_t height)
Sets the viewport to be used when rendering with this camera.
status_t setFrustum(float leftPlane, float rightPlane, float bottomPlane, float topPlane, float nearPlane, float farPlane)
Sets camera frustum planes of the Camera.
The DisplayConfig holds a set of parameters to be used to initialize a display.
Definition: DisplayConfig.h:22
An effect description holds all necessary information for an effect to be created.
Definition: EffectDescription.h:21
status_t setVertexShaderFromFile(const char *shaderSourceFileName)
Reads and sets vertex shader source from file.
status_t setUniformSemantic(const char *inputName, EEffectUniformSemantic semanticType)
Sets an uniform semantic. Used for uniforms which are not locally available on the client,...
status_t setFragmentShaderFromFile(const char *shaderSourceFileName)
Reads and sets fragment shader source from file.
An effect describes how an object will be rendered to the screen.
Definition: Effect.h:26
status_t findUniformInput(const char *inputName, UniformInput &uniformInput) const
Finds uniform input by input name.
status_t getUniformInput(uint32_t index, UniformInput &uniformInput) const
Gets uniform input at given index.
uint32_t getUniformInputCount() const
Gets number of uniform inputs.
status_t findAttributeInput(const char *inputName, AttributeInput &attributeInput) const
Finds attribute input by input name.
A geometry binding together with an appearance describe how an object will be rendered to the screen.
Definition: GeometryBinding.h:25
status_t setIndices(const ArrayResource &indicesResource)
Assign a data array with data type UInt16 or UInt32 to be used when accessing vertex data.
status_t setInputBuffer(const AttributeInput &attributeInput, const ArrayResource &arrayResource, uint32_t instancingDivisor=0)
Assign a data array resource to a given effect attribute input.
The MeshNode holds all information which is needed to render an object to the screen.
Definition: MeshNode.h:25
status_t setAppearance(Appearance &appearance)
Sets the Appearance of the MeshNode.
const Appearance * getAppearance() const
Returns the appearance.
status_t setGeometryBinding(GeometryBinding &geometry)
Sets the GeometryBinding of the MeshNode.
The Node is the base class of all nodes and provides scene graph functionality which propagates to it...
Definition: Node.h:23
status_t setParent(Node &node)
Sets parent Node for this node.
status_t setTranslation(float x, float y, float z)
Sets the absolute translation the absolute values.
status_t setRotation(float x, float y, float z)
Sets the absolute rotation in all three directions for left-handed rotation using Euler ZYX rotation ...
The OrthographicCamera is a local camera which defines an orthographic view into the scene.
Definition: OrthographicCamera.h:22
The PerspectiveCamera is a local camera which defines a perspective view into the scene.
Definition: PerspectiveCamera.h:23
status_t setFrustum(float fov, float aspectRatio, float nearPlane, float farPlane)
An alternative method (see ramses::Camera::setFrustum) to set the perspective view frustum of the cam...
Entry point of RAMSES client API.
Definition: RamsesClient.h:34
Scene * createScene(sceneId_t sceneId, const SceneConfig &sceneConfig=SceneConfig(), const char *name=nullptr)
Create a new empty Scene.
The RamsesFrameworkConfig holds a set of parameters to be used to initialize ramses.
Definition: RamsesFrameworkConfig.h:23
Class representing ramses framework components that are needed to initialize an instance of ramses cl...
Definition: RamsesFramework.h:35
RamsesRenderer is the main renderer component which provides API to configure and control the way con...
Definition: RamsesRenderer.h:37
status_t dispatchEvents(IRendererEventHandler &rendererEventHandler)
Most RamsesRenderer methods push commands to an internal queue which is submitted when calling Ramses...
RendererSceneControl * getSceneControlAPI()
Get scene control API.
static Texture2D * CreateTextureResourceFromPng(const char *pngFilePath, Scene &scene, const TextureSwizzle &swizzle={}, const char *name=nullptr)
Creates a Texture from the given png file.
RenderBuffer can be used with RenderTarget as buffer for writing or with TextureSampler as buffer for...
Definition: RenderBuffer.h:25
The RenderGroup is a container used to collect renderables which are supposed to be rendered together...
Definition: RenderGroup.h:31
status_t addMeshNode(const MeshNode &mesh, int32_t orderWithinGroup=0)
Add a mesh to this RenderGroup. If a mesh is already contained in this RenderGroup only its render or...
The RenderPass is a container used to collect meshes which are supposed to be rendered together.
Definition: RenderPass.h:31
status_t setCamera(const Camera &camera)
Set the camera to use for rendering the objects of this renderpass.
status_t setClearFlags(uint32_t clearFlags)
Set the clear flags which enable/disable the clearing of the render target assigned to this RenderPas...
status_t setRenderTarget(RenderTarget *renderTarget)
Set the render target for the render pass to render into.
status_t addRenderGroup(const RenderGroup &renderGroup, int32_t orderWithinPass=0)
Add a RenderGroup to this RenderPass for rendering.
status_t setRenderOrder(int32_t renderOrder)
Set the render order for the render pass.
status_t setClearColor(float r, float g, float b, float a)
Set the clear color for the RenderPass (default: [0,0,0,0])
RenderTargetDescription holds all necessary information for a RenderTarget to be created.
Definition: RenderTargetDescription.h:22
status_t addRenderBuffer(const RenderBuffer &renderBuffer)
Adds a RenderBuffer to the RenderTargetDescription.
The RenderTarget can be used as an output for a RenderPass.
Definition: RenderTarget.h:20
The RendererConfig holds a set of parameters to be used to initialize a renderer.
Definition: RendererConfig.h:26
Convenience empty implementation of IRendererEventHandler that can be used to derive from when only s...
Definition: IRendererEventHandler.h:194
Convenience empty implementation of IRendererSceneControlEventHandler that can be used to derive from...
Definition: IRendererSceneControlEventHandler.h:214
virtual void sceneFlushed(sceneId_t sceneId, sceneVersionTag_t sceneVersionTag) override
This method will be called after a flush with version tag (ramses::Scene::flush) has been applied.
Definition: IRendererSceneControlEventHandler.h:310
virtual void offscreenBufferLinked(displayBufferId_t offscreenBufferId, sceneId_t consumerScene, dataConsumerId_t consumerId, bool success) override
This method will be called when the data link between offscreen buffer and scene's data slot is estab...
Definition: IRendererSceneControlEventHandler.h:228
virtual void sceneStateChanged(sceneId_t sceneId, RendererSceneState state) override
This method will be called when state of a scene changes.
Definition: IRendererSceneControlEventHandler.h:219
status_t dispatchEvents(IRendererSceneControlEventHandler &eventHandler)
RendererSceneControl methods push commands to an internal queue which is submitted when calling flush...
The SceneConfig holds a set of parameters to be used when creating a scene.
Definition: SceneConfig.h:22
The Scene holds a scene graph. It is the essential class for distributing content to the ramses syste...
Definition: Scene.h:83
OrthographicCamera * createOrthographicCamera(const char *name=nullptr)
Creates a Orthographic Camera in this Scene.
MeshNode * createMeshNode(const char *name=nullptr)
Creates a scene graph MeshNode. MeshNode is a Node with additional properties and bindings that repre...
Effect * createEffect(const EffectDescription &effectDesc, resourceCacheFlag_t cacheFlag=ResourceCacheFlag_DoNotCache, const char *name=nullptr)
Create a new Effect by parsing a GLSL shader described by an EffectDescription instance....
Node * createNode(const char *name=nullptr)
Creates a scene graph node. The basic purpose of Node is to define topology in scene graph by links t...
TextureSamplerMS * createTextureSamplerMS(const RenderBuffer &renderBuffer, const char *name)
Creates a multisampled texture sampler object.
RenderBuffer * createRenderBuffer(uint32_t width, uint32_t height, ERenderBufferType bufferType, ERenderBufferFormat bufferFormat, ERenderBufferAccessMode accessMode, uint32_t sampleCount=0u, const char *name=nullptr)
Create a RenderBuffer to be used with RenderTarget for rendering into and TextureSampler for sampling...
GeometryBinding * createGeometryBinding(const Effect &effect, const char *name=nullptr)
Creates a new GeometryBinding.
ArrayResource * createArrayResource(EDataType type, uint32_t numElements, const void *arrayData, resourceCacheFlag_t cacheFlag=ResourceCacheFlag_DoNotCache, const char *name=nullptr)
Create a new ArrayResource. It makes a copy of the given data of a certain type as a resource,...
status_t publish(EScenePublicationMode publicationMode=EScenePublicationMode_LocalAndRemote)
Publishes the scene to the ramses system.
RenderPass * createRenderPass(const char *name=nullptr)
Create a render pass in the scene.
Appearance * createAppearance(const Effect &effect, const char *name=nullptr)
Creates a new Appearance.
RenderTarget * createRenderTarget(const RenderTargetDescription &rtDesc, const char *name=nullptr)
Create a render target providing a set of RenderBuffers.
RenderGroup * createRenderGroup(const char *name=nullptr)
Create a RenderGroup instance in the scene.
PerspectiveCamera * createPerspectiveCamera(const char *name=nullptr)
Creates a Perspective Camera in this Scene.
const RamsesObject * findObjectByName(const char *name) const
Get an object from the scene by name.
status_t flush(sceneVersionTag_t sceneVersionTag=InvalidSceneVersionTag)
Commits all changes done to the scene since the last flush or since scene creation....
TextureSampler * createTextureSampler(ETextureAddressMode wrapUMode, ETextureAddressMode wrapVMode, ETextureSamplingMethod minSamplingMethod, ETextureSamplingMethod magSamplingMethod, const Texture2D &texture, uint32_t anisotropyLevel=1, const char *name=nullptr)
Creates a texture sampler object.
status_t createTextureConsumer(const TextureSampler &sampler, dataConsumerId_t dataId)
Annotates a ramses::TextureSampler as a content consumer. Texture provider and texture consumer can b...
Helper class to create strongly typed values out of various types.
Definition: StronglyTypedValue.h:23
Texture represents a 2-D texture resource.
Definition: Texture2D.h:24
The ramses::TextureSamplerMS is used to sample multisampled data when bound to a ramses::Appearance u...
Definition: TextureSamplerMS.h:21
The TextureSampler holds a texture and its sampling parameters.
Definition: TextureSampler.h:29
@ ZYX
rotates around X then Y then Z axis
@ ERenderBufferFormat_RGBA8
Definition: TextureEnums.h:141
@ ETextureSamplingMethod_Linear
Definition: TextureEnums.h:21
@ ETextureAddressMode_Repeat
Definition: TextureEnums.h:33
@ EClearFlags_All
Definition: RamsesFrameworkTypes.h:263
@ EClearFlags_None
Definition: RamsesFrameworkTypes.h:257
@ ModelViewProjectionMatrix
Model-view-projection matrix 4x4.
@ Vector2F
two components of type float per data element
@ UInt16
one component of type uint16_t per data element
@ Vector3F
three components of type float per data element
@ ERamsesShellType_Console
Definition: RamsesFrameworkTypes.h:169
RendererSceneState
Definition: RendererSceneState.h:19
@ Unavailable
Scene is unavailable, no scene control possible.
@ Rendered
Scene is being rendered.
@ Ready
Scene is ready to start rendering (its resources are uploaded).
constexpr const status_t StatusOK
Status returned from RAMSES client API methods that succeeded.
Definition: RamsesFrameworkTypes.h:32
constexpr const resourceCacheFlag_t ResourceCacheFlag_DoNotCache
Requests the render to not cache a resource. This is the default value.
Definition: RamsesFrameworkTypes.h:212
uint64_t sceneVersionTag_t
Scene version tag used to refer to content versions of a scene. A scene version may be updated along ...
Definition: RamsesFrameworkTypes.h:49
ERendererEventResult
Specifies the result of the operation referred to by renderer event.
Definition: Types.h:94
@ ERendererEventResult_FAIL
Event referring to an operation that failed.
Definition: Types.h:97
@ ERenderBufferType_Color
Definition: TextureEnums.h:129
constexpr const sceneVersionTag_t InvalidSceneVersionTag
Scene version tag used to refer to an invalid scene version.
Definition: RamsesFrameworkTypes.h:54
@ ERenderBufferAccessMode_ReadWrite
RenderBuffer with this access can be used both in RenderTarget and TextureSampler.
Definition: TextureEnums.h:171
int main(int argc, char *argv[])
Definition: main.cpp:21
constexpr ramses::sceneId_t consumerSceneId(2u)
constexpr ramses::sceneId_t providerSceneId(1u)
uint64_t nowMs()
Definition: main.cpp:40
ramses::Effect & createEffect(ramses::Scene &scene, const std::string &effectName)
Definition: main.cpp:219
ramses::Scene * createProviderScene(ramses::RamsesClient &client, ramses::sceneId_t sceneId, const char *rotationNodeName)
Definition: main.cpp:276
void createClearPass(ramses::Scene *scene, ramses::RenderBuffer *renderBuffer)
Definition: main.cpp:178
ramses::Scene * createConsumerScene(ramses::RamsesClient &client, ramses::sceneId_t sceneId, const char *samplerConsumerName, const char *samplerConsumerNameMS)
Definition: main.cpp:208
ramses::MeshNode * createTexturedQuad(ramses::Scene *clientScene, const ramses::Effect *effect, const ramses::ArrayResource *indices, const ramses::ArrayResource *vertexPositions, const ramses::ArrayResource *textureCoords)
Definition: main.cpp:150
constexpr uint32_t DisplayWidth
Definition: main.cpp:31
constexpr uint32_t DisplayHeight
Definition: main.cpp:32