Apply const correctness to project
This commit is contained in:
parent
a01c597340
commit
60fcecab0e
@ -11,7 +11,7 @@ namespace Dengine
|
|||||||
AssetManager::AssetManager() {}
|
AssetManager::AssetManager() {}
|
||||||
AssetManager::~AssetManager() {}
|
AssetManager::~AssetManager() {}
|
||||||
|
|
||||||
Texture *AssetManager::getTexture(std::string name)
|
const Texture *AssetManager::getTexture(const std::string name)
|
||||||
{
|
{
|
||||||
// NOTE(doyle): Since we're using a map, the count of an object can
|
// NOTE(doyle): Since we're using a map, the count of an object can
|
||||||
// only be 1 or 0
|
// only be 1 or 0
|
||||||
@ -21,7 +21,8 @@ namespace Dengine
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
i32 AssetManager::loadTextureImage(std::string path, std::string name)
|
const i32 AssetManager::loadTextureImage(const std::string path,
|
||||||
|
const std::string name)
|
||||||
{
|
{
|
||||||
/* Open the texture image */
|
/* Open the texture image */
|
||||||
i32 imgWidth, imgHeight, bytesPerPixel;
|
i32 imgWidth, imgHeight, bytesPerPixel;
|
||||||
@ -44,7 +45,7 @@ namespace Dengine
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Shader *AssetManager::getShader(std::string name)
|
const Shader *AssetManager::getShader(const std::string name)
|
||||||
{
|
{
|
||||||
if (mShaders.count(name) == 1)
|
if (mShaders.count(name) == 1)
|
||||||
return &mShaders[name];
|
return &mShaders[name];
|
||||||
@ -97,12 +98,12 @@ namespace Dengine
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
i32 AssetManager::loadShaderFiles(std::string vertexPath,
|
const i32 AssetManager::loadShaderFiles(const std::string vertexPath,
|
||||||
std::string fragmentPath, std::string name)
|
const std::string fragmentPath,
|
||||||
|
const std::string name)
|
||||||
{
|
{
|
||||||
|
|
||||||
GLuint vertexShader =
|
GLuint vertexShader = createShaderFromPath(vertexPath, GL_VERTEX_SHADER);
|
||||||
createShaderFromPath(vertexPath, GL_VERTEX_SHADER);
|
|
||||||
GLuint fragmentShader =
|
GLuint fragmentShader =
|
||||||
createShaderFromPath(fragmentPath, GL_FRAGMENT_SHADER);
|
createShaderFromPath(fragmentPath, GL_FRAGMENT_SHADER);
|
||||||
|
|
||||||
@ -114,5 +115,4 @@ namespace Dengine
|
|||||||
mShaders[name] = shader;
|
mShaders[name] = shader;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
11
src/Game.cpp
11
src/Game.cpp
@ -38,20 +38,23 @@ void Game::init(Dengine::AssetManager *assetManager)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
result = assetManager->loadTextureImage("data/textures/plain_terrain.png",
|
||||||
|
"plain_terrain");
|
||||||
|
|
||||||
this->shader = assetManager->getShader("sprite");
|
this->shader = assetManager->getShader("sprite");
|
||||||
|
|
||||||
/* Init player */
|
/* Init player */
|
||||||
Dengine::Texture *wallTex = assetManager->getTexture("wall");
|
const Dengine::Texture *tex = assetManager->getTexture("plain_terrain");
|
||||||
this->player = Dengine::Sprite();
|
this->player = Dengine::Sprite();
|
||||||
this->player.loadSprite(wallTex, glm::vec2(0, 0));
|
this->player.loadSprite(tex, glm::vec2(0, 0));
|
||||||
|
|
||||||
/* Init game state */
|
/* Init game state */
|
||||||
this->state = GAME_ACTIVE;
|
this->state = GAME_ACTIVE;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::processInput(f32 dt) {}
|
void Game::processInput(const f32 dt) {}
|
||||||
void Game::update(f32 dt) {}
|
void Game::update(const f32 dt) {}
|
||||||
void Game::render()
|
void Game::render()
|
||||||
{
|
{
|
||||||
shader->use();
|
shader->use();
|
||||||
|
@ -36,5 +36,5 @@ i32 Shader::loadProgram(GLuint vertexShader, GLuint fragmentShader)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Shader::use() { glUseProgram(this->program); }
|
void Shader::use() const { glUseProgram(this->program); }
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ tex(nullptr)
|
|||||||
|
|
||||||
Sprite::~Sprite() {}
|
Sprite::~Sprite() {}
|
||||||
|
|
||||||
b32 Sprite::loadSprite(Texture *tex, glm::vec2 pos)
|
const b32 Sprite::loadSprite(const Texture *tex, const glm::vec2 pos)
|
||||||
{
|
{
|
||||||
if (!tex) return -1;
|
if (!tex) return -1;
|
||||||
|
|
||||||
@ -55,7 +55,7 @@ b32 Sprite::loadSprite(Texture *tex, glm::vec2 pos)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sprite::render(Shader *shader)
|
void Sprite::render(const Shader *shader) const
|
||||||
{
|
{
|
||||||
// NOTE(doyle): Associate the VAO with this sprites VBO
|
// NOTE(doyle): Associate the VAO with this sprites VBO
|
||||||
glBindVertexArray(this->vao);
|
glBindVertexArray(this->vao);
|
||||||
|
@ -3,17 +3,17 @@
|
|||||||
namespace Dengine
|
namespace Dengine
|
||||||
{
|
{
|
||||||
Texture::Texture()
|
Texture::Texture()
|
||||||
: mId(0)
|
: id(0)
|
||||||
, mWidth(0)
|
, width(0)
|
||||||
, mHeight(0)
|
, height(0)
|
||||||
, mInternalFormat(GL_RGB)
|
, internalFormat(GL_RGB)
|
||||||
, mImageFormat(GL_RGB)
|
, imageFormat(GL_RGB)
|
||||||
, mWrapS(GL_REPEAT)
|
, wrapS(GL_REPEAT)
|
||||||
, mWrapT(GL_REPEAT)
|
, wrapT(GL_REPEAT)
|
||||||
, mFilterMinification(GL_LINEAR)
|
, filterMinification(GL_LINEAR)
|
||||||
, mFilterMagnification(GL_LINEAR)
|
, filterMagnification(GL_LINEAR)
|
||||||
{
|
{
|
||||||
glGenTextures(1, &mId);
|
glGenTextures(1, &this->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
enum BytesPerPixel
|
enum BytesPerPixel
|
||||||
@ -44,29 +44,32 @@ INTERNAL GLint getGLFormat(BytesPerPixel bytesPerPixel, b32 srgb)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Texture::generate(GLuint width, GLuint height, u8 *image)
|
void Texture::generate(const GLuint width, const GLuint height,
|
||||||
|
const u8 *const image)
|
||||||
{
|
{
|
||||||
// TODO(doyle): Let us set the parameters gl params as well
|
// TODO(doyle): Let us set the parameters gl params as well
|
||||||
mWidth = width;
|
this->width = width;
|
||||||
mHeight = height;
|
this->height = height;
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, mId);
|
glBindTexture(GL_TEXTURE_2D, this->id);
|
||||||
|
|
||||||
/* Load image into texture */
|
/* Load image into texture */
|
||||||
// TODO(doyle) Figure out the gl format
|
// TODO(doyle) Figure out the gl format
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, mInternalFormat, mWidth, mHeight, 0,
|
glTexImage2D(GL_TEXTURE_2D, 0, this->internalFormat, this->width,
|
||||||
mImageFormat, GL_UNSIGNED_BYTE, image);
|
this->height, 0, this->imageFormat, GL_UNSIGNED_BYTE, image);
|
||||||
glGenerateMipmap(GL_TEXTURE_2D);
|
glGenerateMipmap(GL_TEXTURE_2D);
|
||||||
|
|
||||||
/* Set parameter of currently bound texture */
|
/* Set parameter of currently bound texture */
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, mWrapS);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, this->wrapS);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, mWrapT);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, this->wrapT);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, mFilterMinification);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mFilterMagnification);
|
this->filterMinification);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
|
||||||
|
this->filterMagnification);
|
||||||
|
|
||||||
/* Unbind and clean up */
|
/* Unbind and clean up */
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Texture::bind() const { glBindTexture(GL_TEXTURE_2D, mId); }
|
void Texture::bind() const { glBindTexture(GL_TEXTURE_2D, this->id); }
|
||||||
}
|
}
|
||||||
|
@ -29,13 +29,13 @@ public:
|
|||||||
Game(i32 width, i32 height);
|
Game(i32 width, i32 height);
|
||||||
~Game();
|
~Game();
|
||||||
|
|
||||||
void init(Dengine::AssetManager *assetManager);
|
void init(Dengine::AssetManager *const assetManager);
|
||||||
|
|
||||||
void processInput(f32 dt);
|
void processInput(const f32 dt);
|
||||||
void update(f32 dt);
|
void update(const f32 dt);
|
||||||
void render();
|
void render();
|
||||||
private:
|
private:
|
||||||
Dengine::Shader *shader;
|
const Dengine::Shader *shader;
|
||||||
Dengine::Sprite player;
|
Dengine::Sprite player;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -19,13 +19,14 @@ public:
|
|||||||
~AssetManager();
|
~AssetManager();
|
||||||
|
|
||||||
/* Texture */
|
/* Texture */
|
||||||
Texture *getTexture(std::string name);
|
const Texture *getTexture(const std::string name);
|
||||||
i32 loadTextureImage(std::string path, std::string name);
|
const i32 loadTextureImage(const std::string path, const std::string name);
|
||||||
|
|
||||||
/* Shaders */
|
/* Shaders */
|
||||||
Shader *getShader(std::string name);
|
const Shader *getShader(const std::string name);
|
||||||
i32 loadShaderFiles(std::string vertexPath, std::string fragmentPath,
|
const i32 loadShaderFiles(const std::string vertexPath,
|
||||||
std::string name);
|
const std::string fragmentPath,
|
||||||
|
const std::string name);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::map<std::string, Texture> mTextures;
|
std::map<std::string, Texture> mTextures;
|
||||||
|
@ -17,7 +17,7 @@ public:
|
|||||||
|
|
||||||
i32 loadProgram(GLuint vertexShader, GLuint fragmentShader);
|
i32 loadProgram(GLuint vertexShader, GLuint fragmentShader);
|
||||||
|
|
||||||
void use();
|
void use() const;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,12 +13,12 @@ public:
|
|||||||
Sprite();
|
Sprite();
|
||||||
~Sprite();
|
~Sprite();
|
||||||
|
|
||||||
b32 loadSprite(Texture *tex, glm::vec2 pos);
|
const b32 loadSprite(const Texture *tex, const glm::vec2 pos);
|
||||||
|
|
||||||
void render(Shader *shader);
|
void render(const Shader *shader) const;
|
||||||
private:
|
private:
|
||||||
glm::vec2 pos;
|
glm::vec2 pos;
|
||||||
Texture *tex;
|
const Texture *tex;
|
||||||
GLuint vbo;
|
GLuint vbo;
|
||||||
GLuint vao;
|
GLuint vao;
|
||||||
};
|
};
|
||||||
|
@ -9,35 +9,42 @@ namespace Dengine
|
|||||||
class Texture
|
class Texture
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// Holds the ID of the texture object, used for all texture operations to
|
|
||||||
// reference to this particlar texture
|
|
||||||
GLuint mId;
|
|
||||||
|
|
||||||
// Texture image dimensions
|
|
||||||
GLuint mWidth;
|
|
||||||
GLuint mHeight;
|
|
||||||
|
|
||||||
// Texture Format
|
|
||||||
GLuint mInternalFormat; // Format of texture object
|
|
||||||
GLuint mImageFormat; // Format of loaded image
|
|
||||||
|
|
||||||
// Texture configuration
|
|
||||||
GLuint mWrapS; // Wrapping mode on S axis
|
|
||||||
GLuint mWrapT; // Wrapping mode on T axis
|
|
||||||
|
|
||||||
// Filtering mode if texture pixels < screen pixels
|
|
||||||
GLuint mFilterMinification;
|
|
||||||
// Filtering mode if texture pixels > screen pixels
|
|
||||||
GLuint mFilterMagnification;
|
|
||||||
|
|
||||||
// Constructor (sets default texture modes)
|
// Constructor (sets default texture modes)
|
||||||
Texture();
|
Texture();
|
||||||
|
|
||||||
// Generates texture from image data
|
// Generates texture from image data
|
||||||
void generate(GLuint width, GLuint height, unsigned char *data);
|
void generate(const GLuint width, const GLuint height,
|
||||||
|
const u8 *const image);
|
||||||
|
|
||||||
// Binds the texture as the current active GL_TEXTURE_2D texture object
|
// Binds the texture as the current active GL_TEXTURE_2D texture object
|
||||||
void bind() const;
|
void bind() const;
|
||||||
|
|
||||||
|
inline const GLuint getWidth() const { return this->width; }
|
||||||
|
inline const GLuint getHeight() const { return this->height; }
|
||||||
|
inline const GLuint getID() const { return this->id; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
// Holds the ID of the texture object, used for all texture operations to
|
||||||
|
// reference to this particlar texture
|
||||||
|
GLuint id;
|
||||||
|
|
||||||
|
// Texture image dimensions
|
||||||
|
GLuint width;
|
||||||
|
GLuint height;
|
||||||
|
|
||||||
|
// Texture Format
|
||||||
|
GLuint internalFormat; // Format of texture object
|
||||||
|
GLuint imageFormat; // Format of loaded image
|
||||||
|
|
||||||
|
// Texture configuration
|
||||||
|
GLuint wrapS; // Wrapping mode on S axis
|
||||||
|
GLuint wrapT; // Wrapping mode on T axis
|
||||||
|
|
||||||
|
// Filtering mode if texture pixels < screen pixels
|
||||||
|
GLuint filterMinification;
|
||||||
|
// Filtering mode if texture pixels > screen pixels
|
||||||
|
GLuint filterMagnification;
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user