Bladeren bron

Added SpriteBatch::getSampler() for allowing developer access to the Texture::Sampler for controlling sampler modes.
Changed Font to set the sampler filter mode to LINEAR, LINEAR for smoother fonts.
Changed sampler05-particles to use only 1 mid-sized font gpb file.

setaylor 13 jaren geleden
bovenliggende
commit
3da1bbca77
6 gewijzigde bestanden met toevoegingen van 45 en 24 verwijderingen
  1. 7 7
      gameplay.sln
  2. 4 0
      gameplay/src/Font.cpp
  3. 6 11
      gameplay/src/Font.h
  4. 9 3
      gameplay/src/SpriteBatch.cpp
  5. 11 1
      gameplay/src/SpriteBatch.h
  6. 8 2
      gameplay/src/Texture.h

+ 7 - 7
gameplay.sln

@@ -28,7 +28,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sample00-mesh", "gameplay-s
 		{1032BA4B-57EB-4348-9E03-29DD63E80E4A} = {1032BA4B-57EB-4348-9E03-29DD63E80E4A}
 	EndProjectSection
 EndProject
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sample05-lua", "gameplay-samples\sample05-lua\sample05-lua.vcxproj", "{C220DB61-B43A-9628-54DF-7285E1F597C8}"
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sample05-lua", "gameplay-samples\sample05-lua\sample05-lua.vcxproj", "{C6121A62-AA46-BA6D-A1CE-8000544456AA}"
 	ProjectSection(ProjectDependencies) = postProject
 		{1032BA4B-57EB-4348-9E03-29DD63E80E4A} = {1032BA4B-57EB-4348-9E03-29DD63E80E4A}
 	EndProjectSection
@@ -76,12 +76,12 @@ Global
 		{D672DC66-3CE0-4878-B0D2-813CA731012F}.DebugMem|Win32.Build.0 = DebugMem|Win32
 		{D672DC66-3CE0-4878-B0D2-813CA731012F}.Release|Win32.ActiveCfg = Release|Win32
 		{D672DC66-3CE0-4878-B0D2-813CA731012F}.Release|Win32.Build.0 = Release|Win32
-		{C220DB61-B43A-9628-54DF-7285E1F597C8}.Debug|Win32.ActiveCfg = Debug|Win32
-		{C220DB61-B43A-9628-54DF-7285E1F597C8}.Debug|Win32.Build.0 = Debug|Win32
-		{C220DB61-B43A-9628-54DF-7285E1F597C8}.DebugMem|Win32.ActiveCfg = DebugMem|Win32
-		{C220DB61-B43A-9628-54DF-7285E1F597C8}.DebugMem|Win32.Build.0 = DebugMem|Win32
-		{C220DB61-B43A-9628-54DF-7285E1F597C8}.Release|Win32.ActiveCfg = Release|Win32
-		{C220DB61-B43A-9628-54DF-7285E1F597C8}.Release|Win32.Build.0 = Release|Win32
+		{C6121A62-AA46-BA6D-A1CE-8000544456AA}.Debug|Win32.ActiveCfg = Debug|Win32
+		{C6121A62-AA46-BA6D-A1CE-8000544456AA}.Debug|Win32.Build.0 = Debug|Win32
+		{C6121A62-AA46-BA6D-A1CE-8000544456AA}.DebugMem|Win32.ActiveCfg = DebugMem|Win32
+		{C6121A62-AA46-BA6D-A1CE-8000544456AA}.DebugMem|Win32.Build.0 = DebugMem|Win32
+		{C6121A62-AA46-BA6D-A1CE-8000544456AA}.Release|Win32.ActiveCfg = Release|Win32
+		{C6121A62-AA46-BA6D-A1CE-8000544456AA}.Release|Win32.Build.0 = Release|Win32
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE

+ 4 - 0
gameplay/src/Font.cpp

