mirror of https://github.com/axmolengine/axmol.git
added support for precompiled shaders in wp8
This commit is contained in:
parent
5e402ee433
commit
fb574697aa
|
@ -37,6 +37,10 @@ THE SOFTWARE.
|
||||||
#include "kazmath/GL/matrix.h"
|
#include "kazmath/GL/matrix.h"
|
||||||
#include "kazmath/kazmath.h"
|
#include "kazmath/kazmath.h"
|
||||||
|
|
||||||
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
|
||||||
|
#include "CCPrecompiledShaders.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
typedef struct _hashUniformEntry
|
typedef struct _hashUniformEntry
|
||||||
|
@ -116,6 +120,18 @@ GLProgram::~GLProgram()
|
||||||
|
|
||||||
bool GLProgram::initWithByteArrays(const GLchar* vShaderByteArray, const GLchar* fShaderByteArray)
|
bool GLProgram::initWithByteArrays(const GLchar* vShaderByteArray, const GLchar* fShaderByteArray)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
|
||||||
|
GLboolean hasCompiler = false;
|
||||||
|
glGetBooleanv(GL_SHADER_COMPILER, &hasCompiler);
|
||||||
|
_hasShaderCompiler = (hasCompiler == GL_TRUE);
|
||||||
|
|
||||||
|
if(!_hasShaderCompiler)
|
||||||
|
{
|
||||||
|
return initWithPrecompiledProgramByteArray(vShaderByteArray,fShaderByteArray);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
_program = glCreateProgram();
|
_program = glCreateProgram();
|
||||||
CHECK_GL_ERROR_DEBUG();
|
CHECK_GL_ERROR_DEBUG();
|
||||||
|
|
||||||
|
@ -126,7 +142,8 @@ bool GLProgram::initWithByteArrays(const GLchar* vShaderByteArray, const GLchar*
|
||||||
if (!compileShader(&_vertShader, GL_VERTEX_SHADER, vShaderByteArray))
|
if (!compileShader(&_vertShader, GL_VERTEX_SHADER, vShaderByteArray))
|
||||||
{
|
{
|
||||||
CCLOG("cocos2d: ERROR: Failed to compile vertex shader");
|
CCLOG("cocos2d: ERROR: Failed to compile vertex shader");
|
||||||
}
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create and compile fragment shader
|
// Create and compile fragment shader
|
||||||
|
@ -135,6 +152,7 @@ bool GLProgram::initWithByteArrays(const GLchar* vShaderByteArray, const GLchar*
|
||||||
if (!compileShader(&_fragShader, GL_FRAGMENT_SHADER, fShaderByteArray))
|
if (!compileShader(&_fragShader, GL_FRAGMENT_SHADER, fShaderByteArray))
|
||||||
{
|
{
|
||||||
CCLOG("cocos2d: ERROR: Failed to compile fragment shader");
|
CCLOG("cocos2d: ERROR: Failed to compile fragment shader");
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,9 +170,34 @@ bool GLProgram::initWithByteArrays(const GLchar* vShaderByteArray, const GLchar*
|
||||||
|
|
||||||
CHECK_GL_ERROR_DEBUG();
|
CHECK_GL_ERROR_DEBUG();
|
||||||
|
|
||||||
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
|
||||||
|
_shaderId = CCPrecompiledShaders::getInstance()->addShaders(vShaderByteArray, fShaderByteArray);
|
||||||
|
#endif
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
|
||||||
|
bool GLProgram::initWithPrecompiledProgramByteArray(const GLchar* vShaderByteArray, const GLchar* fShaderByteArray)
|
||||||
|
{
|
||||||
|
bool haveProgram = false;
|
||||||
|
|
||||||
|
_program = glCreateProgram();
|
||||||
|
CHECK_GL_ERROR_DEBUG();
|
||||||
|
|
||||||
|
_vertShader = _fragShader = 0;
|
||||||
|
|
||||||
|
haveProgram = CCPrecompiledShaders::getInstance()->loadProgram(_program, vShaderByteArray, fShaderByteArray);
|
||||||
|
|
||||||
|
CHECK_GL_ERROR_DEBUG();
|
||||||
|
_hashForUniforms = NULL;
|
||||||
|
|
||||||
|
CHECK_GL_ERROR_DEBUG();
|
||||||
|
|
||||||
|
return haveProgram;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
bool GLProgram::initWithFilenames(const std::string &vShaderFilename, const std::string &fShaderFilename)
|
bool GLProgram::initWithFilenames(const std::string &vShaderFilename, const std::string &fShaderFilename)
|
||||||
{
|
{
|
||||||
auto fileUtils = FileUtils::getInstance();
|
auto fileUtils = FileUtils::getInstance();
|
||||||
|
@ -275,6 +318,15 @@ bool GLProgram::link()
|
||||||
{
|
{
|
||||||
CCASSERT(_program != 0, "Cannot link invalid program");
|
CCASSERT(_program != 0, "Cannot link invalid program");
|
||||||
|
|
||||||
|
|
||||||
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
|
||||||
|
if(!_hasShaderCompiler)
|
||||||
|
{
|
||||||
|
// precompiled shader program is already linked
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
GLint status = GL_TRUE;
|
GLint status = GL_TRUE;
|
||||||
|
|
||||||
glLinkProgram(_program);
|
glLinkProgram(_program);
|
||||||
|
@ -291,7 +343,7 @@ bool GLProgram::link()
|
||||||
|
|
||||||
_vertShader = _fragShader = 0;
|
_vertShader = _fragShader = 0;
|
||||||
|
|
||||||
#if COCOS2D_DEBUG
|
#if DEBUG || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
|
||||||
glGetProgramiv(_program, GL_LINK_STATUS, &status);
|
glGetProgramiv(_program, GL_LINK_STATUS, &status);
|
||||||
|
|
||||||
if (status == GL_FALSE)
|
if (status == GL_FALSE)
|
||||||
|
@ -301,7 +353,14 @@ bool GLProgram::link()
|
||||||
_program = 0;
|
_program = 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
|
||||||
|
if (status == GL_TRUE)
|
||||||
|
{
|
||||||
|
CCPrecompiledShaders::getInstance()->addProgram(_program, _shaderId);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return (status == GL_TRUE);
|
return (status == GL_TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -126,7 +126,18 @@ public:
|
||||||
* @js initWithString
|
* @js initWithString
|
||||||
* @lua initWithString
|
* @lua initWithString
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
|
||||||
|
/** Initializes the CCGLProgram with precompiled shader program */
|
||||||
|
bool initWithPrecompiledProgramByteArray(const GLchar* vShaderByteArray, const GLchar* fShaderByteArray);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/** Initializes the GLProgram with a vertex and fragment with bytes array
|
||||||
|
* @js initWithString
|
||||||
|
* @lua initWithString
|
||||||
|
*/
|
||||||
bool initWithByteArrays(const GLchar* vShaderByteArray, const GLchar* fShaderByteArray);
|
bool initWithByteArrays(const GLchar* vShaderByteArray, const GLchar* fShaderByteArray);
|
||||||
|
|
||||||
/** Initializes the GLProgram with a vertex and fragment with contents of filenames
|
/** Initializes the GLProgram with a vertex and fragment with contents of filenames
|
||||||
* @js init
|
* @js init
|
||||||
* @lua init
|
* @lua init
|
||||||
|
@ -266,6 +277,10 @@ private:
|
||||||
GLuint _fragShader;
|
GLuint _fragShader;
|
||||||
GLint _uniforms[UNIFORM_MAX];
|
GLint _uniforms[UNIFORM_MAX];
|
||||||
struct _hashUniformEntry* _hashForUniforms;
|
struct _hashUniformEntry* _hashForUniforms;
|
||||||
|
bool _hasShaderCompiler;
|
||||||
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
|
||||||
|
std::string _shaderId;
|
||||||
|
#endif
|
||||||
|
|
||||||
struct flag_struct {
|
struct flag_struct {
|
||||||
unsigned int usesTime:1;
|
unsigned int usesTime:1;
|
||||||
|
|
Loading…
Reference in New Issue