-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from BSBussell/TextureManager
Texture manager
- Loading branch information
Showing
22 changed files
with
283 additions
and
346 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ | |
#define BML_H | ||
|
||
#include <string> | ||
#include <cstdint> | ||
|
||
#include <SDL2/SDL.h> | ||
#include <SDL2/SDL_image.h> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,61 @@ | ||
|
||
// Bee Bussell | ||
// Sept 6, 2021 | ||
// Header | ||
// bTexture/manager | ||
|
||
#ifndef BML_TEXTURE_H | ||
#define BML_TEXTURE_H | ||
|
||
#include <SDL2/SDL.h> | ||
#include <memory> | ||
#include <string> | ||
#include <unordered_map> | ||
|
||
// Just a header file for now | ||
#include <SDL2/SDL.h> | ||
#include <SDL2/SDL_image.h> | ||
|
||
// TODO: Implement texture freeing and destructer for that | ||
#include "bRect.h" | ||
|
||
// @brief Data structure used for storing texture info | ||
struct bTexture { | ||
|
||
SDL_Texture* texture; | ||
|
||
std::string path; | ||
|
||
SDL_Texture *texture; | ||
SDL_Rect src; | ||
|
||
}; | ||
|
||
// @brief Class for mananging usage of textures | ||
class bTextureManager { | ||
|
||
public: | ||
|
||
bTextureManager(SDL_Renderer *renderer); | ||
~bTextureManager(); | ||
|
||
// Load the texture either by creating a new one or grabbing it from the cache | ||
bTexture loadTexture(const char *path, bRect dim); | ||
|
||
// Unloads the texture, if it's not being used by anything else | ||
void unloadTexture(bTexture texture); | ||
|
||
// Does not delete bTextures, User still has to do that on ther own | ||
void clearCache(); | ||
|
||
// Rendering the Texture either using a rect or a point | ||
void renderTexture(bTexture &texture, bRect dest); | ||
void renderTexture(bTexture &texture, bPoint dest); | ||
|
||
|
||
private: | ||
|
||
SDL_Renderer *_sdl_renderer; | ||
|
||
// Cache | ||
std::unordered_map<std::string, SDL_Texture*> _loaded_textures; | ||
std::unordered_map<SDL_Texture*, Uint8> _refs; | ||
|
||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.