// TODO: set surface/device size here (viewport?) void OpenGLVideo::setOpenGLContext(QOpenGLContext *ctx) { DPTR_D(OpenGLVideo); if (!ctx) { d.resetGL(); return; } #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) d.manager = ctx->findChild<ShaderManager*>(QStringLiteral("__qtav_shader_manager")); QSizeF surfaceSize = QOpenGLContext::currentContext()->surface()->size(); #else d.resetGL(); QSizeF surfaceSize = QSizeF(ctx->device()->width(), ctx->device()->height()); #endif d.ctx = ctx; // Qt4: set to null in resetGL() setProjectionMatrixToRect(QRectF(QPointF(), surfaceSize)); if (d.manager) return; // TODO: what if ctx is delete? d.manager = new ShaderManager(ctx); d.manager->setObjectName(QStringLiteral("__qtav_shader_manager")); #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) QObject::connect(ctx, SIGNAL(aboutToBeDestroyed()), this, SLOT(resetGL()), Qt::DirectConnection); //direct? #endif }
void Arc::GraphicsSystem::setWindowSize( Size size ) { _windowSize = size; resetVideoMode(); resetGL(); dispatchEvent(Event(EVENT_WINDOW_SIZE_CHANGED)); }
void Arc::GraphicsSystem::setFullscreen( bool fullscreen ) { _fullscreen = fullscreen; resetVideoMode(); resetGL(); dispatchEvent(Event(EVENT_FULLSCREEN_CHANGED)); }
// TODO: set surface/device size here (viewport?) void OpenGLVideo::setOpenGLContext(QOpenGLContext *ctx) { DPTR_D(OpenGLVideo); if (d.ctx == ctx) return; d.resetGL(); //TODO: is it ok to destroygl resources in another context? d.ctx = ctx; // Qt4: set to null in resetGL() if (!ctx) { return; } if (d.material) delete d.material; d.material = new VideoMaterial(); #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) d.manager = ctx->findChild<ShaderManager*>(QStringLiteral("__qtav_shader_manager")); QSizeF surfaceSize = QOpenGLContext::currentContext()->surface()->size(); #else QSizeF surfaceSize = QSizeF(ctx->device()->width(), ctx->device()->height()); #endif setProjectionMatrixToRect(QRectF(QPointF(), surfaceSize)); if (d.manager) return; // TODO: what if ctx is delete? d.manager = new ShaderManager(ctx); d.manager->setObjectName(QStringLiteral("__qtav_shader_manager")); #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) QObject::connect(ctx, SIGNAL(aboutToBeDestroyed()), this, SLOT(resetGL()), Qt::DirectConnection); //direct? #endif /// get gl info here because context is current(qt ensure it) //const QByteArray extensions(reinterpret_cast<const char *>(glGetString(GL_EXTENSIONS))); bool hasGLSL = QOpenGLShaderProgram::hasOpenGLShaderPrograms(); qDebug("OpenGL version: %d.%d hasGLSL: %d", ctx->format().majorVersion(), ctx->format().minorVersion(), hasGLSL); static bool sInfo = true; if (sInfo) { sInfo = false; qDebug("GL_VERSION: %s", DYGL(glGetString(GL_VERSION))); qDebug("GL_VENDOR: %s", DYGL(glGetString(GL_VENDOR))); qDebug("GL_RENDERER: %s", DYGL(glGetString(GL_RENDERER))); qDebug("GL_SHADING_LANGUAGE_VERSION: %s", DYGL(glGetString(GL_SHADING_LANGUAGE_VERSION))); /// check here with current context can ensure the right result. If the first check is in VideoShader/VideoMaterial/decoder or somewhere else, the context can be null bool v = OpenGLHelper::isOpenGLES(); qDebug("Is OpenGLES: %d", v); v = OpenGLHelper::isEGL(); qDebug("Is EGL: %d", v); const int glsl_ver = OpenGLHelper::GLSLVersion(); qDebug("GLSL version: %d", glsl_ver); v = OpenGLHelper::isPBOSupported(); qDebug("Has PBO: %d", v); v = OpenGLHelper::has16BitTexture(); qDebug("Has 16bit texture: %d", v); v = OpenGLHelper::hasRG(); qDebug("Has RG texture: %d", v); qDebug() << ctx->format(); } }
Framework::Framework(void *surf, const Configuration& conf, Networkstate initial) : field(this), output(this), surface((SDL_Surface*)surf), version(conf.version), paused(1), timeunit(1), lasttime(SDL_GetTicks()), frames(0), state(initial), xdiff(0), camera(conf.width, conf.height) { /* initialize OpenGL */ resetGL(); /* set up the window */ camera.init(); if (conf.fullscreen) SDL_WM_ToggleFullScreen(surface); /* set unpaused state (grab input) */ togglePause(false, false); }
void Framework::handleMouseMove(int x, int y, unsigned char buttons) { if (buttons & SDL_BUTTON(SDL_BUTTON_RIGHT)) { camera.adjustAngle((double)x / 10.0, (double)y / 10.0); } else if (buttons & SDL_BUTTON(SDL_BUTTON_MIDDLE)) { camera.adjustDistance((double)y / 10.0); resetGL(); } else { if (!paused) movePaddle((double)x / 50.0, (double)-y / 50.0, SDL_GetTicks()); if (camera.getMode() == Camera::FOLLOW_PADDLE) camera.adjustAngle((double)-x / 20.0, (double)-y / 20.0); else if (camera.getMode() == Camera::FOLLOW_PADDLE_REVERSE) camera.adjustAngle((double)x / 20.0, (double)y / 20.0); } }
Arc::GraphicsSystem::GraphicsSystem( Program* pProgram, Size windowSize, string windowTitle, Color clearColor, bool fullscreen ) : SystemComponent(pProgram), _clearColor(clearColor), _pRenderTarget(nullptr), _screenBPP(), _windowSize(windowSize), _windowTitle(windowTitle), _fullscreen(fullscreen) { INFO(toString(), "Initializing"); addType(SYS_CMP_TYPE_GRAPHICS); // Set SDL/OpenGL constants SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32); SDL_GL_SetAttribute(SDL_GL_ACCUM_RED_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_ACCUM_GREEN_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_ACCUM_BLUE_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_ACCUM_ALPHA_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); setWindowTitle(_windowTitle); resetVideoMode(); // Create the window resetGL(); // Initialize OpenGL _pRenderTarget = New RenderTarget(this); if (TTF_Init() < 0) // Initialize the SDL TTF Addon for loading Fonts { ERROR(toString(), "Failed to initialize TTF Addon"); die(); } INFO(toString(), "Complete"); }