mirror of
https://github.com/bailwillharr/engine.git
synced 2024-09-21 04:51:18 +00:00
DO stuff
This commit is contained in:
parent
f4fd782930
commit
b65058ab3e
@ -1,4 +1,4 @@
|
||||
cmake_minimum_required(VERSION 3.8)
|
||||
cmake_minimum_required(VERSION 3.23)
|
||||
|
||||
# options
|
||||
option(ENGINE_BUILD_TEST "Compile the test program" ON)
|
||||
@ -77,10 +77,8 @@ set(INCLUDE_FILES
|
||||
)
|
||||
|
||||
add_library(${PROJECT_NAME} STATIC
|
||||
|
||||
${SRC_FILES}
|
||||
${INCLUDE_FILES}
|
||||
|
||||
)
|
||||
|
||||
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/src" PREFIX "Source" FILES ${SRC_FILES})
|
||||
@ -131,6 +129,7 @@ if (MINGW)
|
||||
target_link_libraries(${PROJECT_NAME} PUBLIC mingw32)
|
||||
endif()
|
||||
|
||||
if(ENGINE_BUILD_OPENGL)
|
||||
# GLAD:
|
||||
set(GLAD_PROFILE "core" CACHE INTERNAL "" FORCE)
|
||||
set(GLAD_API "gl=3.3" CACHE INTERNAL "" FORCE)
|
||||
@ -144,6 +143,9 @@ set(BUILD_SHARED_LIBS OFF)
|
||||
add_subdirectory(dependencies/glad)
|
||||
target_link_libraries(${PROJECT_NAME} PUBLIC glad)
|
||||
target_include_directories(${PROJECT_NAME} PUBLIC dependencies/glad/include)
|
||||
endif()
|
||||
|
||||
if(ENGINE_BUILD_VULKAN)
|
||||
|
||||
# Volk
|
||||
set(VOLK_STATIC_DEFINES "")
|
||||
@ -156,6 +158,8 @@ target_link_libraries(${PROJECT_NAME} PRIVATE volk_headers)
|
||||
# Vulkan Memory Allocator
|
||||
target_include_directories(${PROJECT_NAME} PRIVATE dependencies/VulkanMemoryAllocator/include)
|
||||
|
||||
endif()
|
||||
|
||||
# SDL2:
|
||||
find_package(SDL2)
|
||||
if (SDL2_FOUND)
|
||||
|
@ -6,7 +6,6 @@
|
||||
|
||||
#include "resources/shader.hpp"
|
||||
#include "resources/mesh.hpp"
|
||||
#include "resources/texture.hpp"
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
@ -27,7 +26,7 @@ public:
|
||||
void setTexture(const std::string& name);
|
||||
|
||||
std::shared_ptr<resources::Mesh> m_mesh = nullptr;
|
||||
std::shared_ptr<resources::Texture> m_texture;
|
||||
// std::shared_ptr<resources::Texture> m_texture;
|
||||
|
||||
glm::vec3 m_color = { 1.0f, 1.0f, 1.0f };
|
||||
glm::vec3 m_emission = { 0.0f, 0.0f, 0.0f };
|
||||
|
@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#if 0
|
||||
|
||||
#include "engine_api.h"
|
||||
|
||||
#include "component.hpp"
|
||||
@ -39,3 +41,4 @@ private:
|
||||
};
|
||||
|
||||
}
|
||||
#endif
|
@ -1,11 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#if 0
|
||||
|
||||
#include "engine_api.h"
|
||||
|
||||
#include "resource.hpp"
|
||||
|
||||
#include <glad/glad.h>
|
||||
|
||||
#include <glm/vec2.hpp>
|
||||
|
||||
#include <map>
|
||||
@ -33,3 +33,4 @@ public:
|
||||
};
|
||||
|
||||
}
|
||||
#endif
|
@ -1,10 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#if 0
|
||||
|
||||
#include "engine_api.h"
|
||||
|
||||
#include "resource.hpp"
|
||||
|
||||
#include <glad/glad.h>
|
||||
|
||||
namespace engine::resources {
|
||||
|
||||
@ -12,11 +13,6 @@ class ENGINE_API Texture : public Resource {
|
||||
|
||||
private:
|
||||
|
||||
static GLuint s_binded_texture;
|
||||
|
||||
GLuint m_texture;
|
||||
|
||||
|
||||
public:
|
||||
Texture(const std::filesystem::path& resPath);
|
||||
~Texture() override;
|
||||
@ -27,3 +23,5 @@ public:
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -1,3 +1,5 @@
|
||||
#if 0
|
||||
|
||||
#include "components/text_ui_renderer.hpp"
|
||||
|
||||
#include "object.hpp"
|
||||
@ -12,8 +14,8 @@ UI::UI(Object* parent) : Component(parent, TypeEnum::UI)
|
||||
m_font = parent->res.get<resources::Font>(FONTFILE);
|
||||
m_shader = parent->res.get<resources::Shader>("shaders/font.glsl");
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
// glEnable(GL_BLEND);
|
||||
// glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
}
|
||||
|
||||
UI::~UI()
|
||||
@ -70,7 +72,7 @@ void UI::render(glm::mat4 transform)
|
||||
{{xpos + w, ypos + h, 0.0f}, {}, {1.0f, 0.0f}},
|
||||
});*/
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, glyph.textureID);
|
||||
// glBindTexture(GL_TEXTURE_2D, glyph.textureID);
|
||||
|
||||
// mesh.drawMesh(*m_shader);
|
||||
|
||||
@ -83,3 +85,5 @@ void UI::render(glm::mat4 transform)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -18,6 +18,8 @@
|
||||
#define VMA_IMPLEMENTATION
|
||||
#include <vk_mem_alloc.h>
|
||||
|
||||
#include <shaderc/shaderc.hpp>
|
||||
|
||||
#include <SDL_vulkan.h>
|
||||
|
||||
#include <assert.h>
|
||||
@ -145,6 +147,48 @@ namespace engine {
|
||||
|
||||
// functions
|
||||
|
||||
static VkShaderModule compileShader(VkDevice device, shaderc_shader_kind kind, const std::string& source, const char* filename)
|
||||
{
|
||||
|
||||
shaderc::Compiler compiler;
|
||||
shaderc::CompileOptions options;
|
||||
|
||||
options.SetOptimizationLevel(shaderc_optimization_level_performance);
|
||||
|
||||
// preprocess
|
||||
shaderc::PreprocessedSourceCompilationResult preprocessed = compiler.PreprocessGlsl(source, kind, filename, options);
|
||||
|
||||
if (preprocessed.GetCompilationStatus() != shaderc_compilation_status_success)
|
||||
{
|
||||
throw std::runtime_error(preprocessed.GetErrorMessage());
|
||||
}
|
||||
|
||||
std::string shaderStr = { preprocessed.cbegin(), preprocessed.cend() };
|
||||
|
||||
// compile
|
||||
shaderc::SpvCompilationResult module = compiler.CompileGlslToSpv(shaderStr, kind, filename, options);
|
||||
|
||||
if (module.GetCompilationStatus() != shaderc_compilation_status_success)
|
||||
{
|
||||
throw std::runtime_error(module.GetErrorMessage());
|
||||
}
|
||||
|
||||
std::vector<uint32_t> shaderBytecode = { module.cbegin(), module.cend() };// not sure why sample code copy vector like this
|
||||
|
||||
VkShaderModuleCreateInfo createInfo{};
|
||||
createInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
|
||||
createInfo.codeSize = shaderBytecode.size();
|
||||
createInfo.pCode = shaderBytecode.data();
|
||||
|
||||
VkShaderModule shaderModule;
|
||||
if (vkCreateShaderModule(device, &createInfo, nullptr, &shaderModule) != VK_SUCCESS) {
|
||||
throw std::runtime_error("failed to create shader module!");
|
||||
}
|
||||
|
||||
return shaderModule;
|
||||
|
||||
}
|
||||
|
||||
static std::vector<char> readFile(const std::string& filename)
|
||||
{
|
||||
std::ifstream file(filename, std::ios::ate | std::ios::binary);
|
||||
@ -630,21 +674,6 @@ namespace engine {
|
||||
|
||||
}
|
||||
|
||||
static VkShaderModule createShaderModule(VkDevice device, const std::vector<char>& code)
|
||||
{
|
||||
VkShaderModuleCreateInfo createInfo{};
|
||||
createInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
|
||||
createInfo.codeSize = code.size();
|
||||
createInfo.pCode = reinterpret_cast<const uint32_t*>(code.data());
|
||||
|
||||
VkShaderModule shaderModule;
|
||||
if (vkCreateShaderModule(device, &createInfo, nullptr, &shaderModule) != VK_SUCCESS) {
|
||||
throw std::runtime_error("failed to create shader module!");
|
||||
}
|
||||
|
||||
return shaderModule;
|
||||
}
|
||||
|
||||
static void copyBuffer(VkDevice device, VkCommandPool commandPool, VkQueue queue, VkBuffer srcBuffer, VkBuffer dstBuffer, VkDeviceSize size)
|
||||
{
|
||||
VkResult res;
|
||||
@ -1135,9 +1164,6 @@ namespace engine {
|
||||
descriptorSetLayoutInfo.pBindings = &pimpl->uboLayoutBinding;
|
||||
res = vkCreateDescriptorSetLayout(pimpl->device, &descriptorSetLayoutInfo, nullptr, &pimpl->uboLayout);
|
||||
assert(res == VK_SUCCESS);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
GFXDevice::~GFXDevice()
|
||||
@ -1426,8 +1452,8 @@ namespace engine {
|
||||
auto fragShaderCode = readFile(fragShaderPath);
|
||||
INFO("Opened shader: {}", std::filesystem::path(vertShaderPath).filename().string());
|
||||
|
||||
VkShaderModule vertShaderModule = createShaderModule(pimpl->device, vertShaderCode);
|
||||
VkShaderModule fragShaderModule = createShaderModule(pimpl->device, fragShaderCode);
|
||||
VkShaderModule vertShaderModule = compileShader(pimpl->device, shaderc_vertex_shader, vertShaderCode.data(), vertShaderPath);
|
||||
VkShaderModule fragShaderModule = compileShader(pimpl->device, shaderc_fragment_shader, fragShaderCode.data(), fragShaderPath);
|
||||
|
||||
VkPipelineShaderStageCreateInfo vertShaderStageInfo{ VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO };
|
||||
vertShaderStageInfo.stage = VK_SHADER_STAGE_VERTEX_BIT;
|
||||
|
@ -123,7 +123,8 @@ namespace engine {
|
||||
compList.renderers.emplace_back(dynamic_cast<Renderer*>(comp), newTransform);
|
||||
break;
|
||||
case Component::TypeEnum::UI:
|
||||
compList.uis.emplace_back(dynamic_cast<UI*>(comp), newTransform);
|
||||
// compList.uis.emplace_back(dynamic_cast<UI*>(comp), newTransform);
|
||||
throw std::runtime_error("UI is currently not supported");
|
||||
break;
|
||||
case Component::TypeEnum::CUSTOM:
|
||||
compList.customs.emplace_back(dynamic_cast<CustomComponent*>(comp), newTransform);
|
||||
|
@ -1,3 +1,4 @@
|
||||
#if 0
|
||||
#include "resources/font.hpp"
|
||||
|
||||
#include <ft2build.h>
|
||||
@ -94,3 +95,4 @@ Font::Character Font::getChar(char c)
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
@ -35,8 +35,8 @@ Shader::Shader(const std::filesystem::path& resPath) : Resource(resPath, "shader
|
||||
vertexFormat.attributeDescriptions.emplace_back(1, gfx::VertexAttribFormat::VEC3, sizeof(glm::vec3)); // norm
|
||||
vertexFormat.attributeDescriptions.emplace_back(2, gfx::VertexAttribFormat::VEC2, sizeof(glm::vec3) + sizeof(glm::vec3)); // uv
|
||||
|
||||
const std::string vertexShaderPath = (resPath.parent_path()/std::filesystem::path(resPath.stem().string() + ".vert.spv")).string();
|
||||
const std::string fragmentShaderPath = (resPath.parent_path()/std::filesystem::path(resPath.stem().string() + ".frag.spv")).string();
|
||||
const std::string vertexShaderPath = (resPath.parent_path()/std::filesystem::path(resPath.stem().string() + ".vert")).string();
|
||||
const std::string fragmentShaderPath = (resPath.parent_path()/std::filesystem::path(resPath.stem().string() + ".frag")).string();
|
||||
|
||||
m_pipeline = gfxdev->createPipeline(vertexShaderPath.c_str(), fragmentShaderPath.c_str(), vertexFormat, sizeof(UniformBuffer));
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
#if 0
|
||||
|
||||
#include "resources/texture.hpp"
|
||||
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
@ -129,3 +131,4 @@ void Texture::bindTexture() const
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
@ -62,9 +62,10 @@ namespace engine {
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto& [c, t] : compList.uis) {
|
||||
/* for (const auto& [c, t] : compList.uis) {
|
||||
c->render(t);
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user