Skip to content

Commit

Permalink
Normalize code style.
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeyDeVries committed Oct 23, 2017
1 parent 200c8b6 commit 18f69ba
Show file tree
Hide file tree
Showing 22 changed files with 208 additions and 301 deletions.
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -9,6 +9,8 @@ to use and read. Cell also aims to provide both flexible and properly maintainab
The engine will be heavily commented and documented from within the source code itself, to motivate new graphics programmers
to take a look at any of its inner workings, without feeling too overwhelming.

![Cell Preview](preview.png "Cell Preview")

Feature List (complete:base-functionality)
------
* Fully functioning (custom) math library (vectors, matrices, transformations, utility functions):
Expand Down
40 changes: 17 additions & 23 deletions cell/cell.cpp
Expand Up @@ -34,22 +34,20 @@ namespace Cell
Renderer* renderer;
Renderer* Init(GLFWwindow* window, GLADloadproc loadProcFunc)
{
/* NOTE(Joey):
/*
Before doing anything with OpenGL we have to load all its functions
into stored function pointers from the OpenGL driver. Windows by
default only hosts a small set of OpenGL functions in its library
so all the more 'modern' functions have to be manually loaded/
Before doing anything with OpenGL we have to load all its functions into stored function
pointers from the OpenGL driver. Windows by default only hosts a small set of OpenGL
functions in its library so all the more 'modern' functions have to be manually loaded/
requested from the graphics cards' OpenGL driver itself.
This is a cumbersome work as we generally have to store all the
required function prototypes, function pointer storage and all
the enum / unique ids of the OpenGL functionality and on top of
that we have to query for the function's memory location for
This is a cumbersome work as we generally have to store all the required function
prototypes, function pointer storage and all the enum / unique ids of the OpenGL
functionality and on top of that we have to query for the function's memory location for
each and every one of these functions.
For this reason we use a library called GLAD
http://glad.dav1d.de/ <- their webservice for generating header file
For this reason we use a library called GLAD http://glad.dav1d.de/ <- their webservice
for generating header file.
*/
if (!gladLoadGLLoader(loadProcFunc))
Expand All @@ -64,21 +62,17 @@ namespace Cell
Log::Message("Driver: " + std::string((char*)glGetString(GL_VENDOR)) + " Renderer: " + std::string((char*)glGetString(GL_RENDERER)), LOG_INIT);
}

/* NOTE(Joey):
/*
Next up is initializing debug output. Debug output allows us to
give a callback error reporting function to OpenGL that OpenGL
will call each time an internal error occurs with detailed
information about the error. This helps us to easily catch
errors from within OpenGL itself saving us from long hours
of debugging. For more info see:
Next up is initializing debug output. Debug output allows us to give a callback error
reporting function to OpenGL that OpenGL will call each time an internal error occurs
with detailed information about the error. This helps us to easily catch errors from
within OpenGL itself saving us from long hours of debugging. For more info see:
http://learnopengl.com/#!In-Practice/Debugging
Note that debug output will only be initialized if the
windowing library initialized an OpenGL context with the
debug output bit flag set; otherwise this functionality
is simply ignored. Note that it did not on a 3.3 context,
it's interesting to figure out why!
Note that debug output will only be initialized if the windowing library initialized an
OpenGL context with the debug output bit flag set; otherwise this functionality is simply
ignored. Note that it did not on a 3.3 context, it's interesting to figure out why!
*/
Log::Message("Initializing debug Output.", LOG_INIT);
Expand Down
16 changes: 8 additions & 8 deletions cell/cell.h
Expand Up @@ -28,29 +28,29 @@ class GLFWwindow;

