void MGLES2RendererPrivate::init() { m_initialized = true; //init world matrix for the known parts //parts that are changeable by the transformation //are set when rendering in the textures m_matWorld[0][2] = 0.0; m_matWorld[1][2] = 0.0; m_matWorld[2][0] = 0.0; m_matWorld[2][1] = 0.0; m_matWorld[2][2] = 1.0; m_matWorld[2][3] = 0.0; m_matWorld[3][2] = 0.0; //init vertex and texcoord arrays, 4 first vertices are used to draw standard //pixmaps and all the remaining vertices can be used to draw dynamic geometries //like scalable images and other patched stuff, the vertices are packed into same //array so that we don't need to switch the used array on fly. m_vertices.resize(8 + (9 * 4 * 2)); m_texCoords.resize(8 + (9 * 4 * 2)); GLfloat *tc = m_texCoords.data(); tc[0] = 0.0; tc[1] = 1.0; tc[2] = 0.0; tc[3] = 0.0; tc[4] = 1.0; tc[5] = 0.0; tc[6] = 1.0; tc[7] = 1.0; //init index array that is used to draw dynamic geometries //the indices are offset by 4 because the 4 vertices that //are used to draw normal pixmaps are in the beginning of //the array m_indices.resize(9 * 6); GLushort *indices = m_indices.data(); for (GLuint i = 0; i < 9; i++) { indices[i*6+0] = 4 + (i * 4 + 0); //x1 y1 TL indices[i*6+1] = 4 + (i * 4 + 1); //x1 y2 BL indices[i*6+2] = 4 + (i * 4 + 2); //x2 y2 BR indices[i*6+3] = 4 + (i * 4 + 0); //x1 y1 TL indices[i*6+4] = 4 + (i * 4 + 2); //x2 y2 BR indices[i*6+5] = 4 + (i * 4 + 3); //x2 y1 TR } m_glContext->makeCurrent(); //init the orthogonal projection matrix //glOrtho(0, w, h, 0, -1, 1): //2.0/w, 0.0, 0.0, -1.0 //0.0, -2.0/h, 0.0, 1.0 //0.0, 0.0, -1.0, 0.0 //0.0, 0.0, 0.0, 1.0 GLfloat w = m_glContext->device()->width(); GLfloat h = m_glContext->device()->height(); m_matProj[0][0] = 2.0f / w; m_matProj[1][0] = 0.0; m_matProj[2][0] = 0.0; m_matProj[3][0] = -1.0; m_matProj[0][1] = 0.0; m_matProj[1][1] = -2.0f / h; m_matProj[2][1] = 0.0; m_matProj[3][1] = 1.0; m_matProj[0][2] = 0.0; m_matProj[1][2] = 0.0; m_matProj[2][2] = -1.0; m_matProj[3][2] = 0.0; m_matProj[0][3] = 0.0; m_matProj[1][3] = 0.0; m_matProj[2][3] = 0.0; m_matProj[3][3] = 1.0; }
void SN_CheckerGL::doInit() { if (!scene()) { qCritical() << "SN_CheckerGL::doInit() : I'm not added to the scene yet"; } QGLContext *ctx = const_cast<QGLContext *>(QGLContext::currentContext()); if (!ctx || ctx->device()->paintEngine()->type() != QPaintEngine::OpenGL2 ) { qCritical() << "\n\n !! SN_CheckerGL::doInit() : no OpenGL context !!"; } // // init opengl related stuff // glGenTextures(1, &_textureid); glDisable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_RECTANGLE_ARB); glBindTexture(GL_TEXTURE_RECTANGLE_ARB, _textureid); glTexParameterf(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameterf(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexParameterf(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameterf(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST); // internal format 2 -> the number of color components in the texture glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, _pixelFormat, _imgsize.width(), _imgsize.height(), 0, _pixelFormat, GL_UNSIGNED_BYTE, (void *)0 /*static_cast<QImage *>(doubleBuffer->getFrontBuffer())->bits()*/); glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0); glDisable(GL_TEXTURE_RECTANGLE_ARB); glEnable(GL_TEXTURE_2D); // // init worker // _workerThread->setBufPtr(_image->bits()); // now worker is ready to work // run the thread _workerThread->start(); // writeData() will call itself continuously (as long as the eventloop of the thread is running) // if ( ! QMetaObject::invokeMethod(_workerThread, "writeData", Qt::QueuedConnection) ) { // qDebug() << "SN_CheckerGL::doInit() : Failed to invoke Worker::writeData()"; // } scheduleUpdate(); }
void SN_CheckerGLPBO::doInit() { if (!scene()) { qCritical() << "SN_CheckerGLPBO::doInit() : I'm not added to the scene yet"; } QGLContext *ctx = const_cast<QGLContext *>(QGLContext::currentContext()); if (!ctx || ctx->device()->paintEngine()->type() != QPaintEngine::OpenGL2 ) { qCritical() << "\n\n !! SN_CheckerGLPBO::doInit() : no OpenGL context !!"; } glGenTextures(1, &_textureid); glDisable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_RECTANGLE_ARB); glBindTexture(GL_TEXTURE_RECTANGLE_ARB, _textureid); glTexParameterf(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameterf(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexParameterf(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameterf(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST); // internal format 2 -> the number of color components in the texture glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, _pixelFormat, _imgsize.width(), _imgsize.height(), 0, _pixelFormat, GL_UNSIGNED_BYTE, (void *)0 /*static_cast<QImage *>(doubleBuffer->getFrontBuffer())->bits()*/); //glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, _pixelFormat, size().width(), size().height(), 0, _pixelFormat, GL_UNSIGNED_BYTE, (void *)0); glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0); glDisable(GL_TEXTURE_RECTANGLE_ARB); glEnable(GL_TEXTURE_2D); // // init mutex // if ( ! _initPboMutex() ) { qDebug() << "Failed to init mutex !"; } _workerThread->setPboMutex(_pbomutex); _workerThread->setPboCondition(_pbobufferready); for(int i=0; i<2; i++) { _pbobuf[i] = new QGLBuffer(QGLBuffer::PixelUnpackBuffer); _pbobuf[i]->create(); _pbobuf[i]->bind(); _pbobuf[i]->allocate(_appInfo->frameSizeInByte()); _pboIds[i] = _pbobuf[i]->bufferId(); } QGLBuffer::release(QGLBuffer::PixelUnpackBuffer); // run the thread _workerThread->start(); scheduleUpdate(); // writeData() will call itself continuously (as long as the eventloop of the thread is running) // if ( ! QMetaObject::invokeMethod(_workerThread, "writeData", Qt::QueuedConnection) ) { // qDebug() << "SN_CheckerGL::doInit() : Failed to invoke Worker::writeData()"; // } }