Merge branch 'raysan5:master' into master

This commit is contained in:
Luiz Pestana 2021-08-23 13:35:04 -03:00 committed by GitHub
commit db2e7ce901
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 39 additions and 31 deletions

View File

@ -1,7 +1,7 @@
/*******************************************************************************************
*
* raylib [shaders] example - Apply an shdrOutline to a texture
*
*
* 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,7 +9,7 @@
*
* This example has been created using raylib 3.8 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
*
* Example contributed by Samuel Skiff (@GoldenThumbs)
*
* Copyright (c) 2021 Samuel SKiff (@GoldenThumbs) and Ramon Santamaria (@raysan5)
@ -31,11 +31,11 @@ int main(void)
const int screenWidth = 800;
const int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - Apply an shdrOutline to a texture");
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - Apply an outline to a texture");
Texture2D egg = LoadTexture("resources/egg.png");
Texture2D torus = LoadTexture("resources/torus.png");
Shader shdrOutline = LoadShader(0, TextFormat("resources/shaders/glsl%i/shdrOutline.fs", GLSL_VERSION));
Shader shdrOutline = LoadShader(0, TextFormat("resources/shaders/glsl%i/outline.fs", GLSL_VERSION));
float outlineScale = 16.0f;
float textureScale[2] = { 16.0f*4, 16.0f*4 };

View File

@ -2318,8 +2318,11 @@ Shader LoadShader(const char *vsFileName, const char *fsFileName)
{
Shader shader = { 0 };
char *vShaderStr = LoadFileText(vsFileName);
char *fShaderStr = LoadFileText(fsFileName);
char *vShaderStr = NULL;
char *fShaderStr = NULL;
if (vsFileName != NULL) vShaderStr = LoadFileText(vsFileName);
if (fsFileName != NULL) fShaderStr = LoadFileText(fsFileName);
shader = LoadShaderFromMemory(vShaderStr, fShaderStr);
@ -3617,6 +3620,17 @@ static bool InitGraphicsDevice(int width, int height)
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
glfwSetErrorCallback(ErrorCallback);
/*
// Setup custom allocators to match raylib ones
const GLFWallocator allocator = {
.allocate = MemAlloc,
.deallocate = MemFree,
.reallocate = MemRealloc,
.user = NULL
};
glfwInitAllocator(&allocator);
*/
#if defined(__APPLE__)
glfwInitHint(GLFW_COCOA_CHDIR_RESOURCES, GLFW_FALSE);

View File

