PipelineInfo::CullMode and PipelineInfo::RasterMode are no longer within the PipelineInfo class, enabling easier forward declaration.

KRMaterial::bind now accepts remaining parameters required to set up the pipeline.
Removed GL calls from KRModel.
Replaced ifdef guards with pragma once.
KRMesh::model_format_t changed to ModelFormat and is no longer within KRMesh, enabling easier forward declaration.
This commit is contained in:
2022-07-07 22:51:16 -07:00
parent 4f3b8ad584
commit 216cbe3eec
56 changed files with 315 additions and 417 deletions

View File

@@ -140,7 +140,7 @@ void KRAmbientZone::render(RenderInfo& ri)
info.directional_lights = &ri.directional_lights;
info.spot_lights = &ri.spot_lights;
info.renderPass = ri.renderPass;
info.rasterMode = PipelineInfo::RasterMode::kAdditive;
info.rasterMode = RasterMode::kAdditive;
info.modelFormat = sphereModel->getModelFormat();
info.vertexAttributes = sphereModel->getVertexAttributes();

View File

@@ -29,8 +29,7 @@
// or implied, of Kearwood Gilbert.
//
#ifndef KRAMBIENT_ZONE_H
#define KRAMBIENT_ZONE_H
#pragma once
#include "KRResource.h"
#include "KRNode.h"
@@ -72,6 +71,3 @@ private:
std::string m_ambient;
float m_ambient_gain;
};
#endif

View File

@@ -29,8 +29,7 @@
// or implied, of Kearwood Gilbert.
//
#ifndef KRANIMATION_H
#define KRANIMATION_H
#pragma once
#include "KREngine-common.h"
#include "KRContextObject.h"
@@ -83,7 +82,3 @@ private:
float m_duration;
float m_start_time;
};
#endif

View File

@@ -29,8 +29,7 @@
// or implied, of Kearwood Gilbert.
//
#ifndef KRANIMATIONATTRIBUTE_H
#define KRANIMATIONATTRIBUTE_H
#pragma once
#include "KRContextObject.h"
#include "KREngine-common.h"
@@ -67,5 +66,3 @@ private:
KRNode *m_target;
KRAnimationCurve *m_curve;
};
#endif

View File

@@ -29,8 +29,7 @@
// or implied, of Kearwood Gilbert.
//
#ifndef KRANIMATIONCURVE_H
#define KRANIMATIONCURVE_H
#pragma once
#include "KREngine-common.h"
#include "KRContextObject.h"
@@ -82,5 +81,3 @@ private:
};
#endif

View File

@@ -29,8 +29,7 @@
// or implied, of Kearwood Gilbert.
//
#ifndef KRANIMATIONCURVEMANAGER_H
#define KRANIMATIONCURVEMANAGER_H
#pragma once
#include "KREngine-common.h"
@@ -61,6 +60,3 @@ private:
unordered_map<std::string, KRAnimationCurve *> m_animationCurves;
};
#endif

View File

@@ -29,8 +29,7 @@
// or implied, of Kearwood Gilbert.
//
#ifndef KRANIMATIONLAYER_H
#define KRANIMATIONLAYER_H
#pragma once
#include "KRContextObject.h"
#include "KREngine-common.h"
@@ -92,5 +91,3 @@ private:
std::vector<KRAnimationAttribute *> m_attributes;
};
#endif

View File

@@ -29,8 +29,7 @@
// or implied, of Kearwood Gilbert.
//
#ifndef KRANIMATIONMANAGER_H
#define KRANIMATIONMANAGER_H
#pragma once
#include "KREngine-common.h"
@@ -67,6 +66,3 @@ private:
set<KRAnimation *> m_animationsToUpdate;
};
#endif

View File

@@ -29,8 +29,7 @@
// or implied, of Kearwood Gilbert.
//
#ifndef KRAUDIO_BUFFER_H
#define KRAUDIO_BUFFER_H
#pragma once
#include "KREngine-common.h"
#include "KRDataBlock.h"
@@ -61,5 +60,3 @@ private:
KRAudioSample *m_audioSample;
};
#endif /* defined(KRAUDIO_BUFFER_H) */

View File

@@ -29,8 +29,7 @@
// or implied, of Kearwood Gilbert.
//
#ifndef KRAUDIO_MANAGER_H
#define KRAUDIO_MANAGER_H
#pragma once
#include "KREngine-common.h"
@@ -254,5 +253,3 @@ private:
bool m_anticlick_block;
bool m_high_quality_hrtf; // If true, 4 HRTF samples will be interpolated; if false, the nearest HRTF sample will be used without interpolation
};
#endif /* defined(KRAUDIO_MANAGER_H) */

View File

@@ -29,8 +29,7 @@
// or implied, of Kearwood Gilbert.
//
#ifndef KRAUDIOSAMPLE_H
#define KRAUDIOSAMPLE_H
#pragma once
#include "KREngine-common.h"
#include "KRContextObject.h"
@@ -109,5 +108,3 @@ private:
static void PopulateBuffer(KRAudioSample *sound, int index, void *data);
};
#endif /* defined(KRAUDIOSAMPLE_H) */

View File

@@ -206,7 +206,7 @@ void KRAudioSource::render(RenderInfo& ri)
info.directional_lights = &ri.directional_lights;
info.spot_lights = &ri.spot_lights;
info.renderPass = ri.renderPass;
info.rasterMode = PipelineInfo::RasterMode::kAdditive;
info.rasterMode = RasterMode::kAdditive;
info.modelFormat = sphereModel->getModelFormat();
info.vertexAttributes = sphereModel->getVertexAttributes();

View File

@@ -29,8 +29,7 @@
// or implied, of Kearwood Gilbert.
//
#ifndef KRAUDIOSOURCE_H
#define KRAUDIOSOURCE_H
#pragma once
#include "KREngine-common.h"
#include "KRResource.h"
@@ -156,5 +155,3 @@ private:
bool m_enable_occlusion;
bool m_enable_obstruction;
};
#endif /* defined(KRAUDIOSOURCE_H) */

View File

@@ -29,8 +29,7 @@
// or implied, of Kearwood Gilbert.
//
#ifndef KRBEHAVIOR_H
#define KRBEHAVIOR_H
#pragma once
#include <map>
#include <string>
@@ -69,5 +68,3 @@ public:
private:
KRNode *__node;
};
#endif /* defined(KRBEHAVIOR_H) */

View File

@@ -90,7 +90,7 @@ void KRBone::render(RenderInfo& ri)
info.directional_lights = &ri.directional_lights;
info.spot_lights = &ri.spot_lights;
info.renderPass = ri.renderPass;
info.rasterMode = PipelineInfo::RasterMode::kAdditiveNoTest;
info.rasterMode = RasterMode::kAdditiveNoTest;
info.modelFormat = sphereModel->getModelFormat();
info.vertexAttributes = sphereModel->getVertexAttributes();

View File

@@ -29,8 +29,7 @@
// or implied, of Kearwood Gilbert.
//
#ifndef KRBONE_H
#define KRBONE_H
#pragma once
#include "KRResource.h"
#include "KRNode.h"
@@ -56,6 +55,3 @@ public:
private:
Matrix4 m_bind_pose;
};
#endif

View File

@@ -28,8 +28,7 @@
// authors and should not be interpreted as representing official policies, either expressed
// or implied, of Kearwood Gilbert.
//
#ifndef KRBUNDLE_H
#define KRBUNDLE_H
#pragma once
#include "KREngine-common.h"
#include "KRResource.h"
@@ -50,5 +49,3 @@ private:
KRDataBlock *m_pData;
static size_t RoundUpSize(size_t s);
};
#endif /* defined(KRBUNDLE_H) */

View File

@@ -29,8 +29,7 @@
// or implied, of Kearwood Gilbert.
//
#ifndef KRBUNDLEMANAGER_H
#define KRBUNDLEMANAGER_H
#pragma once
#include "KRResourceManager.h"
@@ -59,5 +58,3 @@ public:
private:
unordered_map<std::string, KRBundle *> m_bundles;
};
#endif /* defined(KRBUNDLEMANAGER_H) */

View File

