Separated out assets and utils into their own libraries

Gui_Panel_Refactor
Joeyrp 4 years ago
parent 03fb715622
commit 7ca93ababf

@ -30,16 +30,6 @@ set(LUNARIUM_SRC
"src/core/iRunMode.cpp" "src/core/iRunMode.cpp"
"src/window/window.cpp" "src/window/window.cpp"
"src/tester/tester.cpp" "src/tester/tester.cpp"
"src/utils/types.cpp"
"src/utils/logger.cpp"
"src/utils/highResTimer.cpp"
"src/utils/helpers.cpp"
"src/utils/opRes.cpp"
"src/utils/args.cpp"
"src/utils/binaryFileBuffer.cpp"
"src/utils/frameCounter.cpp"
"src/utils/stb/stb_image.cpp"
"src/utils/stb/stb_image_write.cpp"
"src/graphics/opengl/glGraphics.cpp" "src/graphics/opengl/glGraphics.cpp"
"src/graphics/opengl/glText.cpp" "src/graphics/opengl/glText.cpp"
"src/graphics/opengl/glShader.cpp" "src/graphics/opengl/glShader.cpp"
@ -51,9 +41,6 @@ set(LUNARIUM_SRC
"src/graphics/gui/luaConsole.cpp" "src/graphics/gui/luaConsole.cpp"
"src/scripting/scriptManager.cpp" "src/scripting/scriptManager.cpp"
"src/scripting/coreAPI.cpp" "src/scripting/coreAPI.cpp"
"src/assets/types/image.cpp"
"src/assets/types/asset.cpp"
"src/assets/loaders/binary/assetIndex.cpp"
) )
# add the executable # add the executable
@ -108,6 +95,12 @@ add_subdirectory(external/glm)
# add dearimgui # add dearimgui
add_subdirectory(src/graphics/dearimgui) add_subdirectory(src/graphics/dearimgui)
# add utils
add_subdirectory(src/utils)
# add assets
add_subdirectory(src/assets)
# add lua -- https://github.com/walterschell/Lua # add lua -- https://github.com/walterschell/Lua
add_subdirectory(external/lua) add_subdirectory(external/lua)
@ -134,12 +127,14 @@ target_link_directories(${PROJECT_NAME}
PRIVATE external/glfw/src PRIVATE external/glfw/src
PRIVATE external/glm PRIVATE external/glm
PRIVATE src/graphics/dearimgui PRIVATE src/graphics/dearimgui
PRIVATE src/utils
PRIVATE src/assets
PRIVATE external/glad/src PRIVATE external/glad/src
PRIVATE external/freetype/src PRIVATE external/freetype/src
) )
if(WIN32) if(WIN32)
target_link_libraries(${PROJECT_NAME} opengl32.lib glfw glad glm dearimgui lua_static pugixml freetype) target_link_libraries(${PROJECT_NAME} opengl32.lib glfw glad glm dearimgui utils assets lua_static pugixml freetype)
elseif(UNIX) elseif(UNIX)
target_link_libraries(${PROJECT_NAME} X11 GL glfw glad glm dearimgui lua_static pugixml freetype) target_link_libraries(${PROJECT_NAME} X11 GL glfw glad glm dearimgui utils assets lua_static pugixml freetype)
endif() endif()

