ImageViewport::ImageViewport() :m_alpha(false), m_texInit(false) { /* Because this constructor is called from python direclty without any arguments * the viewport should be the one of the final screen with gaps. * To do this we use the canvas viewport. */ RAS_ICanvas *canvas = KX_GetActiveEngine()->GetCanvas(); const int *viewport = canvas->GetViewPort(); m_viewport[0] = viewport[0]; m_viewport[1] = viewport[1]; m_viewport[2] = viewport[2]; m_viewport[3] = viewport[3]; m_width = m_viewport[2] - m_viewport[0]; m_height = m_viewport[3] - m_viewport[1]; //glGetIntegerv(GL_VIEWPORT, m_viewport); // create buffer for viewport image // Warning: this buffer is also used to get the depth buffer as an array of // float (1 float = 4 bytes per pixel) m_viewportImage = new BYTE [4 * getViewportSize()[0] * getViewportSize()[1]]; // set attributes setWhole(true); }
// constructor ImageViewport::ImageViewport (PyRASOffScreen *offscreen) : m_alpha(false), m_texInit(false) { // get viewport rectangle if (offscreen) { m_viewport[0] = 0; m_viewport[1] = 0; m_viewport[2] = offscreen->ofs->GetWidth(); m_viewport[3] = offscreen->ofs->GetHeight(); } else { RAS_Rect rect = KX_GetActiveEngine()->GetCanvas()->GetWindowArea(); m_viewport[0] = rect.GetLeft(); m_viewport[1] = rect.GetBottom(); m_viewport[2] = rect.GetWidth(); m_viewport[3] = rect.GetHeight(); } //glGetIntegerv(GL_VIEWPORT, m_viewport); // create buffer for viewport image // Warning: this buffer is also used to get the depth buffer as an array of // float (1 float = 4 bytes per pixel) m_viewportImage = new BYTE [4 * getViewportSize()[0] * getViewportSize()[1]]; // set attributes setWhole((offscreen) ? true : false); }
void KX_WorldInfo::UpdateBackGround() { if (m_hasworld) { RAS_IRasterizer *m_rasterizer = KX_GetActiveEngine()->GetRasterizer(); if (m_rasterizer->GetDrawingMode() >= RAS_IRasterizer::KX_SOLID) { m_rasterizer->SetBackColor(m_con_backgroundcolor); GPU_horizon_update_color(m_backgroundcolor); } } }
// constructor ImageViewport::ImageViewport (void) : m_alpha(false), m_texInit(false) { // get viewport rectangle RAS_Rect rect = KX_GetActiveEngine()->GetCanvas()->GetWindowArea(); m_viewport[0] = rect.GetLeft(); m_viewport[1] = rect.GetBottom(); m_viewport[2] = rect.GetWidth(); m_viewport[3] = rect.GetHeight(); //glGetIntegerv(GL_VIEWPORT, m_viewport); // create buffer for viewport image m_viewportImage = new BYTE [4 * getViewportSize()[0] * getViewportSize()[1]]; // set attributes setWhole(false); }
void KX_Scene::UpdateAnimations(double curtime) { TaskPool *pool = BLI_task_pool_create(KX_GetActiveEngine()->GetTaskScheduler(), &curtime); for (int i=0; i<m_animatedlist->GetCount(); ++i) { BLI_task_pool_push(pool, update_anim_thread_func, m_animatedlist->GetValue(i), false, TASK_PRIORITY_LOW); } BLI_task_pool_work_and_wait(pool); BLI_task_pool_free(pool); }
// constructor ImageRender::ImageRender (KX_Scene *scene, KX_Camera * camera) : ImageViewport(), m_render(true), m_scene(scene), m_camera(camera), m_owncamera(false), m_observer(NULL), m_mirror(NULL), m_clip(100.f), m_mirrorHalfWidth(0.f), m_mirrorHalfHeight(0.f) { // initialize background color to scene background color as default setBackgroundFromScene(m_scene); // retrieve rendering objects m_engine = KX_GetActiveEngine(); m_rasterizer = m_engine->GetRasterizer(); m_canvas = m_engine->GetCanvas(); }
void KX_WorldInfo::UpdateWorldSettings() { if (m_hasworld) { RAS_IRasterizer *m_rasterizer = KX_GetActiveEngine()->GetRasterizer(); if (m_rasterizer->GetDrawingMode() >= RAS_IRasterizer::KX_SOLID) { m_rasterizer->SetAmbientColor(m_con_ambientcolor); GPU_ambient_update_color(m_ambientcolor); if (m_hasmist) { m_rasterizer->SetFog(m_misttype, m_miststart, m_mistdistance, m_mistintensity, m_con_mistcolor); GPU_mist_update_values(m_misttype, m_miststart, m_mistdistance, m_mistintensity, m_mistcolor); m_rasterizer->EnableFog(true); GPU_mist_update_enable(true); } else { m_rasterizer->EnableFog(false); GPU_mist_update_enable(false); } } } }
bool BL_Action::Play(const char* name, float start, float end, short priority, float blendin, short play_mode, float layer_weight, short ipo_flags, float playback_speed) { // Only start playing a new action if we're done, or if // the new action has a higher priority if (priority != 0 && !IsDone() && priority >= m_priority) return false; m_priority = priority; bAction* prev_action = m_action; // First try to load the action m_action = (bAction*)KX_GetActiveScene()->GetLogicManager()->GetActionByName(name); if (!m_action) { printf("Failed to load action: %s\n", name); m_done = true; return false; } if (prev_action != m_action) { // First get rid of any old controllers ClearControllerList(); // Create an SG_Controller SG_Controller *sg_contr = BL_CreateIPO(m_action, m_obj, KX_GetActiveScene()->GetSceneConverter()); m_sg_contr_list.push_back(sg_contr); m_obj->GetSGNode()->AddSGController(sg_contr); sg_contr->SetObject(m_obj->GetSGNode()); // Extra controllers if (m_obj->GetGameObjectType() == SCA_IObject::OBJ_LIGHT) { sg_contr = BL_CreateLampIPO(m_action, m_obj, KX_GetActiveScene()->GetSceneConverter()); m_sg_contr_list.push_back(sg_contr); m_obj->GetSGNode()->AddSGController(sg_contr); sg_contr->SetObject(m_obj->GetSGNode()); } else if (m_obj->GetGameObjectType() == SCA_IObject::OBJ_CAMERA) { sg_contr = BL_CreateCameraIPO(m_action, m_obj, KX_GetActiveScene()->GetSceneConverter()); m_sg_contr_list.push_back(sg_contr); m_obj->GetSGNode()->AddSGController(sg_contr); sg_contr->SetObject(m_obj->GetSGNode()); } } m_ipo_flags = ipo_flags; InitIPO(); // Setup blendin shapes/poses if (m_obj->GetGameObjectType() == SCA_IObject::OBJ_ARMATURE) { BL_ArmatureObject *obj = (BL_ArmatureObject*)m_obj; obj->GetMRDPose(&m_blendinpose); } else { BL_DeformableGameObject *obj = (BL_DeformableGameObject*)m_obj; BL_ShapeDeformer *shape_deformer = dynamic_cast<BL_ShapeDeformer*>(obj->GetDeformer()); if (shape_deformer && shape_deformer->GetKey()) { obj->GetShape(m_blendinshape); // Now that we have the previous blend shape saved, we can clear out the key to avoid any // further interference. KeyBlock *kb; for (kb=(KeyBlock*)shape_deformer->GetKey()->block.first; kb; kb=(KeyBlock*)kb->next) kb->curval = 0.f; } } // Now that we have an action, we have something we can play m_starttime = KX_GetActiveEngine()->GetFrameTime(); m_startframe = m_localtime = start; m_endframe = end; m_blendin = blendin; m_playmode = play_mode; m_endtime = 0.f; m_blendframe = 0.f; m_blendstart = 0.f; m_speed = playback_speed; m_layer_weight = layer_weight; m_done = false; return true; }
// refresh texture PyObject * Texture_refresh (Texture * self, PyObject * args) { // get parameter - refresh source PyObject * param; double ts = -1.0; if (!PyArg_ParseTuple(args, "O|d:refresh", ¶m, &ts) || !PyBool_Check(param)) { // report error PyErr_SetString(PyExc_TypeError, "The value must be a bool"); return NULL; } // some trick here: we are in the business of loading a texture, // no use to do it if we are still in the same rendering frame. // We find this out by looking at the engine current clock time KX_KetsjiEngine* engine = KX_GetActiveEngine(); if (engine->GetClockTime() != self->m_lastClock) { self->m_lastClock = engine->GetClockTime(); // set source refresh bool refreshSource = (param == Py_True); // try to proces texture from source try { // if source is available if (self->m_source != NULL) { // check texture code if (!self->m_orgSaved) { self->m_orgSaved = true; // save original image code if (self->m_useMatTexture) self->m_orgTex = self->m_matTexture->swapTexture(self->m_actTex); else { self->m_orgTex = self->m_imgTexture->bindcode; self->m_imgTexture->bindcode = self->m_actTex; } } // get texture unsigned int * texture = self->m_source->m_image->getImage(self->m_actTex, ts); // if texture is available if (texture != NULL) { // get texture size short * orgSize = self->m_source->m_image->getSize(); // calc scaled sizes short size[] = {ImageBase::calcSize(orgSize[0]), ImageBase::calcSize(orgSize[1])}; // scale texture if needed if (size[0] != orgSize[0] || size[1] != orgSize[1]) { // if scaled image buffer is smaller than needed if (self->m_scaledImgSize < (unsigned int)(size[0] * size[1])) { // new size self->m_scaledImgSize = size[0] * size[1]; // allocate scaling image delete [] self->m_scaledImg; self->m_scaledImg = new unsigned int[self->m_scaledImgSize]; } // scale texture gluScaleImage(GL_RGBA, orgSize[0], orgSize[1], GL_UNSIGNED_BYTE, texture, size[0], size[1], GL_UNSIGNED_BYTE, self->m_scaledImg); // use scaled image instead original texture = self->m_scaledImg; } // load texture for rendering loadTexture (self->m_actTex, texture, size, self->m_mipmap); // refresh texture source, if required if (refreshSource) self->m_source->m_image->refresh(); } } } CATCH_EXCP; }
bool BL_Action::Play(const std::string& name, float start, float end, short priority, float blendin, short play_mode, float layer_weight, short ipo_flags, float playback_speed, short blend_mode) { // Only start playing a new action if we're done, or if // the new action has a higher priority if (!IsDone() && priority > m_priority) return false; m_priority = priority; bAction* prev_action = m_action; KX_Scene* kxscene = m_obj->GetScene(); // First try to load the action m_action = (bAction*)kxscene->GetLogicManager()->GetActionByName(name); if (!m_action) { CM_Error("failed to load action: " << name); m_done = true; return false; } // If we have the same settings, don't play again // This is to resolve potential issues with pulses on sensors such as the ones // reported in bug #29412. The fix is here so it works for both logic bricks and Python. // However, this may eventually lead to issues where a user wants to override an already // playing action with the same action and settings. If this becomes an issue, // then this fix may have to be re-evaluated. if (!IsDone() && m_action == prev_action && m_startframe == start && m_endframe == end && m_priority == priority && m_speed == playback_speed) return false; // Keep a copy of the action for threading purposes if (m_tmpaction) { BKE_libblock_free(G.main, m_tmpaction); m_tmpaction = NULL; } m_tmpaction = BKE_action_copy(G.main, m_action); // First get rid of any old controllers ClearControllerList(); // Create an SG_Controller SG_Controller *sg_contr = BL_CreateIPO(m_action, m_obj, kxscene->GetSceneConverter()); m_sg_contr_list.push_back(sg_contr); m_obj->GetSGNode()->AddSGController(sg_contr); sg_contr->SetObject(m_obj->GetSGNode()); // World sg_contr = BL_CreateWorldIPO(m_action, kxscene->GetBlenderScene()->world, kxscene->GetSceneConverter()); if (sg_contr) { m_sg_contr_list.push_back(sg_contr); m_obj->GetSGNode()->AddSGController(sg_contr); sg_contr->SetObject(m_obj->GetSGNode()); } // Try obcolor sg_contr = BL_CreateObColorIPO(m_action, m_obj, kxscene->GetSceneConverter()); if (sg_contr) { m_sg_contr_list.push_back(sg_contr); m_obj->GetSGNode()->AddSGController(sg_contr); sg_contr->SetObject(m_obj->GetSGNode()); } // Now try materials for (int matidx = 1; matidx <= m_obj->GetBlenderObject()->totcol; ++matidx) { Material *mat = give_current_material(m_obj->GetBlenderObject(), matidx); if (!mat) { continue; } KX_BlenderSceneConverter *converter = kxscene->GetSceneConverter(); RAS_IPolyMaterial *polymat = converter->FindCachedPolyMaterial(kxscene, mat); if (!polymat) { continue; } sg_contr = BL_CreateMaterialIpo(m_action, mat, polymat, m_obj, converter); if (sg_contr) { m_sg_contr_list.push_back(sg_contr); m_obj->GetSGNode()->AddSGController(sg_contr); sg_contr->SetObject(m_obj->GetSGNode()); } } // Extra controllers if (m_obj->GetGameObjectType() == SCA_IObject::OBJ_LIGHT) { sg_contr = BL_CreateLampIPO(m_action, m_obj, kxscene->GetSceneConverter()); m_sg_contr_list.push_back(sg_contr); m_obj->GetSGNode()->AddSGController(sg_contr); sg_contr->SetObject(m_obj->GetSGNode()); } else if (m_obj->GetGameObjectType() == SCA_IObject::OBJ_CAMERA) { sg_contr = BL_CreateCameraIPO(m_action, m_obj, kxscene->GetSceneConverter()); m_sg_contr_list.push_back(sg_contr); m_obj->GetSGNode()->AddSGController(sg_contr); sg_contr->SetObject(m_obj->GetSGNode()); } m_ipo_flags = ipo_flags; InitIPO(); // Setup blendin shapes/poses if (m_obj->GetGameObjectType() == SCA_IObject::OBJ_ARMATURE) { BL_ArmatureObject *obj = (BL_ArmatureObject*)m_obj; obj->GetPose(&m_blendinpose); } else { BL_DeformableGameObject *obj = (BL_DeformableGameObject*)m_obj; BL_ShapeDeformer *shape_deformer = dynamic_cast<BL_ShapeDeformer*>(obj->GetDeformer()); if (shape_deformer && shape_deformer->GetKey()) { obj->GetShape(m_blendinshape); // Now that we have the previous blend shape saved, we can clear out the key to avoid any // further interference. KeyBlock *kb; for (kb=(KeyBlock *)shape_deformer->GetKey()->block.first; kb; kb=(KeyBlock *)kb->next) kb->curval = 0.f; } } // Now that we have an action, we have something we can play m_starttime = KX_GetActiveEngine()->GetFrameTime() - kxscene->getSuspendedDelta(); m_startframe = m_localframe = start; m_endframe = end; m_blendin = blendin; m_playmode = play_mode; m_blendmode = blend_mode; m_blendframe = 0.f; m_blendstart = 0.f; m_speed = playback_speed; m_layer_weight = layer_weight; m_done = false; m_appliedToObject = false; m_prevUpdate = -1.0f; return true; }
// refresh texture static PyObject *Texture_refresh(Texture *self, PyObject *args) { // get parameter - refresh source PyObject *param; double ts = -1.0; if (!PyArg_ParseTuple(args, "O|d:refresh", ¶m, &ts) || !PyBool_Check(param)) { // report error PyErr_SetString(PyExc_TypeError, "The value must be a bool"); return NULL; } // some trick here: we are in the business of loading a texture, // no use to do it if we are still in the same rendering frame. // We find this out by looking at the engine current clock time KX_KetsjiEngine* engine = KX_GetActiveEngine(); if (engine->GetClockTime() != self->m_lastClock) { self->m_lastClock = engine->GetClockTime(); // set source refresh bool refreshSource = (param == Py_True); // try to proces texture from source try { // if source is available if (self->m_source != NULL) { // check texture code if (!self->m_orgSaved) { self->m_orgSaved = true; // save original image code if (self->m_useMatTexture) self->m_orgTex = self->m_matTexture->swapTexture(self->m_actTex); else { // Swapping will work only if the GPU has already loaded the image. // If not, it will delete and overwrite our texture on next render. // To avoid that, we acquire the image buffer now. // WARNING: GPU has a ImageUser to pass, we don't. Using NULL // works on image file, not necessarily on other type of image. self->m_imgBuf = BKE_image_acquire_ibuf(self->m_imgTexture, NULL, NULL); self->m_orgTex = self->m_imgTexture->bindcode[TEXTARGET_TEXTURE_2D]; self->m_imgTexture->bindcode[TEXTARGET_TEXTURE_2D] = self->m_actTex; } } // get texture unsigned int * texture = self->m_source->m_image->getImage(self->m_actTex, ts); // if texture is available if (texture != NULL) { // get texture size short * orgSize = self->m_source->m_image->getSize(); // calc scaled sizes short size[2]; if (GLEW_ARB_texture_non_power_of_two) { size[0] = orgSize[0]; size[1] = orgSize[1]; } else { size[0] = ImageBase::calcSize(orgSize[0]); size[1] = ImageBase::calcSize(orgSize[1]); } // scale texture if needed if (size[0] != orgSize[0] || size[1] != orgSize[1]) { IMB_freeImBuf(self->m_scaledImBuf); self->m_scaledImBuf = IMB_allocFromBuffer(texture, NULL, orgSize[0], orgSize[1]); IMB_scaleImBuf(self->m_scaledImBuf, size[0], size[1]); // use scaled image instead original texture = self->m_scaledImBuf->rect; } // load texture for rendering loadTexture(self->m_actTex, texture, size, self->m_mipmap); } // refresh texture source, if required if (refreshSource) { self->m_source->m_image->refresh(); } } } CATCH_EXCP; }