2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#region ================== Copyright (c) 2007 Pascal vd Heiden
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2007 Pascal vd Heiden, www.codeimp.com
|
|
|
|
* This program is released under GNU General Public License
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Namespaces
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Drawing;
|
2016-02-06 00:04:02 +00:00
|
|
|
using System.Windows.Forms;
|
|
|
|
using CodeImp.DoomBuilder.Controls;
|
2009-04-19 18:07:22 +00:00
|
|
|
using CodeImp.DoomBuilder.Geometry;
|
2019-08-09 04:18:08 +00:00
|
|
|
using System.Runtime.InteropServices;
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
namespace CodeImp.DoomBuilder.Rendering
|
|
|
|
{
|
2019-08-15 00:52:21 +00:00
|
|
|
public class RenderDevice : IDisposable
|
2019-08-08 01:51:21 +00:00
|
|
|
{
|
2019-08-15 00:52:21 +00:00
|
|
|
public RenderDevice(RenderTargetControl rendertarget)
|
2019-08-09 04:18:08 +00:00
|
|
|
{
|
2019-08-10 00:32:08 +00:00
|
|
|
Handle = RenderDevice_New(rendertarget.Handle);
|
2019-08-09 04:18:08 +00:00
|
|
|
if (Handle == IntPtr.Zero)
|
|
|
|
throw new Exception("RenderDevice_New failed");
|
2019-08-08 01:51:21 +00:00
|
|
|
|
2019-08-09 04:18:08 +00:00
|
|
|
RenderTarget = rendertarget;
|
2019-08-16 11:07:57 +00:00
|
|
|
|
2019-08-09 04:18:08 +00:00
|
|
|
SetupSettings();
|
|
|
|
}
|
2019-08-08 01:51:21 +00:00
|
|
|
|
2019-08-09 21:22:16 +00:00
|
|
|
~RenderDevice()
|
2019-08-09 04:18:08 +00:00
|
|
|
{
|
|
|
|
Dispose();
|
|
|
|
}
|
2019-08-08 01:51:21 +00:00
|
|
|
|
2019-08-09 04:18:08 +00:00
|
|
|
public bool Disposed { get { return Handle == IntPtr.Zero; } }
|
2019-08-08 01:51:21 +00:00
|
|
|
|
2019-08-09 04:18:08 +00:00
|
|
|
public void Dispose()
|
|
|
|
{
|
|
|
|
if (!Disposed)
|
|
|
|
{
|
|
|
|
RenderDevice_Delete(Handle);
|
|
|
|
Handle = IntPtr.Zero;
|
|
|
|
}
|
|
|
|
}
|
2019-08-08 01:51:21 +00:00
|
|
|
|
2019-08-14 10:36:33 +00:00
|
|
|
public void SetShader(ShaderName shader)
|
|
|
|
{
|
|
|
|
RenderDevice_SetShader(Handle, shader);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetUniform(UniformName uniform, bool value)
|
|
|
|
{
|
|
|
|
RenderDevice_SetUniform(Handle, uniform, new float[] { value ? 1.0f : 0.0f }, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetUniform(UniformName uniform, float value)
|
|
|
|
{
|
|
|
|
RenderDevice_SetUniform(Handle, uniform, new float[] { value }, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetUniform(UniformName uniform, Vector2 value)
|
|
|
|
{
|
|
|
|
RenderDevice_SetUniform(Handle, uniform, new float[] { value.X, value.Y }, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetUniform(UniformName uniform, Vector3 value)
|
|
|
|
{
|
|
|
|
RenderDevice_SetUniform(Handle, uniform, new float[] { value.X, value.Y, value.Z }, 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetUniform(UniformName uniform, Vector4 value)
|
|
|
|
{
|
|
|
|
RenderDevice_SetUniform(Handle, uniform, new float[] { value.X, value.Y, value.Z, value.W }, 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetUniform(UniformName uniform, Color4 value)
|
|
|
|
{
|
|
|
|
RenderDevice_SetUniform(Handle, uniform, new float[] { value.Red, value.Green, value.Blue, value.Alpha }, 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetUniform(UniformName uniform, Matrix matrix)
|
|
|
|
{
|
|
|
|
RenderDevice_SetUniform(Handle, uniform, new float[] {
|
|
|
|
matrix.M11, matrix.M12, matrix.M13, matrix.M14,
|
|
|
|
matrix.M21, matrix.M22, matrix.M23, matrix.M24,
|
|
|
|
matrix.M31, matrix.M32, matrix.M33, matrix.M34,
|
|
|
|
matrix.M41, matrix.M42, matrix.M43, matrix.M44
|
|
|
|
}, 16);
|
|
|
|
}
|
|
|
|
|
2019-08-16 11:07:57 +00:00
|
|
|
public void SetVertexBuffer(VertexBuffer buffer)
|
2019-08-09 04:18:08 +00:00
|
|
|
{
|
2019-08-16 11:07:57 +00:00
|
|
|
RenderDevice_SetVertexBuffer(Handle, buffer != null ? buffer.Handle : IntPtr.Zero);
|
2019-08-09 04:18:08 +00:00
|
|
|
}
|
2019-08-08 01:51:21 +00:00
|
|
|
|
2019-08-09 22:46:51 +00:00
|
|
|
public void SetIndexBuffer(IndexBuffer buffer)
|
2019-08-09 04:18:08 +00:00
|
|
|
{
|
2019-08-09 22:46:51 +00:00
|
|
|
RenderDevice_SetIndexBuffer(Handle, buffer != null ? buffer.Handle : IntPtr.Zero);
|
2019-08-09 04:18:08 +00:00
|
|
|
}
|
2019-08-08 01:51:21 +00:00
|
|
|
|
2019-08-09 22:46:51 +00:00
|
|
|
public void SetAlphaBlendEnable(bool value)
|
2019-08-09 04:18:08 +00:00
|
|
|
{
|
2019-08-09 22:46:51 +00:00
|
|
|
RenderDevice_SetAlphaBlendEnable(Handle, value);
|
2019-08-09 04:18:08 +00:00
|
|
|
}
|
2019-08-08 01:51:21 +00:00
|
|
|
|
2019-08-09 22:46:51 +00:00
|
|
|
public void SetAlphaTestEnable(bool value)
|
2019-08-08 05:10:35 +00:00
|
|
|
{
|
2019-08-09 22:46:51 +00:00
|
|
|
RenderDevice_SetAlphaTestEnable(Handle, value);
|
2019-08-09 04:18:08 +00:00
|
|
|
}
|
2019-08-08 01:51:21 +00:00
|
|
|
|
2019-08-09 22:46:51 +00:00
|
|
|
public void SetCullMode(Cull mode)
|
2019-08-09 04:18:08 +00:00
|
|
|
{
|
2019-08-09 22:46:51 +00:00
|
|
|
RenderDevice_SetCullMode(Handle, mode);
|
2019-08-09 04:18:08 +00:00
|
|
|
}
|
2019-08-08 01:51:21 +00:00
|
|
|
|
2019-08-09 22:46:51 +00:00
|
|
|
public void SetBlendOperation(BlendOperation op)
|
2019-08-09 04:18:08 +00:00
|
|
|
{
|
2019-08-09 22:46:51 +00:00
|
|
|
RenderDevice_SetBlendOperation(Handle, op);
|
2019-08-08 05:10:35 +00:00
|
|
|
}
|
2019-08-08 01:51:21 +00:00
|
|
|
|
2019-08-09 22:46:51 +00:00
|
|
|
public void SetSourceBlend(Blend blend)
|
2019-08-08 05:10:35 +00:00
|
|
|
{
|
2019-08-09 22:46:51 +00:00
|
|
|
RenderDevice_SetSourceBlend(Handle, blend);
|
2019-08-08 05:10:35 +00:00
|
|
|
}
|
2019-08-08 01:51:21 +00:00
|
|
|
|
2019-08-09 22:46:51 +00:00
|
|
|
public void SetDestinationBlend(Blend blend)
|
2019-08-09 04:18:08 +00:00
|
|
|
{
|
2019-08-09 22:46:51 +00:00
|
|
|
RenderDevice_SetDestinationBlend(Handle, blend);
|
2019-08-09 04:18:08 +00:00
|
|
|
}
|
2019-08-08 05:10:35 +00:00
|
|
|
|
2019-08-09 22:46:51 +00:00
|
|
|
public void SetFillMode(FillMode mode)
|
2019-08-09 04:18:08 +00:00
|
|
|
{
|
2019-08-09 22:46:51 +00:00
|
|
|
RenderDevice_SetFillMode(Handle, mode);
|
2019-08-09 04:18:08 +00:00
|
|
|
}
|
2019-08-08 01:51:21 +00:00
|
|
|
|
2019-08-09 22:46:51 +00:00
|
|
|
public void SetFogEnable(bool value)
|
2019-08-09 04:18:08 +00:00
|
|
|
{
|
2019-08-16 05:10:46 +00:00
|
|
|
// To do: move to shaders as an uniform
|
2019-08-09 04:18:08 +00:00
|
|
|
}
|
2019-08-08 01:51:21 +00:00
|
|
|
|
2019-08-09 22:46:51 +00:00
|
|
|
public void SetFogColor(int value)
|
2019-08-09 04:18:08 +00:00
|
|
|
{
|
2019-08-16 05:10:46 +00:00
|
|
|
// To do: move to shaders as an uniform
|
2019-08-09 04:18:08 +00:00
|
|
|
}
|
2019-08-08 01:51:21 +00:00
|
|
|
|
2019-08-09 22:46:51 +00:00
|
|
|
public void SetFogStart(float value)
|
2019-08-09 04:18:08 +00:00
|
|
|
{
|
2019-08-16 05:10:46 +00:00
|
|
|
// To do: move to shaders as an uniform
|
2019-08-09 04:18:08 +00:00
|
|
|
}
|
2019-08-08 01:51:21 +00:00
|
|
|
|
2019-08-09 22:46:51 +00:00
|
|
|
public void SetFogEnd(float value)
|
|
|
|
{
|
2019-08-16 05:10:46 +00:00
|
|
|
// To do: move to shaders as an uniform
|
2019-08-09 22:46:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void SetMultisampleAntialias(bool value)
|
|
|
|
{
|
|
|
|
RenderDevice_SetMultisampleAntialias(Handle, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetZEnable(bool value)
|
|
|
|
{
|
|
|
|
RenderDevice_SetZEnable(Handle, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetZWriteEnable(bool value)
|
|
|
|
{
|
|
|
|
RenderDevice_SetZWriteEnable(Handle, value);
|
|
|
|
}
|
|
|
|
|
2019-08-14 11:51:05 +00:00
|
|
|
public void SetTexture(int unit, BaseTexture value)
|
|
|
|
{
|
|
|
|
RenderDevice_SetTexture(Handle, unit, value != null ? value.Handle : IntPtr.Zero);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetSamplerFilter(int unit, TextureFilter filter)
|
|
|
|
{
|
2019-08-17 01:08:34 +00:00
|
|
|
SetSamplerFilter(unit, filter, filter, TextureFilter.None, 0.0f);
|
2019-08-14 11:51:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void SetSamplerFilter(int unit, TextureFilter minfilter, TextureFilter magfilter, TextureFilter mipfilter, float maxanisotropy)
|
|
|
|
{
|
|
|
|
RenderDevice_SetSamplerFilter(Handle, unit, minfilter, magfilter, mipfilter, maxanisotropy);
|
|
|
|
}
|
|
|
|
|
2019-08-09 22:46:51 +00:00
|
|
|
public void SetSamplerState(int unit, TextureAddress address)
|
2019-08-09 04:18:08 +00:00
|
|
|
{
|
2019-08-09 22:46:51 +00:00
|
|
|
SetSamplerState(unit, address, address, address);
|
2019-08-09 04:18:08 +00:00
|
|
|
}
|
2019-08-08 01:51:21 +00:00
|
|
|
|
2019-08-09 22:46:51 +00:00
|
|
|
public void SetSamplerState(int unit, TextureAddress addressU, TextureAddress addressV, TextureAddress addressW)
|
2019-08-09 04:18:08 +00:00
|
|
|
{
|
2019-08-09 22:46:51 +00:00
|
|
|
RenderDevice_SetSamplerState(Handle, unit, addressU, addressV, addressW);
|
2019-08-08 01:19:11 +00:00
|
|
|
}
|
|
|
|
|
2019-08-15 00:52:21 +00:00
|
|
|
public void DrawIndexed(PrimitiveType type, int startIndex, int primitiveCount)
|
|
|
|
{
|
|
|
|
RenderDevice_DrawIndexed(Handle, type, startIndex, primitiveCount);
|
|
|
|
}
|
|
|
|
|
2019-08-16 05:12:26 +00:00
|
|
|
public void Draw(PrimitiveType type, int startIndex, int primitiveCount)
|
2019-08-09 04:18:08 +00:00
|
|
|
{
|
2019-08-15 00:52:21 +00:00
|
|
|
RenderDevice_Draw(Handle, type, startIndex, primitiveCount);
|
2019-08-09 22:46:51 +00:00
|
|
|
}
|
|
|
|
|
2019-08-16 05:12:26 +00:00
|
|
|
public void Draw(PrimitiveType type, int startIndex, int primitiveCount, FlatVertex[] data)
|
2019-08-09 22:46:51 +00:00
|
|
|
{
|
2019-08-16 11:07:57 +00:00
|
|
|
RenderDevice_DrawData(Handle, type, startIndex, primitiveCount, data);
|
2019-08-09 04:18:08 +00:00
|
|
|
}
|
2019-08-08 01:19:11 +00:00
|
|
|
|
|
|
|
public void StartRendering(bool clear, Color4 backcolor)
|
|
|
|
{
|
2019-08-09 22:46:51 +00:00
|
|
|
RenderDevice_StartRendering(Handle, clear, backcolor.ToArgb(), IntPtr.Zero, true);
|
2019-08-08 01:19:11 +00:00
|
|
|
}
|
2019-08-09 04:18:08 +00:00
|
|
|
|
2019-08-08 01:19:11 +00:00
|
|
|
public void StartRendering(bool clear, Color4 backcolor, Texture target, bool usedepthbuffer)
|
|
|
|
{
|
2019-08-17 01:08:34 +00:00
|
|
|
RenderDevice_StartRendering(Handle, clear, backcolor.ToArgb(), target.Handle, usedepthbuffer);
|
2019-08-08 01:19:11 +00:00
|
|
|
}
|
|
|
|
|
2019-08-09 04:18:08 +00:00
|
|
|
public void FinishRendering()
|
|
|
|
{
|
2019-08-09 22:46:51 +00:00
|
|
|
RenderDevice_FinishRendering(Handle);
|
2019-08-09 04:18:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void Present()
|
|
|
|
{
|
2019-08-09 22:46:51 +00:00
|
|
|
RenderDevice_Present(Handle);
|
2019-08-09 04:18:08 +00:00
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
|
2019-08-09 04:18:08 +00:00
|
|
|
public void ClearTexture(Color4 backcolor, Texture texture)
|
|
|
|
{
|
2019-08-09 22:46:51 +00:00
|
|
|
RenderDevice_ClearTexture(Handle, backcolor.ToArgb(), texture.Handle);
|
2019-08-09 04:18:08 +00:00
|
|
|
}
|
|
|
|
|
2019-08-17 01:08:34 +00:00
|
|
|
public void CopyTexture(CubeTexture dst, CubeMapFace face)
|
2019-08-09 22:46:51 +00:00
|
|
|
{
|
2019-08-17 01:08:34 +00:00
|
|
|
RenderDevice_CopyTexture(Handle, dst.Handle, face);
|
2019-08-09 22:46:51 +00:00
|
|
|
}
|
|
|
|
|
2019-08-15 00:52:21 +00:00
|
|
|
public void SetBufferData(IndexBuffer buffer, int[] data)
|
|
|
|
{
|
|
|
|
RenderDevice_SetIndexBufferData(Handle, buffer.Handle, data, data.Length * Marshal.SizeOf<int>());
|
|
|
|
}
|
|
|
|
|
2019-08-16 11:07:57 +00:00
|
|
|
public void SetBufferData(VertexBuffer buffer, int length, VertexFormat format)
|
2019-08-16 09:24:22 +00:00
|
|
|
{
|
2019-08-16 11:23:25 +00:00
|
|
|
int stride = (format == VertexFormat.Flat) ? FlatVertex.Stride : WorldVertex.Stride;
|
|
|
|
RenderDevice_SetVertexBufferData(Handle, buffer.Handle, IntPtr.Zero, length * stride, format);
|
2019-08-16 09:24:22 +00:00
|
|
|
}
|
|
|
|
|
2019-08-15 00:52:21 +00:00
|
|
|
public void SetBufferData(VertexBuffer buffer, FlatVertex[] data)
|
|
|
|
{
|
2019-08-16 11:07:57 +00:00
|
|
|
RenderDevice_SetVertexBufferData(Handle, buffer.Handle, data, data.Length * Marshal.SizeOf<FlatVertex>(), VertexFormat.Flat);
|
2019-08-15 00:52:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void SetBufferData(VertexBuffer buffer, WorldVertex[] data)
|
|
|
|
{
|
2019-08-16 11:07:57 +00:00
|
|
|
RenderDevice_SetVertexBufferData(Handle, buffer.Handle, data, data.Length * Marshal.SizeOf<WorldVertex>(), VertexFormat.World);
|
2019-08-15 00:52:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void SetBufferSubdata(VertexBuffer buffer, long destOffset, FlatVertex[] data)
|
|
|
|
{
|
2019-08-16 11:23:25 +00:00
|
|
|
RenderDevice_SetVertexBufferSubdata(Handle, buffer.Handle, destOffset * FlatVertex.Stride, data, data.Length * FlatVertex.Stride);
|
2019-08-15 00:52:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void SetBufferSubdata(VertexBuffer buffer, long destOffset, WorldVertex[] data)
|
|
|
|
{
|
2019-08-16 11:23:25 +00:00
|
|
|
RenderDevice_SetVertexBufferSubdata(Handle, buffer.Handle, destOffset * WorldVertex.Stride, data, data.Length * WorldVertex.Stride);
|
2019-08-15 00:52:21 +00:00
|
|
|
}
|
|
|
|
|
2019-08-16 11:23:25 +00:00
|
|
|
public void SetBufferSubdata(VertexBuffer buffer, FlatVertex[] data, long size)
|
2019-08-15 00:52:21 +00:00
|
|
|
{
|
2019-08-16 11:23:25 +00:00
|
|
|
if (size < 0 || size > data.Length) throw new ArgumentOutOfRangeException("size");
|
|
|
|
RenderDevice_SetVertexBufferSubdata(Handle, buffer.Handle, 0, data, size * FlatVertex.Stride);
|
2019-08-15 00:52:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void SetPixels(Texture texture, System.Drawing.Bitmap bitmap)
|
|
|
|
{
|
|
|
|
System.Drawing.Imaging.BitmapData bmpdata = bitmap.LockBits(
|
|
|
|
new System.Drawing.Rectangle(0, 0, bitmap.Size.Width, bitmap.Size.Height),
|
|
|
|
System.Drawing.Imaging.ImageLockMode.ReadOnly,
|
|
|
|
System.Drawing.Imaging.PixelFormat.Format32bppArgb);
|
|
|
|
|
|
|
|
RenderDevice_SetPixels(Handle, texture.Handle, bmpdata.Scan0);
|
|
|
|
|
|
|
|
bitmap.UnlockBits(bmpdata);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetPixels(CubeTexture texture, CubeMapFace face, System.Drawing.Bitmap bitmap)
|
|
|
|
{
|
|
|
|
System.Drawing.Imaging.BitmapData bmpdata = bitmap.LockBits(
|
|
|
|
new System.Drawing.Rectangle(0, 0, bitmap.Size.Width, bitmap.Size.Height),
|
|
|
|
System.Drawing.Imaging.ImageLockMode.ReadOnly,
|
|
|
|
System.Drawing.Imaging.PixelFormat.Format32bppArgb);
|
|
|
|
|
|
|
|
RenderDevice_SetCubePixels(Handle, texture.Handle, face, bmpdata.Scan0);
|
|
|
|
|
|
|
|
bitmap.UnlockBits(bmpdata);
|
|
|
|
}
|
|
|
|
|
|
|
|
internal Plotter LockPlotter(Texture texture, int visibleWidth, int visibleHeight)
|
|
|
|
{
|
|
|
|
unsafe
|
|
|
|
{
|
|
|
|
IntPtr data = RenderDevice_LockTexture(Handle, texture.Handle);
|
|
|
|
return new Plotter((PixelColor*)data.ToPointer(), texture.Width, texture.Height, Math.Min(texture.Width, visibleWidth), Math.Min(texture.Height, visibleHeight));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void UnlockPlotter(Texture texture)
|
|
|
|
{
|
|
|
|
RenderDevice_UnlockTexture(Handle, texture.Handle);
|
|
|
|
}
|
|
|
|
|
2019-08-09 22:46:51 +00:00
|
|
|
internal void RegisterResource(IRenderResource res)
|
2019-08-09 04:18:08 +00:00
|
|
|
{
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
|
2019-08-09 22:46:51 +00:00
|
|
|
internal void UnregisterResource(IRenderResource res)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetupSettings()
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
|
|
|
// Setup renderstates
|
2019-08-09 22:46:51 +00:00
|
|
|
SetAlphaBlendEnable(false);
|
|
|
|
SetAlphaTestEnable(false);
|
|
|
|
SetCullMode(Cull.None);
|
|
|
|
SetDestinationBlend(Blend.InverseSourceAlpha);
|
|
|
|
SetFillMode(FillMode.Solid);
|
|
|
|
SetFogEnable(false);
|
|
|
|
SetMultisampleAntialias((General.Settings.AntiAliasingSamples > 0));
|
|
|
|
SetSourceBlend(Blend.SourceAlpha);
|
2019-08-16 12:01:27 +00:00
|
|
|
SetUniform(UniformName.texturefactor, new Color4(1f, 1f, 1f, 1f));
|
2019-08-09 22:46:51 +00:00
|
|
|
SetZEnable(false);
|
|
|
|
SetZWriteEnable(false);
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// Texture addressing
|
2019-08-09 22:46:51 +00:00
|
|
|
SetSamplerState(0, TextureAddress.Wrap);
|
2009-04-19 18:07:22 +00:00
|
|
|
|
2019-08-16 11:07:57 +00:00
|
|
|
//mxd. It's still nice to have anisotropic filtering when texture filtering is disabled
|
|
|
|
TextureFilter magminfilter = (General.Settings.VisualBilinear ? TextureFilter.Linear : TextureFilter.Point);
|
|
|
|
SetSamplerFilter(0,
|
|
|
|
General.Settings.FilterAnisotropy > 1.0f ? TextureFilter.Anisotropic : magminfilter,
|
|
|
|
magminfilter,
|
|
|
|
General.Settings.VisualBilinear ? TextureFilter.Linear : TextureFilter.None, // [SB] use None, otherwise textures are still filtered
|
|
|
|
General.Settings.FilterAnisotropy);
|
|
|
|
|
|
|
|
// Initialize presentations
|
|
|
|
Presentation.Initialize();
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
2019-08-09 04:18:08 +00:00
|
|
|
IntPtr Handle;
|
|
|
|
|
|
|
|
[DllImport("BuilderNative.dll", CallingConvention = CallingConvention.Cdecl)]
|
2019-08-10 00:32:08 +00:00
|
|
|
static extern IntPtr RenderDevice_New(IntPtr hwnd);
|
2019-08-09 04:18:08 +00:00
|
|
|
|
|
|
|
[DllImport("BuilderNative.dll", CallingConvention = CallingConvention.Cdecl)]
|
|
|
|
static extern void RenderDevice_Delete(IntPtr handle);
|
|
|
|
|
2019-08-14 10:36:33 +00:00
|
|
|
[DllImport("BuilderNative.dll", CallingConvention = CallingConvention.Cdecl)]
|
|
|
|
static extern IntPtr RenderDevice_SetShader(IntPtr hwnd, ShaderName name);
|
|
|
|
|
|
|
|
[DllImport("BuilderNative.dll", CallingConvention = CallingConvention.Cdecl)]
|
|
|
|
static extern IntPtr RenderDevice_SetUniform(IntPtr hwnd, UniformName name, float[] data, int count);
|
|
|
|
|
2019-08-09 22:46:51 +00:00
|
|
|
[DllImport("BuilderNative.dll", CallingConvention = CallingConvention.Cdecl)]
|
2019-08-16 11:07:57 +00:00
|
|
|
static extern void RenderDevice_SetVertexBuffer(IntPtr handle, IntPtr buffer);
|
2019-08-09 22:46:51 +00:00
|
|
|
|
|
|
|
[DllImport("BuilderNative.dll", CallingConvention = CallingConvention.Cdecl)]
|
|
|
|
static extern void RenderDevice_SetIndexBuffer(IntPtr handle, IntPtr buffer);
|
|
|
|
|
|
|
|
[DllImport("BuilderNative.dll", CallingConvention = CallingConvention.Cdecl)]
|
|
|
|
static extern void RenderDevice_SetAlphaBlendEnable(IntPtr handle, bool value);
|
|
|
|
|
|
|
|
[DllImport("BuilderNative.dll", CallingConvention = CallingConvention.Cdecl)]
|
|
|
|
static extern void RenderDevice_SetAlphaTestEnable(IntPtr handle, bool value);
|
|
|
|
|
|
|
|
[DllImport("BuilderNative.dll", CallingConvention = CallingConvention.Cdecl)]
|
|
|
|
static extern void RenderDevice_SetCullMode(IntPtr handle, Cull mode);
|
|
|
|
|
|
|
|
[DllImport("BuilderNative.dll", CallingConvention = CallingConvention.Cdecl)]
|
|
|
|
static extern void RenderDevice_SetBlendOperation(IntPtr handle, BlendOperation op);
|
|
|
|
|
|
|
|
[DllImport("BuilderNative.dll", CallingConvention = CallingConvention.Cdecl)]
|
|
|
|
static extern void RenderDevice_SetSourceBlend(IntPtr handle, Blend blend);
|
|
|
|
|
|
|
|
[DllImport("BuilderNative.dll", CallingConvention = CallingConvention.Cdecl)]
|
|
|
|
static extern void RenderDevice_SetDestinationBlend(IntPtr handle, Blend blend);
|
|
|
|
|
|
|
|
[DllImport("BuilderNative.dll", CallingConvention = CallingConvention.Cdecl)]
|
|
|
|
static extern void RenderDevice_SetFillMode(IntPtr handle, FillMode mode);
|
|
|
|
|
|
|
|
[DllImport("BuilderNative.dll", CallingConvention = CallingConvention.Cdecl)]
|
|
|
|
static extern void RenderDevice_SetMultisampleAntialias(IntPtr handle, bool value);
|
|
|
|
|
|
|
|
[DllImport("BuilderNative.dll", CallingConvention = CallingConvention.Cdecl)]
|
|
|
|
static extern void RenderDevice_SetZEnable(IntPtr handle, bool value);
|
|
|
|
|
|
|
|
[DllImport("BuilderNative.dll", CallingConvention = CallingConvention.Cdecl)]
|
|
|
|
static extern void RenderDevice_SetZWriteEnable(IntPtr handle, bool value);
|
|
|
|
|
2019-08-14 11:51:05 +00:00
|
|
|
[DllImport("BuilderNative.dll", CallingConvention = CallingConvention.Cdecl)]
|
|
|
|
static extern void RenderDevice_SetTexture(IntPtr handle, int unit, IntPtr texture);
|
|
|
|
|
|
|
|
[DllImport("BuilderNative.dll", CallingConvention = CallingConvention.Cdecl)]
|
|
|
|
static extern void RenderDevice_SetSamplerFilter(IntPtr handle, int unit, TextureFilter minfilter, TextureFilter magfilter, TextureFilter mipfilter, float maxanisotropy);
|
|
|
|
|
2019-08-09 22:46:51 +00:00
|
|
|
[DllImport("BuilderNative.dll", CallingConvention = CallingConvention.Cdecl)]
|
|
|
|
static extern void RenderDevice_SetSamplerState(IntPtr handle, int unit, TextureAddress addressU, TextureAddress addressV, TextureAddress addressW);
|
|
|
|
|
|
|
|
[DllImport("BuilderNative.dll", CallingConvention = CallingConvention.Cdecl)]
|
2019-08-15 00:52:21 +00:00
|
|
|
static extern void RenderDevice_Draw(IntPtr handle, PrimitiveType type, int startIndex, int primitiveCount);
|
|
|
|
|
|
|
|
[DllImport("BuilderNative.dll", CallingConvention = CallingConvention.Cdecl)]
|
|
|
|
static extern void RenderDevice_DrawIndexed(IntPtr handle, PrimitiveType type, int startIndex, int primitiveCount);
|
2019-08-09 22:46:51 +00:00
|
|
|
|
|
|
|
[DllImport("BuilderNative.dll", CallingConvention = CallingConvention.Cdecl)]
|
2019-08-16 11:07:57 +00:00
|
|
|
static extern void RenderDevice_DrawData(IntPtr handle, PrimitiveType type, int startIndex, int primitiveCount, FlatVertex[] data);
|
2019-08-09 22:46:51 +00:00
|
|
|
|
|
|
|
[DllImport("BuilderNative.dll", CallingConvention = CallingConvention.Cdecl)]
|
|
|
|
static extern void RenderDevice_StartRendering(IntPtr handle, bool clear, int backcolor);
|
|
|
|
|
|
|
|
[DllImport("BuilderNative.dll", CallingConvention = CallingConvention.Cdecl)]
|
|
|
|
static extern void RenderDevice_StartRendering(IntPtr handle, bool clear, int backcolor, IntPtr target, bool usedepthbuffer);
|
|
|
|
|
|
|
|
[DllImport("BuilderNative.dll", CallingConvention = CallingConvention.Cdecl)]
|
|
|
|
static extern void RenderDevice_FinishRendering(IntPtr handle);
|
|
|
|
|
|
|
|
[DllImport("BuilderNative.dll", CallingConvention = CallingConvention.Cdecl)]
|
|
|
|
static extern void RenderDevice_Present(IntPtr handle);
|
|
|
|
|
|
|
|
[DllImport("BuilderNative.dll", CallingConvention = CallingConvention.Cdecl)]
|
|
|
|
static extern void RenderDevice_ClearTexture(IntPtr handle, int backcolor, IntPtr texture);
|
|
|
|
|
|
|
|
[DllImport("BuilderNative.dll", CallingConvention = CallingConvention.Cdecl)]
|
2019-08-17 01:08:34 +00:00
|
|
|
static extern void RenderDevice_CopyTexture(IntPtr handle, IntPtr dst, CubeMapFace face);
|
2019-08-09 22:46:51 +00:00
|
|
|
|
2019-08-15 00:52:21 +00:00
|
|
|
[DllImport("BuilderNative.dll", CallingConvention = CallingConvention.Cdecl)]
|
|
|
|
static extern void RenderDevice_SetIndexBufferData(IntPtr handle, IntPtr buffer, int[] data, long size);
|
|
|
|
|
2019-08-16 09:24:22 +00:00
|
|
|
[DllImport("BuilderNative.dll", CallingConvention = CallingConvention.Cdecl)]
|
2019-08-16 11:07:57 +00:00
|
|
|
static extern void RenderDevice_SetVertexBufferData(IntPtr handle, IntPtr buffer, IntPtr data, long size, VertexFormat format);
|
2019-08-16 09:24:22 +00:00
|
|
|
|
2019-08-15 00:52:21 +00:00
|
|
|
[DllImport("BuilderNative.dll", CallingConvention = CallingConvention.Cdecl)]
|
2019-08-16 11:07:57 +00:00
|
|
|
static extern void RenderDevice_SetVertexBufferData(IntPtr handle, IntPtr buffer, FlatVertex[] data, long size, VertexFormat format);
|
2019-08-15 00:52:21 +00:00
|
|
|
|
|
|
|
[DllImport("BuilderNative.dll", CallingConvention = CallingConvention.Cdecl)]
|
2019-08-16 11:07:57 +00:00
|
|
|
static extern void RenderDevice_SetVertexBufferData(IntPtr handle, IntPtr buffer, WorldVertex[] data, long size, VertexFormat format);
|
2019-08-15 00:52:21 +00:00
|
|
|
|
|
|
|
[DllImport("BuilderNative.dll", CallingConvention = CallingConvention.Cdecl)]
|
|
|
|
static extern void RenderDevice_SetVertexBufferSubdata(IntPtr handle, IntPtr buffer, long destOffset, FlatVertex[] data, long sizeInBytes);
|
|
|
|
|
|
|
|
[DllImport("BuilderNative.dll", CallingConvention = CallingConvention.Cdecl)]
|
|
|
|
static extern void RenderDevice_SetVertexBufferSubdata(IntPtr handle, IntPtr buffer, long destOffset, WorldVertex[] data, long sizeInBytes);
|
|
|
|
|
|
|
|
[DllImport("BuilderNative.dll", CallingConvention = CallingConvention.Cdecl)]
|
|
|
|
protected static extern void RenderDevice_SetPixels(IntPtr handle, IntPtr texture, IntPtr data);
|
|
|
|
|
|
|
|
[DllImport("BuilderNative.dll", CallingConvention = CallingConvention.Cdecl)]
|
|
|
|
protected static extern void RenderDevice_SetCubePixels(IntPtr handle, IntPtr texture, CubeMapFace face, IntPtr data);
|
|
|
|
|
|
|
|
[DllImport("BuilderNative.dll", CallingConvention = CallingConvention.Cdecl)]
|
|
|
|
protected static extern IntPtr RenderDevice_LockTexture(IntPtr handle, IntPtr texture);
|
|
|
|
|
|
|
|
[DllImport("BuilderNative.dll", CallingConvention = CallingConvention.Cdecl)]
|
|
|
|
protected static extern void RenderDevice_UnlockTexture(IntPtr handle, IntPtr texture);
|
|
|
|
|
2019-08-09 04:18:08 +00:00
|
|
|
//mxd. Anisotropic filtering steps
|
|
|
|
public static readonly List<float> AF_STEPS = new List<float> { 1.0f, 2.0f, 4.0f, 8.0f, 16.0f };
|
|
|
|
|
|
|
|
//mxd. Antialiasing steps
|
|
|
|
public static readonly List<int> AA_STEPS = new List<int> { 0, 2, 4, 8 };
|
|
|
|
|
|
|
|
internal RenderTargetControl RenderTarget { get; private set; }
|
|
|
|
|
|
|
|
// Make a color from ARGB
|
|
|
|
public static int ARGB(float a, float r, float g, float b)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
|
|
|
return Color.FromArgb((int)(a * 255f), (int)(r * 255f), (int)(g * 255f), (int)(b * 255f)).ToArgb();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make a color from RGB
|
|
|
|
public static int RGB(int r, int g, int b)
|
|
|
|
{
|
|
|
|
return Color.FromArgb(255, r, g, b).ToArgb();
|
|
|
|
}
|
|
|
|
|
|
|
|
// This makes a Vector3 from Vector3D
|
|
|
|
public static Vector3 V3(Vector3D v3d)
|
|
|
|
{
|
|
|
|
return new Vector3(v3d.x, v3d.y, v3d.z);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This makes a Vector3D from Vector3
|
|
|
|
public static Vector3D V3D(Vector3 v3)
|
|
|
|
{
|
|
|
|
return new Vector3D(v3.X, v3.Y, v3.Z);
|
|
|
|
}
|
|
|
|
|
2010-01-30 20:46:51 +00:00
|
|
|
// This makes a Vector2 from Vector2D
|
|
|
|
public static Vector2 V2(Vector2D v2d)
|
|
|
|
{
|
|
|
|
return new Vector2(v2d.x, v2d.y);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This makes a Vector2D from Vector2
|
|
|
|
public static Vector2D V2D(Vector2 v2)
|
|
|
|
{
|
|
|
|
return new Vector2D(v2.X, v2.Y);
|
|
|
|
}
|
2019-08-13 00:43:01 +00:00
|
|
|
}
|
|
|
|
|
2019-08-14 10:36:33 +00:00
|
|
|
public enum ShaderName : int
|
2019-08-13 00:43:01 +00:00
|
|
|
{
|
|
|
|
display2d_fsaa,
|
|
|
|
display2d_normal,
|
|
|
|
display2d_fullbright,
|
|
|
|
things2d_thing,
|
|
|
|
things2d_sprite,
|
|
|
|
things2d_fill,
|
2019-08-14 05:55:21 +00:00
|
|
|
world3d_main,
|
|
|
|
world3d_fullbright,
|
|
|
|
world3d_main_highlight,
|
|
|
|
world3d_fullbright_highlight,
|
|
|
|
world3d_main_vertexcolor,
|
|
|
|
world3d_skybox,
|
|
|
|
world3d_main_highlight_vertexcolor,
|
2019-08-13 02:12:04 +00:00
|
|
|
world3d_p7,
|
2019-08-14 05:55:21 +00:00
|
|
|
world3d_main_fog,
|
2019-08-13 02:12:04 +00:00
|
|
|
world3d_p9,
|
2019-08-14 05:55:21 +00:00
|
|
|
world3d_main_highlight_fog,
|
2019-08-13 02:12:04 +00:00
|
|
|
world3d_p11,
|
2019-08-14 05:55:21 +00:00
|
|
|
world3d_main_fog_vertexcolor,
|
2019-08-13 02:12:04 +00:00
|
|
|
world3d_p13,
|
2019-08-14 05:55:21 +00:00
|
|
|
world3d_main_highlight_fog_vertexcolor,
|
|
|
|
world3d_vertex_color,
|
|
|
|
world3d_constant_color,
|
2019-08-17 01:08:34 +00:00
|
|
|
world3d_lightpass
|
2019-08-13 00:43:01 +00:00
|
|
|
}
|
|
|
|
|
2019-08-14 10:36:33 +00:00
|
|
|
public enum UniformName : int
|
2019-08-13 00:43:01 +00:00
|
|
|
{
|
|
|
|
rendersettings,
|
|
|
|
transformsettings,
|
|
|
|
desaturation,
|
|
|
|
highlightcolor,
|
|
|
|
worldviewproj,
|
|
|
|
world,
|
|
|
|
modelnormal,
|
2019-08-13 02:12:04 +00:00
|
|
|
FillColor,
|
2019-08-13 00:43:01 +00:00
|
|
|
vertexColor,
|
|
|
|
stencilColor,
|
|
|
|
lightPosAndRadius,
|
|
|
|
lightOrientation,
|
|
|
|
light2Radius,
|
|
|
|
lightColor,
|
|
|
|
ignoreNormals,
|
|
|
|
spotLight,
|
2019-08-16 12:01:27 +00:00
|
|
|
campos,
|
|
|
|
texturefactor
|
2019-08-08 01:19:11 +00:00
|
|
|
}
|
2019-08-09 04:18:08 +00:00
|
|
|
|
2019-08-16 11:07:57 +00:00
|
|
|
public enum VertexFormat : int { Flat, World }
|
2019-08-15 12:49:49 +00:00
|
|
|
public enum Cull : int { None, Clockwise }
|
2019-08-09 22:46:51 +00:00
|
|
|
public enum Blend : int { InverseSourceAlpha, SourceAlpha, One, BlendFactor }
|
|
|
|
public enum BlendOperation : int { Add, ReverseSubtract }
|
|
|
|
public enum FillMode : int { Solid, Wireframe }
|
|
|
|
public enum TextureAddress : int { Wrap, Clamp }
|
|
|
|
public enum PrimitiveType : int { LineList, TriangleList, TriangleStrip }
|
|
|
|
public enum TextureFilter : int { None, Point, Linear, Anisotropic }
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|