X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2Fmoof%2Fvideo.cc;h=c4e8fd855e9c1f2f597d495eeda6ef100adeaea7;hp=32278cc77ca25422e72595fffab04eeb692040b2;hb=HEAD;hpb=831f04d4bc19a390415ac0bbac4331c7a65509bc diff --git a/src/moof/video.cc b/src/moof/video.cc index 32278cc..c4e8fd8 100644 --- a/src/moof/video.cc +++ b/src/moof/video.cc @@ -1,14 +1,17 @@ -/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +/*] Copyright (c) 2009-2011, Charles McGarvey [***************************** **] All rights reserved. * -* vi:ts=4 sw=4 tw=75 -* * Distributable under the terms and conditions of the 2-clause BSD license; * see the file COPYING for a complete text of the license. * -**************************************************************************/ +*****************************************************************************/ + +#if HAVE_CONFIG_H +#include "config.h" +#endif +#include #include #include "dispatcher.hh" @@ -54,6 +57,8 @@ void video::init() mode(attributes_.mode); if (!current_) make_current(); + + show_fps(false); } void video::recreate_context() @@ -66,56 +71,52 @@ void video::recreate_context() void video::set_opengl_attributes() { SDL_GL_SetAttribute(SDL_GL_RED_SIZE, - attributes_.color_buffer[0]); + attributes_.color_buffer[0]); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, - attributes_.color_buffer[1]); + attributes_.color_buffer[1]); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, - attributes_.color_buffer[2]); + attributes_.color_buffer[2]); SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, - attributes_.color_buffer[3]); + attributes_.color_buffer[3]); SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, - attributes_.frame_buffer); + attributes_.frame_buffer); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, - attributes_.is_double_buffer); + attributes_.is_double_buffer); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, - attributes_.depth_buffer); + attributes_.depth_buffer); SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, - attributes_.stencil_buffer); + attributes_.stencil_buffer); SDL_GL_SetAttribute(SDL_GL_ACCUM_RED_SIZE, - attributes_.accumulator_buffer[0]); + attributes_.accumulator_buffer[0]); SDL_GL_SetAttribute(SDL_GL_ACCUM_GREEN_SIZE, - attributes_.accumulator_buffer[1]); + attributes_.accumulator_buffer[1]); SDL_GL_SetAttribute(SDL_GL_ACCUM_BLUE_SIZE, - attributes_.accumulator_buffer[2]); + attributes_.accumulator_buffer[2]); SDL_GL_SetAttribute(SDL_GL_ACCUM_ALPHA_SIZE, - attributes_.accumulator_buffer[3]); + attributes_.accumulator_buffer[3]); SDL_GL_SetAttribute(SDL_GL_STEREO, - attributes_.is_stereo); + attributes_.is_stereo); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, - attributes_.multisample_buffers); + 0 < attributes_.multisamples); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, - attributes_.multisample_samples); + attributes_.multisamples); SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, - attributes_.is_swap_control); + attributes_.is_swap_control); SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, - attributes_.is_hardware_only); + attributes_.is_hardware_only); } - video::~video() { SDL_FreeSurface(context_); - if (current_ == this) current_ = 0; } - class video::attributes video::attributes() const { return attributes_; } - void video::mode(const int mode[3]) { if (mode != attributes_.mode || !context_) @@ -131,19 +132,18 @@ void video::mode(const int mode[3]) attributes_.mode[1] = mode[1]; attributes_.mode[2] = mode[2]; -#if !defined(linux) && !defined(__linux) && !defined(__linux__) +#if PLATFORM_WIN32 log_info("video context recreated"); dispatcher::global().dispatch("video.newcontext"); #endif } else { - throw std::runtime_error("bad video mode attempted"); + throw std::runtime_error(SDL_GetError()); } } } - void video::resize(int width, int height) { int mode[] = {width, height, attributes_.mode[2]}; @@ -155,20 +155,17 @@ bool video::iconify() return SDL_WM_IconifyWindow(); } - void video::caption(const std::string& caption) { + caption_ = caption; SDL_WM_SetCaption(caption.c_str(), 0); } -std::string video::caption() const +const std::string& video::caption() const { - char* caption; - SDL_WM_GetCaption(&caption, 0); - return std::string(caption); + return caption_; } - void video::fullscreen(bool full) { if (full != fullscreen() || !context_) @@ -177,7 +174,7 @@ void video::fullscreen(bool full) { flags_ ^= SDL_FULLSCREEN; -#if defined(linux) || defined(__linux) || defined(__linux__) +#if PLATFORM_POSIX if (SDL_WM_ToggleFullScreen(context_) == 0) #endif recreate_context(); @@ -200,7 +197,6 @@ void video::toggle_fullscreen() fullscreen(!fullscreen()); } - void video::resizable(bool is_resizable) { if (is_resizable != resizable() || !context_) @@ -228,7 +224,6 @@ void video::toggle_resizable() resizable(!resizable()); } - void video::cursor_visible(bool is_cursor_visible) { SDL_ShowCursor(is_cursor_visible? SDL_ENABLE : SDL_DISABLE); @@ -244,7 +239,6 @@ void video::toggle_cursor_visible() cursor_visible(!cursor_visible()); } - bool video::cursor_captured() const { return (SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_ON); @@ -260,13 +254,29 @@ void video::toggle_cursor_captured() cursor_captured(!cursor_captured()); } - -void video::swap() +void video::swap(scalar t) { + if (show_fps_) + { + scalar dt = t - last_swap_; + last_swap_ = t; + + fps_accumulator_ += dt; + if (SCALAR(1.0) <= fps_accumulator_) + { + std::ostringstream stream; + stream << caption_ << " - " << fps_counter_ << " fps"; + SDL_WM_SetCaption(stream.str().c_str(), 0); + + fps_accumulator_ -= SCALAR(1.0); + fps_counter_ = 0; + } + + ++fps_counter_; + } SDL_GL_SwapBuffers(); } - int video::width() const { return context_->w; @@ -277,7 +287,6 @@ int video::height() const return context_->h; } - void video::make_current() const { current_ = const_cast(this); @@ -313,15 +322,14 @@ video::attributes::attributes(const settings& settings) if (accum.size() > 3) accumulator_buffer[3] = accum[3]; settings.get("stereo", is_stereo); - settings.get("multiesamplebuffers", multisample_buffers); - settings.get("multiesamplesamples", multisample_samples); + settings.get("multisamples", multisamples); settings.get("swapcontrol", is_swap_control); settings.get("hardwareonly", is_hardware_only); settings.get("fullscreen", is_fullscreen); settings.get("resizable", is_resizable); settings.get("showcursor", is_cursor_visible); - settings.get("grab", is_cursor_captured); + settings.get("capturecursor", is_cursor_captured); std::vector dimensions; settings.get("videomode", dimensions); @@ -332,17 +340,15 @@ video::attributes::attributes(const settings& settings) } else if (is_fullscreen && backend::is_initialized()) { - SDL_Rect** modes = SDL_ListModes(NULL, - SDL_FULLSCREEN | SDL_HWSURFACE); + SDL_Rect** modes = SDL_ListModes(NULL, SDL_FULLSCREEN | SDL_HWSURFACE); if (modes == (SDL_Rect**)0) { - log_error("no native video mode"); + throw std::runtime_error("can't find appropriate video mode"); } else if (modes == (SDL_Rect**)-1) { - log_warning("any resolution allowed; " - "choosing default 800x600"); + log_warning("any resolution allowed; choosing default 800x600"); mode[0] = 800; mode[1] = 600; } @@ -350,8 +356,8 @@ video::attributes::attributes(const settings& settings) { mode[0] = (*modes)->w; mode[1] = (*modes)->h; - log_info << "choosing native resolution " - << mode[0] << "x" << mode[1] << std::endl; + log_info << "choosing native resolution: " + << mode[0] << "x" << mode[1] << std::endl; } } if (dimensions.size() > 2) mode[2] = dimensions[2]; @@ -373,8 +379,7 @@ void video::attributes::init() accumulator_buffer[2] = 0; accumulator_buffer[3] = 0; is_stereo = false; - multisample_buffers = 0; - multisample_samples = 0; + multisamples = 0; is_swap_control = false; is_hardware_only = false; mode[0] = 640;