create framebuffer object
This commit is contained in:
@@ -11,6 +11,7 @@
|
|||||||
#include "framebuffer/opengl_framebuffer.h"
|
#include "framebuffer/opengl_framebuffer.h"
|
||||||
#include "graphics_pipeline/opengl_graphics_pipeline.h"
|
#include "graphics_pipeline/opengl_graphics_pipeline.h"
|
||||||
#include "submit/opengl_submit.h"
|
#include "submit/opengl_submit.h"
|
||||||
|
#include "present/opengl_present.h"
|
||||||
|
|
||||||
gnDeviceFunctions loadOpenGLDeviceFunctions() {
|
gnDeviceFunctions loadOpenGLDeviceFunctions() {
|
||||||
return (gnDeviceFunctions){
|
return (gnDeviceFunctions){
|
||||||
@@ -53,7 +54,7 @@ gnDeviceFunctions loadOpenGLDeviceFunctions() {
|
|||||||
._gnDestroyTexture = openglDestroyTexture,
|
._gnDestroyTexture = openglDestroyTexture,
|
||||||
|
|
||||||
._gnSubmit = openglSubmit,
|
._gnSubmit = openglSubmit,
|
||||||
._gnPresent = NULL,
|
._gnPresent = openglPresent,
|
||||||
|
|
||||||
._gnWaitForDevice = waitForOpenGLDevice
|
._gnWaitForDevice = waitForOpenGLDevice
|
||||||
};
|
};
|
||||||
|
22
projects/apis/opengl/src/device/glsl_shader.glsl
Normal file
22
projects/apis/opengl/src/device/glsl_shader.glsl
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
const char * vertex_shader_source =
|
||||||
|
"#version 450 core"
|
||||||
|
""
|
||||||
|
"layout(location = 0) in vec2 inPosition;"
|
||||||
|
"layout(location = 1) in vec2 inTexcoord;"
|
||||||
|
""
|
||||||
|
"out vec2 texcoord;"
|
||||||
|
""
|
||||||
|
"void main() {"
|
||||||
|
" gl_Position = vec4(inPosition, 0.0, 1.0);"
|
||||||
|
" texcoord = inTexcoord;"
|
||||||
|
"}" ;
|
||||||
|
const char * fragment_shader_source =
|
||||||
|
"#version 450 core"
|
||||||
|
""
|
||||||
|
"out vec4 FragColor;"
|
||||||
|
"layout(binding = 0) uniform sampler2D tex;"
|
||||||
|
"in vec2 texcoord;"
|
||||||
|
""
|
||||||
|
"void main() {"
|
||||||
|
" FragColor = texture(tex, texcoord);"
|
||||||
|
"}" ;
|
@@ -1,5 +1,43 @@
|
|||||||
|
#include "glad/glad.h"
|
||||||
#include "opengl_output_device.h"
|
#include "opengl_output_device.h"
|
||||||
|
#include "glsl_shader.glsl"
|
||||||
|
#include "stdlib.h"
|
||||||
|
|
||||||
gnReturnCode createOpenGLOutputDevice(gnInstanceHandle instance, gnOutputDeviceHandle device, gnOutputDeviceInfo deviceInfo) { return GN_SUCCESS; }
|
gnReturnCode createOpenGLOutputDevice(gnInstanceHandle instance, gnOutputDeviceHandle device, gnOutputDeviceInfo deviceInfo) {
|
||||||
|
device->outputDevice = malloc(sizeof(gnPlatformOutputDevice));
|
||||||
|
float vertices[] = {
|
||||||
|
-1.0f, -1.0f, 0.0f, 1.0f,
|
||||||
|
1.0f, -1.0f, 1.0f, 1.0f,
|
||||||
|
-1.0f, 1.0f, 0.0f, 0.0f,
|
||||||
|
1.0f, 1.0f, 1.0f, 0.0f,
|
||||||
|
};
|
||||||
|
glCreateBuffers(1, &device->outputDevice->buffer);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, device->outputDevice->buffer);
|
||||||
|
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
|
||||||
|
|
||||||
|
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 2, (void*)0);
|
||||||
|
glEnableVertexAttribArray(0);
|
||||||
|
|
||||||
|
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 2, (void*)(sizeof(float) * 2));
|
||||||
|
glEnableVertexAttribArray(1);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
|
|
||||||
|
unsigned int vertexShader;
|
||||||
|
vertexShader = glCreateShader(GL_VERTEX_SHADER);
|
||||||
|
glShaderSource(vertexShader, 1, &vertex_shader_source, NULL);
|
||||||
|
glCompileShader(vertexShader);
|
||||||
|
|
||||||
|
unsigned int fragmentShader;
|
||||||
|
fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
|
||||||
|
glShaderSource(fragmentShader, 1, &fragment_shader_source, NULL);
|
||||||
|
glCompileShader(fragmentShader);
|
||||||
|
|
||||||
|
device->outputDevice->shaderProgram = glCreateProgram();
|
||||||
|
glAttachShader(device->outputDevice->shaderProgram, vertexShader);
|
||||||
|
glAttachShader(device->outputDevice->shaderProgram, fragmentShader);
|
||||||
|
glLinkProgram(device->outputDevice->shaderProgram);
|
||||||
|
|
||||||
|
return GN_SUCCESS;
|
||||||
|
}
|
||||||
void waitForOpenGLDevice(const gnOutputDeviceHandle device) {}
|
void waitForOpenGLDevice(const gnOutputDeviceHandle device) {}
|
||||||
void destroyOpenGLOutputDevice(gnOutputDeviceHandle device) {}
|
void destroyOpenGLOutputDevice(gnOutputDeviceHandle device) {}
|
||||||
|
@@ -1,7 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <output_device/gryphn_output_device.h>
|
#include <output_device/gryphn_output_device.h>
|
||||||
|
|
||||||
typedef struct gnPlatformOutputDevice_t {} gnPlatformOutputDevice;
|
typedef struct gnPlatformOutputDevice_t {
|
||||||
|
unsigned int buffer, shaderProgram;
|
||||||
|
} gnPlatformOutputDevice;
|
||||||
|
|
||||||
gnReturnCode createOpenGLOutputDevice(gnInstanceHandle instance, gnOutputDeviceHandle device, gnOutputDeviceInfo deviceInfo);
|
gnReturnCode createOpenGLOutputDevice(gnInstanceHandle instance, gnOutputDeviceHandle device, gnOutputDeviceInfo deviceInfo);
|
||||||
void waitForOpenGLDevice(const gnOutputDeviceHandle device);
|
void waitForOpenGLDevice(const gnOutputDeviceHandle device);
|
||||||
|
Reference in New Issue
Block a user