MCPcopy Create free account
hub / github.com/WolfireGames/overgrowth / makeTextureColorInternal

Method makeTextureColorInternal

Source/Graphics/textures.cpp:1611–1682  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1609}
1610
1611unsigned int Textures::makeTextureColorInternal(int width, int height, GLint internal_format, GLint format, float red, float green, float blue, float alpha, bool mipmap) {
1612 CHECK_GL_ERROR();
1613 unsigned which = AllocateFreeSlot();
1614
1615 Texture& texture = textures[which];
1616 texture.Init();
1617 texture.width = width;
1618 texture.height = height;
1619 texture.internal_format = internal_format;
1620 texture.format = format;
1621 texture.no_mipmap = !mipmap;
1622 texture.tex_target = GL_TEXTURE_2D;
1623
1624 std::vector<GLubyte> data(width * height * 4);
1625
1626 unsigned char red_byte = (unsigned char)(red * 255);
1627 unsigned char green_byte = (unsigned char)(green * 255);
1628 unsigned char blue_byte = (unsigned char)(blue * 255);
1629 unsigned char alpha_byte = (unsigned char)(alpha * 255);
1630
1631 int index;
1632 for (int j = 0; j < width; j++) {
1633 for (int i = 0; i < height; i++) {
1634 index = (i + j * height) * 4;
1635 data[index + 0] = red_byte;
1636 data[index + 1] = green_byte;
1637 data[index + 2] = blue_byte;
1638 data[index + 3] = alpha_byte;
1639 }
1640 }
1641
1642 glGenTextures(1, &textures[which].gl_texture_id);
1643 LOG_ASSERT(textures[which].gl_texture_id != INVALID_ID);
1644 LOG_ASSERT(textures[which].gl_texture_id != UNLOADED_ID);
1645
1646 glBindTexture(texture.tex_target, texture.gl_texture_id);
1647
1648 unsigned int totalTextureSize = 0;
1649 if (internal_format == GL_RGBA16F) {
1650 if (GLAD_GL_ARB_texture_float) {
1651 glTexImage2D(texture.tex_target, 0, internal_format, width, height, 0,
1652 format, GL_FLOAT, &data[0]);
1653 totalTextureSize += width * height * 8;
1654 } else {
1655 glTexImage2D(texture.tex_target, 0, GL_RGBA, width, height, 0,
1656 format, GL_UNSIGNED_BYTE, &data[0]);
1657 totalTextureSize += width * height * 4;
1658 }
1659 } else {
1660 glTexImage2D(texture.tex_target, 0, internal_format, width, height, 0,
1661 format, GL_UNSIGNED_BYTE, &data[0]);
1662 totalTextureSize += width * height * 4;
1663 }
1664 if (mipmap)
1665 glTexParameteri(texture.tex_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1666 else
1667 glTexParameteri(texture.tex_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1668 glTexParameteri(texture.tex_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

Callers

nothing calls this directly

Calls 1

InitMethod · 0.45

Tested by

no test coverage detected