2014-09-17 00:51:31 +04:00
|
|
|
/**********************************************************************************************
|
2014-09-03 18:51:28 +04:00
|
|
|
*
|
2014-03-25 15:40:35 +04:00
|
|
|
* rlgl - raylib OpenGL abstraction layer
|
2014-09-03 18:51:28 +04:00
|
|
|
*
|
2014-03-25 15:40:35 +04:00
|
|
|
* raylib now uses OpenGL 1.1 style functions (rlVertex) that are mapped to selected OpenGL version:
|
|
|
|
* OpenGL 1.1 - Direct map rl* -> gl*
|
|
|
|
* OpenGL 3.3+ - Vertex data is stored in VAOs, call rlglDraw() to render
|
2015-01-02 22:58:06 +03:00
|
|
|
* OpenGL ES 2 - Vertex data is stored in VBOs or VAOs (when available), call rlglDraw() to render
|
2014-09-03 18:51:28 +04:00
|
|
|
*
|
2014-03-25 15:40:35 +04:00
|
|
|
* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com)
|
2014-09-03 18:51:28 +04:00
|
|
|
*
|
|
|
|
* This software is provided "as-is", without any express or implied warranty. In no event
|
2014-03-25 15:40:35 +04:00
|
|
|
* will the authors be held liable for any damages arising from the use of this software.
|
|
|
|
*
|
2014-09-03 18:51:28 +04:00
|
|
|
* Permission is granted to anyone to use this software for any purpose, including commercial
|
2014-03-25 15:40:35 +04:00
|
|
|
* applications, and to alter it and redistribute it freely, subject to the following restrictions:
|
|
|
|
*
|
2014-09-03 18:51:28 +04:00
|
|
|
* 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
|
2014-03-25 15:40:35 +04:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
**********************************************************************************************/
|
|
|
|
|
|
|
|
#ifndef RLGL_H
|
|
|
|
#define RLGL_H
|
|
|
|
|
2014-04-04 22:11:57 +04:00
|
|
|
//#define RLGL_STANDALONE // NOTE: To use rlgl as standalone lib, just uncomment this line
|
|
|
|
|
|
|
|
#ifndef RLGL_STANDALONE
|
2015-03-01 18:00:52 +03:00
|
|
|
#include "raylib.h" // Required for typedef(s): Model, Shader, Texture2D
|
2014-04-09 22:25:26 +04:00
|
|
|
#include "utils.h" // Required for function TraceLog()
|
2014-04-04 22:11:57 +04:00
|
|
|
#endif
|
|
|
|
|
2014-04-19 18:36:49 +04:00
|
|
|
#include "raymath.h" // Required for data type Matrix and Matrix functions
|
2014-04-09 22:25:26 +04:00
|
|
|
|
2014-03-25 15:40:35 +04:00
|
|
|
// Select desired OpenGL version
|
2014-09-17 00:51:31 +04:00
|
|
|
// NOTE: Those preprocessor defines are only used on rlgl module,
|
|
|
|
// if OpenGL version is required by any other module, it uses rlGetVersion()
|
|
|
|
|
|
|
|
// Choose opengl version here or just define it at compile time: -DGRAPHICS_API_OPENGL_33
|
|
|
|
//#define GRAPHICS_API_OPENGL_11 // Only available on PLATFORM_DESKTOP
|
|
|
|
//#define GRAPHICS_API_OPENGL_33 // Only available on PLATFORM_DESKTOP
|
2014-12-15 03:08:30 +03:00
|
|
|
//#define GRAPHICS_API_OPENGL_ES2 // Only available on PLATFORM_ANDROID or PLATFORM_RPI or PLATFORM_WEB
|
2014-09-17 00:51:31 +04:00
|
|
|
|
|
|
|
// Security check in case no GRAPHICS_API_OPENGL_* defined
|
|
|
|
#if !defined(GRAPHICS_API_OPENGL_11) && !defined(GRAPHICS_API_OPENGL_33) && !defined(GRAPHICS_API_OPENGL_ES2)
|
|
|
|
#define GRAPHICS_API_OPENGL_11
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Security check in case multiple GRAPHICS_API_OPENGL_* defined
|
|
|
|
#if defined(GRAPHICS_API_OPENGL_11)
|
|
|
|
#if defined(GRAPHICS_API_OPENGL_33)
|
|
|
|
#undef GRAPHICS_API_OPENGL_33
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(GRAPHICS_API_OPENGL_ES2)
|
|
|
|
#undef GRAPHICS_API_OPENGL_ES2
|
|
|
|
#endif
|
|
|
|
#endif
|
2014-03-25 15:40:35 +04:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------
|
|
|
|
// Defines and Macros
|
|
|
|
//----------------------------------------------------------------------------------
|
2014-09-17 00:51:31 +04:00
|
|
|
#if defined(GRAPHICS_API_OPENGL_11) || defined(GRAPHICS_API_OPENGL_33)
|
|
|
|
// NOTE: This is the maximum amount of lines, triangles and quads per frame, be careful!
|
|
|
|
#define MAX_LINES_BATCH 8192
|
|
|
|
#define MAX_TRIANGLES_BATCH 4096
|
|
|
|
#define MAX_QUADS_BATCH 4096
|
|
|
|
#elif defined(GRAPHICS_API_OPENGL_ES2)
|
2014-12-31 20:03:32 +03:00
|
|
|
// NOTE: Reduce memory sizes for embedded systems (RPI and HTML5)
|
|
|
|
// NOTE: On HTML5 (emscripten) this is allocated on heap, by default it's only 16MB!...just take care...
|
|
|
|
#define MAX_LINES_BATCH 1024 // Critical for wire shapes (sphere)
|
2014-09-17 00:51:31 +04:00
|
|
|
#define MAX_TRIANGLES_BATCH 2048 // Critical for some shapes (sphere)
|
|
|
|
#define MAX_QUADS_BATCH 1024 // Be careful with text, every letter maps a quad
|
|
|
|
#endif
|
2014-03-25 15:40:35 +04:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------
|
|
|
|
// Types and Structures Definition
|
|
|
|
//----------------------------------------------------------------------------------
|
|
|
|
typedef enum { RL_PROJECTION, RL_MODELVIEW, RL_TEXTURE } MatrixMode;
|
|
|
|
|
|
|
|
typedef enum { RL_LINES, RL_TRIANGLES, RL_QUADS } DrawMode;
|
|
|
|
|
2014-09-17 00:51:31 +04:00
|
|
|
typedef enum { OPENGL_11 = 1, OPENGL_33, OPENGL_ES_20 } GlVersion;
|
|
|
|
|
2014-04-04 22:11:57 +04:00
|
|
|
#ifdef RLGL_STANDALONE
|
2015-04-06 15:02:29 +03:00
|
|
|
// Texture formats (support depends on OpenGL version)
|
|
|
|
typedef enum {
|
|
|
|
UNCOMPRESSED_GRAYSCALE = 1, // 8 bit per pixel (no alpha)
|
|
|
|
UNCOMPRESSED_R5G6B5, // 16 bpp
|
|
|
|
UNCOMPRESSED_R8G8B8, // 24 bpp
|
|
|
|
UNCOMPRESSED_R5G5B5A1, // 16 bpp (1 bit alpha)
|
|
|
|
UNCOMPRESSED_R4G4B4A4, // 16 bpp (4 bit alpha)
|
|
|
|
UNCOMPRESSED_R8G8B8A8, // 32 bpp
|
|
|
|
COMPRESSED_DXT1_RGB, // 4 bpp (no alpha)
|
|
|
|
COMPRESSED_DXT1_RGBA, // 4 bpp (1 bit alpha)
|
|
|
|
COMPRESSED_DXT3_RGBA, // 8 bpp
|
|
|
|
COMPRESSED_DXT5_RGBA, // 8 bpp
|
|
|
|
COMPRESSED_ETC1_RGB, // 4 bpp
|
|
|
|
COMPRESSED_ETC2_RGB, // 4 bpp
|
|
|
|
COMPRESSED_ETC2_EAC_RGBA, // 8 bpp
|
2015-04-13 21:15:28 +03:00
|
|
|
COMPRESSED_PVRT_RGB, // 4 bpp
|
|
|
|
COMPRESSED_PVRT_RGBA, // 4 bpp
|
2015-04-06 15:02:29 +03:00
|
|
|
/*COMPRESSED_ASTC_RGBA_4x4*/ // 8 bpp
|
|
|
|
} TextureFormat;
|
|
|
|
|
2015-03-01 18:00:52 +03:00
|
|
|
// VertexData type
|
2015-04-06 15:02:29 +03:00
|
|
|
// NOTE: If using OpenGL 1.1, data loaded in CPU; if OpenGL 3.3+ data loaded in GPU (vaoId)
|
2015-03-01 18:00:52 +03:00
|
|
|
typedef struct VertexData {
|
2014-04-19 18:36:49 +04:00
|
|
|
int vertexCount;
|
|
|
|
float *vertices; // 3 components per vertex
|
|
|
|
float *texcoords; // 2 components per vertex
|
|
|
|
float *normals; // 3 components per vertex
|
2014-07-23 02:06:24 +04:00
|
|
|
unsigned char *colors;
|
2015-04-06 15:02:29 +03:00
|
|
|
unsigned int vaoId;
|
|
|
|
unsigned int vboId[4];
|
2014-04-19 18:36:49 +04:00
|
|
|
} VertexData;
|
2015-03-01 18:00:52 +03:00
|
|
|
|
|
|
|
// Shader type
|
|
|
|
typedef struct Shader {
|
|
|
|
unsigned int id; // Shader program id
|
2015-04-06 15:02:29 +03:00
|
|
|
|
2015-03-01 18:00:52 +03:00
|
|
|
// Variable attributes
|
|
|
|
unsigned int vertexLoc; // Vertex attribute location point (vertex shader)
|
|
|
|
unsigned int texcoordLoc; // Texcoord attribute location point (vertex shader)
|
|
|
|
unsigned int normalLoc; // Normal attribute location point (vertex shader)
|
|
|
|
unsigned int colorLoc; // Color attibute location point (vertex shader)
|
2015-04-06 15:02:29 +03:00
|
|
|
|
2015-03-01 18:00:52 +03:00
|
|
|
// Uniforms
|
|
|
|
unsigned int projectionLoc; // Projection matrix uniform location point (vertex shader)
|
|
|
|
unsigned int modelviewLoc; // ModeView matrix uniform location point (vertex shader)
|
|
|
|
unsigned int textureLoc; // Texture uniform location point (fragment shader)
|
|
|
|
unsigned int tintColorLoc; // Color uniform location point (fragment shader)
|
|
|
|
} Shader;
|
|
|
|
|
|
|
|
// 3d Model type
|
2014-04-19 18:36:49 +04:00
|
|
|
typedef struct Model {
|
|
|
|
VertexData mesh;
|
2015-04-06 15:02:29 +03:00
|
|
|
Matrix transform;
|
2015-03-01 18:00:52 +03:00
|
|
|
Texture2D texture;
|
|
|
|
Shader shader;
|
2014-04-19 18:36:49 +04:00
|
|
|
} Model;
|
2015-04-06 15:02:29 +03:00
|
|
|
|
|
|
|
// Texture2D type
|
|
|
|
typedef struct Texture2D {
|
|
|
|
unsigned int id; // Texture id
|
|
|
|
int width;
|
|
|
|
int height;
|
|
|
|
} Texture2D;
|
2014-04-04 22:11:57 +04:00
|
|
|
#endif
|
|
|
|
|
2014-03-25 15:40:35 +04:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" { // Prevents name mangling of functions
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------------
|
|
|
|
// Functions Declaration - Matrix operations
|
|
|
|
//------------------------------------------------------------------------------------
|
|
|
|
void rlMatrixMode(int mode); // Choose the current matrix to be transformed
|
2014-09-03 19:06:10 +04:00
|
|
|
void rlPushMatrix(void); // Push the current matrix to stack
|
|
|
|
void rlPopMatrix(void); // Pop lattest inserted matrix from stack
|
|
|
|
void rlLoadIdentity(void); // Reset current matrix to identity matrix
|
2014-03-25 15:40:35 +04:00
|
|
|
void rlTranslatef(float x, float y, float z); // Multiply the current matrix by a translation matrix
|
|
|
|
void rlRotatef(float angleDeg, float x, float y, float z); // Multiply the current matrix by a rotation matrix
|
|
|
|
void rlScalef(float x, float y, float z); // Multiply the current matrix by a scaling matrix
|
|
|
|
void rlMultMatrixf(float *mat); // Multiply the current matrix by another matrix
|
|
|
|
void rlFrustum(double left, double right, double bottom, double top, double near, double far);
|
|
|
|
void rlOrtho(double left, double right, double bottom, double top, double near, double far);
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------------
|
|
|
|
// Functions Declaration - Vertex level operations
|
|
|
|
//------------------------------------------------------------------------------------
|
|
|
|
void rlBegin(int mode); // Initialize drawing mode (how to organize vertex)
|
2014-09-03 19:06:10 +04:00
|
|
|
void rlEnd(void); // Finish vertex providing
|
2014-03-25 15:40:35 +04:00
|
|
|
void rlVertex2i(int x, int y); // Define one vertex (position) - 2 int
|
|
|
|
void rlVertex2f(float x, float y); // Define one vertex (position) - 2 float
|
|
|
|
void rlVertex3f(float x, float y, float z); // Define one vertex (position) - 3 float
|
|
|
|
void rlTexCoord2f(float x, float y); // Define one vertex (texture coordinate) - 2 float
|
|
|
|
void rlNormal3f(float x, float y, float z); // Define one vertex (normal) - 3 float
|
|
|
|
void rlColor4ub(byte r, byte g, byte b, byte a); // Define one vertex (color) - 4 byte
|
|
|
|
void rlColor3f(float x, float y, float z); // Define one vertex (color) - 3 float
|
|
|
|
void rlColor4f(float x, float y, float z, float w); // Define one vertex (color) - 4 float
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------------
|
|
|
|
// Functions Declaration - OpenGL equivalent functions (common to 1.1, 3.3+, ES2)
|
|
|
|
// NOTE: This functions are used to completely abstract raylib code from OpenGL layer
|
|
|
|
//------------------------------------------------------------------------------------
|
2014-09-17 00:51:31 +04:00
|
|
|
void rlEnableTexture(unsigned int id); // Enable texture usage
|
|
|
|
void rlDisableTexture(void); // Disable texture usage
|
|
|
|
void rlDeleteTextures(unsigned int id); // Delete OpenGL texture from GPU
|
2015-02-02 02:57:08 +03:00
|
|
|
void rlDeleteShader(unsigned int id); // Delete OpenGL shader program from GPU
|
2014-09-17 00:51:31 +04:00
|
|
|
void rlDeleteVertexArrays(unsigned int id); // Unload vertex data (VAO) from GPU memory
|
|
|
|
void rlDeleteBuffers(unsigned int id); // Unload vertex data (VBO) from GPU memory
|
2014-03-25 15:40:35 +04:00
|
|
|
void rlClearColor(byte r, byte g, byte b, byte a); // Clear color buffer with color
|
2014-09-17 00:51:31 +04:00
|
|
|
void rlClearScreenBuffers(void); // Clear used screen buffers (color and depth)
|
|
|
|
int rlGetVersion(void); // Returns current OpenGL version
|
2015-04-06 15:02:29 +03:00
|
|
|
void rlEnableFBO(void); // Enable rendering to postprocessing FBO
|
2014-03-25 15:40:35 +04:00
|
|
|
|
|
|
|
//------------------------------------------------------------------------------------
|
|
|
|
// Functions Declaration - rlgl functionality
|
|
|
|
//------------------------------------------------------------------------------------
|
2014-09-03 19:06:10 +04:00
|
|
|
void rlglInit(void); // Initialize rlgl (shaders, VAO, VBO...)
|
|
|
|
void rlglClose(void); // De-init rlgl
|
2014-09-17 00:51:31 +04:00
|
|
|
void rlglDraw(void); // Draw VAO/VBO
|
|
|
|
void rlglInitGraphics(int offsetX, int offsetY, int width, int height); // Initialize Graphics (OpenGL stuff)
|
|
|
|
|
2015-07-05 19:21:01 +03:00
|
|
|
unsigned int rlglLoadTexture(void *data, int width, int height, int textureFormat, int mipmapCount); // Load in GPU OpenGL texture
|
|
|
|
void rlglGenerateMipmaps(unsigned int textureId); // Generate mipmap data for selected texture
|
|
|
|
|
2015-04-13 21:15:28 +03:00
|
|
|
Shader rlglLoadShader(char *vsFileName, char *fsFileName); // Load a shader (vertex shader + fragment shader) from files
|
|
|
|
unsigned int rlglLoadShaderFromText(char *vShaderStr, char *fShaderStr); // Load a shader from text data
|
2015-04-06 15:02:29 +03:00
|
|
|
void rlglInitPostpro(void); // Initialize postprocessing system
|
|
|
|
void rlglDrawPostpro(void); // Draw with postprocessing shader
|
|
|
|
void rlglSetPostproShader(Shader shader); // Set postprocessing shader
|
2015-04-13 21:15:28 +03:00
|
|
|
void rlglSetModelShader(Model *model, Shader shader); // Set shader for a model
|
2015-05-05 00:46:31 +03:00
|
|
|
void rlglSetCustomShader(Shader shader); // Set custom shader to be used on batch draw
|
|
|
|
void rlglSetDefaultShader(void); // Set default shader to be used on batch draw
|
2014-03-25 15:40:35 +04:00
|
|
|
|
2014-09-17 00:51:31 +04:00
|
|
|
Model rlglLoadModel(VertexData mesh); // Upload vertex data into GPU and provided VAO/VBO ids
|
2015-03-02 22:52:58 +03:00
|
|
|
void rlglDrawModel(Model model, Vector3 position, float rotationAngle, Vector3 rotationAxis, Vector3 scale, Color color, bool wires);
|
2014-04-19 18:36:49 +04:00
|
|
|
|
2015-07-05 19:21:01 +03:00
|
|
|
Vector3 rlglUnproject(Vector3 source, Matrix proj, Matrix view); // Get world coordinates from screen coordinates
|
2015-04-06 15:02:29 +03:00
|
|
|
|
2015-07-05 19:21:01 +03:00
|
|
|
unsigned char *rlglReadScreenPixels(int width, int height); // Read screen pixel data (color buffer)
|
|
|
|
void *rlglReadTexturePixels(unsigned int textureId, unsigned int format); // Read texture pixel data
|
2014-03-25 15:40:35 +04:00
|
|
|
|
2014-09-17 00:51:31 +04:00
|
|
|
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
2014-09-03 19:06:10 +04:00
|
|
|
void PrintProjectionMatrix(void); // DEBUG: Print projection matrix
|
|
|
|
void PrintModelviewMatrix(void); // DEBUG: Print modelview matrix
|
2014-03-25 15:40:35 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif // RLGL_H
|