Beispiel #1
1
        private static async Task RunSelectedConfigurationAsync(Transport transport, Buffering buffering, Protocol protocol, bool multiplex, CancellationToken cancellationToken)
        {
            TServerTransport serverTransport = transport switch
            {
                Transport.Tcp => new TServerSocketTransport(9090, Configuration),
                Transport.NamedPipe => new TNamedPipeServerTransport(".test", Configuration, NamedPipeClientFlags.None),
                Transport.TcpTls => new TTlsServerSocketTransport(9090, Configuration, GetCertificate(), ClientCertValidator, LocalCertificateSelectionCallback),
                _ => throw new ArgumentException("unsupported value $transport", nameof(transport)),
            };

            TTransportFactory transportFactory = buffering switch
            {
                Buffering.Buffered => new TBufferedTransport.Factory(),
                Buffering.Framed => new TFramedTransport.Factory(),
                // layered transport(s) are optional
                Buffering.None => null,
                _ => throw new ArgumentException("unsupported value $buffering", nameof(buffering)),
            };

            TProtocolFactory protocolFactory = protocol switch
            {
                Protocol.Binary => new TBinaryProtocol.Factory(),
                Protocol.Compact => new TCompactProtocol.Factory(),
                Protocol.Json => new TJsonProtocol.Factory(),
                _ => throw new ArgumentException("unsupported value $protocol", nameof(protocol)),
            };

            var handler = new CalculatorAsyncHandler();
            ITAsyncProcessor processor = new Calculator.AsyncProcessor(handler);

            if (multiplex)
            {
                var multiplexedProcessor = new TMultiplexedProcessor();
                multiplexedProcessor.RegisterProcessor(nameof(Calculator), processor);

                processor = multiplexedProcessor;
            }


            try
            {
                Logger.LogInformation(
                    "TSimpleAsyncServer with \n{transport} transport\n{buffering} buffering\nmultiplex = {multiplex}\n{protocol} protocol",
                    transport,
                    buffering,
                    multiplex ? "yes" : "no",
                    protocol
                    );

                var server = new TSimpleAsyncServer(
                    itProcessorFactory: new TSingletonProcessorFactory(processor),
                    serverTransport: serverTransport,
                    inputTransportFactory: transportFactory,
                    outputTransportFactory: transportFactory,
                    inputProtocolFactory: protocolFactory,
                    outputProtocolFactory: protocolFactory,
                    logger: LoggingHelper.CreateLogger <TSimpleAsyncServer>());

                Logger.LogInformation("Starting the server...");

                await server.ServeAsync(cancellationToken);
            }
            catch (Exception x)
            {
                Logger.LogInformation("{x}", x);
            }
        }
        public override void CollectGeometry(
            RenderingContext rc,
            out GeometryHandle handle,
            out BoundingBox bbox,
            out bool coloring,
            out bool texturing)
        {
            handle    = GeometryHandle.Zero;
            bbox      = BoundingBox.Zero;
            coloring  = false;
            texturing = false;

            parentShape = GetParent <Shape>();

            _pack = new PackedGeometry();
            _pack.restartIndex = -1;
            _pack._indices     = Faces;
            _pack._coords      = Verts;
            _pack.bbox         = BoundingBox.CalculateBoundingBox(Verts);

            _pack.Interleave();

            // BUFFER GEOMETRY
            handle = Buffering.BufferShaderGeometry(_pack);
        }
Beispiel #3
0
        private TTransport MakeTransport(URL url, TConfiguration configuration)
        {
            var ipaddress = IPAddress.Loopback;

            if (!NetUtil.IsAnyHost(url.Host) && !NetUtil.IsLocalHost(url.Host))
            {
                ipaddress = IPAddress.Parse(url.Host);
            }
            // construct endpoint transport
            TTransport transport         = null;
            Transport  selectedTransport = GetTransport(url);
            {
                switch (selectedTransport)
                {
                case Transport.Tcp:
                    transport = new TSocketTransport(ipaddress, url.Port, configuration);
                    break;

                case Transport.NamedPipe:
                    transport = new TNamedPipeTransport(".test", configuration);
                    break;

                case Transport.Http:
                    transport = new THttpTransport(new Uri($"http://{url.Host}:{url.Port}"), configuration);
                    break;

                case Transport.TcpTls:
                    transport = new TTlsSocketTransport(ipaddress, url.Port, configuration,
                                                        GetCertificate(), CertValidator, LocalCertificateSelectionCallback);
                    break;

                default:
                    Console.WriteLine("unhandled case");
                    break;
                }
            }

            // optionally add layered transport(s)
            Buffering selectedBuffering = GetBuffering(url);

            switch (selectedBuffering)
            {
            case Buffering.Buffered:
                transport = new TBufferedTransport(transport);
                break;

            case Buffering.Framed:
                transport = new TFramedTransport(transport);
                break;

            default:     // layered transport(s) are optional
                if (selectedBuffering != Buffering.None)
                {
                    Console.WriteLine("unhandled case");
                }
                break;
            }

            return(transport);
        }
        public void ApplyMaterials(ComposedShader shader)
        {
            List <Material> materials;
            Appearance      appearance;

            materials  = new List <Material>();
            appearance = this.ItemsByType <Appearance>().FirstOrDefault();

            if (appearance != null)
            {
                materials = appearance.ItemsByType <Material>();
            }

            shader.SetFieldValue("materialsEnabled", materials.Any() ? 1 : 0);

            if (materials.Any())
            {
            }
            else
            {
                //shaderMaterials.Add(new ShaderMaterial()
                //{
                //     ambientIntensity = 0.1f,
                //     diffuseColor = new Vector4(0,0,0,0),
                //     emissiveColor = new Vector4(0,0,0,0),
                //    specularColor = new Vector4(1, 1, 1, 1),
                //    transparency = 1.0f,
                //    shininess = 0.2f
                //});
            }

            shader.SetFieldValue("materialsCount", shaderMaterials.Count);

            Buffering.BufferMaterials(shader, shaderMaterials, "materials");
        }
