コード例 #1
0
void CCShaders::setFlash(float r, float g, float b, float t) {
	loadCustomShader(kCCShader_flash);
    CCGLProgram* p = CCShaderCache::sharedShaderCache()->programForKey(kCCShader_flash);
    p->use();
    p->setUniformLocationWith3f(sUniform_pos_CC_flashColor, r, g, b);
    p->setUniformLocationWith1f(sUniform_pos_CC_flashTime, t);
}
コード例 #2
0
void CCShaders::setBlur(CCSize nodeSize, CCSize blurSize, ccColor4F blurSubtract) {
	loadCustomShader(kCCShader_blur);
    CCGLProgram* p = CCShaderCache::sharedShaderCache()->programForKey(kCCShader_blur);
    p->use();
	p->setUniformLocationWith2f(sUniform_pos_CC_blurSize, blurSize.width / nodeSize.width, blurSize.height / nodeSize.height);
	p->setUniformLocationWith4f(sUniform_pos_CC_blurSubtract, blurSubtract.r, blurSubtract.g, blurSubtract.b, blurSubtract.a);
}
コード例 #3
0
bool FragmentEffect::setEffect(CCNode* pNode,unsigned int sel)
{
	if(sel<0 || sel>=m_matrices.size())
		return false;

	std::vector<EffectListNode>::iterator i   = m_nodeList.begin();
	std::vector<EffectListNode>::iterator end = m_nodeList.end();

	while (i != end)
	{
		if(i->_pNode == pNode)
		{
			CCGLProgram* program = i->_pNode->getShaderProgram();

			program->use();
			program->setUniformLocationWithMatrix4fv(i->_uniformMatrix,
													 m_matrices[sel]._matrix,
													 1);

			i->_effectSelect = sel;

			return true;
		}

		i++;
	}

	return false;
}
コード例 #4
0
CCGLProgram * GAFStencilMaskSprite::programShaderForMask()
{
	CCGLProgram *program = CCShaderCache::sharedShaderCache()->programForKey(kPCStencilMaskAlphaFilterProgramCacheKey);
	
    if (!program)
    {
        program = GAFShaderManager::createWithFragmentFilename(ccPositionTextureColor_vert, kPCStencilMaskAlphaFilterFragmentShaderFilename);
        if (program)
        {
			program->addAttribute(kCCAttributeNamePosition, kCCVertexAttrib_Position);
			program->addAttribute(kCCAttributeNameColor,    kCCVertexAttrib_Color);
			program->addAttribute(kCCAttributeNameTexCoord, kCCVertexAttrib_TexCoords);
            program->link();
			program->updateUniforms();
            CHECK_GL_ERROR_DEBUG();
			CCShaderCache::sharedShaderCache()->addProgram(program, kPCStencilMaskAlphaFilterProgramCacheKey);
            program->release();
        }
        else
        {
            CCLOGERROR("Cannot load program for programShaderForMask.");
            return NULL;
        }
    }
	
    program->use();
	return program;
}
コード例 #5
0
ファイル: tolua_CCGLProgram.cpp プロジェクト: imuzi/MyApp
static int tolua_CCGLProgram_CCGLProgram_use00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
 tolua_Error tolua_err;
 if (
     !tolua_isusertype(tolua_S,1,"CCGLProgram",0,&tolua_err) ||
     !tolua_isnoobj(tolua_S,2,&tolua_err)
 )
  goto tolua_lerror;
 else
#endif
 {
  CCGLProgram* self = (CCGLProgram*)  tolua_tousertype(tolua_S,1,0);
#ifndef TOLUA_RELEASE
  if (!self) tolua_error(tolua_S,"invalid 'self' in function 'use'", NULL);
#endif
  {
   self->use();
  }
 }
 return 0;
#ifndef TOLUA_RELEASE
 tolua_lerror:
 tolua_error(tolua_S,"#ferror in function 'use'.",&tolua_err);
 return 0;
