]> git.lizzy.rs Git - dragonblocks_alpha.git/commitdiff
Make texture batching optional (for OpenGL 3.3 compat)
authorElias Fleckenstein <eliasfleckenstein@web.de>
Wed, 11 May 2022 15:49:05 +0000 (17:49 +0200)
committerElias Fleckenstein <eliasfleckenstein@web.de>
Wed, 11 May 2022 15:49:05 +0000 (17:49 +0200)
26 files changed:
README.md
assets/shaders/3d/terrain/fragment.glsl
build/debug.sh
src/CMakeLists.txt
src/client/client_config.c
src/client/client_config.h
src/client/client_entity.c
src/client/client_inventory.c
src/client/debug_menu.c
src/client/font.c
src/client/game.c
src/client/gl_debug.c [deleted file]
src/client/gl_debug.h [deleted file]
src/client/gui.c
src/client/interact.c
src/client/light.c
src/client/mesh.c
src/client/model.c
src/client/opengl.c [new file with mode: 0644]
src/client/opengl.h [new file with mode: 0644]
src/client/screenshot.c
src/client/shader.c
src/client/sky.c
src/client/terrain_gfx.c
src/client/texture.c
src/client/window.c

index 5a14615846f3fc364209efa3f40be2cc1d76f25c..4f350609c8552feb73836e197452656580fdc83a 100644 (file)
--- a/README.md
+++ b/README.md
@@ -48,9 +48,11 @@ singleplayer.bat
 ## System Requirements
 Dragonblocks Alpha targets PCs only. Non x86-64 platforms may work, however there is no guarantee whatsoever.
 You need a POSIX system conforming to the ISO C and POSIX 2008 standards. However, so far only GNU/Linux systems, in particular Ubuntu and Debian, have been tested.
-The minimum OpenGL version is 4.2.0. Dragonblocks has been tested on Intel Integrated and NVIDIA GPUs, however other graphics cards should work as well.
+The minimum OpenGL version is 3.3 core. Dragonblocks has been tested on Intel Integrated and NVIDIA GPUs, however other graphics cards should work as well.
 A PC with at least 4 CPU cores is recommended, but not necessarily required.
 
+Note: The game can work with OpenGL 3.3, but to use texture batching, you need at least OpenGL 4.0. If your machine doesn't that version, disable texture batching by adding the line "texture_batching off" to your client.conf file.
+
 ## Current Features
 - Multiplayer, Animated player model, Nametags
 - Mountains, snow, temperature and humidity, dynamic grass color, oceans and beaches, vulcanos, boulders
index 37bc56746cc76a2bf182f9e7a0b5bca60e40f59f..340eb48b68ecdb0f34c44af99497dacc7d4d052c 100755 (executable)
@@ -7,11 +7,22 @@ out vec4 outColor;
 
 uniform vec3 fogColor;
 uniform vec3 cameraPos;
