Browse Source

Fixed compilation for GCC 2

master
Alexander Memer 1 year ago
parent
commit
063293566b
12 changed files with 161 additions and 44 deletions
  1. 10
    9
      include/Event.hpp
  2. BIN
      include/PCH.hpp
  3. 53
    0
      include/Shader.hpp.bak
  4. BIN
      include/targetver.hpp
  5. BIN
      shaders/frag.spv
  6. 0
    10
      shaders/shader.frag
  7. 0
    22
      shaders/shader.vert
  8. BIN
      shaders/vert.spv
  9. 3
    3
      src/Engine.cpp
  10. BIN
      src/PCH.cpp
  11. 95
    0
      src/Shader.cpp.bak
  12. BIN
      vulkan-1.dll

+ 10
- 9
include/Event.hpp View File

@@ -10,7 +10,8 @@ struct Event
Event() {}
Event(Type pType) : type(pType) {}

union {
union EventUnion {
EventUnion(){}
struct key_struct {
Key key;
bool shift;
@@ -20,11 +21,11 @@ struct Event
bool caps;
};
key_struct keyEvent;
};
} eventUnion;

void constructKey(Key pKey, bool pShift, bool pAlt, bool pSys, bool pCtrl, bool pCaps)
{
keyEvent.key = pKey; keyEvent.shift = pShift; keyEvent.alt = pAlt; keyEvent.sys = pSys; keyEvent.ctrl = pCtrl; keyEvent.caps = pCaps;
eventUnion.keyEvent.key = pKey; eventUnion.keyEvent.shift = pShift; eventUnion.keyEvent.alt = pAlt; eventUnion.keyEvent.sys = pSys; eventUnion.keyEvent.ctrl = pCtrl; eventUnion.keyEvent.caps = pCaps;
}
};

@@ -57,10 +58,10 @@ public:
class KeyEvent : private Event
{
public:
Key getKey() { return keyEvent.key; }
bool getShift() { return keyEvent.shift; }
bool getAlt() { return keyEvent.alt; }
bool getSys() { return keyEvent.sys; }
bool getCtrl() { return keyEvent.ctrl; }
bool getCaps() { return keyEvent.caps; }
Key getKey() { return eventUnion.keyEvent.key; }
bool getShift() { return eventUnion.keyEvent.shift; }
bool getAlt() { return eventUnion.keyEvent.alt; }
bool getSys() { return eventUnion.keyEvent.sys; }
bool getCtrl() { return eventUnion.keyEvent.ctrl; }
bool getCaps() { return eventUnion.keyEvent.caps; }
};

BIN
include/PCH.hpp View File


+ 53
- 0
include/Shader.hpp.bak View File

@@ -0,0 +1,53 @@
#pragma once

#include "PCH.hpp"
#include "File.hpp"
#include "Engine.hpp"

#include <shaderc\shaderc.hpp>

class ShaderModule
{
public:

enum Stage
{
Vertex,
Fragment,
Geometry
};
ShaderModule(Stage stage);
ShaderModule(Stage stage, std::string path);

VkShaderModule getVulkanModule() { return vkShaderModule; }

void init();
void load(std::string path);
void compile();
void createVulkanModule();

private:

VkShaderModule vkShaderModule;

Stage stage;
shaderc_shader_kind kind;

std::string stageMacro;

enum Language
{
GLSL,
SPV,
UNKNOWN
} language;

std::string path;
std::string source;
std::vector<U32> spvSource;

std::string infoLog;
std::string debugLog;
};

BIN
include/targetver.hpp View File


BIN
shaders/frag.spv View File


+ 0
- 10
shaders/shader.frag View File

@@ -1,10 +0,0 @@
#version 450
#extension GL_ARB_separate_shader_objects : enable

layout(location = 0) in vec3 fragColor;

layout(location = 0) out vec4 outColor;

void main() {
outColor = vec4(fragColor, 1.0);
}

+ 0
- 22
shaders/shader.vert View File

@@ -1,22 +0,0 @@
#version 450
#extension GL_ARB_separate_shader_objects : enable

