update shader
This commit is contained in:
parent
8f0b9b634b
commit
13aaa8cd63
@ -37,4 +37,22 @@ namespace engineapi {
|
|||||||
|
|
||||||
return text;
|
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;
|
AssetManager() = default;
|
||||||
public:
|
public:
|
||||||
static string LoadTextFile(const string& path);
|
static string LoadTextFile(const string& path);
|
||||||
|
static vector<char> LoadBinaryFile(const string& path);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
template<>
|
template<>
|
||||||
|
|||||||
@ -7,19 +7,23 @@ namespace engineapi {
|
|||||||
Scene::Scene()
|
Scene::Scene()
|
||||||
{
|
{
|
||||||
mCamera = new Camera();
|
mCamera = new Camera();
|
||||||
|
auto flags = Asset::ASSET_SHARED_FLAG | Asset::ASSET_ASYNC_FLAG;
|
||||||
|
Material* material = new Material("assets/shader/simple", flags);
|
||||||
{
|
{
|
||||||
ActorProperty property;
|
ActorProperty property;
|
||||||
property.id = 1;
|
property.id = 1;
|
||||||
property.flags = Asset::ASSET_SHARED_FLAG | Asset::ASSET_ASYNC_FLAG;
|
property.flags = flags;
|
||||||
property.path = "assets/models/cube.obj";
|
property.path = "assets/models/cube.obj";
|
||||||
actor1 = ActorMesh::New(property);
|
actor1 = ActorMesh::New(property);
|
||||||
|
actor1->Ptr().SetMaterial(material);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
ActorProperty property;
|
ActorProperty property;
|
||||||
property.id = 1;
|
property.id = 1;
|
||||||
property.flags = Asset::ASSET_SHARED_FLAG | Asset::ASSET_ASYNC_FLAG;
|
property.flags = flags;
|
||||||
property.path = "assets/models/box.ply";
|
property.path = "assets/models/box.ply";
|
||||||
actor2 = ActorMesh::New(property);
|
actor2 = ActorMesh::New(property);
|
||||||
|
actor2->Ptr().SetMaterial(material);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Scene::~Scene()
|
Scene::~Scene()
|
||||||
|
|||||||
@ -1,10 +1,11 @@
|
|||||||
#include "material.h"
|
#include "material.h"
|
||||||
|
#include "asset/asset_manager.h"
|
||||||
#include "../renderapi.h"
|
#include "../renderapi.h"
|
||||||
namespace engineapi {
|
namespace engineapi {
|
||||||
Material::Material(string name, uint32_t flags)
|
Material::Material(string name, uint32_t flags)
|
||||||
:Asset(name, flags)
|
:Asset(name, flags)
|
||||||
{
|
{
|
||||||
|
auto vertShader = AssetManager::LoadBinaryFile(name);
|
||||||
}
|
}
|
||||||
Material::~Material()
|
Material::~Material()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
#include "model.h"
|
#include "model.h"
|
||||||
#include "zlog.h"
|
#include "zlog.h"
|
||||||
#include "mesh.h"
|
|
||||||
#include "assimp/Importer.hpp"
|
#include "assimp/Importer.hpp"
|
||||||
#include "assimp/scene.h"
|
#include "assimp/scene.h"
|
||||||
#include "assimp/postprocess.h"
|
#include "assimp/postprocess.h"
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "asset_render.h"
|
#include "asset_render.h"
|
||||||
|
#include "mesh.h"
|
||||||
|
#include "material.h"
|
||||||
class aiNode;
|
class aiNode;
|
||||||
class aiMesh;
|
class aiMesh;
|
||||||
class aiScene;
|
class aiScene;
|
||||||
@ -7,7 +9,7 @@ namespace engineapi {
|
|||||||
class Model : public Asset {
|
class Model : public Asset {
|
||||||
protected:
|
protected:
|
||||||
vector<Mesh*> mMeshes;
|
vector<Mesh*> mMeshes;
|
||||||
|
Material* mMaterial;
|
||||||
public:
|
public:
|
||||||
using Asset::Asset;
|
using Asset::Asset;
|
||||||
void BeginLoad()override;
|
void BeginLoad()override;
|
||||||
@ -16,6 +18,9 @@ namespace engineapi {
|
|||||||
vector<Mesh*>& GetMeshs() {
|
vector<Mesh*>& GetMeshs() {
|
||||||
return mMeshes;
|
return mMeshes;
|
||||||
}
|
}
|
||||||
|
void SetMaterial(Material* material) {
|
||||||
|
mMaterial = material;
|
||||||
|
}
|
||||||
void Use();
|
void Use();
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
Loading…
Reference in New Issue
Block a user