RAMSES Documentation  27.0.130
Information for RAMSES users and developers
ramses-utils.h
Go to the documentation of this file.
1 // -------------------------------------------------------------------------
2 // Copyright (C) 2014 BMW Car IT GmbH
3 // -------------------------------------------------------------------------
4 // This Source Code Form is subject to the terms of the Mozilla Public
5 // License, v. 2.0. If a copy of the MPL was not distributed with this
6 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
7 // -------------------------------------------------------------------------
8 
9 #ifndef RAMSES_RAMSES_UTILS_H
10 #define RAMSES_RAMSES_UTILS_H
11 
17 
18 #include <vector>
19 #include <string>
20 
21 namespace ramses
22 {
23  class RamsesObject;
24  class Effect;
25  class Node;
26  class Scene;
27  class Texture2D;
28  class UniformInput;
29  class DataVector2f;
30  class DataVector4f;
31  struct MipLevelData;
32  struct CubeMipLevelData;
33 
39  {
40  public:
50  template <typename T>
51  static const T* TryConvert(const RamsesObject& obj);
52 
56  template <typename T>
57  static T* TryConvert(RamsesObject& obj);
58 
68  static Texture2D* CreateTextureResourceFromPng(const char* pngFilePath, Scene& scene, const TextureSwizzle& swizzle = {}, const char* name = nullptr);
69 
79  static Texture2D* CreateTextureResourceFromPngBuffer(const std::vector<unsigned char>& pngData, Scene& scene, const TextureSwizzle& swizzle = {}, const char* name = nullptr);
80 
95  static MipLevelData* GenerateMipMapsTexture2D(uint32_t width, uint32_t height, uint8_t bytesPerPixel, uint8_t* data, uint32_t& mipMapCount);
96 
109  static bool SaveImageBufferToPng(const std::string& filePath, const std::vector<uint8_t>& imageData, uint32_t width, uint32_t height);
110 
128  static bool SaveImageBufferToPng(const std::string& filePath, std::vector<uint8_t>& imageData, uint32_t width, uint32_t height, bool flipImageBufferVertically);
129 
144  static CubeMipLevelData* GenerateMipMapsTextureCube(uint32_t faceWidth, uint32_t faceHeight, uint8_t bytesPerPixel, uint8_t* data, uint32_t& mipMapCount);
145 
151  static void DeleteGeneratedMipMaps(MipLevelData*& data, uint32_t mipMapCount);
152 
158  static void DeleteGeneratedMipMaps(CubeMipLevelData*& data, uint32_t mipMapCount);
159 
167  static nodeId_t GetNodeId(const Node& node);
168 
189  static bool SetPerspectiveCameraFrustumToDataObjects(float fov, float aspectRatio, float nearPlane, float farPlane, DataVector4f& frustumPlanesData, DataVector2f& nearFarPlanesData);
190 
210  static Scene* LoadSceneFromMemory(RamsesClient& client, std::unique_ptr<unsigned char[]> data, size_t size, bool localOnly);
211  };
212 
213  inline Scene* RamsesUtils::LoadSceneFromMemory(RamsesClient& client, std::unique_ptr<unsigned char[]> data, size_t size, bool localOnly)
214  {
215  std::unique_ptr<unsigned char[], void(*)(const unsigned char*)> dataWithDeleter(data.release(), [](const unsigned char* ptr) { delete[] ptr; });
216  return client.loadSceneFromMemory(std::move(dataWithDeleter), size, localOnly);
217  }
218 }
219 
220 #endif
#define RAMSES_API
Definition: APIExport.h:35
The DataVector2f data object stores a vector with 2 float components within a scene.
Definition: DataVector2f.h:22
The DataVector4f data object stores a vector with 4 float components within a scene.
Definition: DataVector4f.h:22
The Node is the base class of all nodes and provides scene graph functionality which propagates to it...
Definition: Node.h:23
Entry point of RAMSES client API.
Definition: RamsesClient.h:34
Scene * loadSceneFromMemory(std::unique_ptr< unsigned char[], void(*)(const unsigned char *)> data, size_t size, bool localOnly=false)
Loads scene contents and resources from a memory buffer.
The RamsesObject is a base class for all client API objects owned by the framework.
Definition: RamsesObject.h:21
Temporary functions for convenience. All of these can be implemented on top of the RAMSES Client API,...
Definition: ramses-utils.h:39
static const T * TryConvert(const RamsesObject &obj)
Converts object to a compatible object type. Object can be converted to any of its base classes....
static void DeleteGeneratedMipMaps(CubeMipLevelData *&data, uint32_t mipMapCount)
Deletes mip map data created with RamsesUtils::GenerateMipMapsTextureCube.
static bool SaveImageBufferToPng(const std::string &filePath, std::vector< uint8_t > &imageData, uint32_t width, uint32_t height, bool flipImageBufferVertically)
Creates a png from image data, e.g. data generated by RamsesClientService::readPixels....
static void DeleteGeneratedMipMaps(MipLevelData *&data, uint32_t mipMapCount)
Deletes mip map data created with RamsesUtils::GenerateMipMapsTexture2D.
static Texture2D * CreateTextureResourceFromPngBuffer(const std::vector< unsigned char > &pngData, Scene &scene, const TextureSwizzle &swizzle={}, const char *name=nullptr)
Creates a Texture from the given png memory buffer.
static T * TryConvert(RamsesObject &obj)
Converts object to a compatible object type. Object can be converted to any of its base classes....
static CubeMipLevelData * GenerateMipMapsTextureCube(uint32_t faceWidth, uint32_t faceHeight, uint8_t bytesPerPixel, uint8_t *data, uint32_t &mipMapCount)
Generate mip maps from original texture cube data. You obtain ownership of all the data returned in t...
static Scene * LoadSceneFromMemory(RamsesClient &client, std::unique_ptr< unsigned char[]> data, size_t size, bool localOnly)
Convenience wrapper for RamsesClient::loadSceneFromMemory with automatic deleter.
Definition: ramses-utils.h:213
static MipLevelData * GenerateMipMapsTexture2D(uint32_t width, uint32_t height, uint8_t bytesPerPixel, uint8_t *data, uint32_t &mipMapCount)
Generate mip maps from original texture 2D data. You obtain ownership of all the data returned in the...
static bool SetPerspectiveCameraFrustumToDataObjects(float fov, float aspectRatio, float nearPlane, float farPlane, DataVector4f &frustumPlanesData, DataVector2f &nearFarPlanesData)
Convenience method to set perspective camera frustum using FOV and aspect ratio (like in ramses::Pers...
static bool SaveImageBufferToPng(const std::string &filePath, const std::vector< uint8_t > &imageData, uint32_t width, uint32_t height)
Creates a png from image data, e.g. data generated by RamsesClientService::readPixels....
static Texture2D * CreateTextureResourceFromPng(const char *pngFilePath, Scene &scene, const TextureSwizzle &swizzle={}, const char *name=nullptr)
Creates a Texture from the given png file.
static nodeId_t GetNodeId(const Node &node)
Returns the identifier of a node, which is printed in the renderer logs. The identifier is guaranteed...
The Scene holds a scene graph. It is the essential class for distributing content to the ramses syste...
Definition: Scene.h:83
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 namespace contains all client side objects and functions used to implement RAMSES applicat...
Definition: AnimatedProperty.h:15
Struct containing information about one mip-map level of a cube texture. All faces of the cube textur...
Definition: MipLevelData.h:60
Struct containing information about one mip-map level of a texture.
Definition: MipLevelData.h:24
Information of how color channels of a texture are reordered or set to fixed value (one,...
Definition: TextureSwizzle.h:23