+ if (texture_num == 0 && (pbo != 0 || pixel_data != nullptr)) {
+ // Translate the input format to OpenGL's enums.
+ GLint internal_format;
+ GLenum format;
+ if (type == GL_FLOAT) {
+ if (pixel_format == FORMAT_R) {
+ internal_format = GL_R32F;
+ } else if (pixel_format == FORMAT_RG) {
+ internal_format = GL_RG32F;
+ } else if (pixel_format == FORMAT_RGB) {
+ internal_format = GL_RGB32F;
+ } else {
+ internal_format = GL_RGBA32F;
+ }
+ } else if (type == GL_HALF_FLOAT) {
+ if (pixel_format == FORMAT_R) {
+ internal_format = GL_R16F;
+ } else if (pixel_format == FORMAT_RG) {
+ internal_format = GL_RG16F;
+ } else if (pixel_format == FORMAT_RGB) {
+ internal_format = GL_RGB16F;
+ } else {
+ internal_format = GL_RGBA16F;
+ }
+ } else if (type == GL_UNSIGNED_SHORT) {
+ if (pixel_format == FORMAT_R) {
+ internal_format = GL_R16;
+ } else if (pixel_format == FORMAT_RG) {
+ internal_format = GL_RG16;
+ } else if (pixel_format == FORMAT_RGB) {
+ internal_format = GL_RGB16;
+ } else {
+ internal_format = GL_RGBA16;
+ }
+ } else if (output_linear_gamma) {
+ assert(type == GL_UNSIGNED_BYTE);
+ if (pixel_format == FORMAT_RGB) {
+ internal_format = GL_SRGB8;
+ } else if (pixel_format == FORMAT_RGBA_POSTMULTIPLIED_ALPHA) {
+ internal_format = GL_SRGB8_ALPHA8;
+ } else {
+ assert(false);
+ }
+ } else {
+ assert(type == GL_UNSIGNED_BYTE);
+ if (pixel_format == FORMAT_R) {
+ internal_format = GL_R8;
+ } else if (pixel_format == FORMAT_RG) {
+ internal_format = GL_RG8;
+ } else if (pixel_format == FORMAT_RGB) {
+ internal_format = GL_RGB8;
+ } else {
+ internal_format = GL_RGBA8;
+ }
+ }
+ if (pixel_format == FORMAT_RGB) {
+ format = GL_RGB;
+ } else if (pixel_format == FORMAT_RGBA_PREMULTIPLIED_ALPHA ||
+ pixel_format == FORMAT_RGBA_POSTMULTIPLIED_ALPHA) {
+ format = GL_RGBA;
+ } else if (pixel_format == FORMAT_RG) {
+ format = GL_RG;
+ } else if (pixel_format == FORMAT_R) {
+ format = GL_RED;
+ } else {
+ assert(false);
+ }
+