Added support to GL_TEXTURE_MATRIX on the renderers.

Added Texture::CoordinateType and implemented the support to the TextureFactory::bind.
Some refactor was made.
Text now uses CoordinateType::Pixel.

--HG--
branch : dev-2.1
This commit is contained in:
Martín Lucas Golini
2018-01-18 02:31:53 -03:00
parent 1815b9f6d3
commit 0801d4c23d
27 changed files with 224 additions and 109 deletions

View File

@@ -10,6 +10,8 @@
#include <eepp/system/color.hpp>
using namespace EE::System;
#include <eepp/graphics/texture.hpp>
namespace EE { namespace Graphics {
struct eeTexCoord {
@@ -23,9 +25,6 @@ struct eeVertex {
Color color;
};
class TextureFactory;
class Texture;
/** @brief A batch rendering class. */
class EE_API BatchRenderer {
public:
@@ -40,7 +39,7 @@ class EE_API BatchRenderer {
void allocVertexs( const unsigned int& size );
/** Set the current texture to render on the batch ( if you change the texture and you have batched something, this will be renderer immediately ) */
void setTexture( const Texture * Tex );
void setTexture( const Texture * texture, Texture::CoordinateType coordinateType = Texture::CoordinateType::Normalized );
/** Set the predefined blending function to use on the batch */
void setBlendMode( const BlendMode& Blend );
@@ -246,7 +245,6 @@ class EE_API BatchRenderer {
unsigned int mNumVertex;
const Texture * mTexture;
TextureFactory * mTF;
BlendMode mBlend;
eeTexCoord mTexCoord[4];
@@ -259,6 +257,8 @@ class EE_API BatchRenderer {
Vector2f mPosition;
Vector2f mCenter;
Texture::CoordinateType mCoordinateType;
bool mForceRendering;
bool mForceBlendMode;

View File

@@ -10,6 +10,8 @@ using namespace EE::System;
namespace EE { namespace Graphics {
class Texture;
/** @enum EE_PARTICLE_EFFECT Predefined effects for the particle system. Use Callback when wan't to create a new effect, o set the parameters using NoFx, but it's much more limited. */
enum EE_PARTICLE_EFFECT {
PSE_Nofx = 0, //!< User defined effect
@@ -157,7 +159,7 @@ class EE_API ParticleSystem {
private:
Particle * mParticle;
Uint32 mPCount;
Uint32 mTexId;
const Texture * mTexture;
Uint32 mPLeft;
Uint32 mLoops;

View File

@@ -103,6 +103,7 @@ class EE_API RendererGL3 : public Renderer {
Private::MatrixStack * mStack;
int mProjectionMatrix_id; // cpu-side hook to shader uniform
int mModelViewMatrix_id; // cpu-side hook to shader uniform
int mTextureMatrix_id; // cpu-side hook to shader uniform
unsigned int mCurrentMode;
ShaderProgram * mShaders[ EEGL3_SHADERS_COUNT ];
ShaderProgram * mCurShader;

View File

@@ -105,6 +105,7 @@ class EE_API RendererGL3CP : public Renderer {
Private::MatrixStack * mStack;
int mProjectionMatrix_id; // cpu-side hook to shader uniform
int mModelViewMatrix_id; // cpu-side hook to shader uniform
int mTextureMatrix_id; // cpu-side hook to shader uniform
unsigned int mCurrentMode;
ShaderProgram * mShaders[ EEGL3CP_SHADERS_COUNT ];
ShaderProgram * mCurShader;

View File

@@ -106,6 +106,7 @@ class EE_API RendererGLES2 : public Renderer {
Private::MatrixStack * mStack;
int mProjectionMatrix_id; // cpu-side hook to shader uniform
int mModelViewMatrix_id; // cpu-side hook to shader uniform
int mTextureMatrix_id; // cpu-side hook to shader uniform
unsigned int mCurrentMode;
ShaderProgram * mShaders[ EEGLES2_SHADERS_COUNT ];
ShaderProgram * mCurShader;

View File

@@ -158,9 +158,9 @@ class EE_API Text {
/** Force to cache the width of the current text */
void cacheWidth();
static void addLine(std::vector<VertexCoords>& vertice, Float lineLength, Float lineTop, Float offset, Float thickness, Float outlineThickness, Sizei textureSize, Int32 centerDiffX);
static void addLine(std::vector<VertexCoords>& vertice, Float lineLength, Float lineTop, Float offset, Float thickness, Float outlineThickness, Int32 centerDiffX);
static void addGlyphQuad(std::vector<VertexCoords>& vertices, Vector2f position, const EE::Graphics::Glyph& glyph, Float italic, Float outlineThickness, Sizei textureSize, Int32 centerDiffX);
static void addGlyphQuad(std::vector<VertexCoords>& vertices, Vector2f position, const EE::Graphics::Glyph& glyph, Float italic, Float outlineThickness, Int32 centerDiffX);
Uint32 getTotalVertices();
};

View File

@@ -14,14 +14,19 @@ class EE_API Texture : public Image, public Drawable, private NonCopyable {
public:
/** @enum TextureFilter Defines the texture filter used. */
enum TextureFilter {
TEXTURE_FILTER_LINEAR, //!< Linear filtering (Smoothed Zoom)
TEXTURE_FILTER_NEAREST //!< No filtering (Pixeled Zoom)
Linear, //!< Linear filtering (Smoothed Zoom)
Nearest //!< No filtering (Pixeled Zoom)
};
/** @enum ClampMode Set the clamp mode of the texture. */
enum ClampMode {
CLAMP_TO_EDGE,
CLAMP_REPEAT
ClampToEdge,
ClampRepeat
};
enum CoordinateType {
Normalized, ///< Texture coordinates in range [0 .. 1]
Pixels ///< Texture coordinates in range [0 .. size]
};
static Uint32 getMaximumSize();
@@ -250,8 +255,11 @@ class EE_API Texture : public Image, public Drawable, private NonCopyable {
/** Set a pixel to the locked texture. */
void setPixel( const unsigned int& x, const unsigned int& y, const Color& Color );
/** Bind the texture. Activate the texture for rendering. */
void bind();
/** Bind the texture. Activate the texture for rendering.
* @param coordinateType Type of texture coordinates to use
* @param textureUnit The Texture unit that want to be used to bind ( usually 0 )
*/
void bind( CoordinateType coordinateType = Texture::CoordinateType::Normalized, const Uint32 & textureUnit = 0 );
std::string getName() const;

View File

@@ -28,7 +28,7 @@ class EE_API TextureFactory : protected Mutex {
* @param KeepLocalCopy Keep the array data copy. ( useful if want to reload the texture )
* @return Internal Texture Id
*/
Uint32 createEmptyTexture( const unsigned int& Width, const unsigned int& Height, const unsigned int& Channels = 4, const Color& DefaultColor = Color(0,0,0,255), const bool& Mipmap = false, const Texture::ClampMode& ClampMode = Texture::ClampMode::CLAMP_TO_EDGE, const bool& CompressTexture = false, const bool& KeepLocalCopy = false );
Uint32 createEmptyTexture( const unsigned int& Width, const unsigned int& Height, const unsigned int& Channels = 4, const Color& DefaultColor = Color(0,0,0,255), const bool& Mipmap = false, const Texture::ClampMode& ClampMode = Texture::ClampMode::ClampToEdge, const bool& CompressTexture = false, const bool& KeepLocalCopy = false );
/** Loads a RAW Texture from Memory
* @param Pixels The Texture array
@@ -42,7 +42,7 @@ class EE_API TextureFactory : protected Mutex {
* @param FileName A filename to recognize the texture ( the path in case that was loaded from outside the texture factory ).
* @return Internal Texture Id
*/
Uint32 loadFromPixels( const unsigned char * Pixels, const unsigned int& Width, const unsigned int& Height, const unsigned int& Channels, const bool& Mipmap = false, const Texture::ClampMode& ClampMode = Texture::ClampMode::CLAMP_TO_EDGE, const bool& CompressTexture = false, const bool& KeepLocalCopy = false, const std::string& FileName = std::string("") );
Uint32 loadFromPixels( const unsigned char * Pixels, const unsigned int& Width, const unsigned int& Height, const unsigned int& Channels, const bool& Mipmap = false, const Texture::ClampMode& ClampMode = Texture::ClampMode::ClampToEdge, const bool& CompressTexture = false, const bool& KeepLocalCopy = false, const std::string& FileName = std::string("") );
/** Load a texture from Pack file
* @param Pack Pointer to the pack instance
@@ -53,7 +53,7 @@ class EE_API TextureFactory : protected Mutex {
* @param KeepLocalCopy Keep the array data copy. ( useful if want to reload the texture )
* @return Internal Texture Id
*/
Uint32 loadFromPack( Pack* Pack, const std::string& FilePackPath, const bool& Mipmap = false, const Texture::ClampMode& ClampMode = Texture::ClampMode::CLAMP_TO_EDGE, const bool& CompressTexture = false, const bool& KeepLocalCopy = false );
Uint32 loadFromPack( Pack* Pack, const std::string& FilePackPath, const bool& Mipmap = false, const Texture::ClampMode& ClampMode = Texture::ClampMode::ClampToEdge, const bool& CompressTexture = false, const bool& KeepLocalCopy = false );
/** Load a texture from memory
* @param ImagePtr The image data in RAM just as if it were still in a file
@@ -64,7 +64,7 @@ class EE_API TextureFactory : protected Mutex {
* @param KeepLocalCopy Keep the array data copy. ( useful if want to reload the texture )
* @return The internal Texture Id
*/
Uint32 loadFromMemory( const unsigned char* ImagePtr, const unsigned int& Size, const bool& Mipmap = false, const Texture::ClampMode& ClampMode = Texture::ClampMode::CLAMP_TO_EDGE, const bool& CompressTexture = false, const bool& KeepLocalCopy = false );
Uint32 loadFromMemory( const unsigned char* ImagePtr, const unsigned int& Size, const bool& Mipmap = false, const Texture::ClampMode& ClampMode = Texture::ClampMode::ClampToEdge, const bool& CompressTexture = false, const bool& KeepLocalCopy = false );
/** Load a Texture from stream
* @param Stream The IOStream instance
@@ -74,7 +74,7 @@ class EE_API TextureFactory : protected Mutex {
* @param KeepLocalCopy Keep the array data copy. ( useful if want to reload the texture )
* @return The internal Texture Id
*/
Uint32 loadFromStream( IOStream& Stream, const bool& Mipmap = false, const Texture::ClampMode& ClampMode = Texture::ClampMode::CLAMP_TO_EDGE, const bool& CompressTexture = false, const bool& KeepLocalCopy = false );
Uint32 loadFromStream( IOStream& Stream, const bool& Mipmap = false, const Texture::ClampMode& ClampMode = Texture::ClampMode::ClampToEdge, const bool& CompressTexture = false, const bool& KeepLocalCopy = false );
/** Load a Texture from a file path
* @param Filepath The path for the texture
@@ -84,7 +84,7 @@ class EE_API TextureFactory : protected Mutex {
* @param KeepLocalCopy Keep the array data copy. ( useful if want to reload the texture )
* @return The internal Texture Id
*/
Uint32 loadFromFile( const std::string& Filepath, const bool& Mipmap = false, const Texture::ClampMode& ClampMode = Texture::ClampMode::CLAMP_TO_EDGE, const bool& CompressTexture = false, const bool& KeepLocalCopy = false );
Uint32 loadFromFile( const std::string& Filepath, const bool& Mipmap = false, const Texture::ClampMode& ClampMode = Texture::ClampMode::ClampToEdge, const bool& CompressTexture = false, const bool& KeepLocalCopy = false );
/** Remove and Unload the Texture Id
* @param TexId
@@ -99,13 +99,13 @@ class EE_API TextureFactory : protected Mutex {
* @param TexId The internal Texture Id
* @param TextureUnit The Texture Unit binded
*/
void bind( const Uint32& TexId, const Uint32& TextureUnit = 0 );
void bind( const Uint32& TexId, Texture::CoordinateType coordinateType = Texture::CoordinateType::Normalized, const Uint32& textureUnit = 0 );
/** Bind the the Texture indicated. This is useful if you are rendering a texture outside this class.
* @param Tex The Texture Pointer
* @param TextureUnit The Texture Unit binded
*/
void bind( const Texture* Tex, const Uint32& TextureUnit = 0 );
void bind( const Texture* Tex, Texture::CoordinateType coordinateType = Texture::CoordinateType::Normalized, const Uint32& TextureUnit = 0 );
/**
* @param TexId The internal Texture Id
@@ -192,6 +192,8 @@ class EE_API TextureFactory : protected Mutex {
Texture * getByHash( const Uint32& Hash );
~TextureFactory();
const Texture::CoordinateType& getLastCoordinateType() const;
protected:
friend class Texture;
@@ -207,6 +209,8 @@ class EE_API TextureFactory : protected Mutex {
std::list<Uint32> mVectorFreeSlots;
Texture::CoordinateType mLastCoordinateType;
void unloadTextures();
Uint32 findFreeSlot();

View File

@@ -23,7 +23,7 @@ class EE_API TextureLoader : public ObjectLoader {
* @param CompressTexture If use the DXT compression on the texture loading ( if the card can display them, will convert RGB to DXT1, RGBA to DXT5 )
* @param KeepLocalCopy Keep the array data copy. ( useful if want to reload the texture )
*/
TextureLoader( IOStream& Stream, const bool& Mipmap = false, const Texture::ClampMode& ClampMode = Texture::ClampMode::CLAMP_TO_EDGE, const bool& CompressTexture = false, const bool& KeepLocalCopy = false );
TextureLoader( IOStream& Stream, const bool& Mipmap = false, const Texture::ClampMode& ClampMode = Texture::ClampMode::ClampToEdge, const bool& CompressTexture = false, const bool& KeepLocalCopy = false );
/** Load a Texture from a file path
* @param Filepath The path for the texture
@@ -32,7 +32,7 @@ class EE_API TextureLoader : public ObjectLoader {
* @param CompressTexture If use the DXT compression on the texture loading ( if the card can display them, will convert RGB to DXT1, RGBA to DXT5 )
* @param KeepLocalCopy Keep the array data copy. ( useful if want to reload the texture )
*/
TextureLoader( const std::string& filepath, const bool& Mipmap = false, const Texture::ClampMode& ClampMode = Texture::ClampMode::CLAMP_TO_EDGE, const bool& CompressTexture = false, const bool& KeepLocalCopy = false );
TextureLoader( const std::string& filepath, const bool& Mipmap = false, const Texture::ClampMode& ClampMode = Texture::ClampMode::ClampToEdge, const bool& CompressTexture = false, const bool& KeepLocalCopy = false );
/** Load a texture from memory
* @param ImagePtr The image data in memory just as if it were still in a file
@@ -42,7 +42,7 @@ class EE_API TextureLoader : public ObjectLoader {
* @param CompressTexture If use the DXT compression on the texture loading ( if the card can display them, will convert RGB to DXT1, RGBA to DXT5 )
* @param KeepLocalCopy Keep the array data copy. ( useful if want to reload the texture )
*/
TextureLoader( const unsigned char * ImagePtr, const unsigned int& Size, const bool& Mipmap = false, const Texture::ClampMode& ClampMode = Texture::ClampMode::CLAMP_TO_EDGE, const bool& CompressTexture = false, const bool& KeepLocalCopy = false );
TextureLoader( const unsigned char * ImagePtr, const unsigned int& Size, const bool& Mipmap = false, const Texture::ClampMode& ClampMode = Texture::ClampMode::ClampToEdge, const bool& CompressTexture = false, const bool& KeepLocalCopy = false );
/** Load a texture from a Pack file
* @param Pack Pointer to the pack instance
@@ -52,7 +52,7 @@ class EE_API TextureLoader : public ObjectLoader {
* @param CompressTexture If use the DXT compression on the texture loading ( if the card can display them, will convert RGB to DXT1, RGBA to DXT5 )
* @param KeepLocalCopy Keep the array data copy. ( useful if want to reload the texture )
*/
TextureLoader( Pack * Pack, const std::string& FilePackPath, const bool& Mipmap = false, const Texture::ClampMode& ClampMode = Texture::ClampMode::CLAMP_TO_EDGE, const bool& CompressTexture = false, const bool& KeepLocalCopy = false );
TextureLoader( Pack * Pack, const std::string& FilePackPath, const bool& Mipmap = false, const Texture::ClampMode& ClampMode = Texture::ClampMode::ClampToEdge, const bool& CompressTexture = false, const bool& KeepLocalCopy = false );
/** Loads a RAW Texture from Memory
* @param Pixels The Texture array
@@ -65,7 +65,7 @@ class EE_API TextureLoader : public ObjectLoader {
* @param KeepLocalCopy Keep the array data copy. ( useful if want to reload the texture )
* @param FileName A filename to recognize the texture ( the path in case that was loaded from outside the texture factory ).
*/
TextureLoader( const unsigned char * Pixels, const unsigned int& Width, const unsigned int& Height, const unsigned int& Channels, const bool& Mipmap = false, const Texture::ClampMode& ClampMode = Texture::ClampMode::CLAMP_TO_EDGE, const bool& CompressTexture = false, const bool& KeepLocalCopy = false, const std::string& FileName = std::string("") );
TextureLoader( const unsigned char * Pixels, const unsigned int& Width, const unsigned int& Height, const unsigned int& Channels, const bool& Mipmap = false, const Texture::ClampMode& ClampMode = Texture::ClampMode::ClampToEdge, const bool& CompressTexture = false, const bool& KeepLocalCopy = false, const std::string& FileName = std::string("") );
virtual ~TextureLoader();

View File

@@ -1,6 +1,5 @@
#include <eepp/graphics/batchrenderer.hpp>
#include <eepp/graphics/texture.hpp>
#include <eepp/graphics/texturefactory.hpp>
#include <eepp/graphics/globalbatchrenderer.hpp>
#include <eepp/graphics/renderer/openglext.hpp>
#include <eepp/graphics/renderer/renderer.hpp>
@@ -13,17 +12,17 @@ BatchRenderer::BatchRenderer() :
mTVertex( NULL ),
mNumVertex(0),
mTexture(NULL),
mTF( TextureFactory::instance() ),
mBlend(BlendAlpha),
mCurrentMode(PRIMITIVE_QUADS),
mRotation(0.0f),
mScale(1.0f,1.0f),
mPosition(0.0f, 0.0f),
mCenter(0.0f, 0.0f),
mCoordinateType(Texture::CoordinateType::Normalized),
mForceRendering(false),
mForceBlendMode(true)
{
allocVertexs( 1024 );
allocVertexs( 4096 );
init();
}
@@ -33,13 +32,13 @@ BatchRenderer::BatchRenderer( const unsigned int& Prealloc ) :
mTVertex( NULL ),
mNumVertex(0),
mTexture(NULL),
mTF( TextureFactory::instance() ),
mBlend(BlendAlpha),
mCurrentMode(PRIMITIVE_QUADS),
mRotation(0.0f),
mScale(1.0f,1.0f),
mPosition(0.0f, 0.0f),
mCenter(0.0f, 0.0f),
mCoordinateType(Texture::CoordinateType::Normalized),
mForceRendering(false),
mForceBlendMode(true)
{
@@ -71,11 +70,12 @@ void BatchRenderer::draw() {
flush();
}
void BatchRenderer::setTexture( const Texture * Tex ) {
if ( mTexture != Tex )
void BatchRenderer::setTexture(const Texture * texture , Texture::CoordinateType coordinateType ) {
if ( mTexture != texture || mCoordinateType != coordinateType )
flush();
mTexture = Tex;
mTexture = texture;
mCoordinateType = coordinateType;
}
void BatchRenderer::setBlendMode( const BlendMode& Blend ) {
@@ -131,7 +131,7 @@ void BatchRenderer::flush() {
Uint32 alloc = sizeof(eeVertex) * NumVertex;
if ( NULL != mTexture ) {
mTF->bind( mTexture );
const_cast<Texture*>( mTexture )->bind( mCoordinateType );
GLi->texCoordPointer( 2, GL_FP , sizeof(eeVertex), reinterpret_cast<char*> ( &mVertex[0] ) + sizeof(Vector2f) , alloc );
} else {
GLi->disable( GL_TEXTURE_2D );

View File

@@ -680,7 +680,7 @@ FontTrueType::Page::Page() :
image.setPixel(x, y, Color(255, 255, 255, 255));
// Create the texture
Uint32 texId = TextureFactory::instance()->loadFromPixels( image.getPixelsPtr(), image.getWidth(), image.getHeight(), image.getChannels(), false, Texture::ClampMode::CLAMP_TO_EDGE, false, true );
Uint32 texId = TextureFactory::instance()->loadFromPixels( image.getPixelsPtr(), image.getWidth(), image.getHeight(), image.getChannels(), false, Texture::ClampMode::ClampToEdge, false, true );
texture = TextureFactory::instance()->getTexture( texId );
}

View File

@@ -1,6 +1,7 @@
#include <eepp/graphics/particlesystem.hpp>
#include <eepp/graphics/renderer/openglext.hpp>
#include <eepp/graphics/renderer/renderer.hpp>
#include <eepp/graphics/texture.hpp>
#include <eepp/graphics/texturefactory.hpp>
#include <eepp/graphics/batchrenderer.hpp>
#include <eepp/graphics/globalbatchrenderer.hpp>
@@ -13,7 +14,7 @@ namespace EE { namespace Graphics {
ParticleSystem::ParticleSystem() :
mParticle( NULL ),
mPCount( 0 ),
mTexId( 0 ),
mTexture( 0 ),
mPLeft( 0 ),
mLoops( 0 ),
mEffect( PSE_Nofx ),
@@ -44,7 +45,7 @@ void ParticleSystem::create( const EE_PARTICLE_EFFECT& Effect, const Uint32& Num
mEffect = Effect;
mPos = Pos;
mPCount = NumParticles;
mTexId = TexId;
mTexture = TextureFactory::instance()->getTexture( TexId );
mLoop = AnimLoop;
mLoops = NumLoops;
mColor = Color;
@@ -319,12 +320,16 @@ void ParticleSystem::draw() {
if ( !mUsed )
return;
TextureFactory * TF = TextureFactory::instance();
TF->bind( mTexId );
BlendMode::setMode( mBlend );
if ( mPointsSup ) {
if ( NULL != mTexture ) {
const_cast<Texture*>( mTexture )->bind();
} else {
GLi->disable( GL_TEXTURE_2D );
GLi->disableClientState( GL_TEXTURE_COORD_ARRAY );
}
GLi->enable( GL_POINT_SPRITE );
GLi->pointSize( mSize );
@@ -336,16 +341,13 @@ void ParticleSystem::draw() {
GLi->drawArrays( GL_POINTS, 0, (int)mPCount );
GLi->disable( GL_POINT_SPRITE );
GLi->enable( GL_TEXTURE_2D );
GLi->enableClientState( GL_TEXTURE_COORD_ARRAY );
} else {
Texture * Tex = TF->getTexture( mTexId );
if ( NULL == Tex )
return;
Particle* P;
BatchRenderer * BR = GlobalBatchRenderer::instance();
BR->setTexture( Tex );
BR->setTexture( mTexture );
BR->setBlendMode( mBlend );
BR->quadsBegin();

View File

@@ -47,6 +47,7 @@ const GLchar * EEGL3_SHADER_BASE_FS =
RendererGL3::RendererGL3() :
mProjectionMatrix_id(0),
mModelViewMatrix_id(0),
mTextureMatrix_id(0),
mCurrentMode(0),
mCurShader(NULL),
mShaderPrev(NULL),
@@ -66,6 +67,7 @@ RendererGL3::RendererGL3() :
mStack = eeNew( MatrixStack, () );
mStack->mProjectionMatrix.push ( glm::mat4( 1.0f ) ); // identity matrix
mStack->mModelViewMatrix.push ( glm::mat4( 1.0f ) ); // identity matrix
mStack->mTextureMatrix.push( glm::mat4( 1.0f ) ); // identity matrix
Renderer::enable( GL_VERTEX_PROGRAM_POINT_SIZE );
}
@@ -169,6 +171,7 @@ void RendererGL3::setShader( ShaderProgram * Shader ) {
mCurShader = Shader;
mProjectionMatrix_id = mCurShader->getUniformLocation( "dgl_ProjectionMatrix" );
mModelViewMatrix_id = mCurShader->getUniformLocation( "dgl_ModelViewMatrix" );
mTextureMatrix_id = mCurShader->getUniformLocation( "dgl_TextureMatrix" );
mTexActiveLoc = mCurShader->getUniformLocation( "dgl_TexActive" );
mPointSpriteLoc = mCurShader->getUniformLocation( "dgl_PointSpriteActive" );
mClippingEnabledLoc = mCurShader->getUniformLocation( "dgl_ClippingEnabled" );
@@ -440,6 +443,14 @@ void RendererGL3::updateMatrix() {
mCurShader->setUniformMatrix( mModelViewMatrix_id, &mStack->mModelViewMatrix.top()[0][0] );
}
break;
}
case GL_TEXTURE:
{
if ( -1 != mTextureMatrix_id ) {
mCurShader->setUniformMatrix( mTextureMatrix_id, &mStack->mTextureMatrix.top()[0][0] );
}
break;
}
}
@@ -519,6 +530,12 @@ void RendererGL3::getCurrentMatrix( unsigned int mode, float * m ) {
fromGLMmat4( mStack->mModelViewMatrix.top(), m );
break;
}
case GL_TEXTURE:
case GL_TEXTURE_MATRIX:
{
fromGLMmat4( mStack->mTextureMatrix.top(), m );
break;
}
}
}
@@ -542,6 +559,12 @@ void RendererGL3::matrixMode(unsigned int mode) {
mStack->mCurMatrix = &mStack->mModelViewMatrix;
break;
}
case GL_TEXTURE:
case GL_TEXTURE_MATRIX:
{
mStack->mCurMatrix = &mStack->mTextureMatrix;
break;
}
}
}

View File

@@ -61,6 +61,7 @@ const GLchar * EEGL3CP_SHADER_BASE_FS =
RendererGL3CP::RendererGL3CP() :
mProjectionMatrix_id(0),
mModelViewMatrix_id(0),
mTextureMatrix_id(0),
mCurrentMode(0),
mCurShader(NULL),
mShaderPrev(NULL),
@@ -80,6 +81,7 @@ RendererGL3CP::RendererGL3CP() :
mStack = eeNew( MatrixStack, () );
mStack->mProjectionMatrix.push ( glm::mat4( 1.0f ) ); // identity matrix
mStack->mModelViewMatrix.push ( glm::mat4( 1.0f ) ); // identity matrix
mStack->mTextureMatrix.push( glm::mat4( 1.0f ) ); // identity matrix
}
RendererGL3CP::~RendererGL3CP() {
@@ -196,6 +198,7 @@ void RendererGL3CP::setShader( ShaderProgram * Shader ) {
mCurShader = Shader;
mProjectionMatrix_id = mCurShader->getUniformLocation( "dgl_ProjectionMatrix" );
mModelViewMatrix_id = mCurShader->getUniformLocation( "dgl_ModelViewMatrix" );
mTextureMatrix_id = mCurShader->getUniformLocation( "dgl_TextureMatrix" );
mTexActiveLoc = mCurShader->getUniformLocation( "dgl_TexActive" );
mPointSpriteLoc = mCurShader->getUniformLocation( "dgl_PointSpriteActive" );
mClippingEnabledLoc = mCurShader->getUniformLocation( "dgl_ClippingEnabled" );
@@ -510,6 +513,14 @@ void RendererGL3CP::updateMatrix() {
mCurShader->setUniformMatrix( mModelViewMatrix_id, &mStack->mModelViewMatrix.top()[0][0] );
}
break;
}
case GL_TEXTURE:
{
if ( -1 != mTextureMatrix_id ) {
mCurShader->setUniformMatrix( mTextureMatrix_id, &mStack->mTextureMatrix.top()[0][0] );
}
break;
}
}
@@ -589,6 +600,12 @@ void RendererGL3CP::getCurrentMatrix( unsigned int mode, float * m ) {
fromGLMmat4( mStack->mModelViewMatrix.top(), m );
break;
}
case GL_TEXTURE:
case GL_TEXTURE_MATRIX:
{
fromGLMmat4( mStack->mTextureMatrix.top(), m );
break;
}
}
}
@@ -612,6 +629,12 @@ void RendererGL3CP::matrixMode(unsigned int mode) {
mStack->mCurMatrix = &mStack->mModelViewMatrix;
break;
}
case GL_TEXTURE:
case GL_TEXTURE_MATRIX:
{
mStack->mCurMatrix = &mStack->mTextureMatrix;
break;
}
}
}

View File

@@ -66,6 +66,7 @@ RendererGLES2::RendererGLES2() :
mStack( eeNew( MatrixStack, () ) ),
mProjectionMatrix_id(0),
mModelViewMatrix_id(0),
mTextureMatrix_id(0),
mCurrentMode(0),
mCurShader(NULL),
mShaderPrev(NULL),
@@ -84,6 +85,7 @@ RendererGLES2::RendererGLES2() :
mStack->mProjectionMatrix.push ( glm::mat4( 1.0f ) ); // identity matrix
mStack->mModelViewMatrix.push ( glm::mat4( 1.0f ) ); // identity matrix
mStack->mTextureMatrix.push( glm::mat4( 1.0f ) ); // identity matrix
}
RendererGLES2::~RendererGLES2() {
@@ -217,6 +219,7 @@ void RendererGLES2::setShader( ShaderProgram * Shader ) {
mProjectionMatrix_id = mCurShader->getUniformLocation( "dgl_ProjectionMatrix" );
mModelViewMatrix_id = mCurShader->getUniformLocation( "dgl_ModelViewMatrix" );
mTextureMatrix_id = mCurShader->getUniformLocation( "dgl_TextureMatrix" );
mTexActiveLoc = mCurShader->getUniformLocation( "dgl_TexActive" );
mClippingEnabledLoc = mCurShader->getUniformLocation( "dgl_ClippingEnabled" );
mCurActiveTex = 0;
@@ -524,6 +527,14 @@ void RendererGLES2::updateMatrix() {
mCurShader->setUniformMatrix( mModelViewMatrix_id, &mStack->mModelViewMatrix.top()[0][0] );
}
break;
}
case GL_TEXTURE:
{
if ( -1 != mTextureMatrix_id ) {
mCurShader->setUniformMatrix( mTextureMatrix_id, &mStack->mTextureMatrix.top()[0][0] );
}
break;
}
}
@@ -603,6 +614,12 @@ void RendererGLES2::getCurrentMatrix( unsigned int mode, float * m ) {
fromGLMmat4( mStack->mModelViewMatrix.top(), m );
break;
}
case GL_TEXTURE:
case GL_TEXTURE_MATRIX:
{
fromGLMmat4( mStack->mTextureMatrix.top(), m );
break;
}
}
}
@@ -626,6 +643,12 @@ void RendererGLES2::matrixMode(unsigned int mode) {
mStack->mCurMatrix = &mStack->mModelViewMatrix;
break;
}
case GL_TEXTURE:
case GL_TEXTURE_MATRIX:
{
mStack->mCurMatrix = &mStack->mTextureMatrix;
break;
}
}
}

View File

@@ -25,6 +25,7 @@ class MatrixStack
public:
std::stack<glm::mat4> mProjectionMatrix; // cpu-side
std::stack<glm::mat4> mModelViewMatrix; // cpu-side
std::stack<glm::mat4> mTextureMatrix; // cpu-side
std::stack<glm::mat4>* mCurMatrix;
};

View File

@@ -6,6 +6,7 @@
#endif
"uniform mat4 dgl_ProjectionMatrix;\n\
uniform mat4 dgl_ModelViewMatrix;\n\
uniform mat4 dgl_TextureMatrix;\n\
attribute vec4 dgl_Vertex;\n\
attribute vec4 dgl_FrontColor;\n\
attribute vec4 dgl_MultiTexCoord0;\n\
@@ -18,7 +19,7 @@ varying mediump vec4 dgl_TexCoord[ 1 ];\n\
void main(void)\n\
{\n\
dgl_Color = dgl_FrontColor;\n\
dgl_TexCoord[0] = dgl_MultiTexCoord0;\n\
dgl_TexCoord[0] = dgl_TextureMatrix * dgl_MultiTexCoord0;\n\
gl_Position = dgl_ProjectionMatrix * ( dgl_ModelViewMatrix * dgl_Vertex );\n\
}\n\
";

View File

@@ -7,6 +7,7 @@
"#define MAX_CLIP_PLANES 6\n\
uniform mat4 dgl_ProjectionMatrix;\n\
uniform mat4 dgl_ModelViewMatrix;\n\
uniform mat4 dgl_TextureMatrix;\n\
uniform int dgl_ClippingEnabled;\n\
uniform int dgl_ClipEnabled[ MAX_CLIP_PLANES ];\n\
uniform vec4 dgl_ClipPlane[ MAX_CLIP_PLANES ];\n\
@@ -21,7 +22,7 @@ void main(void)\n\
{\n\
gl_PointSize = dgl_PointSize;\n\
dgl_Color = dgl_FrontColor;\n\
dgl_TexCoord[0] = dgl_MultiTexCoord0;\n\
dgl_TexCoord[0] = dgl_TextureMatrix * dgl_MultiTexCoord0;\n\
vec4 vEye = dgl_ModelViewMatrix * dgl_Vertex;\n\
gl_Position = dgl_ProjectionMatrix * vEye;\n\
if ( 1 == dgl_ClippingEnabled ) {\n\

View File

@@ -7,6 +7,7 @@
"#define MAX_CLIP_PLANES 6\n\
uniform mat4 dgl_ProjectionMatrix;\n\
uniform mat4 dgl_ModelViewMatrix;\n\
uniform mat4 dgl_TextureMatrix;\n\
uniform int dgl_ClippingEnabled;\n\
uniform int dgl_ClipEnabled[ MAX_CLIP_PLANES ];\n\
uniform vec4 dgl_ClipPlane[ MAX_CLIP_PLANES ];\n\
@@ -21,7 +22,7 @@ void main(void)\n\
{\n\
gl_PointSize = dgl_PointSize;\n\
dgl_Color = dgl_FrontColor;\n\
dgl_TexCoord[0] = dgl_MultiTexCoord0;\n\
dgl_TexCoord[0] = dgl_TextureMatrix * dgl_MultiTexCoord0;\n\
vec4 vEye = dgl_ModelViewMatrix * dgl_Vertex;\n\
gl_Position = dgl_ProjectionMatrix * vEye;\n\
if ( 1 == dgl_ClippingEnabled ) {\n\

View File

@@ -7,6 +7,7 @@
"#define MAX_CLIP_PLANES 6\n\
uniform mat4 dgl_ProjectionMatrix;\n\
uniform mat4 dgl_ModelViewMatrix;\n\
uniform mat4 dgl_TextureMatrix;\n\
#ifndef GL_ES\n\
uniform int dgl_ClippingEnabled;\n\
uniform int dgl_ClipEnabled[ MAX_CLIP_PLANES ];\n\
@@ -28,7 +29,7 @@ varying float dgl_ClipDistance[ MAX_CLIP_PLANES ];\n\
void main(void)\n\
{\n\
dgl_Color = dgl_FrontColor;\n\
dgl_TexCoord[0] = dgl_MultiTexCoord0;\n\
dgl_TexCoord[0] = dgl_TextureMatrix * dgl_MultiTexCoord0;\n\
vec4 vEye = dgl_ModelViewMatrix * dgl_Vertex;\n\
gl_Position = dgl_ProjectionMatrix * vEye;\n\
if ( 1 == dgl_ClippingEnabled ) {\n\

View File

@@ -504,12 +504,10 @@ void Text::draw(const Float & X, const Float & Y, const Vector2f & Scale, const
return;
GlobalBatchRenderer::instance()->draw();
TextureFactory::instance()->bind( mFont->getTexture(mRealCharacterSize) );
TextureFactory::instance()->bind( mFont->getTexture(mRealCharacterSize), Texture::CoordinateType::Pixels );
BlendMode::setMode( Effect );
if ( mStyle & Shadow ) {
Uint32 f = mStyle;
mStyle &= ~Shadow;
Color Col = getFillColor();
@@ -529,7 +527,7 @@ void Text::draw(const Float & X, const Float & Y, const Vector2f & Scale, const
draw( X + pd, Y + pd, Scale, Rotation, Effect );
mStyle = f;
mStyle |= Shadow;
setFillColor( Col );
mColors.assign( mColors.size(), getFillColor() );
@@ -597,17 +595,10 @@ void Text::draw(const Float & X, const Float & Y, const Vector2f & Scale, const
void Text::ensureGeometryUpdate() {
cacheWidth();
Sizei textureSize = mFont->getTexture(mRealCharacterSize)->getPixelSize();
if ( textureSize != mTextureSize )
mGeometryNeedUpdate = true;
// Do nothing, if geometry has not changed
if (!mGeometryNeedUpdate)
return;
mTextureSize = textureSize;
// Mark geometry as updated
mGeometryNeedUpdate = false;
@@ -670,18 +661,18 @@ void Text::ensureGeometryUpdate() {
// If we're using the underlined style and there's a new line, draw a line
if (underlined && (curChar == L'\n')) {
addLine(mVertices, x, y, underlineOffset, underlineThickness, 0, textureSize, centerDiffX);
addLine(mVertices, x, y, underlineOffset, underlineThickness, 0, centerDiffX);
if (mOutlineThickness != 0)
addLine(mOutlineVertices, x, y, underlineOffset, underlineThickness, mOutlineThickness, textureSize, centerDiffX);
addLine(mOutlineVertices, x, y, underlineOffset, underlineThickness, mOutlineThickness, centerDiffX);
}
// If we're using the strike through style and there's a new line, draw a line across all characters
if (strikeThrough && (curChar == L'\n')) {
addLine(mVertices, x, y, strikeThroughOffset, underlineThickness, 0, textureSize, centerDiffX);
addLine(mVertices, x, y, strikeThroughOffset, underlineThickness, 0, centerDiffX);
if (mOutlineThickness != 0)
addLine(mOutlineVertices, x, y, strikeThroughOffset, underlineThickness, mOutlineThickness, textureSize, centerDiffX);
addLine(mOutlineVertices, x, y, strikeThroughOffset, underlineThickness, mOutlineThickness, centerDiffX);
}
if ( curChar == L'\n' ) {
@@ -729,7 +720,7 @@ void Text::ensureGeometryUpdate() {
Float bottom = glyph.bounds.Top + glyph.bounds.Bottom;
// Add the outline glyph to the vertices
addGlyphQuad(mOutlineVertices, Vector2f(x, y), glyph, italic, mOutlineThickness, textureSize, centerDiffX);
addGlyphQuad(mOutlineVertices, Vector2f(x, y), glyph, italic, mOutlineThickness, centerDiffX);
// Update the current bounds with the outlined glyph bounds
minX = std::min(minX, x + left - italic * bottom - mOutlineThickness);
@@ -742,7 +733,7 @@ void Text::ensureGeometryUpdate() {
const Glyph& glyph = mFont->getGlyph(curChar, mRealCharacterSize, bold);
// Add the glyph to the vertices
addGlyphQuad(mVertices, Vector2f(x, y), glyph, italic, 0, textureSize, centerDiffX);
addGlyphQuad(mVertices, Vector2f(x, y), glyph, italic, 0, centerDiffX);
// Update the current bounds with the non outlined glyph bounds
if (mOutlineThickness == 0) {
@@ -763,18 +754,18 @@ void Text::ensureGeometryUpdate() {
// If we're using the underlined style, add the last line
if (underlined && (x > 0)) {
addLine(mVertices, x, y, underlineOffset, underlineThickness, 0, textureSize, centerDiffX);
addLine(mVertices, x, y, underlineOffset, underlineThickness, 0, centerDiffX);
if (mOutlineThickness != 0)
addLine(mOutlineVertices, x, y, underlineOffset, underlineThickness, mOutlineThickness, textureSize, centerDiffX);
addLine(mOutlineVertices, x, y, underlineOffset, underlineThickness, mOutlineThickness, centerDiffX);
}
// If we're using the strike through style, add the last line across all characters
if (strikeThrough && (x > 0)) {
addLine(mVertices, x, y, strikeThroughOffset, underlineThickness, 0, textureSize, centerDiffX);
addLine(mVertices, x, y, strikeThroughOffset, underlineThickness, 0, centerDiffX);
if (mOutlineThickness != 0)
addLine(mOutlineVertices, x, y, strikeThroughOffset, underlineThickness, mOutlineThickness, textureSize, centerDiffX);
addLine(mOutlineVertices, x, y, strikeThroughOffset, underlineThickness, mOutlineThickness, centerDiffX);
}
// Update the bounding rectangle
@@ -782,9 +773,6 @@ void Text::ensureGeometryUpdate() {
mBounds.Top = minY;
mBounds.Right = maxX - minX;
mBounds.Bottom = maxY - minY;
if ( mFont->getTexture(mRealCharacterSize)->getPixelSize() != mTextureSize )
ensureGeometryUpdate();
}
void Text::ensureColorUpdate() {
@@ -951,13 +939,13 @@ void Text::setFillColor( const Color& color, Uint32 from, Uint32 to ) {
}
// Add an underline or strikethrough line to the vertex array
void Text::addLine(std::vector<VertexCoords>& vertices, Float lineLength, Float lineTop, Float offset, Float thickness, Float outlineThickness, Sizei textureSize, Int32 centerDiffX) {
void Text::addLine(std::vector<VertexCoords>& vertices, Float lineLength, Float lineTop, Float offset, Float thickness, Float outlineThickness, Int32 centerDiffX) {
Float top = std::floor(lineTop + offset - (thickness / 2) + 0.5f);
Float bottom = top + std::floor(thickness + 0.5f);
Float u1 = 0;
Float v1 = 0;
Float u2 = 1 / (Float)textureSize.getWidth();
Float v2 = 1 / (Float)textureSize.getHeight();
Float u2 = 1;
Float v2 = 1;
VertexCoords vc;
if ( GLi->quadsSupported() ) {
@@ -1024,16 +1012,16 @@ void Text::addLine(std::vector<VertexCoords>& vertices, Float lineLength, Float
}
// Add a glyph quad to the vertex array
void Text::addGlyphQuad(std::vector<VertexCoords>& vertices, Vector2f position, const EE::Graphics::Glyph& glyph, Float italic, Float outlineThickness, Sizei textureSize, Int32 centerDiffX) {
void Text::addGlyphQuad(std::vector<VertexCoords>& vertices, Vector2f position, const EE::Graphics::Glyph& glyph, Float italic, Float outlineThickness, Int32 centerDiffX) {
Float left = glyph.bounds.Left;
Float top = glyph.bounds.Top;
Float right = glyph.bounds.Left + glyph.bounds.Right;
Float bottom = glyph.bounds.Top + glyph.bounds.Bottom;
Float u1 = static_cast<Float>(glyph.textureRect.Left) / (Float)textureSize.getWidth();
Float v1 = static_cast<Float>(glyph.textureRect.Top) / (Float)textureSize.getHeight();
Float u2 = static_cast<Float>(glyph.textureRect.Left + glyph.textureRect.Right) / (Float)textureSize.getWidth();
Float v2 = static_cast<Float>(glyph.textureRect.Top + glyph.textureRect.Bottom) / (Float)textureSize.getHeight();
Float u1 = static_cast<Float>(glyph.textureRect.Left);
Float v1 = static_cast<Float>(glyph.textureRect.Top);
Float u2 = static_cast<Float>(glyph.textureRect.Left + glyph.textureRect.Right);
Float v2 = static_cast<Float>(glyph.textureRect.Top + glyph.textureRect.Bottom);
VertexCoords vc;
if ( GLi->quadsSupported() ) {

View File

@@ -35,8 +35,8 @@ Texture::Texture() :
mImgWidth(0),
mImgHeight(0),
mFlags(0),
mClampMode( CLAMP_TO_EDGE ),
mFilter( TEXTURE_FILTER_LINEAR )
mClampMode( ClampToEdge ),
mFilter( Linear )
{
if ( NULL == sBR ) {
sBR = GlobalBatchRenderer::instance();
@@ -102,7 +102,7 @@ void Texture::create( const Uint32& texture, const unsigned int& width, const un
mImgHeight = imgheight;
mSize = MemSize;
mClampMode = ClampMode;
mFilter = TEXTURE_FILTER_LINEAR;
mFilter = Linear;
if ( UseMipmap )
mFlags |= TEX_FLAG_MIPMAP;
@@ -206,7 +206,7 @@ bool Texture::unlock( const bool& KeepData, const bool& Modified ) {
TextureSaver saver( mTexture );
Uint32 flags = ( mFlags & TEX_FLAG_MIPMAP ) ? SOIL_FLAG_MIPMAPS : 0;
flags = (mClampMode == CLAMP_REPEAT) ? (flags | SOIL_FLAG_TEXTURE_REPEATS) : flags;
flags = (mClampMode == ClampRepeat) ? (flags | SOIL_FLAG_TEXTURE_REPEATS) : flags;
NTexId = SOIL_create_OGL_texture( reinterpret_cast<Uint8*>(&mPixels[0]), &width, &height, mChannels, mTexture, flags );
@@ -248,8 +248,8 @@ void Texture::setPixel( const unsigned int& x, const unsigned int& y, const Colo
mFlags |= TEX_FLAG_MODIFIED;
}
void Texture::bind() {
TextureFactory::instance()->bind( this );
void Texture::bind( CoordinateType coordinateType , const Uint32& textureUnit ) {
TextureFactory::instance()->bind( this, coordinateType, textureUnit );
}
bool Texture::saveToFile(const std::string& filepath, const SaveType & Format ) {
@@ -278,12 +278,12 @@ void Texture::iTextureFilter( const TextureFilter& filter ) {
TextureSaver saver( mTexture );
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, (mFilter == TEXTURE_FILTER_LINEAR) ? GL_LINEAR : GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, (mFilter == Linear) ? GL_LINEAR : GL_NEAREST);
if ( mFlags & TEX_FLAG_MIPMAP )
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, (mFilter == TEXTURE_FILTER_LINEAR) ? GL_LINEAR_MIPMAP_LINEAR : GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, (mFilter == Linear) ? GL_LINEAR_MIPMAP_LINEAR : GL_NEAREST);
else
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, (mFilter == TEXTURE_FILTER_LINEAR) ? GL_LINEAR : GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, (mFilter == Linear) ? GL_LINEAR : GL_NEAREST);
}
}
@@ -365,7 +365,7 @@ void Texture::applyClampMode() {
if (mTexture) {
TextureSaver saver( mTexture );
if( mClampMode == CLAMP_REPEAT ) {
if( mClampMode == ClampRepeat ) {
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
} else {
@@ -392,7 +392,7 @@ void Texture::reload() {
TextureSaver saver( mTexture );
Uint32 flags = ( mFlags & TEX_FLAG_MIPMAP ) ? SOIL_FLAG_MIPMAPS : 0;
flags = (mClampMode == CLAMP_REPEAT) ? (flags | SOIL_FLAG_TEXTURE_REPEATS) : flags;
flags = (mClampMode == ClampRepeat) ? (flags | SOIL_FLAG_TEXTURE_REPEATS) : flags;
if ( ( mFlags & TEX_FLAG_COMPRESSED ) ) {
if ( isGrabed() )
@@ -464,7 +464,7 @@ void Texture::update( Image *image, Uint32 x, Uint32 y ) {
void Texture::replace( Image * image ) {
Uint32 flags = ( mFlags & TEX_FLAG_MIPMAP ) ? SOIL_FLAG_MIPMAPS : 0;
flags = (mClampMode == CLAMP_REPEAT) ? (flags | SOIL_FLAG_TEXTURE_REPEATS) : flags;
flags = (mClampMode == ClampRepeat) ? (flags | SOIL_FLAG_TEXTURE_REPEATS) : flags;
TextureSaver textureSaver;
@@ -536,7 +536,7 @@ void Texture::drawFast( const Float& x, const Float& y, const Float& Angle, cons
sBR->quadsBegin();
sBR->quadsSetColor( Color );
if ( getClampMode() == CLAMP_REPEAT ) {
if ( getClampMode() == ClampRepeat ) {
Float iw = (Float)getImageWidth();
Float ih = (Float)getImageHeight();
sBR->quadsSetTexCoordFree( 0, 0, 0, height / ih, width / iw, height / ih, width / iw, 0 );
@@ -574,7 +574,7 @@ void Texture::drawEx( Float x, Float y, Float width, Float height, const Float &
sBR->quadsSetColorFree( Color0, Color1, Color2, Color3 );
if ( Effect <= RENDER_FLIPPED_MIRRORED ) {
if ( getClampMode() == CLAMP_REPEAT ) {
if ( getClampMode() == ClampRepeat ) {
if ( Effect == RENDER_NORMAL ) {
if ( renderSector ) {
sBR->quadsSetTexCoordFree( Sector.Left / w, Sector.Top / h, Sector.Left / w, Sector.Bottom / h, Sector.Right / w, Sector.Bottom / h, Sector.Right / w, Sector.Top / h );
@@ -744,7 +744,7 @@ void Texture::drawQuadEx( Quad2f Q, const Vector2f& Offset, const Float &Angle,
Q.scale( Scale, QCenter );
}
if ( getClampMode() == CLAMP_REPEAT ) {
if ( getClampMode() == ClampRepeat ) {
sBR->quadsSetTexCoordFree( 0, 0, 0, ( Q.V[0].y - Q.V[0].y ) / h, ( Q.V[0].x - Q.V[0].x ) / w, ( Q.V[0].y - Q.V[0].y ) / h, ( Q.V[0].x - Q.V[0].x ) / w, 0 );
} else if ( renderSector ) {
sBR->quadsSetTexCoordFree( texSector.Left / w, texSector.Top / h, texSector.Left / w, texSector.Bottom / h, texSector.Right / w, texSector.Bottom / h, texSector.Right / w, texSector.Top / h );

View File

@@ -15,6 +15,7 @@ SINGLETON_DECLARE_IMPLEMENTATION(TextureFactory)
TextureFactory::TextureFactory() :
mLastBlend(BlendAlpha),
mMemSize(0),
mLastCoordinateType( Texture::CoordinateType::Normalized ),
mErasing(false)
{
mTextures.clear();
@@ -23,6 +24,10 @@ TextureFactory::TextureFactory() :
memset( &mCurrentTexture[0], 0, EE_MAX_TEXTURE_UNITS );
}
const Texture::CoordinateType & TextureFactory::getLastCoordinateType() const {
return mLastCoordinateType;
}
TextureFactory::~TextureFactory() {
unloadTextures();
}
@@ -104,22 +109,51 @@ Uint32 TextureFactory::findFreeSlot() {
return (Uint32)mTextures.size() - 1;
}
void TextureFactory::bind( const Texture* Tex, const Uint32& TextureUnit ) {
if( NULL != Tex && mCurrentTexture[ TextureUnit ] != (Int32)Tex->getHandle() ) {
void TextureFactory::bind( const Texture* texture, Texture::CoordinateType coordinateType, const Uint32& TextureUnit ) {
if( NULL != texture ) {
if ( mCurrentTexture[ TextureUnit ] == (Int32)texture->getHandle() )
return;
if ( TextureUnit && GLi->isExtension( EEGL_ARB_multitexture ) )
setActiveTextureUnit( TextureUnit );
GLi->bindTexture( GL_TEXTURE_2D, Tex->getHandle() );
GLi->bindTexture( GL_TEXTURE_2D, texture->getHandle() );
mCurrentTexture[ TextureUnit ] = Tex->getHandle();
mCurrentTexture[ TextureUnit ] = texture->getHandle();
if ( TextureUnit && GLi->isExtension( EEGL_ARB_multitexture ) )
setActiveTextureUnit( 0 );
if ( coordinateType == Texture::CoordinateType::Pixels ) {
GLfloat matrix[16] = {1.f, 0.f, 0.f, 0.f,
0.f, 1.f, 0.f, 0.f,
0.f, 0.f, 1.f, 0.f,
0.f, 0.f, 0.f, 1.f};
matrix[0] = 1.f / const_cast<Texture*>( texture )->getPixelSize().x;
matrix[5] = 1.f / const_cast<Texture*>( texture )->getPixelSize().y;
GLi->matrixMode(GL_TEXTURE);
GLi->loadMatrixf(matrix);
GLi->matrixMode(GL_MODELVIEW);
mLastCoordinateType = coordinateType;
return;
}
}
if ( Texture::CoordinateType::Normalized != mLastCoordinateType ) {
mLastCoordinateType = coordinateType;
GLi->matrixMode(GL_TEXTURE);
GLi->loadIdentity();
GLi->matrixMode(GL_MODELVIEW);
}
}
void TextureFactory::bind( const Uint32& TexId, const Uint32& TextureUnit ) {
bind( getTexture( TexId ), TextureUnit );
void TextureFactory::bind( const Uint32& TexId, Texture::CoordinateType coordinateType, const Uint32& textureUnit ) {
bind( getTexture( TexId ), coordinateType, textureUnit );
}
void TextureFactory::unloadTextures() {

View File

@@ -423,7 +423,7 @@ void TextureLoader::loadFromPixels() {
Uint32 flags = mMipmap ? SOIL_FLAG_MIPMAPS | SOIL_FLAG_GL_MIPMAPS : 0;
flags = ( mClampMode == Texture::ClampMode::CLAMP_REPEAT) ? (flags | SOIL_FLAG_TEXTURE_REPEATS) : flags;
flags = ( mClampMode == Texture::ClampMode::ClampRepeat) ? (flags | SOIL_FLAG_TEXTURE_REPEATS) : flags;
flags = ( mCompressTexture ) ? ( flags | SOIL_FLAG_COMPRESS_TO_DXT ) : flags;
bool ForceGLThreaded = Thread::getCurrentThreadId() != Engine::instance()->getMainThreadId();

View File

@@ -147,7 +147,7 @@ void TileMap::createEmptyTile() {
Img.getHeight(),
Img.getChannels(),
true,
Texture::ClampMode::CLAMP_TO_EDGE,
Texture::ClampMode::ClampToEdge,
false,
false,
tileName

View File

@@ -53,7 +53,7 @@ UITheme * UITheme::loadFromTextureAtlas( UITheme * tTheme, Graphics::TextureAtla
/** Themes use nearest filter by default, force the filter to the textures. */
for ( Uint32 tC = 0; tC < TextureAtlas->getTexturesCount(); tC++ ) {
TextureAtlas->getTexture( tC )->setFilter( Texture::TextureFilter::TEXTURE_FILTER_NEAREST );
TextureAtlas->getTexture( tC )->setFilter( Texture::TextureFilter::Nearest );
}
Clock TE;

View File

@@ -371,7 +371,7 @@ void EETest::createUI() {
Uint32 UI_MAN_OPS = 0;
if ( mDebugUI )
UI_MAN_OPS = UI_MANAGER_HIGHLIGHT_FOCUS | UI_MANAGER_HIGHLIGHT_OVER | UI_MANAGER_DRAW_DEBUG_DATA | UI_MANAGER_DRAW_BOXES | UI_MANAGER_HIGHLIGHT_INVALIDATION;
UIManager::instance()->init(UI_MAN_OPS | UI_MANAGER_USE_DRAW_INVALIDATION | UI_MANAGER_MAIN_CONTROL_IN_FRAME_BUFFER);
UIManager::instance()->init(UI_MAN_OPS | UI_MANAGER_USE_DRAW_INVALIDATION /*| UI_MANAGER_MAIN_CONTROL_IN_FRAME_BUFFER*/);
UIManager::instance()->setTranslator( mTranslator );
//mTheme = UITheme::loadFromDirectory( UIThemeDefault::New( mThemeName, mThemeName ), MyPath + "ui/" + mThemeName + "/" );
@@ -1214,7 +1214,7 @@ void EETest::loadTextures() {
TNP.resize(12);
for ( i = 0; i <= 6; i++ ) {
TN[i] = TF->loadFromFile( MyPath + "sprites/" + String::toStr(i+1) + ".png", (i+1) == 7 ? true : false, ( (i+1) == 4 ) ? Texture::ClampMode::CLAMP_REPEAT : Texture::ClampMode::CLAMP_TO_EDGE );
TN[i] = TF->loadFromFile( MyPath + "sprites/" + String::toStr(i+1) + ".png", (i+1) == 7 ? true : false, ( (i+1) == 4 ) ? Texture::ClampMode::ClampRepeat : Texture::ClampMode::ClampToEdge );
TNP[i] = TF->getTexture( TN[i] );
}