Merge remote-tracking branch 'refs/remotes/raysan5/develop' into develop

This commit is contained in:
Joshua Reisenauer
2016-06-07 16:07:57 -07:00
17 changed files with 9814 additions and 9068 deletions

View File

@ -92,13 +92,7 @@ else
endif
# define all object files required
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
OBJS = core.o rlgl.o glad.o shapes.o text.o textures.o models.o audio.o utils.o camera.o gestures.o stb_vorbis.o
else
#GLAD only required on desktop platform
OBJS = core.o rlgl.o shapes.o text.o textures.o models.o audio.o stb_vorbis.o utils.o camera.o gestures.o
endif
OBJS = core.o rlgl.o shapes.o text.o textures.o models.o audio.o utils.o camera.o gestures.o stb_vorbis.o
# typing 'make' will invoke the default target entry called 'all',
# in this case, the 'default' target entry is raylib
@ -153,10 +147,6 @@ camera.o: camera.c
gestures.o: gestures.c
$(CC) -c gestures.c $(CFLAGS) $(INCLUDES) -D$(PLATFORM)
# compile glad module
glad.o: external/glad.c
$(CC) -c external/glad.c $(CFLAGS) $(INCLUDES)
# compile stb_vorbis library
stb_vorbis.o: external/stb_vorbis.c
$(CC) -c external/stb_vorbis.c -O1 $(INCLUDES) -D$(PLATFORM)

View File

@ -46,13 +46,13 @@ LOCAL_SRC_FILES :=\
../../models.c \
../../utils.c \
../../audio.c \
../../stb_vorbis.c \
../../external/stb_vorbis.c \
# Required includes paths (.h)
LOCAL_C_INCLUDES := $(LOCAL_PATH) $(LOCAL_PATH)/include $(LOCAL_PATH)/../..
# Required flags for compilation: defines PLATFORM_ANDROID and GRAPHICS_API_OPENGL_ES2
LOCAL_CFLAGS := -Wall -std=c99 -Wno-missing-braces -g -DPLATFORM_ANDROID -DGRAPHICS_API_OPENGL_ES2
LOCAL_CFLAGS := -Wall -std=c99 -Wno-missing-braces -DPLATFORM_ANDROID -DGRAPHICS_API_OPENGL_ES2
# Build the static library libraylib.a
include $(BUILD_STATIC_LIBRARY)

7684
src/external/glad.c vendored

File diff suppressed because one or more lines are too long

