Compare commits

...

9 Commits

  1. 28
      Makefile
  2. 2
      examples/Makefile
  3. 4
      examples/main.cpp
  4. 5
      include/GLDebug.h
  5. 1
      include/asset.h
  6. 1
      include/camera.h
  7. 1
      include/shader.h
  8. 17
      include/tangerine.h
  9. 1
      include/types.h
  10. 1
      src/asset.cpp
  11. 1
      src/camera.cpp
  12. 1
      src/entity.cpp
  13. 4
      src/shader.cpp
  14. 10
      src/tangerine.cpp

28
Makefile

@ -1,20 +1,24 @@
SHELL = /bin/sh SHELL := /bin/sh
CXX = g++ CXX := g++
CXXFLAGS = -std=c++11 -g -ggdb3 -Wall \ # NOTE: have to set -O or -O1 here to get warnings for uninitialized variables
CXXFLAGS := -std=c++11 -g -ggdb3 -Wall -O -Wall -Wuninitialized \
-Iinclude \ -Iinclude \
-I/usr/include/SDL2 \ -I/usr/include/SDL2 \
-Iext/stb_libs \ -Iext/stb_libs \
-Iext/tinygltf -Iext/tinygltf
EXAMPLEDIR = examples EXAMPLEDIR := examples
OBJDIR = build OBJDIR := build
SRCDIR = src SRCDIR := src
LIBNAME = libTangerine.a LIBNAME := libTangerine.a
SOURCES = $(wildcard $(SRCDIR)/*.cpp) # NOTE: optional library settings
OBJECTS = $(patsubst $(SRCDIR)/%.cpp, $(OBJDIR)/%.o, $(SOURCES)) CXXFLAGS += -DTANGERINE_GL_DEBUG_QUIET
NDBG_SOURCES = $(wildcard $(SRCDIR)/*.cc)
NDBG_OBJS = $(patsubst $(SRCDIR)/%.cc, $(OBJDIR)/%.o, $(NDBG_SOURCES)) SOURCES := $(wildcard $(SRCDIR)/*.cpp)
OBJECTS := $(patsubst $(SRCDIR)/%.cpp, $(OBJDIR)/%.o, $(SOURCES))
NDBG_SOURCES := $(wildcard $(SRCDIR)/*.cc)
NDBG_OBJS := $(patsubst $(SRCDIR)/%.cc, $(OBJDIR)/%.o, $(NDBG_SOURCES))
all: mkdirs $(LIBNAME) all: mkdirs $(LIBNAME)

2
examples/Makefile

@ -34,7 +34,7 @@ BINDIR = bin
#.PHONY: clean #.PHONY: clean
all: mkdirs all: mkdirs
$(CXX) $(CXXFLAGS) main.cpp -o $(BINDIR)/testing $(LDFLAGS) $(LIB) $(CXX) $(CXXFLAGS) main.cpp -o $(BINDIR)/testing $(LIB) $(LDFLAGS)
mkdirs: mkdirs:
@mkdir -p $(BINDIR) $(OBJDIR) @mkdir -p $(BINDIR) $(OBJDIR)

4
examples/main.cpp

@ -261,7 +261,7 @@ orbitPositionZ0(vec4* pos, float angle)
} }
void void
render_cb_pre(RenderState* rs) render_cb_pre(RenderState* rs, void* user_data = nullptr)
{ {
SDL_Event e; SDL_Event e;
@ -332,7 +332,7 @@ main()
return 1; return 1;
} }
doRenderLoop(rs, 60, render_cb_pre, nullptr); doRenderLoop(rs, 60, render_cb_pre, nullptr, nullptr);
freeRenderState(rs); freeRenderState(rs);
return 0; return 0;

5
include/GLDebug.h

@ -92,6 +92,11 @@ openglDebugCallback(GLenum source,
if (id == 131185) if (id == 131185)
return; return;
#ifdef TANGERINE_GL_DEBUG_QUIET
if (type != GL_DEBUG_TYPE_ERROR)
return;
#endif
std::cout << "message id: " << id << ", " std::cout << "message id: " << id << ", "
<< ((type == GL_DEBUG_TYPE_ERROR) ? "Error" : "Debug") << ((type == GL_DEBUG_TYPE_ERROR) ? "Error" : "Debug")
<< (type == GL_DEBUG_TYPE_ERROR ? "** GL Error **" : "") << (type == GL_DEBUG_TYPE_ERROR ? "** GL Error **" : "")

1
include/asset.h

@ -2,6 +2,7 @@
#pragma once #pragma once
#include <GL/glew.h> #include <GL/glew.h>
#define GLM_FORCE_XYZW_ONLY
#include <glm/glm.hpp> #include <glm/glm.hpp>
#include "types.h" #include "types.h"

1
include/camera.h

@ -1,6 +1,7 @@
#pragma once #pragma once
#define GLM_FORCE_XYZW_ONLY
#include <glm/glm.hpp> #include <glm/glm.hpp>
#include "types.h" #include "types.h"

1
include/shader.h

@ -3,6 +3,7 @@
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
#include <GL/glew.h> #include <GL/glew.h>
#define GLM_FORCE_XYZW_ONLY
#include <glm/glm.hpp> #include <glm/glm.hpp>
#include "asset.h" #include "asset.h"

17
include/tangerine.h

@ -75,11 +75,17 @@
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
// NOTE: optional compile-time defines:
// TANGERINE_GL_DEBUG_QUIET disable extra debug messages from openGL
#include "asset.h" #include "asset.h"
#include "camera.h" #include "camera.h"
#include "entity.h" #include "entity.h"
#include "dumbLog.h" #include "dumbLog.h"
#include "GLDebug.h" #include "GLDebug.h"
#include "input.h"
#include "shader.h" #include "shader.h"
#include "types.h" #include "types.h"
#include "util.h" #include "util.h"
@ -93,9 +99,6 @@ struct SDLHandles
u32 SDL_flags; u32 SDL_flags;
}; };
// TODO: node/tree structure for entities
struct Node;
struct RenderGroup struct RenderGroup
{ {
ShaderProgram* shader; ShaderProgram* shader;
@ -105,7 +108,10 @@ struct RenderGroup
char* name; char* name;
}; };
// TODO: node/tree structure for entities
#if 0 #if 0
struct Node;
struct Scene struct Scene
{ {
MemoryArena* rg_arena; MemoryArena* rg_arena;
@ -234,7 +240,7 @@ Entity* getFreeEntity(RenderGroup* rg);
Entity* getEntityByName(RenderGroup* rg, const char* name); Entity* getEntityByName(RenderGroup* rg, const char* name);
// NOTE: callback function signature to use with renDoRenderLoop() // NOTE: callback function signature to use with renDoRenderLoop()
typedef void (*frame_callback_fn) (RenderState*); typedef void (*frame_callback_fn) (RenderState*, void*);
// NOTE: There are 2 callbacks to use here, cb_func_pre is called before // NOTE: There are 2 callbacks to use here, cb_func_pre is called before
// the call to renRenderFrame(), cb_fun_post is called after // the call to renRenderFrame(), cb_fun_post is called after
@ -243,7 +249,8 @@ typedef void (*frame_callback_fn) (RenderState*);
void doRenderLoop(RenderState* rs, void doRenderLoop(RenderState* rs,
uint framerate = 60, uint framerate = 60,
frame_callback_fn cb_func_pre = nullptr, frame_callback_fn cb_func_pre = nullptr,
frame_callback_fn cb_func_post = nullptr); frame_callback_fn cb_func_post = nullptr,
void* user_data = nullptr);
void renderFrame(RenderState* rs, const GLClearColor& clear_col); void renderFrame(RenderState* rs, const GLClearColor& clear_col);

1
include/types.h

@ -2,6 +2,7 @@
#pragma once #pragma once
#include <cstdint> #include <cstdint>
#define GLM_FORCE_XYZW_ONLY
#include <glm/glm.hpp> #include <glm/glm.hpp>

1
src/asset.cpp

@ -2,6 +2,7 @@
#include <cassert> #include <cassert>
#include <cstring> #include <cstring>
#define GLM_FORCE_XYZW_ONLY
#include <glm/ext/matrix_transform.hpp> #include <glm/ext/matrix_transform.hpp>
#include "tiny_gltf.h" #include "tiny_gltf.h"

1
src/camera.cpp

@ -2,6 +2,7 @@
#include <cassert> #include <cassert>
#include <GL/glew.h> #include <GL/glew.h>
#define GLM_FORCE_XYZW_ONLY
#include <glm/glm.hpp> #include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp> #include <glm/gtc/matrix_transform.hpp>

1
src/entity.cpp

@ -1,4 +1,5 @@
#define GLM_FORCE_XYZW_ONLY
#include <glm/gtc/matrix_transform.hpp> #include <glm/gtc/matrix_transform.hpp>
#include "dumbLog.h" #include "dumbLog.h"

4
src/shader.cpp

@ -6,12 +6,12 @@
#include <cstring> #include <cstring>
#include <fstream> #include <fstream>
#define GLM_FORCE_XYZW_ONLY
#include <glm/gtc/matrix_transform.hpp> #include <glm/gtc/matrix_transform.hpp>
#include "asset.h" #include "asset.h"
#include "dumbLog.h" #include "dumbLog.h"
#include "dummy_shader.h" #include "dummy_shader.h"
#define GL_DEBUG_IMPLEMENTATION
#include "GLDebug.h" #include "GLDebug.h"
#include "shader.h" #include "shader.h"
#include "util.h" #include "util.h"
@ -135,7 +135,7 @@ getFreeShader(GLContext* gl_ctx)
ShaderProgram* ShaderProgram*
getShaderByHash(GLContext* gl_ctx, u64 hash) getShaderByHash(GLContext* gl_ctx, u64 hash)
{ {
for (u32 i; i < gl_ctx->num_shaders; i++) { for (u32 i = 0; i < gl_ctx->num_shaders; i++) {
if (gl_ctx->shaders[i].hash == hash) if (gl_ctx->shaders[i].hash == hash)
return &gl_ctx->shaders[i]; return &gl_ctx->shaders[i];
} }

10
src/tangerine.cpp

@ -1,11 +1,14 @@
#include <cassert> #include <cassert>
#define GLM_FORCE_XYZW_ONLY
#include <glm/gtc/matrix_transform.hpp> #include <glm/gtc/matrix_transform.hpp>
#include "tangerine.h" #include "tangerine.h"
#define UTIL_IMPLEMENTATION #define UTIL_IMPLEMENTATION
#include "util.h" #include "util.h"
#define GL_DEBUG_IMPLEMENTATION
#include "GLDebug.h"
// forward declarations // forward declarations
@ -175,7 +178,8 @@ void
doRenderLoop(RenderState* rs, doRenderLoop(RenderState* rs,
u32 framerate, u32 framerate,
frame_callback_fn cb_func_pre, frame_callback_fn cb_func_pre,
frame_callback_fn cb_func_post) frame_callback_fn cb_func_post,
void* user_data)
{ {
u32 delay = (framerate > 0) ? 1 / framerate : 0; u32 delay = (framerate > 0) ? 1 / framerate : 0;
u32 frameStart, frameTime; u32 frameStart, frameTime;
@ -186,7 +190,7 @@ doRenderLoop(RenderState* rs,
frameStart = SDL_GetTicks(); frameStart = SDL_GetTicks();
if (cb_func_pre != nullptr) { if (cb_func_pre != nullptr) {
cb_func_pre(rs); cb_func_pre(rs, user_data);
} else { } else {
while (SDL_PollEvent(&e)) { while (SDL_PollEvent(&e)) {
if (e.type == SDL_QUIT || if (e.type == SDL_QUIT ||
@ -201,7 +205,7 @@ doRenderLoop(RenderState* rs,
renderFrame(rs, rs->clear_col); renderFrame(rs, rs->clear_col);
if (cb_func_post != nullptr) if (cb_func_post != nullptr)
cb_func_post(rs); cb_func_post(rs, user_data);
SDL_GL_SwapWindow(rs->handles.window); SDL_GL_SwapWindow(rs->handles.window);
frameTime = SDL_GetTicks() - frameStart; frameTime = SDL_GetTicks() - frameStart;

Loading…
Cancel
Save