//////////////////////////////////////////////////////////// /// <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 (CPointer == IntPtr.Zero) throw new LoadingFailedException("font"); }
//////////////////////////////////////////////////////////// /// <summary> /// Construct the music from a custom stream /// </summary> /// <param name="stream">Source stream to read from</param> //////////////////////////////////////////////////////////// public Music(Stream stream) : base(IntPtr.Zero) { myStream = new StreamAdaptor(stream); CPointer = sfMusic_createFromStream(myStream.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 (CPointer == IntPtr.Zero) throw new LoadingFailedException("texture"); }
//////////////////////////////////////////////////////////// /// <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)) { CPointer = sfSoundBuffer_createFromStream(adaptor.InputStreamPtr); } if (CPointer == IntPtr.Zero) throw new LoadingFailedException("sound buffer"); }
//////////////////////////////////////////////////////////// /// <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> /// 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"); }