Esempio n. 1
0
            ////////////////////////////////////////////////////////////
            /// <summary>
            /// Load both the vertex and fragment shaders from custom streams
            ///
            /// This function can load both the vertex and the fragment
            /// shaders, or only one of them: pass NULL if you don't want to load
            /// either the vertex shader or the fragment shader.
            /// The sources must be valid shaders in GLSL language. GLSL is
            /// a C-like language dedicated to OpenGL shaders; you'll
            /// probably need to read a good documentation for it before
            /// writing your own shaders.
            /// </summary>
            /// <param name="vertexShaderStream">Source stream to read the vertex shader from, or null to skip this shader</param>
            /// <param name="fragmentShaderStream">Source stream to read the fragment shader from, or null to skip this shader</param>
            /// <exception cref="LoadingFailedException" />
            ////////////////////////////////////////////////////////////
            public Shader(Stream vertexShaderStream, Stream fragmentShaderStream) :
                base(IntPtr.Zero)
            {
                if ((fragmentShaderStream != null) || (vertexShaderStream != null))
                {
                    if (fragmentShaderStream == null)
                    {
                        StreamAdaptor vertexAdaptor = new StreamAdaptor(vertexShaderStream);
                        CPointer = sfShader_createFromStream(vertexAdaptor.InputStreamPtr, IntPtr.Zero);
                        vertexAdaptor.Dispose();
                    }
                    else if (vertexShaderStream == null)
                    {
                        StreamAdaptor fragmentAdaptor = new StreamAdaptor(fragmentShaderStream);
                        CPointer = sfShader_createFromStream(IntPtr.Zero, fragmentAdaptor.InputStreamPtr);
                        fragmentAdaptor.Dispose();
                    }
                    else
                    {
                        StreamAdaptor vertexAdaptor   = new StreamAdaptor(vertexShaderStream);
                        StreamAdaptor fragmentAdaptor = new StreamAdaptor(fragmentShaderStream);
                        CPointer = sfShader_createFromStream(vertexAdaptor.InputStreamPtr, fragmentAdaptor.InputStreamPtr);
                        vertexAdaptor.Dispose();
                        fragmentAdaptor.Dispose();
                    }
                }

                if (CPointer == IntPtr.Zero)
                {
                    throw new LoadingFailedException("shader");
                }
            }
Esempio n. 2
0
            ////////////////////////////////////////////////////////////
            /// <summary>
            /// Construct the font from a custom stream
            /// </summary>
            /// <param name="stream">Source stream to read from</param>
            /// <exception cref="LoadingFailedException" />
            ////////////////////////////////////////////////////////////
            public Font(Stream stream)
                : base(IntPtr.Zero)
            {
                myStream = new StreamAdaptor(stream);
                SetThis(sfFont_CreateFromStream(myStream.InputStreamPtr));

                if (This == IntPtr.Zero)
                    throw new LoadingFailedException("font");
            }
Esempio n. 3
0
        ////////////////////////////////////////////////////////////
        /// <summary>
        /// Construct the font from a custom stream
        /// </summary>
        /// <param name="stream">Source stream to read from</param>
        /// <exception cref="LoadingFailedException" />
        ////////////////////////////////////////////////////////////
        public Font(Stream stream) : base(IntPtr.Zero)
        {
            myStream = new StreamAdaptor(stream);
            CPointer = sfFont_createFromStream(myStream.InputStreamPtr);

            if (CPointer == IntPtr.Zero)
            {
                throw new LoadingFailedException("font");
            }
        }
Esempio n. 4
0
 /// <summary>
 /// Constructs a music from a custom stream.
 /// Since the music is not loaded at once but rather streamed continuously,
 /// the stream must remain accessible until this Music object is disposed.
 /// </summary>
 /// <param name="stream">Source stream to read from.</param>
 public Music(Stream stream)
     : base(IntPtr.Zero)
 {
     _stream  = new StreamAdaptor(stream);
     CPointer = sfMusic_createFromStream(_stream.InputStreamPtr);
     if (CPointer == IntPtr.Zero)
     {
         throw new LoadingFailedException("music");
     }
 }
