Some code tweaks
This commit is contained in:
parent
2d6213af60
commit
d593bd0081
4 changed files with 70 additions and 91 deletions
|
@ -351,7 +351,7 @@ typedef struct Image {
|
||||||
int format; // Data format (TextureFormat type)
|
int format; // Data format (TextureFormat type)
|
||||||
} Image;
|
} Image;
|
||||||
|
|
||||||
// Texture2D type, bpp always RGBA (32bit)
|
// Texture2D type
|
||||||
// NOTE: Data stored in GPU memory
|
// NOTE: Data stored in GPU memory
|
||||||
typedef struct Texture2D {
|
typedef struct Texture2D {
|
||||||
unsigned int id; // OpenGL texture id
|
unsigned int id; // OpenGL texture id
|
||||||
|
|
|
@ -64,7 +64,7 @@
|
||||||
|
|
||||||
#include <stdio.h> // Required for: fopen(), fclose(), fread()... [Used only on LoadText()]
|
#include <stdio.h> // Required for: fopen(), fclose(), fread()... [Used only on LoadText()]
|
||||||
#include <stdlib.h> // Required for: malloc(), free(), rand()
|
#include <stdlib.h> // Required for: malloc(), free(), rand()
|
||||||
#include <string.h> // Required for: strcmp(), strlen(), strtok()
|
#include <string.h> // Required for: strcmp(), strlen(), strtok() [Used only in extensions loading]
|
||||||
#include <math.h> // Required for: atan2()
|
#include <math.h> // Required for: atan2()
|
||||||
|
|
||||||
#ifndef RLGL_STANDALONE
|
#ifndef RLGL_STANDALONE
|
||||||
|
|
118
src/rlgl.h
118
src/rlgl.h
|
@ -17,7 +17,9 @@
|
||||||
* #define GRAPHICS_API_OPENGL_21
|
* #define GRAPHICS_API_OPENGL_21
|
||||||
* #define GRAPHICS_API_OPENGL_33
|
* #define GRAPHICS_API_OPENGL_33
|
||||||
* #define GRAPHICS_API_OPENGL_ES2
|
* #define GRAPHICS_API_OPENGL_ES2
|
||||||
* Use selected OpenGL backend
|
* Use selected OpenGL graphics backend, should be supported by platform
|
||||||
|
* Those preprocessor defines are only used on rlgl module, if OpenGL version is
|
||||||
|
* required by any other module, use rlGetVersion() tocheck it
|
||||||
*
|
*
|
||||||
* #define RLGL_STANDALONE
|
* #define RLGL_STANDALONE
|
||||||
* Use rlgl as standalone library (no raylib dependency)
|
* Use rlgl as standalone library (no raylib dependency)
|
||||||
|
@ -57,11 +59,8 @@
|
||||||
#ifndef RLGL_H
|
#ifndef RLGL_H
|
||||||
#define RLGL_H
|
#define RLGL_H
|
||||||
|
|
||||||
//#define RLGL_STANDALONE // NOTE: To use rlgl as standalone lib, just uncomment this line
|
|
||||||
|
|
||||||
#ifndef RLGL_STANDALONE
|
#ifndef RLGL_STANDALONE
|
||||||
#include "raylib.h" // Required for: Model, Shader, Texture2D
|
#include "raylib.h" // Required for: Model, Shader, Texture2D, TraceLog()
|
||||||
#include "utils.h" // Required for: TraceLog()
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef RLGL_STANDALONE
|
#ifdef RLGL_STANDALONE
|
||||||
|
@ -70,15 +69,6 @@
|
||||||
|
|
||||||
#include "raymath.h" // Required for: Vector3, Matrix
|
#include "raymath.h" // Required for: Vector3, Matrix
|
||||||
|
|
||||||
// Select desired OpenGL version
|
|
||||||
// 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 and RLGL_OCULUS_SUPPORT
|
|
||||||
//#define GRAPHICS_API_OPENGL_ES2 // Only available on PLATFORM_ANDROID or PLATFORM_RPI or PLATFORM_WEB
|
|
||||||
|
|
||||||
// Security check in case no GRAPHICS_API_OPENGL_* defined
|
// Security check in case no GRAPHICS_API_OPENGL_* defined
|
||||||
#if !defined(GRAPHICS_API_OPENGL_11) && !defined(GRAPHICS_API_OPENGL_21) && !defined(GRAPHICS_API_OPENGL_33) && !defined(GRAPHICS_API_OPENGL_ES2)
|
#if !defined(GRAPHICS_API_OPENGL_11) && !defined(GRAPHICS_API_OPENGL_21) && !defined(GRAPHICS_API_OPENGL_33) && !defined(GRAPHICS_API_OPENGL_ES2)
|
||||||
#define GRAPHICS_API_OPENGL_11
|
#define GRAPHICS_API_OPENGL_11
|
||||||
|
@ -166,27 +156,22 @@ typedef unsigned char byte;
|
||||||
unsigned char a;
|
unsigned char a;
|
||||||
} Color;
|
} Color;
|
||||||
|
|
||||||
// Texture formats (support depends on OpenGL version)
|
// Texture2D type
|
||||||
typedef enum {
|
// NOTE: Data stored in GPU memory
|
||||||
UNCOMPRESSED_GRAYSCALE = 1, // 8 bit per pixel (no alpha)
|
typedef struct Texture2D {
|
||||||
UNCOMPRESSED_GRAY_ALPHA,
|
unsigned int id; // OpenGL texture id
|
||||||
UNCOMPRESSED_R5G6B5, // 16 bpp
|
int width; // Texture base width
|
||||||
UNCOMPRESSED_R8G8B8, // 24 bpp
|
int height; // Texture base height
|
||||||
UNCOMPRESSED_R5G5B5A1, // 16 bpp (1 bit alpha)
|
int mipmaps; // Mipmap levels, 1 by default
|
||||||
UNCOMPRESSED_R4G4B4A4, // 16 bpp (4 bit alpha)
|
int format; // Data format (TextureFormat)
|
||||||
UNCOMPRESSED_R8G8B8A8, // 32 bpp
|
} Texture2D;
|
||||||
COMPRESSED_DXT1_RGB, // 4 bpp (no alpha)
|
|
||||||
COMPRESSED_DXT1_RGBA, // 4 bpp (1 bit alpha)
|
// RenderTexture2D type, for texture rendering
|
||||||
COMPRESSED_DXT3_RGBA, // 8 bpp
|
typedef struct RenderTexture2D {
|
||||||
COMPRESSED_DXT5_RGBA, // 8 bpp
|
unsigned int id; // Render texture (fbo) id
|
||||||
COMPRESSED_ETC1_RGB, // 4 bpp
|
Texture2D texture; // Color buffer attachment texture
|
||||||
COMPRESSED_ETC2_RGB, // 4 bpp
|
Texture2D depth; // Depth buffer attachment texture
|
||||||
COMPRESSED_ETC2_EAC_RGBA, // 8 bpp
|
} RenderTexture2D;
|
||||||
COMPRESSED_PVRT_RGB, // 4 bpp
|
|
||||||
COMPRESSED_PVRT_RGBA, // 4 bpp
|
|
||||||
COMPRESSED_ASTC_4x4_RGBA, // 8 bpp
|
|
||||||
COMPRESSED_ASTC_8x8_RGBA // 2 bpp
|
|
||||||
} TextureFormat;
|
|
||||||
|
|
||||||
// Vertex data definning a mesh
|
// Vertex data definning a mesh
|
||||||
typedef struct Mesh {
|
typedef struct Mesh {
|
||||||
|
@ -228,23 +213,6 @@ typedef unsigned char byte;
|
||||||
int mapTexture2Loc; // Map texture uniform location point (default-texture-unit = 2)
|
int mapTexture2Loc; // Map texture uniform location point (default-texture-unit = 2)
|
||||||
} Shader;
|
} Shader;
|
||||||
|
|
||||||
// Texture2D type
|
|
||||||
// NOTE: Data stored in GPU memory
|
|
||||||
typedef struct Texture2D {
|
|
||||||
unsigned int id; // OpenGL texture id
|
|
||||||
int width; // Texture base width
|
|
||||||
int height; // Texture base height
|
|
||||||
int mipmaps; // Mipmap levels, 1 by default
|
|
||||||
int format; // Data format (TextureFormat)
|
|
||||||
} Texture2D;
|
|
||||||
|
|
||||||
// RenderTexture2D type, for texture rendering
|
|
||||||
typedef struct RenderTexture2D {
|
|
||||||
unsigned int id; // Render texture (fbo) id
|
|
||||||
Texture2D texture; // Color buffer attachment texture
|
|
||||||
Texture2D depth; // Depth buffer attachment texture
|
|
||||||
} RenderTexture2D;
|
|
||||||
|
|
||||||
// Material type
|
// Material type
|
||||||
typedef struct Material {
|
typedef struct Material {
|
||||||
Shader shader; // Standard shader (supports 3 map types: diffuse, normal, specular)
|
Shader shader; // Standard shader (supports 3 map types: diffuse, normal, specular)
|
||||||
|
@ -268,6 +236,37 @@ typedef unsigned char byte;
|
||||||
float fovy; // Camera field-of-view apperture in Y (degrees)
|
float fovy; // Camera field-of-view apperture in Y (degrees)
|
||||||
} Camera;
|
} Camera;
|
||||||
|
|
||||||
|
// TraceLog message types
|
||||||
|
typedef enum {
|
||||||
|
INFO = 0,
|
||||||
|
ERROR,
|
||||||
|
WARNING,
|
||||||
|
DEBUG,
|
||||||
|
OTHER
|
||||||
|
} TraceLogType;
|
||||||
|
|
||||||
|
// Texture formats (support depends on OpenGL version)
|
||||||
|
typedef enum {
|
||||||
|
UNCOMPRESSED_GRAYSCALE = 1, // 8 bit per pixel (no alpha)
|
||||||
|
UNCOMPRESSED_GRAY_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
|
||||||
|
COMPRESSED_PVRT_RGB, // 4 bpp
|
||||||
|
COMPRESSED_PVRT_RGBA, // 4 bpp
|
||||||
|
COMPRESSED_ASTC_4x4_RGBA, // 8 bpp
|
||||||
|
COMPRESSED_ASTC_8x8_RGBA // 2 bpp
|
||||||
|
} TextureFormat;
|
||||||
|
|
||||||
// Texture parameters: filter mode
|
// Texture parameters: filter mode
|
||||||
// NOTE 1: Filtering considers mipmaps if available in the texture
|
// NOTE 1: Filtering considers mipmaps if available in the texture
|
||||||
// NOTE 2: Filter is accordingly set for minification and magnification
|
// NOTE 2: Filter is accordingly set for minification and magnification
|
||||||
|
@ -281,13 +280,18 @@ typedef unsigned char byte;
|
||||||
} TextureFilterMode;
|
} TextureFilterMode;
|
||||||
|
|
||||||
// Texture parameters: wrap mode
|
// Texture parameters: wrap mode
|
||||||
typedef enum { WRAP_REPEAT = 0, WRAP_CLAMP, WRAP_MIRROR } TextureWrapMode;
|
typedef enum {
|
||||||
|
WRAP_REPEAT = 0,
|
||||||
|
WRAP_CLAMP,
|
||||||
|
WRAP_MIRROR
|
||||||
|
} TextureWrapMode;
|
||||||
|
|
||||||
// Color blending modes (pre-defined)
|
// Color blending modes (pre-defined)
|
||||||
typedef enum { BLEND_ALPHA = 0, BLEND_ADDITIVE, BLEND_MULTIPLIED } BlendMode;
|
typedef enum {
|
||||||
|
BLEND_ALPHA = 0,
|
||||||
// TraceLog message types
|
BLEND_ADDITIVE,
|
||||||
typedef enum { INFO = 0, ERROR, WARNING, DEBUG, OTHER } TraceLogType;
|
BLEND_MULTIPLIED
|
||||||
|
} BlendMode;
|
||||||
|
|
||||||
// VR Head Mounted Display devices
|
// VR Head Mounted Display devices
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
|
|
@ -154,14 +154,7 @@ static Image LoadASTC(const char *fileName); // Load ASTC file
|
||||||
// Load image from file into CPU memory (RAM)
|
// Load image from file into CPU memory (RAM)
|
||||||
Image LoadImage(const char *fileName)
|
Image LoadImage(const char *fileName)
|
||||||
{
|
{
|
||||||
Image image;
|
Image image = { 0 };
|
||||||
|
|
||||||
// Initialize image default values
|
|
||||||
image.data = NULL;
|
|
||||||
image.width = 0;
|
|
||||||
image.height = 0;
|
|
||||||
image.mipmaps = 0;
|
|
||||||
image.format = 0;
|
|
||||||
|
|
||||||
if (IsFileExtension(fileName, ".rres"))
|
if (IsFileExtension(fileName, ".rres"))
|
||||||
{
|
{
|
||||||
|
@ -282,13 +275,7 @@ Image LoadImagePro(void *data, int width, int height, int format)
|
||||||
// Load an image from RAW file data
|
// Load an image from RAW file data
|
||||||
Image LoadImageRaw(const char *fileName, int width, int height, int format, int headerSize)
|
Image LoadImageRaw(const char *fileName, int width, int height, int format, int headerSize)
|
||||||
{
|
{
|
||||||
Image image;
|
Image image = { 0 };
|
||||||
|
|
||||||
image.data = NULL;
|
|
||||||
image.width = 0;
|
|
||||||
image.height = 0;
|
|
||||||
image.mipmaps = 0;
|
|
||||||
image.format = 0;
|
|
||||||
|
|
||||||
FILE *rawFile = fopen(fileName, "rb");
|
FILE *rawFile = fopen(fileName, "rb");
|
||||||
|
|
||||||
|
@ -342,7 +329,7 @@ Image LoadImageRaw(const char *fileName, int width, int height, int format, int
|
||||||
// Load texture from file into GPU memory (VRAM)
|
// Load texture from file into GPU memory (VRAM)
|
||||||
Texture2D LoadTexture(const char *fileName)
|
Texture2D LoadTexture(const char *fileName)
|
||||||
{
|
{
|
||||||
Texture2D texture;
|
Texture2D texture = { 0 };
|
||||||
|
|
||||||
Image image = LoadImage(fileName);
|
Image image = LoadImage(fileName);
|
||||||
|
|
||||||
|
@ -351,11 +338,7 @@ Texture2D LoadTexture(const char *fileName)
|
||||||
texture = LoadTextureFromImage(image);
|
texture = LoadTextureFromImage(image);
|
||||||
UnloadImage(image);
|
UnloadImage(image);
|
||||||
}
|
}
|
||||||
else
|
else TraceLog(WARNING, "Texture could not be created");
|
||||||
{
|
|
||||||
TraceLog(WARNING, "Texture could not be created");
|
|
||||||
texture.id = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return texture;
|
return texture;
|
||||||
}
|
}
|
||||||
|
@ -364,14 +347,7 @@ Texture2D LoadTexture(const char *fileName)
|
||||||
// NOTE: image is not unloaded, it must be done manually
|
// NOTE: image is not unloaded, it must be done manually
|
||||||
Texture2D LoadTextureFromImage(Image image)
|
Texture2D LoadTextureFromImage(Image image)
|
||||||
{
|
{
|
||||||
Texture2D texture;
|
Texture2D texture = { 0 };
|
||||||
|
|
||||||
// Init texture to default values
|
|
||||||
texture.id = 0;
|
|
||||||
texture.width = 0;
|
|
||||||
texture.height = 0;
|
|
||||||
texture.mipmaps = 0;
|
|
||||||
texture.format = 0;
|
|
||||||
|
|
||||||
texture.id = rlglLoadTexture(image.data, image.width, image.height, image.format, image.mipmaps);
|
texture.id = rlglLoadTexture(image.data, image.width, image.height, image.format, image.mipmaps);
|
||||||
|
|
||||||
|
@ -510,8 +486,7 @@ Color *GetImageData(Image image)
|
||||||
// NOTE: Compressed texture formats not supported
|
// NOTE: Compressed texture formats not supported
|
||||||
Image GetTextureData(Texture2D texture)
|
Image GetTextureData(Texture2D texture)
|
||||||
{
|
{
|
||||||
Image image;
|
Image image = { 0 };
|
||||||
image.data = NULL;
|
|
||||||
|
|
||||||
if (texture.format < 8)
|
if (texture.format < 8)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue