1
1

DRW: Make use of shader shared header

# Conflicts:
#	source/blender/draw/intern/draw_manager.h
#	source/blender/draw/intern/draw_manager_exec.c
#	source/blender/draw/intern/draw_shader_shared.h
This commit is contained in:
2022-03-19 20:40:13 +01:00
parent 3eaf345352
commit 6ae03375b6
5 changed files with 32 additions and 29 deletions

View File

@@ -616,7 +616,7 @@ static void drw_manager_init(DRWManager *dst, GPUViewport *viewport, const int s
}
if (G_draw.view_ubo == NULL) {
G_draw.view_ubo = GPU_uniformbuf_create_ex(sizeof(DRWViewUboStorage), NULL, "G_draw.view_ubo");
G_draw.view_ubo = GPU_uniformbuf_create_ex(sizeof(ViewInfos), NULL, "G_draw.view_ubo");
}
if (dst->draw_list == NULL) {

View File

@@ -27,6 +27,7 @@
#include "GPU_viewport.h"
#include "draw_instance_data.h"
#include "draw_shader_shared.h"
#ifdef __cplusplus
extern "C" {
@@ -424,31 +425,13 @@ struct DRWPass {
char name[MAX_PASS_NAME];
};
/* keep in sync with viewBlock */
typedef struct DRWViewUboStorage {
/* View matrices */
float persmat[4][4];
float persinv[4][4];
float viewmat[4][4];
float viewinv[4][4];
float winmat[4][4];
float wininv[4][4];
float clipplanes[6][4];
float viewvecs[2][4];
/* Should not be here. Not view dependent (only main view). */
float viewcamtexcofac[4];
} DRWViewUboStorage;
BLI_STATIC_ASSERT_ALIGN(DRWViewUboStorage, 16)
#define MAX_CULLED_VIEWS 32
struct DRWView {
/** Parent view if this is a sub view. NULL otherwise. */
struct DRWView *parent;
DRWViewUboStorage storage;
ViewInfos storage;
/** Number of active clipplanes. */
int clip_planes_len;
/** Does culling result needs to be updated. */
@@ -633,7 +616,7 @@ typedef struct DRWManager {
uint primary_view_ct;
/** TODO(@fclem): Remove this. Only here to support
* shaders without common_view_lib.glsl */
DRWViewUboStorage view_storage_cpy;
ViewInfos view_storage_cpy;
#ifdef USE_GPU_SELECT
uint select_id;

View File

@@ -1825,7 +1825,7 @@ static void draw_frustum_bound_sphere_calc(const BoundBox *bbox,
}
}
static void draw_view_matrix_state_update(DRWViewUboStorage *storage,
static void draw_view_matrix_state_update(ViewInfos *storage,
const float viewmat[4][4],
const float winmat[4][4])
{
@@ -2037,7 +2037,7 @@ void DRW_view_clip_planes_set(DRWView *view, float (*planes)[4], int plane_len)
BLI_assert(plane_len <= MAX_CLIP_PLANES);
view->clip_planes_len = plane_len;
if (plane_len > 0) {
memcpy(view->storage.clipplanes, planes, sizeof(float[4]) * plane_len);
memcpy(view->storage.clip_planes, planes, sizeof(float[4]) * plane_len);
}
}
@@ -2089,21 +2089,21 @@ float DRW_view_far_distance_get(const DRWView *view)
void DRW_view_viewmat_get(const DRWView *view, float mat[4][4], bool inverse)
{
view = (view) ? view : DST.view_default;
const DRWViewUboStorage *storage = &view->storage;
const ViewInfos *storage = &view->storage;
copy_m4_m4(mat, (inverse) ? storage->viewinv : storage->viewmat);
}
void DRW_view_winmat_get(const DRWView *view, float mat[4][4], bool inverse)
{
view = (view) ? view : DST.view_default;
const DRWViewUboStorage *storage = &view->storage;
const ViewInfos *storage = &view->storage;
copy_m4_m4(mat, (inverse) ? storage->wininv : storage->winmat);
}
void DRW_view_persmat_get(const DRWView *view, float mat[4][4], bool inverse)
{
view = (view) ? view : DST.view_default;
const DRWViewUboStorage *storage = &view->storage;
const ViewInfos *storage = &view->storage;
copy_m4_m4(mat, (inverse) ? storage->persinv : storage->persmat);
}

View File

@@ -1068,8 +1068,13 @@ static void draw_shgroup(DRWShadingGroup *shgroup, DRWState pass_state)
}
}
static void drw_update_view(void)
static void drw_update_view(const float viewport_size[2])
{
ViewInfos *storage = &DST.view_active->storage;
copy_v2_v2(storage->viewport_size, viewport_size);
copy_v2_v2(storage->viewport_size_inverse, viewport_size);
invert_v2(storage->viewport_size_inverse);
/* TODO(fclem): update a big UBO and only bind ranges here. */
GPU_uniformbuf_update(G_draw.view_ubo, &DST.view_active->storage);
@@ -1097,8 +1102,11 @@ static void drw_draw_pass_ex(DRWPass *pass,
BLI_assert(DST.buffer_finish_called &&
"DRW_render_instance_buffer_finish had not been called before drawing");
if (DST.view_previous != DST.view_active || DST.view_active->is_dirty) {
drw_update_view();
float viewport[4];
GPU_viewport_size_get_f(viewport);
if (DST.view_previous != DST.view_active || DST.view_active->is_dirty ||
!equals_v2v2(DST.view_active->storage.viewport_size, &viewport[2])) {
drw_update_view(&viewport[2]);
DST.view_active->is_dirty = false;
DST.view_previous = DST.view_active;
}

View File

@@ -2,6 +2,10 @@
#ifndef GPU_SHADER
# include "GPU_shader_shared_utils.h"
typedef struct ViewInfos ViewInfos;
typedef struct ObjectMatrices ObjectMatrices;
typedef struct ObjectInfos ObjectInfos;
#endif
#define DRW_SHADER_SHARED_H
@@ -21,6 +25,14 @@ struct ViewInfos {
float4 viewvecs[2];
/* Should not be here. Not view dependent (only main view). */
float4 viewcamtexcofac;
float2 viewport_size;
float2 viewport_size_inverse;
/** Frustum culling data. */
/** NOTE: vec3 arrays are paded to vec4. */
float4 frustum_corners[8];
float4 frustum_planes[6];
};
BLI_STATIC_ASSERT_ALIGN(ViewInfos, 16)