Fixed KRDatablock::Append where the data was not expanded correctly to concatenate a std::String. Converted sprite shader. Adjusted Spirv compile logging.

This commit is contained in:
2020-12-30 18:24:36 -08:00
parent 75d3f019ae
commit 76b7e64ae6
8 changed files with 57 additions and 42 deletions

View File

@@ -329,7 +329,7 @@ void KRDataBlock::append(const std::string &s)
append((void*)szText, text_length + 1); append((void*)szText, text_length + 1);
} else { } else {
// prev_size includes a null terminating character, don't need to add two. // prev_size includes a null terminating character, don't need to add two.
expand(prev_size + text_length); expand(text_length);
lock(); lock();
// Copy new string, overwriting prior null terminating character and // Copy new string, overwriting prior null terminating character and
// including new terminating character // including new terminating character

View File

@@ -288,8 +288,10 @@ bool KRShaderManager::compileAll(KRBundle* outputBundle, KRUnknown* logResource)
program.addShader(&shader); program.addShader(&shader);
} else { } else {
const char* log = shader.getInfoLog(); const char* log = shader.getInfoLog();
logResource->getData()->append(log); if (log[0] != '\0') {
logResource->getData()->append("\n"); logResource->getData()->append(log);
logResource->getData()->append("\n");
}
success = false; success = false;
} }
}; };
@@ -299,8 +301,10 @@ bool KRShaderManager::compileAll(KRBundle* outputBundle, KRUnknown* logResource)
if (!program.link(messages)) { if (!program.link(messages)) {
const char* log = program.getInfoLog(); const char* log = program.getInfoLog();
logResource->getData()->append(log); if (log[0] != '\0') {
logResource->getData()->append("\n"); logResource->getData()->append(log);
logResource->getData()->append("\n");
}
success = false; success = false;
} }
@@ -312,8 +316,11 @@ bool KRShaderManager::compileAll(KRBundle* outputBundle, KRUnknown* logResource)
spv::SpvBuildLogger logger; spv::SpvBuildLogger logger;
glslang::SpvOptions spvOptions; glslang::SpvOptions spvOptions;
glslang::GlslangToSpv(*program.getIntermediate((EShLanguage)stage), spirv, &logger, &spvOptions); glslang::GlslangToSpv(*program.getIntermediate((EShLanguage)stage), spirv, &logger, &spvOptions);
logResource->getData()->append(logger.getAllMessages().c_str()); std::string messages = logger.getAllMessages();
logResource->getData()->append("\n"); if (!messages.empty()) {
logResource->getData()->append(messages.c_str());
logResource->getData()->append("\n");
}
std::string shader_name; std::string shader_name;
switch (stage) switch (stage)

View File

@@ -1,3 +1,5 @@
set(KRAKEN_STANDARD_ASSETS "${KRAKEN_STANDARD_ASSETS}" PARENT_SCOPE) set(KRAKEN_STANDARD_ASSETS "${KRAKEN_STANDARD_ASSETS}" PARENT_SCOPE)
add_standard_asset(simple_blit.frag) add_standard_asset(simple_blit.frag)
add_standard_asset(simple_blit.vert) add_standard_asset(simple_blit.vert)
add_standard_asset(sprite.frag)
add_standard_asset(sprite.vert)

View File

@@ -1,4 +1,4 @@
// Copyright 2019 Kearwood Gilbert. All rights reserved. // Copyright 2020 Kearwood Gilbert. All rights reserved.
// //
// Redistribution and use in source and binary forms, with or without modification, are // Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met: // permitted provided that the following conditions are met:

View File

@@ -1,4 +1,4 @@
// Copyright 2019 Kearwood Gilbert. All rights reserved. // Copyright 2020 Kearwood Gilbert. All rights reserved.
// //
// Redistribution and use in source and binary forms, with or without modification, are // Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met: // permitted provided that the following conditions are met:
@@ -30,13 +30,13 @@
#extension GL_ARB_shading_language_420pack : enable #extension GL_ARB_shading_language_420pack : enable
layout (std140, binding = 0) uniform buf { layout (std140, binding = 0) uniform buf {
mat4 mvp_matrix; // mvp_matrix is the result of multiplying the model, view, and projection matrices mat4 mvp_matrix; // mvp_matrix is the result of multiplying the model, view, and projection matrices
} ubuf; } ubuf;
layout (location = 0) in vec4 vertex_position; layout (location = 0) in vec4 vertex_position;
layout (location = 1) in vec2 vertex_uv; layout (location = 1) in vec2 vertex_uv;
layout (location = 0) out vec2 textureCoordinate; layout (location = 0) out vec2 textureCoordinate;
void main() { void main() {
textureCoordinate = vertex_uv; textureCoordinate = vertex_uv;
gl_Position = ubuf.mvp_matrix * vertex_position; gl_Position = ubuf.mvp_matrix * vertex_position;
} }

