Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added methods and constants to SharpGL.Core to allow the use of VAO and PBO. #37

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
150 changes: 150 additions & 0 deletions source/SharpGL/Core/SharpGL.SceneGraph/JOG/ColorF.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SharpGL.SceneGraph.JOG
{
public class ColorF
{
#region fields
float[] _argb = new float[4];
#endregion fields

#region properties
public float A
{
get { return this[0]; }
set { this[0] = value; }
}

public float R
{
get { return this[1]; }
set { this[1] = value; }
}

public float G
{
get { return this[2]; }
set { this[2] = value; }
}

public float B
{
get { return this[3]; }
set { this[3] = value; }
}

/// <summary>
/// Gets or sets a color by index (0 = Alpha, 1 = Red, 2 = Green, 3 = Blue)
/// </summary>
/// <param name="it"></param>
/// <returns></returns>
public float this[int i]
{
get
{
return _argb[i];
}
set
{
_argb[i] = value;
}
}

public float[] Argb
{
get { return _argb; }
set { _argb = value; }
}
#endregion properties

#region constructors
public ColorF()
{ }

/// <summary>
/// Converts uint to ColorF. Second byte = blue, Thirth byte = green, Last byte = red.
/// </summary>
/// <param name="colorRGB"></param>
public ColorF(uint colorRGB)
{
// Get the integer ID
var i = colorRGB;

int b = (int)(i >> 16) & 0xFF;
int g = (int)(i >> 8) & 0xFF;
int r = (int)i & 0xFF;

IntToFloatColor(255, r, g, b);
}

/// <summary>
/// Converts uint to ColorF. 3th and 4th byte = blue, 5th and 6th byte = green, 7th and last byte = red.
/// </summary>
/// <param name="colorRGB"></param>
public ColorF(ulong colorRGB)
{
// Get the integer ID
var i = colorRGB;

int b = (int)(i >> 32) & 0xFF;
int g = (int)(i >> 16) & 0xFF;
int r = (int)i & 0xFF;

IntToFloatColor(255, r, g, b);
}

public ColorF(int a, int r, int g, int b)
{
IntToFloatColor(a, r, g, b);
}

public ColorF(float a, float r, float g, float b)
{
A = a;
R = r;
G = g;
B = b;
}

public ColorF(System.Drawing.Color color)
: this(color.A, color.R, color.G, color.B)
{ }


#endregion constructors

private void IntToFloatColor(int a, int r, int g, int b)
{
A = a / 255.0f;
R = r / 255.0f;
G = g / 255.0f;
B = b / 255.0f;
}

public uint ToUint()
{
// Get color id from pixel data.
return (uint)(R * 255 + G * 65025 + B * 16581375); // r * 255 + g * 255² + b * 255³.
}

public float[] ToRGB()
{
return new float[] { R, G, B };
}
public float[] ToRGBA()
{
return new float[] { R, G, B, A };
}
public float[] ToBGR()
{
return new float[] { B, G, R };
}
public float[] ToBGRA()
{
return new float[] { B, G, R, A };
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System.IO;
using System.Reflection;
using System.Resources;
using System.Text;

namespace SharpGL.SceneGraph.JOG
{
/// <summary>
/// A small helper class to load manifest resource files.
/// </summary>
public static class ManifestResourceLoader
{
/// <summary>
/// Loads the named manifest resource as a text string.
/// </summary>
/// <param name="textFileName">Name of the text file.</param>
/// <returns>The contents of the manifest resource.</returns>
public static string LoadTextFile(string path, Assembly executingAssembly, bool autoAttachAssemblyName = true)
{
if (executingAssembly == null)
executingAssembly = Assembly.GetExecutingAssembly();

var pathToDots = path.Replace("\\", ".").Replace("/", ".");


string location;
if (autoAttachAssemblyName)
{
string assemblyName = executingAssembly.GetName().Name;
location = string.Format("{0}.{1}", assemblyName, pathToDots);
}
else
{
location = pathToDots;
}

using (var stream = executingAssembly.GetManifestResourceStream(location))
{
using (var reader = new StreamReader(stream))
{
return reader.ReadToEnd();
}
}
}
}
}
77 changes: 77 additions & 0 deletions source/SharpGL/Core/SharpGL.SceneGraph/JOG/Material.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Drawing;
using System.Linq;
using System.Text;

namespace SharpGL.SceneGraph.JOG
{
/// <summary>
///
/// </summary>
public class Material
{
#region fields
static ColorF _defaultColor = new ColorF(0, 0, 0, 0);
float shininess;
ColorF _ambient, diffuse, specular, emission;
#endregion fields

#region properties
public ColorF Ambient
{
get { return _ambient; }
set { _ambient = value; }
}

public ColorF Diffuse
{
get { return diffuse; }
set { diffuse = value; }
}

public ColorF Specular
{
get { return specular; }
set { specular = value; }
}

public ColorF Emission
{
get { return emission; }
set { emission = value; }
}

public float Shininess
{
get { return shininess; }
set { shininess = value; }
}
#endregion properties

#region constructors
/// <summary>
/// Default constructor. No users will be recorded.
/// </summary>
public Material()
{
Ambient = _defaultColor;
Diffuse = _defaultColor;
Specular = _defaultColor;
Emission = _defaultColor;
}
public Material(ColorF ambient, ColorF diffuse, ColorF specular, ColorF emission, float shininess)
: this()
{
Ambient = ambient == null? _defaultColor : ambient;
Diffuse = diffuse == null? _defaultColor : diffuse;
Specular = specular == null? _defaultColor : specular;
Emission = emission == null? _defaultColor : emission;
Shininess = shininess;
}
#endregion constructors


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
<UseVSHostingProcess>true</UseVSHostingProcess>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand Down Expand Up @@ -64,6 +65,9 @@
<Compile Include="..\..\SharedAssemblyInfo.cs">
<Link>Properties\SharedAssemblyInfo.cs</Link>
</Compile>
<Compile Include="JOG\ColorF.cs" />
<Compile Include="JOG\ManifestResourceLoader.cs" />
<Compile Include="JOG\Material.cs" />
<Compile Include="Core\IHasMaterial.cs" />
<Compile Include="IDeepClonable.cs" />
<Compile Include="NETDesignSurface.cs" />
Expand Down Expand Up @@ -178,6 +182,7 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<None Include="SharpGL.snk" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
4 changes: 4 additions & 0 deletions source/SharpGL/Core/SharpGL.SceneGraph/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="GlmNet" version="0.0.2.0" targetFramework="net40" />
</packages>
Loading