Added documentation.

Added more documentation.

Corrected doc.
This commit is contained in:
Harrison Deng 2020-04-04 17:35:06 -05:00
parent d541961007
commit 04f9aab10b
7 changed files with 96 additions and 0 deletions

View File

@ -1,8 +1,16 @@
using OpenTK;
namespace RecrownedGTK.Graphics {
/// <summary>
/// Basic camera handling up to x, y and z axis.
/// </summary>
public class Camera {
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 {
get {
return scale;
@ -12,12 +20,21 @@ namespace RecrownedGTK.Graphics {
scale = value;
}
}
/// <summary>
/// The translation applied after scaling and rotating.
/// </summary>
/// <value></value>
public Vector3 Translate {
set {
updated = true;
translate = value;
}
}
/// <summary>
/// Rotation applied before translation.
/// </summary>
/// <value></value>
public Vector3 Rotation {
set {
updated = true;
@ -29,6 +46,10 @@ namespace RecrownedGTK.Graphics {
}
private Matrix4 transform;
/// <summary>
/// If values have updated, recalculate transformation matrix.
/// </summary>
/// <value>The transformation matrix.</value>
public Matrix4 Transform {
get {
if (!updated) return transform;

View File

@ -11,6 +11,7 @@ namespace RecrownedGTK.Graphics {
public void Bind() {
GL.BindBuffer(BufferTarget.ElementArrayBuffer, handle);
}
public void Buffer(uint[] indices, BufferUsageHint hint = BufferUsageHint.DynamicDraw) {
Bind();
GL.BufferData(BufferTarget.ElementArrayBuffer, indices.Length * sizeof(uint), indices, hint);

View File

@ -4,6 +4,10 @@ using OpenTK.Graphics.OpenGL;
using OpenTK.Graphics;
using System;
namespace RecrownedGTK.Graphics {
/// <summary>
/// Represents the texture for any given vertice.
/// Contains bytes that form the texture.
/// </summary>
public class TextureData : IDisposable {
private bool disposed;
int handle;
@ -13,6 +17,10 @@ namespace RecrownedGTK.Graphics {
public TextureMinFilter textureMinFilter;
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) {
int width;
int height;
@ -20,6 +28,12 @@ namespace RecrownedGTK.Graphics {
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) {
textureWrapModeHeight = TextureWrapMode.ClampToBorder;
textureWrapModeWidth = TextureWrapMode.ClampToBorder;
@ -30,6 +44,15 @@ namespace RecrownedGTK.Graphics {
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) {
byte[] textureData = null;
using (FileStream file = new FileStream(path, FileMode.Open)) {
@ -43,6 +66,12 @@ namespace RecrownedGTK.Graphics {
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) {
if (handle != 0) throw new InvalidOperationException("This texture data already holds a texture.");
handle = GL.GenTexture();
@ -51,9 +80,16 @@ namespace RecrownedGTK.Graphics {
GL.GenerateMipmap(GenerateMipmapTarget.Texture2D);
}
/// <summary>
/// Binds the OpenGL texture.
/// </summary>
internal void Use() {
GL.BindTexture(TextureTarget.Texture2D, handle);
}
/// <summary>
/// Removes texture data from memory.
/// </summary>
public void Dispose() {
Dispose(true);
GC.SuppressFinalize(this);

View File

@ -3,13 +3,24 @@ using OpenTK.Graphics.OpenGL;
using OpenTK;
using RecrownedGTK.Graphics.Render.Shaders;
namespace RecrownedGTK.Graphics {
/// <summary>
/// The attributes of the vertex.
/// Handle for openGL.
/// </summary>
public class VertexAttributesArrayHandle : IDisposable {
private bool disposed;
private int handle;
/// <summary>
/// Generates an openGL vertex array.
/// </summary>
public VertexAttributesArrayHandle() {
handle = GL.GenVertexArray();
}
/// <summary>
/// Tells openGL to bind this vertex attributes array.
/// </summary>
public void Bind() {
GL.BindVertexArray(handle);
}

View File

@ -1,6 +1,9 @@
using System;
using OpenTK.Graphics.OpenGL;
namespace RecrownedGTK.Graphics {
/// <summary>
/// Handles the openGL vertex buffer.
/// </summary>
public class VertexBufferArrayHandle : IDisposable {
private bool disposed;
private int handle;

View File

@ -1,6 +1,9 @@
using OpenTK;
using OpenTK.Graphics;
namespace RecrownedGTK.Graphics {
/// <summary>
/// Stores the information that is required per vertex.
/// </summary>
public struct VertexInformation {
public Vector3 coords;
public Vector2 textureCoords;

View File

@ -1,7 +1,18 @@
using System.Collections.Generic;
namespace RecrownedGTK.Persistence {
/// <summary>
/// Serializable preferences.
/// </summary>
public struct PreferencesInfo {
/// <summary>
/// Array of preferences.
/// </summary>
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)
{
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() {
Dictionary<string, string> res = new Dictionary<string, string>();
for (int prefID = 0; prefID < preferences.Length; prefID++) {
@ -21,7 +36,13 @@ namespace RecrownedGTK.Persistence {
return res;
}
/// <summary>
/// Serializable preference option.
/// </summary>
public struct PreferenceInfo {
/// <summary>
/// The key and value of the option in the preferences.
/// </summary>
public string key, value;
public PreferenceInfo(string key, string value) {