// ----------------------------------------------------------------------------------------- MaterialPtr::MaterialPtr(const ResourcePtr& r) : CPepeEngineSharedPtr<CPepeEngineMaterial>() { ptr = (CPepeEngineMaterial*)r.data(); if (ptr) { ptr->ref(); } }
GLuint loadTextureFromPKM(const ResourcePtr& pkmData, int &width, int &height) { #ifdef GL_ETC1_RGB8_OES const unsigned ETC_PKM_HEADER_SIZE = 16; if (pkmData->data().size() <= ETC_PKM_HEADER_SIZE) { LOGE("pkmData is not the right size. expected > %u, is: %zu", ETC_PKM_HEADER_SIZE, pkmData->data().size()); return TEXTURE_LOAD_ERROR; } etc1_byte* header = &pkmData->data()[0]; if (!etc1_pkm_is_valid(header)) return TEXTURE_LOAD_ERROR; width = etc1_pkm_get_width(header); height = etc1_pkm_get_height(header); size_t encodedDataSize = etc1_get_encoded_data_size(width, height); if (pkmData->data().size() != ETC_PKM_HEADER_SIZE + encodedDataSize) { LOGE("pkmData is not the right size. expected: %zu, is: %zu", ETC_PKM_HEADER_SIZE + encodedDataSize, pkmData->data().size()); return TEXTURE_LOAD_ERROR; } //Now generate the OpenGL texture object GLuint texture = genTexture(); bindTexture2D(texture); compressedTexImage2D(GL_ETC1_RGB8_OES, width, height, encodedDataSize, static_cast<GLvoid*> (&pkmData->data()[ETC_PKM_HEADER_SIZE])); texParameter(GL_TEXTURE_MIN_FILTER, GL_LINEAR); texParameter(GL_TEXTURE_MAG_FILTER, GL_NEAREST); return texture; #else LOGE("PKM texture format not supported by this platform"); return TEXTURE_LOAD_ERROR; #endif }