Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
IMPrimitive.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2018 DIVIDE-Studio
3 Copyright (c) 2009 Ionut Cava
4
5 This file is part of DIVIDE Framework.
6
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software
9 and associated documentation files (the "Software"), to deal in the Software
10 without restriction,
11 including without limitation the rights to use, copy, modify, merge, publish,
12 distribute, sublicense,
13 and/or sell copies of the Software, and to permit persons to whom the
14 Software is furnished to do so,
15 subject to the following conditions:
16
17 The above copyright notice and this permission notice shall be included in
18 all copies or substantial portions of the Software.
19
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 IMPLIED,
22 INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23 PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25 DAMAGES OR OTHER LIABILITY,
26 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
27 IN CONNECTION WITH THE SOFTWARE
28 OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
30 */
31
32#pragma once
33#ifndef DVD_IM_EMULATION_H_
34#define DVD_IM_EMULATION_H_
35
37#include "DescriptorSetsFwd.h"
38#include "Pipeline.h"
39#include "PushConstants.h"
42
43namespace NS_GLIM {
45}
46
47namespace Divide {
48
49namespace GFX {
50 class CommandBuffer;
51};
52
53class GFXDevice;
56
58class IMPrimitive final {
59 public:
60
61 public:
62 static void InitStaticData();
63
64 public:
65 IMPrimitive(GFXDevice& context, const Str<64>& name);
66 ~IMPrimitive() = default;
67
68 void setPushConstants(const PushConstantsStruct& fastData);
69 void setUniformData(const UniformData& constants);
70 void setUniformDataAndConstants(const UniformData& constants, const PushConstantsStruct& fastData);
71
72 void setPipelineDescriptor(const PipelineDescriptor& descriptor);
73 void setTexture(const ImageView& texture, SamplerDescriptor sampler);
74
75 void begin(PrimitiveTopology type);
76 void end();
77
78 void beginBatch(bool reserveBuffers, U32 vertexCount, U32 attributeCount);
79 void endBatch() noexcept;
80
81 void clearBatch();
82 bool hasBatch() const noexcept;
83 void reset();
84
85 void vertex(F32 x, F32 y, F32 z);
86 void attribute1i(U32 attribLocation, I32 value);
87 void attribute1f(U32 attribLocation, F32 value);
88 void attribute2f(U32 attribLocation, vec2<F32> value);
89 void attribute3f(U32 attribLocation, vec3<F32> value);
90 void attribute4ub(U32 attribLocation, U8 x, U8 y, U8 z, U8 w);
91 void attribute4f(U32 attribLocation, F32 x, F32 y, F32 z, F32 w);
92 inline void vertex(const vec3<F32>& vert) { vertex(vert.x, vert.y, vert.z); }
93 inline void attribute4ub(const U32 attribLocation, const vec4<U8> value) { attribute4ub(attribLocation, value.x, value.y, value.z, value.w); }
94 inline void attribute4f(const U32 attribLocation, const vec4<F32>& value) { attribute4f(attribLocation, value.x, value.y, value.z, value.w); }
95
96 void fromLines(const IM::LineDescriptor& lines);
97 void fromLines(const IM::LineDescriptor* lines, size_t count);
98
99 void fromFrustum(const IM::FrustumDescriptor& frustum);
100 void fromFrustums(const IM::FrustumDescriptor* frustums, size_t count);
101
102 void fromOBB(const IM::OBBDescriptor& box);
103 void fromOBBs(const IM::OBBDescriptor* boxes, size_t count);
104
105 void fromBox(const IM::BoxDescriptor& box);
106 void fromBoxes(const IM::BoxDescriptor* boxes, size_t count);
107 void fromSphere(const IM::SphereDescriptor& sphere);
108 void fromSpheres(const IM::SphereDescriptor* spheres, size_t count);
109 void fromCone(const IM::ConeDescriptor& cone);
110 void fromCones(const IM::ConeDescriptor* cones, size_t count);
111 void fromLines(const Line* lines, size_t count);
112
113 template<size_t N>
114 inline void fromLines(const std::array<IM::LineDescriptor, N>& lines) { fromLines(lines.data(), lines.size()); }
115 template<size_t N>
116 inline void fromOBBs(const std::array<IM::OBBDescriptor, N>& obbs) { fromOBBs(obbs.data(), obbs.size()); }
117 template<size_t N>
118 inline void fromBoxes(const std::array<IM::BoxDescriptor, N>& boxes) { fromBoxes(boxes.data(), boxes.size()); }
119 template<size_t N>
120 inline void fromSpheres(const std::array<IM::SphereDescriptor, N>& spheres) { fromSpheres(spheres.data(), spheres.size()); }
121 template<size_t N>
122 inline void fromCones(const std::array<IM::ConeDescriptor, N>& cones) { fromCones(cones.data(), cones.size()); }
123
124 void getCommandBuffer(GFX::CommandBuffer& commandBufferInOut, GFX::MemoryBarrierCommand& memCmdInOut);
125 void getCommandBuffer(const mat4<F32>& worldMatrix, GFX::CommandBuffer& commandBufferInOut, GFX::MemoryBarrierCommand& memCmdInOut);
126
128 PROPERTY_RW(bool, forceWireframe, false);
129
130 protected:
131 template <typename Data, size_t N>
133 friend void DestroyIMP(IMPrimitive*&);
134
135 [[nodiscard]] inline GFXDevice& context() noexcept { return _context; }
136
137 private:
138 void fromLinesInternal(const Line* lines, size_t count);
139
140 private:
144 NS_GLIM::GLIM_BATCH_uptr _imInterface;
152 GenericVertexData_ptr _dataBuffer = nullptr;
153
155};
156
157}; // namespace Divide
158
159#endif //DVD_IM_EMULATION_H_
#define FWD_DECLARE_MANAGED_CLASS(T)
Rough around the edges Adapter pattern abstracting the actual rendering API and access to the GPU.
Definition: GFXDevice.h:215
IMPrimitive replaces immediate mode calls to VB based rendering.
Definition: IMPrimitive.h:58
void attribute1f(U32 attribLocation, F32 value)
void getCommandBuffer(GFX::CommandBuffer &commandBufferInOut, GFX::MemoryBarrierCommand &memCmdInOut)
void beginBatch(bool reserveBuffers, U32 vertexCount, U32 attributeCount)
Definition: IMPrimitive.cpp:96
GFX::MemoryBarrierCommand _memCmd
Definition: IMPrimitive.h:154
~IMPrimitive()=default
void attribute4ub(U32 attribLocation, U8 x, U8 y, U8 z, U8 w)
void fromCones(const std::array< IM::ConeDescriptor, N > &cones)
Definition: IMPrimitive.h:122
void setUniformData(const UniformData &constants)
void vertex(F32 x, F32 y, F32 z)
bool hasBatch() const noexcept
friend void DestroyIMP(IMPrimitive *&)
Definition: GFXDevice.cpp:3092
void fromOBB(const IM::OBBDescriptor &box)
void fromOBBs(const std::array< IM::OBBDescriptor, N > &obbs)
Definition: IMPrimitive.h:116
PushConstantsStruct _fastData
Definition: IMPrimitive.h:143
GFXDevice & context() noexcept
Definition: IMPrimitive.h:135
std::array< size_t, to_base(NS_GLIM::GLIM_BUFFER_TYPE::COUNT)> _indexCount
Definition: IMPrimitive.h:149
GenericVertexData_ptr _dataBuffer
Definition: IMPrimitive.h:152
void attribute1i(U32 attribLocation, I32 value)
PROPERTY_R(Str< 64 >, name)
UniformData _additionalUniforms
Definition: IMPrimitive.h:142
void fromSpheres(const std::array< IM::SphereDescriptor, N > &spheres)
Definition: IMPrimitive.h:120
void fromLinesInternal(const Line *lines, size_t count)
void fromSpheres(const IM::SphereDescriptor *spheres, size_t count)
void fromCones(const IM::ConeDescriptor *cones, size_t count)
void fromOBBs(const IM::OBBDescriptor *boxes, size_t count)
NS_GLIM::GLIM_BATCH_uptr _imInterface
Definition: IMPrimitive.h:144
std::array< bool, to_base(NS_GLIM::GLIM_BUFFER_TYPE::COUNT)> _drawFlags
Definition: IMPrimitive.h:148
void attribute4f(const U32 attribLocation, const vec4< F32 > &value)
Definition: IMPrimitive.h:94
void setPipelineDescriptor(const PipelineDescriptor &descriptor)
void fromFrustums(const IM::FrustumDescriptor *frustums, size_t count)
void fromBox(const IM::BoxDescriptor &box)
void fromCone(const IM::ConeDescriptor &cone)
void fromLines(const std::array< IM::LineDescriptor, N > &lines)
Definition: IMPrimitive.h:114
void attribute4f(U32 attribLocation, F32 x, F32 y, F32 z, F32 w)
void fromBoxes(const IM::BoxDescriptor *boxes, size_t count)
void fromLines(const IM::LineDescriptor &lines)
std::array< Pipeline *, to_base(NS_GLIM::GLIM_BUFFER_TYPE::COUNT)> _pipelines
Definition: IMPrimitive.h:150
void attribute3f(U32 attribLocation, vec3< F32 > value)
void attribute2f(U32 attribLocation, vec2< F32 > value)
SamplerDescriptor _sampler
Definition: IMPrimitive.h:147
void fromFrustum(const IM::FrustumDescriptor &frustum)
static void InitStaticData()
Definition: IMPrimitive.cpp:55
void setPushConstants(const PushConstantsStruct &fastData)
std::array< U8, to_base(NS_GLIM::GLIM_BUFFER_TYPE::COUNT)> _indexBufferId
Definition: IMPrimitive.h:151
void fromBoxes(const std::array< IM::BoxDescriptor, N > &boxes)
Definition: IMPrimitive.h:118
void setTexture(const ImageView &texture, SamplerDescriptor sampler)
PipelineDescriptor _basePipelineDescriptor
Definition: IMPrimitive.h:145
PROPERTY_RW(bool, forceWireframe, false)
GFXDevice & _context
Definition: IMPrimitive.h:141
void setUniformDataAndConstants(const UniformData &constants, const PushConstantsStruct &fastData)
void begin(PrimitiveTopology type)
void endBatch() noexcept
void attribute4ub(const U32 attribLocation, const vec4< U8 > value)
Definition: IMPrimitive.h:93
void fromSphere(const IM::SphereDescriptor &sphere)
void vertex(const vec3< F32 > &vert)
Definition: IMPrimitive.h:92
An Implementation of the GLIM_Interface.
Definition: glimBatch.h:16
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
int32_t I32
uint8_t U8
uint32_t U32
constexpr auto to_base(const Type value) -> Type