Beispiel #5
0
 private void VlcMediaPlayer_Buffering(object sender, Meta.Vlc.MediaPlayerBufferingEventArgs e)
 {
     if (Buffering != null)
     {
         Buffering.Invoke(this, EventArgs.Empty);
     }
 }
        public TTlsServerSocketTransport(
            int port,
            X509Certificate2 certificate,
            Buffering buffering = Buffering.None,
            RemoteCertificateValidationCallback clientCertValidator             = null,
            LocalCertificateSelectionCallback localCertificateSelectionCallback = null,
            SslProtocols sslProtocols = SslProtocols.Tls12)
        {
            if (!certificate.HasPrivateKey)
            {
                throw new TTransportException(TTransportException.ExceptionType.Unknown,
                                              "Your server-certificate needs to have a private key");
            }

            _serverCertificate   = certificate;
            _buffering           = buffering;
            _clientCertValidator = clientCertValidator;
            _localCertificateSelectionCallback = localCertificateSelectionCallback;
            _sslProtocols = sslProtocols;

            try
            {
                // Create server socket
                _server = new TcpListener(IPAddress.Any, port);
                _server.Server.NoDelay = true;
            }
            catch (Exception)
            {
                _server = null;
                throw new TTransportException($"Could not create ServerSocket on port {port}.");
            }
        }
Beispiel #7
0
        public void Load()
        {
            Vertex v;
            List<Vertex> geometry = new List<Vertex>();

            v = new Vertex()
            {
                Position = new Vector3(0f, 0f, 0) + Position,
                TexCoord = new Vector2(0f, 1f)
            };
            geometry.Add(v);

            v = new Vertex()
            {
                Position = new Vector3(this.Height, 0f, 0) + Position,
                TexCoord = new Vector2(1f, 1f)
            };
            geometry.Add(v);

            v = new Vertex()
            {
                Position = new Vector3(this.Height, this.Height, 0) + Position,
                TexCoord = new Vector2(1f, 0f)
            };
            geometry.Add(v);

            v = new Vertex()
            {
                Position = new Vector3(0f, this.Height, 0) + Position,
                TexCoord = new Vector2(0f, 0f)
            };

            geometry.Add(v);



            //Bitmap bmpCross = ImageTexture.CreateBitmap(System.Drawing.Color.Black, 100, 100);
            //GraphicsUnit gunit = GraphicsUnit.Pixel;
            //var bounds = bmpCross.GetBounds(ref gunit);
            //this._image = ImageTexture.CreateTextureFromImage(bmpCross, bounds);


            //var @default = ShaderCompiler.BuildDefaultShader();
            //@default.Link();
            //@default.Use();

            var @default = ShaderCompiler.ApplyShader(PerlinNoiseShader.vertexShaderSource, PerlinNoiseShader.fragmentShaderSource);
            @default.Link();
            @default.Use();

            CurrentShader = @default;

            Buffering.BufferShaderGeometry(geometry, out vbo, out NumVerticies);
        }
        private void RenderTessellator(RenderingContext rc)
        {
            //Vector4 lightPosition = new Vector4(0.25f, 0.25f, 1f, 0f);
            var shader = CurrentShader;

            //shader.SetFieldValue("normalmatrix", ref NormalMatrix);
            //GL.UniformMatrix3(parentShape.Uniforms.NormalMatrix, false, ref parentShape.NormalMatrix);
            //GL.Uniform3(Uniforms.LightPosition, 1, ref lightPosition.X);
            //GL.Uniform3(Uniforms.AmbientMaterial, X3DTypeConverters.ToVec3(OpenTK.Graphics.Color4.Aqua)); // 0.04f, 0.04f, 0.04f
            //GL.Uniform3(Uniforms.DiffuseMaterial, 0.0f, 0.75f, 0.75f);

            int PatchMatrix           = GL.GetUniformLocation(CurrentShader.ShaderHandle, "B");
            int TransposedPatchMatrix = GL.GetUniformLocation(CurrentShader.ShaderHandle, "BT");

            Matrix4 bezier = new Matrix4
                                 (-1, 3, -3, 1,
                                 3, -6, 3, 0,
                                 -3, 3, 0, 0,
                                 1, 0, 0, 0);

            GL.UniformMatrix4(PatchMatrix, false, ref bezier);
            GL.UniformMatrix4(TransposedPatchMatrix, true, ref bezier);

            if (_handle.NumVerticies3 > 0)
            {
                GL.UseProgram(shader.ShaderHandle);

                shader.SetFieldValue("size", size);
                shader.SetFieldValue("scale", scale);

                GL.PatchParameter(PatchParameterInt.PatchVertices, 3);
                GL.BindBuffer(BufferTarget.ArrayBuffer, _handle.vbo3);
                Buffering.ApplyBufferPointers(shader);
                GL.DrawArrays(PrimitiveType.Patches, 0, _handle.NumVerticies3);
            }


            if (_handle.NumVerticies4 > 0)
            {
                shader = quadShader;

                GL.UseProgram(shader.ShaderHandle);

                shader.SetFieldValue("size", size);
                shader.SetFieldValue("scale", scale);

                GL.PatchParameter(PatchParameterInt.PatchVertices, 16);
                GL.BindBuffer(BufferTarget.ArrayBuffer, _handle.vbo4);
                Buffering.ApplyBufferPointers(shader);
                GL.DrawArrays(PrimitiveType.Patches, 0, _handle.NumVerticies4);
            }
        }
        public MediaPlayer()
        {
            _player.PlaybackCompleted += (s, e) => Stop();

            _player.BufferingProgressChanged += (s, e) =>
                                                Buffering?.Invoke(this, new BufferingEventArgs(e.Percent));

            _player.ErrorOccurred += (s, e) =>
                                     ErrorOccurred?.Invoke(this, new ErrorEventArgs(e.Error.ToString()));

            _player.SubtitleUpdated += (s, e) =>
                                       SubtitleUpdated?.Invoke(this, new SubtitleUpdatedEventArgs(e.Text, e.Duration));
        }
