Compare commits
8 Commits
97a70e911d
...
5db32f367a
Author | SHA1 | Date | |
---|---|---|---|
![]() |
5db32f367a | ||
![]() |
2e02bbf799 | ||
![]() |
8658c7646f | ||
![]() |
c99a4cdb31 | ||
![]() |
f045793322 | ||
![]() |
5213e0135a | ||
![]() |
e973386511 | ||
![]() |
cb55a7716f |
@@ -22,8 +22,6 @@ typedef struct gnPlatformRenderPassDescriptor_t {
|
|||||||
uint32_t subpassCount;
|
uint32_t subpassCount;
|
||||||
mtlSubpass* subpasses;
|
mtlSubpass* subpasses;
|
||||||
mtlSubpassCopyInfo* copyInfos;
|
mtlSubpassCopyInfo* copyInfos;
|
||||||
|
|
||||||
|
|
||||||
} gnPlatformRenderPassDescriptor;
|
} gnPlatformRenderPassDescriptor;
|
||||||
|
|
||||||
gnReturnCode createMetalRenderPass(gnRenderPassDescriptor renderPass, gnDevice device, gnRenderPassDescriptorInfo info);
|
gnReturnCode createMetalRenderPass(gnRenderPassDescriptor renderPass, gnDevice device, gnRenderPassDescriptorInfo info);
|
||||||
|
@@ -7,6 +7,7 @@
|
|||||||
#include "uniforms/uniform/opengl_uniform.h"
|
#include "uniforms/uniform/opengl_uniform.h"
|
||||||
#include "commands/pool/opengl_command_pool.h"
|
#include "commands/pool/opengl_command_pool.h"
|
||||||
#include "buffer/opengl_buffer.h"
|
#include "buffer/opengl_buffer.h"
|
||||||
|
#include "textures/opengl_texture.h"
|
||||||
|
|
||||||
gnDeviceFunctions loadOpenGLDeviceFunctions() {
|
gnDeviceFunctions loadOpenGLDeviceFunctions() {
|
||||||
return (gnDeviceFunctions){
|
return (gnDeviceFunctions){
|
||||||
@@ -44,9 +45,9 @@ gnDeviceFunctions loadOpenGLDeviceFunctions() {
|
|||||||
._gnUpdateStorageUniform = openglUpdateStorageUniform,
|
._gnUpdateStorageUniform = openglUpdateStorageUniform,
|
||||||
._gnUpdateImageUniform = openglUpdateImageUniform,
|
._gnUpdateImageUniform = openglUpdateImageUniform,
|
||||||
|
|
||||||
._gnCreateTexture = NULL,
|
._gnCreateTexture = openglCreateTexture,
|
||||||
._gnTextureData = NULL,
|
._gnTextureData = openglTextureData,
|
||||||
._gnDestroyTexture = NULL,
|
._gnDestroyTexture = openglDestroyTexture,
|
||||||
|
|
||||||
._gnSubmit = NULL,
|
._gnSubmit = NULL,
|
||||||
._gnPresent = NULL,
|
._gnPresent = NULL,
|
||||||
|
@@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
gnReturnCode openglCreateInstance(gnInstanceHandle instance, gnInstanceCreateInfo* instanceInfo, gryphnInstanceFunctionLayers* next, gnAllocators* allocators) {
|
gnReturnCode openglCreateInstance(gnInstanceHandle instance, gnInstanceCreateInfo* instanceInfo, gryphnInstanceFunctionLayers* next, gnAllocators* allocators) {
|
||||||
if (instanceInfo->coreAPI != GN_RENDERINGAPI_OPENGL) return GN_UNSUPPORTED_API;
|
if (instanceInfo->coreAPI != GN_RENDERINGAPI_OPENGL) return GN_UNSUPPORTED_API;
|
||||||
|
instance->instance = malloc(sizeof(gnPlatformInstance));
|
||||||
|
instance->instance->enableDebugger = instance->enabledLayerCounts[GN_DEBUGGER_LAYER_PLATFORM] >= 1;
|
||||||
|
|
||||||
return GN_SUCCESS;
|
return GN_SUCCESS;
|
||||||
}
|
}
|
||||||
void openglDestroyInstance(gnInstanceHandle instance, gryphnInstanceFunctionLayers* next, gnAllocators* allocators) {
|
void openglDestroyInstance(gnInstanceHandle instance, gryphnInstanceFunctionLayers* next, gnAllocators* allocators) {
|
||||||
|
@@ -2,7 +2,9 @@
|
|||||||
#include <GL/gl.h>
|
#include <GL/gl.h>
|
||||||
#include "instance/gryphn_instance.h"
|
#include "instance/gryphn_instance.h"
|
||||||
|
|
||||||
typedef struct gnPlatformInstance_t {} gnPlatformInstance;
|
typedef struct gnPlatformInstance_t {
|
||||||
|
gnBool enableDebugger;
|
||||||
|
} gnPlatformInstance;
|
||||||
|
|
||||||
gnReturnCode openglCreateInstance(gnInstanceHandle instance, gnInstanceCreateInfo* instanceInfo, gryphnInstanceFunctionLayers* next, gnAllocators* allocators);
|
gnReturnCode openglCreateInstance(gnInstanceHandle instance, gnInstanceCreateInfo* instanceInfo, gryphnInstanceFunctionLayers* next, gnAllocators* allocators);
|
||||||
void openglDestroyInstance(gnInstanceHandle instance, gryphnInstanceFunctionLayers* next, gnAllocators* allocators);
|
void openglDestroyInstance(gnInstanceHandle instance, gryphnInstanceFunctionLayers* next, gnAllocators* allocators);
|
||||||
|
@@ -5,8 +5,6 @@
|
|||||||
gnReturnCode createOpenGLPresentationQueue(gnPresentationQueueHandle presentationQueue, gnOutputDeviceHandle device, gnPresentationQueueInfo presentationInfo) {
|
gnReturnCode createOpenGLPresentationQueue(gnPresentationQueueHandle presentationQueue, gnOutputDeviceHandle device, gnPresentationQueueInfo presentationInfo) {
|
||||||
presentationQueue->presentationQueue = malloc(sizeof(struct gnPlatformPresentationQueue_t));
|
presentationQueue->presentationQueue = malloc(sizeof(struct gnPlatformPresentationQueue_t));
|
||||||
|
|
||||||
uint32_t convertedFormat = glGryphnFormatToOpenGLFormat(presentationInfo.format.format);
|
|
||||||
|
|
||||||
presentationQueue->imageCount = presentationInfo.minImageCount;
|
presentationQueue->imageCount = presentationInfo.minImageCount;
|
||||||
presentationQueue->images = malloc(sizeof(gnTexture) * presentationInfo.minImageCount);
|
presentationQueue->images = malloc(sizeof(gnTexture) * presentationInfo.minImageCount);
|
||||||
presentationQueue->presentationQueue->textures = GLuintArrayListCreate();
|
presentationQueue->presentationQueue->textures = GLuintArrayListCreate();
|
||||||
@@ -14,19 +12,13 @@ gnReturnCode createOpenGLPresentationQueue(gnPresentationQueueHandle presentatio
|
|||||||
for (int i = 0; i < presentationInfo.minImageCount; i++) {
|
for (int i = 0; i < presentationInfo.minImageCount; i++) {
|
||||||
presentationQueue->images[i] = malloc(sizeof(struct gnTexture_t));
|
presentationQueue->images[i] = malloc(sizeof(struct gnTexture_t));
|
||||||
presentationQueue->images[i]->texture = malloc(sizeof(gnPlatformTexture));
|
presentationQueue->images[i]->texture = malloc(sizeof(gnPlatformTexture));
|
||||||
glGenTextures(1, &presentationQueue->images[i]->texture->id);
|
glCreateTextures(GL_TEXTURE_2D, 1, &presentationQueue->images[i]->texture->id);
|
||||||
|
glTextureStorage2D(
|
||||||
glTexImage2D(
|
presentationQueue->images[i]->texture->id,
|
||||||
GL_TEXTURE_2D,
|
1,
|
||||||
0,
|
|
||||||
glGryphnFormatToOpenGLInternalFormat(presentationInfo.format.format),
|
glGryphnFormatToOpenGLInternalFormat(presentationInfo.format.format),
|
||||||
presentationInfo.imageSize.x, presentationInfo.imageSize.y,
|
presentationInfo.imageSize.x, presentationInfo.imageSize.y
|
||||||
0,
|
|
||||||
glGryphnFormatToOpenGLFormat(presentationInfo.format.format),
|
|
||||||
GL_UNSIGNED_BYTE,
|
|
||||||
NULL
|
|
||||||
);
|
);
|
||||||
|
|
||||||
GLuintArrayListAdd(presentationQueue->presentationQueue->textures, presentationQueue->images[i]->texture->id);
|
GLuintArrayListAdd(presentationQueue->presentationQueue->textures, presentationQueue->images[i]->texture->id);
|
||||||
uint32_tArrayListAdd(presentationQueue->presentationQueue->avaliableTextures, i);
|
uint32_tArrayListAdd(presentationQueue->presentationQueue->avaliableTextures, i);
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,50 @@
|
|||||||
#include "opengl_render_pass_descriptor.h"
|
#include "opengl_render_pass_descriptor.h"
|
||||||
|
#include "surface/opengl_surface.h"
|
||||||
|
#include "stdlib.h"
|
||||||
|
|
||||||
gnReturnCode openglCreateRenderPass(gnRenderPassDescriptor renderPass, gnDevice device, gnRenderPassDescriptorInfo info) {
|
gnReturnCode openglCreateRenderPass(gnRenderPassDescriptor renderPass, gnDevice device, gnRenderPassDescriptorInfo info) {
|
||||||
|
if (device == GN_NULL_HANDLE) return GN_INVALID_HANDLE;
|
||||||
|
renderPass->renderPassDescriptor = malloc(sizeof(gnPlatformRenderPassDescriptor));
|
||||||
|
renderPass->renderPassDescriptor->subpassCount = info.subpassCount;
|
||||||
|
renderPass->renderPassDescriptor->subpasses = malloc(sizeof(glSubpass) * info.subpassCount);
|
||||||
|
|
||||||
|
for (uint32_t i = 0; i < info.subpassCount; i++) {
|
||||||
|
renderPass->renderPassDescriptor->subpasses[i] = (glSubpass){
|
||||||
|
.colorAttachmentCount = info.subpassInfos[i].colorAttachmentCount,
|
||||||
|
.colorAttachments = malloc(sizeof(glColorAttachment) * info.subpassInfos[i].colorAttachmentCount),
|
||||||
|
.depthAttachment.index = -1
|
||||||
|
};
|
||||||
|
gnBool resolve = !(info.subpassInfos[i].resolveAttachments == NULL);
|
||||||
|
for (uint32_t c = 0; c < info.subpassInfos[i].colorAttachmentCount; c++) {
|
||||||
|
uint32_t attachmentIndex = info.subpassInfos[i].colorAttachments[c].index;
|
||||||
|
int resolveAttachmentIndex = -1;
|
||||||
|
if (resolve)
|
||||||
|
resolveAttachmentIndex = info.subpassInfos[i].resolveAttachments[c].index;
|
||||||
|
|
||||||
|
renderPass->renderPassDescriptor->subpasses[i].colorAttachments[c] = (glColorAttachment){
|
||||||
|
.loadOperation = info.attachmentInfos[attachmentIndex].loadOperation,
|
||||||
|
.storeOperation = info.attachmentInfos[attachmentIndex].storeOperation,
|
||||||
|
.attachmentIndex = attachmentIndex,
|
||||||
|
.resolveAttachmentIndex = resolveAttachmentIndex,
|
||||||
|
.format = glGryphnFormatToOpenGLFormat(info.attachmentInfos[attachmentIndex].format)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (info.subpassInfos[i].depthAttachment != NULL) {
|
||||||
|
uint32_t depthAttachmentIndex = info.subpassInfos[i].depthAttachment->index;
|
||||||
|
renderPass->renderPassDescriptor->subpasses[i].depthAttachment = (gnDepthAttachment){
|
||||||
|
.index = depthAttachmentIndex,
|
||||||
|
.format = glGryphnFormatToOpenGLFormat(info.attachmentInfos[depthAttachmentIndex].format),
|
||||||
|
.loadOperation = info.attachmentInfos[depthAttachmentIndex].loadOperation,
|
||||||
|
.storeOperation = info.attachmentInfos[depthAttachmentIndex].storeOperation,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
return GN_SUCCESS;
|
return GN_SUCCESS;
|
||||||
}
|
}
|
||||||
void openglDestroyRenderPass(gnRenderPassDescriptor renderPass) {}
|
void openglDestroyRenderPass(gnRenderPassDescriptor renderPass) {
|
||||||
|
for (int i = 0; i < renderPass->renderPassDescriptor->subpassCount; i++)
|
||||||
|
free(renderPass->renderPassDescriptor->subpasses[i].colorAttachments);
|
||||||
|
free(renderPass->renderPassDescriptor->subpasses);
|
||||||
|
free(renderPass->renderPassDescriptor);
|
||||||
|
}
|
||||||
|
@@ -1,6 +1,34 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include "glad/glad.h"
|
||||||
#include "core/src/renderpass/gryphn_render_pass_descriptor.h"
|
#include "core/src/renderpass/gryphn_render_pass_descriptor.h"
|
||||||
|
#include "utils/gryphn_color.h"
|
||||||
|
|
||||||
typedef struct gnPlatformRenderPassDescriptor_t gnPlatformRenderPassDescriptor;
|
typedef struct glColorAttachment {
|
||||||
|
gnColor clearColor;
|
||||||
|
gnLoadOperation loadOperation;
|
||||||
|
gnStoreOperation storeOperation;
|
||||||
|
|
||||||
|
GLint format;
|
||||||
|
uint32_t attachmentIndex;
|
||||||
|
int resolveAttachmentIndex; // -1 = no attachment
|
||||||
|
} glColorAttachment;
|
||||||
|
|
||||||
|
typedef struct gnDepthAttachment {
|
||||||
|
int index;
|
||||||
|
gnLoadOperation loadOperation;
|
||||||
|
gnStoreOperation storeOperation;
|
||||||
|
GLint format;
|
||||||
|
} gnDepthAttachment;
|
||||||
|
|
||||||
|
typedef struct glSubpass {
|
||||||
|
uint32_t colorAttachmentCount;
|
||||||
|
glColorAttachment* colorAttachments;
|
||||||
|
gnDepthAttachment depthAttachment;
|
||||||
|
} glSubpass;
|
||||||
|
|
||||||
|
typedef struct gnPlatformRenderPassDescriptor_t {
|
||||||
|
uint32_t subpassCount;
|
||||||
|
glSubpass* subpasses;
|
||||||
|
} gnPlatformRenderPassDescriptor;
|
||||||
gnReturnCode openglCreateRenderPass(gnRenderPassDescriptor renderPass, gnDevice device, gnRenderPassDescriptorInfo info);
|
gnReturnCode openglCreateRenderPass(gnRenderPassDescriptor renderPass, gnDevice device, gnRenderPassDescriptorInfo info);
|
||||||
void openglDestroyRenderPass(gnRenderPassDescriptor renderPass);
|
void openglDestroyRenderPass(gnRenderPassDescriptor renderPass);
|
||||||
|
@@ -2,6 +2,55 @@
|
|||||||
#include "opengl_surface.h"
|
#include "opengl_surface.h"
|
||||||
#include "utils/gryphn_string.h"
|
#include "utils/gryphn_string.h"
|
||||||
|
|
||||||
|
#include "stdio.h"
|
||||||
|
|
||||||
|
void GLAPIENTRY openglMessageCallback( GLenum source,
|
||||||
|
GLenum type,
|
||||||
|
GLuint id,
|
||||||
|
GLenum severity,
|
||||||
|
GLsizei length,
|
||||||
|
const GLchar* message,
|
||||||
|
const void* userParam ) {
|
||||||
|
gnInstanceHandle handle = (gnInstanceHandle)userParam;
|
||||||
|
|
||||||
|
gnMessageSeverity gryphnSeverity;
|
||||||
|
if (severity == GL_DEBUG_SEVERITY_HIGH) gryphnSeverity = GN_MESSAGE_ERROR;
|
||||||
|
else if (severity == GL_DEBUG_SEVERITY_MEDIUM) gryphnSeverity = GN_MESSAGE_WARNING;
|
||||||
|
else if (severity == GL_DEBUG_SEVERITY_LOW) gryphnSeverity = GN_MESSAGE_WARNING;
|
||||||
|
else if (severity == GL_DEBUG_SEVERITY_NOTIFICATION) gryphnSeverity = GN_MESSAGE_VERBOSE;
|
||||||
|
else {
|
||||||
|
handle->debugger.callback(
|
||||||
|
GN_MESSAGE_ERROR,
|
||||||
|
GN_DEBUG_MESSAGE_VALIDATION,
|
||||||
|
(gnMessageData){ .message = gnCreateString("Uknown severity type from OpenGL") },
|
||||||
|
handle->debugger.userData
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
gnMessageType gryphnType;
|
||||||
|
if (type == GL_DEBUG_TYPE_ERROR) gryphnType = GN_DEBUG_MESSAGE_VALIDATION;
|
||||||
|
else if (type == GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR) gryphnType = GN_DEBUG_MESSAGE_VALIDATION;
|
||||||
|
else if (type == GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR) gryphnType = GN_DEBUG_MESSAGE_VALIDATION;
|
||||||
|
else if (type == GL_DEBUG_TYPE_PORTABILITY) gryphnType = GN_DEBUG_MESSAGE_VALIDATION;
|
||||||
|
else if (type == GL_DEBUG_TYPE_PERFORMANCE) gryphnType = GN_DEBUG_MESSAGE_PERFORMANCE;
|
||||||
|
else if (type == GL_DEBUG_TYPE_OTHER) gryphnType = GN_DEBUG_MESSAGE_GENERAL;
|
||||||
|
else {
|
||||||
|
handle->debugger.callback(
|
||||||
|
GN_MESSAGE_ERROR,
|
||||||
|
GN_DEBUG_MESSAGE_VALIDATION,
|
||||||
|
(gnMessageData){ .message = gnCreateString("Uknown message type from OpenGL") },
|
||||||
|
handle->debugger.userData
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
handle->debugger.callback(
|
||||||
|
gryphnSeverity,
|
||||||
|
gryphnType,
|
||||||
|
(gnMessageData){ .message = gnCreateString(message) },
|
||||||
|
handle->debugger.userData
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef GN_PLATFORM_LINUX
|
#ifdef GN_PLATFORM_LINUX
|
||||||
#ifdef GN_WINDOW_X11
|
#ifdef GN_WINDOW_X11
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
@@ -27,6 +76,10 @@ gnReturnCode createGLXContext(gnWindowSurfaceHandle windowSurface, gnInstanceHan
|
|||||||
|
|
||||||
return GN_UNKNOWN_ERROR;
|
return GN_UNKNOWN_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glEnable(GL_DEBUG_OUTPUT);
|
||||||
|
glDebugMessageCallback(openglMessageCallback, instance);
|
||||||
|
|
||||||
return GN_SUCCESS;
|
return GN_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,11 +103,14 @@ gnSurfaceDetails genOpenGLSurfaceDetails(
|
|||||||
) {
|
) {
|
||||||
gnSurfaceDetails surfaceDetails;
|
gnSurfaceDetails surfaceDetails;
|
||||||
surfaceDetails.formatCount = 1;
|
surfaceDetails.formatCount = 1;
|
||||||
surfaceDetails.formats = (gnSurfaceFormat[]){
|
surfaceDetails.formats = malloc(sizeof(gnSurfaceFormat) * 2);
|
||||||
(gnSurfaceFormat){
|
surfaceDetails.formats[0] = (gnSurfaceFormat){
|
||||||
|
.format = GN_FORMAT_RGBA8,
|
||||||
|
.colorSpace = GN_COLOR_SPACE_SRGB_NONLINEAR
|
||||||
|
};
|
||||||
|
surfaceDetails.formats[1] = (gnSurfaceFormat){
|
||||||
.format = GN_FORMAT_RGBA8_SRGB,
|
.format = GN_FORMAT_RGBA8_SRGB,
|
||||||
.colorSpace = GN_COLOR_SPACE_SRGB_NONLINEAR
|
.colorSpace = GN_COLOR_SPACE_SRGB_NONLINEAR
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
surfaceDetails.minImageCount = 2;
|
surfaceDetails.minImageCount = 2;
|
||||||
@@ -75,7 +131,8 @@ void destroyOpenGLSurface(gnWindowSurface surface) {
|
|||||||
GLint glGryphnFormatToOpenGLFormat(gnImageFormat format) {
|
GLint glGryphnFormatToOpenGLFormat(gnImageFormat format) {
|
||||||
switch (format) {
|
switch (format) {
|
||||||
case GN_FORMAT_NONE: return GL_NONE;
|
case GN_FORMAT_NONE: return GL_NONE;
|
||||||
case GN_FORMAT_RGBA8_SRGB: return GL_SRGB_ALPHA;
|
case GN_FORMAT_RGBA8: return GL_RGBA;
|
||||||
|
case GN_FORMAT_RGBA8_SRGB: return GL_RGBA;
|
||||||
case GN_FORMAT_D32S8_UINT: return GL_DEPTH_STENCIL;
|
case GN_FORMAT_D32S8_UINT: return GL_DEPTH_STENCIL;
|
||||||
case GN_FORMAT_D24S8_UINT: return GL_DEPTH_STENCIL;
|
case GN_FORMAT_D24S8_UINT: return GL_DEPTH_STENCIL;
|
||||||
|
|
||||||
@@ -87,6 +144,7 @@ GLint glGryphnFormatToOpenGLFormat(gnImageFormat format) {
|
|||||||
GLint glGryphnFormatToOpenGLInternalFormat(gnImageFormat format) {
|
GLint glGryphnFormatToOpenGLInternalFormat(gnImageFormat format) {
|
||||||
switch (format) {
|
switch (format) {
|
||||||
case GN_FORMAT_NONE: return GL_NONE;
|
case GN_FORMAT_NONE: return GL_NONE;
|
||||||
|
case GN_FORMAT_RGBA8: return GL_RGBA8;
|
||||||
case GN_FORMAT_RGBA8_SRGB: return GL_SRGB8_ALPHA8;
|
case GN_FORMAT_RGBA8_SRGB: return GL_SRGB8_ALPHA8;
|
||||||
case GN_FORMAT_D32S8_UINT: return GL_DEPTH32F_STENCIL8;
|
case GN_FORMAT_D32S8_UINT: return GL_DEPTH32F_STENCIL8;
|
||||||
case GN_FORMAT_D24S8_UINT: return GL_DEPTH24_STENCIL8;
|
case GN_FORMAT_D24S8_UINT: return GL_DEPTH24_STENCIL8;
|
||||||
|
34
projects/apis/opengl/src/textures/opengl_texture.c
Normal file
34
projects/apis/opengl/src/textures/opengl_texture.c
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
#include "opengl_texture.h"
|
||||||
|
#include "surface/opengl_surface.h"
|
||||||
|
|
||||||
|
GLenum GryphnTargetToOpenGL(gnTextureType type) {
|
||||||
|
switch(type) {
|
||||||
|
case GN_TEXTURE_2D: return GL_TEXTURE_2D;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
gnReturnCode openglCreateTexture(gnTexture texture, gnDevice device, const gnTextureInfo info) {
|
||||||
|
texture->texture = malloc(sizeof(gnPlatformTexture));
|
||||||
|
glCreateTextures(GryphnTargetToOpenGL(info.type), 1, &texture->texture->id);
|
||||||
|
glTextureStorage2D(
|
||||||
|
texture->texture->id,
|
||||||
|
1,
|
||||||
|
glGryphnFormatToOpenGLInternalFormat(info.format),
|
||||||
|
info.extent.x, info.extent.y
|
||||||
|
);
|
||||||
|
return GN_SUCCESS;
|
||||||
|
}
|
||||||
|
void openglTextureData(gnTextureHandle texture, void* pixelData) {
|
||||||
|
glTextureSubImage2D(
|
||||||
|
texture->texture->id,
|
||||||
|
0,
|
||||||
|
0, 0,
|
||||||
|
texture->info.extent.x, texture->info.extent.y,
|
||||||
|
GL_RGBA,
|
||||||
|
GL_UNSIGNED_BYTE,
|
||||||
|
pixelData
|
||||||
|
);
|
||||||
|
}
|
||||||
|
void openglDestroyTexture(gnTexture texture) {
|
||||||
|
|
||||||
|
}
|
@@ -5,3 +5,7 @@
|
|||||||
typedef struct gnPlatformTexture_t {
|
typedef struct gnPlatformTexture_t {
|
||||||
GLuint id;
|
GLuint id;
|
||||||
} gnPlatformTexture;
|
} gnPlatformTexture;
|
||||||
|
|
||||||
|
gnReturnCode openglCreateTexture(gnTexture texture, gnDevice device, const gnTextureInfo info);
|
||||||
|
void openglTextureData(gnTextureHandle texture, void* pixelData);
|
||||||
|
void openglDestroyTexture(gnTexture texture);
|
||||||
|
@@ -144,8 +144,15 @@ void VkCopyBufferToImage(VkGryphnBuffer buffer, VkGryphnImage image, gnExtent3D
|
|||||||
gnReturnCode createTexture(gnTexture texture, gnDevice device, const gnTextureInfo info) {
|
gnReturnCode createTexture(gnTexture texture, gnDevice device, const gnTextureInfo info) {
|
||||||
texture->texture = malloc(sizeof(struct gnPlatformTexture_t));
|
texture->texture = malloc(sizeof(struct gnPlatformTexture_t));
|
||||||
size_t imageSize = info.extent.width * info.extent.height;
|
size_t imageSize = info.extent.width * info.extent.height;
|
||||||
if (info.format == GN_FORMAT_BGRA8_SRGB) { imageSize *= 4; }
|
switch (info.format) {
|
||||||
if (info.format == GN_FORMAT_RGBA8_SRGB) { imageSize *= 4; }
|
case GN_FORMAT_NONE: imageSize *= 0; break;
|
||||||
|
case GN_FORMAT_BGRA8_SRGB: imageSize *= 4; break;
|
||||||
|
case GN_FORMAT_BGRA8: imageSize *= 4; break;
|
||||||
|
case GN_FORMAT_RGBA8: imageSize *= 4; break;
|
||||||
|
case GN_FORMAT_RGBA8_SRGB: imageSize *= 4; break;
|
||||||
|
case GN_FORMAT_D32S8_UINT: imageSize *= 5; break;
|
||||||
|
case GN_FORMAT_D24S8_UINT: imageSize *= 4; break;
|
||||||
|
};
|
||||||
texture->texture->size = imageSize;
|
texture->texture->size = imageSize;
|
||||||
VkImageCreateInfo imageInfo = {
|
VkImageCreateInfo imageInfo = {
|
||||||
.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
|
.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
|
||||||
|
@@ -109,6 +109,7 @@ VkFormat vkGryphnFormatToVulkanFormat(gnImageFormat format) {
|
|||||||
case GN_FORMAT_NONE: return VK_FORMAT_UNDEFINED;
|
case GN_FORMAT_NONE: return VK_FORMAT_UNDEFINED;
|
||||||
case GN_FORMAT_BGRA8_SRGB: return VK_FORMAT_B8G8R8A8_SRGB;
|
case GN_FORMAT_BGRA8_SRGB: return VK_FORMAT_B8G8R8A8_SRGB;
|
||||||
case GN_FORMAT_BGRA8: return VK_FORMAT_B8G8R8A8_UNORM;
|
case GN_FORMAT_BGRA8: return VK_FORMAT_B8G8R8A8_UNORM;
|
||||||
|
case GN_FORMAT_RGBA8: return VK_FORMAT_R8G8B8A8_UNORM;
|
||||||
case GN_FORMAT_RGBA8_SRGB: return VK_FORMAT_R8G8B8A8_SRGB;
|
case GN_FORMAT_RGBA8_SRGB: return VK_FORMAT_R8G8B8A8_SRGB;
|
||||||
case GN_FORMAT_D32S8_UINT: return VK_FORMAT_D32_SFLOAT_S8_UINT;
|
case GN_FORMAT_D32S8_UINT: return VK_FORMAT_D32_SFLOAT_S8_UINT;
|
||||||
case GN_FORMAT_D24S8_UINT: return VK_FORMAT_D24_UNORM_S8_UINT;
|
case GN_FORMAT_D24S8_UINT: return VK_FORMAT_D24_UNORM_S8_UINT;
|
||||||
|
@@ -2,8 +2,9 @@
|
|||||||
|
|
||||||
typedef enum gnImageFormat {
|
typedef enum gnImageFormat {
|
||||||
GN_FORMAT_NONE,
|
GN_FORMAT_NONE,
|
||||||
GN_FORMAT_BGRA8_SRGB,
|
|
||||||
GN_FORMAT_BGRA8,
|
GN_FORMAT_BGRA8,
|
||||||
|
GN_FORMAT_BGRA8_SRGB,
|
||||||
|
GN_FORMAT_RGBA8,
|
||||||
GN_FORMAT_RGBA8_SRGB,
|
GN_FORMAT_RGBA8_SRGB,
|
||||||
GN_FORMAT_D24S8_UINT,
|
GN_FORMAT_D24S8_UINT,
|
||||||
GN_FORMAT_D32S8_UINT,
|
GN_FORMAT_D32S8_UINT,
|
||||||
|
Reference in New Issue
Block a user