[graphics, win32] applying changes to surface backend API

This commit is contained in:
martinfouilleul 2023-03-01 17:41:39 +01:00
parent 43d413dbbc
commit 1dfc5dd684
3 changed files with 79 additions and 81 deletions

View File

@ -2,7 +2,7 @@
* *
* file: glsl_shaders.h * file: glsl_shaders.h
* note: string literals auto-generated by embed_text.py * note: string literals auto-generated by embed_text.py
* date: 27/022023 * date: 01/032023
* *
**********************************************************************/ **********************************************************************/
#ifndef __GLSL_SHADERS_H__ #ifndef __GLSL_SHADERS_H__

View File

@ -192,7 +192,7 @@ bool mg_wgl_surface_get_hidden(mg_surface_data* interface)
void* mg_wgl_surface_native_layer(mg_surface_data* interface) void* mg_wgl_surface_native_layer(mg_surface_data* interface)
{ {
mg_wgl_surface* surface = (mg_wgl_surface*)interface; mg_wgl_surface* surface = (mg_wgl_surface*)interface;
return(mg_layer_native_surface(&surface->layer)); return(mp_layer_native_surface(&surface->layer));
} }
void* mg_wgl_get_proc(const char* name) void* mg_wgl_get_proc(const char* name)
@ -211,9 +211,9 @@ void* mg_wgl_get_proc(const char* name)
return(p); return(p);
} }
mg_surface mg_wgl_surface_create_for_window(mp_window window) mg_surface_data* mg_wgl_surface_create_for_window(mp_window window)
{ {
mg_surface surfaceHandle = mg_surface_nil(); mg_surface* surface = 0;
mp_window_data* windowData = mp_window_ptr_from_handle(window); mp_window_data* windowData = mp_window_ptr_from_handle(window);
if(windowData) if(windowData)
@ -222,86 +222,84 @@ mg_surface mg_wgl_surface_create_for_window(mp_window window)
//NOTE: fill surface data and load api //NOTE: fill surface data and load api
mg_wgl_surface* surface = malloc_type(mg_wgl_surface); mg_wgl_surface* surface = malloc_type(mg_wgl_surface);
if(surface)
surface->interface.backend = MG_BACKEND_GL;
surface->interface.destroy = mg_wgl_surface_destroy;
surface->interface.prepare = mg_wgl_surface_prepare;
surface->interface.present = mg_wgl_surface_present;
surface->interface.swapInterval = mg_wgl_surface_swap_interval;
surface->interface.contentsScaling = mg_wgl_surface_contents_scaling;
surface->interface.getFrame = mg_wgl_surface_get_frame;
surface->interface.setFrame = mg_wgl_surface_set_frame;
surface->interface.getHidden = mg_wgl_surface_get_hidden;
surface->interface.setHidden = mg_wgl_surface_set_hidden;
mp_layer_init_for_window(&surface->layer, windowData);
surface->hDC = GetDC(surface->layer.hWnd);
//NOTE(martin): create the pixel format and gl context
PIXELFORMATDESCRIPTOR pixelFormatDesc =
{ {
sizeof(PIXELFORMATDESCRIPTOR), surface->interface.backend = MG_BACKEND_GL;
1, surface->interface.destroy = mg_wgl_surface_destroy;
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER, // Flags surface->interface.prepare = mg_wgl_surface_prepare;
PFD_TYPE_RGBA, // The kind of framebuffer. RGBA or palette. surface->interface.present = mg_wgl_surface_present;
32, // Colordepth of the framebuffer. surface->interface.swapInterval = mg_wgl_surface_swap_interval;
0, 0, 0, 0, 0, 0, surface->interface.contentsScaling = mg_wgl_surface_contents_scaling;
0, surface->interface.getFrame = mg_wgl_surface_get_frame;
0, surface->interface.setFrame = mg_wgl_surface_set_frame;
0, surface->interface.getHidden = mg_wgl_surface_get_hidden;
0, 0, 0, 0, surface->interface.setHidden = mg_wgl_surface_set_hidden;
24, // Number of bits for the depthbuffer
8, // Number of bits for the stencilbuffer
0, // Number of Aux buffers in the framebuffer.
PFD_MAIN_PLANE,
0,
0, 0, 0
};
int pixelFormatAttrs[] = { mp_layer_init_for_window(&surface->layer, windowData);
WGL_DRAW_TO_WINDOW_ARB, GL_TRUE, surface->hDC = GetDC(surface->layer.hWnd);
WGL_SUPPORT_OPENGL_ARB, GL_TRUE,
WGL_DOUBLE_BUFFER_ARB, GL_TRUE,
WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB,
WGL_COLOR_BITS_ARB, 32,
WGL_DEPTH_BITS_ARB, 24,
WGL_STENCIL_BITS_ARB, 8,
0};
u32 numFormats = 0; //NOTE(martin): create the pixel format and gl context
int pixelFormat = 0; PIXELFORMATDESCRIPTOR pixelFormatDesc =
{
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER, // Flags
PFD_TYPE_RGBA, // The kind of framebuffer. RGBA or palette.
32, // Colordepth of the framebuffer.
0, 0, 0, 0, 0, 0,
0,
0,
0,
0, 0, 0, 0,
24, // Number of bits for the depthbuffer
8, // Number of bits for the stencilbuffer
0, // Number of Aux buffers in the framebuffer.
PFD_MAIN_PLANE,
0,
0, 0, 0
};
wglChoosePixelFormatARB(surface->hDC, pixelFormatAttrs, 0, 1, &pixelFormat, &numFormats); int pixelFormatAttrs[] = {
WGL_DRAW_TO_WINDOW_ARB, GL_TRUE,
WGL_SUPPORT_OPENGL_ARB, GL_TRUE,
WGL_DOUBLE_BUFFER_ARB, GL_TRUE,
WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB,
WGL_COLOR_BITS_ARB, 32,
WGL_DEPTH_BITS_ARB, 24,
WGL_STENCIL_BITS_ARB, 8,
0};
if(!pixelFormat) u32 numFormats = 0;
{ int pixelFormat = 0;
//TODO: error
wglChoosePixelFormatARB(surface->hDC, pixelFormatAttrs, 0, 1, &pixelFormat, &numFormats);
if(!pixelFormat)
{
//TODO: error
}
SetPixelFormat(surface->hDC, pixelFormat, &pixelFormatDesc);
int contextAttrs[] = {
WGL_CONTEXT_MAJOR_VERSION_ARB, 4,
WGL_CONTEXT_MINOR_VERSION_ARB, 3,
WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
0};
surface->glContext = wglCreateContextAttribsARB(surface->hDC, __mgWGLDummyContext.glContext, contextAttrs);
if(!surface->glContext)
{
//TODO error
int error = GetLastError();
printf("error: %i\n", error);
}
//NOTE: make gl context current and load api
wglMakeCurrent(surface->hDC, surface->glContext);
wglSwapIntervalEXT(1);
mg_gl_load_gl43(&surface->api, mg_wgl_get_proc);
} }
SetPixelFormat(surface->hDC, pixelFormat, &pixelFormatDesc);
int contextAttrs[] = {
WGL_CONTEXT_MAJOR_VERSION_ARB, 4,
WGL_CONTEXT_MINOR_VERSION_ARB, 3,
WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
0};
surface->glContext = wglCreateContextAttribsARB(surface->hDC, __mgWGLDummyContext.glContext, contextAttrs);
if(!surface->glContext)
{
//TODO error
int error = GetLastError();
printf("error: %i\n", error);
}
//NOTE: make gl context current and load api
wglMakeCurrent(surface->hDC, surface->glContext);
wglSwapIntervalEXT(1);
mg_gl_load_gl43(&surface->api, mg_wgl_get_proc);
surfaceHandle = mg_surface_alloc_handle((mg_surface_data*)surface);
} }
return((mg_surface_data*)surface);
quit:;
return(surfaceHandle);
} }

View File

@ -9,8 +9,8 @@
#ifndef __WGL_SURFACE_H_ #ifndef __WGL_SURFACE_H_
#define __WGL_SURFACE_H_ #define __WGL_SURFACE_H_
#include"graphics.h" #include"graphics_internal.h"
mg_surface mg_wgl_surface_create_for_window(mp_window window); mg_surface_data* mg_wgl_surface_create_for_window(mp_window window);
#endif // __WIN32_GL_SURFACE_H_ #endif // __WIN32_GL_SURFACE_H_