UltimateZoneBuilder/Source/Native/RenderDevice.h

196 lines
5.3 KiB
C
Raw Normal View History

#pragma once
2019-08-10 00:32:08 +00:00
#include "OpenGLContext.h"
2019-08-09 22:46:51 +00:00
class VertexBuffer;
class IndexBuffer;
class VertexDeclaration;
class Texture;
class ShaderManager;
2019-08-14 10:36:33 +00:00
class Shader;
2019-08-09 22:46:51 +00:00
enum class CubeMapFace;
enum class Cull : int { None, Clockwise };
2019-08-09 22:46:51 +00:00
enum class Blend : int { InverseSourceAlpha, SourceAlpha, One, BlendFactor };
enum class BlendOperation : int { Add, ReverseSubtract };
enum class FillMode : int { Solid, Wireframe };
enum class TransformState : int { World, View, Projection, NumTransforms };
2019-08-09 22:46:51 +00:00
enum class TextureAddress : int { Wrap, Clamp };
enum class ShaderFlags : int { None, Debug };
enum class PrimitiveType : int { LineList, TriangleList, TriangleStrip };
enum class TextureFilter : int { None, Point, Linear, Anisotropic };
2019-08-14 10:36:33 +00:00
enum class ShaderName
{
display2d_fsaa,
display2d_normal,
display2d_fullbright,
things2d_thing,
things2d_sprite,
things2d_fill,
world3d_main,
world3d_fullbright,
world3d_main_highlight,
world3d_fullbright_highlight,
world3d_main_vertexcolor,
world3d_skybox,
world3d_main_highlight_vertexcolor,
world3d_p7,
world3d_main_fog,
world3d_p9,
world3d_main_highlight_fog,
world3d_p11,
world3d_main_fog_vertexcolor,
world3d_p13,
world3d_main_highlight_fog_vertexcolor,
world3d_vertex_color,
world3d_constant_color,
world3d_lightpass,
2019-08-14 10:36:33 +00:00
count
};
enum class UniformName : int
{
rendersettings,
transformsettings,
desaturation,
highlightcolor,
worldviewproj,
world,
modelnormal,
FillColor,
vertexColor,
stencilColor,
lightPosAndRadius,
lightOrientation,
light2Radius,
lightColor,
ignoreNormals,
spotLight,
campos,
NumUniforms
};
class RenderDevice
{
public:
2019-08-10 00:32:08 +00:00
RenderDevice(HWND hwnd);
~RenderDevice();
2019-08-09 22:46:51 +00:00
2019-08-14 10:36:33 +00:00
void SetShader(ShaderName name);
void SetUniform(UniformName name, const void* values, int count);
2019-08-09 22:46:51 +00:00
void SetVertexBuffer(int index, VertexBuffer* buffer, long offset, long stride);
void SetIndexBuffer(IndexBuffer* buffer);
void SetAlphaBlendEnable(bool value);
void SetAlphaTestEnable(bool value);
void SetCullMode(Cull mode);
void SetBlendOperation(BlendOperation op);
void SetSourceBlend(Blend blend);
void SetDestinationBlend(Blend blend);
void SetFillMode(FillMode mode);
void SetMultisampleAntialias(bool value);
void SetZEnable(bool value);
void SetZWriteEnable(bool value);
2019-08-14 11:51:05 +00:00
void SetTexture(int unit, Texture* texture);
void SetSamplerFilter(int unit, TextureFilter minfilter, TextureFilter magfilter, TextureFilter mipfilter, float maxanisotropy);
2019-08-09 22:46:51 +00:00
void SetSamplerState(int unit, TextureAddress addressU, TextureAddress addressV, TextureAddress addressW);
void Draw(PrimitiveType type, int startIndex, int primitiveCount);
void DrawIndexed(PrimitiveType type, int startIndex, int primitiveCount);
2019-08-16 05:45:34 +00:00
void DrawData(PrimitiveType type, int startIndex, int primitiveCount, const void* data, int stride);
2019-08-09 22:46:51 +00:00
void SetVertexDeclaration(VertexDeclaration* decl);
void StartRendering(bool clear, int backcolor, Texture* target, bool usedepthbuffer);
void FinishRendering();
void Present();
void ClearTexture(int backcolor, Texture* texture);
void CopyTexture(Texture* src, Texture* dst, CubeMapFace face);
2019-08-10 00:32:08 +00:00
void SetVertexBufferData(VertexBuffer* buffer, void* data, int64_t size);
void SetVertexBufferSubdata(VertexBuffer* buffer, int64_t destOffset, void* data, int64_t size);
void SetIndexBufferData(IndexBuffer* buffer, void* data, int64_t size);
void SetPixels(Texture* texture, const void* data);
void SetCubePixels(Texture* texture, CubeMapFace face, const void* data);
void* LockTexture(Texture* texture);
void UnlockTexture(Texture* texture);
void InvalidateTexture(Texture* texture);
void ApplyChanges();
void ApplyVertexBuffers();
void ApplyIndexBuffer();
void ApplyShader();
2019-08-14 10:36:33 +00:00
void ApplyUniforms();
void ApplyTextures();
void ApplyRasterizerState();
void ApplyBlendState();
void ApplyDepthState();
void CheckError();
2019-08-16 02:10:03 +00:00
Shader* GetActiveShader();
2019-08-14 11:51:05 +00:00
GLint GetGLMinFilter(TextureFilter filter, TextureFilter mipfilter);
2019-08-10 00:32:08 +00:00
OpenGLContext Context;
struct VertexBinding
{
VertexBinding() = default;
VertexBinding(VertexBuffer* buffer, long offset, long stride) : Buffer(buffer), Offset(offset), Stride(stride) { }
VertexBuffer* Buffer = nullptr;
long Offset = 0;
long Stride = 0;
};
2019-08-14 11:51:05 +00:00
struct TextureUnit
{
2019-08-14 11:51:05 +00:00
Texture* Tex = nullptr;
GLuint MinFilter = GL_NEAREST;
GLuint MagFilter = GL_NEAREST;
float MaxAnisotropy = 0.0f;
TextureAddress AddressU = TextureAddress::Wrap;
TextureAddress AddressV = TextureAddress::Wrap;
TextureAddress AddressW = TextureAddress::Wrap;
};
enum { NumSlots = 16 };
VertexDeclaration *mVertexDeclaration = nullptr;
GLuint mVAO = 0;
int mEnabledVertexAttributes[NumSlots] = { 0 };
VertexBinding mVertexBindings[NumSlots];
2019-08-14 11:51:05 +00:00
TextureUnit mTextureUnits[NumSlots];
IndexBuffer* mIndexBuffer = nullptr;
std::unique_ptr<ShaderManager> mShaderManager;
ShaderName mShaderName = ShaderName::display2d_normal;
2019-08-14 10:36:33 +00:00
union UniformEntry
{
float valuef;
int32_t valuei;
};
UniformEntry mUniforms[4 * 16 + 12 * 4];
2019-08-16 05:45:34 +00:00
GLuint mStreamVertexBuffer = 0;
int mStreamBufferStride = 0;
Cull mCullMode = Cull::None;
FillMode mFillMode = FillMode::Solid;
bool mAlphaTest = false;
bool mAlphaBlend = false;
BlendOperation mBlendOperation = BlendOperation::Add;
Blend mSourceBlend = Blend::SourceAlpha;
Blend mDestinationBlend = Blend::InverseSourceAlpha;
bool mDepthTest = false;
bool mDepthWrite = false;
bool mNeedApply = true;
};