Exemplo n.º 1
0
Texture::Texture(int width, int height, GLuint target, int flag)
  : target(target)
{
  extractParams(flag);
  genTexture();
  glTexImage2D(target, 0, internalFormat, width, height, 0, format, type, NULL);
  texParameter(GL_TEXTURE_MAG_FILTER, magFilter);
  texParameter(GL_TEXTURE_MIN_FILTER, minFilter);
}
Exemplo n.º 2
0
GLuint loadTextureFromPNGData(png_byte* image_data, int &width, int &height)
{
	if (image_data == NULL) LOGE("loadTextureFromPNGData:Image data == NULL");
	GLuint texture = genTexture();
	bindTexture2D(texture);
	texImage2D(width, height, static_cast<GLvoid*>(image_data));
	texParameter(GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	texParameter(GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	return texture;
}
Exemplo n.º 3
0
Texture::Texture(const char *filename, GLuint target, int flag)
  : name(filename), target(target)
{
  flag |= UNSIGNED_BYTE|RGB; //RGB avoid an exception in extractParams
  extractParams(flag);
  genTexture();

  if(target == TEXTURE_CUBE_MAP)
    loadCubemap(flag);
  else if(target == TEXTURE_2D)
    loadTexture2D(name, target, flag);

  texParameter(GL_TEXTURE_MAG_FILTER, magFilter);
  texParameter(GL_TEXTURE_MIN_FILTER, minFilter);
}
Exemplo n.º 4
0
GLuint loadTextureFromPNG(const ResourcePtr& pngData, int &width, int &height)
{
	//Now generate the OpenGL texture object
	GLuint texture = genTexture();
	bindTexture2D(texture);
	png_byte* image_data = loadImageFromPNG(pngData, width, height);
	// got this logic from android_source/frameworks/base/cmds/bootanimation/BootAnimation.cpp,
	// but it doesn't seem to work right. The odd-sized texture loads, but it is squished. I could probably fix
	// that, but I'm not going to worry about it for now.
//    int tw = 1 << (31 - __builtin_clz(width));
//    int th = 1 << (31 - __builtin_clz(height));
//    if (tw < width) tw <<= 1;
//    if (th < height) th <<= 1;
//
//    if (tw != width || th != height)
//    {
//        GLint crop[4] = { 0, height, width, -height };
//    	texImage2D(tw, th, 0);
//    	glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, static_cast<GLvoid*>(image_data));
//    	checkGLError("glTexSubImage2D");
//        glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop);
//        checkGLError("glTexParameteriv");
//    }
//    else
//    {
    	texImage2D(width, height, static_cast<GLvoid*>(image_data));
//    }

	texParameter(GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	texParameter(GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	// I thought these might help with random black pixels on the edge of a rotated texture, but they didn't.
//	texParameter(GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
//	texParameter(GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

	//clean up memory and close stuff
	//png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
	//delete[] image_data;
	//delete[] row_pointers;
	delete[] image_data;
	return texture;
}
Exemplo n.º 5
0
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
}