Skip to content
Snippets Groups Projects
Commit 43e51154 authored by Micah Elizabeth Scott's avatar Micah Elizabeth Scott
Browse files

Use a different name for integer-coordinate samplers

It was too easy to accidentally use the integer version before. Now it's convenient to sample from floats or a Vec2.
parent 40ce47dc
No related branches found
No related tags found
No related merge requests found
...@@ -50,10 +50,11 @@ public: ...@@ -50,10 +50,11 @@ public:
// Interpolated sampling. Texture coordinates in the range [0, 1] // Interpolated sampling. Texture coordinates in the range [0, 1]
Vec3 sample(Vec2 texcoord); Vec3 sample(Vec2 texcoord);
Vec3 sample(float x, float y);
// Raw sampling, integer pixel coordinates. // Raw sampling, integer pixel coordinates.
uint32_t sampleRGBA32(int x, int y); uint32_t sampleIntRGBA32(int x, int y);
Vec3 sample(int x, int y); Vec3 sampleInt(int x, int y);
private: private:
unsigned long width, height; unsigned long width, height;
...@@ -129,7 +130,7 @@ inline bool Texture::isLoaded() ...@@ -129,7 +130,7 @@ inline bool Texture::isLoaded()
return width && height; return width && height;
} }
inline uint32_t Texture::sampleRGBA32(int x, int y) inline uint32_t Texture::sampleIntRGBA32(int x, int y)
{ {
if (!isLoaded()) { if (!isLoaded()) {
return 0; return 0;
...@@ -140,9 +141,9 @@ inline uint32_t Texture::sampleRGBA32(int x, int y) ...@@ -140,9 +141,9 @@ inline uint32_t Texture::sampleRGBA32(int x, int y)
return ((uint32_t*)(&pixels[0]))[ x + y * width ]; return ((uint32_t*)(&pixels[0]))[ x + y * width ];
} }
inline Vec3 Texture::sample(int x, int y) inline Vec3 Texture::sampleInt(int x, int y)
{ {
uint32_t rgba = sampleRGBA32(x, y); uint32_t rgba = sampleIntRGBA32(x, y);
return Vec3( return Vec3(
((rgba ) & 0xFF) / 255.0f, ((rgba ) & 0xFF) / 255.0f,
((rgba >> 8 ) & 0xFF) / 255.0f, ((rgba >> 8 ) & 0xFF) / 255.0f,
...@@ -151,17 +152,22 @@ inline Vec3 Texture::sample(int x, int y) ...@@ -151,17 +152,22 @@ inline Vec3 Texture::sample(int x, int y)
inline Vec3 Texture::sample(Vec2 texcoord) inline Vec3 Texture::sample(Vec2 texcoord)
{ {
float fx = texcoord[0] * width; return sample(texcoord[0], texcoord[1]);
float fy = texcoord[1] * height; }
inline Vec3 Texture::sample(float x, float y)
{
float fx = x * width;
float fy = y * height;
int ix = fx; int ix = fx;
int iy = fy; int iy = fy;
// Sample four points // Sample four points
Vec3 aa = sample(ix, iy); Vec3 aa = sampleInt(ix, iy);
Vec3 ba = sample(ix + 1, iy); Vec3 ba = sampleInt(ix + 1, iy);
Vec3 ab = sample(ix, iy + 1); Vec3 ab = sampleInt(ix, iy + 1);
Vec3 bb = sample(ix + 1, iy + 1); Vec3 bb = sampleInt(ix + 1, iy + 1);
// X interpolation // X interpolation
Vec3 ca = aa + (ba - aa) * (fx - ix); Vec3 ca = aa + (ba - aa) * (fx - ix);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment