mirror of
https://git.do.srb2.org/STJr/UltimateZoneBuilder.git
synced 2025-01-19 06:51:09 +00:00
- draw streamed vertices
This commit is contained in:
parent
dc3bd6cb9c
commit
fb137d46db
3 changed files with 50 additions and 14 deletions
|
@ -236,7 +236,7 @@ namespace CodeImp.DoomBuilder.Rendering
|
||||||
|
|
||||||
public void Draw(PrimitiveType type, int startIndex, int primitiveCount, FlatVertex[] data)
|
public void Draw(PrimitiveType type, int startIndex, int primitiveCount, FlatVertex[] data)
|
||||||
{
|
{
|
||||||
RenderDevice_DrawData(Handle, type, startIndex, primitiveCount, data);
|
RenderDevice_DrawData(Handle, type, startIndex, primitiveCount, data, Marshal.SizeOf<FlatVertex>());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetVertexDeclaration(VertexDeclaration decl)
|
public void SetVertexDeclaration(VertexDeclaration decl)
|
||||||
|
@ -447,7 +447,7 @@ namespace CodeImp.DoomBuilder.Rendering
|
||||||
static extern void RenderDevice_DrawIndexed(IntPtr handle, PrimitiveType type, int startIndex, int primitiveCount);
|
static extern void RenderDevice_DrawIndexed(IntPtr handle, PrimitiveType type, int startIndex, int primitiveCount);
|
||||||
|
|
||||||
[DllImport("BuilderNative.dll", CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("BuilderNative.dll", CallingConvention = CallingConvention.Cdecl)]
|
||||||
static extern void RenderDevice_DrawData(IntPtr handle, PrimitiveType type, int startIndex, int primitiveCount, FlatVertex[] data);
|
static extern void RenderDevice_DrawData(IntPtr handle, PrimitiveType type, int startIndex, int primitiveCount, FlatVertex[] data, int stride);
|
||||||
|
|
||||||
[DllImport("BuilderNative.dll", CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("BuilderNative.dll", CallingConvention = CallingConvention.Cdecl)]
|
||||||
static extern void RenderDevice_SetVertexDeclaration(IntPtr handle, IntPtr decl);
|
static extern void RenderDevice_SetVertexDeclaration(IntPtr handle, IntPtr decl);
|
||||||
|
|
|
@ -15,6 +15,7 @@ RenderDevice::RenderDevice(HWND hwnd) : Context(hwnd)
|
||||||
if (Context)
|
if (Context)
|
||||||
{
|
{
|
||||||
Context.Begin();
|
Context.Begin();
|
||||||
|
glGenBuffers(1, &mStreamVertexBuffer);
|
||||||
mShaderManager = std::make_unique<ShaderManager>();
|
mShaderManager = std::make_unique<ShaderManager>();
|
||||||
Context.End();
|
Context.End();
|
||||||
}
|
}
|
||||||
|
@ -25,6 +26,7 @@ RenderDevice::~RenderDevice()
|
||||||
if (Context)
|
if (Context)
|
||||||
{
|
{
|
||||||
Context.Begin();
|
Context.Begin();
|
||||||
|
glDeleteBuffers(1, &mStreamVertexBuffer);
|
||||||
mShaderManager->ReleaseResources();
|
mShaderManager->ReleaseResources();
|
||||||
Context.End();
|
Context.End();
|
||||||
}
|
}
|
||||||
|
@ -171,8 +173,22 @@ void RenderDevice::DrawIndexed(PrimitiveType type, int startIndex, int primitive
|
||||||
Context.End();
|
Context.End();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderDevice::DrawData(PrimitiveType type, int startIndex, int primitiveCount, const void* data)
|
void RenderDevice::DrawData(PrimitiveType type, int startIndex, int primitiveCount, const void* data, int stride)
|
||||||
{
|
{
|
||||||
|
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 };
|
||||||
|
|
||||||
|
int vertcount = toVertexStart[(int)type] + primitiveCount * toVertexCount[(int)type];
|
||||||
|
|
||||||
|
Context.Begin();
|
||||||
|
mStreamBufferStride = stride;
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, mStreamVertexBuffer);
|
||||||
|
glBufferData(GL_ARRAY_BUFFER, vertcount * (size_t)stride, static_cast<const uint8_t*>(data) + startIndex * (size_t)stride, GL_STREAM_DRAW);
|
||||||
|
ApplyChanges();
|
||||||
|
glDrawArrays(modes[(int)type], 0, vertcount);
|
||||||
|
mStreamBufferStride = 0;
|
||||||
|
Context.End();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderDevice::SetVertexDeclaration(VertexDeclaration* decl)
|
void RenderDevice::SetVertexDeclaration(VertexDeclaration* decl)
|
||||||
|
@ -418,21 +434,38 @@ void RenderDevice::ApplyVertexBuffers()
|
||||||
glBindVertexArray(mVAO);
|
glBindVertexArray(mVAO);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < mVertexDeclaration->Elements.size(); i++)
|
if (mStreamBufferStride)
|
||||||
{
|
{
|
||||||
const auto& element = mVertexDeclaration->Elements[i];
|
glBindBuffer(GL_ARRAY_BUFFER, mStreamVertexBuffer);
|
||||||
auto& vertBinding = mVertexBindings[element.Stream];
|
for (size_t i = 0; i < mVertexDeclaration->Elements.size(); i++)
|
||||||
GLuint location = (int)element.Usage;
|
|
||||||
if (vertBinding.Buffer)
|
|
||||||
{
|
{
|
||||||
GLuint vertexbuffer = vertBinding.Buffer->GetBuffer();
|
const auto& element = mVertexDeclaration->Elements[i];
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
|
GLuint location = (int)element.Usage;
|
||||||
|
|
||||||
glEnableVertexAttribArray(location);
|
glEnableVertexAttribArray(location);
|
||||||
glVertexAttribPointer(location, typeSize[(int)element.Type], type[(int)element.Type], typeNormalized[(int)element.Type], vertBinding.Stride, (const void*)(element.Offset + (ptrdiff_t)vertBinding.Offset));
|
glVertexAttribPointer(location, typeSize[(int)element.Type], type[(int)element.Type], typeNormalized[(int)element.Type], mStreamBufferStride, (const void*)element.Offset);
|
||||||
|
|
||||||
mEnabledVertexAttributes[location] = 2;
|
mEnabledVertexAttributes[location] = 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
glEnableVertexAttribArray(location);
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -654,9 +687,9 @@ void RenderDevice_DrawIndexed(RenderDevice* device, PrimitiveType type, int star
|
||||||
device->DrawIndexed(type, startIndex, primitiveCount);
|
device->DrawIndexed(type, startIndex, primitiveCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderDevice_DrawData(RenderDevice* device, PrimitiveType type, int startIndex, int primitiveCount, const void* data)
|
void RenderDevice_DrawData(RenderDevice* device, PrimitiveType type, int startIndex, int primitiveCount, const void* data, int stride)
|
||||||
{
|
{
|
||||||
device->DrawData(type, startIndex, primitiveCount, data);
|
device->DrawData(type, startIndex, primitiveCount, data, stride);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderDevice_SetVertexDeclaration(RenderDevice* device, VertexDeclaration* decl)
|
void RenderDevice_SetVertexDeclaration(RenderDevice* device, VertexDeclaration* decl)
|
||||||
|
|
|
@ -96,7 +96,7 @@ public:
|
||||||
void SetSamplerState(int unit, TextureAddress addressU, TextureAddress addressV, TextureAddress addressW);
|
void SetSamplerState(int unit, TextureAddress addressU, TextureAddress addressV, TextureAddress addressW);
|
||||||
void Draw(PrimitiveType type, int startIndex, int primitiveCount);
|
void Draw(PrimitiveType type, int startIndex, int primitiveCount);
|
||||||
void DrawIndexed(PrimitiveType type, int startIndex, int primitiveCount);
|
void DrawIndexed(PrimitiveType type, int startIndex, int primitiveCount);
|
||||||
void DrawData(PrimitiveType type, int startIndex, int primitiveCount, const void* data);
|
void DrawData(PrimitiveType type, int startIndex, int primitiveCount, const void* data, int stride);
|
||||||
void SetVertexDeclaration(VertexDeclaration* decl);
|
void SetVertexDeclaration(VertexDeclaration* decl);
|
||||||
void StartRendering(bool clear, int backcolor, Texture* target, bool usedepthbuffer);
|
void StartRendering(bool clear, int backcolor, Texture* target, bool usedepthbuffer);
|
||||||
void FinishRendering();
|
void FinishRendering();
|
||||||
|
@ -176,6 +176,9 @@ public:
|
||||||
|
|
||||||
UniformEntry mUniforms[4 * 16 + 12 * 4];
|
UniformEntry mUniforms[4 * 16 + 12 * 4];
|
||||||
|
|
||||||
|
GLuint mStreamVertexBuffer = 0;
|
||||||
|
int mStreamBufferStride = 0;
|
||||||
|
|
||||||
Cull mCullMode = Cull::None;
|
Cull mCullMode = Cull::None;
|
||||||
FillMode mFillMode = FillMode::Solid;
|
FillMode mFillMode = FillMode::Solid;
|
||||||
bool mAlphaTest = false;
|
bool mAlphaTest = false;
|
||||||
|
|
Loading…
Reference in a new issue