[wip] win32 gles surface using angle

This commit is contained in:
martinfouilleul 2023-01-29 01:04:24 +01:00
parent bd7e1a15f1
commit c5ae556f22
12 changed files with 758 additions and 572 deletions

View File

@ -1,6 +1,6 @@
if not exist bin mkdir bin
set INCLUDES=/I src /I src/util /I src/platform /I ext
set INCLUDES=/I src /I src/util /I src/platform /I ext /I ext/angle_headers
cl /we4013 /Zi /Zc:preprocessor /std:c11 %INCLUDES% /c /Fo:bin/milepost.obj src/milepost.c
lib bin/milepost.obj /OUT:bin/milepost.lib

View File

@ -13,6 +13,7 @@
#include<math.h>
#include"milepost.h"
#include"win32_gl_surface.h"
#define LOG_SUBSYSTEM "Main"
@ -67,7 +68,7 @@ int main()
mp_window window = mp_window_create(rect, "test", 0);
//NOTE: create surface
mg_surface surface = mg_surface_create_for_window(window, MG_BACKEND_GL);
mg_surface surface = mg_gl_surface_create_for_window(window);
//NOTE: init shader and gl state
GLuint vao;

View File

@ -1,2 +1,2 @@
set INCLUDES=/I ..\..\src /I ..\..\src\util /I ..\..\src\platform /I ../../ext
cl /we4013 /Zi /Zc:preprocessor /std:c11 %INCLUDES% main.c /link /LIBPATH:../../bin milepost.lib user32.lib opengl32.lib gdi32.lib /out:test.exe
set INCLUDES=/I ..\..\src /I ..\..\src\util /I ..\..\src\platform /I ../../ext /I ../../ext/angle_headers
cl /we4013 /Zi /Zc:preprocessor /std:c11 %INCLUDES% main.c /link /LIBPATH:../../bin milepost.lib /LIBPATH:./ libEGL.dll.lib libGLESv2.dll.lib user32.lib opengl32.lib gdi32.lib /out:test.exe

View File

@ -0,0 +1,31 @@
angle install on windows
* need Python3 (can install through win app store)
* need Windows SDK
* clone depot_tools git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
or download and unzip bundle at https://storage.googleapis.com/chrome-infra/depot_tools.zip
* set depot_tools in path env variable through control panel>System and security>system>advanced system settings
* run gclient in a cmd shell
* set DEPOT_TOOLS_WIN_TOOLCHAIN=0
* mkdir angle
* cd angle
* fetch angle
* wait a million years
* fails when running python3 third_party/depot_tools/download_from_google_storage.py ...
-> open DEPS and change third_party/depot_tools with ../depot/tools
* run gclient sync to complete previous step
* gn gen out/Debug
* gn args out/Debug and edit arguments:
angle_enable_vulkan = false
angle_build_tests = false
is_component_build = false
* autoninja -C out/Debug
* wait a while
* link with libEGL.dll.lib and libGLESv2.dll.lib
* put libEGL.dll and libGLESv2.dll in same directory as executable

Binary file not shown.

Binary file not shown.

View File

@ -52,7 +52,8 @@
#if defined(OS_WIN64)
#include"win32_app.c"
#include"win32_gl_surface.c"
// #include"win32_gl_surface.c"
#include"win32_gles_surface.c"
#elif defined(OS_MACOS)
//NOTE: macos application layer is defined in milepost.m
#else

View File

@ -39,7 +39,7 @@
#if defined(OS_WIN64) || defined(OS_WIN32)
#define WIN32_GL_LOADER_API
#include"win32_gl_loader.h"
// #include"win32_gl_loader.h"
#endif
//----------------------------------------------------------------

View File

@ -17,27 +17,27 @@
typedef struct mg_gl_surface
{
mg_surface_info interface;
mg_surface_data interface;
HDC hDC;
HGLRC glContext;
} mg_gl_surface;
void mg_gl_surface_destroy(mg_surface_info* interface)
void mg_gl_surface_destroy(mg_surface_data* interface)
{
mg_gl_surface* surface = (mg_gl_surface*)interface;
//TODO
}
void mg_gl_surface_prepare(mg_surface_info* interface)
void mg_gl_surface_prepare(mg_surface_data* interface)
{
mg_gl_surface* surface = (mg_gl_surface*)interface;
wglMakeCurrent(surface->hDC, surface->glContext);
}
void mg_gl_surface_present(mg_surface_info* interface)
void mg_gl_surface_present(mg_surface_data* interface)
{
mg_gl_surface* surface = (mg_gl_surface*)interface;
@ -212,7 +212,7 @@ mg_surface mg_gl_surface_create_for_window(mp_window window)
surface->hDC = hDC;
surface->glContext = glContext;
surfaceHandle = mg_surface_alloc_handle((mg_surface_info*)surface);
surfaceHandle = mg_surface_alloc_handle((mg_surface_data*)surface);
}
quit:;

14
src/win32_gl_surface.h Normal file
View File

@ -0,0 +1,14 @@
/************************************************************//**
*
* @file: win32_gl_surface.c
* @author: Martin Fouilleul
* @date: 28/01/2023
* @revision:
*
*****************************************************************/
#ifndef __WIN32_GL_SURFACE_H_
#define __WIN32_GL_SURFACE_H_
mg_surface mg_gl_surface_create_for_window(mp_window window);
#endif // __WIN32_GL_SURFACE_H_

125
src/win32_gles_surface.c Normal file
View File

