Skip to content

Commit

Permalink
Some cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
kullingk committed Jan 8, 2025
1 parent 1aaf62e commit 94f3884
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 110 deletions.
15 changes: 1 addition & 14 deletions samples/00_HelloWorld/HelloWorld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,14 @@ 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.
HelloWorldApp(int argc, char *argv[]) :
AppBase(argc, (const char **)argv),
mTransformMatrix(),
mEntity(nullptr),
mKeyboardTransCtrl(nullptr),
mAngle(1.0f) {
mKeyboardTransCtrl(nullptr) {
// empty
}

Expand All @@ -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);
Expand Down
28 changes: 19 additions & 9 deletions samples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -36,6 +41,9 @@ ADD_EXECUTABLE(modelloading
${01_modelloading_src}
)

ADD_EXECUTABLE(demo2d
${02_demo2d_src}
)

ADD_EXECUTABLE(instancing
${03_instancing_src}
Expand All @@ -45,8 +53,8 @@ ADD_EXECUTABLE(terrain
${04_terrain_src}
)

ADD_EXECUTABLE(demo2d
${02_demo2d_src}
ADD_EXECUTABLE(animation
${05_animation_src}
)

link_directories(
Expand All @@ -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)

4 changes: 1 addition & 3 deletions src/Engine/RenderBackend/MaterialBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Material *MaterialBuilder::create2DMaterial() {
shArray[static_cast<ui32>(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);
Expand Down Expand Up @@ -154,8 +154,6 @@ Material *MaterialBuilder::createTextMaterial(const String &fontName) {
" f_color = vec4(v_color0,1);\n"
"}\n";



return mat;
}

Expand Down
4 changes: 3 additions & 1 deletion src/Engine/RenderBackend/MaterialBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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);

Expand Down
52 changes: 0 additions & 52 deletions src/Engine/RenderBackend/MeshBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<f32>(dim.getX1());
const f32 y = static_cast<f32>(dim.getY1());
const f32 w = static_cast<f32>(dim.getWidth());
const f32 h = static_cast<f32>(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);
Expand Down
7 changes: 0 additions & 7 deletions src/Engine/RenderBackend/MeshBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/Engine/RenderBackend/Pipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
43 changes: 22 additions & 21 deletions src/Engine/RenderBackend/RenderStates.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -52,7 +52,7 @@ struct ClearState {
bool operator != (const ClearState &rhs) const;
};

inline ClearState::ClearState() :
inline ClearState::ClearState() noexcept:
m_state(0) {
// empty
}
Expand All @@ -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,
Expand All @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -165,31 +165,34 @@ struct StencilState {
public:
/// @brief
enum class StencilFunc {
Never,
Invalid = -1,
Never = 0,
Always,
Equal,
NotEqual,
Less,
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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/Engine/RenderBackend/Shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 3 additions & 2 deletions src/Engine/RenderBackend/Shader.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 94f3884

Please sign in to comment.