//--------------------------------------------------------------------- void Viewport::clear(unsigned int buffers, const ColourValue& col, Real depth, unsigned short stencil) { RenderSystem* rs = Root::getSingleton().getRenderSystem(); if (rs) { Viewport* currentvp = rs->_getViewport(); rs->_setViewport(this); rs->clearFrameBuffer(buffers, col, depth, stencil); if (currentvp && currentvp != this) rs->_setViewport(currentvp); } }
void SDLWindow::copyContentsToMemory(const PixelBox &dst, FrameBuffer buffer) { if ((dst.left < 0) || (dst.right > mWidth) || (dst.top < 0) || (dst.bottom > mHeight) || (dst.front != 0) || (dst.back != 1)) { OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "Invalid box.", "SDLWindow::copyContentsToMemory" ); } if (buffer == FB_AUTO) { buffer = mIsFullScreen? FB_FRONT : FB_BACK; } GLenum format = Ogre::GLPixelUtil::getGLOriginFormat(dst.format); GLenum type = Ogre::GLPixelUtil::getGLOriginDataType(dst.format); if ((format == GL_NONE) || (type == 0)) { OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "Unsupported format.", "SDLWindow::copyContentsToMemory" ); } // Switch context if different from current one RenderSystem* rsys = Root::getSingleton().getRenderSystem(); rsys->_setViewport(this->getViewport(0)); // Must change the packing to ensure no overruns! glPixelStorei(GL_PACK_ALIGNMENT, 1); glReadBuffer((buffer == FB_FRONT)? GL_FRONT : GL_BACK); glReadPixels((GLint)dst.left, (GLint)dst.top, (GLsizei)dst.getWidth(), (GLsizei)dst.getHeight(), format, type, dst.data); // restore default alignment glPixelStorei(GL_PACK_ALIGNMENT, 4); //vertical flip { size_t rowSpan = dst.getWidth() * PixelUtil::getNumElemBytes(dst.format); size_t height = dst.getHeight(); uchar *tmpData = new uchar[rowSpan * height]; uchar *srcRow = (uchar *)dst.data, *tmpRow = tmpData + (height - 1) * rowSpan; while (tmpRow >= tmpData) { memcpy(tmpRow, srcRow, rowSpan); srcRow += rowSpan; tmpRow -= rowSpan; } memcpy(dst.data, tmpData, rowSpan * height); delete [] tmpData; } }
//--------------------------------------------------------------------- Viewport::~Viewport() { RenderSystem* rs = Root::getSingleton().getRenderSystem(); if ((rs) && (rs->_getViewport() == this)) { rs->_setViewport(NULL); } }
void Win32Window::writeContentsToFile(const String& filename) { ImageCodec::ImageData *imgData = new ImageCodec::ImageData(); imgData->width = mWidth; imgData->height = mHeight; imgData->depth = 1; imgData->format = PF_BYTE_RGB; // Allocate buffer uchar* pBuffer = new uchar[mWidth * mHeight * 3]; // Switch context if different from current one RenderSystem* rsys = Root::getSingleton().getRenderSystem(); rsys->_setViewport(this->getViewport(0)); // Must change the packing to ensure no overruns! glPixelStorei(GL_PACK_ALIGNMENT, 1); // Read pixels // I love GL: it does all the locking & colour conversion for us if (mIsFullScreen) glReadBuffer(GL_FRONT); glReadPixels(0,0, mWidth, mHeight, GL_RGB, GL_UNSIGNED_BYTE, pBuffer); // restore default alignment glPixelStorei(GL_PACK_ALIGNMENT, 4); // Wrap buffer in a memory stream DataStreamPtr stream(new MemoryDataStream(pBuffer, mWidth * mHeight * 3, false)); // Need to flip the read data over in Y though Image img; img.loadRawData(stream, mWidth, mHeight, imgData->format ); img.flipAroundX(); MemoryDataStreamPtr streamFlipped(new MemoryDataStream(img.getData(), stream->size(), false)); // Get codec size_t pos = filename.find_last_of("."); String extension; if( pos == String::npos ) OGRE_EXCEPT( Exception::ERR_INVALIDPARAMS, "Unable to determine image type for '" + filename + "' - invalid extension.", "Win32Window::writeContentsToFile" ); while( pos != filename.length() - 1 ) extension += filename[++pos]; // Get the codec Codec * pCodec = Codec::getCodec(extension); // Write out Codec::CodecDataPtr ptr(imgData); pCodec->codeToFile(streamFlipped, filename, ptr); delete [] pBuffer; }
void EGLWindow::copyContentsToMemory(const PixelBox &dst, FrameBuffer buffer) { if ((dst.left < 0) || (dst.right > mWidth) || (dst.top < 0) || (dst.bottom > mHeight) || (dst.front != 0) || (dst.back != 1)) { OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "Invalid box.", "Win32Window::copyContentsToMemory" ); } if (buffer == FB_AUTO) { buffer = mIsFullScreen? FB_FRONT : FB_BACK; } GLenum format = GLESPixelUtil::getGLOriginFormat(dst.format); GLenum type = GLESPixelUtil::getGLOriginDataType(dst.format); if ((format == 0) || (type == 0)) { OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "Unsupported format.", "GtkEGLWindow::copyContentsToMemory" ); } // Switch context if different from current one RenderSystem* rsys = Root::getSingleton().getRenderSystem(); rsys->_setViewport(this->getViewport(0)); #if OGRE_NO_GLES3_SUPPORT == 0 if(dst.getWidth() != dst.rowPitch) glPixelStorei(GL_PACK_ROW_LENGTH, dst.rowPitch); #endif // Must change the packing to ensure no overruns! glPixelStorei(GL_PACK_ALIGNMENT, 1); //glReadBuffer((buffer == FB_FRONT)? GL_FRONT : GL_BACK); glReadPixels((GLint)0, (GLint)(mHeight - dst.getHeight()), (GLsizei)dst.getWidth(), (GLsizei)dst.getHeight(), format, type, dst.getTopLeftFrontPixelPtr()); // restore default alignment glPixelStorei(GL_PACK_ALIGNMENT, 4); #if OGRE_NO_GLES3_SUPPORT == 0 glPixelStorei(GL_PACK_ROW_LENGTH, 0); #endif PixelUtil::bulkPixelVerticalFlip(dst); }
//--------------------------------------------------------------------- Viewport::~Viewport() { ListenerList listenersCopy; std::swap(mListeners, listenersCopy); for (ListenerList::iterator i = listenersCopy.begin(); i != listenersCopy.end(); ++i) { (*i)->viewportDestroyed(this); } RenderSystem* rs = Root::getSingleton().getRenderSystem(); if ((rs) && (rs->_getViewport() == this)) { rs->_setViewport(NULL); } }