OpenGL presentaion queue *****
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
#include "opengl_presentation_queue.h"
|
||||
#include "surface/opengl_surface.h"
|
||||
#include "textures/opengl_texture.h"
|
||||
|
||||
gnReturnCode createOpenGLPresentationQueue(gnPresentationQueueHandle presentationQueue, gnOutputDeviceHandle device, gnPresentationQueueInfo presentationInfo) {
|
||||
presentationQueue->presentationQueue = malloc(sizeof(struct gnPlatformPresentationQueue_t));
|
||||
|
||||
uint32_t convertedFormat = glGryphnFormatToOpenGLFormat(presentationInfo.format.format);
|
||||
|
||||
presentationQueue->imageCount = presentationInfo.minImageCount;
|
||||
presentationQueue->images = malloc(sizeof(gnTexture) * presentationInfo.minImageCount);
|
||||
presentationQueue->presentationQueue->textures = GLuintArrayListCreate();
|
||||
presentationQueue->presentationQueue->avaliableTextures = uint32_tArrayListCreate();
|
||||
for (int i = 0; i < presentationInfo.minImageCount; i++) {
|
||||
presentationQueue->images[i] = malloc(sizeof(struct gnTexture_t));
|
||||
presentationQueue->images[i]->texture = malloc(sizeof(gnPlatformTexture));
|
||||
glGenTextures(1, &presentationQueue->images[i]->texture->id);
|
||||
|
||||
glTexImage2D(
|
||||
GL_TEXTURE_2D,
|
||||
0,
|
||||
glGryphnFormatToOpenGLInternalFormat(presentationInfo.format.format),
|
||||
presentationInfo.imageSize.x, presentationInfo.imageSize.y,
|
||||
0,
|
||||
glGryphnFormatToOpenGLFormat(presentationInfo.format.format),
|
||||
GL_UNSIGNED_BYTE,
|
||||
NULL
|
||||
);
|
||||
|
||||
GLuintArrayListAdd(&presentationQueue->presentationQueue->textures, presentationQueue->images[i]->texture->id);
|
||||
uint32_tArrayListAdd(&presentationQueue->presentationQueue->avaliableTextures, i);
|
||||
}
|
||||
return GN_SUCCESS;
|
||||
}
|
||||
gnReturnCode getOpenGLPresentationQueueImage(gnPresentationQueue presentationQueue, uint32_t* imageIndex) {
|
||||
while (presentationQueue->presentationQueue->avaliableTextures.count == 0) {}
|
||||
*imageIndex = presentationQueue->presentationQueue->avaliableTextures.data[0];
|
||||
uint32_tArrayListPopHead(&presentationQueue->presentationQueue->avaliableTextures);
|
||||
return GN_SUCCESS;
|
||||
}
|
||||
void destroyOpenGLPresentationQueue(gnPresentationQueueHandle presentationQueue) {
|
||||
free(presentationQueue->presentationQueue);
|
||||
}
|
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
#include <glad/glad.h>
|
||||
#include "presentation_queue/gryphn_presentation_queue.h"
|
||||
|
||||
GN_ARRAY_LIST(GLuint);
|
||||
|
||||
typedef struct gnPlatformPresentationQueue_t {
|
||||
GLuintArrayList textures;
|
||||
uint32_tArrayList avaliableTextures;
|
||||
} gnPlatformPresentationQueue_t;
|
||||
|
||||
gnReturnCode createOpenGLPresentationQueue(gnPresentationQueueHandle presentationQueue, gnOutputDeviceHandle device, gnPresentationQueueInfo presentationInfo);
|
||||
gnReturnCode getOpenGLPresentationQueueImage(gnPresentationQueue presentationQueue, uint32_t* imageIndex);
|
||||
void destroyOpenGLPresentationQueue(gnPresentationQueueHandle presentationQueue);
|
@@ -1,4 +1,5 @@
|
||||
#include <glad/glad.h>
|
||||
#include "GL/glext.h"
|
||||
#include "opengl_surface.h"
|
||||
|
||||
#ifdef GN_PLATFORM_LINUX
|
||||
@@ -65,3 +66,28 @@ gnSurfaceDetails genOpenGLSurfaceDetails(
|
||||
void destroyOpenGLSurface(gnWindowSurface surface) {
|
||||
free(surface->windowSurface);
|
||||
}
|
||||
|
||||
GLint glGryphnFormatToOpenGLFormat(gnImageFormat format) {
|
||||
switch (format) {
|
||||
case GN_FORMAT_NONE: return GL_NONE;
|
||||
case GN_FORMAT_BGRA8: return GL_BGRA;
|
||||
case GN_FORMAT_RGBA8_SRGB: return GL_SRGB_ALPHA;
|
||||
case GN_FORMAT_D32S8_UINT: return GL_DEPTH_STENCIL;
|
||||
case GN_FORMAT_D24S8_UINT: return GL_DEPTH_STENCIL;
|
||||
|
||||
// unsupprted formats
|
||||
case GN_FORMAT_BGRA8_SRGB: return GL_NONE;
|
||||
}
|
||||
}
|
||||
GLint glGryphnFormatToOpenGLInternalFormat(gnImageFormat format) {
|
||||
switch (format) {
|
||||
case GN_FORMAT_NONE: return GL_NONE;
|
||||
case GN_FORMAT_BGRA8: return GL_BGRA8_EXT;
|
||||
case GN_FORMAT_RGBA8_SRGB: return GL_SRGB8_ALPHA8;
|
||||
case GN_FORMAT_D32S8_UINT: return GL_DEPTH32F_STENCIL8;
|
||||
case GN_FORMAT_D24S8_UINT: return GL_DEPTH24_STENCIL8;
|
||||
|
||||
// unsupprted formats
|
||||
case GN_FORMAT_BGRA8_SRGB: return GL_NONE;
|
||||
}
|
||||
}
|
||||
|
@@ -17,3 +17,6 @@ gnReturnCode createGLXContext(gnWindowSurfaceHandle windowSurface, gnInstanceHan
|
||||
gnUInt2 getWindowSize(gnPlatformWindowSurface* surface);
|
||||
gnSurfaceDetails genOpenGLSurfaceDetails(gnWindowSurfaceHandle windowSurface, gnPhysicalDevice device);
|
||||
void destroyOpenGLSurface(gnWindowSurface surface);
|
||||
|
||||
GLint glGryphnFormatToOpenGLFormat(gnImageFormat format);
|
||||
GLint glGryphnFormatToOpenGLInternalFormat(gnImageFormat format);
|
||||
|
7
projects/apis/opengl/src/textures/opengl_texture.h
Normal file
7
projects/apis/opengl/src/textures/opengl_texture.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
#include <glad/glad.h>
|
||||
#include "textures/gryphn_texture.h"
|
||||
|
||||
typedef struct gnPlatformTexture_t {
|
||||
GLuint id;
|
||||
} gnPlatformTexture;
|
Reference in New Issue
Block a user