namespace Cell
{
/* NOTE(Joey):
/*
Global entry-point for Cell's initialization. Starts all Cell's relevant
initialization calls, and makes sure Cell is ready to operate after
calling its initialization function. Note that all GL function pointers
are initialized here as well (including any extensions) w/ GLAD.
Global entry-point for Cell's initialization. Starts all Cell's relevant initialization
calls, and makes sure Cell is ready to operate after calling its initialization function.
Note that all GL function pointers are initialized here as well (including any extensions)
w/ GLAD.
*/
Renderer* Init(GLFWwindow* window, GLADloadproc loadProcFunc);


// Cleans up Cell of all resources that are no longer relevant.
// cleans up Cell of all resources that are no longer relevant.
void Clean();

/* NOTE(Joey):
/*
Initializes all render data required for processing a new frame. This is mostly relevant
for rendering GUI items.
*/
void NewFrame();

/* NOTE(Joey):
/*
Renders (debugging) GUI (IMGUI) on top of Cell's main renderer, by default the renderer's
configuration UI is rendered as well, which can be enabled/disabled on demand.
Expand Down
6 changes: 3 additions & 3 deletions cell/renderer/PostProcessor.h
Expand Up @@ -18,9 +18,9 @@ namespace Cell
Manages and maintains all data and functionality related to end-of-frame post-processing.
This doesn't only include post-processing effects like SSAO, Bloom, Vignette, but also
includes general functionality like blitting and blurring. The post-processor's multi-pass
effects support multiple resolutions and adjusts accordingly when a resolution change
occurs.
includes general functionality like blitting, blurring, HDR and gammac-orrection.
The post-processor's multi-pass effects support multiple resolutions and adjusts accordingly
when a resolution change occurs.
*/
class PostProcessor
Expand Down
4 changes: 2 additions & 2 deletions cell/resources/mesh_loader.h
Expand Up @@ -19,9 +19,9 @@ namespace Cell
class Mesh;
class Material;

/* NOTE(Joey):
/*
MeshLoader
Mesh load functionality.
*/
class MeshLoader
Expand Down
72 changes: 33 additions & 39 deletions cell/resources/resources.cpp
Expand Up @@ -19,21 +19,16 @@ namespace Cell
std::map<unsigned int, Texture> Resources::m_Textures = std::map<unsigned int, Texture>();
std::map<unsigned int, TextureCube> Resources::m_TexturesCube = std::map<unsigned int, TextureCube>();
std::map<unsigned int, SceneNode*> Resources::m_Meshes = std::map<unsigned int, SceneNode*>();

// ------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------
void Resources::Init()
{
// NOTE(Joey): initialize default assets/resources that should
// always be available, regardless of configuration.
//Shader defaultShader = ShaderLoader::Load("default", "shaders/default.vs", "shaders/default.fs");
// initialize default assets/resources that should always be available, regardless of
// configuration.
Texture placeholderTexture;

//m_Shaders[SID("default")] = defaultShader;
//m_Textures[SID("default")] = placeholderTexture;
}
void Resources::Clean()
{
// NOTE(Joey): traverse all stored mesh scene nodes and delete accordingly.
// traverse all stored mesh scene nodes and delete accordingly.
// Note that this time we don't care about deleting dangling pointers as each scene node is
// unique and shouldn't reference other scene nodes than their children.
for(auto it = m_Meshes.begin(); it != m_Meshes.end(); it++)
Expand All @@ -42,25 +37,25 @@ namespace Cell
}
}

