kick
/Users/morten/Programmering/cpp/kick/src/kick/core/project.h
00001 //
00002 //  project.h
00003 //  KickCPP
00004 //
00005 //  Created by morten on 8/25/13.
00006 //  Copyright (c) 2013 Morten Nobel-Joergensen. All rights reserved.
00007 //
00008 
00009 #pragma once
00010 
00011 #include <iostream>
00012 #include <memory>
00013 #include <unordered_map>
00014 #include <vector>
00015 
00016 #include "kick/core/project_asset.h"
00017 #include "kick/texture/texture2d.h"
00018 #include "kick/material/shader.h"
00019 #include "kick/texture/texture_atlas.h"
00020 
00021 // forward declaration
00022 struct SDL_Surface;
00023 
00024 namespace kick {
00025     class Engine;
00026     class TextureAtlas;
00027     class Font;
00028 
00029     class Project {
00030     public:
00031         // Create a new material with a specific shader attached
00032         // Returns nullptr if shader cannot be loaded
00033         static Material *createMaterial(std::string shaderUri = "assets/shaders/diffuse.shader");
00034 
00035         static bool loadTextResource(std::string uri, std::string &outText);
00036         static bool loadBinaryResource(std::string uri, std::vector<char> &outResource);
00037         static std::shared_ptr<Shader> loadShader(std::string uri);
00038         static std::shared_ptr<Texture2D> loadTexture2D(std::string uri, TextureSampler sampler = {});
00039         static std::shared_ptr<Font> loadFont(int fontsize = 16);
00040         static std::shared_ptr<Font> loadFont(std::string fontName = "assets/font/open_sans_28.fnt");
00041         static std::shared_ptr<Texture2D> loadTexture2DFromMemory(const char *data, int size);
00042 
00043         static std::shared_ptr<TextureCube> loadTextureCube(std::string uri);
00044         static TextureCube* loadTextureCubeFromMemory(const char *data, int size);
00045 
00046         // filename should be the .txt file. There should be a png file with the same name in the same folder containing
00047         // the actual sprites
00048         static std::shared_ptr<TextureAtlas> loadTextureAtlas(std::string filename);
00049 
00050         friend class ProjectAsset;
00051         friend class Engine;
00052     private:
00053         Project();
00054         Project(const Project&) = delete;
00055         Project(Project&&) = delete;
00056 
00057         static Texture2D *surfaceToTexture2D( SDL_Surface *image, TextureSampler sampler = {});
00058 
00059         static TextureCube *surfaceToTextureCube(SDL_Surface *image);
00060 
00061         static std::map<std::string, std::weak_ptr<TextureAtlas>> textureAtlasRef;
00062         static std::map<std::string, std::weak_ptr<Shader>> shaderRef;
00063         static std::map<std::string, std::weak_ptr<Texture2D>> texture2DRef;
00064         static std::map<std::string, std::weak_ptr<TextureCube>> textureCubeRef;
00065         static std::map<std::string, std::weak_ptr<Font>> fontRef;
00066 
00067 
00068     };
00069 }
 All Classes Functions Variables