Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GLEW and FreeGLUT refactor and cleanup #441

Merged
merged 15 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,11 @@ ifneq ($(filter y,$(DEP_HTTP)),)
endif

ifneq ($(OS),osx)
EXE_LIBS += $(QB_CORE_LIB)
EXE_LIBS += $(QB_CORE_LIB) $(GLEW_OBJS)

LICENSE_IN_USE += freeglut
else
EXE_LIBS += $(GLEW_OBJS)
endif

ifeq ($(OS),win)
Expand All @@ -341,7 +343,7 @@ ifeq ($(OS),win)

ifneq ($(filter y,$(DEP_CONSOLE_ONLY)),)
CXXFLAGS := $(filter-out -DFREEGLUT_STATIC,$(CXXFLAGS))
EXE_LIBS := $(filter-out $(QB_CORE_LIB),$(EXE_LIBS))
EXE_LIBS := $(filter-out $(QB_CORE_LIB) $(GLEW_OBJS),$(EXE_LIBS))

LICENSE_IN_USE := $(filter-out freeglut,$(LICENSE_IN_USE))
else
Expand Down
20 changes: 12 additions & 8 deletions internal/c/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,18 @@
// core
# ifdef QB64_GUI
# ifdef QB64_GLUT
// This file only contains header stuff
# include "parts/core/src.c"
# include <GL/glew.h>
# ifdef QB64_MACOSX
// note: MacOSX uses Apple's GLUT not FreeGLUT
# include <GLUT/glut.h>
# include <OpenGL/gl.h>
# include <OpenGL/glext.h>
# include <OpenGL/glu.h>
# else
# define CORE_FREEGLUT
# include <GL/freeglut.h>
# include <GL/glext.h>
# endif
# endif
# endif

Expand Down Expand Up @@ -87,12 +97,6 @@

# endif

# ifdef QB64_GUI
# ifdef QB64_GLUT
# include "parts/core/gl_headers/opengl_org_registery/glext.h"
# endif
# endif

# define QB_FALSE 0
# define QB_TRUE -1

Expand Down
16 changes: 1 addition & 15 deletions internal/c/libqb.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
#include "libqb.h"
#include "common.h"

#ifdef QB64_GUI
# include "parts/core/glew/src/glew.c"
#endif

#ifdef QB64_WINDOWS
# include <fcntl.h>
# include <shellapi.h>
Expand Down Expand Up @@ -1022,7 +1018,6 @@ void hardware_img_requires_depthbuffer(hardware_img_struct *hardware_img) {
// inspiration...
// http://www.opengl.org/wiki/Framebuffer_Object_Examples#Color_texture.2C_Depth_texture
static GLuint depth_tex;
# ifndef QB64_GLES
glGenTextures(1, &depth_tex);
glBindTexture(GL_TEXTURE_2D, depth_tex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
Expand All @@ -1034,12 +1029,7 @@ void hardware_img_requires_depthbuffer(hardware_img_struct *hardware_img) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, hardware_img->w, hardware_img->h, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, depth_tex, 0 /*mipmap level*/);
# else
glGenRenderbuffers(1, &depth_tex);
glBindRenderbuffer(GL_RENDERBUFFER, depth_tex);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, hardware_img->w, hardware_img->h);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depth_tex);
# endif

