Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
GUISplash.cpp
Go to the documentation of this file.
1
2
3#include "Headers/GUISplash.h"
4
11
12namespace Divide {
13
14GUISplash::GUISplash(const std::string_view splashImageName, vec2<U16> dimensions)
15 : _dimensions(MOV(dimensions))
16{
17 TextureDescriptor textureDescriptor{};
18 textureDescriptor._textureOptions._alphaChannelTransparency = false;
19
20 ResourceDescriptor<Texture> splashImage("SplashScreen Texture", textureDescriptor);
21 splashImage.assetName(splashImageName);
22 splashImage.assetLocation(Paths::g_imagesLocation);
23 _splashImage = CreateResource(splashImage);
24
25 ShaderModuleDescriptor vertModule = {};
27 vertModule._sourceFile = "baseVertexShaders.glsl";
28 vertModule._variant = "FullScreenQuad";
29
30 ShaderModuleDescriptor fragModule = {};
32 fragModule._sourceFile = "fbPreview.glsl";
33
34 ShaderProgramDescriptor shaderDescriptor = {};
35 shaderDescriptor._modules.push_back(vertModule);
36 shaderDescriptor._modules.push_back(fragModule);
37
38 ResourceDescriptor<ShaderProgram> splashShader("fbPreview", shaderDescriptor);
39 _splashShader = CreateResource(splashShader);
40
41 _uniformData.set( _ID( "lodLevel" ), PushConstantType::FLOAT, 1.f );
42 _uniformData.set( _ID( "channelsArePacked" ), PushConstantType::BOOL, false );
43 _uniformData.set( _ID( "channelCount" ), PushConstantType::UINT, 4u );
44 _uniformData.set( _ID( "startChannel" ), PushConstantType::UINT, 0u );
45 _uniformData.set( _ID( "multiplier" ), PushConstantType::FLOAT, 1.f );
46}
47
49{
51}
52
54{
55
56 SamplerDescriptor splashSampler = {};
57 splashSampler._wrapU = TextureWrap::CLAMP_TO_EDGE;
58 splashSampler._wrapV = TextureWrap::CLAMP_TO_EDGE;
59 splashSampler._wrapW = TextureWrap::CLAMP_TO_EDGE;
60 splashSampler._minFilter = TextureFilter::LINEAR;
61 splashSampler._magFilter = TextureFilter::LINEAR;
63 splashSampler._anisotropyLevel = 0u;
64
65
66 PipelineDescriptor pipelineDescriptor;
67 pipelineDescriptor._stateBlock = context.get2DStateBlock();
68 pipelineDescriptor._shaderProgramHandle = _splashShader;
70
71 Handle<GFX::CommandBuffer> handle = GFX::AllocateCommandBuffer("Splash Screen", 16u);
72 GFX::CommandBuffer& buffer = *GFX::Get(handle);
73
74 GFX::BeginRenderPassCommand beginRenderPassCmd{};
75 beginRenderPassCmd._target = SCREEN_TARGET_ID;
76 beginRenderPassCmd._name = "BLIT_TO_BACKBUFFER";
77 beginRenderPassCmd._descriptor._drawMask[to_base( RTColourAttachmentSlot::SLOT_0 )] = true;
78 GFX::EnqueueCommand( buffer, beginRenderPassCmd);
79
80 GFX::BindPipelineCommand pipelineCmd;
81 pipelineCmd._pipeline = context.newPipeline(pipelineDescriptor);
82 GFX::EnqueueCommand( buffer, pipelineCmd);
83
84 GFX::EnqueueCommand<GFX::SendPushConstantsCommand>( buffer )->_uniformData = &_uniformData;
85
86 GFX::SetViewportCommand viewportCommand;
87 viewportCommand._viewport.set(0, 0, _dimensions.width, _dimensions.height);
88 GFX::EnqueueCommand( buffer, viewportCommand);
89
92
93 auto cmd = GFX::EnqueueCommand<GFX::BindShaderResourcesCommand>( buffer );
94 cmd->_usage = DescriptorSetUsage::PER_DRAW;
95
97 Set( binding._data, _splashImage, splashSampler );
98
99 GFX::EnqueueCommand<GFX::DrawCommand>( buffer )->_drawCommands.emplace_back();
100
101 GFX::EnqueueCommand<GFX::EndRenderPassCommand>( buffer );
102
103 context.flushCommandBuffer( MOV( handle ) );
104}
105
106}; //namespace Divide
#define MOV(...)
Rough around the edges Adapter pattern abstracting the actual rendering API and access to the GPU.
Definition: GFXDevice.h:215
Pipeline * newPipeline(const PipelineDescriptor &descriptor)
Create and return a new graphics pipeline. This is only used for caching and doesn't use the object a...
Definition: GFXDevice.cpp:3074
const RenderStateBlock & get2DStateBlock() const noexcept
Definition: GFXDevice.inl:123
void flushCommandBuffer(Handle< GFX::CommandBuffer > &&commandBuffer)
Definition: GFXDevice.cpp:2120
void render(GFXDevice &context)
Definition: GUISplash.cpp:53
vec2< U16 > _dimensions
Definition: GUISplash.h:55
Handle< Texture > _splashImage
Definition: GUISplash.h:56
UniformData _uniformData
Definition: GUISplash.h:58
Handle< ShaderProgram > _splashShader
Definition: GUISplash.h:57
GUISplash(std::string_view splashImageName, vec2< U16 > dimensions)
Definition: GUISplash.cpp:14
void set(const T *v) noexcept
set the 4 components of the vector manually using a source pointer to a (large enough) array
Definition: MathVectors.h:1241
CommandBuffer * Get(Handle< CommandBuffer > handle)
FORCE_INLINE T * EnqueueCommand(CommandBuffer &buffer)
Handle< CommandBuffer > AllocateCommandBuffer(const char *name, const size_t reservedCmdCount)
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
FORCE_INLINE void DestroyResource(Handle< T > &handle, const bool immediate=false)
constexpr RenderTargetID SCREEN_TARGET_ID
void WaitForReady(Resource *res)
Definition: Resource.cpp:27
void Set(DescriptorSetBindingData &dataInOut, ShaderBuffer *buffer, const BufferRange range) noexcept
constexpr U64 _ID(const char *const str, const U64 value=val_64_const) noexcept
DescriptorSetBinding & AddBinding(DescriptorSet &setInOut, U8 slot, U16 stageVisibilityMask)
FORCE_INLINE Handle< T > CreateResource(const ResourceDescriptor< T > &descriptor, bool &wasInCache, std::atomic_uint &taskCounter)
FORCE_INLINE T * Get(const Handle< T > handle)
constexpr auto to_base(const Type value) -> Type
DescriptorSetBindingData _data
bool _alphaChannelTransparency
If false, the alpha channel represents arbitrary data (e.g. in splatmaps)
Definition: ImageToolsFwd.h:72
PrimitiveTopology _primitiveTopology
Definition: Pipeline.h:48
Handle< ShaderProgram > _shaderProgramHandle
Definition: Pipeline.h:47
RenderStateBlock _stateBlock
Definition: Pipeline.h:46
vector< ShaderModuleDescriptor > _modules
ImageTools::ImportOptions _textureOptions
TextureFilter _minFilter
Texture filtering mode.
TextureWrap _wrapU
Texture wrap mode (Or S-R-T)
U8 _anisotropyLevel
The value must be in the range [0...255] and is automatically clamped by the max HW supported level.
TextureMipSampling _mipSampling
void set(U64 bindingHash, PushConstantType type, const T &value)