diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2022-03-26 13:53:24 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2022-03-26 15:16:01 +0300 |
commit | 23bbc0d7481cefd746cd32bfa8526ecaea9bf71d (patch) | |
tree | 1469b0c8e2153b83c4bc90cf56fc29736e1aa364 | |
parent | 6073b6b874e4b5fa990153dfbaa04dac5d884094 (diff) |
DRW: Port draw_common.c to use shared definition with GLSL
-rw-r--r-- | source/blender/draw/CMakeLists.txt | 1 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_common.c | 7 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_common.h | 122 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_common_shader_shared.h | 245 | ||||
-rw-r--r-- | source/blender/draw/intern/shaders/draw_view_info.hh | 10 |
5 files changed, 262 insertions, 123 deletions
diff --git a/source/blender/draw/CMakeLists.txt b/source/blender/draw/CMakeLists.txt index 38ae9e86585..2a2335aa44c 100644 --- a/source/blender/draw/CMakeLists.txt +++ b/source/blender/draw/CMakeLists.txt @@ -190,6 +190,7 @@ set(SRC intern/draw_cache_inline.h intern/draw_color_management.h intern/draw_common.h + intern/draw_common_shader_shared.h intern/draw_debug.h intern/draw_hair_private.h intern/draw_instance_data.h diff --git a/source/blender/draw/intern/draw_common.c b/source/blender/draw/intern/draw_common.c index c7edf003346..462ae6f7cf1 100644 --- a/source/blender/draw/intern/draw_common.c +++ b/source/blender/draw/intern/draw_common.c @@ -184,9 +184,10 @@ void DRW_globals_update(void) gb->pixelFac = *DRW_viewport_pixelsize_get(); - copy_v2_v2(gb->sizeViewport, DRW_viewport_size_get()); - copy_v2_v2(gb->sizeViewportInv, gb->sizeViewport); - invert_v2(gb->sizeViewportInv); + /* Deprecated, use drw_view.viewport_size instead */ + copy_v2_v2(&gb->sizeViewport[0], DRW_viewport_size_get()); + copy_v2_v2(&gb->sizeViewport[2], &gb->sizeViewport[0]); + invert_v2(&gb->sizeViewport[2]); /* Color management. */ { diff --git a/source/blender/draw/intern/draw_common.h b/source/blender/draw/intern/draw_common.h index 53946c0cec5..e2dc91f64be 100644 --- a/source/blender/draw/intern/draw_common.h +++ b/source/blender/draw/intern/draw_common.h @@ -7,6 +7,8 @@ #pragma once +#include "draw_common_shader_shared.h" + struct DRWShadingGroup; struct FluidModifierData; struct GPUMaterial; @@ -16,126 +18,6 @@ struct ParticleSystem; struct RegionView3D; struct ViewLayer; -#define UBO_FIRST_COLOR colorWire -#define UBO_LAST_COLOR colorUVShadow - -/* Used as ubo but colors can be directly referenced as well */ -/* Keep in sync with: common_globals_lib.glsl (globalsBlock) */ -/* NOTE: Also keep all color as vec4 and between #UBO_FIRST_COLOR and #UBO_LAST_COLOR. */ -typedef struct GlobalsUboStorage { - /* UBOs data needs to be 16 byte aligned (size of vec4) */ - float colorWire[4]; - float colorWireEdit[4]; - float colorActive[4]; - float colorSelect[4]; - float colorLibrarySelect[4]; - float colorLibrary[4]; - float colorTransform[4]; - float colorLight[4]; - float colorSpeaker[4]; - float colorCamera[4]; - float colorCameraPath[4]; - float colorEmpty[4]; - float colorVertex[4]; - float colorVertexSelect[4]; - float colorVertexUnreferenced[4]; - float colorVertexMissingData[4]; - float colorEditMeshActive[4]; - float colorEdgeSelect[4]; - float colorEdgeSeam[4]; - float colorEdgeSharp[4]; - float colorEdgeCrease[4]; - float colorEdgeBWeight[4]; - float colorEdgeFaceSelect[4]; - float colorEdgeFreestyle[4]; - float colorFace[4]; - float colorFaceSelect[4]; - float colorFaceFreestyle[4]; - float colorGpencilVertex[4]; - float colorGpencilVertexSelect[4]; - float colorNormal[4]; - float colorVNormal[4]; - float colorLNormal[4]; - float colorFaceDot[4]; - float colorSkinRoot[4]; - - float colorDeselect[4]; - float colorOutline[4]; - float colorLightNoAlpha[4]; - - float colorBackground[4]; - float colorBackgroundGradient[4]; - float colorCheckerPrimary[4]; - float colorCheckerSecondary[4]; - float colorClippingBorder[4]; - float colorEditMeshMiddle[4]; - - float colorHandleFree[4]; - float colorHandleAuto[4]; - float colorHandleVect[4]; - float colorHandleAlign[4]; - float colorHandleAutoclamp[4]; - float colorHandleSelFree[4]; - float colorHandleSelAuto[4]; - float colorHandleSelVect[4]; - float colorHandleSelAlign[4]; - float colorHandleSelAutoclamp[4]; - float colorNurbUline[4]; - float colorNurbVline[4]; - float colorNurbSelUline[4]; - float colorNurbSelVline[4]; - float colorActiveSpline[4]; - - float colorBonePose[4]; - float colorBonePoseActive[4]; - float colorBonePoseActiveUnsel[4]; - float colorBonePoseConstraint[4]; - float colorBonePoseIK[4]; - float colorBonePoseSplineIK[4]; - float colorBonePoseTarget[4]; - float colorBoneSolid[4]; - float colorBoneLocked[4]; - float colorBoneActive[4]; - float colorBoneActiveUnsel[4]; - float colorBoneSelect[4]; - float colorBoneIKLine[4]; - float colorBoneIKLineNoTarget[4]; - float colorBoneIKLineSpline[4]; - - float colorText[4]; - float colorTextHi[4]; - - float colorBundleSolid[4]; - - float colorMballRadius[4]; - float colorMballRadiusSelect[4]; - float colorMballStiffness[4]; - float colorMballStiffnessSelect[4]; - - float colorCurrentFrame[4]; - - float colorGrid[4]; - float colorGridEmphasis[4]; - float colorGridAxisX[4]; - float colorGridAxisY[4]; - float colorGridAxisZ[4]; - - float colorFaceBack[4]; - float colorFaceFront[4]; - - float colorUVShadow[4]; - - /* NOTE: Put all color before #UBO_LAST_COLOR. */ - float screenVecs[2][4]; /* Padded as vec4. */ - float sizeViewport[2], sizeViewportInv[2]; /* Packed as vec4 in GLSL. */ - - /* Pack individual float at the end of the buffer to avoid alignment errors */ - float sizePixel, pixelFac; - float sizeObjectCenter, sizeLightCenter, sizeLightCircle, sizeLightCircleShadow; - float sizeVertex, sizeEdge, sizeEdgeFix, sizeFaceDot; - float sizeChecker; - float sizeVertexGpencil; -} GlobalsUboStorage; /* Keep in sync with globalsBlock in shaders */ BLI_STATIC_ASSERT_ALIGN(GlobalsUboStorage, 16) diff --git a/source/blender/draw/intern/draw_common_shader_shared.h b/source/blender/draw/intern/draw_common_shader_shared.h new file mode 100644 index 00000000000..c83af2eef84 --- /dev/null +++ b/source/blender/draw/intern/draw_common_shader_shared.h @@ -0,0 +1,245 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later + * Copyright 2022 Blender Foundation. */ + +/** \file + * \ingroup draw + */ + +#ifndef GPU_SHADER +# include "GPU_shader_shared_utils.h" + +typedef struct GlobalsUboStorage GlobalsUboStorage; +#endif + +/* Future Plan: These globals were once shared between multiple overlay engines. But now that they + * have been merged into one engine, there is no reasons to keep these globals out of the overlay + * engine. */ + +#define UBO_FIRST_COLOR colorWire +#define UBO_LAST_COLOR colorUVShadow + +/* Used as ubo but colors can be directly referenced as well */ +/* NOTE: Also keep all color as vec4 and between #UBO_FIRST_COLOR and #UBO_LAST_COLOR. */ +struct GlobalsUboStorage { + /* UBOs data needs to be 16 byte aligned (size of vec4) */ + float4 colorWire; + float4 colorWireEdit; + float4 colorActive; + float4 colorSelect; + float4 colorLibrarySelect; + float4 colorLibrary; + float4 colorTransform; + float4 colorLight; + float4 colorSpeaker; + float4 colorCamera; + float4 colorCameraPath; + float4 colorEmpty; + float4 colorVertex; + float4 colorVertexSelect; + float4 colorVertexUnreferenced; + float4 colorVertexMissingData; + float4 colorEditMeshActive; + float4 colorEdgeSelect; + float4 colorEdgeSeam; + float4 colorEdgeSharp; + float4 colorEdgeCrease; + float4 colorEdgeBWeight; + float4 colorEdgeFaceSelect; + float4 colorEdgeFreestyle; + float4 colorFace; + float4 colorFaceSelect; + float4 colorFaceFreestyle; + float4 colorGpencilVertex; + float4 colorGpencilVertexSelect; + float4 colorNormal; + float4 colorVNormal; + float4 colorLNormal; + float4 colorFaceDot; + float4 colorSkinRoot; + + float4 colorDeselect; + float4 colorOutline; + float4 colorLightNoAlpha; + + float4 colorBackground; + float4 colorBackgroundGradient; + float4 colorCheckerPrimary; + float4 colorCheckerSecondary; + float4 colorClippingBorder; + float4 colorEditMeshMiddle; + + float4 colorHandleFree; + float4 colorHandleAuto; + float4 colorHandleVect; + float4 colorHandleAlign; + float4 colorHandleAutoclamp; + float4 colorHandleSelFree; + float4 colorHandleSelAuto; + float4 colorHandleSelVect; + float4 colorHandleSelAlign; + float4 colorHandleSelAutoclamp; + float4 colorNurbUline; + float4 colorNurbVline; + float4 colorNurbSelUline; + float4 colorNurbSelVline; + float4 colorActiveSpline; + + float4 colorBonePose; + float4 colorBonePoseActive; + float4 colorBonePoseActiveUnsel; + float4 colorBonePoseConstraint; + float4 colorBonePoseIK; + float4 colorBonePoseSplineIK; + float4 colorBonePoseTarget; + float4 colorBoneSolid; + float4 colorBoneLocked; + float4 colorBoneActive; + float4 colorBoneActiveUnsel; + float4 colorBoneSelect; + float4 colorBoneIKLine; + float4 colorBoneIKLineNoTarget; + float4 colorBoneIKLineSpline; + + float4 colorText; + float4 colorTextHi; + + float4 colorBundleSolid; + + float4 colorMballRadius; + float4 colorMballRadiusSelect; + float4 colorMballStiffness; + float4 colorMballStiffnessSelect; + + float4 colorCurrentFrame; + + float4 colorGrid; + float4 colorGridEmphasis; + float4 colorGridAxisX; + float4 colorGridAxisY; + float4 colorGridAxisZ; + + float4 colorFaceBack; + float4 colorFaceFront; + + float4 colorUVShadow; + + /* NOTE: Put all color before #UBO_LAST_COLOR. */ + float4 screenVecs[2]; /* Padded as vec4. */ + float4 sizeViewport; /* Packed as vec4. */ + + /* Pack individual float at the end of the buffer to avoid alignment errors */ + float sizePixel, pixelFac; + float sizeObjectCenter, sizeLightCenter, sizeLightCircle, sizeLightCircleShadow; + float sizeVertex, sizeEdge, sizeEdgeFix, sizeFaceDot; + float sizeChecker; + float sizeVertexGpencil; +}; +BLI_STATIC_ASSERT_ALIGN(GlobalsUboStorage, 16) + +#ifdef GPU_SHADER +/* Keep compatibility_with old global scope syntax. */ +/* TODO(@fclem) Mass rename and remove the camel case. */ +# define colorWire drw_globals.colorWire +# define colorWireEdit drw_globals.colorWireEdit +# define colorActive drw_globals.colorActive +# define colorSelect drw_globals.colorSelect +# define colorLibrarySelect drw_globals.colorLibrarySelect +# define colorLibrary drw_globals.colorLibrary +# define colorTransform drw_globals.colorTransform +# define colorLight drw_globals.colorLight +# define colorSpeaker drw_globals.colorSpeaker +# define colorCamera drw_globals.colorCamera +# define colorCameraPath drw_globals.colorCameraPath +# define colorEmpty drw_globals.colorEmpty +# define colorVertex drw_globals.colorVertex +# define colorVertexSelect drw_globals.colorVertexSelect +# define colorVertexUnreferenced drw_globals.colorVertexUnreferenced +# define colorVertexMissingData drw_globals.colorVertexMissingData +# define colorEditMeshActive drw_globals.colorEditMeshActive +# define colorEdgeSelect drw_globals.colorEdgeSelect +# define colorEdgeSeam drw_globals.colorEdgeSeam +# define colorEdgeSharp drw_globals.colorEdgeSharp +# define colorEdgeCrease drw_globals.colorEdgeCrease +# define colorEdgeBWeight drw_globals.colorEdgeBWeight +# define colorEdgeFaceSelect drw_globals.colorEdgeFaceSelect +# define colorEdgeFreestyle drw_globals.colorEdgeFreestyle +# define colorFace drw_globals.colorFace +# define colorFaceSelect drw_globals.colorFaceSelect +# define colorFaceFreestyle drw_globals.colorFaceFreestyle +# define colorGpencilVertex drw_globals.colorGpencilVertex +# define colorGpencilVertexSelect drw_globals.colorGpencilVertexSelect +# define colorNormal drw_globals.colorNormal +# define colorVNormal drw_globals.colorVNormal +# define colorLNormal drw_globals.colorLNormal +# define colorFaceDot drw_globals.colorFaceDot +# define colorSkinRoot drw_globals.colorSkinRoot +# define colorDeselect drw_globals.colorDeselect +# define colorOutline drw_globals.colorOutline +# define colorLightNoAlpha drw_globals.colorLightNoAlpha +# define colorBackground drw_globals.colorBackground +# define colorBackgroundGradient drw_globals.colorBackgroundGradient +# define colorCheckerPrimary drw_globals.colorCheckerPrimary +# define colorCheckerSecondary drw_globals.colorCheckerSecondary +# define colorClippingBorder drw_globals.colorClippingBorder +# define colorEditMeshMiddle drw_globals.colorEditMeshMiddle +# define colorHandleFree drw_globals.colorHandleFree +# define colorHandleAuto drw_globals.colorHandleAuto +# define colorHandleVect drw_globals.colorHandleVect +# define colorHandleAlign drw_globals.colorHandleAlign +# define colorHandleAutoclamp drw_globals.colorHandleAutoclamp +# define colorHandleSelFree drw_globals.colorHandleSelFree +# define colorHandleSelAuto drw_globals.colorHandleSelAuto +# define colorHandleSelVect drw_globals.colorHandleSelVect +# define colorHandleSelAlign drw_globals.colorHandleSelAlign +# define colorHandleSelAutoclamp drw_globals.colorHandleSelAutoclamp +# define colorNurbUline drw_globals.colorNurbUline +# define colorNurbVline drw_globals.colorNurbVline +# define colorNurbSelUline drw_globals.colorNurbSelUline +# define colorNurbSelVline drw_globals.colorNurbSelVline +# define colorActiveSpline drw_globals.colorActiveSpline +# define colorBonePose drw_globals.colorBonePose +# define colorBonePoseActive drw_globals.colorBonePoseActive +# define colorBonePoseActiveUnsel drw_globals.colorBonePoseActiveUnsel +# define colorBonePoseConstraint drw_globals.colorBonePoseConstraint +# define colorBonePoseIK drw_globals.colorBonePoseIK +# define colorBonePoseSplineIK drw_globals.colorBonePoseSplineIK +# define colorBonePoseTarget drw_globals.colorBonePoseTarget +# define colorBoneSolid drw_globals.colorBoneSolid +# define colorBoneLocked drw_globals.colorBoneLocked +# define colorBoneActive drw_globals.colorBoneActive +# define colorBoneActiveUnsel drw_globals.colorBoneActiveUnsel +# define colorBoneSelect drw_globals.colorBoneSelect +# define colorBoneIKLine drw_globals.colorBoneIKLine +# define colorBoneIKLineNoTarget drw_globals.colorBoneIKLineNoTarget +# define colorBoneIKLineSpline drw_globals.colorBoneIKLineSpline +# define colorText drw_globals.colorText +# define colorTextHi drw_globals.colorTextHi +# define colorBundleSolid drw_globals.colorBundleSolid +# define colorMballRadius drw_globals.colorMballRadius +# define colorMballRadiusSelect drw_globals.colorMballRadiusSelect +# define colorMballStiffness drw_globals.colorMballStiffness +# define colorMballStiffnessSelect drw_globals.colorMballStiffnessSelect +# define colorCurrentFrame drw_globals.colorCurrentFrame +# define colorGrid drw_globals.colorGrid +# define colorGridEmphasis drw_globals.colorGridEmphasis +# define colorGridAxisX drw_globals.colorGridAxisX +# define colorGridAxisY drw_globals.colorGridAxisY +# define colorGridAxisZ drw_globals.colorGridAxisZ +# define colorFaceBack drw_globals.colorFaceBack +# define colorFaceFront drw_globals.colorFaceFront +# define colorUVShadow drw_globals.colorUVShadow +# define screenVecs drw_globals.screenVecs +# define sizeViewport drw_globals.sizeViewport +# define sizePixel drw_globals.sizePixel +# define pixelFac drw_globals.pixelFac +# define sizeObjectCenter drw_globals.sizeObjectCenter +# define sizeLightCenter drw_globals.sizeLightCenter +# define sizeLightCircle drw_globals.sizeLightCircle +# define sizeLightCircleShadow drw_globals.sizeLightCircleShadow +# define sizeVertex drw_globals.sizeVertex +# define sizeEdge drw_globals.sizeEdge +# define sizeEdgeFix drw_globals.sizeEdgeFix +# define sizeFaceDot drw_globals.sizeFaceDot +# define sizeChecker drw_globals.sizeChecker +# define sizeVertexGpencil drw_globals.sizeVertexGpencil +#endif diff --git a/source/blender/draw/intern/shaders/draw_view_info.hh b/source/blender/draw/intern/shaders/draw_view_info.hh index a699b9013ef..ba43938cbc0 100644 --- a/source/blender/draw/intern/shaders/draw_view_info.hh +++ b/source/blender/draw/intern/shaders/draw_view_info.hh @@ -75,6 +75,16 @@ GPU_SHADER_CREATE_INFO(drw_clipped).define("USE_WORLD_CLIP_PLANES"); /** \} */ /* -------------------------------------------------------------------- */ +/** \name Draw Globals + * \{ */ + +GPU_SHADER_CREATE_INFO(draw_globals) + .typedef_source("draw_common_shader_shared.h") + .uniform_buf(1, "ObjectMatrices", "drw_globals", Frequency::PASS); + +/** \} */ + +/* -------------------------------------------------------------------- */ /** \name Geometry Type * \{ */ |