get image count and preferred surface format
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include "output_device/gryphn_physical_output_device.h"
|
||||
#include "output_device/gryphn_output_device.h"
|
||||
#include "window_surface/gryphn_surface.h"
|
||||
#include "window_surface/gryphn_surface_create_functions.h"
|
||||
|
||||
typedef struct gnFunctions_t {
|
||||
gnReturnCode (*_gnCreateInstance)(gnInstance* instance, struct gnInstanceInfo_t info);
|
||||
@@ -42,7 +43,7 @@ typedef struct gnFunctions_t {
|
||||
#endif
|
||||
|
||||
void (*_gnDestroyWindowSurface)(struct gnWindowSurface_t* windowSurface);
|
||||
struct gnSurfaceFormat_t* (*_gnGetSupportedSurfaceFormats)(struct gnWindowSurface_t* windowSurface, struct gnPhysicalDevice_t device, uint32_t* formatCount);
|
||||
struct gnSurfaceDetails_t (*_gnGetSurfaceDetails)(struct gnWindowSurface_t* windowSurface, struct gnPhysicalDevice_t device);
|
||||
} gnFunctions;
|
||||
|
||||
#include "core/presentation_queue/gryphn_presentation_queue.h"
|
||||
|
@@ -65,7 +65,7 @@ void gnLoadFunctions(struct gnDynamicLibrary_t* lib, struct gnFunctions_t* funct
|
||||
#endif
|
||||
|
||||
gnLoadDLLFunction(lib, functions->_gnDestroyWindowSurface, "gnDestroyWindowSurfaceFn");
|
||||
gnLoadDLLFunction(lib, functions->_gnGetSupportedSurfaceFormats, "gnGetSupportedSurfaceFormatsFn");
|
||||
gnLoadDLLFunction(lib, functions->_gnGetSurfaceDetails, "gnGetSurfaceDetailsFn");
|
||||
}
|
||||
|
||||
void gnLoadDeviceFunctions(struct gnDynamicLibrary_t* lib, struct gnDeviceFunctions_t* functions) {
|
||||
|
@@ -1,12 +1,12 @@
|
||||
#pragma once
|
||||
#include <gryphn/gryphn_utils.h>
|
||||
#include "core/output_device/gryphn_output_device.h"
|
||||
#include <core/output_device/gryphn_output_device.h>
|
||||
#include <core/window_surface/gryphn_surface.h>
|
||||
#include <utils/types/gryphn_image_format.h>
|
||||
|
||||
typedef struct gnPresentationQueueInfo_t {
|
||||
gnUInt ImageCount;
|
||||
gnUInt2 ImageSize;
|
||||
uint32_t ImageCount;
|
||||
struct gnUInt2_t ImageSize;
|
||||
struct gnWindowSurface_t surface;
|
||||
struct gnSurfaceFormat_t format;
|
||||
} gnPresentationQueueInfo;
|
||||
|
@@ -1,34 +1,6 @@
|
||||
|
||||
#include "gryphn_surface.h"
|
||||
#include "core/gryphn_platform_functions.h"
|
||||
|
||||
#ifdef GN_PLATFORM_LINUX
|
||||
#ifdef GN_WINDOW_X11
|
||||
gnReturnCode gnCreateX11WindowSurface(struct gnWindowSurface_t* windowSurface, gnInstance* instance, struct gnX11WindowSurfaceInfo_t createInfo) {
|
||||
return instance->functions->_gnCreateX11WindowSurface(windowSurface, instance, createInfo);
|
||||
}
|
||||
#endif
|
||||
#ifdef GN_WINDOW_WAYLAND
|
||||
gnReturnCode gnCreateWaylandWindowSurface(struct gnWindowSurface_t* windowSurface, gnInstance* instance, struct gnWaylandWindowSurfaceInfo_t createInfo) {
|
||||
return instance->functions->_gnCreateWaylandWindowSurface(windowSurface, instance, createInfo);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef GN_PLATFORM_WIN32
|
||||
gnReturnCode gnCreateWin32WindowSurface(struct gnWindowSurface_t* windowSurface, gnInstance* instance, struct gnWin32WindowSurfaceInfo_t createInfo) {
|
||||
return instance->functions->_gnCreateWin32WindowSurface(windowSurface, instance, createInfo);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef GN_PLATFORM_MACOS
|
||||
gnReturnCode gnCreateMacOSWindowSurface(struct gnWindowSurface_t* windowSurface, gnInstance* instance, struct gnMacOSWindowSurfaceInfo_t createInfo) {
|
||||
windowSurface->instance = instance;
|
||||
return instance->functions->_gnCreateMacOSWindowSurface(windowSurface, instance, createInfo);
|
||||
}
|
||||
#endif
|
||||
|
||||
void gnDestroyWindowSurface(struct gnWindowSurface_t *windowSurface) {
|
||||
windowSurface->instance->functions->_gnDestroyWindowSurface(windowSurface);
|
||||
}
|
||||
@@ -38,5 +10,54 @@ struct gnSurfaceFormat_t* gnGetSupportedSurfaceFormats(
|
||||
struct gnPhysicalDevice_t device,
|
||||
uint32_t* formatCount
|
||||
) {
|
||||
return windowSurface->instance->functions->_gnGetSupportedSurfaceFormats(windowSurface, device, formatCount);
|
||||
struct gnSurfaceDetails_t surfaceDetails = windowSurface->instance->functions->_gnGetSurfaceDetails(windowSurface, device);
|
||||
*formatCount = surfaceDetails.formatCount;
|
||||
return surfaceDetails.formats;
|
||||
}
|
||||
|
||||
gnBool gnIsSurfaceFormatSupported(
|
||||
struct gnWindowSurface_t* windowSurface,
|
||||
struct gnPhysicalDevice_t device,
|
||||
struct gnSurfaceFormat_t format
|
||||
) {
|
||||
uint32_t formatCount = 0;
|
||||
gnSurfaceFormat* formats = gnGetSupportedSurfaceFormats(windowSurface, device, &formatCount);
|
||||
for (int i = 0; i < formatCount; i++) {
|
||||
if (formats[i].format == format.format && formats[i].colorSpace == format.colorSpace) {
|
||||
return gnTrue;
|
||||
}
|
||||
}
|
||||
return gnFalse;
|
||||
}
|
||||
|
||||
struct gnSurfaceFormat_t gnGetPreferredSurfaceFormat(
|
||||
struct gnWindowSurface_t* windowSurface,
|
||||
struct gnPhysicalDevice_t device,
|
||||
struct gnSurfaceFormat_t format
|
||||
) {
|
||||
uint32_t formatCount = 0;
|
||||
gnSurfaceFormat* formats = gnGetSupportedSurfaceFormats(windowSurface, device, &formatCount);
|
||||
for (int i = 0; i < formatCount; i++) {
|
||||
if (formats[i].format == format.format && formats[i].colorSpace == format.colorSpace) {
|
||||
return formats[i];
|
||||
}
|
||||
}
|
||||
|
||||
// will attempt to give you a simmilar format that either matches the Image format and the Color space
|
||||
for (int i = 0; i < formatCount; i++) {
|
||||
if (formats[i].format == format.format || formats[i].colorSpace == format.colorSpace) {
|
||||
return formats[i];
|
||||
}
|
||||
}
|
||||
|
||||
return formats[0];
|
||||
}
|
||||
|
||||
int gnGetMinImageCount(struct gnWindowSurface_t surface, struct gnPhysicalDevice_t device) {
|
||||
struct gnSurfaceDetails_t surfaceDetails = surface.instance->functions->_gnGetSurfaceDetails(&surface, device);
|
||||
return surfaceDetails.minImageCount;
|
||||
}
|
||||
int gnGetMaxImageCount(struct gnWindowSurface_t surface, struct gnPhysicalDevice_t device) {
|
||||
struct gnSurfaceDetails_t surfaceDetails = surface.instance->functions->_gnGetSurfaceDetails(&surface, device);
|
||||
return surfaceDetails.maxImageCount;
|
||||
}
|
||||
|
@@ -11,6 +11,13 @@ typedef struct gnSurfaceFormat_t {
|
||||
gnColorSpace colorSpace;
|
||||
} gnSurfaceFormat;
|
||||
|
||||
typedef struct gnSurfaceDetails_t {
|
||||
uint32_t formatCount;
|
||||
struct gnSurfaceFormat_t* formats;
|
||||
|
||||
int minImageCount, maxImageCount;
|
||||
} gnSufaceDetails;
|
||||
|
||||
typedef struct gnWindowSurface_t {
|
||||
struct gnPlatformWindowSurface_t* windowSurface;
|
||||
gnInstance* instance;
|
||||
@@ -21,40 +28,18 @@ struct gnSurfaceFormat_t* gnGetSupportedSurfaceFormats(
|
||||
struct gnPhysicalDevice_t device,
|
||||
uint32_t* formatCount
|
||||
);
|
||||
|
||||
#ifdef GN_PLATFORM_LINUX
|
||||
#ifdef GN_WINDOW_X11
|
||||
typedef struct gnX11WindowSurfaceInfo_t {
|
||||
Display* display;
|
||||
Window* window;
|
||||
} gnX11WindowSurfaceCreateInfo;
|
||||
|
||||
gnReturnCode gnCreateX11WindowSurface(struct gnWindowSurface_t* windowSurface, gnInstance* instance, struct gnX11WindowSurfaceInfo_t createInfo);
|
||||
#endif
|
||||
#ifdef GN_WINDOW_WAYLAND
|
||||
typedef struct gnWaylandWindowSurfaceInfo_t {
|
||||
wl_display* display;
|
||||
wl_surface* surface;
|
||||
} gnWaylandWindowSurfaceInfo;
|
||||
|
||||
gnReturnCode gnCreateWaylandWindowSurface(struct gnWindowSurface_t* windowSurface, gnInstance* instance, struct gnWaylandWindowSurfaceInfo_t createInfo);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef GN_PLATFORM_WIN32
|
||||
typedef struct gnWin32WindowSurfaceInfo_t {
|
||||
HWND* window;
|
||||
HINSTANCE* instance;
|
||||
} gnWin32WindowSurfaceInfo;
|
||||
|
||||
gnReturnCode gnCreateWin32WindowSurface(struct gnWindowSurface_t* windowSurface, gnInstance* instance, struct gnWin32WindowSurfaceInfo_t createInfo);
|
||||
#endif
|
||||
|
||||
#ifdef GN_PLATFORM_MACOS
|
||||
typedef struct gnMacOSWindowSurfaceInfo_t {
|
||||
NSWindow* window;
|
||||
} gnMacOSWindowSurfaceInfo;
|
||||
|
||||
gnReturnCode gnCreateMacOSWindowSurface(struct gnWindowSurface_t* windowSurface, gnInstance* instance, struct gnMacOSWindowSurfaceInfo_t createInfo);
|
||||
#endif
|
||||
gnBool gnIsSurfaceFormatSupported(
|
||||
struct gnWindowSurface_t* windowSurface,
|
||||
struct gnPhysicalDevice_t device,
|
||||
struct gnSurfaceFormat_t format
|
||||
);
|
||||
// this function will give you you're preferred surface format
|
||||
// unless its not supported then it will give you the first supported surface format
|
||||
// at some point this function will attempt to give you the most simmilar surface format
|
||||
struct gnSurfaceFormat_t gnGetPreferredSurfaceFormat(
|
||||
struct gnWindowSurface_t* windowSurface,
|
||||
struct gnPhysicalDevice_t device,
|
||||
struct gnSurfaceFormat_t format
|
||||
);
|
||||
int gnGetMinImageCount(struct gnWindowSurface_t surface, struct gnPhysicalDevice_t device);
|
||||
int gnGetMaxImageCount(struct gnWindowSurface_t surface, struct gnPhysicalDevice_t device);
|
||||
|
30
src/core/window_surface/gryphn_surface_create_functions.c
Normal file
30
src/core/window_surface/gryphn_surface_create_functions.c
Normal file
@@ -0,0 +1,30 @@
|
||||
#include "gryphn_surface_create_functions.h"
|
||||
#include "core/instance/gryphn_instance.h"
|
||||
#include "core/gryphn_platform_functions.h"
|
||||
|
||||
#ifdef GN_PLATFORM_LINUX
|
||||
#ifdef GN_WINDOW_X11
|
||||
gnReturnCode gnCreateX11WindowSurface(struct gnWindowSurface_t* windowSurface, gnInstance* instance, struct gnX11WindowSurfaceInfo_t createInfo) {
|
||||
return instance->functions->_gnCreateX11WindowSurface(windowSurface, instance, createInfo);
|
||||
}
|
||||
#endif
|
||||
#ifdef GN_WINDOW_WAYLAND
|
||||
gnReturnCode gnCreateWaylandWindowSurface(struct gnWindowSurface_t* windowSurface, gnInstance* instance, struct gnWaylandWindowSurfaceInfo_t createInfo) {
|
||||
return instance->functions->_gnCreateWaylandWindowSurface(windowSurface, instance, createInfo);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef GN_PLATFORM_WIN32
|
||||
gnReturnCode gnCreateWin32WindowSurface(struct gnWindowSurface_t* windowSurface, gnInstance* instance, struct gnWin32WindowSurfaceInfo_t createInfo) {
|
||||
return instance->functions->_gnCreateWin32WindowSurface(windowSurface, instance, createInfo);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef GN_PLATFORM_MACOS
|
||||
gnReturnCode gnCreateMacOSWindowSurface(struct gnWindowSurface_t* windowSurface, gnInstance* instance, struct gnMacOSWindowSurfaceInfo_t createInfo) {
|
||||
windowSurface->instance = instance;
|
||||
return instance->functions->_gnCreateMacOSWindowSurface(windowSurface, instance, createInfo);
|
||||
}
|
||||
#endif
|
39
src/core/window_surface/gryphn_surface_create_functions.h
Normal file
39
src/core/window_surface/gryphn_surface_create_functions.h
Normal file
@@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
#include "gryphn_surface.h"
|
||||
|
||||
#ifdef GN_PLATFORM_LINUX
|
||||
#ifdef GN_WINDOW_X11
|
||||
typedef struct gnX11WindowSurfaceInfo_t {
|
||||
Display* display;
|
||||
Window* window;
|
||||
} gnX11WindowSurfaceCreateInfo;
|
||||
|
||||
gnReturnCode gnCreateX11WindowSurface(struct gnWindowSurface_t* windowSurface, gnInstance* instance, struct gnX11WindowSurfaceInfo_t createInfo);
|
||||
#endif
|
||||
#ifdef GN_WINDOW_WAYLAND
|
||||
typedef struct gnWaylandWindowSurfaceInfo_t {
|
||||
wl_display* display;
|
||||
wl_surface* surface;
|
||||
} gnWaylandWindowSurfaceInfo;
|
||||
|
||||
gnReturnCode gnCreateWaylandWindowSurface(struct gnWindowSurface_t* windowSurface, gnInstance* instance, struct gnWaylandWindowSurfaceInfo_t createInfo);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef GN_PLATFORM_WIN32
|
||||
typedef struct gnWin32WindowSurfaceInfo_t {
|
||||
HWND* window;
|
||||
HINSTANCE* instance;
|
||||
} gnWin32WindowSurfaceInfo;
|
||||
|
||||
gnReturnCode gnCreateWin32WindowSurface(struct gnWindowSurface_t* windowSurface, gnInstance* instance, struct gnWin32WindowSurfaceInfo_t createInfo);
|
||||
#endif
|
||||
|
||||
#ifdef GN_PLATFORM_MACOS
|
||||
typedef struct gnMacOSWindowSurfaceInfo_t {
|
||||
NSWindow* window;
|
||||
} gnMacOSWindowSurfaceInfo;
|
||||
|
||||
gnReturnCode gnCreateMacOSWindowSurface(struct gnWindowSurface_t* windowSurface, gnInstance* instance, struct gnMacOSWindowSurfaceInfo_t createInfo);
|
||||
#endif
|
@@ -12,7 +12,8 @@ typedef enum gnReturnCode_t {
|
||||
GN_INVALID_INSTANCE,
|
||||
GN_DEBUGGER_EXISTS,
|
||||
GN_NO_SUPPORTED_FORMATS,
|
||||
GN_NO_SUPPORTED_PRESENT_MODES
|
||||
GN_NO_SUPPORTED_PRESENT_MODES,
|
||||
GN_UNKNOWN_IMAGE_FORMAT
|
||||
|
||||
// GN_UNKNOWN_ERROR,
|
||||
// GN_UNKNOWN_FRAMEBUFFER_ATTACHMENT,
|
||||
@@ -45,5 +46,6 @@ static const char* gnErrorCodeToCString(enum gnReturnCode_t returnCode) {
|
||||
case GN_DEBUGGER_EXISTS: return "GN_DEBUGGER_EXISTS";
|
||||
case GN_NO_SUPPORTED_FORMATS: return "GN_NO_SUPPORTED_FORMATS";
|
||||
case GN_NO_SUPPORTED_PRESENT_MODES: return "GN_NO_SUPPORTED_PRESENT_MODES";
|
||||
case GN_UNKNOWN_IMAGE_FORMAT: return "GN_UNKNOWN_IMAGE_FORMAT";
|
||||
}
|
||||
}
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
#include "stdint.h"
|
||||
|
||||
typedef struct gnVec2 {
|
||||
typedef struct gnVec2_t {
|
||||
union {
|
||||
struct { float a, b; };
|
||||
struct { float x, y; };
|
||||
@@ -28,7 +28,7 @@ typedef struct gnVec2 {
|
||||
typedef gnVec2 gnFVec2;
|
||||
typedef gnVec2 gnFloat2;
|
||||
|
||||
typedef struct gnUInt2 {
|
||||
typedef struct gnUInt2_t {
|
||||
union {
|
||||
struct { uint32_t a, b; };
|
||||
struct { uint32_t x, y; };
|
||||
@@ -52,7 +52,7 @@ typedef struct gnUInt2 {
|
||||
#endif
|
||||
} gnUInt2;
|
||||
|
||||
typedef struct gnInt2 {
|
||||
typedef struct gnInt2_t {
|
||||
union {
|
||||
struct { int a, b; };
|
||||
struct { int x, y; };
|
||||
|
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
typedef enum gnImageFormat_e {
|
||||
GN_FORMAT_NONE,
|
||||
GN_FORMAT_BGRA8_SRGB
|
||||
} gnImageFormat;
|
||||
|
||||
|
Reference in New Issue
Block a user