Esempio n. 5
0
            ////////////////////////////////////////////////////////////
            /// <summary>
            /// Construct the texture from a file in a stream
            /// </summary>
            /// <param name="stream">Stream containing the file contents</param>
            /// <param name="area">Area of the image to load</param>
            /// <exception cref="LoadingFailedException" />
            ////////////////////////////////////////////////////////////
            public Texture(Stream stream, IntRect area)
                : base(IntPtr.Zero)
            {
                using (StreamAdaptor adaptor = new StreamAdaptor(stream))
                {
                    SetThis(sfTexture_CreateFromStream(adaptor.InputStreamPtr, ref area));
                }

                if (This == IntPtr.Zero)
                    throw new LoadingFailedException("texture");
            }
Esempio n. 6
0
            ////////////////////////////////////////////////////////////
            /// <summary>
            /// Construct the image from a file in a stream
            /// </summary>
            /// <param name="stream">Stream containing the file contents</param>
            /// <exception cref="LoadingFailedException" />
            ////////////////////////////////////////////////////////////
            public Image(Stream stream)
                : base(IntPtr.Zero)
            {
                using (StreamAdaptor adaptor = new StreamAdaptor(stream))
                {
                    SetThis(sfImage_CreateFromStream(adaptor.InputStreamPtr));
                }

                if (This == IntPtr.Zero)
                    throw new LoadingFailedException("image");
            }
Esempio n. 7
0
            ////////////////////////////////////////////////////////////
            /// <summary>
            /// Load the sound buffer from a custom stream
            /// </summary>
            /// <param name="stream">Source stream to read from</param>
            /// <exception cref="LoadingFailedException" />
            ////////////////////////////////////////////////////////////
            public SoundBuffer(Stream stream)
                : base(IntPtr.Zero)
            {
                using (StreamAdaptor adaptor = new StreamAdaptor(stream))
                {
                    SetThis(sfSoundBuffer_createFromStream(adaptor.InputStreamPtr));
                }

                if (CPointer == IntPtr.Zero)
                    throw new LoadingFailedException("sound buffer");
            }
Esempio n. 8
0
            ////////////////////////////////////////////////////////////
            /// <summary>
            /// Load both the vertex and fragment shaders from custom streams
            ///
            /// This function can load both the vertex and the fragment
            /// shaders, or only one of them: pass NULL if you don't want to load
            /// either the vertex shader or the fragment shader.
            /// The sources must be valid shaders in GLSL language. GLSL is
            /// a C-like language dedicated to OpenGL shaders; you'll
            /// probably need to read a good documentation for it before
            /// writing your own shaders.
            /// </summary>
            /// <param name="vertexShaderStream">Source stream to read the vertex shader from, or null to skip this shader</param>
            /// <param name="fragmentShaderStream">Source stream to read the fragment shader from, or null to skip this shader</param>
            /// <exception cref="LoadingFailedException" />
            ////////////////////////////////////////////////////////////
            public Shader(Stream vertexShaderStream, Stream fragmentShaderStream) :
                base(IntPtr.Zero)
            {
                StreamAdaptor vertexAdaptor = new StreamAdaptor(vertexShaderStream);
                StreamAdaptor fragmentAdaptor = new StreamAdaptor(fragmentShaderStream);
                SetThis(sfShader_createFromStream(vertexAdaptor.InputStreamPtr, fragmentAdaptor.InputStreamPtr));
                vertexAdaptor.Dispose();
                fragmentAdaptor.Dispose();

                if (CPointer == IntPtr.Zero)
                    throw new LoadingFailedException("shader");
            }
Esempio n. 9
0
        ////////////////////////////////////////////////////////////
        /// <summary>
        /// Construct the image from a file in a stream
        /// </summary>
        /// <param name="stream">Stream containing the file contents</param>
        /// <exception cref="LoadingFailedException" />
        ////////////////////////////////////////////////////////////
        public Image(Stream stream) :
            base(IntPtr.Zero)
        {
            using (StreamAdaptor adaptor = new StreamAdaptor(stream))
            {
                SetThis(sfImage_createFromStream(adaptor.InputStreamPtr));
            }

            if (CPointer == IntPtr.Zero)
            {
                throw new LoadingFailedException("image");
            }
        }
