本文整理汇总了C++中PixelBox::getDepth方法的典型用法代码示例。如果您正苦于以下问题:C++ PixelBox::getDepth方法的具体用法?C++ PixelBox::getDepth怎么用?C++ PixelBox::getDepth使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PixelBox
的用法示例。
在下文中一共展示了PixelBox::getDepth方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: toOgre
//-----------------------------------------------------------------------
void ILUtil::toOgre(const PixelBox &dst)
{
if(!dst.isConsecutive())
OGRE_EXCEPT( Exception::ERR_NOT_IMPLEMENTED,
"Destination must currently be consecutive",
"ILUtil::ilToOgre" ) ;
if(dst.getWidth() != static_cast<size_t>(ilGetInteger( IL_IMAGE_WIDTH )) ||
dst.getHeight() != static_cast<size_t>(ilGetInteger( IL_IMAGE_HEIGHT )) ||
dst.getDepth() != static_cast<size_t>(ilGetInteger( IL_IMAGE_DEPTH )))
OGRE_EXCEPT( Exception::ERR_INVALIDPARAMS,
"Destination dimensions must equal IL dimension",
"ILUtil::ilToOgre" ) ;
int ilfmt = ilGetInteger( IL_IMAGE_FORMAT );
int iltp = ilGetInteger( IL_IMAGE_TYPE );
// Check if in-memory format just matches
// If yes, we can just copy it and save conversion
ILFormat ifmt = OgreFormat2ilFormat( dst.format );
if(ifmt.format == ilfmt && ILabs(ifmt.type) == ILabs(iltp)) {
memcpy(dst.data, ilGetData(), ilGetInteger( IL_IMAGE_SIZE_OF_DATA ));
return;
}
// Try if buffer is in a known OGRE format so we can use OGRE its
// conversion routines
PixelFormat bufFmt = ilFormat2OgreFormat((int)ilfmt, (int)iltp);
ifmt = OgreFormat2ilFormat( bufFmt );
if(ifmt.format == ilfmt && ILabs(ifmt.type) == ILabs(iltp))
{
// IL format matches another OGRE format
PixelBox src(dst.getWidth(), dst.getHeight(), dst.getDepth(), bufFmt, ilGetData());
PixelUtil::bulkPixelConversion(src, dst);
return;
}
// Thee extremely slow method
if(iltp == IL_UNSIGNED_BYTE || iltp == IL_BYTE)
{
ilToOgreInternal(static_cast<uint8*>(dst.data), dst.format, (uint8)0x00,(uint8)0x00,(uint8)0x00,(uint8)0xFF);
}
else if(iltp == IL_FLOAT)
{
ilToOgreInternal(static_cast<uint8*>(dst.data), dst.format, 0.0f,0.0f,0.0f,1.0f);
}
else if(iltp == IL_SHORT || iltp == IL_UNSIGNED_SHORT)
{
ilToOgreInternal(static_cast<uint8*>(dst.data), dst.format,
(uint16)0x0000,(uint16)0x0000,(uint16)0x0000,(uint16)0xFFFF);
}
else
{
OGRE_EXCEPT( Exception::ERR_NOT_IMPLEMENTED,
"Cannot convert this DevIL type",
"ILUtil::ilToOgre" ) ;
}
}
示例2: locked
//-----------------------------------------------------------------------------
void D3D11HardwarePixelBuffer::blitToMemory(const Image::Box &srcBox, const PixelBox &dst)
{
// Decide on pixel format of temp surface
PixelFormat tmpFormat = mFormat;
if(D3D11Mappings::_getPF(dst.format) != DXGI_FORMAT_UNKNOWN)
{
tmpFormat = dst.format;
}
assert(srcBox.getDepth() == 1 && dst.getDepth() == 1);
//This is a pointer to the texture we're trying to copy
//Only implemented for 2D at the moment...
ID3D11Texture2D *textureResource = mParentTexture->GetTex2D();
// get the description of the texture
D3D11_TEXTURE2D_DESC desc = {0};
textureResource->GetDesc( &desc );
//Alter the description to set up a staging texture
desc.Usage = D3D11_USAGE_STAGING;
//This texture is not bound to any part of the pipeline
desc.BindFlags = 0;
//Allow CPU Access
desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
//No Misc Flags
desc.MiscFlags = 0;
//Create the staging texture
ID3D11Texture2D* pStagingTexture = NULL;
mDevice->CreateTexture2D( &desc, NULL, &pStagingTexture );
//Copy our texture into the staging texture
mDevice.GetImmediateContext()->CopyResource( pStagingTexture, textureResource );
//Create a mapped resource and map the staging texture to the resource
D3D11_MAPPED_SUBRESOURCE mapped = {0};
mDevice.GetImmediateContext()->Map( pStagingTexture, 0, D3D11_MAP_READ , 0, &mapped );
// read the data out of the texture.
unsigned int rPitch = mapped.RowPitch;
BYTE *data = ((BYTE *)mapped.pData);
//Using existing OGRE functions
DXGI_MAPPED_RECT lrect;
lrect.pBits = data;
lrect.Pitch = rPitch;
PixelBox locked(dst.getWidth(), dst.getHeight(), dst.getDepth(), tmpFormat);
fromD3DLock(locked, lrect);
PixelUtil::bulkPixelConversion(locked, dst);
//Release the staging texture
mDevice.GetImmediateContext()->Unmap( pStagingTexture, 0 );
pStagingTexture->Release();
}
示例3: if
void GLES2HardwarePixelBuffer::blitFromMemory(const PixelBox &src, const Image::Box &dstBox)
{
if (!mBuffer.contains(dstBox))
{
OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS,
"Destination box out of range",
"GLES2HardwarePixelBuffer::blitFromMemory");
}
PixelBox scaled;
if (src.getWidth() != dstBox.getWidth() ||
src.getHeight() != dstBox.getHeight() ||
src.getDepth() != dstBox.getDepth())
{
// Scale to destination size.
// This also does pixel format conversion if needed
allocateBuffer();
scaled = mBuffer.getSubVolume(dstBox);
Image::scale(src, scaled, Image::FILTER_BILINEAR);
}
#if OGRE_PLATFORM != OGRE_PLATFORM_APPLE_IOS
else if ((src.format != mFormat) ||
((GLES2PixelUtil::getGLOriginFormat(src.format) == 0) && (src.format != PF_R8G8B8)))
#else
else if (GLES2PixelUtil::getGLOriginFormat(src.format) == 0)
#endif
{
// Extents match, but format is not accepted as valid source format for GL
// do conversion in temporary buffer
allocateBuffer();
scaled = mBuffer.getSubVolume(dstBox);
PixelUtil::bulkPixelConversion(src, scaled);
}
else
{
allocateBuffer();
// No scaling or conversion needed
scaled = src;
if (src.format == PF_R8G8B8)
{
scaled.format = PF_B8G8R8;
PixelUtil::bulkPixelConversion(src, scaled);
}
#if OGRE_PLATFORM == OGRE_PLATFORM_NACL
if (src.format == PF_A8R8G8B8)
{
scaled.format = PF_A8B8G8R8;
PixelUtil::bulkPixelConversion(src, scaled);
}
#endif
}
upload(scaled, dstBox);
freeBuffer();
}
示例4: toD3DRECTExtent
// Convert Ogre pixelbox extent to D3D rectangle
RECT toD3DRECTExtent(const PixelBox &lockBox)
{
RECT prect;
assert(lockBox.getDepth() == 1);
prect.left = 0;
prect.right = static_cast<LONG>(lockBox.getWidth());
prect.top = 0;
prect.bottom = static_cast<LONG>(lockBox.getHeight());
return prect;
}
示例5: blitToMemory
void GLESHardwarePixelBuffer::blitToMemory(const Image::Box &srcBox, const PixelBox &dst)
{
if (!mBuffer.contains(srcBox))
{
OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS,
"source box out of range",
"GLESHardwarePixelBuffer::blitToMemory");
}
if (srcBox.left == 0 && srcBox.right == getWidth() &&
srcBox.top == 0 && srcBox.bottom == getHeight() &&
srcBox.front == 0 && srcBox.back == getDepth() &&
dst.getWidth() == getWidth() &&
dst.getHeight() == getHeight() &&
dst.getDepth() == getDepth() &&
GLESPixelUtil::getGLOriginFormat(dst.format) != 0)
{
// The direct case: the user wants the entire texture in a format supported by GL
// so we don't need an intermediate buffer
download(dst);
}
else
{
// Use buffer for intermediate copy
allocateBuffer();
// Download entire buffer
download(mBuffer);
if(srcBox.getWidth() != dst.getWidth() ||
srcBox.getHeight() != dst.getHeight() ||
srcBox.getDepth() != dst.getDepth())
{
// We need scaling
Image::scale(mBuffer.getSubVolume(srcBox), dst, Image::FILTER_BILINEAR);
}
else
{
// Just copy the bit that we need
PixelUtil::bulkPixelConversion(mBuffer.getSubVolume(srcBox), dst);
}
freeBuffer();
}
}
示例6:
// Convert Ogre pixelbox extent to D3D box
D3DBOX toD3DBOXExtent(const PixelBox &lockBox)
{
D3DBOX pbox;
pbox.Left = 0;
pbox.Right = static_cast<UINT>(lockBox.getWidth());
pbox.Top = 0;
pbox.Bottom = static_cast<UINT>(lockBox.getHeight());
pbox.Front = 0;
pbox.Back = static_cast<UINT>(lockBox.getDepth());
return pbox;
}
示例7: copyContentsToMemory
void EGLWindow::copyContentsToMemory(const Box& src, const PixelBox &dst, FrameBuffer buffer)
{
if(src.right > mWidth || src.bottom > mHeight || src.front != 0 || src.back != 1
|| dst.getWidth() != src.getWidth() || dst.getHeight() != src.getHeight() || dst.getDepth() != 1
#if OGRE_NO_GLES3_SUPPORT == 1
|| dst.getWidth() != dst.rowPitch /* GLES2 does not support GL_PACK_ROW_LENGTH, TODO: check for GL_NV_pack_subimage availability */
#endif
)
{
OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "Invalid box.", "EGLWindow::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.", "EGLWindow::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)src.left, (GLint)(mHeight - src.bottom),
(GLsizei)src.getWidth(), (GLsizei)src.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);
}
示例8: copyContentsToMemory
void EGLWindow::copyContentsToMemory(const Box& src, const PixelBox &dst, FrameBuffer buffer)
{
if(src.right > mWidth || src.bottom > mHeight || src.front != 0 || src.back != 1
|| dst.getWidth() != src.getWidth() || dst.getHeight() != src.getHeight() || dst.getDepth() != 1)
{
OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "Invalid box.", "EGLWindow::copyContentsToMemory");
}
if (buffer == FB_AUTO)
{
buffer = mIsFullScreen? FB_FRONT : FB_BACK;
}
static_cast<GLRenderSystemCommon*>(Root::getSingleton().getRenderSystem())
->_copyContentsToMemory(getViewport(0), src, dst, buffer);
}
示例9: if
void GL3PlusHardwarePixelBuffer::blitFromMemory(const PixelBox &src, const Image::Box &dstBox)
{
if (!mBuffer.contains(dstBox))
{
OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS,
"Destination box out of range",
"GL3PlusHardwarePixelBuffer::blitFromMemory");
}
PixelBox scaled;
if (src.getWidth() != dstBox.getWidth() ||
src.getHeight() != dstBox.getHeight() ||
src.getDepth() != dstBox.getDepth())
{
// Scale to destination size.
// This also does pixel format conversion if needed.
allocateBuffer( mSizeInBytes );
scaled = mBuffer.getSubVolume(dstBox);
Image::scale(src, scaled, Image::FILTER_BILINEAR);
}
else if (GL3PlusPixelUtil::getGLOriginFormat(src.format) == 0)
{
// Extents match, but format is not accepted as valid
// source format for GL. Do conversion in temporary buffer.
allocateBuffer( mSizeInBytes );
scaled = mBuffer.getSubVolume(dstBox);
PixelUtil::bulkPixelConversion(src, scaled);
}
else
{
allocateBuffer( mSizeInBytes );
// No scaling or conversion needed.
scaled = src;
}
upload(scaled, dstBox);
freeBuffer();
}
示例10: defined
//-----------------------------------------------------------------------------
void GLES2TextureBuffer::download(const PixelBox &data)
{
#if 0 || defined(GL_NV_get_tex_image)
if(data.getWidth() != getWidth() ||
data.getHeight() != getHeight() ||
data.getDepth() != getDepth())
OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "only download of entire buffer is supported by GL",
"GLTextureBuffer::download");
glBindTexture( mTarget, mTextureID );
if(PixelUtil::isCompressed(data.format))
{
if(data.format != mFormat || !data.isConsecutive())
OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS,
"Compressed images must be consecutive, in the source format",
"GLTextureBuffer::download");
// Data must be consecutive and at beginning of buffer as PixelStorei not allowed
// for compressed formate
glGetCompressedTexImageNV(mFaceTarget, mLevel, data.data);
}
else
{
if((data.getWidth()*PixelUtil::getNumElemBytes(data.format)) & 3) {
// Standard alignment of 4 is not right
glPixelStorei(GL_PACK_ALIGNMENT, 1);
}
// We can only get the entire texture
glGetTexImageNV(mFaceTarget, mLevel,
GLES2PixelUtil::getGLOriginFormat(data.format), GLES2PixelUtil::getGLOriginDataType(data.format),
data.data);
// Restore defaults
glPixelStorei(GL_PACK_ALIGNMENT, 4);
}
#else
OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED,
"Downloading texture buffers is not supported by OpenGL ES",
"GLES2TextureBuffer::download");
#endif
}
示例11: scale
//-----------------------------------------------------------------------
void Image::scale(const PixelBox &src, const PixelBox &scaled, Filter filter)
{
assert(PixelUtil::isAccessible(src.format));
assert(PixelUtil::isAccessible(scaled.format));
MemoryDataStreamPtr buf; // For auto-delete
PixelBox temp;
switch (filter)
{
default:
case FILTER_NEAREST:
if(src.format == scaled.format)
{
// No intermediate buffer needed
temp = scaled;
}
else
{
// Allocate temporary buffer of destination size in source format
temp = PixelBox(scaled.getWidth(), scaled.getHeight(), scaled.getDepth(), src.format);
buf.bind(OGRE_NEW MemoryDataStream(temp.getConsecutiveSize()));
temp.data = buf->getPtr();
}
// super-optimized: no conversion
switch (PixelUtil::getNumElemBytes(src.format))
{
case 1: NearestResampler<1>::scale(src, temp); break;
case 2: NearestResampler<2>::scale(src, temp); break;
case 3: NearestResampler<3>::scale(src, temp); break;
case 4: NearestResampler<4>::scale(src, temp); break;
case 6: NearestResampler<6>::scale(src, temp); break;
case 8: NearestResampler<8>::scale(src, temp); break;
case 12: NearestResampler<12>::scale(src, temp); break;
case 16: NearestResampler<16>::scale(src, temp); break;
default:
// never reached
assert(false);
}
if(temp.data != scaled.data)
{
// Blit temp buffer
PixelUtil::bulkPixelConversion(temp, scaled);
}
break;
case FILTER_LINEAR:
case FILTER_BILINEAR:
switch (src.format)
{
case PF_L8: case PF_A8: case PF_BYTE_LA:
case PF_R8G8B8: case PF_B8G8R8:
case PF_R8G8B8A8: case PF_B8G8R8A8:
case PF_A8B8G8R8: case PF_A8R8G8B8:
case PF_X8B8G8R8: case PF_X8R8G8B8:
if(src.format == scaled.format)
{
// No intermediate buffer needed
temp = scaled;
}
else
{
// Allocate temp buffer of destination size in source format
temp = PixelBox(scaled.getWidth(), scaled.getHeight(), scaled.getDepth(), src.format);
buf.bind(OGRE_NEW MemoryDataStream(temp.getConsecutiveSize()));
temp.data = buf->getPtr();
}
// super-optimized: byte-oriented math, no conversion
switch (PixelUtil::getNumElemBytes(src.format))
{
case 1: LinearResampler_Byte<1>::scale(src, temp); break;
case 2: LinearResampler_Byte<2>::scale(src, temp); break;
case 3: LinearResampler_Byte<3>::scale(src, temp); break;
case 4: LinearResampler_Byte<4>::scale(src, temp); break;
default:
// never reached
assert(false);
}
if(temp.data != scaled.data)
{
// Blit temp buffer
PixelUtil::bulkPixelConversion(temp, scaled);
}
break;
case PF_FLOAT32_RGB:
case PF_FLOAT32_RGBA:
if (scaled.format == PF_FLOAT32_RGB || scaled.format == PF_FLOAT32_RGBA)
{
// float32 to float32, avoid unpack/repack overhead
LinearResampler_Float32::scale(src, scaled);
break;
}
// else, fall through
default:
// non-optimized: floating-point math, performs conversion but always works
LinearResampler::scale(src, scaled);
}
break;
}
}
示例12: blitFromMemory
//-----------------------------------------------------------------------------
// blitFromMemory doing hardware trilinear scaling
void GLESTextureBuffer::blitFromMemory(const PixelBox &src_orig, const Image::Box &dstBox)
{
// Fall back to normal GLHardwarePixelBuffer::blitFromMemory in case
// - FBO is not supported
// - Either source or target is luminance due doesn't looks like supported by hardware
// - the source dimensions match the destination ones, in which case no scaling is needed
if(!GL_OES_framebuffer_object ||
PixelUtil::isLuminance(src_orig.format) ||
PixelUtil::isLuminance(mFormat) ||
(src_orig.getWidth() == dstBox.getWidth() &&
src_orig.getHeight() == dstBox.getHeight() &&
src_orig.getDepth() == dstBox.getDepth()))
{
GLESHardwarePixelBuffer::blitFromMemory(src_orig, dstBox);
return;
}
if(!mBuffer.contains(dstBox))
OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "Destination box out of range",
"GLESTextureBuffer::blitFromMemory");
// For scoped deletion of conversion buffer
MemoryDataStreamPtr buf;
PixelBox src;
// First, convert the srcbox to a OpenGL compatible pixel format
if(GLESPixelUtil::getGLOriginFormat(src_orig.format) == 0)
{
// Convert to buffer internal format
buf.bind(OGRE_NEW MemoryDataStream(PixelUtil::getMemorySize(src_orig.getWidth(), src_orig.getHeight(), src_orig.getDepth(),
mFormat)));
src = PixelBox(src_orig.getWidth(), src_orig.getHeight(), src_orig.getDepth(), mFormat, buf->getPtr());
PixelUtil::bulkPixelConversion(src_orig, src);
}
else
{
// No conversion needed
src = src_orig;
}
// Create temporary texture to store source data
GLuint id;
GLenum target = GL_TEXTURE_2D;
GLsizei width = GLESPixelUtil::optionalPO2(src.getWidth());
GLsizei height = GLESPixelUtil::optionalPO2(src.getHeight());
GLenum format = GLESPixelUtil::getClosestGLInternalFormat(src.format);
GLenum datatype = GLESPixelUtil::getGLOriginDataType(src.format);
// Generate texture name
glGenTextures(1, &id);
GL_CHECK_ERROR;
// Set texture type
glBindTexture(target, id);
GL_CHECK_ERROR;
// Set automatic mipmap generation; nice for minimisation
glTexParameteri(target, GL_GENERATE_MIPMAP, GL_TRUE );
GL_CHECK_ERROR;
// Allocate texture memory
glTexImage2D(target, 0, format, width, height, 0, format, datatype, 0);
GL_CHECK_ERROR;
// GL texture buffer
GLESTextureBuffer tex(BLANKSTRING, target, id, width, height, format, src.format,
0, 0, (Usage)(TU_AUTOMIPMAP|HBU_STATIC_WRITE_ONLY), false, false, 0);
// Upload data to 0,0,0 in temporary texture
Image::Box tempTarget(0, 0, 0, src.getWidth(), src.getHeight(), src.getDepth());
tex.upload(src, tempTarget);
// Blit
blitFromTexture(&tex, tempTarget, dstBox);
// Delete temp texture
glDeleteTextures(1, &id);
GL_CHECK_ERROR;
}
示例13: getHeight
//-----------------------------------------------------------------------------
void GLES2TextureBuffer::download(const PixelBox &data)
{
if(data.getWidth() != getWidth() ||
data.getHeight() != getHeight() ||
data.getDepth() != getDepth())
OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "only download of entire buffer is supported by GL ES",
"GLES2TextureBuffer::download");
if(PixelUtil::isCompressed(data.format))
{
OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS,
"Compressed images cannot be downloaded by GL ES",
"GLES2TextureBuffer::download");
}
GLenum texBinding = GL_NONE;
switch (mTarget)
{
case GL_TEXTURE_2D:
texBinding = GL_TEXTURE_BINDING_2D;
break;
case GL_TEXTURE_CUBE_MAP:
texBinding = GL_TEXTURE_BINDING_CUBE_MAP;
break;
#if OGRE_NO_GLES3_SUPPORT == 0
case GL_TEXTURE_3D:
texBinding = GL_TEXTURE_BINDING_3D;
break;
#endif
default:
return;
}
#if OGRE_NO_GLES3_SUPPORT == 0
if(data.getWidth() != data.rowPitch)
OGRE_CHECK_GL_ERROR(glPixelStorei(GL_PACK_ROW_LENGTH, data.rowPitch));
if(data.getHeight()*data.getWidth() != data.slicePitch)
OGRE_CHECK_GL_ERROR(glPixelStorei(GL_PACK_IMAGE_HEIGHT, (data.slicePitch/data.getWidth())));
if(data.left > 0 || data.top > 0 || data.front > 0)
OGRE_CHECK_GL_ERROR(glPixelStorei(GL_PACK_SKIP_PIXELS, data.left + data.rowPitch * data.top + data.slicePitch * data.front));
#endif
if((data.getWidth()*PixelUtil::getNumElemBytes(data.format)) & 3) {
// Standard alignment of 4 is not right
OGRE_CHECK_GL_ERROR(glPixelStorei(GL_PACK_ALIGNMENT, 1));
}
GLint currentFBO = 0;
GLuint tempFBO = 0;
OGRE_CHECK_GL_ERROR(glGetIntegerv(GL_FRAMEBUFFER_BINDING, ¤tFBO));
OGRE_CHECK_GL_ERROR(glGenFramebuffers(1, &tempFBO));
OGRE_CHECK_GL_ERROR(glBindFramebuffer(GL_FRAMEBUFFER, tempFBO));
switch (mTarget)
{
case GL_TEXTURE_2D:
case GL_TEXTURE_CUBE_MAP:
OGRE_CHECK_GL_ERROR(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextureID, 0));
OGRE_CHECK_GL_ERROR(glCheckFramebufferStatus(GL_FRAMEBUFFER));
OGRE_CHECK_GL_ERROR(glReadPixels(0, 0, data.getWidth(), data.getHeight(),
GLES2PixelUtil::getGLOriginFormat(data.format),
GLES2PixelUtil::getGLOriginDataType(data.format), data.data));
break;
#if OGRE_NO_GLES3_SUPPORT == 0
case GL_TEXTURE_3D:
for (int i = 0; i < desc.depth; i++) {
OGRE_CHECK_GL_ERROR(glFramebufferTexture3D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_3D, mTextureID, mLevel, i));
OGRE_CHECK_GL_ERROR(glReadPixels(0, 0, data.getWidth(), data.getHeight(), GL_RGBA, GL_UNSIGNED_BYTE, pixels + 4 * i * data.getWidth() * data.getHeight()));
}
break;
#endif
}
// Restore defaults
#if OGRE_NO_GLES3_SUPPORT == 0
OGRE_CHECK_GL_ERROR(glPixelStorei(GL_PACK_ROW_LENGTH, 0));
OGRE_CHECK_GL_ERROR(glPixelStorei(GL_PACK_IMAGE_HEIGHT, 0));
OGRE_CHECK_GL_ERROR(glPixelStorei(GL_PACK_SKIP_PIXELS, 0));
#endif
OGRE_CHECK_GL_ERROR(glPixelStorei(GL_PACK_ALIGNMENT, 4));
OGRE_CHECK_GL_ERROR(glBindFramebuffer(GL_FRAMEBUFFER, currentFBO));
OGRE_CHECK_GL_ERROR(glDeleteFramebuffers(1, &tempFBO));
}
示例14: _loadImages
//--------------------------------------------------------------------------
void Texture::_loadImages( const ConstImagePtrList& images )
{
if(images.size() < 1)
OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "Cannot load empty vector of images",
"Texture::loadImages");
// Set desired texture size and properties from images[0]
mSrcWidth = mWidth = images[0]->getWidth();
mSrcHeight = mHeight = images[0]->getHeight();
mSrcDepth = mDepth = images[0]->getDepth();
// Get source image format and adjust if required
mSrcFormat = images[0]->getFormat();
if (mTreatLuminanceAsAlpha && mSrcFormat == PF_L8)
{
mSrcFormat = PF_A8;
}
if (mDesiredFormat != PF_UNKNOWN)
{
// If have desired format, use it
mFormat = mDesiredFormat;
}
else
{
// Get the format according with desired bit depth
mFormat = PixelUtil::getFormatForBitDepths(mSrcFormat, mDesiredIntegerBitDepth, mDesiredFloatBitDepth);
}
// The custom mipmaps in the image have priority over everything
size_t imageMips = images[0]->getNumMipmaps();
if(imageMips > 0) {
mNumMipmaps = mNumRequestedMipmaps = images[0]->getNumMipmaps();
// Disable flag for auto mip generation
mUsage &= ~TU_AUTOMIPMAP;
}
// Create the texture
createInternalResources();
// Check if we're loading one image with multiple faces
// or a vector of images representing the faces
size_t faces;
bool multiImage; // Load from multiple images?
if(images.size() > 1)
{
faces = images.size();
multiImage = true;
}
else
{
faces = images[0]->getNumFaces();
multiImage = false;
}
// Check wether number of faces in images exceeds number of faces
// in this texture. If so, clamp it.
if(faces > getNumFaces())
faces = getNumFaces();
if (TextureManager::getSingleton().getVerbose()) {
// Say what we're doing
StringUtil::StrStreamType str;
str << "Texture: " << mName << ": Loading " << faces << " faces"
<< "(" << PixelUtil::getFormatName(images[0]->getFormat()) << "," <<
images[0]->getWidth() << "x" << images[0]->getHeight() << "x" << images[0]->getDepth() <<
") with ";
if (!(mMipmapsHardwareGenerated && mNumMipmaps == 0))
str << mNumMipmaps;
if(mUsage & TU_AUTOMIPMAP)
{
if (mMipmapsHardwareGenerated)
str << " hardware";
str << " generated mipmaps";
}
else
{
str << " custom mipmaps";
}
if(multiImage)
str << " from multiple Images.";
else
str << " from Image.";
// Scoped
{
// Print data about first destination surface
HardwarePixelBufferSharedPtr buf = getBuffer(0, 0);
str << " Internal format is " << PixelUtil::getFormatName(buf->getFormat()) <<
"," << buf->getWidth() << "x" << buf->getHeight() << "x" << buf->getDepth() << ".";
}
LogManager::getSingleton().logMessage(
LML_NORMAL, str.str());
}
// Main loading loop
// imageMips == 0 if the image has no custom mipmaps, otherwise contains the number of custom mips
for(size_t mip = 0; mip<=imageMips; ++mip)
{
//.........这里部分代码省略.........
示例15: fromOgre
//-----------------------------------------------------------------------
void ILUtil::fromOgre(const PixelBox &src)
{
// ilTexImage http://openil.sourceforge.net/docs/il/f00059.htm
ILFormat ifmt = OgreFormat2ilFormat( src.format );
if(src.isConsecutive() && ifmt.isValid())
{
// The easy case, the buffer is laid out in memory just like
// we want it to be and is in a format DevIL can understand directly
// We could even save the copy if DevIL would let us
ilTexImage(static_cast<ILuint>(src.getWidth()),
static_cast<ILuint>(src.getHeight()),
static_cast<ILuint>(src.getDepth()), ifmt.numberOfChannels,
ifmt.format, ifmt.type, src.data);
}
else if(ifmt.isValid())
{
// The format can be understood directly by DevIL. The only
// problem is that ilTexImage expects our image data consecutively
// so we cannot use that directly.
// Let DevIL allocate the memory for us, and copy the data consecutively
// to its memory
ilTexImage(static_cast<ILuint>(src.getWidth()),
static_cast<ILuint>(src.getHeight()),
static_cast<ILuint>(src.getDepth()), ifmt.numberOfChannels,
ifmt.format, ifmt.type, 0);
PixelBox dst(src.getWidth(), src.getHeight(), src.getDepth(), src.format, ilGetData());
PixelUtil::bulkPixelConversion(src, dst);
}
else
{
// Here it gets ugly. We're stuck with a pixel format that DevIL
// can't do anything with. We will do a bulk pixel conversion and
// then feed it to DevIL anyway. The problem is finding the best
// format to convert to.
// most general format supported by OGRE and DevIL
PixelFormat fmt = PixelUtil::hasAlpha(src.format)?PF_FLOAT32_RGBA:PF_FLOAT32_RGB;
// Make up a pixel format
// We don't have to consider luminance formats as they have
// straight conversions to DevIL, just weird permutations of RGBA an LA
int depths[4];
PixelUtil::getBitDepths(src.format, depths);
// Native endian format with all bit depths<8 can safely and quickly be
// converted to 24/32 bit
if(PixelUtil::isNativeEndian(src.format) &&
depths[0]<=8 && depths[1]<=8 && depths[2]<=8 && depths[3]<=8) {
if(PixelUtil::hasAlpha(src.format)) {
fmt = PF_A8R8G8B8;
} else {
fmt = PF_R8G8B8;
}
}
// Let DevIL allocate the memory for us, then do the conversion ourselves
ifmt = OgreFormat2ilFormat( fmt );
ilTexImage(static_cast<ILuint>(src.getWidth()),
static_cast<ILuint>(src.getHeight()),
static_cast<ILuint>(src.getDepth()), ifmt.numberOfChannels,
ifmt.format, ifmt.type, 0);
PixelBox dst(src.getWidth(), src.getHeight(), src.getDepth(), fmt, ilGetData());
PixelUtil::bulkPixelConversion(src, dst);
}
}