Esempio n. 1
0
cxTexture cxTextureCreate(cxConstChars file)
{
    cxTexture texture = NULL;
    CX_ASSERT(file != NULL, "file args error");
    cxStream stream = cxAssetsStreamCreate(file);
    if(stream == NULL){
        CX_ERROR("create stream from file %s failed",file);
        return NULL;
    }
    char *ext = strrchr(file, '.');
    if(ext == NULL){
        CX_ERROR("unknow file ext name");
        return NULL;
    }
    if(cxConstCharsEqu(ext, ".png")){
        texture = cxTexturePNGLoadStream(stream);
    }else if(cxConstCharsEqu(ext, ".pvr")){
        texture = cxTexturePVRLoadStream(stream);
    }else if(cxConstCharsEqu(ext, ".xml")){
        texture = cxTextureXMLLoadStream(stream);
    }else if(cxConstCharsEqu(ext, ".pkm")){
        texture = cxTexturePKMLoadStream(stream);
    }else if(cxConstCharsEqu(ext, ".jpg") || cxConstCharsEqu(ext, ".jpeg")){
        texture = cxTextureJPGLoadStream(stream);
    }else{
        CX_ERROR("load texture failed %s",file);
    }
    return texture;
}
Esempio n. 2
0
static cxBool cxTextureMTFMake(cxAny pthis,cxStr data,cxInt idx)
{
    CX_ASSERT_THIS(pthis, cxTextureMTF);
    CX_ASSERT(idx >= 0 && idx < this->header.count, "idx range");
    cxTexture ret = NULL;
    cxInt off = sizeof(cxTextureMTFHeader) + idx * this->header.length;
    cxStr d = cxStrNoCopy(cxStrBody(data) + off, this->header.length);
    if (d == NULL) {
        return false;
    }
    cxStream stream = cxMemStreamCreateRefStr(d);
    if(this->header.type == 1){
        ret = cxTexturePVRLoadStream(stream);
    }
    if(this->header.type == 2){
        ret = cxTexturePKMLoadStream(stream);
    }
    if(ret == NULL){
        return false;
    }
    cxHashSet(this->caches, cxHashIntKey(idx), ret);
    return true;
}