Merge branch 'master' of https://github.com/raysan5/raylib into raysan5-master

# Conflicts:
#	src/raylib.h
This commit is contained in:
Jak Barnes 2019-03-10 23:56:30 +00:00
commit 983d31c9d0
9 changed files with 1199 additions and 1265 deletions

View file

@ -273,6 +273,7 @@ static GLFWwindow *window; // Native window (graphic device
#endif #endif
static bool windowReady = false; // Check if window has been initialized successfully static bool windowReady = false; // Check if window has been initialized successfully
static bool windowMinimized = false; // Check if window has been minimized static bool windowMinimized = false; // Check if window has been minimized
static bool windowResized = false; // Check if window has been resized
static const char *windowTitle = NULL; // Window text title... static const char *windowTitle = NULL; // Window text title...
static unsigned int displayWidth, displayHeight;// Display width and height (monitor, device-screen, LCD, ...) static unsigned int displayWidth, displayHeight;// Display width and height (monitor, device-screen, LCD, ...)
@ -742,6 +743,16 @@ bool IsWindowMinimized(void)
#endif #endif
} }
// Check if window has been resized
bool IsWindowResized(void)
{
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB) || defined(PLATFORM_UWP)
return windowResized;
#else
return false;
#endif
}
// Check if window is currently hidden // Check if window is currently hidden
bool IsWindowHidden(void) bool IsWindowHidden(void)
{ {
@ -990,6 +1001,8 @@ const char *GetClipboardText(void)
{ {
#if defined(PLATFORM_DESKTOP) #if defined(PLATFORM_DESKTOP)
return glfwGetClipboardString(window); return glfwGetClipboardString(window);
#else
return NULL;
#endif #endif
} }
@ -3136,6 +3149,8 @@ static void PollInputEvents(void)
} }
} }
windowResized = false;
#if defined(SUPPORT_EVENTS_WAITING) #if defined(SUPPORT_EVENTS_WAITING)
glfwWaitEvents(); glfwWaitEvents();
#else #else
@ -3412,6 +3427,8 @@ static void WindowSizeCallback(GLFWwindow *window, int width, int height)
currentHeight = height; currentHeight = height;
// NOTE: Postprocessing texture is not scaled to new size // NOTE: Postprocessing texture is not scaled to new size
windowResized = true;
} }
// GLFW3 WindowIconify Callback, runs when window is minimized/restored // GLFW3 WindowIconify Callback, runs when window is minimized/restored
@ -4319,7 +4336,7 @@ static void *EventThread(void *arg)
// Button parsing // Button parsing
if (event.type == EV_KEY) if (event.type == EV_KEY)
{ {
if((event.code == BTN_TOUCH) || (event.code == BTN_LEFT)) if ((event.code == BTN_TOUCH) || (event.code == BTN_LEFT))
{ {
currentMouseStateEvdev[MOUSE_LEFT_BUTTON] = event.value; currentMouseStateEvdev[MOUSE_LEFT_BUTTON] = event.value;
if (event.value > 0) gestureEvent.touchAction = TOUCH_DOWN; if (event.value > 0) gestureEvent.touchAction = TOUCH_DOWN;

View file

@ -367,7 +367,7 @@ static mal_uint32 OnAudioBufferDSPRead(mal_dsp *pDSP, mal_uint32 frameCount, voi
{ {
AudioBuffer *audioBuffer = (AudioBuffer *)pUserData; AudioBuffer *audioBuffer = (AudioBuffer *)pUserData;
mal_uint32 subBufferSizeInFrames = audioBuffer->bufferSizeInFrames/2; mal_uint32 subBufferSizeInFrames = (audioBuffer->bufferSizeInFrames > 1)? audioBuffer->bufferSizeInFrames/2 : audioBuffer->bufferSizeInFrames;
mal_uint32 currentSubBufferIndex = audioBuffer->frameCursorPos/subBufferSizeInFrames; mal_uint32 currentSubBufferIndex = audioBuffer->frameCursorPos/subBufferSizeInFrames;
if (currentSubBufferIndex > 1) if (currentSubBufferIndex > 1)

File diff suppressed because it is too large Load diff

View file

@ -728,6 +728,8 @@ typedef struct DrawCall {
//unsigned int vaoId; // Vertex Array id to be used on the draw //unsigned int vaoId; // Vertex Array id to be used on the draw
//unsigned int shaderId; // Shader id to be used on the draw //unsigned int shaderId; // Shader id to be used on the draw
unsigned int textureId; // Texture id to be used on the draw unsigned int textureId; // Texture id to be used on the draw
// TODO: Support additional texture units?
//Matrix projection; // Projection matrix for this draw //Matrix projection; // Projection matrix for this draw
//Matrix modelview; // Modelview matrix for this draw //Matrix modelview; // Modelview matrix for this draw
} DrawCall; } DrawCall;
@ -1622,7 +1624,7 @@ void rlglInit(int width, int height)
if (strcmp(extList[i], (const char *)"GL_EXT_texture_mirror_clamp") == 0) texMirrorClampSupported = true; if (strcmp(extList[i], (const char *)"GL_EXT_texture_mirror_clamp") == 0) texMirrorClampSupported = true;
// Debug marker support // Debug marker support
if(strcmp(extList[i], (const char *)"GL_EXT_debug_marker") == 0) debugMarkerSupported = true; if (strcmp(extList[i], (const char *)"GL_EXT_debug_marker") == 0) debugMarkerSupported = true;
} }
#if defined(_WIN32) && defined(_MSC_VER) #if defined(_WIN32) && defined(_MSC_VER)
@ -1802,7 +1804,7 @@ void rlLoadExtensions(void *loader)
#if defined(GRAPHICS_API_OPENGL_21) #if defined(GRAPHICS_API_OPENGL_21)
if (GLAD_GL_VERSION_2_1) TraceLog(LOG_INFO, "OpenGL 2.1 profile supported"); if (GLAD_GL_VERSION_2_1) TraceLog(LOG_INFO, "OpenGL 2.1 profile supported");
#elif defined(GRAPHICS_API_OPENGL_33) #elif defined(GRAPHICS_API_OPENGL_33)
if(GLAD_GL_VERSION_3_3) TraceLog(LOG_INFO, "OpenGL 3.3 Core profile supported"); if (GLAD_GL_VERSION_3_3) TraceLog(LOG_INFO, "OpenGL 3.3 Core profile supported");
else TraceLog(LOG_ERROR, "OpenGL 3.3 Core profile not supported"); else TraceLog(LOG_ERROR, "OpenGL 3.3 Core profile not supported");
#endif #endif
#endif #endif
@ -2725,18 +2727,18 @@ void rlDrawMesh(Mesh mesh, Material material, Matrix transform)
// Unload mesh data from CPU and GPU // Unload mesh data from CPU and GPU
void rlUnloadMesh(Mesh *mesh) void rlUnloadMesh(Mesh *mesh)
{ {
if (mesh->vertices != NULL) free(mesh->vertices); free(mesh->vertices);
if (mesh->texcoords != NULL) free(mesh->texcoords); free(mesh->texcoords);
if (mesh->normals != NULL) free(mesh->normals); free(mesh->normals);
if (mesh->colors != NULL) free(mesh->colors); free(mesh->colors);
if (mesh->tangents != NULL) free(mesh->tangents); free(mesh->tangents);
if (mesh->texcoords2 != NULL) free(mesh->texcoords2); free(mesh->texcoords2);
if (mesh->indices != NULL) free(mesh->indices); free(mesh->indices);
if (mesh->baseVertices != NULL) free(mesh->baseVertices); free(mesh->baseVertices);
if (mesh->baseNormals != NULL) free(mesh->baseNormals); free(mesh->baseNormals);
if (mesh->weightBias != NULL) free(mesh->weightBias); free(mesh->weightBias);
if (mesh->weightId != NULL) free(mesh->weightId); free(mesh->weightId);
rlDeleteBuffers(mesh->vboId[0]); // vertex rlDeleteBuffers(mesh->vboId[0]); // vertex
rlDeleteBuffers(mesh->vboId[1]); // texcoords rlDeleteBuffers(mesh->vboId[1]); // texcoords
@ -4093,7 +4095,7 @@ static void UpdateBuffersDefault(void)
// Another option: map the buffer object into client's memory // Another option: map the buffer object into client's memory
// Probably this code could be moved somewhere else... // Probably this code could be moved somewhere else...
// vertexData[currentBuffer].vertices = (float *)glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE); // vertexData[currentBuffer].vertices = (float *)glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE);
// if(vertexData[currentBuffer].vertices) // if (vertexData[currentBuffer].vertices)
// { // {
// Update vertex data // Update vertex data
// } // }
@ -4132,9 +4134,13 @@ static void DrawBuffersDefault(void)
glUniformMatrix4fv(currentShader.locs[LOC_MATRIX_MVP], 1, false, MatrixToFloat(matMVP)); glUniformMatrix4fv(currentShader.locs[LOC_MATRIX_MVP], 1, false, MatrixToFloat(matMVP));
glUniform4f(currentShader.locs[LOC_COLOR_DIFFUSE], 1.0f, 1.0f, 1.0f, 1.0f); glUniform4f(currentShader.locs[LOC_COLOR_DIFFUSE], 1.0f, 1.0f, 1.0f, 1.0f);
glUniform1i(currentShader.locs[LOC_MAP_DIFFUSE], 0); glUniform1i(currentShader.locs[LOC_MAP_DIFFUSE], 0); // Provided value refers to the texture unit (active)
// NOTE: Additional map textures not considered for default buffers drawing // TODO: Support additional texture units on custom shader
//if (currentShader->locs[LOC_MAP_SPECULAR] > 0) glUniform1i(currentShader.locs[LOC_MAP_SPECULAR], 1);
//if (currentShader->locs[LOC_MAP_NORMAL] > 0) glUniform1i(currentShader.locs[LOC_MAP_NORMAL], 2);
// NOTE: Right now additional map textures not considered for default buffers drawing
int vertexOffset = 0; int vertexOffset = 0;
@ -4165,6 +4171,10 @@ static void DrawBuffersDefault(void)
{ {
glBindTexture(GL_TEXTURE_2D, draws[i].textureId); glBindTexture(GL_TEXTURE_2D, draws[i].textureId);
// TODO: Find some way to bind additional textures --> Use global texture IDs? Register them on draw[i]?
//if (currentShader->locs[LOC_MAP_SPECULAR] > 0) { glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, textureUnit1_id); }
//if (currentShader->locs[LOC_MAP_SPECULAR] > 0) { glActiveTexture(GL_TEXTURE2); glBindTexture(GL_TEXTURE_2D, textureUnit2_id); }
if ((draws[i].mode == RL_LINES) || (draws[i].mode == RL_TRIANGLES)) glDrawArrays(draws[i].mode, vertexOffset, draws[i].vertexCount); if ((draws[i].mode == RL_LINES) || (draws[i].mode == RL_TRIANGLES)) glDrawArrays(draws[i].mode, vertexOffset, draws[i].vertexCount);
else else
{ {

View file

@ -7,7 +7,7 @@
* *
* DEPENDENCIES: * DEPENDENCIES:
* raylib.h - TraceLog * raylib.h - TraceLog
* sysnet.h - platform-specific network includes * rnet.h - platform-specific network includes
* *
* CONTRIBUTORS: * CONTRIBUTORS:
* Jak Barnes (github: @syphonx) (Feb. 2019): * Jak Barnes (github: @syphonx) (Feb. 2019):
@ -44,7 +44,7 @@
# include <stdarg.h> # include <stdarg.h>
#else #else
# include "raylib.h" # include "raylib.h"
# include "sysnet.h" # include "rnet.h"
# if !defined(EXTERNAL_CONFIG_FLAGS) # if !defined(EXTERNAL_CONFIG_FLAGS)
# include "config.h" // Defines module configuration flags # include "config.h" // Defines module configuration flags
# endif # endif

255
src/rnet.h Normal file
View file

@ -0,0 +1,255 @@
/**********************************************************************************************
*
* rnet - Provides cross-platform network defines, macros etc
*
* DEPENDENCIES:
* <limits.h> - Used for cross-platform type specifiers
*
* INSPIRED BY:
* SFML Sockets - https://www.sfml-dev.org/documentation/2.5.1/classsf_1_1Socket.php
* SDL_net - https://www.libsdl.org/projects/SDL_net/
* BSD Sockets - https://www.gnu.org/software/libc/manual/html_node/Sockets.html
* BEEJ - https://beej.us/guide/bgnet/html/single/bgnet.html
* Winsock2 - https://docs.microsoft.com/en-us/windows/desktop/api/winsock2
*
*
* CONTRIBUTORS:
* Jak Barnes (github: @syphonx) (Feb. 2019):
* - Initial version
*
* LICENSE: zlib/libpng
*
* Copyright (c) 2014-2019 Ramon Santamaria (@raysan5)
*
* This software is provided "as-is", without any express or implied warranty. In no event
* will the authors be held liable for any damages arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose, including commercial
* applications, and to alter it and redistribute it freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not claim that you
* wrote the original software. If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be misrepresented
* as being the original software.
*
* 3. This notice may not be removed or altered from any source distribution.
*
**********************************************************************************************/
//----------------------------------------------------------------------------------
// Platform type sizes
//----------------------------------------------------------------------------------
#include <limits.h>
//----------------------------------------------------------------------------------
// Undefine any conflicting windows.h symbols
//----------------------------------------------------------------------------------
// If defined, the following flags inhibit definition of the indicated items.
#define NOGDICAPMASKS // CC_*, LC_*, PC_*, CP_*, TC_*, RC_
#define NOVIRTUALKEYCODES // VK_*
#define NOWINMESSAGES // WM_*, EM_*, LB_*, CB_*
#define NOWINSTYLES // WS_*, CS_*, ES_*, LBS_*, SBS_*, CBS_*
#define NOSYSMETRICS // SM_*
#define NOMENUS // MF_*
#define NOICONS // IDI_*
#define NOKEYSTATES // MK_*
#define NOSYSCOMMANDS // SC_*
#define NORASTEROPS // Binary and Tertiary raster ops
#define NOSHOWWINDOW // SW_*
#define OEMRESOURCE // OEM Resource values
#define NOATOM // Atom Manager routines
#define NOCLIPBOARD // Clipboard routines
#define NOCOLOR // Screen colors
#define NOCTLMGR // Control and Dialog routines
#define NODRAWTEXT // DrawText() and DT_*
#define NOGDI // All GDI defines and routines
#define NOKERNEL // All KERNEL defines and routines
#define NOUSER // All USER defines and routines
#define NONLS // All NLS defines and routines
#define NOMB // MB_* and MessageBox()
#define NOMEMMGR // GMEM_*, LMEM_*, GHND, LHND, associated routines
#define NOMETAFILE // typedef METAFILEPICT
#define NOMINMAX // Macros min(a,b) and max(a,b)
#define NOMSG // typedef MSG and associated routines
#define NOOPENFILE // OpenFile(), OemToAnsi, AnsiToOem, and OF_*
#define NOSCROLL // SB_* and scrolling routines
#define NOSERVICE // All Service Controller routines, SERVICE_ equates, etc.
#define NOSOUND // Sound driver routines
#define NOTEXTMETRIC // typedef TEXTMETRIC and associated routines
#define NOWH // SetWindowsHook and WH_*
#define NOWINOFFSETS // GWL_*, GCL_*, associated routines
#define NOCOMM // COMM driver routines
#define NOKANJI // Kanji support stuff.
#define NOHELP // Help engine interface.
#define NOPROFILER // Profiler interface.
#define NODEFERWINDOWPOS // DeferWindowPos routines
#define NOMCX // Modem Configuration Extensions
#define MMNOSOUND
//----------------------------------------------------------------------------------
// Platform defines
//----------------------------------------------------------------------------------
#define PLATFORM_WINDOWS 1
#define PLATFORM_LINUX 2
#if defined(__WIN32__) || defined(WIN32)
# define PLATFORM PLATFORM_WINDOWS
#elif defined(_LINUX)
# define PLATFORM PLATFORM_LINUX
#endif
//----------------------------------------------------------------------------------
// Platform type definitions
// From: https://github.com/DFHack/clsocket/blob/master/src/Host.h
//----------------------------------------------------------------------------------
#ifndef __WORDSIZE
# define __WORDSIZE 32
#endif
#if defined(_LINUX) || defined(_DARWIN)
typedef unsigned char uint8;
typedef char int8;
typedef unsigned short uint16;
typedef short int16;
typedef unsigned int uint32;
typedef int int32;
typedef int SOCKET;
#endif
#ifdef WIN32
typedef unsigned char uint8;
typedef char int8;
typedef unsigned short uint16;
typedef short int16;
typedef unsigned int uint32;
typedef int int32;
#endif
#ifdef WIN32
typedef int socklen_t;
#endif
#if defined(WIN32)
typedef unsigned long long int uint64;
typedef long long int int64;
#elif (__WORDSIZE == 32)
__extension__ typedef long long int int64;
__extension__ typedef unsigned long long int uint64;
#elif (__WORDSIZE == 64)
typedef unsigned long int uint64;
typedef long int int64;
#endif
#ifdef WIN32
# ifndef UINT8_MAX
# define UINT8_MAX (UCHAR_MAX)
# endif // UINT8_MAX
# ifndef UINT16_MAX
# define UINT16_MAX (USHRT_MAX)
# endif // UINT16_MAX
# ifndef UINT32_MAX
# define UINT32_MAX (ULONG_MAX)
# endif // UINT32_MAX
# if __WORDSIZE == 64
# define SIZE_MAX (18446744073709551615UL)
# else
# ifndef SIZE_MAX
# define SIZE_MAX (4294967295U)
# endif // SIZE_MAX
# endif // __WORDSIZE == 64
#endif // WIN32
#if defined(WIN32)
# define ssize_t size_t
#endif // WIN32
#ifndef TRUE
# define TRUE 1
#endif // TRUE
#ifndef FALSE
# define FALSE 0
#endif // FALSE
#ifndef RESULT_SUCCESS
# define RESULT_SUCCESS 0
#endif // RESULT_SUCCESS
#ifndef RESULT_FAILURE
# define RESULT_FAILURE 1
#endif // RESULT_FAILURE
#ifndef INADDR_ANY
# define INADDR_ANY 0x00000000
#endif // INADDR_ANY
#ifndef INADDR_NONE
# define INADDR_NONE 0xFFFFFFFF
#endif // INADDR_NONE
#ifndef INADDR_LOOPBACK
# define INADDR_LOOPBACK 0x7f000001
#endif // INADDR_LOOPBACK
#ifndef INADDR_BROADCAST
# define INADDR_BROADCAST 0xFFFFFFFF
#endif // INADDR_BROADCAST
#ifndef htonll
# ifdef _BIG_ENDIAN
# define htonll(x) (x)
# define ntohll(x) (x)
# else
# define htonll(x) ((((uint64) htonl(x)) << 32) + htonl(x >> 32))
# define ntohll(x) ((((uint64) ntohl(x)) << 32) + ntohl(x >> 32))
# endif // _BIG_ENDIAN
#endif // htonll
//----------------------------------------------------------------------------------
// Platform specific network includes
// From: https://github.com/SDL-mirror/SDL_net/blob/master/SDLnetsys.h
//----------------------------------------------------------------------------------
// Include system network headers
#ifdef _WIN32
# pragma comment(lib, "ws2_32.lib")
# define __USE_W32_SOCKETS
# define WIN32_LEAN_AND_MEAN
# include <winsock2.h>
# include <Ws2tcpip.h>
# include <io.h>
# define IPTOS_LOWDELAY 0x10
#else /* UNIX */
# include <sys/types.h>
# include <fcntl.h>
# include <netinet/in.h>
# include <sys/ioctl.h>
# include <sys/time.h>
# include <unistd.h>
# include <net/if.h>
# include <netdb.h>
# include <netinet/tcp.h>
# include <sys/socket.h>
#endif /* WIN32 */
#ifndef INVALID_SOCKET
# define INVALID_SOCKET ~(0)
#endif
#ifndef __USE_W32_SOCKETS
# define closesocket close
# define SOCKET int
# define INVALID_SOCKET -1
# define SOCKET_ERROR -1
#endif
#ifdef __USE_W32_SOCKETS
# ifndef EINTR
# define EINTR WSAEINTR
# endif
#endif

View file

@ -400,7 +400,7 @@ void DrawRectangleLinesEx(Rectangle rec, int lineThick, Color color)
{ {
if (lineThick > rec.width || lineThick > rec.height) if (lineThick > rec.width || lineThick > rec.height)
{ {
if(rec.width > rec.height) lineThick = (int)rec.height/2; if (rec.width > rec.height) lineThick = (int)rec.height/2;
else if (rec.width < rec.height) lineThick = (int)rec.width/2; else if (rec.width < rec.height) lineThick = (int)rec.width/2;
} }

View file

@ -688,8 +688,7 @@ void UnloadFont(Font font)
{ {
for (int i = 0; i < font.charsCount; i++) for (int i = 0; i < font.charsCount; i++)
{ {
if(font.chars[i].data != NULL) free(font.chars[i].data);
free(font.chars[i].data);
} }
UnloadTexture(font.texture); UnloadTexture(font.texture);
free(font.chars); free(font.chars);
@ -1327,13 +1326,11 @@ int TextToInteger(const char *text)
return result; return result;
} }
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Module specific Functions Definition // Module specific Functions Definition
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
#if defined(SUPPORT_FILEFORMAT_FNT) #if defined(SUPPORT_FILEFORMAT_FNT)
// Load a BMFont file (AngelCode font file) // Load a BMFont file (AngelCode font file)
static Font LoadBMFont(const char *fileName) static Font LoadBMFont(const char *fileName)

View file

@ -353,7 +353,7 @@ Image LoadImageRaw(const char *fileName, int width, int height, int format, int
{ {
TraceLog(LOG_WARNING, "[%s] RAW image data can not be read, wrong requested format or size", fileName); TraceLog(LOG_WARNING, "[%s] RAW image data can not be read, wrong requested format or size", fileName);
if (image.data != NULL) free(image.data); free(image.data);
} }
else else
{ {
@ -414,10 +414,7 @@ RenderTexture2D LoadRenderTexture(int width, int height)
// Unload image from CPU memory (RAM) // Unload image from CPU memory (RAM)
void UnloadImage(Image image) void UnloadImage(Image image)
{ {
if (image.data != NULL) free(image.data); free(image.data);
// NOTE: It becomes anoying every time a texture is loaded
//TraceLog(LOG_INFO, "Unloaded image data");
} }
// Unload texture from GPU memory (VRAM) // Unload texture from GPU memory (VRAM)