out gl_PerVertex {
vec4 gl_Position;
};

layout(binding = 0) uniform UniformBufferObject {
mat4 model;
mat4 view;
mat4 proj;
} ubo;

layout(location = 0) in vec2 inPosition;
layout(location = 1) in vec3 inColor;

layout(location = 0) out vec3 fragColor;

void main() {
gl_Position = ubo.proj * ubo.view * ubo.model * vec4(inPosition, 0.0, 1.0);
fragColor = inColor;
}

BIN
shaders/vert.spv View File


+ 3
- 3
src/Engine.cpp View File

@@ -36,13 +36,13 @@ void Engine::start()
while (window->eventQ.pollEvent(ev)) {
switch (ev.type) {
case Event::KeyDown: {
if (ev.keyEvent.key.code == Key::KC_ESCAPE)
if (ev.eventUnion.keyEvent.key.code == Key::KC_ESCAPE)
isRunning = false;
std::cout << "Key down: " << char(ev.keyEvent.key.code) << std::endl;
std::cout << "Key down: " << char(ev.eventUnion.keyEvent.key.code) << std::endl;
break;
}
case Event::KeyUp: {
std::cout << "Key up: " << char(ev.keyEvent.key.code) << std::endl;
std::cout << "Key up: " << char(ev.eventUnion.keyEvent.key.code) << std::endl;
break;
}
}

BIN
src/PCH.cpp View File


+ 95
- 0
src/Shader.cpp.bak View File

@@ -0,0 +1,95 @@
#include "Shader.hpp"

ShaderModule::ShaderModule(Stage s) : stage(s)
{
switch (stage)
{
case Vertex:
kind = shaderc_shader_kind::shaderc_glsl_vertex_shader; stageMacro = "VERTEX"; return;
case Fragment:
kind = shaderc_shader_kind::shaderc_glsl_fragment_shader; stageMacro = "FRAGMENT"; return;
case Geometry:
kind = shaderc_shader_kind::shaderc_glsl_geometry_shader; stageMacro = "GEOMETRY"; return;
}
}

ShaderModule::ShaderModule(Stage s, std::string path) : ShaderModule(s)
{
load(path);
}

void ShaderModule::load(std::string path)
{
int i = 0;
while (path[i] != '.')
{
++i;
if (i > path.length())
{
LOG_WARN("Bad shader file name format: " << path);
}
}
std::string extension;
extension.assign(&path[i + 1]);
if (extension == "glsl" || extension == "GLSL")
{
language = GLSL;
}
else if (extension == "spv" || extension == "SPV")
{
language = SPV;
}
else
{
LOG_WARN("Bad shader file extension: " << path << " - '.glsl' and 'spv' supported");
language = UNKNOWN;
}

File file;
if (!file.open(path))
{
LOG_WARN("Can't open shader file: " << path);
}

if (language == GLSL)
{
source.resize(file.getSize());
file.readFile(&source[0]);
}
if (language == SPV)
{
spvSource.resize(file.getSize());
file.readFile(&spvSource[0]);
}
}

void ShaderModule::compile()
{
if (language == GLSL)
{
shaderc::Compiler c;
shaderc::CompileOptions o;
o.SetAutoBindUniforms(true);
o.AddMacroDefinition(stageMacro);
auto res = c.CompileGlslToSpv(source, kind, path.c_str(), o);
spvSource.assign(res.begin(), res.end());
}
}

void ShaderModule::createVulkanModule()
{
if (spvSource.size() == 0)
{
LOG_FATAL("SPIRV source missing, cannot compile shader: " << path);
return;
}
VkShaderModuleCreateInfo createInfo = {};
createInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
createInfo.codeSize = spvSource.size() * sizeof(int);
createInfo.pCode = spvSource.data();

if (vkCreateShaderModule(Engine::renderer->vkLogicalDevice, &createInfo, nullptr, &vkShaderModule) != VK_SUCCESS)
{
LOG_FATAL("Failed to create shader module");
}
}

BIN
vulkan-1.dll View File


Loading…
Cancel
Save