Make texture batching optional (for OpenGL 3.3 compat)

master
Elias Fleckenstein 2022-05-11 17:49:05 +02:00
parent f3b659aef4
commit 6fb0af2756
No known key found for this signature in database
GPG Key ID: 06927A5199D6C9B2
25 changed files with 89 additions and 50 deletions

View File

@ -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

View File

@ -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)

View File

@ -22,7 +22,7 @@ end
"
echo "$COMMON
break gl_error
break opengl_error
run \"[::1]:4000\" < $DEBUG_DIR/name
" > $DEBUG_DIR/client_script

View 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

View 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()

View File

@ -10,6 +10,7 @@ extern struct ClientConfig {
bool vsync;
unsigned int meshgen_threads;
bool swap_mouse_buttons;
bool texture_batching;
} client_config;
#endif

View 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"

View 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"

View 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"

View 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

View 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"

View File

@ -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

View 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"

View 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"

View 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"

View 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 {

View 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

View File

@ -1,10 +1,9 @@
#include <GL/glew.h>
#include <GL/gl.h>
#include <stdio.h>
#include "client/gl_debug.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 gl_error(GLenum err, const char *file, int line)
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;
@ -17,10 +16,21 @@ static void gl_error(GLenum err, const char *file, int line)
default: break;
}
}
void gl_debug(const char *file, int line)
void opengl_debug(const char *file, int line)
{
GLenum err = glGetError();
if (err != GL_NO_ERROR)
gl_error(err, file, line);
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;
}

16
src/client/opengl.h Normal file
View File

@ -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

View 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()

View 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,

View 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"

View 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

View 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;

View 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"