void Extent::load_0001(Iff & iff) { iff.enterForm(TAG_0001); loadSphere(iff); iff.exitForm(TAG_0001); }
void Reader::read() { int quality = 50; int width = 256; int height = 256; quality = atoi(document->FirstChildElement("scene")->FirstChildElement("properties")->FirstChildElement("quality")->FirstChild()->Value()); width = atoi(document->FirstChildElement("scene")->FirstChildElement("properties")->FirstChildElement("width")->FirstChild()->Value()); height = atoi(document->FirstChildElement("scene")->FirstChildElement("properties")->FirstChildElement("height")->FirstChild()->Value()); this->scene->setHeight(height); this->scene->setWidth(width); this->scene->setQuality(quality); printf("Width = %d, Height = %d, Quality = %d\n", width, height, quality); float ex, ey, ez; float lx, ly, lz; ex = atof(document->FirstChildElement("scene")->FirstChildElement("camera")->FirstChildElement("eye")->FirstChildElement("x")->FirstChild()->Value()); ey = atof(document->FirstChildElement("scene")->FirstChildElement("camera")->FirstChildElement("eye")->FirstChildElement("y")->FirstChild()->Value()); ez = atof(document->FirstChildElement("scene")->FirstChildElement("camera")->FirstChildElement("eye")->FirstChildElement("z")->FirstChild()->Value()); lx = atof(document->FirstChildElement("scene")->FirstChildElement("camera")->FirstChildElement("lookAt")->FirstChildElement("x")->FirstChild()->Value()); ly = atof(document->FirstChildElement("scene")->FirstChildElement("camera")->FirstChildElement("lookAt")->FirstChildElement("y")->FirstChild()->Value()); lz = atof(document->FirstChildElement("scene")->FirstChildElement("camera")->FirstChildElement("lookAt")->FirstChildElement("z")->FirstChild()->Value()); this->scene->setEyeX(ex); this->scene->setEyeY(ey); this->scene->setEyeZ(ez); this->scene->setLookAtX(lx); this->scene->setLookAtY(ly); this->scene->setLookAtZ(lz); printf("Setting camera: %f %f %f, %f %f %f\n", ex, ey, ez, lx, ly, lz); TiXmlElement *o; o = document->FirstChildElement("scene")->FirstChildElement("objects")->FirstChildElement(); while (o != NULL) { if (strcmp(o->Value(), "cube") == 0) { loadCube(o); } else if (strcmp(o->Value(), "sphere") == 0) { loadSphere(o); } o = o->NextSiblingElement(); } }
// // FUNCTION: InitInstance(HINSTANCE, int) // // PURPOSE: Saves instance handle and creates main window // // COMMENTS: // // In this function, we save the instance handle in a global variable and // create and display the main program window. // BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) { hInst = hInstance; // Store instance handle in our global variable hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL); if (!hWnd) { return FALSE; } loadSphere(); sphere->scale(80.0F,80.0F,80.0F); sphere->translate(-100.0F,-100.0F,0.0F); ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); return TRUE; }
void OpenGL2Common::paintGL() { const bool frameIsEmpty = videoFrame.isEmpty(); if (updateTimer.isActive()) updateTimer.stop(); if (frameIsEmpty && !hasImage) return; const QSize winSize = widget()->size(); bool resetDone = false; if (!frameIsEmpty && hwAccellPossibleLock()) { const GLsizei widths[3] = { videoFrame.size.width, videoFrame.size.chromaWidth(), videoFrame.size.chromaWidth(), }; const GLsizei heights[3] = { videoFrame.size.height, videoFrame.size.chromaHeight(), videoFrame.size.chromaHeight() }; if (doReset) { if (hwAccellnterface) { /* Release HWAccell resources */ hwAccellnterface->clear(false); if (hwAccellnterface->canInitializeTextures()) { if (numPlanes == 2) { //NV12 for (int p = 0; p < 2; ++p) { glBindTexture(target, textures[p + 1]); glTexImage2D(target, 0, !p ? GL_R8 : GL_RG8, widths[p], heights[p], 0, !p ? GL_RED : GL_RG, GL_UNSIGNED_BYTE, nullptr); } } else if (numPlanes == 1) { //RGB32 glBindTexture(target, textures[1]); glTexImage2D(target, 0, GL_RGBA, widths[0], heights[0], 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); } } m_textureSize = QSize(widths[0], heights[0]); if (hqScaling) { // Must be set before "HWAccelInterface::init()" and must have "m_textureSize" maybeSetMipmaps(widget()->devicePixelRatioF()); } /* Prepare textures, register GL textures */ const bool hasHwAccelError = hwAccelError; hwAccelError = !hwAccellnterface->init(&textures[1]); if (hwAccelError && !hasHwAccelError) QMPlay2Core.logError("OpenGL 2 :: " + tr("Can't init textures for") + " " + hwAccellnterface->name()); /* Prepare texture coordinates */ texCoordYCbCr[2] = texCoordYCbCr[6] = 1.0f; } else { /* Check linesize */ const qint32 halfLinesize = (videoFrame.linesize[0] >> videoFrame.size.chromaShiftW); correctLinesize = ( (halfLinesize == videoFrame.linesize[1] && videoFrame.linesize[1] == videoFrame.linesize[2]) && (!sphericalView ? (videoFrame.linesize[1] == halfLinesize) : (videoFrame.linesize[0] == widths[0])) ); /* Prepare textures */ for (qint32 p = 0; p < 3; ++p) { const GLsizei w = correctLinesize ? videoFrame.linesize[p] : widths[p]; const GLsizei h = heights[p]; if (p == 0) m_textureSize = QSize(w, h); if (hasPbo) { glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo[p + 1]); glBufferData(GL_PIXEL_UNPACK_BUFFER, w * h, nullptr, GL_DYNAMIC_DRAW); } glBindTexture(GL_TEXTURE_2D, textures[p + 1]); glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, w, h, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, nullptr); } /* Prepare texture coordinates */ texCoordYCbCr[2] = texCoordYCbCr[6] = (videoFrame.linesize[0] == widths[0]) ? 1.0f : (widths[0] / (videoFrame.linesize[0] + 1.0f)); if (hqScaling) maybeSetMipmaps(widget()->devicePixelRatioF()); } resetDone = true; hasImage = false; } if (hwAccellnterface) { const HWAccelInterface::Field field = (HWAccelInterface::Field)Functions::getField(videoFrame, Deinterlace, HWAccelInterface::FullFrame, HWAccelInterface::TopField, HWAccelInterface::BottomField); bool imageReady = false; if (!hwAccelError) { const HWAccelInterface::CopyResult res = hwAccellnterface->copyFrame(videoFrame, field); if (res == HWAccelInterface::CopyOk) imageReady = true; else if (res == HWAccelInterface::CopyError) { QMPlay2Core.logError("OpenGL 2 :: " + hwAccellnterface->name() + " " + tr("texture copy error")); hwAccelError = true; } } hwAccellnterface->unlock(); if (!imageReady && !hasImage) return; for (int p = 0; p < numPlanes; ++p) { glActiveTexture(GL_TEXTURE0 + p); glBindTexture(target, textures[p + 1]); if (m_useMipmaps) glGenerateMipmap(target); } } else { /* Load textures */ for (qint32 p = 0; p < 3; ++p) { const quint8 *data = videoFrame.buffer[p].constData(); const GLsizei w = correctLinesize ? videoFrame.linesize[p] : widths[p]; const GLsizei h = heights[p]; if (hasPbo) { glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo[p + 1]); quint8 *dst; if (glMapBufferRange) dst = (quint8 *)glMapBufferRange(GL_PIXEL_UNPACK_BUFFER, 0, w * h, GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT); else dst = (quint8 *)glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY); if (!dst) glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); else { if (correctLinesize) memcpy(dst, data, w * h); else for (int y = 0; y < h; ++y) { memcpy(dst, data, w); data += videoFrame.linesize[p]; dst += w; } glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER); data = nullptr; } } glActiveTexture(GL_TEXTURE0 + p); glBindTexture(GL_TEXTURE_2D, textures[p + 1]); if (hasPbo || correctLinesize) glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_LUMINANCE, GL_UNSIGNED_BYTE, data); else for (int y = 0; y < h; ++y) { glTexSubImage2D(GL_TEXTURE_2D, 0, 0, y, w, 1, GL_LUMINANCE, GL_UNSIGNED_BYTE, data); data += videoFrame.linesize[p]; } if (m_useMipmaps) glGenerateMipmap(GL_TEXTURE_2D); } if (hasPbo) glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); } videoFrame.clear(); hasImage = true; } if (!sphericalView) { deleteSphereVbo(); shaderProgramVideo->setAttributeArray(positionYCbCrLoc, verticesYCbCr[verticesIdx], 2); shaderProgramVideo->setAttributeArray(texCoordYCbCrLoc, texCoordYCbCr, 2); } else { if (nIndices == 0) loadSphere(); glBindBuffer(GL_ARRAY_BUFFER, sphereVbo[0]); shaderProgramVideo->setAttributeBuffer(positionYCbCrLoc, GL_FLOAT, 0, 3); glBindBuffer(GL_ARRAY_BUFFER, sphereVbo[1]); shaderProgramVideo->setAttributeBuffer(texCoordYCbCrLoc, GL_FLOAT, 0, 2); glBindBuffer(GL_ARRAY_BUFFER, 0); } shaderProgramVideo->enableAttributeArray(positionYCbCrLoc); shaderProgramVideo->enableAttributeArray(texCoordYCbCrLoc); shaderProgramVideo->bind(); if (doReset) { const float brightness = videoAdjustment.brightness / 100.0f; const float contrast = (videoAdjustment.contrast + 100) / 100.0f; const float sharpness = videoAdjustment.sharpness / 50.0f; if (hwAccellnterface && numPlanes == 1) { hwAccellnterface->setVideAdjustment(videoAdjustment); const bool hasBrightness = videoAdjustmentKeys.contains("Brightness"); const bool hasContrast = videoAdjustmentKeys.contains("Contrast"); const bool hasSharpness = videoAdjustmentKeys.contains("Sharpness"); shaderProgramVideo->setUniformValue ( "uVideoAdj", hasBrightness ? 0.0f : brightness, hasContrast ? 1.0f : contrast, hasSharpness ? 0.0f : sharpness ); } else { const float saturation = (videoAdjustment.saturation + 100) / 100.0f; const float hue = videoAdjustment.hue / -31.831f; shaderProgramVideo->setUniformValue("uVideoEq", brightness, contrast, saturation, hue); shaderProgramVideo->setUniformValue("uSharpness", sharpness); } if (hqScaling) { const qreal dpr = widget()->devicePixelRatioF(); if (!resetDone) maybeSetMipmaps(dpr); const bool useBicubic = (W * dpr > m_textureSize.width() || H * dpr > m_textureSize.height()); shaderProgramVideo->setUniformValue("uBicubic", useBicubic ? 1 : 0); } shaderProgramVideo->setUniformValue("uTextureSize", m_textureSize); doReset = !resetDone; setMatrix = true; } if (setMatrix) { QMatrix4x4 matrix; if (!sphericalView) { matrix.scale(W / (qreal)winSize.width(), H / (qreal)winSize.height()); if (!videoOffset.isNull()) matrix.translate(-videoOffset.x(), videoOffset.y()); } else { const double z = qBound(-1.0, (zoom > 1.0 ? log10(zoom) : zoom - 1.0), 0.99); matrix.perspective(68.0, (qreal)winSize.width() / (qreal)winSize.height(), 0.001, 2.0); matrix.translate(0.0, 0.0, z); matrix.rotate(rot.x(), 1.0, 0.0, 0.0); matrix.rotate(rot.y(), 0.0, 0.0, 1.0); } shaderProgramVideo->setUniformValue("uMatrix", matrix); setMatrix = false; } if (!sphericalView) glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); else { glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, sphereVbo[2]); glDrawElements(GL_TRIANGLE_STRIP, nIndices, GL_UNSIGNED_SHORT, nullptr); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } shaderProgramVideo->release(); shaderProgramVideo->disableAttributeArray(texCoordYCbCrLoc); shaderProgramVideo->disableAttributeArray(positionYCbCrLoc); glActiveTexture(GL_TEXTURE3); /* OSD */ osdMutex.lock(); if (!osdList.isEmpty()) { glBindTexture(GL_TEXTURE_2D, textures[0]); QRect bounds; const qreal scaleW = (qreal)subsW / outW, scaleH = (qreal)subsH / outH; bool mustRepaint = Functions::mustRepaintOSD(osdList, osd_ids, &scaleW, &scaleH, &bounds); bool hasNewSize = false; if (!mustRepaint) mustRepaint = osdImg.size() != bounds.size(); if (mustRepaint) { if (osdImg.size() != bounds.size()) { osdImg = QImage(bounds.size(), QImage::Format_ARGB32); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, bounds.width(), bounds.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); hasNewSize = true; } osdImg.fill(0); QPainter p(&osdImg); p.translate(-bounds.topLeft()); Functions::paintOSD(false, osdList, scaleW, scaleH, p, &osd_ids); const quint8 *data = osdImg.constBits(); if (hasPbo) { const GLsizeiptr dataSize = (osdImg.width() * osdImg.height()) << 2; glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo[0]); if (hasNewSize) glBufferData(GL_PIXEL_UNPACK_BUFFER, dataSize, nullptr, GL_DYNAMIC_DRAW); quint8 *dst; if (glMapBufferRange) dst = (quint8 *)glMapBufferRange(GL_PIXEL_UNPACK_BUFFER, 0, dataSize, GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT); else dst = (quint8 *)glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY); if (!dst) glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); else { memcpy(dst, data, dataSize); glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER); data = nullptr; } } glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, bounds.width(), bounds.height(), GL_RGBA, GL_UNSIGNED_BYTE, data); if (hasPbo && !data) glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); } const QSizeF winSizeSubs = winSize * widget()->devicePixelRatioF(); const float left = (bounds.left() + subsX) * 2.0f / winSizeSubs.width() - osdOffset.x(); const float right = (bounds.right() + subsX + 1) * 2.0f / winSizeSubs.width() - osdOffset.x(); const float top = (bounds.top() + subsY) * 2.0f / winSizeSubs.height() - osdOffset.y(); const float bottom = (bounds.bottom() + subsY + 1) * 2.0f / winSizeSubs.height() - osdOffset.y(); const float verticesOSD[8] = { left - 1.0f, -bottom + 1.0f, right - 1.0f, -bottom + 1.0f, left - 1.0f, -top + 1.0f, right - 1.0f, -top + 1.0f, }; shaderProgramOSD->setAttributeArray(positionOSDLoc, verticesOSD, 2); shaderProgramOSD->setAttributeArray(texCoordOSDLoc, texCoordOSD, 2); shaderProgramOSD->enableAttributeArray(positionOSDLoc); shaderProgramOSD->enableAttributeArray(texCoordOSDLoc); glEnable(GL_BLEND); shaderProgramOSD->bind(); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); shaderProgramOSD->release(); glDisable(GL_BLEND); shaderProgramOSD->disableAttributeArray(texCoordOSDLoc); shaderProgramOSD->disableAttributeArray(positionOSDLoc); } osdMutex.unlock(); glBindTexture(GL_TEXTURE_2D, 0); }