#endif
}
コード例 #6
0
ファイル: XSpriteBatchNode.cpp プロジェクト: SLS-ACT/TeamTest
void XSpriteBatchNode::draw()
{
	XFUNC_START();
	CC_PROFILER_START("XSpriteBatchNode - draw");

	if (m_pobTextureAtlas->getTotalQuads() == 0)
	{
		return;
	}
	do 
	{
		ccGLEnable(m_eGLServerState);
		if (m_pShaderKTX)
		{
			CCGLProgram* pProg = m_pShaderKTX->GetProgram();
			if (pProg)
			{
				pProg->use();
				pProg->setUniformsForBuiltins();
			}
		}
		else
		{
			if (getShaderProgram())
			{
				getShaderProgram()->use();
				getShaderProgram()->setUniformsForBuiltins();
			}			
		}
		if(m_pShaderOnce)
		{
			m_pShaderOnce->use();
			m_pShaderOnce->setUniformsForBuiltins();
			if(m_pShaderOnce->m_pShader)
				m_pShaderOnce->m_pShader->RunBeforeDraw();
			m_pShaderOnce = NULL;
		}
		//else if(m_pobTextureAtlas->getTexture())
		//{
		//	static XShaderBloom stShaderBloom;
		//	stShaderBloom.UseShader();
		//	stShaderBloom.SetTexSize(SCRPIX_W, SCRPIX_H);
		//}
	} while (0);
	arrayMakeObjectsPerformSelector(m_pChildren, updateTransform, CCSprite*);
	ccGLBlendFunc(m_blendFunc.src, m_blendFunc.dst);
	if (m_pTexKtxAlpha)
	{
		ccGLBindTexture2DN(1, m_pTexKtxAlpha->getName());
		if (m_pShaderKTX)
		{
			m_pShaderKTX->RunBeforeDraw();
		}	
	}
	m_pobTextureAtlas->drawQuads();
	CC_PROFILER_STOP("XSpriteBatchNode - draw");
	
	XFUNC_END();
}
コード例 #7
0
	void Cocos2dRenderManager::doRender(IVertexBuffer* _buffer, ITexture* _texture, size_t _count)
	{
		Cocos2dVertexBuffer* buffer = static_cast<Cocos2dVertexBuffer*>(_buffer);
		unsigned int buffer_id = buffer->getBufferID();

		unsigned int texture_id = 0;
		Cocos2dTexture* texture = static_cast<Cocos2dTexture*>(_texture);
		texture_id = texture->getGLTexture();

		//MYGUI_PLATFORM_ASSERT(buffer_id, "Texture is not created");
		//MYGUI_PLATFORM_ASSERT(texture_id, "Texture is not created");
		if (!buffer_id) return;
		if (!texture_id) return;

		ccGLEnable(m_eGLServerState);

		CCGLProgram* shaderProgram = NULL;
		cocos2d::ccBlendFunc blendFunc;

		shaderProgram = CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionTextureColor_MyGUI);
		// 对于
		if (texture->getCocos2dTexture()->hasPremultipliedAlpha())
		{
			blendFunc.src = CC_BLEND_SRC;
			blendFunc.dst = CC_BLEND_DST;
		}
		else
		{
			blendFunc.src = GL_SRC_ALPHA;
			blendFunc.dst = GL_ONE_MINUS_SRC_ALPHA;
		}

		shaderProgram->use();
		shaderProgram->setUniformsForBuiltins();
		ccGLBlendFunc(blendFunc.src, blendFunc.dst);

		ccGLEnableVertexAttribs( kCCVertexAttribFlag_PosColorTex );

		ccGLBindTexture2D(texture_id);
		glBindBuffer(GL_ARRAY_BUFFER, buffer_id);

		glVertexAttribPointer(kCCVertexAttrib_Position, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex, x));
		glVertexAttribPointer(kCCVertexAttrib_Color, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(Vertex), (void*)offsetof(Vertex, colour));
		glVertexAttribPointer(kCCVertexAttrib_TexCoords, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex, u));

		glDrawArrays(GL_TRIANGLES, 0, _count);

		vbo_count++;
		vertex_count += _count;

		glBindBuffer(GL_ARRAY_BUFFER, 0);
	}
コード例 #8
0
bool FragmentEffect::setEffect(unsigned int nodeIndex,unsigned int sel)
{
	if(nodeIndex<0 || nodeIndex>=m_nodeList.size() || sel<0 || sel>=m_matrices.size())
		return false;

	CCGLProgram* program = m_nodeList[nodeIndex]._pNode->getShaderProgram();

	program->use();
	program->setUniformLocationWithMatrix4fv(m_nodeList[nodeIndex]._uniformMatrix,
											 m_matrices[sel]._matrix,
											 1);

	m_nodeList[nodeIndex]._effectSelect = sel;

	return true;
}
コード例 #9
0
int FragmentEffect::addEffectNode(CCNode* pNode)
{
	do
	{
		CCGLProgram* program = new CCGLProgram();

		GLchar* pszFragSource =
				"#ifdef GL_ES													  \n \
				precision mediump float;										  \n \
				#endif															  \n \
				uniform sampler2D u_texture;									  \n \
				varying vec2 v_texCoord;										  \n \
				varying vec4 v_fragmentColor;									  \n \
				uniform mat4 matrixEffect;										  \n \
				void main(void)													  \n \
				{																  \n \
					gl_FragColor = texture2D(u_texture, v_texCoord)*matrixEffect; \n \
				}";

		program->initWithVertexShaderByteArray(ccPositionTextureColor_vert, //顶点找色器,这里是引擎自带的
												 pszFragSource);            //像素找色器,这里是自己写的

		//将生成的shader程序传给CCSprite类
		pNode->setShaderProgram(program);
		
		//要release一次,在上面的setShaderProgram将pProgram托管给CCSprite
		//setShaderProgram只调用了pProgram->retain(),没有release(),现在pProgram的m_uReference是2
		program->release();
		
		CHECK_GL_ERROR_DEBUG();
		
		//启用顶点着色器的attribute变量,坐标、纹理坐标、颜色 ,去掉其中一个或两个还能工作
		program->addAttribute(kCCAttributeNamePosition, kCCVertexAttrib_Position);
		program->addAttribute(kCCAttributeNameColor,    kCCVertexAttrib_Color);
		program->addAttribute(kCCAttributeNameTexCoord, kCCVertexAttrib_TexCoords);
		
		CHECK_GL_ERROR_DEBUG();

		//自定义着色器链接
		program->link();
		CHECK_GL_ERROR_DEBUG();

		// 设置移动、缩放、旋转矩阵  
		program->updateUniforms();
		CHECK_GL_ERROR_DEBUG();

		EffectListNode listNode;
		listNode._pNode         = pNode;
		listNode._effectSelect  = 0;
		listNode._uniformMatrix = program->getUniformLocationForName("matrixEffect");

		program->use();
		program->setUniformLocationWithMatrix4fv(listNode._uniformMatrix,
												 m_matrices[0]._matrix,
												 1);
		m_nodeList.push_back(listNode);

		return m_nodeList.size()-1;

	} while (0);
	
	return -1;
}