2019-08-09 04:18:08 +00:00
|
|
|
#pragma once
|
|
|
|
|
2019-08-10 00:32:08 +00:00
|
|
|
#include "OpenGLContext.h"
|
2019-08-09 04:18:08 +00:00
|
|
|
|
2019-08-09 22:46:51 +00:00
|
|
|
class VertexBuffer;
|
|
|
|
class IndexBuffer;
|
|
|
|
class VertexDeclaration;
|
|
|
|
class Texture;
|
2019-08-14 05:55:21 +00:00
|
|
|
class ShaderManager;
|
2019-08-09 22:46:51 +00:00
|
|
|
enum class CubeMapFace;
|
|
|
|
|
|
|
|
enum class Cull : int { None, Counterclockwise };
|
|
|
|
enum class Blend : int { InverseSourceAlpha, SourceAlpha, One, BlendFactor };
|
|
|
|
enum class BlendOperation : int { Add, ReverseSubtract };
|
|
|
|
enum class FillMode : int { Solid, Wireframe };
|
2019-08-12 06:33:40 +00:00
|
|
|
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-09 04:18:08 +00:00
|
|
|
class RenderDevice
|
|
|
|
{
|
|
|
|
public:
|
2019-08-10 00:32:08 +00:00
|
|
|
RenderDevice(HWND hwnd);
|
2019-08-12 06:33:40 +00:00
|
|
|
~RenderDevice();
|
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 SetFogEnable(bool value);
|
|
|
|
void SetFogColor(int value);
|
|
|
|
void SetFogStart(float value);
|
|
|
|
void SetFogEnd(float value);
|
|
|
|
void SetMultisampleAntialias(bool value);
|
|
|
|
void SetTextureFactor(int factor);
|
|
|
|
void SetZEnable(bool value);
|
|
|
|
void SetZWriteEnable(bool value);
|
|
|
|
void SetTransform(TransformState state, float* matrix);
|
|
|
|
void SetSamplerState(int unit, TextureAddress addressU, TextureAddress addressV, TextureAddress addressW);
|
|
|
|
void DrawPrimitives(PrimitiveType type, int startIndex, int primitiveCount);
|
|
|
|
void DrawUserPrimitives(PrimitiveType type, int startIndex, int primitiveCount, const void* data);
|
|
|
|
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
|
|
|
|
2019-08-10 05:46:29 +00:00
|
|
|
void ApplyChanges();
|
|
|
|
void ApplyVertexBuffers();
|
|
|
|
void ApplyIndexBuffer();
|
2019-08-12 06:33:40 +00:00
|
|
|
void ApplyShader();
|
2019-08-10 05:46:29 +00:00
|
|
|
void ApplyMatrices();
|
|
|
|
void ApplyTextures();
|
2019-08-12 06:33:40 +00:00
|
|
|
void ApplyRasterizerState();
|
|
|
|
void ApplyBlendState();
|
|
|
|
void ApplyDepthState();
|
2019-08-10 05:46:29 +00:00
|
|
|
void ApplyRenderTarget(Texture* target, bool usedepthbuffer);
|
|
|
|
|
2019-08-12 06:33:40 +00:00
|
|
|
void CheckError();
|
|
|
|
|
2019-08-10 00:32:08 +00:00
|
|
|
OpenGLContext Context;
|
2019-08-10 05:46:29 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Mat4f
|
|
|
|
{
|
|
|
|
Mat4f() { Values[0] = 1.0f; Values[5] = 1.0f; Values[10] = 1.0f; Values[15] = 1.0f; }
|
|
|
|
float Values[16] = { 0.0f };
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SamplerState
|
|
|
|
{
|
|
|
|
SamplerState() = default;
|
|
|
|
SamplerState(TextureAddress addressU, TextureAddress addressV, TextureAddress addressW) : AddressU(addressU), AddressV(addressV), AddressW(addressW) { }
|
|
|
|
|
|
|
|
TextureAddress AddressU = TextureAddress::Wrap;
|
|
|
|
TextureAddress AddressV = TextureAddress::Wrap;
|
|
|
|
TextureAddress AddressW = TextureAddress::Wrap;
|
|
|
|
};
|
|
|
|
|
2019-08-12 06:33:40 +00:00
|
|
|
enum { NumSlots = 16 };
|
|
|
|
Mat4f mTransforms[(int)TransformState::NumTransforms];
|
|
|
|
|
2019-08-10 05:46:29 +00:00
|
|
|
VertexDeclaration *mVertexDeclaration = nullptr;
|
2019-08-12 06:33:40 +00:00
|
|
|
GLuint mVAO = 0;
|
2019-08-10 05:46:29 +00:00
|
|
|
int mEnabledVertexAttributes[NumSlots] = { 0 };
|
|
|
|
VertexBinding mVertexBindings[NumSlots];
|
2019-08-12 06:33:40 +00:00
|
|
|
|
2019-08-10 05:46:29 +00:00
|
|
|
SamplerState mSamplerStates[NumSlots];
|
2019-08-12 06:33:40 +00:00
|
|
|
|
2019-08-10 05:46:29 +00:00
|
|
|
IndexBuffer* mIndexBuffer = nullptr;
|
2019-08-12 06:33:40 +00:00
|
|
|
|
2019-08-14 05:55:21 +00:00
|
|
|
std::unique_ptr<ShaderManager> mShaderManager;
|
2019-08-12 06:33:40 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2019-08-10 05:46:29 +00:00
|
|
|
bool mNeedApply = true;
|
2019-08-09 04:18:08 +00:00
|
|
|
};
|