mirror of
https://github.com/devZoGok/vb01.git
synced 2026-08-26 19:43:30 +00:00
moved texture GPU data loading to Root
reordered node and mesh rendering data generation materials no longer create their own shaders
This commit is contained in:
+13
-7
@@ -61,23 +61,16 @@ namespace vb01{
|
||||
|
||||
string format = file.substr(file.find_last_of(".") + 1, string::npos);
|
||||
AbstractAssetReader *assetReader = nullptr;
|
||||
vector<string> imageFormats = vector<string>{"png", "jpeg", "jpg"};
|
||||
|
||||
if(find(imageFormats.begin(), imageFormats.end(), format) != imageFormats.end())
|
||||
assetReader = ImageReader::getSingleton();
|
||||
|
||||
vector<string> fontFormats = vector<string>{"ttf"};
|
||||
|
||||
if(find(fontFormats.begin(), fontFormats.end(), format) != fontFormats.end())
|
||||
assetReader = FontReader::getSingleton();
|
||||
|
||||
vector<string> modelFormats = vector<string>{"xml"};
|
||||
|
||||
if(find(modelFormats.begin(), modelFormats.end(), format) != modelFormats.end())
|
||||
assetReader = XmlModelReader::getSingleton();
|
||||
|
||||
vector<string> shaderFormats = vector<string>{"vert", "frag", "geo"};
|
||||
|
||||
if(find(shaderFormats.begin(), shaderFormats.end(), format) != shaderFormats.end())
|
||||
assetReader = ShaderReader::getSingleton();
|
||||
|
||||
@@ -96,6 +89,19 @@ namespace vb01{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
vector<Asset*> AssetManager::getAssets(vector<string> formats){
|
||||
vector<Asset*> formatAssets;
|
||||
|
||||
for(Asset *a : assets){
|
||||
string format = a->path.substr(a->path.find_last_of(".") + 1, string::npos);
|
||||
|
||||
if(find(formats.begin(), formats.end(), format) != formats.end())
|
||||
formatAssets.push_back(a);
|
||||
}
|
||||
|
||||
return formatAssets;
|
||||
}
|
||||
|
||||
void AssetManager::editAsset(string path, Asset &newAsset){
|
||||
ShaderAsset *oldAsset = (ShaderAsset*)getAsset(path);
|
||||
|
||||
|
||||
@@ -15,6 +15,11 @@ namespace vb01{
|
||||
void load(std::string, bool = false);
|
||||
void editAsset(std::string, Asset&);
|
||||
Asset* getAsset(std::string);
|
||||
std::vector<Asset*> getAssets(std::vector<std::string>);
|
||||
inline std::vector<std::string> getImageFormats(){return imageFormats;}
|
||||
inline std::vector<std::string> getShaderFormats(){return shaderFormats;}
|
||||
inline std::vector<std::string> getModelFormats(){return modelFormats;}
|
||||
inline std::vector<std::string> getFontFormats(){return fontFormats;}
|
||||
inline Asset* getAsset(int i){return assets[i];}
|
||||
inline std::vector<Asset*> getAssets(){return assets;}
|
||||
inline int getNumAssets(){return assets.size();}
|
||||
@@ -22,6 +27,10 @@ namespace vb01{
|
||||
AssetManager(){}
|
||||
|
||||
std::vector<Asset*> assets;
|
||||
const std::vector<std::string> imageFormats = std::vector<std::string>{"png", "jpeg", "jpg"};
|
||||
const std::vector<std::string> shaderFormats = std::vector<std::string>{"vert", "frag", "geo"};
|
||||
const std::vector<std::string> modelFormats = std::vector<std::string>{"xml"};
|
||||
const std::vector<std::string> fontFormats = std::vector<std::string>{"ttf"};
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
+13
-11
@@ -4,18 +4,20 @@
|
||||
#include "asset.h"
|
||||
|
||||
namespace vb01{
|
||||
struct ImageAsset : public Asset{
|
||||
ImageAsset(std::string path, u8 *image, int width, int height, int numChannels){
|
||||
this->path = path;
|
||||
this->image = image;
|
||||
this->width = width;
|
||||
this->height = height;
|
||||
this->numChannels = numChannels;
|
||||
}
|
||||
struct ImageAsset : public Asset{
|
||||
ImageAsset(std::string p, u8 *img, int w, int h, int nc, int lid) :
|
||||
image(img),
|
||||
width(w),
|
||||
height(h),
|
||||
numChannels(nc),
|
||||
layerId(lid)
|
||||
{
|
||||
this->path = p;
|
||||
}
|
||||
|
||||
u8 *image;
|
||||
int width, height, numChannels;
|
||||
};
|
||||
u8 *image;
|
||||
int width, height, numChannels, layerId;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+4
-2
@@ -1,4 +1,5 @@
|
||||
#include "imageReader.h"
|
||||
#include "root.h"
|
||||
|
||||
#include "stb_image.h"
|
||||
|
||||
@@ -16,8 +17,9 @@ namespace vb01{
|
||||
|
||||
Asset* ImageReader::readAsset(string path){
|
||||
stbi_set_flip_vertically_on_load(flip);
|
||||
int width, height, numChannels;
|
||||
int width, height, numChannels, layerId;
|
||||
u8 *data = stbi_load(path.c_str(), &width, &height, &numChannels, 0);
|
||||
return new ImageAsset(path, data, width, height, numChannels);
|
||||
Root::getSingleton()->initTextureDataOnGpu(Root::getSingleton()->getMeshTextureBuffer(), data, width, height, layerId);
|
||||
return new ImageAsset(path, data, width, height, numChannels, layerId);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-4
@@ -1,14 +1,11 @@
|
||||
#include "material.h"
|
||||
#include "shader.h"
|
||||
#include "root.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace glm;
|
||||
|
||||
namespace vb01{
|
||||
Material::Material(string shaderName, bool geometryShader){
|
||||
shader = new Shader(shaderName);
|
||||
}
|
||||
Material::Material(Shader *sh) : shader(sh){}
|
||||
|
||||
Material::~Material(){
|
||||
delete shader;
|
||||
|
||||
+1
-1
@@ -139,7 +139,7 @@ namespace vb01{
|
||||
}
|
||||
};
|
||||
|
||||
Material(std::string, bool = false);
|
||||
Material(Shader*);
|
||||
~Material();
|
||||
void update();
|
||||
void setIntUniform(std::string, int);
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "camera.h"
|
||||
#include "lineRenderer.h"
|
||||
#include "assetManager.h"
|
||||
#include "imageAsset.h"
|
||||
#include "animationController.h"
|
||||
|
||||
#include "glad.h"
|
||||
@@ -65,6 +66,15 @@ namespace vb01{
|
||||
glGenBuffers(1, &drawCmdBuffer);
|
||||
glGenBuffers(1, &objVertBuffer);
|
||||
glGenBuffers(1, &objFragBuffer);
|
||||
|
||||
guiPlaneTextureBuffer = new u32;
|
||||
glGenTextures(1, guiPlaneTextureBuffer);
|
||||
|
||||
meshTextureBuffer = new u32[NUM_MAX_TEXTURE_UNITS];
|
||||
glGenTextures(NUM_MAX_TEXTURE_UNITS, meshTextureBuffer);
|
||||
glBindTexture(GL_TEXTURE_2D_ARRAY, meshTextureBuffer[0]);
|
||||
|
||||
phongShader = new Shader(libPath + "phong4");
|
||||
|
||||
initMeshRendering(meshVAO, meshVBO, meshEBO);
|
||||
initParticleRendering();
|
||||
@@ -113,6 +123,67 @@ namespace vb01{
|
||||
*/
|
||||
}
|
||||
|
||||
void Root::initTextureDataOnGpu(int width, int height){
|
||||
glBindTexture(GL_TEXTURE_2D, guiPlaneTextureBuffer[0]);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
|
||||
|
||||
//textureGpuData.push_back(TextureGpuData(textureBuffer, , width, height));
|
||||
}
|
||||
|
||||
void Root::initTextureDataOnGpu(u32 *textureBuffer, u8 *data, int width, int height, int &layerId){
|
||||
bool present = false;
|
||||
|
||||
for(pair<int, int> &p : currTextureDims)
|
||||
if(p.first == width && p.second == height){
|
||||
present = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if(!present) currTextureDims.push_back(make_pair(width, height));
|
||||
|
||||
AssetManager *assetManager = AssetManager::getSingleton();
|
||||
vector<Asset*> assets = assetManager->getAssets(assetManager->getImageFormats());
|
||||
|
||||
for(int i = 0; i < currTextureDims.size(); i++){
|
||||
vector<ImageAsset*> imgAssets;
|
||||
pair<int, int> &resPair = currTextureDims[i];
|
||||
|
||||
for(Asset *asset : assets){
|
||||
ImageAsset *a = (ImageAsset*)asset;
|
||||
|
||||
if(a->width == resPair.first && a->height == resPair.second)
|
||||
imgAssets.push_back((ImageAsset*)asset);
|
||||
}
|
||||
|
||||
//layerId = currNumLayers, currNumLayers++;
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D_ARRAY, textureBuffer[i]);
|
||||
glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, resPair.first, resPair.second, imgAssets.size() + 1, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
|
||||
|
||||
for(int i = 0; i < imgAssets.size(); i++)
|
||||
glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, i, width, height, 1, GL_RGB, GL_UNSIGNED_BYTE, imgAssets[i]->image);
|
||||
|
||||
if(resPair.first == width && resPair.second == height){
|
||||
int lid = 0 + (imgAssets.size() == 0 ? 0 : 1);
|
||||
layerId = lid;
|
||||
glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, lid, width, height, 1, GL_RGB, GL_UNSIGNED_BYTE, data);
|
||||
}
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
}
|
||||
|
||||
//textureGpuData.push_back(TextureGpuData(textureBuffer, , width, height));
|
||||
}
|
||||
|
||||
void Root::initVertexDataOnGpu(MeshData &meshData, u32 &VAO, u32 &VBO, u32 &EBO, bool updateDrawCommands){
|
||||
glBindVertexArray(VAO);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||
@@ -167,8 +238,8 @@ namespace vb01{
|
||||
for(int i = 0; i < 2; i++)
|
||||
pingPongTextures[i] = new Texture(width, height, false);
|
||||
|
||||
Texture *fragTexture = new Texture(width, height, false);
|
||||
Texture *brightTexture = new Texture(width, height, false);
|
||||
//Texture *fragTexture = new Texture(width, height, false);
|
||||
//Texture *brightTexture = new Texture(width, height, false);
|
||||
}
|
||||
|
||||
void Root::addMeshes(Node *rootNode){
|
||||
@@ -250,7 +321,7 @@ namespace vb01{
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, FBO);
|
||||
|
||||
u32 colorAttachments[]{GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1};
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, colorAttachments[0], GL_TEXTURE_2D, *fragTexture->getTexture(), 0);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, colorAttachments[0], GL_TEXTURE_2D, *guiPlaneTextureBuffer, 0);
|
||||
|
||||
if(brightTexture){
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, colorAttachments[1], GL_TEXTURE_2D, *brightTexture->getTexture(), 0);
|
||||
@@ -276,7 +347,7 @@ namespace vb01{
|
||||
initMeshRendering(guiPlaneVAO, guiPlaneVBO, guiPlaneEBO);
|
||||
initVertexDataOnGpu(guiPlane->getMeshBase(), guiPlaneVAO, guiPlaneVBO, guiPlaneEBO, false);
|
||||
|
||||
Material *mat = new Material(libPath + "postProcess");
|
||||
Material *mat = new Material(new Shader(libPath + "postProcess"));
|
||||
mat->addTexUniform("frag", pingPongTextures[0], false);
|
||||
mat->addTexUniform("bright", pingPongTextures[1], false);
|
||||
guiPlane->setMaterial(mat);
|
||||
@@ -355,6 +426,11 @@ namespace vb01{
|
||||
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, objFragBuffer);
|
||||
*/
|
||||
|
||||
for(int i = 0; i < currTextureDims.size(); i++){
|
||||
glActiveTexture(GL_TEXTURE0 + i);
|
||||
glBindTexture(GL_TEXTURE_2D_ARRAY, meshTextureBuffer[i]);
|
||||
}
|
||||
|
||||
glBindVertexArray(meshVAO);
|
||||
|
||||
glBindBuffer(GL_DRAW_INDIRECT_BUFFER, drawCmdBuffer);
|
||||
@@ -371,123 +447,27 @@ namespace vb01{
|
||||
void Root::renderGui(vector<Mesh*> &meshes){
|
||||
}
|
||||
|
||||
void Root::updateNode(Node *node, mat4 &proj, mat4 &view, bool gui){
|
||||
Quaternion orient = Quaternion::QUAT_W;
|
||||
Vector3 pos = Vector3::VEC_ZERO, scale = Vector3::VEC_IJK;
|
||||
|
||||
if(!gui){
|
||||
pos = node->localToGlobalPosition(Vector3::VEC_ZERO);
|
||||
orient = node->localToGlobalOrientation(Quaternion::QUAT_W);
|
||||
scale = node->getScale();
|
||||
}
|
||||
|
||||
Vector3 rotAxis = orient.getAxis();
|
||||
|
||||
if(rotAxis == Vector3::VEC_ZERO)
|
||||
rotAxis = Vector3::VEC_I;
|
||||
|
||||
mat4 model = mat4(1.);
|
||||
model = translate(model, vec3(pos.x, pos.y, pos.z));
|
||||
model = rotate(model, orient.getAngle(), vec3(rotAxis.x, rotAxis.y, rotAxis.z));
|
||||
model = glm::scale(model, vec3(scale.x, scale.y, scale.z));
|
||||
|
||||
vector<Mesh*> mesh = node->getMeshes();
|
||||
vector<ParticleEmitter*> pe = node->getParticleEmitters();
|
||||
|
||||
/*
|
||||
for(Mesh *m : mesh){
|
||||
}
|
||||
*/
|
||||
|
||||
//meshes.insert(meshes.end(), mesh.begin(), mesh.end());
|
||||
//particleEmitters.insert(particleEmitters.end(), pe.begin(), pe.end());
|
||||
|
||||
node->update();
|
||||
}
|
||||
|
||||
//TODO replace sorting algorithm
|
||||
//TODO specify differentiation of nodes with translucent meshes AND texts
|
||||
void Root::updateNodeTree(Node *node, mat4 &projView, bool gui){
|
||||
objVertData.clear();
|
||||
objFragData.clear();
|
||||
|
||||
for(DrawElementsIndirectCommand &cmd : drawCmds)
|
||||
cmd.instanceCount = 0;
|
||||
|
||||
vector<Node*> descendants, opaqueNodes, transparentNodes;
|
||||
node->getDescendants(descendants);
|
||||
|
||||
for(Node *desc : descendants){
|
||||
if(!desc->isVisible()) continue;
|
||||
|
||||
vector<Mesh*> meshes = desc->getMeshes();
|
||||
|
||||
if(!desc->getMeshes().empty()){
|
||||
Quaternion orient = Quaternion::QUAT_W;
|
||||
Vector3 pos = Vector3::VEC_ZERO, scale = Vector3::VEC_IJK;
|
||||
|
||||
if(!gui){
|
||||
pos = desc->localToGlobalPosition(Vector3::VEC_ZERO);
|
||||
orient = desc->localToGlobalOrientation(Quaternion::QUAT_W);
|
||||
scale = desc->getScale();
|
||||
if(!meshes.empty())
|
||||
for(Mesh *mesh : meshes){
|
||||
bool transparentMesh = (mesh->getMaterial()->isTransparent());
|
||||
(transparentMesh ? transparentNodes : opaqueNodes).push_back(desc);
|
||||
}
|
||||
|
||||
Vector3 rotAxis = orient.getAxis();
|
||||
|
||||
if(rotAxis == Vector3::VEC_ZERO)
|
||||
rotAxis = Vector3::VEC_I;
|
||||
|
||||
mat4 model = mat4(1.);
|
||||
model = translate(model, vec3(pos.x, pos.y, pos.z));
|
||||
model = rotate(model, orient.getAngle(), vec3(rotAxis.x, rotAxis.y, rotAxis.z));
|
||||
model = glm::scale(model, vec3(scale.x, scale.y, scale.z));
|
||||
|
||||
for(Mesh *mesh : desc->getMeshes()){
|
||||
if(mesh->getMaterial()->isTransparent()){
|
||||
transparentNodes.push_back(desc);
|
||||
}
|
||||
else{
|
||||
mesh->getMaterial()->getShader()->use();
|
||||
ObjectVertexData ovd;
|
||||
ovd.viewProj = projView;
|
||||
ovd.model = model;
|
||||
//ovd.animated = 0;
|
||||
//ovd.bones[0];
|
||||
MeshData &meshData = mesh->getMeshBase();
|
||||
|
||||
for(int i = 0; i < drawCmdMeshes.size(); i++)
|
||||
if(*(drawCmdMeshes[i]) == meshData)
|
||||
drawCmds[i].instanceCount++;
|
||||
/*
|
||||
*/
|
||||
|
||||
//for(int i = 0; i < meshData.numShapeKeys; i++) ovd.shapeKeyFactors[i] = meshData.shapeKeys[i].value;
|
||||
|
||||
objVertData.push_back(ovd);
|
||||
|
||||
ObjectFragmentData ofd;
|
||||
ofd.diffuseColor = Vector4::VEC_IJKL;
|
||||
ofd.specularColor;
|
||||
ofd.shinyness;
|
||||
ofd.specularStrength;
|
||||
ofd.lightingEnabled = false,
|
||||
ofd.constLightingEnabled = false,
|
||||
ofd.texturingEnabled = false,
|
||||
ofd.normalMapEnabled = false,
|
||||
ofd.specularMapEnabled = false,
|
||||
ofd.castShadow = false,
|
||||
ofd.environmentMapEnabled = false;
|
||||
objFragData.push_back(ofd);
|
||||
|
||||
//updateNode(desc, projView, gui);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if(!desc->getTexts().empty())
|
||||
transparentNodes.push_back(desc);
|
||||
else{
|
||||
//updateNode(desc, proj, view, gui);
|
||||
//opaqueNodes.push_back(desc);
|
||||
}
|
||||
opaqueNodes.push_back(desc);
|
||||
}
|
||||
}
|
||||
|
||||
int numNodes = transparentNodes.size();
|
||||
@@ -515,6 +495,102 @@ namespace vb01{
|
||||
}
|
||||
}
|
||||
|
||||
objVertData.clear();
|
||||
objFragData.clear();
|
||||
|
||||
for(DrawElementsIndirectCommand &cmd : drawCmds)
|
||||
cmd.instanceCount = 0;
|
||||
|
||||
vector<Node*> renderNodes = opaqueNodes;
|
||||
renderNodes.insert(renderNodes.end(), transparentNodes.begin(), transparentNodes.end());
|
||||
|
||||
for(Node *renderNode : renderNodes){
|
||||
renderNode->update();
|
||||
|
||||
Quaternion orient = Quaternion::QUAT_W;
|
||||
Vector3 pos = Vector3::VEC_ZERO, scale = Vector3::VEC_IJK;
|
||||
|
||||
if(!gui){
|
||||
pos = renderNode->localToGlobalPosition(Vector3::VEC_ZERO);
|
||||
orient = renderNode->localToGlobalOrientation(Quaternion::QUAT_W);
|
||||
scale = renderNode->getScale();
|
||||
}
|
||||
|
||||
Vector3 rotAxis = orient.getAxis();
|
||||
|
||||
if(rotAxis == Vector3::VEC_ZERO)
|
||||
rotAxis = Vector3::VEC_I;
|
||||
|
||||
mat4 model = mat4(1.);
|
||||
model = translate(model, vec3(pos.x, pos.y, pos.z));
|
||||
model = rotate(model, orient.getAngle(), vec3(rotAxis.x, rotAxis.y, rotAxis.z));
|
||||
model = glm::scale(model, vec3(scale.x, scale.y, scale.z));
|
||||
|
||||
for(Mesh *mesh : renderNode->getMeshes()){
|
||||
Material *mat = mesh->getMaterial();
|
||||
mat->getShader()->use();
|
||||
mat->getShader()->setInt(0, "textureSampler");
|
||||
|
||||
ObjectVertexData ovd;
|
||||
ovd.viewProj = projView;
|
||||
ovd.model = model;
|
||||
//ovd.animated = 0;
|
||||
//ovd.bones[0];
|
||||
MeshData &meshData = mesh->getMeshBase();
|
||||
|
||||
for(int i = 0; i < drawCmdMeshes.size(); i++)
|
||||
if(*(drawCmdMeshes[i]) == meshData)
|
||||
drawCmds[i].instanceCount++;
|
||||
|
||||
/*
|
||||
for(int i = 0; i < meshData.numShapeKeys; i++)
|
||||
ovd.shapeKeyFactors[i] = meshData.shapeKeys[i].value;
|
||||
*/
|
||||
|
||||
objVertData.push_back(ovd);
|
||||
|
||||
ObjectFragmentData ofd;
|
||||
ofd.texturingEnabled = true;
|
||||
|
||||
if(ofd.texturingEnabled){
|
||||
ofd.pastTexture[0] = 0;
|
||||
ofd.pastTexture[1] = 0;
|
||||
}
|
||||
else{
|
||||
Vector4 diffuseColor = ((Material::Vector4Uniform*)mat->getUniform("diffuseColor"))->value;
|
||||
|
||||
ofd.diffuseColor[0] = diffuseColor.x;
|
||||
ofd.diffuseColor[1] = diffuseColor.y;
|
||||
ofd.diffuseColor[2] = diffuseColor.z;
|
||||
ofd.diffuseColor[3] = diffuseColor.w;
|
||||
}
|
||||
|
||||
ofd.lightingEnabled = false;
|
||||
|
||||
if(ofd.lightingEnabled){
|
||||
ofd.constLightingEnabled = false;
|
||||
ofd.texturingEnabled = false;
|
||||
ofd.normalMapEnabled = false;
|
||||
ofd.castShadow = false;
|
||||
ofd.environmentMapEnabled = false;
|
||||
ofd.specularMapEnabled = false;
|
||||
|
||||
if(!ofd.specularMapEnabled){
|
||||
Vector4 specularColor = ((Material::Vector4Uniform*)mat->getUniform("specularColor"))->value;
|
||||
|
||||
ofd.specularColor[0] = specularColor.x;
|
||||
ofd.specularColor[1] = specularColor.y;
|
||||
ofd.specularColor[2] = specularColor.z;
|
||||
ofd.specularColor[3] = specularColor.w;
|
||||
ofd.shinyness;
|
||||
ofd.specularStrength;
|
||||
}
|
||||
}
|
||||
|
||||
objFragData.push_back(ofd);
|
||||
}
|
||||
}
|
||||
|
||||
if(gui){} //renderGui();
|
||||
else{
|
||||
renderMeshes();
|
||||
@@ -555,7 +631,9 @@ namespace vb01{
|
||||
shader->setFloat(gamma, "gamma");
|
||||
shader->setInt(0, "frag");
|
||||
|
||||
((Material::TextureUniform*)material->getUniform("frag"))->value->select(0);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, guiPlaneTextureBuffer[0]);
|
||||
//((Material::TextureUniform*)material->getUniform("frag"))->value->select(0);
|
||||
|
||||
if(hdr){
|
||||
shader->setInt(1, "bright");
|
||||
@@ -572,7 +650,7 @@ namespace vb01{
|
||||
|
||||
void Root::createSkybox(Texture *texture){
|
||||
skybox = new Box(Vector3::VEC_IJK * 10);
|
||||
Material *skyboxMat = new Material(libPath + "skybox");
|
||||
Material *skyboxMat = new Material(new Shader(libPath + "skybox"));
|
||||
skyboxMat->addTexUniform("tex", texture, true);
|
||||
skybox->setMaterial(skyboxMat);
|
||||
}
|
||||
|
||||
@@ -28,6 +28,8 @@ namespace vb01{
|
||||
class Shader;
|
||||
class ParticleEmitter;
|
||||
|
||||
struct ImageAsset;
|
||||
|
||||
class Root{
|
||||
public:
|
||||
static Root* getSingleton();
|
||||
@@ -40,9 +42,14 @@ namespace vb01{
|
||||
void createSkybox(vb01::Texture*);
|
||||
void removeSkybox();
|
||||
void initVertexDataOnGpu(MeshData&, u32&, u32&, u32&, bool);
|
||||
void initTextureDataOnGpu(int, int);
|
||||
void initTextureDataOnGpu(u32*, u8*, int, int, int&);
|
||||
inline Shader* getPhongShader(){return phongShader;}
|
||||
inline u32& getMeshVAO(){return meshVAO;}
|
||||
inline u32& getMeshVBO(){return meshVBO;}
|
||||
inline u32& getMeshEBO(){return meshEBO;}
|
||||
inline u32* getMeshTextureBuffer(){return meshTextureBuffer;}
|
||||
inline u32* getGuiPlaneTextureBuffer(){return guiPlaneTextureBuffer;}
|
||||
inline const int getMaxNumShapeKeys(){return MAX_NUM_SHAPE_KEYS;}
|
||||
inline Camera* getCamera(){return camera;}
|
||||
inline Node* getRootNode(){return rootNode;}
|
||||
@@ -75,14 +82,23 @@ namespace vb01{
|
||||
//bool animated;
|
||||
};
|
||||
struct ObjectFragmentData {
|
||||
Vector4 diffuseColor, specularColor;
|
||||
float mixRatio;
|
||||
int pastTexture[2], lastTexture[2];
|
||||
int animated;
|
||||
float diffuseColor[4], specularColor[4];
|
||||
float shinyness, specularStrength;
|
||||
bool lightingEnabled, constLightingEnabled, texturingEnabled, normalMapEnabled, specularMapEnabled, castShadow, environmentMapEnabled;
|
||||
int lightingEnabled, constLightingEnabled, texturingEnabled, normalMapEnabled, specularMapEnabled, castShadow, environmentMapEnabled;
|
||||
};
|
||||
struct TextureGpuData {
|
||||
u32 *buffer = nullptr;
|
||||
int unitId = 0, layerId = 0, width = 0, height = 0;
|
||||
|
||||
TextureGpuData(u32 *b, int u, int l, int w, int h) : buffer(b), unitId(u), layerId(l), width(w), height(h){}
|
||||
};
|
||||
|
||||
const int MAX_NUM_SHAPE_KEYS = 5;
|
||||
int NUM_MAX_TEXTURE_UNITS = 0, NUM_MAX_TEXTURE_ARRAY_SIZE = 0, numLights = 0, width, height, blurLevel = 10, currNumVerts = 0, currNumIndexes = 0;
|
||||
u32 meshVAO, meshVBO, meshEBO, particleVAO, particleVBO, guiPlaneVAO, guiPlaneVBO, guiPlaneEBO, FBO, RBO, pingpongBuffers[2], drawCmdBuffer = -1, objVertBuffer = -1, objFragBuffer = -1;
|
||||
int NUM_MAX_TEXTURE_UNITS = 0, NUM_MAX_TEXTURE_ARRAY_SIZE = 0, numLights = 0, width, height, blurLevel = 10, currNumVerts = 0, currNumIndexes = 0, depthmapSize = 512, currNumLayers = 0;
|
||||
u32 meshVAO, meshVBO, meshEBO, particleVAO, particleVBO, guiPlaneVAO, guiPlaneVBO, guiPlaneEBO, *meshTextureBuffer = nullptr, *guiPlaneTextureBuffer = nullptr, *depthmapBuffer = nullptr, FBO, RBO, pingpongBuffers[2], drawCmdBuffer = -1, objVertBuffer = -1, objFragBuffer = -1;
|
||||
bool bloom = false, hdr = false;
|
||||
float exposure = 1, gamma = 1;
|
||||
Box *skybox = nullptr, *iblBox = nullptr;
|
||||
@@ -90,15 +106,17 @@ namespace vb01{
|
||||
GLFWwindow *window;
|
||||
Node *rootNode, *guiNode;
|
||||
Camera *camera;
|
||||
Shader *blurShader;
|
||||
Shader *blurShader = nullptr, *phongShader = nullptr;
|
||||
Texture *pingPongTextures[2];
|
||||
std::vector<MeshData*> drawCmdMeshes;
|
||||
std::vector<MeshData::GpuVertex> currentGpuVertices;
|
||||
std::vector<std::pair<int, int>> currTextureDims;
|
||||
std::vector<u32> currentIndices;
|
||||
std::vector<Mesh*> meshes;
|
||||
std::vector<DrawElementsIndirectCommand> drawCmds;
|
||||
std::vector<ObjectVertexData> objVertData;
|
||||
std::vector<ObjectFragmentData> objFragData;
|
||||
std::vector<TextureGpuData> textureGpuData;
|
||||
std::string libPath;
|
||||
|
||||
Root();
|
||||
@@ -113,8 +131,8 @@ namespace vb01{
|
||||
void updateBloomFramebuffer();
|
||||
void updateGuiPlane();
|
||||
void updateNodeTree(vb01::Node*, glm::mat4&, bool);
|
||||
void updateNode(vb01::Node*, glm::mat4&, glm::mat4&, bool);
|
||||
void renderMesh(Mesh*, u32&);
|
||||
|
||||
protected:
|
||||
virtual void initMeshRendering(u32 &vao, u32 &vbo, u32 &ebo);
|
||||
virtual void initParticleRendering();
|
||||
|
||||
+17
-8
@@ -7,6 +7,7 @@
|
||||
#include "texture.h"
|
||||
#include "assetManager.h"
|
||||
#include "imageAsset.h"
|
||||
#include "root.h"
|
||||
|
||||
#include <glad.h>
|
||||
#include <glfw3.h>
|
||||
@@ -15,15 +16,12 @@
|
||||
using namespace std;
|
||||
|
||||
namespace vb01{
|
||||
Texture::Texture(int width, int height, bool shadowMap, bool hiRes) : Animatable(Animatable::TEXTURE){
|
||||
this->width = width;
|
||||
this->height = height;
|
||||
Texture::Texture(int w, int h, bool shadowMap, bool hiRes) : Animatable(Animatable::TEXTURE), width(w), height(h), texture(new u32){
|
||||
if(shadowMap){
|
||||
/*
|
||||
texture = new u32;
|
||||
|
||||
glGenTextures(1, &texture[0]);
|
||||
glBindTexture(GL_TEXTURE_2D, texture[0]);
|
||||
|
||||
if(shadowMap){
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, width, height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
@@ -31,13 +29,17 @@ namespace vb01{
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
|
||||
float borderColor[] = {1, 1, 1, 1};
|
||||
glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor);
|
||||
*/
|
||||
}
|
||||
else{
|
||||
Root::getSingleton()->initTextureDataOnGpu(width, height);
|
||||
/*
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, (hiRes ? GL_RGB16F : GL_RGB), width, height, 0, GL_RGB, GL_FLOAT, NULL);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,8 +56,13 @@ namespace vb01{
|
||||
}
|
||||
else{
|
||||
this->numFrames = numPaths;
|
||||
texture = new u32[numPaths];
|
||||
create2DTexture(flip);
|
||||
//texture = new u32[numPaths];
|
||||
//create2DTexture(flip);
|
||||
//
|
||||
for(int i = 0; i < numFrames; i++){
|
||||
ImageAsset *imgAsset = (ImageAsset*)AssetManager::getSingleton()->getAsset(paths[i]);
|
||||
frames.push_back(Frame(nullptr, imgAsset->layerId));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,10 +190,12 @@ namespace vb01{
|
||||
}
|
||||
|
||||
void Texture::update(int id){
|
||||
/*
|
||||
select(id, frameA);
|
||||
|
||||
if(numFrames > 0)
|
||||
select(id + 1, frameB);
|
||||
*/
|
||||
}
|
||||
|
||||
void Texture::select(int id, int fr){
|
||||
|
||||
@@ -31,12 +31,20 @@ namespace vb01{
|
||||
inline bool isCubemap(){return cubemap;}
|
||||
inline bool isTransparent(){return png;}
|
||||
private:
|
||||
struct Frame{
|
||||
u32 *buffer = nullptr;
|
||||
int layerId = 0;
|
||||
|
||||
Frame(u32 *b, int lid) : buffer(b), layerId(lid){}
|
||||
};
|
||||
|
||||
bool cubemap = false, png = false;
|
||||
u32 *texture = nullptr;
|
||||
s64 lastUpdateTime = 0;
|
||||
int width, height, updateRate = 0, numFrames = 0, frameA = 0, frameB = 0, mipmapLevel = 1;
|
||||
float mixRatio;
|
||||
std::string *paths = nullptr;
|
||||
std::vector<Frame> frames;
|
||||
|
||||
void createCubemap(bool, bool, bool);
|
||||
void create2DTexture(bool);
|
||||
|
||||
Reference in New Issue
Block a user