Browse Source

Some code tweaks

pull/282/head
Ray 7 years ago
parent
commit
d593bd0081
4 changed files with 70 additions and 91 deletions
  1. +1
    -1
      src/raylib.h
  2. +1
    -1
      src/rlgl.c
  3. +61
    -57
      src/rlgl.h
  4. +7
    -32
      src/textures.c

+ 1
- 1
src/raylib.h View File

@ -351,7 +351,7 @@ typedef struct Image {
int format; // Data format (TextureFormat type)
} Image;
// Texture2D type, bpp always RGBA (32bit)
// Texture2D type
// NOTE: Data stored in GPU memory
typedef struct Texture2D {
unsigned int id; // OpenGL texture id

+ 1
- 1
src/rlgl.c View File

@ -64,7 +64,7 @@
#include <stdio.h> // Required for: fopen(), fclose(), fread()... [Used only on LoadText()]
#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()
#ifndef RLGL_STANDALONE

+ 61
- 57
src/rlgl.h View File

@ -17,7 +17,9 @@
* #define GRAPHICS_API_OPENGL_21
* #define GRAPHICS_API_OPENGL_33
* #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
* Use rlgl as standalone library (no raylib dependency)
@ -57,11 +59,8 @@
#ifndef RLGL_H
#define RLGL_H
//#define RLGL_STANDALONE // NOTE: To use rlgl as standalone lib, just uncomment this line
#ifndef RLGL_STANDALONE
#include "raylib.h" // Required for: Model, Shader, Texture2D
#include "utils.h" // Required for: TraceLog()
#include "raylib.h" // Required for: Model, Shader, Texture2D, TraceLog()
#endif
#ifdef RLGL_STANDALONE
@ -70,15 +69,6 @@
#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
#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
@ -165,28 +155,23 @@ typedef unsigned char byte;
unsigned char b;
unsigned char a;
} Color;
// 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;
// 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;
// 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;
// Vertex data definning a mesh
typedef struct Mesh {
@ -228,23 +213,6 @@ typedef unsigned char byte;
int mapTexture2Loc; // Map texture uniform location point (default-texture-unit = 2)
} 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
typedef struct Material {
Shader shader; // Standard shader (supports 3 map types: diffuse, normal, specular)
@ -267,6 +235,37 @@ typedef unsigned char byte;
Vector3 up; // Camera up vector (rotation over its axis)
float fovy; // Camera field-of-view apperture in Y (degrees)
} 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
// NOTE 1: Filtering considers mipmaps if available in the texture
@ -281,13 +280,18 @@ typedef unsigned char byte;
} TextureFilterMode;
// 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)
typedef enum { BLEND_ALPHA = 0, BLEND_ADDITIVE, BLEND_MULTIPLIED } BlendMode;
// TraceLog message types
typedef enum { INFO = 0, ERROR, WARNING, DEBUG, OTHER } TraceLogType;
typedef enum {
BLEND_ALPHA = 0,
BLEND_ADDITIVE,
BLEND_MULTIPLIED
} BlendMode;
// VR Head Mounted Display devices
typedef enum {

+ 7
- 32
src/textures.c View File

@ -154,14 +154,7 @@ static Image LoadASTC(const char *fileName); // Load ASTC file
// Load image from file into CPU memory (RAM)
Image LoadImage(const char *fileName)
{
Image image;
// Initialize image default values
image.data = NULL;
image.width = 0;
image.height = 0;
image.mipmaps = 0;
image.format = 0;
Image image = { 0 };
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
Image LoadImageRaw(const char *fileName, int width, int height, int format, int headerSize)
{
Image image;
image.data = NULL;
image.width = 0;
image.height = 0;
image.mipmaps = 0;
image.format = 0;
Image image = { 0 };
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)
Texture2D LoadTexture(const char *fileName)
{
Texture2D texture;
Texture2D texture = { 0 };
Image image = LoadImage(fileName);
@ -351,11 +338,7 @@ Texture2D LoadTexture(const char *fileName)
texture = LoadTextureFromImage(image);
UnloadImage(image);
}
else
{
TraceLog(WARNING, "Texture could not be created");
texture.id = 0;
}
else TraceLog(WARNING, "Texture could not be created");
return texture;
}
@ -364,14 +347,7 @@ Texture2D LoadTexture(const char *fileName)
// NOTE: image is not unloaded, it must be done manually
Texture2D LoadTextureFromImage(Image image)
{
Texture2D texture;
// Init texture to default values
texture.id = 0;
texture.width = 0;
texture.height = 0;
texture.mipmaps = 0;
texture.format = 0;
Texture2D texture = { 0 };
texture.id = rlglLoadTexture(image.data, image.width, image.height, image.format, image.mipmaps);
@ -510,9 +486,8 @@ Color *GetImageData(Image image)
// NOTE: Compressed texture formats not supported
Image GetTextureData(Texture2D texture)
{
Image image;
image.data = NULL;
Image image = { 0 };
if (texture.format < 8)
{
image.data = rlglReadTexturePixels(texture);

Loading…
Cancel
Save