| 1691 | } |
| 1692 | |
| 1693 | unsigned int Textures::makeTextureTestPatternInternal(int width, int height, GLint internal_format, GLint format, bool mipmap) { |
| 1694 | CHECK_GL_ERROR(); |
| 1695 | unsigned which = AllocateFreeSlot(); |
| 1696 | |
| 1697 | Texture& texture = textures[which]; |
| 1698 | texture.Init(); |
| 1699 | texture.width = width; |
| 1700 | texture.height = height; |
| 1701 | texture.internal_format = internal_format; |
| 1702 | texture.format = format; |
| 1703 | texture.tex_target = GL_TEXTURE_2D; |
| 1704 | |
| 1705 | std::vector<GLubyte> data(width * height * 4); |
| 1706 | |
| 1707 | int index; |
| 1708 | int multiple = width / 32; |
| 1709 | int cornerWidth = multiple * 4; |
| 1710 | for (int j = 0; j < width; j++) { |
| 1711 | for (int i = 0; i < height; i++) { |
| 1712 | index = (i + j * width) * 4; |
| 1713 | // Color the corners |
| 1714 | if ((i < cornerWidth && j < cornerWidth) || |
| 1715 | (i > height - cornerWidth && j > height - cornerWidth) || |
| 1716 | (i > height - cornerWidth && j < cornerWidth) || |
| 1717 | (i < cornerWidth && j > height - cornerWidth)) { |
| 1718 | data[index + 0] = 255; |
| 1719 | } else { |
| 1720 | data[index + 0] = ((i / multiple + j / multiple) % 2) * 255; |
| 1721 | } |
| 1722 | |
| 1723 | data[index + 1] = data[index]; |
| 1724 | data[index + 2] = data[index]; |
| 1725 | data[index + 3] = 128; |
| 1726 | } |
| 1727 | } |
| 1728 | |
| 1729 | glGenTextures(1, &texture.gl_texture_id); |
| 1730 | LOG_ASSERT(texture.gl_texture_id != INVALID_ID); |
| 1731 | LOG_ASSERT(texture.gl_texture_id != UNLOADED_ID); |
| 1732 | |
| 1733 | glBindTexture(texture.tex_target, texture.gl_texture_id); |
| 1734 | if (internal_format == GL_RGBA16F) { |
| 1735 | if (GLAD_GL_ARB_texture_float) { |
| 1736 | glTexImage2D(texture.tex_target, 0, internal_format, width, height, 0, |
| 1737 | format, GL_FLOAT, &data[0]); |
| 1738 | } else { |
| 1739 | glTexImage2D(texture.tex_target, 0, GL_RGBA, width, height, 0, |
| 1740 | format, GL_UNSIGNED_BYTE, &data[0]); |
| 1741 | } |
| 1742 | } else { |
| 1743 | glTexImage2D(texture.tex_target, 0, internal_format, width, height, 0, |
| 1744 | format, GL_UNSIGNED_BYTE, &data[0]); |
| 1745 | } |
| 1746 | if (mipmap) |
| 1747 | glTexParameteri(texture.tex_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); |
| 1748 | else |
| 1749 | glTexParameteri(texture.tex_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 1750 | glTexParameteri(texture.tex_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |