Merge branch 'raysan5:master' into master
This commit is contained in:
commit
8e1ce316ea
|
|
@ -546,9 +546,6 @@ void PollInputEvents(void)
|
||||||
CORE.Input.Keyboard.keyPressedQueueCount = 0;
|
CORE.Input.Keyboard.keyPressedQueueCount = 0;
|
||||||
CORE.Input.Keyboard.charPressedQueueCount = 0;
|
CORE.Input.Keyboard.charPressedQueueCount = 0;
|
||||||
|
|
||||||
// Reset key repeats
|
|
||||||
for (int i = 0; i < MAX_KEYBOARD_KEYS; i++) CORE.Input.Keyboard.keyRepeatInFrame[i] = 0;
|
|
||||||
|
|
||||||
// Reset last gamepad button/axis registered state
|
// Reset last gamepad button/axis registered state
|
||||||
CORE.Input.Gamepad.lastButtonPressed = 0; // GAMEPAD_BUTTON_UNKNOWN
|
CORE.Input.Gamepad.lastButtonPressed = 0; // GAMEPAD_BUTTON_UNKNOWN
|
||||||
//CORE.Input.Gamepad.axisCount = 0;
|
//CORE.Input.Gamepad.axisCount = 0;
|
||||||
|
|
@ -1709,6 +1706,7 @@ static void PollKeyboardEvents(void)
|
||||||
// Event interface: 'value' is the value the event carries. Either a relative change for EV_REL,
|
// Event interface: 'value' is the value the event carries. Either a relative change for EV_REL,
|
||||||
// absolute new value for EV_ABS (joysticks ...), or 0 for EV_KEY for release, 1 for keypress and 2 for autorepeat
|
// absolute new value for EV_ABS (joysticks ...), or 0 for EV_KEY for release, 1 for keypress and 2 for autorepeat
|
||||||
CORE.Input.Keyboard.currentKeyState[keycode] = (event.value >= 1)? 1 : 0;
|
CORE.Input.Keyboard.currentKeyState[keycode] = (event.value >= 1)? 1 : 0;
|
||||||
|
CORE.Input.Keyboard.keyRepeatInFrame[keycode] = (event.value == 2)? 1 : 0;
|
||||||
if (event.value >= 1)
|
if (event.value >= 1)
|
||||||
{
|
{
|
||||||
CORE.Input.Keyboard.keyPressedQueue[CORE.Input.Keyboard.keyPressedQueueCount] = keycode; // Register last key pressed
|
CORE.Input.Keyboard.keyPressedQueue[CORE.Input.Keyboard.keyPressedQueueCount] = keycode; // Register last key pressed
|
||||||
|
|
|
||||||
|
|
@ -1536,9 +1536,10 @@ RLAPI void UpdateMeshBuffer(Mesh mesh, int index, const void *data, int dataSize
|
||||||
RLAPI void UnloadMesh(Mesh mesh); // Unload mesh data from CPU and GPU
|
RLAPI void UnloadMesh(Mesh mesh); // Unload mesh data from CPU and GPU
|
||||||
RLAPI void DrawMesh(Mesh mesh, Material material, Matrix transform); // Draw a 3d mesh with material and transform
|
RLAPI void DrawMesh(Mesh mesh, Material material, Matrix transform); // Draw a 3d mesh with material and transform
|
||||||
RLAPI void DrawMeshInstanced(Mesh mesh, Material material, const Matrix *transforms, int instances); // Draw multiple mesh instances with material and different transforms
|
RLAPI void DrawMeshInstanced(Mesh mesh, Material material, const Matrix *transforms, int instances); // Draw multiple mesh instances with material and different transforms
|
||||||
RLAPI bool ExportMesh(Mesh mesh, const char *fileName); // Export mesh data to file, returns true on success
|
|
||||||
RLAPI BoundingBox GetMeshBoundingBox(Mesh mesh); // Compute mesh bounding box limits
|
RLAPI BoundingBox GetMeshBoundingBox(Mesh mesh); // Compute mesh bounding box limits
|
||||||
RLAPI void GenMeshTangents(Mesh *mesh); // Compute mesh tangents
|
RLAPI void GenMeshTangents(Mesh *mesh); // Compute mesh tangents
|
||||||
|
RLAPI bool ExportMesh(Mesh mesh, const char *fileName); // Export mesh data to file, returns true on success
|
||||||
|
RLAPI bool ExportMeshAsCode(Mesh mesh, const char *fileName); // Export mesh as code file (.h) defining multiple arrays of vertex attributes
|
||||||
|
|
||||||
// Mesh generation functions
|
// Mesh generation functions
|
||||||
RLAPI Mesh GenMeshPoly(int sides, float radius); // Generate polygonal mesh
|
RLAPI Mesh GenMeshPoly(int sides, float radius); // Generate polygonal mesh
|
||||||
|
|
|
||||||
39
src/rlgl.h
39
src/rlgl.h
|
|
@ -686,25 +686,25 @@ RLAPI void rlSetTexture(unsigned int id); // Set current texture f
|
||||||
|
|
||||||
// Vertex buffers management
|
// Vertex buffers management
|
||||||
RLAPI unsigned int rlLoadVertexArray(void); // Load vertex array (vao) if supported
|
RLAPI unsigned int rlLoadVertexArray(void); // Load vertex array (vao) if supported
|
||||||
RLAPI unsigned int rlLoadVertexBuffer(const void *buffer, int size, bool dynamic); // Load a vertex buffer attribute
|
RLAPI unsigned int rlLoadVertexBuffer(const void *buffer, int size, bool dynamic); // Load a vertex buffer object
|
||||||
RLAPI unsigned int rlLoadVertexBufferElement(const void *buffer, int size, bool dynamic); // Load a new attributes element buffer
|
RLAPI unsigned int rlLoadVertexBufferElement(const void *buffer, int size, bool dynamic); // Load vertex buffer elements object
|
||||||
RLAPI void rlUpdateVertexBuffer(unsigned int bufferId, const void *data, int dataSize, int offset); // Update GPU buffer with new data
|
RLAPI void rlUpdateVertexBuffer(unsigned int bufferId, const void *data, int dataSize, int offset); // Update vertex buffer object data on GPU buffer
|
||||||
RLAPI void rlUpdateVertexBufferElements(unsigned int id, const void *data, int dataSize, int offset); // Update vertex buffer elements with new data
|
RLAPI void rlUpdateVertexBufferElements(unsigned int id, const void *data, int dataSize, int offset); // Update vertex buffer elements data on GPU buffer
|
||||||
RLAPI void rlUnloadVertexArray(unsigned int vaoId);
|
RLAPI void rlUnloadVertexArray(unsigned int vaoId); // Unload vertex array (vao)
|
||||||
RLAPI void rlUnloadVertexBuffer(unsigned int vboId);
|
RLAPI void rlUnloadVertexBuffer(unsigned int vboId); // Unload vertex buffer object
|
||||||
RLAPI void rlSetVertexAttribute(unsigned int index, int compSize, int type, bool normalized, int stride, const void *pointer);
|
RLAPI void rlSetVertexAttribute(unsigned int index, int compSize, int type, bool normalized, int stride, const void *pointer); // Set vertex attribute data configuration
|
||||||
RLAPI void rlSetVertexAttributeDivisor(unsigned int index, int divisor);
|
RLAPI void rlSetVertexAttributeDivisor(unsigned int index, int divisor); // Set vertex attribute data divisor
|
||||||
RLAPI void rlSetVertexAttributeDefault(int locIndex, const void *value, int attribType, int count); // Set vertex attribute default value
|
RLAPI void rlSetVertexAttributeDefault(int locIndex, const void *value, int attribType, int count); // Set vertex attribute default value, when attribute to provided
|
||||||
RLAPI void rlDrawVertexArray(int offset, int count);
|
RLAPI void rlDrawVertexArray(int offset, int count); // Draw vertex array (currently active vao)
|
||||||
RLAPI void rlDrawVertexArrayElements(int offset, int count, const void *buffer);
|
RLAPI void rlDrawVertexArrayElements(int offset, int count, const void *buffer); // Draw vertex array elements
|
||||||
RLAPI void rlDrawVertexArrayInstanced(int offset, int count, int instances);
|
RLAPI void rlDrawVertexArrayInstanced(int offset, int count, int instances); // Draw vertex array (currently active vao) with instancing
|
||||||
RLAPI void rlDrawVertexArrayElementsInstanced(int offset, int count, const void *buffer, int instances);
|
RLAPI void rlDrawVertexArrayElementsInstanced(int offset, int count, const void *buffer, int instances); // Draw vertex array elements with instancing
|
||||||
|
|
||||||
// Textures management
|
// Textures management
|
||||||
RLAPI unsigned int rlLoadTexture(const void *data, int width, int height, int format, int mipmapCount); // Load texture in GPU
|
RLAPI unsigned int rlLoadTexture(const void *data, int width, int height, int format, int mipmapCount); // Load texture data
|
||||||
RLAPI unsigned int rlLoadTextureDepth(int width, int height, bool useRenderBuffer); // Load depth texture/renderbuffer (to be attached to fbo)
|
RLAPI unsigned int rlLoadTextureDepth(int width, int height, bool useRenderBuffer); // Load depth texture/renderbuffer (to be attached to fbo)
|
||||||
RLAPI unsigned int rlLoadTextureCubemap(const void *data, int size, int format); // Load texture cubemap
|
RLAPI unsigned int rlLoadTextureCubemap(const void *data, int size, int format); // Load texture cubemap data
|
||||||
RLAPI void rlUpdateTexture(unsigned int id, int offsetX, int offsetY, int width, int height, int format, const void *data); // Update GPU texture with new data
|
RLAPI void rlUpdateTexture(unsigned int id, int offsetX, int offsetY, int width, int height, int format, const void *data); // Update texture with new data on GPU
|
||||||
RLAPI void rlGetGlTextureFormats(int format, unsigned int *glInternalFormat, unsigned int *glFormat, unsigned int *glType); // Get OpenGL internal formats
|
RLAPI void rlGetGlTextureFormats(int format, unsigned int *glInternalFormat, unsigned int *glFormat, unsigned int *glType); // Get OpenGL internal formats
|
||||||
RLAPI const char *rlGetPixelFormatName(unsigned int format); // Get name string for pixel format
|
RLAPI const char *rlGetPixelFormatName(unsigned int format); // Get name string for pixel format
|
||||||
RLAPI void rlUnloadTexture(unsigned int id); // Unload texture from GPU memory
|
RLAPI void rlUnloadTexture(unsigned int id); // Unload texture from GPU memory
|
||||||
|
|
@ -776,7 +776,8 @@ RLAPI void rlLoadDrawQuad(void); // Load and draw a quad
|
||||||
#if defined(RLGL_IMPLEMENTATION)
|
#if defined(RLGL_IMPLEMENTATION)
|
||||||
|
|
||||||
// Expose OpenGL functions from glad in raylib
|
// Expose OpenGL functions from glad in raylib
|
||||||
#if defined(BUILD_SHARED_LIBS)
|
#if defined(BUILD_LIBTYPE_SHARED)
|
||||||
|
#define GLAD_API_CALL_EXPORT
|
||||||
#define GLAD_API_CALL_EXPORT_BUILD
|
#define GLAD_API_CALL_EXPORT_BUILD
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
@ -3794,6 +3795,10 @@ unsigned int rlLoadVertexArray(void)
|
||||||
void rlSetVertexAttribute(unsigned int index, int compSize, int type, bool normalized, int stride, const void *pointer)
|
void rlSetVertexAttribute(unsigned int index, int compSize, int type, bool normalized, int stride, const void *pointer)
|
||||||
{
|
{
|
||||||
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
||||||
|
// NOTE: Data type could be: GL_BYTE, GL_UNSIGNED_BYTE, GL_SHORT, GL_UNSIGNED_SHORT, GL_INT, GL_UNSIGNED_INT
|
||||||
|
// Additional types (depends on OpenGL version or extensions):
|
||||||
|
// - GL_HALF_FLOAT, GL_FLOAT, GL_DOUBLE, GL_FIXED,
|
||||||
|
// - GL_INT_2_10_10_10_REV, GL_UNSIGNED_INT_2_10_10_10_REV, GL_UNSIGNED_INT_10F_11F_11F_REV
|
||||||
glVertexAttribPointer(index, compSize, type, normalized, stride, pointer);
|
glVertexAttribPointer(index, compSize, type, normalized, stride, pointer);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1850,6 +1850,104 @@ bool ExportMesh(Mesh mesh, const char *fileName)
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Export mesh as code file (.h) defining multiple arrays of vertex attributes
|
||||||
|
bool ExportMeshAsCode(Mesh mesh, const char *fileName)
|
||||||
|
{
|
||||||
|
bool success = false;
|
||||||
|
|
||||||
|
#ifndef TEXT_BYTES_PER_LINE
|
||||||
|
#define TEXT_BYTES_PER_LINE 20
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// NOTE: Text data buffer size is fixed to 64MB
|
||||||
|
char *txtData = (char *)RL_CALLOC(64*1024*1024, sizeof(char)); // 64 MB
|
||||||
|
|
||||||
|
int byteCount = 0;
|
||||||
|
byteCount += sprintf(txtData + byteCount, "////////////////////////////////////////////////////////////////////////////////////////\n");
|
||||||
|
byteCount += sprintf(txtData + byteCount, "// //\n");
|
||||||
|
byteCount += sprintf(txtData + byteCount, "// MeshAsCode exporter v1.0 - Mesh vertex data exported as arrays //\n");
|
||||||
|
byteCount += sprintf(txtData + byteCount, "// //\n");
|
||||||
|
byteCount += sprintf(txtData + byteCount, "// more info and bugs-report: github.com/raysan5/raylib //\n");
|
||||||
|
byteCount += sprintf(txtData + byteCount, "// feedback and support: ray[at]raylib.com //\n");
|
||||||
|
byteCount += sprintf(txtData + byteCount, "// //\n");
|
||||||
|
byteCount += sprintf(txtData + byteCount, "// Copyright (c) 2023 Ramon Santamaria (@raysan5) //\n");
|
||||||
|
byteCount += sprintf(txtData + byteCount, "// //\n");
|
||||||
|
byteCount += sprintf(txtData + byteCount, "////////////////////////////////////////////////////////////////////////////////////////\n\n");
|
||||||
|
|
||||||
|
// Get file name from path and convert variable name to uppercase
|
||||||
|
char varFileName[256] = { 0 };
|
||||||
|
strcpy(varFileName, GetFileNameWithoutExt(fileName));
|
||||||
|
for (int i = 0; varFileName[i] != '\0'; i++) if ((varFileName[i] >= 'a') && (varFileName[i] <= 'z')) { varFileName[i] = varFileName[i] - 32; }
|
||||||
|
|
||||||
|
// Add image information
|
||||||
|
byteCount += sprintf(txtData + byteCount, "// Mesh basic information\n");
|
||||||
|
byteCount += sprintf(txtData + byteCount, "#define %s_VERTEX_COUNT %i\n", varFileName, mesh.vertexCount);
|
||||||
|
byteCount += sprintf(txtData + byteCount, "#define %s_TRIANGLE_COUNT %i\n\n", varFileName, mesh.triangleCount);
|
||||||
|
|
||||||
|
// Define vertex attributes data as separate arrays
|
||||||
|
//-----------------------------------------------------------------------------------------
|
||||||
|
if (mesh.vertices != NULL) // Vertex position (XYZ - 3 components per vertex - float)
|
||||||
|
{
|
||||||
|
byteCount += sprintf(txtData + byteCount, "static float %s_VERTEX_DATA[%i] = { ", varFileName, mesh.vertexCount*3);
|
||||||
|
for (int i = 0; i < mesh.vertexCount*3 - 1; i++) byteCount += sprintf(txtData + byteCount, ((i%TEXT_BYTES_PER_LINE == 0)? "%.3ff,\n" : "%.3ff, "), mesh.vertices[i]);
|
||||||
|
byteCount += sprintf(txtData + byteCount, "%.3ff };\n\n", mesh.vertices[mesh.vertexCount*3 - 1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mesh.texcoords != NULL) // Vertex texture coordinates (UV - 2 components per vertex - float)
|
||||||
|
{
|
||||||
|
byteCount += sprintf(txtData + byteCount, "static float %s_TEXCOORD_DATA[%i] = { ", varFileName, mesh.vertexCount*2);
|
||||||
|
for (int i = 0; i < mesh.vertexCount*2 - 1; i++) byteCount += sprintf(txtData + byteCount, ((i%TEXT_BYTES_PER_LINE == 0)? "%.3ff,\n" : "%.3ff, "), mesh.texcoords[i]);
|
||||||
|
byteCount += sprintf(txtData + byteCount, "%.3ff };\n\n", mesh.texcoords[mesh.vertexCount*2 - 1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mesh.texcoords2 != NULL) // Vertex texture coordinates (UV - 2 components per vertex - float)
|
||||||
|
{
|
||||||
|
byteCount += sprintf(txtData + byteCount, "static float %s_TEXCOORD2_DATA[%i] = { ", varFileName, mesh.vertexCount*2);
|
||||||
|
for (int i = 0; i < mesh.vertexCount*2 - 1; i++) byteCount += sprintf(txtData + byteCount, ((i%TEXT_BYTES_PER_LINE == 0)? "%.3ff,\n" : "%.3ff, "), mesh.texcoords2[i]);
|
||||||
|
byteCount += sprintf(txtData + byteCount, "%.3ff };\n\n", mesh.texcoords2[mesh.vertexCount*2 - 1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mesh.normals != NULL) // Vertex normals (XYZ - 3 components per vertex - float)
|
||||||
|
{
|
||||||
|
byteCount += sprintf(txtData + byteCount, "static float %s_NORMAL_DATA[%i] = { ", varFileName, mesh.vertexCount*3);
|
||||||
|
for (int i = 0; i < mesh.vertexCount*3 - 1; i++) byteCount += sprintf(txtData + byteCount, ((i%TEXT_BYTES_PER_LINE == 0)? "%.3ff,\n" : "%.3ff, "), mesh.normals[i]);
|
||||||
|
byteCount += sprintf(txtData + byteCount, "%.3ff };\n\n", mesh.normals[mesh.vertexCount*3 - 1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mesh.tangents != NULL) // Vertex tangents (XYZW - 4 components per vertex - float)
|
||||||
|
{
|
||||||
|
byteCount += sprintf(txtData + byteCount, "static float %s_TANGENT_DATA[%i] = { ", varFileName, mesh.vertexCount*4);
|
||||||
|
for (int i = 0; i < mesh.vertexCount*4 - 1; i++) byteCount += sprintf(txtData + byteCount, ((i%TEXT_BYTES_PER_LINE == 0)? "%.3ff,\n" : "%.3ff, "), mesh.tangents[i]);
|
||||||
|
byteCount += sprintf(txtData + byteCount, "%.3ff };\n\n", mesh.tangents[mesh.vertexCount*4 - 1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mesh.colors != NULL) // Vertex colors (RGBA - 4 components per vertex - unsigned char)
|
||||||
|
{
|
||||||
|
byteCount += sprintf(txtData + byteCount, "static unsigned char %s_COLOR_DATA[%i] = { ", varFileName, mesh.vertexCount*4);
|
||||||
|
for (int i = 0; i < mesh.vertexCount*4 - 1; i++) byteCount += sprintf(txtData + byteCount, ((i%TEXT_BYTES_PER_LINE == 0)? "0x%x,\n" : "0x%x, "), mesh.colors[i]);
|
||||||
|
byteCount += sprintf(txtData + byteCount, "0x%x };\n\n", mesh.colors[mesh.vertexCount*4 - 1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mesh.indices != NULL) // Vertex indices (3 index per triangle - unsigned short)
|
||||||
|
{
|
||||||
|
byteCount += sprintf(txtData + byteCount, "static unsigned short %s_INDEX_DATA[%i] = { ", varFileName, mesh.triangleCount*3);
|
||||||
|
for (int i = 0; i < mesh.triangleCount*3 - 1; i++) byteCount += sprintf(txtData + byteCount, ((i%TEXT_BYTES_PER_LINE == 0)? "%i,\n" : "%i, "), mesh.indices[i]);
|
||||||
|
byteCount += sprintf(txtData + byteCount, "%i };\n", mesh.indices[mesh.triangleCount*3 - 1]);
|
||||||
|
}
|
||||||
|
//-----------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// NOTE: Text data size exported is determined by '\0' (NULL) character
|
||||||
|
success = SaveFileText(fileName, txtData);
|
||||||
|
|
||||||
|
RL_FREE(txtData);
|
||||||
|
|
||||||
|
//if (success != 0) TRACELOG(LOG_INFO, "FILEIO: [%s] Image as code exported successfully", fileName);
|
||||||
|
//else TRACELOG(LOG_WARNING, "FILEIO: [%s] Failed to export image as code", fileName);
|
||||||
|
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#if defined(SUPPORT_FILEFORMAT_OBJ) || defined(SUPPORT_FILEFORMAT_MTL)
|
#if defined(SUPPORT_FILEFORMAT_OBJ) || defined(SUPPORT_FILEFORMAT_MTL)
|
||||||
// Process obj materials
|
// Process obj materials
|
||||||
static void ProcessMaterialsOBJ(Material *materials, tinyobj_material_t *mats, int materialCount)
|
static void ProcessMaterialsOBJ(Material *materials, tinyobj_material_t *mats, int materialCount)
|
||||||
|
|
|
||||||
|
|
@ -2132,11 +2132,11 @@ bool CheckCollisionCircleRec(Vector2 center, float radius, Rectangle rec)
|
||||||
{
|
{
|
||||||
bool collision = false;
|
bool collision = false;
|
||||||
|
|
||||||
int recCenterX = (int)(rec.x + rec.width/2.0f);
|
float recCenterX = rec.x + rec.width/2.0f;
|
||||||
int recCenterY = (int)(rec.y + rec.height/2.0f);
|
float recCenterY = rec.y + rec.height/2.0f;
|
||||||
|
|
||||||
float dx = fabsf(center.x - (float)recCenterX);
|
float dx = fabsf(center.x - recCenterX);
|
||||||
float dy = fabsf(center.y - (float)recCenterY);
|
float dy = fabsf(center.y - recCenterY);
|
||||||
|
|
||||||
if (dx > (rec.width/2.0f + radius)) { return false; }
|
if (dx > (rec.width/2.0f + radius)) { return false; }
|
||||||
if (dy > (rec.height/2.0f + radius)) { return false; }
|
if (dy > (rec.height/2.0f + radius)) { return false; }
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user