void sdl_window_info::destroy() { sdl_window_info **prevptr; ASSERT_MAIN_THREAD(); if (multithreading_enabled) { sdlwindow_sync(); } //osd_event_wait(window->rendered_event, osd_ticks_per_second()*10); // remove us from the list for (prevptr = &sdl_window_list; *prevptr != NULL; prevptr = &(*prevptr)->m_next) if (*prevptr == this) { *prevptr = this->m_next; break; } // free the textures etc execute_async_wait(&sdlwindow_video_window_destroy_wt, worker_param(this)); // free the render target, after the textures! this->machine().render().target_free(m_target); // free the event osd_event_free(m_rendered_event); // free the lock osd_lock_free(this->m_render_lock); }
void ShaderState::DrawArrays(uint dt, size_t count) const { ASSERT_MAIN_THREAD(); glDrawArrays(dt, 0, (GLsizei)count); glReportError(); graphicsDrawCount++; }
static void sdlwindow_exit(running_machine &machine) { ASSERT_MAIN_THREAD(); mame_printf_verbose("Enter sdlwindow_exit\n"); // free all the windows while (sdl_window_list != NULL) { sdl_window_info *temp = sdl_window_list; sdl_window_list = temp->next; sdlwindow_video_window_destroy(machine, temp); } // if we're multithreaded, clean up the window thread if (multithreading_enabled) { sdlwindow_sync(); } // kill the drawers (*draw.exit)(); execute_async_wait(&sdlwindow_exit_wt, NULL); if (multithreading_enabled) { osd_work_queue_wait(work_queue, 1000000); osd_work_queue_free(work_queue); } mame_printf_verbose("Leave sdlwindow_exit\n"); }
void ShaderState::DrawElements(uint dt, size_t ic, const uint* i) const { ASSERT_MAIN_THREAD(); glDrawElements(dt, (GLsizei) ic, GL_UNSIGNED_INT, i); glReportError(); graphicsDrawCount++; }
int CScriptSystem::BeginCall(const char* sFuncName, const bool bRaiseError /* = true */) { ASSERT_MAIN_THREAD(); // Check for LUA stack corruption CheckStackOnBeginCall(); lua_getglobal(m_pLS, sFuncName); m_nTempArg = 0; #ifdef _DEBUG if (!lua_isfunction(m_pLS, -1)) { if (bRaiseError) { RaiseError(m_pLS, "Function %s not found(check for syntax errors or if the file wasn't loaded)", sFuncName); } m_nTempArg = -1; lua_pop(m_pLS, 1); m_CurrentDeep--; return 0; } #endif return 1; }
void sdlwindow_video_window_update_hi(running_machine &machine, sdl_window_info *window) { ASSERT_MAIN_THREAD(); // adjust the cursor state sdlwindow_update_cursor_state(machine, window); }
int sdl_window_info::window_init() { worker_param *wp = (worker_param *) osd_malloc(sizeof(worker_param)); int result; ASSERT_MAIN_THREAD(); // set the initial maximized state // FIXME: Does not belong here sdl_options &options = downcast<sdl_options &>(m_machine.options()); m_startmaximized = options.maximize(); // add us to the list *last_window_ptr = this; last_window_ptr = &this->m_next; set_renderer(draw.create(this)); // create an event that we can use to skip blitting m_rendered_event = osd_event_alloc(FALSE, TRUE); // load the layout m_target = m_machine.render().target_alloc(); // set the specific view set_starting_view(m_index, options.view(), options.view(m_index)); // make the window title if (video_config.numscreens == 1) sprintf(m_title, "%s: %s [%s]", emulator_info::get_appname(), m_machine.system().description, m_machine.system().name); else sprintf(m_title, "%s: %s [%s] - Screen %d", emulator_info::get_appname(), m_machine.system().description, m_machine.system().name, m_index); wp->set_window(this); // FIXME: pass error back in a different way if (multithreading_enabled) { osd_work_item *wi; wi = osd_work_item_queue(work_queue, &sdl_window_info::complete_create_wt, (void *) wp, 0); sdlwindow_sync(); result = *((int *) (osd_work_item_result)(wi)); osd_work_item_release(wi); } else result = *((int *) sdl_window_info::complete_create_wt((void *) wp, 0)); // handle error conditions if (result == 1) goto error; return 0; error: destroy(); return 1; }
void sdlwindow_video_window_update(running_machine &machine, sdl_window_info *window) { osd_ticks_t event_wait_ticks; ASSERT_MAIN_THREAD(); // adjust the cursor state sdlwindow_update_cursor_state(machine, window); // if we're visible and running and not in the middle of a resize, draw if (window->target != NULL) { int tempwidth, tempheight; // see if the games video mode has changed window->target->compute_minimum_size(tempwidth, tempheight); if (tempwidth != window->minwidth || tempheight != window->minheight) { window->minwidth = tempwidth; window->minheight = tempheight; if (!window->fullscreen) { sdlwindow_blit_surface_size(window, window->width, window->height); sdlwindow_resize(window, window->blitwidth, window->blitheight); } else if (video_config.switchres) { pick_best_mode(window, &tempwidth, &tempheight); sdlwindow_resize(window, tempwidth, tempheight); } } if (video_config.waitvsync && video_config.syncrefresh) event_wait_ticks = osd_ticks_per_second(); // block at most a second else event_wait_ticks = 0; if (osd_event_wait(window->rendered_event, event_wait_ticks)) { worker_param wp; render_primitive_list *primlist; clear_worker_param(&wp); // ensure the target bounds are up-to-date, and then get the primitives primlist = &window->get_primitives(window); // and redraw now wp.list = primlist; wp.window = window; wp.m_machine = &machine; execute_async(&draw_video_contents_wt, &wp); } } }
void ShaderProgramBase::reset() { ASSERT_MAIN_THREAD(); if (m_programHandle) { glDeleteProgram(m_programHandle); m_programHandle = 0; m_name = ""; } }
void sdl_window_info::resize(INT32 width, INT32 height) { ASSERT_MAIN_THREAD(); osd_dim cd = get_size(); if (width != cd.width() || height != cd.height()) execute_async_wait(&sdlwindow_resize_wt, worker_param(this, width, height)); }
void ShaderProgramBase::UseProgramBase(const ShaderState& ss) const { ASSERT_MAIN_THREAD(); ASSERTF(isLoaded(), "%s", m_name.c_str()); glReportError(); glUseProgram(m_programHandle); glUniformMatrix4fv(m_transformUniform, 1, GL_FALSE, &ss.uTransform[0][0]); glReportError(); }
void sdl_window_info::resize(INT32 width, INT32 height) { ASSERT_MAIN_THREAD(); osd_dim cd = get_size(); if (width != cd.width() || height != cd.height()) { auto wp = std::make_unique<worker_param>(std::static_pointer_cast<sdl_window_info>(shared_from_this()), width, height); execute_async_wait(&sdlwindow_resize_wt, std::move(wp)); } }
void sdlwindow_toggle_full_screen(running_machine &machine, sdl_window_info *window) { worker_param wp; ASSERT_MAIN_THREAD(); clear_worker_param(&wp); wp.window = window; wp.m_machine = &machine; execute_async_wait(&sdlwindow_toggle_full_screen_wt, &wp); }
void ShaderProgramBase::UnuseProgram() const { ASSERT_MAIN_THREAD(); glReportValidateShaderError(m_programHandle, m_name.c_str()); if (m_positionSlot >= 0) { glDisableVertexAttribArray(m_positionSlot); } foreach (GLuint slot, m_enabledAttribs) glDisableVertexAttribArray(slot); m_enabledAttribs.clear(); glUseProgram(0); }
void sdlwindow_video_window_update(running_machine *machine, sdl_window_info *window) { ASSERT_MAIN_THREAD(); // adjust the cursor state sdlwindow_update_cursor_state(machine, window); // if we're visible and running and not in the middle of a resize, draw if (window->target != NULL) { int tempwidth, tempheight; // see if the games video mode has changed render_target_get_minimum_size(window->target, &tempwidth, &tempheight); if (tempwidth != window->minwidth || tempheight != window->minheight) { window->minwidth = tempwidth; window->minheight = tempheight; if (!window->fullscreen) { sdlwindow_blit_surface_size(window, window->width, window->height); sdlwindow_resize(window, window->blitwidth, window->blitheight); } else if (video_config.switchres) { pick_best_mode(window, &tempwidth, &tempheight); sdlwindow_resize(window, tempwidth, tempheight); } } // only render if we have been signalled if (osd_event_wait(window->rendered_event, 0)) { worker_param wp; const render_primitive_list *primlist; clear_worker_param(&wp); // ensure the target bounds are up-to-date, and then get the primitives primlist = window->get_primitives(window); // and redraw now wp.list = primlist; wp.window = window; wp.machine = machine; execute_async(&draw_video_contents_wt, &wp); } } }
void sdl_window_info::update() { osd_ticks_t event_wait_ticks; ASSERT_MAIN_THREAD(); // adjust the cursor state //sdlwindow_update_cursor_state(machine, window); auto wp = std::make_unique<worker_param>(std::static_pointer_cast<sdl_window_info>(shared_from_this())); execute_async(&update_cursor_state_wt, std::move(wp)); // if we're visible and running and not in the middle of a resize, draw if (m_target != nullptr) { int tempwidth, tempheight; // see if the games video mode has changed m_target->compute_minimum_size(tempwidth, tempheight); if (osd_dim(tempwidth, tempheight) != m_minimum_dim) { m_minimum_dim = osd_dim(tempwidth, tempheight); if (!this->m_fullscreen) { //Don't resize window without user interaction; //window_resize(blitwidth, blitheight); } else if (video_config.switchres) { osd_dim tmp = this->pick_best_mode(); resize(tmp.width(), tmp.height()); } } if (video_config.waitvsync && video_config.syncrefresh) event_wait_ticks = osd_ticks_per_second(); // block at most a second else event_wait_ticks = 0; if (m_rendered_event.wait(event_wait_ticks)) { // ensure the target bounds are up-to-date, and then get the primitives render_primitive_list &primlist = *renderer().get_primitives(); // and redraw now auto wp = std::make_unique<worker_param>(std::static_pointer_cast<sdl_window_info>(shared_from_this()), primlist); execute_async(&draw_video_contents_wt, std::move(wp)); } } }
void glReportValidateShaderError1(const char *file, uint line, const char *function, GLuint program, const char *name) { ASSERT_MAIN_THREAD(); if (!(globals.debugRender&DBG_GLERROR) && globals.frameStep > kDebugFrames) return; glValidateProgram(program); GLint status = 0; glGetProgramiv(program, GL_VALIDATE_STATUS, &status); checkProgramInfoLog(program, "validate"); glReportError1(file, line, function); ASSERT_(status == GL_TRUE, file, line, function, "%s", name); }
static GLenum glReportFramebufferError1(const char *file, uint line, const char *function) { ASSERT_MAIN_THREAD(); if (!(globals.debugRender&DBG_GLERROR) && globals.frameStep > kDebugFrames) return GL_NO_ERROR; GLenum err = glCheckFramebufferStatus(GL_FRAMEBUFFER); if (GL_FRAMEBUFFER_COMPLETE != err) { OLG_OnAssertFailed(file, line, function, "glCheckFramebufferStatus", "%s", getGLFrameBufferStatusString(err).c_str()); } return err; }
void sdlwindow_resize(sdl_window_info *window, INT32 width, INT32 height) { worker_param wp; ASSERT_MAIN_THREAD(); if (width == window->width && height == window->height) return; clear_worker_param(&wp); wp.resize_new_width = width; wp.resize_new_height = height; wp.window = window; execute_async_wait(&sdlwindow_resize_wt, &wp); }
void sdl_window_info::set_starting_view(int index, const char *defview, const char *view) { int viewindex; ASSERT_MAIN_THREAD(); // choose non-auto over auto if (strcmp(view, "auto") == 0 && strcmp(defview, "auto") != 0) view = defview; // query the video system to help us pick a view viewindex = target()->configured_view(view, index, video_config.numscreens); // set the view target()->set_view(viewindex); }
GLenum glReportError1(const char *file, uint line, const char *function) { ASSERT_MAIN_THREAD(); if (!(globals.debugRender&DBG_GLERROR) && globals.frameStep > kDebugFrames) return GL_NO_ERROR; GLenum err = GL_NO_ERROR; while (GL_NO_ERROR != (err = glGetError())) { const char* msg = (const char *)gluErrorString(err); OLG_OnAssertFailed(file, line, function, "glGetError", "%s", msg); } return err; }
static void set_starting_view(running_machine &machine, int index, sdl_window_info *window, const char *defview, const char *view) { int viewindex; ASSERT_MAIN_THREAD(); // choose non-auto over auto if (strcmp(view, "auto") == 0 && strcmp(defview, "auto") != 0) view = defview; // query the video system to help us pick a view viewindex = window->target->configured_view(view, index, video_config.numscreens); // set the view window->target->set_view(viewindex); window->start_viewscreen=viewindex; }
void sdl_window_info::destroy() { ASSERT_MAIN_THREAD(); //osd_event_wait(window->rendered_event, osd_ticks_per_second()*10); // remove us from the list sdl_window_list.remove(std::static_pointer_cast<sdl_window_info>(shared_from_this())); // free the textures etc auto wp = std::make_unique<worker_param>(std::static_pointer_cast<sdl_window_info>(shared_from_this())); execute_async_wait(&sdlwindow_video_window_destroy_wt, std::move(wp)); // free the render target, after the textures! this->machine().render().target_free(m_target); }
static void set_starting_view(running_machine *machine, int index, sdl_window_info *window, const char *view) { const char *defview = options_get_string(machine->options(), SDLOPTION_VIEW( )); int viewindex; ASSERT_MAIN_THREAD(); // choose non-auto over auto if (strcmp(view, "auto") == 0 && strcmp(defview, "auto") != 0) view = defview; // query the video system to help us pick a view viewindex = video_get_view_for_target(machine, window->target, view, index, video_config.numscreens); // set the view render_target_set_view(window->target, viewindex); window->start_viewscreen=viewindex; }
void sdl_osd_interface::window_exit() { std::unique_ptr<worker_param> wp_dummy(nullptr); ASSERT_MAIN_THREAD(); osd_printf_verbose("Enter sdlwindow_exit\n"); // free all the windows while (!sdl_window_list.empty()) { auto window = sdl_window_list.front(); // Part of destroy removes the window from the list window->destroy(); } switch(video_config.mode) { case VIDEO_MODE_SDL2ACCEL: renderer_sdl1::exit(); break; case VIDEO_MODE_SOFT: renderer_sdl1::exit(); break; case VIDEO_MODE_BGFX: renderer_bgfx::exit(); break; #if (USE_OPENGL) case VIDEO_MODE_OPENGL: renderer_ogl::exit(); break; #endif default: break; } execute_async_wait(&sdlwindow_exit_wt, std::move(wp_dummy)); osd_printf_verbose("Leave sdlwindow_exit\n"); }
int sdl_window_info::window_init() { int result; ASSERT_MAIN_THREAD(); // set the initial maximized state // FIXME: Does not belong here sdl_options &options = downcast<sdl_options &>(m_machine.options()); m_startmaximized = options.maximize(); // add us to the list sdl_window_list.push_back(std::static_pointer_cast<sdl_window_info>(shared_from_this())); set_renderer(osd_renderer::make_for_type(video_config.mode, static_cast<osd_window*>(this)->shared_from_this())); // load the layout m_target = m_machine.render().target_alloc(); // set the specific view set_starting_view(m_index, options.view(), options.view(m_index)); // make the window title if (video_config.numscreens == 1) sprintf(m_title, "%s: %s [%s]", emulator_info::get_appname(), m_machine.system().description, m_machine.system().name); else sprintf(m_title, "%s: %s [%s] - Screen %d", emulator_info::get_appname(), m_machine.system().description, m_machine.system().name, m_index); auto wp = std::make_unique<worker_param>(std::static_pointer_cast<sdl_window_info>(shared_from_this())); result = *((int *) sdl_window_info::complete_create_wt(wp.release(), 0)); // handle error conditions if (result == 1) goto error; return 0; error: destroy(); return 1; }
void Context::RemoveAgent(Agent* pAgent) { ASSERT_MAIN_THREAD(); int agentId = pAgent->GetId(); int priority = pAgent->GetPriority(); vector<behaviac::Context::HeapItem_t>::iterator it = std::find_if(this->m_agents.begin(), this->m_agents.end(), HeapFinder_t(priority)); if (it != this->m_agents.end()) { HeapItem_t& pa = *it; Agents_t::iterator ita = pa.agents.find(agentId); if (ita != pa.agents.end()) { pa.agents.erase(ita); } } }
int CScriptSystem::BeginCall(const char* sTableName, const char* sFuncName, const bool bRaiseError /* = true */) { ASSERT_MAIN_THREAD(); // Check for LUA stack corruption CheckStackOnBeginCall(); lua_getglobal(m_pLS, sTableName); if (!lua_istable(m_pLS, -1)) { if (bRaiseError) { RaiseError(m_pLS, "(BeginCall)Table %s: not found(check for syntax errors or if the file wasn't loaded)", sTableName); } m_nTempArg = -1; lua_pop(m_pLS, 1); m_CurrentDeep--; return 0; } lua_pushstring(m_pLS, sFuncName); lua_rawget(m_pLS, - 2); lua_remove(m_pLS, - 2); // Remove table global. m_nTempArg = 0; if (!lua_isfunction(m_pLS, -1)) { if (bRaiseError) { RaiseError(m_pLS, "Function %s:%s not found(check for syntax errors or if the file wasn't loaded)", sTableName, sFuncName); } m_nTempArg = -1; lua_pop(m_pLS, 1); m_CurrentDeep--; return 0; } return 1; }
void Context::AddAgent(Agent* pAgent) { ASSERT_MAIN_THREAD(); int agentId = pAgent->GetId(); int priority = pAgent->GetPriority(); vector<behaviac::Context::HeapItem_t>::iterator it = std::find_if(this->m_agents.begin(), this->m_agents.end(), HeapFinder_t(priority)); if (it == this->m_agents.end()) { HeapItem_t pa; pa.priority = priority; pa.agents[agentId] = pAgent; this->m_agents.push_back(pa); } else { HeapItem_t& pa = *it; pa.agents[agentId] = pAgent; } }
static void sdlwindow_video_window_destroy(running_machine *machine, sdl_window_info *window) { sdl_window_info **prevptr; worker_param wp; ASSERT_MAIN_THREAD(); if (multithreading_enabled) { sdlwindow_sync(); } //osd_event_wait(window->rendered_event, osd_ticks_per_second()*10); // remove us from the list for (prevptr = &sdl_window_list; *prevptr != NULL; prevptr = &(*prevptr)->next) if (*prevptr == window) { *prevptr = window->next; break; } // free the textures etc clear_worker_param(&wp); wp.window = window; wp.machine = machine; execute_async_wait(&sdlwindow_video_window_destroy_wt, &wp); // free the render target, after the textures! if (window->target != NULL) render_target_free(window->target); // free the event osd_event_free(window->rendered_event); // free the window itself global_free(window); }