Skip to content

Commit

Permalink
[OpenGL] Add OpenGLPlatformInfo.SetSwapchainFramebuffer
Browse files Browse the repository at this point in the history
This is used when a non-zero FBO represents the main swapchain framebuffer.
  • Loading branch information
mellinoe committed Apr 6, 2018
1 parent 952a8e0 commit aaf1cd2
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 5 deletions.
19 changes: 15 additions & 4 deletions src/Veldrid/OpenGL/OpenGLCommandExecutor.cs
Expand Up @@ -10,7 +10,8 @@ internal unsafe class OpenGLCommandExecutor
private readonly GraphicsBackend _backend;
private readonly OpenGLTextureSamplerManager _textureSamplerManager;
private readonly StagingMemoryPool _stagingMemoryPool;
private OpenGLExtensions _extensions;
private readonly OpenGLExtensions _extensions;
private Action _setSwapchainFramebuffer;

private Framebuffer _fb;
private bool _isSwapchainFB;
Expand All @@ -34,12 +35,14 @@ internal unsafe class OpenGLCommandExecutor
GraphicsBackend backend,
OpenGLTextureSamplerManager textureSamplerManager,
OpenGLExtensions extensions,
StagingMemoryPool stagingMemoryPool)
StagingMemoryPool stagingMemoryPool,
Action setSwapchainFramebuffer)
{
_backend = backend;
_extensions = extensions;
_textureSamplerManager = textureSamplerManager;
_stagingMemoryPool = stagingMemoryPool;
_setSwapchainFramebuffer = setSwapchainFramebuffer;
}

public void Begin()
Expand Down Expand Up @@ -314,8 +317,16 @@ public void SetFramebuffer(Framebuffer fb)
}
else if (fb is OpenGLSwapchainFramebuffer)
{
glBindFramebuffer(FramebufferTarget.Framebuffer, 0);
CheckLastError();
if (_setSwapchainFramebuffer != null)
{
_setSwapchainFramebuffer();
}
else
{
glBindFramebuffer(FramebufferTarget.Framebuffer, 0);
CheckLastError();
}

_isSwapchainFB = true;
}
else
Expand Down
7 changes: 6 additions & 1 deletion src/Veldrid/OpenGL/OpenGLGraphicsDevice.cs
Expand Up @@ -163,7 +163,12 @@ public override bool SyncToVerticalBlank
}

_textureSamplerManager = new OpenGLTextureSamplerManager(_extensions);
_commandExecutor = new OpenGLCommandExecutor(_backendType, _textureSamplerManager, _extensions, _stagingMemoryPool);
_commandExecutor = new OpenGLCommandExecutor(
_backendType,
_textureSamplerManager,
_extensions,
_stagingMemoryPool,
platformInfo.SetSwapchainFramebuffer);

int maxColorTextureSamples;
glGetIntegerv(GetPName.MaxColorTextureSamples, &maxColorTextureSamples);
Expand Down
43 changes: 43 additions & 0 deletions src/Veldrid/OpenGL/OpenGLPlatformInfo.cs
Expand Up @@ -40,6 +40,11 @@ public class OpenGLPlatformInfo
/// A delegate which can be used to set the synchronization behavior of the OpenGL context.
/// </summary>
public Action<bool> SetSyncToVerticalBlank { get; }
/// <summary>
/// A delegate which can be used to set the framebuffer used to render to the application Swapchain.
/// If this is null, the default FBO (0) will be bound.
/// </summary>
public Action SetSwapchainFramebuffer { get; }

/// <summary>
/// Constructs a new OpenGLPlatformInfo.
Expand Down Expand Up @@ -74,5 +79,43 @@ public class OpenGLPlatformInfo
SwapBuffers = swapBuffers;
SetSyncToVerticalBlank = setSyncToVerticalBlank;
}

/// <summary>
/// Constructs a new OpenGLPlatformInfo.
/// </summary>
/// <param name="openGLContextHandle">The OpenGL context handle.</param>
/// <param name="getProcAddress">A delegate which can be used to retrieve OpenGL function pointers by name.</param>
/// <param name="makeCurrent">A delegate which can be used to make the given OpenGL context current on the calling
/// thread.</param>
/// <param name="getCurrentContext">A delegate which can be used to retrieve the calling thread's active OpenGL context.</param>
/// <param name="clearCurrentContext">A delegate which can be used to clear the calling thread's GL context.</param>
/// <param name="deleteContext">A delegate which can be used to delete the given context.</param>
/// <param name="swapBuffers">A delegate which can be used to swap the main back buffer associated with the OpenGL
/// context.</param>
/// <param name="setSyncToVerticalBlank">A delegate which can be used to set the synchronization behavior of the OpenGL
/// context.</param>
/// <param name="setSwapchainFramebuffer">A delegate which can be used to set the framebuffer used to render to the
/// application Swapchain.</param>
public OpenGLPlatformInfo(
IntPtr openGLContextHandle,
Func<string, IntPtr> getProcAddress,
Action<IntPtr> makeCurrent,
Func<IntPtr> getCurrentContext,
Action clearCurrentContext,
Action<IntPtr> deleteContext,
Action swapBuffers,
Action<bool> setSyncToVerticalBlank,
Action setSwapchainFramebuffer)
{
OpenGLContextHandle = openGLContextHandle;
GetProcAddress = getProcAddress;
MakeCurrent = makeCurrent;
GetCurrentContext = getCurrentContext;
ClearCurrentContext = clearCurrentContext;
DeleteContext = deleteContext;
SwapBuffers = swapBuffers;
SetSyncToVerticalBlank = setSyncToVerticalBlank;
SetSwapchainFramebuffer = setSwapchainFramebuffer;
}
}
}

0 comments on commit aaf1cd2

Please sign in to comment.