mirror of https://github.com/encounter/aurora.git
Update dawn & use external OpenGL context hooks
This commit is contained in:
parent
99bb9e5f83
commit
d8e41e4bcc
|
@ -1 +1 @@
|
||||||
Subproject commit 64a23ce0ede5f232cc209b69d64164ede6810b65
|
Subproject commit db82c79db65e502dd226f5cb4e2c03d85f8ffd2d
|
|
@ -37,6 +37,22 @@ BackendBinding* CreateVulkanBinding(SDL_Window* window, WGPUDevice device);
|
||||||
|
|
||||||
BackendBinding::BackendBinding(SDL_Window* window, WGPUDevice device) : m_window(window), m_device(device) {}
|
BackendBinding::BackendBinding(SDL_Window* window, WGPUDevice device) : m_window(window), m_device(device) {}
|
||||||
|
|
||||||
|
#if defined(DAWN_ENABLE_BACKEND_OPENGL)
|
||||||
|
struct GLUserData {
|
||||||
|
SDL_Window* window;
|
||||||
|
SDL_GLContext context;
|
||||||
|
};
|
||||||
|
void GLMakeCurrent(void* userData) {
|
||||||
|
auto* data = static_cast<GLUserData*>(userData);
|
||||||
|
SDL_GL_MakeCurrent(data->window, data->context);
|
||||||
|
}
|
||||||
|
void GLDestroy(void* userData) {
|
||||||
|
auto* data = static_cast<GLUserData*>(userData);
|
||||||
|
SDL_GL_DeleteContext(data->context);
|
||||||
|
delete data;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
bool DiscoverAdapter(dawn::native::Instance* instance, SDL_Window* window, wgpu::BackendType type) {
|
bool DiscoverAdapter(dawn::native::Instance* instance, SDL_Window* window, wgpu::BackendType type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
#if defined(DAWN_ENABLE_BACKEND_D3D12)
|
#if defined(DAWN_ENABLE_BACKEND_D3D12)
|
||||||
|
@ -63,10 +79,15 @@ bool DiscoverAdapter(dawn::native::Instance* instance, SDL_Window* window, wgpu:
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4);
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4);
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 4);
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 4);
|
||||||
SDL_GL_CreateContext(window);
|
SDL_GLContext context = SDL_GL_CreateContext(window);
|
||||||
auto getProc = reinterpret_cast<void* (*)(const char*)>(SDL_GL_GetProcAddress);
|
dawn::native::opengl::AdapterDiscoveryOptions adapterOptions{WGPUBackendType_OpenGL};
|
||||||
dawn::native::opengl::AdapterDiscoveryOptions adapterOptions;
|
adapterOptions.getProc = SDL_GL_GetProcAddress;
|
||||||
adapterOptions.getProc = getProc;
|
adapterOptions.makeCurrent = GLMakeCurrent;
|
||||||
|
adapterOptions.destroy = GLDestroy;
|
||||||
|
adapterOptions.userData = new GLUserData{
|
||||||
|
.window = window,
|
||||||
|
.context = context,
|
||||||
|
};
|
||||||
return instance->DiscoverAdapters(&adapterOptions);
|
return instance->DiscoverAdapters(&adapterOptions);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -76,10 +97,15 @@ bool DiscoverAdapter(dawn::native::Instance* instance, SDL_Window* window, wgpu:
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
|
||||||
SDL_GL_CreateContext(window);
|
SDL_GLContext context = SDL_GL_CreateContext(window);
|
||||||
auto getProc = reinterpret_cast<void* (*)(const char*)>(SDL_GL_GetProcAddress);
|
dawn::native::opengl::AdapterDiscoveryOptions adapterOptions{WGPUBackendType_OpenGLES};
|
||||||
dawn::native::opengl::AdapterDiscoveryOptionsES adapterOptions;
|
adapterOptions.getProc = SDL_GL_GetProcAddress;
|
||||||
adapterOptions.getProc = getProc;
|
adapterOptions.makeCurrent = GLMakeCurrent;
|
||||||
|
adapterOptions.destroy = GLDestroy;
|
||||||
|
adapterOptions.userData = new GLUserData{
|
||||||
|
.window = window,
|
||||||
|
.context = context,
|
||||||
|
};
|
||||||
return instance->DiscoverAdapters(&adapterOptions);
|
return instance->DiscoverAdapters(&adapterOptions);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1311,14 +1311,14 @@ fn textureSamplePaletteI4(tex: texture_2d<f32>, samp: sampler, uv: vec2<f32>, tl
|
||||||
return mix(t0, t1, f.y);
|
return mix(t0, t1, f.y);
|
||||||
}}
|
}}
|
||||||
|
|
||||||
@stage(vertex)
|
@vertex
|
||||||
fn vs_main({5}
|
fn vs_main({5}
|
||||||
) -> VertexOutput {{
|
) -> VertexOutput {{
|
||||||
var out: VertexOutput;{9}{6}
|
var out: VertexOutput;{9}{6}
|
||||||
return out;
|
return out;
|
||||||
}}
|
}}
|
||||||
|
|
||||||
@stage(fragment)
|
@fragment
|
||||||
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {{{8}{7}
|
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {{{8}{7}
|
||||||
return prev;
|
return prev;
|
||||||
}}
|
}}
|
||||||
|
|
|
@ -170,7 +170,7 @@ var<private> uvs: array<vec2<f32>, 3> = array<vec2<f32>, 3>(
|
||||||
vec2(2.0, 0.0),
|
vec2(2.0, 0.0),
|
||||||
);
|
);
|
||||||
|
|
||||||
@stage(vertex)
|
@vertex
|
||||||
fn vs_main(@builtin(vertex_index) vtxIdx: u32) -> VertexOutput {
|
fn vs_main(@builtin(vertex_index) vtxIdx: u32) -> VertexOutput {
|
||||||
var out: VertexOutput;
|
var out: VertexOutput;
|
||||||
out.pos = vec4<f32>(pos[vtxIdx], 0.0, 1.0);
|
out.pos = vec4<f32>(pos[vtxIdx], 0.0, 1.0);
|
||||||
|
@ -178,7 +178,7 @@ fn vs_main(@builtin(vertex_index) vtxIdx: u32) -> VertexOutput {
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@stage(fragment)
|
@fragment
|
||||||
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
|
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
|
||||||
return textureSample(efb_texture, efb_sampler, in.uv);
|
return textureSample(efb_texture, efb_sampler, in.uv);
|
||||||
}
|
}
|
||||||
|
|
|
@ -157,6 +157,7 @@ bool create_window(AuroraBackend backend) {
|
||||||
#endif
|
#endif
|
||||||
g_window = SDL_CreateWindow(g_config.appName, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, flags);
|
g_window = SDL_CreateWindow(g_config.appName, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, flags);
|
||||||
if (g_window == nullptr) {
|
if (g_window == nullptr) {
|
||||||
|
Log.report(LOG_WARNING, FMT_STRING("Failed to create window: {}"), SDL_GetError());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
set_window_icon();
|
set_window_icon();
|
||||||
|
|
Loading…
Reference in New Issue