Skip to content

Commit

Permalink
Add SDL2 platform (#166)
Browse files Browse the repository at this point in the history
* Add SDL2 platform

* add desktopGL support to the SDL2 platform, and add SDL2 context shutdown calls
  • Loading branch information
vanfanel2 authored and XProger committed Feb 20, 2019
1 parent 1833cb1 commit a8ec6cc
Show file tree
Hide file tree
Showing 5 changed files with 594 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
//#define _GAPI_VULKAN

extern void osToggleVR(bool enable);
#elif __SDL2__
#define _GAPI_GL 1
#ifdef SDL2GLES
#define _GAPI_GLES 1
#define DYNGEOM_NO_VBO
#endif
#elif __RPI__
#define _OS_RPI 1
#define _GAPI_GL 1
Expand Down
56 changes: 53 additions & 3 deletions src/gapi_gl.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,51 @@
#include <GLES3/gl3.h>
#include <GLES3/gl3ext.h>
#include <GLES2/gl2ext.h>

#elif defined(__SDL2__)
#include <SDL2/SDL.h>
#if !defined(_GAPI_GLES)
#include <SDL2/SDL_opengl.h>
#else
#include <SDL2/SDL_opengles2.h>

#define GL_CLAMP_TO_BORDER 0x812D
#define GL_TEXTURE_BORDER_COLOR 0x1004

#define GL_TEXTURE_COMPARE_MODE 0x884C
#define GL_TEXTURE_COMPARE_FUNC 0x884D
#define GL_COMPARE_REF_TO_TEXTURE 0x884E

#undef GL_RG
#undef GL_RG32F
#undef GL_RG16F
#undef GL_RGBA32F
#undef GL_RGBA16F
#undef GL_HALF_FLOAT

#define GL_RG GL_RGBA
#define GL_RGBA32F GL_RGBA
#define GL_RGBA16F GL_RGBA
#define GL_RG32F GL_RGBA
#define GL_RG16F GL_RGBA
#define GL_HALF_FLOAT GL_HALF_FLOAT_OES

#define GL_TEXTURE_3D 0
#define GL_TEXTURE_WRAP_R 0
#define GL_DEPTH_STENCIL GL_DEPTH_STENCIL_OES
#define GL_UNSIGNED_INT_24_8 GL_UNSIGNED_INT_24_8_OES

#define glTexImage3D(...) 0

#define glGenVertexArrays(...)
#define glDeleteVertexArrays(...)
#define glBindVertexArray(...)

#define GL_PROGRAM_BINARY_LENGTH GL_PROGRAM_BINARY_LENGTH_OES
#define glGetProgramBinary(...)
#define glProgramBinary(...)
#endif

#elif defined(_OS_RPI) || defined(_OS_CLOVER)
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
Expand Down Expand Up @@ -245,11 +290,10 @@
PFNGLPROGRAMBINARYPROC glProgramBinary;
#endif

#if defined(_GAPI_GLES) && !defined(_OS_RPI) && !defined(_OS_CLOVER) && !defined(_OS_IOS) && !defined(_OS_ANDROID)
#if defined(_GAPI_GLES) && !defined(_OS_RPI) && !defined(_OS_CLOVER) && !defined(_OS_IOS) && !defined(_OS_ANDROID) && !defined(__SDL2__)
PFNGLDISCARDFRAMEBUFFEREXTPROC glDiscardFramebufferEXT;
#endif


#ifdef PROFILE
//#define USE_CV_MARKERS

Expand Down Expand Up @@ -1074,7 +1118,11 @@ namespace GAPI {
#else
#ifdef _GAPI_GLES
int GLES_VERSION = 1;
#if defined(__SDL2__)
SDL_GL_GetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, &GLES_VERSION);
#else
glGetIntegerv(GL_MAJOR_VERSION, &GLES_VERSION);
#endif
GLES3 = GLES_VERSION > 2;
#endif
#endif
Expand Down Expand Up @@ -1272,7 +1320,9 @@ namespace GAPI {
#ifdef _OS_ANDROID
glInvalidateFramebuffer(GL_FRAMEBUFFER, count, discard);
#else
glDiscardFramebufferEXT(GL_FRAMEBUFFER, count, discard);
#if !defined(__SDL2__)
glDiscardFramebufferEXT(GL_FRAMEBUFFER, count, discard);
#endif
#endif
}
}
Expand Down
31 changes: 31 additions & 0 deletions src/platform/sdl2/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
SRCS=main.cpp ../../libs/stb_vorbis/stb_vorbis.c ../../libs/minimp3/minimp3.cpp ../../libs/tinf/tinflate.c
CC=g++
OBJS=OpenLara.o
BIN=OpenLara

CFLAGS+=-D__SDL2__
LDFLAGS+=-lGLESv2 -lEGL -lSDL2 -lpthread -lrt -lm

INCLUDES+=-I./

openlara : $(OBJS)
$(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@

%.o: %.c
@rm -f $@
$(CC) $(CFLAGS) $(INCLUDES) -g -c $< -o $@ -Wno-deprecated-declarations

%.o: %.cpp
@rm -f $@
$(CXX) $(CFLAGS) $(INCLUDES) -g -c $< -o $@ -Wno-deprecated-declarations

%.bin: $(OBJS)
$(CC) -o $@ -Wl,--whole-archive $(OBJS) $(LDFLAGS) -Wl,--no-whole-archive -rdynamic

%.a: $(OBJS)
$(AR) r $@ $^

clean:
for i in $(OBJS); do (if test -e "$$i"; then ( rm $$i ); fi ); done
@rm -f $(BIN) $(LIB)

4 changes: 4 additions & 0 deletions src/platform/sdl2/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
set -e
g++ -DSDL2_GLES -std=c++11 `sdl2-config --cflags` -O3 -fno-exceptions -fno-rtti -ffunction-sections -fdata-sections -Wl,--gc-sections -DNDEBUG -D__SDL2__ main.cpp ../../libs/stb_vorbis/stb_vorbis.c ../../libs/minimp3/minimp3.cpp ../../libs/tinf/tinflate.c -I../../ -o OpenLara `sdl2-config --libs` -lGLESv2 -lEGL -lm -lrt -lpthread -lasound -ludev
#g++ -std=c++11 `sdl2-config --cflags` -O3 -fno-exceptions -fno-rtti -ffunction-sections -fdata-sections -Wl,--gc-sections -DNDEBUG -D__SDL2__ main.cpp ../../libs/stb_vorbis/stb_vorbis.c ../../libs/minimp3/minimp3.cpp ../../libs/tinf/tinflate.c -I../../ -o OpenLara `sdl2-config --libs` -lGL -lm -lrt -lpthread -lasound -ludev
#strip ../../../bin/OpenLara --strip-all --remove-section=.comment --remove-section=.note
Loading

0 comments on commit a8ec6cc

Please sign in to comment.