removed duplicates of gl and vk folders
This commit is contained in:
parent
1070d03815
commit
34b6e19896
14 changed files with 2 additions and 6179 deletions
304
gl/khrplatform.h
304
gl/khrplatform.h
|
|
@ -1,304 +0,0 @@
|
||||||
#ifndef __khrplatform_h_
|
|
||||||
#define __khrplatform_h_
|
|
||||||
|
|
||||||
/*
|
|
||||||
* * Copyright (c) 2008-2018 The Khronos Group Inc. *
|
|
||||||
*
|
|
||||||
* * Permission is hereby granted, free of charge, to any person obtaining a *
|
|
||||||
* copy of this software and/or associated documentation files (the *
|
|
||||||
* "Materials"), to deal in the Materials without restriction, including *
|
|
||||||
* without limitation the rights to use, copy, modify, merge, publish, *
|
|
||||||
* distribute, sublicense, and/or sell copies of the Materials, and to * permit
|
|
||||||
* persons to whom the Materials are furnished to do so, subject to * the
|
|
||||||
* following conditions: *
|
|
||||||
*
|
|
||||||
* * The above copyright notice and this permission notice shall be included *
|
|
||||||
* in all copies or substantial portions of the Materials. *
|
|
||||||
*
|
|
||||||
* * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *
|
|
||||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
|
|
||||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN
|
|
||||||
* NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM,
|
|
||||||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * TORT OR
|
|
||||||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * MATERIALS OR THE
|
|
||||||
* USE OR OTHER DEALINGS IN THE MATERIALS.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Khronos platform-specific types and definitions.
|
|
||||||
*
|
|
||||||
* The master copy of khrplatform.h is maintained in the Khronos EGL Registry
|
|
||||||
* repository at https://github.com/KhronosGroup/EGL-Registry The last semantic
|
|
||||||
* modification to khrplatform.h was at commit ID:
|
|
||||||
* 67a3e0864c2d75ea5287b9f3d2eb74a745936692
|
|
||||||
*
|
|
||||||
* Adopters may modify this file to suit their platform. Adopters are
|
|
||||||
* encouraged to submit platform specific modifications to the Khronos group so
|
|
||||||
* that they can be included in future versions of this file. Please submit
|
|
||||||
* changes by filing pull requests or issues on the EGL Registry repository
|
|
||||||
* linked above.
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* See the Implementer's Guidelines for information about where this file
|
|
||||||
* should be located on your system and for more details of its use:
|
|
||||||
* http://www.khronos.org/registry/implementers_guide.pdf
|
|
||||||
*
|
|
||||||
* This file should be included as #include <KHR/khrplatform.h> by Khronos
|
|
||||||
* client API header files that use its types and defines.
|
|
||||||
*
|
|
||||||
* The types in khrplatform.h should only be used to define API-specific types.
|
|
||||||
*
|
|
||||||
* Types defined in khrplatform.h: khronos_int8_t signed 8 bit
|
|
||||||
* khronos_uint8_t unsigned 8 bit khronos_int16_t signed 16 bit
|
|
||||||
* khronos_uint16_t unsigned 16 bit khronos_int32_t signed 32 bit
|
|
||||||
* khronos_uint32_t unsigned 32 bit khronos_int64_t signed 64 bit
|
|
||||||
* khronos_uint64_t unsigned 64 bit khronos_intptr_t signed same
|
|
||||||
* number of bits as a pointer khronos_uintptr_t unsigned same number of bits
|
|
||||||
* as a pointer khronos_ssize_t signed size khronos_usize_t
|
|
||||||
* unsigned size khronos_float_t signed 32 bit floating point
|
|
||||||
* khronos_time_ns_t unsigned 64 bit time in nanoseconds
|
|
||||||
* khronos_utime_nanoseconds_t unsigned time interval or absolute time in
|
|
||||||
* nanoseconds khronos_stime_nanoseconds_t signed time interval in nanoseconds
|
|
||||||
* khronos_boolean_enum_t enumerated boolean type. This should only be
|
|
||||||
* used as a base type when a client API's boolean type is an enum. Client APIs
|
|
||||||
* which use an integer or other type for booleans cannot use this as the base
|
|
||||||
* type for their boolean.
|
|
||||||
*
|
|
||||||
* Tokens defined in khrplatform.h:
|
|
||||||
*
|
|
||||||
* KHRONOS_FALSE, KHRONOS_TRUE Enumerated boolean false/true values.
|
|
||||||
*
|
|
||||||
* KHRONOS_SUPPORT_INT64 is 1 if 64 bit integers are supported; otherwise 0.
|
|
||||||
* KHRONOS_SUPPORT_FLOAT is 1 if floats are supported; otherwise 0.
|
|
||||||
*
|
|
||||||
* Calling convention macros defined in this file: KHRONOS_APICALL
|
|
||||||
* KHRONOS_APIENTRY KHRONOS_APIATTRIBUTES
|
|
||||||
*
|
|
||||||
* These may be used in function prototypes as:
|
|
||||||
*
|
|
||||||
* KHRONOS_APICALL void KHRONOS_APIENTRY funcname( int arg1, int arg2)
|
|
||||||
* KHRONOS_APIATTRIBUTES;
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if defined(__SCITECH_SNAP__) && !defined(KHRONOS_STATIC)
|
|
||||||
#define KHRONOS_STATIC 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------
|
|
||||||
* Definition of KHRONOS_APICALL
|
|
||||||
*-------------------------------------------------------------------------
|
|
||||||
* This precedes the return type of the function in the function prototype.
|
|
||||||
*/
|
|
||||||
#if defined(KHRONOS_STATIC)
|
|
||||||
/*
|
|
||||||
* If the preprocessor constant KHRONOS_STATIC is defined, make the header
|
|
||||||
* compatible with static linking.
|
|
||||||
*/
|
|
||||||
#define KHRONOS_APICALL
|
|
||||||
#elif defined(_WIN32)
|
|
||||||
#define KHRONOS_APICALL __declspec(dllimport)
|
|
||||||
#elif defined (__SYMBIAN32__)
|
|
||||||
#define KHRONOS_APICALL IMPORT_C
|
|
||||||
#elif defined(__ANDROID__)
|
|
||||||
#define KHRONOS_APICALL __attribute__((visibility("default")))
|
|
||||||
#else
|
|
||||||
#define KHRONOS_APICALL
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------
|
|
||||||
* Definition of KHRONOS_APIENTRY
|
|
||||||
*-------------------------------------------------------------------------
|
|
||||||
* This follows the return type of the function and precedes the function
|
|
||||||
* name in the function prototype.
|
|
||||||
*/
|
|
||||||
#if defined(_WIN32) && !defined(_WIN32_WCE) && !defined(__SCITECH_SNAP__)
|
|
||||||
/* Win32 but not WinCE */
|
|
||||||
#define KHRONOS_APIENTRY __stdcall
|
|
||||||
#else
|
|
||||||
#define KHRONOS_APIENTRY
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------
|
|
||||||
* Definition of KHRONOS_APIATTRIBUTES
|
|
||||||
*-------------------------------------------------------------------------
|
|
||||||
* This follows the closing parenthesis of the function prototype arguments.
|
|
||||||
*/
|
|
||||||
#if defined (__ARMCC_2__)
|
|
||||||
#define KHRONOS_APIATTRIBUTES __softfp
|
|
||||||
#else
|
|
||||||
#define KHRONOS_APIATTRIBUTES
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------
|
|
||||||
* basic type definitions
|
|
||||||
*-----------------------------------------------------------------------*/
|
|
||||||
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__GNUC__) || defined(__SCO__) || defined(__USLC__)
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Using <stdint.h>
|
|
||||||
*/
|
|
||||||
#include <stdint.h>
|
|
||||||
typedef int32_t khronos_int32_t;
|
|
||||||
typedef uint32_t khronos_uint32_t;
|
|
||||||
typedef int64_t khronos_int64_t;
|
|
||||||
typedef uint64_t khronos_uint64_t;
|
|
||||||
#define KHRONOS_SUPPORT_INT64 1
|
|
||||||
#define KHRONOS_SUPPORT_FLOAT 1
|
|
||||||
/*
|
|
||||||
* To support platform where unsigned long cannot be used interchangeably with
|
|
||||||
* inptr_t (e.g. CHERI-extended ISAs), we can use the stdint.h intptr_t.
|
|
||||||
* Ideally, we could just use (u)intptr_t everywhere, but this could result in
|
|
||||||
* ABI breakage if khronos_uintptr_t is changed from unsigned long to unsigned
|
|
||||||
* long long or similar (this results in different C++ name mangling). To avoid
|
|
||||||
* changes for existing platforms, we restrict usage of intptr_t to platforms
|
|
||||||
* where the size of a pointer is larger than the size of long.
|
|
||||||
*/
|
|
||||||
#if defined(__SIZEOF_LONG__) && defined(__SIZEOF_POINTER__)
|
|
||||||
#if __SIZEOF_POINTER__ > __SIZEOF_LONG__
|
|
||||||
#define KHRONOS_USE_INTPTR_T
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#elif defined(__VMS ) || defined(__sgi)
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Using <inttypes.h>
|
|
||||||
*/
|
|
||||||
#include <inttypes.h>
|
|
||||||
typedef int32_t khronos_int32_t;
|
|
||||||
typedef uint32_t khronos_uint32_t;
|
|
||||||
typedef int64_t khronos_int64_t;
|
|
||||||
typedef uint64_t khronos_uint64_t;
|
|
||||||
#define KHRONOS_SUPPORT_INT64 1
|
|
||||||
#define KHRONOS_SUPPORT_FLOAT 1
|
|
||||||
|
|
||||||
#elif defined(_WIN32) && !defined(__SCITECH_SNAP__)
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Win32
|
|
||||||
*/
|
|
||||||
typedef __int32 khronos_int32_t;
|
|
||||||
typedef unsigned __int32 khronos_uint32_t;
|
|
||||||
typedef __int64 khronos_int64_t;
|
|
||||||
typedef unsigned __int64 khronos_uint64_t;
|
|
||||||
#define KHRONOS_SUPPORT_INT64 1
|
|
||||||
#define KHRONOS_SUPPORT_FLOAT 1
|
|
||||||
|
|
||||||
#elif defined(__sun__) || defined(__digital__)
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Sun or Digital
|
|
||||||
*/
|
|
||||||
typedef int khronos_int32_t;
|
|
||||||
typedef unsigned int khronos_uint32_t;
|
|
||||||
#if defined(__arch64__) || defined(_LP64)
|
|
||||||
typedef long int khronos_int64_t;
|
|
||||||
typedef unsigned long int khronos_uint64_t;
|
|
||||||
#else
|
|
||||||
typedef long long int khronos_int64_t;
|
|
||||||
typedef unsigned long long int khronos_uint64_t;
|
|
||||||
#endif /* __arch64__ */
|
|
||||||
#define KHRONOS_SUPPORT_INT64 1
|
|
||||||
#define KHRONOS_SUPPORT_FLOAT 1
|
|
||||||
|
|
||||||
#elif 0
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Hypothetical platform with no float or int64 support
|
|
||||||
*/
|
|
||||||
typedef int khronos_int32_t;
|
|
||||||
typedef unsigned int khronos_uint32_t;
|
|
||||||
#define KHRONOS_SUPPORT_INT64 0
|
|
||||||
#define KHRONOS_SUPPORT_FLOAT 0
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Generic fallback
|
|
||||||
*/
|
|
||||||
#include <stdint.h>
|
|
||||||
typedef int32_t khronos_int32_t;
|
|
||||||
typedef uint32_t khronos_uint32_t;
|
|
||||||
typedef int64_t khronos_int64_t;
|
|
||||||
typedef uint64_t khronos_uint64_t;
|
|
||||||
#define KHRONOS_SUPPORT_INT64 1
|
|
||||||
#define KHRONOS_SUPPORT_FLOAT 1
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Types that are (so far) the same on all platforms
|
|
||||||
*/
|
|
||||||
typedef signed char khronos_int8_t;
|
|
||||||
typedef unsigned char khronos_uint8_t;
|
|
||||||
typedef signed short int khronos_int16_t;
|
|
||||||
typedef unsigned short int khronos_uint16_t;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Types that differ between LLP64 and LP64 architectures - in LLP64, pointers
|
|
||||||
* are 64 bits, but 'long' is still 32 bits. Win64 appears to be the only LLP64
|
|
||||||
* architecture in current use.
|
|
||||||
*/
|
|
||||||
#ifdef KHRONOS_USE_INTPTR_T
|
|
||||||
typedef intptr_t khronos_intptr_t;
|
|
||||||
typedef uintptr_t khronos_uintptr_t;
|
|
||||||
#elif defined(_WIN64)
|
|
||||||
typedef signed long long int khronos_intptr_t;
|
|
||||||
typedef unsigned long long int khronos_uintptr_t;
|
|
||||||
#else
|
|
||||||
typedef signed long int khronos_intptr_t;
|
|
||||||
typedef unsigned long int khronos_uintptr_t;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(_WIN64)
|
|
||||||
typedef signed long long int khronos_ssize_t;
|
|
||||||
typedef unsigned long long int khronos_usize_t;
|
|
||||||
#else
|
|
||||||
typedef signed long int khronos_ssize_t;
|
|
||||||
typedef unsigned long int khronos_usize_t;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if KHRONOS_SUPPORT_FLOAT
|
|
||||||
/*
|
|
||||||
* Float type
|
|
||||||
*/
|
|
||||||
typedef float khronos_float_t;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if KHRONOS_SUPPORT_INT64
|
|
||||||
/*
|
|
||||||
* Time types
|
|
||||||
*
|
|
||||||
* These types can be used to represent a time interval in nanoseconds or an
|
|
||||||
* absolute Unadjusted System Time. Unadjusted System Time is the number of
|
|
||||||
* nanoseconds since some arbitrary system event (e.g. since the last time the
|
|
||||||
* system booted). The Unadjusted System Time is an unsigned 64 bit value that
|
|
||||||
* wraps back to 0 every 584 years. Time intervals may be either signed or
|
|
||||||
* unsigned.
|
|
||||||
*/
|
|
||||||
typedef khronos_uint64_t khronos_utime_nanoseconds_t;
|
|
||||||
typedef khronos_int64_t khronos_stime_nanoseconds_t;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Dummy value used to pad enum types to 32 bits.
|
|
||||||
*/
|
|
||||||
#ifndef KHRONOS_MAX_ENUM
|
|
||||||
#define KHRONOS_MAX_ENUM 0x7FFFFFFF
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Enumerated boolean type
|
|
||||||
*
|
|
||||||
* Values other than zero should be considered to be true. Therefore
|
|
||||||
* comparisons should not be made against KHRONOS_TRUE.
|
|
||||||
*/
|
|
||||||
typedef enum {
|
|
||||||
KHRONOS_FALSE = 0,
|
|
||||||
KHRONOS_TRUE = 1,
|
|
||||||
KHRONOS_BOOLEAN_ENUM_FORCE_SIZE = KHRONOS_MAX_ENUM
|
|
||||||
} khronos_boolean_enum_t;
|
|
||||||
|
|
||||||
#endif /* __khrplatform_h_ */
|
|
||||||
|
|
@ -1,51 +0,0 @@
|
||||||
/* SPDX-License-Identifier:BSD-3-Clause */
|
|
||||||
|
|
||||||
#include "gl.h"
|
|
||||||
#define RGFW_IMPLEMENTATION
|
|
||||||
#define RGFW_OPENGL
|
|
||||||
#include "../rgfw.h"
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This function is the entrypoint for the whole game. Its role is to
|
|
||||||
* initialize OpenGL, create the renderer and start the game loop.
|
|
||||||
*/
|
|
||||||
int platform_run(i32 argc, u8 * *argv)
|
|
||||||
{
|
|
||||||
(void)argc;
|
|
||||||
(void)argv;
|
|
||||||
|
|
||||||
RGFW_glHints *hints = RGFW_getGlobalHints_OpenGL();
|
|
||||||
hints->major = 3;
|
|
||||||
hints->minor = 3;
|
|
||||||
RGFW_setGlobalHints_OpenGL(hints);
|
|
||||||
|
|
||||||
RGFW_window *win = RGFW_createWindow("Topaz", 0, 0, 800, 600, RGFW_windowCenter | RGFW_windowNoResize | RGFW_windowHide);
|
|
||||||
RGFW_window_createContext_OpenGL(win, hints);
|
|
||||||
|
|
||||||
int glad_version = gladLoadGL(RGFW_getProcAddress_OpenGL);
|
|
||||||
if (glad_version == 0) {
|
|
||||||
printf("Failed to initialize OpenGL context.\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
RGFW_window_show(win);
|
|
||||||
|
|
||||||
RGFW_window_setExitKey(win, RGFW_escape);
|
|
||||||
|
|
||||||
const u8 *version = glGetString(GL_VERSION);
|
|
||||||
printf("OpenGL Version: %s\n", version);
|
|
||||||
printf("GLAD Version: %d.%d\n", GLAD_VERSION_MAJOR(glad_version), GLAD_VERSION_MINOR(glad_version));
|
|
||||||
|
|
||||||
|
|
||||||
while (RGFW_window_shouldClose(win) == RGFW_FALSE) {
|
|
||||||
RGFW_event event;
|
|
||||||
while (RGFW_window_checkEvent(win, &event));
|
|
||||||
|
|
||||||
glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
|
||||||
RGFW_window_swapBuffers_OpenGL(win);
|
|
||||||
}
|
|
||||||
|
|
||||||
RGFW_window_close(win);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
@ -45,6 +45,8 @@ void vk_device_init(struct renderer_context *context)
|
||||||
};
|
};
|
||||||
|
|
||||||
if (vkCreateDevice(context->physical_device, &device_create_info, NULL, &context->device) != VK_SUCCESS) {
|
if (vkCreateDevice(context->physical_device, &device_create_info, NULL, &context->device) != VK_SUCCESS) {
|
||||||
|
vector_deinit(physical_device_extensions);
|
||||||
|
vector_deinit(device_extensions);
|
||||||
fatal("Can't create Vulkan device.\n");
|
fatal("Can't create Vulkan device.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
60
vk/device.c
60
vk/device.c
|
|
@ -1,60 +0,0 @@
|
||||||
/* SPDX-License-Identifier:BSD-3-Clause */
|
|
||||||
#include "device.h"
|
|
||||||
#include "physical_device.h"
|
|
||||||
#include "../core/vector.h"
|
|
||||||
#include "../core/log.h"
|
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
void vk_device_init(struct renderer_context *context)
|
|
||||||
{
|
|
||||||
struct vector *device_extensions = vector_init(0, sizeof(char *));
|
|
||||||
struct vector *physical_device_extensions = vk_physical_device_get_extensions(context);
|
|
||||||
for (usize i = 0; i < physical_device_extensions->length; i++) {
|
|
||||||
if (strcmp(((char **)physical_device_extensions->data)[i], "VK_KHR_portability_subset") == 0) {
|
|
||||||
/*
|
|
||||||
* The spec states that if VK_KHR_portability_subset is
|
|
||||||
* present in the physical device extensions, the
|
|
||||||
* device should also have that extension enabled.
|
|
||||||
*/
|
|
||||||
vector_push(device_extensions, char *, "VK_KHR_portability_subset");
|
|
||||||
}
|
|
||||||
|
|
||||||
free(((char **)physical_device_extensions->data)[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
f32 priority = 0.0;
|
|
||||||
VkDeviceQueueCreateInfo graphics_queue_create_info = {
|
|
||||||
.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO,
|
|
||||||
.queueFamilyIndex = context->queue_indices.graphics,
|
|
||||||
.queueCount = 1,
|
|
||||||
.pQueuePriorities = &priority
|
|
||||||
};
|
|
||||||
|
|
||||||
VkDeviceCreateInfo device_create_info = {
|
|
||||||
.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO,
|
|
||||||
.pNext = NULL,
|
|
||||||
.flags = 0,
|
|
||||||
.queueCreateInfoCount = 1,
|
|
||||||
.pQueueCreateInfos = &graphics_queue_create_info,
|
|
||||||
.enabledLayerCount = 0,
|
|
||||||
.ppEnabledLayerNames = NULL,
|
|
||||||
.enabledExtensionCount = device_extensions->length,
|
|
||||||
.ppEnabledExtensionNames = (const char **)device_extensions->data,
|
|
||||||
.pEnabledFeatures = NULL,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (vkCreateDevice(context->physical_device, &device_create_info, NULL, &context->device) != VK_SUCCESS) {
|
|
||||||
fatal("Can't create Vulkan device.\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
vkGetDeviceQueue(context->device, graphics_queue_create_info.queueFamilyIndex, 0, &context->graphics_queue);
|
|
||||||
|
|
||||||
vector_deinit(physical_device_extensions);
|
|
||||||
vector_deinit(device_extensions);
|
|
||||||
}
|
|
||||||
|
|
||||||
void vk_device_deinit(struct renderer_context *context)
|
|
||||||
{
|
|
||||||
vkDestroyDevice(context->device, NULL);
|
|
||||||
}
|
|
||||||
10
vk/device.h
10
vk/device.h
|
|
@ -1,10 +0,0 @@
|
||||||
/* SPDX-License-Identifier:BSD-3-Clause */
|
|
||||||
#ifndef DEVICE_H
|
|
||||||
#define DEVICE_H
|
|
||||||
|
|
||||||
#include "vk.h"
|
|
||||||
|
|
||||||
void vk_device_init(struct renderer_context *context);
|
|
||||||
void vk_device_deinit(struct renderer_context *context);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
104
vk/instance.c
104
vk/instance.c
|
|
@ -1,104 +0,0 @@
|
||||||
/* SPDX-License-Identifier:BSD-3-Clause */
|
|
||||||
#include "instance.h"
|
|
||||||
#include "../core/log.h"
|
|
||||||
#define RGFW_VULKAN
|
|
||||||
#include "../rgfw.h"
|
|
||||||
#include "vk.h"
|
|
||||||
|
|
||||||
const char *extensions[] = {
|
|
||||||
#ifdef PLATFORM_MACOS
|
|
||||||
VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME,
|
|
||||||
VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME,
|
|
||||||
#endif
|
|
||||||
NULL
|
|
||||||
};
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
const char *layers[] = {
|
|
||||||
"VK_LAYER_KHRONOS_validation"
|
|
||||||
};
|
|
||||||
#define LAYER_COUNT (sizeof(layers)/sizeof(layers[0]))
|
|
||||||
#else
|
|
||||||
#define LAYER_COUNT 0
|
|
||||||
const char *layers[] = {NULL};
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Vulkan is modular by design. This means that some features that might not be
|
|
||||||
* always needed are not enabled by default. To enable those features (like
|
|
||||||
* macOS platform compatibility or windowing) extensions are needed. This
|
|
||||||
* function checks which extensions are required by RGFW and adds extensions
|
|
||||||
* required by the game itself.
|
|
||||||
*/
|
|
||||||
const char **vk_instance_extensions(usize * count)
|
|
||||||
{
|
|
||||||
usize rgfw_extension_count = 0;
|
|
||||||
const char **rgfw_extensions = RGFW_getRequiredInstanceExtensions_Vulkan(&rgfw_extension_count);
|
|
||||||
|
|
||||||
usize extension_count = sizeof(extensions) / sizeof(extensions[0]) - 1;
|
|
||||||
*count = rgfw_extension_count + extension_count;
|
|
||||||
const char **instance_extensions = malloc(*count * sizeof(char *));
|
|
||||||
|
|
||||||
log_info("Required Vulkan extensions: ");
|
|
||||||
|
|
||||||
for (usize i = 0; i < rgfw_extension_count; i++) {
|
|
||||||
printf("%s ", rgfw_extensions[i]);
|
|
||||||
instance_extensions[i] = rgfw_extensions[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
for (usize i = 0; i < extension_count; i++) {
|
|
||||||
printf("%s ", extensions[i]);
|
|
||||||
instance_extensions[rgfw_extension_count + i] = extensions[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("\n");
|
|
||||||
|
|
||||||
return instance_extensions;
|
|
||||||
}
|
|
||||||
|
|
||||||
void vk_instance_init(struct renderer_context *context)
|
|
||||||
{
|
|
||||||
VkApplicationInfo application_info = {
|
|
||||||
.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO,
|
|
||||||
.pApplicationName = "topaz",
|
|
||||||
.applicationVersion = 0,
|
|
||||||
.pEngineName = "topaz",
|
|
||||||
.engineVersion = 0,
|
|
||||||
.apiVersion = VK_API_VERSION_1_4
|
|
||||||
};
|
|
||||||
|
|
||||||
usize extension_count = 0;
|
|
||||||
const char **extension_names = vk_instance_extensions(&extension_count);
|
|
||||||
|
|
||||||
VkInstanceCreateInfo instance_info = {
|
|
||||||
.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
|
|
||||||
.pApplicationInfo = &application_info,
|
|
||||||
.flags = VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR,
|
|
||||||
.enabledLayerCount = LAYER_COUNT,
|
|
||||||
.ppEnabledLayerNames = layers,
|
|
||||||
.enabledExtensionCount = extension_count,
|
|
||||||
.ppEnabledExtensionNames = extension_names,
|
|
||||||
};
|
|
||||||
|
|
||||||
VkResult result = vkCreateInstance(&instance_info, NULL, &context->instance);
|
|
||||||
switch (result) {
|
|
||||||
case VK_ERROR_INCOMPATIBLE_DRIVER:
|
|
||||||
free(extension_names);
|
|
||||||
fatal("Incompatible driver.\n");
|
|
||||||
case VK_ERROR_LAYER_NOT_PRESENT:
|
|
||||||
free(extension_names);
|
|
||||||
fatal("Requested vulkan layers are not present.\n");
|
|
||||||
case VK_SUCCESS:
|
|
||||||
log_info("Vulkan instance created.\n");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
fatal("Can't create Vulkan instance.\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
free(extension_names);
|
|
||||||
}
|
|
||||||
|
|
||||||
void vk_instance_deinit(struct renderer_context *context)
|
|
||||||
{
|
|
||||||
vkDestroyInstance(context->instance, NULL);
|
|
||||||
}
|
|
||||||
|
|
@ -1,10 +0,0 @@
|
||||||
/* SPDX-License-Identifier:BSD-3-Clause */
|
|
||||||
#ifndef INSTANCE_H
|
|
||||||
#define INSTANCE_H
|
|
||||||
|
|
||||||
#include "../rendering/renderer.h"
|
|
||||||
|
|
||||||
void vk_instance_init(struct renderer_context *context);
|
|
||||||
void vk_instance_deinit(struct renderer_context *context);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
@ -1,77 +0,0 @@
|
||||||
/* SPDX-License-Identifier:BSD-3-Clause */
|
|
||||||
#include "physical_device.h"
|
|
||||||
#include "../core/log.h"
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
void vk_physical_device_pick(struct renderer_context *context)
|
|
||||||
{
|
|
||||||
u32 device_count = 0;
|
|
||||||
|
|
||||||
vkEnumeratePhysicalDevices(context->instance, &device_count, NULL);
|
|
||||||
|
|
||||||
VkPhysicalDevice *devices = malloc(sizeof(VkPhysicalDevice) * device_count);
|
|
||||||
|
|
||||||
if (vkEnumeratePhysicalDevices(context->instance, &device_count, devices) != VK_SUCCESS || device_count == 0) {
|
|
||||||
fatal("Can't get physical devices.\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
log_info("Available devices:\n");
|
|
||||||
for (usize i = 0; i < device_count; i++) {
|
|
||||||
VkPhysicalDeviceProperties properties;
|
|
||||||
vkGetPhysicalDeviceProperties(devices[i], &properties);
|
|
||||||
printf("%s\n", properties.deviceName);
|
|
||||||
}
|
|
||||||
|
|
||||||
context->physical_device = devices[0];
|
|
||||||
|
|
||||||
free(devices);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct vector *vk_physical_device_get_extensions(struct renderer_context *context)
|
|
||||||
{
|
|
||||||
u32 property_count = 0;
|
|
||||||
VkExtensionProperties *properties = NULL;
|
|
||||||
|
|
||||||
vkEnumerateDeviceExtensionProperties(context->physical_device, NULL, &property_count, NULL);
|
|
||||||
|
|
||||||
struct vector *extensions = vector_init(property_count, sizeof(char *));
|
|
||||||
properties = (VkExtensionProperties *) malloc(sizeof(VkExtensionProperties) * property_count);
|
|
||||||
|
|
||||||
if (vkEnumerateDeviceExtensionProperties(context->physical_device, NULL, &property_count, properties) != VK_SUCCESS) {
|
|
||||||
free(properties);
|
|
||||||
fatal("Can't get physical device extension properties.\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
for (usize i = 0; i < property_count; i++) {
|
|
||||||
char *name = malloc(strlen(properties[i].extensionName) + 1);
|
|
||||||
strcpy(name, properties[i].extensionName);
|
|
||||||
vector_push(extensions, char *, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
free(properties);
|
|
||||||
|
|
||||||
return extensions;
|
|
||||||
}
|
|
||||||
|
|
||||||
void vk_physical_device_select_family_indices(struct renderer_context *context)
|
|
||||||
{
|
|
||||||
u32 property_count = 0;
|
|
||||||
VkQueueFamilyProperties *properties = NULL;
|
|
||||||
|
|
||||||
vkGetPhysicalDeviceQueueFamilyProperties(context->physical_device, &property_count, NULL);
|
|
||||||
|
|
||||||
properties = (VkQueueFamilyProperties *) malloc(sizeof(VkExtensionProperties) * property_count);
|
|
||||||
|
|
||||||
vkGetPhysicalDeviceQueueFamilyProperties(context->physical_device, &property_count, properties);
|
|
||||||
|
|
||||||
for (u32 i = 0; i < property_count; i++) {
|
|
||||||
VkQueueFamilyProperties prop = properties[i];
|
|
||||||
|
|
||||||
if (prop.queueFlags & VK_QUEUE_GRAPHICS_BIT) {
|
|
||||||
context->queue_indices.graphics = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
free(properties);
|
|
||||||
}
|
|
||||||
|
|
@ -1,26 +0,0 @@
|
||||||
/* SPDX-License-Identifier:BSD-3-Clause */
|
|
||||||
#ifndef PHYSICAL_DEVICE_H
|
|
||||||
#define PHYSICAL_DEVICE_H
|
|
||||||
|
|
||||||
#include "vk.h"
|
|
||||||
#include "../types.h"
|
|
||||||
#include "../core/vector.h"
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Get the list of all available devices and pick the best option.
|
|
||||||
*/
|
|
||||||
void vk_physical_device_pick(struct renderer_context *context);
|
|
||||||
/*
|
|
||||||
* Get the list of all available device extensions and return a vector
|
|
||||||
* containing those.
|
|
||||||
*/
|
|
||||||
struct vector *vk_physical_device_get_extensions(struct renderer_context *context);
|
|
||||||
/*
|
|
||||||
* The physical device is responsible of selecting the queue family indices,
|
|
||||||
* used later by the device to create the queues. This function sets the family
|
|
||||||
* indices in the renderer context.
|
|
||||||
*/
|
|
||||||
void vk_physical_device_select_family_indices(struct renderer_context *context);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
@ -1,41 +0,0 @@
|
||||||
/* SPDX-License-Identifier:BSD-3-Clause */
|
|
||||||
|
|
||||||
#define RGFW_VULKAN
|
|
||||||
#define RGFW_IMPLEMENTATION
|
|
||||||
#include "../rgfw.h"
|
|
||||||
#include <vulkan/vulkan.h>
|
|
||||||
#include "../core/log.h"
|
|
||||||
|
|
||||||
#ifdef PLATFORM_MACOS
|
|
||||||
#include <vulkan/vulkan_macos.h>
|
|
||||||
#include <vulkan/vulkan_metal.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "../rendering/renderer.h"
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This function is the entrypoint for the whole game. Its role is to
|
|
||||||
* initialize Vulkan, create the renderer and start the game loop.
|
|
||||||
*/
|
|
||||||
int platform_run(i32 argc, u8 * *argv)
|
|
||||||
{
|
|
||||||
(void)argc;
|
|
||||||
(void)argv;
|
|
||||||
|
|
||||||
log_info("Using Vulkan as rendering backend.\n");
|
|
||||||
|
|
||||||
RGFW_window *win = RGFW_createWindow("topaz", 0, 0, 800, 600, RGFW_windowCenter | RGFW_windowNoResize | RGFW_windowHide);
|
|
||||||
RGFW_window_show(win);
|
|
||||||
RGFW_window_setExitKey(win, RGFW_escape);
|
|
||||||
|
|
||||||
struct renderer_context *context = renderer_context_init();
|
|
||||||
|
|
||||||
while (RGFW_window_shouldClose(win) == RGFW_FALSE) {
|
|
||||||
RGFW_event event;
|
|
||||||
while (RGFW_window_checkEvent(win, &event));
|
|
||||||
}
|
|
||||||
|
|
||||||
renderer_context_deinit(context);
|
|
||||||
RGFW_window_close(win);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
@ -1,43 +0,0 @@
|
||||||
/* SPDX-License-Identifier:BSD-3-Clause */
|
|
||||||
#include "../rendering/renderer.h"
|
|
||||||
#include "instance.h"
|
|
||||||
#include "physical_device.h"
|
|
||||||
#include "device.h"
|
|
||||||
#include "vk.h"
|
|
||||||
#include "../core/arena.h"
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
struct renderer_context *renderer_context_init(void)
|
|
||||||
{
|
|
||||||
struct renderer_context *context = (struct renderer_context *)arena_alloc(global_arena, (sizeof(struct renderer_context)));
|
|
||||||
|
|
||||||
vk_instance_init(context);
|
|
||||||
vk_physical_device_pick(context);
|
|
||||||
vk_physical_device_select_family_indices(context);
|
|
||||||
vk_device_init(context);
|
|
||||||
return context;
|
|
||||||
}
|
|
||||||
|
|
||||||
void renderer_context_deinit(struct renderer_context *context)
|
|
||||||
{
|
|
||||||
vk_device_deinit(context);
|
|
||||||
vk_instance_deinit(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct mesh *renderer_build_chunk_mesh(void)
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
void renderer_draw_mesh(struct renderer_context *context, struct mesh mesh)
|
|
||||||
{
|
|
||||||
(void) context;
|
|
||||||
(void)mesh;
|
|
||||||
}
|
|
||||||
|
|
||||||
void renderer_draw_chunk(struct renderer_context *context, struct mesh mesh)
|
|
||||||
{
|
|
||||||
(void)mesh;
|
|
||||||
(void)context;
|
|
||||||
}
|
|
||||||
20
vk/vk.h
20
vk/vk.h
|
|
@ -1,20 +0,0 @@
|
||||||
/* SPDX-License-Identifier:BSD-3-Clause */
|
|
||||||
#ifndef VK_H
|
|
||||||
#define VK_H
|
|
||||||
|
|
||||||
#include <vulkan/vulkan.h>
|
|
||||||
#include "../types.h"
|
|
||||||
|
|
||||||
struct queue_family_indices {
|
|
||||||
u32 graphics, present;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct renderer_context {
|
|
||||||
VkInstance instance;
|
|
||||||
VkPhysicalDevice physical_device;
|
|
||||||
VkDevice device;
|
|
||||||
VkQueue graphics_queue;
|
|
||||||
struct queue_family_indices queue_indices;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue