void Init( void ) { rdState.valid = true; RegisterCvars(); CreateDisplay(); glewExperimental = GL_TRUE; GLenum error = glewInit(); if ( error != GLEW_OK ) { throw( XSError( String::Format( "Failed to initialise GLEW: %s\n", glewGetErrorString( error ) ).c_str() ) ); } #ifdef RENDERER_DEBUG_OUTPUT if ( GLEW_ARB_debug_output ) { glEnable( GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB ); glDebugMessageCallbackARB( OnGLError, nullptr ); } #endif Backend::Init(); //FIXME: make these TextureManager/ShaderManager? Texture::Init(); ShaderProgram::Init(); #ifdef FBO_COMPOSITE // create composite shader static const VertexAttribute attributes[] = { { 0, "in_Position" }, { 1, "in_TexCoord" }, { 2, "in_Colour" }, }; if ( !compositeShader ) { compositeShader = new ShaderProgram( "composite", "composite", attributes, ARRAY_LEN( attributes ) ); } #endif Font::Init(); RenderCommand::Init(); glViewport( 0, 0, rdState.window.width, rdState.window.height ); }
// instance functions Framebuffer::Framebuffer() : id( 0 ), depthTexture( nullptr ), stencilTexture( 0u ) { glGenFramebuffers( 1, &id ); if ( Check() ) { if ( r_debug->GetBool() ) { console.Print( PrintLevel::Normal, "Creation of framebuffer %d completed successfully.\n", id ); } } if ( !id ) { throw( XSError( "Failed to create framebuffer" ) ); } for ( int i = 0; i < MAX_FBO_COLOR_TEXTURES; i++ ) { colourTextures[i] = nullptr; } }
static void Cmd_Quit( const CommandContext &context ) { // generic shutdown throw( XSError() ); }
static void AssertView( void ) { if ( !currentView ) { throw( XSError( "Attempted to issue render command without binding a view" ) ); } }
void Poll( void ) { SDL_Event e; while ( SDL_PollEvent( &e ) ) { switch ( e.type ) { case SDL_QUIT: { throw( XSError( "Quit application" ) ); } break; case SDL_WINDOWEVENT: { static const char *funcName = XS_FUNCTION_VERBOSE; switch ( e.window.event ) { case SDL_WINDOWEVENT_SHOWN: { if ( debug_input->GetBool() ) { console.Print( PrintLevel::Normal, "%s: Window %d shown\n", funcName, e.window.windowID ); } } break; case SDL_WINDOWEVENT_HIDDEN: { if ( debug_input->GetBool() ) { console.Print( PrintLevel::Normal, "%s: Window %d hidden\n", funcName, e.window.windowID ); } } break; case SDL_WINDOWEVENT_EXPOSED: { if ( debug_input->GetBool() ) { console.Print( PrintLevel::Normal, "%s: Window %d exposed\n", funcName, e.window.windowID ); } } break; case SDL_WINDOWEVENT_MOVED: { if ( debug_input->GetBool() ) { console.Print( PrintLevel::Normal, "%s: Window %d moved to %d,%d\n", funcName, e.window.windowID, e.window.data1, e.window.data2 ); } } break; case SDL_WINDOWEVENT_RESIZED: { if ( debug_input->GetBool() ) { console.Print( PrintLevel::Normal, "%s: Window %d resized to %dx%d\n", funcName, e.window.windowID, e.window.data1, e.window.data2 ); } } break; case SDL_WINDOWEVENT_MINIMIZED: { if ( debug_input->GetBool() ) { console.Print( PrintLevel::Normal, "%s: Window %d minimized\n", funcName, e.window.windowID ); } } break; case SDL_WINDOWEVENT_MAXIMIZED: { if ( debug_input->GetBool() ) { console.Print( PrintLevel::Normal, "%s: Window %d maximized\n", funcName, e.window.windowID ); } } break; case SDL_WINDOWEVENT_RESTORED: { if ( debug_input->GetBool() ) { console.Print( PrintLevel::Normal, "%s: Window %d restored\n", funcName, e.window.windowID ); } } break; case SDL_WINDOWEVENT_ENTER: { if ( debug_input->GetBool() ) { console.Print( PrintLevel::Normal, "%s: Mouse entered window %d\n", funcName, e.window.windowID ); } } break; case SDL_WINDOWEVENT_LEAVE: { if ( debug_input->GetBool() ) { console.Print( PrintLevel::Normal, "%s: Mouse left window %d\n", funcName, e.window.windowID ); } } break; case SDL_WINDOWEVENT_FOCUS_GAINED: { if ( debug_input->GetBool() ) { console.Print( PrintLevel::Normal, "%s: Window %d gained keyboard focus\n", funcName, e.window.windowID ); } } break; case SDL_WINDOWEVENT_FOCUS_LOST: { if ( debug_input->GetBool() ) { console.Print( PrintLevel::Normal, "%s: Window %d lost keyboard focus\n", funcName, e.window.windowID ); } } break; case SDL_WINDOWEVENT_CLOSE: { if ( debug_input->GetBool() ) { console.Print( PrintLevel::Normal, "%s: Window %d closed\n", funcName, e.window.windowID ); } } break; default: { if ( debug_input->GetBool() ) { console.Print( PrintLevel::Normal, "%s: Window %d got unknown event %d\n", funcName, e.window.windowID, e.window.event ); } } break; } } break; // ignoring these for now... case SDL_FINGERUP: case SDL_FINGERDOWN: case SDL_TEXTINPUT: { // ... } break; case SDL_FINGERMOTION: { /* const real32_t relativeMotion[2] = { e.tfinger.dx, e.tfinger.dy }; const real32_t absolutePosition[2] = { e.tfinger.x, e.tfinger.y }; console.Print( PrintLevel::Normal, "Touch motion: d( %.3f,%.3f ) - a( %.3f,%.3f )\n", relativeMotion[0], relativeMotion[1], absolutePosition[0], absolutePosition[1] ); */ } break; case SDL_MOUSEMOTION: { const int32_t relativeMotion[2] = { e.motion.xrel, e.motion.yrel }; //const int32_t absolutePosition[2] = { e.motion.x, e.motion.y }; /* console.Print( PrintLevel::Normal, "Mouse motion: d( %i,%i ) - a( %i,%i )\n", relativeMotion[0], relativeMotion[1], absolutePosition[0], absolutePosition[1] ); */ XSEvent ev( EventType::MouseMotion ); ev.mouseMotion.x = relativeMotion[0]; ev.mouseMotion.y = relativeMotion[1]; Event::Queue( &ev ); } break; case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: { XSEvent ev( EventType::MouseButton ); ev.mouseButton.button = e.button.button; ev.mouseButton.pressed = (e.button.state == SDL_PRESSED) ? true : false; //ev.mouseButton.position[0] = e.button.x; //ev.mouseButton.position[1] = e.button.y; Event::Queue( &ev ); } break; case SDL_MOUSEWHEEL: { XSEvent ev( EventType::MouseWheel ); ev.mouseWheel.up = (e.wheel.y > 0); ev.mouseWheel.amount = std::abs( e.wheel.y ); Event::Queue( &ev ); } break; case SDL_MULTIGESTURE: { #if 0 XSEvent ev( EventType::MouseWheel ); //FIXME: translate gesture events into actual mouse wheel events ev.mouseWheel.up = true; ev.mouseWheel.amount = 1u; Event::Queue( &ev ); #endif } break; case SDL_KEYDOWN: case SDL_KEYUP: { SDL_Keycode key = e.key.keysym.sym; bool pressed = (e.key.state == SDL_PRESSED); //FIXME: is this really where the keystate should be set? or should it be set when the list // is pumped keystate[key] = pressed; XSEvent ev( EventType::Keyboard ); ev.keyboard.key = key; ev.keyboard.down = pressed; Event::Queue( &ev ); } break; default: { console.Print( PrintLevel::Developer, "Unhandled SDL event %d\n", e.type ); } break; } } }