Skip to content

Commit

Permalink
Added mipmap to Texture and RenderTexture
Browse files Browse the repository at this point in the history
  • Loading branch information
dabbertorres committed Aug 17, 2016
1 parent 770c4ff commit d9e4870
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 6 deletions.
54 changes: 49 additions & 5 deletions src/Graphics/RenderTexture.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
using System;
using System.Runtime.InteropServices;
using System.Collections;
using System.Collections.Generic;
using System.Security;
using SFML.Window;
using SFML.System;

namespace SFML
Expand Down Expand Up @@ -60,6 +57,22 @@ public bool SetActive(bool active)
return sfRenderTexture_setActive(CPointer, active);
}

////////////////////////////////////////////////////////////
/// <summary>
/// Enable or disable texture repeating
/// </summary>
///
/// <remarks>
/// This property is similar to <see cref="Texture.Repeated"/>.
/// This parameter is disabled by default.
/// </remarks>
////////////////////////////////////////////////////////////
public bool Repeated
{
get { return sfRenderTexture_isRepeated(CPointer); }
set { sfRenderTexture_setRepeated(CPointer, value); }
}

////////////////////////////////////////////////////////////
/// <summary>
/// Size of the rendering region of the render texture
Expand Down Expand Up @@ -208,6 +221,28 @@ public Vector2i MapCoordsToPixel(Vector2f point, View view)
return sfRenderTexture_mapCoordsToPixel(CPointer, point, view != null ? view.CPointer : IntPtr.Zero);
}

////////////////////////////////////////////////////////////
/// <summary>
/// Generate a mipmap using the current texture data
/// </summary>
///
/// <remarks>
/// This function is similar to <see cref="Texture.GenerateMipmap"/> and operates
/// on the texture used as the target for drawing.
/// Be aware that any draw operation may modify the base level image data.
/// For this reason, calling this function only makes sense after all
/// drawing is completed and display has been called. Not calling display
/// after subsequent drawing will lead to undefined behavior if a mipmap
/// had been previously generated.
/// </remarks>
///
/// <returns>True if mipmap generation was successful, false if unsuccessful</returns>
////////////////////////////////////////////////////////////
public bool GenerateMipmap()
{
return sfRenderTexture_generateMipmap(CPointer);
}

////////////////////////////////////////////////////////////
/// <summary>
/// Clear the entire render texture with black color
Expand Down Expand Up @@ -507,10 +542,19 @@ protected override void Destroy(bool disposing)
static extern IntPtr sfRenderTexture_getTexture(IntPtr CPointer);

[DllImport("csfml-graphics-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
static extern void sfRenderTexture_setSmooth(IntPtr texture, bool smooth);
static extern void sfRenderTexture_setSmooth(IntPtr CPointer, bool smooth);

[DllImport("csfml-graphics-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
static extern bool sfRenderTexture_isSmooth(IntPtr CPointer);

[DllImport("csfml-graphics-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
static extern void sfRenderTexture_setRepeated(IntPtr CPointer, bool repeated);

[DllImport("csfml-graphics-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
static extern bool sfRenderTexture_isRepeated(IntPtr CPointer);

[DllImport("csfml-graphics-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
static extern bool sfRenderTexture_isSmooth(IntPtr texture);
static extern bool sfRenderTexture_generateMipmap(IntPtr CPointer);

[DllImport("csfml-graphics-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
unsafe static extern void sfRenderTexture_drawPrimitives(IntPtr CPointer, Vertex* vertexPtr, uint vertexCount, PrimitiveType type, ref RenderStates.MarshalData renderStates);
Expand Down
35 changes: 34 additions & 1 deletion src/Graphics/Texture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Runtime.InteropServices;
using System.Security;
using System.IO;
using System.Runtime.ConstrainedExecution;
using SFML.Window;
using SFML.System;

Expand Down Expand Up @@ -284,6 +283,37 @@ public void Update(RenderWindow window, uint x, uint y)
sfTexture_updateFromRenderWindow(CPointer, window.CPointer, x, y);
}

////////////////////////////////////////////////////////////
/// <summary>
/// Generate a mipmap using the current texture data
/// </summary>
///
/// <remarks>
/// <para>Mipmaps are pre-computed chains of optimized textures. Each
/// level of texture in a mipmap is generated by halving each of
/// the previous level's dimensions. This is done until the final
/// level has the size of 1x1. The textures generated in this process may
/// make use of more advanced filters which might improve the visual quality
/// of textures when they are applied to objects much smaller than they are.
/// This is known as minification. Because fewer texels (texture elements)
/// have to be sampled from when heavily minified, usage of mipmaps
/// can also improve rendering performance in certain scenarios.</para>
///
/// <para>Mipmap generation relies on the necessary OpenGL extension being
/// available. If it is unavailable or generation fails due to another
/// reason, this function will return false. Mipmap data is only valid from
/// the time it is generated until the next time the base level image is
/// modified, at which point this function will have to be called again to
/// regenerate it.</para>
/// </remarks>
///
/// <returns>True if mipmap generation was successful, false if unsuccessful</returns>
////////////////////////////////////////////////////////////
public bool GenerateMipmap()
{
return sfTexture_generateMipmap(CPointer);
}

////////////////////////////////////////////////////////////
/// <summary>
/// Control the smooth filter
Expand Down Expand Up @@ -474,6 +504,9 @@ protected override void Destroy(bool disposing)
[DllImport("csfml-graphics-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
static extern bool sfTexture_isRepeated(IntPtr texture);

[DllImport("csfml-graphics-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
static extern bool sfTexture_generateMipmap(IntPtr texture);

[DllImport("csfml-graphics-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
static extern uint sfTexture_getNativeHandle(IntPtr shader);

Expand Down

0 comments on commit d9e4870

Please sign in to comment.