TriEngine  v0.0.16
General-purpose engine in C#/OpenGL
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events
TriDevs.TriEngine.Graphics.Primitive Class Reference

Represents a primitive 2D shape composed of triangles. More...

Inheritance diagram for TriDevs.TriEngine.Graphics.Primitive:
[legend]
Collaboration diagram for TriDevs.TriEngine.Graphics.Primitive:
[legend]

Public Member Functions

void Draw ()
 Draw the object to screen. More...
 
void Dispose ()
 

Protected Member Functions

 Primitive (ushort[] indices, Vector3[] vectors, Color[] colors=null)
 
 Primitive (ushort[] indices, float[] vertices, Color[] colors=null)
 

Protected Attributes

uint[] Ids
 
uint ColorId
 
ushort[] Indices
 
float[] Vertices
 
int[] Colors
 

Properties

uint IndicesID [get]
 Indices buffer ID assigned to this primitive by GL.BindBuffer. More...
 
uint VerticesID [get]
 Vertices buffer ID assigned to this primitive by GL.BindBuffer. More...
 
uint ColorID [get]
 Color buffer ID assigned to this primitive by GL.BindBuffer. More...
 

Detailed Description

Represents a primitive 2D shape composed of triangles.

Constructor & Destructor Documentation

TriDevs.TriEngine.Graphics.Primitive.Primitive ( ushort[]  indices,
Vector3[]  vectors,
Color[]  colors = null 
)
protected
60  : this(indices, vectors.ToFloatArray(), colors)
61  {
62  }
TriDevs.TriEngine.Graphics.Primitive.Primitive ( ushort[]  indices,
float[]  vertices,
Color[]  colors = null 
)
protected
65  {
66  if (indices.Length % 3 != 0)
67  throw new EngineException(
68  "Primitives can only be composed of a series of triangles. Expected n*3 points, got " +
69  vertices.Length + ".",
70  new ArgumentException("Unexpected number of array items.", "indices"));
71 
72  Indices = indices;
73  Vertices = vertices;
74 
75  Ids = new uint[2];
76 
77  GL.GenBuffers(2, Ids);
78 
79  GL.BindBuffer(BufferTarget.ElementArrayBuffer, IndicesID);
80  GL.BufferData(BufferTarget.ElementArrayBuffer, new IntPtr(Indices.Length * sizeof(ushort)), Indices, BufferUsageHint.StaticDraw);
81  GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0);
82 
83  GL.BindBuffer(BufferTarget.ArrayBuffer, VerticesID);
84  GL.BufferData(BufferTarget.ArrayBuffer, new IntPtr(Vertices.Length * sizeof(float)), Vertices, BufferUsageHint.StaticDraw);
85  GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
86 
87  if (colors != null)
88  {
89  Colors = new int[colors.Length];
90  for (int i = 0; i < colors.Length; i++)
91  Colors[i] = colors[i].ToColor4().ToArgb();
92 
93  GL.GenBuffers(1, out ColorId);
94  GL.BindBuffer(BufferTarget.ArrayBuffer, ColorID);
95  GL.BufferData(BufferTarget.ArrayBuffer, new IntPtr(Colors.Length * sizeof(int)), Colors, BufferUsageHint.StaticDraw);
96  GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
97  }
98  }

Member Function Documentation

void TriDevs.TriEngine.Graphics.Primitive.Dispose ( )
123  {
124  GL.DeleteBuffers(2, Ids);
125 
126  if (ColorID != 0)
127  GL.DeleteBuffers(1, ref ColorId);
128  }
void TriDevs.TriEngine.Graphics.Primitive.Draw ( )

Draw the object to screen.

Implements TriDevs.TriEngine.Interfaces.IDrawable.

101  {
102  GL.PushClientAttrib(ClientAttribMask.ClientVertexArrayBit);
103 
104  GL.EnableClientState(ArrayCap.VertexArray);
105 
106  if (ColorID != 0)
107  {
108  GL.EnableClientState(ArrayCap.ColorArray);
109  GL.BindBuffer(BufferTarget.ArrayBuffer, ColorID);
110  GL.ColorPointer(sizeof(int), ColorPointerType.UnsignedByte, 0, 0);
111  }
112 
113  GL.BindBuffer(BufferTarget.ArrayBuffer, VerticesID);
114  GL.VertexPointer(3, VertexPointerType.Float, 0, 0);
115 
116  GL.BindBuffer(BufferTarget.ElementArrayBuffer, IndicesID);
117  GL.DrawElements(BeginMode.Triangles, Indices.Length, DrawElementsType.UnsignedShort, 0);
118 
119  GL.PopClientAttrib();
120  }

Member Data Documentation

uint TriDevs.TriEngine.Graphics.Primitive.ColorId
protected
int [] TriDevs.TriEngine.Graphics.Primitive.Colors
protected
uint [] TriDevs.TriEngine.Graphics.Primitive.Ids
protected
ushort [] TriDevs.TriEngine.Graphics.Primitive.Indices
protected
float [] TriDevs.TriEngine.Graphics.Primitive.Vertices
protected

Property Documentation

uint TriDevs.TriEngine.Graphics.Primitive.ColorID
get

Color buffer ID assigned to this primitive by GL.BindBuffer.

uint TriDevs.TriEngine.Graphics.Primitive.IndicesID
get

Indices buffer ID assigned to this primitive by GL.BindBuffer.

uint TriDevs.TriEngine.Graphics.Primitive.VerticesID
get

Vertices buffer ID assigned to this primitive by GL.BindBuffer.


The documentation for this class was generated from the following file: