feat: Add initial Vulkan backend framework and compile flag

I've introduced the foundational infrastructure for a Vulkan rendering backend in raylib.

Key changes:
- CMake:
    - I added a `SUPPORT_VULKAN` option (default OFF) to enable Vulkan.
    - It finds the Vulkan SDK and links appropriate libraries when enabled.
    - I defined `CF_VULKAN_` (0 by default, 1 if Vulkan enabled) and `GRAPHICS_API_VULKAN` preprocessor macros.
    - I updated `LibraryConfigurations.cmake` and `src/CMakeLists.txt` to handle Vulkan as a graphics API.
- Vulkan Abstraction Layer:
    - I created `src/rlvk.h` and `src/rlvk.c` with stub implementations for Vulkan rendering functions (e.g., `rlvkInit`, `rlvkClose`, drawing functions). These are compiled only when `SUPPORT_VULKAN` is ON.
- Core Integration:
    - `rlgl.h` and `rcore.c` now have conditional code paths for `GRAPHICS_API_VULKAN`.
    - `InitWindow` and `CloseWindow` in `rcore.c` call Vulkan-specific platform and backend initialization/deinitialization stubs.
- Platform Layer (GLFW):
    - `src/platforms/rcore_desktop_glfw.c` includes stubbed `InitPlatformVulkan` and `ClosePlatformVulkan` to set up GLFW for a Vulkan context (actual Vulkan instance/surface creation is stubbed).

This commit establishes the necessary build system changes and C code structure to allow for the incremental implementation of the Vulkan renderer. Currently, enabling Vulkan will compile the stubs, allowing your application to run but without actual Vulkan rendering. The `CF_VULKAN_` flag controls the compilation and selection of Vulkan as the default renderer when active.
This commit is contained in:
google-labs-jules[bot] 2025-06-01 02:12:36 +00:00
commit b93ec12bfe

77
src/rlvk.c Normal file
View file

@ -0,0 +1,77 @@
#include "rlvk.h"
#include "utils.h" // For TRACELOG if needed
#include <stdio.h> // For printf in stubs
#include <stdlib.h> // For RL_MALLOC, RL_FREE if used
// Global or static variables for Vulkan state (minimal for stubs)
static bool rlvkReady = false;
void rlvkInit(VkInstance instance, VkSurfaceKHR surface, int width, int height) {
printf("rlvkInit called (STUB)\n");
// Minimal check or setup
if (instance != VK_NULL_HANDLE && surface != VK_NULL_HANDLE) {
rlvkReady = true;
TRACELOG(LOG_INFO, "RLVK: Vulkan backend initialized (stubbed).");
} else {
TRACELOG(LOG_ERROR, "RLVK: Failed to initialize Vulkan backend due to null instance or surface (stubbed).");
rlvkReady = false;
}
}
void rlvkClose(void) {
printf("rlvkClose called (STUB)\n");
rlvkReady = false;
TRACELOG(LOG_INFO, "RLVK: Vulkan backend closed (stubbed).");
}
bool rlvkIsReady(void) {
return rlvkReady;
}
void rlvkBeginDrawing(void) {
// printf("rlvkBeginDrawing called (STUB)\n");
}
void rlvkEndDrawing(void) {
// printf("rlvkEndDrawing called (STUB)\n");
}
void rlvkClearBackground(unsigned char r, unsigned char g, unsigned char b, unsigned char a) {
// printf("rlvkClearBackground called (STUB) with color: %u, %u, %u, %u\n", r, g, b, a);
}
unsigned int rlvkLoadTexture(const void *data, int width, int height, int format, int mipmaps) {
printf("rlvkLoadTexture called (STUB)\n");
return 0; // Return a dummy ID
}
void rlvkUnloadTexture(unsigned int id) {
printf("rlvkUnloadTexture called (STUB) for ID: %u\n", id);
}
unsigned int rlvkLoadShaderCode(const char *vsCode, const char *fsCode) {
printf("rlvkLoadShaderCode called (STUB)\n");
return 0; // Return a dummy ID
}
void rlvkUnloadShaderProgram(unsigned int id) {
printf("rlvkUnloadShaderProgram called (STUB) for ID: %u\n", id);
}
int rlvkGetLocationUniform(unsigned int shaderId, const char *uniformName) {
// printf("rlvkGetLocationUniform called (STUB) for shader ID: %u, uniform: %s\n", shaderId, uniformName);
return -1;
}
int rlvkGetLocationAttrib(unsigned int shaderId, const char *attribName) {
// printf("rlvkGetLocationAttrib called (STUB) for shader ID: %u, attrib: %s\n", shaderId, attribName);
return -1;
}
void rlvkSetUniform(int locIndex, const void *value, int uniformType, int count) {
// printf("rlvkSetUniform called (STUB) for locIndex: %d\n", locIndex);
}
// ... other rlgl equivalent function stub implementations ...
// TRACELOG can be used for more detailed stub logging if utils.h is appropriately included and linked.
// For now, simple printf might be fine for basic stub verification.