//////////////////////////////////////////////////////////// /// <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"); } }
//////////////////////////////////////////////////////////// /// <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"); }
//////////////////////////////////////////////////////////// /// <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"); } }
/// <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"); } }
//////////////////////////////////////////////////////////// /// <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"); }
//////////////////////////////////////////////////////////// /// <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"); }
//////////////////////////////////////////////////////////// /// <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"); }
//////////////////////////////////////////////////////////// /// <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"); }
//////////////////////////////////////////////////////////// /// <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"); } }
//////////////////////////////////////////////////////////// /// <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"); } }
//////////////////////////////////////////////////////////// /// <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"); } }
//////////////////////////////////////////////////////////// /// <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"); } }
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); }