-uniform sampler2D textures[MAX_TEXTURE_UNITS];
+
+#if TEXURE_BATCH_UNITS > 1
+uniform sampler2D textures[8];
+#else
+uniform sampler2D texture0;
+#endif
 
 void main()
 {
-       outColor = texture(textures[int(fragmentTextureIndex + 0.5)], fragmentTextureCoordinates) * vec4(fragmentColor, 1.0);
+#if TEXURE_BATCH_UNITS > 1
+       vec4 texel = texture(textures[int(fragmentTextureIndex + 0.5)], fragmentTextureCoordinates);
+#else
+       vec4 texel = texture(texture0, fragmentTextureCoordinates);
+#endif
+
+       outColor = texel * vec4(fragmentColor, 1.0);
        outColor.rgb = mix(outColor.rgb, fogColor, clamp(length(fragmentPosition - cameraPos) / VIEW_DISTANCE, 0.0, 1.0));
 
        if (outColor.a == 0.0)
index 4323a994ab09eb547ad343e168e5252b73ae8a33..8decc74faacfd19f6260cf1494a3e41385d806c0 100755 (executable)
@@ -22,7 +22,7 @@ end
 "
 
 echo "$COMMON
-break gl_error
+break opengl_error
 run \"[::1]:4000\" < $DEBUG_DIR/name
 " > $DEBUG_DIR/client_script
 
index 48801d91803e50b26bcb49fc47caa0ee957163b1..cc2ded0c53078b9f288f35c7eaeca2ffdb644e1e 100644 (file)
@@ -129,13 +129,13 @@ add_executable(dragonblocks_client
        client/font.c
        client/frustum.c
        client/game.c
-       client/gl_debug.c
        client/gui.c
        client/input.c
        client/interact.c
        client/light.c
        client/mesh.c
        client/model.c
+       client/opengl.c
        client/raycast.c
        client/screenshot.c
        client/shader.c
index a1c34ab0a69d8036f92e93dd36a2ae63884a57c7..a777cea48ccea58de031694a9a08c4a2dfddb493 100644 (file)
@@ -8,6 +8,7 @@ struct ClientConfig client_config = {
        .vsync = true,
        .meshgen_threads = 4,
        .swap_mouse_buttons = true,
+       .texture_batching = true,
 };
 
 static ConfigEntry config_entries[] = {
@@ -41,6 +42,11 @@ static ConfigEntry config_entries[] = {
                .key = "swap_mouse_buttons",
                .value = &client_config.meshgen_threads,
        },
+       {
+               .type = CONFIG_BOOL,
+               .key = "texture_batching",
+               .value = &client_config.texture_batching,
+       },
 };
 
 __attribute__((constructor)) static void client_config_init()
index 05fbbe70bf2c0b56791a346e73ea03c705fe8902..0e4adf78d6ed8c25b428da991cb98c17f7847ca5 100644 (file)
@@ -10,6 +10,7 @@ extern struct ClientConfig {
        bool vsync;
        unsigned int meshgen_threads;
        bool swap_mouse_buttons;
+       bool texture_batching;
 } client_config;
 
 #endif
index 49f8d614eccc6e44a72886496e21dfd21b451337..8b073a8c4c601a3cbae8c254df15156dd63a16b3 100644 (file)
@@ -8,7 +8,7 @@
 #include "client/client_entity.h"
 #include "client/client_player.h"
 #include "client/frustum.h"
-#include "client/gl_debug.h"
+#include "client/opengl.h"
 #include "client/light.h"
 #include "client/shader.h"
 #include "client/window.h"
index c0f780b3bd58d30e7e890b3ed139e98fd7e7f595..d5178b9879c962f1060f84dde620227b027ed1bb 100644 (file)
@@ -4,7 +4,7 @@
 #include "client/client_config.h"
 #include "client/client_inventory.h"
 #include "client/client_item.h"
-#include "client/gl_debug.h"
+#include "client/opengl.h"
 #include "client/frustum.h"
 #include "client/light.h"
 #include "client/shader.h"
index ef1c457d03fd5bf63fcebbddb5f517ff888617a5..f2525653f5162fa5c2fb0ed07c55a9aa0064e8b5 100644 (file)
@@ -11,7 +11,7 @@
 #include "client/client_terrain.h"
 #include "client/debug_menu.h"
 #include "client/game.h"
-#include "client/gl_debug.h"
+#include "client/opengl.h"
 #include "client/gui.h"
 #include "client/interact.h"
 #include "client/window.h"
index 56c6e07f1fa30d0ec724cec47df76cc3a37012cd..e03c828e1f5875cd4b4b4953eb79a7da41656923 100644 (file)
@@ -3,7 +3,7 @@
 #include FT_FREETYPE_H
 #include "client/client.h"
 #include "client/font.h"
-#include "client/gl_debug.h"
+#include "client/opengl.h"
 #include "client/texture.h"
 
 #define NUM_CHARS 128
index 859d9cfd80527558d534a19f11a5af96c9007b46..8366976b494776ea9489f8f48927142034e25ecb 100644 (file)
@@ -15,7 +15,7 @@
 #include "client/font.h"
 #include "client/frustum.h"
 #include "client/game.h"
-#include "client/gl_debug.h"
+#include "client/opengl.h"
 #include "client/gui.h"
 #include "client/input.h"
 #include "client/interact.h"
diff --git a/src/client/gl_debug.c b/src/client/gl_debug.c
deleted file mode 100644 (file)
index 7aa163f..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-#include <GL/glew.h>
-#include <GL/gl.h>
-#include <stdio.h>
-#include "client/gl_debug.h"
-
-// put this into seperate function to make it easy to trace stack using external debugger
-static void gl_error(GLenum err, const char *file, int line)
-{
-       switch (err) {
-               case GL_INVALID_ENUM:                  fprintf(stderr, "[warning] OpenGL error: INVALID_ENUM %s:%d\n", file, line); break;
-               case GL_INVALID_VALUE:                 fprintf(stderr, "[warning] OpenGL error: INVALID_VALUE %s:%d\n", file, line); break;
-               case GL_INVALID_OPERATION:             fprintf(stderr, "[warning] OpenGL error: INVALID_OPERATION %s:%d\n", file, line); break;
-               case GL_STACK_OVERFLOW:                fprintf(stderr, "[warning] OpenGL error: STACK_OVERFLOW %s:%d\n", file, line); break;
-               case GL_STACK_UNDERFLOW:               fprintf(stderr, "[warning] OpenGL error: STACK_UNDERFLOW %s:%d\n", file, line); break;
-               case GL_OUT_OF_MEMORY:                 fprintf(stderr, "[warning] OpenGL error: OUT_OF_MEMORY %s:%d\n", file, line); break;
-               case GL_INVALID_FRAMEBUFFER_OPERATION: fprintf(stderr, "[warning] OpenGL error: INVALID_FRAMEBUFFER_OPERATION %s:%d\n", file, line); break;
-               default: break;
-       }
-}
-void gl_debug(const char *file, int line)
-{
-       GLenum err = glGetError();
-
-       if (err != GL_NO_ERROR)
-               gl_error(err, file, line);
-}
diff --git a/src/client/gl_debug.h b/src/client/gl_debug.h
deleted file mode 100644 (file)
index f65f080..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-#ifndef _GL_DEBUG_H_
-#define _GL_DEBUG_H_
-
-#ifdef ENABLE_GL_DEBUG
-#define GL_DEBUG gl_debug(__FILE__, __LINE__);
-#else
-#define GL_DEBUG
-#endif
-
-void gl_debug(const char *file, int line);
-
-#endif
index 8e5e1f3b14562f26a64947ca245c07968bd60077..1d5f472679de7cc6f45db6b091f30883fc840c90 100644 (file)
@@ -5,7 +5,7 @@
 #include <string.h>
 #include "client/client.h"
 #include "client/cube.h"
-#include "client/gl_debug.h"
+#include "client/opengl.h"
 #include "client/gui.h"
 #include "client/mesh.h"
 #include "client/shader.h"
index 1e2fb6ea69fb5be7908ad0cca92a099375726b9d..c8a74fc4d1bd2db8e9b4dff0c6e7b17b30f6401f 100644 (file)
@@ -8,7 +8,7 @@
 #include "client/cube.h"
 #include "client/debug_menu.h"
 #include "client/frustum.h"
-#include "client/gl_debug.h"
+#include "client/opengl.h"
 #include "client/gui.h"
 #include "client/interact.h"
 #include "client/mesh.h"
index a17c2d05e7aea2ef00d5486a41aa305849034c2a..4d7cb4679752230300a47790d0b29726d0ebb2bc 100644 (file)
@@ -1,6 +1,6 @@
 #include <linmath.h>
 #include "client/camera.h"
-#include "client/gl_debug.h"
+#include "client/opengl.h"
 #include "client/light.h"
 #include "common/day.h"
 
index 75b0b10fc26f2269de91c9c686fec51c3eec419c..59e495bc4def9d6593f6a50d5b6fce1860d5c3a7 100644 (file)
@@ -4,7 +4,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include "client/cube.h"
-#include "client/gl_debug.h"
+#include "client/opengl.h"
 #include "client/mesh.h"
 
 typedef struct {
index 93bc773895b88744e6f3222ae3a2c20f2d9046a7..24a115fa3ec3259b3c9d15208d3f301765161769 100644 (file)
@@ -6,7 +6,7 @@
 #include "client/camera.h"
 #include "client/client_config.h"
 #include "client/frustum.h"
-#include "client/gl_debug.h"
+#include "client/opengl.h"
 #include "client/model.h"
 
 typedef struct {
@@ -189,7 +189,7 @@ void model_init()
        list_ini(&scene_new);
 
        pthread_mutex_init(&lock_scene_new, NULL);
-       glGetIntegerv(GL_MAX_TEXTURE_UNITS, &units); GL_DEBUG
+       units = opengl_texture_batch_units();
 }
 
 // ded
diff --git a/src/client/opengl.c b/src/client/opengl.c
new file mode 100644 (file)
index 0000000..c0c128f
--- /dev/null
@@ -0,0 +1,36 @@
+#include <stdio.h>
+#include "client/client_config.h"
+#include "client/opengl.h"
+
+// put this into seperate function to make it easy to trace stack using external debugger
+static void opengl_error(GLenum err, const char *file, int line)
+{
+       switch (err) {
+               case GL_INVALID_ENUM:                  fprintf(stderr, "[warning] OpenGL error: INVALID_ENUM %s:%d\n", file, line); break;
+               case GL_INVALID_VALUE:                 fprintf(stderr, "[warning] OpenGL error: INVALID_VALUE %s:%d\n", file, line); break;
+               case GL_INVALID_OPERATION:             fprintf(stderr, "[warning] OpenGL error: INVALID_OPERATION %s:%d\n", file, line); break;
+               case GL_STACK_OVERFLOW:                fprintf(stderr, "[warning] OpenGL error: STACK_OVERFLOW %s:%d\n", file, line); break;
+               case GL_STACK_UNDERFLOW:               fprintf(stderr, "[warning] OpenGL error: STACK_UNDERFLOW %s:%d\n", file, line); break;
+               case GL_OUT_OF_MEMORY:                 fprintf(stderr, "[warning] OpenGL error: OUT_OF_MEMORY %s:%d\n", file, line); break;
+               case GL_INVALID_FRAMEBUFFER_OPERATION: fprintf(stderr, "[warning] OpenGL error: INVALID_FRAMEBUFFER_OPERATION %s:%d\n", file, line); break;
+               default: break;
+       }
+}
+void opengl_debug(const char *file, int line)
+{
+       GLenum err = glGetError();
+
+       if (err != GL_NO_ERROR)
+               opengl_error(err, file, line);
+}
+
+GLint opengl_texture_batch_units()
+{
+       if (!client_config.texture_batching)
+               return 1;
+
+       GLint units;
+       glGetIntegerv(GL_MAX_TEXTURE_UNITS, &units); GL_DEBUG
+
+       return units;
+}
diff --git a/src/client/opengl.h b/src/client/opengl.h
new file mode 100644 (file)
index 0000000..d08fadc
--- /dev/null
@@ -0,0 +1,16 @@
+#ifndef _OPENGL_H_
+#define _OPENGL_H_
+
+#ifdef ENABLE_GL_DEBUG
+#define GL_DEBUG opengl_debug(__FILE__, __LINE__);
+#else
+#define GL_DEBUG
+#endif
+
+#include <GL/glew.h>
+#include <GL/gl.h>
+
+void opengl_debug(const char *file, int line);
+GLint opengl_texture_batch_units();
+
+#endif
index 1569d1481ac902ce56dc9c6fc6e26370b9768571..28d5acf27c2f81eef67e836f2883f3468305e389 100644 (file)
@@ -5,7 +5,7 @@
 #include <string.h>
 #include <time.h>
 #include "client/game.h"
-#include "client/gl_debug.h"
+#include "client/opengl.h"
 #include "client/window.h"
 
 char *screenshot()
index eeea589517ef1a7ab6ce12755806d091fe4407ad..a9c1346645c3798a8aeb7832eba55f55728ed1cd 100644 (file)
@@ -2,7 +2,8 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
-#include "client/gl_debug.h"
+#include "client/client_config.h"
+#include "client/opengl.h"
 #include "client/shader.h"
 
 static GLuint compile_shader(GLenum type, const char *path, const char *name, GLuint program, const char *def)
@@ -48,8 +49,9 @@ static GLuint compile_shader(GLenum type, const char *path, const char *name, GL
 
        GLuint id = glCreateShader(type); GL_DEBUG
 
-       // Minimum OpenGL version is 4.2.0 (idk some shader feature from that version is required)
-       const char *version = "#version 420 core\n"; // 420 blaze it
+       const char *version = client_config.texture_batching
+               ? "#version 400 core\n"
+               : "#version 330 core\n";
 
        const char *code_list[3] = {
                version,
index d20b1495ba3b02481dc8deb93056224f5e4278ab..e9ac71905fd4ecd58965b3aa00bff61190d1394b 100644 (file)
@@ -4,7 +4,7 @@
 #include "client/camera.h"
 #include "client/client.h"
 #include "client/cube.h"
-#include "client/gl_debug.h"
+#include "client/opengl.h"
 #include "client/mesh.h"
 #include "client/shader.h"
 #include "client/sky.h"
index d8ce09fcd05e1854831bc2acbe6d063a34721f33..144c4657848356bfe8478e4dc94a21d476ca769d 100644 (file)
@@ -8,7 +8,7 @@
 #include "client/client_terrain.h"
 #include "client/cube.h"
 #include "client/frustum.h"
-#include "client/gl_debug.h"
+#include "client/opengl.h"
 #include "client/light.h"
 #include "client/shader.h"
 #include "client/terrain_gfx.h"
@@ -215,26 +215,29 @@ static Model *create_chunk_model(ChunkRenderData *data)
 
 void terrain_gfx_init()
 {
-       GLint texture_units;
-       glGetIntegerv(GL_MAX_TEXTURE_UNITS, &texture_units); GL_DEBUG
+       GLint texture_batch_units = opengl_texture_batch_units();
 
        char *shader_def;
        asprintf(&shader_def,
-               "#define MAX_TEXTURE_UNITS %d\n"
+               "#define TEXURE_BATCH_UNITS %d\n"
                "#define VIEW_DISTANCE %lf\n",
-               texture_units,
+               texture_batch_units,
                client_config.view_distance
        );
+
        shader_prog = shader_program_create(ASSET_PATH "shaders/3d/terrain", shader_def);
        free(shader_def);
 
        loc_VP = glGetUniformLocation(shader_prog, "VP"); GL_DEBUG
 
-       GLint texture_indices[texture_units];
-       for (GLint i = 0; i < texture_units; i++)
-               texture_indices[i] = i;
+       if (texture_batch_units > 1) {
+               GLint texture_indices[texture_batch_units];
+               for (GLint i = 0; i < texture_batch_units; i++)
+                       texture_indices[i] = i;
 
-       glProgramUniform1iv(shader_prog, glGetUniformLocation(shader_prog, "textures"), texture_units, texture_indices); GL_DEBUG
+               glProgramUniform1iv(shader_prog, glGetUniformLocation(shader_prog, "textures"),
+                       texture_batch_units, texture_indices); GL_DEBUG
+       }
 
        model_shader.prog = shader_prog;
        model_shader.loc_transform = glGetUniformLocation(shader_prog, "model"); GL_DEBUG
index fb489ca6ac5dfaad5e844faca7a3d2699b7f5d28..a531d4201c4315c7efe33b8a0111171e75e5acbf 100644 (file)
@@ -5,7 +5,7 @@
 #include <stdbool.h>
 #include <dragonstd/tree.h>
 #include "client/client_config.h"
-#include "client/gl_debug.h"
+#include "client/opengl.h"
 #include "client/texture.h"
 
 static Tree textures;
index 5f6cca8bedf862ab9ed58ae0b832e043a4a3ee84..01e61ca1c9b0b8db053ad7ecbf6a0a3353cec840 100644 (file)
@@ -5,7 +5,7 @@
 #include "client/client_config.h"
 #include "client/debug_menu.h"
 #include "client/game.h"
-#include "client/gl_debug.h"
+#include "client/opengl.h"
 #include "client/gui.h"
 #include "client/input.h"
 #include "client/window.h"