Beispiel #10
0
        private static TTransport MakeTransport(string[] args)
        {
            // construct endpoint transport
            TTransport transport         = null;
            Transport  selectedTransport = GetTransport(args);
            {
                switch (selectedTransport)
                {
                case Transport.Tcp:
                    transport = new TSocketTransport(IPAddress.Loopback, 9090, Configuration);
                    break;

                case Transport.NamedPipe:
                    transport = new TNamedPipeTransport(".test", Configuration);
                    break;

                case Transport.Http:
                    transport = new THttpTransport(new Uri("http://localhost:9090"), Configuration);
                    break;

                case Transport.TcpTls:
                    transport = new TTlsSocketTransport(IPAddress.Loopback, 9090, Configuration,
                                                        GetCertificate(), CertValidator, LocalCertificateSelectionCallback);
                    break;

                default:
                    Debug.Assert(false, "unhandled case");
                    break;
                }
            }

            // optionally add layered transport(s)
            Buffering selectedBuffering = GetBuffering(args);

            switch (selectedBuffering)
            {
            case Buffering.Buffered:
                transport = new TBufferedTransport(transport);
                break;

            case Buffering.Framed:
                transport = new TFramedTransport(transport);
                break;

            default:     // layered transport(s) are optional
                Debug.Assert(selectedBuffering == Buffering.None, "unhandled case");
                break;
            }

            return(transport);
        }
Beispiel #11
0
        private void RenderSkybox(RenderingContext rc)
        {
            rc.PushMatricies();

            // Inner cubemapped skybox
            //this._shapeInnerCube.Render(rc);

            _shaderInnerCube.Use();
#if APPLY_BACKDROP
            Matrix4 mat4 = rc.cam.GetWorldOrientation();
            _shaderInnerCube.SetFieldValue("modelview", ref mat4);
#endif
            _shaderInnerCube.SetFieldValue("scale", scaleCube);
            _shaderInnerCube.SetFieldValue("size", size);
            _shaderInnerCube.SetFieldValue("coloringEnabled", 0);
            _shaderInnerCube.SetFieldValue("texturingEnabled", 1);
            _shaderInnerCube.SetFieldValue("lightingEnabled", 0);

            _shaderInnerCube.SetFieldValue("projection", ref rc.matricies.projection);
            _shaderInnerCube.SetFieldValue("camscale", rc.cam.Scale.X);
            _shaderInnerCube.SetFieldValue("X3DScale", rc.matricies.Scale);


            texture2d = GL.IsEnabled(EnableCap.Texture2D);

            if (!texture2d)
            {
                GL.Enable(EnableCap.Texture2D);
            }

#if APPLY_BACKDROP
            GL.DepthMask(false);
#endif

            GL.ActiveTexture(TextureUnit.Texture0);
            GL.BindTexture(TextureTarget.TextureCubeMap, tex_cube);
            GL.BindBuffer(BufferTarget.ArrayBuffer, cubeHandle.vbo3);
            Buffering.ApplyBufferPointers(_shaderInnerCube);
            GL.DrawArrays(PrimitiveType.Triangles, 0, cubeHandle.NumVerticies3);

#if APPLY_BACKDROP
            GL.DepthMask(true);
#endif

            if (!texture2d)
            {
                GL.Disable(EnableCap.Texture2D);
            }

            rc.PopMatricies();
        }
        public override void Render(RenderingContext rc)
        {
            base.Render(rc);
            this._shape.Render(rc);

            var size  = new Vector3(1, 1, 1);
            var scale = new Vector3(1, 1, 1);

            _shape.CurrentShader.Use();
#if APPLY_BACKDROP
            Matrix4 mat4 = rc.cam.GetWorldOrientation();
            _shape.CurrentShader.SetFieldValue("modelview", ref mat4);
#endif
            _shape.CurrentShader.SetFieldValue("scale", scale);
            _shape.CurrentShader.SetFieldValue("size", size);

            bool texture2d = GL.IsEnabled(EnableCap.Texture2D);

            if (!texture2d)
            {
                GL.Enable(EnableCap.Texture2D);
            }

#if APPLY_BACKDROP
            GL.DepthMask(false);
#endif
#if CULL_FACE
            GL.Enable(EnableCap.CullFace);
            GL.CullFace(CullFaceMode.Back);
#endif

            //GL.FrontFace(FrontFaceDirection.Cw);
            GL.ActiveTexture(TextureUnit.Texture0);
            GL.BindTexture(TextureTarget.TextureCubeMap, tex_cube);
            GL.BindBuffer(BufferTarget.ArrayBuffer, _handle.vbo3);
            Buffering.ApplyBufferPointers(_shape.CurrentShader);
            //Buffering.ApplyBufferPointers(_shape.uniforms);
            GL.DrawArrays(PrimitiveType.Triangles, 0, _handle.NumVerticies3);
#if APPLY_BACKDROP
            GL.DepthMask(true);
#endif
#if CULL_FACE
            GL.Disable(EnableCap.CullFace);
#endif
            //GL.FrontFace(FrontFaceDirection.Ccw);

            if (!texture2d)
            {
                GL.Disable(EnableCap.Texture2D);
            }
        }
        public void Load()
        {
            Vertex        v;
            List <Vertex> geometry = new List <Vertex>();

            v = new Vertex()
            {
                Position = new Vector3(0f, 0f, 0) + Position,
                TexCoord = new Vector2(0f, 1f)
            };
            geometry.Add(v);

            v = new Vertex()
            {
                Position = new Vector3(1.0f, 0f, 0) + Position,
                TexCoord = new Vector2(1f, 1f)
            };
            geometry.Add(v);

            v = new Vertex()
            {
                Position = new Vector3(1.0f, this.Height, 0) + Position,
                TexCoord = new Vector2(1f, 0f)
            };
            geometry.Add(v);

            v = new Vertex()
            {
                Position = new Vector3(0f, this.Height, 0) + Position,
                TexCoord = new Vector2(0f, 0f)
            };

            geometry.Add(v);


            Bitmap       bmpCross = Properties.Resources.crosshair;
            GraphicsUnit gunit    = GraphicsUnit.Pixel;
            var          bounds   = bmpCross.GetBounds(ref gunit);

            this._crosshair = ImageTexture.CreateTextureFromImage(bmpCross, bounds);

            var @default = ShaderCompiler.ApplyShader(CrosshairShader.vertexShaderSource, CrosshairShader.fragmentShaderSource);

            @default.Link();
            @default.Use();

            CurrentShader = @default;

            Buffering.BufferShaderGeometry(geometry, out vbo, out NumVerticies);
        }
