add LoadTextuer2D function at RenderResource
This commit is contained in:
parent
8f78e6ea18
commit
96c237e504
@ -15,10 +15,6 @@ using namespace hgl::graph;
|
||||
constexpr uint32_t SCREEN_WIDTH=1280;
|
||||
constexpr uint32_t SCREEN_HEIGHT=720;
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
Texture2D *CreateTextureFromFile(GPUDevice *device,const OSString &filename);
|
||||
VK_NAMESPACE_END
|
||||
|
||||
struct PhongLight
|
||||
{
|
||||
Vector4f color;
|
||||
@ -97,11 +93,8 @@ private:
|
||||
{
|
||||
texture.sampler =db->CreateSampler();
|
||||
|
||||
texture.color =CreateTextureFromFile(device,OS_TEXT("res/image/Brickwall/Albedo.Tex2D"));
|
||||
texture.normal =CreateTextureFromFile(device,OS_TEXT("res/image/Brickwall/Normal.Tex2D"));
|
||||
|
||||
db->Add(texture.color);
|
||||
db->Add(texture.normal);
|
||||
texture.color =db->LoadTexture2D(OS_TEXT("res/image/Brickwall/Albedo.Tex2D"));
|
||||
texture.normal =db->LoadTexture2D(OS_TEXT("res/image/Brickwall/Normal.Tex2D"));
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -35,6 +35,7 @@ class RenderResource
|
||||
|
||||
MapObject<OSString,ShaderModule> shader_module_by_name;
|
||||
Map<OSString,Material *> material_by_name;
|
||||
Map<OSString,Texture *> texture_by_name;
|
||||
|
||||
IDResManage<MaterialID, Material> rm_material; ///<材质合集
|
||||
IDResManage<MaterialInstanceID, MaterialInstance> rm_material_instance; ///<材质实例合集
|
||||
@ -58,7 +59,7 @@ public: //Add
|
||||
PipelineID Add(Pipeline * p ){return rm_pipeline.Add(p);}
|
||||
DescriptorSetsID Add(DescriptorSets * ds ){return rm_desc_sets.Add(ds);}
|
||||
RenderableID Add(Renderable * r ){return rm_renderables.Add(r);}
|
||||
BufferID Add(GPUBuffer * buf ){return rm_buffers.Add(buf);}
|
||||
BufferID Add(GPUBuffer * buf ){return rm_buffers.Add(buf);}
|
||||
SamplerID Add(Sampler * s ){return rm_samplers.Add(s);}
|
||||
TextureID Add(Texture * t ){return rm_textures.Add(t);}
|
||||
RenderableInstanceID Add(RenderableInstance *ri ){return rm_renderable_instances.Add(ri);}
|
||||
@ -112,6 +113,10 @@ public: //Material
|
||||
|
||||
Sampler * CreateSampler(VkSamplerCreateInfo *sci=nullptr);
|
||||
|
||||
public: //texture
|
||||
|
||||
Texture2D * LoadTexture2D(const OSString &);
|
||||
|
||||
public: //Get
|
||||
|
||||
Material * GetMaterial (const MaterialID &id){return rm_material.Get(id);}
|
||||
|
@ -167,4 +167,24 @@ Sampler *RenderResource::CreateSampler(VkSamplerCreateInfo *sci)
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
Texture2D *CreateTextureFromFile(GPUDevice *device,const OSString &filename);
|
||||
|
||||
Texture2D *RenderResource::LoadTexture2D(const OSString &filename)
|
||||
{
|
||||
Texture2D *tex;
|
||||
|
||||
if(texture_by_name.Get(filename,(Texture *&)tex))
|
||||
return tex;
|
||||
|
||||
tex=CreateTextureFromFile(device,filename);
|
||||
|
||||
if(tex)
|
||||
{
|
||||
texture_by_name.Add(filename,tex);
|
||||
Add(tex);
|
||||
}
|
||||
|
||||
return tex;
|
||||
}
|
||||
VK_NAMESPACE_END
|
||||
|
Loading…
x
Reference in New Issue
Block a user