2019-08-09 04:18:08 +00:00
|
|
|
|
2019-08-10 00:32:08 +00:00
|
|
|
#include "Precomp.h"
|
2019-08-09 04:18:08 +00:00
|
|
|
#include "RenderDevice.h"
|
2019-08-09 22:46:51 +00:00
|
|
|
#include "VertexBuffer.h"
|
|
|
|
#include "IndexBuffer.h"
|
|
|
|
#include "VertexDeclaration.h"
|
|
|
|
#include "Texture.h"
|
2019-08-14 05:55:21 +00:00
|
|
|
#include "ShaderManager.h"
|
2019-08-12 06:33:40 +00:00
|
|
|
#include <stdexcept>
|
|
|
|
|
2019-08-10 00:32:08 +00:00
|
|
|
RenderDevice::RenderDevice(HWND hwnd) : Context(hwnd)
|
2019-08-12 06:33:40 +00:00
|
|
|
{
|
2019-08-14 10:36:33 +00:00
|
|
|
memset(mUniforms, 0, sizeof(mUniforms));
|
|
|
|
|
2019-08-12 06:33:40 +00:00
|
|
|
if (Context)
|
|
|
|
{
|
|
|
|
Context.Begin();
|
2019-08-14 05:55:21 +00:00
|
|
|
mShaderManager = std::make_unique<ShaderManager>();
|
2019-08-14 10:36:33 +00:00
|
|
|
mShader = &mShaderManager->Shaders[(int)ShaderName::basic];
|
2019-08-12 06:33:40 +00:00
|
|
|
Context.End();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RenderDevice::~RenderDevice()
|
2019-08-09 04:18:08 +00:00
|
|
|
{
|
2019-08-14 05:55:21 +00:00
|
|
|
if (Context)
|
|
|
|
{
|
|
|
|
Context.Begin();
|
|
|
|
mShaderManager->ReleaseResources();
|
|
|
|
Context.End();
|
|
|
|
}
|
2019-08-09 04:18:08 +00:00
|
|
|
}
|
|
|
|
|
2019-08-09 22:46:51 +00:00
|
|
|
void RenderDevice::SetVertexBuffer(int index, VertexBuffer* buffer, long offset, long stride)
|
|
|
|
{
|
2019-08-10 05:46:29 +00:00
|
|
|
mVertexBindings[index] = { buffer, offset, stride };
|
|
|
|
mNeedApply = true;
|
2019-08-09 22:46:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RenderDevice::SetIndexBuffer(IndexBuffer* buffer)
|
|
|
|
{
|
2019-08-10 05:46:29 +00:00
|
|
|
mIndexBuffer = buffer;
|
|
|
|
mNeedApply = true;
|
2019-08-09 22:46:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RenderDevice::SetAlphaBlendEnable(bool value)
|
|
|
|
{
|
2019-08-12 06:33:40 +00:00
|
|
|
mAlphaBlend = value;
|
|
|
|
mNeedApply = true;
|
2019-08-09 22:46:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RenderDevice::SetAlphaTestEnable(bool value)
|
|
|
|
{
|
2019-08-12 06:33:40 +00:00
|
|
|
mAlphaTest = value;
|
|
|
|
mNeedApply = true;
|
2019-08-09 22:46:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RenderDevice::SetCullMode(Cull mode)
|
|
|
|
{
|
2019-08-12 06:33:40 +00:00
|
|
|
mCullMode = mode;
|
|
|
|
mNeedApply = true;
|
2019-08-09 22:46:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RenderDevice::SetBlendOperation(BlendOperation op)
|
|
|
|
{
|
2019-08-12 06:33:40 +00:00
|
|
|
mBlendOperation = op;
|
|
|
|
mNeedApply = true;
|
2019-08-09 22:46:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RenderDevice::SetSourceBlend(Blend blend)
|
|
|
|
{
|
2019-08-12 06:33:40 +00:00
|
|
|
mSourceBlend = blend;
|
|
|
|
mNeedApply = true;
|
2019-08-09 22:46:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RenderDevice::SetDestinationBlend(Blend blend)
|
|
|
|
{
|
2019-08-12 06:33:40 +00:00
|
|
|
mDestinationBlend = blend;
|
|
|
|
mNeedApply = true;
|
2019-08-09 22:46:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RenderDevice::SetFillMode(FillMode mode)
|
|
|
|
{
|
2019-08-12 06:33:40 +00:00
|
|
|
mFillMode = mode;
|
|
|
|
mNeedApply = true;
|
2019-08-09 22:46:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RenderDevice::SetFogEnable(bool value)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderDevice::SetFogColor(int value)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderDevice::SetFogStart(float value)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderDevice::SetFogEnd(float value)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderDevice::SetMultisampleAntialias(bool value)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderDevice::SetTextureFactor(int factor)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderDevice::SetZEnable(bool value)
|
|
|
|
{
|
2019-08-12 06:33:40 +00:00
|
|
|
mDepthTest = value;
|
|
|
|
mNeedApply = true;
|
2019-08-09 22:46:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RenderDevice::SetZWriteEnable(bool value)
|
|
|
|
{
|
2019-08-12 06:33:40 +00:00
|
|
|
mDepthWrite = value;
|
|
|
|
mNeedApply = true;
|
2019-08-09 22:46:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RenderDevice::SetTransform(TransformState state, float* matrix)
|
|
|
|
{
|
2019-08-10 05:46:29 +00:00
|
|
|
memcpy(mTransforms[(int)state].Values, matrix, 16 * sizeof(float));
|
|
|
|
mNeedApply = true;
|
2019-08-09 22:46:51 +00:00
|
|
|
}
|
|
|
|
|
2019-08-10 05:46:29 +00:00
|
|
|
void RenderDevice::SetSamplerState(int index, TextureAddress addressU, TextureAddress addressV, TextureAddress addressW)
|
2019-08-09 22:46:51 +00:00
|
|
|
{
|
2019-08-10 05:46:29 +00:00
|
|
|
mSamplerStates[index] = { addressU, addressV, addressW };
|
|
|
|
mNeedApply = true;
|
2019-08-09 22:46:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RenderDevice::DrawPrimitives(PrimitiveType type, int startIndex, int primitiveCount)
|
|
|
|
{
|
2019-08-10 05:46:29 +00:00
|
|
|
static const int modes[] = { GL_LINES, GL_TRIANGLES, GL_TRIANGLE_STRIP };
|
|
|
|
static const int toVertexCount[] = { 2, 3, 1 };
|
|
|
|
static const int toVertexStart[] = { 0, 0, 2 };
|
|
|
|
|
|
|
|
Context.Begin();
|
|
|
|
if (mNeedApply) ApplyChanges();
|
|
|
|
glDrawArrays(modes[(int)type], startIndex, toVertexStart[(int)type] + primitiveCount * toVertexCount[(int)type]);
|
|
|
|
Context.End();
|
2019-08-09 22:46:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RenderDevice::DrawUserPrimitives(PrimitiveType type, int startIndex, int primitiveCount, const void* data)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderDevice::SetVertexDeclaration(VertexDeclaration* decl)
|
|
|
|
{
|
2019-08-10 05:46:29 +00:00
|
|
|
mVertexDeclaration = decl;
|
|
|
|
mNeedApply = true;
|
2019-08-09 22:46:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RenderDevice::StartRendering(bool clear, int backcolor, Texture* target, bool usedepthbuffer)
|
|
|
|
{
|
2019-08-10 00:32:08 +00:00
|
|
|
Context.Begin();
|
2019-08-10 05:46:29 +00:00
|
|
|
ApplyRenderTarget(target, usedepthbuffer);
|
2019-08-10 00:32:08 +00:00
|
|
|
if (clear && usedepthbuffer)
|
|
|
|
{
|
|
|
|
glClearColor(RPART(backcolor) / 255.0f, GPART(backcolor) / 255.0f, BPART(backcolor) / 255.0f, APART(backcolor) / 255.0f);
|
|
|
|
glClearDepthf(1.0f);
|
2019-08-12 06:33:40 +00:00
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
2019-08-10 00:32:08 +00:00
|
|
|
}
|
|
|
|
else if (clear)
|
|
|
|
{
|
|
|
|
glClearColor(RPART(backcolor) / 255.0f, GPART(backcolor) / 255.0f, BPART(backcolor) / 255.0f, APART(backcolor) / 255.0f);
|
2019-08-12 06:33:40 +00:00
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
2019-08-10 00:32:08 +00:00
|
|
|
}
|
|
|
|
Context.End();
|
2019-08-09 22:46:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RenderDevice::FinishRendering()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderDevice::Present()
|
|
|
|
{
|
2019-08-10 00:32:08 +00:00
|
|
|
Context.SwapBuffers();
|
2019-08-09 22:46:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RenderDevice::ClearTexture(int backcolor, Texture* texture)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderDevice::CopyTexture(Texture* src, Texture* dst, CubeMapFace face)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-08-12 06:33:40 +00:00
|
|
|
void RenderDevice::CheckError()
|
|
|
|
{
|
|
|
|
GLenum error = glGetError();
|
|
|
|
if (error != GL_NO_ERROR)
|
|
|
|
throw std::runtime_error("OpenGL error!");
|
|
|
|
}
|
|
|
|
|
2019-08-10 05:46:29 +00:00
|
|
|
void RenderDevice::ApplyChanges()
|
|
|
|
{
|
2019-08-12 06:33:40 +00:00
|
|
|
ApplyShader();
|
2019-08-10 05:46:29 +00:00
|
|
|
ApplyVertexBuffers();
|
|
|
|
ApplyIndexBuffer();
|
|
|
|
ApplyMatrices();
|
2019-08-14 10:36:33 +00:00
|
|
|
ApplyUniforms();
|
2019-08-10 05:46:29 +00:00
|
|
|
ApplyTextures();
|
2019-08-12 06:33:40 +00:00
|
|
|
ApplyRasterizerState();
|
|
|
|
ApplyBlendState();
|
|
|
|
ApplyDepthState();
|
|
|
|
|
|
|
|
CheckError();
|
2019-08-10 05:46:29 +00:00
|
|
|
|
|
|
|
mNeedApply = false;
|
|
|
|
}
|
|
|
|
|
2019-08-12 06:33:40 +00:00
|
|
|
void RenderDevice::ApplyShader()
|
|
|
|
{
|
2019-08-14 10:36:33 +00:00
|
|
|
glUseProgram(mShader->GetProgram());
|
2019-08-12 06:33:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RenderDevice::ApplyRasterizerState()
|
|
|
|
{
|
|
|
|
if (mCullMode == Cull::None)
|
|
|
|
{
|
|
|
|
glDisable(GL_CULL_FACE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
glEnable(GL_CULL_FACE);
|
|
|
|
glFrontFace(GL_CCW);
|
|
|
|
}
|
|
|
|
|
|
|
|
GLenum fillMode2GL[] = { GL_FILL, GL_LINE };
|
|
|
|
glPolygonMode(GL_FRONT_AND_BACK, fillMode2GL[(int)mFillMode]);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderDevice::ApplyBlendState()
|
|
|
|
{
|
|
|
|
if (mAlphaBlend)
|
|
|
|
{
|
|
|
|
static const GLenum blendOp2GL[] = { GL_FUNC_ADD, GL_FUNC_REVERSE_SUBTRACT };
|
|
|
|
static const GLenum blendFunc2GL[] = { GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA, GL_ONE, GL_CONSTANT_COLOR };
|
|
|
|
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glBlendEquation(blendOp2GL[(int)mBlendOperation]);
|
|
|
|
glBlendFunc(blendFunc2GL[(int)mSourceBlend], blendFunc2GL[(int)mDestinationBlend]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
glDisable(GL_BLEND);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderDevice::ApplyDepthState()
|
|
|
|
{
|
|
|
|
if (mDepthTest)
|
|
|
|
{
|
|
|
|
glEnable(GL_DEPTH_TEST);
|
|
|
|
glDepthMask(mDepthWrite ? GL_TRUE : GL_FALSE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
glDisable(GL_DEPTH_TEST);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-10 05:46:29 +00:00
|
|
|
void RenderDevice::ApplyIndexBuffer()
|
|
|
|
{
|
|
|
|
if (mIndexBuffer)
|
|
|
|
{
|
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mIndexBuffer->GetBuffer());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderDevice::ApplyVertexBuffers()
|
|
|
|
{
|
|
|
|
static const int typeSize[] = { 2, 3, 4 };
|
2019-08-12 06:33:40 +00:00
|
|
|
static const int type[] = { GL_FLOAT, GL_FLOAT, GL_BGRA };
|
2019-08-10 05:46:29 +00:00
|
|
|
static const int typeNormalized[] = { GL_FALSE, GL_FALSE, GL_TRUE };
|
|
|
|
|
|
|
|
if (mVertexDeclaration)
|
|
|
|
{
|
2019-08-12 06:33:40 +00:00
|
|
|
if (!mVAO)
|
|
|
|
{
|
|
|
|
glGenVertexArrays(1, &mVAO);
|
|
|
|
glBindVertexArray(mVAO);
|
|
|
|
}
|
|
|
|
|
2019-08-10 05:46:29 +00:00
|
|
|
for (size_t i = 0; i < mVertexDeclaration->Elements.size(); i++)
|
|
|
|
{
|
|
|
|
const auto& element = mVertexDeclaration->Elements[i];
|
|
|
|
auto& vertBinding = mVertexBindings[element.Stream];
|
|
|
|
GLuint location = (int)element.Usage;
|
|
|
|
if (vertBinding.Buffer)
|
|
|
|
{
|
|
|
|
GLuint vertexbuffer = vertBinding.Buffer->GetBuffer();
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
|
2019-08-12 06:33:40 +00:00
|
|
|
glEnableVertexAttribArray(location);
|
2019-08-10 05:46:29 +00:00
|
|
|
glVertexAttribPointer(location, typeSize[(int)element.Type], type[(int)element.Type], typeNormalized[(int)element.Type], vertBinding.Stride, (const void*)(element.Offset + (ptrdiff_t)vertBinding.Offset));
|
|
|
|
|
|
|
|
mEnabledVertexAttributes[location] = 2;
|
2019-08-12 06:33:40 +00:00
|
|
|
break;
|
2019-08-10 05:46:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (size_t i = 0; i < NumSlots; i++)
|
|
|
|
{
|
|
|
|
if (mEnabledVertexAttributes[i] == 2)
|
|
|
|
{
|
2019-08-12 06:33:40 +00:00
|
|
|
mEnabledVertexAttributes[i] = 1;
|
2019-08-10 05:46:29 +00:00
|
|
|
}
|
|
|
|
else if (mEnabledVertexAttributes[i] == 1)
|
|
|
|
{
|
|
|
|
glDisableVertexAttribArray((GLuint)i);
|
|
|
|
mEnabledVertexAttributes[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderDevice::ApplyMatrices()
|
|
|
|
{
|
2019-08-12 06:33:40 +00:00
|
|
|
for (size_t i = 0; i < (size_t)TransformState::NumTransforms; i++)
|
2019-08-10 05:46:29 +00:00
|
|
|
{
|
|
|
|
auto& binding = mTransforms[i];
|
2019-08-14 10:36:33 +00:00
|
|
|
glUniformMatrix4fv(mShader->TransformLocations[i], 1, GL_FALSE, binding.Values);
|
2019-08-10 05:46:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-14 10:36:33 +00:00
|
|
|
void RenderDevice::SetShader(ShaderName name)
|
|
|
|
{
|
|
|
|
mShader = &mShaderManager->Shaders[(int)name];
|
|
|
|
mNeedApply = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const int uniformLocations[(int)UniformName::NumUniforms] = {
|
|
|
|
64, // rendersettings
|
|
|
|
0, // transformsettings
|
|
|
|
108, // desaturation
|
|
|
|
-1, // texture1,
|
|
|
|
80, // highlightcolor
|
|
|
|
16, // worldviewproj
|
|
|
|
32, // world
|
|
|
|
48, // modelnormal
|
|
|
|
68, // FillColor
|
|
|
|
72, // vertexColor
|
|
|
|
84, // stencilColor
|
|
|
|
92, // lightPosAndRadius
|
|
|
|
96, // lightOrientation
|
|
|
|
100, // light2Radius
|
|
|
|
104, // lightColor
|
|
|
|
109, // ignoreNormals
|
|
|
|
110, // spotLight
|
|
|
|
76, // campos
|
|
|
|
};
|
|
|
|
|
|
|
|
void RenderDevice::SetUniform(UniformName name, const void* values, int count)
|
|
|
|
{
|
|
|
|
memcpy(&mUniforms[uniformLocations[(int)name]], values, sizeof(float) * count);
|
|
|
|
mNeedApply = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderDevice::ApplyUniforms()
|
|
|
|
{
|
|
|
|
auto& locations = mShader->UniformLocations;
|
|
|
|
|
|
|
|
glUniformMatrix4fv(locations[(int)UniformName::transformsettings], 1, GL_FALSE, &mUniforms[0].valuef);
|
|
|
|
glUniformMatrix4fv(locations[(int)UniformName::worldviewproj], 1, GL_FALSE, &mUniforms[16].valuef);
|
|
|
|
glUniformMatrix4fv(locations[(int)UniformName::world], 1, GL_FALSE, &mUniforms[32].valuef);
|
|
|
|
glUniformMatrix4fv(locations[(int)UniformName::modelnormal], 1, GL_FALSE, &mUniforms[48].valuef);
|
|
|
|
|
|
|
|
glUniform4fv(locations[(int)UniformName::rendersettings], 1, &mUniforms[64].valuef);
|
|
|
|
glUniform4fv(locations[(int)UniformName::FillColor], 1, &mUniforms[68].valuef);
|
|
|
|
glUniform4fv(locations[(int)UniformName::vertexColor], 1, &mUniforms[72].valuef);
|
|
|
|
glUniform4fv(locations[(int)UniformName::campos], 1, &mUniforms[76].valuef);
|
|
|
|
glUniform4fv(locations[(int)UniformName::highlightcolor], 1, &mUniforms[80].valuef);
|
|
|
|
glUniform4fv(locations[(int)UniformName::stencilColor], 1, &mUniforms[84].valuef);
|
|
|
|
glUniform4fv(locations[(int)UniformName::lightColor], 1, &mUniforms[88].valuef);
|
|
|
|
glUniform4fv(locations[(int)UniformName::lightPosAndRadius], 1, &mUniforms[92].valuef);
|
|
|
|
glUniform3fv(locations[(int)UniformName::lightOrientation], 1, &mUniforms[96].valuef);
|
|
|
|
glUniform2fv(locations[(int)UniformName::light2Radius], 1, &mUniforms[100].valuef);
|
|
|
|
glUniform4fv(locations[(int)UniformName::lightColor], 1, &mUniforms[104].valuef);
|
|
|
|
|
|
|
|
glUniform1fv(locations[(int)UniformName::desaturation], 1, &mUniforms[108].valuef);
|
|
|
|
glUniform1fv(locations[(int)UniformName::ignoreNormals], 1, &mUniforms[109].valuef);
|
|
|
|
glUniform1fv(locations[(int)UniformName::spotLight], 1, &mUniforms[110].valuef);
|
|
|
|
|
|
|
|
glUniform1i(locations[(int)UniformName::texture1], 0);
|
|
|
|
}
|
|
|
|
|
2019-08-10 05:46:29 +00:00
|
|
|
void RenderDevice::ApplyTextures()
|
|
|
|
{
|
|
|
|
static const int wrapMode[] = { GL_REPEAT, GL_CLAMP_TO_EDGE };
|
|
|
|
|
|
|
|
for (size_t i = 0; i < NumSlots; i++)
|
|
|
|
{
|
|
|
|
auto& binding = mSamplerStates[i];
|
|
|
|
glActiveTexture(GL_TEXTURE0 + (GLenum)i);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrapMode[(int)binding.AddressU]);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrapMode[(int)binding.AddressV]);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, wrapMode[(int)binding.AddressW]);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderDevice::ApplyRenderTarget(Texture* target, bool usedepthbuffer)
|
|
|
|
{
|
2019-08-12 06:33:40 +00:00
|
|
|
glViewport(0, 0, Context.GetWidth(), Context.GetHeight());
|
2019-08-10 05:46:29 +00:00
|
|
|
}
|
|
|
|
|
2019-08-09 22:46:51 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2019-08-10 00:32:08 +00:00
|
|
|
RenderDevice* RenderDevice_New(HWND hwnd)
|
|
|
|
{
|
|
|
|
RenderDevice *device = new RenderDevice(hwnd);
|
|
|
|
if (!device->Context)
|
|
|
|
{
|
|
|
|
delete device;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return device;
|
|
|
|
}
|
2019-08-09 04:18:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RenderDevice_Delete(RenderDevice* device)
|
|
|
|
{
|
|
|
|
delete device;
|
|
|
|
}
|
2019-08-09 22:46:51 +00:00
|
|
|
|
2019-08-14 10:36:33 +00:00
|
|
|
void RenderDevice_SetShader(RenderDevice* device, ShaderName name)
|
|
|
|
{
|
|
|
|
device->SetShader(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderDevice_SetUniform(RenderDevice* device, UniformName name, const void* values, int count)
|
|
|
|
{
|
|
|
|
device->SetUniform(name, values, count);
|
|
|
|
}
|
|
|
|
|
2019-08-09 22:46:51 +00:00
|
|
|
void RenderDevice_SetVertexBuffer(RenderDevice* device, int index, VertexBuffer* buffer, long offset, long stride)
|
|
|
|
{
|
|
|
|
device->SetVertexBuffer(index, buffer, offset, stride);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderDevice_SetIndexBuffer(RenderDevice* device, IndexBuffer* buffer)
|
|
|
|
{
|
|
|
|
device->SetIndexBuffer(buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderDevice_SetAlphaBlendEnable(RenderDevice* device, bool value)
|
|
|
|
{
|
|
|
|
device->SetAlphaBlendEnable(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderDevice_SetAlphaTestEnable(RenderDevice* device, bool value)
|
|
|
|
{
|
|
|
|
device->SetAlphaTestEnable(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderDevice_SetCullMode(RenderDevice* device, Cull mode)
|
|
|
|
{
|
|
|
|
device->SetCullMode(mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderDevice_SetBlendOperation(RenderDevice* device, BlendOperation op)
|
|
|
|
{
|
|
|
|
device->SetBlendOperation(op);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderDevice_SetSourceBlend(RenderDevice* device, Blend blend)
|
|
|
|
{
|
|
|
|
device->SetSourceBlend(blend);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderDevice_SetDestinationBlend(RenderDevice* device, Blend blend)
|
|
|
|
{
|
|
|
|
device->SetDestinationBlend(blend);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderDevice_SetFillMode(RenderDevice* device, FillMode mode)
|
|
|
|
{
|
|
|
|
device->SetFillMode(mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderDevice_SetFogEnable(RenderDevice* device, bool value)
|
|
|
|
{
|
|
|
|
device->SetFogEnable(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderDevice_SetFogColor(RenderDevice* device, int value)
|
|
|
|
{
|
|
|
|
device->SetFogColor(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderDevice_SetFogStart(RenderDevice* device, float value)
|
|
|
|
{
|
|
|
|
device->SetFogStart(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderDevice_SetFogEnd(RenderDevice* device, float value)
|
|
|
|
{
|
|
|
|
device->SetFogEnd(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderDevice_SetMultisampleAntialias(RenderDevice* device, bool value)
|
|
|
|
{
|
|
|
|
device->SetMultisampleAntialias(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderDevice_SetTextureFactor(RenderDevice* device, int factor)
|
|
|
|
{
|
|
|
|
device->SetTextureFactor(factor);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderDevice_SetZEnable(RenderDevice* device, bool value)
|
|
|
|
{
|
|
|
|
device->SetZEnable(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderDevice_SetZWriteEnable(RenderDevice* device, bool value)
|
|
|
|
{
|
|
|
|
device->SetZWriteEnable(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderDevice_SetTransform(RenderDevice* device, TransformState state, float* matrix)
|
|
|
|
{
|
|
|
|
device->SetTransform(state, matrix);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderDevice_SetSamplerState(RenderDevice* device, int unit, TextureAddress addressU, TextureAddress addressV, TextureAddress addressW)
|
|
|
|
{
|
|
|
|
device->SetSamplerState(unit, addressU, addressV, addressW);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderDevice_DrawPrimitives(RenderDevice* device, PrimitiveType type, int startIndex, int primitiveCount)
|
|
|
|
{
|
|
|
|
device->DrawPrimitives(type, startIndex, primitiveCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderDevice_DrawUserPrimitives(RenderDevice* device, PrimitiveType type, int startIndex, int primitiveCount, const void* data)
|
|
|
|
{
|
|
|
|
device->DrawUserPrimitives(type, startIndex, primitiveCount, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderDevice_SetVertexDeclaration(RenderDevice* device, VertexDeclaration* decl)
|
|
|
|
{
|
|
|
|
device->SetVertexDeclaration(decl);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderDevice_StartRendering(RenderDevice* device, bool clear, int backcolor, Texture* target, bool usedepthbuffer)
|
|
|
|
{
|
|
|
|
device->StartRendering(clear, backcolor, target, usedepthbuffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderDevice_FinishRendering(RenderDevice* device)
|
|
|
|
{
|
|
|
|
device->FinishRendering();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderDevice_Present(RenderDevice* device)
|
|
|
|
{
|
|
|
|
device->Present();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderDevice_ClearTexture(RenderDevice* device, int backcolor, Texture* texture)
|
|
|
|
{
|
|
|
|
device->ClearTexture(backcolor, texture);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderDevice_CopyTexture(RenderDevice* device, Texture* src, Texture* dst, CubeMapFace face)
|
|
|
|
{
|
|
|
|
device->CopyTexture(src, dst, face);
|
|
|
|
}
|