@@ -140,6 +140,10 @@ Font* Font::create(const char* family, Style style, unsigned int size, Glyph* gl
     // Create batch for the font.
     SpriteBatch* batch = SpriteBatch::create(texture, __fontEffect, 128);
 
+    // Add linear filtering for better font quality.
+    Texture::Sampler* sampler = batch->getSampler();
+    sampler->setFilterMode(Texture::LINEAR, Texture::LINEAR);
+
     // Release __fontEffect since the SpriteBatch keeps a reference to it
     SAFE_RELEASE(__fontEffect);
 

+ 6 - 11
gameplay/src/Font.h

@@ -32,17 +32,12 @@ public:
      */
     enum Justify
     {
-        // Specify horizontal alignment, use default vertical alignment (ALIGN_TOP).
         ALIGN_LEFT = 0x01,
         ALIGN_HCENTER = 0x02,
         ALIGN_RIGHT = 0x04,
-    
-        // Specify vertical alignment, use default horizontal alignment (ALIGN_LEFT).
         ALIGN_TOP = 0x10,
         ALIGN_VCENTER = 0x20,
         ALIGN_BOTTOM = 0x40,
-
-        // Specify both vertical and horizontal alignment.
         ALIGN_TOP_LEFT = ALIGN_TOP | ALIGN_LEFT,
         ALIGN_VCENTER_LEFT = ALIGN_VCENTER | ALIGN_LEFT,
         ALIGN_BOTTOM_LEFT = ALIGN_BOTTOM | ALIGN_LEFT,
@@ -121,11 +116,6 @@ public:
      */
     void start();
 
-    /**
-     * Finishes text batching for this font and renders all drawn text.
-     */
-    void finish();
-
     /**
      * Draws the specified text in a solid color, with a scaling factor.
      *
@@ -181,6 +171,11 @@ public:
     Text* createText(const char* text, const Rectangle& area, const Vector4& color, unsigned int size = 0,
                      Justify justify = ALIGN_TOP_LEFT, bool wrap = true, bool rightToLeft = false, const Rectangle* clip = NULL);
 
+    /**
+     * Finishes text batching for this font and renders all drawn text.
+     */
+    void finish();
+
     /**
      * Measures a string's width and height without alignment, wrapping or clipping.
      *
@@ -235,8 +230,8 @@ public:
      */
     static Justify getJustify(const char* justify);
 
-
 private:
+
     /**
      * Defines a font glyph within the texture map for a font.
      */

+ 9 - 3
gameplay/src/SpriteBatch.cpp

@@ -48,13 +48,14 @@ namespace gameplay
 static Effect* __spriteEffect = NULL;
 
 SpriteBatch::SpriteBatch()
-    : _batch(NULL), _textureWidthRatio(0.0f), _textureHeightRatio(0.0f)
+    : _batch(NULL), _sampler(NULL), _textureWidthRatio(0.0f), _textureHeightRatio(0.0f)
 {
 }
 
 SpriteBatch::~SpriteBatch()
 {
     SAFE_DELETE(_batch);
+    SAFE_RELEASE(_sampler);
     if (!_customEffect)
     {
         if (__spriteEffect && __spriteEffect->getRefCount() == 1)
@@ -131,8 +132,7 @@ SpriteBatch* SpriteBatch::create(Texture* texture, Effect* effect, unsigned int
     // Bind the texture to the material as a sampler
     Texture::Sampler* sampler = Texture::Sampler::create(texture); // +ref texture
     material->getParameter(samplerUniform->getName())->setValue(sampler);
-    SAFE_RELEASE(sampler);
-
+    
     // Define the vertex format for the batch
     VertexFormat::Element vertexElements[] =
     {
@@ -148,6 +148,7 @@ SpriteBatch* SpriteBatch::create(Texture* texture, Effect* effect, unsigned int
 
     // Create the batch
     SpriteBatch* batch = new SpriteBatch();
+    batch->_sampler = sampler;
     batch->_customEffect = customEffect;
     batch->_batch = meshBatch;
     batch->_textureWidthRatio = 1.0f / (float)texture->getWidth();
@@ -395,6 +396,11 @@ RenderState::StateBlock* SpriteBatch::getStateBlock() const
     return _batch->getMaterial()->getStateBlock();
 }
 
+Texture::Sampler* SpriteBatch::getSampler() const
+{
+    return _sampler;
+}
+
 Material* SpriteBatch::getMaterial() const
 {
     return _batch->getMaterial();

+ 11 - 1
gameplay/src/SpriteBatch.h

@@ -246,7 +246,16 @@ public:
     void finish();
 
     /**
-     * Returns the StateBlock for the SpriteBatch.
+     * Gets the texture sampler. 
+     *
+     * This return texture sampler is used when sampling the texture in the
+     * effect. This can be modified for controlling sampler setting such as
+     * filtering modes.
+     */
+    Texture::Sampler* getSampler() const;
+
+    /**
+     * Gets the StateBlock for the SpriteBatch.
      *
      * The returned state block controls the renderer state used when drawing items
      * with this sprite batch. Modification can be made to the returned state block
@@ -363,6 +372,7 @@ private:
     bool clipSprite(const Rectangle& clip, float& x, float& y, float& width, float& height, float& u1, float& v1, float& u2, float& v2);
 
     MeshBatch* _batch;
+    Texture::Sampler* _sampler;
     bool _customEffect;
     float _textureWidthRatio;
     float _textureHeightRatio;

+ 8 - 2
gameplay/src/Texture.h

@@ -63,6 +63,11 @@ public:
 
     public:
 
+        /**
+         * Destructor.
+         */
+        virtual ~Sampler();
+
         /**
          * Creates a sampler for the specified texture.
          *
@@ -114,10 +119,11 @@ public:
 
     private:
 
+        /**
+         * Constructor.
+         */
         Sampler(Texture* texture);
 
-        ~Sampler();
-
         /**
          * Hidden copy assignment operator.
          */