diff --git a/README.md b/README.md index 6350ce36c..e3761dad4 100644 --- a/README.md +++ b/README.md @@ -166,7 +166,3 @@ OSRE_MAIN(QuickStartdApp) ![ESRE-Ed](assets/Images/sponza.png) The engine provdes an 3D-Editor called OSRE-Ed. It is still experimental: - -# Get involved -If you want to contribute just use the github project page or reach us via Gitter: -[![Join the chat at https://gitter.im/kimkulling/osre](https://badges.gitter.im/kimkulling/osre.svg)](https://gitter.im/kimkulling/osre?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) diff --git a/samples/00_HelloWorld/HelloWorld.cpp b/samples/00_HelloWorld/HelloWorld.cpp index 5e9ba6165..2b45a80f5 100644 --- a/samples/00_HelloWorld/HelloWorld.cpp +++ b/samples/00_HelloWorld/HelloWorld.cpp @@ -105,7 +105,9 @@ class HelloWorldApp : public App::AppBase { void onUpdate() override { Platform::Key key = AppBase::getKeyboardEventListener()->getLastKey(); - mKeyboardTransCtrl->update(mKeyboardTransCtrl->getKeyBinding(key)); + if (key != Platform::KEY_UNKNOWN) { + mKeyboardTransCtrl->update(mKeyboardTransCtrl->getKeyBinding(key)); + } RenderBackendService *rbSrv = ServiceProvider::getService(ServiceType::RenderService); diff --git a/samples/01_ModelLoading/ModelLoading.cpp b/samples/01_ModelLoading/ModelLoading.cpp index 60f36b4e0..fbc8ba049 100644 --- a/samples/01_ModelLoading/ModelLoading.cpp +++ b/samples/01_ModelLoading/ModelLoading.cpp @@ -185,7 +185,7 @@ class ModelLoadingApp : public App::AppBase { int main(int argc, char *argv[]) { ModelLoadingApp myApp(argc, argv); - if (!myApp.initWindow(10, 10, 1024, 768, "ModelLoader sample! Press o to import an Asset", false, false, App::RenderBackendType::OpenGLRenderBackend)) { + if (!myApp.initWindow(10, 10, 1024, 768, "ModelLoader sample! Press o to import an Asset", WindowMode::Windowed, WindowType::Root, App::RenderBackendType::OpenGLRenderBackend)) { return 1; } diff --git a/samples/03_Instancing/Instancing.cpp b/samples/03_Instancing/Instancing.cpp index 9d0e1fbed..fb1f6bc57 100644 --- a/samples/03_Instancing/Instancing.cpp +++ b/samples/03_Instancing/Instancing.cpp @@ -116,7 +116,7 @@ class InstancingApp : public App::AppBase { int main(int argc, char *argv[]) { InstancingApp myApp(argc, argv); - if (!myApp.initWindow(10, 10, 1024, 768, "Instancing-Sample", false, false, RenderBackendType::OpenGLRenderBackend)) { + if (!myApp.initWindow(10, 10, 1024, 768, "Instancing-Sample", WindowMode::Windowed, WindowType::Root, RenderBackendType::OpenGLRenderBackend)) { return 1; } diff --git a/samples/04_terrain/TerrainRendering.cpp b/samples/04_terrain/TerrainRendering.cpp index df0e5472c..b6e8b86e2 100644 --- a/samples/04_terrain/TerrainRendering.cpp +++ b/samples/04_terrain/TerrainRendering.cpp @@ -205,7 +205,7 @@ class TerrainRenderingApp : public App::AppBase { int main(int argc, char *argv[]) { TerrainRenderingApp myApp(argc, argv); - if (!myApp.initWindow(10, 10, 1024, 768, "Instancing-Sample", false, false, RenderBackendType::OpenGLRenderBackend)) { + if (!myApp.initWindow(10, 10, 1024, 768, "Instancing-Sample", WindowMode::Windowed, WindowType::Root, RenderBackendType::OpenGLRenderBackend)) { return 1; } @@ -218,4 +218,3 @@ int main(int argc, char *argv[]) { return 0; } - diff --git a/src/Editor/src/OsreEdApp.cpp b/src/Editor/src/OsreEdApp.cpp index 5287c5761..e21245480 100644 --- a/src/Editor/src/OsreEdApp.cpp +++ b/src/Editor/src/OsreEdApp.cpp @@ -3,7 +3,7 @@ #include "OSREEdApp.h" #include "ProgressReporter.h" #include "Actions/ImportAction.h" - +#include "Platform/PlatformOperations.h" #include "RenderBackend/MeshBuilder.h" #include "App/Stage.h" #include "App/TransformController.h" @@ -154,8 +154,16 @@ bool OsreEdApp::onCreate() { } void OsreEdApp::onUpdate() { + if (AppBase::isKeyPressed(Platform::KEY_O) || AppBase::isKeyPressed(Platform::KEY_o)) { + IO::Uri modelLoc; + Platform::PlatformOperations::getFileOpenDialog("Choose asset for import", "*", modelLoc); + if (modelLoc.isValid()) { + loadAsset(modelLoc); + } + } + Platform::Key key = AppBase::getKeyboardEventListener()->getLastKey(); - if (mKeyboardTransCtrl != nullptr) { + if (key != Platform::KEY_UNKNOWN && mKeyboardTransCtrl != nullptr) { mKeyboardTransCtrl->update(mKeyboardTransCtrl->getKeyBinding(key)); } diff --git a/src/Editor/src/main.cpp b/src/Editor/src/main.cpp index e3b5de1da..8d0959e90 100644 --- a/src/Editor/src/main.cpp +++ b/src/Editor/src/main.cpp @@ -34,7 +34,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include "App/Entity.h" #include "Platform/AbstractWindow.h" #include "Common/glm_common.h" -#include "Platform/PlatformOperations.h" +//#include "Platform/PlatformOperations.h" #include "Platform/PlatformInterface.h" #include "Platform/win32/Win32Window.h" @@ -48,7 +48,6 @@ using namespace OSRE::Editor; static constexpr c8 Tag[] = "HelloWorldApp"; - int main(int argc, char *argv[]) { std::cout << "Editor version 0.1\n"; @@ -57,17 +56,12 @@ int main(int argc, char *argv[]) { return -1; } - IO::Uri modelLoc; - PlatformOperations::getFileOpenDialog("Select asset for import", "*", modelLoc); - if (modelLoc.isValid()) { - osreApp.loadAsset(modelLoc); - } // Main loop bool done = false; while (!done) { static int counter = 0; - osreApp.handleEvents(); + done = osreApp.handleEvents(); App::Stage *stage = osreApp.getStage(); if (stage != nullptr) { World *world = stage->getActiveWorld(0); diff --git a/src/Engine/App/AppBase.cpp b/src/Engine/App/AppBase.cpp index 5c824cb63..885a861a4 100644 --- a/src/Engine/App/AppBase.cpp +++ b/src/Engine/App/AppBase.cpp @@ -82,7 +82,7 @@ AppBase::~AppBase() { delete mSettings; } -bool AppBase::initWindow(ui32 x, ui32 y, ui32 width, ui32 height, const String &title, bool fullscreen, bool childWindow, +bool AppBase::initWindow(ui32 x, ui32 y, ui32 width, ui32 height, const String &title, WindowMode mode, WindowType type, RenderBackendType renderer) { osre_assert(nullptr != mSettings); @@ -90,8 +90,8 @@ bool AppBase::initWindow(ui32 x, ui32 y, ui32 width, ui32 height, const String & mSettings->setInt(Settings::WinY, y); mSettings->setInt(Settings::WinWidth, width); mSettings->setInt(Settings::WinHeight, height); - mSettings->setBool(Settings::FullScreen, fullscreen); - mSettings->setBool(Settings::ChildWindow, childWindow); + mSettings->setBool(Settings::FullScreen, mode == WindowMode::Fullscreen); + mSettings->setBool(Settings::ChildWindow, type == WindowType::Child); mSettings->setString(Settings::WindowsTitle, title); if (renderer == RenderBackendType::OpenGLRenderBackend) { mSettings->setString(Settings::RenderAPI, "opengl"); diff --git a/src/Engine/App/AppBase.h b/src/Engine/App/AppBase.h index 00f1fcb82..36275a498 100644 --- a/src/Engine/App/AppBase.h +++ b/src/Engine/App/AppBase.h @@ -103,6 +103,20 @@ class OSRE_EXPORT KeyboardEventListener : public Platform::OSEventListener { char mKeymap[Platform::KEY_LAST]; }; +enum class WindowMode { + Invalid, + Windowed, + Fullscreen, + Count +}; + +enum class WindowType { + Invalid, + Root, + Child, + Count +}; + //------------------------------------------------------------------------------------------------- /// @ingroup Engine /// @@ -143,7 +157,7 @@ class OSRE_EXPORT AppBase { /// @param[in] renderer The requested render mode. /// @return true, if the window was generated. virtual bool initWindow( ui32 x, ui32 y, ui32 width, ui32 height, const String &title, - bool fullscreen, bool childWindow, RenderBackendType renderer); + WindowMode mode, WindowType type, RenderBackendType renderer); /// @brief Creates the application. /// @param settings [in] The user-defined settings. diff --git a/src/Engine/App/Component.cpp b/src/Engine/App/Component.cpp index 92448a927..7530638d6 100644 --- a/src/Engine/App/Component.cpp +++ b/src/Engine/App/Component.cpp @@ -70,7 +70,7 @@ void RenderComponent::addStaticMeshArray(const RenderBackend::MeshArray &array) } } -size_t RenderComponent::getNumGeometry() const { +size_t RenderComponent::getNumMeshes() const { return m_newGeo.size(); } diff --git a/src/Engine/App/Component.h b/src/Engine/App/Component.h index c0af614df..4353ea9ad 100644 --- a/src/Engine/App/Component.h +++ b/src/Engine/App/Component.h @@ -124,24 +124,24 @@ inline size_t Component::getIndex( ComponentType type ) { //------------------------------------------------------------------------------------------------- class OSRE_EXPORT RenderComponent : public Component { public: - /// @brief - /// @param owner + /// @brief The class constructor. + /// @param owner The owning entity. RenderComponent(Entity *owner); - /// @brief + /// @brief The class destructor. ~RenderComponent() override = default; - /// @brief - /// @return - size_t getNumGeometry() const; + /// @brief Returns the number of meshes + /// @return The number of stored meshes. + size_t getNumMeshes() const; - /// @brief - /// @param idx - /// @return + /// @brief Returns the mesh at a given index. + /// @param[in] idx The requested index. + /// @return The mesh os a nullptr if the index in invalid. RenderBackend::Mesh *getMeshAt(size_t idx) const; - /// @brief - /// @param array + /// @brief Returns the mesh array. + /// @param[inout] array void getMeshArray(RenderBackend::MeshArray &array); /// @brief diff --git a/src/Engine/App/Project.cpp b/src/Engine/App/Project.cpp index 6c6202e27..52dc6ce9e 100644 --- a/src/Engine/App/Project.cpp +++ b/src/Engine/App/Project.cpp @@ -212,7 +212,7 @@ static void storeEntities(const cppcore::TArray &entities, WorldData & } auto *rc = (RenderComponent *)entity->getComponent(ComponentType::RenderComponentType); - numMeshes += rc->getNumGeometry(); + numMeshes += rc->getNumMeshes(); } MeshData *md = new MeshData[numMeshes]; diff --git a/src/Engine/App/World.cpp b/src/Engine/App/World.cpp index 3d3a16690..ede6849c2 100644 --- a/src/Engine/App/World.cpp +++ b/src/Engine/App/World.cpp @@ -178,7 +178,7 @@ void World::updateBoundingTrees() { } MeshProcessor processor; RenderComponent *rc = (RenderComponent *)entity->getComponent(ComponentType::RenderComponentType); - for (ui32 j = 0; j < rc->getNumGeometry(); ++j) { + for (ui32 j = 0; j < rc->getNumMeshes(); ++j) { processor.addMesh(rc->getMeshAt(j)); } if (processor.execute()) { diff --git a/src/Engine/RenderBackend/OGLRenderer/OGLCommon.h b/src/Engine/RenderBackend/OGLRenderer/OGLCommon.h index 635f35a16..db22dc5d9 100644 --- a/src/Engine/RenderBackend/OGLRenderer/OGLCommon.h +++ b/src/Engine/RenderBackend/OGLRenderer/OGLCommon.h @@ -48,9 +48,9 @@ void checkOGLErrorState(const c8 *file, ui32 line); /// @brief This macro will check the OpenGL-error state and write a message into the log. //------------------------------------------------------------------------------------------------- #ifdef _DEBUG -#define CHECKOGLERRORSTATE() checkOGLErrorState(__FILE__, __LINE__) +# define CHECKOGLERRORSTATE() checkOGLErrorState(__FILE__, __LINE__) #else -#define CHECKOGLERRORSTATE() +# define CHECKOGLERRORSTATE() #endif // _DEBUG static constexpr GLuint OGLNotSetId = 999999; ///< Indicates a not inited opengl id. @@ -67,7 +67,7 @@ struct OGLBuffer { /// @brief The default class constructor. OGLBuffer() : m_handle(0), m_type(BufferType::InvalidType), m_oglId(OGLNotSetId), m_geoId(0), m_size(0){} - + /// @brief The class destructor, default implementation. ~OGLBuffer() = default; }; diff --git a/src/Engine/RenderBackend/OGLRenderer/OGLRenderBackend.h b/src/Engine/RenderBackend/OGLRenderer/OGLRenderBackend.h index b1a9d1bc8..e84d43f4a 100644 --- a/src/Engine/RenderBackend/OGLRenderer/OGLRenderBackend.h +++ b/src/Engine/RenderBackend/OGLRenderer/OGLRenderBackend.h @@ -80,20 +80,32 @@ class OGLRenderBackend { public: using VertAttribArray = cppcore::TArray; - /// The default class constructor. + /// @brief The default class constructor. OGLRenderBackend(); - /// The class destructor. + + /// @brief The class destructor. ~OGLRenderBackend(); - /// + + /// @brief Will enumerate the GPU capabilities. void enumerateGPUCaps(); - /// - void setClearColor(const Color4 &clearColor); - /// Will set the requested global matrix for the frame. + + /// @brief Will set the clear color. + /// @param[in] clearColor The new clear color. + void setClearColor(const Color4 &clearColor); + + /// @brief Will set the requested global matrix for the frame. void setMatrix(MatrixType type, const glm::mat4 &mat); - /// All matrix values will be applied to the current frame. + + /// @brief All matrix values will be applied to the current frame. void applyMatrix(); + + /// @brief const glm::mat4 &getMatrix(MatrixType type) const; + + /// @brief bool create(Platform::AbstractOGLRenderContext *renderCtx); + + /// @brief bool destroy(); void setTimer(Platform::AbstractTimer *timer); void setRenderContext(Platform::AbstractOGLRenderContext *renderCtx); diff --git a/src/Engine/RenderBackend/OGLRenderer/OGLRenderCommands.h b/src/Engine/RenderBackend/OGLRenderer/OGLRenderCommands.h index 6a5a86d71..28077fabb 100644 --- a/src/Engine/RenderBackend/OGLRenderer/OGLRenderCommands.h +++ b/src/Engine/RenderBackend/OGLRenderer/OGLRenderCommands.h @@ -54,14 +54,27 @@ struct OGLParameter; struct UniformVar; struct SetMaterialStageCmdData; +/// @brief Setup for screenshots bool makeScreenShot(const c8 *filename, ui32 w, ui32 h); + +/// @brief Setup for textures. bool setupTextures(Material* mat, OGLRenderBackend* rb, OGLTextureArray& textures); + +/// @brief Setup for materials. SetMaterialStageCmdData* setupMaterial(Material* material, OGLRenderBackend* rb, OGLRenderEventHandler* eh); + +/// @brief Setup for shader parameters. void setupParameter(UniformVar* param, OGLRenderBackend* rb, OGLRenderEventHandler* ev); + +/// @brief Setup for opengl buffers. OGLVertexArray* setupBuffers(Mesh* mesh, OGLRenderBackend* rb, OGLShader* oglShader); + +/// @brief Setup for render calls. void setupPrimDrawCmd(const char* id, bool useLocalMatrix, const glm::mat4& model, const cppcore::TArray& primGroups, OGLRenderBackend* rb, OGLRenderEventHandler* eh, OGLVertexArray* va); + +/// @brief Setup for instanced render calls. void setupInstancedDrawCmd(const char* id, const cppcore::TArray& ids, OGLRenderBackend* rb, OGLRenderEventHandler* eh, OGLVertexArray* va, size_t numInstances); diff --git a/src/Engine/RenderBackend/OGLRenderer/OGLRenderEventHandler.h b/src/Engine/RenderBackend/OGLRenderer/OGLRenderEventHandler.h index 5ce4c09b2..8ce57dc34 100644 --- a/src/Engine/RenderBackend/OGLRenderer/OGLRenderEventHandler.h +++ b/src/Engine/RenderBackend/OGLRenderer/OGLRenderEventHandler.h @@ -65,7 +65,7 @@ struct OGLBuffer; /// @brief This class is used to handle all incoming events for the render back-end, which /// implements the OpenGL renderer. //------------------------------------------------------------------------------------------------- -class OGLRenderEventHandler : public Common::AbstractEventHandler { +class OGLRenderEventHandler final : public Common::AbstractEventHandler { public: /// @brief The default class constructor. OGLRenderEventHandler(); @@ -142,22 +142,22 @@ class OGLRenderEventHandler : public Common::AbstractEventHandler { /// @param[in] eventData The event state data /// @return true if successful, false if not. bool onRenderFrame( const Common::EventData *eventData ); - + /// @brief Callback to init the passes. /// @param[in] eventData The event state data /// @return true if successful, false if not. bool onInitRenderPasses(const Common::EventData *eventData); - + /// @brief Callback to commit the next frame. /// @param[in] eventData The event state data /// @return true if successful, false if not. bool onCommitNexFrame( const Common::EventData *eventData ); - + /// @brief Callback for dealing with a shutdown request. /// @param[in] eventData The event state data /// @return true if successful, false if not. bool onShutdownRequest( const Common::EventData *eventData ); - + /// @brief Callback for dealing with resize events. /// @param[in] eventData The event state data /// @return true if successful, false if not. diff --git a/src/Engine/RenderBackend/OGLRenderer/OGLShader.cpp b/src/Engine/RenderBackend/OGLRenderer/OGLShader.cpp index 372fcc49a..3d4cbb0d9 100644 --- a/src/Engine/RenderBackend/OGLRenderer/OGLShader.cpp +++ b/src/Engine/RenderBackend/OGLRenderer/OGLShader.cpp @@ -29,38 +29,40 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. namespace OSRE { namespace RenderBackend { +using namespace OSRE::Common; + static constexpr c8 Tag[] = "OGLShader"; OGLShader::OGLShader(const String &name) : Object(name), - m_attribParams(), - m_uniformParams(), - m_shaderprog(0), - m_numShader(0), - m_attributeMap(), - m_uniformLocationMap(), - m_isCompiledAndLinked(false), - m_isInUse(false) { - ::memset(m_shaders, 0, sizeof(unsigned int) * 3); + mAttribParams(), + mUniformParams(), + mShaderprog(0), + mNumShader(0), + mAttributeMap(), + mUniformLocationMap(), + mIsCompiledAndLinked(false), + mIsInUse(false) { + ::memset(mShaders, 0, sizeof(unsigned int) * MaxShaderTypes); } OGLShader::~OGLShader() { - if (m_isInUse) { + if (mIsInUse) { osre_warn(Tag, "Destroying shader which is still in use."); } - cppcore::ContainerClear(m_attribParams); - cppcore::ContainerClear(m_uniformParams); + cppcore::ContainerClear(mAttribParams); + cppcore::ContainerClear(mUniformParams); for (ui32 i = 0; i < static_cast(ShaderType::Count); ++i) { - if (0 != m_shaders[i]) { - glDeleteShader(m_shaders[i]); - m_shaders[i] = 0; + if (0 != mShaders[i]) { + glDeleteShader(mShaders[i]); + mShaders[i] = 0; } } - if (0 != m_shaderprog) { - glDeleteProgram(m_shaderprog); - m_shaderprog = 0; + if (0 != mShaderprog) { + glDeleteProgram(mShaderprog); + mShaderprog = 0; } } @@ -69,7 +71,7 @@ bool OGLShader::loadFromSource(ShaderType type, const String &src) { return false; } GLuint shader = glCreateShader(OGLEnum::getOGLShaderType(type)); - m_shaders[static_cast(type)] = shader; + mShaders[static_cast(type)] = shader; const char *tmp = src.c_str(); glShaderSource(shader, 1, &tmp, nullptr); @@ -87,11 +89,9 @@ bool OGLShader::loadFromStream(ShaderType type, IO::Stream &stream) { return true; } - c8 *data = new c8[filesize]; - stream.read(data, filesize); - - const bool retCode = loadFromSource(type, String(data)); - delete[] data; + MemoryBuffer buffer(filesize); + stream.read(&buffer[0], filesize); + const bool retCode = loadFromSource(type, String(&buffer[0])); return retCode; } @@ -102,75 +102,83 @@ bool OGLShader::createAndLink() { return true; } - m_shaderprog = glCreateProgram(); - if (0 == m_shaderprog) { + mShaderprog = glCreateProgram(); + if (0 == mShaderprog) { osre_error(Tag, "Error while creating shader program."); return false; } - if (0 != m_shaders[static_cast(ShaderType::SH_VertexShaderType)]) { - glAttachShader(m_shaderprog, m_shaders[static_cast(ShaderType::SH_VertexShaderType)]); + if (0 != mShaders[static_cast(ShaderType::SH_VertexShaderType)]) { + glAttachShader(mShaderprog, mShaders[static_cast(ShaderType::SH_VertexShaderType)]); } - if (0 != m_shaders[static_cast(ShaderType::SH_FragmentShaderType)]) { - glAttachShader(m_shaderprog, m_shaders[static_cast(ShaderType::SH_FragmentShaderType)]); + if (0 != mShaders[static_cast(ShaderType::SH_FragmentShaderType)]) { + glAttachShader(mShaderprog, mShaders[static_cast(ShaderType::SH_FragmentShaderType)]); } - if (0 != m_shaders[static_cast(ShaderType::SH_GeometryShaderType)]) { - glAttachShader(m_shaderprog, m_shaders[static_cast(ShaderType::SH_GeometryShaderType)]); + if (0 != mShaders[static_cast(ShaderType::SH_GeometryShaderType)]) { + glAttachShader(mShaderprog, mShaders[static_cast(ShaderType::SH_GeometryShaderType)]); } GLint status(0); - glLinkProgram(m_shaderprog); - glGetProgramiv(m_shaderprog, GL_LINK_STATUS, &status); + glLinkProgram(mShaderprog); + glGetProgramiv(mShaderprog, GL_LINK_STATUS, &status); if (status == GL_FALSE) { - logCompileOrLinkError(m_shaderprog); - m_isCompiledAndLinked = false; + logCompileOrLinkError(mShaderprog); + mIsCompiledAndLinked = false; return false; } getActiveAttributeList(); getActiveUniformList(); - m_isCompiledAndLinked = true; + mIsCompiledAndLinked = true; - return m_isCompiledAndLinked; + return mIsCompiledAndLinked; } void OGLShader::use() { - m_isInUse = true; - glUseProgram(m_shaderprog); + if (mIsInUse) { + return; + } + + mIsInUse = true; + glUseProgram(mShaderprog); } void OGLShader::unuse() { - m_isInUse = false; + if (!mIsInUse) { + return; + } + + mIsInUse = false; glUseProgram(0); } bool OGLShader::hasAttribute(const String &attribute) { - if (0 == m_shaderprog) { + if (mShaderprog == 0) { return false; } - const GLint location = glGetAttribLocation(m_shaderprog, attribute.c_str()); + const GLint location = glGetAttribLocation(mShaderprog, attribute.c_str()); return InvalidLocationId != location; } void OGLShader::addAttribute(const String &attribute) { - const GLint location = glGetAttribLocation(m_shaderprog, attribute.c_str()); - m_attributeMap[attribute] = location; + const GLint location = glGetAttribLocation(mShaderprog, attribute.c_str()); + mAttributeMap[attribute] = location; if (InvalidLocationId == location) { osre_debug(Tag, "Cannot find attribute " + attribute + " in shader."); } } bool OGLShader::hasUniform(const String &uniform) { - if (0 == m_shaderprog) { + if (0 == mShaderprog) { return false; } - const GLint location = glGetUniformLocation(m_shaderprog, uniform.c_str()); + const GLint location = glGetUniformLocation(mShaderprog, uniform.c_str()); return InvalidLocationId != location; } void OGLShader::addUniform(const String &uniform) { - const GLint location = glGetUniformLocation(m_shaderprog, uniform.c_str()); - m_uniformLocationMap[uniform] = location; + const GLint location = glGetUniformLocation(mShaderprog, uniform.c_str()); + mUniformLocationMap[uniform] = location; if (InvalidLocationId == location) { osre_debug(Tag, "Cannot find uniform variable " + uniform + " in shader."); } @@ -188,7 +196,7 @@ static i32 getActiveParam(ui32 progId, GLenum type) { } void OGLShader::getActiveAttributeList() { - const i32 numAtttibs(getActiveParam(m_shaderprog, GL_ACTIVE_ATTRIBUTES)); + const i32 numAtttibs(getActiveParam(mShaderprog, GL_ACTIVE_ATTRIBUTES)); if (numAtttibs < 1) { return; } @@ -197,27 +205,27 @@ void OGLShader::getActiveAttributeList() { GLint actual_length(0), size(0); GLenum type; c8 name[MaxLen]; - glGetActiveAttrib(m_shaderprog, i, MaxLen, &actual_length, &size, &type, name); + glGetActiveAttrib(mShaderprog, i, MaxLen, &actual_length, &size, &type, name); if (size > 1) { for (i32 attribIdx = 0; attribIdx < size; attribIdx++) { ActiveParameter *attribParam = new ActiveParameter; std::stringstream stream; stream << name << attribIdx; strncpy(attribParam->m_name, stream.str().c_str(), stream.str().size()); - attribParam->m_location = glGetAttribLocation(m_shaderprog, attribParam->m_name); - m_attribParams.add(attribParam); + attribParam->m_location = glGetAttribLocation(mShaderprog, attribParam->m_name); + mAttribParams.add(attribParam); } } else { ActiveParameter *attribParam = new ActiveParameter; strncpy(attribParam->m_name, name, strlen(name)); - attribParam->m_location = glGetAttribLocation(m_shaderprog, attribParam->m_name); - m_attribParams.add(attribParam); + attribParam->m_location = glGetAttribLocation(mShaderprog, attribParam->m_name); + mAttribParams.add(attribParam); } } } void OGLShader::getActiveUniformList() { - const i32 numUniforms(getActiveParam(m_shaderprog, GL_ACTIVE_UNIFORMS)); + const i32 numUniforms(getActiveParam(mShaderprog, GL_ACTIVE_UNIFORMS)); if (numUniforms < 1) { return; } @@ -227,31 +235,31 @@ void OGLShader::getActiveUniformList() { GLenum type; c8 name[MaxLen]; ::memset(name, '\0', sizeof(c8) * MaxLen); - glGetActiveUniform(m_shaderprog, i, MaxLen, &actual_length, &size, &type, name); + glGetActiveUniform(mShaderprog, i, MaxLen, &actual_length, &size, &type, name); ActiveParameter *attribParam = new ActiveParameter; strncpy(attribParam->m_name, name, strlen(name)); - attribParam->m_location = glGetUniformLocation(m_shaderprog, name); - m_attribParams.add(attribParam); + attribParam->m_location = glGetUniformLocation(mShaderprog, name); + mAttribParams.add(attribParam); } } void OGLShader::logCompileOrLinkError(ui32 shaderprog) { - GLint infoLogLength(0); + GLint infoLogLength{0}; glGetProgramiv(shaderprog, GL_INFO_LOG_LENGTH, &infoLogLength); GLchar *infoLog = new GLchar[infoLogLength]; ::memset(infoLog, 0, infoLogLength); glGetProgramInfoLog(shaderprog, infoLogLength, NULL, infoLog); String error(infoLog); - Common::Logger::getInstance()->print("Link log:\n" + error + "\n"); + Logger::getInstance()->print("Link log:\n" + error + "\n"); delete[] infoLog; } bool OGLShader::isCompiled() const { - return m_isCompiledAndLinked; + return mIsCompiledAndLinked; } GLint OGLShader::getAttributeLocation(const String &attribute) { - const GLint loc = m_attributeMap[attribute]; + const GLint loc = mAttributeMap[attribute]; return loc; } @@ -260,11 +268,11 @@ GLint OGLShader::getUniformLocation(const String &uniform) { return InvalidLocationId; } - std::map::iterator it = m_uniformLocationMap.find(uniform); - if (m_uniformLocationMap.end() == it) { + std::map::iterator it = mUniformLocationMap.find(uniform); + if (mUniformLocationMap.end() == it) { return InvalidLocationId; } - const GLint loc = m_uniformLocationMap[uniform]; + const GLint loc = mUniformLocationMap[uniform]; return loc; } diff --git a/src/Engine/RenderBackend/OGLRenderer/OGLShader.h b/src/Engine/RenderBackend/OGLRenderer/OGLShader.h index 3ed1ee2af..0da2fe266 100644 --- a/src/Engine/RenderBackend/OGLRenderer/OGLShader.h +++ b/src/Engine/RenderBackend/OGLRenderer/OGLShader.h @@ -48,10 +48,12 @@ static constexpr GLint InvalidLocationId = -1; /// shader stages like vertex-, fragment or geometry-shader. /// You can load a shader for a given type from a file or from in-memory string buffer. //------------------------------------------------------------------------------------------------- -class OGLShader : public Common::Object { +class OGLShader final : public Common::Object { public: + /// @brief Buffer length. static constexpr ui32 MaxLen = 64u; + /// @brief Declares an active parameter. struct ActiveParameter { c8 m_name[MaxLen]; GLint m_location; @@ -70,15 +72,15 @@ class OGLShader : public Common::Object { OGLShader( const String &name ); /// @brief The class destructor. - virtual ~OGLShader(); - + ~OGLShader() override; + /// @brief Will load the shader type from a given string. /// @param type [in] The shader type. /// @param src [in] The shader source to compile. /// @return true, if compile was successful, false in case of an error. bool loadFromSource( ShaderType type, const String &src ); - - /// @brief + + /// @brief Will load the source fir a given io-stream. /// @param type [in] The shader type. /// @param stream [in] The stream containing the source. /// @return true, if compile was successful, false in case of an error. @@ -87,13 +89,13 @@ class OGLShader : public Common::Object { /// @brief Will create and link a shader program. /// @return true, if create & link was successful, false in case of an error. bool createAndLink(); - + /// @brief Will bind this program to the current render context. void use(); /// @brief Will unbind this program to the current render context. void unuse(); - + /// @brief Will perform a lookup if the attribute is used in the shader program. /// The shader program must be compiled before. /// @param attribute [in] The name of the attribute to look for. @@ -113,7 +115,7 @@ class OGLShader : public Common::Object { /// @brief Adds a new uniform to the shader. /// @param uniform [in] The name of the uniform. void addUniform( const String& uniform ); - + /// @brief Will create a list with all active attributes. void getActiveAttributeList(); @@ -136,16 +138,16 @@ class OGLShader : public Common::Object { OGLShader &operator = ( const OGLShader & ) = delete; private: - ParameterArray m_attribParams; - ParameterArray m_uniformParams; - - ui32 m_shaderprog; - ui32 m_numShader; - ui32 m_shaders[ MaxShaderTypes ]; - std::map m_attributeMap; - std::map m_uniformLocationMap; - bool m_isCompiledAndLinked; - bool m_isInUse; + ParameterArray mAttribParams; + ParameterArray mUniformParams; + + ui32 mShaderprog; + ui32 mNumShader; + ui32 mShaders[MaxShaderTypes]; + std::map mAttributeMap; + std::map mUniformLocationMap; + bool mIsCompiledAndLinked; + bool mIsInUse; }; } // Namespace RenderBackend diff --git a/src/Engine/RenderBackend/RenderCommon.cpp b/src/Engine/RenderBackend/RenderCommon.cpp index 6ca68c205..97fce9944 100644 --- a/src/Engine/RenderBackend/RenderCommon.cpp +++ b/src/Engine/RenderBackend/RenderCommon.cpp @@ -531,18 +531,14 @@ bool Viewport::operator!=(const Viewport &rhs) const { } Light::Light() : - m_position(0.0f, 0.0f, 0.0f, 1.0f), - m_specular(1.0f, 1.0f, 1.0f), - m_diffuse(1.0f, 1.0f, 1.0f), - m_ambient(1.0f, 1.0f, 1.0f), - m_direction(0.0f, 0.0f, 1.0f, 1.0f), - m_specularExp(1.0f), - mRadius(1.0f), - m_type(LightType::InvalidLightType) { - // empty -} - -Light::~Light() { + Position(0.0f, 0.0f, 0.0f, 1.0f), + Specular(1.0f, 1.0f, 1.0f), + Diffuse(1.0f, 1.0f, 1.0f), + Ambient(1.0f, 1.0f, 1.0f), + Direction(0.0f, 0.0f, 1.0f, 1.0f), + SpecularExp(1.0f), + Radius(1.0f), + Type(LightType::InvalidLightType) { // empty } diff --git a/src/Engine/RenderBackend/RenderCommon.h b/src/Engine/RenderBackend/RenderCommon.h index 04143f6e4..f87c36bab 100644 --- a/src/Engine/RenderBackend/RenderCommon.h +++ b/src/Engine/RenderBackend/RenderCommon.h @@ -635,20 +635,20 @@ struct TIndexCache { /// @brief This struct is used to desribe a light source. struct OSRE_EXPORT Light { - glm::vec4 m_position; ///< The position of the light - glm::vec3 m_specular; ///< The specular colot. - glm::vec3 m_diffuse; ///< The diffuse color. - glm::vec3 m_ambient; ///< The ambient color. - glm::vec4 m_direction; ///< The direction vector. - f32 m_specularExp; ///< The specular exponent. - f32 mRadius; ///< The light radius. - LightType m_type; ///< The light type. + glm::vec4 Position; ///< The position of the light + glm::vec3 Specular; ///< The specular colot. + glm::vec3 Diffuse; ///< The diffuse color. + glm::vec3 Ambient; ///< The ambient color. + glm::vec4 Direction; ///< The direction vector. + f32 SpecularExp; ///< The specular exponent. + f32 Radius; ///< The light radius. + LightType Type; ///< The light type. /// @brief The class constructor. Light(); /// @brief The class destructor. - ~Light(); + ~Light() = default; }; using UiVertexCache = RenderBackend::TVertexCache; diff --git a/src/Engine/RenderBackend/Shader.cpp b/src/Engine/RenderBackend/Shader.cpp index 188935f07..b0ca70a41 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) * MaxCompileState); } void Shader::addVertexAttribute(const String &name) { diff --git a/src/Engine/RenderBackend/TransformMatrixBlock.cpp b/src/Engine/RenderBackend/TransformMatrixBlock.cpp index a6970d5e4..9aff48d9f 100644 --- a/src/Engine/RenderBackend/TransformMatrixBlock.cpp +++ b/src/Engine/RenderBackend/TransformMatrixBlock.cpp @@ -25,12 +25,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. namespace OSRE { namespace RenderBackend { -TransformMatrixBlock::TransformMatrixBlock() : - mProjection(1.0f), - mModel(1.0f), - mView(1.0f), - mNormal(1.0f), - mMvp(1.0f) { +TransformMatrixBlock::TransformMatrixBlock() { init(); } @@ -77,6 +72,5 @@ const float *TransformMatrixBlock::getMVP() { return glm::value_ptr(mMvp); } - } // namespace RenderBackend } // namespace OSRE diff --git a/src/Engine/RenderBackend/TransformMatrixBlock.h b/src/Engine/RenderBackend/TransformMatrixBlock.h index 68e4cd296..52a710e20 100644 --- a/src/Engine/RenderBackend/TransformMatrixBlock.h +++ b/src/Engine/RenderBackend/TransformMatrixBlock.h @@ -40,20 +40,20 @@ struct OSRE_EXPORT TransformMatrixBlock { /// @brief The class constructor. TransformMatrixBlock(); - + /// @brief The class destructor. ~TransformMatrixBlock() = default; - + /// @brief Will init the data, all matrixes ar unit-matrices again. void init(); - + /// @brief All matrices will be recomputed. void update(); - + /// @brief The model matrix getter. /// @return const reference to the model matrix. const glm::mat4 &getModel() const; - + /// @brief The view matrix getter. /// @return const reference to the view matrix. const glm::mat4 &getView() const;