Hash :
49e8de70
Author :
Date :
2015-08-14T10:50:17
Fix remaining size_t conversion warnings. BUG=angleproject:1120 Change-Id: If4fba903511dcd57d21f8f8178e772cf3cae4187 Reviewed-on: https://chromium-review.googlesource.com/293750 Tested-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Geoff Lang <geofflang@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
//
// Copyright (c) 2014 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#include "texture_utils.h"
#include <array>
GLuint CreateSimpleTexture2D()
{
// Use tightly packed data
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
// Generate a texture object
GLuint texture;
glGenTextures(1, &texture);
// Bind the texture object
glBindTexture(GL_TEXTURE_2D, texture);
// Load the texture: 2x2 Image, 3 bytes per pixel (R, G, B)
const size_t width = 2;
const size_t height = 2;
GLubyte pixels[width * height * 3] =
{
255, 0, 0, // Red
0, 255, 0, // Green
0, 0, 255, // Blue
255, 255, 0, // Yellow
};
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, pixels);
// Set the filtering mode
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
return texture;
}
GLuint CreateSimpleTextureCubemap()
{
// Generate a texture object
GLuint texture;
glGenTextures(1, &texture);
// Bind the texture object
glBindTexture(GL_TEXTURE_CUBE_MAP, texture);
// Load the texture faces
GLubyte pixels[6][3] =
{
// Face 0 - Red
{ 255, 0, 0 },
// Face 1 - Green,
{ 0, 255, 0 },
// Face 3 - Blue
{ 0, 0, 255 },
// Face 4 - Yellow
{ 255, 255, 0 },
// Face 5 - Purple
{ 255, 0, 255 },
// Face 6 - White
{ 255, 255, 255 }
};
for (size_t i = 0; i < 6; i++)
{
glTexImage2D(static_cast<GLenum>(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i), 0, GL_RGB, 1, 1, 0,
GL_RGB, GL_UNSIGNED_BYTE, &pixels[i]);
}
// Set the filtering mode
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
return texture;
}
GLuint CreateMipMappedTexture2D()
{
// Texture object handle
const size_t width = 256;
const size_t height = 256;
std::array<GLubyte, width * height * 3> pixels;
const size_t checkerSize = 8;
for (size_t y = 0; y < height; y++)
{
for (size_t x = 0; x < width; x++)
{
GLubyte rColor = 0;
GLubyte bColor = 0;
if ((x / checkerSize) % 2 == 0)
{
rColor = 255 * ((y / checkerSize) % 2);
bColor = 255 * (1 - ((y / checkerSize) % 2));
}
else
{
bColor = 255 * ((y / checkerSize) % 2);
rColor = 255 * (1 - ((y / checkerSize) % 2));
}
pixels[(y * height + x) * 3] = rColor;
pixels[(y * height + x) * 3 + 1] = 0;
pixels[(y * height + x) * 3 + 2] = bColor;
}
}
// Generate a texture object
GLuint texture;
glGenTextures(1, &texture);
// Bind the texture object
glBindTexture(GL_TEXTURE_2D, texture);
// Load mipmap level 0
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, pixels.data());
// Generate mipmaps
glGenerateMipmap(GL_TEXTURE_2D);
// Set the filtering mode
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
return texture;
}