From 94f3884d9ca74c149d03ea16e11ae22516be15f0 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Wed, 8 Jan 2025 16:36:02 +0100 Subject: [PATCH] Some cleanups --- samples/00_HelloWorld/HelloWorld.cpp | 15 +----- samples/CMakeLists.txt | 28 +++++++---- src/Engine/RenderBackend/MaterialBuilder.cpp | 4 +- src/Engine/RenderBackend/MaterialBuilder.h | 4 +- src/Engine/RenderBackend/MeshBuilder.cpp | 52 -------------------- src/Engine/RenderBackend/MeshBuilder.h | 7 --- src/Engine/RenderBackend/Pipeline.h | 1 + src/Engine/RenderBackend/RenderStates.h | 43 ++++++++-------- src/Engine/RenderBackend/Shader.cpp | 2 +- src/Engine/RenderBackend/Shader.h | 5 +- 10 files changed, 51 insertions(+), 110 deletions(-) diff --git a/samples/00_HelloWorld/HelloWorld.cpp b/samples/00_HelloWorld/HelloWorld.cpp index e5dbafa56..a9da82c45 100644 --- a/samples/00_HelloWorld/HelloWorld.cpp +++ b/samples/00_HelloWorld/HelloWorld.cpp @@ -52,8 +52,6 @@ class HelloWorldApp : public App::AppBase { Entity *mEntity; /// The keyboard controller instance. Animation::AnimationControllerBase *mKeyboardTransCtrl; - Animation::AnimationTrack mTrack; - f32 mAngle; public: /// The class constructor with the incoming arguments from the command line. @@ -61,8 +59,7 @@ class HelloWorldApp : public App::AppBase { AppBase(argc, (const char **)argv), mTransformMatrix(), mEntity(nullptr), - mKeyboardTransCtrl(nullptr), - mAngle(1.0f) { + mKeyboardTransCtrl(nullptr) { // empty } @@ -75,16 +72,6 @@ class HelloWorldApp : public App::AppBase { world->addEntity(camEntity); CameraComponent *camera =(CameraComponent*) camEntity->createComponent(ComponentType::CameraComponentType); world->setActiveCamera(camera); - Animation::AnimatorComponent *animator = (Animation::AnimatorComponent *)camEntity->createComponent(ComponentType::AnimationComponentType); - mTrack.NumVectorChannels = 1; - mTrack.AnimationChannels = new Animation::AnimationChannel[mTrack.NumVectorChannels]; - mTrack.Duration = 1.0f; - Animation::AnimationChannel channel; - Animation::RotationKey rot; - rot.Quad = glm::angleAxis(glm::radians(mAngle), glm::vec3(0.f, 1.f, 0.f)); - rot.Time = 1.0f; - mTrack.AnimationChannels[0].RotationKeys.add(rot); - animator->addTrack(&mTrack); ui32 w, h; AppBase::getResolution(w, h); diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt index 0678003dc..b868656cb 100644 --- a/samples/CMakeLists.txt +++ b/samples/CMakeLists.txt @@ -3,29 +3,34 @@ INCLUDE_DIRECTORIES( ../ ) -SET ( 00_helloworld_src +SET (00_helloworld_src 00_HelloWorld/HelloWorld.cpp 00_HelloWorld/README.md ) -SET ( 01_modelloading_src +SET (01_modelloading_src 01_ModelLoading/ModelLoading.cpp 01_ModelLoading/README.md ) -SET ( 02_demo2d_src +SET (02_demo2d_src 02_Demo2D/Demo2D.cpp 02_Demo2D/README.md ) -SET ( 03_instancing_src +SET (03_instancing_src 03_Instancing/Instancing.cpp 03_Instancing/README.md ) -SET ( 04_terrain_src - 04_terrain/TerrainRendering.cpp - 04_terrain/README.md +SET (04_terrain_src + 04_terrain/TerrainRendering.cpp + 04_terrain/README.md +) + +SET (05_animation_src + 05_Animation/Animation.cpp + 05_Animation/README.md ) ADD_EXECUTABLE(helloworld @@ -36,6 +41,9 @@ ADD_EXECUTABLE(modelloading ${01_modelloading_src} ) +ADD_EXECUTABLE(demo2d + ${02_demo2d_src} +) ADD_EXECUTABLE(instancing ${03_instancing_src} @@ -45,8 +53,8 @@ ADD_EXECUTABLE(terrain ${04_terrain_src} ) -ADD_EXECUTABLE(demo2d - ${02_demo2d_src} +ADD_EXECUTABLE(animation + ${05_animation_src} ) link_directories( @@ -59,10 +67,12 @@ target_link_libraries(modelloading osre) target_link_libraries(demo2d osre) target_link_libraries(instancing osre) target_link_libraries(terrain osre) +target_link_libraries(animation osre) set_target_properties(helloworld PROPERTIES FOLDER Samples) set_target_properties(modelloading PROPERTIES FOLDER Samples) set_target_properties(demo2d PROPERTIES FOLDER Samples) set_target_properties(instancing PROPERTIES FOLDER Samples) set_target_properties(terrain PROPERTIES FOLDER Samples) +set_target_properties(animation PROPERTIES FOLDER Samples) diff --git a/src/Engine/RenderBackend/MaterialBuilder.cpp b/src/Engine/RenderBackend/MaterialBuilder.cpp index 2aa879e5b..2aa05c997 100644 --- a/src/Engine/RenderBackend/MaterialBuilder.cpp +++ b/src/Engine/RenderBackend/MaterialBuilder.cpp @@ -95,7 +95,7 @@ Material *MaterialBuilder::create2DMaterial() { shArray[static_cast(ShaderType::SH_FragmentShaderType)] = fragment_2d; mat->createShader(shArray); - // Setup shader attributes and variables + // Setup shader attributes and variables if (nullptr != mat->mShader) { mat->mShader->addVertexAttributes(RenderVert::getAttributes(), RenderVert::getNumAttributes()); addMaterialParameter(mat); @@ -154,8 +154,6 @@ Material *MaterialBuilder::createTextMaterial(const String &fontName) { " f_color = vec4(v_color0,1);\n" "}\n"; - - return mat; } diff --git a/src/Engine/RenderBackend/MaterialBuilder.h b/src/Engine/RenderBackend/MaterialBuilder.h index ac3cdc6b3..36a46b520 100644 --- a/src/Engine/RenderBackend/MaterialBuilder.h +++ b/src/Engine/RenderBackend/MaterialBuilder.h @@ -32,7 +32,7 @@ namespace RenderBackend { //------------------------------------------------------------------------------------------------- /// @ingroup Engine /// -/// @brief This class takes care of all default materials. +/// @brief This class takes care of all default material management tasks. //------------------------------------------------------------------------------------------------- class OSRE_EXPORT MaterialBuilder { public: @@ -71,6 +71,8 @@ class OSRE_EXPORT MaterialBuilder { /// @return The instance of the material. static RenderBackend::Material *createDebugRenderTextMaterial(); + /// @brief Will return the default 2d material. + /// @return The 2D material. static Material *create2DMaterial(); static Material *createTextMaterial(const String &fontName); diff --git a/src/Engine/RenderBackend/MeshBuilder.cpp b/src/Engine/RenderBackend/MeshBuilder.cpp index ea6e25acd..31e2007aa 100644 --- a/src/Engine/RenderBackend/MeshBuilder.cpp +++ b/src/Engine/RenderBackend/MeshBuilder.cpp @@ -184,58 +184,6 @@ MeshBuilder &MeshBuilder::allocQuads( VertexType type, BufferAccessType access ) return *this; } -/*MeshBuilder &MeshBuilder::allocUiQuad( const Rect2ui &dim, UiVertexCache &vc, RenderBackend::UiIndexCache &ic ) { - const f32 x = static_cast(dim.getX1()); - const f32 y = static_cast(dim.getY1()); - const f32 w = static_cast(dim.getWidth()); - const f32 h = static_cast(dim.getHeight()); - - // setup triangle vertices - static const ui32 NumVert = 4; - glm::vec3 col[NumVert] = {}; - col[ 0 ] = glm::vec3( 1, 0, 0 ); - col[ 1 ] = glm::vec3( 0, 1, 0 ); - col[ 2 ] = glm::vec3( 0, 0, 1 ); - col[ 3 ] = glm::vec3( 1, 0, 0 ); - - glm::vec3 pos[NumVert] = {}; - pos[ 0 ] = glm::vec3( x, y, 0 ); - pos[ 1 ] = glm::vec3( x, y+h, 0 ); - pos[ 2 ] = glm::vec3( x+w, y, 0 ); - pos[ 3 ] = glm::vec3( x+h, y+h, 0 ); - - glm::vec2 tex0[NumVert] = {}; - tex0[ 0 ] = glm::vec2( 0, 0 ); - tex0[ 1 ] = glm::vec2( 0, 1 ); - tex0[ 2 ] = glm::vec2( 1, 0 ); - tex0[ 3 ] = glm::vec2( 1, 1 ); - - for (ui32 i = 0; i < 4; ++i) { - RenderVert v; - v.position = pos[ i ]; - v.color0 = col[ i ]; - v.tex0 = tex0[ i ]; - vc.add( v ); - } - - // setup triangle indices - static const ui32 NumIndices = 6; - ui16 indices[NumIndices] = {}; - indices[ 0 ] = 0; - indices[ 1 ] = 2; - indices[ 2 ] = 1; - - indices[ 3 ] = 1; - indices[ 4 ] = 2; - indices[ 5 ] = 3; - - for (ui32 i = 0; i < 4; ++i) { - ic.add( indices[ i ] ); - } - - return *this; -}*/ - MeshBuilder &MeshBuilder::createCube(VertexType type, f32 w, f32 h, f32 d, BufferAccessType access ) { clear(); mActiveMesh = new Mesh("cube", type, IndexType::UnsignedShort); diff --git a/src/Engine/RenderBackend/MeshBuilder.h b/src/Engine/RenderBackend/MeshBuilder.h index 57a7ba3e5..2772572fd 100644 --- a/src/Engine/RenderBackend/MeshBuilder.h +++ b/src/Engine/RenderBackend/MeshBuilder.h @@ -60,13 +60,6 @@ class OSRE_EXPORT MeshBuilder { /// @param access [in] The data access type. /// @return The created mesh. MeshBuilder& allocQuads(RenderBackend::VertexType type, RenderBackend::BufferAccessType access ); - - /// @brief - /// @param dim - /// @param vc - /// @param ic - /// @return - //MeshBuilder& allocUiQuad(const Rect2ui &dim, RenderBackend::UiVertexCache &vc, RenderBackend::UiIndexCache &ic ); /// @brief /// @param type diff --git a/src/Engine/RenderBackend/Pipeline.h b/src/Engine/RenderBackend/Pipeline.h index d4cbebb19..4a88f12d1 100644 --- a/src/Engine/RenderBackend/Pipeline.h +++ b/src/Engine/RenderBackend/Pipeline.h @@ -37,6 +37,7 @@ class RenderBackendService; using cppcore::TArray; +/// @brief The pipeline access namespace DefaultPipelines { OSRE_EXPORT const c8 *get3DPipelineDefault(); OSRE_EXPORT const c8 *get2DPipelineDefault(); diff --git a/src/Engine/RenderBackend/RenderStates.h b/src/Engine/RenderBackend/RenderStates.h index 52256c3a6..c0c7a317d 100644 --- a/src/Engine/RenderBackend/RenderStates.h +++ b/src/Engine/RenderBackend/RenderStates.h @@ -41,7 +41,7 @@ struct ClearState { ui32 m_state; /// @brief The default class constructor. - ClearState(); + ClearState() noexcept; /// @brief The class constructor with the requested clear states. /// @param states [in] The requested clear states. @@ -52,7 +52,7 @@ struct ClearState { bool operator != (const ClearState &rhs) const; }; -inline ClearState::ClearState() : +inline ClearState::ClearState() noexcept: m_state(0) { // empty } @@ -72,16 +72,17 @@ inline bool ClearState::operator!=(const ClearState &rhs) const { /// @brief struct DepthState { - /// @brief + /// @brief The enum to descrive the type of depth state. enum class DepthStateType { + Invalid = -1, Enabled = 0, Disabled, - NumDepthStates, - InvalidDepthState + Count }; - /// @brief + /// @brief The enum to describe the type of requested depth function. enum class DepthFuncType { + Invalid = -1, Always = 0, Never, Less, @@ -90,15 +91,14 @@ struct DepthState { Greater, NotEqual, GEqual, - NumDepthFuncs, - InvalidDepthFunc + Count }; DepthStateType m_type; DepthFuncType m_func; /// @brief The default class constructor. - DepthState(); + DepthState() noexcept; /// @brief The class constructor with all parameters. /// @param stateType [in] The state type enum. @@ -112,7 +112,7 @@ struct DepthState { bool operator!=(const DepthState &rhs) const; }; -inline DepthState::DepthState() : +inline DepthState::DepthState() noexcept: m_type(DepthStateType::Enabled), m_func(DepthFuncType::Always) { // empty @@ -165,7 +165,8 @@ struct StencilState { public: /// @brief enum class StencilFunc { - Never, + Invalid = -1, + Never = 0, Always, Equal, NotEqual, @@ -173,23 +174,25 @@ struct StencilState { LEqual, GEqual, Greater, - Off + Off, + Count }; /// @brief enum class StencilOp { - Keep, + Invalid = -1, + Keep = 0, Zero, Replace, Incr, IncrWrap, Decr, DecrWrap, - Invert + Invert, + Count }; StencilState(); - ~StencilState(); void setStencilFunc(StencilFunc, i32 ref, c8 mask); StencilFunc getStencilFunc() const; i32 getStencilFuncRef() const; @@ -215,10 +218,6 @@ inline StencilState::StencilState() : // empty } -inline StencilState::~StencilState() { - // empty -} - inline void StencilState::setStencilFunc(StencilFunc func, i32 ref, c8 mask) { m_stencilFunc = func; m_stencilFuncRef = ref; @@ -266,13 +265,15 @@ inline bool StencilState::operator!=(const StencilState &rhs) const { struct BlendState { /// enum class BlendFunc { - FuncNone, + Invalid = -1, + FuncNone = 0, FuncAdd, FuncSubstract, ReverseSubstract, Min, Max, - Off + Off, + Count }; BlendFunc m_blendFunc; diff --git a/src/Engine/RenderBackend/Shader.cpp b/src/Engine/RenderBackend/Shader.cpp index b0ca70a41..8e86195a3 100644 --- a/src/Engine/RenderBackend/Shader.cpp +++ b/src/Engine/RenderBackend/Shader.cpp @@ -32,7 +32,7 @@ using namespace ::OSRE::IO; Shader::Shader() : mUniformBuffer(), mVertexAttributes(), mSrc{}, mCompileState{} { - ::memset(mCompileState, 0, sizeof(CompileState) * MaxCompileState); + ::memset(mCompileState, 0, sizeof(CompileState) * Count); } void Shader::addVertexAttribute(const String &name) { diff --git a/src/Engine/RenderBackend/Shader.h b/src/Engine/RenderBackend/Shader.h index 2b609aa23..750b35cbd 100644 --- a/src/Engine/RenderBackend/Shader.h +++ b/src/Engine/RenderBackend/Shader.h @@ -120,16 +120,17 @@ class OSRE_EXPORT Shader { private: enum CompileState { + Invalid = -1, Updated = 0, Compiled, Error, - MaxCompileState + Count }; StringArray mUniformBuffer; StringArray mVertexAttributes; String mSrc[MaxShaderTypes]; - CompileState mCompileState[MaxCompileState]; + CompileState mCompileState[Count]; }; inline size_t Shader::getNumVertexAttributes() const {