@@ -227,7 +227,7 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, KRSurface& compositeS
info.shader_name = &shader_name;
info.pCamera = this;
info.renderPass = KRNode::RENDER_PASS_FORWARD_TRANSPARENT;
info.rasterMode = PipelineInfo::RasterMode::kAlphaBlend;
info.rasterMode = RasterMode::kAlphaBlend;
info.vertexAttributes = sphereMesh->getVertexAttributes();
info.modelFormat = sphereMesh->getModelFormat();
KRPipeline* testPipeline = m_pContext->getPipelineManager()->getPipeline(compositeSurface, info);
@@ -256,8 +256,8 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, KRSurface& compositeS
info.shader_name = &shader_name;
info.pCamera = this;
info.renderPass = KRNode::RENDER_PASS_FORWARD_OPAQUE;
info.rasterMode = PipelineInfo::RasterMode::kOpaqueNoDepthWrite;
info.cullMode = PipelineInfo::CullMode::kCullNone;
info.rasterMode = RasterMode::kOpaqueNoDepthWrite;
info.cullMode = CullMode::kCullNone;
KRPipeline* pPipeline = getContext().getPipelineManager()->getPipeline(compositeSurface, info);
pPipeline->bind(commandBuffer, *this, m_viewport, Matrix4(), nullptr, nullptr, nullptr, KRNode::RENDER_PASS_FORWARD_OPAQUE, Vector3::Zero(), 0.0f, Vector4::Zero());
@@ -344,9 +344,9 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, KRSurface& compositeS
info.shader_name = &shader_name;
info.pCamera = this;
info.renderPass = KRNode::RENDER_PASS_FORWARD_TRANSPARENT;
info.rasterMode = PipelineInfo::RasterMode::kAdditive;
info.rasterMode = RasterMode::kAdditive;
info.vertexAttributes = vertices.getVertexAttributes();
info.modelFormat = KRMesh::model_format_t::KRENGINE_MODEL_FORMAT_STRIP;
info.modelFormat = ModelFormat::KRENGINE_MODEL_FORMAT_STRIP;
KRPipeline *pVisShader = getContext().getPipelineManager()->getPipeline(compositeSurface, info);
m_pContext->getMeshManager()->bindVBO(commandBuffer, &vertices, 1.0f);
@@ -566,8 +566,8 @@ void KRCamera::renderPost(VkCommandBuffer& commandBuffer, KRSurface& surface)
info.shader_name = &shader_name;
info.pCamera = this;
info.renderPass = KRNode::RENDER_PASS_FORWARD_TRANSPARENT;
info.rasterMode = PipelineInfo::RasterMode::kOpaqueNoTest;
info.modelFormat = KRMesh::model_format_t::KRENGINE_MODEL_FORMAT_STRIP;
info.rasterMode = RasterMode::kOpaqueNoTest;
info.modelFormat = ModelFormat::KRENGINE_MODEL_FORMAT_STRIP;
info.vertexAttributes = vertices.getVertexAttributes();
KRPipeline *postShader = m_pContext->getPipelineManager()->getPipeline(surface, info);
@@ -742,10 +742,10 @@ void KRCamera::renderPost(VkCommandBuffer& commandBuffer, KRSurface& surface)
info.shader_name = &shader_name;
info.pCamera = this;
info.renderPass = KRNode::RENDER_PASS_FORWARD_TRANSPARENT;
info.rasterMode = PipelineInfo::RasterMode::kAlphaBlendNoTest;
info.cullMode = PipelineInfo::CullMode::kCullNone;
info.rasterMode = RasterMode::kAlphaBlendNoTest;
info.cullMode = CullMode::kCullNone;
info.vertexAttributes = (1 << KRMesh::KRENGINE_ATTRIB_VERTEX) | (1 << KRMesh::KRENGINE_ATTRIB_TEXUVA);
info.modelFormat = KRMesh::model_format_t::KRENGINE_MODEL_FORMAT_TRIANGLES;
info.modelFormat = ModelFormat::KRENGINE_MODEL_FORMAT_TRIANGLES;
KRPipeline *fontShader = m_pContext->getPipelineManager()->getPipeline(surface, info);
fontShader->bind(commandBuffer, *this, m_viewport, Matrix4(), nullptr, nullptr, nullptr, KRNode::RENDER_PASS_FORWARD_TRANSPARENT, Vector3::Zero(), 0.0f, Vector4::Zero());

View File

@@ -29,8 +29,7 @@
// or implied, of Kearwood Gilbert.
//
#ifndef KRCAMERA_H
#define KRCAMERA_H
#pragma once
#include "KREngine-common.h"
@@ -118,5 +117,3 @@ private:
int m_frame_times[KRAKEN_FPS_AVERAGE_FRAME_COUNT];
int m_frame_times_filled;
};
#endif

View File

@@ -213,7 +213,7 @@ void KRCollider::render(RenderInfo& ri)
info.directional_lights = &ri.directional_lights;
info.spot_lights = &ri.spot_lights;
info.renderPass = ri.renderPass;
info.rasterMode = PipelineInfo::RasterMode::kAdditive;
info.rasterMode = RasterMode::kAdditive;
info.modelFormat = m_model->getModelFormat();
info.vertexAttributes = m_model->getVertexAttributes();

View File

@@ -29,10 +29,10 @@
// or implied, of Kearwood Gilbert.
//
#pragma once
#include "KREngine-common.h"
#ifndef KRCOLLIDER_H
#define KRCOLLIDER_H
#define KRAKEN_COLLIDER_PHYSICS 1
#define KRAKEN_COLLIDER_AUDIO 2
@@ -80,5 +80,3 @@ private:
void loadModel();
};
#endif /* defined(KRCOLLIDER_H) */

View File

@@ -29,8 +29,7 @@
// or implied, of Kearwood Gilbert.
//
#ifndef KREngine_KRContext_h
#define KREngine_KRContext_h
#pragma once
#include "KREngine-common.h"
#include "KRBundleManager.h"
@@ -52,6 +51,7 @@
class KRAudioManager;
class KRPresentationThread;
class KRStreamerThread;
class KRDeviceManager;
class KRContext {
public:
@@ -203,5 +203,3 @@ private:
unordered_map<KrSurfaceMapIndex, KrSurfaceHandle> m_surfaceHandleMap;
};
#endif

View File

@@ -29,8 +29,7 @@
// or implied, of Kearwood Gilbert.
//
#ifndef KRCONTEXTOBJECT_H
#define KRCONTEXTOBJECT_H
#pragma once
class KRContext;
@@ -44,5 +43,3 @@ public:
protected:
KRContext *m_pContext;
};
#endif

View File

@@ -29,8 +29,7 @@
// or implied, of Kearwood Gilbert.
//
#ifndef _KRDSP_H
#define _KRDSP_H
#pragma once
#include "KREngine-common.h"
@@ -90,5 +89,3 @@ void Accumulate(SplitComplex *buffer, const SplitComplex *buffer2, size_t count)
void Multiply(const SplitComplex *a, const SplitComplex *b, SplitComplex *c, size_t count);
} // namespace KRDSP
#endif // _KRDSP_H

View File

@@ -29,8 +29,7 @@
// or implied, of Kearwood Gilbert.
//
#ifndef KREngine_KRDataBlock_h
#define KREngine_KRDataBlock_h
#pragma once
#include "KREngine-common.h"
@@ -127,5 +126,3 @@ private:
void assertLocked();
};
#endif

View File

@@ -32,8 +32,7 @@
#include "KREngine-common.h"
#include "KRContextObject.h"
#ifndef KRDEVICE_H
#define KRDEVICE_H
#pragma once
class KRDevice : public KRContextObject
{
@@ -68,5 +67,3 @@ public:
VmaAllocator m_allocator;
private:
};
#endif // KRDEVICE_H

View File

@@ -29,14 +29,13 @@
// or implied, of Kearwood Gilbert.
//
#pragma once
#include "KREngine-common.h"
#include "KRContext.h"
#include "KRDevice.h"
#ifndef KRDEVICEMANAGER_H
#define KRDEVICEMANAGER_H
class KRDeviceManager : KRContextObject
{
public:
@@ -61,5 +60,3 @@ private:
VkInstance m_vulkanInstance;
};
#endif // KRDEVICEMANAGER_H

View File

@@ -146,10 +146,10 @@ void KRDirectionalLight::render(RenderInfo& ri) {
info.pCamera = ri.camera;
info.directional_lights = &this_light;
info.renderPass = ri.renderPass;
info.rasterMode = PipelineInfo::RasterMode::kAdditiveNoTest;
info.rasterMode = RasterMode::kAdditiveNoTest;
info.vertexAttributes = vertices.getVertexAttributes();
info.modelFormat = KRMesh::model_format_t::KRENGINE_MODEL_FORMAT_STRIP;
info.modelFormat = ModelFormat::KRENGINE_MODEL_FORMAT_STRIP;
KRPipeline *pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, info);
pShader->setUniform(KRPipeline::KRENGINE_UNIFORM_LIGHT_DIRECTION_VIEW_SPACE, light_direction_view_space);

View File

@@ -29,8 +29,7 @@
// or implied, of Kearwood Gilbert.
//
#ifndef KREngine_KRDirectionalLight_h
#define KREngine_KRDirectionalLight_h
#pragma once
#include "KRLight.h"
@@ -55,5 +54,3 @@ protected:
};
#endif

