-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathResourceManager.h
125 lines (105 loc) · 4.08 KB
/
ResourceManager.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
//-----------------------------------------------------------------
// Resource Manager class
//-----------------------------------------------------------------
#pragma once
//-----------------------------------------------------------------
// Include Files
//-----------------------------------------------------------------
#include "AssetIOHandler.h"
#include <GL/glew.h>
#include <d3dcompiler.h>
#include <d3dcommon.h>
#include "jpeglib.h"
#include "png.h"
#include <map>
#include <string>
namespace Emerald
{
//-----------------------------------------------------------------
//data structure definitions
//-----------------------------------------------------------------
struct GLSLShader
{
GLuint type;
LPWSTR pFileName;
int index;//index into the text resource pool
};
struct GLSLEffect
{
GLSLShader* pGLSLShaders;
int glShaderCount;
LPWSTR pEffectName;
int effectProgramIndex;//index into the GLSLEffectProgram pool maintained by OpenglRenderer
LPWSTR* ppAttribNames;
int attribCount;
};
struct Mesh//mesh structure for storing model information, very crude for now
{
float* pPositions;
float* pColours;
int vertexCount;
int vertexSize;//the dimension of a vertex
};
struct Texture2D
{
//texture data info
GLsizei width;
GLsizei height;
GLenum pixelFormatClient;
GLenum channelType;
GLint pixelDataAlignment;//1, 2, 4 or 8
GLint pixelFormatInternal;
//texture paramter for openGL
GLint minFilter;
GLint magFilter;
GLint wrapS;
GLint wrapT;
BYTE* pData;
};
//-----------------------------------------------------------------
// Resource Manager Class
//-----------------------------------------------------------------
class ResourceManager
{
protected:
AssetIOHandler* m_pAssetIOHandler;
//text resource pool
LPWSTR* m_ppTextResources;
int m_textResourceCount;
int m_currentTextResourceIndex;
//GLSL shader effect resource pool
GLSLEffect* m_pGLSLEffectResources;
int m_GLSLEffectResourceCount;
int m_currentGLSLEffectResourceIndex;
//D3D11 shader resouce pool
std::map<std::string, ID3D10Blob*> m_HLSLShaderCodes;
//mesh resource pool
Mesh* m_pMeshResources;
int m_meshResourceCount;
int m_currentMeshResourceIndex;
//texture resource pool
Texture2D* m_pTexture2DResources;
int m_texture2DResourceCount;
int m_currentTexture2DResourceIndex;
private:
void DestroyGLSLEffectPool();
void DestroyHLSLShaderPool();
public:
//Constructor/Destructor
ResourceManager();
virtual ~ResourceManager();
//General class functions
int GenerateTextResource(LPCWSTR pFileName, LPCWSTR pType);
int GenerateGLSLEffectResource(GLSLShader* pRequiredShaders, int requiredShaderCount, LPWSTR pName, LPWSTR* ppAttribs, int attribNum);
HRESULT GenerateHLSLShaderResource();
//the actual signature: int GenerateMeshResource(LPCWSTR fileName, LPCWSTR type); but for now:
int GenerateMeshResource(Mesh* pMeshData);
int GenerateTexture2DResource(LPCWSTR pFileName, LPCWSTR pType);
//Accessors
LPCWSTR GetTextResource(int index) { return m_ppTextResources[index]; }//to add: boundary check
const int GetTextResourceCount() { return m_textResourceCount; }
const GLSLEffect GetGLSLEffectResource(int index) { return m_pGLSLEffectResources[index]; }
const Mesh GetMeshResource(int index) { return m_pMeshResources[index]; }
ID3D10Blob* GetHLSLShader(std::string name);
};
}