Major Update - Complete Rework Texture System - V10.0.0
This commit is contained in:
@@ -22,7 +22,78 @@ using namespace std;
|
||||
///////////////////////
|
||||
#include "textureclass.h"
|
||||
|
||||
enum class TextureType
|
||||
{
|
||||
Diffuse,
|
||||
Normal,
|
||||
Specular,
|
||||
Alpha
|
||||
};
|
||||
|
||||
struct TextureContainer
|
||||
{
|
||||
std::vector<ID3D11ShaderResourceView*> diffuse;
|
||||
std::vector<ID3D11ShaderResourceView*> normal;
|
||||
std::vector<ID3D11ShaderResourceView*> specular;
|
||||
std::vector<ID3D11ShaderResourceView*> alpha;
|
||||
|
||||
std::vector<ID3D11ShaderResourceView*>& Get(TextureType type) const {
|
||||
switch (type) {
|
||||
case TextureType::Diffuse: return const_cast<std::vector<ID3D11ShaderResourceView*>&>(diffuse);
|
||||
case TextureType::Normal: return const_cast<std::vector<ID3D11ShaderResourceView*>&>(normal);
|
||||
case TextureType::Specular: return const_cast<std::vector<ID3D11ShaderResourceView*>&>(specular);
|
||||
case TextureType::Alpha: return const_cast<std::vector<ID3D11ShaderResourceView*>&>(alpha);
|
||||
default: return const_cast<std::vector<ID3D11ShaderResourceView*>&>(diffuse);
|
||||
}
|
||||
}
|
||||
|
||||
ID3D11ShaderResourceView* GetTexture(TextureType type, int index) const {
|
||||
auto& vec = Get(type);
|
||||
if (index >= 0 && index < vec.size())
|
||||
return vec[index];
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void ReleaseAll() {
|
||||
ReleaseVector(diffuse);
|
||||
ReleaseVector(normal);
|
||||
ReleaseVector(specular);
|
||||
ReleaseVector(alpha);
|
||||
}
|
||||
|
||||
void AssignTexture(TextureContainer& textContainer, ID3D11ShaderResourceView* texture, int index)
|
||||
{
|
||||
switch (index)
|
||||
{
|
||||
case 0:
|
||||
textContainer.diffuse.push_back(texture);
|
||||
break;
|
||||
case 1:
|
||||
textContainer.normal.push_back(texture);
|
||||
break;
|
||||
case 2:
|
||||
textContainer.specular.push_back(texture);
|
||||
break;
|
||||
case 3:
|
||||
textContainer.alpha.push_back(texture);
|
||||
break;
|
||||
default:
|
||||
textContainer.diffuse.push_back(texture);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
void ReleaseVector(std::vector<ID3D11ShaderResourceView*>& vec) {
|
||||
for (auto& tex : vec) {
|
||||
if (tex) {
|
||||
tex->Release();
|
||||
tex = nullptr;
|
||||
}
|
||||
}
|
||||
vec.clear();
|
||||
}
|
||||
};
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Class name: ModelClass
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -83,15 +154,25 @@ public:
|
||||
ModelClass(const ModelClass&);
|
||||
~ModelClass();
|
||||
|
||||
bool Initialize(ID3D11Device*, ID3D11DeviceContext*, char*, std::vector<ID3D11ShaderResourceView*>);
|
||||
|
||||
//bool Initialize(ID3D11Device*, ID3D11DeviceContext*, char*, std::vector<ID3D11ShaderResourceView*>);
|
||||
// Nouvelle surcharge avec TextureContainer
|
||||
bool Initialize(ID3D11Device*, ID3D11DeviceContext*, char*, const TextureContainer&);
|
||||
// Nouvelle m<>thode - initialisation sans textures
|
||||
bool Initialize(ID3D11Device*, ID3D11DeviceContext*, char*);
|
||||
void Shutdown();
|
||||
void Render(ID3D11DeviceContext*);
|
||||
|
||||
int GetIndexCount();
|
||||
ID3D11ShaderResourceView* GetTexture(int index) const;
|
||||
bool ChangeTexture(ID3D11Device*, ID3D11DeviceContext*, std::wstring filename, int index);
|
||||
//ID3D11ShaderResourceView* GetTexture(int index) const;
|
||||
ID3D11ShaderResourceView* GetTexture(TextureType type, int index) const;
|
||||
|
||||
//bool ChangeTexture(ID3D11Device* device, ID3D11DeviceContext* deviceContext, std::wstring filename, int index);
|
||||
bool ChangeTexture(ID3D11Device* device, ID3D11DeviceContext* deviceContext,std::wstring filename, TextureType type, int index);
|
||||
|
||||
// M<>thodes pour ajouter une nouvelle texture
|
||||
bool AddTexture(ID3D11Device* device, ID3D11DeviceContext* deviceContext,std::wstring filename, TextureType type);
|
||||
bool AddTexture(ID3D11ShaderResourceView* texture, TextureType type);
|
||||
|
||||
private:
|
||||
bool InitializeBuffers(ID3D11Device*);
|
||||
void ShutdownBuffers();
|
||||
@@ -106,11 +187,10 @@ private:
|
||||
|
||||
void CalculateModelVectors();
|
||||
void CalculateTangentBinormal(TempVertexType, TempVertexType, TempVertexType, VectorType&, VectorType&);
|
||||
|
||||
private:
|
||||
|
||||
ID3D11Buffer* m_vertexBuffer, * m_indexBuffer;
|
||||
int m_vertexCount, m_indexCount;
|
||||
std::vector<ID3D11ShaderResourceView*> m_Textures;
|
||||
TextureContainer m_Textures;
|
||||
ModelType* m_model;
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user