// ------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------
Shader* Resources::LoadShader(std::string name, std::string vsPath, std::string fsPath, std::vector<std::string> defines)
{
unsigned int id = SID(name);

// NOTE(Joey): if shader already exists, return that handle
// if shader already exists, return that handle
if(Resources::m_Shaders.find(id) != Resources::m_Shaders.end())
return &Resources::m_Shaders[id];

Shader shader = ShaderLoader::Load(name, vsPath, fsPath, defines);
Resources::m_Shaders[id] = shader;
return &Resources::m_Shaders[id];
}
// ------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------
Shader* Resources::GetShader(std::string name)
{
unsigned int id = SID(name);

// NOTE(Joey): if shader exists, return that handle
// if shader exists, return that handle
if (Resources::m_Shaders.find(id) != Resources::m_Shaders.end())
{
return &Resources::m_Shaders[id];
Expand All @@ -71,12 +66,12 @@ namespace Cell
return nullptr;
}
}
// ------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------
Texture* Resources::LoadTexture(std::string name, std::string path, GLenum target, GLenum format, bool srgb)
{
unsigned int id = SID(name);

// NOTE(Joey): if texture already exists, return that handle
// if texture already exists, return that handle
if (Resources::m_Textures.find(id) != Resources::m_Textures.end())
return &Resources::m_Textures[id];

Expand All @@ -86,7 +81,7 @@ namespace Cell

Log::Message("Succesfully loaded: " + path + ".", LOG_INIT);

// NOTE(Joey): make sure texture got properly loaded
// make sure texture got properly loaded
if (texture.Width > 0)
{
Resources::m_Textures[id] = texture;
Expand All @@ -97,17 +92,17 @@ namespace Cell
return nullptr;
}
}
// ------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------
Texture* Resources::LoadHDR(std::string name, std::string path)
{
unsigned int id = SID(name);

// NOTE(Joey): if texture already exists, return that handle
// if texture already exists, return that handle
if (Resources::m_Textures.find(id) != Resources::m_Textures.end())
return &Resources::m_Textures[id];

Texture texture = TextureLoader::LoadHDRTexture(path);
// NOTE(Joey): make sure texture got properly loaded
// make sure texture got properly loaded
if (texture.Width > 0)
{
Resources::m_Textures[id] = texture;
Expand All @@ -118,12 +113,12 @@ namespace Cell
return nullptr;
}
}
// ------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------
Texture* Resources::GetTexture(std::string name)
{
unsigned int id = SID(name);

// NOTE(Joey): if shader exists, return that handle
// if shader exists, return that handle
if (Resources::m_Textures.find(id) != Resources::m_Textures.end())
{
return &Resources::m_Textures[id];
Expand All @@ -134,25 +129,25 @@ namespace Cell
return nullptr;
}
}
// ------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------
TextureCube* Resources::LoadTextureCube(std::string name, std::string folder)
{
unsigned int id = SID(name);

// NOTE(Joey): if texture already exists, return that handle
// if texture already exists, return that handle
if (Resources::m_TexturesCube.find(id) != Resources::m_TexturesCube.end())
return &Resources::m_TexturesCube[id];

TextureCube texture = TextureLoader::LoadTextureCube(folder);
Resources::m_TexturesCube[id] = texture;
return &Resources::m_TexturesCube[id];
}
// ------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------
TextureCube* Resources::GetTextureCube(std::string name)
{
unsigned int id = SID(name);

// NOTE(Joey): if shader exists, return that handle
// if shader exists, return that handle
if (Resources::m_TexturesCube.find(id) != Resources::m_TexturesCube.end())
{
return &Resources::m_TexturesCube[id];
Expand All @@ -163,38 +158,37 @@ namespace Cell
return nullptr;
}
}
// ------------------------------------------------------------------------
SceneNode* Resources::LoadMesh(Renderer *renderer, std::string name, std::string path)
// --------------------------------------------------------------------------------------------
SceneNode* Resources::LoadMesh(Renderer* renderer, std::string name, std::string path)
{
unsigned int id = SID(name);

// NOTE(Joey): if mesh's scene node was already loaded before, copy the scene node's memory
// and return the copied reference. We return a copy as the moment the global scene deletes
// the returned node, all other and next requested scene nodes of this model will end up as
// if mesh's scene node was already loaded before, copy the scene node's memory and return
// the copied reference. We return a copy as the moment the global scene deletes the
// returned node, all other and next requested scene nodes of this model will end up as
// dangling pointers.
if (Resources::m_Meshes.find(id) != Resources::m_Meshes.end())
{
return Scene::MakeSceneNode(Resources::m_Meshes[id]);
}

// NOTE(Joey): MeshLoader::LoadMesh initializes a scene node hierarchy on the heap. We are
// responsible for managing the memory; keep a reference to the root node of the model
// scene.
SceneNode *node = MeshLoader::LoadMesh(renderer, path);
// MeshLoader::LoadMesh initializes a scene node hierarchy on the heap. We are responsible
// for managing the memory; keep a reference to the root node of the model scene.
SceneNode* node = MeshLoader::LoadMesh(renderer, path);
Resources::m_Meshes[id] = node;

// NOTE(Joey): return a copied reference through the scene to prevent dangling pointers.
// return a copied reference through the scene to prevent dangling pointers.
// See description above.
return Scene::MakeSceneNode(node);
}
// ------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------
SceneNode* Resources::GetMesh(std::string name)
{
unsigned int id = SID(name);

// NOTE(Joey): if mesh's scene node was already loaded before, copy the scene node's memory
// and return the copied reference. We return a copy as the moment the global scene deletes
// the returned node, all other and next requested scene nodes of this model will end up as
// if mesh's scene node was already loaded before, copy the scene node's memory and return
// the copied reference. We return a copy as the moment the global scene deletes the
// returned node, all other and next requested scene nodes of this model will end up as
// dangling pointers.
if (Resources::m_Meshes.find(id) != Resources::m_Meshes.end())
{
Expand Down
20 changes: 10 additions & 10 deletions cell/resources/resources.h
Expand Up @@ -18,42 +18,42 @@ namespace Cell
class SceneNode;
class Renderer;

/* NOTE(Joey):
/*
Resources
Global resource manager. Manages and maintains all resource memory used throughout the
rendering application. New resources are loaded from here, and duplicate resource loads
are prevented. Every resource is referenced by a hashed string ID.
*/
class Resources
{
private:
// NOTE(Joey): we index all resources w/ a hashed string ID
// we index all resources w/ a hashed string ID
static std::map<unsigned int, Shader> m_Shaders;
static std::map<unsigned int, Texture> m_Textures;
static std::map<unsigned int, TextureCube> m_TexturesCube;
static std::map<unsigned int, SceneNode*> m_Meshes;
public:

private:
// NOTE(Joey): disallow creation of any Resources object; it's defined as a static object
// disallow creation of any Resources object; it's defined as a static object
Resources();
public:
static void Init();
static void Clean();

// NOTE(Joey): shader resources
// shader resources
static Shader* LoadShader(std::string name, std::string vsPath, std::string fsPath, std::vector<std::string> defines = std::vector<std::string>());
static Shader* GetShader(std::string name);
// NOTE(Joey): texture resources
// texture resources
static Texture* LoadTexture(std::string name, std::string path, GLenum target = GL_TEXTURE_2D, GLenum format = GL_RGBA, bool srgb = false);
static Texture* LoadHDR(std::string name, std::string path);
static TextureCube* LoadTextureCube(std::string name, std::string folder);
static Texture* GetTexture(std::string name);
static TextureCube* GetTextureCube(std::string name);
// NOTE(Joey): mesh/scene resources
static SceneNode* LoadMesh(Renderer *renderer, std::string name, std::string path);
// mesh/scene resources
static SceneNode* LoadMesh(Renderer* renderer, std::string name, std::string path);
static SceneNode* GetMesh(std::string name);
};
}


#endif
2 changes: 1 addition & 1 deletion cell/resources/shader_loader.cpp
Expand Up @@ -33,7 +33,7 @@ namespace Cell
return shader;
}
// --------------------------------------------------------------------------------------------
std::string ShaderLoader::readShader(std::ifstream &file, const std::string& name, std::string path)
std::string ShaderLoader::readShader(std::ifstream& file, const std::string& name, std::string path)
{
std::string directory = path.substr(0, path.find_last_of("/\\"));
std::string source, line;
Expand Down

0 comments on commit 18f69ba

Please sign in to comment.