@ -137,6 +137,10 @@
#include "raylib.h"
#endif
#ifndef RAYGUIDEF
#define RAYGUIDEF // We are building or using rlgl as a static library (or Linux shared library)
#endif
// Define functions scope to be used internally (static) or externally (extern) to the module including this file
#if defined(_WIN32)
// Microsoft attibutes to tell compiler that symbols are imported/exported from a .dll
@ -144,11 +148,7 @@
#define RAYGUIDEF __declspec(dllexport) // We are building raygui as a Win32 shared library (.dll)
#elif defined(USE_LIBTYPE_SHARED)
#define RAYGUIDEF __declspec(dllimport) // We are using raygui as a Win32 shared library (.dll)
#else
#define RAYGUIDEF // We are building or using raygui as a static library
#endif
#else
#define RAYGUIDEF // We are building or using raygui as a static library (or Linux shared library)
#endif
#if !defined(RAYGUI_MALLOC) && !defined(RAYGUI_CALLOC) && !defined(RAYGUI_FREE)
@ -175,10 +175,6 @@
#define TEXTEDIT_CURSOR_BLINK_FRAMES 20 // Text edit controls cursor blink timming
#if defined(__cplusplus)
extern "C" { // Prevents name mangling of functions
#endif
//----------------------------------------------------------------------------------
// Types and Structures Definition
// NOTE: Some types are required for RAYGUI_STANDALONE usage
@ -231,7 +227,7 @@ extern "C" { // Prevents name mangling of functions
} Texture2D;
// Font character info
typedef struct CharInfo CharInfo;
typedef struct GlyphInfo GlyphInfo;
// TODO: Font type is very coupled to raylib, mostly required by GuiLoadStyle()
// It should be redesigned to be provided by user
@ -240,7 +236,7 @@ extern "C" { // Prevents name mangling of functions
int charsCount; // Number of characters
Texture2D texture; // Characters texture atlas
Rectangle *recs; // Characters rectangles in texture
CharInfo *chars; // Characters info data
GlyphInfo *chars; // Characters info data
} Font;
#endif
@ -412,6 +408,10 @@ typedef enum {
// Module Functions Declaration
//----------------------------------------------------------------------------------
#if defined(__cplusplus)
extern "C" { // Prevents name mangling of functions
#endif
// State modification functions
RAYGUIDEF void GuiEnable(void); // Enable gui controls (global state)
RAYGUIDEF void GuiDisable(void); // Disable gui controls (global state)
@ -495,7 +495,6 @@ RAYGUIDEF void GuiClearIconPixel(int iconId, int x, int y); // Clear icon pi
RAYGUIDEF bool GuiCheckIconPixel(int iconId, int x, int y); // Check icon pixel value
#endif
#if defined(__cplusplus)
} // Prevents name mangling of functions
#endif
@ -1407,11 +1406,11 @@ bool GuiTextBox(Rectangle bounds, char *text, int textSize, bool editMode)
if ((GetTextWidth(text) < (maxWidth - GuiGetStyle(DEFAULT, TEXT_SIZE))) && (key >= 32))
{
int byteLength = 0;
const char *textUtf8 = CodepointToUtf8(key, &byteLength);
const char *textUTF8 = CodepointToUTF8(key, &byteLength);
for (int i = 0; i < byteLength; i++)
{
text[keyCount] = textUtf8[i];
text[keyCount] = textUTF8[i];
keyCount++;
}
@ -2890,7 +2889,7 @@ void GuiLoadStyle(const char *fileName)
for (int i = 0; i < font.charsCount; i++) fread(&font.recs[i], 1, sizeof(Rectangle), rgsFile);
// Load font chars info data
font.chars = (CharInfo *)RAYGUI_CALLOC(font.charsCount, sizeof(CharInfo));
font.chars = (GlyphInfo *)RAYGUI_CALLOC(font.charsCount, sizeof(GlyphInfo));
for (int i = 0; i < font.charsCount; i++)
{
fread(&font.chars[i].value, 1, sizeof(int), rgsFile);
@ -3640,8 +3639,8 @@ static int TextToInteger(const char *text)
return value*sign;
}
// Encode codepoint into utf8 text (char array length returned as parameter)
static const char *CodepointToUtf8(int codepoint, int *byteLength)
// Encode codepoint into UTF-8 text (char array length returned as parameter)
static const char *CodepointToUTF8(int codepoint, int *byteLength)
{
static char utf8[6] = { 0 };
int length = 0;

View File

@ -276,6 +276,7 @@ static void __InsertMemNode(MemPool *const mempool, AllocList *const list, MemNo
mempool->arena.offs += iter->size;
__RemoveMemNode(list, iter);
iter = list->head;
if (iter == NULL) return;
}
const uintptr_t inode = ( uintptr_t )node;
const uintptr_t iiter = ( uintptr_t )iter;

View File

@ -134,6 +134,8 @@
// Other modules (raymath, rlgl) also require some of those types, so,
// to be able to use those other modules as standalone (not depending on raylib)
// this defines are very useful for internal check and avoid type (re)definitions
#define RL_COLOR_TYPE
#define RL_RECTANGLE_TYPE
#define RL_VECTOR2_TYPE
#define RL_VECTOR3_TYPE
#define RL_VECTOR4_TYPE
@ -170,14 +172,6 @@
#define MAGENTA CLITERAL(Color){ 255, 0, 255, 255 } // Magenta
#define RAYWHITE CLITERAL(Color){ 245, 245, 245, 255 } // My own White (raylib logo)
// WARNING: Temporal hacks to avoid breaking old codebases using
// deprecated raylib implementations or definitions
#define GetImageData LoadImageColors
#define FILTER_POINT TEXTURE_FILTER_POINT
#define FILTER_BILINEAR TEXTURE_FILTER_BILINEAR
#define MAP_DIFFUSE MATERIAL_MAP_DIFFUSE
#define UNCOMPRESSED_R8G8B8A8 PIXELFORMAT_UNCOMPRESSED_R8G8B8A8
//----------------------------------------------------------------------------------
// Structures Definition
//----------------------------------------------------------------------------------
@ -324,7 +318,7 @@ typedef struct Mesh {
int vertexCount; // Number of vertices stored in arrays
int triangleCount; // Number of triangles stored (indexed or not)
// Default vertex data
// Vertex attributes data
float *vertices; // Vertex position (XYZ - 3 components per vertex) (shader-location = 0)
float *texcoords; // Vertex texture coordinates (UV - 2 components per vertex) (shader-location = 1)
float *texcoords2; // Vertex second texture coordinates (useful for lightmaps) (shader-location = 5)