7678
src/external/glad.h vendored

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -48,7 +48,13 @@
#ifdef __APPLE__
#include <OpenGL/gl3.h> // OpenGL 3 library for OSX
#else
#include "external/glad.h" // GLAD library, includes OpenGL headers
#define GLAD_IMPLEMENTATION
#if defined(RLGL_STANDALONE)
#include "glad.h" // GLAD extensions loading library, includes OpenGL headers
#else
#include "external/glad.h" // GLAD extensions loading library, includes OpenGL headers
#endif
#endif
#endif
@ -62,6 +68,10 @@
#include <stdarg.h> // Required for: va_list, va_start(), vfprintf(), va_end() [Used only on TraceLog()]
#endif
#if !defined(GRAPHICS_API_OPENGL_11)
#include "standard_shader.h" // Standard shader to embed
#endif
//----------------------------------------------------------------------------------
// Defines and Macros
//----------------------------------------------------------------------------------
@ -154,10 +164,6 @@ typedef struct {
// TODO: Store draw state -> blending mode, shader
} DrawCall;
#if defined(RLGL_STANDALONE)
typedef enum { INFO = 0, ERROR, WARNING, DEBUG, OTHER } TraceLogType;
#endif
//----------------------------------------------------------------------------------
// Global Variables Definition
//----------------------------------------------------------------------------------
@ -189,26 +195,27 @@ static bool useTempBuffer = false;
// Shader Programs
static Shader defaultShader;
static Shader standardShader;
static Shader currentShader; // By default, defaultShader
static Shader standardShader; // Lazy initialization when GetStandardShader()
static Shader currentShader; // By default, defaultShader
static bool standardShaderLoaded = false;
// Flags for supported extensions
static bool vaoSupported = false; // VAO support (OpenGL ES2 could not support VAO extension)
static bool vaoSupported = false; // VAO support (OpenGL ES2 could not support VAO extension)
// Compressed textures support flags
static bool texCompETC1Supported = false; // ETC1 texture compression support
static bool texCompETC2Supported = false; // ETC2/EAC texture compression support
static bool texCompPVRTSupported = false; // PVR texture compression support
static bool texCompASTCSupported = false; // ASTC texture compression support
static bool texCompETC1Supported = false; // ETC1 texture compression support
static bool texCompETC2Supported = false; // ETC2/EAC texture compression support
static bool texCompPVRTSupported = false; // PVR texture compression support
static bool texCompASTCSupported = false; // ASTC texture compression support
// Lighting data
static Light lights[MAX_LIGHTS]; // Lights pool
static int lightsCount; // Counts current enabled physic objects
static Light lights[MAX_LIGHTS]; // Lights pool
static int lightsCount; // Counts current enabled physic objects
#endif
// Compressed textures support flags
static bool texCompDXTSupported = false; // DDS texture compression support
static bool npotSupported = false; // NPOT textures full support
static bool texCompDXTSupported = false; // DDS texture compression support
static bool npotSupported = false; // NPOT textures full support
#if defined(GRAPHICS_API_OPENGL_ES2)
// NOTE: VAO functionality is exposed through extensions (OES)
@ -253,7 +260,6 @@ static Color *GenNextMipmap(Color *srcData, int srcWidth, int srcHeight);
#endif
#if defined(RLGL_STANDALONE)
static void TraceLog(int msgType, const char *text, ...);
float *MatrixToFloat(Matrix mat); // Converts Matrix to float array
#endif
@ -1031,7 +1037,6 @@ void rlglInit(void)
// Init default Shader (customized for GL 3.3 and ES2)
defaultShader = LoadDefaultShader();
standardShader = LoadStandardShader();
currentShader = defaultShader;
LoadDefaultBuffers(); // Initialize default vertex arrays buffers (lines, triangles, quads)
@ -2184,14 +2189,22 @@ Shader GetDefaultShader(void)
}
// Get default shader
// NOTE: Inits global variable standardShader
Shader GetStandardShader(void)
{
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
return standardShader;
#else
Shader shader = { 0 };
return shader;
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
if (standardShaderLoaded) shader = standardShader;
else
{
// Lazy initialization of standard shader
standardShader = LoadStandardShader();
shader = standardShader;
}
#endif
return shader;
}
// Get shader uniform location
@ -2567,18 +2580,22 @@ static Shader LoadDefaultShader(void)
// Load standard shader
// NOTE: This shader supports:
// - Up to 3 different maps: diffuse, normal, specular
// - Material properties: colAmbient, colDiffuse, colSpecular, glossiness
// - Up to 8 lights: Point, Directional or Spot
// - Up to 3 different maps: diffuse, normal, specular
// - Material properties: colAmbient, colDiffuse, colSpecular, glossiness
// - Up to 8 lights: Point, Directional or Spot
static Shader LoadStandardShader(void)
{
// Load standard shader (TODO: rewrite as char pointers)
Shader shader = LoadShader("resources/shaders/standard.vs", "resources/shaders/standard.fs");
Shader shader;
// Load standard shader (embeded in standard_shader.h)
shader.id = LoadShaderProgram(vStandardShaderStr, fStandardShaderStr);
if (shader.id != 0)
{
LoadDefaultShaderLocations(&shader);
TraceLog(INFO, "[SHDR ID %i] Standard shader loaded successfully", shader.id);
standardShaderLoaded = true;
}
else
{
@ -3327,7 +3344,7 @@ static Color *GenNextMipmap(Color *srcData, int srcWidth, int srcHeight)
#if defined(RLGL_STANDALONE)
// Output a trace log message
// NOTE: Expected msgType: (0)Info, (1)Error, (2)Warning
static void TraceLog(int msgType, const char *text, ...)
void TraceLog(int msgType, const char *text, ...)
{
va_list args;
va_start(args, text);

View File

@ -230,6 +230,9 @@ typedef enum { OPENGL_11 = 1, OPENGL_33, OPENGL_ES_20 } GlVersion;
// Color blending modes (pre-defined)
typedef enum { BLEND_ALPHA = 0, BLEND_ADDITIVE, BLEND_MULTIPLIED } BlendMode;
// TraceLog message types
typedef enum { INFO = 0, ERROR, WARNING, DEBUG, OTHER } TraceLogType;
#endif
#ifdef __cplusplus
@ -339,6 +342,8 @@ void EndBlendMode(void); // End blend
Light CreateLight(int type, Vector3 position, Color diffuse); // Create a new light, initialize it and add to pool
void DestroyLight(Light light); // Destroy a light and take it out of the list
void TraceLog(int msgType, const char *text, ...);
#endif
#ifdef __cplusplus

166
src/standard_shader.h Normal file
View File

@ -0,0 +1,166 @@
// Vertex shader definition to embed, no external file required
const static unsigned char vStandardShaderStr[] =
#if defined(GRAPHICS_API_OPENGL_21)
"#version 120 \n"
#elif defined(GRAPHICS_API_OPENGL_ES2)
"#version 100 \n"
#endif
#if defined(GRAPHICS_API_OPENGL_ES2) || defined(GRAPHICS_API_OPENGL_21)
"attribute vec3 vertexPosition; \n"
"attribute vec3 vertexNormal; \n"
"attribute vec2 vertexTexCoord; \n"
"attribute vec4 vertexColor; \n"
"varying vec3 fragPosition; \n"
"varying vec3 fragNormal; \n"
"varying vec2 fragTexCoord; \n"
"varying vec4 fragColor; \n"
#elif defined(GRAPHICS_API_OPENGL_33)
"#version 330 \n"
"in vec3 vertexPosition; \n"
"in vec3 vertexNormal; \n"
"in vec2 vertexTexCoord; \n"
"in vec4 vertexColor; \n"
"out vec3 fragPosition; \n"
"out vec3 fragNormal; \n"
"out vec2 fragTexCoord; \n"
"out vec4 fragColor; \n"
#endif
"uniform mat4 mvpMatrix; \n"
"void main() \n"
"{ \n"
" fragPosition = vertexPosition; \n"
" fragNormal = vertexNormal; \n"
" fragTexCoord = vertexTexCoord; \n"
" fragColor = vertexColor; \n"
" gl_Position = mvpMatrix*vec4(vertexPosition, 1.0); \n"
"} \n";
// Fragment shader definition to embed, no external file required
const static unsigned char fStandardShaderStr[] =
#if defined(GRAPHICS_API_OPENGL_21)
"#version 120 \n"
#elif defined(GRAPHICS_API_OPENGL_ES2)
"#version 100 \n"
"precision mediump float; \n" // precision required for OpenGL ES2 (WebGL)
#endif
#if defined(GRAPHICS_API_OPENGL_ES2) || defined(GRAPHICS_API_OPENGL_21)
"varying vec3 fragPosition; \n"
"varying vec3 fragNormal; \n"
"varying vec2 fragTexCoord; \n"
"varying vec4 fragColor; \n"
#elif defined(GRAPHICS_API_OPENGL_33)
"#version 330 \n"
"in vec3 fragPosition; \n"
"in vec3 fragNormal; \n"
"in vec2 fragTexCoord; \n"
"in vec4 fragColor; \n"
"out vec4 finalColor; \n"
#endif
"uniform sampler2D texture0; \n"
"uniform sampler2D texture1; \n"
"uniform sampler2D texture2; \n"
"uniform vec4 colAmbient; \n"
"uniform vec4 colDiffuse; \n"
"uniform vec4 colSpecular; \n"
"uniform float glossiness; \n"
"uniform int useNormal; \n"
"uniform int useSpecular; \n"
"uniform mat4 modelMatrix; \n"
"uniform vec3 viewDir; \n"
"struct Light { \n"
" int enabled; \n"
" int type; \n"
" vec3 position; \n"
" vec3 direction; \n"
" vec4 diffuse; \n"
" float intensity; \n"
" float radius; \n"
" float coneAngle; }; \n"
"const int maxLights = 8; \n"
"uniform int lightsCount; \n"
"uniform Light lights[maxLights]; \n"
"\n"
"vec3 CalcPointLight(Light l, vec3 n, vec3 v, float s) \n"
"{\n"
" vec3 surfacePos = vec3(modelMatrix*vec4(fragPosition, 1));\n"
" vec3 surfaceToLight = l.position - surfacePos;\n"
" float brightness = clamp(dot(n, surfaceToLight)/(length(surfaceToLight)*length(n)), 0, 1);\n"
" float diff = 1.0/dot(surfaceToLight/l.radius, surfaceToLight/l.radius)*brightness*l.intensity;\n"
" float spec = 0.0;\n"
" if (diff > 0.0)\n"
" {\n"
" vec3 h = normalize(-l.direction + v);\n"
" spec = pow(dot(n, h), 3 + glossiness)*s;\n"
" }\n"
" return (diff*l.diffuse.rgb + spec*colSpecular.rgb);\n"
"}\n"
"\n"
"vec3 CalcDirectionalLight(Light l, vec3 n, vec3 v, float s)\n"
"{\n"
" vec3 lightDir = normalize(-l.direction);\n"
" float diff = clamp(dot(n, lightDir), 0.0, 1.0)*l.intensity;\n"
" float spec = 0.0;\n"
" if (diff > 0.0)\n"
" {\n"
" vec3 h = normalize(lightDir + v);\n"
" spec = pow(dot(n, h), 3 + glossiness)*s;\n"
" }\n"
" return (diff*l.intensity*l.diffuse.rgb + spec*colSpecular.rgb);\n"
"}\n"
"\n"
"vec3 CalcSpotLight(Light l, vec3 n, vec3 v, float s)\n"
"{\n"
" vec3 surfacePos = vec3(modelMatrix*vec4(fragPosition, 1));\n"
" vec3 lightToSurface = normalize(surfacePos - l.position);\n"
" vec3 lightDir = normalize(-l.direction);\n"
" float diff = clamp(dot(n, lightDir), 0.0, 1.0)*l.intensity;\n"
" float attenuation = clamp(dot(n, lightToSurface), 0.0, 1.0);\n"
" attenuation = dot(lightToSurface, -lightDir);\n"
" float lightToSurfaceAngle = degrees(acos(attenuation));\n"
" if (lightToSurfaceAngle > l.coneAngle) attenuation = 0.0;\n"
" float falloff = (l.coneAngle - lightToSurfaceAngle)/l.coneAngle;\n"
" float diffAttenuation = diff*attenuation;\n"
" float spec = 0.0;\n"
" if (diffAttenuation > 0.0)\n"
" {\n"
" vec3 h = normalize(lightDir + v);\n"
" spec = pow(dot(n, h), 3 + glossiness)*s;\n"
" }\n"
" return (falloff*(diffAttenuation*l.diffuse.rgb + spec*colSpecular.rgb));\n"
"}\n"
"\n"
"void main()\n"
"{\n"
" mat3 normalMatrix = transpose(inverse(mat3(modelMatrix)));\n"
" vec3 normal = normalize(normalMatrix*fragNormal);\n"
" vec3 n = normalize(normal);\n"
" vec3 v = normalize(viewDir);\n"
" vec4 texelColor = texture(texture0, fragTexCoord);\n"
" vec3 lighting = colAmbient.rgb;\n"
" if (useNormal == 1)\n"
" {\n"
" n *= texture(texture1, fragTexCoord).rgb;\n"
" n = normalize(n);\n"
" }\n"
" float spec = 1.0;\n"
" if (useSpecular == 1) spec *= normalize(texture(texture2, fragTexCoord).r);\n"
" for (int i = 0; i < lightsCount; i++)\n"
" {\n"
" if (lights[i].enabled == 1)\n"
" {\n"
" switch (lights[i].type)\n"
" {\n"
" case 0: lighting += CalcPointLight(lights[i], n, v, spec); break;\n"
" case 1: lighting += CalcDirectionalLight(lights[i], n, v, spec); break;\n"
" case 2: lighting += CalcSpotLight(lights[i], n, v, spec); break;\n"
" default: break;\n"
" }\n"
" }\n"
" }\n"
#if defined(GRAPHICS_API_OPENGL_33)
" finalColor = vec4(texelColor.rgb*lighting*colDiffuse.rgb, texelColor.a*colDiffuse.a); \n"
#elif defined(GRAPHICS_API_OPENGL_ES2) || defined(GRAPHICS_API_OPENGL_21)
" gl_FragColor = vec4(texelColor.rgb*lighting*colDiffuse.rgb, texelColor.a*colDiffuse.a); \n"
#endif
"} \n";