Esempio n. 10
0
        ////////////////////////////////////////////////////////////
        /// <summary>
        /// Construct the texture from a file in a stream
        /// </summary>
        /// <param name="stream">Stream containing the file contents</param>
        /// <param name="area">Area of the image to load</param>
        /// <exception cref="LoadingFailedException" />
        ////////////////////////////////////////////////////////////
        public Texture(Stream stream, IntRect area) :
            base(IntPtr.Zero)
        {
            using (StreamAdaptor adaptor = new StreamAdaptor(stream))
            {
                CPointer = sfTexture_createFromStream(adaptor.InputStreamPtr, ref area);
            }

            if (CPointer == IntPtr.Zero)
            {
                throw new LoadingFailedException("texture");
            }
        }
Esempio n. 11
0
        ////////////////////////////////////////////////////////////
        /// <summary>
        /// Construct a sound buffer from a custom stream.
        ///
        /// Here is a complete list of all the supported audio formats:
        /// ogg, wav, flac, aiff, au, raw, paf, svx, nist, voc, ircam,
        /// w64, mat4, mat5 pvf, htk, sds, avr, sd2, caf, wve, mpc2k, rf64.
        /// </summary>
        /// <param name="stream">Source stream to read from</param>
        /// <exception cref="LoadingFailedException" />
        ////////////////////////////////////////////////////////////
        public SoundBuffer(Stream stream) :
            base(IntPtr.Zero)
        {
            using (StreamAdaptor adaptor = new StreamAdaptor(stream))
            {
                CPointer = sfSoundBuffer_createFromStream(adaptor.InputStreamPtr);
            }

            if (CPointer == IntPtr.Zero)
            {
                throw new LoadingFailedException("sound buffer");
            }
        }
Esempio n. 12
0
        ////////////////////////////////////////////////////////////
        /// <summary>
        /// Load the vertex, geometry and fragment shaders from custom streams
        /// </summary>
        ///
        /// <remarks>
        /// This function loads the vertex, geometry and fragment
        /// shaders. Pass NULL if you don't want to load
        /// a specific shader.
        /// The sources must be valid shaders in GLSL language. GLSL is
        /// a C-like language dedicated to OpenGL shaders; you'll
        /// probably need to read a good documentation for it before
        /// writing your own shaders.
        /// </remarks>
        /// <param name="vertexShaderStream">Source stream to read the vertex shader from, or null to skip this shader</param>
        /// <param name="geometryShaderStream">Source stream to read the geometry shader from, or null to skip this shader</param>
        /// <param name="fragmentShaderStream">Source stream to read the fragment shader from, or null to skip this shader</param>
        /// <exception cref="LoadingFailedException" />
        ////////////////////////////////////////////////////////////
        public Shader(Stream vertexShaderStream, Stream geometryShaderStream, Stream fragmentShaderStream) :
            base(IntPtr.Zero)
        {
            // using these funky conditional operators because StreamAdaptor doesn't have some method for dealing with
            // its constructor argument being null
            using (StreamAdaptor vertexAdaptor = vertexShaderStream != null ? new StreamAdaptor(vertexShaderStream) : null,
                   geometryAdaptor = geometryShaderStream != null ? new StreamAdaptor(geometryShaderStream) : null,
                   fragmentAdaptor = fragmentShaderStream != null ? new StreamAdaptor(fragmentShaderStream) : null)
            {
                CPointer = sfShader_createFromStream(vertexAdaptor.InputStreamPtr, geometryAdaptor.InputStreamPtr, fragmentAdaptor.InputStreamPtr);
            }

            if (CPointer == IntPtr.Zero)
            {
                throw new LoadingFailedException("shader");
            }
        }
Esempio n. 13
0
    public bool Connect(IScheduler scheduler, string ip, int port)
    {
        if (!_isConnected)
        {
            try
            {
                _router = new IdpRouter();
                _router.AddNode(this);

                _client = new TcpClient();
                _client.Connect(ip, port);

                _dataStream = _client.GetStream();

                _adaptor = new StreamAdaptor(scheduler, _dataStream, _dataStream);

                _adaptor.ConnectionError += (sender, e) =>
                {
                    Dispose();
                };

                _router.AddAdaptor(_adaptor);
                _adaptor.Start();

                _isConnected = true;

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }

        return(false);
    }