//--------------------------------------------------------
void CShaderNode::draw()
{
	CC_NODE_DRAW_SETUP();  

	//传递uniform变量  
	CCGLProgram* shader = getShaderProgram();  
	shader->setUniformLocationWith2f(m_unUniformResolution, m_tagResolutionPos.x, m_tagResolutionPos.y);
	shader->setUniformLocationWith1i(m_unUniformTex0, 0); 
	glUniform1f(m_unUniformTime, m_fTime);

	//获取attribute变量  
	CCSize size = this->getContentSize();  
	float w = size.width;  
	float h = size.height;  

	ccGLBindTexture2D(m_pTexture);								//绑定纹理到槽位  
	glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, w, h, 0); //截取屏幕数据到纹理  
	glEnableVertexAttribArray(m_unAttributePosition); 

	//传递attribute变量  
	GLfloat vertices[12] = {  
		0, 0, //左下0
		w, 0, //右下1
		w, h, //右上2
		0, 0, //左下0
		0, h, //左上3
		w, h, //右上2
	};  
	glVertexAttribPointer(m_unAttributePosition, 2, GL_FLOAT, GL_FALSE, 0, vertices);  
	glVertexAttrib4fv(m_unAttributeColor, m_fColor);  
	//绘制  
	glDrawArrays(GL_TRIANGLES, 0, 6);  
}
Пример #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
static int tolua_CCGLProgram_CCGLProgram_setUniformLocationWith2f00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
 tolua_Error tolua_err;
 if (
     !tolua_isusertype(tolua_S,1,"CCGLProgram",0,&tolua_err) ||
     !tolua_isnumber(tolua_S,2,0,&tolua_err) ||
     !tolua_isnumber(tolua_S,3,0,&tolua_err) ||
     !tolua_isnumber(tolua_S,4,0,&tolua_err) ||
     !tolua_isnoobj(tolua_S,5,&tolua_err)
 )
  goto tolua_lerror;
 else
#endif
 {
  CCGLProgram* self = (CCGLProgram*)  tolua_tousertype(tolua_S,1,0);
  int location = ((int)  tolua_tonumber(tolua_S,2,0));
  float f1 = ((float)  tolua_tonumber(tolua_S,3,0));
  float f2 = ((float)  tolua_tonumber(tolua_S,4,0));
#ifndef TOLUA_RELEASE
  if (!self) tolua_error(tolua_S,"invalid 'self' in function 'setUniformLocationWith2f'", NULL);
#endif
  {
   self->setUniformLocationWith2f(location,f1,f2);
  }
 }
 return 0;
#ifndef TOLUA_RELEASE
 tolua_lerror:
 tolua_error(tolua_S,"#ferror in function 'setUniformLocationWith2f'.",&tolua_err);
 return 0;
#endif
}