summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRay <[email protected]>2024-05-05 19:46:31 +0200
committerRay <[email protected]>2024-05-05 19:46:31 +0200
commit34d00d52177230cb3434240c263a0529aa0b4891 (patch)
treedece7b21e111712160742dc94a00b36245ac45c1
parentf1007554a0a8145060797c0aa8169bdaf2c1c6b8 (diff)
downloadraylib-34d00d52177230cb3434240c263a0529aa0b4891.tar.gz
raylib-34d00d52177230cb3434240c263a0529aa0b4891.zip
Minor formatting tweaks
-rw-r--r--examples/shaders/resources/shaders/glsl100/palette_switch.fs16
-rw-r--r--examples/shaders/resources/shaders/glsl330/palette_switch.fs13
-rw-r--r--src/external/rl_gputex.h4
3 files changed, 19 insertions, 14 deletions
diff --git a/examples/shaders/resources/shaders/glsl100/palette_switch.fs b/examples/shaders/resources/shaders/glsl100/palette_switch.fs
index 25b49632..d8d696d4 100644
--- a/examples/shaders/resources/shaders/glsl100/palette_switch.fs
+++ b/examples/shaders/resources/shaders/glsl100/palette_switch.fs
@@ -2,7 +2,7 @@
precision mediump float;
-const int colors = 8;
+const int MAX_INDEXED_COLORS = 8;
// Input vertex attributes (from vertex shader)
varying vec2 fragTexCoord;
@@ -10,7 +10,8 @@ varying vec4 fragColor;
// Input uniform values
uniform sampler2D texture0;
-uniform ivec3 palette[colors];
+uniform ivec3 palette[MAX_INDEXED_COLORS];
+//uniform sampler2D palette; // Alternative to ivec3, palette provided as a 256x1 texture
void main()
{
@@ -18,13 +19,13 @@ void main()
vec4 texelColor = texture2D(texture0, fragTexCoord)*fragColor;
// Convert the (normalized) texel color RED component (GB would work, too)
- // to the palette index by scaling up from [0, 1] to [0, 255].
+ // to the palette index by scaling up from [0..1] to [0..255]
int index = int(texelColor.r*255.0);
-
+
ivec3 color = ivec3(0);
// NOTE: On GLSL 100 we are not allowed to index a uniform array by a variable value,
- // a constantmust be used, so this logic...
+ // a constant must be used, so this logic...
if (index == 0) color = palette[0];
else if (index == 1) color = palette[1];
else if (index == 2) color = palette[2];
@@ -33,9 +34,10 @@ void main()
else if (index == 5) color = palette[5];
else if (index == 6) color = palette[6];
else if (index == 7) color = palette[7];
+
+ //gl_FragColor = texture2D(palette, texelColor.xy); // Alternative to ivec3
// Calculate final fragment color. Note that the palette color components
- // are defined in the range [0, 255] and need to be normalized to [0, 1]
- // for OpenGL to work.
+ // are defined in the range [0..255] and need to be normalized to [0..1]
gl_FragColor = vec4(float(color.x)/255.0, float(color.y)/255.0, float(color.z)/255.0, texelColor.a);
}
diff --git a/examples/shaders/resources/shaders/glsl330/palette_switch.fs b/examples/shaders/resources/shaders/glsl330/palette_switch.fs
index 7c8a488c..6a82529b 100644
--- a/examples/shaders/resources/shaders/glsl330/palette_switch.fs
+++ b/examples/shaders/resources/shaders/glsl330/palette_switch.fs
@@ -1,6 +1,6 @@
#version 330
-const int colors = 8;
+const int MAX_INDEXED_COLORS = 8;
// Input fragment attributes (from fragment shader)
in vec2 fragTexCoord;
@@ -8,7 +8,8 @@ in vec4 fragColor;
// Input uniform values
uniform sampler2D texture0;
-uniform ivec3 palette[colors];
+uniform ivec3 palette[MAX_INDEXED_COLORS];
+//uniform sampler2D palette; // Alternative to ivec3, palette provided as a 256x1 texture
// Output fragment color
out vec4 finalColor;
@@ -16,15 +17,17 @@ out vec4 finalColor;
void main()
{
// Texel color fetching from texture sampler
+ // NOTE: The texel is actually the a GRAYSCALE index color
vec4 texelColor = texture(texture0, fragTexCoord)*fragColor;
// Convert the (normalized) texel color RED component (GB would work, too)
- // to the palette index by scaling up from [0, 1] to [0, 255].
+ // to the palette index by scaling up from [0..1] to [0..255]
int index = int(texelColor.r*255.0);
ivec3 color = palette[index];
+
+ //finalColor = texture(palette, texelColor.xy); // Alternative to ivec3
// Calculate final fragment color. Note that the palette color components
- // are defined in the range [0, 255] and need to be normalized to [0, 1]
- // for OpenGL to work.
+ // are defined in the range [0..255] and need to be normalized to [0..1]
finalColor = vec4(color/255.0, texelColor.a);
}
diff --git a/src/external/rl_gputex.h b/src/external/rl_gputex.h
index 2cbe5963..c5773055 100644
--- a/src/external/rl_gputex.h
+++ b/src/external/rl_gputex.h
@@ -229,7 +229,7 @@ void *rl_load_dds_from_memory(const unsigned char *file_data, unsigned int file_
}
}
}
- else if (header->ddspf.flags == 0x40 && header->ddspf.rgb_bit_count == 24) // DDS_RGB, no compressed
+ else if ((header->ddspf.flags == 0x40) && (header->ddspf.rgb_bit_count == 24)) // DDS_RGB, no compressed
{
int data_size = image_pixel_size*3*sizeof(unsigned char);
image_data = RL_MALLOC(data_size);
@@ -238,7 +238,7 @@ void *rl_load_dds_from_memory(const unsigned char *file_data, unsigned int file_
*format = PIXELFORMAT_UNCOMPRESSED_R8G8B8;
}
- else if (header->ddspf.flags == 0x41 && header->ddspf.rgb_bit_count == 32) // DDS_RGBA, no compressed
+ else if ((header->ddspf.flags == 0x41) && (header->ddspf.rgb_bit_count == 32)) // DDS_RGBA, no compressed
{
int data_size = image_pixel_size*4*sizeof(unsigned char);
image_data = RL_MALLOC(data_size);