2022-02-11 09:07:11 +11:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
* Copyright 2006 Blender Foundation. All rights reserved. */
|
2016-10-13 04:22:28 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup gpu
|
2016-10-13 04:22:28 +00:00
|
|
|
*
|
|
|
|
|
* System that manages viewport drawing.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-02-07 11:20:15 +01:00
|
|
|
#include <string.h>
|
|
|
|
|
|
2020-02-11 15:18:55 +01:00
|
|
|
#include "BLI_math_vector.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BLI_rect.h"
|
2017-02-07 11:20:15 +01:00
|
|
|
|
2020-02-11 15:18:55 +01:00
|
|
|
#include "BKE_colortools.h"
|
|
|
|
|
|
|
|
|
|
#include "IMB_colormanagement.h"
|
|
|
|
|
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "DNA_vec_types.h"
|
2017-02-07 11:20:15 +01:00
|
|
|
|
2022-05-10 08:10:46 +02:00
|
|
|
#include "GPU_capabilities.h"
|
2017-02-07 11:20:15 +01:00
|
|
|
#include "GPU_framebuffer.h"
|
2016-10-21 20:50:00 +00:00
|
|
|
#include "GPU_immediate.h"
|
2020-03-19 08:06:49 +01:00
|
|
|
#include "GPU_matrix.h"
|
2016-10-21 20:50:00 +00:00
|
|
|
#include "GPU_texture.h"
|
2020-08-20 23:09:37 +02:00
|
|
|
#include "GPU_uniform_buffer.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "GPU_viewport.h"
|
2017-02-07 11:20:15 +01:00
|
|
|
|
|
|
|
|
#include "DRW_engine.h"
|
2016-10-13 04:22:28 +00:00
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
2020-04-16 08:40:22 +02:00
|
|
|
/* Struct storing a viewport specific GPUBatch.
|
|
|
|
|
* The end-goal is to have a single batch shared across viewport and use a model matrix to place
|
|
|
|
|
* the batch. Due to OCIO and Image/UV editor we are not able to use an model matrix yet. */
|
|
|
|
|
struct GPUViewportBatch {
|
|
|
|
|
GPUBatch *batch;
|
|
|
|
|
struct {
|
|
|
|
|
rctf rect_pos;
|
|
|
|
|
rctf rect_uv;
|
|
|
|
|
} last_used_parameters;
|
2020-04-20 12:02:45 +10:00
|
|
|
};
|
2020-04-16 08:40:22 +02:00
|
|
|
|
|
|
|
|
static struct {
|
|
|
|
|
GPUVertFormat format;
|
|
|
|
|
struct {
|
|
|
|
|
uint pos, tex_coord;
|
|
|
|
|
} attr_id;
|
|
|
|
|
} g_viewport = {{0}};
|
|
|
|
|
|
2016-10-13 04:22:28 +00:00
|
|
|
struct GPUViewport {
|
2017-02-07 11:20:15 +01:00
|
|
|
int size[2];
|
2017-09-25 20:07:02 +02:00
|
|
|
int flag;
|
2017-02-07 11:20:15 +01:00
|
|
|
|
2021-02-05 16:23:34 +11:00
|
|
|
/* Set the active view (for stereoscopic viewport rendering). */
|
2020-03-19 08:06:49 +01:00
|
|
|
int active_view;
|
|
|
|
|
|
2021-10-05 09:36:11 +02:00
|
|
|
/* Viewport Resources. */
|
|
|
|
|
struct DRWData *draw_data;
|
|
|
|
|
/** Color buffers, one for each stereo view. Only one if not stereo viewport. */
|
|
|
|
|
GPUTexture *color_render_tx[2];
|
|
|
|
|
GPUTexture *color_overlay_tx[2];
|
|
|
|
|
/** Depth buffer. Can be shared with GPUOffscreen. */
|
|
|
|
|
GPUTexture *depth_tx;
|
|
|
|
|
/** Compositing framebuffer for stereo viewport. */
|
|
|
|
|
GPUFrameBuffer *stereo_comp_fb;
|
|
|
|
|
/** Overlay framebuffer for drawing outside of DRW module. */
|
|
|
|
|
GPUFrameBuffer *overlay_fb;
|
2020-02-11 15:18:55 +01:00
|
|
|
|
|
|
|
|
/* Color management. */
|
|
|
|
|
ColorManagedViewSettings view_settings;
|
|
|
|
|
ColorManagedDisplaySettings display_settings;
|
2020-04-15 22:26:20 +02:00
|
|
|
CurveMapping *orig_curve_mapping;
|
2020-02-11 15:18:55 +01:00
|
|
|
float dither;
|
2020-09-19 14:32:41 +10:00
|
|
|
/* TODO(fclem): the uvimage display use the viewport but do not set any view transform for the
|
2020-02-11 15:18:55 +01:00
|
|
|
* moment. The end goal would be to let the GPUViewport do the color management. */
|
|
|
|
|
bool do_color_management;
|
2020-04-16 08:40:22 +02:00
|
|
|
struct GPUViewportBatch batch;
|
2016-10-13 04:22:28 +00:00
|
|
|
};
|
|
|
|
|
|
2017-09-25 20:07:02 +02:00
|
|
|
enum {
|
|
|
|
|
DO_UPDATE = (1 << 0),
|
2020-03-19 08:06:49 +01:00
|
|
|
GPU_VIEWPORT_STEREO = (1 << 1),
|
2017-09-25 20:07:02 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void GPU_viewport_tag_update(GPUViewport *viewport)
|
|
|
|
|
{
|
|
|
|
|
viewport->flag |= DO_UPDATE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool GPU_viewport_do_update(GPUViewport *viewport)
|
|
|
|
|
{
|
|
|
|
|
bool ret = (viewport->flag & DO_UPDATE);
|
|
|
|
|
viewport->flag &= ~DO_UPDATE;
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-13 04:22:28 +00:00
|
|
|
GPUViewport *GPU_viewport_create(void)
|
|
|
|
|
{
|
|
|
|
|
GPUViewport *viewport = MEM_callocN(sizeof(GPUViewport), "GPUViewport");
|
2020-02-11 15:18:55 +01:00
|
|
|
viewport->do_color_management = false;
|
2017-02-07 11:20:15 +01:00
|
|
|
viewport->size[0] = viewport->size[1] = -1;
|
2021-10-05 09:36:11 +02:00
|
|
|
viewport->active_view = 0;
|
2020-03-19 08:06:49 +01:00
|
|
|
return viewport;
|
|
|
|
|
}
|
2017-02-07 11:20:15 +01:00
|
|
|
|
2020-03-19 08:06:49 +01:00
|
|
|
GPUViewport *GPU_viewport_stereo_create(void)
|
|
|
|
|
{
|
|
|
|
|
GPUViewport *viewport = GPU_viewport_create();
|
|
|
|
|
viewport->flag = GPU_VIEWPORT_STEREO;
|
2016-10-13 04:22:28 +00:00
|
|
|
return viewport;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-05 09:36:11 +02:00
|
|
|
struct DRWData **GPU_viewport_data_get(GPUViewport *viewport)
|
2017-02-17 17:29:43 +01:00
|
|
|
{
|
2021-10-05 09:36:11 +02:00
|
|
|
return &viewport->draw_data;
|
2017-11-06 16:47:23 +01:00
|
|
|
}
|
|
|
|
|
|
2021-10-05 09:36:11 +02:00
|
|
|
static void gpu_viewport_textures_create(GPUViewport *viewport)
|
2017-05-16 02:59:25 +02:00
|
|
|
{
|
2018-03-14 03:22:35 +01:00
|
|
|
int *size = viewport->size;
|
2022-01-27 15:50:38 +01:00
|
|
|
float empty_pixel[4] = {0.0f, 0.0f, 0.0f, 0.0f};
|
2022-12-08 23:30:57 +01:00
|
|
|
eGPUTextureUsage usage = GPU_TEXTURE_USAGE_SHADER_READ | GPU_TEXTURE_USAGE_ATTACHMENT;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-10-05 09:36:11 +02:00
|
|
|
if (viewport->color_render_tx[0] == NULL) {
|
2022-12-08 23:30:57 +01:00
|
|
|
|
2023-01-30 11:00:26 +01:00
|
|
|
/* NOTE: dtxl_color texture requires write support as it may be written to by the realtime
|
|
|
|
|
* compositor. */
|
2023-02-25 01:52:27 +01:00
|
|
|
viewport->color_render_tx[0] = GPU_texture_create_2d(
|
2023-01-30 11:00:26 +01:00
|
|
|
"dtxl_color", UNPACK2(size), 1, GPU_RGBA16F, usage | GPU_TEXTURE_USAGE_SHADER_WRITE, NULL);
|
2023-02-25 01:52:27 +01:00
|
|
|
viewport->color_overlay_tx[0] = GPU_texture_create_2d(
|
2022-12-08 23:30:57 +01:00
|
|
|
"dtxl_color_overlay", UNPACK2(size), 1, GPU_SRGB8_A8, usage, NULL);
|
|
|
|
|
|
2022-05-10 08:10:46 +02:00
|
|
|
if (GPU_clear_viewport_workaround()) {
|
|
|
|
|
GPU_texture_clear(viewport->color_render_tx[0], GPU_DATA_FLOAT, empty_pixel);
|
|
|
|
|
GPU_texture_clear(viewport->color_overlay_tx[0], GPU_DATA_FLOAT, empty_pixel);
|
|
|
|
|
}
|
2021-10-05 09:36:11 +02:00
|
|
|
}
|
2020-09-05 17:33:56 +02:00
|
|
|
|
2021-10-05 09:36:11 +02:00
|
|
|
if ((viewport->flag & GPU_VIEWPORT_STEREO) != 0 && viewport->color_render_tx[1] == NULL) {
|
2023-02-25 01:52:27 +01:00
|
|
|
viewport->color_render_tx[1] = GPU_texture_create_2d("dtxl_color_stereo",
|
|
|
|
|
UNPACK2(size),
|
|
|
|
|
1,
|
|
|
|
|
GPU_RGBA16F,
|
|
|
|
|
usage | GPU_TEXTURE_USAGE_SHADER_WRITE,
|
|
|
|
|
NULL);
|
|
|
|
|
viewport->color_overlay_tx[1] = GPU_texture_create_2d(
|
2022-12-08 23:30:57 +01:00
|
|
|
"dtxl_color_overlay_stereo", UNPACK2(size), 1, GPU_SRGB8_A8, usage, NULL);
|
|
|
|
|
|
2022-05-10 08:10:46 +02:00
|
|
|
if (GPU_clear_viewport_workaround()) {
|
|
|
|
|
GPU_texture_clear(viewport->color_render_tx[1], GPU_DATA_FLOAT, empty_pixel);
|
|
|
|
|
GPU_texture_clear(viewport->color_overlay_tx[1], GPU_DATA_FLOAT, empty_pixel);
|
|
|
|
|
}
|
2020-03-19 08:06:49 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-02-11 15:18:55 +01:00
|
|
|
/* Can be shared with GPUOffscreen. */
|
2021-10-05 09:36:11 +02:00
|
|
|
if (viewport->depth_tx == NULL) {
|
2023-02-27 21:44:59 +11:00
|
|
|
/* Depth texture can be read back by gizmos #view3d_depths_create. */
|
2023-02-25 01:52:27 +01:00
|
|
|
viewport->depth_tx = GPU_texture_create_2d("dtxl_depth",
|
|
|
|
|
UNPACK2(size),
|
|
|
|
|
1,
|
|
|
|
|
GPU_DEPTH24_STENCIL8,
|
|
|
|
|
usage | GPU_TEXTURE_USAGE_HOST_READ,
|
|
|
|
|
NULL);
|
2022-10-18 12:18:25 +02:00
|
|
|
if (GPU_clear_viewport_workaround()) {
|
|
|
|
|
static int depth_clear = 0;
|
|
|
|
|
GPU_texture_clear(viewport->depth_tx, GPU_DATA_UINT_24_8, &depth_clear);
|
|
|
|
|
}
|
2020-02-11 15:18:55 +01:00
|
|
|
}
|
|
|
|
|
|
2021-10-05 09:36:11 +02:00
|
|
|
if (!viewport->depth_tx || !viewport->color_render_tx[0] || !viewport->color_overlay_tx[0]) {
|
|
|
|
|
GPU_viewport_free(viewport);
|
2018-03-14 03:22:35 +01:00
|
|
|
}
|
2021-10-05 09:36:11 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-10-05 09:36:11 +02:00
|
|
|
static void gpu_viewport_textures_free(GPUViewport *viewport)
|
|
|
|
|
{
|
|
|
|
|
GPU_FRAMEBUFFER_FREE_SAFE(viewport->stereo_comp_fb);
|
|
|
|
|
GPU_FRAMEBUFFER_FREE_SAFE(viewport->overlay_fb);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-10-05 09:36:11 +02:00
|
|
|
for (int i = 0; i < 2; i++) {
|
|
|
|
|
GPU_TEXTURE_FREE_SAFE(viewport->color_render_tx[i]);
|
|
|
|
|
GPU_TEXTURE_FREE_SAFE(viewport->color_overlay_tx[i]);
|
2018-03-14 03:22:35 +01:00
|
|
|
}
|
|
|
|
|
|
2021-10-05 09:36:11 +02:00
|
|
|
GPU_TEXTURE_FREE_SAFE(viewport->depth_tx);
|
2018-03-14 03:22:35 +01:00
|
|
|
}
|
|
|
|
|
|
2020-03-19 08:06:49 +01:00
|
|
|
void GPU_viewport_bind(GPUViewport *viewport, int view, const rcti *rect)
|
2017-03-08 20:00:09 +01:00
|
|
|
{
|
2020-02-11 15:18:55 +01:00
|
|
|
int rect_size[2];
|
2017-03-08 20:00:09 +01:00
|
|
|
/* add one pixel because of scissor test */
|
2020-02-11 15:18:55 +01:00
|
|
|
rect_size[0] = BLI_rcti_size_x(rect) + 1;
|
|
|
|
|
rect_size[1] = BLI_rcti_size_y(rect) + 1;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-02-26 19:41:17 +01:00
|
|
|
DRW_opengl_context_enable();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-10-05 09:36:11 +02:00
|
|
|
if (!equals_v2v2_int(viewport->size, rect_size)) {
|
|
|
|
|
copy_v2_v2_int(viewport->size, rect_size);
|
|
|
|
|
gpu_viewport_textures_free(viewport);
|
|
|
|
|
gpu_viewport_textures_create(viewport);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
2021-10-05 09:36:11 +02:00
|
|
|
viewport->active_view = view;
|
2020-02-11 15:18:55 +01:00
|
|
|
}
|
|
|
|
|
|
2022-02-11 20:44:26 +09:00
|
|
|
void GPU_viewport_bind_from_offscreen(GPUViewport *viewport,
|
|
|
|
|
struct GPUOffScreen *ofs,
|
|
|
|
|
bool is_xr_surface)
|
2020-02-11 15:18:55 +01:00
|
|
|
{
|
|
|
|
|
GPUTexture *color, *depth;
|
|
|
|
|
GPUFrameBuffer *fb;
|
|
|
|
|
viewport->size[0] = GPU_offscreen_width(ofs);
|
|
|
|
|
viewport->size[1] = GPU_offscreen_height(ofs);
|
|
|
|
|
|
|
|
|
|
GPU_offscreen_viewport_data_get(ofs, &fb, &color, &depth);
|
|
|
|
|
|
2022-02-11 20:44:26 +09:00
|
|
|
/* XR surfaces will already check for texture size changes and free if necessary (see
|
|
|
|
|
* #wm_xr_session_surface_offscreen_ensure()), so don't free here as it has a significant
|
|
|
|
|
* performance impact (leads to texture re-creation in #gpu_viewport_textures_create() every VR
|
2022-03-31 13:00:10 +11:00
|
|
|
* drawing iteration). */
|
2022-02-11 20:44:26 +09:00
|
|
|
if (!is_xr_surface) {
|
|
|
|
|
gpu_viewport_textures_free(viewport);
|
|
|
|
|
}
|
2020-02-11 15:18:55 +01:00
|
|
|
|
2021-10-05 09:36:11 +02:00
|
|
|
/* This is the only texture we can share. */
|
|
|
|
|
viewport->depth_tx = depth;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-10-05 09:36:11 +02:00
|
|
|
gpu_viewport_textures_create(viewport);
|
2020-02-11 15:18:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GPU_viewport_colorspace_set(GPUViewport *viewport,
|
|
|
|
|
ColorManagedViewSettings *view_settings,
|
2021-08-31 12:45:22 +02:00
|
|
|
const ColorManagedDisplaySettings *display_settings,
|
2020-02-11 15:18:55 +01:00
|
|
|
float dither)
|
|
|
|
|
{
|
2020-04-15 22:26:20 +02:00
|
|
|
/**
|
|
|
|
|
* HACK(fclem): We copy the settings here to avoid use after free if an update frees the scene
|
2023-02-12 14:37:16 +11:00
|
|
|
* and the viewport stays cached (see #75443). But this means the OCIO curve-mapping caching
|
2020-04-17 11:11:30 +10:00
|
|
|
* (which is based on #CurveMap pointer address) cannot operate correctly and it will create
|
|
|
|
|
* a different OCIO processor for each viewport. We try to only reallocate the curve-map copy
|
|
|
|
|
* if needed to avoid unneeded cache invalidation.
|
2020-04-15 22:26:20 +02:00
|
|
|
*/
|
|
|
|
|
if (view_settings->curve_mapping) {
|
|
|
|
|
if (viewport->view_settings.curve_mapping) {
|
|
|
|
|
if (view_settings->curve_mapping->changed_timestamp !=
|
|
|
|
|
viewport->view_settings.curve_mapping->changed_timestamp) {
|
|
|
|
|
BKE_color_managed_view_settings_free(&viewport->view_settings);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (viewport->orig_curve_mapping != view_settings->curve_mapping) {
|
|
|
|
|
viewport->orig_curve_mapping = view_settings->curve_mapping;
|
|
|
|
|
BKE_color_managed_view_settings_free(&viewport->view_settings);
|
|
|
|
|
}
|
|
|
|
|
/* Don't copy the curve mapping already. */
|
|
|
|
|
CurveMapping *tmp_curve_mapping = view_settings->curve_mapping;
|
|
|
|
|
CurveMapping *tmp_curve_mapping_vp = viewport->view_settings.curve_mapping;
|
|
|
|
|
view_settings->curve_mapping = NULL;
|
|
|
|
|
viewport->view_settings.curve_mapping = NULL;
|
|
|
|
|
|
|
|
|
|
BKE_color_managed_view_settings_copy(&viewport->view_settings, view_settings);
|
|
|
|
|
/* Restore. */
|
|
|
|
|
view_settings->curve_mapping = tmp_curve_mapping;
|
|
|
|
|
viewport->view_settings.curve_mapping = tmp_curve_mapping_vp;
|
2021-02-05 16:23:34 +11:00
|
|
|
/* Only copy curve-mapping if needed. Avoid unneeded OCIO cache miss. */
|
2020-04-15 22:26:20 +02:00
|
|
|
if (tmp_curve_mapping && viewport->view_settings.curve_mapping == NULL) {
|
|
|
|
|
BKE_color_managed_view_settings_free(&viewport->view_settings);
|
|
|
|
|
viewport->view_settings.curve_mapping = BKE_curvemapping_copy(tmp_curve_mapping);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BKE_color_managed_display_settings_copy(&viewport->display_settings, display_settings);
|
2020-02-11 15:18:55 +01:00
|
|
|
viewport->dither = dither;
|
|
|
|
|
viewport->do_color_management = true;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-19 08:06:49 +01:00
|
|
|
void GPU_viewport_stereo_composite(GPUViewport *viewport, Stereo3dFormat *stereo_format)
|
|
|
|
|
{
|
|
|
|
|
if (!ELEM(stereo_format->display_mode, S3D_DISPLAY_ANAGLYPH, S3D_DISPLAY_INTERLACE)) {
|
|
|
|
|
/* Early Exit: the other display modes need access to the full screen and cannot be
|
|
|
|
|
* done from a single viewport. See `wm_stereo.c` */
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-04-16 15:47:18 +02:00
|
|
|
/* The composite framebuffer object needs to be created in the window context. */
|
2022-05-10 12:33:08 +02:00
|
|
|
GPU_framebuffer_ensure_config(
|
|
|
|
|
&viewport->stereo_comp_fb,
|
|
|
|
|
{
|
|
|
|
|
GPU_ATTACHMENT_NONE,
|
|
|
|
|
/* We need the sRGB attachment to be first for GL_FRAMEBUFFER_SRGB to be turned on.
|
|
|
|
|
* Note that this is the opposite of what the texture binding is. */
|
|
|
|
|
GPU_ATTACHMENT_TEXTURE(viewport->color_overlay_tx[0]),
|
|
|
|
|
GPU_ATTACHMENT_TEXTURE(viewport->color_render_tx[0]),
|
|
|
|
|
});
|
2020-04-16 15:47:18 +02:00
|
|
|
|
2020-03-19 08:06:49 +01:00
|
|
|
GPUVertFormat *vert_format = immVertexFormat();
|
|
|
|
|
uint pos = GPU_vertformat_attr_add(vert_format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
|
2021-10-05 09:36:11 +02:00
|
|
|
GPU_framebuffer_bind(viewport->stereo_comp_fb);
|
2020-03-19 08:06:49 +01:00
|
|
|
GPU_matrix_push();
|
|
|
|
|
GPU_matrix_push_projection();
|
|
|
|
|
GPU_matrix_identity_set();
|
|
|
|
|
GPU_matrix_identity_projection_set();
|
|
|
|
|
immBindBuiltinProgram(GPU_SHADER_2D_IMAGE_OVERLAYS_STEREO_MERGE);
|
|
|
|
|
int settings = stereo_format->display_mode;
|
|
|
|
|
if (settings == S3D_DISPLAY_ANAGLYPH) {
|
|
|
|
|
switch (stereo_format->anaglyph_type) {
|
|
|
|
|
case S3D_ANAGLYPH_REDCYAN:
|
2020-07-16 04:16:10 +02:00
|
|
|
GPU_color_mask(false, true, true, true);
|
2020-03-19 08:06:49 +01:00
|
|
|
break;
|
|
|
|
|
case S3D_ANAGLYPH_GREENMAGENTA:
|
2020-07-16 04:16:10 +02:00
|
|
|
GPU_color_mask(true, false, true, true);
|
2020-03-19 08:06:49 +01:00
|
|
|
break;
|
|
|
|
|
case S3D_ANAGLYPH_YELLOWBLUE:
|
2020-07-16 04:16:10 +02:00
|
|
|
GPU_color_mask(false, false, true, true);
|
2020-03-19 08:06:49 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (settings == S3D_DISPLAY_INTERLACE) {
|
|
|
|
|
settings |= stereo_format->interlace_type << 3;
|
|
|
|
|
SET_FLAG_FROM_TEST(settings, stereo_format->flag & S3D_INTERLACE_SWAP, 1 << 6);
|
|
|
|
|
}
|
|
|
|
|
immUniform1i("stereoDisplaySettings", settings);
|
|
|
|
|
|
2021-10-05 09:36:11 +02:00
|
|
|
GPU_texture_bind(viewport->color_render_tx[1], 0);
|
|
|
|
|
GPU_texture_bind(viewport->color_overlay_tx[1], 1);
|
2020-03-19 08:06:49 +01:00
|
|
|
|
|
|
|
|
immBegin(GPU_PRIM_TRI_STRIP, 4);
|
|
|
|
|
|
|
|
|
|
immVertex2f(pos, -1.0f, -1.0f);
|
|
|
|
|
immVertex2f(pos, 1.0f, -1.0f);
|
|
|
|
|
immVertex2f(pos, -1.0f, 1.0f);
|
|
|
|
|
immVertex2f(pos, 1.0f, 1.0f);
|
|
|
|
|
|
|
|
|
|
immEnd();
|
|
|
|
|
|
2021-10-05 09:36:11 +02:00
|
|
|
GPU_texture_unbind(viewport->color_render_tx[1]);
|
|
|
|
|
GPU_texture_unbind(viewport->color_overlay_tx[1]);
|
2020-03-19 08:06:49 +01:00
|
|
|
|
|
|
|
|
immUnbindProgram();
|
|
|
|
|
GPU_matrix_pop_projection();
|
|
|
|
|
GPU_matrix_pop();
|
|
|
|
|
|
|
|
|
|
if (settings == S3D_DISPLAY_ANAGLYPH) {
|
2020-07-16 04:16:10 +02:00
|
|
|
GPU_color_mask(true, true, true, true);
|
2020-03-19 08:06:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GPU_framebuffer_restore();
|
|
|
|
|
}
|
2020-04-16 08:40:22 +02:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Viewport Batches
|
|
|
|
|
* \{ */
|
|
|
|
|
|
|
|
|
|
static GPUVertFormat *gpu_viewport_batch_format(void)
|
|
|
|
|
{
|
|
|
|
|
if (g_viewport.format.attr_len == 0) {
|
|
|
|
|
GPUVertFormat *format = &g_viewport.format;
|
|
|
|
|
g_viewport.attr_id.pos = GPU_vertformat_attr_add(
|
|
|
|
|
format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
|
|
|
|
|
g_viewport.attr_id.tex_coord = GPU_vertformat_attr_add(
|
|
|
|
|
format, "texCoord", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
|
|
|
|
|
}
|
|
|
|
|
return &g_viewport.format;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static GPUBatch *gpu_viewport_batch_create(const rctf *rect_pos, const rctf *rect_uv)
|
|
|
|
|
{
|
|
|
|
|
GPUVertBuf *vbo = GPU_vertbuf_create_with_format(gpu_viewport_batch_format());
|
|
|
|
|
const uint vbo_len = 4;
|
|
|
|
|
GPU_vertbuf_data_alloc(vbo, vbo_len);
|
|
|
|
|
|
|
|
|
|
GPUVertBufRaw pos_step, tex_coord_step;
|
|
|
|
|
GPU_vertbuf_attr_get_raw_data(vbo, g_viewport.attr_id.pos, &pos_step);
|
|
|
|
|
GPU_vertbuf_attr_get_raw_data(vbo, g_viewport.attr_id.tex_coord, &tex_coord_step);
|
|
|
|
|
|
|
|
|
|
copy_v2_fl2(GPU_vertbuf_raw_step(&pos_step), rect_pos->xmin, rect_pos->ymin);
|
|
|
|
|
copy_v2_fl2(GPU_vertbuf_raw_step(&tex_coord_step), rect_uv->xmin, rect_uv->ymin);
|
|
|
|
|
copy_v2_fl2(GPU_vertbuf_raw_step(&pos_step), rect_pos->xmax, rect_pos->ymin);
|
|
|
|
|
copy_v2_fl2(GPU_vertbuf_raw_step(&tex_coord_step), rect_uv->xmax, rect_uv->ymin);
|
|
|
|
|
copy_v2_fl2(GPU_vertbuf_raw_step(&pos_step), rect_pos->xmin, rect_pos->ymax);
|
|
|
|
|
copy_v2_fl2(GPU_vertbuf_raw_step(&tex_coord_step), rect_uv->xmin, rect_uv->ymax);
|
|
|
|
|
copy_v2_fl2(GPU_vertbuf_raw_step(&pos_step), rect_pos->xmax, rect_pos->ymax);
|
|
|
|
|
copy_v2_fl2(GPU_vertbuf_raw_step(&tex_coord_step), rect_uv->xmax, rect_uv->ymax);
|
|
|
|
|
|
|
|
|
|
return GPU_batch_create_ex(GPU_PRIM_TRI_STRIP, vbo, NULL, GPU_BATCH_OWNS_VBO);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static GPUBatch *gpu_viewport_batch_get(GPUViewport *viewport,
|
|
|
|
|
const rctf *rect_pos,
|
|
|
|
|
const rctf *rect_uv)
|
|
|
|
|
{
|
|
|
|
|
const float compare_limit = 0.0001f;
|
|
|
|
|
const bool parameters_changed =
|
|
|
|
|
(!BLI_rctf_compare(
|
|
|
|
|
&viewport->batch.last_used_parameters.rect_pos, rect_pos, compare_limit) ||
|
|
|
|
|
!BLI_rctf_compare(&viewport->batch.last_used_parameters.rect_uv, rect_uv, compare_limit));
|
|
|
|
|
|
|
|
|
|
if (viewport->batch.batch && parameters_changed) {
|
|
|
|
|
GPU_batch_discard(viewport->batch.batch);
|
|
|
|
|
viewport->batch.batch = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!viewport->batch.batch) {
|
|
|
|
|
viewport->batch.batch = gpu_viewport_batch_create(rect_pos, rect_uv);
|
|
|
|
|
viewport->batch.last_used_parameters.rect_pos = *rect_pos;
|
|
|
|
|
viewport->batch.last_used_parameters.rect_uv = *rect_uv;
|
|
|
|
|
}
|
|
|
|
|
return viewport->batch.batch;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void gpu_viewport_batch_free(GPUViewport *viewport)
|
|
|
|
|
{
|
|
|
|
|
if (viewport->batch.batch) {
|
|
|
|
|
GPU_batch_discard(viewport->batch.batch);
|
|
|
|
|
viewport->batch.batch = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** \} */
|
2020-03-19 08:06:49 +01:00
|
|
|
|
2020-02-11 15:18:55 +01:00
|
|
|
static void gpu_viewport_draw_colormanaged(GPUViewport *viewport,
|
2021-10-05 09:36:11 +02:00
|
|
|
int view,
|
2020-02-11 15:18:55 +01:00
|
|
|
const rctf *rect_pos,
|
|
|
|
|
const rctf *rect_uv,
|
2021-01-26 14:05:50 +01:00
|
|
|
bool display_colorspace,
|
|
|
|
|
bool do_overlay_merge)
|
2020-02-11 15:18:55 +01:00
|
|
|
{
|
2021-10-05 09:36:11 +02:00
|
|
|
GPUTexture *color = viewport->color_render_tx[view];
|
|
|
|
|
GPUTexture *color_overlay = viewport->color_overlay_tx[view];
|
2020-02-11 15:18:55 +01:00
|
|
|
|
|
|
|
|
bool use_ocio = false;
|
|
|
|
|
|
|
|
|
|
if (viewport->do_color_management && display_colorspace) {
|
2020-04-16 08:40:22 +02:00
|
|
|
/* During the binding process the last used VertexFormat is tested and can assert as it is not
|
|
|
|
|
* valid. By calling the `immVertexFormat` the last used VertexFormat is reset and the assert
|
|
|
|
|
* does not happen. This solves a chicken and egg problem when using GPUBatches. GPUBatches
|
|
|
|
|
* contain the correct vertex format, but can only bind after the shader is bound.
|
|
|
|
|
*
|
|
|
|
|
* Image/UV editor still uses imm, after that has been changed we could move this fix to the
|
|
|
|
|
* OCIO. */
|
|
|
|
|
immVertexFormat();
|
2020-02-11 15:18:55 +01:00
|
|
|
use_ocio = IMB_colormanagement_setup_glsl_draw_from_space(&viewport->view_settings,
|
|
|
|
|
&viewport->display_settings,
|
|
|
|
|
NULL,
|
|
|
|
|
viewport->dither,
|
|
|
|
|
false,
|
2021-01-26 14:05:50 +01:00
|
|
|
do_overlay_merge);
|
2020-02-11 15:18:55 +01:00
|
|
|
}
|
|
|
|
|
|
2020-04-16 08:40:22 +02:00
|
|
|
GPUBatch *batch = gpu_viewport_batch_get(viewport, rect_pos, rect_uv);
|
|
|
|
|
if (use_ocio) {
|
|
|
|
|
GPU_batch_program_set_imm_shader(batch);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
GPU_batch_program_set_builtin(batch, GPU_SHADER_2D_IMAGE_OVERLAYS_MERGE);
|
2021-01-26 14:05:50 +01:00
|
|
|
GPU_batch_uniform_1i(batch, "overlay", do_overlay_merge);
|
2020-04-16 08:40:22 +02:00
|
|
|
GPU_batch_uniform_1i(batch, "display_transform", display_colorspace);
|
2020-02-11 15:18:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GPU_texture_bind(color, 0);
|
|
|
|
|
GPU_texture_bind(color_overlay, 1);
|
2020-04-16 08:40:22 +02:00
|
|
|
GPU_batch_draw(batch);
|
2020-02-11 15:18:55 +01:00
|
|
|
GPU_texture_unbind(color);
|
|
|
|
|
GPU_texture_unbind(color_overlay);
|
|
|
|
|
|
|
|
|
|
if (use_ocio) {
|
|
|
|
|
IMB_colormanagement_finish_glsl_draw();
|
|
|
|
|
}
|
2017-02-07 11:20:15 +01:00
|
|
|
}
|
|
|
|
|
|
VR: Initial Virtual Reality support - Milestone 1, Scene Inspection
NOTE: While most of the milestone 1 goals are there, a few smaller features and
improvements are still to be done.
Big picture of this milestone: Initial, OpenXR-based virtual reality support
for users and foundation for advanced use cases.
Maniphest Task: https://developer.blender.org/T71347
The tasks contains more information about this milestone.
To be clear: This is not a feature rich VR implementation, it's focused on the
initial scene inspection use case. We intentionally focused on that, further
features like controller support are part of the next milestone.
- How to use?
Instructions on how to use this are here:
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/How_to_Test
These will be updated and moved to a more official place (likely the manual) soon.
Currently Windows Mixed Reality and Oculus devices are usable. Valve/HTC
headsets don't support the OpenXR standard yet and hence, do not work with this
implementation.
---------------
This is the C-side implementation of the features added for initial VR
support as per milestone 1. A "VR Scene Inspection" Add-on will be
committed separately, to expose the VR functionality in the UI. It also
adds some further features for milestone 1, namely a landmarking system
(stored view locations in the VR space)
Main additions/features:
* Support for rendering viewports to an HMD, with good performance.
* Option to sync the VR view perspective with a fully interactive,
regular 3D View (VR-Mirror).
* Option to disable positional tracking. Keeps the current position (calculated
based on the VR eye center pose) when enabled while a VR session is running.
* Some regular viewport settings for the VR view
* RNA/Python-API to query and set VR session state information.
* WM-XR: Layer tying Ghost-XR to the Blender specific APIs/data
* wmSurface API: drawable, non-window container (manages Ghost-OpenGL and GPU
context)
* DNA/RNA for management of VR session settings
* `--debug-xr` and `--debug-xr-time` commandline options
* Utility batch & config file for using the Oculus runtime on Windows.
* Most VR data is runtime only. The exception is user settings which are saved
to files (`XrSessionSettings`).
* VR support can be disabled through the `WITH_XR_OPENXR` compiler flag.
For architecture and code documentation, see
https://wiki.blender.org/wiki/Source/Interface/XR.
---------------
A few thank you's:
* A huge shoutout to Ray Molenkamp for his help during the project - it would
have not been that successful without him!
* Sebastian Koenig and Simeon Conzendorf for testing and feedback!
* The reviewers, especially Brecht Van Lommel!
* Dalai Felinto for pushing and managing me to get this done ;)
* The OpenXR working group for providing an open standard. I think we're the
first bigger application to adopt OpenXR. Congratulations to them and
ourselves :)
This project started as a Google Summer of Code 2019 project - "Core Support of
Virtual Reality Headsets through OpenXR" (see
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/).
Some further information, including ideas for further improvements can be found
in the final GSoC report:
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/Final_Report
Differential Revisions: D6193, D7098
Reviewed by: Brecht Van Lommel, Jeroen Bakker
2020-03-17 20:20:55 +01:00
|
|
|
void GPU_viewport_draw_to_screen_ex(GPUViewport *viewport,
|
2020-03-19 08:06:49 +01:00
|
|
|
int view,
|
VR: Initial Virtual Reality support - Milestone 1, Scene Inspection
NOTE: While most of the milestone 1 goals are there, a few smaller features and
improvements are still to be done.
Big picture of this milestone: Initial, OpenXR-based virtual reality support
for users and foundation for advanced use cases.
Maniphest Task: https://developer.blender.org/T71347
The tasks contains more information about this milestone.
To be clear: This is not a feature rich VR implementation, it's focused on the
initial scene inspection use case. We intentionally focused on that, further
features like controller support are part of the next milestone.
- How to use?
Instructions on how to use this are here:
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/How_to_Test
These will be updated and moved to a more official place (likely the manual) soon.
Currently Windows Mixed Reality and Oculus devices are usable. Valve/HTC
headsets don't support the OpenXR standard yet and hence, do not work with this
implementation.
---------------
This is the C-side implementation of the features added for initial VR
support as per milestone 1. A "VR Scene Inspection" Add-on will be
committed separately, to expose the VR functionality in the UI. It also
adds some further features for milestone 1, namely a landmarking system
(stored view locations in the VR space)
Main additions/features:
* Support for rendering viewports to an HMD, with good performance.
* Option to sync the VR view perspective with a fully interactive,
regular 3D View (VR-Mirror).
* Option to disable positional tracking. Keeps the current position (calculated
based on the VR eye center pose) when enabled while a VR session is running.
* Some regular viewport settings for the VR view
* RNA/Python-API to query and set VR session state information.
* WM-XR: Layer tying Ghost-XR to the Blender specific APIs/data
* wmSurface API: drawable, non-window container (manages Ghost-OpenGL and GPU
context)
* DNA/RNA for management of VR session settings
* `--debug-xr` and `--debug-xr-time` commandline options
* Utility batch & config file for using the Oculus runtime on Windows.
* Most VR data is runtime only. The exception is user settings which are saved
to files (`XrSessionSettings`).
* VR support can be disabled through the `WITH_XR_OPENXR` compiler flag.
For architecture and code documentation, see
https://wiki.blender.org/wiki/Source/Interface/XR.
---------------
A few thank you's:
* A huge shoutout to Ray Molenkamp for his help during the project - it would
have not been that successful without him!
* Sebastian Koenig and Simeon Conzendorf for testing and feedback!
* The reviewers, especially Brecht Van Lommel!
* Dalai Felinto for pushing and managing me to get this done ;)
* The OpenXR working group for providing an open standard. I think we're the
first bigger application to adopt OpenXR. Congratulations to them and
ourselves :)
This project started as a Google Summer of Code 2019 project - "Core Support of
Virtual Reality Headsets through OpenXR" (see
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/).
Some further information, including ideas for further improvements can be found
in the final GSoC report:
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/Final_Report
Differential Revisions: D6193, D7098
Reviewed by: Brecht Van Lommel, Jeroen Bakker
2020-03-17 20:20:55 +01:00
|
|
|
const rcti *rect,
|
2021-01-26 14:05:50 +01:00
|
|
|
bool display_colorspace,
|
|
|
|
|
bool do_overlay_merge)
|
2017-02-07 11:20:15 +01:00
|
|
|
{
|
2021-10-05 09:36:11 +02:00
|
|
|
GPUTexture *color = viewport->color_render_tx[view];
|
2018-03-25 03:34:06 +02:00
|
|
|
|
2021-10-05 09:36:11 +02:00
|
|
|
if (color == NULL) {
|
2018-03-25 03:34:06 +02:00
|
|
|
return;
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
2018-03-25 03:34:06 +02:00
|
|
|
|
2017-02-07 11:20:15 +01:00
|
|
|
const float w = (float)GPU_texture_width(color);
|
|
|
|
|
const float h = (float)GPU_texture_height(color);
|
|
|
|
|
|
2021-02-05 16:23:34 +11:00
|
|
|
/* We allow rects with min/max swapped, but we also need correctly assigned coordinates. */
|
VR: Initial Virtual Reality support - Milestone 1, Scene Inspection
NOTE: While most of the milestone 1 goals are there, a few smaller features and
improvements are still to be done.
Big picture of this milestone: Initial, OpenXR-based virtual reality support
for users and foundation for advanced use cases.
Maniphest Task: https://developer.blender.org/T71347
The tasks contains more information about this milestone.
To be clear: This is not a feature rich VR implementation, it's focused on the
initial scene inspection use case. We intentionally focused on that, further
features like controller support are part of the next milestone.
- How to use?
Instructions on how to use this are here:
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/How_to_Test
These will be updated and moved to a more official place (likely the manual) soon.
Currently Windows Mixed Reality and Oculus devices are usable. Valve/HTC
headsets don't support the OpenXR standard yet and hence, do not work with this
implementation.
---------------
This is the C-side implementation of the features added for initial VR
support as per milestone 1. A "VR Scene Inspection" Add-on will be
committed separately, to expose the VR functionality in the UI. It also
adds some further features for milestone 1, namely a landmarking system
(stored view locations in the VR space)
Main additions/features:
* Support for rendering viewports to an HMD, with good performance.
* Option to sync the VR view perspective with a fully interactive,
regular 3D View (VR-Mirror).
* Option to disable positional tracking. Keeps the current position (calculated
based on the VR eye center pose) when enabled while a VR session is running.
* Some regular viewport settings for the VR view
* RNA/Python-API to query and set VR session state information.
* WM-XR: Layer tying Ghost-XR to the Blender specific APIs/data
* wmSurface API: drawable, non-window container (manages Ghost-OpenGL and GPU
context)
* DNA/RNA for management of VR session settings
* `--debug-xr` and `--debug-xr-time` commandline options
* Utility batch & config file for using the Oculus runtime on Windows.
* Most VR data is runtime only. The exception is user settings which are saved
to files (`XrSessionSettings`).
* VR support can be disabled through the `WITH_XR_OPENXR` compiler flag.
For architecture and code documentation, see
https://wiki.blender.org/wiki/Source/Interface/XR.
---------------
A few thank you's:
* A huge shoutout to Ray Molenkamp for his help during the project - it would
have not been that successful without him!
* Sebastian Koenig and Simeon Conzendorf for testing and feedback!
* The reviewers, especially Brecht Van Lommel!
* Dalai Felinto for pushing and managing me to get this done ;)
* The OpenXR working group for providing an open standard. I think we're the
first bigger application to adopt OpenXR. Congratulations to them and
ourselves :)
This project started as a Google Summer of Code 2019 project - "Core Support of
Virtual Reality Headsets through OpenXR" (see
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/).
Some further information, including ideas for further improvements can be found
in the final GSoC report:
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/Final_Report
Differential Revisions: D6193, D7098
Reviewed by: Brecht Van Lommel, Jeroen Bakker
2020-03-17 20:20:55 +01:00
|
|
|
rcti sanitized_rect = *rect;
|
|
|
|
|
BLI_rcti_sanitize(&sanitized_rect);
|
|
|
|
|
|
|
|
|
|
BLI_assert(w == BLI_rcti_size_x(&sanitized_rect) + 1);
|
|
|
|
|
BLI_assert(h == BLI_rcti_size_y(&sanitized_rect) + 1);
|
2018-02-13 18:18:04 +01:00
|
|
|
|
2018-04-27 10:22:37 +02:00
|
|
|
/* wmOrtho for the screen has this same offset */
|
|
|
|
|
const float halfx = GLA_PIXEL_OFS / w;
|
|
|
|
|
const float halfy = GLA_PIXEL_OFS / h;
|
|
|
|
|
|
2020-02-11 15:18:55 +01:00
|
|
|
rctf pos_rect = {
|
VR: Initial Virtual Reality support - Milestone 1, Scene Inspection
NOTE: While most of the milestone 1 goals are there, a few smaller features and
improvements are still to be done.
Big picture of this milestone: Initial, OpenXR-based virtual reality support
for users and foundation for advanced use cases.
Maniphest Task: https://developer.blender.org/T71347
The tasks contains more information about this milestone.
To be clear: This is not a feature rich VR implementation, it's focused on the
initial scene inspection use case. We intentionally focused on that, further
features like controller support are part of the next milestone.
- How to use?
Instructions on how to use this are here:
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/How_to_Test
These will be updated and moved to a more official place (likely the manual) soon.
Currently Windows Mixed Reality and Oculus devices are usable. Valve/HTC
headsets don't support the OpenXR standard yet and hence, do not work with this
implementation.
---------------
This is the C-side implementation of the features added for initial VR
support as per milestone 1. A "VR Scene Inspection" Add-on will be
committed separately, to expose the VR functionality in the UI. It also
adds some further features for milestone 1, namely a landmarking system
(stored view locations in the VR space)
Main additions/features:
* Support for rendering viewports to an HMD, with good performance.
* Option to sync the VR view perspective with a fully interactive,
regular 3D View (VR-Mirror).
* Option to disable positional tracking. Keeps the current position (calculated
based on the VR eye center pose) when enabled while a VR session is running.
* Some regular viewport settings for the VR view
* RNA/Python-API to query and set VR session state information.
* WM-XR: Layer tying Ghost-XR to the Blender specific APIs/data
* wmSurface API: drawable, non-window container (manages Ghost-OpenGL and GPU
context)
* DNA/RNA for management of VR session settings
* `--debug-xr` and `--debug-xr-time` commandline options
* Utility batch & config file for using the Oculus runtime on Windows.
* Most VR data is runtime only. The exception is user settings which are saved
to files (`XrSessionSettings`).
* VR support can be disabled through the `WITH_XR_OPENXR` compiler flag.
For architecture and code documentation, see
https://wiki.blender.org/wiki/Source/Interface/XR.
---------------
A few thank you's:
* A huge shoutout to Ray Molenkamp for his help during the project - it would
have not been that successful without him!
* Sebastian Koenig and Simeon Conzendorf for testing and feedback!
* The reviewers, especially Brecht Van Lommel!
* Dalai Felinto for pushing and managing me to get this done ;)
* The OpenXR working group for providing an open standard. I think we're the
first bigger application to adopt OpenXR. Congratulations to them and
ourselves :)
This project started as a Google Summer of Code 2019 project - "Core Support of
Virtual Reality Headsets through OpenXR" (see
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/).
Some further information, including ideas for further improvements can be found
in the final GSoC report:
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/Final_Report
Differential Revisions: D6193, D7098
Reviewed by: Brecht Van Lommel, Jeroen Bakker
2020-03-17 20:20:55 +01:00
|
|
|
.xmin = sanitized_rect.xmin,
|
|
|
|
|
.ymin = sanitized_rect.ymin,
|
|
|
|
|
.xmax = sanitized_rect.xmin + w,
|
|
|
|
|
.ymax = sanitized_rect.ymin + h,
|
2020-02-11 15:18:55 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
rctf uv_rect = {
|
|
|
|
|
.xmin = halfx,
|
|
|
|
|
.ymin = halfy,
|
|
|
|
|
.xmax = halfx + 1.0f,
|
|
|
|
|
.ymax = halfy + 1.0f,
|
|
|
|
|
};
|
VR: Initial Virtual Reality support - Milestone 1, Scene Inspection
NOTE: While most of the milestone 1 goals are there, a few smaller features and
improvements are still to be done.
Big picture of this milestone: Initial, OpenXR-based virtual reality support
for users and foundation for advanced use cases.
Maniphest Task: https://developer.blender.org/T71347
The tasks contains more information about this milestone.
To be clear: This is not a feature rich VR implementation, it's focused on the
initial scene inspection use case. We intentionally focused on that, further
features like controller support are part of the next milestone.
- How to use?
Instructions on how to use this are here:
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/How_to_Test
These will be updated and moved to a more official place (likely the manual) soon.
Currently Windows Mixed Reality and Oculus devices are usable. Valve/HTC
headsets don't support the OpenXR standard yet and hence, do not work with this
implementation.
---------------
This is the C-side implementation of the features added for initial VR
support as per milestone 1. A "VR Scene Inspection" Add-on will be
committed separately, to expose the VR functionality in the UI. It also
adds some further features for milestone 1, namely a landmarking system
(stored view locations in the VR space)
Main additions/features:
* Support for rendering viewports to an HMD, with good performance.
* Option to sync the VR view perspective with a fully interactive,
regular 3D View (VR-Mirror).
* Option to disable positional tracking. Keeps the current position (calculated
based on the VR eye center pose) when enabled while a VR session is running.
* Some regular viewport settings for the VR view
* RNA/Python-API to query and set VR session state information.
* WM-XR: Layer tying Ghost-XR to the Blender specific APIs/data
* wmSurface API: drawable, non-window container (manages Ghost-OpenGL and GPU
context)
* DNA/RNA for management of VR session settings
* `--debug-xr` and `--debug-xr-time` commandline options
* Utility batch & config file for using the Oculus runtime on Windows.
* Most VR data is runtime only. The exception is user settings which are saved
to files (`XrSessionSettings`).
* VR support can be disabled through the `WITH_XR_OPENXR` compiler flag.
For architecture and code documentation, see
https://wiki.blender.org/wiki/Source/Interface/XR.
---------------
A few thank you's:
* A huge shoutout to Ray Molenkamp for his help during the project - it would
have not been that successful without him!
* Sebastian Koenig and Simeon Conzendorf for testing and feedback!
* The reviewers, especially Brecht Van Lommel!
* Dalai Felinto for pushing and managing me to get this done ;)
* The OpenXR working group for providing an open standard. I think we're the
first bigger application to adopt OpenXR. Congratulations to them and
ourselves :)
This project started as a Google Summer of Code 2019 project - "Core Support of
Virtual Reality Headsets through OpenXR" (see
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/).
Some further information, including ideas for further improvements can be found
in the final GSoC report:
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/Final_Report
Differential Revisions: D6193, D7098
Reviewed by: Brecht Van Lommel, Jeroen Bakker
2020-03-17 20:20:55 +01:00
|
|
|
/* Mirror the UV rect in case axis-swapped drawing is requested (by passing a rect with min and
|
|
|
|
|
* max values swapped). */
|
|
|
|
|
if (BLI_rcti_size_x(rect) < 0) {
|
|
|
|
|
SWAP(float, uv_rect.xmin, uv_rect.xmax);
|
|
|
|
|
}
|
|
|
|
|
if (BLI_rcti_size_y(rect) < 0) {
|
|
|
|
|
SWAP(float, uv_rect.ymin, uv_rect.ymax);
|
|
|
|
|
}
|
2020-02-11 15:18:55 +01:00
|
|
|
|
2021-01-26 14:05:50 +01:00
|
|
|
gpu_viewport_draw_colormanaged(
|
2021-10-05 09:36:11 +02:00
|
|
|
viewport, view, &pos_rect, &uv_rect, display_colorspace, do_overlay_merge);
|
VR: Initial Virtual Reality support - Milestone 1, Scene Inspection
NOTE: While most of the milestone 1 goals are there, a few smaller features and
improvements are still to be done.
Big picture of this milestone: Initial, OpenXR-based virtual reality support
for users and foundation for advanced use cases.
Maniphest Task: https://developer.blender.org/T71347
The tasks contains more information about this milestone.
To be clear: This is not a feature rich VR implementation, it's focused on the
initial scene inspection use case. We intentionally focused on that, further
features like controller support are part of the next milestone.
- How to use?
Instructions on how to use this are here:
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/How_to_Test
These will be updated and moved to a more official place (likely the manual) soon.
Currently Windows Mixed Reality and Oculus devices are usable. Valve/HTC
headsets don't support the OpenXR standard yet and hence, do not work with this
implementation.
---------------
This is the C-side implementation of the features added for initial VR
support as per milestone 1. A "VR Scene Inspection" Add-on will be
committed separately, to expose the VR functionality in the UI. It also
adds some further features for milestone 1, namely a landmarking system
(stored view locations in the VR space)
Main additions/features:
* Support for rendering viewports to an HMD, with good performance.
* Option to sync the VR view perspective with a fully interactive,
regular 3D View (VR-Mirror).
* Option to disable positional tracking. Keeps the current position (calculated
based on the VR eye center pose) when enabled while a VR session is running.
* Some regular viewport settings for the VR view
* RNA/Python-API to query and set VR session state information.
* WM-XR: Layer tying Ghost-XR to the Blender specific APIs/data
* wmSurface API: drawable, non-window container (manages Ghost-OpenGL and GPU
context)
* DNA/RNA for management of VR session settings
* `--debug-xr` and `--debug-xr-time` commandline options
* Utility batch & config file for using the Oculus runtime on Windows.
* Most VR data is runtime only. The exception is user settings which are saved
to files (`XrSessionSettings`).
* VR support can be disabled through the `WITH_XR_OPENXR` compiler flag.
For architecture and code documentation, see
https://wiki.blender.org/wiki/Source/Interface/XR.
---------------
A few thank you's:
* A huge shoutout to Ray Molenkamp for his help during the project - it would
have not been that successful without him!
* Sebastian Koenig and Simeon Conzendorf for testing and feedback!
* The reviewers, especially Brecht Van Lommel!
* Dalai Felinto for pushing and managing me to get this done ;)
* The OpenXR working group for providing an open standard. I think we're the
first bigger application to adopt OpenXR. Congratulations to them and
ourselves :)
This project started as a Google Summer of Code 2019 project - "Core Support of
Virtual Reality Headsets through OpenXR" (see
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/).
Some further information, including ideas for further improvements can be found
in the final GSoC report:
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/Final_Report
Differential Revisions: D6193, D7098
Reviewed by: Brecht Van Lommel, Jeroen Bakker
2020-03-17 20:20:55 +01:00
|
|
|
}
|
|
|
|
|
|
2020-03-19 08:06:49 +01:00
|
|
|
void GPU_viewport_draw_to_screen(GPUViewport *viewport, int view, const rcti *rect)
|
VR: Initial Virtual Reality support - Milestone 1, Scene Inspection
NOTE: While most of the milestone 1 goals are there, a few smaller features and
improvements are still to be done.
Big picture of this milestone: Initial, OpenXR-based virtual reality support
for users and foundation for advanced use cases.
Maniphest Task: https://developer.blender.org/T71347
The tasks contains more information about this milestone.
To be clear: This is not a feature rich VR implementation, it's focused on the
initial scene inspection use case. We intentionally focused on that, further
features like controller support are part of the next milestone.
- How to use?
Instructions on how to use this are here:
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/How_to_Test
These will be updated and moved to a more official place (likely the manual) soon.
Currently Windows Mixed Reality and Oculus devices are usable. Valve/HTC
headsets don't support the OpenXR standard yet and hence, do not work with this
implementation.
---------------
This is the C-side implementation of the features added for initial VR
support as per milestone 1. A "VR Scene Inspection" Add-on will be
committed separately, to expose the VR functionality in the UI. It also
adds some further features for milestone 1, namely a landmarking system
(stored view locations in the VR space)
Main additions/features:
* Support for rendering viewports to an HMD, with good performance.
* Option to sync the VR view perspective with a fully interactive,
regular 3D View (VR-Mirror).
* Option to disable positional tracking. Keeps the current position (calculated
based on the VR eye center pose) when enabled while a VR session is running.
* Some regular viewport settings for the VR view
* RNA/Python-API to query and set VR session state information.
* WM-XR: Layer tying Ghost-XR to the Blender specific APIs/data
* wmSurface API: drawable, non-window container (manages Ghost-OpenGL and GPU
context)
* DNA/RNA for management of VR session settings
* `--debug-xr` and `--debug-xr-time` commandline options
* Utility batch & config file for using the Oculus runtime on Windows.
* Most VR data is runtime only. The exception is user settings which are saved
to files (`XrSessionSettings`).
* VR support can be disabled through the `WITH_XR_OPENXR` compiler flag.
For architecture and code documentation, see
https://wiki.blender.org/wiki/Source/Interface/XR.
---------------
A few thank you's:
* A huge shoutout to Ray Molenkamp for his help during the project - it would
have not been that successful without him!
* Sebastian Koenig and Simeon Conzendorf for testing and feedback!
* The reviewers, especially Brecht Van Lommel!
* Dalai Felinto for pushing and managing me to get this done ;)
* The OpenXR working group for providing an open standard. I think we're the
first bigger application to adopt OpenXR. Congratulations to them and
ourselves :)
This project started as a Google Summer of Code 2019 project - "Core Support of
Virtual Reality Headsets through OpenXR" (see
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/).
Some further information, including ideas for further improvements can be found
in the final GSoC report:
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/Final_Report
Differential Revisions: D6193, D7098
Reviewed by: Brecht Van Lommel, Jeroen Bakker
2020-03-17 20:20:55 +01:00
|
|
|
{
|
2021-01-26 14:05:50 +01:00
|
|
|
GPU_viewport_draw_to_screen_ex(viewport, view, rect, true, true);
|
2020-02-11 15:18:55 +01:00
|
|
|
}
|
2017-02-07 11:20:15 +01:00
|
|
|
|
2020-02-11 15:18:55 +01:00
|
|
|
void GPU_viewport_unbind_from_offscreen(GPUViewport *viewport,
|
|
|
|
|
struct GPUOffScreen *ofs,
|
2021-01-26 14:05:50 +01:00
|
|
|
bool display_colorspace,
|
|
|
|
|
bool do_overlay_merge)
|
2020-02-11 15:18:55 +01:00
|
|
|
{
|
2022-03-23 21:47:13 +11:00
|
|
|
const int view = 0;
|
|
|
|
|
|
|
|
|
|
if (viewport->color_render_tx[view] == NULL) {
|
2020-02-11 15:18:55 +01:00
|
|
|
return;
|
|
|
|
|
}
|
2017-03-08 20:00:09 +01:00
|
|
|
|
2020-09-15 10:15:54 +02:00
|
|
|
GPU_depth_test(GPU_DEPTH_NONE);
|
2020-02-11 15:18:55 +01:00
|
|
|
GPU_offscreen_bind(ofs, false);
|
2017-02-07 11:20:15 +01:00
|
|
|
|
2020-02-11 15:18:55 +01:00
|
|
|
rctf pos_rect = {
|
|
|
|
|
.xmin = -1.0f,
|
|
|
|
|
.ymin = -1.0f,
|
|
|
|
|
.xmax = 1.0f,
|
|
|
|
|
.ymax = 1.0f,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
rctf uv_rect = {
|
|
|
|
|
.xmin = 0.0f,
|
|
|
|
|
.ymin = 0.0f,
|
|
|
|
|
.xmax = 1.0f,
|
|
|
|
|
.ymax = 1.0f,
|
|
|
|
|
};
|
|
|
|
|
|
2021-01-26 14:05:50 +01:00
|
|
|
gpu_viewport_draw_colormanaged(
|
2022-03-23 21:47:13 +11:00
|
|
|
viewport, view, &pos_rect, &uv_rect, display_colorspace, do_overlay_merge);
|
2020-02-11 15:18:55 +01:00
|
|
|
|
|
|
|
|
/* This one is from the offscreen. Don't free it with the viewport. */
|
2021-10-05 09:36:11 +02:00
|
|
|
viewport->depth_tx = NULL;
|
2017-02-07 11:20:15 +01:00
|
|
|
}
|
|
|
|
|
|
2018-03-25 03:34:06 +02:00
|
|
|
void GPU_viewport_unbind(GPUViewport *UNUSED(viewport))
|
2017-02-07 11:20:15 +01:00
|
|
|
{
|
2018-04-27 18:46:16 +02:00
|
|
|
GPU_framebuffer_restore();
|
2018-02-26 19:41:17 +01:00
|
|
|
DRW_opengl_context_disable();
|
2017-02-07 11:20:15 +01:00
|
|
|
}
|
|
|
|
|
|
2021-10-05 09:36:11 +02:00
|
|
|
int GPU_viewport_active_view_get(GPUViewport *viewport)
|
2018-04-27 10:22:37 +02:00
|
|
|
{
|
2021-10-05 09:36:11 +02:00
|
|
|
return viewport->active_view;
|
|
|
|
|
}
|
2020-08-07 12:39:35 +02:00
|
|
|
|
2021-10-05 09:36:11 +02:00
|
|
|
bool GPU_viewport_is_stereo_get(GPUViewport *viewport)
|
|
|
|
|
{
|
|
|
|
|
return (viewport->flag & GPU_VIEWPORT_STEREO) != 0;
|
|
|
|
|
}
|
2018-04-27 10:22:37 +02:00
|
|
|
|
2021-10-05 09:36:11 +02:00
|
|
|
GPUTexture *GPU_viewport_color_texture(GPUViewport *viewport, int view)
|
|
|
|
|
{
|
|
|
|
|
return viewport->color_render_tx[view];
|
2018-04-27 10:22:37 +02:00
|
|
|
}
|
|
|
|
|
|
2021-10-05 09:36:11 +02:00
|
|
|
GPUTexture *GPU_viewport_overlay_texture(GPUViewport *viewport, int view)
|
2017-02-07 11:20:15 +01:00
|
|
|
{
|
2021-10-05 09:36:11 +02:00
|
|
|
return viewport->color_overlay_tx[view];
|
2017-02-07 11:20:15 +01:00
|
|
|
}
|
|
|
|
|
|
2021-10-05 09:36:11 +02:00
|
|
|
GPUTexture *GPU_viewport_depth_texture(GPUViewport *viewport)
|
2017-02-08 21:44:13 +01:00
|
|
|
{
|
2021-10-05 09:36:11 +02:00
|
|
|
return viewport->depth_tx;
|
2017-02-08 21:44:13 +01:00
|
|
|
}
|
|
|
|
|
|
2021-10-05 09:36:11 +02:00
|
|
|
GPUFrameBuffer *GPU_viewport_framebuffer_overlay_get(GPUViewport *viewport)
|
2017-02-07 11:20:15 +01:00
|
|
|
{
|
2021-11-25 13:40:04 +01:00
|
|
|
GPU_framebuffer_ensure_config(
|
|
|
|
|
&viewport->overlay_fb,
|
|
|
|
|
{
|
|
|
|
|
GPU_ATTACHMENT_TEXTURE(viewport->depth_tx),
|
|
|
|
|
GPU_ATTACHMENT_TEXTURE(viewport->color_overlay_tx[viewport->active_view]),
|
|
|
|
|
});
|
2021-10-05 09:36:11 +02:00
|
|
|
return viewport->overlay_fb;
|
2017-02-07 11:20:15 +01:00
|
|
|
}
|
|
|
|
|
|
2016-10-13 04:22:28 +00:00
|
|
|
void GPU_viewport_free(GPUViewport *viewport)
|
|
|
|
|
{
|
2021-10-05 09:36:11 +02:00
|
|
|
if (viewport->draw_data) {
|
|
|
|
|
DRW_viewport_data_free(viewport->draw_data);
|
Materials: add custom object properties as uniform attributes.
This patch allows the user to type a property name into the
Attribute node, which will then output the value of the property
for each individual object, allowing to e.g. customize shaders
by object without duplicating the shader.
In order to make supporting this easier for Eevee, it is necessary
to explicitly choose whether the attribute is varying or uniform
via a dropdown option of the Attribute node. The dropdown also
allows choosing whether instancing should be taken into account.
The Cycles design treats all attributes as one common namespace,
so the Blender interface converts the enum to a name prefix that
can't be entered using keyboard.
In Eevee, the attributes are provided to the shader via a UBO indexed
with resource_id, similar to the existing Object Info data. Unlike it,
however, it is necessary to maintain a separate buffer for every
requested combination of attributes.
This is done using a hash table with the attribute set as the key,
as it is expected that technically different but similar materials
may use the same set of attributes. In addition, in order to minimize
wasted memory, a sparse UBO pool is implemented, so that chunks that
don't contain any data don't have to be allocated.
The back-end Cycles code is already refactored and committed by Brecht.
Differential Revision: https://developer.blender.org/D2057
2020-08-05 19:14:40 +03:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-10-05 09:36:11 +02:00
|
|
|
gpu_viewport_textures_free(viewport);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-04-15 22:26:20 +02:00
|
|
|
BKE_color_managed_view_settings_free(&viewport->view_settings);
|
2020-04-16 08:40:22 +02:00
|
|
|
gpu_viewport_batch_free(viewport);
|
2020-04-15 22:26:20 +02:00
|
|
|
|
2018-02-28 02:29:55 +01:00
|
|
|
MEM_freeN(viewport);
|
2016-10-13 04:22:28 +00:00
|
|
|
}
|