コード例 #1
0
ファイル: Texture2D.cpp プロジェクト: qqdiguo/ork
 Texture2DResource(ptr<ResourceManager> manager, const string &name, ptr<ResourceDescriptor> desc, const TiXmlElement *e = NULL) :
     ResourceTemplate<0, Texture2D>(manager, name, desc)
 {
     e = e == NULL ? desc->descriptor : e;
     TextureInternalFormat tf;
     TextureFormat f;
     PixelType t;
     Texture::Parameters params;
     Buffer::Parameters s;
     int w;
     int h;
     try {
         checkParameters(desc, e, "name,source,internalformat,format,type,min,mag,wraps,wrapt,minLod,maxLod,compare,borderType,borderr,borderg,borderb,bordera,maxAniso,width,height,");
         getIntParameter(desc, e, "width", &w);
         getIntParameter(desc, e, "height", &h);
         getParameters(desc, e, tf, f, t);
         getParameters(desc, e, params);
         s.compressedSize(desc->getSize());
         init(w, h, tf, f, t, params, s, CPUBuffer(desc->getData()));
         desc->clearData();
     } catch (...) {
         desc->clearData();
         throw exception();
     }
 }
コード例 #2
0
ファイル: Texture2D.cpp プロジェクト: qqdiguo/ork
void Texture2D::init(int w, int h, TextureInternalFormat tf, TextureFormat f, PixelType t,
    const Parameters &params, const Buffer::Parameters &s, const Buffer &pixels)
{
    Texture::init(tf, params);

    this->w = w;
    this->h = h;

    pixels.bind(GL_PIXEL_UNPACK_BUFFER);

    if (isCompressed() && s.compressedSize() > 0) {
        glCompressedTexImage2D(textureTarget, 0, getTextureInternalFormat(internalFormat), w, h, 0, s.compressedSize(), pixels.data(0));
    } else {
        s.set();
        glTexImage2D(textureTarget, 0, getTextureInternalFormat(internalFormat), w, h, 0, getTextureFormat(f), getPixelType(t), pixels.data(0));
        s.unset();
    }
    pixels.unbind(GL_PIXEL_UNPACK_BUFFER);

    generateMipMap();

    if (FrameBuffer::getError() != 0) {
        throw exception();
    }
}
コード例 #3
0
ファイル: Texture3D.cpp プロジェクト: LarsFlaeten/ork
 Texture3DResource(ptr<ResourceManager> manager, const string &name, ptr<ResourceDescriptor> desc, const TiXmlElement *e = NULL) :
     ResourceTemplate<0, Texture3D>(manager, name, desc)
 {
     e = e == NULL ? desc->descriptor : e;
     TextureInternalFormat tf;
     TextureFormat f;
     PixelType t;
     Texture::Parameters params;
     Buffer::Parameters s;
     int w;
     int h;
     int d;
     try {
         checkParameters(desc, e, "name,source,internalformat,format,type,min,mag,wraps,wrapt,wrapr,minLod,maxLod,width,height,depth,");
         getIntParameter(desc, e, "width", &w);
         getIntParameter(desc, e, "height", &h);
         getIntParameter(desc, e, "depth", &d);
         if (h % d != 0) {
             if (Logger::ERROR_LOGGER != NULL) {
                 log(Logger::ERROR_LOGGER, desc, e, "Inconsistent 'height' and 'depth' attributes");
             }
             throw exception();
         }
         getParameters(desc, e, tf, f, t);
         getParameters(desc, e, params);
         s.compressedSize(desc->getSize());
         init(w, h / d, d, tf, f, t, params, s, CPUBuffer(desc->getData()));
         desc->clearData();
     } catch (...) {
         desc->clearData();
         throw exception();
     }
 }
