/** * \param type bit 0: render OSD, bit 1: render EOSD */ static void do_render_osd(int type) { if (((type & 1) && osdtexCnt > 0) || ((type & 2) && eosdDispList)) { // set special rendering parameters if (!scaled_osd) { MatrixMode(GL_PROJECTION); PushMatrix(); LoadIdentity(); Ortho(0, vo_dwidth, vo_dheight, 0, -1, 1); } Enable(GL_BLEND); if ((type & 2) && eosdDispList) { BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); CallList(eosdDispList); } if ((type & 1) && osdtexCnt > 0) { Color4ub((osd_color >> 16) & 0xff, (osd_color >> 8) & 0xff, osd_color & 0xff, 0xff - (osd_color >> 24)); // draw OSD #ifndef FAST_OSD BlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_ALPHA); CallLists(osdtexCnt, GL_UNSIGNED_INT, osdaDispList); #endif BlendFunc(GL_SRC_ALPHA, GL_ONE); CallLists(osdtexCnt, GL_UNSIGNED_INT, osdDispList); } // set rendering parameters back to defaults Disable(GL_BLEND); if (!scaled_osd) PopMatrix(); BindTexture(gl_target, 0); }
void GL::EnableBlending(GLenum aSourceFactorRGB, GLenum aDestFactorRGB, GLenum aSourceFactorAlpha, GLenum aDestFactorAlpha) { MOZ_ASSERT(IsCurrent()); if (!mBlendingEnabled) { Enable(GL_BLEND); mBlendingEnabled = true; } if (mSourceBlendFactorRGB != aSourceFactorRGB || mDestBlendFactorRGB != aDestFactorRGB || mSourceBlendFactorAlpha != aSourceFactorAlpha || mDestBlendFactorAlpha != aDestFactorAlpha) { if (aSourceFactorRGB == aSourceFactorAlpha && aDestFactorRGB == aDestFactorAlpha) { BlendFunc(aSourceFactorRGB, aDestFactorRGB); } else { BlendFuncSeparate(aSourceFactorRGB, aDestFactorRGB, aSourceFactorAlpha, aDestFactorAlpha); } mSourceBlendFactorRGB = aSourceFactorRGB; mDestBlendFactorRGB = aDestFactorRGB; mSourceBlendFactorAlpha = aSourceFactorAlpha; mDestBlendFactorAlpha = aDestFactorAlpha; } }
void Renderer::SetupShader(Shader *shader, int lm_index) { // the light map could change even though we have the same shaders // check and set new lightmap, leave everthing else the same if (shader == current_shader_ && lm_index != -1) { if (lm_index == current_lightmap_) { return; } if (shader->lightmap_stage_ == -1) { return; } current_lightmap_ = lm_index; BindTexture(shader->lightmap_stage_, textureLoader::GetLightmap(lm_index)); ++num_skipped_shaders_; return; } // THIS ONLY DISABLES BLENDING BUT WE WANT TO ALWAYS BLEND.. maybe // if (current_shader_ != 0) //{ // FinishShader(*current_shader_); //} // current_shader_ = shader; // JUST ENABLE BLENDING ALL THE TIME AND BLEND NON TRANSLUCENT TEXTURES WITH // ONE ZERO // only enable blending if stage 0 wants to blend with background // shaders can only blend with textures // if (i == 0 && stage.blendfunc[0] == GL_ONE && stage.blendfunc[1] == GL_ONE) //{ if (shader->q3_shader_.stages_.size() > 0) { Blend(true); BlendFunc(shader->q3_shader_.stages_[0].blendfunc[0], shader->q3_shader_.stages_[0].blendfunc[1]); } else { Blend(false); } // BlendFunc(GL_ONE, GL_ZERO); //} for (unsigned int i = 0; i < shader->q3_shader_.stages_.size(); ++i) { // maybe put lightmap directly into stage so we dont need this if // seems we can optimize it by first only checking lm_index if (i == shader->lightmap_stage_ && lm_index != -1) { BindTexture(i, textureLoader::GetLightmap(lm_index)); current_lightmap_ = lm_index; } else { BindTexture(i, shader->texture_id_[i]); } } }
void FSprite::InitShader(const std::string& alpha_file) { #ifdef ETC1 //Shader GLProgram* glp = new GLProgram(); glp->autorelease(); glp->initWithFilenames("testv.vsh", "test.fsh"); glp->bindAttribLocation(GLProgram::ATTRIBUTE_NAME_POSITION, GLProgram::VERTEX_ATTRIB_POSITION); glp->bindAttribLocation(GLProgram::ATTRIBUTE_NAME_COLOR, GLProgram::VERTEX_ATTRIB_COLOR); glp->bindAttribLocation(GLProgram::ATTRIBUTE_NAME_TEX_COORD, GLProgram::VERTEX_ATTRIB_TEX_COORD); glp->link(); glp->updateUniforms(); opacity_location_ = glGetUniformLocation(glp->getProgram(), "u_opacity"); current_alpha_file_ = alpha_file; // #pragma message WARN("getTextureForKey or someth else, texture should be added on loading scene, do not add (cocos should check that anyway but still dont do it) all the time!!") Texture2D* tex = Director::getInstance()->getTextureCache()->addImage(alpha_file); setBlendFunc(BlendFunc({ GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA })); //setBlendFunc((BlendFunc) { GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA }); GLProgramState* glprogramstate = GLProgramState::getOrCreateWithGLProgram(glp); setGLProgramState(glprogramstate); glprogramstate->setUniformFloat(opacity_location_, (float)getOpacity()/255.0); glprogramstate->setUniformTexture("u_texture1", tex); setGLProgram(glp); #endif }