Beispiel #14
0
        public void Render(Shape transform_context, RenderingContext rc)
        {
            if (!renderingEnabled)
            {
                return;
            }

            var shader = bboxShader;

            Matrix4 modelview;
            Vector3 x3dScale = new Vector3(0.06f, 0.06f, 0.06f);

            modelview = calculateModelview(transform_context, rc);

            //const float bbscale = 0.0329999961f; // (rc.cam.calibTrans.X* 0.1f)
            //float bbscale = (rc.cam.calibTrans.X * 0.1f);

            GL.UseProgram(shader.ShaderHandle);
            //rc.matricies.Scale = new Vector3(this.Width, this.Height, this.Depth);
            shader.SetFieldValue("size", new Vector3(this.Width, this.Height, this.Depth) * (x3dScale / 2.0f));
            shader.SetFieldValue("scale", Vector3.One);
            shader.SetFieldValue("modelview", ref modelview);
            shader.SetFieldValue("projection", ref rc.matricies.projection);
            shader.SetFieldValue("camscale", 1.0f);
            shader.SetFieldValue("X3DScale", Vector3.One);
            shader.SetFieldValue("coloringEnabled", 1);
            shader.SetFieldValue("texturingEnabled", 0);
            shader.SetFieldValue("lightingEnabled", 0);


            // BOUNDARY LINES
            GL.BindBuffer(BufferTarget.ArrayBuffer, _handle.vbo3);
            Buffering.ApplyBufferPointers(bboxShader);
            GL.DrawArrays(PrimitiveType.LineLoop, 0, _handle.NumVerticies3);


            // BOUNDARY POINTS
            GL.BindBuffer(BufferTarget.ArrayBuffer, _handle.vbo3);
            Buffering.ApplyBufferPointers(bboxShader);
            GL.DrawArrays(PrimitiveType.Points, 0, _handle.NumVerticies3);

            // MAX-MIN POINTS
            //GL.PointSize(8.0f);
            //GL.BindBuffer(BufferTarget.ArrayBuffer, _handlepb.vbo3);
            //Buffering.ApplyBufferPointers(bboxShader);
            //GL.DrawArrays(PrimitiveType.Points, 0, _handlepb.NumVerticies3);

            PostRender();
        }
Beispiel #15
0
        private static void Main(string[] args)
        {
            Console.BufferHeight = 100;
            Console.BufferWidth  = 100;
            Console.SetWindowSize(100, 100);

            logger.WriteLine("Game started");
            #region INIT
            logger.WriteLine("Loading Elements: ");
            ExtraTools.Loader.LoadElements();

            logger.WriteLine("Loading Mods: ");
            ExtraTools.Loader.LoadMods();

            logger.WriteLine("Elements loaded: ");
            foreach (KeyValuePair <string, Element> Entry in Simulation.Loaded.Elements)
            {
                logger.WriteLine("    " + Entry.Key);
                Entry.Value.Spawn();
                logger.WriteLine("        " + Entry.Value.Description.Category + " - " + Entry.Value.Description.Name4);
            }
            GC.Collect();
            #endregion

            Buffering.Layers.Add(new Layer());
            Buffering.Layers.Add(new Layer());

            Buffering.TargetLayer = 0;
            Buffering.Put(new Vector2(10, 10), 'A');
            Buffering.Flush(0);

            Buffering.TargetLayer = 1;
            Buffering.DrawBox(Boxes.DubbleLine(), new Vector2(0, 45), new Vector2(99, 49));
            Buffering.FlushTransparant(1);
            //Buffering.Clear( 1 );

            Buffering.TargetLayer = 0;
            while (true)
            {
                logger.WriteLine("dsgdsgdsg");
                Thread.Sleep(100);
                Buffering.Put(new Vector2(10, 10), 'A');
                Buffering.FlushTransparant(0);
            }

            Console.Read();
            Exit();
        }
Beispiel #16
0
 public TServerSocketTransport(int port, int clientTimeout = 0, Buffering buffering = Buffering.None)
 {
     _clientTimeout = clientTimeout;
     _buffering     = buffering;
     try
     {
         // Make server socket
         _server = new TcpListener(IPAddress.Any, port);
         _server.Server.NoDelay = true;
     }
     catch (Exception)
     {
         _server = null;
         throw new TTransportException("Could not create ServerSocket on port " + port + ".");
     }
 }
        private void RenderTriangles(RenderingContext rc)
        {
            if (_handle.NumVerticies3 > 0)
            {
                GL.UseProgram(CurrentShader.ShaderHandle);

                CurrentShader.SetFieldValue("size", size);
                CurrentShader.SetFieldValue("scale", scale);

                GL.BindBuffer(BufferTarget.ArrayBuffer, _handle.vbo3);
                Buffering.ApplyBufferPointers(CurrentShader);
                GL.DrawArrays(PrimitiveType.Triangles, 0, _handle.NumVerticies3);

                GL.UseProgram(0);
            }
        }
        private void RenderQuads(RenderingContext rc)
        {
            if (_handle.NumVerticies4 > 0)
            {
                GL.UseProgram(quadShader.ShaderHandle);

                if (depthMask)
                {
                    ApplyGeometricTransformations(rc, quadShader, this);
                }
                else
                {
                    //REFACTOR!!
                    Matrix4 mat4 = Matrix4.Identity;
                    //Quaternion qRotFix = QuaternionExtensions.EulerToQuat(rc.cam.calibOrient.X, rc.cam.calibOrient.Y, rc.cam.calibOrient.Z);
                    //mat4 *= Matrix4.CreateTranslation(rc.cam.calibTrans) * Matrix4.CreateFromQuaternion(qRotFix);
                    Quaternion qRotFix = QuaternionExtensions.EulerToQuat(0.15f, 3.479997f, 0f);
                    mat4 *= Matrix4.CreateTranslation(new Vector3(0f, 0f, -0.29f)) * Matrix4.CreateFromQuaternion(qRotFix);

                    // test weapon/gun rendering fixed in front of player
                    //TODO: port this to X3D

                    quadShader.SetFieldValue("modelview", ref mat4);

                    RefreshDefaultUniforms(quadShader);

                    quadShader.SetFieldValue("bbox_x", bbox.Width);
                    quadShader.SetFieldValue("bbox_y", bbox.Height);
                    quadShader.SetFieldValue("bbox_z", bbox.Depth);
                    quadShader.SetFieldValue("projection", ref rc.matricies.projection);
                    quadShader.SetFieldValue("camscale", rc.cam.Scale.X);                   //GL.Uniform1(uniformCameraScale, rc.cam.Scale.X);
                    quadShader.SetFieldValue("X3DScale", rc.matricies.Scale);               //GL.Uniform3(uniformX3DScale, rc.matricies.Scale);
                    quadShader.SetFieldValue("coloringEnabled", coloring ? 1 : 0);
                    quadShader.SetFieldValue("texturingEnabled", texturingEnabled ? 1 : 0); //GL.Uniform1(uniforms.a_texturingEnabled, this.texturingEnabled ? 1 : 0);
                }
                quadShader.SetFieldValue("size", size);
                quadShader.SetFieldValue("scale", scale);

                ApplyMaterials(quadShader);

                GL.BindBuffer(BufferTarget.ArrayBuffer, _handle.vbo4);
                Buffering.ApplyBufferPointers(quadShader);
                GL.DrawArrays(PrimitiveType.Quads, 0, _handle.NumVerticies4);

                GL.UseProgram(0);
            }
        }
        public void Render(RenderingContext rc)
        {
            CurrentShader.Use();
            CurrentShader.SetFieldValue("scale", scale);
            CurrentShader.SetFieldValue("size", size);

            var identity = Matrix4.Identity;

            CurrentShader.SetFieldValue("modelview", ref identity);

            GL.Enable(EnableCap.Texture2D);
            GL.DepthMask(false);
            GL.BindTexture(TextureTarget.Texture2D, _crosshair.Index);
            GL.BindBuffer(BufferTarget.ArrayBuffer, vbo);
            Buffering.ApplyBufferPointers(CurrentShader);
            GL.DrawArrays(PrimitiveType.Quads, 0, NumVerticies);
            GL.DepthMask(true);
            GL.BindTexture(TextureTarget.Texture2D, 0);
        }
        private IndexedFaceSet ifs2; // without bottom face

        public override void CollectGeometry(
            RenderingContext rc,
            out GeometryHandle handle,
            out BoundingBox bbox,
            out bool Coloring,
            out bool Texturing)
        {
            PackedGeometry        master;
            PackedGeometry        packed1;
            PackedGeometry        packed2;
            List <PackedGeometry> packs;

            handle    = GeometryHandle.Zero;
            bbox      = BoundingBox.Zero;
            Texturing = false;
            Coloring  = false;

            packs = new List <PackedGeometry>();

            if (this.bottom)
            {
                // Cone with bottom face

                packed1 = PackedGeometry.Pack(ifs1);
                packs.Add(packed1);
            }
            else
            {
                // Cone without bottom face

                packed2 = PackedGeometry.Pack(ifs2);
                packs.Add(packed2);
            }

            master = PackedGeometry.InterleavePacks(packs);

            bbox = BoundingBox.CalculateBoundingBox(master);

            // BUFFER GEOMETRY
            handle = Buffering.BufferShaderGeometry(master);
        }