View File

@@ -1,19 +1,15 @@
// Copyright 2020 Kearwood Gilbert. All rights reserved.
// //
// sprite.fsh
// KREngine
//
// Copyright 2012 Kearwood Gilbert. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are // Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met: // permitted provided that the following conditions are met:
// //
// 1. Redistributions of source code must retain the above copyright notice, this list of // 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer. // conditions and the following disclaimer.
// //
// 2. Redistributions in binary form must reproduce the above copyright notice, this list // 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials // of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution. // provided with the distribution.
// //
// THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED // THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR
@@ -23,18 +19,27 @@
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// //
// The views and conclusions contained in the software and documentation are those of the // The views and conclusions contained in the software and documentation are those of the
// authors and should not be interpreted as representing official policies, either expressed // authors and should not be interpreted as representing official policies, either expressed
// or implied, of Kearwood Gilbert. // or implied, of Kearwood Gilbert.
// //
out vec4 colorOut; #version 400
#extension GL_ARB_separate_shader_objects : enable
#extension GL_ARB_shading_language_420pack : enable
layout (binding = 0) uniform MaterialObject
{
float alpha;
} material;
layout (binding = 1) uniform sampler2D diffuseTexture;
layout (location = 0) in vec2 textureCoordinate;
layout (location = 0) out vec4 colorOut;
in mediump vec2 texCoord; in mediump vec2 texCoord;
uniform sampler2D diffuseTexture;
uniform lowp float material_alpha;
void main() { void main() {
colorOut = vec4(vec3(texture(diffuseTexture, texCoord)), 1.0) * material_alpha; colorOut = vec4(vec3(texture(diffuseTexture, texCoord)), 1.0) * material.alpha;
} }

View File

@@ -1,19 +1,15 @@
// Copyright 2020 Kearwood Gilbert. All rights reserved.
// //
// sprite.vsh
// KREngine
//
// Copyright 2012 Kearwood Gilbert. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are // Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met: // permitted provided that the following conditions are met:
// //
// 1. Redistributions of source code must retain the above copyright notice, this list of // 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer. // conditions and the following disclaimer.
// //
// 2. Redistributions in binary form must reproduce the above copyright notice, this list // 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials // of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution. // provided with the distribution.
// //
// THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED // THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR
@@ -23,19 +19,24 @@
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// //
// The views and conclusions contained in the software and documentation are those of the // The views and conclusions contained in the software and documentation are those of the
// authors and should not be interpreted as representing official policies, either expressed // authors and should not be interpreted as representing official policies, either expressed
// or implied, of Kearwood Gilbert. // or implied, of Kearwood Gilbert.
// //
in mediump vec2 vertex_uv; #version 400
uniform highp mat4 mvp_matrix; // mvp_matrix is the result of multiplying the model, view, and projection matrices #extension GL_ARB_separate_shader_objects : enable
uniform mediump vec4 viewport; #extension GL_ARB_shading_language_420pack : enable
out mediump vec2 texCoord; layout (std140, binding = 0) uniform buf {
mat4 mvp_matrix; // mvp_matrix is the result of multiplying the model, view, and projection matrices
vec4 viewport;
} ubuf;
layout (location = 0) in vec2 vertex_uv;
layout (location = 0) out vec2 textureCoordinate;
void main() { void main() {
texCoord = vertex_uv; textureCoordinate = vertex_uv;
gl_Position = mvp_matrix * vec4(vertex_uv.x * 2.0 - 1.0, vertex_uv.y * 2.0 - 1.0, 0.0, 1.0); gl_Position = ubuf.mvp_matrix * vec4(vertex_uv.x * 2.0 - 1.0, vertex_uv.y * 2.0 - 1.0, 0.0, 1.0);
} }

View File

@@ -169,7 +169,7 @@ int main( int argc, char *argv[] )
printf("Failed to get shader compile log. (Error %i)\n", result.result); printf("Failed to get shader compile log. (Error %i)\n", result.result);
} else { } else {
// result.data will be a null terminated string // result.data will be a null terminated string
if (result.data != nullptr && static_cast<char*>(result.data)[0] != '\0') { if (result.data != nullptr && result.length > 0) {
printf("Shader compile log:\n%s\n", static_cast<char *>(result.data)); printf("Shader compile log:\n%s\n", static_cast<char *>(result.data));
} }
} }