Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
sdl_interface.h File Reference

Go to the source code of this file.

Macros

#define PH_DEFINE_SDL_CLASS(...)
 Define a SDL class with function-like syntax.
 
#define PH_DEFINE_SDL_STRUCT(...)
 
#define PH_DEFINE_SDL_FUNCTION(...)
 
#define PH_DEFINE_SDL_ENUM(...)
 Define a SDL enum with function-like syntax.
 

Macro Definition Documentation

◆ PH_DEFINE_SDL_CLASS

#define PH_DEFINE_SDL_CLASS ( ...)
Value:
/* variadic args for template types that contain commas */\
\
using ClassType = std::remove_cv_t<__VA_ARGS__>;\
using OwnerType = std::remove_cv_t<typename ClassType::OwnerType>;\
\
/* A marker so we know the macro has been called. */\
using SdlClassDefinitionMarker = OwnerType;\
\
inline static const ClassType* getSdlClass()\
{\
static_assert(std::is_base_of_v<::ph::ISdlResource, OwnerType>,\
"PH_DEFINE_SDL_CLASS() can only be defined for SDL resource.");\
static_assert(std::is_base_of_v<::ph::SdlClass, ClassType>,\
"PH_DEFINE_SDL_CLASS() must return a class derived from SdlClass.");\
\
static const ClassType sdlClass = internal_sdl_class_impl();\
return &sdlClass;\
}\
\
inline const ::ph::SdlClass* getDynamicSdlClass() const override\
{\
return getSdlClass();\
}\
\
inline static ClassType internal_sdl_class_impl()

Define a SDL class with function-like syntax.

Use this macro in the class body of a SDL resource to provide an interface for introspection. The SDL class instance type to be defined should be the only argument to the macro. Followed is a ordinary C++ scope (a pair of curly braces) where the definition for the SDL class instance resides. Several utility types can be used within the scope: ClassType for the type of the SDL class, and OwnerType for the type of the SDL resource. Finally, use a return statement to return the SDL class instance.

Available functionalities after defining the macro:

const ClassType* getSdlClass()

  • A static method for accessing the static SDL class.

const SdlClass* getDynamicSdlClass() const

  • A virtual method for accessing SDL class in runtime, through an instance to resource. The returned class will be the one defined for the actual type of the resource.

◆ PH_DEFINE_SDL_ENUM

#define PH_DEFINE_SDL_ENUM ( ...)

Define a SDL enum with function-like syntax.

One does not need to define all enum entries. It is valid to partially expose some enum entries and keep the others hidden from SDL. Note that it is highly encouraged to provide a valid entry with the value 0 as it will be used as the default.

A limitation of this macro is that it must be called in the enclosing namespace of ph (within namespace ph itself). Note this should not cause any name collision–the enum type can still be defined in an appropriate namespace. (The underlying implementation depends on explicit template specialization which requires the aforementioned rule. As long as a unique enum type is used for specializing TSdlEnum, the resulting type should still be unique.)

For a enum EnumType, after the definition is done by calling this macro, you can use methods in TSdlEnum<EnumType> to access functionalities. See TSdlEnum for what methods are available.

◆ PH_DEFINE_SDL_FUNCTION

#define PH_DEFINE_SDL_FUNCTION ( ...)
Value:
/* variadic args for template types that contain commas */\
\
using FunctionType = std::remove_cv_t<__VA_ARGS__>;\
using OwnerType = std::remove_cv_t<typename FunctionType::OwnerType>;\
\
/* A marker so we know the macro has been called. */\
using SdlFunctionDefinitionMarker = OwnerType;\
\
inline static const FunctionType* getSdlFunction()\
{\
static_assert(std::is_base_of_v<::ph::SdlFunction, FunctionType>,\
"PH_DEFINE_SDL_FUNCTION() must return a function derived from SdlFunction.");\
\
static const FunctionType sdlFunction = internal_sdl_function_impl();\
return &sdlFunction;\
}\
\
inline static FunctionType internal_sdl_function_impl()

◆ PH_DEFINE_SDL_STRUCT

#define PH_DEFINE_SDL_STRUCT ( ...)
Value:
/* variadic args for template types that contain commas */\
\
using StructType = std::remove_cv_t<__VA_ARGS__>;\
using OwnerType = std::remove_cv_t<typename StructType::OwnerType>;\
\
/* A marker so we know the macro has been called. */\
using SdlStructDefinitionMarker = OwnerType;\
\
inline static const StructType* getSdlStruct()\
{\
static_assert(std::is_base_of_v<::ph::SdlStruct, StructType>,\
"PH_DEFINE_SDL_STRUCT() must return a struct derived from SdlStruct.");\
\
static const StructType sdlStruct = internal_sdl_struct_impl();\
return &sdlStruct;\
}\
\
inline static StructType internal_sdl_struct_impl()