|
@@ -12,7 +12,7 @@
|
|
|
|
|
|
namespace GL {
|
|
namespace GL {
|
|
|
|
|
|
-void Texture2D::upload_texture_data(GLenum, GLint lod, GLint internal_format, GLsizei width, GLsizei height, GLint, GLenum format, GLenum, const GLvoid* pixels)
|
|
|
|
|
|
+void Texture2D::upload_texture_data(GLenum, GLint lod, GLint internal_format, GLsizei width, GLsizei height, GLint, GLenum format, GLenum, const GLvoid* pixels, size_t pixels_per_row)
|
|
{
|
|
{
|
|
// NOTE: Some target, format, and internal formats are currently unsupported.
|
|
// NOTE: Some target, format, and internal formats are currently unsupported.
|
|
// Considering we control this library, and `gl.h` itself, we don't need to add any
|
|
// Considering we control this library, and `gl.h` itself, we don't need to add any
|
|
@@ -34,44 +34,68 @@ void Texture2D::upload_texture_data(GLenum, GLint lod, GLint internal_format, GL
|
|
|
|
|
|
mip.pixel_data().clear();
|
|
mip.pixel_data().clear();
|
|
if (format == GL_RGBA) {
|
|
if (format == GL_RGBA) {
|
|
- for (auto i = 0; i < width * height * 4; i += 4) {
|
|
|
|
- u32 r = pixel_byte_array[i + 0];
|
|
|
|
- u32 g = pixel_byte_array[i + 1];
|
|
|
|
- u32 b = pixel_byte_array[i + 2];
|
|
|
|
- u32 a = pixel_byte_array[i + 3];
|
|
|
|
-
|
|
|
|
- u32 pixel = ((a << 24) | (r << 16) | (g << 8) | b);
|
|
|
|
- mip.pixel_data().append(pixel);
|
|
|
|
|
|
+ for (auto y = 0; y < height; y++) {
|
|
|
|
+ for (auto x = 0; x < width; x++) {
|
|
|
|
+ u32 r = *pixel_byte_array++;
|
|
|
|
+ u32 g = *pixel_byte_array++;
|
|
|
|
+ u32 b = *pixel_byte_array++;
|
|
|
|
+ u32 a = *pixel_byte_array++;
|
|
|
|
+
|
|
|
|
+ u32 pixel = ((a << 24) | (r << 16) | (g << 8) | b);
|
|
|
|
+ mip.pixel_data().append(pixel);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (pixels_per_row > 0) {
|
|
|
|
+ pixel_byte_array += (pixels_per_row - width) * 4;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
} else if (format == GL_BGRA) {
|
|
} else if (format == GL_BGRA) {
|
|
- for (auto i = 0; i < width * height * 4; i += 4) {
|
|
|
|
- u32 b = pixel_byte_array[i + 0];
|
|
|
|
- u32 g = pixel_byte_array[i + 1];
|
|
|
|
- u32 r = pixel_byte_array[i + 2];
|
|
|
|
- u32 a = pixel_byte_array[i + 3];
|
|
|
|
-
|
|
|
|
- u32 pixel = ((a << 24) | (r << 16) | (g << 8) | b);
|
|
|
|
- mip.pixel_data().append(pixel);
|
|
|
|
|
|
+ for (auto y = 0; y < height; y++) {
|
|
|
|
+ for (auto x = 0; x < width; x++) {
|
|
|
|
+ u32 b = *pixel_byte_array++;
|
|
|
|
+ u32 g = *pixel_byte_array++;
|
|
|
|
+ u32 r = *pixel_byte_array++;
|
|
|
|
+ u32 a = *pixel_byte_array++;
|
|
|
|
+
|
|
|
|
+ u32 pixel = ((a << 24) | (r << 16) | (g << 8) | b);
|
|
|
|
+ mip.pixel_data().append(pixel);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (pixels_per_row > 0) {
|
|
|
|
+ pixel_byte_array += (pixels_per_row - width) * 4;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
} else if (format == GL_BGR) {
|
|
} else if (format == GL_BGR) {
|
|
- for (auto i = 0; i < width * height * 3; i += 3) {
|
|
|
|
- u32 b = pixel_byte_array[i + 0];
|
|
|
|
- u32 g = pixel_byte_array[i + 1];
|
|
|
|
- u32 r = pixel_byte_array[i + 2];
|
|
|
|
- u32 a = 255;
|
|
|
|
-
|
|
|
|
- u32 pixel = ((a << 24) | (r << 16) | (g << 8) | b);
|
|
|
|
- mip.pixel_data().append(pixel);
|
|
|
|
|
|
+ for (auto y = 0; y < height; y++) {
|
|
|
|
+ for (auto x = 0; x < width; x++) {
|
|
|
|
+ u32 b = *pixel_byte_array++;
|
|
|
|
+ u32 g = *pixel_byte_array++;
|
|
|
|
+ u32 r = *pixel_byte_array++;
|
|
|
|
+ u32 a = 255;
|
|
|
|
+
|
|
|
|
+ u32 pixel = ((a << 24) | (r << 16) | (g << 8) | b);
|
|
|
|
+ mip.pixel_data().append(pixel);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (pixels_per_row > 0) {
|
|
|
|
+ pixel_byte_array += (pixels_per_row - width) * 3;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
} else if (format == GL_RGB) {
|
|
} else if (format == GL_RGB) {
|
|
- for (auto i = 0; i < width * height * 3; i += 3) {
|
|
|
|
- u32 r = pixel_byte_array[i + 0];
|
|
|
|
- u32 g = pixel_byte_array[i + 1];
|
|
|
|
- u32 b = pixel_byte_array[i + 2];
|
|
|
|
- u32 a = 255;
|
|
|
|
-
|
|
|
|
- u32 pixel = ((a << 24) | (r << 16) | (g << 8) | b);
|
|
|
|
- mip.pixel_data().append(pixel);
|
|
|
|
|
|
+ for (auto y = 0; y < height; y++) {
|
|
|
|
+ for (auto x = 0; x < width; x++) {
|
|
|
|
+ u32 r = *pixel_byte_array++;
|
|
|
|
+ u32 g = *pixel_byte_array++;
|
|
|
|
+ u32 b = *pixel_byte_array++;
|
|
|
|
+ u32 a = 255;
|
|
|
|
+
|
|
|
|
+ u32 pixel = ((a << 24) | (r << 16) | (g << 8) | b);
|
|
|
|
+ mip.pixel_data().append(pixel);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (pixels_per_row > 0) {
|
|
|
|
+ pixel_byte_array += (pixels_per_row - width) * 3;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
VERIFY_NOT_REACHED();
|
|
VERIFY_NOT_REACHED();
|