Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/gpu/opengl/gl_context.cc')
-rw-r--r--source/blender/gpu/opengl/gl_context.cc116
1 files changed, 78 insertions, 38 deletions
diff --git a/source/blender/gpu/opengl/gl_context.cc b/source/blender/gpu/opengl/gl_context.cc
index 37c84abaa7f..1495e665aa8 100644
--- a/source/blender/gpu/opengl/gl_context.cc
+++ b/source/blender/gpu/opengl/gl_context.cc
@@ -22,14 +22,22 @@
*/
#include "BLI_assert.h"
+#include "BLI_system.h"
#include "BLI_utildefines.h"
+#include "BKE_global.h"
+
#include "GPU_framebuffer.h"
#include "GHOST_C-api.h"
#include "gpu_context_private.hh"
+#include "gl_debug.hh"
+#include "gl_immediate.hh"
+#include "gl_state.hh"
+#include "gl_uniform_buffer.hh"
+
#include "gl_backend.hh" /* TODO remove */
#include "gl_context.hh"
@@ -43,17 +51,50 @@ using namespace blender::gpu;
GLContext::GLContext(void *ghost_window, GLSharedOrphanLists &shared_orphan_list)
: shared_orphan_list_(shared_orphan_list)
{
- default_framebuffer_ = ghost_window ?
- GHOST_GetDefaultOpenGLFramebuffer((GHOST_WindowHandle)ghost_window) :
- 0;
-
- glGenVertexArrays(1, &default_vao_);
+ if (G.debug & G_DEBUG_GPU) {
+ debug::init_gl_callbacks();
+ }
float data[4] = {0.0f, 0.0f, 0.0f, 1.0f};
glGenBuffers(1, &default_attr_vbo_);
glBindBuffer(GL_ARRAY_BUFFER, default_attr_vbo_);
glBufferData(GL_ARRAY_BUFFER, sizeof(data), data, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
+
+ state_manager = new GLStateManager();
+ imm = new GLImmediate();
+ ghost_window_ = ghost_window;
+
+ if (ghost_window) {
+ GLuint default_fbo = GHOST_GetDefaultOpenGLFramebuffer((GHOST_WindowHandle)ghost_window);
+ GHOST_RectangleHandle bounds = GHOST_GetClientBounds((GHOST_WindowHandle)ghost_window);
+ int w = GHOST_GetWidthRectangle(bounds);
+ int h = GHOST_GetHeightRectangle(bounds);
+ GHOST_DisposeRectangle(bounds);
+
+ if (default_fbo != 0) {
+ front_left = new GLFrameBuffer("front_left", this, GL_COLOR_ATTACHMENT0, default_fbo, w, h);
+ back_left = new GLFrameBuffer("back_left", this, GL_COLOR_ATTACHMENT0, default_fbo, w, h);
+ }
+ else {
+ front_left = new GLFrameBuffer("front_left", this, GL_FRONT_LEFT, 0, w, h);
+ back_left = new GLFrameBuffer("back_left", this, GL_BACK_LEFT, 0, w, h);
+ }
+ /* TODO(fclem) enable is supported. */
+ const bool supports_stereo_quad_buffer = false;
+ if (supports_stereo_quad_buffer) {
+ front_right = new GLFrameBuffer("front_right", this, GL_FRONT_RIGHT, 0, w, h);
+ back_right = new GLFrameBuffer("back_right", this, GL_BACK_RIGHT, 0, w, h);
+ }
+ }
+ else {
+ /* For offscreen contexts. Default framebuffer is NULL. */
+ back_left = new GLFrameBuffer("back_left", this, GL_NONE, 0, 0, 0);
+ }
+
+ active_fb = back_left;
+ static_cast<GLStateManager *>(state_manager)->active_fb = static_cast<GLFrameBuffer *>(
+ back_left);
}
GLContext::~GLContext()
@@ -63,10 +104,9 @@ GLContext::~GLContext()
/* For now don't allow GPUFrameBuffers to be reuse in another context. */
BLI_assert(framebuffers_.is_empty());
/* Delete vaos so the batch can be reused in another context. */
- for (GPUBatch *batch : batches_) {
- GPU_batch_vao_cache_clear(batch);
+ for (GLVaoCache *cache : vao_caches_) {
+ cache->clear();
}
- glDeleteVertexArrays(1, &default_vao_);
glDeleteBuffers(1, &default_attr_vbo_);
}
@@ -86,6 +126,31 @@ void GLContext::activate(void)
/* Clear accumulated orphans. */
orphans_clear();
+
+ if (ghost_window_) {
+ /* Get the correct framebuffer size for the internal framebuffers. */
+ GHOST_RectangleHandle bounds = GHOST_GetClientBounds((GHOST_WindowHandle)ghost_window_);
+ int w = GHOST_GetWidthRectangle(bounds);
+ int h = GHOST_GetHeightRectangle(bounds);
+ GHOST_DisposeRectangle(bounds);
+
+ if (front_left) {
+ front_left->size_set(w, h);
+ }
+ if (back_left) {
+ back_left->size_set(w, h);
+ }
+ if (front_right) {
+ front_right->size_set(w, h);
+ }
+ if (back_right) {
+ back_right->size_set(w, h);
+ }
+ }
+
+ /* Not really following the state but we should consider
+ * no ubo bound when activating a context. */
+ bound_ubo_slots = 0;
}
void GLContext::deactivate(void)
@@ -193,47 +258,22 @@ void GLBackend::tex_free(GLuint tex_id)
/** \name Linked object deletion
*
* These objects contain data that are stored per context. We
- * need to do some cleanup if they are used accross context or if context
+ * need to do some cleanup if they are used across context or if context
* is discarded.
* \{ */
-void GLContext::batch_register(struct GPUBatch *batch)
-{
- lists_mutex_.lock();
- batches_.add(batch);
- lists_mutex_.unlock();
-}
-
-void GLContext::batch_unregister(struct GPUBatch *batch)
-{
- /* vao_cache_clear() can acquire lists_mutex_ so avoid deadlock. */
- // reinterpret_cast<GLBatch *>(batch)->vao_cache_clear();
-
- lists_mutex_.lock();
- batches_.remove(batch);
- lists_mutex_.unlock();
-}
-
-void GLContext::framebuffer_register(struct GPUFrameBuffer *fb)
+void GLContext::vao_cache_register(GLVaoCache *cache)
{
-#ifdef DEBUG
lists_mutex_.lock();
- framebuffers_.add(fb);
+ vao_caches_.add(cache);
lists_mutex_.unlock();
-#else
- UNUSED_VARS(fb);
-#endif
}
-void GLContext::framebuffer_unregister(struct GPUFrameBuffer *fb)
+void GLContext::vao_cache_unregister(GLVaoCache *cache)
{
-#ifdef DEBUG
lists_mutex_.lock();
- framebuffers_.remove(fb);
+ vao_caches_.remove(cache);
lists_mutex_.unlock();
-#else
- UNUSED_VARS(fb);
-#endif
}
/** \} */