mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-21 16:12:40 +08:00
Merge pull request #288 from knoxHuang/v1.2
add enableAntiAlias for Native for fireball/issues/2836
This commit is contained in:
@@ -101,6 +101,7 @@ GLContextAttrs GLView::getGLContextAttrs()
|
||||
GLView::GLView()
|
||||
: _scaleX(1.0f)
|
||||
, _scaleY(1.0f)
|
||||
, _antiAliasEnabled(true)
|
||||
, _resolutionPolicy(ResolutionPolicy::UNKNOWN)
|
||||
{
|
||||
}
|
||||
@@ -457,5 +458,31 @@ float GLView::getScaleY() const
|
||||
return _scaleY;
|
||||
}
|
||||
|
||||
bool GLView::isAntiAliasEnabled() const
|
||||
{
|
||||
return _antiAliasEnabled;
|
||||
}
|
||||
|
||||
void GLView::enableAntiAlias(bool enabled)
|
||||
{
|
||||
if (_antiAliasEnabled == enabled) {
|
||||
return;
|
||||
}
|
||||
_antiAliasEnabled = enabled;
|
||||
|
||||
cocos2d::Vector<Texture2D*> list = Director::getInstance()->getTextureCache()->getAllTextures();
|
||||
for (size_t i = 0; i < list.size(); i++) {
|
||||
Texture2D* tex = list.at(i);
|
||||
if (tex) {
|
||||
if (enabled) {
|
||||
tex->setAntiAliasTexParameters();
|
||||
}
|
||||
else {
|
||||
tex->setAliasTexParameters();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
|
||||
|
||||
@@ -371,6 +371,19 @@ public:
|
||||
*/
|
||||
ResolutionPolicy getResolutionPolicy() const { return _resolutionPolicy; }
|
||||
|
||||
/** Returns whether the current enable on anti-alias.
|
||||
*
|
||||
* @return The antiAlias enabled.
|
||||
*/
|
||||
bool isAntiAliasEnabled() const;
|
||||
|
||||
/** Whether to Enable on anti-alias.
|
||||
*
|
||||
* @param enabled The Enable or not anti-alias.
|
||||
*/
|
||||
void enableAntiAlias(bool enabled);
|
||||
|
||||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
||||
virtual HWND getWin32Window() = 0;
|
||||
#endif /* (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) */
|
||||
@@ -392,6 +405,8 @@ protected:
|
||||
Rect _viewPortRect;
|
||||
// the view name
|
||||
std::string _viewName;
|
||||
// anti alias state
|
||||
bool _antiAliasEnabled;
|
||||
|
||||
float _scaleX;
|
||||
float _scaleY;
|
||||
|
||||
@@ -446,6 +446,7 @@ Texture2D::Texture2D()
|
||||
, _ninePatchInfo(nullptr)
|
||||
{
|
||||
s_allGLTexture2D.insert(this);
|
||||
_antialiasEnabled = Director::getInstance()->getOpenGLView()->isAntiAliasEnabled();
|
||||
}
|
||||
|
||||
Texture2D::~Texture2D()
|
||||
|
||||
@@ -456,6 +456,15 @@ bool TextureCache::reloadTexture(const std::string& fileName)
|
||||
return ret;
|
||||
}
|
||||
|
||||
cocos2d::Vector<Texture2D*> TextureCache::getAllTextures() const
|
||||
{
|
||||
cocos2d::Vector<Texture2D*> result;
|
||||
for( auto it=_textures.begin(); it!=_textures.end(); ++it ) {
|
||||
result.pushBack(it->second);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// TextureCache - Remove
|
||||
|
||||
void TextureCache::removeAllTextures()
|
||||
|
||||
@@ -38,6 +38,7 @@ THE SOFTWARE.
|
||||
#include <functional>
|
||||
|
||||
#include "base/CCRef.h"
|
||||
#include "base/CCVector.h"
|
||||
#include "renderer/CCTexture2D.h"
|
||||
#include "platform/CCImage.h"
|
||||
|
||||
@@ -151,6 +152,13 @@ public:
|
||||
*/
|
||||
bool reloadTexture(const std::string& fileName);
|
||||
|
||||
/**
|
||||
* get all textures.
|
||||
*
|
||||
* @return all textures.
|
||||
*/
|
||||
cocos2d::Vector<Texture2D*> getAllTextures() const;
|
||||
|
||||
/** Purges the dictionary of loaded textures.
|
||||
* Call this method if you receive the "Memory Warning".
|
||||
* In the short term: it will free some resources preventing your app from being killed.
|
||||
|
||||
Reference in New Issue
Block a user