View File

@@ -29,9 +29,7 @@
// or implied, of Kearwood Gilbert.
//
#ifndef KRENGINE_COMMON_H
#define KRENGINE_COMMON_H
#pragma once
#define KRENGINE_MAX_GPU_COUNT 4
#define KRENGINE_DEBUG_GPU_LABELS 1
@@ -266,6 +264,4 @@ typedef int KrSurfaceHandle;
#include "KRBehavior.h"
#endif
using namespace kraken;

View File

@@ -29,8 +29,7 @@
// or implied, of Kearwood Gilbert.
//
#ifndef KRHELPERS_H
#define KRHELPERS_H
#pragma once
#include "vector2.h"
#include "vector3.h"
@@ -65,4 +64,3 @@ namespace kraken {
const Vector3 getXMLAttribute(const std::string &base_name, ::tinyxml2::XMLElement *e, const Vector3 &default_value);
} // namespace kraken
#endif

View File

@@ -29,8 +29,7 @@
// or implied, of Kearwood Gilbert.
//
#ifndef KRLODGROUP_H
#define KRLODGROUP_H
#pragma once
#include "KRResource.h"
#include "KRNode.h"
@@ -62,6 +61,3 @@ private:
AABB m_reference; // Point of reference, used for distance calculation. Usually set to the bounding box center
bool m_use_world_units;
};
#endif

View File

@@ -29,8 +29,7 @@
// or implied, of Kearwood Gilbert.
//
#ifndef KRLODSET_H
#define KRLODSET_H
#pragma once
#include "KRResource.h"
#include "KRNode.h"
@@ -52,6 +51,3 @@ public:
virtual kraken_stream_level getStreamLevel(const KRViewport &viewport);
};
#endif

View File

@@ -264,10 +264,10 @@ void KRLight::render(RenderInfo& ri) {
info.directional_lights = &this_directional_light;
info.spot_lights = &this_spot_light;
info.renderPass = ri.renderPass;
info.rasterMode = PipelineInfo::RasterMode::kAdditive;
info.cullMode = PipelineInfo::CullMode::kCullNone;
info.rasterMode = RasterMode::kAdditive;
info.cullMode = CullMode::kCullNone;
info.vertexAttributes = (1 << KRMesh::KRENGINE_ATTRIB_VERTEX) | (1 << KRMesh::KRENGINE_ATTRIB_TEXUVA);
info.modelFormat = KRMesh::model_format_t::KRENGINE_MODEL_FORMAT_TRIANGLES;
info.modelFormat = ModelFormat::KRENGINE_MODEL_FORMAT_TRIANGLES;
KRPipeline *pParticleShader = m_pContext->getPipelineManager()->getPipeline(*ri.surface, info);
pParticleShader->setUniform(KRPipeline::KRENGINE_UNIFORM_LIGHT_COLOR, m_color * ri.camera->settings.dust_particle_intensity * m_dust_particle_intensity * m_intensity);
@@ -313,10 +313,10 @@ void KRLight::render(RenderInfo& ri) {
info.directional_lights = &this_directional_light;
info.spot_lights = &this_spot_light;
info.renderPass = KRNode::RENDER_PASS_ADDITIVE_PARTICLES;
info.rasterMode = PipelineInfo::RasterMode::kAdditive;
info.cullMode = PipelineInfo::CullMode::kCullNone;
info.rasterMode = RasterMode::kAdditive;
info.cullMode = CullMode::kCullNone;
info.vertexAttributes = (1 << KRMesh::KRENGINE_ATTRIB_VERTEX);
info.modelFormat = KRMesh::model_format_t::KRENGINE_MODEL_FORMAT_TRIANGLES;
info.modelFormat = ModelFormat::KRENGINE_MODEL_FORMAT_TRIANGLES;
KRPipeline *pFogShader = m_pContext->getPipelineManager()->getPipeline(*ri.surface, info);
@@ -360,8 +360,8 @@ void KRLight::render(RenderInfo& ri) {
info.directional_lights = &ri.directional_lights;
info.spot_lights = &ri.spot_lights;
info.renderPass = ri.renderPass;
info.rasterMode = PipelineInfo::RasterMode::kAdditive;
info.cullMode = PipelineInfo::CullMode::kCullNone;
info.rasterMode = RasterMode::kAdditive;
info.cullMode = CullMode::kCullNone;
info.modelFormat = sphereModel->getModelFormat();
info.vertexAttributes = sphereModel->getVertexAttributes();
@@ -413,10 +413,10 @@ void KRLight::render(RenderInfo& ri) {
info.directional_lights = &ri.directional_lights;
info.spot_lights = &ri.spot_lights;
info.renderPass = ri.renderPass;
info.rasterMode = PipelineInfo::RasterMode::kAdditiveNoTest;
info.cullMode = PipelineInfo::CullMode::kCullNone;
info.rasterMode = RasterMode::kAdditiveNoTest;
info.cullMode = CullMode::kCullNone;
info.vertexAttributes = vertices.getVertexAttributes();
info.modelFormat = KRMesh::model_format_t::KRENGINE_MODEL_FORMAT_STRIP;
info.modelFormat = ModelFormat::KRENGINE_MODEL_FORMAT_STRIP;
KRPipeline *pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, info);
@@ -528,8 +528,8 @@ void KRLight::renderShadowBuffers(RenderInfo& ri)
info.shader_name = &shader_name;
info.pCamera = ri.camera;
info.renderPass = KRNode::RENDER_PASS_FORWARD_TRANSPARENT;
info.rasterMode = PipelineInfo::RasterMode::kOpaqueLessTest; // TODO - This is sub-optimal. Evaluate increasing depth buffer resolution instead of disabling depth test.
info.cullMode = PipelineInfo::CullMode::kCullNone; // Disabling culling, which eliminates some self-cast shadow artifacts
info.rasterMode = RasterMode::kOpaqueLessTest; // TODO - This is sub-optimal. Evaluate increasing depth buffer resolution instead of disabling depth test.
info.cullMode = CullMode::kCullNone; // Disabling culling, which eliminates some self-cast shadow artifacts
KRPipeline *shadowShader = m_pContext->getPipelineManager()->getPipeline(*ri.surface, info);
shadowShader->bind(ri.commandBuffer, *ri.camera, m_shadowViewports[iShadow], Matrix4(), nullptr, nullptr, nullptr, KRNode::RENDER_PASS_SHADOWMAP, Vector3::Zero(), 0.0f, Vector4::Zero());

View File

@@ -28,8 +28,7 @@
// authors and should not be interpreted as representing official policies, either expressed
// or implied, of Kearwood Gilbert.
//
#ifndef KRLIGHT_H
#define KRLIGHT_H
#pragma once
#include "KRResource.h"
#include "KRNode.h"
@@ -104,5 +103,3 @@ protected:
virtual int configureShadowBufferViewports(const KRViewport &viewport);
void renderShadowBuffers(RenderInfo& ri);
};
#endif

View File

@@ -29,8 +29,7 @@
// or implied, of Kearwood Gilbert.
//
#ifndef KRLOCATOR_H
#define KRLOCATOR_H
#pragma once
#include "KRResource.h"
#include "KRNode.h"
@@ -56,6 +55,3 @@ private:
unordered_map<std::string, bool> m_userBoolAttributes;
unordered_map<std::string, std::string> m_userStringAttributes;
};
#endif

View File

@@ -302,7 +302,7 @@ void KRMaterial::getTextures()
}
}
bool KRMaterial::bind(const KRNode::RenderInfo& ri, const std::vector<KRBone *> &bones, const std::vector<Matrix4> &bind_poses, const Matrix4 &matModel, KRTexture *pLightMap, const Vector3 &rim_color, float rim_power, float lod_coverage)
void KRMaterial::bind(const KRNode::RenderInfo& ri, ModelFormat modelFormat, __uint32_t vertexAttributes, CullMode cullMode, const std::vector<KRBone *> &bones, const std::vector<Matrix4> &bind_poses, const Matrix4 &matModel, KRTexture *pLightMap, const Vector3 &rim_color, float rim_power, float lod_coverage)
{
bool bLightMap = pLightMap && ri.camera->settings.bEnableLightMap;
@@ -344,9 +344,12 @@ bool KRMaterial::bind(const KRNode::RenderInfo& ri, const std::vector<KRBone *>
info.bNormalMapOffset = m_normalMapOffset != default_offset && bNormalMap;
info.bReflectionMapOffset = m_reflectionMapOffset != default_offset && bReflectionMap;
info.bAlphaTest = bAlphaTest;
info.rasterMode = bAlphaBlend ? PipelineInfo::RasterMode::kAlphaBlend : PipelineInfo::RasterMode::kOpaque;
info.rasterMode = bAlphaBlend ? RasterMode::kAlphaBlend : RasterMode::kOpaque;
info.bRimColor = rim_power != 0.0f;
info.renderPass = ri.renderPass;
info.modelFormat = modelFormat;
info.vertexAttributes = vertexAttributes;
info.cullMode = cullMode;
KRPipeline *pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, info);
// Bind bones
@@ -434,8 +437,6 @@ bool KRMaterial::bind(const KRNode::RenderInfo& ri, const std::vector<KRBone *>
}
pShader->bind(ri.commandBuffer, *ri.camera, ri.viewport, matModel, &ri.point_lights, &ri.directional_lights, &ri.spot_lights, ri.renderPass, rim_color, rim_power, Vector4::Zero());
return true;
}
const std::string &KRMaterial::getName() const

