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;
|
2022-01-04 19:17:12 +00:00
|
|
|
using System.Diagnostics;
|
2009-04-19 18:07:22 +00:00
|
|
|
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;
|
2019-08-30 08:30:28 +00:00
|
|
|
using System.Reflection;
|
2019-09-29 16:57:51 +00:00
|
|
|
using System.IO;
|
|
|
|
using System.Text;
|
|
|
|
using System.Linq;
|
2020-01-01 20:41:04 +00:00
|
|
|
using CodeImp.DoomBuilder.Rendering.Shaders;
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
namespace CodeImp.DoomBuilder.Rendering
|
|
|
|
{
|
2019-12-15 21:53:33 +00:00
|
|
|
public class RenderDeviceException : Exception
|
|
|
|
{
|
|
|
|
public RenderDeviceException(string message) : base(message) { }
|
|
|
|
}
|
|
|
|
|
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-12-21 01:14:42 +00:00
|
|
|
RenderTarget = rendertarget;
|
|
|
|
|
|
|
|
CreateDevice();
|
|
|
|
|
2020-01-03 01:22:33 +00:00
|
|
|
DeclareUniform(UniformName.rendersettings, "rendersettings", UniformType.Vec4f);
|
2019-12-21 01:14:42 +00:00
|
|
|
DeclareUniform(UniformName.projection, "projection", UniformType.Mat4);
|
|
|
|
DeclareUniform(UniformName.desaturation, "desaturation", UniformType.Float);
|
2020-01-03 01:22:33 +00:00
|
|
|
DeclareUniform(UniformName.highlightcolor, "highlightcolor", UniformType.Vec4f);
|
2019-12-21 01:14:42 +00:00
|
|
|
DeclareUniform(UniformName.view, "view", UniformType.Mat4);
|
|
|
|
DeclareUniform(UniformName.world, "world", UniformType.Mat4);
|
|
|
|
DeclareUniform(UniformName.modelnormal, "modelnormal", UniformType.Mat4);
|
2020-01-03 01:22:33 +00:00
|
|
|
DeclareUniform(UniformName.FillColor, "fillColor", UniformType.Vec4f);
|
|
|
|
DeclareUniform(UniformName.vertexColor, "vertexColor", UniformType.Vec4f);
|
|
|
|
DeclareUniform(UniformName.stencilColor, "stencilColor", UniformType.Vec4f);
|
|
|
|
DeclareUniform(UniformName.lightPosAndRadius, "lightPosAndRadius", UniformType.Vec4fArray);
|
|
|
|
DeclareUniform(UniformName.lightOrientation, "lightOrientation", UniformType.Vec4fArray);
|
|
|
|
DeclareUniform(UniformName.light2Radius, "light2Radius", UniformType.Vec2fArray);
|
|
|
|
DeclareUniform(UniformName.lightColor, "lightColor", UniformType.Vec4fArray);
|
2019-12-21 01:14:42 +00:00
|
|
|
DeclareUniform(UniformName.ignoreNormals, "ignoreNormals", UniformType.Float);
|
|
|
|
DeclareUniform(UniformName.spotLight, "spotLight", UniformType.Float);
|
2020-01-03 01:22:33 +00:00
|
|
|
DeclareUniform(UniformName.campos, "campos", UniformType.Vec4f);
|
|
|
|
DeclareUniform(UniformName.texturefactor, "texturefactor", UniformType.Vec4f);
|
|
|
|
DeclareUniform(UniformName.fogsettings, "fogsettings", UniformType.Vec4f);
|
|
|
|
DeclareUniform(UniformName.fogcolor, "fogcolor", UniformType.Vec4f);
|
|
|
|
DeclareUniform(UniformName.sectorfogcolor, "sectorfogcolor", UniformType.Vec4f);
|
|
|
|
DeclareUniform(UniformName.lightsEnabled, "lightsEnabled", UniformType.Float);
|
2020-01-01 20:47:33 +00:00
|
|
|
DeclareUniform(UniformName.slopeHandleLength, "slopeHandleLength", UniformType.Float);
|
2022-01-04 19:17:12 +00:00
|
|
|
|
|
|
|
// volte: classic rendering
|
|
|
|
DeclareUniform(UniformName.drawPaletted, "drawPaletted", UniformType.Int);
|
|
|
|
DeclareUniform(UniformName.colormapSize, "colormapSize", UniformType.Vec2i);
|
2022-01-31 18:49:26 +00:00
|
|
|
DeclareUniform(UniformName.doomlightlevels, "doomlightlevels", UniformType.Int);
|
|
|
|
DeclareUniform(UniformName.sectorLightLevel, "sectorLightLevel", UniformType.Int);
|
2019-08-08 01:51:21 +00:00
|
|
|
|
2020-01-01 20:41:04 +00:00
|
|
|
// 2d fsaa
|
|
|
|
CompileShader(ShaderName.display2d_fsaa, "display2d.shader", "display2d_fsaa");
|
|
|
|
|
|
|
|
// 2d normal
|
|
|
|
CompileShader(ShaderName.display2d_normal, "display2d.shader", "display2d_normal");
|
|
|
|
CompileShader(ShaderName.display2d_fullbright, "display2d.shader", "display2d_fullbright");
|
|
|
|
|
|
|
|
// 2d things
|
|
|
|
CompileShader(ShaderName.things2d_thing, "things2d.shader", "things2d_thing");
|
|
|
|
CompileShader(ShaderName.things2d_sprite, "things2d.shader", "things2d_sprite");
|
|
|
|
CompileShader(ShaderName.things2d_fill, "things2d.shader", "things2d_fill");
|
|
|
|
|
|
|
|
// non-fog 3d shaders
|
|
|
|
CompileShader(ShaderName.world3d_main, "world3d.shader", "world3d_main");
|
|
|
|
CompileShader(ShaderName.world3d_fullbright, "world3d.shader", "world3d_fullbright");
|
|
|
|
CompileShader(ShaderName.world3d_main_highlight, "world3d.shader", "world3d_main_highlight");
|
|
|
|
CompileShader(ShaderName.world3d_fullbright_highlight, "world3d.shader", "world3d_fullbright_highlight");
|
|
|
|
CompileShader(ShaderName.world3d_vertex_color, "world3d.shader", "world3d_vertex_color");
|
|
|
|
CompileShader(ShaderName.world3d_main_vertexcolor, "world3d.shader", "world3d_main_vertexcolor");
|
|
|
|
CompileShader(ShaderName.world3d_constant_color, "world3d.shader", "world3d_constant_color");
|
2022-01-04 19:17:12 +00:00
|
|
|
|
|
|
|
// classic rendering
|
|
|
|
CompileShader(ShaderName.world3d_classic, "world3d.shader", "world3d_classic");
|
|
|
|
CompileShader(ShaderName.world3d_classic_highlight, "world3d.shader", "world3d_classic_highlight");
|
2020-01-01 20:41:04 +00:00
|
|
|
|
|
|
|
// skybox shader
|
|
|
|
CompileShader(ShaderName.world3d_skybox, "world3d_skybox.shader", "world3d_skybox");
|
|
|
|
|
|
|
|
// fog 3d shaders
|
|
|
|
CompileShader(ShaderName.world3d_main_fog, "world3d.shader", "world3d_main_fog");
|
2020-01-14 09:09:33 +00:00
|
|
|
CompileShader(ShaderName.world3d_main_highlight_vertexcolor, "world3d.shader", "world3d_highlight_vertexcolor");
|
2020-01-01 20:41:04 +00:00
|
|
|
CompileShader(ShaderName.world3d_main_highlight_fog, "world3d.shader", "world3d_main_highlight_fog");
|
|
|
|
CompileShader(ShaderName.world3d_main_fog_vertexcolor, "world3d.shader", "world3d_main_fog_vertexcolor");
|
|
|
|
CompileShader(ShaderName.world3d_main_highlight_fog_vertexcolor, "world3d.shader", "world3d_main_highlight_fog_vertexcolor");
|
|
|
|
|
2020-01-04 21:15:13 +00:00
|
|
|
// Slope handle
|
|
|
|
CompileShader(ShaderName.world3d_slope_handle, "world3d.shader", "world3d_slope_handle");
|
|
|
|
|
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-12-21 01:14:42 +00:00
|
|
|
void CreateDevice()
|
|
|
|
{
|
|
|
|
// Grab the X11 Display handle by abusing reflection to access internal classes in the mono implementation.
|
|
|
|
// That's par for the course for everything in Linux, so yeah..
|
|
|
|
IntPtr display = IntPtr.Zero;
|
|
|
|
Type xplatui = Type.GetType("System.Windows.Forms.XplatUIX11, System.Windows.Forms");
|
|
|
|
if (xplatui != null)
|
|
|
|
{
|
|
|
|
display = (IntPtr)xplatui.GetField("DisplayHandle", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null);
|
|
|
|
}
|
|
|
|
|
2022-08-18 08:18:16 +00:00
|
|
|
Handle = RenderDevice_New(display, RenderTarget.Handle, General.DebugRenderDevice);
|
2019-12-21 01:14:42 +00:00
|
|
|
if (Handle == IntPtr.Zero)
|
2022-01-04 19:17:12 +00:00
|
|
|
{
|
|
|
|
StringBuilder sb = new StringBuilder(4096);
|
|
|
|
BuilderNative_GetError(sb, sb.Capacity);
|
|
|
|
throw new RenderDeviceException(string.Format("Could not create render device: {0}", sb));
|
|
|
|
}
|
2019-12-21 01:14:42 +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-12-20 02:39:06 +00:00
|
|
|
void ThrowIfFailed(bool result)
|
2019-12-16 04:54:44 +00:00
|
|
|
{
|
2019-12-20 02:39:06 +00:00
|
|
|
if (!result)
|
2022-01-04 19:17:12 +00:00
|
|
|
{
|
|
|
|
StringBuilder sb = new StringBuilder(4096);
|
|
|
|
BuilderNative_GetError(sb, sb.Capacity);
|
|
|
|
throw new RenderDeviceException(sb.ToString());
|
|
|
|
}
|
2019-12-15 21:53:33 +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-12-21 01:14:42 +00:00
|
|
|
public void DeclareUniform(UniformName name, string variablename, UniformType type)
|
|
|
|
{
|
|
|
|
RenderDevice_DeclareUniform(Handle, name, variablename, type);
|
|
|
|
}
|
|
|
|
|
2019-09-29 16:57:51 +00:00
|
|
|
public void DeclareShader(ShaderName name, string vertResourceName, string fragResourceName)
|
|
|
|
{
|
2019-12-21 00:47:27 +00:00
|
|
|
RenderDevice_DeclareShader(Handle, name, name.ToString(), GetResourceText(vertResourceName), GetResourceText(fragResourceName));
|
2019-09-29 16:57:51 +00:00
|
|
|
}
|
|
|
|
|
2020-01-01 20:41:04 +00:00
|
|
|
// save precompiled shaders -- don't build from scratch every time
|
|
|
|
private static Dictionary<string, ShaderGroup> precompiledGroups = new Dictionary<string, ShaderGroup>();
|
|
|
|
public void CompileShader(ShaderName internalName, string groupName, string shaderName)
|
|
|
|
{
|
|
|
|
ShaderGroup sg;
|
|
|
|
|
|
|
|
if (precompiledGroups.ContainsKey(groupName))
|
|
|
|
sg = precompiledGroups[groupName];
|
|
|
|
else sg = ShaderCompiler.Compile(GetResourceText(groupName));
|
|
|
|
|
|
|
|
Shader s = sg.GetShader(shaderName);
|
|
|
|
|
|
|
|
if (s == null)
|
|
|
|
throw new RenderDeviceException(string.Format("Shader {0}::{1} not found", groupName, shaderName));
|
|
|
|
|
2020-01-02 00:56:27 +00:00
|
|
|
/*General.WriteLogLine(string.Format("===========================================\nDBG: loading shader {0} / {1}\n\nVertex source: {2}\n\nFragment source: {3}\n\n===========================================",
|
|
|
|
groupName, shaderName, s.GetVertexSource(), s.GetFragmentSource()));*/
|
2020-01-01 20:41:04 +00:00
|
|
|
RenderDevice_DeclareShader(Handle, internalName, internalName.ToString(), s.GetVertexSource(), s.GetFragmentSource());
|
|
|
|
}
|
|
|
|
|
2019-09-29 16:57:51 +00:00
|
|
|
static string GetResourceText(string name)
|
|
|
|
{
|
|
|
|
string fullname = string.Format("CodeImp.DoomBuilder.Resources.{0}", name);
|
|
|
|
using (Stream stream = General.ThisAssembly.GetManifestResourceStream(fullname))
|
|
|
|
{
|
|
|
|
if (stream == null)
|
|
|
|
throw new Exception(string.Format("Resource {0} not found!", fullname));
|
|
|
|
byte[] data = new byte[stream.Length];
|
|
|
|
if (stream.Read(data, 0, data.Length) != data.Length)
|
|
|
|
throw new Exception("Could not read resource stream");
|
2020-01-01 08:21:41 +00:00
|
|
|
int start = 0;
|
|
|
|
if (data.Length >= 3 && data[0] == 0xef && data[1] == 0xbb && data[2] == 0xbf)
|
|
|
|
start = 3;
|
|
|
|
return Encoding.UTF8.GetString(data, start, data.Length - start);
|
2019-09-29 16:57:51 +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)
|
|
|
|
{
|
2020-01-02 19:31:59 +00:00
|
|
|
RenderDevice_SetUniform(Handle, uniform, new float[] { value ? 1.0f : 0.0f }, 1, sizeof(float));
|
2019-08-14 10:36:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void SetUniform(UniformName uniform, float value)
|
|
|
|
{
|
2020-01-02 19:31:59 +00:00
|
|
|
RenderDevice_SetUniform(Handle, uniform, new float[] { value }, 1, sizeof(float));
|
2019-08-14 10:36:33 +00:00
|
|
|
}
|
|
|
|
|
2020-01-03 01:22:33 +00:00
|
|
|
public void SetUniform(UniformName uniform, Vector2f value)
|
2019-08-14 10:36:33 +00:00
|
|
|
{
|
2020-01-02 19:31:59 +00:00
|
|
|
RenderDevice_SetUniform(Handle, uniform, new float[] { value.X, value.Y }, 1, sizeof(float) * 2);
|
2019-08-14 10:36:33 +00:00
|
|
|
}
|
|
|
|
|
2020-01-03 01:22:33 +00:00
|
|
|
public void SetUniform(UniformName uniform, Vector3f value)
|
2019-08-14 10:36:33 +00:00
|
|
|
{
|
2020-01-02 19:31:59 +00:00
|
|
|
RenderDevice_SetUniform(Handle, uniform, new float[] { value.X, value.Y, value.Z }, 1, sizeof(float) * 3);
|
2019-08-14 10:36:33 +00:00
|
|
|
}
|
|
|
|
|
2020-01-03 01:22:33 +00:00
|
|
|
public void SetUniform(UniformName uniform, Vector4f value)
|
2019-08-14 10:36:33 +00:00
|
|
|
{
|
2020-01-02 19:31:59 +00:00
|
|
|
RenderDevice_SetUniform(Handle, uniform, new float[] { value.X, value.Y, value.Z, value.W }, 1, sizeof(float) * 4);
|
2019-08-14 10:36:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void SetUniform(UniformName uniform, Color4 value)
|
|
|
|
{
|
2020-01-02 19:31:59 +00:00
|
|
|
RenderDevice_SetUniform(Handle, uniform, new float[] { value.Red, value.Green, value.Blue, value.Alpha }, 1, sizeof(float) * 4);
|
2019-08-14 10:36:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void SetUniform(UniformName uniform, Matrix matrix)
|
|
|
|
{
|
2020-01-02 19:31:59 +00:00
|
|
|
RenderDevice_SetUniform(Handle, uniform, ref matrix, 1, sizeof(float) * 16);
|
2019-12-19 02:12:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void SetUniform(UniformName uniform, ref Matrix matrix)
|
|
|
|
{
|
2020-01-02 19:31:59 +00:00
|
|
|
RenderDevice_SetUniform(Handle, uniform, ref matrix, 1, sizeof(float) * 16);
|
2019-08-14 10:36:33 +00:00
|
|
|
}
|
|
|
|
|
2020-01-03 01:22:33 +00:00
|
|
|
public void SetUniform(UniformName uniform, int value)
|
|
|
|
{
|
|
|
|
RenderDevice_SetUniform(Handle, uniform, new int[] { value }, 1, sizeof(int));
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetUniform(UniformName uniform, Vector2i value)
|
|
|
|
{
|
|
|
|
RenderDevice_SetUniform(Handle, uniform, new int[] { value.X, value.Y }, 1, sizeof(int) * 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetUniform(UniformName uniform, Vector3i value)
|
|
|
|
{
|
|
|
|
RenderDevice_SetUniform(Handle, uniform, new int[] { value.X, value.Y, value.Z }, 1, sizeof(int) * 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetUniform(UniformName uniform, Vector4i value)
|
|
|
|
{
|
|
|
|
RenderDevice_SetUniform(Handle, uniform, new int[] { value.X, value.Y, value.Z, value.W }, 1, sizeof(int) * 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetUniform(UniformName uniform, Vector2f[] value)
|
|
|
|
{
|
|
|
|
float[] conv = new float[value.Length * 2];
|
|
|
|
int cv = 0;
|
|
|
|
for (int i = 0; i < conv.Length; i += 2)
|
|
|
|
{
|
|
|
|
conv[i] = value[cv].X;
|
|
|
|
conv[i + 1] = value[cv].Y;
|
|
|
|
cv++;
|
|
|
|
}
|
|
|
|
RenderDevice_SetUniform(Handle, uniform, conv, value.Length, sizeof(float) * conv.Length);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetUniform(UniformName uniform, Vector3f[] value)
|
|
|
|
{
|
|
|
|
float[] conv = new float[value.Length * 3];
|
|
|
|
int cv = 0;
|
|
|
|
for (int i = 0; i < conv.Length; i += 3)
|
|
|
|
{
|
|
|
|
conv[i] = value[cv].X;
|
|
|
|
conv[i + 1] = value[cv].Y;
|
|
|
|
conv[i + 2] = value[cv].Z;
|
|
|
|
cv++;
|
|
|
|
}
|
|
|
|
RenderDevice_SetUniform(Handle, uniform, conv, value.Length, sizeof(float) * conv.Length);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetUniform(UniformName uniform, Vector4f[] value)
|
|
|
|
{
|
|
|
|
float[] conv = new float[value.Length * 4];
|
|
|
|
int cv = 0;
|
|
|
|
for (int i = 0; i < conv.Length; i += 4)
|
|
|
|
{
|
|
|
|
conv[i] = value[cv].X;
|
|
|
|
conv[i + 1] = value[cv].Y;
|
|
|
|
conv[i + 2] = value[cv].Z;
|
|
|
|
conv[i + 3] = value[cv].W;
|
|
|
|
cv++;
|
|
|
|
}
|
|
|
|
RenderDevice_SetUniform(Handle, uniform, conv, value.Length, sizeof(float) * conv.Length);
|
2019-08-14 10:36:33 +00:00
|
|
|
}
|
|
|
|
|
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 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);
|
|
|
|
}
|
|
|
|
|
2022-01-04 19:17:12 +00:00
|
|
|
public void SetTexture(BaseTexture value, int unit = 0)
|
2019-08-14 11:51:05 +00:00
|
|
|
{
|
2022-01-04 19:17:12 +00:00
|
|
|
RenderDevice_SetTexture(Handle, unit, value != null ? value.Handle : IntPtr.Zero);
|
2019-08-14 11:51:05 +00:00
|
|
|
}
|
|
|
|
|
2022-01-04 19:17:12 +00:00
|
|
|
public void SetSamplerFilter(TextureFilter filter, int unit = 0)
|
2019-08-14 11:51:05 +00:00
|
|
|
{
|
2022-01-04 19:17:12 +00:00
|
|
|
SetSamplerFilter(filter, filter, MipmapFilter.None, 0.0f, unit);
|
2019-08-14 11:51:05 +00:00
|
|
|
}
|
|
|
|
|
2022-01-04 19:17:12 +00:00
|
|
|
public void SetSamplerFilter(TextureFilter minfilter, TextureFilter magfilter, MipmapFilter mipfilter, float maxanisotropy, int unit = 0)
|
2019-08-14 11:51:05 +00:00
|
|
|
{
|
2022-01-04 19:17:12 +00:00
|
|
|
RenderDevice_SetSamplerFilter(Handle, unit, minfilter, magfilter, mipfilter, maxanisotropy);
|
2019-08-14 11:51:05 +00:00
|
|
|
}
|
|
|
|
|
2022-01-04 19:17:12 +00:00
|
|
|
public void SetSamplerState(TextureAddress address, int unit = 0)
|
2019-08-09 04:18:08 +00:00
|
|
|
{
|
2022-01-04 19:17:12 +00:00
|
|
|
RenderDevice_SetSamplerState(Handle, unit, address);
|
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)
|
|
|
|
{
|
2019-12-20 02:39:06 +00:00
|
|
|
ThrowIfFailed(RenderDevice_DrawIndexed(Handle, type, startIndex, primitiveCount));
|
2019-08-15 00:52:21 +00:00
|
|
|
}
|
|
|
|
|
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-12-20 02:39:06 +00:00
|
|
|
ThrowIfFailed(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-12-20 02:39:06 +00:00
|
|
|
ThrowIfFailed(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-12-20 02:39:06 +00:00
|
|
|
ThrowIfFailed(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-12-20 02:39:06 +00:00
|
|
|
ThrowIfFailed(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-12-20 02:39:06 +00:00
|
|
|
ThrowIfFailed(RenderDevice_FinishRendering(Handle));
|
2019-08-09 04:18:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void Present()
|
|
|
|
{
|
2019-12-20 02:39:06 +00:00
|
|
|
ThrowIfFailed(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-12-20 02:39:06 +00:00
|
|
|
ThrowIfFailed(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-12-20 02:39:06 +00:00
|
|
|
ThrowIfFailed(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)
|
|
|
|
{
|
2019-12-20 02:39:06 +00:00
|
|
|
ThrowIfFailed(RenderDevice_SetIndexBufferData(Handle, buffer.Handle, data, data.Length * Marshal.SizeOf<int>()));
|
2019-08-15 00:52:21 +00:00
|
|
|
}
|
|
|
|
|
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;
|
2019-12-20 02:39:06 +00:00
|
|
|
ThrowIfFailed(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-12-20 02:39:06 +00:00
|
|
|
ThrowIfFailed(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-12-20 02:39:06 +00:00
|
|
|
ThrowIfFailed(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-12-20 02:39:06 +00:00
|
|
|
ThrowIfFailed(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-12-20 02:39:06 +00:00
|
|
|
ThrowIfFailed(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");
|
2019-12-20 02:39:06 +00:00
|
|
|
ThrowIfFailed(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);
|
|
|
|
|
2019-12-20 02:39:06 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
ThrowIfFailed(RenderDevice_SetPixels(Handle, texture.Handle, bmpdata.Scan0));
|
|
|
|
}
|
|
|
|
finally
|
|
|
|
{
|
|
|
|
bitmap.UnlockBits(bmpdata);
|
|
|
|
}
|
2019-08-15 00:52:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2019-12-20 02:39:06 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
ThrowIfFailed(RenderDevice_SetCubePixels(Handle, texture.Handle, face, bmpdata.Scan0));
|
|
|
|
}
|
|
|
|
finally
|
|
|
|
{
|
|
|
|
bitmap.UnlockBits(bmpdata);
|
|
|
|
}
|
2019-08-15 00:52:21 +00:00
|
|
|
}
|
|
|
|
|
2019-12-16 02:15:53 +00:00
|
|
|
public unsafe void SetPixels(Texture texture, uint* pixeldata)
|
|
|
|
{
|
2019-12-20 02:39:06 +00:00
|
|
|
ThrowIfFailed(RenderDevice_SetPixels(Handle, texture.Handle, new IntPtr(pixeldata)));
|
2019-12-16 02:15:53 +00:00
|
|
|
}
|
|
|
|
|
2019-12-16 04:54:44 +00:00
|
|
|
public unsafe void* MapPBO(Texture texture)
|
|
|
|
{
|
|
|
|
void* ptr = RenderDevice_MapPBO(Handle, texture.Handle).ToPointer();
|
2019-12-20 02:39:06 +00:00
|
|
|
ThrowIfFailed(ptr != null);
|
2019-12-16 04:54:44 +00:00
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void UnmapPBO(Texture texture)
|
|
|
|
{
|
2019-12-20 02:39:06 +00:00
|
|
|
ThrowIfFailed(RenderDevice_UnmapPBO(Handle, texture.Handle));
|
2019-12-16 04:54:44 +00:00
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
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-17 01:21:11 +00:00
|
|
|
SetSamplerState(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
|
2019-12-29 17:54:22 +00:00
|
|
|
TextureFilter magminfilter = (General.Settings.VisualBilinear ? TextureFilter.Linear : TextureFilter.Nearest);
|
2019-08-17 01:21:11 +00:00
|
|
|
SetSamplerFilter(
|
2019-08-16 11:07:57 +00:00
|
|
|
magminfilter,
|
2019-12-29 17:54:22 +00:00
|
|
|
magminfilter,
|
|
|
|
General.Settings.VisualBilinear ? MipmapFilter.Linear : MipmapFilter.Nearest,
|
2019-08-16 11:07:57 +00:00
|
|
|
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;
|
|
|
|
|
2019-08-30 08:30:28 +00:00
|
|
|
[DllImport("BuilderNative", CallingConvention = CallingConvention.Cdecl)]
|
2022-08-18 08:18:16 +00:00
|
|
|
static extern IntPtr RenderDevice_New(IntPtr display, IntPtr window, bool debug);
|
2019-08-09 04:18:08 +00:00
|
|
|
|
2019-08-30 08:30:28 +00:00
|
|
|
[DllImport("BuilderNative", CallingConvention = CallingConvention.Cdecl)]
|
2019-08-09 04:18:08 +00:00
|
|
|
static extern void RenderDevice_Delete(IntPtr handle);
|
|
|
|
|
2019-12-21 01:14:42 +00:00
|
|
|
[DllImport("BuilderNative", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
|
|
|
static extern void RenderDevice_DeclareUniform(IntPtr handle, UniformName name, string variablename, UniformType type);
|
|
|
|
|
2019-09-29 16:57:51 +00:00
|
|
|
[DllImport("BuilderNative", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
2019-12-21 00:47:27 +00:00
|
|
|
static extern void RenderDevice_DeclareShader(IntPtr handle, ShaderName index, string name, string vertexShader, string fragShader);
|
2019-09-29 16:57:51 +00:00
|
|
|
|
2020-01-02 18:45:45 +00:00
|
|
|
[DllImport("BuilderNative", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
2022-01-04 19:17:12 +00:00
|
|
|
static extern void BuilderNative_GetError(StringBuilder str, int length);
|
2019-12-15 21:53:33 +00:00
|
|
|
|
|
|
|
[DllImport("BuilderNative", CallingConvention = CallingConvention.Cdecl)]
|
2019-12-20 02:39:06 +00:00
|
|
|
static extern bool RenderDevice_SetShader(IntPtr handle, ShaderName name);
|
2019-08-14 10:36:33 +00:00
|
|
|
|
2019-08-30 08:30:28 +00:00
|
|
|
[DllImport("BuilderNative", CallingConvention = CallingConvention.Cdecl)]
|
2020-01-03 01:22:33 +00:00
|
|
|
static extern void RenderDevice_SetUniform(IntPtr handle, UniformName name, int[] data, int count, int bytesize);
|
|
|
|
|
2019-08-30 08:30:28 +00:00
|
|
|
[DllImport("BuilderNative", CallingConvention = CallingConvention.Cdecl)]
|
2020-01-02 19:31:59 +00:00
|
|
|
static extern void RenderDevice_SetUniform(IntPtr handle, UniformName name, float[] data, int count, int bytesize);
|
2019-08-14 10:36:33 +00:00
|
|
|
|
2019-12-19 02:12:44 +00:00
|
|
|
[DllImport("BuilderNative", CallingConvention = CallingConvention.Cdecl)]
|
2020-01-02 19:31:59 +00:00
|
|
|
static extern void RenderDevice_SetUniform(IntPtr handle, UniformName name, ref Matrix data, int count, int bytesize);
|
2019-12-19 02:12:44 +00:00
|
|
|
|
2019-08-30 08:30:28 +00:00
|
|
|
[DllImport("BuilderNative", 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
|
|
|
|
2019-08-30 08:30:28 +00:00
|
|
|
[DllImport("BuilderNative", CallingConvention = CallingConvention.Cdecl)]
|
2019-08-09 22:46:51 +00:00
|
|
|
static extern void RenderDevice_SetIndexBuffer(IntPtr handle, IntPtr buffer);
|
|
|
|
|
2019-08-30 08:30:28 +00:00
|
|
|
[DllImport("BuilderNative", CallingConvention = CallingConvention.Cdecl)]
|
2019-08-09 22:46:51 +00:00
|
|
|
static extern void RenderDevice_SetAlphaBlendEnable(IntPtr handle, bool value);
|
|
|
|
|
2019-08-30 08:30:28 +00:00
|
|
|
[DllImport("BuilderNative", CallingConvention = CallingConvention.Cdecl)]
|
2019-08-09 22:46:51 +00:00
|
|
|
static extern void RenderDevice_SetAlphaTestEnable(IntPtr handle, bool value);
|
|
|
|
|
2019-08-30 08:30:28 +00:00
|
|
|
[DllImport("BuilderNative", CallingConvention = CallingConvention.Cdecl)]
|
2019-08-09 22:46:51 +00:00
|
|
|
static extern void RenderDevice_SetCullMode(IntPtr handle, Cull mode);
|
|
|
|
|
2019-08-30 08:30:28 +00:00
|
|
|
[DllImport("BuilderNative", CallingConvention = CallingConvention.Cdecl)]
|
2019-08-09 22:46:51 +00:00
|
|
|
static extern void RenderDevice_SetBlendOperation(IntPtr handle, BlendOperation op);
|
|
|
|
|
2019-08-30 08:30:28 +00:00
|
|
|
[DllImport("BuilderNative", CallingConvention = CallingConvention.Cdecl)]
|
2019-08-09 22:46:51 +00:00
|
|
|
static extern void RenderDevice_SetSourceBlend(IntPtr handle, Blend blend);
|
|
|
|
|
2019-08-30 08:30:28 +00:00
|
|
|
[DllImport("BuilderNative", CallingConvention = CallingConvention.Cdecl)]
|
2019-08-09 22:46:51 +00:00
|
|
|
static extern void RenderDevice_SetDestinationBlend(IntPtr handle, Blend blend);
|
|
|
|
|
2019-08-30 08:30:28 +00:00
|
|
|
[DllImport("BuilderNative", CallingConvention = CallingConvention.Cdecl)]
|
2019-08-09 22:46:51 +00:00
|
|
|
static extern void RenderDevice_SetFillMode(IntPtr handle, FillMode mode);
|
|
|
|
|
2019-08-30 08:30:28 +00:00
|
|
|
[DllImport("BuilderNative", CallingConvention = CallingConvention.Cdecl)]
|
2019-08-09 22:46:51 +00:00
|
|
|
static extern void RenderDevice_SetMultisampleAntialias(IntPtr handle, bool value);
|
|
|
|
|
2019-08-30 08:30:28 +00:00
|
|
|
[DllImport("BuilderNative", CallingConvention = CallingConvention.Cdecl)]
|
2019-08-09 22:46:51 +00:00
|
|
|
static extern void RenderDevice_SetZEnable(IntPtr handle, bool value);
|
|
|
|
|
2019-08-30 08:30:28 +00:00
|
|
|
[DllImport("BuilderNative", CallingConvention = CallingConvention.Cdecl)]
|
2019-08-09 22:46:51 +00:00
|
|
|
static extern void RenderDevice_SetZWriteEnable(IntPtr handle, bool value);
|
|
|
|
|
2019-08-30 08:30:28 +00:00
|
|
|
[DllImport("BuilderNative", CallingConvention = CallingConvention.Cdecl)]
|
2022-01-04 19:17:12 +00:00
|
|
|
static extern void RenderDevice_SetTexture(IntPtr handle, int unit, IntPtr texture);
|
2019-08-14 11:51:05 +00:00
|
|
|
|
2019-08-30 08:30:28 +00:00
|
|
|
[DllImport("BuilderNative", CallingConvention = CallingConvention.Cdecl)]
|
2022-01-04 19:17:12 +00:00
|
|
|
static extern void RenderDevice_SetSamplerFilter(IntPtr handle, int unit, TextureFilter minfilter, TextureFilter magfilter, MipmapFilter mipfilter, float maxanisotropy);
|
2019-08-14 11:51:05 +00:00
|
|
|
|
2019-08-30 08:30:28 +00:00
|
|
|
[DllImport("BuilderNative", CallingConvention = CallingConvention.Cdecl)]
|
2022-01-04 19:17:12 +00:00
|
|
|
static extern void RenderDevice_SetSamplerState(IntPtr handle, int unit, TextureAddress address);
|
2019-08-09 22:46:51 +00:00
|
|
|
|
2019-08-30 08:30:28 +00:00
|
|
|
[DllImport("BuilderNative", CallingConvention = CallingConvention.Cdecl)]
|
2019-12-20 02:39:06 +00:00
|
|
|
static extern bool RenderDevice_Draw(IntPtr handle, PrimitiveType type, int startIndex, int primitiveCount);
|
2019-08-09 22:46:51 +00:00
|
|
|
|
2019-08-30 08:30:28 +00:00
|
|
|
[DllImport("BuilderNative", CallingConvention = CallingConvention.Cdecl)]
|
2019-12-20 02:39:06 +00:00
|
|
|
static extern bool RenderDevice_DrawIndexed(IntPtr handle, PrimitiveType type, int startIndex, int primitiveCount);
|
2019-08-09 22:46:51 +00:00
|
|
|
|
2019-08-30 08:30:28 +00:00
|
|
|
[DllImport("BuilderNative", CallingConvention = CallingConvention.Cdecl)]
|
2019-12-20 02:39:06 +00:00
|
|
|
static extern bool RenderDevice_DrawData(IntPtr handle, PrimitiveType type, int startIndex, int primitiveCount, FlatVertex[] data);
|
2019-08-09 22:46:51 +00:00
|
|
|
|
2019-08-30 08:30:28 +00:00
|
|
|
[DllImport("BuilderNative", CallingConvention = CallingConvention.Cdecl)]
|
2019-12-20 02:39:06 +00:00
|
|
|
static extern bool RenderDevice_StartRendering(IntPtr handle, bool clear, int backcolor, IntPtr target, bool usedepthbuffer);
|
2019-08-09 22:46:51 +00:00
|
|
|
|
2019-08-30 08:30:28 +00:00
|
|
|
[DllImport("BuilderNative", CallingConvention = CallingConvention.Cdecl)]
|
2019-12-20 02:39:06 +00:00
|
|
|
static extern bool RenderDevice_FinishRendering(IntPtr handle);
|
2019-08-09 22:46:51 +00:00
|
|
|
|
2019-08-30 08:30:28 +00:00
|
|
|
[DllImport("BuilderNative", CallingConvention = CallingConvention.Cdecl)]
|
2019-12-20 02:39:06 +00:00
|
|
|
static extern bool RenderDevice_Present(IntPtr handle);
|
2019-08-09 22:46:51 +00:00
|
|
|
|
2019-08-30 08:30:28 +00:00
|
|
|
[DllImport("BuilderNative", CallingConvention = CallingConvention.Cdecl)]
|
2019-12-20 02:39:06 +00:00
|
|
|
static extern bool RenderDevice_ClearTexture(IntPtr handle, int backcolor, IntPtr texture);
|
2019-08-09 22:46:51 +00:00
|
|
|
|
2019-08-30 08:30:28 +00:00
|
|
|
[DllImport("BuilderNative", CallingConvention = CallingConvention.Cdecl)]
|
2019-12-20 02:39:06 +00:00
|
|
|
static extern bool RenderDevice_CopyTexture(IntPtr handle, IntPtr dst, CubeMapFace face);
|
2019-08-09 22:46:51 +00:00
|
|
|
|
2019-08-30 08:30:28 +00:00
|
|
|
[DllImport("BuilderNative", CallingConvention = CallingConvention.Cdecl)]
|
2019-12-20 02:39:06 +00:00
|
|
|
static extern bool RenderDevice_SetIndexBufferData(IntPtr handle, IntPtr buffer, int[] data, long size);
|
2019-08-15 00:52:21 +00:00
|
|
|
|
2019-08-30 08:30:28 +00:00
|
|
|
[DllImport("BuilderNative", CallingConvention = CallingConvention.Cdecl)]
|
2019-12-20 02:39:06 +00:00
|
|
|
static extern bool RenderDevice_SetVertexBufferData(IntPtr handle, IntPtr buffer, IntPtr data, long size, VertexFormat format);
|
2019-08-16 09:24:22 +00:00
|
|
|
|
2019-08-30 08:30:28 +00:00
|
|
|
[DllImport("BuilderNative", CallingConvention = CallingConvention.Cdecl)]
|
2019-12-20 02:39:06 +00:00
|
|
|
static extern bool RenderDevice_SetVertexBufferData(IntPtr handle, IntPtr buffer, FlatVertex[] data, long size, VertexFormat format);
|
2019-08-15 00:52:21 +00:00
|
|
|
|
2019-08-30 08:30:28 +00:00
|
|
|
[DllImport("BuilderNative", CallingConvention = CallingConvention.Cdecl)]
|
2019-12-20 02:39:06 +00:00
|
|
|
static extern bool RenderDevice_SetVertexBufferData(IntPtr handle, IntPtr buffer, WorldVertex[] data, long size, VertexFormat format);
|
2019-08-15 00:52:21 +00:00
|
|
|
|
2019-08-30 08:30:28 +00:00
|
|
|
[DllImport("BuilderNative", CallingConvention = CallingConvention.Cdecl)]
|
2019-12-20 02:39:06 +00:00
|
|
|
static extern bool RenderDevice_SetVertexBufferSubdata(IntPtr handle, IntPtr buffer, long destOffset, FlatVertex[] data, long sizeInBytes);
|
2019-08-15 00:52:21 +00:00
|
|
|
|
2019-08-30 08:30:28 +00:00
|
|
|
[DllImport("BuilderNative", CallingConvention = CallingConvention.Cdecl)]
|
2019-12-20 02:39:06 +00:00
|
|
|
static extern bool RenderDevice_SetVertexBufferSubdata(IntPtr handle, IntPtr buffer, long destOffset, WorldVertex[] data, long sizeInBytes);
|
2019-08-15 00:52:21 +00:00
|
|
|
|
2019-08-30 08:30:28 +00:00
|
|
|
[DllImport("BuilderNative", CallingConvention = CallingConvention.Cdecl)]
|
2019-12-20 02:39:06 +00:00
|
|
|
protected static extern bool RenderDevice_SetPixels(IntPtr handle, IntPtr texture, IntPtr data);
|
2019-08-15 00:52:21 +00:00
|
|
|
|
2019-12-16 04:54:44 +00:00
|
|
|
[DllImport("BuilderNative", CallingConvention = CallingConvention.Cdecl)]
|
|
|
|
protected static extern IntPtr RenderDevice_MapPBO(IntPtr handle, IntPtr texture);
|
|
|
|
|
|
|
|
[DllImport("BuilderNative", CallingConvention = CallingConvention.Cdecl)]
|
2019-12-20 02:39:06 +00:00
|
|
|
protected static extern bool RenderDevice_UnmapPBO(IntPtr handle, IntPtr texture);
|
2019-12-16 04:54:44 +00:00
|
|
|
|
2019-08-30 08:30:28 +00:00
|
|
|
[DllImport("BuilderNative", CallingConvention = CallingConvention.Cdecl)]
|
2019-12-20 02:39:06 +00:00
|
|
|
protected static extern bool RenderDevice_SetCubePixels(IntPtr handle, IntPtr texture, CubeMapFace face, IntPtr data);
|
2019-08-15 00:52:21 +00:00
|
|
|
|
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; }
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
// This makes a Vector3 from Vector3D
|
2020-01-03 01:22:33 +00:00
|
|
|
public static Vector3f V3(Vector3D v3d)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2020-05-18 16:14:54 +00:00
|
|
|
return new Vector3f((float)v3d.x, (float)v3d.y, (float)v3d.z);
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This makes a Vector3D from Vector3
|
2020-01-03 01:22:33 +00:00
|
|
|
public static Vector3D V3D(Vector3f v3)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
|
|
|
return new Vector3D(v3.X, v3.Y, v3.Z);
|
|
|
|
}
|
|
|
|
|
2010-01-30 20:46:51 +00:00
|
|
|
// This makes a Vector2 from Vector2D
|
2020-01-03 01:22:33 +00:00
|
|
|
public static Vector2f V2(Vector2D v2d)
|
2010-01-30 20:46:51 +00:00
|
|
|
{
|
2020-05-18 16:14:54 +00:00
|
|
|
return new Vector2f((float)v2d.x, (float)v2d.y);
|
2010-01-30 20:46:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This makes a Vector2D from Vector2
|
2020-01-03 01:22:33 +00:00
|
|
|
public static Vector2D V2D(Vector2f v2)
|
2010-01-30 20:46:51 +00:00
|
|
|
{
|
|
|
|
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,
|
2022-01-04 19:17:12 +00:00
|
|
|
world3d_slope_handle,
|
|
|
|
world3d_classic,
|
|
|
|
world3d_p19,
|
|
|
|
world3d_classic_highlight
|
2019-08-13 00:43:01 +00:00
|
|
|
}
|
|
|
|
|
2019-12-21 01:14:42 +00:00
|
|
|
public enum UniformType : int
|
|
|
|
{
|
2020-01-03 01:22:33 +00:00
|
|
|
Vec4f,
|
|
|
|
Vec3f,
|
|
|
|
Vec2f,
|
2019-12-21 01:14:42 +00:00
|
|
|
Float,
|
2020-01-03 01:22:33 +00:00
|
|
|
Mat4,
|
|
|
|
Vec4i,
|
|
|
|
Vec3i,
|
|
|
|
Vec2i,
|
|
|
|
Int,
|
|
|
|
Vec4fArray,
|
|
|
|
Vec3fArray,
|
|
|
|
Vec2fArray
|
2019-12-21 01:14:42 +00:00
|
|
|
}
|
|
|
|
|
2019-08-14 10:36:33 +00:00
|
|
|
public enum UniformName : int
|
2019-08-13 00:43:01 +00:00
|
|
|
{
|
|
|
|
rendersettings,
|
2019-08-22 16:43:54 +00:00
|
|
|
projection,
|
2019-08-13 00:43:01 +00:00
|
|
|
desaturation,
|
|
|
|
highlightcolor,
|
2019-08-22 16:43:54 +00:00
|
|
|
view,
|
2019-08-13 00:43:01 +00:00
|
|
|
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,
|
2019-08-22 16:43:54 +00:00
|
|
|
texturefactor,
|
|
|
|
fogsettings,
|
2020-01-01 20:47:33 +00:00
|
|
|
fogcolor,
|
2020-01-03 01:22:33 +00:00
|
|
|
sectorfogcolor,
|
2020-01-04 21:15:13 +00:00
|
|
|
lightsEnabled,
|
2022-01-04 19:17:12 +00:00
|
|
|
slopeHandleLength,
|
|
|
|
drawPaletted,
|
|
|
|
colormapSize,
|
2022-01-31 18:49:26 +00:00
|
|
|
sectorLightLevel,
|
|
|
|
doomlightlevels
|
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-17 03:21:28 +00:00
|
|
|
public enum Blend : int { InverseSourceAlpha, SourceAlpha, One }
|
2019-08-09 22:46:51 +00:00
|
|
|
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 }
|
2019-12-29 17:54:22 +00:00
|
|
|
public enum TextureFilter : int { Nearest, Linear }
|
|
|
|
public enum MipmapFilter : int { None, Nearest, Linear}
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|