Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
2d47bc8
Delete IDE files and fix compiling
gravypod Sep 2, 2018
ab52063
Add gitignore file to project
gravypod Sep 2, 2018
7d2d03b
Begin loading vulkan components and modules
gravypod Sep 2, 2018
6502622
Enable validation layers and print errors if the layers are not enabled
gravypod Sep 3, 2018
b83ebd6
Create and teardown vulkan debugging objects
gravypod Sep 3, 2018
feb9fb0
Find a device to use.
gravypod Sep 3, 2018
bc23c0a
Move vulkan into it's own folder
gravypod Sep 3, 2018
0bdbcbb
Delete old wrapper file
gravypod Sep 3, 2018
15e30e1
Clean up CMakeLists.txt
gravypod Sep 8, 2018
f72bbc0
Setup the first queue
gravypod Sep 8, 2018
a759721
Begin surface creation and initialization of multiple queues
gravypod Sep 8, 2018
fb596e4
Create the first swapchain
gravypod Sep 8, 2018
d230a33
Make views of all images from the swapchain
gravypod Sep 8, 2018
da9e03b
Add a glsl shader compiler into the project
gravypod Sep 8, 2018
b1eaada
Move from tools into libs folder
gravypod Sep 8, 2018
146d3f1
Get a shader compiling during runtime
gravypod Sep 8, 2018
4c34c7b
Implement pipeline creation
gravypod Sep 15, 2018
561da2f
Enable recording on command buffers and start rendering fixed polygon…
gravypod Sep 15, 2018
c260012
Implement locking, depend on gpu provided subpasses, and command pool
gravypod Sep 15, 2018
3677993
Implement base dictionary type
gravypod Sep 16, 2018
f7194b5
Organize CMakeLists file
gravypod Sep 16, 2018
9fe2eb1
Merge pull request #7 from gravypod/dictionary-datatype
gravypod Sep 17, 2018
9837bca
Implement geometry shader into the engine.
gravypod Sep 19, 2018
d1c1f56
Send a vertex buffer to the GPU and use it as the position of our tri…
gravypod Sep 20, 2018
f18a9aa
Reformat code and improve the layout of the shader compilation
gravypod Sep 23, 2018
72eb05d
Move shader loading and configuration out of pipeline.c and into shad…
gravypod Sep 23, 2018
0a3b83e
Reformate code
gravypod Sep 23, 2018
bd4f709
Move buffer and memory into it's own folder
gravypod Sep 23, 2018
9ad6f2d
Implement basic entity system and allow all the basic entity functions
gravypod Sep 24, 2018
b1788c3
Merge pull request #9 from gravypod/implement-basic-entity-system
gravypod Sep 28, 2018
bdf6354
Merge pull request #8 from gravypod/explor-geometry-shaders
gravypod Sep 28, 2018
6e09571
Refactor entire command buffer/command pool code.
gravypod Sep 30, 2018
a344583
Test out a staging buffer for sending position data over to the GPU
gravypod Oct 1, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.idea
cmake-build-debug/
lib/duktape/
lib/glad/

15 changes: 15 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,18 @@
path = vendor/glad
url = [email protected]:Dav1dde/glad.git
branch = master
[submodule "tools/shaderc"]
path = lib/shaderc
url = [email protected]:google/shaderc.git
[submodule "tools/googletest"]
path = lib/googletest
url = [email protected]:google/googletest.git
[submodule "tools/glslang"]
path = lib/glslang
url = [email protected]:google/glslang.git
[submodule "tools/spirv-tools"]
path = lib/spirv-tools
url = [email protected]:KhronosGroup/SPIRV-Tools.git
[submodule "tools/spirv-headers"]
path = lib/spirv-headers
url = [email protected]:KhronosGroup/SPIRV-Headers.git
2 changes: 0 additions & 2 deletions .idea/engine.iml

This file was deleted.

4 changes: 0 additions & 4 deletions .idea/misc.xml

This file was deleted.

8 changes: 0 additions & 8 deletions .idea/modules.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

110 changes: 87 additions & 23 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,49 @@
cmake_minimum_required(VERSION 3.5)
project(engine)

find_package( PythonInterp 2.7 REQUIRED )
find_package(PythonInterp 2.7 REQUIRED)
include(CheckCCompilerFlag)
include(ExternalProject)

# Source: https://stackoverflow.com/a/33266748/1127064
function(enable_c_compiler_flag_if_supported flag)
string(FIND "${CMAKE_C_FLAGS}" "${flag}" flag_already_set)
if(flag_already_set EQUAL -1)
if (flag_already_set EQUAL -1)
check_c_compiler_flag("${flag}" flag_supported)
if(flag_supported)
if (flag_supported)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flag}" PARENT_SCOPE)
endif()
endif ()
unset(flag_supported CACHE)
endif()
endif ()
endfunction()


