private unsafe List <Fragment> LinearInterpolationQuadStrip(int count, DrawElementsType type, IntPtr indices, VertexArrayObject vao, ShaderProgram program, GLBuffer indexBuffer, PassBuffer[] passBuffers) { var result = new List <Fragment>(); var gl_PositionArray = (vec4 *)passBuffers[0].Mapbuffer().ToPointer(); var pointers = new void *[passBuffers.Length - 1]; for (int i = 0; i < pointers.Length; i++) { pointers[i] = passBuffers[i + 1].Mapbuffer().ToPointer(); } byte[] indexData = indexBuffer.Data; int indexLength = indexData.Length / ByteLength(type); GCHandle pin = GCHandle.Alloc(indexData, GCHandleType.Pinned); IntPtr pointer = pin.AddrOfPinnedObject(); var groupList = new List <LinearInterpolationInfoGroup>(); ivec4 viewport = this.viewport; // ivec4(x, y, width, height) count = (count - count % 2); for (int indexID = indices.ToInt32() / ByteLength(type), c = 0; c < count - 3 && indexID < indexLength - 3; indexID += 2, c += 2) { var group = new LinearInterpolationInfoGroup(4); for (int i = 0; i < 4; i++) { uint gl_VertexID = GetVertexID(pointer, type, indexID + i); vec4 gl_Position = gl_PositionArray[gl_VertexID]; vec3 fragCoord = new vec3((gl_Position.x + 1) / 2.0f * viewport.z + viewport.x, (gl_Position.y + 1) / 2.0f * viewport.w + viewport.y, (gl_Position.z + 1) / 2.0f * (float)(this.depthRangeFar - this.depthRangeNear) + (float)this.depthRangeNear); group.array[i] = new LinearInterpolationInfo(gl_VertexID, fragCoord); } if (groupList.Contains(group)) { continue; } // discard the same line. else { groupList.Add(group); } vec3 fragCoord0 = group.array[0].fragCoord; vec3 fragCoord1 = group.array[1].fragCoord; vec3 fragCoord2 = group.array[2].fragCoord; vec3 fragCoord3 = group.array[3].fragCoord; FindFragmentsInTriangle(fragCoord0, fragCoord1, fragCoord2, pointers, group, passBuffers, result); FindFragmentsInTriangle(fragCoord1, fragCoord3, fragCoord2, pointers, group, passBuffers, result); } for (int i = 0; i < passBuffers.Length; i++) { passBuffers[i].Unmapbuffer(); } return(result); }
private void Uniform4iv(int location, int count, int[] value) { if (location < 0 || value == null || value.Length != 4) { return; } ShaderProgram program = this.currentShaderProgram; if (program == null) { SetLastError(ErrorCode.InvalidOperation); return; } // TODO:GL_INVALID_OPERATION is generated if the size of the uniform variable declared in the shader does not match the size indicated by the glUniform command. if (count < 0) { SetLastError(ErrorCode.InvalidValue); return; } UniformVariable v = program.GetUniformVariable(location); if (v == null) { SetLastError(ErrorCode.InvalidOperation); return; } FieldInfo fieldInfo = v.fieldInfo; if ((count > 1) && (!fieldInfo.FieldType.IsArray)) { SetLastError(ErrorCode.InvalidOperation); return; } var copy = new ivec4[count]; for (int i = 0; i < count; i++) { copy[i] = new ivec4(value[i * 4 + 0], value[i * 4 + 1], value[i * 4 + 2], value[i * 4 + 3]); } program.SetUniform(location, copy); }
private unsafe List <Fragment> LinearInterpolationLineLoop(int count, DrawElementsType type, IntPtr indices, VertexArrayObject vao, ShaderProgram program, GLBuffer indexBuffer, PassBuffer[] passBuffers) { var result = new List <Fragment>(); var gl_PositionArray = (vec4 *)passBuffers[0].Mapbuffer().ToPointer(); var pointers = new void *[passBuffers.Length - 1]; for (int i = 0; i < pointers.Length; i++) { pointers[i] = passBuffers[i + 1].Mapbuffer().ToPointer(); } byte[] indexData = indexBuffer.Data; int indexLength = indexData.Length / ByteLength(type); GCHandle pin = GCHandle.Alloc(indexData, GCHandleType.Pinned); IntPtr pointer = pin.AddrOfPinnedObject(); var groupList = new List <LinearInterpolationInfoGroup>(); ivec4 viewport = this.viewport; // ivec4(x, y, width, height) for (int indexID = indices.ToInt32() / ByteLength(type), c = 0; c < count && indexID < indexLength; indexID++, c++) { var group = new LinearInterpolationInfoGroup(2); for (int i = 0; i < 2; i++) { uint gl_VertexID = GetVertexID(pointer, type, (indexID + i) % count);//TODO: line-loop vs indices & count. vec4 gl_Position = gl_PositionArray[gl_VertexID]; vec3 fragCoord = new vec3((gl_Position.x + 1) / 2.0f * viewport.z + viewport.x, (gl_Position.y + 1) / 2.0f * viewport.w + viewport.y, (gl_Position.z + 1) / 2.0f * (float)(this.depthRangeFar - this.depthRangeNear) + (float)this.depthRangeNear); group.array[i] = new LinearInterpolationInfo(gl_VertexID, fragCoord); } if (groupList.Contains(group)) { continue; } // discard the same line. else { groupList.Add(group); } vec3 fragCoord0 = group.array[0].fragCoord, fragCoord1 = group.array[1].fragCoord; { vec3 diff = (fragCoord0 - fragCoord1); // discard line that is too small. if (Math.Abs(diff.x) < epsilon && Math.Abs(diff.y) < epsilon && Math.Abs(diff.z) < epsilon ) { continue; } } FindFragmentsInLine(fragCoord0, fragCoord1, pointers, group, passBuffers, result); } for (int i = 0; i < passBuffers.Length; i++) { passBuffers[i].Unmapbuffer(); } return(result); }
/// <summary> /// /// </summary> /// <param name="v"></param> public ivec3(ivec4 v) { this.x = v.x; this.y = v.y; this.z = v.z; }
private unsafe List <Fragment> LinearInterpolationPoints(int count, DrawElementsType type, IntPtr indices, VertexArrayObject vao, ShaderProgram program, GLBuffer indexBuffer, PassBuffer[] passBuffers) { var result = new List <Fragment>(); int attributeCount = passBuffers.Length - 1; var gl_PositionArray = (vec4 *)passBuffers[0].Mapbuffer().ToPointer(); var pointers = new void *[passBuffers.Length - 1]; for (int i = 0; i < pointers.Length; i++) { pointers[i] = passBuffers[i + 1].Mapbuffer().ToPointer(); } byte[] indexData = indexBuffer.Data; int indexLength = indexData.Length / ByteLength(type); GCHandle pin = GCHandle.Alloc(indexData, GCHandleType.Pinned); IntPtr pointer = pin.AddrOfPinnedObject(); var gl_VertexIDList = new List <uint>(); ivec4 viewport = this.viewport; for (int indexID = indices.ToInt32() / ByteLength(type), c = 0; c < count && indexID < indexLength; indexID++, c++) { uint gl_VertexID = GetVertexID(pointer, type, indexID); if (gl_VertexIDList.Contains(gl_VertexID)) { continue; } else { gl_VertexIDList.Add(gl_VertexID); } vec3 fragCoord = new vec3((gl_PositionArray[gl_VertexID].x + 1) / 2.0f * viewport.z + viewport.x, (gl_PositionArray[gl_VertexID].y + 1) / 2.0f * viewport.w + viewport.y, (gl_PositionArray[gl_VertexID].z + 1) / 2.0f * (float)(this.depthRangeFar - this.depthRangeNear) + (float)this.depthRangeNear); var fragment = new Fragment(fragCoord, attributeCount); for (int i = 0; i < attributeCount; i++) // new pass-buffer objects. { PassType passType = passBuffers[i].elementType; fragment.attributes[i] = new PassBuffer(passType, 1); // only one element. } for (int attrIndex = 0; attrIndex < attributeCount; attrIndex++) // fill data in pass-buffer. { PassBuffer attribute = fragment.attributes[attrIndex]; void * fragmentAttribute = attribute.Mapbuffer().ToPointer(); switch (attribute.elementType) { case PassType.Float: { var fAttr = (float *)fragmentAttribute; var array = (float *)pointers[attrIndex]; fAttr[0] = array[gl_VertexID]; } break; case PassType.Vec2: { var fAttr = (vec2 *)fragmentAttribute; var array = (vec2 *)pointers[attrIndex]; fAttr[0] = array[gl_VertexID]; } break; case PassType.Vec3: { var fAttr = (vec3 *)fragmentAttribute; var array = (vec3 *)pointers[attrIndex]; fAttr[0] = array[gl_VertexID]; } break; case PassType.Vec4: { var fAttr = (vec4 *)fragmentAttribute; var array = (vec4 *)pointers[attrIndex]; fAttr[0] = array[gl_VertexID]; } break; case PassType.Mat2: { var fAttr = (mat2 *)fragmentAttribute; var array = (mat2 *)pointers[attrIndex]; fAttr[0] = array[gl_VertexID]; } break; case PassType.Mat3: { var fAttr = (mat3 *)fragmentAttribute; var array = (mat3 *)pointers[attrIndex]; fAttr[0] = array[gl_VertexID]; } break; case PassType.Mat4: { var fAttr = (mat4 *)fragmentAttribute; var array = (mat4 *)pointers[attrIndex]; fAttr[0] = array[gl_VertexID]; } break; default: throw new NotDealWithNewEnumItemException(typeof(PassType)); } attribute.Unmapbuffer(); } result.Add(fragment); } for (int i = 0; i < passBuffers.Length; i++) { passBuffers[i].Unmapbuffer(); } return(result); }
/// <summary> /// /// </summary> /// <param name="v"></param> public ivec2(ivec4 v) { this.x = v.x; this.y = v.y; }
public static ivec3 ivec3(ivec4 v) { return(new ivec3(v.x, v.y, v.z)); }
public static ivec2 ivec2(ivec4 v) { return(new ivec2(v.x, v.y)); }