update shader
This commit is contained in:
parent
8f0b9b634b
commit
13aaa8cd63
@ -37,4 +37,22 @@ namespace engineapi {
|
||||
|
||||
return text;
|
||||
}
|
||||
vector<char> AssetManager::LoadBinaryFile(const string& path)
|
||||
{
|
||||
// ate:在文件末尾开始读取,从文件末尾开始读取的优点是我们可以使用读取位置来确定文件的大小并分配缓冲区
|
||||
ifstream file(path, std::ios::ate | std::ios::binary);
|
||||
if (!file.is_open())
|
||||
zlog::info("Failed to load binary file: {}", path);
|
||||
|
||||
// 使用读取位置来确定文件的大小并分配缓冲区
|
||||
size_t fileSize = (size_t)file.tellg();
|
||||
vector<char> data(fileSize);
|
||||
|
||||
// 返回文件开头,真正读取内容
|
||||
file.seekg(0);
|
||||
file.read(data.data(), fileSize);
|
||||
file.close();
|
||||
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
@ -49,6 +49,7 @@ namespace engineapi
|
||||
AssetManager() = default;
|
||||
public:
|
||||
static string LoadTextFile(const string& path);
|
||||
static vector<char> LoadBinaryFile(const string& path);
|
||||
};
|
||||
}
|
||||
template<>
|
||||
|
||||
@ -7,19 +7,23 @@ namespace engineapi {
|
||||
Scene::Scene()
|
||||
{
|
||||
mCamera = new Camera();
|
||||
auto flags = Asset::ASSET_SHARED_FLAG | Asset::ASSET_ASYNC_FLAG;
|
||||
Material* material = new Material("assets/shader/simple", flags);
|
||||
{
|
||||
ActorProperty property;
|
||||
property.id = 1;
|
||||
property.flags = Asset::ASSET_SHARED_FLAG | Asset::ASSET_ASYNC_FLAG;
|
||||
property.flags = flags;
|
||||
property.path = "assets/models/cube.obj";
|
||||
actor1 = ActorMesh::New(property);
|
||||
actor1->Ptr().SetMaterial(material);
|
||||
}
|
||||
{
|
||||
ActorProperty property;
|
||||
property.id = 1;
|
||||
property.flags = Asset::ASSET_SHARED_FLAG | Asset::ASSET_ASYNC_FLAG;
|
||||
property.flags = flags;
|
||||
property.path = "assets/models/box.ply";
|
||||
actor2 = ActorMesh::New(property);
|
||||
actor2->Ptr().SetMaterial(material);
|
||||
}
|
||||
}
|
||||
Scene::~Scene()
|
||||
|
||||
@ -1,10 +1,11 @@
|
||||
#include "material.h"
|
||||
#include "asset/asset_manager.h"
|
||||
#include "../renderapi.h"
|
||||
namespace engineapi {
|
||||
Material::Material(string name, uint32_t flags)
|
||||
:Asset(name, flags)
|
||||
{
|
||||
|
||||
auto vertShader = AssetManager::LoadBinaryFile(name);
|
||||
}
|
||||
Material::~Material()
|
||||
{
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
#include "model.h"
|
||||
#include "zlog.h"
|
||||
#include "mesh.h"
|
||||
#include "assimp/Importer.hpp"
|
||||
#include "assimp/scene.h"
|
||||
#include "assimp/postprocess.h"
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
#include "asset_render.h"
|
||||
#include "mesh.h"
|
||||
#include "material.h"
|
||||
class aiNode;
|
||||
class aiMesh;
|
||||
class aiScene;
|
||||
@ -7,7 +9,7 @@ namespace engineapi {
|
||||
class Model : public Asset {
|
||||
protected:
|
||||
vector<Mesh*> mMeshes;
|
||||
|
||||
Material* mMaterial;
|
||||
public:
|
||||
using Asset::Asset;
|
||||
void BeginLoad()override;
|
||||
@ -16,6 +18,9 @@ namespace engineapi {
|
||||
vector<Mesh*>& GetMeshs() {
|
||||
return mMeshes;
|
||||
}
|
||||
void SetMaterial(Material* material) {
|
||||
mMaterial = material;
|
||||
}
|
||||
void Use();
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue
Block a user