| 1 | #pragma once |
| 2 | |
| 3 | #include <nn/gfx/detail/gfx_DataContainer.h> |
| 4 | #include <nn/gfx/gfx_Common.h> |
| 5 | #include <nn/gfx/gfx_Enum.h> |
| 6 | #include <nn/gfx/gfx_StateInfoData.h> |
| 7 | |
| 8 | namespace nn::gfx { |
| 9 | |
| 10 | class MultisampleStateInfo : public detail::DataContainer<MultisampleStateInfoData> { |
| 11 | public: |
| 12 | MultisampleStateInfo() {} |
| 13 | |
| 14 | void SetDefault(); |
| 15 | |
| 16 | void SetSampleCount(int count) { sampleCount = count; } |
| 17 | void SetSampleMask(int mask) { sampleMask = mask; } |
| 18 | void SetAlphaToCoverageEnabled(bool alpha) { flag.SetBit(p: Flag_AlphaToCoverageEnable, on: alpha); } |
| 19 | |
| 20 | bool IsAlphaToCoverageEnabled() const { return flag.GetBit(p: Flag_AlphaToCoverageEnable); } |
| 21 | int GetSampleCount() const { return sampleCount; } |
| 22 | int GetSampleMask() const { return sampleMask; } |
| 23 | }; |
| 24 | |
| 25 | class RasterizerStateInfo : public detail::DataContainer<RasterizerStateInfoData> { |
| 26 | public: |
| 27 | RasterizerStateInfo() {} |
| 28 | |
| 29 | void SetDefault(); |
| 30 | |
| 31 | void SetFillMode(FillMode fill) { fillMode = fill; } |
| 32 | void SetFrontFace(FrontFace face) { frontFace = face; } |
| 33 | void SetCullMode(CullMode cull) { cullMode = cull; } |
| 34 | void SetPrimitiveTopologyType(PrimitiveTopologyType type) { primitiveTopologyType = type; } |
| 35 | void SetRasterEnabled(bool b) { flag.SetBit(p: Flag_RasterDisable, on: !b); } |
| 36 | void SetMultisampleEnabled(bool b) { flag.SetBit(p: Flag_MultisampleEnable, on: b); } |
| 37 | void SetDepthClipEnabled(bool b) { flag.SetBit(p: Flag_DepthClipDisable, on: !b); } |
| 38 | void SetScissorEnabled(bool b) { flag.SetBit(p: Flag_ScissorEnable, on: b); } |
| 39 | void SetSlopeScaledDepthBias(float bias) { slopeScaledDepthBias = bias; } |
| 40 | void SetDepthBias(int bias) { depthBias = bias; } |
| 41 | void SetDepthBiasClamp(float clamp) { depthBiasClamp = clamp; } |
| 42 | |
| 43 | void SetConservativeRasterizationMode(ConservativeRasterizationMode mode) { |
| 44 | conservativeRasterizationMode = mode; |
| 45 | } |
| 46 | |
| 47 | MultisampleStateInfo& EditMultisampleStateInfo() { |
| 48 | return nn::gfx::DataToAccessor(data&: multisample); |
| 49 | } |
| 50 | |
| 51 | FillMode GetFillMode() const { return static_cast<FillMode>(fillMode); } |
| 52 | FrontFace GetFrontFace() const { return static_cast<FrontFace>(frontFace); } |
| 53 | CullMode GetCullMode() const { return static_cast<CullMode>(cullMode); } |
| 54 | |
| 55 | PrimitiveTopologyType GetPrimitiveTopologyType() const { |
| 56 | return static_cast<PrimitiveTopologyType>(primitiveTopologyType); |
| 57 | } |
| 58 | |
| 59 | bool IsRasterEnabled() const { return !flag.GetBit(p: Flag_RasterDisable); } |
| 60 | bool IsMultisampleEnabled() const { return flag.GetBit(p: Flag_MultisampleEnable); } |
| 61 | bool IsDepthClipEnabled() const { return !flag.GetBit(p: Flag_DepthClipDisable); } |
| 62 | bool IsScissorEnabled() const { return flag.GetBit(p: Flag_ScissorEnable); } |
| 63 | float GetSlopeScaledDepthBias() const { return slopeScaledDepthBias; } |
| 64 | int GetDepthBias() const { return depthBias; } |
| 65 | float GetDepthBiasClamp() const { return depthBiasClamp; } |
| 66 | |
| 67 | ConservativeRasterizationMode GetConservativeRasterizationMode() const { |
| 68 | return static_cast<ConservativeRasterizationMode>(conservativeRasterizationMode); |
| 69 | } |
| 70 | |
| 71 | const MultisampleStateInfo& GetMultisampleStateInfo() const { |
| 72 | return nn::gfx::DataToAccessor(data: multisample); |
| 73 | } |
| 74 | }; |
| 75 | |
| 76 | class BlendTargetStateInfo : public detail::DataContainer<BlendTargetStateInfoData> { |
| 77 | public: |
| 78 | BlendTargetStateInfo(); |
| 79 | void SetDefault(); |
| 80 | |
| 81 | void SetBlendEnabled(bool b) { flag.SetBit(p: Flag_BlendEnable, on: b); } |
| 82 | void SetSourceColorBlendFactor(BlendFactor factor) { sourceColorBlendFactor = factor; } |
| 83 | |
| 84 | void SetDestinationColorBlendFactor(BlendFactor factor) { |
| 85 | destinationColorBlendFactor = factor; |
| 86 | } |
| 87 | |
| 88 | void SetColorBlendFunction(BlendFunction function) { colorBlendFunction = function; } |
| 89 | void SetSourceAlphaBlendFactor(BlendFactor factor) { sourceAlphaBlendFactor = factor; } |
| 90 | |
| 91 | void SetDestinationAlphaBlendFactor(BlendFactor factor) { |
| 92 | destinationAlphaBlendFactor = factor; |
| 93 | } |
| 94 | |
| 95 | void SetAlphaBlendFunction(BlendFunction function) { alphaBlendFunction = function; } |
| 96 | void SetChannelMask(int mask) { channelMask = mask; } |
| 97 | |
| 98 | bool IsBlendEnabled() const { return flag.GetBit(p: Flag_BlendEnable); } |
| 99 | |
| 100 | BlendFactor GetSourceColorBlendFactor() const { |
| 101 | return static_cast<BlendFactor>(sourceColorBlendFactor); |
| 102 | } |
| 103 | |
| 104 | BlendFactor GetDestinationColorBlendFactor() const { |
| 105 | return static_cast<BlendFactor>(destinationColorBlendFactor); |
| 106 | } |
| 107 | |
| 108 | BlendFunction GetColorBlendFunction() const { |
| 109 | return static_cast<BlendFunction>(colorBlendFunction); |
| 110 | } |
| 111 | |
| 112 | BlendFactor GetSourceAlphaBlendFactor() const { |
| 113 | return static_cast<BlendFactor>(sourceAlphaBlendFactor); |
| 114 | } |
| 115 | |
| 116 | BlendFactor GetDestinationAlphaBlendFactor() const { |
| 117 | return static_cast<BlendFactor>(destinationAlphaBlendFactor); |
| 118 | } |
| 119 | |
| 120 | BlendFunction GetAlphaBlendFunction() const { |
| 121 | return static_cast<BlendFunction>(alphaBlendFunction); |
| 122 | } |
| 123 | |
| 124 | int GetChannelMask() const { return channelMask; } |
| 125 | }; |
| 126 | |
| 127 | class BlendStateInfo : public detail::DataContainer<BlendStateInfoData> { |
| 128 | public: |
| 129 | BlendStateInfo() {} |
| 130 | |
| 131 | void SetDefault(); |
| 132 | |
| 133 | void SetLogicOperation(LogicOperation op) { logicOperation = op; } |
| 134 | void SetAlphaToCoverageEnabled(bool b) { flag.SetBit(p: Flag_AlphaToCoverageEnable, on: b); } |
| 135 | void SetDualSourceBlendEnabled(bool b) { flag.SetBit(p: Flag_DualSourceBlendEnable, on: b); } |
| 136 | void SetIndependentBlendEnabled(bool b) { flag.SetBit(p: Flag_IndependentBlendEnable, on: b); } |
| 137 | void SetLogicOperationEnabled(bool b) { flag.SetBit(p: Flag_LogicOperationEnable, on: b); } |
| 138 | |
| 139 | void SetBlendConstant(float r, float g, float b, float alpha) { |
| 140 | blendConstant[0] = r; |
| 141 | blendConstant[1] = g; |
| 142 | blendConstant[2] = b; |
| 143 | blendConstant[3] = alpha; |
| 144 | } |
| 145 | |
| 146 | void SetBlendTargetStateInfoArray(const BlendTargetStateInfo* p, int c) { |
| 147 | blendTargetCount = c; |
| 148 | pBlendTargetArray.ptr = p->ToData(); |
| 149 | } |
| 150 | |
| 151 | int GetBlendTargetCount() const { return blendTargetCount; } |
| 152 | LogicOperation GetLogicOperation() const { return static_cast<LogicOperation>(logicOperation); } |
| 153 | bool IsAlphaToCoverageEnabled() const { return flag.GetBit(p: Flag_AlphaToCoverageEnable); } |
| 154 | bool IsDualSourceBlendEnabled() const { return flag.GetBit(p: Flag_DualSourceBlendEnable); } |
| 155 | bool IsIndependentBlendEnabled() const { return flag.GetBit(p: Flag_IndependentBlendEnable); } |
| 156 | bool IsLogicOperationEnabled() const { return flag.GetBit(p: Flag_LogicOperationEnable); } |
| 157 | float GetBlendConstant(ColorChannel channel) const { return blendConstant[channel]; } |
| 158 | |
| 159 | const BlendTargetStateInfo* GetBlendTargetStateInfoArray() const { |
| 160 | return nn::gfx::DataToAccessor(data: pBlendTargetArray.ptr); |
| 161 | } |
| 162 | }; |
| 163 | |
| 164 | class StencilStateInfo : public detail::DataContainer<StencilStateInfoData> { |
| 165 | public: |
| 166 | StencilStateInfo() {} |
| 167 | |
| 168 | void SetDefault(); |
| 169 | |
| 170 | void SetStencilFailOperation(StencilOperation op) { stencilFailOperation = op; } |
| 171 | void SetDepthFailOperation(StencilOperation op) { depthFailOperation = op; } |
| 172 | void SetDepthPassOperation(StencilOperation op) { depthPassOperation = op; } |
| 173 | void SetComparisonFunction(ComparisonFunction function) { comparisonFunction = function; } |
| 174 | void SetStencilRef(int ref) { stencilRef = ref; } |
| 175 | |
| 176 | StencilOperation GetStencilFailOperation() const { |
| 177 | return static_cast<StencilOperation>(stencilFailOperation); |
| 178 | } |
| 179 | |
| 180 | StencilOperation GetDepthFailOperation() const { |
| 181 | return static_cast<StencilOperation>(depthFailOperation); |
| 182 | } |
| 183 | |
| 184 | StencilOperation GetDepthPassOperation() const { |
| 185 | return static_cast<StencilOperation>(depthPassOperation); |
| 186 | } |
| 187 | |
| 188 | ComparisonFunction GetComparisonFunction() const { |
| 189 | return static_cast<ComparisonFunction>(comparisonFunction); |
| 190 | } |
| 191 | |
| 192 | int GetStencilRef() const { return stencilRef; } |
| 193 | }; |
| 194 | |
| 195 | class DepthStencilStateInfo : public detail::DataContainer<DepthStencilStateInfoData> { |
| 196 | public: |
| 197 | DepthStencilStateInfo() {} |
| 198 | |
| 199 | void SetDefault(); |
| 200 | |
| 201 | void SetDepthComparisonFunction(ComparisonFunction function) { |
| 202 | depthComparisonFunction = function; |
| 203 | } |
| 204 | |
| 205 | void SetDepthTestEnabled(bool b) { flag.SetBit(p: Flag_DepthTestEnable, on: b); } |
| 206 | void SetDepthWriteEnabled(bool b) { flag.SetBit(p: Flag_DepthWriteEnable, on: b); } |
| 207 | void SetStencilTestEnabled(bool b) { flag.SetBit(p: Flag_StencilTestEnable, on: b); } |
| 208 | void SetDepthBoundsTestEnabled(bool b) { flag.SetBit(p: Flag_DepthBoundsTestEnable, on: b); } |
| 209 | void SetStencilReadMask(int mask) { stencilReadMask = mask; } |
| 210 | void SetStencilWriteMask(int mask) { stencilWriteMask = mask; } |
| 211 | StencilStateInfo& EditFrontStencilStateInfo() { return nn::gfx::DataToAccessor(data&: frontStencil); } |
| 212 | StencilStateInfo& EditBackStencilStateInfo() { return nn::gfx::DataToAccessor(data&: backStencil); } |
| 213 | |
| 214 | ComparisonFunction GetDepthComparisonFunction() const { |
| 215 | return static_cast<ComparisonFunction>(depthComparisonFunction); |
| 216 | } |
| 217 | |
| 218 | bool IsDepthTestEnabled() const { return flag.GetBit(p: Flag_DepthTestEnable); } |
| 219 | bool IsDepthWriteEnabled() const { return flag.GetBit(p: Flag_DepthWriteEnable); } |
| 220 | bool IsStencilTestEnabled() const { return flag.GetBit(p: Flag_StencilTestEnable); } |
| 221 | bool IsDepthBoundsTestEnabled() const { return flag.GetBit(p: Flag_DepthBoundsTestEnable); } |
| 222 | int GetStencilReadMask() const { return stencilReadMask; } |
| 223 | int GetStencilWriteMask() const { return stencilWriteMask; } |
| 224 | |
| 225 | const StencilStateInfo& GetFrontStencilStateInfo() const { |
| 226 | return nn::gfx::DataToAccessor(data: frontStencil); |
| 227 | } |
| 228 | |
| 229 | const StencilStateInfo& GetBackStencilStateInfo() const { |
| 230 | return nn::gfx::DataToAccessor(data: backStencil); |
| 231 | } |
| 232 | }; |
| 233 | |
| 234 | class ColorTargetStateInfo : public detail::DataContainer<ColorTargetStateInfoData> { |
| 235 | public: |
| 236 | ColorTargetStateInfo() {} |
| 237 | |
| 238 | void SetDefault(); |
| 239 | |
| 240 | void SetFormat(ImageFormat value) { format = value; } |
| 241 | ImageFormat GetFormat() const { return static_cast<ImageFormat>(format); } |
| 242 | }; |
| 243 | |
| 244 | class RenderTargetStateInfo : public detail::DataContainer<RenderTargetStateInfoData> { |
| 245 | public: |
| 246 | RenderTargetStateInfo() {} |
| 247 | |
| 248 | void SetDefault(); |
| 249 | |
| 250 | void SetDepthStencilFormat(ImageFormat value) { depthStencilFormat = value; } |
| 251 | void SetColorTargetStateInfoArray(const ColorTargetStateInfo* pColorTargetStateInfoArray, |
| 252 | int colorTargetStateCount) { |
| 253 | pColorTargetStateArray.ptr = pColorTargetStateInfoArray->ToData(); |
| 254 | colorTargetCount = colorTargetStateCount; |
| 255 | } |
| 256 | |
| 257 | ImageFormat GetDepthStencilFormat() const { |
| 258 | return static_cast<ImageFormat>(depthStencilFormat); |
| 259 | } |
| 260 | |
| 261 | int GetColorTargetCount() const { return colorTargetCount; } |
| 262 | |
| 263 | const ColorTargetStateInfo* GetColorTargetStateInfoArray() const { |
| 264 | return nn::gfx::DataToAccessor(data: pColorTargetStateArray.ptr); |
| 265 | } |
| 266 | }; |
| 267 | |
| 268 | class VertexAttributeStateInfo : public detail::DataContainer<VertexAttributeStateInfoData> { |
| 269 | public: |
| 270 | VertexAttributeStateInfo() {} |
| 271 | |
| 272 | void SetDefault(); |
| 273 | |
| 274 | void SetSemanticIndex(int i) { semanticIndex = i; } |
| 275 | void SetShaderSlot(int s) { shaderSlot = s; } |
| 276 | void SetBufferIndex(int i) { bufferIndex = i; } |
| 277 | void SetOffset(ptrdiff_t o) { offset = o; } |
| 278 | void SetFormat(AttributeFormat f) { format = f; } |
| 279 | void SetNamePtr(const char* n) { pName = n; } |
| 280 | |
| 281 | int GetSemanticIndex() const { return semanticIndex; } |
| 282 | int GetShaderSlot() const { return shaderSlot; } |
| 283 | int GetBufferIndex() const { return bufferIndex; } |
| 284 | ptrdiff_t GetOffset() const { return offset; } |
| 285 | AttributeFormat GetFormat() const { return static_cast<AttributeFormat>(format); } |
| 286 | const char* GetNamePtr() const { return pName; } |
| 287 | }; |
| 288 | |
| 289 | class VertexBufferStateInfo : public detail::DataContainer<VertexBufferStateInfoData> { |
| 290 | public: |
| 291 | VertexBufferStateInfo() {} |
| 292 | |
| 293 | void SetDefault(); |
| 294 | |
| 295 | void SetStride(ptrdiff_t s) { stride = s; } |
| 296 | void SetDivisor(int d) { divisor = d; } |
| 297 | |
| 298 | ptrdiff_t GetStride() const { return stride; } |
| 299 | int GetDivisor() const { return divisor; } |
| 300 | }; |
| 301 | |
| 302 | class VertexStateInfo : public detail::DataContainer<VertexStateInfoData> { |
| 303 | public: |
| 304 | VertexStateInfo() {} |
| 305 | |
| 306 | void SetDefault(); |
| 307 | |
| 308 | void SetVertexAttributeStateInfoArray(const VertexAttributeStateInfo* p, int c) { |
| 309 | attributeCount = c; |
| 310 | pAttributeArray.ptr = p->ToData(); |
| 311 | } |
| 312 | |
| 313 | void SetVertexBufferStateInfoArray(const VertexBufferStateInfo* p, int c) { |
| 314 | bufferCount = c; |
| 315 | pBufferArray.ptr = p->ToData(); |
| 316 | } |
| 317 | |
| 318 | int GetVertexAttributeCount() const { return attributeCount; } |
| 319 | int GetVertexBufferCount() const { return bufferCount; } |
| 320 | |
| 321 | const VertexAttributeStateInfo* GetVertexAttributeStateInfoArray() const { |
| 322 | return nn::gfx::DataToAccessor(data: pAttributeArray.ptr); |
| 323 | } |
| 324 | |
| 325 | const VertexBufferStateInfo* GetVertexBufferStateInfoArray() const { |
| 326 | return nn::gfx::DataToAccessor(data: pBufferArray.ptr); |
| 327 | } |
| 328 | }; |
| 329 | |
| 330 | class TessellationStateInfo : public detail::DataContainer<TessellationStateInfoData> { |
| 331 | public: |
| 332 | TessellationStateInfo() {} |
| 333 | |
| 334 | void SetDefault(); |
| 335 | |
| 336 | void SetPatchControlPointCount(int c) { patchControlPointCount = c; } |
| 337 | |
| 338 | int GetPatchControlPointCount() const { return patchControlPointCount; } |
| 339 | }; |
| 340 | |
| 341 | class ViewportStateInfo : public detail::DataContainer<ViewportStateInfoData> { |
| 342 | public: |
| 343 | ViewportStateInfo() {} |
| 344 | |
| 345 | void SetDefault(); |
| 346 | |
| 347 | void SetOriginX(float value) { originX = value; } |
| 348 | void SetOriginY(float value) { originY = value; } |
| 349 | void SetWidth(float value) { width = value; } |
| 350 | void SetHeight(float value) { height = value; } |
| 351 | void SetMinDepth(float value) { depthRange.minDepth = value; } |
| 352 | void SetMaxDepth(float value) { depthRange.maxDepth = value; } |
| 353 | |
| 354 | float GetOriginX() const { return originX; } |
| 355 | float GetOriginY() const { return originY; } |
| 356 | float GetWidth() const { return width; } |
| 357 | float GetHeight() const { return height; } |
| 358 | float GetMinDepth() const { return depthRange.minDepth; } |
| 359 | float GetMaxDepth() const { return depthRange.maxDepth; } |
| 360 | }; |
| 361 | |
| 362 | class ScissorStateInfo : public detail::DataContainer<ScissorStateInfoData> { |
| 363 | public: |
| 364 | ScissorStateInfo() {} |
| 365 | |
| 366 | void SetDefault(); |
| 367 | |
| 368 | void SetOriginX(int value) { originX = value; } |
| 369 | void SetOriginY(int value) { originY = value; } |
| 370 | void SetWidth(int value) { width = value; } |
| 371 | void SetHeight(int value) { height = value; } |
| 372 | |
| 373 | int GetOriginX() const { return originX; } |
| 374 | int GetOriginY() const { return originY; } |
| 375 | int GetWidth() const { return width; } |
| 376 | int GetHeight() const { return height; } |
| 377 | }; |
| 378 | |
| 379 | class ViewportScissorStateInfo : public detail::DataContainer<ViewportScissorStateInfoData> { |
| 380 | public: |
| 381 | ViewportScissorStateInfo() {} |
| 382 | |
| 383 | void SetDefault(); |
| 384 | |
| 385 | void SetScissorEnabled(bool value) { flag.SetBit(p: Flag_ScissorEnable, on: value); } |
| 386 | |
| 387 | void SetViewportStateInfoArray(const ViewportStateInfo* pViewportStateInfoArray, |
| 388 | int viewportStateCount) { |
| 389 | pViewportArray.ptr = pViewportStateInfoArray->ToData(); |
| 390 | viewportCount = viewportStateCount; |
| 391 | } |
| 392 | |
| 393 | void SetScissorStateInfoArray(const ScissorStateInfo* pScissorStateInfoArray, |
| 394 | int scissorStateCount) { |
| 395 | pScissorArray.ptr = pScissorStateInfoArray->ToData(); |
| 396 | scissorCount = scissorStateCount; |
| 397 | } |
| 398 | |
| 399 | bool IsScissorEnabled() const { return flag.GetBit(p: Flag_ScissorEnable); } |
| 400 | int GetViewportCount() const { return viewportCount; } |
| 401 | int GetScissorCount() const { return scissorCount; } |
| 402 | |
| 403 | const ViewportStateInfo* GetViewportStateInfoArray() const { |
| 404 | return nn::gfx::DataToAccessor(data: pViewportArray.ptr); |
| 405 | } |
| 406 | |
| 407 | const ScissorStateInfo* GetScissorStateInfoArray() const { |
| 408 | return nn::gfx::DataToAccessor(data: pScissorArray.ptr); |
| 409 | } |
| 410 | }; |
| 411 | |
| 412 | } // namespace nn::gfx |