# Build shaderc library for compiling glsl shaders
set(SHADERC_SYMLINKS
${CMAKE_SOURCE_DIR}/lib/shaderc/third_party/glslang
${CMAKE_SOURCE_DIR}/lib/shaderc/third_party/googletest
${CMAKE_SOURCE_DIR}/lib/shaderc/third_party/spirv-headers
${CMAKE_SOURCE_DIR}/lib/shaderc/third_party/spirv-tools)
add_custom_command(
OUTPUT ${SHADERC_SYMLINKS}
COMMAND ln -s ${CMAKE_SOURCE_DIR}/lib/glslang ${CMAKE_SOURCE_DIR}/lib/shaderc/third_party/glslang
COMMAND ln -s ${CMAKE_SOURCE_DIR}/lib/googletest ${CMAKE_SOURCE_DIR}/lib/shaderc/third_party/googletest
COMMAND ln -s ${CMAKE_SOURCE_DIR}/lib/spirv-headers ${CMAKE_SOURCE_DIR}/lib/shaderc/third_party/spirv-headers
COMMAND ln -s ${CMAKE_SOURCE_DIR}/lib/spirv-tools ${CMAKE_SOURCE_DIR}/lib/shaderc/third_party/spirv-tools
)
add_custom_target(shadercsymlinktarget
ALL
DEPENDS ${SHADERC_SYMLINKS})
ExternalProject_Add(localshaderc
DEPENDS shadercsymlinktarget
PREFIX lib/shaderc
SOURCE_DIR ${CMAKE_SOURCE_DIR}/lib/shaderc/
CONFIGURE_COMMAND cmake -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/lib/shaderc/ -DCMAKE_BUILD_TYPE=Debug ${CMAKE_SOURCE_DIR}/lib/shaderc
BUILD_COMMAND make -j4
INSTALL_COMMAND make install
)
link_directories(${CMAKE_BINARY_DIR}/lib/shaderc/lib/)
include_directories(${CMAKE_BINARY_DIR}/lib/shaderc/include)

# VENDOR DUKTAPE
set(VENDOR_DUKTAPE_SOURCES ${CMAKE_SOURCE_DIR}/lib/duktape/duktape.c ${CMAKE_SOURCE_DIR}/lib/duktape/duktape.h ${CMAKE_SOURCE_DIR}/lib/duktape/duk_config.h ${CMAKE_SOURCE_DIR}/lib/duktape/duk_source_meta.json)
Expand All @@ -31,54 +58,91 @@ add_custom_target(localduktape

set(VENDOR_GLAD_SOURCES ${CMAKE_SOURCE_DIR}/lib/glad/glad.c ${CMAKE_SOURCE_DIR}/lib/glad/glad.h)
add_custom_command(
OUTPUT ${VENDOR_GLAD_SOURCES}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/vendor/glad/
PRE_BUILD
COMMAND ${PYTHON_EXECUTABLE} -m glad --generator c --out-path ${CMAKE_SOURCE_DIR}/lib/glad/ --spec gl --omit-khrplatform --local-files
OUTPUT ${VENDOR_GLAD_SOURCES}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/vendor/glad/
PRE_BUILD
COMMAND ${PYTHON_EXECUTABLE} -m glad --generator c --out-path ${CMAKE_SOURCE_DIR}/lib/glad/ --spec gl --omit-khrplatform --local-files
)
add_custom_target(localglad
ALL
DEPENDS ${VENDOR_GLAD_SOURCES})
ALL
DEPENDS ${VENDOR_GLAD_SOURCES})


# lib/glad/glad.c
# lib/duktape/duktape.c lib/duktape/duktape.h lib/duktape/duk_config.h

# ALL SOURCES
set(SOURCE_FILES
${VENDOR_GLAD_SOURCES} ${VENDOR_DUKTAPE_SOURCES}
${VENDOR_GLAD_SOURCES} ${VENDOR_DUKTAPE_SOURCES}
src/engine/main.c

# Scripting
src/engine/scripting/interface.c src/engine/scripting/interface.h
src/engine/scripting/script.h

# Utilities
src/engine/util/llist.c src/engine/util/llist.h
src/engine/util/files.c src/engine/util/files.h
src/engine/util/dict.c src/engine/util/dict.h
src/engine/util/hashing/crc.c src/engine/util/hashing/crc.h

# Engine source
src/engine/graphics/quadmesh.c src/engine/graphics/quadmesh.h
src/engine/graphics/shader.c src/engine/graphics/shader.h
src/engine/graphics/texture.c src/engine/graphics/texture.h lib/stb/stb_image.h
src/engine/graphics/style.c src/engine/graphics/style.h
lib/linmath/linmath.h src/engine/scripting/callbacks.c src/engine/scripting/callbacks.h src/engine/graphics/screen.c src/engine/graphics/screen.h)
lib/linmath/linmath.h
src/engine/scripting/callbacks.c src/engine/scripting/callbacks.h
src/engine/graphics/screen.c src/engine/graphics/screen.h