View File

@@ -29,6 +29,10 @@
// or implied, of Kearwood Gilbert.
//
#pragma once
#include "KREngine-common.h"
#include "KRTexture.h"
@@ -39,10 +43,8 @@
#include "KRScene.h"
#include "KRBone.h"
#ifndef KRMATERIAL_H
#define KRMATERIAL_H
enum class CullMode : __uint32_t;
enum class ModelFormat : __uint8_t;
class KRTextureManager;
class KRContext;
@@ -83,7 +85,7 @@ public:
bool isTransparent();
const std::string &getName() const;
bool bind(const KRNode::RenderInfo& ri, const std::vector<KRBone*>& bones, const std::vector<Matrix4>& bind_poses, const Matrix4& matModel, KRTexture* pLightMap, const Vector3& rim_color, float rim_power, float lod_coverage = 0.0f);
void bind(const KRNode::RenderInfo& ri, ModelFormat modelFormat, __uint32_t vertexAttributes, CullMode cullMode, const std::vector<KRBone*>& bones, const std::vector<Matrix4>& bind_poses, const Matrix4& matModel, KRTexture* pLightMap, const Vector3& rim_color, float rim_power, float lod_coverage = 0.0f);
bool needsVertexTangents();
@@ -134,5 +136,3 @@ private:
void getTextures();
};
#endif

View File

@@ -29,8 +29,7 @@
// or implied, of Kearwood Gilbert.
//
#ifndef KRMATERIALMANAGER_H
#define KRMATERIALMANAGER_H
#pragma once
#include "KREngine-common.h"
@@ -40,6 +39,7 @@
#include "KRTextureManager.h"
#include "KRMaterialManager.h"
class KRMaterial;
using std::map;
@@ -63,6 +63,3 @@ private:
KRPipelineManager *m_pPipelineManager;
};
#endif

View File

@@ -279,26 +279,27 @@ void KRMesh::render(const KRNode::RenderInfo& ri, const std::string& object_name
for(int i=0; i < (int)bones.size(); i++) {
bone_bind_poses.push_back(getBoneBindPose(i));
}
if(pMaterial->bind(ri, bones, bone_bind_poses, matModel, pLightMap, rim_color, rim_power, lod_coverage)) {
switch(pMaterial->getAlphaMode()) {
case KRMaterial::KRMATERIAL_ALPHA_MODE_OPAQUE: // Non-transparent materials
case KRMaterial::KRMATERIAL_ALPHA_MODE_TEST: // Alpha in diffuse texture is interpreted as punch-through when < 0.5
renderSubmesh(ri.commandBuffer, iSubmesh, ri.renderPass, object_name, pMaterial->getName(), lod_coverage);
break;
case KRMaterial::KRMATERIAL_ALPHA_MODE_BLENDONESIDE: // Blended alpha with backface culling
renderSubmesh(ri.commandBuffer, iSubmesh, ri.renderPass, object_name, pMaterial->getName(), lod_coverage);
break;
case KRMaterial::KRMATERIAL_ALPHA_MODE_BLENDTWOSIDE: // Blended alpha rendered in two passes. First pass renders backfaces; second pass renders frontfaces.
// Render back faces first
GLDEBUG(glCullFace(GL_FRONT));
renderSubmesh(ri.commandBuffer, iSubmesh, ri.renderPass, object_name, pMaterial->getName(), lod_coverage);
// Render front faces second
GLDEBUG(glCullFace(GL_BACK));
renderSubmesh(ri.commandBuffer, iSubmesh, ri.renderPass, object_name, pMaterial->getName(), lod_coverage);
break;
}
switch(pMaterial->getAlphaMode()) {
case KRMaterial::KRMATERIAL_ALPHA_MODE_OPAQUE: // Non-transparent materials
case KRMaterial::KRMATERIAL_ALPHA_MODE_TEST: // Alpha in diffuse texture is interpreted as punch-through when < 0.5
pMaterial->bind(ri, getModelFormat(), getVertexAttributes(), CullMode::kCullBack, bones, bone_bind_poses, matModel, pLightMap, rim_color, rim_power, lod_coverage);
renderSubmesh(ri.commandBuffer, iSubmesh, ri.renderPass, object_name, pMaterial->getName(), lod_coverage);
break;
case KRMaterial::KRMATERIAL_ALPHA_MODE_BLENDONESIDE: // Blended alpha with backface culling
pMaterial->bind(ri, getModelFormat(), getVertexAttributes(), CullMode::kCullBack, bones, bone_bind_poses, matModel, pLightMap, rim_color, rim_power, lod_coverage);
renderSubmesh(ri.commandBuffer, iSubmesh, ri.renderPass, object_name, pMaterial->getName(), lod_coverage);
break;
case KRMaterial::KRMATERIAL_ALPHA_MODE_BLENDTWOSIDE: // Blended alpha rendered in two passes. First pass renders backfaces; second pass renders frontfaces.
// Render back faces first
pMaterial->bind(ri, getModelFormat(), getVertexAttributes(), CullMode::kCullFront, bones, bone_bind_poses, matModel, pLightMap, rim_color, rim_power, lod_coverage);
renderSubmesh(ri.commandBuffer, iSubmesh, ri.renderPass, object_name, pMaterial->getName(), lod_coverage);
// Render front faces second
pMaterial->bind(ri, getModelFormat(), getVertexAttributes(), CullMode::kCullBack, bones, bone_bind_poses, matModel, pLightMap, rim_color, rim_power, lod_coverage);
renderSubmesh(ri.commandBuffer, iSubmesh, ri.renderPass, object_name, pMaterial->getName(), lod_coverage);
break;
}
}
}
@@ -357,7 +358,7 @@ void KRMesh::createDataBlocks(KRMeshManager::KRVBOData::vbo_type t)
int32_t vertex_count = pHeader->vertex_count;
int vbo_index=0;
if(getModelFormat() == KRENGINE_MODEL_FORMAT_INDEXED_TRIANGLES) {
if(getModelFormat() == ModelFormat::KRENGINE_MODEL_FORMAT_INDEXED_TRIANGLES) {
int index_group = getSubmesh(iSubmesh)->index_group;
int index_group_offset = getSubmesh(iSubmesh)->index_group_offset;
@@ -457,7 +458,7 @@ void KRMesh::renderSubmesh(VkCommandBuffer& commandBuffer, int iSubmesh, KRNode:
int cVertexes = pSubmesh->vertex_count;
int vbo_index=0;
if(getModelFormat() == KRENGINE_MODEL_FORMAT_INDEXED_TRIANGLES) {
if(getModelFormat() == ModelFormat::KRENGINE_MODEL_FORMAT_INDEXED_TRIANGLES) {
int index_group = getSubmesh(iSubmesh)->index_group;
int index_group_offset = getSubmesh(iSubmesh)->index_group_offset;
@@ -497,12 +498,12 @@ void KRMesh::renderSubmesh(VkCommandBuffer& commandBuffer, int iSubmesh, KRNode:
if(iVertex + cVertexes >= MAX_VBO_SIZE) {
assert(iVertex + (MAX_VBO_SIZE - iVertex) <= cBufferVertexes);
switch (getModelFormat()) {
case KRENGINE_MODEL_FORMAT_TRIANGLES:
case KRENGINE_MODEL_FORMAT_STRIP:
case ModelFormat::KRENGINE_MODEL_FORMAT_TRIANGLES:
case ModelFormat::KRENGINE_MODEL_FORMAT_STRIP:
vkCmdDraw(commandBuffer, (MAX_VBO_SIZE - iVertex), 1, iVertex, 0);
break;
case KRENGINE_MODEL_FORMAT_INDEXED_TRIANGLES:
case KRENGINE_MODEL_FORMAT_INDEXED_STRIP:
case ModelFormat::KRENGINE_MODEL_FORMAT_INDEXED_TRIANGLES:
case ModelFormat::KRENGINE_MODEL_FORMAT_INDEXED_STRIP:
vkCmdDrawIndexed(commandBuffer, (MAX_VBO_SIZE - iVertex), 1, iVertex, 0, 0);
break;
}
@@ -515,10 +516,10 @@ void KRMesh::renderSubmesh(VkCommandBuffer& commandBuffer, int iSubmesh, KRNode:
assert(iVertex + cVertexes <= cBufferVertexes);
switch (getModelFormat()) {
case KRENGINE_MODEL_FORMAT_TRIANGLES:
case ModelFormat::KRENGINE_MODEL_FORMAT_TRIANGLES:
GLDEBUG(glDrawArrays(GL_TRIANGLES, iVertex, cVertexes));
break;
case KRENGINE_MODEL_FORMAT_STRIP:
case ModelFormat::KRENGINE_MODEL_FORMAT_STRIP:
GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, iVertex, cVertexes));
break;
default:
@@ -626,7 +627,7 @@ void KRMesh::LoadData(const KRMesh::mesh_info &mi, bool calculate_normals, bool
pHeader->bone_count = (__int32_t)bone_count;
pHeader->index_count = (__int32_t)index_count;
pHeader->index_base_count = (__int32_t)index_base_count;
pHeader->model_format = mi.format;
pHeader->model_format = (__int32_t)mi.format;
strcpy(pHeader->szTag, "KROBJPACK1.2 ");
updateAttributeOffsets();
@@ -704,7 +705,7 @@ void KRMesh::LoadData(const KRMesh::mesh_info &mi, bool calculate_normals, bool
*index_base_data++ = (*itr).second;
}
if(getModelFormat() == KRENGINE_MODEL_FORMAT_TRIANGLES) {
if(getModelFormat() == ModelFormat::KRENGINE_MODEL_FORMAT_TRIANGLES) {
// Calculate missing surface normals and tangents
//cout << " Calculate surface normals and tangents\n";
if(calculate_normals || calculate_tangents) {
@@ -1147,9 +1148,9 @@ Matrix4 KRMesh::getBoneBindPose(int bone_index)
return Matrix4::Create(getBone(bone_index)->bind_pose);
}
KRMesh::model_format_t KRMesh::getModelFormat() const
ModelFormat KRMesh::getModelFormat() const
{
model_format_t f = (model_format_t)getHeader()->model_format;
ModelFormat f = (ModelFormat)getHeader()->model_format;
return f;
}
@@ -1195,8 +1196,8 @@ bool KRMesh::rayCast(const Vector3 &start, const Vector3 &dir, HitInfo &hitinfo)
// int vertex_start = getSubmesh(submesh_index)->start_vertex;
int vertex_count = getVertexCount(submesh_index);
switch(getModelFormat()) {
case KRENGINE_MODEL_FORMAT_TRIANGLES:
case KRENGINE_MODEL_FORMAT_INDEXED_TRIANGLES:
case ModelFormat::KRENGINE_MODEL_FORMAT_TRIANGLES:
case ModelFormat::KRENGINE_MODEL_FORMAT_INDEXED_TRIANGLES:
for(int triangle_index=0; triangle_index < vertex_count / 3; triangle_index++) {
int tri_vert_index[3]; // FINDME, HACK! This is not very efficient for indexed collider meshes...
tri_vert_index[0] = getTriangleVertexIndex(submesh_index, triangle_index*3);
@@ -1212,8 +1213,8 @@ bool KRMesh::rayCast(const Vector3 &start, const Vector3 &dir, HitInfo &hitinfo)
NOTE: Not yet supported:
case KRENGINE_MODEL_FORMAT_STRIP:
case KRENGINE_MODEL_FORMAT_INDEXED_STRIP:
case ModelFormat::KRENGINE_MODEL_FORMAT_STRIP:
case ModelFormat::KRENGINE_MODEL_FORMAT_INDEXED_STRIP:
for(int triangle_index=0; triangle_index < vertex_count - 2; triangle_index++) {
int tri_vert_index[3];
tri_vert_index[0] = getTriangleVertexIndex(submesh_index, vertex_start + triangle_index*3);
@@ -1241,8 +1242,8 @@ bool KRMesh::sphereCast(const Matrix4 &model_to_world, const Vector3 &v0, const
for(int submesh_index=0; submesh_index < getSubmeshCount(); submesh_index++) {
int vertex_count = getVertexCount(submesh_index);
switch(getModelFormat()) {
case KRENGINE_MODEL_FORMAT_TRIANGLES:
case KRENGINE_MODEL_FORMAT_INDEXED_TRIANGLES:
case ModelFormat::KRENGINE_MODEL_FORMAT_TRIANGLES:
case ModelFormat::KRENGINE_MODEL_FORMAT_INDEXED_TRIANGLES:
for(int triangle_index=0; triangle_index < vertex_count / 3; triangle_index++) {
int tri_vert_index[3]; // FINDME, HACK! This is not very efficient for indexed collider meshes...
tri_vert_index[0] = getTriangleVertexIndex(submesh_index, triangle_index*3);
@@ -1264,8 +1265,8 @@ bool KRMesh::sphereCast(const Matrix4 &model_to_world, const Vector3 &v0, const
NOTE: Not yet supported:
case KRENGINE_MODEL_FORMAT_STRIP:
case KRENGINE_MODEL_FORMAT_INDEXED_STRIP:
case ModelFormat::KRENGINE_MODEL_FORMAT_STRIP:
case ModelFormat::KRENGINE_MODEL_FORMAT_INDEXED_STRIP:
for(int triangle_index=0; triangle_index < vertex_count - 2; triangle_index++) {
int tri_vert_index[3];
tri_vert_index[0] = getTriangleVertexIndex(submesh_index, vertex_start + triangle_index*3);
@@ -1511,7 +1512,7 @@ void KRMesh::convertToIndexed()
KRContext::Log(KRContext::LOG_LEVEL_INFORMATION, "Convert to indexed, before: %i after: %i (%.2f%% saving)", getHeader()->vertex_count, mi.vertices.size(), ((float)getHeader()->vertex_count - (float)mi.vertices.size()) / (float)getHeader()->vertex_count * 100.0f);
mi.format = KRENGINE_MODEL_FORMAT_INDEXED_TRIANGLES;
mi.format = ModelFormat::KRENGINE_MODEL_FORMAT_INDEXED_TRIANGLES;
m_pData->unlock();
LoadData(mi, false, false);
@@ -1520,7 +1521,7 @@ void KRMesh::convertToIndexed()
void KRMesh::optimize()
{
switch(getModelFormat()) {
case KRENGINE_MODEL_FORMAT_INDEXED_TRIANGLES:
case ModelFormat::KRENGINE_MODEL_FORMAT_INDEXED_TRIANGLES:
optimizeIndexes();
break;
default:
@@ -1546,7 +1547,7 @@ void KRMesh::getIndexedRange(int index_group, int &start_index_offset, int &star
int KRMesh::getTriangleVertexIndex(int submesh, int index) const
{
switch(getModelFormat()) {
case KRENGINE_MODEL_FORMAT_INDEXED_TRIANGLES:
case ModelFormat::KRENGINE_MODEL_FORMAT_INDEXED_TRIANGLES:
{
__uint16_t *index_data = getIndexData();
@@ -1572,7 +1573,7 @@ int KRMesh::getTriangleVertexIndex(int submesh, int index) const
void KRMesh::optimizeIndexes()
{
m_pData->lock();
if(getModelFormat() == KRENGINE_MODEL_FORMAT_INDEXED_TRIANGLES) {
if(getModelFormat() == ModelFormat::KRENGINE_MODEL_FORMAT_INDEXED_TRIANGLES) {
__uint16_t *new_indices = (__uint16_t *)malloc(0x10000 * sizeof(__uint16_t));
__uint16_t *vertex_mapping = (__uint16_t *)malloc(0x10000 * sizeof(__uint16_t));
@@ -1653,7 +1654,7 @@ void KRMesh::optimizeIndexes()
free(new_indices);
free(vertex_mapping);
free(new_vertex_data);
} // if(getModelFormat() == KRENGINE_MODEL_FORMAT_INDEXED_TRIANGLES)
} // if(getModelFormat() == ModelFormat::KRENGINE_MODEL_FORMAT_INDEXED_TRIANGLES)
m_pData->unlock();
}

View File

@@ -28,6 +28,9 @@
// authors and should not be interpreted as representing official policies, either expressed
// or implied, of Kearwood Gilbert.
//
#pragma once
#include "KREngine-common.h"
#include "KRContext.h"
@@ -47,9 +50,6 @@ using namespace kraken;
#define BUFFER_OFFSET(i) ((char *)NULL + (i))
#ifndef KRMesh_I
#define KRMesh_I
#include "KRMaterialManager.h"
#include "KRCamera.h"
#include "KRViewport.h"
@@ -57,6 +57,14 @@ using namespace kraken;
class KRMaterial;
class KRNode;
enum class ModelFormat : __uint8_t
{
KRENGINE_MODEL_FORMAT_TRIANGLES = 0,
KRENGINE_MODEL_FORMAT_STRIP,
KRENGINE_MODEL_FORMAT_INDEXED_TRIANGLES,
KRENGINE_MODEL_FORMAT_INDEXED_STRIP
};
class KRMesh : public KRResource {
public:
@@ -87,15 +95,10 @@ public:
KRENGINE_NUM_ATTRIBUTES
} vertex_attrib_t;
typedef enum {
KRENGINE_MODEL_FORMAT_TRIANGLES = 0,
KRENGINE_MODEL_FORMAT_STRIP,
KRENGINE_MODEL_FORMAT_INDEXED_TRIANGLES,
KRENGINE_MODEL_FORMAT_INDEXED_STRIP
} model_format_t;
typedef struct {
model_format_t format;
ModelFormat format;
std::vector<Vector3> vertices;
std::vector<__uint16_t> vertex_indexes;
std::vector<std::pair<int, int> > vertex_index_bases;
@@ -213,7 +216,7 @@ public:
Matrix4 getBoneBindPose(int bone_index);
model_format_t getModelFormat() const;
ModelFormat getModelFormat() const;
bool lineCast(const Vector3 &v0, const Vector3 &v1, HitInfo &hitinfo) const;
bool rayCast(const Vector3 &v0, const Vector3 &dir, HitInfo &hitinfo) const;
@@ -289,6 +292,3 @@ private:
};
#endif // KRMesh_I

View File

@@ -57,7 +57,7 @@ KRMeshCube::KRMeshCube(KRContext &context) : KRMesh(context, "__cube")
mi.submesh_starts.push_back(0);
mi.submesh_lengths.push_back((int)mi.vertices.size());
mi.material_names.push_back("");
mi.format = KRENGINE_MODEL_FORMAT_STRIP;
mi.format = ModelFormat::KRENGINE_MODEL_FORMAT_STRIP;
LoadData(mi, true, true);

View File

@@ -52,7 +52,7 @@ KRMeshQuad::KRMeshQuad(KRContext &context) : KRMesh(context, "__quad")
mi.submesh_starts.push_back(0);
mi.submesh_lengths.push_back((int)mi.vertices.size());
mi.material_names.push_back("");
mi.format = KRENGINE_MODEL_FORMAT_STRIP;
mi.format = ModelFormat::KRENGINE_MODEL_FORMAT_STRIP;
LoadData(mi, true, true);
}

View File

@@ -112,7 +112,7 @@ KRMeshSphere::KRMeshSphere(KRContext &context) : KRMesh(context, "__sphere")
mi.material_names.push_back("");
mi.format = KRENGINE_MODEL_FORMAT_TRIANGLES;
mi.format = ModelFormat::KRENGINE_MODEL_FORMAT_TRIANGLES;
LoadData(mi, true, true);
}

View File

@@ -98,10 +98,10 @@ void KRParticleSystemNewtonian::render(RenderInfo& ri) {
info.directional_lights = &ri.directional_lights;
info.spot_lights = &ri.spot_lights;
info.renderPass = ri.renderPass;
info.rasterMode = PipelineInfo::RasterMode::kAdditive;
info.cullMode = PipelineInfo::CullMode::kCullNone;
info.rasterMode = RasterMode::kAdditive;
info.cullMode = CullMode::kCullNone;
info.vertexAttributes = (1 << KRMesh::KRENGINE_ATTRIB_VERTEX) | (1 << KRMesh::KRENGINE_ATTRIB_TEXUVA);
info.modelFormat = KRMesh::model_format_t::KRENGINE_MODEL_FORMAT_TRIANGLES;
info.modelFormat = ModelFormat::KRENGINE_MODEL_FORMAT_TRIANGLES;
KRPipeline *pParticleShader = m_pContext->getPipelineManager()->getPipeline(*ri.surface, info);
pParticleShader->setUniform(KRPipeline::KRENGINE_UNIFORM_FLARE_SIZE, 1.0f);

View File

@@ -110,7 +110,7 @@ const char *KRPipeline::KRENGINE_UNIFORM_NAMES[] = {
"fade_color", // KRENGINE_UNIFORM_FADE_COLOR
};
KRPipeline::KRPipeline(KRContext& context, KRSurface& surface, const PipelineInfo& info, const char* szKey, const std::vector<KRShader*>& shaders, uint32_t vertexAttributes, KRMesh::model_format_t modelFormat)
KRPipeline::KRPipeline(KRContext& context, KRSurface& surface, const PipelineInfo& info, const char* szKey, const std::vector<KRShader*>& shaders, uint32_t vertexAttributes, ModelFormat modelFormat)
: KRContextObject(context)
, m_pushConstantBuffer(nullptr)
, m_pushConstantBufferSize(0)
@@ -251,12 +251,12 @@ KRPipeline::KRPipeline(KRContext& context, KRSurface& surface, const PipelineInf
VkPipelineInputAssemblyStateCreateInfo inputAssembly{};
inputAssembly.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
switch (modelFormat) {
case KRMesh::model_format_t::KRENGINE_MODEL_FORMAT_INDEXED_TRIANGLES:
case KRMesh::model_format_t::KRENGINE_MODEL_FORMAT_TRIANGLES:
case ModelFormat::KRENGINE_MODEL_FORMAT_INDEXED_TRIANGLES:
case ModelFormat::KRENGINE_MODEL_FORMAT_TRIANGLES:
inputAssembly.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
break;
case KRMesh::model_format_t::KRENGINE_MODEL_FORMAT_INDEXED_STRIP:
case KRMesh::model_format_t::KRENGINE_MODEL_FORMAT_STRIP:
case ModelFormat::KRENGINE_MODEL_FORMAT_INDEXED_STRIP:
case ModelFormat::KRENGINE_MODEL_FORMAT_STRIP:
inputAssembly.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
break;
}
@@ -290,13 +290,13 @@ KRPipeline::KRPipeline(KRContext& context, KRSurface& surface, const PipelineInf
rasterizer.polygonMode = VK_POLYGON_MODE_FILL;
rasterizer.lineWidth = 1.0f;
switch (info.cullMode) {
case PipelineInfo::CullMode::kCullBack:
case CullMode::kCullBack:
rasterizer.cullMode = VK_CULL_MODE_BACK_BIT;
break;
case PipelineInfo::CullMode::kCullFront:
case CullMode::kCullFront:
rasterizer.cullMode = VK_CULL_MODE_FRONT_BIT;
break;
case PipelineInfo::CullMode::kCullNone:
case CullMode::kCullNone:
rasterizer.cullMode = VK_CULL_MODE_NONE;
break;
}
@@ -319,24 +319,24 @@ KRPipeline::KRPipeline(KRContext& context, KRSurface& surface, const PipelineInf
colorBlendAttachment.colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT;
switch (info.rasterMode) {
case PipelineInfo::RasterMode::kOpaque:
case PipelineInfo::RasterMode::kOpaqueLessTest:
case PipelineInfo::RasterMode::kOpaqueNoTest:
case PipelineInfo::RasterMode::kOpaqueNoDepthWrite:
case RasterMode::kOpaque:
case RasterMode::kOpaqueLessTest:
case RasterMode::kOpaqueNoTest:
case RasterMode::kOpaqueNoDepthWrite:
colorBlendAttachment.blendEnable = VK_FALSE;
colorBlendAttachment.srcColorBlendFactor = VK_BLEND_FACTOR_ONE;
colorBlendAttachment.dstColorBlendFactor = VK_BLEND_FACTOR_ZERO;
colorBlendAttachment.colorBlendOp = VK_BLEND_OP_ADD;
break;
case PipelineInfo::RasterMode::kAlphaBlend:
case PipelineInfo::RasterMode::kAlphaBlendNoTest:
case RasterMode::kAlphaBlend:
case RasterMode::kAlphaBlendNoTest:
colorBlendAttachment.blendEnable = VK_TRUE;
colorBlendAttachment.srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA;
colorBlendAttachment.dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
colorBlendAttachment.colorBlendOp = VK_BLEND_OP_ADD;
break;
case PipelineInfo::RasterMode::kAdditive:
case PipelineInfo::RasterMode::kAdditiveNoTest:
case RasterMode::kAdditive:
case RasterMode::kAdditiveNoTest:
colorBlendAttachment.blendEnable = VK_TRUE;
colorBlendAttachment.srcColorBlendFactor = VK_BLEND_FACTOR_ONE;
colorBlendAttachment.dstColorBlendFactor = VK_BLEND_FACTOR_ONE;
@@ -393,29 +393,29 @@ KRPipeline::KRPipeline(KRContext& context, KRSurface& surface, const PipelineInf
VkPipelineDepthStencilStateCreateInfo depthStencil{};
depthStencil.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
switch (info.rasterMode) {
case PipelineInfo::RasterMode::kOpaque:
case PipelineInfo::RasterMode::kOpaqueLessTest:
case RasterMode::kOpaque:
case RasterMode::kOpaqueLessTest:
depthStencil.depthTestEnable = VK_TRUE;
depthStencil.depthWriteEnable = VK_TRUE;
break;
case PipelineInfo::RasterMode::kOpaqueNoTest:
case RasterMode::kOpaqueNoTest:
depthStencil.depthTestEnable = VK_FALSE;
depthStencil.depthWriteEnable = VK_TRUE;
break;
case PipelineInfo::RasterMode::kOpaqueNoDepthWrite:
case PipelineInfo::RasterMode::kAlphaBlend:
case PipelineInfo::RasterMode::kAdditive:
case RasterMode::kOpaqueNoDepthWrite:
case RasterMode::kAlphaBlend:
case RasterMode::kAdditive:
depthStencil.depthTestEnable = VK_TRUE;
depthStencil.depthWriteEnable = VK_FALSE;
break;
case PipelineInfo::RasterMode::kAlphaBlendNoTest:
case PipelineInfo::RasterMode::kAdditiveNoTest:
case RasterMode::kAlphaBlendNoTest:
case RasterMode::kAdditiveNoTest:
depthStencil.depthTestEnable = VK_FALSE;
depthStencil.depthWriteEnable = VK_FALSE;
break;
}
if (info.rasterMode == PipelineInfo::RasterMode::kOpaqueLessTest) {
if (info.rasterMode == RasterMode::kOpaqueLessTest) {
depthStencil.depthCompareOp = VK_COMPARE_OP_LESS;
} else {
depthStencil.depthCompareOp = VK_COMPARE_OP_LESS_OR_EQUAL;

View File

@@ -30,9 +30,7 @@
//
#ifndef KRPIPELINE_H
#define KRPIPELINE_H
#pragma once
#include "KREngine-common.h"
#include "KRCamera.h"
@@ -44,134 +42,138 @@ class KRShader;
class KRSurface;
class KRRenderPass;
enum class ModelFormat : __uint8_t;
enum class CullMode : uint32_t {
kCullBack = 0,
kCullFront,
kCullNone
};
// Note: RasterMode is likely to be refactored later to a bitfield
enum class RasterMode : uint32_t {
kOpaque = 0,
/*
kOpaque is equivalent to:
// Disable blending
glDisable(GL_BLEND));
// Enable z-buffer write
glDepthMask(GL_TRUE);
// Enable z-buffer test
glEnable(GL_DEPTH_TEST))
glDepthFunc(GL_LEQUAL);
glDepthRangef(0.0, 1.0);
*/
kOpaqueNoDepthWrite,
/*
kOpaque is equivalent to:
// Disable blending
glDisable(GL_BLEND));
// Disable z-buffer write
glDepthMask(GL_FALSE);
// Enable z-buffer test
glEnable(GL_DEPTH_TEST))
glDepthFunc(GL_LEQUAL);
glDepthRangef(0.0, 1.0);
*/
kOpaqueLessTest,
/*
kOpaqueLessTest is equivalent to:
// Disable blending
glDisable(GL_BLEND));
// Enable z-buffer write
glDepthMask(GL_TRUE);
// Enable z-buffer test
glEnable(GL_DEPTH_TEST))
glDepthFunc(GL_LESS);
glDepthRangef(0.0, 1.0);
*/
kOpaqueNoTest,
/*
kOpaqueNoTest is equivalent to:
// Disable blending
glDisable(GL_BLEND));
// Enable z-buffer write
glDepthMask(GL_TRUE);
// Disable z-buffer test
glDisable(GL_DEPTH_TEST)
*/
kAlphaBlend,
/*
kAlphaBlend is equivalent to:
// Enable alpha blending
glEnable(GL_BLEND));
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA));
// Disable z-buffer write
glDepthMask(GL_FALSE);
// Enable z-buffer test
glEnable(GL_DEPTH_TEST))
glDepthFunc(GL_LEQUAL);
glDepthRangef(0.0, 1.0);
*/
kAlphaBlendNoTest,
/*
kAlphaBlendNoTest is equivalent to:
// Enable alpha blending
glEnable(GL_BLEND));
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA));
// Disable z-buffer write
glDepthMask(GL_FALSE);
// Disable z-buffer test
glDisable(GL_DEPTH_TEST)
*/
kAdditive,
/*
kAdditive is equivalent to:
// Enable additive blending
glEnable(GL_BLEND));
glBlendFunc(GL_ONE, GL_ONE));
// Disable z-buffer write
glDepthMask(GL_FALSE);
// Enable z-buffer test
glEnable(GL_DEPTH_TEST))
glDepthFunc(GL_LEQUAL);
glDepthRangef(0.0, 1.0);
*/
kAdditiveNoTest,
/*
kAdditive is equivalent to:
// Enable additive blending
glEnable(GL_BLEND));
glBlendFunc(GL_ONE, GL_ONE));
// Disable z-buffer write
glDepthMask(GL_FALSE);
// Disable z-buffer test
glDisable(GL_DEPTH_TEST)
*/
};
class PipelineInfo {
public:
// Note: RasterMode is likely to be refactored later to a bitfield
enum class RasterMode : uint32_t {
kOpaque = 0,
/*
kOpaque is equivalent to:
// Disable blending
glDisable(GL_BLEND));
// Enable z-buffer write
glDepthMask(GL_TRUE);
// Enable z-buffer test
glEnable(GL_DEPTH_TEST))
glDepthFunc(GL_LEQUAL);
glDepthRangef(0.0, 1.0);
*/
kOpaqueNoDepthWrite,
/*
kOpaque is equivalent to:
// Disable blending
glDisable(GL_BLEND));
// Disable z-buffer write
glDepthMask(GL_FALSE);
// Enable z-buffer test
glEnable(GL_DEPTH_TEST))
glDepthFunc(GL_LEQUAL);
glDepthRangef(0.0, 1.0);
*/
kOpaqueLessTest,
/*
kOpaqueLessTest is equivalent to:
// Disable blending
glDisable(GL_BLEND));
// Enable z-buffer write
glDepthMask(GL_TRUE);
// Enable z-buffer test
glEnable(GL_DEPTH_TEST))
glDepthFunc(GL_LESS);
glDepthRangef(0.0, 1.0);
*/
kOpaqueNoTest,
/*
kOpaqueNoTest is equivalent to:
// Disable blending
glDisable(GL_BLEND));
// Enable z-buffer write
glDepthMask(GL_TRUE);
// Disable z-buffer test
glDisable(GL_DEPTH_TEST)
*/
kAlphaBlend,
/*
kAlphaBlend is equivalent to:
// Enable alpha blending
glEnable(GL_BLEND));
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA));
// Disable z-buffer write
glDepthMask(GL_FALSE);
// Enable z-buffer test
glEnable(GL_DEPTH_TEST))
glDepthFunc(GL_LEQUAL);
glDepthRangef(0.0, 1.0);
*/
kAlphaBlendNoTest,
/*
kAlphaBlendNoTest is equivalent to:
// Enable alpha blending
glEnable(GL_BLEND));
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA));
// Disable z-buffer write
glDepthMask(GL_FALSE);
// Disable z-buffer test
glDisable(GL_DEPTH_TEST)
*/
kAdditive,
/*
kAdditive is equivalent to:
// Enable additive blending
glEnable(GL_BLEND));
glBlendFunc(GL_ONE, GL_ONE));
// Disable z-buffer write
glDepthMask(GL_FALSE);
// Enable z-buffer test
glEnable(GL_DEPTH_TEST))
glDepthFunc(GL_LEQUAL);
glDepthRangef(0.0, 1.0);
*/
kAdditiveNoTest,
/*
kAdditive is equivalent to:
// Enable additive blending
glEnable(GL_BLEND));
glBlendFunc(GL_ONE, GL_ONE));
// Disable z-buffer write
glDepthMask(GL_FALSE);
// Disable z-buffer test
glDisable(GL_DEPTH_TEST)
*/
};
enum class CullMode : uint32_t {
kCullBack = 0,
kCullFront,
kCullNone
};
const std::string* shader_name;
KRCamera* pCamera;
const std::vector<KRPointLight*>* point_lights;
@@ -197,14 +199,14 @@ public:
RasterMode rasterMode;
CullMode cullMode;
uint32_t vertexAttributes;
KRMesh::model_format_t modelFormat;
ModelFormat modelFormat;
KRNode::RenderPass renderPass;
};
class KRPipeline : public KRContextObject {
public:
KRPipeline(KRContext& context, KRSurface& surface, const PipelineInfo& info, const char* szKey, const std::vector<KRShader*>& shaders, uint32_t vertexAttributes, KRMesh::model_format_t modelFormat);
KRPipeline(KRContext& context, KRSurface& surface, const PipelineInfo& info, const char* szKey, const std::vector<KRShader*>& shaders, uint32_t vertexAttributes, ModelFormat modelFormat);
virtual ~KRPipeline();
const char *getKey() const;
@@ -305,5 +307,3 @@ private:
VkPipelineLayout m_pushConstantsLayout;
};
#endif

View File

@@ -72,7 +72,7 @@ KRPipeline* KRPipelineManager::getPipeline(KRSurface& surface, const PipelineInf
key.second.push_back(surface.m_swapChain->m_extent.width);
key.second.push_back(surface.m_swapChain->m_extent.height);
key.second.push_back(info.vertexAttributes);
key.second.push_back(info.modelFormat);
key.second.push_back((int)info.modelFormat);
// TODO - Add renderPass unique identifier to key
PipelineMap::iterator itr = m_pipelines.find(key);
if (itr != m_pipelines.end()) {
@@ -220,10 +220,10 @@ KRPipeline *KRPipelineManager::getPipeline(KRSurface& surface, const PipelineInf
stream << "\n#define HAS_REFLECTION_CUBE_MAP " << (info.bReflectionCubeMap ? "1" : "0");
stream << "\n#define ALPHA_TEST " << (info.bAlphaTest ? "1" : "0");
stream << "\n#define ALPHA_BLEND " << ((info.rasterMode == PipelineInfo::RasterMode::kAlphaBlend
|| info.rasterMode == PipelineInfo::RasterMode::kAlphaBlendNoTest
|| info.rasterMode == PipelineInfo::RasterMode::kAdditive
|| info.rasterMode == PipelineInfo::RasterMode::kAdditiveNoTest) ? "1" : "0");
stream << "\n#define ALPHA_BLEND " << ((info.rasterMode == RasterMode::kAlphaBlend
|| info.rasterMode == RasterMode::kAlphaBlendNoTest
|| info.rasterMode == RasterMode::kAdditive
|| info.rasterMode == RasterMode::kAdditiveNoTest) ? "1" : "0");
stream << "\n#define ENABLE_PER_PIXEL " << (info.pCamera->settings.bEnablePerPixel ? "1" : "0");
stream << "\n#define DEBUG_PSSM " << (info.pCamera->settings.bDebugPSSM ? "1" : "0");

View File

@@ -29,6 +29,7 @@
// or implied, of Kearwood Gilbert.
//
#pragma once
#include "KREngine-common.h"
@@ -43,9 +44,6 @@ using std::vector;
#include "KRPipeline.h"
#ifndef KRPIPELINEMANAGER_H
#define KRPIPELINEMANAGER_H
class KRPipeline;
class PipelineInfo;
class KRCamera;
@@ -67,5 +65,3 @@ private:
typedef std::map<std::pair<std::string, std::vector<int> >, KRPipeline*> PipelineMap;
PipelineMap m_pipelines;
};
#endif

View File

@@ -103,13 +103,13 @@ void KRPointLight::render(RenderInfo& ri)
info.point_lights = &this_light;
info.renderPass = ri.renderPass;
if (bInsideLight) {
info.rasterMode = bVisualize ? PipelineInfo::RasterMode::kAdditiveNoTest : PipelineInfo::RasterMode::kAlphaBlendNoTest;
info.rasterMode = bVisualize ? RasterMode::kAdditiveNoTest : RasterMode::kAlphaBlendNoTest;
}
else {
info.rasterMode = bVisualize ? PipelineInfo::RasterMode::kAdditive : PipelineInfo::RasterMode::kAlphaBlend;
info.rasterMode = bVisualize ? RasterMode::kAdditive : RasterMode::kAlphaBlend;
}
info.vertexAttributes = bInsideLight ? m_pContext->getMeshManager()->KRENGINE_VBO_DATA_2D_SQUARE_VERTICES.getVertexAttributes() : 1 << KRMesh::KRENGINE_ATTRIB_VERTEX;
info.modelFormat = bInsideLight ? KRMesh::model_format_t::KRENGINE_MODEL_FORMAT_STRIP : KRMesh::model_format_t::KRENGINE_MODEL_FORMAT_TRIANGLES;
info.modelFormat = bInsideLight ? ModelFormat::KRENGINE_MODEL_FORMAT_STRIP : ModelFormat::KRENGINE_MODEL_FORMAT_TRIANGLES;
KRPipeline *pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, info);
pShader->setUniform(KRPipeline::KRENGINE_UNIFORM_LIGHT_COLOR, m_color);

View File

@@ -1282,7 +1282,7 @@ void LoadMaterial(KRContext &context, FbxSurfaceMaterial *pMaterial) {
void LoadMesh(KRContext &context, FbxScene* pFbxScene, FbxGeometryConverter *pGeometryConverter, FbxMesh* pMesh) {
KRMesh::mesh_info mi;
mi.format = KRMesh::KRENGINE_MODEL_FORMAT_TRIANGLES;
mi.format = ModelFormat::KRENGINE_MODEL_FORMAT_TRIANGLES;
typedef struct {
float weights[KRENGINE_MAX_BONE_WEIGHTS_PER_VERTEX];

View File

@@ -349,7 +349,7 @@ KRMesh* KRResource::LoadObj(KRContext &context, const std::string& path)
// std::vector<__uint16_t> vertex_indexes;
// std::vector<std::pair<int, int> > vertex_index_bases;
mi.format = KRMesh::KRENGINE_MODEL_FORMAT_TRIANGLES;
mi.format = ModelFormat::KRENGINE_MODEL_FORMAT_TRIANGLES;
new_mesh->LoadData(mi, true, false);
}

View File

@@ -137,7 +137,7 @@ void KRReverbZone::render(RenderInfo& ri)
info.directional_lights = &ri.directional_lights;
info.spot_lights = &ri.spot_lights;
info.renderPass = ri.renderPass;
info.rasterMode = PipelineInfo::RasterMode::kAlphaBlend;
info.rasterMode = RasterMode::kAlphaBlend;
info.modelFormat = sphereModel->getModelFormat();
info.vertexAttributes = sphereModel->getVertexAttributes();

View File

@@ -293,9 +293,9 @@ void KRScene::render(KRNode::RenderInfo& ri, KROctreeNode* pOctreeNode, unordere
info.directional_lights = &ri.directional_lights;
info.spot_lights = &ri.spot_lights;
info.renderPass = KRNode::RENDER_PASS_FORWARD_TRANSPARENT;
info.rasterMode = PipelineInfo::RasterMode::kAdditive;
info.rasterMode = RasterMode::kAdditive;
info.vertexAttributes = vertices.getVertexAttributes();
info.modelFormat = KRMesh::model_format_t::KRENGINE_MODEL_FORMAT_STRIP;
info.modelFormat = ModelFormat::KRENGINE_MODEL_FORMAT_STRIP;
KRPipeline* pPipeline = getContext().getPipelineManager()->getPipeline(*ri.surface, info);
pPipeline->bind(ri.commandBuffer, *info.pCamera, ri.viewport, matModel, info.point_lights, info.directional_lights, info.spot_lights, info.renderPass, Vector3::Zero(), 0.0f, Vector4::Zero());

View File

@@ -152,10 +152,10 @@ void KRSprite::render(RenderInfo& ri) {
info.directional_lights = &ri.directional_lights;
info.spot_lights = &ri.spot_lights;
info.renderPass = ri.renderPass;
info.rasterMode = PipelineInfo::RasterMode::kAdditive;
info.cullMode = PipelineInfo::CullMode::kCullNone;
info.rasterMode = RasterMode::kAdditive;
info.cullMode = CullMode::kCullNone;
info.vertexAttributes = vertices.getVertexAttributes();
info.modelFormat = KRMesh::model_format_t::KRENGINE_MODEL_FORMAT_STRIP;
info.modelFormat = ModelFormat::KRENGINE_MODEL_FORMAT_STRIP;
KRPipeline *pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, info);
pShader->setUniform(KRPipeline::KRENGINE_UNIFORM_MATERIAL_ALPHA, m_spriteAlpha);