void BoneNode::addToSkinList(SkinNode* skin) { _boneSkins.pushBack(skin); auto blendSkin = dynamic_cast<BlendProtocol*>(skin); if (nullptr != blendSkin && _blendFunc != blendSkin->getBlendFunc()) { blendSkin->setBlendFunc(_blendFunc); } }
void Label::alignText() { if (_fontAtlas == nullptr || _utf16Text.empty()) { setContentSize(Size::ZERO); return; } _fontAtlas->prepareLetterDefinitions(_utf16Text); auto& textures = _fontAtlas->getTextures(); if (textures.size() > _batchNodes.size()) { for (auto index = _batchNodes.size(); index < textures.size(); ++index) { auto batchNode = SpriteBatchNode::createWithTexture(textures.at(index)); if (batchNode) { _isOpacityModifyRGB = batchNode->getTexture()->hasPremultipliedAlpha(); _blendFunc = batchNode->getBlendFunc(); batchNode->setAnchorPoint(Vec2::ANCHOR_TOP_LEFT); batchNode->setPosition(Vec2::ZERO); _batchNodes.pushBack(batchNode); } } } if (_batchNodes.empty()) { return; } _reusedLetter->setBatchNode(_batchNodes.at(0)); _lengthOfString = 0; _textDesiredHeight = 0.f; _linesWidth.clear(); if (_maxLineWidth > 0.f && !_lineBreakWithoutSpaces) { multilineTextWrapByWord(); } else { multilineTextWrapByChar(); } computeAlignmentOffset(); updateQuads(); updateLabelLetters(); updateColor(); }
uint32_t GAFSprite::setUniforms() { #if COCOS2D_VERSION < 0x00030300 uint32_t materialID = QuadCommand::MATERIAL_ID_DO_NOT_BATCH; #else uint32_t materialID = Renderer::MATERIAL_ID_DO_NOT_BATCH; #endif if (_glProgramState->getUniformCount() == 0) { int glProgram = (int)getGLProgram()->getProgram(); int intArray[4] = { glProgram, (int)getTexture()->getName(), (int)getBlendFunc().src, (int)getBlendFunc().dst }; materialID = XXH32((const void*)intArray, sizeof(intArray), 0); } return materialID; }
void SpriteBlur::initProgram() { GLchar * fragSource = (GLchar*) CCString::createWithContentsOfFile( CCFileUtils::sharedFileUtils()->fullPathForFilename("Shaders/example_Blur.fsh").c_str())->getCString(); CCGLProgram* pProgram = new CCGLProgram(); pProgram->initWithVertexShaderByteArray(ccPositionTextureColor_vert, fragSource); setShaderProgram(pProgram); pProgram->release(); CHECK_GL_ERROR_DEBUG(); getShaderProgram()->addAttribute(kCCAttributeNamePosition, kCCVertexAttrib_Position); getShaderProgram()->addAttribute(kCCAttributeNameColor, kCCVertexAttrib_Color); getShaderProgram()->addAttribute(kCCAttributeNameTexCoord, kCCVertexAttrib_TexCoords); CHECK_GL_ERROR_DEBUG(); getShaderProgram()->link(); CHECK_GL_ERROR_DEBUG(); getShaderProgram()->updateUniforms(); CHECK_GL_ERROR_DEBUG(); subLocation = glGetUniformLocation( getShaderProgram()->getProgram(), "substract"); blurLocation = glGetUniformLocation( getShaderProgram()->getProgram(), "blurSize"); CHECK_GL_ERROR_DEBUG(); ccGLEnableVertexAttribs(kCCVertexAttribFlag_PosColorTex ); ccBlendFunc blend = getBlendFunc(); ccGLBlendFunc(blend.src, blend.dst); getShaderProgram()->use(); getShaderProgram()->setUniformsForBuiltins(); getShaderProgram()->setUniformLocationWith2f(blurLocation, blur_.x, blur_.y); getShaderProgram()->setUniformLocationWith4fv(subLocation, sub_, 1); ccGLBindTexture2D( getTexture()->getName()); }
void SpriteRenderTextureBug::SimpleSprite::draw() { if (rt == NULL) { auto s = Director::getInstance()->getWinSize(); rt = new RenderTexture(); rt->initWithWidthAndHeight(s.width, s.height, Texture2D::PixelFormat::RGBA8888); } rt->beginWithClear(0.0f, 0.0f, 0.0f, 1.0f); rt->end(); CC_NODE_DRAW_SETUP(); BlendFunc blend = getBlendFunc(); GL::blendFunc(blend.src, blend.dst); GL::bindTexture2D(getTexture()->getName()); // // Attributes // GL::enableVertexAttribs(cocos2d::GL::VERTEX_ATTRIB_FLAG_POS_COLOR_TEX); #define kQuadSize sizeof(_quad.bl) long offset = (long)&_quad; // vertex int diff = offsetof( V3F_C4B_T2F, vertices); glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 3, GL_FLOAT, GL_FALSE, kQuadSize, (void*) (offset + diff)); // texCoods diff = offsetof( V3F_C4B_T2F, texCoords); glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_TEX_COORDS, 2, GL_FLOAT, GL_FALSE, kQuadSize, (void*)(offset + diff)); // color diff = offsetof( V3F_C4B_T2F, colors); glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, kQuadSize, (void*)(offset + diff)); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); }
void LayerTestBlend::newBlend(float dt) { auto layer = (LayerColor*)getChildByTag(kTagLayer); GLenum src; GLenum dst; if( layer->getBlendFunc().dst == GL_ZERO ) { src = GL_SRC_ALPHA; dst = GL_ONE_MINUS_SRC_ALPHA; } else { src = GL_ONE_MINUS_DST_COLOR; dst = GL_ZERO; } BlendFunc bf = {src, dst}; layer->setBlendFunc( bf ); }
void SpriteBlur::draw() { ccGLEnableVertexAttribs(kCCVertexAttribFlag_PosColorTex ); ccBlendFunc blend = getBlendFunc(); ccGLBlendFunc(blend.src, blend.dst); getShaderProgram()->use(); getShaderProgram()->setUniformsForBuiltins(); getShaderProgram()->setUniformLocationWith2f(blurLocation, blur_.x, blur_.y); getShaderProgram()->setUniformLocationWith4fv(subLocation, sub_, 1); ccGLBiScutTexture2D( getTexture()->getName()); // // Attributes // #define kQuadSize sizeof(m_sQuad.bl) long offset = (long)&m_sQuad; // vertex int diff = offsetof( ccV3F_C4B_T2F, vertices); glVertexAttribPointer(kCCVertexAttrib_Position, 3, GL_FLOAT, GL_FALSE, kQuadSize, (void*) (offset + diff)); // texCoods diff = offsetof( ccV3F_C4B_T2F, texCoords); glVertexAttribPointer(kCCVertexAttrib_TexCoords, 2, GL_FLOAT, GL_FALSE, kQuadSize, (void*)(offset + diff)); // color diff = offsetof( ccV3F_C4B_T2F, colors); glVertexAttribPointer(kCCVertexAttrib_Color, 4, GL_UNSIGNED_BYTE, GL_TRUE, kQuadSize, (void*)(offset + diff)); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); CC_INCREMENT_GL_DRAWS(1); }
void ParticleEditor::SaveConfigFile(QString filename) { FILE* sFile; sFile = fopen(filename.toLocal8Bit().data(), "wb"); if (!sFile){ addConsoleInfo("保存失败"); return; } QVariantMap document; QVariantList resList; QVariantMap particleData; //导出资源 QStringList imageList = resourceView->getImageList(); for (int i = 0; i < imageList.size(); i++){ QVariant res = imageList.at(i); resList.append(res); } //导出粒子 auto layer = dynamic_cast<C3DLayer*>(g_Layer); auto particleSystem = layer->getParticleSystem(); particleData.insert("texture", particleSystem->getTextureFileName().c_str()); particleData.insert("count", particleSystem->getParticleCount()); particleData.insert("particle_type", particleSystem->getParticleType()); particleData.insert("blendfunc_src", particleSystem->getBlendFunc().src); particleData.insert("blendfunc_dst", particleSystem->getBlendFunc().dst); auto data = particleSystem->getParticleData(); particleData.insert("velocity_min_x", data.m_Velocity_Min.x); particleData.insert("velocity_min_y", data.m_Velocity_Min.y); particleData.insert("velocity_min_z", data.m_Velocity_Min.z); particleData.insert("velocity_max_x", data.m_Velocity_Max.x); particleData.insert("velocity_max_y", data.m_Velocity_Max.y); particleData.insert("velocity_max_z", data.m_Velocity_Max.z); particleData.insert("accleration_min_x", data.m_Acceleration_Min.x); particleData.insert("accleration_min_y", data.m_Acceleration_Min.y); particleData.insert("accleration_min_z", data.m_Acceleration_Min.z); particleData.insert("accleration_max_x", data.m_Acceleration_Max.x); particleData.insert("accleration_max_y", data.m_Acceleration_Max.y); particleData.insert("accleration_max_z", data.m_Acceleration_Max.z); particleData.insert("size_min_x", data.m_Size_Min.x); particleData.insert("size_min_y", data.m_Size_Min.y); particleData.insert("size_min_z", data.m_Size_Min.z); particleData.insert("size_max_x", data.m_Size_Max.x); particleData.insert("size_max_y", data.m_Size_Max.y); particleData.insert("size_max_z", data.m_Size_Max.z); particleData.insert("size_velocity_x", data.m_Size_Velocity.x); particleData.insert("size_velocity_y", data.m_Size_Velocity.y); particleData.insert("size_velocity_z", data.m_Size_Velocity.z); particleData.insert("color_min_x", data.m_Color_Min.x); particleData.insert("color_min_y", data.m_Color_Min.y); particleData.insert("color_min_z", data.m_Color_Min.z); particleData.insert("color_max_x", data.m_Color_Max.x); particleData.insert("color_max_y", data.m_Color_Max.y); particleData.insert("color_max_z", data.m_Color_Max.z); particleData.insert("color_velocity_x", data.m_Color_Velocity.x); particleData.insert("color_velocity_y", data.m_Color_Velocity.y); particleData.insert("color_velocity_z", data.m_Color_Velocity.z); particleData.insert("life_min", data.m_Life_Min); particleData.insert("life_max", data.m_Life_Max); particleData.insert("life_velocity", data.m_Life_Velocity); particleData.insert("m_color_r", particleSystem->getColor()[0]); particleData.insert("m_color_g", particleSystem->getColor()[1]); particleData.insert("m_color_b", particleSystem->getColor()[2]); particleData.insert("m_color_a", particleSystem->getColor()[3]); document.insert("resList", resList); document.insert("particleData", particleData); QJsonDocument jsonDocument = QJsonDocument::fromVariant(document); QByteArray array = jsonDocument.toJson(QJsonDocument::Compact); unsigned int count = array.size(); const char* data__ = (const char*)array.data(); fwrite(data__, count, 1, sFile); fclose(sFile); }
/* this loader applies only textures for stage 1 & 2 */ s32 CQ3LevelMesh::setShaderMaterial( video::SMaterial &material, const tBSPFace * face ) const { material.MaterialType = video::EMT_SOLID; material.Wireframe = false; material.Lighting = false; material.BackfaceCulling = true; material.setTexture(0, 0); material.setTexture(1, 0); material.setTexture(2, 0); material.setTexture(3, 0); material.ZBuffer = video::ECFN_LESSEQUAL; material.ZWriteEnable = true; material.MaterialTypeParam = 0.f; s32 shaderState = -1; if ( face->textureID >= 0 && face->textureID < (s32)Tex.size() ) { material.setTexture(0, Tex [ face->textureID ].Texture); shaderState = Tex [ face->textureID ].ShaderID; } if ( face->lightmapID >= 0 && face->lightmapID < (s32)Lightmap.size() ) { material.setTexture(1, Lightmap [ face->lightmapID ]); material.MaterialType = LoadParam.defaultLightMapMaterial; } // store shader ID material.MaterialTypeParam2 = (f32) shaderState; const IShader *shader = getShader(shaderState); if ( 0 == shader ) return shaderState; return shaderState; #if 0 const SVarGroup *group; // generic group = shader->getGroup( 1 ); if ( group ) { material.BackfaceCulling = getCullingFunction( group->get( "cull" ) ); if ( group->isDefined( "surfaceparm", "nolightmap" ) ) { material.MaterialType = video::EMT_SOLID; material.setTexture(1, 0); } } // try to get the best of the 8 texture stages.. // texture 1, texture 2 u32 startPos; for ( s32 g = 2; g <= 3; ++g ) { group = shader->getGroup( g ); if ( 0 == group ) continue; startPos = 0; if ( group->isDefined( "depthwrite" ) ) { material.ZWriteEnable = true; } SBlendFunc blendfunc ( LoadParam.defaultModulate ); getBlendFunc( group->get( "blendfunc" ), blendfunc ); getBlendFunc( group->get( "alphafunc" ), blendfunc ); if ( 0 == LoadParam.alpharef && ( blendfunc.type == video::EMT_TRANSPARENT_ALPHA_CHANNEL || blendfunc.type == video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF ) ) { blendfunc.type = video::EMT_TRANSPARENT_ALPHA_CHANNEL; blendfunc.param0 = 0.f; } material.MaterialType = blendfunc.type; material.MaterialTypeParam = blendfunc.param0; // try if we can match better shaderState |= (material.MaterialType == video::EMT_SOLID ) ? 0x00020000 : 0; } //material.BackfaceCulling = false; if ( shader->VarGroup->VariableGroup.size() <= 4 ) { shaderState |= 0x00010000; } material.MaterialTypeParam2 = (f32) shaderState; return shaderState; #endif }
/*********************************************************************** * Blend ***********************************************************************/ void glBlendFunc(GLenum sfactor, GLenum dfactor) { GLImpl.state.blend_src = getBlendFunc(sfactor); GLImpl.state.blend_dst = getBlendFunc(dfactor); GLImpl.state.dirty |= DIRTY_BLEND; }
void Label::alignText() { if (_fontAtlas == nullptr || _currentUTF16String.empty()) { setContentSize(Size::ZERO); return; } _fontAtlas->prepareLetterDefinitions(_currentUTF16String); auto& textures = _fontAtlas->getTextures(); if (textures.size() > _batchNodes.size()) { for (auto index = _batchNodes.size(); index < textures.size(); ++index) { auto batchNode = SpriteBatchNode::createWithTexture(textures.at(index)); if (batchNode) { _blendFunc = batchNode->getBlendFunc(); batchNode->setAnchorPoint(Vec2::ANCHOR_TOP_LEFT); batchNode->setPosition(Vec2::ZERO); _batchNodes.pushBack(batchNode); } } } if (_batchNodes.empty()) { return; } _reusedLetter->setBatchNode(_batchNodes.at(0)); LabelTextFormatter::createStringSprites(this); if(_maxLineWidth > 0 && _contentSize.width > _maxLineWidth && LabelTextFormatter::multilineText(this) ) LabelTextFormatter::createStringSprites(this); if(_labelWidth > 0 || (_currNumLines > 1 && _hAlignment != TextHAlignment::LEFT)) LabelTextFormatter::alignText(this); if (!_letters.empty()) { Rect uvRect; Sprite* letterSprite; int letterIndex; for (auto it = _letters.begin(); it != _letters.end();) { letterIndex = it->first; letterSprite = it->second; if (letterIndex >= _limitShowCount) { Node::removeChild(letterSprite, true); it = _letters.erase(it); } else { auto& letterDef = _lettersInfo[letterIndex].def; uvRect.size.height = letterDef.height; uvRect.size.width = letterDef.width; uvRect.origin.x = letterDef.U; uvRect.origin.y = letterDef.V; letterSprite->setBatchNode(_batchNodes.at(letterDef.textureID)); letterSprite->setTextureRect(uvRect, false, uvRect.size); letterSprite->setPosition(_lettersInfo[letterIndex].position.x + letterDef.width / 2, _lettersInfo[letterIndex].position.y - letterDef.height / 2); ++it; } } } for (const auto& batchNode : _batchNodes) { batchNode->getTextureAtlas()->removeAllQuads(); } updateQuads(); updateColor(); }