Browse Source

Some code tweaks

pull/19/head
raysan5 10 years ago
parent
commit
5104567a24
6 changed files with 33 additions and 22 deletions
  1. +0
    -1
      src/audio.c
  2. +2
    -2
      src/core.c
  3. +28
    -16
      src/models.c
  4. +1
    -1
      src/raylib.h
  5. +1
    -1
      src/rlgl.c
  6. +1
    -1
      src/utils.c

+ 0
- 1
src/audio.c View File

@ -865,7 +865,6 @@ static Wave LoadOGG(char *fileName)
TraceLog(DEBUG, "[%s] Total samples calculated: %i", fileName, totalSamples); TraceLog(DEBUG, "[%s] Total samples calculated: %i", fileName, totalSamples);
//short *data
wave.data = malloc(sizeof(short)*totalSamplesLength); wave.data = malloc(sizeof(short)*totalSamplesLength);
int samplesObtained = stb_vorbis_get_samples_short_interleaved(oggFile, info.channels, wave.data, totalSamplesLength); int samplesObtained = stb_vorbis_get_samples_short_interleaved(oggFile, info.channels, wave.data, totalSamplesLength);

+ 2
- 2
src/core.c View File

@ -261,7 +261,7 @@ static void CommandCallback(struct android_app *app, int32_t cmd); //
// Initialize Window and Graphics Context (OpenGL) // Initialize Window and Graphics Context (OpenGL)
void InitWindow(int width, int height, const char *title) void InitWindow(int width, int height, const char *title)
{ {
TraceLog(INFO, "Initializing raylib...");
TraceLog(INFO, "Initializing raylib (v1.2.2)");
// Store window title (could be useful...) // Store window title (could be useful...)
windowTitle = title; windowTitle = title;
@ -300,7 +300,7 @@ void InitWindow(int width, int height, const char *title)
// Android activity initialization // Android activity initialization
void InitWindow(int width, int height, struct android_app *state) void InitWindow(int width, int height, struct android_app *state)
{ {
TraceLog(INFO, "Initializing raylib...");
TraceLog(INFO, "Initializing raylib (v1.2.2)");
app_dummy(); app_dummy();

+ 28
- 16
src/models.c View File

@ -686,10 +686,13 @@ Model LoadModel(const char *fileName)
Model model = rlglLoadModel(vData); // Upload vertex data to GPU Model model = rlglLoadModel(vData); // Upload vertex data to GPU
// Now that vertex data is uploaded to GPU, we can free arrays // Now that vertex data is uploaded to GPU, we can free arrays
// NOTE: Despite vertex data is useless on OpenGL 3.3 or ES2, we will keep it...
//free(vData.vertices);
//free(vData.texcoords);
//free(vData.normals);
// NOTE: We don't need CPU vertex data on OpenGL 3.3 or ES2
if (rlGetVersion() != OPENGL_11)
{
free(vData.vertices);
free(vData.texcoords);
free(vData.normals);
}
return model; return model;
} }
@ -803,10 +806,13 @@ Model LoadHeightmap(Image heightmap, float maxHeight)
Model model = rlglLoadModel(vData); Model model = rlglLoadModel(vData);
// Now that vertex data is uploaded to GPU, we can free arrays // Now that vertex data is uploaded to GPU, we can free arrays
// NOTE: Despite vertex data is useless on OpenGL 3.3 or ES2, we will keep it...
//free(vData.vertices);
//free(vData.texcoords);
//free(vData.normals);
// NOTE: We don't need CPU vertex data on OpenGL 3.3 or ES2
if (rlGetVersion() != OPENGL_11)
{
free(vData.vertices);
free(vData.texcoords);
free(vData.normals);
}
return model; return model;
} }
@ -1118,10 +1124,13 @@ Model LoadCubicmap(Image cubesmap)
Model model = rlglLoadModel(vData); Model model = rlglLoadModel(vData);
// Now that vertex data is uploaded to GPU, we can free arrays // Now that vertex data is uploaded to GPU, we can free arrays
// NOTE: Despite vertex data is useless on OpenGL 3.3 or ES2, we will keep it...
//free(vData.vertices);
//free(vData.texcoords);
//free(vData.normals);
// NOTE: We don't need CPU vertex data on OpenGL 3.3 or ES2
if (rlGetVersion() != OPENGL_11)
{
free(vData.vertices);
free(vData.texcoords);
free(vData.normals);
}
return model; return model;
} }
@ -1129,10 +1138,13 @@ Model LoadCubicmap(Image cubesmap)
// Unload 3d model from memory // Unload 3d model from memory
void UnloadModel(Model model) void UnloadModel(Model model)
{ {
free(model.mesh.vertices);
free(model.mesh.texcoords);
free(model.mesh.normals);
if (rlGetVersion() == OPENGL_11)
{
free(model.mesh.vertices);
free(model.mesh.texcoords);
free(model.mesh.normals);
}
rlDeleteBuffers(model.vboId[0]); rlDeleteBuffers(model.vboId[0]);
rlDeleteBuffers(model.vboId[1]); rlDeleteBuffers(model.vboId[1]);
rlDeleteBuffers(model.vboId[2]); rlDeleteBuffers(model.vboId[2]);

+ 1
- 1
src/raylib.h View File

@ -312,7 +312,6 @@ void SetExitKey(int key); // Set a custom key
#endif #endif
int GetScreenWidth(void); // Get current screen width int GetScreenWidth(void); // Get current screen width
int GetScreenHeight(void); // Get current screen height int GetScreenHeight(void); // Get current screen height
int GetKeyPressed(void); // Get latest key pressed
void ClearBackground(Color color); // Sets Background Color void ClearBackground(Color color); // Sets Background Color
void BeginDrawing(void); // Setup drawing canvas to start drawing void BeginDrawing(void); // Setup drawing canvas to start drawing
@ -342,6 +341,7 @@ bool IsKeyPressed(int key); // Detect if a key has b
bool IsKeyDown(int key); // Detect if a key is being pressed bool IsKeyDown(int key); // Detect if a key is being pressed
bool IsKeyReleased(int key); // Detect if a key has been released once bool IsKeyReleased(int key); // Detect if a key has been released once
bool IsKeyUp(int key); // Detect if a key is NOT being pressed bool IsKeyUp(int key); // Detect if a key is NOT being pressed
int GetKeyPressed(void); // Get latest key pressed
bool IsMouseButtonPressed(int button); // Detect if a mouse button has been pressed once bool IsMouseButtonPressed(int button); // Detect if a mouse button has been pressed once
bool IsMouseButtonDown(int button); // Detect if a mouse button is being pressed bool IsMouseButtonDown(int button); // Detect if a mouse button is being pressed

+ 1
- 1
src/rlgl.c View File

@ -1682,7 +1682,7 @@ static GLuint LoadSimpleShader(void)
char fShaderStr[] = " #version 110 \n" // NOTE: Equivalent to version 100 on ES2 char fShaderStr[] = " #version 110 \n" // NOTE: Equivalent to version 100 on ES2
#elif defined(GRAPHICS_API_OPENGL_ES2) #elif defined(GRAPHICS_API_OPENGL_ES2)
char fShaderStr[] = " #version 100 \n" // NOTE: Must be defined this way! 110 doesn't work! char fShaderStr[] = " #version 100 \n" // NOTE: Must be defined this way! 110 doesn't work!
"precision mediump float; \n" // WebGL, required for emscripten
"precision mediump float; \n" // precision required for OpenGL ES2 (WebGL)
#endif #endif
"uniform sampler2D texture0; \n" "uniform sampler2D texture0; \n"
"varying vec2 fragTexCoord; \n" "varying vec2 fragTexCoord; \n"

+ 1
- 1
src/utils.c View File

@ -79,7 +79,7 @@ unsigned char *DecompressData(const unsigned char *data, unsigned long compSize,
pUncomp = (mz_uint8 *)malloc((size_t)uncompSize); pUncomp = (mz_uint8 *)malloc((size_t)uncompSize);
// Check correct memory allocation // Check correct memory allocation
if (o">!pUncomp)
if (n">pUncomp == NULL)
{ {
TraceLog(WARNING, "Out of memory while decompressing data"); TraceLog(WARNING, "Out of memory while decompressing data");
} }

Loading…
Cancel
Save