@ -24,7 +24,7 @@ Core:
✔ Debug log window @done (9/10/2021, 4:44:48 PM) ✔ Debug log window @done (9/10/2021, 4:44:48 PM)
✔ Add key to show debug log window @done (9/13/2021, 6:47:44 PM) ✔ Add key to show debug log window @done (9/13/2021, 6:47:44 PM)
☐ Add checkboxes to disable log categories and levels ☐ Add checkboxes to disable log categories and levels
☐ Add LUA Console window ✔ Add LUA Console window @done (10/26/2021, 4:43:41 PM)
Input: Input:
✔ Port over the Element2D input system and adjust it to use glfw @done (9/8/2021, 8:20:07 PM) ✔ Port over the Element2D input system and adjust it to use glfw @done (9/8/2021, 8:20:07 PM)
@ -41,8 +41,8 @@ Core:
☐ Provide Methods that give access to the C++ code ☐ Provide Methods that give access to the C++ code
Utils: Utils:
Make Logger fully static (no need to ever GetInstance) Make Logger fully static (no need to ever GetInstance) @done (10/26/2021, 4:43:55 PM)
☐ Need to add a static initialize method ✔ Need to add a static initialize method @done (10/26/2021, 4:43:57 PM)
Game: Game:
☐ Implement Run Mode interface class ☐ Implement Run Mode interface class
@ -76,19 +76,20 @@ Game:
☐ Animated Sprite class ☐ Animated Sprite class
Editor: Editor: @high
✔ Come up with project directory structure @done (9/17/2021, 6:46:44 PM) ✔ Come up with project directory structure @done (9/17/2021, 6:46:44 PM)
✔ Implement Run Mode interface class @done (10/25/2021, 6:54:36 PM) ☐ Make the editor a separate module @high
☐ Reference raw asset files in a "content" folder ☐ Implement Run Mode interface class @high
☐ Reference raw asset files in a "content" folder@high
☐ Platform independant file browsing ☐ Platform independant file browsing
☐ Scan script files to make sure they don't overwrite globals ☐ Scan script files to make sure they don't overwrite globals
Raw Asset Importers: Raw Asset Importers:
- Need classes to load raw resource files for the editor - Need classes to import raw resource files for the editor
☐ Raw Resource loader interface class ☐ Raw Resource importer interface class
☐ Raw Image loader class ☐ Raw Image importer class
☐ Raw Sound loader class ☐ Raw Sound importer class
☐ Raw font file loader class ☐ Raw font file importer class
GUI Panels: GUI Panels:
Project Overview (Tree view): Project Overview (Tree view):
@ -108,12 +109,12 @@ Editor:
Properties: Properties:
Assets: Assets:
Types: Types:
- Classes that represent each resource Types - Classes that represent each resource Types
✔ Image class @done (9/16/2021, 2:46:34 PM) ✔ Image class @done (9/16/2021, 2:46:34 PM)
☐ Decouple Image class from OGLRenderer @high
- Give the renderer a register image method that will take an Image and finish setting it up
☐ Font class ☐ Font class
☐ Sound class ☐ Sound class
☐ Script class ☐ Script class
@ -132,11 +133,11 @@ Assets:
Tester: Tester:
- A special class that is used to unit-test features of the engine - A special class that is used to unit-test features of the engine
✔ Implement Run Mode interface class @done (10/25/2021, 7:37:00 PM) ✔ Implement Run Mode interface class @done (10/25/2021, 7:37:00 PM)
Needs a timer to keep track of how long a test has run Needs a timer to keep track of how long a test has run @cancelled (10/26/2021, 4:36:45 PM)
Main Tick method should use the timer to determine when to switch to the next test Main Tick method should use the timer to determine when to switch to the next test @cancelled (10/26/2021, 4:36:16 PM)
☐ Add function for testing render to Texture ✔ Add function for testing render to Texture @done (10/26/2021, 4:35:52 PM)
☐ Add function for testing input ✔ Add function for testing input @done (10/26/2021, 4:36:05 PM)
☐ Add function for testing text rendering ✔ Add function for testing text rendering @done (10/26/2021, 4:35:54 PM)
☐ Add function for testing shape drawing ✔ Add function for testing shape drawing @done (10/26/2021, 4:35:58 PM)
☐ Add function for testing image drawing ✔ Add function for testing image drawing @done (10/26/2021, 4:36:00 PM)

@ -0,0 +1,11 @@
add_library(assets assetManager.cpp types/asset.cpp types/image.cpp loaders/assetIndex.cpp)
# add utils
target_link_directories(assets
PRIVATE ../utils
)
target_include_directories(assets
PUBLIC ../
PUBLIC ../../external/glm
)