Beispiel #21
0
        public override void CollectGeometry(
            RenderingContext rc,
            out GeometryHandle handle,
            out BoundingBox bbox,
            out bool Coloring,
            out bool Texturing)
        {
            handle    = GeometryHandle.Zero;
            bbox      = BoundingBox.Zero;
            Texturing = true;
            Coloring  = true;

            parentShape = GetParent <Shape>();

            buildCylinderGeometry();

            _pack = PackedGeometry.Pack(ifs1);

            // BUFFER GEOMETRY
            handle = Buffering.BufferShaderGeometry(_pack);
        }
        public TTlsServerSocketTransport(
            TcpListener listener,
            X509Certificate2 certificate,
            Buffering buffering = Buffering.None,
            RemoteCertificateValidationCallback clientCertValidator             = null,
            LocalCertificateSelectionCallback localCertificateSelectionCallback = null,
            SslProtocols sslProtocols = SslProtocols.Tls12)
        {
            if (!certificate.HasPrivateKey)
            {
                throw new TTransportException(TTransportException.ExceptionType.Unknown,
                                              "Your server-certificate needs to have a private key");
            }

            _serverCertificate   = certificate;
            _buffering           = buffering;
            _clientCertValidator = clientCertValidator;
            _localCertificateSelectionCallback = localCertificateSelectionCallback;
            _sslProtocols = sslProtocols;
            _server       = listener;
        }
        private void RenderLines(RenderingContext rc)
        {
            if (_handle.NumVerticies3 > 0)
            {
                PrimitiveType prim;

                GL.UseProgram(CurrentShader.ShaderHandle);

                CurrentShader.SetFieldValue("lightingEnabled", 0);
                CurrentShader.SetFieldValue("headlightEnabled", 0);

                CurrentShader.SetFieldValue("size", size);
                CurrentShader.SetFieldValue("scale", scale);

                GL.LineWidth(8.0f); // todo: LineProperties

                prim = PrimitiveType.Lines;

                if (typeof(IndexedLineSet).IsInstanceOfType(geometry))
                {
                    IndexedLineSet ils = (IndexedLineSet)geometry;
                    prim = ils.PrimativeType;
                }
                if (typeof(LineSet).IsInstanceOfType(geometry))
                {
                    LineSet ls = (LineSet)geometry;
                    prim = ls.PrimativeType;
                }

                GL.BindBuffer(BufferTarget.ArrayBuffer, _handle.vbo3);
                Buffering.ApplyBufferPointers(CurrentShader);
                GL.DrawArrays(prim, 0, _handle.NumVerticies3);


                GL.UseProgram(0);
                GL.LineWidth(1.0f);
            }
        }
        private void RenderPoints(RenderingContext rc)
        {
            if (_handle.NumVerticies3 > 0)
            {
                GL.UseProgram(CurrentShader.ShaderHandle);

                CurrentShader.SetFieldValue("lightingEnabled", 0);
                CurrentShader.SetFieldValue("headlightEnabled", 0);

                CurrentShader.SetFieldValue("size", size);
                CurrentShader.SetFieldValue("scale", scale);

                GL.PointSize(8.0f); // todo:  point properties

                GL.BindBuffer(BufferTarget.ArrayBuffer, _handle.vbo3);
                Buffering.ApplyBufferPointers(CurrentShader);
                GL.DrawArrays(PrimitiveType.Points, 0, _handle.NumVerticies3);


                GL.UseProgram(0);
                GL.PointSize(1.0f);
            }
        }
Beispiel #25
0
        public Bitmap GenerateHeightMap(RenderingContext rc)
        {
            GL.BindTexture(TextureTarget.Texture2D, 0);

            Bitmap b = TakeRenderingContextScreenshot(0, 0, 800, 600, () =>
            {

                GL.Enable(EnableCap.Texture2D);

                Vector3 size = new Vector3(1, 1, 1);
                Vector3 scale = new Vector3(1, 1, 1);

                //GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
                CurrentShader.Use();
                CurrentShader.SetFieldValue("scale", scale);
                CurrentShader.SetFieldValue("size", size);
                CurrentShader.SetFieldValue("seed", (float)seed.NextDouble()); //  (float)rc.Time * 0.001f

                var identity = Matrix4.Identity;
                CurrentShader.SetFieldValue("modelview", ref identity);

                GL.DepthMask(false);
                GL.BindBuffer(BufferTarget.ArrayBuffer, vbo);
                Buffering.ApplyBufferPointers(CurrentShader);
                GL.DrawArrays(PrimitiveType.Quads, 0, NumVerticies);
                GL.DepthMask(true);

            });

            GL.BindTexture(TextureTarget.Texture2D, 0);
            GL.UseProgram(0);

            this.Image = b;

            return b;
        }
        public override void CollectGeometry(
            RenderingContext rc,
            out GeometryHandle handle,
            out BoundingBox bbox,
            out bool Coloring,
            out bool Texturing)
        {
            List <Vertex> geometry;


            handle = GeometryHandle.Zero;
            bbox   = BoundingBox.Zero;



            parentShape       = GetParent <Shape>();
            colorNode         = (Color)this.Children.FirstOrDefault(n => n.GetType() == typeof(Color));
            colorRGBANode     = (ColorRGBA)this.Children.FirstOrDefault(n => n.GetType() == typeof(ColorRGBA));
            texCoordinateNode = (TextureCoordinate)this.Children.FirstOrDefault(n => n.GetType() == typeof(TextureCoordinate));

            RGBA             = colorRGBANode != null;
            RGB              = colorNode != null;
            coloring         = RGBA || RGB;
            generateColorMap = coloring;

            texturing           = texCoordinateNode != null || parentShape.texturingEnabled;
            generateTexCoordMap = texturing;

            Coloring  = coloring;
            Texturing = texturing;

            if (RGB && !RGBA)
            {
                color = X3DTypeConverters.Floats(colorNode.color);
            }
            else if (RGBA && !RGB)
            {
                color = X3DTypeConverters.Floats(colorRGBANode.color);
            }

            _isLoaded = true;


            ////
            ////
            ////



            if (construct)
            {
                float sx = this.xSpacing;
                float sz = this.zSpacing;

                IConstructionSet      constructionSet;
                IPerlinNoiseGenerator perlinProvider;
                Bitmap largePerlinImage;

                constructionSet = SceneManager.GetCurrentConstructionSet();
                perlinProvider  = constructionSet.GetPerlinNoiseProvider();

                ElevationGrid generated = constructionSet.ElevationBuilder.BuildHeightmapFromGenerator(
                    rc,
                    perlinProvider,
                    out largePerlinImage, 40, 40, 20, 20, 20); // build a rather large height map

                largePerlinImage.Dispose();

                Color genColorNode = (Color)generated.Children.FirstOrDefault(n => n.GetType() == typeof(Color));
                this.RGB             = coloring = generateColorMap = true;
                this.height          = generated.height;
                this.color           = X3DTypeConverters.Floats(genColorNode.color);
                this.colorPerVertex  = generated.colorPerVertex;
                this.normalPerVertex = generated.normalPerVertex;
                this.Children        = generated.Children;
                this.xSpacing        = generated.xSpacing;
                this.zSpacing        = generated.zSpacing;
                this.xDimension      = generated.xDimension;
                this.zDimension      = generated.zDimension;
            }



            if (!this._isLoaded)
            {
                parentShape = GetParent <Shape>();

                texturing           = parentShape.texturingEnabled;
                generateTexCoordMap = texturing && texCoordinateNode == null;

                this._isLoaded = true;
            }


            height_mapping();

            bbox = BoundingBox.CalcBoundingBox(this);


            geometry = BuildElevationGeometryQuads(bbox);

            Buffering.BufferShaderGeometry(geometry, out handle.vbo4, out handle.NumVerticies4);
        }
