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/window/window.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/glText.cpp"
"src/graphics/opengl/glShader.cpp"
@ -51,9 +41,6 @@ set(LUNARIUM_SRC
"src/graphics/gui/luaConsole.cpp"
"src/scripting/scriptManager.cpp"
"src/scripting/coreAPI.cpp"
"src/assets/types/image.cpp"
"src/assets/types/asset.cpp"
"src/assets/loaders/binary/assetIndex.cpp"
)
# add the executable
@ -108,6 +95,12 @@ add_subdirectory(external/glm)
# add 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_subdirectory(external/lua)
@ -134,12 +127,14 @@ target_link_directories(${PROJECT_NAME}
PRIVATE external/glfw/src
PRIVATE external/glm
PRIVATE src/graphics/dearimgui
PRIVATE src/utils
PRIVATE src/assets
PRIVATE external/glad/src
PRIVATE external/freetype/src
)
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)
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()

@ -24,7 +24,7 @@ Core:
✔ 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 checkboxes to disable log categories and levels
☐ Add LUA Console window
✔ Add LUA Console window @done (10/26/2021, 4:43:41 PM)
Input:
✔ 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
Utils:
Make Logger fully static (no need to ever GetInstance)
☐ Need to add a static initialize method
Make Logger fully static (no need to ever GetInstance) @done (10/26/2021, 4:43:55 PM)
✔ Need to add a static initialize method @done (10/26/2021, 4:43:57 PM)
Game:
☐ Implement Run Mode interface class
@ -76,19 +76,20 @@ Game:
☐ Animated Sprite class
Editor:
Editor: @high
✔ 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)
☐ Reference raw asset files in a "content" folder
☐ Make the editor a separate module @high
☐ Implement Run Mode interface class @high
☐ Reference raw asset files in a "content" folder@high
☐ Platform independant file browsing
☐ Scan script files to make sure they don't overwrite globals
Raw Asset Importers:
- Need classes to load raw resource files for the editor
☐ Raw Resource loader interface class
☐ Raw Image loader class
☐ Raw Sound loader class
☐ Raw font file loader class
- Need classes to import raw resource files for the editor
☐ Raw Resource importer interface class
☐ Raw Image importer class
☐ Raw Sound importer class
☐ Raw font file importer class
GUI Panels:
Project Overview (Tree view):
@ -108,12 +109,12 @@ Editor:
Properties:
Assets:
Types:
- Classes that represent each resource Types
✔ 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
☐ Sound class
☐ Script class
@ -132,11 +133,11 @@ Assets:
Tester:
- 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)
Needs a timer to keep track of how long a test has run
Main Tick method should use the timer to determine when to switch to the next test
☐ Add function for testing render to Texture
☐ Add function for testing input
☐ Add function for testing text rendering
☐ Add function for testing shape drawing
☐ Add function for testing image drawing
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 @cancelled (10/26/2021, 4:36:16 PM)
✔ Add function for testing render to Texture @done (10/26/2021, 4:35:52 PM)
✔ Add function for testing input @done (10/26/2021, 4:36:05 PM)
✔ Add function for testing text rendering @done (10/26/2021, 4:35:54 PM)
✔ Add function for testing shape drawing @done (10/26/2021, 4:35:58 PM)
✔ 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()
: 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;
}
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()
{
delete[] mRawData;

@ -10,29 +10,32 @@
#ifndef IMAGE_H_
#define IMAGE_H_
#include <graphics/definitions.h>
#include <assets/definitions.h>
#include "asset.h"
namespace lunarium
{
class OglGraphics;
class Image : public Asset
{
friend OglGraphics;
public:
Image();
~Image();
unsigned int GetGLTextureID() const;
int GetWidth() const;
int GetHeight() 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();
private:
Image();
~Image();
Image(const Image& rhs);
const Image& operator=(const Image& rhs);

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

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

@ -10,7 +10,6 @@
#ifndef IGRAPHICS_H_
#define IGRAPHICS_H_
#include "definitions.h"
#include <utils/types.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 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.
// 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;
virtual void RegisterImage(Image& image) = 0;
// Fonts
virtual int DefaultFont() const = 0;

@ -145,7 +145,7 @@ namespace lunarium
if (mRT == RenderTarget::RT_IMAGE)
{
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
// Need to multiply these by the number bytes per pixel
@ -158,9 +158,9 @@ namespace lunarium
//glSetTexImage()
mpFBTexture->FreeRawData();
mpFBTexture->mWidth = mFBWidth;
mpFBTexture->mHeight = mFBHeight;
mpFBTexture->mFormat = ImageFormat::RGBA;
mpFBTexture->SetWidth(mFBWidth);
mpFBTexture->SetHeight(mFBHeight);
mpFBTexture->SetFormat(ImageFormat::RGBA);
// return a copy of the image
return mpFBTexture;
@ -369,14 +369,15 @@ namespace lunarium
// 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.
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 textureID = 0;
glGenTextures(1, &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);
@ -387,18 +388,7 @@ namespace lunarium
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
Image* image = new Image;
image->mWidth = width;
image->mHeight = height;
image->mGLTextureID = textureID;
return image;
}
void OglGraphics::DestroyImage(Image* i)
{
i->FreeRawData();
delete i;
image.SetGLTextureID(textureID);
}
// Fonts
@ -537,15 +527,17 @@ namespace lunarium
glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
// Texture
glGenTextures(1, &mpFBTexture->mGLTextureID);
glBindTexture(GL_TEXTURE_2D, mpFBTexture->mGLTextureID);
unsigned int id = -1;
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);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glBindTexture(GL_TEXTURE_2D, 0);
// 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
glGenRenderbuffers(1, &mRBO);

@ -52,10 +52,7 @@ namespace lunarium
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);
// 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.
virtual Image* CreateImage(const unsigned char* pData, int width, int height, ImageFormat format);
virtual void DestroyImage(Image* i);
virtual void RegisterImage(Image& image);
// Fonts
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 <LunariumConfig.h>
#include <algorithm>
#ifdef WIN32
@ -29,6 +28,7 @@ namespace lunarium
#endif // WIN32
}
std::string System::GetGLSLVersionString()
{
std::string glsl_version = "#version ";

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

Loading…
Cancel
Save