- // Translate the input format to OpenGL's enums.
- GLenum internal_format;
- if (use_srgb_texture_format) {
- internal_format = GL_SRGB8;
- } else {
- internal_format = GL_RGBA8;
- }
- if (input_format.pixel_format == FORMAT_RGB) {
- format = GL_RGB;
- bytes_per_pixel = 3;
- } else if (input_format.pixel_format == FORMAT_RGBA) {
- format = GL_RGBA;
- bytes_per_pixel = 4;
- } else if (input_format.pixel_format == FORMAT_BGR) {
- format = GL_BGR;
- bytes_per_pixel = 3;
- } else if (input_format.pixel_format == FORMAT_BGRA) {
- format = GL_BGRA;
- bytes_per_pixel = 4;
- } else {
- assert(false);
- }
-
- // Create PBO to hold the texture holding the input image, and then the texture itself.
- glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, 2);
- check_error();
- glBufferData(GL_PIXEL_UNPACK_BUFFER_ARB, width * height * bytes_per_pixel, NULL, GL_STREAM_DRAW);
- check_error();
- glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
- check_error();
-
- glGenTextures(1, &source_image_num);
- check_error();
- glBindTexture(GL_TEXTURE_2D, source_image_num);
- check_error();
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- check_error();
- // Intel/Mesa seems to have a broken glGenerateMipmap() for non-FBO textures, so do it here.
- glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, phases[0].input_needs_mipmaps ? GL_TRUE : GL_FALSE);
- check_error();
- glTexImage2D(GL_TEXTURE_2D, 0, internal_format, width, height, 0, format, GL_UNSIGNED_BYTE, NULL);
- check_error();
-