aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorRay <raysan5@gmail.com>2019-01-10 11:25:26 +0100
committerRay <raysan5@gmail.com>2019-01-10 11:25:26 +0100
commit55f8dbc755c2e31d2112e71439fef0d31e8090a6 (patch)
treee55e8b27cf4ef488167acd7bac9ec8a62c92ac97 /examples
parent7c4a0f963dfc6f089337158ea6b78b84f4022368 (diff)
downloadraylib-55f8dbc755c2e31d2112e71439fef0d31e8090a6.tar.gz
raylib-55f8dbc755c2e31d2112e71439fef0d31e8090a6.zip
WARNING: Redesigned SetShaderValue()
Diffstat (limited to 'examples')
-rw-r--r--examples/models/models_material_pbr.c20
-rw-r--r--examples/models/models_skybox.c4
-rw-r--r--examples/models/rlights.h10
-rw-r--r--examples/others/standard_lighting.c25
-rw-r--r--examples/shaders/resources/shaders/glsl330/palette-switch.fs2
-rw-r--r--examples/shaders/shaders_custom_uniform.c2
-rw-r--r--examples/shaders/shaders_palette_switch.c24
-rw-r--r--examples/shaders/shaders_raymarching.c12
8 files changed, 50 insertions, 49 deletions
diff --git a/examples/models/models_material_pbr.c b/examples/models/models_material_pbr.c
index 6885f753..f93c7a68 100644
--- a/examples/models/models_material_pbr.c
+++ b/examples/models/models_material_pbr.c
@@ -64,7 +64,7 @@ int main()
// Send to material PBR shader camera view position
float cameraPos[3] = { camera.position.x, camera.position.y, camera.position.z };
- SetShaderValue(model.material.shader, model.material.shader.locs[LOC_VECTOR_VIEW], cameraPos, 3);
+ SetShaderValue(model.material.shader, model.material.shader.locs[LOC_VECTOR_VIEW], cameraPos, UNIFORM_VEC3);
//----------------------------------------------------------------------------------
// Draw
@@ -148,9 +148,9 @@ static Material LoadMaterialPBR(Color albedo, float metalness, float roughness)
Shader shdrBRDF = LoadShader(PATH_BRDF_VS, PATH_BRDF_FS);
// Setup required shader locations
- SetShaderValuei(shdrCubemap, GetShaderLocation(shdrCubemap, "equirectangularMap"), (int[1]){ 0 }, 1);
- SetShaderValuei(shdrIrradiance, GetShaderLocation(shdrIrradiance, "environmentMap"), (int[1]){ 0 }, 1);
- SetShaderValuei(shdrPrefilter, GetShaderLocation(shdrPrefilter, "environmentMap"), (int[1]){ 0 }, 1);
+ SetShaderValue(shdrCubemap, GetShaderLocation(shdrCubemap, "equirectangularMap"), (int[1]){ 0 }, UNIFORM_INT);
+ SetShaderValue(shdrIrradiance, GetShaderLocation(shdrIrradiance, "environmentMap"), (int[1]){ 0 }, UNIFORM_INT);
+ SetShaderValue(shdrPrefilter, GetShaderLocation(shdrPrefilter, "environmentMap"), (int[1]){ 0 }, UNIFORM_INT);
Texture2D texHDR = LoadTexture("resources/dresden_square.hdr");
Texture2D cubemap = GenTextureCubemap(shdrCubemap, texHDR, CUBEMAP_SIZE);
@@ -174,14 +174,14 @@ static Material LoadMaterialPBR(Color albedo, float metalness, float roughness)
SetTextureFilter(mat.maps[MAP_OCCLUSION].texture, FILTER_BILINEAR);
// Enable sample usage in shader for assigned textures
- SetShaderValuei(mat.shader, GetShaderLocation(mat.shader, "albedo.useSampler"), (int[1]){ 1 }, 1);
- SetShaderValuei(mat.shader, GetShaderLocation(mat.shader, "normals.useSampler"), (int[1]){ 1 }, 1);
- SetShaderValuei(mat.shader, GetShaderLocation(mat.shader, "metalness.useSampler"), (int[1]){ 1 }, 1);
- SetShaderValuei(mat.shader, GetShaderLocation(mat.shader, "roughness.useSampler"), (int[1]){ 1 }, 1);
- SetShaderValuei(mat.shader, GetShaderLocation(mat.shader, "occlusion.useSampler"), (int[1]){ 1 }, 1);
+ SetShaderValue(mat.shader, GetShaderLocation(mat.shader, "albedo.useSampler"), (int[1]){ 1 }, UNIFORM_INT);
+ SetShaderValue(mat.shader, GetShaderLocation(mat.shader, "normals.useSampler"), (int[1]){ 1 }, UNIFORM_INT);
+ SetShaderValue(mat.shader, GetShaderLocation(mat.shader, "metalness.useSampler"), (int[1]){ 1 }, UNIFORM_INT);
+ SetShaderValue(mat.shader, GetShaderLocation(mat.shader, "roughness.useSampler"), (int[1]){ 1 }, UNIFORM_INT);
+ SetShaderValue(mat.shader, GetShaderLocation(mat.shader, "occlusion.useSampler"), (int[1]){ 1 }, UNIFORM_INT);
int renderModeLoc = GetShaderLocation(mat.shader, "renderMode");
- SetShaderValuei(mat.shader, renderModeLoc, (int[1]){ 0 }, 1);
+ SetShaderValue(mat.shader, renderModeLoc, (int[1]){ 0 }, UNIFORM_INT);
// Set up material properties color
mat.maps[MAP_ALBEDO].color = albedo;
diff --git a/examples/models/models_skybox.c b/examples/models/models_skybox.c
index a6b233e3..c7f76ecf 100644
--- a/examples/models/models_skybox.c
+++ b/examples/models/models_skybox.c
@@ -30,11 +30,11 @@ int main()
// Load skybox shader and set required locations
// NOTE: Some locations are automatically set at shader loading
skybox.material.shader = LoadShader("resources/shaders/skybox.vs", "resources/shaders/skybox.fs");
- SetShaderValuei(skybox.material.shader, GetShaderLocation(skybox.material.shader, "environmentMap"), (int[1]){ MAP_CUBEMAP }, 1);
+ SetShaderValue(skybox.material.shader, GetShaderLocation(skybox.material.shader, "environmentMap"), (int[1]){ MAP_CUBEMAP }, UNIFORM_INT);
// Load cubemap shader and setup required shader locations
Shader shdrCubemap = LoadShader("resources/shaders/cubemap.vs", "resources/shaders/cubemap.fs");
- SetShaderValuei(shdrCubemap, GetShaderLocation(shdrCubemap, "equirectangularMap"), (int[1]){ 0 }, 1);
+ SetShaderValue(shdrCubemap, GetShaderLocation(shdrCubemap, "equirectangularMap"), (int[1]){ 0 }, UNIFORM_INT);
// Load HDR panorama (sphere) texture
Texture2D texHDR = LoadTexture("resources/dresden_square.hdr");
diff --git a/examples/models/rlights.h b/examples/models/rlights.h
index 0da3e2cb..19504473 100644
--- a/examples/models/rlights.h
+++ b/examples/models/rlights.h
@@ -158,20 +158,20 @@ Light CreateLight(int type, Vector3 pos, Vector3 targ, Color color, Shader shade
void UpdateLightValues(Shader shader, Light light)
{
// Send to shader light enabled state and type
- SetShaderValuei(shader, light.enabledLoc, (int[1]){ light.enabled }, 1);
- SetShaderValuei(shader, light.typeLoc, (int[1]){ light.type }, 1);
+ SetShaderValue(shader, light.enabledLoc, &light.enabled, UNIFORM_INT);
+ SetShaderValue(shader, light.typeLoc, &light.type, UNIFORM_INT);
// Send to shader light position values
float position[3] = { light.position.x, light.position.y, light.position.z };
- SetShaderValue(shader, light.posLoc, position, 3);
+ SetShaderValue(shader, light.posLoc, position, UNIFORM_VEC3);
// Send to shader light target position values
float target[3] = { light.target.x, light.target.y, light.target.z };
- SetShaderValue(shader, light.targetLoc, target, 3);
+ SetShaderValue(shader, light.targetLoc, target, UNIFORM_VEC3);
// Send to shader light color values
float diff[4] = { (float)light.color.r/(float)255, (float)light.color.g/(float)255, (float)light.color.b/(float)255, (float)light.color.a/(float)255 };
- SetShaderValue(shader, light.colorLoc, diff, 4);
+ SetShaderValue(shader, light.colorLoc, diff, UNIFORM_VEC4);
}
#endif // RLIGHTS_IMPLEMENTATION \ No newline at end of file
diff --git a/examples/others/standard_lighting.c b/examples/others/standard_lighting.c
index 72890436..7034aa35 100644
--- a/examples/others/standard_lighting.c
+++ b/examples/others/standard_lighting.c
@@ -350,9 +350,6 @@ static void GetShaderLightsLocations(Shader shader)
// Set shader uniform values for lights
// NOTE: It would be far easier with shader UBOs but are not supported on OpenGL ES 2.0
-// TODO: Replace glUniform1i(), glUniform1f(), glUniform3f(), glUniform4f():
-//SetShaderValue(Shader shader, int uniformLoc, float *value, int size)
-//SetShaderValuei(Shader shader, int uniformLoc, int *value, int size)
static void SetShaderLightsValues(Shader shader)
{
int tempInt[8] = { 0 };
@@ -363,20 +360,20 @@ static void SetShaderLightsValues(Shader shader)
if (i < lightsCount)
{
tempInt[0] = lights[i]->enabled;
- SetShaderValuei(shader, lightsLocs[i][0], tempInt, 1); //glUniform1i(lightsLocs[i][0], lights[i]->enabled);
+ SetShaderValue(shader, lightsLocs[i][0], tempInt, UNIFORM_INT); //glUniform1i(lightsLocs[i][0], lights[i]->enabled);
tempInt[0] = lights[i]->type;
- SetShaderValuei(shader, lightsLocs[i][1], tempInt, 1); //glUniform1i(lightsLocs[i][1], lights[i]->type);
+ SetShaderValue(shader, lightsLocs[i][1], tempInt, UNIFORM_INT); //glUniform1i(lightsLocs[i][1], lights[i]->type);
tempFloat[0] = (float)lights[i]->diffuse.r/255.0f;
tempFloat[1] = (float)lights[i]->diffuse.g/255.0f;
tempFloat[2] = (float)lights[i]->diffuse.b/255.0f;
tempFloat[3] = (float)lights[i]->diffuse.a/255.0f;
- SetShaderValue(shader, lightsLocs[i][5], tempFloat, 4);
+ SetShaderValue(shader, lightsLocs[i][5], tempFloat, UNIFORM_VEC4);
//glUniform4f(lightsLocs[i][5], (float)lights[i]->diffuse.r/255, (float)lights[i]->diffuse.g/255, (float)lights[i]->diffuse.b/255, (float)lights[i]->diffuse.a/255);
tempFloat[0] = lights[i]->intensity;
- SetShaderValue(shader, lightsLocs[i][6], tempFloat, 1);
+ SetShaderValue(shader, lightsLocs[i][6], tempFloat, UNIFORM_FLOAT);
switch (lights[i]->type)
{
@@ -385,10 +382,10 @@ static void SetShaderLightsValues(Shader shader)
tempFloat[0] = lights[i]->position.x;
tempFloat[1] = lights[i]->position.y;
tempFloat[2] = lights[i]->position.z;
- SetShaderValue(shader, lightsLocs[i][2], tempFloat, 3);
+ SetShaderValue(shader, lightsLocs[i][2], tempFloat, UNIFORM_VEC3);
tempFloat[0] = lights[i]->radius;
- SetShaderValue(shader, lightsLocs[i][4], tempFloat, 1);
+ SetShaderValue(shader, lightsLocs[i][4], tempFloat, UNIFORM_FLOAT);
//glUniform3f(lightsLocs[i][2], lights[i]->position.x, lights[i]->position.y, lights[i]->position.z);
//glUniform1f(lightsLocs[i][4], lights[i]->radius);
@@ -401,7 +398,7 @@ static void SetShaderLightsValues(Shader shader)
tempFloat[0] = direction.x;
tempFloat[1] = direction.y;
tempFloat[2] = direction.z;
- SetShaderValue(shader, lightsLocs[i][3], tempFloat, 3);
+ SetShaderValue(shader, lightsLocs[i][3], tempFloat, UNIFORM_VEC3);
//glUniform3f(lightsLocs[i][3], direction.x, direction.y, direction.z);
} break;
@@ -410,7 +407,7 @@ static void SetShaderLightsValues(Shader shader)
tempFloat[0] = lights[i]->position.x;
tempFloat[1] = lights[i]->position.y;
tempFloat[2] = lights[i]->position.z;
- SetShaderValue(shader, lightsLocs[i][2], tempFloat, 3);
+ SetShaderValue(shader, lightsLocs[i][2], tempFloat, UNIFORM_VEC3);
//glUniform3f(lightsLocs[i][2], lights[i]->position.x, lights[i]->position.y, lights[i]->position.z);
@@ -420,11 +417,11 @@ static void SetShaderLightsValues(Shader shader)
tempFloat[0] = direction.x;
tempFloat[1] = direction.y;
tempFloat[2] = direction.z;
- SetShaderValue(shader, lightsLocs[i][3], tempFloat, 3);
+ SetShaderValue(shader, lightsLocs[i][3], tempFloat, UNIFORM_VEC3);
//glUniform3f(lightsLocs[i][3], direction.x, direction.y, direction.z);
tempFloat[0] = lights[i]->coneAngle;
- SetShaderValue(shader, lightsLocs[i][7], tempFloat, 1);
+ SetShaderValue(shader, lightsLocs[i][7], tempFloat, UNIFORM_FLOAT);
//glUniform1f(lightsLocs[i][7], lights[i]->coneAngle);
} break;
default: break;
@@ -433,7 +430,7 @@ static void SetShaderLightsValues(Shader shader)
else
{
tempInt[0] = 0;
- SetShaderValuei(shader, lightsLocs[i][0], tempInt, 1); //glUniform1i(lightsLocs[i][0], 0); // Light disabled
+ SetShaderValue(shader, lightsLocs[i][0], tempInt, UNIFORM_INT); //glUniform1i(lightsLocs[i][0], 0); // Light disabled
}
}
}
diff --git a/examples/shaders/resources/shaders/glsl330/palette-switch.fs b/examples/shaders/resources/shaders/glsl330/palette-switch.fs
index 178c42c5..61b532ed 100644
--- a/examples/shaders/resources/shaders/glsl330/palette-switch.fs
+++ b/examples/shaders/resources/shaders/glsl330/palette-switch.fs
@@ -16,7 +16,7 @@ out vec4 finalColor;
void main()
{
// Texel color fetching from texture sampler
- vec4 texelColor = texture(texture0, fragTexCoord) * fragColor;
+ 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].
diff --git a/examples/shaders/shaders_custom_uniform.c b/examples/shaders/shaders_custom_uniform.c
index de76a376..fbfd82d0 100644
--- a/examples/shaders/shaders_custom_uniform.c
+++ b/examples/shaders/shaders_custom_uniform.c
@@ -79,7 +79,7 @@ int main()
swirlCenter[1] = screenHeight - mousePosition.y;
// Send new value to the shader to be used on drawing
- SetShaderValue(shader, swirlCenterLoc, swirlCenter, 2);
+ SetShaderValue(shader, swirlCenterLoc, swirlCenter, UNIFORM_VEC2);
UpdateCamera(&camera); // Update camera
//----------------------------------------------------------------------------------
diff --git a/examples/shaders/shaders_palette_switch.c b/examples/shaders/shaders_palette_switch.c
index ad09ca73..d0b56190 100644
--- a/examples/shaders/shaders_palette_switch.c
+++ b/examples/shaders/shaders_palette_switch.c
@@ -1,6 +1,6 @@
/*******************************************************************************************
*
-* raylib [shaders] example - Apply a postprocessing shader to a scene
+* raylib [shaders] example - Color palette switch
*
* NOTE: This example requires raylib OpenGL 3.3 or ES2 versions for shaders support,
* OpenGL 1.1 does not support shaders, recompile raylib to OpenGL 3.3 version.
@@ -9,10 +9,10 @@
* on OpenGL ES 2.0 platforms (Android, Raspberry Pi, HTML5), use #version 100 shaders
* raylib comes with shaders ready for both versions, check raylib/shaders install folder
*
-* This example has been created using raylib 2.x (www.raylib.com)
+* This example has been created using raylib 2.3 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
-* Copyright (c) 2015 Ramon Santamaria (@raysan5)
+* Copyright (c) 2019 Ramon Santamaria (@raysan5)
*
********************************************************************************************/
@@ -28,7 +28,7 @@
#define COLORS_PER_PALETTE 8
#define VALUES_PER_COLOR 3
-static const int palettes[MAX_PALETTES][COLORS_PER_PALETTE * VALUES_PER_COLOR] = {
+static const int palettes[MAX_PALETTES][COLORS_PER_PALETTE*VALUES_PER_COLOR] = {
{
0, 0, 0,
255, 0, 0,
@@ -74,7 +74,7 @@ int main()
int screenWidth = 800;
int screenHeight = 450;
- InitWindow(screenWidth, screenHeight, "raylib [shaders] example - palette-switch shader");
+ InitWindow(screenWidth, screenHeight, "raylib [shaders] example - color palette switch");
// Load shader to be used on some parts drawing
// NOTE 1: Using GLSL 330 shader version, on OpenGL ES 2.0 use GLSL 100 shader version
@@ -106,9 +106,10 @@ int main()
// Send new value to the shader to be used on drawing.
// Note that we are sending RGB triplets w/o the alpha channel *only* if the current
// palette index has changed (in order to save performances).
- if (currentPalette != paletteIndex) {
+ if (currentPalette != paletteIndex)
+ {
currentPalette = paletteIndex;
- SetShaderValueArrayi(shader, paletteLoc, palettes[currentPalette], VALUES_PER_COLOR, COLORS_PER_PALETTE);
+ SetShaderValueV(shader, paletteLoc, palettes[currentPalette], UNIFORM_IVEC3, COLORS_PER_PALETTE);
}
//----------------------------------------------------------------------------------
@@ -126,14 +127,17 @@ int main()
int leftover = screenHeight % COLORS_PER_PALETTE;
int y = 0;
- for (int i = 0; i < COLORS_PER_PALETTE; ++i) {
+ for (int i = 0; i < COLORS_PER_PALETTE; ++i)
+ {
int height = linesPerRectangle;
- if (leftover > 0) {
+
+ if (leftover > 0)
+ {
height += 1;
leftover -= 1;
}
- DrawRectangle(0, y, screenWidth, height, CLITERAL{ i, i, i, 255 });
+ DrawRectangle(0, y, screenWidth, height, (Color){ i, i, i, 255 });
y += height;
}
diff --git a/examples/shaders/shaders_raymarching.c b/examples/shaders/shaders_raymarching.c
index d1f9d5f8..79868a2a 100644
--- a/examples/shaders/shaders_raymarching.c
+++ b/examples/shaders/shaders_raymarching.c
@@ -48,7 +48,7 @@ int main()
int resolutionLoc = GetShaderLocation(shader, "resolution");
float resolution[2] = { screenWidth, screenHeight };
- SetShaderValue(shader, resolutionLoc, resolution, 2);
+ SetShaderValue(shader, resolutionLoc, resolution, UNIFORM_VEC2);
float runTime = 0.0f;
@@ -70,11 +70,11 @@ int main()
runTime += deltaTime;
// Set shader required uniform values
- SetShaderValue(shader, viewEyeLoc, cameraPos, 3);
- SetShaderValue(shader, viewCenterLoc, cameraTarget, 3);
- SetShaderValue(shader, viewUpLoc, cameraUp, 3);
- SetShaderValue(shader, deltaTimeLoc, &deltaTime, 1);
- SetShaderValue(shader, runTimeLoc, &runTime, 1);
+ SetShaderValue(shader, viewEyeLoc, cameraPos, UNIFORM_VEC3);
+ SetShaderValue(shader, viewCenterLoc, cameraTarget, UNIFORM_VEC3);
+ SetShaderValue(shader, viewUpLoc, cameraUp, UNIFORM_VEC3);
+ SetShaderValue(shader, deltaTimeLoc, &deltaTime, UNIFORM_FLOAT);
+ SetShaderValue(shader, runTimeLoc, &runTime, UNIFORM_FLOAT);
//----------------------------------------------------------------------------------
// Draw