RAMSES Documentation  27.0.130
Information for RAMSES users and developers
ramses-example-basic-renderpasses/src/main.cpp

Basic Renderpasses Example

// -------------------------------------------------------------------------
// Copyright (C) 2015 BMW Car IT GmbH
// -------------------------------------------------------------------------
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
// -------------------------------------------------------------------------
#include "ramses-client.h"
#include <thread>
int main(int argc, char* argv[])
{
// register at RAMSES daemon
ramses::RamsesFramework framework(argc, argv);
ramses::RamsesClient& ramses(*framework.createClient("ramses-example-basic-renderpasses"));
framework.connect();
// create a scene
ramses::Scene* scene = ramses.createScene(ramses::sceneId_t(123u), ramses::SceneConfig(), "basic renderpasses scene");
// prepare triangle geometry: vertex position array and index array
float vertexPositionsArray[] = { -0.5f, 0.f, -1.f, 0.5f, 0.f, -1.f, -0.5f, 1.f, -1.f, 0.5f, 1.f, -1.f };
ramses::ArrayResource* vertexPositions = scene->createArrayResource(ramses::EDataType::Vector3F, 4, vertexPositionsArray);
uint16_t indicesArray[] = { 0, 1, 2, 2, 1, 3 };
effectDesc.setVertexShaderFromFile("res/ramses-example-basic-renderpasses.vert");
effectDesc.setFragmentShaderFromFile("res/ramses-example-basic-renderpasses.frag");
ramses::Effect* effectTex = scene->createEffect(effectDesc, ramses::ResourceCacheFlag_DoNotCache, "glsl shader");
// IMPORTANT NOTE: For simplicity and readability the example code does not check return values from API calls.
// This should not be the case for real applications.
// every render pass needs a camera to define rendering parameters
// create camera with perspective projection
ramses::Node* cameraTranslate = scene->createNode();
cameraTranslate->setTranslation(0.0f, 0.0f, 5.0f);
ramses::PerspectiveCamera* cameraA = scene->createPerspectiveCamera("perspective camera of renderpass A");
cameraA->setParent(*cameraTranslate);
cameraA->setFrustum(45.f, 640.f / 480.f, 0.1f, 100.f);
// use left side of the viewport
cameraA->setViewport(0u, 0u, 640u, 480u);
// create camera with orthographic projection
ramses::OrthographicCamera* cameraB = scene->createOrthographicCamera("ortho camera of renderpass B");
cameraB->setParent(*cameraTranslate);
cameraB->setFrustum(-2.f, 2.f, -2.f, 2.f, 0.1f, 100.f);
// use right side of the viewport
cameraB->setViewport(640u, 0u, 640u, 480u);
// create two renderpasses
ramses::RenderPass* renderPassA = scene->createRenderPass("renderpass A");
ramses::RenderPass* renderPassB = scene->createRenderPass("renderpass B");
// set valid cameras for the passes
renderPassA->setCamera(*cameraA);
renderPassB->setCamera(*cameraB);
// create render group for each renderpass
ramses::RenderGroup* renderGroupA = scene->createRenderGroup("rendergroup A");
ramses::RenderGroup* renderGroupB = scene->createRenderGroup("rendergroup B");
renderPassA->addRenderGroup(*renderGroupA);
renderPassB->addRenderGroup(*renderGroupB);
ramses::Appearance* appearanceA = scene->createAppearance(*effectTex, "triangle appearance");
ramses::Appearance* appearanceB = scene->createAppearance(*effectTex, "triangle appearance");
// set vertex positions directly in geometry
ramses::GeometryBinding* geometry = scene->createGeometryBinding(*effectTex, "triangle geometry");
geometry->setIndices(*indices);
ramses::AttributeInput positionsInput;
effectTex->findAttributeInput("a_position", positionsInput);
geometry->setInputBuffer(positionsInput, *vertexPositions);
// use two appearances, each with a different color for distinguishing the meshes
effectTex->findUniformInput("color", color);
appearanceA->setInputValueVector4f(color, 1.0f,0.0f,0.0f,1.0f);
appearanceB->setInputValueVector4f(color, 0.0f,1.0f,0.0f,1.0f);
ramses::MeshNode* meshNodeA = scene->createMeshNode("red triangle mesh node");
meshNodeA->setAppearance(*appearanceA);
meshNodeA->setGeometryBinding(*geometry);
ramses::MeshNode* meshNodeB = scene->createMeshNode("green triangle mesh node");
meshNodeB->setAppearance(*appearanceB);
meshNodeB->setGeometryBinding(*geometry);
// add each mesh to one pass
renderGroupA->addMeshNode(*meshNodeA);
renderGroupB->addMeshNode(*meshNodeB);
// signal the scene it is in a state that can be rendered
scene->flush();
scene->publish();
// distribute the scene to RAMSES
std::this_thread::sleep_for(std::chrono::seconds(2));
// application logic
uint32_t loops = 10000;
while (--loops)
{
std::this_thread::sleep_for(std::chrono::seconds(2));
}
// shutdown: stop distribution, free resources, unregister
scene->unpublish();
scene->destroy(*vertexPositions);
scene->destroy(*indices);
ramses.destroy(*scene);
framework.disconnect();
return 0;
}
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.
The ArrayResource stores a data array of a given type. The data is immutable. The resource can be use...
Definition: ArrayResource.h:26
The AttributeInput is a description of an attribute effect input.
Definition: AttributeInput.h:22
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.
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 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.
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.
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
Class representing ramses framework components that are needed to initialize an instance of ramses cl...
Definition: RamsesFramework.h:35
status_t connect()
Tries to establish a connection to the RAMSES system.
RamsesClient * createClient(const char *applicationName)
Create a new RamsesClient linked to this framework. Creation of multiple clients is supported....
status_t disconnect()
Disconnects the RamsesClient from the system.
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 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...
status_t unpublish()
Unpublish the scene from the ramses system.
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.
status_t destroy(SceneObject &object)
Destroys a previously created object using this scene The object must be owned by this scene in order...
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 flush(sceneVersionTag_t sceneVersionTag=InvalidSceneVersionTag)
Commits all changes done to the scene since the last flush or since scene creation....
Helper class to create strongly typed values out of various types.
Definition: StronglyTypedValue.h:23
The UniformInput is a description of an uniform effect input.
Definition: UniformInput.h:22
The RAMSES namespace contains all client side objects and functions used to implement RAMSES applicat...
Definition: AnimatedProperty.h:15
@ 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
constexpr const resourceCacheFlag_t ResourceCacheFlag_DoNotCache
Requests the render to not cache a resource. This is the default value.
Definition: RamsesFrameworkTypes.h:212
int main(int argc, char *argv[])
Definition: main.cpp:21