Example for controlling scene state and data linking of scenes via scene referencing instead of renderer API.
#include <thread>
#include <unordered_map>
{
public:
{
m_windowClosed = true;
}
{
return m_windowClosed;
}
private:
bool m_windowClosed = false;
};
{
public:
: m_client(client)
{}
{
}
{
while (m_sceneRefState.count(sceneId) == 0 || m_sceneRefState.find(sceneId)->second != state)
{
std::this_thread::sleep_for(std::chrono::milliseconds(5));
m_client.dispatchEvents(*this);
}
}
private:
std::unordered_map<ramses::sceneId_t, ramses::RendererSceneState> m_sceneRefState;
};
static constexpr unsigned VPWidth = 600;
static constexpr unsigned VPHeight = 400;
static constexpr unsigned DispWidth = 1280;
static constexpr unsigned DispHeight = 480;
{
camera->
setFrustum(19.f, 1280.f / 480.f, 0.1f, 1500.f);
vpSizeData->setValue(VPWidth, VPHeight);
float vertexPositionsArray[] = { -1.f, 0.f, -6.f, 1.f, 0.f, -6.f, 0.f, 1.f, -6.f };
uint16_t indicesArray[] = { 0, 1, 2 };
uniform highp mat4 mvpMatrix;
attribute vec3 a_position;
void main() {
gl_Position = mvpMatrix * vec4(a_position, 1.0);
})glsl");
uniform highp vec4 color;
void main(void) {
gl_FragColor = color + vec4(0.1);
})glsl");
color1->setValue(0.5f, 0.5f, 0.5f, 1.f);
}
{
vp1size->setValue(DispWidth, DispHeight);
vp2offset->setValue(0, 0);
vp2size->setValue(DispWidth, DispHeight);
color2->setValue(0.f, 0.3f, 0.5f, 1.f);
color3->setValue(1.f, 0.f, 0.5f, 1.f);
color4->setValue(0.5f, 0.3f, 0.f, 1.f);
return clientScene;
}
int main(
int argc,
char* argv[])
{
renderer.startThread();
renderer.flush();
framework.connect();
SceneReferenceEventHandler eventHandler(client);
masterScene->
linkData(
nullptr, VP1OffsetProviderId, sceneRef1, VPOffsetConsumerId);
masterScene->
linkData(
nullptr, VP1SizeProviderId, sceneRef1, VPSizeConsumerId);
masterScene->
linkData(
nullptr, VP2OffsetProviderId, sceneRef2, VPOffsetConsumerId);
masterScene->
linkData(
nullptr, VP2SizeProviderId, sceneRef2, VPSizeConsumerId);
masterScene->
linkData(
nullptr, Color1ProviderId, sceneRef1, Color1ConsumerId);
masterScene->
linkData(
nullptr, Color2ProviderId, sceneRef1, Color2ConsumerId);
masterScene->
linkData(
nullptr, Color3ProviderId, sceneRef2, Color1ConsumerId);
masterScene->
linkData(
nullptr, Color4ProviderId, sceneRef2, Color2ConsumerId);
auto scene1vpOffset = ramses::RamsesUtils::TryConvert<ramses::DataVector2i>(*masterScene->
findObjectByName(
"vp1offset"));
auto scene1vpSize = ramses::RamsesUtils::TryConvert<ramses::DataVector2i>(*masterScene->
findObjectByName(
"vp1size"));
auto scene2vpOffset = ramses::RamsesUtils::TryConvert<ramses::DataVector2i>(*masterScene->
findObjectByName(
"vp2offset"));
auto scene2vpSize = ramses::RamsesUtils::TryConvert<ramses::DataVector2i>(*masterScene->
findObjectByName(
"vp2size"));
int animParam = 0;
bool animInc = true;
{
renderer.dispatchEvents(rendererEventHandler);
scene1vpOffset->setValue(VPWidth / 8 + VPWidth / 2 * animParam / 100, VPHeight / 8 + VPHeight / 4 * animParam / 100);
scene1vpSize->setValue(VPWidth / 4 + VPWidth / 2 * animParam / 100, VPHeight / 4 + VPHeight / 4 * animParam / 100);
const auto invAnimParam = 100 - animParam;
scene2vpOffset->setValue(DispWidth / 2 - VPWidth / 2 * invAnimParam / 100, DispHeight - DispHeight / 4 - VPHeight / 4 * invAnimParam / 100);
scene2vpSize->setValue(VPWidth / 2 + VPWidth / 2 * invAnimParam / 100, VPHeight / 4 + VPHeight / 4 * invAnimParam / 100);
animParam = (animInc ? animParam + 1 : animParam - 1);
if (animParam == 0 || animParam == 100)
animInc = !animInc;
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
}
void windowClosed(ramses::displayId_t) override
This method will be called when a display's window has been closed.
Definition: main.cpp:26
bool isWindowClosed() const
Definition: main.cpp:31
The Appearance describes how an object should look like. This includes GLSL uniform values,...
Definition: Appearance.h:34
status_t bindInput(const UniformInput &input, const DataObject &dataObject)
Bind a DataObject to the Appearance's uniform input. The value from the DataObject will be used and a...
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 bindViewportOffset(const DataVector2i &offsetData)
Binds a ramses::DataObject to be used as source for viewport offset values.
status_t bindViewportSize(const DataVector2i &sizeData)
Binds a ramses::DataObject to be used as source for viewport size values.
status_t setValue(int32_t x, int32_t y)
Sets/updates the stored values of the vector.
status_t setValue(float x, float y, float z, float w)
Sets/updates the stored values of the vector.
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 setVertexShader(const char *shaderSource)
Sets vertex shader source from string.
status_t setFragmentShader(const char *shaderSource)
Sets fragment shader source from string.
status_t setUniformSemantic(const char *inputName, EEffectUniformSemantic semanticType)
Sets an uniform semantic. Used for uniforms which are not locally available on the client,...
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 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.
Provides an interface for handling the result of client events. Implementation of this interface must...
Definition: IClientEventHandler.h:27
virtual void sceneReferenceStateChanged(SceneReference &sceneRef, RendererSceneState state)=0
This method will be called when state on renderer side of a scene referenced using ramses::SceneRefer...
virtual void dataUnlinked(sceneId_t consumerScene, dataConsumerId_t consumerId, bool success)=0
This method will be called when the data link between a data provider and data consumer is destroyed ...
virtual void sceneFileLoadFailed(const char *filename)=0
This method will be called when asynchronous loading of a scene or one of its associated resource fil...
virtual void sceneFileLoadSucceeded(const char *filename, Scene *loadedScene)=0
This method will be called when asynchronous loading of a scene file and its associated resource file...
virtual void dataLinked(sceneId_t providerScene, dataProviderId_t providerId, sceneId_t consumerScene, dataConsumerId_t consumerId, bool success)=0
This method will be called when the data link between a data provider and data consumer is establishe...
virtual void sceneReferenceFlushed(SceneReference &sceneRef, sceneVersionTag_t versionTag)=0
This method will be called after a flush with version tag (ramses::Scene::flush) has been applied and...
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.
status_t setGeometryBinding(GeometryBinding &geometry)
Sets the GeometryBinding of the MeshNode.
status_t setScaling(float x, float y, float z)
Sets the absolute scale in all three dimensions.
status_t setTranslation(float x, float y, float z)
Sets the absolute translation the absolute values.
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
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 addRenderGroup(const RenderGroup &renderGroup, int32_t orderWithinPass=0)
Add a RenderGroup to this RenderPass for rendering.
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
Control states of scenes.
Definition: RendererSceneControl.h:33
status_t setSceneState(sceneId_t sceneId, RendererSceneState state)
Request state change of a scene.
status_t setSceneMapping(sceneId_t sceneId, displayId_t displayId)
Set scene display mapping.
status_t flush()
Submits scene control commands (API calls on RendererSceneControl) since previous flush to be execute...
The SceneReference object refers to another ramses scene using its sceneId.
Definition: SceneReference.h:37
status_t requestState(RendererSceneState requestedState)
Set a requested state for this scene reference.
sceneId_t getReferencedSceneId() const
Get the sceneId of the referenced scene.
The Scene holds a scene graph. It is the essential class for distributing content to the ramses syste...
Definition: Scene.h:83
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....
SceneReference * createSceneReference(sceneId_t referencedScene, const char *name=nullptr)
Creates a new SceneReference object.
DataVector4f * createDataVector4f(const char *name=nullptr)
Creates a data object within the scene, which holds a data value of type Vector4f.
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.
status_t linkData(SceneReference *providerReference, dataProviderId_t providerId, SceneReference *consumerReference, dataConsumerId_t consumerId)
Tell the RamsesRenderer to link a data provider to a data consumer across two scenes.
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.
DataVector2i * createDataVector2i(const char *name=nullptr)
Creates a data object within the scene, which holds a data value of type Vector2i.
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.
status_t createDataConsumer(const DataObject &dataObject, dataConsumerId_t dataId)
Annotates a DataObject as a data consumer. Data provider and data consumer can be linked on Ramses Re...
status_t createDataProvider(const DataObject &dataObject, dataProviderId_t dataId)
Annotates a DataObject as a data provider. Data provider and data consumer can be linked on Ramses Re...
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....
@ EClearFlags_None
Definition: RamsesFrameworkTypes.h:257
@ ModelViewProjectionMatrix
Model-view-projection matrix 4x4.
@ 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
@ Rendered
Scene is being rendered.
@ Ready
Scene is ready to start rendering (its resources are uploaded).
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
int main(int argc, char *argv[])
Definition: main.cpp:21
void createContentProviderScene(ramses::RamsesClient &client, ramses::sceneId_t sceneId)
Definition: main.cpp:96
ramses::Scene * createSceneMaster(ramses::RamsesClient &client, ramses::sceneId_t sceneId)
Definition: main.cpp:178