Added documentation.
Added more documentation. Corrected doc.
This commit is contained in:
parent
d541961007
commit
04f9aab10b
@ -1,8 +1,16 @@
|
|||||||
using OpenTK;
|
using OpenTK;
|
||||||
|
|
||||||
namespace RecrownedGTK.Graphics {
|
namespace RecrownedGTK.Graphics {
|
||||||
|
/// <summary>
|
||||||
|
/// Basic camera handling up to x, y and z axis.
|
||||||
|
/// </summary>
|
||||||
public class Camera {
|
public class Camera {
|
||||||
private Vector3 scale = new Vector3(1f), translate, rotation;
|
private Vector3 scale = new Vector3(1f), translate, rotation;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Scale factor multiplied to the camera coordinates.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The value to be multiplied.</value>
|
||||||
public Vector3 Scale {
|
public Vector3 Scale {
|
||||||
get {
|
get {
|
||||||
return scale;
|
return scale;
|
||||||
@ -12,12 +20,21 @@ namespace RecrownedGTK.Graphics {
|
|||||||
scale = value;
|
scale = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The translation applied after scaling and rotating.
|
||||||
|
/// </summary>
|
||||||
|
/// <value></value>
|
||||||
public Vector3 Translate {
|
public Vector3 Translate {
|
||||||
set {
|
set {
|
||||||
updated = true;
|
updated = true;
|
||||||
translate = value;
|
translate = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Rotation applied before translation.
|
||||||
|
/// </summary>
|
||||||
|
/// <value></value>
|
||||||
public Vector3 Rotation {
|
public Vector3 Rotation {
|
||||||
set {
|
set {
|
||||||
updated = true;
|
updated = true;
|
||||||
@ -29,6 +46,10 @@ namespace RecrownedGTK.Graphics {
|
|||||||
}
|
}
|
||||||
private Matrix4 transform;
|
private Matrix4 transform;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// If values have updated, recalculate transformation matrix.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The transformation matrix.</value>
|
||||||
public Matrix4 Transform {
|
public Matrix4 Transform {
|
||||||
get {
|
get {
|
||||||
if (!updated) return transform;
|
if (!updated) return transform;
|
||||||
|
@ -11,6 +11,7 @@ namespace RecrownedGTK.Graphics {
|
|||||||
public void Bind() {
|
public void Bind() {
|
||||||
GL.BindBuffer(BufferTarget.ElementArrayBuffer, handle);
|
GL.BindBuffer(BufferTarget.ElementArrayBuffer, handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Buffer(uint[] indices, BufferUsageHint hint = BufferUsageHint.DynamicDraw) {
|
public void Buffer(uint[] indices, BufferUsageHint hint = BufferUsageHint.DynamicDraw) {
|
||||||
Bind();
|
Bind();
|
||||||
GL.BufferData(BufferTarget.ElementArrayBuffer, indices.Length * sizeof(uint), indices, hint);
|
GL.BufferData(BufferTarget.ElementArrayBuffer, indices.Length * sizeof(uint), indices, hint);
|
||||||
|
@ -4,6 +4,10 @@ using OpenTK.Graphics.OpenGL;
|
|||||||
using OpenTK.Graphics;
|
using OpenTK.Graphics;
|
||||||
using System;
|
using System;
|
||||||
namespace RecrownedGTK.Graphics {
|
namespace RecrownedGTK.Graphics {
|
||||||
|
/// <summary>
|
||||||
|
/// Represents the texture for any given vertice.
|
||||||
|
/// Contains bytes that form the texture.
|
||||||
|
/// </summary>
|
||||||
public class TextureData : IDisposable {
|
public class TextureData : IDisposable {
|
||||||
private bool disposed;
|
private bool disposed;
|
||||||
int handle;
|
int handle;
|
||||||
@ -13,6 +17,10 @@ namespace RecrownedGTK.Graphics {
|
|||||||
public TextureMinFilter textureMinFilter;
|
public TextureMinFilter textureMinFilter;
|
||||||
public TextureMagFilter textureMagFilter;
|
public TextureMagFilter textureMagFilter;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Generates a texture data with a png.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="path">A path to a texture represented in PNG format.</param>
|
||||||
public TextureData(string path) {
|
public TextureData(string path) {
|
||||||
int width;
|
int width;
|
||||||
int height;
|
int height;
|
||||||
@ -20,6 +28,12 @@ namespace RecrownedGTK.Graphics {
|
|||||||
GenerateTexture(textureData, width, height);
|
GenerateTexture(textureData, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Generates a texture using a byte array of the texture data.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="textureData">The byte array representing the texture.</param>
|
||||||
|
/// <param name="width">The width of the texture.</param>
|
||||||
|
/// <param name="height">The height of the texture.</param>
|
||||||
public TextureData(byte[] textureData, int width, int height) {
|
public TextureData(byte[] textureData, int width, int height) {
|
||||||
textureWrapModeHeight = TextureWrapMode.ClampToBorder;
|
textureWrapModeHeight = TextureWrapMode.ClampToBorder;
|
||||||
textureWrapModeWidth = TextureWrapMode.ClampToBorder;
|
textureWrapModeWidth = TextureWrapMode.ClampToBorder;
|
||||||
@ -30,6 +44,15 @@ namespace RecrownedGTK.Graphics {
|
|||||||
GenerateTexture(textureData, width, height);
|
GenerateTexture(textureData, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///Load PNG data to this texture representation.
|
||||||
|
///
|
||||||
|
/// Decodes the PNG into a byte array to be stored.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="path">The path to the PNG file to be represented.</param>
|
||||||
|
/// <param name="width">Outputs the width of the PNG file.</param>
|
||||||
|
/// <param name="height">Outputs the height of the PNG file.</param>
|
||||||
|
/// <returns>A byte array representing the PNG.</returns>
|
||||||
private byte[] LoadPNG(string path, out int width, out int height) {
|
private byte[] LoadPNG(string path, out int width, out int height) {
|
||||||
byte[] textureData = null;
|
byte[] textureData = null;
|
||||||
using (FileStream file = new FileStream(path, FileMode.Open)) {
|
using (FileStream file = new FileStream(path, FileMode.Open)) {
|
||||||
@ -43,6 +66,12 @@ namespace RecrownedGTK.Graphics {
|
|||||||
return textureData;
|
return textureData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Generates a texture in the OpenGL context.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="textureData">Byte array representing the texture.</param>
|
||||||
|
/// <param name="width">Width of the texture.</param>
|
||||||
|
/// <param name="height">Height of the texture.</param>
|
||||||
private void GenerateTexture(byte[] textureData, int width, int height) {
|
private void GenerateTexture(byte[] textureData, int width, int height) {
|
||||||
if (handle != 0) throw new InvalidOperationException("This texture data already holds a texture.");
|
if (handle != 0) throw new InvalidOperationException("This texture data already holds a texture.");
|
||||||
handle = GL.GenTexture();
|
handle = GL.GenTexture();
|
||||||
@ -51,9 +80,16 @@ namespace RecrownedGTK.Graphics {
|
|||||||
GL.GenerateMipmap(GenerateMipmapTarget.Texture2D);
|
GL.GenerateMipmap(GenerateMipmapTarget.Texture2D);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Binds the OpenGL texture.
|
||||||
|
/// </summary>
|
||||||
internal void Use() {
|
internal void Use() {
|
||||||
GL.BindTexture(TextureTarget.Texture2D, handle);
|
GL.BindTexture(TextureTarget.Texture2D, handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Removes texture data from memory.
|
||||||
|
/// </summary>
|
||||||
public void Dispose() {
|
public void Dispose() {
|
||||||
Dispose(true);
|
Dispose(true);
|
||||||
GC.SuppressFinalize(this);
|
GC.SuppressFinalize(this);
|
||||||
|
@ -3,13 +3,24 @@ using OpenTK.Graphics.OpenGL;
|
|||||||
using OpenTK;
|
using OpenTK;
|
||||||
using RecrownedGTK.Graphics.Render.Shaders;
|
using RecrownedGTK.Graphics.Render.Shaders;
|
||||||
namespace RecrownedGTK.Graphics {
|
namespace RecrownedGTK.Graphics {
|
||||||
|
/// <summary>
|
||||||
|
/// The attributes of the vertex.
|
||||||
|
/// Handle for openGL.
|
||||||
|
/// </summary>
|
||||||
public class VertexAttributesArrayHandle : IDisposable {
|
public class VertexAttributesArrayHandle : IDisposable {
|
||||||
private bool disposed;
|
private bool disposed;
|
||||||
private int handle;
|
private int handle;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Generates an openGL vertex array.
|
||||||
|
/// </summary>
|
||||||
public VertexAttributesArrayHandle() {
|
public VertexAttributesArrayHandle() {
|
||||||
handle = GL.GenVertexArray();
|
handle = GL.GenVertexArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Tells openGL to bind this vertex attributes array.
|
||||||
|
/// </summary>
|
||||||
public void Bind() {
|
public void Bind() {
|
||||||
GL.BindVertexArray(handle);
|
GL.BindVertexArray(handle);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
using System;
|
using System;
|
||||||
using OpenTK.Graphics.OpenGL;
|
using OpenTK.Graphics.OpenGL;
|
||||||
namespace RecrownedGTK.Graphics {
|
namespace RecrownedGTK.Graphics {
|
||||||
|
/// <summary>
|
||||||
|
/// Handles the openGL vertex buffer.
|
||||||
|
/// </summary>
|
||||||
public class VertexBufferArrayHandle : IDisposable {
|
public class VertexBufferArrayHandle : IDisposable {
|
||||||
private bool disposed;
|
private bool disposed;
|
||||||
private int handle;
|
private int handle;
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
using OpenTK;
|
using OpenTK;
|
||||||
using OpenTK.Graphics;
|
using OpenTK.Graphics;
|
||||||
namespace RecrownedGTK.Graphics {
|
namespace RecrownedGTK.Graphics {
|
||||||
|
/// <summary>
|
||||||
|
/// Stores the information that is required per vertex.
|
||||||
|
/// </summary>
|
||||||
public struct VertexInformation {
|
public struct VertexInformation {
|
||||||
public Vector3 coords;
|
public Vector3 coords;
|
||||||
public Vector2 textureCoords;
|
public Vector2 textureCoords;
|
||||||
|
@ -1,7 +1,18 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
namespace RecrownedGTK.Persistence {
|
namespace RecrownedGTK.Persistence {
|
||||||
|
/// <summary>
|
||||||
|
/// Serializable preferences.
|
||||||
|
/// </summary>
|
||||||
public struct PreferencesInfo {
|
public struct PreferencesInfo {
|
||||||
|
/// <summary>
|
||||||
|
/// Array of preferences.
|
||||||
|
/// </summary>
|
||||||
public PreferenceInfo[] preferences;
|
public PreferenceInfo[] preferences;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the serializable preference with a string string value pair dictionary.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="preferences">A dictionary of string and string pair.</param>
|
||||||
public void SetPreferences(Dictionary<string, string> preferences)
|
public void SetPreferences(Dictionary<string, string> preferences)
|
||||||
{
|
{
|
||||||
this.preferences = new PreferenceInfo[preferences.Count];
|
this.preferences = new PreferenceInfo[preferences.Count];
|
||||||
@ -13,6 +24,10 @@ namespace RecrownedGTK.Persistence {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Return a dictionary containing a string string key value pair.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Dictionary with a string value and string key representing a preference option.</returns>
|
||||||
public Dictionary<string, string> GetPreferences() {
|
public Dictionary<string, string> GetPreferences() {
|
||||||
Dictionary<string, string> res = new Dictionary<string, string>();
|
Dictionary<string, string> res = new Dictionary<string, string>();
|
||||||
for (int prefID = 0; prefID < preferences.Length; prefID++) {
|
for (int prefID = 0; prefID < preferences.Length; prefID++) {
|
||||||
@ -21,7 +36,13 @@ namespace RecrownedGTK.Persistence {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Serializable preference option.
|
||||||
|
/// </summary>
|
||||||
public struct PreferenceInfo {
|
public struct PreferenceInfo {
|
||||||
|
/// <summary>
|
||||||
|
/// The key and value of the option in the preferences.
|
||||||
|
/// </summary>
|
||||||
public string key, value;
|
public string key, value;
|
||||||
|
|
||||||
public PreferenceInfo(string key, string value) {
|
public PreferenceInfo(string key, string value) {
|
||||||
|
Loading…
Reference in New Issue
Block a user