KRPipeline's are now created with the passed in KRMesh::model_format_t
This commit is contained in:
@@ -109,7 +109,7 @@ const char *KRPipeline::KRENGINE_UNIFORM_NAMES[] = {
|
||||
"fade_color", // KRENGINE_UNIFORM_FADE_COLOR
|
||||
};
|
||||
|
||||
KRPipeline::KRPipeline(KRContext& context, KRSurface& surface, const char* szKey, const std::vector<KRShader*>& shaders, uint32_t vertexAttributes)
|
||||
KRPipeline::KRPipeline(KRContext& context, KRSurface& surface, const char* szKey, const std::vector<KRShader*>& shaders, uint32_t vertexAttributes, KRMesh::model_format_t modelFormat)
|
||||
: KRContextObject(context)
|
||||
, m_iProgram(0) // not used for Vulkan
|
||||
{
|
||||
@@ -160,24 +160,32 @@ KRPipeline::KRPipeline(KRContext& context, KRSurface& surface, const char* szKey
|
||||
SpvReflectInterfaceVariable& input_var = *reflection->input_variables[i];
|
||||
if (strcmp(input_var.name, "vertex_position") == 0) {
|
||||
attribute_locations[KRMesh::KRENGINE_ATTRIB_VERTEX] = input_var.location + 1;
|
||||
} else if (strcmp(input_var.name, "vertex_normal") == 0) {
|
||||
}
|
||||
else if (strcmp(input_var.name, "vertex_normal") == 0) {
|
||||
attribute_locations[KRMesh::KRENGINE_ATTRIB_NORMAL] = input_var.location + 1;
|
||||
} else if (strcmp(input_var.name, "vertex_tangent") == 0) {
|
||||
}
|
||||
else if (strcmp(input_var.name, "vertex_tangent") == 0) {
|
||||
attribute_locations[KRMesh::KRENGINE_ATTRIB_TANGENT] = input_var.location + 1;
|
||||
} else if (strcmp(input_var.name, "vertex_uv") == 0) {
|
||||
}
|
||||
else if (strcmp(input_var.name, "vertex_uv") == 0) {
|
||||
attribute_locations[KRMesh::KRENGINE_ATTRIB_TEXUVA] = input_var.location + 1;
|
||||
} else if (strcmp(input_var.name, "vertex_lightmap_uv") == 0) {
|
||||
}
|
||||
else if (strcmp(input_var.name, "vertex_lightmap_uv") == 0) {
|
||||
attribute_locations[KRMesh::KRENGINE_ATTRIB_TEXUVB] = input_var.location + 1;
|
||||
} else if (strcmp(input_var.name, "bone_indexes") == 0) {
|
||||
}
|
||||
else if (strcmp(input_var.name, "bone_indexes") == 0) {
|
||||
attribute_locations[KRMesh::KRENGINE_ATTRIB_BONEINDEXES] = input_var.location + 1;
|
||||
} else if (strcmp(input_var.name, "bone_weights") == 0) {
|
||||
}
|
||||
else if (strcmp(input_var.name, "bone_weights") == 0) {
|
||||
attribute_locations[KRMesh::KRENGINE_ATTRIB_BONEWEIGHTS] = input_var.location + 1;
|
||||
}
|
||||
}
|
||||
|
||||
} else if (shader->getSubExtension().compare("frag") == 0) {
|
||||
}
|
||||
else if (shader->getSubExtension().compare("frag") == 0) {
|
||||
stageInfo.stage = VK_SHADER_STAGE_FRAGMENT_BIT;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
// failed! TODO - Error handling
|
||||
}
|
||||
stageInfo.module = shaderModule;
|
||||
@@ -213,7 +221,17 @@ KRPipeline::KRPipeline(KRContext& context, KRSurface& surface, const char* szKey
|
||||
|
||||
VkPipelineInputAssemblyStateCreateInfo inputAssembly{};
|
||||
inputAssembly.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
|
||||
inputAssembly.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
|
||||
switch (modelFormat) {
|
||||
case KRMesh::model_format_t::KRENGINE_MODEL_FORMAT_INDEXED_TRIANGLES:
|
||||
case KRMesh::model_format_t::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:
|
||||
inputAssembly.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
|
||||
break;
|
||||
}
|
||||
|
||||
inputAssembly.primitiveRestartEnable = VK_FALSE;
|
||||
|
||||
VkViewport viewport{};
|
||||
|
||||
@@ -39,13 +39,15 @@
|
||||
#include "KRCamera.h"
|
||||
#include "KRNode.h"
|
||||
#include "KRViewport.h"
|
||||
#include "KRMesh.h"
|
||||
|
||||
class KRShader;
|
||||
class KRSurface;
|
||||
|
||||
|
||||
class KRPipeline : public KRContextObject {
|
||||
public:
|
||||
KRPipeline(KRContext& context, KRSurface& surface, const char* szKey, const std::vector<KRShader*>& shaders, uint32_t vertexAttributes);
|
||||
KRPipeline(KRContext& context, KRSurface& surface, const char* szKey, const std::vector<KRShader*>& shaders, uint32_t vertexAttributes, KRMesh::model_format_t modelFormat);
|
||||
KRPipeline(KRContext &context, char *szKey, std::string options, std::string vertShaderSource, const std::string fragShaderSource);
|
||||
virtual ~KRPipeline();
|
||||
const char *getKey() const;
|
||||
|
||||
@@ -62,7 +62,7 @@ KRPipelineManager::~KRPipelineManager() {
|
||||
#endif // ANDROID
|
||||
}
|
||||
|
||||
KRPipeline* KRPipelineManager::getPipeline(KRSurface& surface, const std::string& shader_name, uint32_t vertexAttributes)
|
||||
KRPipeline* KRPipelineManager::getPipeline(KRSurface& surface, const std::string& shader_name, uint32_t vertexAttributes, KRMesh::model_format_t modelFormat)
|
||||
{
|
||||
std::pair<std::string, std::vector<int> > key;
|
||||
key.first = shader_name;
|
||||
@@ -71,6 +71,7 @@ KRPipeline* KRPipelineManager::getPipeline(KRSurface& surface, const std::string
|
||||
key.second.push_back(surface.m_swapChainExtent.width);
|
||||
key.second.push_back(surface.m_swapChainExtent.height);
|
||||
key.second.push_back(vertexAttributes);
|
||||
key.second.push_back(modelFormat);
|
||||
PipelineMap::iterator itr = m_pipelines.find(key);
|
||||
if (itr != m_pipelines.end()) {
|
||||
return itr->second;
|
||||
@@ -79,7 +80,7 @@ KRPipeline* KRPipelineManager::getPipeline(KRSurface& surface, const std::string
|
||||
std::vector<KRShader*> shaders;
|
||||
shaders.push_back(m_pContext->getShaderManager()->get(shader_name + ".vert", "spv"));
|
||||
shaders.push_back(m_pContext->getShaderManager()->get(shader_name + ".frag", "spv"));
|
||||
KRPipeline* pipeline = new KRPipeline(*m_pContext, surface, shader_name.c_str(), shaders, vertexAttributes);
|
||||
KRPipeline* pipeline = new KRPipeline(*m_pContext, surface, shader_name.c_str(), shaders, vertexAttributes, modelFormat);
|
||||
|
||||
m_pipelines[key] = pipeline;
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
#include "KRDataBlock.h"
|
||||
#include "KRNode.h"
|
||||
#include "KRSurface.h"
|
||||
#include "KRMesh.h"
|
||||
|
||||
using std::map;
|
||||
using std::vector;
|
||||
@@ -54,7 +55,7 @@ public:
|
||||
virtual ~KRPipelineManager();
|
||||
KRPipeline* get(const char* szKey);
|
||||
|
||||
KRPipeline *getPipeline(KRSurface& surface, const std::string& shader_name, uint32_t vertexAttributes);
|
||||
KRPipeline *getPipeline(KRSurface& surface, const std::string& shader_name, uint32_t vertexAttributes, KRMesh::model_format_t modelFormat);
|
||||
KRPipeline *getPipeline(const std::string &pipeline_name, KRCamera *pCamera, const std::vector<KRPointLight *> &point_lights, const std::vector<KRDirectionalLight *> &directional_lights, const std::vector<KRSpotLight *>&spot_lights, int bone_count, bool bDiffuseMap, bool bNormalMap, bool bSpecMap, bool bReflectionMap, bool bReflectionCubeMap, bool bLightMap, bool bDiffuseMapScale,bool bSpecMapScale, bool bNormalMapScale, bool bReflectionMapScale, bool bDiffuseMapOffset, bool bSpecMapOffset, bool bNormalMapOffset, bool bReflectionMapOffset, bool bAlphaTest, bool bAlphaBlend, KRNode::RenderPass renderPass, bool bRimColor = false);
|
||||
|
||||
bool selectPipeline(KRCamera &camera, KRPipeline *pPipeline, const KRViewport &viewport, const Matrix4 &matModel, const std::vector<KRPointLight *> &point_lights, const std::vector<KRDirectionalLight *> &directional_lights, const std::vector<KRSpotLight *>&spot_lights, int bone_count, const KRNode::RenderPass &renderPass, const Vector3 &rim_color, float rim_power, const Vector4 &fade_color);
|
||||
|
||||
@@ -167,10 +167,10 @@ void KRPresentationThread::renderFrame()
|
||||
bool haveMesh = testVertices.isVBOReady();
|
||||
|
||||
if (haveMesh) {
|
||||
KRPipeline* testPipeline = m_pContext->getPipelineManager()->getPipeline(surface, "vulkan_test", testVertices.getVertexAttributes());
|
||||
KRPipeline* testPipeline = m_pContext->getPipelineManager()->getPipeline(surface, "vulkan_test", testVertices.getVertexAttributes(), KRMesh::model_format_t::KRENGINE_MODEL_FORMAT_STRIP);
|
||||
testPipeline->bind(commandBuffer);
|
||||
testVertices.bind(commandBuffer);
|
||||
vkCmdDraw(commandBuffer, 3, 1, 0, 0);
|
||||
vkCmdDraw(commandBuffer, 4, 1, 0, 0);
|
||||
}
|
||||
|
||||
vkCmdEndRenderPass(commandBuffer);
|
||||
|
||||
@@ -8,16 +8,11 @@ layout(location = 0) in vec3 vertex_position;
|
||||
layout(location = 1) in vec3 vertex_uv;
|
||||
layout(constant_id = 0) const int QUALITY_LEVEL = 64; // Specialization constant test
|
||||
|
||||
vec2 positions[3] = vec2[](
|
||||
vec2(0.0, -0.5),
|
||||
vec2(0.5, 0.5),
|
||||
vec2(-0.5, 0.5)
|
||||
);
|
||||
|
||||
vec3 colors[3] = vec3[](
|
||||
vec3 colors[4] = vec3[](
|
||||
vec3(1.0, 0.0, 0.0),
|
||||
vec3(0.0, 1.0, 0.0),
|
||||
vec3(0.0, 0.0, 1.0)
|
||||
vec3(0.0, 0.0, 1.0),
|
||||
vec3(1.0, 0.0, 1.0)
|
||||
);
|
||||
|
||||
void main() {
|
||||
|
||||
Reference in New Issue
Block a user