public GPURelativeToEye(Context context, Vector3D[] positions, byte[] colors) { _sp = Device.CreateShaderProgram( EmbeddedResources.GetText("OpenGlobe.Examples.GPURelativeToEye.Shaders.VS.glsl"), EmbeddedResources.GetText("OpenGlobe.Examples.Shaders.FS.glsl")); _cameraEyeHigh = (Uniform <Vector3F>)_sp.Uniforms["u_cameraEyeHigh"]; _cameraEyeLow = (Uniform <Vector3F>)_sp.Uniforms["u_cameraEyeLow"]; _modelViewPerspectiveMatrixRelativeToEye = (Uniform <Matrix4F>)(_sp.Uniforms["u_modelViewPerspectiveMatrixRelativeToEye"]); _pointSize = (Uniform <float>)_sp.Uniforms["u_pointSize"]; /////////////////////////////////////////////////////////////////// Mesh mesh = new Mesh(); VertexAttributeFloatVector3 positionsHighAttribute = new VertexAttributeFloatVector3("positionHigh", positions.Length); VertexAttributeFloatVector3 positionsLowAttribute = new VertexAttributeFloatVector3("positionLow", positions.Length); VertexAttributeRGB colorAttribute = new VertexAttributeRGB("color", positions.Length); mesh.Attributes.Add(positionsHighAttribute); mesh.Attributes.Add(positionsLowAttribute); mesh.Attributes.Add(colorAttribute); for (int i = 0; i < positions.Length; ++i) { Vector3F positionHigh; Vector3F positionLow; Vector3DToTwoVector3F(positions[i], out positionHigh, out positionLow); positionsHighAttribute.Values.Add(positionHigh); positionsLowAttribute.Values.Add(positionLow); } for (int i = 0; i < colors.Length; ++i) { colorAttribute.Values.Add(colors[i]); } _va = context.CreateVertexArray(mesh, _sp.VertexAttributes, BufferHint.StaticDraw); /////////////////////////////////////////////////////////////////// RenderState renderState = new RenderState(); renderState.FacetCulling.Enabled = false; renderState.DepthTest.Enabled = false; renderState.ProgramPointSize = ProgramPointSize.Enabled; _drawState = new DrawState(renderState, _sp, _va); }
public RelativeToCenter(Context context, Vector3D[] positions, byte[] colors) { _sp = Device.CreateShaderProgram( EmbeddedResources.GetText("OpenGlobe.Examples.RelativeToCenter.Shaders.VS.glsl"), EmbeddedResources.GetText("OpenGlobe.Examples.Shaders.FS.glsl")); _modelViewPerspectiveMatrixRelativeToCenter = (Uniform <Matrix4F>)(_sp.Uniforms["u_modelViewPerspectiveMatrixRelativeToCenter"]); _pointSize = (Uniform <float>)_sp.Uniforms["u_pointSize"]; /////////////////////////////////////////////////////////////////// Mesh mesh = new Mesh(); VertexAttributeFloatVector3 positionsAttribute = new VertexAttributeFloatVector3("position", positions.Length); VertexAttributeRGB colorAttribute = new VertexAttributeRGB("color", positions.Length); mesh.Attributes.Add(positionsAttribute); mesh.Attributes.Add(colorAttribute); _center = new AxisAlignedBoundingBox(positions).Center; for (int i = 0; i < positions.Length; ++i) { positionsAttribute.Values.Add((positions[i] - _center).ToVector3F()); } for (int i = 0; i < colors.Length; ++i) { colorAttribute.Values.Add(colors[i]); } _va = context.CreateVertexArray(mesh, _sp.VertexAttributes, BufferHint.StaticDraw); /////////////////////////////////////////////////////////////////// RenderState renderState = new RenderState(); renderState.FacetCulling.Enabled = false; renderState.DepthTest.Enabled = false; renderState.ProgramPointSize = ProgramPointSize.Enabled; _drawState = new DrawState(renderState, _sp, _va); }
public CPURelativeToEye(Context context, Vector3D[] positions, byte[] colors) { _sp = Device.CreateShaderProgram( EmbeddedResources.GetText("OpenGlobe.Examples.CPURelativeToEye.Shaders.VS.glsl"), EmbeddedResources.GetText("OpenGlobe.Examples.Shaders.FS.glsl")); _modelViewPerspectiveMatrixRelativeToEye = (Uniform <Matrix4F>)(_sp.Uniforms["u_modelViewPerspectiveMatrixRelativeToEye"]); _pointSize = (Uniform <float>)_sp.Uniforms["u_pointSize"]; /////////////////////////////////////////////////////////////////// _positions = new Vector3D[positions.Length]; positions.CopyTo(_positions, 0); _positionsRelativeToEye = new Vector3F[_positions.Length]; _eye = Vector3D.Zero; // // _positionBuffer is dynamic, and is written to when the camera moves. // _positionBuffer = Device.CreateVertexBuffer(BufferHint.DynamicDraw, ArraySizeInBytes.Size(_positionsRelativeToEye)); _colorBuffer = Device.CreateVertexBuffer(BufferHint.StaticDraw, colors.Length); _colorBuffer.CopyFromSystemMemory(colors); _va = context.CreateVertexArray(); _va.Attributes[_sp.VertexAttributes["position"].Location] = new VertexBufferAttribute(_positionBuffer, ComponentDatatype.Float, 3); _va.Attributes[_sp.VertexAttributes["color"].Location] = new VertexBufferAttribute(_colorBuffer, ComponentDatatype.UnsignedByte, 3, true, 0, 0); /////////////////////////////////////////////////////////////////// RenderState renderState = new RenderState(); renderState.FacetCulling.Enabled = false; renderState.DepthTest.Enabled = false; renderState.ProgramPointSize = ProgramPointSize.Enabled; _drawState = new DrawState(renderState, _sp, _va); }
public SceneGPURelativeToEyeLOD(Context context, Vector3D[] positions, byte[] colors) { _spHigh = Device.CreateShaderProgram( EmbeddedResources.GetText("OpenGlobe.Examples.GPURelativeToEyeLOD.Shaders.HighPrecisionVS.glsl"), EmbeddedResources.GetText("OpenGlobe.Examples.Shaders.FS.glsl")); _cameraEyeHigh = (Uniform <Vector3F>)_spHigh.Uniforms["u_cameraEyeHigh"]; _cameraEyeLow = (Uniform <Vector3F>)_spHigh.Uniforms["u_cameraEyeLow"]; _modelViewPerspectiveMatrixRelativeToEye = (Uniform <Matrix4F>)(_spHigh.Uniforms["u_modelViewPerspectiveMatrixRelativeToEye"]); _pointSizeHigh = (Uniform <float>)_spHigh.Uniforms["u_pointSize"]; /////////////////////////////////////////////////////////////////// Vector3F[] positionsHigh = new Vector3F[positions.Length]; Vector3F[] positionsLow = new Vector3F[positions.Length]; for (int i = 0; i < positions.Length; ++i) { Vector3DToTwoVector3F(positions[i], out positionsHigh[i], out positionsLow[i]); } _center = positions[6]; _positionBufferHigh = Device.CreateVertexBuffer(BufferHint.StaticDraw, ArraySizeInBytes.Size(positions)); _positionBufferLow = Device.CreateVertexBuffer(BufferHint.StaticDraw, ArraySizeInBytes.Size(positions)); _colorBuffer = Device.CreateVertexBuffer(BufferHint.StaticDraw, colors.Length); _positionBufferHigh.CopyFromSystemMemory(positionsHigh); _positionBufferLow.CopyFromSystemMemory(positionsLow); _colorBuffer.CopyFromSystemMemory(colors); _vaHigh = context.CreateVertexArray(); _vaHigh.Attributes[_spHigh.VertexAttributes["positionHigh"].Location] = new VertexBufferAttribute(_positionBufferHigh, ComponentDatatype.Float, 3); _vaHigh.Attributes[_spHigh.VertexAttributes["positionLow"].Location] = new VertexBufferAttribute(_positionBufferLow, ComponentDatatype.Float, 3); _vaHigh.Attributes[_spHigh.VertexAttributes["color"].Location] = new VertexBufferAttribute(_colorBuffer, ComponentDatatype.UnsignedByte, 3, true, 0, 0); /////////////////////////////////////////////////////////////////// RenderState renderState = new RenderState(); renderState.FacetCulling.Enabled = false; renderState.DepthTest.Enabled = false; renderState.ProgramPointSize = ProgramPointSize.Enabled; _drawStateHigh = new DrawState(renderState, _spHigh, _vaHigh); /////////////////////////////////////////////////////////////////// // Low Precision _spLow = Device.CreateShaderProgram( EmbeddedResources.GetText("OpenGlobe.Examples.GPURelativeToEyeLOD.Shaders.LowPrecisionVS.glsl"), EmbeddedResources.GetText("OpenGlobe.Examples.Shaders.FS.glsl")); _pointSizeLow = (Uniform <float>)_spLow.Uniforms["u_pointSize"]; _vaLow = context.CreateVertexArray(); _vaLow.Attributes[_spLow.VertexAttributes["position"].Location] = new VertexBufferAttribute(_positionBufferHigh, ComponentDatatype.Float, 3); _vaLow.Attributes[_spLow.VertexAttributes["color"].Location] = new VertexBufferAttribute(_colorBuffer, ComponentDatatype.UnsignedByte, 3, true, 0, 0); _drawStateLow = new DrawState(renderState, _spLow, _vaLow); }