/// <summary> /// /// </summary> /// <param name="projection"></param> /// <param name="view"></param> /// <param name="model"></param> /// <returns></returns> public string ToString(mat4 projection, mat4 view, mat4 model) { StringBuilder builder = BasicInfo(); builder.AppendLine(); vec3[] positions = this.Positions; if (positions == null) { positions = new vec3[0]; } uint[] indexes = this.Indexes; var worldPos = new vec4[positions.Length]; var viewPos = new vec4[positions.Length]; var projectionPos = new vec4[positions.Length]; var normalizedPos = new vec3[positions.Length]; var screenPos = new vec3[positions.Length]; builder.Append("Positions in World Space:"); builder.AppendLine(); for (int i = 0; i < positions.Length; i++) { var pos4 = new vec4(positions[i], 1); worldPos[i] = model * pos4; builder.Append('['); builder.Append(indexes[i]); builder.Append("]: "); builder.Append(worldPos[i]); builder.AppendLine(); } builder.Append("Positions in Camera/View Space:"); builder.AppendLine(); for (int i = 0; i < positions.Length; i++) { var pos4 = new vec4(positions[i], 1); viewPos[i] = view * worldPos[i]; builder.Append('['); builder.Append(indexes[i]); builder.Append("]: "); builder.Append(viewPos[i]); builder.AppendLine(); } builder.Append("Positions in Projection Space:"); builder.AppendLine(); for (int i = 0; i < positions.Length; i++) { projectionPos[i] = projection * viewPos[i]; builder.Append('['); builder.Append(indexes[i]); builder.Append("]: "); builder.Append(projectionPos[i]); builder.AppendLine(); } builder.Append("Positions in Normalized Space:"); builder.AppendLine(); for (int i = 0; i < positions.Length; i++) { builder.Append('['); builder.Append(indexes[i]); builder.Append("]: "); normalizedPos[i] = new vec3(projectionPos[i] / projectionPos[i].w); builder.Append(normalizedPos[i]); builder.AppendLine(); } builder.Append("Positions in Screen Space:"); builder.AppendLine(); int x, y, width, height; OpenGL.GetViewport(out x, out y, out width, out height); float near, far; OpenGL.GetDepthRange(out near, out far); for (int i = 0; i < positions.Length; i++) { builder.Append('['); builder.Append(indexes[i]); builder.Append("]: "); screenPos[i] = new vec3( normalizedPos[i].x * width / 2 + (x + width / 2), normalizedPos[i].y * height / 2 + (y + height / 2), normalizedPos[i].z * (far - near) / 2 + ((far + near) / 2) ); builder.Append(screenPos[i]); builder.AppendLine(); } return(builder.ToString()); }
/// <summary> /// Creates a sub-type of <see cref="Buffer"/> object directly in server side(GPU) without initializing its value. /// </summary> /// <param name="target"></param> /// <param name="elementType"></param> /// <param name="length"></param> /// <param name="usage"></param> /// <returns></returns> public static Buffer Create(IndependentBufferTarget target, Type elementType, int length, BufferUsage usage) { if (!elementType.IsValueType) { throw new ArgumentException(string.Format("{0} must be a value type!", elementType)); } if (glGenBuffers == null) { glGenBuffers = OpenGL.GetDelegateFor <OpenGL.glGenBuffers>(); } if (glBindBuffer == null) { glBindBuffer = OpenGL.GetDelegateFor <OpenGL.glBindBuffer>(); } if (glBufferData == null) { glBufferData = OpenGL.GetDelegateFor <OpenGL.glBufferData>(); } uint bufferTarget = (uint)target; int byteLength = Marshal.SizeOf(elementType) * length; uint[] buffers = new uint[1]; glGenBuffers(1, buffers); glBindBuffer(bufferTarget, buffers[0]); glBufferData(bufferTarget, byteLength, IntPtr.Zero, (uint)usage); glBindBuffer(bufferTarget, 0); Buffer buffer; switch (target) { case IndependentBufferTarget.AtomicCounterBuffer: buffer = new AtomicCounterBuffer(buffers[0], length, byteLength); break; case IndependentBufferTarget.PixelPackBuffer: buffer = new PixelPackBuffer(buffers[0], length, byteLength); break; case IndependentBufferTarget.PixelUnpackBuffer: buffer = new PixelUnpackBuffer(buffers[0], length, byteLength); break; case IndependentBufferTarget.ShaderStorageBuffer: buffer = new ShaderStorageBuffer(buffers[0], length, byteLength); break; case IndependentBufferTarget.TextureBuffer: buffer = new TextureBuffer(buffers[0], length, byteLength); break; case IndependentBufferTarget.UniformBuffer: buffer = new UniformBuffer(buffers[0], length, byteLength); break; default: throw new NotImplementedException(); } return(buffer); }
/// <summary> /// GL.Enable(capacity); or GL.Disable(capacity); /// </summary> /// <param name="capacity"></param> /// <param name="enableCapacity">Enable() or Disable() this capacity?</param> public EnableSwitch(uint capacity, bool enableCapacity) { byte original = OpenGL.IsEnabled(capacity); this.Init(capacity, enableCapacity); }
protected override void SwitchOff() { OpenGL.Viewport(original[0], original[1], original[2], original[3]); }
/// <summary> /// /// </summary> protected override void SwitchOff() { OpenGL.ClearColor(original[0], original[1], original[2], original[3]); }
public ViewportSwitch() { int[] viewport = OpenGL.GetViewport(); this.Init(viewport[0], viewport[1], viewport[2], viewport[3]); }
protected override void SwitchOn() { OpenGL.GetInteger(GetTarget.Viewport, original); OpenGL.Viewport(X, Y, Width, Height); }
/// <summary> /// /// </summary> protected override void SwitchOff() { OpenGL.PointSize(original[0]); }
/// <summary> /// /// </summary> protected override void SwitchOn() { OpenGL.GetFloat(GetTarget.PointSize, original); OpenGL.PointSize(PointSize); }
static PointSizeSwitch() { OpenGL.PointSizeRange(out min, out max); //GL.GetFloat(GetTarget.PointSizeGranularity, pointSizeWidthRange);//TODO: what does PointSizeGranularity mean? }
public void Unbind() { OpenGL.BindTexture(OpenGL.GL_TEXTURE_1D, 0); }
} // end sub #endregion public void Bind() { OpenGL.BindTexture(OpenGL.GL_TEXTURE_1D, this.id[0]); }