openGL之API学习(二一零)纹理要素设置过程
Posted hankern
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了openGL之API学习(二一零)纹理要素设置过程相关的知识,希望对你有一定的参考价值。
包括纹理尺寸、格式、类型、边框
边框在构造是置为0,后期不再修改
1、在读取图片时确定
内部格式和像素格式是一样的
osgPlugins/rgb/ReaderWriterRGB.cpp
ReadResult readRGBStream(std::istream& fin) const
osg::ref_ptr<refImageRec> raw;
if( (raw = RawImageOpen(fin)) == NULL )
return ReadResult::ERROR_IN_READING_FILE;
int s = raw->sizeX;
int t = raw->sizeY;
int r = 1;
unsigned int pixelFormat =
raw->sizeZ == 1 ? GL_LUMINANCE :
raw->sizeZ == 2 ? GL_LUMINANCE_ALPHA :
raw->sizeZ == 3 ? GL_RGB :
raw->sizeZ == 4 ? GL_RGBA : (GLenum)-1;
int internalFormat = pixelFormat;
unsigned int dataType = raw->bpc == 1 ? GL_UNSIGNED_BYTE :
GL_UNSIGNED_SHORT;
unsigned char *data;
RawImageGetData(*raw, &data);
Image* image = new Image();
image->setImage(s,t,r,
internalFormat,
pixelFormat,
dataType,
data,
osg::Image::USE_NEW_DELETE);
OSG_INFO << "image read ok "<<s<<" "<<t<< std::endl;
return image;
osg/Image.cpp
void Image::setImage(int s,int t,int r,
GLint internalTextureFormat,
GLenum format,GLenum type,
unsigned char *data,
AllocationMode mode,
int packing,
int rowLength)
_mipmapData.clear();
bool callback_needed = (_s != s) || (_t != t) || (_r != r);
_s = s;
_t = t;
_r = r;
_internalTextureFormat = internalTextureFormat;
_pixelFormat = format;
_dataType = type;
setData(data,mode);
_packing = packing;
_rowLength = rowLength;
dirty();
if (callback_needed)
handleDimensionsChangedCallbacks();
在apply时设置内部格式
osg/Texture.cpp
void Texture::computeInternalFormatWithImage(const osg::Image& image) const
internalFormat = image.getInternalTextureFormat();
在apply时设置纹理尺寸
osg/Texture.cpp
void Texture::computeRequiredTextureDimensions(State& state, const osg::Image& image,GLsizei& inwidth, GLsizei& inheight,GLsizei& numMipmapLevels) const
width = Image::computeNearestPowerOfTwo(image.s()-2*_borderWidth)+2*_borderWidth;
height = Image::computeNearestPowerOfTwo(image.t()-2*_borderWidth)+2*_borderWidth;
inwidth = width;
inheight = height;
if( _min_filter == LINEAR || _min_filter == NEAREST)
numMipmapLevels = 1;
else if( image.isMipmap() )
numMipmapLevels = image.getNumMipmapLevels();
else
numMipmapLevels = 1;
for(int s=1; s<width || s<height; s <<= 1, ++numMipmapLevels)
以上是关于openGL之API学习(二一零)纹理要素设置过程的主要内容,如果未能解决你的问题,请参考以下文章
openGL之API学习(二零三)GL_TEXTURE_WRAP_S GL_TEXTURE_WRAP_T
openGL之API学习(一九六)纹理单元名和纹理单元的管理