void KX_PolygonMaterial::DefaultActivate(RAS_IRasterizer* rasty, TCachingInfo& cachingInfo) const { if (GetCachingInfo() != cachingInfo) { if (!cachingInfo) GPU_set_tpage(NULL, 0, 0); cachingInfo = GetCachingInfo(); if ((m_drawingmode & RAS_IRasterizer::KX_TEX)&& (rasty->GetDrawingMode() == RAS_IRasterizer::KX_TEXTURED)) { Image *ima = (Image*)m_tface->tpage; GPU_update_image_time(ima, rasty->GetTime()); GPU_set_tpage(m_tface, 1, m_alphablend); } else GPU_set_tpage(NULL, 0, 0); if(m_drawingmode & RAS_IRasterizer::KX_BACKCULL) rasty->SetCullFace(true); else rasty->SetCullFace(false); if ((m_drawingmode & RAS_IRasterizer::KX_LINES) || (rasty->GetDrawingMode() <= RAS_IRasterizer::KX_WIREFRAME)) rasty->SetLines(true); else rasty->SetLines(false); rasty->SetSpecularity(m_specular[0],m_specular[1],m_specular[2],m_specularity); rasty->SetShinyness(m_shininess); rasty->SetDiffuse(m_diffuse[0], m_diffuse[1],m_diffuse[2], 1.0); if (m_material) rasty->SetPolygonOffset(-m_material->zoffs, 0.0); } //rasty->SetSpecularity(m_specular[0],m_specular[1],m_specular[2],m_specularity); //rasty->SetShinyness(m_shininess); //rasty->SetDiffuse(m_diffuse[0], m_diffuse[1],m_diffuse[2], 1.0); //if (m_material) // rasty->SetPolygonOffset(-m_material->zoffs, 0.0); }
static void draw_textured_end(void) { if (Gtexdraw.ob->mode & OB_MODE_TEXTURE_PAINT) { glActiveTexture(GL_TEXTURE1); glDisable(GL_TEXTURE_2D); glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB, GL_SRC_COLOR); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glBindTexture(GL_TEXTURE_2D, 0); if (Gtexdraw.stencil != NULL) { glActiveTexture(GL_TEXTURE2); glDisable(GL_TEXTURE_2D); glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB, GL_SRC_COLOR); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glBindTexture(GL_TEXTURE_2D, 0); } glActiveTexture(GL_TEXTURE0); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); /* manual reset, since we don't use tpage */ glBindTexture(GL_TEXTURE_2D, 0); /* force switch off textures */ GPU_clear_tpage(true); } else { /* switch off textures */ GPU_set_tpage(NULL, 0, 0); } glShadeModel(GL_FLAT); glDisable(GL_CULL_FACE); glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE); /* XXX, bad patch - GPU_default_lights() calls * glLightfv(GL_POSITION, ...) which * is transformed by the current matrix... we * need to make sure that matrix is identity. * * It would be better if drawmesh.c kept track * of and restored the light settings it changed. * - zr */ glPushMatrix(); glLoadIdentity(); GPU_default_lights(); glPopMatrix(); }
static void draw_textured_end(void) { /* switch off textures */ GPU_set_tpage(NULL, 0, 0); glShadeModel(GL_FLAT); glDisable(GL_CULL_FACE); glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE); /* XXX, bad patch - GPU_default_lights() calls * glLightfv(GL_POSITION, ...) which * is transformed by the current matrix... we * need to make sure that matrix is identity. * * It would be better if drawmesh.c kept track * of and restored the light settings it changed. * - zr */ glPushMatrix(); glLoadIdentity(); GPU_default_lights(); glPopMatrix(); }
static void RestoreState(bContext *C, wmWindow *win) { Object *obact = CTX_data_active_object(C); if (obact && obact->mode & OB_MODE_TEXTURE_PAINT) GPU_paint_set_mipmap(0); //XXX curarea->win_swap = 0; //XXX curarea->head_swap = 0; //XXX allqueue(REDRAWVIEW3D, 1); //XXX allqueue(REDRAWBUTSALL, 0); //XXX reset_slowparents(); //XXX waitcursor(0); //XXX G.qual = 0; if (win) /* check because closing win can set to NULL */ win->queue = queue_back; GPU_state_init(); GPU_set_tpage(NULL, 0, 0); glPopAttrib(); }
void KX_BlenderMaterial::OnExit() { if ( mShader ) { //note, the shader here is allocated, per unique material //and this function is called per face if (mShader == mLastShader) { mShader->SetProg(false); mLastShader = NULL; } delete mShader; mShader = 0; } if ( mBlenderShader ) { if (mBlenderShader == mLastBlenderShader) { mBlenderShader->SetProg(false); mLastBlenderShader = NULL; } delete mBlenderShader; mBlenderShader = 0; } BL_Texture::ActivateFirst(); for (int i=0; i<BL_Texture::GetMaxUnits(); i++) { if (!mTextures[i].Ok()) continue; BL_Texture::ActivateUnit(i); mTextures[i].DeleteTex(); mTextures[i].DisableUnit(); } /* used to call with 'mMaterial->tface' but this can be a freed array, * see: [#30493], so just call with NULL, this is best since it clears * the 'lastface' pointer in GPU too - campbell */ GPU_set_tpage(NULL, 1, mMaterial->alphablend); }
static bool set_draw_settings_cached(int clearcache, MTFace *texface, Material *ma, struct TextureDrawState gtexdraw) { static Material *c_ma; static int c_textured; static MTFace c_texface; static int c_backculled; static bool c_badtex; static int c_lit; static int c_has_texface; Object *litob = NULL; /* to get mode to turn off mipmap in painting mode */ int backculled = 1; int alphablend = GPU_BLEND_SOLID; int textured = 0; int lit = 0; int has_texface = texface != NULL; bool need_set_tpage = false; if (clearcache) { c_textured = c_lit = c_backculled = -1; memset(&c_texface, 0, sizeof(MTFace)); c_badtex = false; c_has_texface = -1; } else { textured = gtexdraw.is_tex; litob = gtexdraw.ob; } /* convert number of lights into boolean */ if (gtexdraw.is_lit) lit = 1; if (ma) { if (ma->mode & MA_SHLESS) lit = 0; backculled = gtexdraw.use_backface_culling; if (gtexdraw.use_game_mat) { backculled = backculled || (ma->game.flag & GEMAT_BACKCULL); alphablend = ma->game.alpha_blend; } } if (texface) { textured = textured && (texface->tpage); /* no material, render alpha if texture has depth=32 */ if (!ma && BKE_image_has_alpha(texface->tpage)) alphablend = GPU_BLEND_ALPHA; } else textured = 0; if (backculled != c_backculled) { if (backculled) glEnable(GL_CULL_FACE); else glDisable(GL_CULL_FACE); c_backculled = backculled; } /* need to re-set tpage if textured flag changed or existsment of texface changed.. */ need_set_tpage = textured != c_textured || has_texface != c_has_texface; /* ..or if settings inside texface were changed (if texface was used) */ need_set_tpage |= texface && memcmp(&c_texface, texface, sizeof(c_texface)); if (need_set_tpage) { if (textured) { c_badtex = !GPU_set_tpage(texface, !(litob->mode & OB_MODE_TEXTURE_PAINT), alphablend); } else { GPU_set_tpage(NULL, 0, 0); c_badtex = false; } c_textured = textured; c_has_texface = has_texface; if (texface) memcpy(&c_texface, texface, sizeof(c_texface)); } if (c_badtex) lit = 0; if (lit != c_lit || ma != c_ma) { if (lit) { float spec[4]; if (!ma) ma = give_current_material_or_def(NULL, 0); /* default material */ spec[0] = ma->spec * ma->specr; spec[1] = ma->spec * ma->specg; spec[2] = ma->spec * ma->specb; spec[3] = 1.0; glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, spec); glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE); glMateriali(GL_FRONT_AND_BACK, GL_SHININESS, CLAMPIS(ma->har, 0, 128)); glEnable(GL_LIGHTING); glEnable(GL_COLOR_MATERIAL); } else { glDisable(GL_LIGHTING); glDisable(GL_COLOR_MATERIAL); } c_lit = lit; } return c_badtex; }
static bool set_draw_settings_cached(int clearcache, MTexPoly *texface, Material *ma, struct TextureDrawState gtexdraw) { static Material *c_ma; static int c_textured; static MTexPoly c_texface; static int c_backculled; static bool c_badtex; static int c_lit; static int c_has_texface; int backculled = 1; int alphablend = GPU_BLEND_SOLID; int textured = 0; int lit = 0; int has_texface = texface != NULL; bool need_set_tpage = false; bool texpaint = ((gtexdraw.ob->mode & OB_MODE_TEXTURE_PAINT) != 0); Image *ima = NULL; if (ma != NULL) { if (ma->mode & MA_TRANSP) { alphablend = GPU_BLEND_ALPHA; } } if (clearcache) { c_textured = c_lit = c_backculled = -1; memset(&c_texface, 0, sizeof(c_texface)); c_badtex = false; c_has_texface = -1; c_ma = NULL; } else { textured = gtexdraw.is_tex; } /* convert number of lights into boolean */ if (gtexdraw.is_lit) lit = 1; backculled = gtexdraw.use_backface_culling; if (ma) { if (ma->mode & MA_SHLESS) lit = 0; if (gtexdraw.use_game_mat) { backculled = backculled || (ma->game.flag & GEMAT_BACKCULL); alphablend = ma->game.alpha_blend; } } if (texface && !texpaint) { textured = textured && (texface->tpage); /* no material, render alpha if texture has depth=32 */ if (!ma && BKE_image_has_alpha(texface->tpage)) alphablend = GPU_BLEND_ALPHA; } else if (texpaint) { if (gtexdraw.texpaint_material) ima = ma && ma->texpaintslot ? ma->texpaintslot[ma->paint_active_slot].ima : NULL; else ima = gtexdraw.canvas; } else textured = 0; if (backculled != c_backculled) { if (backculled) glEnable(GL_CULL_FACE); else glDisable(GL_CULL_FACE); c_backculled = backculled; } /* need to re-set tpage if textured flag changed or existsment of texface changed.. */ need_set_tpage = textured != c_textured || has_texface != c_has_texface; /* ..or if settings inside texface were changed (if texface was used) */ need_set_tpage |= (texpaint && c_ma != ma) || (texface && memcmp(&c_texface, texface, sizeof(c_texface))); if (need_set_tpage) { if (textured) { if (texpaint) { c_badtex = false; if (GPU_verify_image(ima, NULL, 0, 1, 0, false)) { glEnable(GL_TEXTURE_2D); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE); glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_TEXTURE); glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_PRIMARY_COLOR); glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE); glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_TEXTURE); glActiveTexture(GL_TEXTURE1); glEnable(GL_TEXTURE_2D); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_INTERPOLATE); glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_PREVIOUS); glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_PRIMARY_COLOR); glTexEnvi(GL_TEXTURE_ENV, GL_SRC2_RGB, GL_PREVIOUS); glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB, GL_SRC_ALPHA); glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE); glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_PREVIOUS); glBindTexture(GL_TEXTURE_2D, ima->bindcode); glActiveTexture(GL_TEXTURE0); } else { glActiveTexture(GL_TEXTURE1); glDisable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, 0); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glActiveTexture(GL_TEXTURE0); c_badtex = true; GPU_clear_tpage(true); glDisable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, 0); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); } } else { c_badtex = !GPU_set_tpage(texface, !texpaint, alphablend); } } else { GPU_set_tpage(NULL, 0, 0); c_badtex = false; } c_textured = textured; c_has_texface = has_texface; if (texface) memcpy(&c_texface, texface, sizeof(c_texface)); } if (c_badtex) lit = 0; if (lit != c_lit || ma != c_ma) { if (lit) { float spec[4]; if (!ma) ma = give_current_material_or_def(NULL, 0); /* default material */ spec[0] = ma->spec * ma->specr; spec[1] = ma->spec * ma->specg; spec[2] = ma->spec * ma->specb; spec[3] = 1.0; glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, spec); glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE); glMateriali(GL_FRONT_AND_BACK, GL_SHININESS, CLAMPIS(ma->har, 0, 128)); glEnable(GL_LIGHTING); glEnable(GL_COLOR_MATERIAL); } else { glDisable(GL_LIGHTING); glDisable(GL_COLOR_MATERIAL); } c_lit = lit; c_ma = ma; } return c_badtex; }