@ -14,7 +14,7 @@ namespace lunarium
{ {
Image::Image() Image::Image()
: Asset(AssetType::ASSET_TYPE_IMAGE), mRawData(nullptr), mRawDataSize(0), mWidth(0), mHeight(0) : Asset(AssetType::ASSET_TYPE_IMAGE), mRawData(nullptr), mRawDataSize(0), mWidth(0), mHeight(0), mGLTextureID((unsigned)-1)
{ {
} }
@ -71,6 +71,32 @@ namespace lunarium
return mFormat; return mFormat;
} }
const unsigned char* Image::GetData() const
{
return mRawData;
}
void Image::SetWidth(int width)
{
mWidth = width;
}
void Image::SetHeight(int height)
{
mHeight = height;
}
void Image::SetFormat(ImageFormat format)
{
mFormat = format;
}
void Image::SetGLTextureID(unsigned int id)
{
mGLTextureID = id;
}
void Image::FreeRawData() void Image::FreeRawData()
{ {
delete[] mRawData; delete[] mRawData;

@ -10,29 +10,32 @@
#ifndef IMAGE_H_ #ifndef IMAGE_H_
#define IMAGE_H_ #define IMAGE_H_
#include <graphics/definitions.h> #include <assets/definitions.h>
#include "asset.h" #include "asset.h"
namespace lunarium namespace lunarium
{ {
class OglGraphics;
class Image : public Asset class Image : public Asset
{ {
friend OglGraphics;
public: public:
Image();
~Image();
unsigned int GetGLTextureID() const; unsigned int GetGLTextureID() const;
int GetWidth() const; int GetWidth() const;
int GetHeight() const; int GetHeight() const;
ImageFormat GetFormat() const; ImageFormat GetFormat() const;
const unsigned char* GetData() const;
void SetGLTextureID(unsigned int id);
void SetWidth(int width);
void SetHeight(int height);
void SetFormat(ImageFormat format);
void FreeRawData(); void FreeRawData();
private: private:
Image();
~Image();
Image(const Image& rhs); Image(const Image& rhs);
const Image& operator=(const Image& rhs); const Image& operator=(const Image& rhs);

@ -10,6 +10,7 @@
#include "version.h" #include "version.h"
#include <imgui.h> #include <imgui.h>
#include <LunariumConfig.h>
// Run modes // Run modes
#include <tester/tester.h> #include <tester/tester.h>

@ -44,6 +44,7 @@ namespace lunarium
OpRes BeginRenderToTexture(); OpRes BeginRenderToTexture();
Image* EndRenderToTexture(); Image* EndRenderToTexture();
private: // DATA private: // DATA
static Core* mpInstance; static Core* mpInstance;
bool mbIsInit; bool mbIsInit;

@ -10,7 +10,6 @@
#ifndef IGRAPHICS_H_ #ifndef IGRAPHICS_H_
#define IGRAPHICS_H_ #define IGRAPHICS_H_
#include "definitions.h"
#include <utils/types.h> #include <utils/types.h>
#include <utils/opRes.h> #include <utils/opRes.h>
@ -58,10 +57,7 @@ namespace lunarium
virtual void DrawImage(Image& image, Rectangle source, Rectangle destination, Color color) = 0; virtual void DrawImage(Image& image, Rectangle source, Rectangle destination, Color color) = 0;
virtual void DrawString(const char* string, Rectangle boundingArea, Color color, float scale = 1.0f, int font = 0) = 0; virtual void DrawString(const char* string, Rectangle boundingArea, Color color, float scale = 1.0f, int font = 0) = 0;
// Takes raw image data and creates and Image class instance out of it. virtual void RegisterImage(Image& image) = 0;
// The raw data must be in one of the ImageFormats and it must be 1 byte per channel.
virtual Image* CreateImage(const unsigned char* pData, int width, int height, ImageFormat format) = 0;
virtual void DestroyImage(Image* i) = 0;
// Fonts // Fonts
virtual int DefaultFont() const = 0; virtual int DefaultFont() const = 0;

@ -145,7 +145,7 @@ namespace lunarium
if (mRT == RenderTarget::RT_IMAGE) if (mRT == RenderTarget::RT_IMAGE)
{ {
glBindFramebuffer(GL_FRAMEBUFFER, 0); glBindFramebuffer(GL_FRAMEBUFFER, 0);
glBindTexture(GL_TEXTURE_2D, mpFBTexture->mGLTextureID); glBindTexture(GL_TEXTURE_2D, mpFBTexture->GetGLTextureID());
// Buffer width and height (in pixels) is the same as the screen size // Buffer width and height (in pixels) is the same as the screen size
// Need to multiply these by the number bytes per pixel // Need to multiply these by the number bytes per pixel
@ -158,9 +158,9 @@ namespace lunarium
//glSetTexImage() //glSetTexImage()
mpFBTexture->FreeRawData(); mpFBTexture->FreeRawData();
mpFBTexture->mWidth = mFBWidth; mpFBTexture->SetWidth(mFBWidth);
mpFBTexture->mHeight = mFBHeight; mpFBTexture->SetHeight(mFBHeight);
mpFBTexture->mFormat = ImageFormat::RGBA; mpFBTexture->SetFormat(ImageFormat::RGBA);
// return a copy of the image // return a copy of the image
return mpFBTexture; return mpFBTexture;
@ -369,14 +369,15 @@ namespace lunarium
// Takes raw image data and creates and Image class instance out of it. // Takes raw image data and creates and Image class instance out of it.
// The raw data must be in one of the ImageFormats and it must be 1 byte per channel. // The raw data must be in one of the ImageFormats and it must be 1 byte per channel.
Image* OglGraphics::CreateImage(const unsigned char* pData, int width, int height, ImageFormat format) void OglGraphics::RegisterImage(Image& image)
{ {
unsigned int glFormat[4] = { GL_RGB, GL_RGBA, GL_BGR, GL_BGRA }; unsigned int glFormat[4] = { GL_RGB, GL_RGBA, GL_BGR, GL_BGRA };
unsigned int textureID = 0; unsigned int textureID = 0;
glGenTextures(1, &textureID); glGenTextures(1, &textureID);
glBindTexture(GL_TEXTURE_2D, textureID); glBindTexture(GL_TEXTURE_2D, textureID);
glTexImage2D(GL_TEXTURE_2D, 0, glFormat[format], width, height, 0, glFormat[format], GL_UNSIGNED_BYTE, pData); glTexImage2D(GL_TEXTURE_2D, 0, glFormat[image.GetFormat()], image.GetWidth(),
image.GetHeight(), 0, glFormat[image.GetFormat()], GL_UNSIGNED_BYTE, image.GetData());
glGenerateMipmap(GL_TEXTURE_2D); glGenerateMipmap(GL_TEXTURE_2D);
@ -387,20 +388,9 @@ namespace lunarium
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
Image* image = new Image; image.SetGLTextureID(textureID);
image->mWidth = width;
image->mHeight = height;
image->mGLTextureID = textureID;
return image;
} }
void OglGraphics::DestroyImage(Image* i)
{
i->FreeRawData();
delete i;
}
// Fonts // Fonts
int OglGraphics::DefaultFont() const int OglGraphics::DefaultFont() const
{ {
@ -537,15 +527,17 @@ namespace lunarium
glBindFramebuffer(GL_FRAMEBUFFER, mFBO); glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
// Texture // Texture
glGenTextures(1, &mpFBTexture->mGLTextureID); unsigned int id = -1;
glBindTexture(GL_TEXTURE_2D, mpFBTexture->mGLTextureID); glGenTextures(1, &id);
mpFBTexture->SetGLTextureID(id);
glBindTexture(GL_TEXTURE_2D, mpFBTexture->GetGLTextureID());
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, mFBWidth, mFBHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, mFBWidth, mFBHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glBindTexture(GL_TEXTURE_2D, 0); glBindTexture(GL_TEXTURE_2D, 0);
// Attach texture // Attach texture
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mpFBTexture->mGLTextureID, 0); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mpFBTexture->GetGLTextureID(), 0);
// Render Buffer for depth/stencil testing // Render Buffer for depth/stencil testing
glGenRenderbuffers(1, &mRBO); glGenRenderbuffers(1, &mRBO);

@ -52,10 +52,7 @@ namespace lunarium
virtual void DrawImage(Image& image, Rectangle source, Rectangle destination, Color color); virtual void DrawImage(Image& image, Rectangle source, Rectangle destination, Color color);
virtual void DrawString(const char* string, Rectangle boundingArea, Color color, float scale = 1.0f, int font = 0); virtual void DrawString(const char* string, Rectangle boundingArea, Color color, float scale = 1.0f, int font = 0);
// Takes raw image data and creates and Image class instance out of it. virtual void RegisterImage(Image& image);
// The raw data must be in one of the ImageFormats and it must be 1 byte per channel.
virtual Image* CreateImage(const unsigned char* pData, int width, int height, ImageFormat format);
virtual void DestroyImage(Image* i);
// Fonts // Fonts
int DefaultFont() const; int DefaultFont() const;

@ -0,0 +1,9 @@
add_library(utils stb/stb_image_write.cpp stb/stb_image.cpp args.cpp binaryFileBuffer.cpp frameCounter.cpp
helpers.cpp highResTimer.cpp logger.cpp opRes.cpp types.cpp)
target_include_directories(utils
PUBLIC "${PROJECT_BINARY_DIR}"
PUBLIC ../../external/glm
)
message( " current source dir: ${CMAKE_CURRENT_SOURCE_DIR}" )

@ -7,7 +7,6 @@
******************************************************************************/ ******************************************************************************/
#include "helpers.h" #include "helpers.h"
#include <LunariumConfig.h>
#include <algorithm> #include <algorithm>
#ifdef WIN32 #ifdef WIN32
@ -29,6 +28,7 @@ namespace lunarium
#endif // WIN32 #endif // WIN32
} }
std::string System::GetGLSLVersionString() std::string System::GetGLSLVersionString()
{ {
std::string glsl_version = "#version "; std::string glsl_version = "#version ";

@ -10,6 +10,7 @@
#define HELPERS_H_ #define HELPERS_H_
#include "types.h" #include "types.h"
#include <LunariumConfig.h>
#include <string> #include <string>
#include <vector> #include <vector>

Loading…
Cancel
Save