// NULL means reserve texture memory, but texels are undefined
glClear(GL_DEPTH_BUFFER_BIT);
hardware_img->depthbuffer_handle = depth_tex;
Expand Down Expand Up @@ -34298,13 +34288,9 @@ void set_alpha(int32 new_mode) {
if (new_mode == ALPHA_MODE__BLEND) {
glEnable(GL_BLEND);
if (framebufferobjects_supported) {
# ifndef QB64_GLES
// glBlendFuncSeparateEXT(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,
// GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
glBlendFuncSeparateEXT(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE);
# else
glBlendFuncSeparateOES(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE);
# endif
} else {
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
Expand Down
2 changes: 1 addition & 1 deletion internal/c/libqb/src/glut-main-thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# include <GLUT/glut.h>
#else
# define CORE_FREEGLUT
# include "freeglut.h"
# include <GL/freeglut.h>
#endif

#include "mutex.h"
Expand Down
2 changes: 1 addition & 1 deletion internal/c/libqb/src/glut-message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# include <GLUT/glut.h>
#else
# define CORE_FREEGLUT
# include "freeglut.h"
# include <GL/freeglut.h>
#endif

#include "glut-message.h"
Expand Down
2 changes: 1 addition & 1 deletion internal/c/libqb/src/glut-msg-queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# include <GLUT/glut.h>
#else
# define CORE_FREEGLUT
# include "freeglut.h"
# include <GL/freeglut.h>
#endif

#include "mutex.h"
Expand Down
35 changes: 28 additions & 7 deletions internal/c/parts/core/build.mk
Original file line number Diff line number Diff line change
@@ -1,18 +1,39 @@

FREEGLUT_SRCS := $(wildcard $(PATH_INTERNAL_C)/parts/core/src/*.c)
# GLEW Setup:
# Download the latest release from https://github.com/nigels-com/glew/releases/latest
# Only copy glew.c in src/ to internal/c/parts/core/glew
# Copy the include directory to internal/c/parts/core/glew
# Compile the source using -DGLEW_STATIC
#
# FreeGLUT Setup:
# Although newer version of FreeGLUT (3.x) are available we do not use those (yet).
# This is because the local version has quite a few custom changes that should be moved out first.
# Download the latest 2.x release from https://freeglut.sourceforge.net/
# Copy all .c files from the src directory into internal/c/parts/core/freeglut (after making QB64-PE specific changes)
# Copy the include directory to internal/c/parts/core/freeglut
# Compile the source using -DFREEGLUT_STATIC

FREEGLUT_SRCS := $(wildcard $(PATH_INTERNAL_C)/parts/core/freeglut/*.c)
GLEW_SRCS := $(PATH_INTERNAL_C)/parts/core/glew/glew.c

FREEGLUT_INCLUDE := -I$(PATH_INTERNAL_C)/parts/core/freeglut/include -I$(PATH_INTERNAL_C)/parts/core/glew/include

FREEGLUT_OBJS := $(FREEGLUT_SRCS:.c=.o)
GLEW_OBJS := $(GLEW_SRCS:.c=.o)

FREEGLUT_LIB := $(PATH_INTERNAL_C)/parts/core/freeglut.a

FREEGLUT_LIB := $(PATH_INTERNAL_C)/parts/core/src.a
$(PATH_INTERNAL_C)/parts/core/glew/%.o: $(PATH_INTERNAL_C)/parts/core/glew/%.c
$(CC) -O1 $(CFLAGS) $(FREEGLUT_INCLUDE) -DGLEW_STATIC -Wall $< -c -o $@

$(PATH_INTERNAL_C)/parts/core/src/%.o: $(PATH_INTERNAL_C)/parts/core/src/%.c
$(CC) -O2 -c $< -o $@
$(PATH_INTERNAL_C)/parts/core/freeglut/%.o: $(PATH_INTERNAL_C)/parts/core/freeglut/%.c
$(CC) -O3 $(CFLAGS) $(FREEGLUT_INCLUDE) -DFREEGLUT_STATIC -DHAVE_UNISTD_H -DHAVE_FCNTL_H -Wall $< -c -o $@

$(FREEGLUT_LIB): $(FREEGLUT_OBJS)
$(AR) rcs $@ $(FREEGLUT_OBJS)

QB_CORE_LIB := $(FREEGLUT_LIB)

CXXFLAGS += -I$(PATH_INTERNAL_C)/parts/core/src/ -I$(PATH_INTERNAL_C)/parts/core/glew/include/

CLEAN_LIST += $(FREEGLUT_LIB) $(FREEGLUT_OBJS)
CXXFLAGS += $(FREEGLUT_INCLUDE)

CLEAN_LIST += $(FREEGLUT_LIB) $(FREEGLUT_OBJS) $(GLEW_OBJS)
39 changes: 0 additions & 39 deletions internal/c/parts/core/download/freeglut-2.8.0/AUTHORS

This file was deleted.

27 changes: 0 additions & 27 deletions internal/c/parts/core/download/freeglut-2.8.0/COPYING

This file was deleted.

Loading