@ -0,0 +1,125 @@
/************************************************************//**
*
* @file: osx_gles_surface.cpp
* @author: Martin Fouilleul
* @date: 18/08/2022
* @revision:
*
*****************************************************************/
#include<GLES3/gl32.h>
#define EGL_EGLEXT_PROTOTYPES
#include<EGL/egl.h>
#include<EGL/eglext.h>
#include"graphics_internal.h"
typedef struct mg_gles_surface
{
mg_surface_data interface;
HWND hWnd;
EGLDisplay eglDisplay;
EGLConfig eglConfig;
EGLContext eglContext;
EGLSurface eglSurface;
} mg_gles_surface;
void mg_gles_surface_destroy(mg_surface_data* interface)
{
//////////////////////////////////////////////////
//TODO
//////////////////////////////////////////////////
}
void mg_gles_surface_prepare(mg_surface_data* interface)
{
mg_gles_surface* surface = (mg_gles_surface*)interface;
eglMakeCurrent(surface->eglDisplay, surface->eglSurface, surface->eglSurface, surface->eglContext);
}
void mg_gles_surface_present(mg_surface_data* interface)
{
//TODO: eglSwapBuffers seem to never block in macOS (ie eglSwapInterval doesn't seem to have any effect)
// We need to use a CVDisplayLink to time this if we want surface present to block
mg_gles_surface* surface = (mg_gles_surface*)interface;
eglSwapBuffers(surface->eglDisplay, surface->eglSurface);
}
/*
void mg_gles_surface_set_frame(mg_surface_data* interface, mp_rect frame);
mp_rect mg_gles_surface_get_frame(mg_surface_data* interface);
void mg_gles_surface_set_hidden(mg_surface_data* interface, bool hidden);
bool mg_gles_surface_get_hidden(mg_surface_data* interface);
*/
mg_surface mg_gles_surface_create_for_window(mp_window window)
{
mg_surface res = mg_surface_nil();
mp_window_data* windowData = mp_window_ptr_from_handle(window);
if(windowData)
{
mg_gles_surface* surface = malloc_type(mg_gles_surface);
memset(surface, 0, sizeof(mg_gles_surface));
surface->interface.backend = MG_BACKEND_GLES;
surface->interface.destroy = mg_gles_surface_destroy;
surface->interface.prepare = mg_gles_surface_prepare;
surface->interface.present = mg_gles_surface_present;
/*TODO
surface->interface.getFrame = mg_gles_surface_get_frame;
surface->interface.setFrame = mg_gles_surface_set_frame;
surface->interface.getHidden = mg_gles_surface_get_hidden;
surface->interface.setHidden = mg_gles_surface_set_hidden;
*/
surface->hWnd = windowData->win32.hWnd;
EGLAttrib displayAttribs[] = {
EGL_PLATFORM_ANGLE_TYPE_ANGLE, EGL_PLATFORM_ANGLE_TYPE_DEFAULT_ANGLE,
EGL_PLATFORM_ANGLE_DEVICE_TYPE_ANGLE, EGL_PLATFORM_ANGLE_DEVICE_TYPE_HARDWARE_ANGLE,
EGL_NONE};
surface->eglDisplay = eglGetPlatformDisplay(EGL_PLATFORM_ANGLE_ANGLE, (void*)EGL_DEFAULT_DISPLAY, displayAttribs);
eglInitialize(surface->eglDisplay, NULL, NULL);
EGLint const configAttributes[] = {
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
EGL_RED_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_BLUE_SIZE, 8,
EGL_ALPHA_SIZE, 8,
EGL_DEPTH_SIZE, 24,
EGL_STENCIL_SIZE, 8,
EGL_SAMPLE_BUFFERS, 0,
EGL_SAMPLES, EGL_DONT_CARE,
EGL_COLOR_COMPONENT_TYPE_EXT, EGL_COLOR_COMPONENT_TYPE_FIXED_EXT,
EGL_NONE };
int numConfigs = 0;
eglChooseConfig(surface->eglDisplay, configAttributes, &surface->eglConfig, 1, &numConfigs);
EGLint const surfaceAttributes[] = {EGL_NONE};
surface->eglSurface = eglCreateWindowSurface(surface->eglDisplay, surface->eglConfig, surface->hWnd, surfaceAttributes);
eglBindAPI(EGL_OPENGL_ES_API);
EGLint contextAttributes[] = {
EGL_CONTEXT_MAJOR_VERSION_KHR, 3,
EGL_CONTEXT_MINOR_VERSION_KHR, 0, //NOTE: Angle can't create a GLES 3.1 context on macOS
EGL_CONTEXT_BIND_GENERATES_RESOURCE_CHROMIUM, EGL_TRUE,
EGL_CONTEXT_CLIENT_ARRAYS_ENABLED_ANGLE, EGL_TRUE,
EGL_CONTEXT_OPENGL_BACKWARDS_COMPATIBLE_ANGLE, EGL_FALSE,
EGL_NONE};
surface->eglContext = eglCreateContext(surface->eglDisplay, surface->eglConfig, EGL_NO_CONTEXT, contextAttributes);
eglMakeCurrent(surface->eglDisplay, surface->eglSurface, surface->eglSurface, surface->eglContext);
eglSwapInterval(surface->eglDisplay, 1);
res = mg_surface_alloc_handle((mg_surface_data*)surface);
}
return(res);
}

14
src/win32_gles_surface.h Normal file
View File

@ -0,0 +1,14 @@
/************************************************************//**
*
* @file: win32_gles_surface.h
* @author: Martin Fouilleul
* @date: 28/01/2023
* @revision:
*
*****************************************************************/
#ifndef __WIN32_GLES_SURFACE_H_
#define __WIN32_GLES_SURFACE_H_
mg_surface mg_gles_surface_create_for_window(mg_window window);
#endif // __WIN32_GLES_SURFACE_H_