mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-08 12:18:30 +09:00
219 lines
6.1 KiB
C++
219 lines
6.1 KiB
C++
// MobileGL - MobileGL/MG_State/GLState/RenderState/RenderState.h
|
|
// Copyright (c) 2025-2026 MobileGL-Dev
|
|
// Licensed under the GNU Lesser General Public License v3.0:
|
|
// https://www.gnu.org/licenses/gpl-3.0.txt
|
|
// https://www.gnu.org/licenses/lgpl-3.0.txt
|
|
// SPDX-License-Identifier: LGPL-3.0-only
|
|
// End of Source File Header
|
|
|
|
#pragma once
|
|
#include <Includes.h>
|
|
#include <MG_Util/Math/VectorTypes.h>
|
|
|
|
namespace MobileGL {
|
|
enum class BlendFactor {
|
|
Zero,
|
|
One,
|
|
SrcColor,
|
|
OneMinusSrcColor,
|
|
DstColor,
|
|
OneMinusDstColor,
|
|
SrcAlpha,
|
|
OneMinusSrcAlpha,
|
|
DstAlpha,
|
|
OneMinusDstAlpha,
|
|
ConstantColor,
|
|
OneMinusConstantColor,
|
|
ConstantAlpha,
|
|
OneMinusConstantAlpha,
|
|
BlendFactorCount,
|
|
Unknown = -1
|
|
};
|
|
|
|
enum class DepthTestFunc {
|
|
Never,
|
|
Less,
|
|
Equal,
|
|
LessEqual,
|
|
Greater,
|
|
NotEqual,
|
|
GreaterEqual,
|
|
Always,
|
|
DepthTestFuncCount,
|
|
Unknown = -1
|
|
};
|
|
|
|
enum class PixelStoreParam {
|
|
// Pack Parameters
|
|
PackAlignment,
|
|
PackRowLength,
|
|
PackImageHeight,
|
|
PackSkipRows,
|
|
PackSkipPixels,
|
|
PackSkipImages,
|
|
PackSwapBytes,
|
|
PackLsbFirst,
|
|
|
|
// Unpack Parameters
|
|
UnpackAlignment,
|
|
UnpackRowLength,
|
|
UnpackImageHeight,
|
|
UnpackSkipRows,
|
|
UnpackSkipPixels,
|
|
UnpackSkipImages,
|
|
UnpackSwapBytes,
|
|
UnpackLsbFirst,
|
|
|
|
PixelStoreParamCount,
|
|
Unknown = -1
|
|
};
|
|
|
|
enum class CullFaceMode {
|
|
Front,
|
|
Back,
|
|
FrontAndBack,
|
|
CullFaceModeCount,
|
|
Unknown = -1
|
|
};
|
|
|
|
enum class CapabilityInput {
|
|
Blend,
|
|
ClipDistance0,
|
|
ClipDistance1,
|
|
ClipDistance2,
|
|
ClipDistance3,
|
|
ClipDistance4,
|
|
ClipDistance5,
|
|
ClipDistance6,
|
|
ClipDistance7,
|
|
ColorLogicOp,
|
|
CullFace,
|
|
DebugOutput,
|
|
DebugOutputSynchronous,
|
|
DepthClamp,
|
|
DepthTest,
|
|
Dither,
|
|
FramebufferSrgb,
|
|
LineSmooth,
|
|
Multisample,
|
|
PolygonOffsetFill,
|
|
PolygonOffsetLine,
|
|
PolygonOffsetPoint,
|
|
PolygonSmooth,
|
|
PrimitiveRestart,
|
|
PrimitiveRestartFixedIndex,
|
|
RasterizerDiscard,
|
|
SampleAlphaToCoverage,
|
|
SampleAlphaToOne,
|
|
SampleCoverage,
|
|
SampleShading,
|
|
SampleMask,
|
|
ScissorTest,
|
|
StencilTest,
|
|
TextureCubeMapSeamless,
|
|
ProgramPointSize,
|
|
CapabilityInputCount,
|
|
Unknown = -1
|
|
};
|
|
|
|
struct PixelStoreParameters {
|
|
Bool SwapBytes = false;
|
|
Bool LSBFirst = false;
|
|
Int RowLength = 0;
|
|
Int ImageHeight = 0;
|
|
Int SkipPixels = 0;
|
|
Int SkipRows = 0;
|
|
Int SkipImages = 0;
|
|
Int Alignment = 4;
|
|
};
|
|
|
|
struct RenderStateParameters {
|
|
// Rasterization
|
|
IntVec4 Viewport = IntVec4(0, 0, 0, 0); // x, y, width, height
|
|
|
|
// Blending
|
|
Bool BlendEnabled = false;
|
|
BlendFactor SrcFactorRGB = BlendFactor::One;
|
|
BlendFactor DstFactorRGB = BlendFactor::Zero;
|
|
BlendFactor SrcFactorAlpha = BlendFactor::One;
|
|
BlendFactor DstFactorAlpha = BlendFactor::Zero;
|
|
|
|
// Depth
|
|
Bool DepthTestEnabled = false;
|
|
DepthTestFunc DepthFunc = DepthTestFunc::Less;
|
|
Bool DepthMask = true;
|
|
|
|
// Color Mask
|
|
BoolVec4 ColorMask = BoolVec4(true, true, true, true);
|
|
|
|
// Clear State
|
|
FloatVec4 ClearColor = FloatVec4(0.0f, 0.0f, 0.0f, 1.0f);
|
|
Float ClearDepth = 1.0f;
|
|
|
|
// Pixel Store
|
|
PixelStoreParameters PackParameters;
|
|
PixelStoreParameters UnpackParameters;
|
|
|
|
// Cull Face
|
|
Bool CullFaceEnabled = false;
|
|
CullFaceMode CullFaceModeSetting = CullFaceMode::Back;
|
|
|
|
// Scissor
|
|
Bool ScissorTestEnabled = false;
|
|
IntVec4 ScissorBox = IntVec4(0, 0, 0, 0); // x, y, width, height
|
|
};
|
|
|
|
namespace MG_State {
|
|
namespace GLState {
|
|
class RenderState {
|
|
public:
|
|
RenderState();
|
|
|
|
// Rasterization
|
|
void SetViewport(IntVec4 viewport); // x, y, width, height
|
|
const IntVec4& GetViewport() const; // x, y, width, height
|
|
|
|
// Capabilities
|
|
void SetCapability(CapabilityInput cap, Bool enabled);
|
|
Bool IsCapabilityEnabled(CapabilityInput cap) const;
|
|
|
|
// Blending
|
|
void SetBlendFunc(BlendFactor srcRGB, BlendFactor dstRGB, BlendFactor srcAlpha, BlendFactor dstAlpha);
|
|
void GetBlendFunc(BlendFactor& srcRGB, BlendFactor& dstRGB, BlendFactor& srcAlpha,
|
|
BlendFactor& dstAlpha) const;
|
|
|
|
// Depth
|
|
void SetDepthFunc(DepthTestFunc func);
|
|
DepthTestFunc GetDepthFunc() const;
|
|
void SetDepthMask(Bool flag);
|
|
Bool GetDepthMask() const;
|
|
|
|
// Color Mask
|
|
void SetColorMask(BoolVec4 mask);
|
|
const BoolVec4 GetColorMask() const;
|
|
|
|
// Clear State
|
|
void SetClearColor(FloatVec4 color);
|
|
const FloatVec4& GetClearColor() const;
|
|
void SetClearDepth(Float depth);
|
|
Float GetClearDepth() const;
|
|
|
|
// Pixel Store
|
|
void SetPixelStoreParam(PixelStoreParam param, Int value);
|
|
Int GetPixelStoreParam(PixelStoreParam param) const;
|
|
PixelStoreParameters GetPixelStoreParameters(Bool isUnpack) const;
|
|
|
|
// Cull Face
|
|
void SetCullFaceMode(CullFaceMode mode);
|
|
CullFaceMode GetCullFaceMode() const;
|
|
|
|
// Scissor
|
|
void SetScissorBox(IntVec4 box); // x, y, width, height
|
|
const IntVec4& GetScissorBox() const; // x, y, width, height
|
|
|
|
private:
|
|
RenderStateParameters m_parameters;
|
|
};
|
|
} // namespace GLState
|
|
} // namespace MG_State
|
|
} // namespace MobileGL
|