コード例 #1
0
ファイル: CC3PVRTexture.cpp プロジェクト: ClAndHHL/cocos3d-x
void CC3PVRTexture::bindTextureContent( CC3PVRTextureContent* texContent, GLenum target )
{
	if (!texContent) 
		return;
	
	deleteGLTexture();		// Delete any existing texture in the GL engine
	
	_textureID = texContent->getTextureID();
	_size = texContent->getSize();
	_hasMipmap = texContent->hasMipmap();
	_hasPremultipliedAlpha = texContent->hasPremultipliedAlpha();
	_isTextureCube = texContent->isTextureCube();
	_coverage = CCSizeMake(1.0f, 1.0f);				// PVR textures are always POT
	_pixelFormat = texContent->getPixelFormat();
	_pixelType = texContent->getPixelType();
	
	//LogTrace(@"Bound PVR texture ID %u", _textureID);
	
	// Update the texture parameters depending on whether the PVR file is 2D or cube-map.
	setTextureParameters( isTextureCube()
								? CC3TextureCube::defaultTextureParameters()
								: CC3Texture2D::defaultTextureParameters() );
}
コード例 #2
0
/**
 * @brief cwImageTexture::~cwImageTexture
 *
 * The deconstructor assumes that the current opengl context has
 * been set, and this object is being destroyed in the correct thread
 */
cwImageTexture::~cwImageTexture()
{
    deleteGLTexture();
}
コード例 #3
0
/**
  This upload the results from texture image to the graphics card
  */
void cwImageTexture::updateData() {
    if(!isDirty()) { return; }

    if(DeleteTexture) {
        deleteGLTexture();
        TextureDirty = false;
        return;
    }

    if(TextureUploadTask == nullptr) {
        TextureDirty = false;
        return;
    }

    if(TextureUploadTask->isRunning()) { return; }

    QList<QPair<QByteArray, QSize> > mipmaps = TextureUploadTask->mipmaps();
    ScaleTexCoords = TextureUploadTask->scaleTexCoords();

    if(mipmaps.empty()) { return; }

    QSize firstLevel = mipmaps.first().second;
    if(!cwTextureUploadTask::isDivisibleBy4(firstLevel)) {
        qDebug() << "Trying to upload an image that isn't divisible by 4. This will crash ANGLE on windows." << LOCATION;
        TextureDirty = false;
        return;
    }

    //Load the data into opengl
    bind();

    //Get the max texture size
    GLint maxTextureSize;
    glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize);

    int trueMipmapLevel = 0;
    for(int mipmapLevel = 0; mipmapLevel < mipmaps.size(); mipmapLevel++) {

        //Get the mipmap data
        QPair<QByteArray, QSize> image = mipmaps.at(mipmapLevel);
        QByteArray imageData = image.first;
        QSize size = image.second;

        if(size.width() < maxTextureSize && size.height() < maxTextureSize) {
            glCompressedTexImage2D(GL_TEXTURE_2D, trueMipmapLevel, GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
                                   size.width(), size.height(), 0,
                                   imageData.size(), imageData.data());

            trueMipmapLevel++;

#ifdef Q_OS_WIN
            //Only upload one texture, because some intel cards, don't support npot dxt1 copression, so we just used nearest
            //FIXME: ADD to rendering settings!
            break;
#endif //Q_OS_WIN
        }
    }

    release();

    deleteLoadNoteTask();

    TextureDirty = false;
}