Use std::uint8_t in procedural texture code

pull/1288/head
Andrew Tribick 2021-12-29 15:22:26 +01:00 committed by ajtribick
parent 85e5bae406
commit c632aea62d
3 changed files with 13 additions and 12 deletions

View File

@ -112,20 +112,20 @@ constexpr const GalaxyTypeName GalaxyTypeNames[] =
{ "E7", GalaxyType::E7 },
};
void galaxyTextureEval(float u, float v, float /*w*/, unsigned char *pixel)
void galaxyTextureEval(float u, float v, float /*w*/, std::uint8_t *pixel)
{
float r = 0.9f - std::sqrt(u * u + v * v );
if (r < 0)
r = 0;
auto pixVal = static_cast<unsigned char>(r * 255.99f);
auto pixVal = static_cast<std::uint8_t>(r * 255.99f);
pixel[0] = 255;//65;
pixel[1] = 255;//64;
pixel[2] = 255;//65;
pixel[3] = pixVal;
}
void colorTextureEval(float u, float /*v*/, float /*w*/, unsigned char *pixel)
void colorTextureEval(float u, float /*v*/, float /*w*/, std::uint8_t *pixel)
{
unsigned int i = static_cast<unsigned int>((static_cast<float>(u)*0.5f + 0.5f)*255.99f); // [-1, 1] -> [0, 255]
@ -136,9 +136,9 @@ void colorTextureEval(float u, float /*v*/, float /*w*/, unsigned char *pixel)
//convert Hue to RGB
float r, g, b;
DeepSkyObject::hsv2rgb(&r, &g, &b, hue, 0.20f, 1.0f);
pixel[0] = static_cast<unsigned char>(r * 255.99f);
pixel[1] = static_cast<unsigned char>(g * 255.99f);
pixel[2] = static_cast<unsigned char>(b * 255.99f);
pixel[0] = static_cast<std::uint8_t>(r * 255.99f);
pixel[1] = static_cast<std::uint8_t>(g * 255.99f);
pixel[2] = static_cast<std::uint8_t>(b * 255.99f);
}
struct GalaxyVertex

View File

@ -80,7 +80,7 @@ constexpr const float RADIUS_CORRECTION = 0.025f;
float CBin, RRatio, XI, Rr = 1.0f, Gg = 1.0f, Bb = 1.0f;
void globularTextureEval(float u, float v, float /*w*/, unsigned char *pixel)
void globularTextureEval(float u, float v, float /*w*/, std::uint8_t *pixel)
{
// use an exponential luminosity shape for the individual stars
// giving sort of a halo for the brighter (i.e.bigger) stars.
@ -91,7 +91,7 @@ void globularTextureEval(float u, float v, float /*w*/, unsigned char *pixel)
if (lumi <= 0.0f)
lumi = 0.0f;
auto pixVal = static_cast<unsigned char>(lumi * 255.99f);
auto pixVal = static_cast<std::uint8_t>(lumi * 255.99f);
pixel[0] = 255;
pixel[1] = 255;
pixel[2] = 255;
@ -123,7 +123,7 @@ float relStarDensity(float eta)
return ((std::log(rho2) + 4.0f * (1.0f - std::sqrt(rho2)) * Xi) / (rho2 - 1.0f) + XI2) / (1.0f - 2.0f * Xi + XI2);
}
void centerCloudTexEval(float u, float v, float /*w*/, unsigned char *pixel)
void centerCloudTexEval(float u, float v, float /*w*/, std::uint8_t *pixel)
{
/*! For reasons of speed, calculate central "cloud" texture only for
* 8 bins of King_1962 concentration, c = CBin, XI(CBin), RRatio(CBin).
@ -154,7 +154,7 @@ void centerCloudTexEval(float u, float v, float /*w*/, unsigned char *pixel)
pixel[0] = 255;
pixel[1] = 255;
pixel[2] = 255;
pixel[3] = static_cast<unsigned char>(relStarDensity(eta) * profile_2d * 255.99f);
pixel[3] = static_cast<std::uint8_t>(relStarDensity(eta) * profile_2d * 255.99f);
}
void initGlobularData(celgl::VertexObject& vo,

View File

@ -10,13 +10,14 @@
#ifndef _CELENGINE_TEXTURE_H_
#define _CELENGINE_TEXTURE_H_
#include <cstdint>
#include <string>
#include <celutil/color.h>
#include <celcompat/filesystem.h>
#include <celengine/image.h>
typedef void (*ProceduralTexEval)(float, float, float, unsigned char*);
typedef void (*ProceduralTexEval)(float, float, float, std::uint8_t*);
struct TextureTile
@ -40,7 +41,7 @@ class TexelFunctionObject
TexelFunctionObject() {};
virtual ~TexelFunctionObject() {};
virtual void operator()(float u, float v, float w,
unsigned char* pixel) = 0;
std::uint8_t* pixel) = 0;
};