コード例 #4
0
ファイル: TextureCube.cpp プロジェクト: LarsFlaeten/ork
void TextureCube::setSubImage(CubeFace cf, int level, int x, int y, int w, int h, TextureFormat f, PixelType t, const Buffer::Parameters &s, const Buffer &pixels)
{
    bindToTextureUnit();
    pixels.bind(GL_PIXEL_UNPACK_BUFFER);
    s.set();
    glTexSubImage2D(getCubeFace(cf), level, x, y, w, h, getTextureFormat(f), getPixelType(t), pixels.data(0));
    s.unset();
    pixels.unbind(GL_PIXEL_UNPACK_BUFFER);
    assert(FrameBuffer::getError() == GL_NO_ERROR);
}
コード例 #5
0
ファイル: Texture2DArray.cpp プロジェクト: whztt07/nature3d
void Texture2DArray::setSubImage(int level, int x, int y, int l, int w, int h, int d, TextureFormat f, PixelType t, const Buffer::Parameters &s, const Buffer &pixels)
{
    bindToTextureUnit();
    pixels.bind(GL_PIXEL_UNPACK_BUFFER);
    s.set();
    glTexSubImage3D(GL_TEXTURE_2D_ARRAY, level, x, y, l, w, h, d, getTextureFormat(f), getPixelType(t), pixels.data(0));
    s.unset();
    pixels.unbind(GL_PIXEL_UNPACK_BUFFER);
    assert(FrameBuffer::getError() == GL_NO_ERROR);
}
コード例 #6
0
void TextureRectangle::init(int w, int h, TextureInternalFormat tf, TextureFormat f, PixelType t,
    const Parameters &params, const Buffer::Parameters &s, const Buffer &pixels)
{
    Texture::init(tf, params);
    this->w = w;
    this->h = h;

    pixels.bind(GL_PIXEL_UNPACK_BUFFER);
    bool needToGenerateMipmaps = true;
    if (isCompressed() && s.compressedSize() > 0) {
        glCompressedTexImage2D(textureTarget, 0, getTextureInternalFormat(internalFormat), w, h, 0, s.compressedSize(), pixels.data(0));
    } else {
        s.set();
        glTexImage2D(textureTarget, 0, getTextureInternalFormat(internalFormat), w, h, 0, getTextureFormat(f), getPixelType(t), pixels.data(0));
        s.unset();

        GLsizei size = s.compressedSize(); // should work because size is retrieved from file descriptor.
        int pixelSize = getFormatSize(f, t);
        if (size > w * h * pixelSize) {
            // get the other levels from the same buffer
            int offset = w * h * pixelSize;
            int level = 0;
            int wl = w;
            int hl = h;
            while (wl % 2 == 0 && hl % 2 == 0 && size - offset >= (wl * hl / 4) * pixelSize) {
                level += 1;
                wl = wl / 2;
                hl = hl / 2;
                glTexImage2D(textureTarget, level, getTextureInternalFormat(internalFormat), wl, hl, 0, getTextureFormat(f), getPixelType(t), pixels.data(offset));
                offset += wl * hl * pixelSize;
                needToGenerateMipmaps = false;
            }
            this->params.lodMax(clamp(params.lodMax(), GLfloat(0.0f), GLfloat(level)));
        }
    }
    pixels.unbind(GL_PIXEL_UNPACK_BUFFER);

    if (needToGenerateMipmaps) {
        generateMipMap();
    }

    if (FrameBuffer::getError() != 0) {
        throw exception();
    }
}
コード例 #7
0
ファイル: Texture2DArray.cpp プロジェクト: whztt07/nature3d
 Texture2DArrayResource(ptr<ResourceManager> manager, const string &name, ptr<ResourceDescriptor> desc, const TiXmlElement *e = NULL) :
     ResourceTemplate<0, Texture2DArray>(manager, name, desc)
 {
     e = e == NULL ? desc->descriptor : e;
     TextureInternalFormat tf;
     TextureFormat f;
     PixelType t;
     Texture::Parameters params;
     Buffer::Parameters s;
     int w;
     int h;
     int l;
     try {
         checkParameters(desc, e, "name,source,internalformat,format,type,min,mag,wraps,wrapt,minLod,maxLod,compare,borderType,borderr,borderg,borderb,bordera,maxAniso,width,height,depth,layers,");
         getIntParameter(desc, e, "width", &w);
         getIntParameter(desc, e, "height", &h);
         if (e->Attribute("depth") != NULL) {
             getIntParameter(desc, e, "depth", &l);
         } else {
             getIntParameter(desc, e, "layers", &l);
         }
         if (h % l != 0) {
             if (Logger::ERROR_LOGGER != NULL) {
                 log(Logger::ERROR_LOGGER, desc, e, "Inconsistent 'height' and 'layers' attributes");
             }
             throw exception();
         }
         getParameters(desc, e, tf, f, t);
         getParameters(desc, e, params);
         s.compressedSize(desc->getSize());
         init(w, h / l, l, tf, f, t, params, s, CPUBuffer(desc->getData()));
         desc->clearData();
     } catch (...) {
         desc->clearData();
         throw exception();
     }
 }