# Vulkan
src/engine/graphics/vulkan/vulkan.c src/engine/graphics/vulkan/vulkan.h
src/engine/graphics/vulkan/wrappers.h
src/engine/graphics/vulkan/query.c src/engine/graphics/vulkan/query.h
src/engine/graphics/vulkan/debug.c src/engine/graphics/vulkan/debug.h
src/engine/graphics/vulkan/config.c src/engine/graphics/vulkan/config.h
src/engine/graphics/vulkan/queues.c src/engine/graphics/vulkan/queues.h
src/engine/graphics/vulkan/surface.c src/engine/graphics/vulkan/surface.h
src/engine/graphics/vulkan/window.c src/engine/graphics/vulkan/window.h
src/engine/graphics/vulkan/swapchain.c src/engine/graphics/vulkan/swapchain.h
src/engine/graphics/vulkan/shaders/shader.c src/engine/graphics/vulkan/shaders/shader.h
src/engine/graphics/vulkan/pipeline.c src/engine/graphics/vulkan/pipeline.h
src/engine/graphics/vulkan/framebuffer.c src/engine/graphics/vulkan/framebuffer.h
src/engine/graphics/vulkan/locking.c src/engine/graphics/vulkan/locking.h
src/engine/graphics/vulkan/memory/vbuffer.c src/engine/graphics/vulkan/memory/vbuffer.h
src/engine/graphics/vulkan/memory/memory.c src/engine/graphics/vulkan/memory/memory.h
src/engine/util/bits.h src/engine/graphics/vulkan/memory/buffer.h src/engine/graphics/vulkan/memory/buffer.c

src/engine/entity/entity.c src/engine/entity/entity.h
src/engine/entity/definitions/triangle.c src/engine/entity/definitions/triangle.h
src/engine/entity/manager.c src/engine/entity/manager.h
src/engine/graphics/vulkan/commands/pool.c src/engine/graphics/vulkan/commands/pool.h src/engine/graphics/vulkan/commands/buffer.c src/engine/graphics/vulkan/commands/buffer.h src/engine/graphics/vulkan/commands/render.c src/engine/graphics/vulkan/commands/render.h)

set(CMAKE_INCLUDE_CURRENT_DIR ON)



set(CMAKE_INCLUDE_CURRENT_DIR ON)

# COPY SOURCE OF GAME INTO BUILD DIR
add_custom_target(
game_client_code
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_SOURCE_DIR}/src/game/
${CMAKE_CURRENT_BINARY_DIR}/)


add_executable(engine ${SOURCE_FILES})

# VENDOR DUKTAPE
add_dependencies(engine localduktape localglad)
add_dependencies(engine localduktape localglad localshaderc game_client_code)

# GL, GLFW, DL, M
target_link_libraries(engine dl m glfw GL)
target_link_libraries(engine
dl m glfw GL vulkan
shaderc_combined stdc++ pthread)

# STANDARDS
set_property(TARGET engine PROPERTY C_STANDARD 99)
enable_c_compiler_flag_if_supported("-Wall")
enable_c_compiler_flag_if_supported("-Wextra")
enable_c_compiler_flag_if_supported("-pedantic")

# COPY SOURCE OF GAME INTO BUILD DIR
add_custom_command(
TARGET engine POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_SOURCE_DIR}/src/game/
${CMAKE_CURRENT_BINARY_DIR}/)
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ git pull --recursive-submodules
| dl | N/A | Dynamically load libraries |
| m | N/A | Standard math library |
| GLFW3 | libglfw3-dev | GLFW 3 headers |
| GL | GPU drivers, N/A | OpenGL headers and libs |
| Python 2 | python2 | Python 2 to build duktape |
| Ninja | ninja-build | Used by google's shaderc |

## Used Libraries