Beispiel #27
0
 internal void Parse(List <string> args)
 {
     for (var i = 0; i < args.Count; i++)
     {
         if (args[i].StartsWith("--pipe="))
         {
             pipe      = args[i].Substring(args[i].IndexOf("=") + 1);
             transport = TransportChoice.NamedPipe;
         }
         else if (args[i].StartsWith("--port="))
         {
             port = int.Parse(args[i].Substring(args[i].IndexOf("=") + 1));
             if (transport != TransportChoice.TlsSocket)
             {
                 transport = TransportChoice.Socket;
             }
         }
         else if (args[i] == "-b" || args[i] == "--buffered" || args[i] == "--transport=buffered")
         {
             buffering = Buffering.BufferedTransport;
         }
         else if (args[i] == "-f" || args[i] == "--framed" || args[i] == "--transport=framed")
         {
             buffering = Buffering.FramedTransport;
         }
         else if (args[i] == "--binary" || args[i] == "--protocol=binary")
         {
             protocol = ProtocolChoice.Binary;
         }
         else if (args[i] == "--compact" || args[i] == "--protocol=compact")
         {
             protocol = ProtocolChoice.Compact;
         }
         else if (args[i] == "--json" || args[i] == "--protocol=json")
         {
             protocol = ProtocolChoice.Json;
         }
         else if (args[i] == "--threaded" || args[i] == "--server-type=threaded")
         {
             throw new NotImplementedException(args[i]);
         }
         else if (args[i] == "--threadpool" || args[i] == "--server-type=threadpool")
         {
             throw new NotImplementedException(args[i]);
         }
         else if (args[i] == "--prototype" || args[i] == "--processor=prototype")
         {
             throw new NotImplementedException(args[i]);
         }
         else if (args[i] == "--ssl")
         {
             transport = TransportChoice.TlsSocket;
         }
         else if (args[i] == "--help")
         {
             PrintOptionsHelp();
             return;
         }
         else
         {
             Console.WriteLine("Invalid argument: {0}", args[i]);
             PrintOptionsHelp();
             return;
         }
     }
 }
Beispiel #28
0
 private void ReportVideoBuffering(bool isBuffering)
 {
     Buffering?.Invoke(this, new VideoBufferingEventArgs(isBuffering));
 }
Beispiel #29
0
        private static async Task RunSelectedConfigurationAsync(Transport transport, Buffering buffering, Protocol protocol, CancellationToken cancellationToken)
        {
            var handler = new CalculatorAsyncHandler();

            TServerTransport serverTransport = null;

            switch (transport)
            {
            case Transport.Tcp:
                serverTransport = new TServerSocketTransport(9090);
                break;

            case Transport.NamedPipe:
                serverTransport = new TNamedPipeServerTransport(".test");
                break;

            case Transport.TcpTls:
                serverTransport = new TTlsServerSocketTransport(9090, GetCertificate(), ClientCertValidator, LocalCertificateSelectionCallback);
                break;
            }

            TTransportFactory inputTransportFactory  = null;
            TTransportFactory outputTransportFactory = null;

            switch (buffering)
            {
            case Buffering.Buffered:
                inputTransportFactory  = new TBufferedTransport.Factory();
                outputTransportFactory = new TBufferedTransport.Factory();
                break;

            case Buffering.Framed:
                inputTransportFactory  = new TFramedTransport.Factory();
                outputTransportFactory = new TFramedTransport.Factory();
                break;

            default:     // layered transport(s) are optional
                Debug.Assert(buffering == Buffering.None, "unhandled case");
                break;
            }

            TProtocolFactory inputProtocolFactory  = null;
            TProtocolFactory outputProtocolFactory = null;
            ITAsyncProcessor processor             = null;

            switch (protocol)
            {
            case Protocol.Binary:
                inputProtocolFactory  = new TBinaryProtocol.Factory();
                outputProtocolFactory = new TBinaryProtocol.Factory();
                processor             = new Calculator.AsyncProcessor(handler);
                break;

            case Protocol.Compact:
                inputProtocolFactory  = new TCompactProtocol.Factory();
                outputProtocolFactory = new TCompactProtocol.Factory();
                processor             = new Calculator.AsyncProcessor(handler);
                break;

            case Protocol.Json:
                inputProtocolFactory  = new TJsonProtocol.Factory();
                outputProtocolFactory = new TJsonProtocol.Factory();
                processor             = new Calculator.AsyncProcessor(handler);
                break;

            case Protocol.Multiplexed:
                inputProtocolFactory  = new TBinaryProtocol.Factory();
                outputProtocolFactory = new TBinaryProtocol.Factory();

                var calcHandler   = new CalculatorAsyncHandler();
                var calcProcessor = new Calculator.AsyncProcessor(calcHandler);

                var sharedServiceHandler   = new SharedServiceAsyncHandler();
                var sharedServiceProcessor = new SharedService.AsyncProcessor(sharedServiceHandler);

                var multiplexedProcessor = new TMultiplexedProcessor();
                multiplexedProcessor.RegisterProcessor(nameof(Calculator), calcProcessor);
                multiplexedProcessor.RegisterProcessor(nameof(SharedService), sharedServiceProcessor);

                processor = multiplexedProcessor;
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(protocol), protocol, null);
            }


            try
            {
                Logger.LogInformation(
                    $"Selected TAsyncServer with {serverTransport} transport, {processor} processor and {inputProtocolFactory} protocol factories");

                var loggerFactory = ServiceCollection.BuildServiceProvider().GetService <ILoggerFactory>();

                var server = new TSimpleAsyncServer(
                    itProcessorFactory: new TSingletonProcessorFactory(processor),
                    serverTransport: serverTransport,
                    inputTransportFactory: inputTransportFactory,
                    outputTransportFactory: outputTransportFactory,
                    inputProtocolFactory: inputProtocolFactory,
                    outputProtocolFactory: outputProtocolFactory,
                    logger: loggerFactory.CreateLogger <TSimpleAsyncServer>());

                Logger.LogInformation("Starting the server...");

                await server.ServeAsync(cancellationToken);
            }
            catch (Exception x)
            {
                Logger.LogInformation(x.ToString());
            }
        }
