Extend Gawain to use Blender's built-in shaders

Was already done for immediate mode, but rearranged code to make a clean separation. Cleaned up #includes for code that uses this feature.

Added same for batched rendering.
This commit is contained in:
2016-09-15 18:41:28 +02:00
parent 39f7a81176
commit 5eddb80513
12 changed files with 122 additions and 30 deletions

View File

@@ -57,7 +57,6 @@
#include "GPU_draw.h"
#include "GPU_basic_shader.h"
#include "GPU_shader.h"
#include "GPU_immediate.h"
#include "UI_interface.h"

View File

@@ -58,7 +58,6 @@
#include "interface_intern.h"
#include "GPU_basic_shader.h"
#include "GPU_shader.h"
#include "GPU_immediate.h"
#ifdef WITH_INPUT_IME

View File

@@ -57,7 +57,6 @@
#include "ED_screen_types.h"
#include "ED_space_api.h"
#include "GPU_shader.h"
#include "GPU_immediate.h"
#include "BIF_gl.h"

View File

@@ -100,7 +100,6 @@
#include "GPU_material.h"
#include "GPU_compositing.h"
#include "GPU_extensions.h"
#include "GPU_shader.h"
#include "GPU_immediate.h"
#include "view3d_intern.h" /* own include */

View File

@@ -47,6 +47,7 @@ set(INC_SYS
set(SRC
intern/gpu_basic_shader.c
intern/gpu_batch.c
intern/gpu_buffers.c
intern/gpu_codegen.c
intern/gpu_compositing.c
@@ -54,6 +55,7 @@ set(SRC
intern/gpu_draw.c
intern/gpu_extensions.c
intern/gpu_framebuffer.c
intern/gpu_immediate.c
intern/gpu_init_exit.c
intern/gpu_material.c
intern/gpu_select.c

View File

@@ -31,3 +31,7 @@
#pragma once
#include "gawain/batch.h"
#include "GPU_shader.h"
/* Extend Batch_set_program to use Blenders library of built-in shader programs. */
void Batch_set_builtin_program(Batch*, GPUBuiltinShader);

View File

@@ -31,3 +31,8 @@
#pragma once
#include "gawain/immediate.h"
#include "GPU_shader.h"
/* Extend immBindProgram to use Blenders library of built-in shader programs.
* Use immUnbindProgram() when done. */
void immBindBuiltinProgram(GPUBuiltinShader);

View File

@@ -106,10 +106,6 @@ GPUShader *GPU_shader_get_builtin_fx_shader(int effects, bool persp);
void GPU_shader_free_builtin_shaders(void);
/* Extend Gawains immBindProgram to use Blenders library of built-in shader programs.
* Use immUnbindProgram() when done. */
void immBindBuiltinProgram(GPUBuiltinShader);
/* Vertex attributes for shaders */
#define GPU_MAX_ATTRIB 32

View File

@@ -0,0 +1,35 @@
/*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2016 Blender Foundation.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): Mike Erwin
*
* ***** END GPL LICENSE BLOCK *****
*/
#include "GPU_batch.h"
#include "gpu_shader_private.h"
void Batch_set_builtin_program(Batch* batch, GPUBuiltinShader shader_id)
{
GPUShader *shader = GPU_shader_get_builtin_shader(shader_id);
Batch_set_program(batch, shader->program);
}

View File

@@ -0,0 +1,35 @@
/*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2016 Blender Foundation.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): Mike Erwin
*
* ***** END GPL LICENSE BLOCK *****
*/
#include "GPU_immediate.h"
#include "gpu_shader_private.h"
void immBindBuiltinProgram(GPUBuiltinShader shader_id)
{
GPUShader *shader = GPU_shader_get_builtin_shader(shader_id);
immBindProgram(shader->program);
}

View File

@@ -36,10 +36,9 @@
#include "GPU_compositing.h"
#include "GPU_debug.h"
#include "GPU_extensions.h"
#include "GPU_glew.h"
#include "GPU_shader.h"
#include "GPU_shader_private.h"
#include "GPU_texture.h"
#include "GPU_immediate.h"
/* TODO(sergey): Find better default values for this constants. */
#define MAX_DEFINE_LENGTH 1024
@@ -95,20 +94,6 @@ static struct GPUShadersGlobal {
} shaders;
} GG = {{NULL}};
/* GPUShader */
struct GPUShader {
GLuint program; /* handle for full program (links shader stages below) */
GLuint vertex; /* handle for vertex shader */
GLuint geometry; /* handle for geometry shader */
GLuint fragment; /* handle for fragment shader */
int totattrib; /* total number of attributes */
int uniforms; /* required uniforms */
void *uniform_interface; /* cached uniform interface for shader. Data depends on shader */
};
static void shader_print_errors(const char *task, const char *log, const char **code, int totcode)
{
@@ -828,9 +813,3 @@ void GPU_shader_free_builtin_shaders(void)
}
}
}
void immBindBuiltinProgram(GPUBuiltinShader shader_id)
{
GPUShader *shader = GPU_shader_get_builtin_shader(shader_id);
immBindProgram(shader->program);
}

View File

@@ -0,0 +1,40 @@
/*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* ***** END GPL LICENSE BLOCK *****
*/
/** \file gpu_shader_private.h
* \ingroup gpu
*/
#pragma once
#include "GPU_glew.h"
struct GPUShader {
GLuint program; /* handle for full program (links shader stages below) */
GLuint vertex; /* handle for vertex shader */
GLuint geometry; /* handle for geometry shader */
GLuint fragment; /* handle for fragment shader */
int totattrib; /* total number of attributes */
int uniforms; /* required uniforms */
void *uniform_interface; /* cached uniform interface for shader. Data depends on shader */
};