using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
namespace BansheeEngine
{
///
/// Material that controls how objects are rendered. It is represented by a shader and parameters used to set up that
/// shader. It provides a simple interface for manipulating the parameters.
///
public class Material : Resource
{
///
/// Creates a new empty material that references no shader.
///
public Material()
{
Internal_CreateInstance(this, IntPtr.Zero);
}
///
/// Constructor for internal runtime use only.
///
/// Dummy parameter to differentiate it from other constructors.
private Material(bool dummy)
{ }
///
/// Creates a new material with the specified shader.
///
/// Shader to initialize the material with.
public Material(Shader shader)
{
IntPtr nativeShader = IntPtr.Zero;
if (shader != null)
nativeShader = shader.GetCachedPtr();
Internal_CreateInstance(this, nativeShader);
}
///
/// Shader used by the material. Best technique from the shader will be used for rendering, depending on currently
/// active renderer and render API.
///
public Shader Shader
{
get { return Internal_GetShader(mCachedPtr); }
set
{
IntPtr nativeShader = IntPtr.Zero;
if (value != null)
nativeShader = value.GetCachedPtr();
Internal_SetShader(mCachedPtr, nativeShader);
}
}
///
/// Assigns a float value to the shader parameter with the specified name.
///
/// Name of the shader parameter.
/// Value of the parameter.
public void SetFloat(string name, float value)
{
Internal_SetFloat(mCachedPtr, name, value);
}
///
/// Assigns a 2D vector to the shader parameter with the specified name.
///
/// Name of the shader parameter.
/// Value of the parameter.
public void SetVector2(string name, Vector2 value)
{
Internal_SetVector2(mCachedPtr, name, value);
}
///
/// Assigns a 3D vector to the shader parameter with the specified name.
///
/// Name of the shader parameter.
/// Value of the parameter.
public void SetVector3(string name, Vector3 value)
{
Internal_SetVector3(mCachedPtr, name, value);
}
///
/// Assigns a 4D vector to the shader parameter with the specified name.
///
/// Name of the shader parameter.
/// Value of the parameter.
public void SetVector4(string name, Vector4 value)
{
Internal_SetVector4(mCachedPtr, name, value);
}
///
/// Assigns a 3x3 matrix to the shader parameter with the specified name.
///
/// Name of the shader parameter.
/// Value of the parameter.
public void SetMatrix3(string name, Matrix3 value)
{
Internal_SetMatrix3(mCachedPtr, name, value);
}
///
/// Assigns a 4x4 matrix to the shader parameter with the specified name.
///
/// Name of the shader parameter.
/// Value of the parameter.
public void SetMatrix4(string name, Matrix4 value)
{
Internal_SetMatrix4(mCachedPtr, name, value);
}
///
/// Assigns a color to the shader parameter with the specified name.
///
/// Name of the shader parameter.
/// Value of the parameter.
public void SetColor(string name, Color value)
{
Internal_SetColor(mCachedPtr, name, value);
}
///
/// Assigns a 2D texture to the shader parameter with the specified name.
///
/// Name of the shader parameter.
/// Value of the parameter.
public void SetTexture2D(string name, Texture2D value)
{
IntPtr texturePtr = IntPtr.Zero;
if (value != null)
texturePtr = value.GetCachedPtr();
Internal_SetTexture2D(mCachedPtr, name, texturePtr);
}
///
/// Assigns a 3D texture to the shader parameter with the specified name.
///
/// Name of the shader parameter.
/// Value of the parameter.
public void SetTexture3D(string name, Texture3D value)
{
IntPtr texturePtr = IntPtr.Zero;
if (value != null)
texturePtr = value.GetCachedPtr();
Internal_SetTexture3D(mCachedPtr, name, texturePtr);
}
///
/// Assigns a cube texture to the shader parameter with the specified name.
///
/// Name of the shader parameter.
/// Value of the parameter.
public void SetTextureCube(string name, TextureCube value)
{
IntPtr texturePtr = IntPtr.Zero;
if (value != null)
texturePtr = value.GetCachedPtr();
Internal_SetTextureCube(mCachedPtr, name, texturePtr);
}
///
/// Returns a float value assigned with the parameter with the specified name.
///
/// Name of the shader parameter.
/// Value of the parameter.
public float GetFloat(string name)
{
return Internal_GetFloat(mCachedPtr, name);
}
///
/// Returns a 2D vector assigned with the parameter with the specified name.
///
/// Name of the shader parameter.
/// Value of the parameter.
public Vector2 GetVector2(string name)
{
return Internal_GetVector2(mCachedPtr, name);
}
///
/// Returns a 3D vector assigned with the parameter with the specified name.
///
/// Name of the shader parameter.
/// Value of the parameter.
public Vector3 GetVector3(string name)
{
return Internal_GetVector3(mCachedPtr, name);
}
///
/// Returns a 4D vector assigned with the parameter with the specified name.
///
/// Name of the shader parameter.
/// Value of the parameter.
public Vector4 GetVector4(string name)
{
return Internal_GetVector4(mCachedPtr, name);
}
///
/// Returns a 3x3 matrix assigned with the parameter with the specified name.
///
/// Name of the shader parameter.
/// Value of the parameter.
public Matrix3 GetMatrix3(string name)
{
return Internal_GetMatrix3(mCachedPtr, name);
}
///
/// Returns a 4x4 matrix assigned with the parameter with the specified name.
///
/// Name of the shader parameter.
/// Value of the parameter.
public Matrix4 GetMatrix4(string name)
{
return Internal_GetMatrix4(mCachedPtr, name);
}
///
/// Returns a color assigned with the parameter with the specified name.
///
/// Name of the shader parameter.
/// Value of the parameter.
public Color GetColor(string name)
{
return Internal_GetColor(mCachedPtr, name);
}
///
/// Returns a 2D texture assigned with the parameter with the specified name.
///
/// Name of the shader parameter.
/// Value of the parameter.
public Texture2D GetTexture2D(string name)
{
return Internal_GetTexture2D(mCachedPtr, name);
}
///
/// Returns a 3D texture assigned with the parameter with the specified name.
///
/// Name of the shader parameter.
/// Value of the parameter.
public Texture3D GetTexture3D(string name)
{
return Internal_GetTexture3D(mCachedPtr, name);
}
///
/// Returns a cube texture assigned with the parameter with the specified name.
///
/// Name of the shader parameter.
/// Value of the parameter.
public TextureCube GetTextureCube(string name)
{
return Internal_GetTextureCube(mCachedPtr, name);
}
///
/// Creates a deep copy of the material.
///
/// A new object with exact data as this object.
public Material Clone()
{
return Internal_Clone(mCachedPtr);
}
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_CreateInstance(Material instance, IntPtr shader);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern Shader Internal_GetShader(IntPtr nativeInstance);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_SetShader(IntPtr nativeInstance, IntPtr shader);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_SetFloat(IntPtr nativeInstance, string name, float value);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_SetVector2(IntPtr nativeInstance, string name, Vector2 value);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_SetVector3(IntPtr nativeInstance, string name, Vector3 value);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_SetVector4(IntPtr nativeInstance, string name, Vector4 value);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_SetMatrix3(IntPtr nativeInstance, string name, Matrix3 value);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_SetMatrix4(IntPtr nativeInstance, string name, Matrix4 value);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_SetColor(IntPtr nativeInstance, string name, Color value);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_SetTexture2D(IntPtr nativeInstance, string name, IntPtr value);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_SetTexture3D(IntPtr nativeInstance, string name, IntPtr value);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_SetTextureCube(IntPtr nativeInstance, string name, IntPtr value);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern float Internal_GetFloat(IntPtr nativeInstance, string name);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern Vector2 Internal_GetVector2(IntPtr nativeInstance, string name);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern Vector3 Internal_GetVector3(IntPtr nativeInstance, string name);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern Vector4 Internal_GetVector4(IntPtr nativeInstance, string name);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern Matrix3 Internal_GetMatrix3(IntPtr nativeInstance, string name);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern Matrix4 Internal_GetMatrix4(IntPtr nativeInstance, string name);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern Color Internal_GetColor(IntPtr nativeInstance, string name);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern Texture2D Internal_GetTexture2D(IntPtr nativeInstance, string name);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern Texture3D Internal_GetTexture3D(IntPtr nativeInstance, string name);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern TextureCube Internal_GetTextureCube(IntPtr nativeInstance, string name);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern Material Internal_Clone(IntPtr nativeInstance);
}
}