GPU: support default framebuffer with ID not equal to 0
This commit is contained in:
parent
2a5dc454f6
commit
62fe7e9a9d
@ -721,6 +721,11 @@ extern GHOST_TSuccess GHOST_ActivateOpenGLContext(GHOST_ContextHandle contexthan
|
||||
*/
|
||||
extern GHOST_TSuccess GHOST_ReleaseOpenGLContext(GHOST_ContextHandle contexthandle);
|
||||
|
||||
/**
|
||||
* Get the OpenGL framebuffer handle that serves as a default framebuffer.
|
||||
*/
|
||||
extern unsigned int GHOST_GetDefaultOpenGLFramebuffer(GHOST_WindowHandle windwHandle);
|
||||
|
||||
/**
|
||||
* Set which tablet API to use. Only affects Windows, other platforms have a single API.
|
||||
* \param systemhandle The handle to the system
|
||||
|
@ -217,6 +217,12 @@ class GHOST_IWindow {
|
||||
*/
|
||||
virtual GHOST_TSuccess activateDrawingContext() = 0;
|
||||
|
||||
/**
|
||||
* Gets the OpenGL framebuffer associated with the window's contents.
|
||||
* \return The name of an OpenGL framebuffer object.
|
||||
*/
|
||||
virtual unsigned int getDefaultFramebuffer() = 0;
|
||||
|
||||
/**
|
||||
* Invalidates the contents of this window.
|
||||
* \return Indication of success.
|
||||
|
@ -633,6 +633,13 @@ GHOST_TSuccess GHOST_ReleaseOpenGLContext(GHOST_ContextHandle contexthandle)
|
||||
return context->releaseDrawingContext();
|
||||
}
|
||||
|
||||
unsigned int GHOST_GetDefaultOpenGLFramebuffer(GHOST_WindowHandle windowhandle)
|
||||
{
|
||||
GHOST_IWindow *window = (GHOST_IWindow *)windowhandle;
|
||||
|
||||
return window->getDefaultFramebuffer();
|
||||
}
|
||||
|
||||
GHOST_TSuccess GHOST_InvalidateWindow(GHOST_WindowHandle windowhandle)
|
||||
{
|
||||
GHOST_IWindow *window = (GHOST_IWindow *)windowhandle;
|
||||
|
@ -119,6 +119,15 @@ class GHOST_Context : public GHOST_IContext {
|
||||
return m_stereoVisual;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the OpenGL framebuffer associated with the OpenGL context
|
||||
* \return The ID of an OpenGL framebuffer object.
|
||||
*/
|
||||
virtual unsigned int getDefaultFramebuffer()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected:
|
||||
void initContextGLEW();
|
||||
|
||||
|
@ -109,6 +109,11 @@ GHOST_TSuccess GHOST_Window::getSwapInterval(int &intervalOut)
|
||||
return m_context->getSwapInterval(intervalOut);
|
||||
}
|
||||
|
||||
unsigned int GHOST_Window::getDefaultFramebuffer()
|
||||
{
|
||||
return (m_context) ? m_context->getDefaultFramebuffer() : 0;
|
||||
}
|
||||
|
||||
GHOST_TSuccess GHOST_Window::activateDrawingContext()
|
||||
{
|
||||
return m_context->activateDrawingContext();
|
||||
|
@ -261,6 +261,12 @@ class GHOST_Window : public GHOST_IWindow {
|
||||
*/
|
||||
GHOST_TSuccess updateDrawingContext();
|
||||
|
||||
/**
|
||||
* Gets the OpenGL framebuffer associated with the window's contents.
|
||||
* \return The ID of an OpenGL framebuffer object.
|
||||
*/
|
||||
virtual unsigned int getDefaultFramebuffer();
|
||||
|
||||
/**
|
||||
* Returns the window user data.
|
||||
* \return The window user data.
|
||||
|
@ -409,7 +409,7 @@ static void eevee_lightbake_context_enable(EEVEE_LightBake *lbake)
|
||||
if (lbake->gl_context) {
|
||||
DRW_opengl_render_context_enable(lbake->gl_context);
|
||||
if (lbake->gpu_context == NULL) {
|
||||
lbake->gpu_context = GPU_context_create();
|
||||
lbake->gpu_context = GPU_context_create(0);
|
||||
}
|
||||
DRW_gawain_render_context_enable(lbake->gpu_context);
|
||||
}
|
||||
|
@ -3158,7 +3158,7 @@ void DRW_opengl_context_create(void)
|
||||
DST.gl_context = WM_opengl_context_create();
|
||||
WM_opengl_context_activate(DST.gl_context);
|
||||
/* Be sure to create gawain.context too. */
|
||||
DST.gpu_context = GPU_context_create();
|
||||
DST.gpu_context = GPU_context_create(0);
|
||||
if (!G.background) {
|
||||
immActivate();
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ extern "C" {
|
||||
|
||||
typedef struct GPUContext GPUContext;
|
||||
|
||||
GPUContext *GPU_context_create(void);
|
||||
GPUContext *GPU_context_create(GLuint default_framebuffer);
|
||||
void GPU_context_discard(GPUContext *);
|
||||
|
||||
void GPU_context_active_set(GPUContext *);
|
||||
|
@ -64,6 +64,7 @@ static std::mutex orphans_mutex;
|
||||
|
||||
struct GPUContext {
|
||||
GLuint default_vao;
|
||||
GLuint default_framebuffer;
|
||||
GPUFrameBuffer *current_fbo;
|
||||
std::unordered_set<GPUBatch *> batches; /* Batches that have VAOs from this context */
|
||||
#ifdef DEBUG
|
||||
@ -137,11 +138,12 @@ static void orphans_clear(GPUContext *ctx)
|
||||
orphans_mutex.unlock();
|
||||
}
|
||||
|
||||
GPUContext *GPU_context_create(void)
|
||||
GPUContext *GPU_context_create(GLuint default_framebuffer)
|
||||
{
|
||||
/* BLI_assert(thread_is_main()); */
|
||||
GPUContext *ctx = new GPUContext;
|
||||
glGenVertexArrays(1, &ctx->default_vao);
|
||||
ctx->default_framebuffer = default_framebuffer;
|
||||
GPU_context_active_set(ctx);
|
||||
return ctx;
|
||||
}
|
||||
@ -201,6 +203,14 @@ GLuint GPU_vao_default(void)
|
||||
return active_ctx->default_vao;
|
||||
}
|
||||
|
||||
GLuint GPU_framebuffer_default(void)
|
||||
{
|
||||
BLI_assert(active_ctx); /* need at least an active context */
|
||||
BLI_assert(pthread_equal(
|
||||
pthread_self(), active_ctx->thread)); /* context has been activated by another thread! */
|
||||
return active_ctx->default_framebuffer;
|
||||
}
|
||||
|
||||
GLuint GPU_vao_alloc(void)
|
||||
{
|
||||
GLuint new_vao_id = 0;
|
||||
|
@ -35,6 +35,7 @@ extern "C" {
|
||||
struct GPUFrameBuffer;
|
||||
|
||||
GLuint GPU_vao_default(void);
|
||||
GLuint GPU_framebuffer_default(void);
|
||||
|
||||
/* These require a gl ctx bound. */
|
||||
GLuint GPU_buf_alloc(void);
|
||||
|
@ -244,15 +244,6 @@ void gpu_extensions_init(void)
|
||||
|
||||
glGetFloatv(GL_ALIASED_LINE_WIDTH_RANGE, GG.line_width_range);
|
||||
|
||||
#ifndef NDEBUG
|
||||
GLint ret;
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
glGetFramebufferAttachmentParameteriv(
|
||||
GL_FRAMEBUFFER, GL_FRONT_LEFT, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &ret);
|
||||
/* We expect FRONT_LEFT to be the default buffer. */
|
||||
BLI_assert(ret == GL_FRAMEBUFFER_DEFAULT);
|
||||
#endif
|
||||
|
||||
glGetIntegerv(GL_MAX_COLOR_TEXTURE_SAMPLES, &GG.samples_color_texture_max);
|
||||
|
||||
const char *vendor = (const char *)glGetString(GL_VENDOR);
|
||||
|
@ -539,7 +539,7 @@ void GPU_framebuffer_bind(GPUFrameBuffer *fb)
|
||||
void GPU_framebuffer_restore(void)
|
||||
{
|
||||
if (GPU_framebuffer_active_get() != NULL) {
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, GPU_framebuffer_default());
|
||||
gpu_framebuffer_current_set(NULL);
|
||||
}
|
||||
}
|
||||
@ -718,7 +718,7 @@ void GPU_framebuffer_blit(GPUFrameBuffer *fb_read,
|
||||
gpu_framebuffer_current_set(prev_fb);
|
||||
}
|
||||
else {
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, GPU_framebuffer_default());
|
||||
gpu_framebuffer_current_set(NULL);
|
||||
}
|
||||
}
|
||||
@ -909,7 +909,7 @@ void GPU_offscreen_draw_to_screen(GPUOffScreen *ofs, int x, int y)
|
||||
gpu_print_framebuffer_error(status, NULL);
|
||||
}
|
||||
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, GPU_framebuffer_default());
|
||||
}
|
||||
|
||||
void GPU_offscreen_read_pixels(GPUOffScreen *ofs, int type, void *pixels)
|
||||
|
@ -1116,7 +1116,7 @@ void *RE_gl_context_get(Render *re)
|
||||
void *RE_gpu_context_get(Render *re)
|
||||
{
|
||||
if (re->gpu_context == NULL) {
|
||||
re->gpu_context = GPU_context_create();
|
||||
re->gpu_context = GPU_context_create(0);
|
||||
}
|
||||
return re->gpu_context;
|
||||
}
|
||||
|
@ -1287,7 +1287,8 @@ static char *wm_main_playanim_intern(int argc, const char **argv)
|
||||
// GHOST_ActivateWindowDrawingContext(g_WS.ghost_window);
|
||||
|
||||
/* initialize OpenGL immediate mode */
|
||||
g_WS.gpu_context = GPU_context_create();
|
||||
GLuint default_fb = GHOST_GetDefaultOpenGLFramebuffer(g_WS.ghost_window);
|
||||
g_WS.gpu_context = GPU_context_create(default_fb);
|
||||
GPU_init();
|
||||
immActivate();
|
||||
|
||||
|
@ -581,7 +581,8 @@ static void wm_window_ghostwindow_add(wmWindowManager *wm, const char *title, wm
|
||||
if (ghostwin) {
|
||||
GHOST_RectangleHandle bounds;
|
||||
|
||||
win->gpuctx = GPU_context_create();
|
||||
GLuint default_fb = GHOST_GetDefaultOpenGLFramebuffer(ghostwin);
|
||||
win->gpuctx = GPU_context_create(default_fb);
|
||||
|
||||
/* needed so we can detect the graphics card below */
|
||||
GPU_init();
|
||||
|
Loading…
Reference in New Issue
Block a user