Expand Down
1 change: 1 addition & 0 deletions lib/glslang
Submodule glslang added at 1ca0f8
1 change: 1 addition & 0 deletions lib/googletest
Submodule googletest added at 34d5d2
1 change: 1 addition & 0 deletions lib/shaderc
Submodule shaderc added at 30af9f
1 change: 1 addition & 0 deletions lib/spirv-headers
Submodule spirv-headers added at dcf23b
1 change: 1 addition & 0 deletions lib/spirv-tools
Submodule spirv-tools added at 40a685
76 changes: 76 additions & 0 deletions src/engine/entity/definitions/triangle.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#include <lib/linmath/linmath.h>
#include <src/engine/graphics/vulkan/memory/buffer.h>
#include <src/engine/graphics/vulkan/window.h>
#include <memory.h>
#include <src/engine/graphics/vulkan/memory/vbuffer.h>
#include <stdio.h>
#include <src/engine/graphics/vulkan/commands/pool.h>
#include <src/engine/graphics/vulkan/commands/buffer.h>
#include "triangle.h"


vec2 *triangle_center_position;
buffer_t triangle_position_buffer, triangle_position_staging_buffer;

void entity_triangle_update(entity_t *entity, void *metadata)
{
(void) entity;
(void) metadata;

vec2 position = {
(cursor_x - (vulkan_window_width_get() / 2.0f)) / vulkan_window_width_get(),
(cursor_y - (vulkan_window_height_get() / 2.0f)) / vulkan_window_height_get()
};

/**
* set triangle position
*/
memcpy(triangle_center_position, &position, sizeof(vec2));


uint32_t cbuffer_id = vulkan_commands_cpool_cbuffer_id_take(cpool);
vulkan_commands_buffer_begin(cpool, cbuffer_id);
{
vulkan_memory_buffer_copy(&triangle_position_staging_buffer, &triangle_position_buffer, vulkan_commands_cpool_cbuffer_get(cpool, cbuffer_id));
}
vulkan_commands_buffer_end(
cpool, cbuffer_id,
0, NULL, NULL,
0, NULL
);
}

void entity_triangle_free(entity_t *entity, void *metadata)
{
(void) entity;
(void) metadata;
}

void entity_triangle_draw(entity_t *e, VkCommandBuffer buffer)
{
(void) e;

VkBuffer vertexBuffers[] = {triangle_position_buffer.buffer};
VkDeviceSize offsets[] = {0};
vkCmdBindVertexBuffers(buffer, 0, 1, vertexBuffers, offsets);

vkCmdDraw(buffer, (uint32_t) triangle_position_buffer.num_elements, 1, 0, 0);
}


void entity_triangle_init(entity_t *entity, vulkan *v)
{
// TODO: Do not allocate this here. This is game state logic
if (!vulkan_memory_vbuffer_allocate(v, &triangle_position_buffer, sizeof(vec2), 1, false)) {
printf("Failed allocate buffer\n");
}

if (!vulkan_memory_vbuffer_allocate(v, &triangle_position_staging_buffer, sizeof(vec2), 1, true)) {
printf("Failed allocate buffer\n");
}
triangle_center_position = triangle_position_staging_buffer.mapped_memory;

entity->update = (void (*)(struct entity_struct *)) entity_triangle_update;
entity->draw = (void (*)(struct entity_struct *, VkCommandBuffer)) (void (*)(struct entity_struct *)) entity_triangle_draw;
entity->free = (void (*)(struct entity_struct *)) entity_triangle_free;
}
17 changes: 17 additions & 0 deletions src/engine/entity/definitions/triangle.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef ENGINE_TRIANGLE_H
#define ENGINE_TRIANGLE_H


#include <src/engine/entity/entity.h>
#include <vulkan/vulkan.h>
#include <src/engine/graphics/vulkan/vulkan.h>

void entity_triangle_init(entity_t *entity, vulkan *v);

void entity_triangle_update(entity_t *entity, void *metadata);

void entity_triangle_free(entity_t *entity, void *metadata);

void entity_triangle_draw(entity_t *e, VkCommandBuffer buffer);

#endif
47 changes: 47 additions & 0 deletions src/engine/entity/entity.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include "entity.h"

void entity_init_empty(entity_t *e, void *metadata)
{
(void) metadata;
if (!e) {
return;
}

e->allocated = false;

// Null out behavior
e->draw = NULL;
e->free = NULL;
e->update = NULL;

if (!e->paramaters) {
// This entity needs a dictionary allocated for them.
e->paramaters = dict_init(16);
} else {
// This entity already had a dict allocated. Just reuse this by emptying it
dict_clear(e->paramaters);
}
}

void entity_update(entity_t *entity, void *metadata)
{
(void) metadata;
if (entity->update) {
entity->update(entity);
}
}

void entity_free(entity_t *entity, void *metadata)
{
(void) metadata;
if (entity->free) {
entity->free(entity);
}
}

void entity_draw(entity_t *e, VkCommandBuffer metadata)
{
if (e->draw) {
e->draw(e, metadata);
}
}
Loading