Beispiel #30
0
        private void RenderSkydome(RenderingContext rc)
        {
            rc.PushMatricies();

            texture2d = GL.IsEnabled(EnableCap.Texture2D);

            if (texture2d)
            {
                GL.Disable(EnableCap.Texture2D);
            }

            Matrix4 mat4;

            // Outer sky Sphere
            //this._shapeOuter.Render(rc);

            _shaderOuter.Use();



#if APPLY_BACKDROP
            mat4 = rc.cam.GetWorldOrientation();
            _shaderOuter.SetFieldValue("modelview", ref mat4);
#endif
            //_shaderOuter.SetFieldValue("scale", scaleSky);
            _shaderOuter.SetFieldValue("scale", size);
            _shaderOuter.SetFieldValue("size", size);
            if (skydomeColors != null && skydomeColors.Length > 0)
            {
                _shaderOuter.SetFieldValue("skyColors", this.skydomeColors.Length);//_shaderOuter.SetFieldValue("skyColors", this.colors.Length);
                _shaderOuter.SetFieldValue("skyColor", this.skydomeColors, 255 * 3);
            }
            //_shaderOuter.SetFieldValue("skyColor", this.colors, 255 * 3);
            _shaderOuter.SetFieldValue("skyAngle", this.angles, 255);

            _shaderOuter.SetFieldValue("isGround", 0);
            _shaderOuter.SetFieldValue("bbox", bboxOuter);
            _shaderOuter.SetFieldValue("max", max);
            _shaderOuter.SetFieldValue("min", min);

            _shaderOuter.SetFieldValue("projection", ref rc.matricies.projection);
            _shaderOuter.SetFieldValue("camscale", rc.cam.Scale.X);
            _shaderOuter.SetFieldValue("X3DScale", rc.matricies.Scale);

#if APPLY_BACKDROP
            GL.DepthMask(false);
#endif
            if (skydomeComputed)
            {
                GL.BindTexture(TextureTarget.Texture2D, skydomeTexture);
            }

            GL.BindBuffer(BufferTarget.ArrayBuffer, outerHandle.vbo4);
            Buffering.ApplyBufferPointers(_shaderOuter);
            GL.DrawArrays(PrimitiveType.Quads, 0, outerHandle.NumVerticies4);

            if (skydomeComputed)
            {
                GL.BindTexture(TextureTarget.Texture2D, 0);
            }

#if APPLY_BACKDROP
            GL.DepthMask(true);
#endif
            rc.PopMatricies();


            //            rc.PushMatricies();

            //            // Inner ground Hemisphere
            //            //RenderCube(rc);

            //            _shaderInner.Use();
            //#if APPLY_BACKDROP
            //            mat4 = rc.cam.GetWorldOrientation();
            //            _shaderInner.SetFieldValue("modelview", ref mat4);
            //#endif
            //            _shaderInner.SetFieldValue("scale", scaleGround);
            //            _shaderInner.SetFieldValue("size", size);
            //            _shaderOuter.SetFieldValue("skyColor", this.skydomeColors, 255 * 3);
            //            //_shaderInner.SetFieldValue("skyColor", this.colors, 255 * 3);
            //            _shaderInner.SetFieldValue("skyAngle", this.angles, 255);
            //            _shaderInner.SetFieldValue("skyColors", this.colors.Length);
            //            _shaderInner.SetFieldValue("isGround", 1);
            //            _shaderInner.SetFieldValue("bbox", bboxInner);

            //            _shaderInner.SetFieldValue("projection", ref rc.matricies.projection);
            //            _shaderInner.SetFieldValue("camscale", rc.cam.Scale.X);
            //            _shaderInner.SetFieldValue("X3DScale", rc.matricies.Scale);

            //#if APPLY_BACKDROP
            //            GL.DepthMask(false);
            //#endif
            //            GL.BindBuffer(BufferTarget.ArrayBuffer, innerHandle.vbo4);
            //            Buffering.ApplyBufferPointers(_shaderInner);
            //            GL.DrawArrays(PrimitiveType.Quads, 0, innerHandle.NumVerticies4);

            //#if APPLY_BACKDROP
            //            GL.DepthMask(true);
            //#endif


            //            rc.PopMatricies();

            if (texture2d)
            {
                GL.Enable(EnableCap.Texture2D);
            }
        }