2011-02-23 10:52:22 +00:00
|
|
|
/*
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
* ***** 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
|
2011-11-29 10:54:47 +00:00
|
|
|
* of the License, or (at your option) any later version.
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
*
|
|
|
|
* 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,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2005 Blender Foundation.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* The Original Code is: all of this file.
|
|
|
|
*
|
|
|
|
* Contributor(s): Brecht Van Lommel.
|
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*/
|
|
|
|
|
2011-02-27 20:25:53 +00:00
|
|
|
/** \file blender/gpu/intern/gpu_extensions.c
|
|
|
|
* \ingroup gpu
|
2014-01-19 23:14:24 +11:00
|
|
|
*
|
|
|
|
* Wrap OpenGL features such as textures, shaders and GLSL
|
|
|
|
* with checks for drivers and GPU support.
|
2011-02-27 20:25:53 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
#include "DNA_image_types.h"
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
#include "BLI_blenlib.h"
|
2011-01-07 18:36:47 +00:00
|
|
|
#include "BLI_utildefines.h"
|
2011-12-16 09:25:07 +00:00
|
|
|
#include "BLI_math_base.h"
|
2015-03-30 14:14:32 +02:00
|
|
|
#include "BLI_math_vector.h"
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
|
2013-01-24 21:57:13 +00:00
|
|
|
#include "BKE_global.h"
|
|
|
|
|
2015-02-16 21:19:12 +01:00
|
|
|
#include "GPU_glew.h"
|
|
|
|
#include "GPU_debug.h"
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
#include "GPU_draw.h"
|
|
|
|
#include "GPU_extensions.h"
|
2015-02-12 18:54:41 +01:00
|
|
|
#include "GPU_compositing.h"
|
2013-03-10 15:38:23 +00:00
|
|
|
#include "GPU_simple_shader.h"
|
2014-10-07 15:46:19 -05:00
|
|
|
|
2015-02-16 21:19:12 +01:00
|
|
|
#include "intern/gpu_private.h"
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2012-04-15 07:54:07 +00:00
|
|
|
#ifdef WIN32
|
|
|
|
# include "BLI_winstuff.h"
|
|
|
|
#endif
|
2011-03-07 00:49:21 +00:00
|
|
|
|
2015-07-20 16:08:06 +02:00
|
|
|
/* TODO(sergey): Find better default values for this constants. */
|
|
|
|
#define MAX_DEFINE_LENGTH 1024
|
|
|
|
#define MAX_EXT_DEFINE_LENGTH 1024
|
2014-07-11 19:17:29 +03:00
|
|
|
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
/* Extensions support */
|
|
|
|
|
|
|
|
/* extensions used:
|
2012-03-09 18:28:30 +00:00
|
|
|
* - texture border clamp: 1.3 core
|
2012-04-21 14:14:58 +00:00
|
|
|
* - fragment shader: 2.0 core
|
2012-03-09 18:28:30 +00:00
|
|
|
* - framebuffer object: ext specification
|
|
|
|
* - multitexture 1.3 core
|
|
|
|
* - arb non power of two: 2.0 core
|
|
|
|
* - pixel buffer objects? 2.1 core
|
|
|
|
* - arb draw buffers? 2.0 core
|
|
|
|
*/
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
|
2012-05-01 02:50:17 +00:00
|
|
|
/* Non-generated shaders */
|
2015-04-09 20:20:33 +02:00
|
|
|
extern char datatoc_gpu_program_smoke_frag_glsl[];
|
|
|
|
extern char datatoc_gpu_program_smoke_color_frag_glsl[];
|
2012-05-01 02:50:17 +00:00
|
|
|
extern char datatoc_gpu_shader_vsm_store_vert_glsl[];
|
|
|
|
extern char datatoc_gpu_shader_vsm_store_frag_glsl[];
|
|
|
|
extern char datatoc_gpu_shader_sep_gaussian_blur_vert_glsl[];
|
|
|
|
extern char datatoc_gpu_shader_sep_gaussian_blur_frag_glsl[];
|
2015-02-12 18:54:41 +01:00
|
|
|
extern char datatoc_gpu_shader_fx_vert_glsl[];
|
|
|
|
extern char datatoc_gpu_shader_fx_ssao_frag_glsl[];
|
|
|
|
extern char datatoc_gpu_shader_fx_dof_frag_glsl[];
|
|
|
|
extern char datatoc_gpu_shader_fx_dof_vert_glsl[];
|
2015-03-03 17:47:31 +01:00
|
|
|
extern char datatoc_gpu_shader_fx_dof_hq_frag_glsl[];
|
|
|
|
extern char datatoc_gpu_shader_fx_dof_hq_vert_glsl[];
|
|
|
|
extern char datatoc_gpu_shader_fx_dof_hq_geo_glsl[];
|
2015-02-17 18:08:28 +01:00
|
|
|
extern char datatoc_gpu_shader_fx_depth_resolve_glsl[];
|
2015-02-12 18:54:41 +01:00
|
|
|
extern char datatoc_gpu_shader_fx_lib_glsl[];
|
2012-05-01 02:50:17 +00:00
|
|
|
|
|
|
|
typedef struct GPUShaders {
|
|
|
|
GPUShader *vsm_store;
|
|
|
|
GPUShader *sep_gaussian_blur;
|
2015-04-09 20:20:33 +02:00
|
|
|
GPUProgram *smoke;
|
|
|
|
GPUProgram *smoke_colored;
|
2015-02-12 18:54:41 +01:00
|
|
|
/* cache for shader fx. Those can exist in combinations so store them here */
|
|
|
|
GPUShader *fx_shaders[MAX_FX_SHADERS * 2];
|
2012-05-01 02:50:17 +00:00
|
|
|
} GPUShaders;
|
|
|
|
|
2008-10-12 18:32:26 +00:00
|
|
|
static struct GPUGlobal {
|
2013-04-12 17:56:07 +00:00
|
|
|
GLint maxtexsize;
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
GLint maxtextures;
|
|
|
|
GLuint currentfb;
|
2009-10-19 10:10:05 +00:00
|
|
|
int glslsupport;
|
2008-10-12 18:32:26 +00:00
|
|
|
int extdisabled;
|
2010-07-04 12:24:19 +00:00
|
|
|
int colordepth;
|
2010-11-27 19:59:00 +00:00
|
|
|
int npotdisabled; /* ATI 3xx-5xx (and more) chipsets support NPoT partially (== not enough) */
|
2013-09-11 23:24:45 +00:00
|
|
|
int dlistsdisabled; /* Legacy ATI driver does not support display lists well */
|
2010-01-31 23:45:51 +00:00
|
|
|
GPUDeviceType device;
|
|
|
|
GPUOSType os;
|
|
|
|
GPUDriverType driver;
|
2012-05-01 02:50:17 +00:00
|
|
|
GPUShaders shaders;
|
2014-06-10 01:36:53 +03:00
|
|
|
GPUTexture *invalid_tex_1D; /* texture used in place of invalid textures (not loaded correctly, missing) */
|
|
|
|
GPUTexture *invalid_tex_2D;
|
|
|
|
GPUTexture *invalid_tex_3D;
|
2015-03-30 14:14:32 +02:00
|
|
|
float dfdyfactors[2]; /* workaround for different calculation of dfdy factors on GPUs. Some GPUs/drivers
|
|
|
|
calculate dfdy in shader differently when drawing to an offscreen buffer. First
|
|
|
|
number is factor on screen and second is off-screen */
|
2012-05-01 02:50:17 +00:00
|
|
|
} GG = {1, 0};
|
2008-10-12 18:32:26 +00:00
|
|
|
|
2014-11-18 12:12:28 +01:00
|
|
|
/* Number of maximum output slots. We support 4 outputs for now (usually we wouldn't need more to preserve fill rate) */
|
|
|
|
#define GPU_FB_MAX_SLOTS 4
|
|
|
|
|
|
|
|
struct GPUFrameBuffer {
|
|
|
|
GLuint object;
|
|
|
|
GPUTexture *colortex[GPU_FB_MAX_SLOTS];
|
|
|
|
GPUTexture *depthtex;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-01-31 23:45:51 +00:00
|
|
|
/* GPU Types */
|
|
|
|
|
2015-03-16 22:57:56 -04:00
|
|
|
bool GPU_type_matches(GPUDeviceType device, GPUOSType os, GPUDriverType driver)
|
2010-01-31 23:45:51 +00:00
|
|
|
{
|
|
|
|
return (GG.device & device) && (GG.os & os) && (GG.driver & driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* GPU Extensions */
|
|
|
|
|
2011-02-13 15:02:21 +00:00
|
|
|
void GPU_extensions_disable(void)
|
2008-10-12 18:32:26 +00:00
|
|
|
{
|
|
|
|
GG.extdisabled = 1;
|
|
|
|
}
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
|
2013-04-13 00:43:49 +00:00
|
|
|
int GPU_max_texture_size(void)
|
2013-04-12 17:56:07 +00:00
|
|
|
{
|
|
|
|
return GG.maxtexsize;
|
|
|
|
}
|
|
|
|
|
2015-03-30 14:14:32 +02:00
|
|
|
void GPU_get_dfdy_factors(float fac[2])
|
|
|
|
{
|
|
|
|
copy_v2_v2(fac, GG.dfdyfactors);
|
|
|
|
}
|
|
|
|
|
2014-10-07 15:46:19 -05:00
|
|
|
void gpu_extensions_init(void)
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
{
|
2010-07-04 12:24:19 +00:00
|
|
|
GLint r, g, b;
|
2015-03-30 14:14:32 +02:00
|
|
|
const char *vendor, *renderer, *version;
|
2010-01-31 23:45:51 +00:00
|
|
|
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
/* glewIsSupported("GL_VERSION_2_0") */
|
|
|
|
|
|
|
|
if (GLEW_ARB_multitexture)
|
|
|
|
glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS_ARB, &GG.maxtextures);
|
|
|
|
|
2013-04-12 17:56:07 +00:00
|
|
|
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &GG.maxtexsize);
|
|
|
|
|
2009-10-19 10:10:05 +00:00
|
|
|
GG.glslsupport = 1;
|
|
|
|
if (!GLEW_ARB_multitexture) GG.glslsupport = 0;
|
|
|
|
if (!GLEW_ARB_vertex_shader) GG.glslsupport = 0;
|
|
|
|
if (!GLEW_ARB_fragment_shader) GG.glslsupport = 0;
|
2010-01-31 23:45:51 +00:00
|
|
|
|
2010-07-04 12:24:19 +00:00
|
|
|
glGetIntegerv(GL_RED_BITS, &r);
|
|
|
|
glGetIntegerv(GL_GREEN_BITS, &g);
|
|
|
|
glGetIntegerv(GL_BLUE_BITS, &b);
|
2015-03-23 15:29:42 -04:00
|
|
|
GG.colordepth = r + g + b; /* assumes same depth for RGB */
|
2011-04-21 13:11:51 +00:00
|
|
|
|
2012-12-28 14:19:05 +00:00
|
|
|
vendor = (const char *)glGetString(GL_VENDOR);
|
|
|
|
renderer = (const char *)glGetString(GL_RENDERER);
|
2015-03-30 14:14:32 +02:00
|
|
|
version = (const char *)glGetString(GL_VERSION);
|
2010-01-31 23:45:51 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (strstr(vendor, "ATI")) {
|
2010-01-31 23:45:51 +00:00
|
|
|
GG.device = GPU_DEVICE_ATI;
|
|
|
|
GG.driver = GPU_DRIVER_OFFICIAL;
|
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
else if (strstr(vendor, "NVIDIA")) {
|
2010-01-31 23:45:51 +00:00
|
|
|
GG.device = GPU_DEVICE_NVIDIA;
|
|
|
|
GG.driver = GPU_DRIVER_OFFICIAL;
|
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
else if (strstr(vendor, "Intel") ||
|
2010-04-14 21:12:05 +00:00
|
|
|
/* src/mesa/drivers/dri/intel/intel_context.c */
|
|
|
|
strstr(renderer, "Mesa DRI Intel") ||
|
2011-04-21 13:11:51 +00:00
|
|
|
strstr(renderer, "Mesa DRI Mobile Intel")) {
|
2010-01-31 23:45:51 +00:00
|
|
|
GG.device = GPU_DEVICE_INTEL;
|
|
|
|
GG.driver = GPU_DRIVER_OFFICIAL;
|
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
else if (strstr(renderer, "Mesa DRI R") || (strstr(renderer, "Gallium ") && strstr(renderer, " on ATI "))) {
|
2010-01-31 23:45:51 +00:00
|
|
|
GG.device = GPU_DEVICE_ATI;
|
|
|
|
GG.driver = GPU_DRIVER_OPENSOURCE;
|
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
else if (strstr(renderer, "Nouveau") || strstr(vendor, "nouveau")) {
|
2010-01-31 23:45:51 +00:00
|
|
|
GG.device = GPU_DEVICE_NVIDIA;
|
|
|
|
GG.driver = GPU_DRIVER_OPENSOURCE;
|
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
else if (strstr(vendor, "Mesa")) {
|
2010-01-31 23:45:51 +00:00
|
|
|
GG.device = GPU_DEVICE_SOFTWARE;
|
|
|
|
GG.driver = GPU_DRIVER_SOFTWARE;
|
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
else if (strstr(vendor, "Microsoft")) {
|
2010-01-31 23:45:51 +00:00
|
|
|
GG.device = GPU_DEVICE_SOFTWARE;
|
|
|
|
GG.driver = GPU_DRIVER_SOFTWARE;
|
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
else if (strstr(renderer, "Apple Software Renderer")) {
|
2010-01-31 23:45:51 +00:00
|
|
|
GG.device = GPU_DEVICE_SOFTWARE;
|
|
|
|
GG.driver = GPU_DRIVER_SOFTWARE;
|
|
|
|
}
|
|
|
|
else {
|
2010-07-16 10:13:04 +00:00
|
|
|
GG.device = GPU_DEVICE_ANY;
|
|
|
|
GG.driver = GPU_DRIVER_ANY;
|
2010-01-31 23:45:51 +00:00
|
|
|
}
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (GG.device == GPU_DEVICE_ATI) {
|
2012-02-04 19:57:09 +00:00
|
|
|
/* ATI 9500 to X2300 cards support NPoT textures poorly
|
|
|
|
* Incomplete list http://dri.freedesktop.org/wiki/ATIRadeon
|
|
|
|
* New IDs from MESA's src/gallium/drivers/r300/r300_screen.c
|
|
|
|
*/
|
2013-09-11 23:24:45 +00:00
|
|
|
/* This list is close enough to those using the legacy driver which
|
|
|
|
* has a bug with display lists and glVertexAttrib
|
|
|
|
*/
|
2012-03-24 06:38:07 +00:00
|
|
|
if (strstr(renderer, "R3") || strstr(renderer, "RV3") ||
|
2012-04-28 06:31:57 +00:00
|
|
|
strstr(renderer, "R4") || strstr(renderer, "RV4") ||
|
|
|
|
strstr(renderer, "RS4") || strstr(renderer, "RC4") ||
|
|
|
|
strstr(renderer, "R5") || strstr(renderer, "RV5") ||
|
|
|
|
strstr(renderer, "RS600") || strstr(renderer, "RS690") ||
|
|
|
|
strstr(renderer, "RS740") || strstr(renderer, "X1") ||
|
|
|
|
strstr(renderer, "X2") || strstr(renderer, "Radeon 9") ||
|
|
|
|
strstr(renderer, "RADEON 9"))
|
|
|
|
{
|
2012-02-04 19:57:09 +00:00
|
|
|
GG.npotdisabled = 1;
|
2013-09-11 23:24:45 +00:00
|
|
|
GG.dlistsdisabled = 1;
|
2012-04-28 06:31:57 +00:00
|
|
|
}
|
2012-02-04 19:57:09 +00:00
|
|
|
}
|
|
|
|
|
2012-03-02 16:05:54 +00:00
|
|
|
/* make sure double side isn't used by default and only getting enabled in places where it's
|
2012-02-25 18:09:39 +00:00
|
|
|
* really needed to prevent different unexpected behaviors like with intel gme965 card (sergey) */
|
2012-02-25 21:27:45 +00:00
|
|
|
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);
|
2012-02-25 18:09:39 +00:00
|
|
|
|
2010-01-31 23:45:51 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
GG.os = GPU_OS_WIN;
|
2012-03-08 04:38:35 +00:00
|
|
|
#elif defined(__APPLE__)
|
2010-01-31 23:45:51 +00:00
|
|
|
GG.os = GPU_OS_MAC;
|
2012-03-08 04:38:35 +00:00
|
|
|
#else
|
|
|
|
GG.os = GPU_OS_UNIX;
|
2010-01-31 23:45:51 +00:00
|
|
|
#endif
|
2013-02-26 00:49:42 +00:00
|
|
|
|
2014-06-10 01:36:53 +03:00
|
|
|
|
2015-03-30 14:14:32 +02:00
|
|
|
/* df/dy calculation factors, those are dependent on driver */
|
|
|
|
if ((strstr(vendor, "ATI") && strstr(version, "3.3.10750"))) {
|
|
|
|
GG.dfdyfactors[0] = 1.0;
|
|
|
|
GG.dfdyfactors[1] = -1.0;
|
|
|
|
}
|
2015-05-18 22:05:38 +02:00
|
|
|
else if (GG.device == GPU_DEVICE_INTEL && GG.os == GPU_OS_WIN &&
|
2015-05-21 18:37:48 +02:00
|
|
|
(strstr(version, "4.0.0 - Build 10.18.10.3308") ||
|
|
|
|
strstr(version, "4.0.0 - Build 9.18.10.3186") ||
|
2015-05-19 16:25:42 +02:00
|
|
|
strstr(version, "4.0.0 - Build 9.18.10.3165") ||
|
2015-05-18 22:05:38 +02:00
|
|
|
strstr(version, "3.1.0 - Build 9.17.10.3347") ||
|
|
|
|
strstr(version, "3.1.0 - Build 9.17.10.4101")))
|
|
|
|
{
|
|
|
|
GG.dfdyfactors[0] = -1.0;
|
|
|
|
GG.dfdyfactors[1] = 1.0;
|
2015-03-30 14:14:32 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
GG.dfdyfactors[0] = 1.0;
|
|
|
|
GG.dfdyfactors[1] = 1.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-06-10 01:36:53 +03:00
|
|
|
GPU_invalid_tex_init();
|
2013-03-10 15:38:23 +00:00
|
|
|
GPU_simple_shaders_init();
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
}
|
|
|
|
|
2014-10-07 15:46:19 -05:00
|
|
|
void gpu_extensions_exit(void)
|
2011-12-23 07:10:01 +00:00
|
|
|
{
|
2013-03-10 15:38:23 +00:00
|
|
|
GPU_simple_shaders_exit();
|
2014-06-10 01:36:53 +03:00
|
|
|
GPU_invalid_tex_free();
|
2011-12-23 07:10:01 +00:00
|
|
|
}
|
|
|
|
|
2015-03-16 22:57:56 -04:00
|
|
|
bool GPU_glsl_support(void)
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
{
|
2009-10-19 10:10:05 +00:00
|
|
|
return !GG.extdisabled && GG.glslsupport;
|
|
|
|
}
|
|
|
|
|
2015-03-16 22:57:56 -04:00
|
|
|
bool GPU_non_power_of_two_support(void)
|
2009-10-19 10:10:05 +00:00
|
|
|
{
|
2012-03-24 06:38:07 +00:00
|
|
|
if (GG.npotdisabled)
|
2015-03-16 22:57:56 -04:00
|
|
|
return false;
|
2010-11-25 22:15:04 +00:00
|
|
|
|
2009-10-19 10:10:05 +00:00
|
|
|
return GLEW_ARB_texture_non_power_of_two;
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
}
|
|
|
|
|
2015-03-16 22:57:56 -04:00
|
|
|
bool GPU_vertex_buffer_support(void)
|
2015-03-03 11:34:23 +01:00
|
|
|
{
|
|
|
|
return GLEW_ARB_vertex_buffer_object || GLEW_VERSION_1_5;
|
|
|
|
}
|
|
|
|
|
2015-03-16 22:57:56 -04:00
|
|
|
bool GPU_display_list_support(void)
|
2013-09-11 23:24:45 +00:00
|
|
|
{
|
|
|
|
return !GG.dlistsdisabled;
|
|
|
|
}
|
|
|
|
|
2015-03-16 22:57:56 -04:00
|
|
|
bool GPU_bicubic_bump_support(void)
|
|
|
|
{
|
|
|
|
return GLEW_ARB_texture_query_lod && GLEW_VERSION_3_0;
|
|
|
|
}
|
|
|
|
|
2015-03-03 17:47:31 +01:00
|
|
|
bool GPU_geometry_shader_support(void)
|
|
|
|
{
|
|
|
|
return GLEW_EXT_geometry_shader4 || GLEW_VERSION_3_2;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GPU_instanced_drawing_support(void)
|
|
|
|
{
|
2015-03-20 15:26:13 +01:00
|
|
|
return GLEW_ARB_draw_instanced;
|
2015-03-03 17:47:31 +01:00
|
|
|
}
|
|
|
|
|
2011-02-13 15:02:21 +00:00
|
|
|
int GPU_color_depth(void)
|
2010-04-05 10:25:40 +00:00
|
|
|
{
|
2011-04-21 13:11:51 +00:00
|
|
|
return GG.colordepth;
|
2010-04-05 10:25:40 +00:00
|
|
|
}
|
|
|
|
|
2011-03-06 23:12:12 +00:00
|
|
|
static void GPU_print_framebuffer_error(GLenum status, char err_out[256])
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
{
|
2015-03-23 15:29:42 -04:00
|
|
|
const char *err = "unknown";
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
|
2012-04-28 06:31:57 +00:00
|
|
|
switch (status) {
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
case GL_FRAMEBUFFER_COMPLETE_EXT:
|
|
|
|
break;
|
2012-12-03 08:31:16 +00:00
|
|
|
case GL_INVALID_OPERATION:
|
2015-03-23 15:29:42 -04:00
|
|
|
err = "Invalid operation";
|
2012-12-03 08:31:16 +00:00
|
|
|
break;
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT:
|
2015-03-23 15:29:42 -04:00
|
|
|
err = "Incomplete attachment";
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
break;
|
|
|
|
case GL_FRAMEBUFFER_UNSUPPORTED_EXT:
|
2015-03-23 15:29:42 -04:00
|
|
|
err = "Unsupported framebuffer format";
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
break;
|
|
|
|
case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT:
|
2015-03-23 15:29:42 -04:00
|
|
|
err = "Missing attachment";
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
break;
|
|
|
|
case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT:
|
2015-03-23 15:29:42 -04:00
|
|
|
err = "Attached images must have same dimensions";
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
break;
|
|
|
|
case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT:
|
2015-03-23 15:29:42 -04:00
|
|
|
err = "Attached images must have same format";
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
break;
|
|
|
|
case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT:
|
2015-03-23 15:29:42 -04:00
|
|
|
err = "Missing draw buffer";
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
break;
|
|
|
|
case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT:
|
2015-03-23 15:29:42 -04:00
|
|
|
err = "Missing read buffer";
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
break;
|
|
|
|
}
|
2011-03-06 23:12:12 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (err_out) {
|
2011-03-07 03:57:04 +00:00
|
|
|
BLI_snprintf(err_out, 256, "GPUFrameBuffer: framebuffer incomplete error %d '%s'",
|
|
|
|
(int)status, err);
|
2011-03-06 23:12:12 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
fprintf(stderr, "GPUFrameBuffer: framebuffer incomplete error %d '%s'\n",
|
2011-03-07 03:57:04 +00:00
|
|
|
(int)status, err);
|
2011-03-06 23:12:12 +00:00
|
|
|
}
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* GPUTexture */
|
|
|
|
|
|
|
|
struct GPUTexture {
|
2015-03-23 15:29:42 -04:00
|
|
|
int w, h; /* width/height */
|
2015-09-14 13:18:43 +10:00
|
|
|
int w_orig, h_orig; /* width/height (before power of 2 is applied) */
|
2015-03-23 15:29:42 -04:00
|
|
|
int number; /* number for multitexture binding */
|
|
|
|
int refcount; /* reference count */
|
|
|
|
GLenum target; /* GL_TEXTURE_* */
|
|
|
|
GLuint bindcode; /* opengl identifier for texture */
|
|
|
|
int fromblender; /* we got the texture from Blender */
|
|
|
|
|
|
|
|
GPUFrameBuffer *fb; /* GPUFramebuffer this texture is attached to */
|
|
|
|
int fb_attachment; /* slot the texture is attached to */
|
|
|
|
int depth; /* is a depth texture? if 3D how deep? */
|
2015-09-14 13:18:43 +10:00
|
|
|
int depth_orig; /* depth (before power of 2 is applied) */
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
};
|
|
|
|
|
2015-03-16 22:57:56 -04:00
|
|
|
static unsigned char *GPU_texture_convert_pixels(int length, const float *fpixels)
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
{
|
|
|
|
unsigned char *pixels, *p;
|
2015-03-16 22:57:56 -04:00
|
|
|
const float *fp = fpixels;
|
2015-03-23 15:29:42 -04:00
|
|
|
const int len = 4 * length;
|
2015-03-16 22:57:56 -04:00
|
|
|
int a;
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
|
2015-03-23 15:29:42 -04:00
|
|
|
p = pixels = MEM_callocN(sizeof(unsigned char) * len, "GPUTexturePixels");
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
|
2015-03-23 15:29:42 -04:00
|
|
|
for (a = 0; a < len; a++, p++, fp++)
|
|
|
|
*p = FTOCHAR((*fp));
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
|
|
|
|
return pixels;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void GPU_glTexSubImageEmpty(GLenum target, GLenum format, int x, int y, int w, int h)
|
|
|
|
{
|
2015-03-23 15:29:42 -04:00
|
|
|
void *pixels = MEM_callocN(sizeof(char) * 4 * w * h, "GPUTextureEmptyPixels");
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
|
|
|
|
if (target == GL_TEXTURE_1D)
|
|
|
|
glTexSubImage1D(target, 0, x, w, format, GL_UNSIGNED_BYTE, pixels);
|
|
|
|
else
|
|
|
|
glTexSubImage2D(target, 0, x, y, w, h, format, GL_UNSIGNED_BYTE, pixels);
|
|
|
|
|
|
|
|
MEM_freeN(pixels);
|
|
|
|
}
|
|
|
|
|
2015-02-12 18:54:41 +01:00
|
|
|
static GPUTexture *GPU_texture_create_nD(
|
2015-03-16 22:57:56 -04:00
|
|
|
int w, int h, int n, const float *fpixels, int depth, GPUHDRType hdr_type, int components,
|
2015-02-12 18:54:41 +01:00
|
|
|
char err_out[256])
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
{
|
|
|
|
GPUTexture *tex;
|
|
|
|
GLenum type, format, internalformat;
|
|
|
|
void *pixels = NULL;
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (depth && !GLEW_ARB_depth_texture)
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
tex = MEM_callocN(sizeof(GPUTexture), "GPUTexture");
|
2015-09-14 13:18:43 +10:00
|
|
|
tex->w = tex->w_orig = w;
|
|
|
|
tex->h = tex->h_orig = h;
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
tex->number = -1;
|
|
|
|
tex->refcount = 1;
|
|
|
|
tex->target = (n == 1)? GL_TEXTURE_1D: GL_TEXTURE_2D;
|
2015-09-14 13:18:43 +10:00
|
|
|
tex->depth = tex->depth_orig = depth;
|
2014-11-18 11:56:23 +01:00
|
|
|
tex->fb_attachment = -1;
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
|
|
|
|
glGenTextures(1, &tex->bindcode);
|
|
|
|
|
|
|
|
if (!tex->bindcode) {
|
2012-03-24 06:38:07 +00:00
|
|
|
if (err_out) {
|
2011-03-07 03:57:04 +00:00
|
|
|
BLI_snprintf(err_out, 256, "GPUTexture: texture create failed: %d",
|
2011-03-06 23:12:12 +00:00
|
|
|
(int)glGetError());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fprintf(stderr, "GPUTexture: texture create failed: %d\n",
|
|
|
|
(int)glGetError());
|
|
|
|
}
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
GPU_texture_free(tex);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-10-19 10:10:05 +00:00
|
|
|
if (!GPU_non_power_of_two_support()) {
|
2011-12-16 09:25:07 +00:00
|
|
|
tex->w = power_of_2_max_i(tex->w);
|
|
|
|
tex->h = power_of_2_max_i(tex->h);
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
tex->number = 0;
|
|
|
|
glBindTexture(tex->target, tex->bindcode);
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (depth) {
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
type = GL_UNSIGNED_BYTE;
|
|
|
|
format = GL_DEPTH_COMPONENT;
|
|
|
|
internalformat = GL_DEPTH_COMPONENT;
|
|
|
|
}
|
|
|
|
else {
|
2015-02-12 18:54:41 +01:00
|
|
|
type = GL_FLOAT;
|
|
|
|
|
|
|
|
if (components == 4) {
|
|
|
|
format = GL_RGBA;
|
|
|
|
switch (hdr_type) {
|
|
|
|
case GPU_HDR_NONE:
|
|
|
|
internalformat = GL_RGBA8;
|
|
|
|
break;
|
|
|
|
case GPU_HDR_HALF_FLOAT:
|
|
|
|
internalformat = GL_RGBA16F;
|
|
|
|
break;
|
|
|
|
case GPU_HDR_FULL_FLOAT:
|
|
|
|
internalformat = GL_RGBA32F;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (components == 2) {
|
|
|
|
format = GL_RG;
|
|
|
|
switch (hdr_type) {
|
|
|
|
case GPU_HDR_NONE:
|
|
|
|
internalformat = GL_RG8;
|
|
|
|
break;
|
|
|
|
case GPU_HDR_HALF_FLOAT:
|
|
|
|
internalformat = GL_RG16F;
|
|
|
|
break;
|
|
|
|
case GPU_HDR_FULL_FLOAT:
|
|
|
|
internalformat = GL_RG32F;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
|
2015-02-12 18:54:41 +01:00
|
|
|
if (fpixels && hdr_type == GPU_HDR_NONE) {
|
|
|
|
type = GL_UNSIGNED_BYTE;
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
pixels = GPU_texture_convert_pixels(w*h, fpixels);
|
2015-02-12 18:54:41 +01:00
|
|
|
}
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (tex->target == GL_TEXTURE_1D) {
|
2011-03-05 10:29:10 +00:00
|
|
|
glTexImage1D(tex->target, 0, internalformat, tex->w, 0, format, type, NULL);
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
|
|
|
|
if (fpixels) {
|
|
|
|
glTexSubImage1D(tex->target, 0, 0, w, format, type,
|
2013-03-31 03:28:46 +00:00
|
|
|
pixels ? pixels : fpixels);
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
|
|
|
|
if (tex->w > w)
|
|
|
|
GPU_glTexSubImageEmpty(tex->target, format, w, 0,
|
|
|
|
tex->w-w, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
glTexImage2D(tex->target, 0, internalformat, tex->w, tex->h, 0,
|
2013-03-27 20:27:07 +00:00
|
|
|
format, type, NULL);
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
|
|
|
|
if (fpixels) {
|
|
|
|
glTexSubImage2D(tex->target, 0, 0, 0, w, h,
|
2013-03-31 03:28:46 +00:00
|
|
|
format, type, pixels ? pixels : fpixels);
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
|
|
|
|
if (tex->w > w)
|
|
|
|
GPU_glTexSubImageEmpty(tex->target, format, w, 0, tex->w-w, tex->h);
|
|
|
|
if (tex->h > h)
|
|
|
|
GPU_glTexSubImageEmpty(tex->target, format, 0, h, w, tex->h-h);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pixels)
|
|
|
|
MEM_freeN(pixels);
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (depth) {
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
glTexParameteri(tex->target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
|
|
glTexParameteri(tex->target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
glTexParameteri(tex->target, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE);
|
|
|
|
glTexParameteri(tex->target, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LEQUAL);
|
|
|
|
glTexParameteri(tex->target, GL_DEPTH_TEXTURE_MODE_ARB, GL_INTENSITY);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
glTexParameteri(tex->target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
glTexParameteri(tex->target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tex->target != GL_TEXTURE_1D) {
|
2015-01-05 14:23:15 +01:00
|
|
|
glTexParameteri(tex->target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
|
|
glTexParameteri(tex->target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
glTexParameteri(tex->target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
|
|
|
|
|
|
return tex;
|
|
|
|
}
|
|
|
|
|
2009-08-20 00:33:59 +00:00
|
|
|
|
2015-03-16 22:57:56 -04:00
|
|
|
GPUTexture *GPU_texture_create_3D(int w, int h, int depth, int channels, const float *fpixels)
|
2009-08-20 00:33:59 +00:00
|
|
|
{
|
|
|
|
GPUTexture *tex;
|
|
|
|
GLenum type, format, internalformat;
|
|
|
|
void *pixels = NULL;
|
2015-04-23 19:02:08 +02:00
|
|
|
int r_width;
|
2015-04-24 11:35:49 +02:00
|
|
|
bool rescale = false;
|
2009-08-20 00:33:59 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (!GLEW_VERSION_1_2)
|
2010-03-27 10:48:01 +00:00
|
|
|
return NULL;
|
|
|
|
|
2009-08-20 00:33:59 +00:00
|
|
|
tex = MEM_callocN(sizeof(GPUTexture), "GPUTexture");
|
2015-09-14 13:18:43 +10:00
|
|
|
tex->w = tex->w_orig = w;
|
|
|
|
tex->h = tex->h_orig = h;
|
|
|
|
tex->depth = tex->depth_orig = depth;
|
2009-08-20 00:33:59 +00:00
|
|
|
tex->number = -1;
|
|
|
|
tex->refcount = 1;
|
|
|
|
tex->target = GL_TEXTURE_3D;
|
|
|
|
|
|
|
|
glGenTextures(1, &tex->bindcode);
|
|
|
|
|
|
|
|
if (!tex->bindcode) {
|
|
|
|
fprintf(stderr, "GPUTexture: texture create failed: %d\n",
|
|
|
|
(int)glGetError());
|
|
|
|
GPU_texture_free(tex);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-10-19 10:10:05 +00:00
|
|
|
if (!GPU_non_power_of_two_support()) {
|
2011-12-16 09:25:07 +00:00
|
|
|
tex->w = power_of_2_max_i(tex->w);
|
|
|
|
tex->h = power_of_2_max_i(tex->h);
|
|
|
|
tex->depth = power_of_2_max_i(tex->depth);
|
2009-08-20 00:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
tex->number = 0;
|
|
|
|
glBindTexture(tex->target, tex->bindcode);
|
|
|
|
|
2015-02-16 21:19:12 +01:00
|
|
|
GPU_ASSERT_NO_GL_ERRORS("3D glBindTexture");
|
2009-09-15 10:26:36 +00:00
|
|
|
|
2012-10-10 13:18:07 +00:00
|
|
|
type = GL_FLOAT;
|
|
|
|
if (channels == 4) {
|
|
|
|
format = GL_RGBA;
|
|
|
|
internalformat = GL_RGBA;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
format = GL_RED;
|
|
|
|
internalformat = GL_INTENSITY;
|
|
|
|
}
|
2009-08-20 00:33:59 +00:00
|
|
|
|
2015-04-23 19:02:08 +02:00
|
|
|
/* 3D textures are quite heavy, test if it's possible to create them first */
|
|
|
|
glTexImage3D(GL_PROXY_TEXTURE_3D, 0, internalformat, tex->w, tex->h, tex->depth, 0, format, type, NULL);
|
|
|
|
glGetTexLevelParameteriv(GL_PROXY_TEXTURE_3D, 0, GL_TEXTURE_WIDTH, &r_width);
|
|
|
|
|
2015-04-24 11:35:49 +02:00
|
|
|
while (r_width == 0) {
|
|
|
|
rescale = true;
|
|
|
|
tex->w /= 2;
|
|
|
|
tex->h /= 2;
|
|
|
|
tex->depth /= 2;
|
|
|
|
glTexImage3D(GL_PROXY_TEXTURE_3D, 0, internalformat, tex->w, tex->h, tex->depth, 0, format, type, NULL);
|
|
|
|
glGetTexLevelParameteriv(GL_PROXY_TEXTURE_3D, 0, GL_TEXTURE_WIDTH, &r_width);
|
2015-04-23 19:02:08 +02:00
|
|
|
}
|
|
|
|
|
2015-04-24 11:35:49 +02:00
|
|
|
/* really unlikely to happen but keep this just in case */
|
|
|
|
tex->w = max_ii(tex->w, 1);
|
|
|
|
tex->h = max_ii(tex->h, 1);
|
|
|
|
tex->depth = max_ii(tex->depth, 1);
|
|
|
|
|
2015-03-23 15:29:42 -04:00
|
|
|
#if 0
|
|
|
|
if (fpixels)
|
|
|
|
pixels = GPU_texture_convert_pixels(w*h*depth, fpixels);
|
|
|
|
#endif
|
2009-08-20 00:33:59 +00:00
|
|
|
|
2015-02-16 21:19:12 +01:00
|
|
|
GPU_ASSERT_NO_GL_ERRORS("3D glTexImage3D");
|
2009-09-15 10:26:36 +00:00
|
|
|
|
2015-04-24 11:35:49 +02:00
|
|
|
/* hardcore stuff, 3D texture rescaling - warning, this is gonna hurt your performance a lot, but we need it
|
|
|
|
* for gooseberry */
|
|
|
|
if (rescale && fpixels) {
|
|
|
|
unsigned int i, j, k;
|
|
|
|
unsigned int xf = w / tex->w, yf = h / tex->h, zf = depth / tex->depth;
|
|
|
|
float *tex3d = MEM_mallocN(channels * sizeof(float)*tex->w*tex->h*tex->depth, "tex3d");
|
|
|
|
|
|
|
|
GPU_print_error_debug("You need to scale a 3D texture, feel the pain!");
|
|
|
|
|
|
|
|
for (k = 0; k < tex->depth; k++) {
|
|
|
|
for (j = 0; j < tex->h; j++) {
|
|
|
|
for (i = 0; i < tex->w; i++) {
|
|
|
|
/* obviously doing nearest filtering here, it's going to be slow in any case, let's not make it worse */
|
|
|
|
float xb = i * xf;
|
|
|
|
float yb = j * yf;
|
|
|
|
float zb = k * zf;
|
|
|
|
unsigned int offset = k * (tex->w * tex->h) + i * tex->h + j;
|
|
|
|
unsigned int offset_orig = (zb) * (w * h) + (xb) * h + (yb);
|
|
|
|
|
|
|
|
if (channels == 4) {
|
|
|
|
tex3d[offset * 4] = fpixels[offset_orig * 4];
|
|
|
|
tex3d[offset * 4 + 1] = fpixels[offset_orig * 4 + 1];
|
|
|
|
tex3d[offset * 4 + 2] = fpixels[offset_orig * 4 + 2];
|
|
|
|
tex3d[offset * 4 + 3] = fpixels[offset_orig * 4 + 3];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
tex3d[offset] = fpixels[offset_orig];
|
|
|
|
}
|
|
|
|
}
|
2015-04-23 19:02:08 +02:00
|
|
|
}
|
2010-01-30 09:24:50 +00:00
|
|
|
|
2015-04-24 11:35:49 +02:00
|
|
|
glTexImage3D(tex->target, 0, internalformat, tex->w, tex->h, tex->depth, 0, format, type, tex3d);
|
|
|
|
|
|
|
|
MEM_freeN(tex3d);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (fpixels) {
|
|
|
|
if (!GPU_non_power_of_two_support() && (w != tex->w || h != tex->h || depth != tex->depth)) {
|
|
|
|
/* clear first to avoid unitialized pixels */
|
|
|
|
float *zero= MEM_callocN(sizeof(float)*tex->w*tex->h*tex->depth, "zero");
|
|
|
|
glTexImage3D(tex->target, 0, internalformat, tex->w, tex->h, tex->depth, 0, format, type, NULL);
|
|
|
|
glTexSubImage3D(tex->target, 0, 0, 0, 0, tex->w, tex->h, tex->depth, GL_INTENSITY, GL_FLOAT, zero);
|
|
|
|
glTexSubImage3D(tex->target, 0, 0, 0, 0, w, h, depth, format, type, fpixels);
|
|
|
|
MEM_freeN(zero);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
glTexImage3D(tex->target, 0, internalformat, tex->w, tex->h, tex->depth, 0, format, type, fpixels);
|
|
|
|
}
|
|
|
|
|
|
|
|
GPU_ASSERT_NO_GL_ERRORS("3D glTexSubImage3D");
|
|
|
|
}
|
2009-08-20 00:33:59 +00:00
|
|
|
}
|
|
|
|
|
2009-09-15 10:26:36 +00:00
|
|
|
|
2009-08-20 00:33:59 +00:00
|
|
|
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
2009-10-20 15:51:25 +00:00
|
|
|
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
|
|
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
|
|
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
|
2009-08-20 00:33:59 +00:00
|
|
|
|
|
|
|
if (pixels)
|
|
|
|
MEM_freeN(pixels);
|
|
|
|
|
2011-09-16 06:47:01 +00:00
|
|
|
GPU_texture_unbind(tex);
|
2009-08-20 00:33:59 +00:00
|
|
|
|
|
|
|
return tex;
|
|
|
|
}
|
|
|
|
|
2014-04-01 11:34:00 +11:00
|
|
|
GPUTexture *GPU_texture_from_blender(Image *ima, ImageUser *iuser, bool is_data, double time, int mipmap)
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
{
|
|
|
|
GPUTexture *tex;
|
|
|
|
GLint w, h, border, lastbindcode, bindcode;
|
|
|
|
|
|
|
|
glGetIntegerv(GL_TEXTURE_BINDING_2D, &lastbindcode);
|
|
|
|
|
|
|
|
GPU_update_image_time(ima, time);
|
2013-01-22 11:18:41 +00:00
|
|
|
/* this binds a texture, so that's why to restore it with lastbindcode */
|
2014-04-01 11:34:00 +11:00
|
|
|
bindcode = GPU_verify_image(ima, iuser, 0, 0, mipmap, is_data);
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (ima->gputexture) {
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
ima->gputexture->bindcode = bindcode;
|
|
|
|
glBindTexture(GL_TEXTURE_2D, lastbindcode);
|
|
|
|
return ima->gputexture;
|
|
|
|
}
|
|
|
|
|
|
|
|
tex = MEM_callocN(sizeof(GPUTexture), "GPUTexture");
|
|
|
|
tex->bindcode = bindcode;
|
|
|
|
tex->number = -1;
|
|
|
|
tex->refcount = 1;
|
|
|
|
tex->target = GL_TEXTURE_2D;
|
|
|
|
tex->fromblender = 1;
|
|
|
|
|
|
|
|
ima->gputexture= tex;
|
|
|
|
|
|
|
|
if (!glIsTexture(tex->bindcode)) {
|
2015-02-16 21:19:12 +01:00
|
|
|
GPU_ASSERT_NO_GL_ERRORS("Blender Texture Not Loaded");
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
glBindTexture(GL_TEXTURE_2D, tex->bindcode);
|
|
|
|
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &w);
|
|
|
|
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &h);
|
|
|
|
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_BORDER, &border);
|
|
|
|
|
2015-09-14 13:18:43 +10:00
|
|
|
tex->w = tex->w_orig = w - border;
|
|
|
|
tex->h = tex->h_orig = h - border;
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, lastbindcode);
|
|
|
|
|
|
|
|
return tex;
|
|
|
|
}
|
|
|
|
|
2013-01-22 11:18:41 +00:00
|
|
|
GPUTexture *GPU_texture_from_preview(PreviewImage *prv, int mipmap)
|
|
|
|
{
|
|
|
|
GPUTexture *tex = prv->gputexture[0];
|
|
|
|
GLint w, h, lastbindcode;
|
|
|
|
GLuint bindcode = 0;
|
|
|
|
|
|
|
|
glGetIntegerv(GL_TEXTURE_BINDING_2D, &lastbindcode);
|
|
|
|
|
|
|
|
if (tex)
|
|
|
|
bindcode = tex->bindcode;
|
|
|
|
|
|
|
|
/* this binds a texture, so that's why to restore it */
|
|
|
|
if (bindcode == 0) {
|
|
|
|
GPU_create_gl_tex(&bindcode, prv->rect[0], NULL, prv->w[0], prv->h[0], mipmap, 0, NULL);
|
|
|
|
}
|
|
|
|
if (tex) {
|
|
|
|
tex->bindcode = bindcode;
|
|
|
|
glBindTexture(GL_TEXTURE_2D, lastbindcode);
|
|
|
|
return tex;
|
|
|
|
}
|
|
|
|
|
|
|
|
tex = MEM_callocN(sizeof(GPUTexture), "GPUTexture");
|
|
|
|
tex->bindcode = bindcode;
|
|
|
|
tex->number = -1;
|
|
|
|
tex->refcount = 1;
|
|
|
|
tex->target = GL_TEXTURE_2D;
|
|
|
|
|
2015-06-24 05:13:43 +10:00
|
|
|
prv->gputexture[0] = tex;
|
2013-01-22 11:18:41 +00:00
|
|
|
|
|
|
|
if (!glIsTexture(tex->bindcode)) {
|
2015-02-16 21:19:12 +01:00
|
|
|
GPU_ASSERT_NO_GL_ERRORS("Blender Texture Not Loaded");
|
2013-01-22 11:18:41 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
glBindTexture(GL_TEXTURE_2D, tex->bindcode);
|
|
|
|
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &w);
|
|
|
|
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &h);
|
|
|
|
|
2015-09-14 13:18:43 +10:00
|
|
|
tex->w = tex->w_orig = w;
|
|
|
|
tex->h = tex->h_orig = h;
|
2013-01-22 11:18:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, lastbindcode);
|
|
|
|
|
|
|
|
return tex;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-03-16 22:57:56 -04:00
|
|
|
GPUTexture *GPU_texture_create_1D(int w, const float *fpixels, char err_out[256])
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
{
|
2015-02-12 18:54:41 +01:00
|
|
|
GPUTexture *tex = GPU_texture_create_nD(w, 1, 1, fpixels, 0, GPU_HDR_NONE, 4, err_out);
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
|
|
|
|
if (tex)
|
|
|
|
GPU_texture_unbind(tex);
|
|
|
|
|
|
|
|
return tex;
|
|
|
|
}
|
|
|
|
|
2015-03-16 22:57:56 -04:00
|
|
|
GPUTexture *GPU_texture_create_2D(int w, int h, const float *fpixels, GPUHDRType hdr, char err_out[256])
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
{
|
2015-02-12 18:54:41 +01:00
|
|
|
GPUTexture *tex = GPU_texture_create_nD(w, h, 2, fpixels, 0, hdr, 4, err_out);
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
|
|
|
|
if (tex)
|
|
|
|
GPU_texture_unbind(tex);
|
|
|
|
|
|
|
|
return tex;
|
|
|
|
}
|
|
|
|
|
2011-03-06 23:12:12 +00:00
|
|
|
GPUTexture *GPU_texture_create_depth(int w, int h, char err_out[256])
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
{
|
2015-02-12 18:54:41 +01:00
|
|
|
GPUTexture *tex = GPU_texture_create_nD(w, h, 2, NULL, 1, GPU_HDR_NONE, 1, err_out);
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
|
|
|
|
if (tex)
|
|
|
|
GPU_texture_unbind(tex);
|
|
|
|
|
|
|
|
return tex;
|
|
|
|
}
|
|
|
|
|
2012-05-01 02:50:17 +00:00
|
|
|
/**
|
|
|
|
* A shadow map for VSM needs two components (depth and depth^2)
|
|
|
|
*/
|
|
|
|
GPUTexture *GPU_texture_create_vsm_shadow_map(int size, char err_out[256])
|
|
|
|
{
|
2015-02-12 18:54:41 +01:00
|
|
|
GPUTexture *tex = GPU_texture_create_nD(size, size, 2, NULL, 0, GPU_HDR_FULL_FLOAT, 2, err_out);
|
2012-05-01 02:50:17 +00:00
|
|
|
|
|
|
|
if (tex) {
|
|
|
|
/* Now we tweak some of the settings */
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
2015-02-12 18:54:41 +01:00
|
|
|
|
|
|
|
GPU_texture_unbind(tex);
|
|
|
|
}
|
|
|
|
|
|
|
|
return tex;
|
|
|
|
}
|
|
|
|
|
2015-03-03 17:47:31 +01:00
|
|
|
GPUTexture *GPU_texture_create_2D_procedural(int w, int h, const float *pixels, bool repeat, char err_out[256])
|
2015-02-12 18:54:41 +01:00
|
|
|
{
|
|
|
|
GPUTexture *tex = GPU_texture_create_nD(w, h, 2, pixels, 0, GPU_HDR_HALF_FLOAT, 2, err_out);
|
|
|
|
|
|
|
|
if (tex) {
|
|
|
|
/* Now we tweak some of the settings */
|
2015-03-03 17:47:31 +01:00
|
|
|
if (repeat) {
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
|
|
|
}
|
2015-02-12 18:54:41 +01:00
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
|
|
|
|
|
|
GPU_texture_unbind(tex);
|
|
|
|
}
|
|
|
|
|
|
|
|
return tex;
|
|
|
|
}
|
|
|
|
|
2015-03-16 22:57:56 -04:00
|
|
|
GPUTexture *GPU_texture_create_1D_procedural(int w, const float *pixels, char err_out[256])
|
2015-02-12 18:54:41 +01:00
|
|
|
{
|
|
|
|
GPUTexture *tex = GPU_texture_create_nD(w, 0, 1, pixels, 0, GPU_HDR_HALF_FLOAT, 2, err_out);
|
|
|
|
|
|
|
|
if (tex) {
|
|
|
|
/* Now we tweak some of the settings */
|
|
|
|
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
|
|
|
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
|
|
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
2012-05-01 02:50:17 +00:00
|
|
|
|
|
|
|
GPU_texture_unbind(tex);
|
|
|
|
}
|
|
|
|
|
|
|
|
return tex;
|
|
|
|
}
|
|
|
|
|
2014-06-10 01:36:53 +03:00
|
|
|
void GPU_invalid_tex_init(void)
|
|
|
|
{
|
2015-03-16 22:57:56 -04:00
|
|
|
const float color[4] = {1.0f, 0.0f, 1.0f, 1.0f};
|
2014-06-10 01:36:53 +03:00
|
|
|
GG.invalid_tex_1D = GPU_texture_create_1D(1, color, NULL);
|
2015-02-12 18:54:41 +01:00
|
|
|
GG.invalid_tex_2D = GPU_texture_create_2D(1, 1, color, GPU_HDR_NONE, NULL);
|
2014-06-10 01:36:53 +03:00
|
|
|
GG.invalid_tex_3D = GPU_texture_create_3D(1, 1, 1, 4, color);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPU_invalid_tex_bind(int mode)
|
|
|
|
{
|
2014-06-13 02:22:40 +10:00
|
|
|
switch (mode) {
|
2014-06-10 01:36:53 +03:00
|
|
|
case GL_TEXTURE_1D:
|
|
|
|
glBindTexture(GL_TEXTURE_1D, GG.invalid_tex_1D->bindcode);
|
|
|
|
break;
|
|
|
|
case GL_TEXTURE_2D:
|
|
|
|
glBindTexture(GL_TEXTURE_2D, GG.invalid_tex_2D->bindcode);
|
|
|
|
break;
|
|
|
|
case GL_TEXTURE_3D:
|
|
|
|
glBindTexture(GL_TEXTURE_3D, GG.invalid_tex_3D->bindcode);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPU_invalid_tex_free(void)
|
|
|
|
{
|
2014-10-02 16:21:26 +02:00
|
|
|
if (GG.invalid_tex_1D)
|
|
|
|
GPU_texture_free(GG.invalid_tex_1D);
|
|
|
|
if (GG.invalid_tex_2D)
|
|
|
|
GPU_texture_free(GG.invalid_tex_2D);
|
|
|
|
if (GG.invalid_tex_3D)
|
|
|
|
GPU_texture_free(GG.invalid_tex_3D);
|
2014-06-10 01:36:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
void GPU_texture_bind(GPUTexture *tex, int number)
|
|
|
|
{
|
|
|
|
GLenum arbnumber;
|
|
|
|
|
|
|
|
if (number >= GG.maxtextures) {
|
2015-02-16 21:19:12 +01:00
|
|
|
fprintf(stderr, "Not enough texture slots.");
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-12-03 17:26:43 -02:00
|
|
|
if ((G.debug & G_DEBUG)) {
|
|
|
|
if (tex->fb && tex->fb->object == GG.currentfb) {
|
2014-11-18 12:12:28 +01:00
|
|
|
fprintf(stderr, "Feedback loop warning!: Attempting to bind texture attached to current framebuffer!\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (number < 0)
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
return;
|
|
|
|
|
2015-02-16 21:19:12 +01:00
|
|
|
GPU_ASSERT_NO_GL_ERRORS("Pre Texture Bind");
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
|
|
|
|
arbnumber = (GLenum)((GLuint)GL_TEXTURE0_ARB + number);
|
|
|
|
if (number != 0) glActiveTextureARB(arbnumber);
|
2014-06-10 01:36:53 +03:00
|
|
|
if (tex->bindcode != 0) {
|
|
|
|
glBindTexture(tex->target, tex->bindcode);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
GPU_invalid_tex_bind(tex->target);
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
glEnable(tex->target);
|
|
|
|
if (number != 0) glActiveTextureARB(GL_TEXTURE0_ARB);
|
|
|
|
|
|
|
|
tex->number = number;
|
|
|
|
|
2015-02-16 21:19:12 +01:00
|
|
|
GPU_ASSERT_NO_GL_ERRORS("Post Texture Bind");
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GPU_texture_unbind(GPUTexture *tex)
|
|
|
|
{
|
|
|
|
GLenum arbnumber;
|
|
|
|
|
|
|
|
if (tex->number >= GG.maxtextures) {
|
2015-02-16 21:19:12 +01:00
|
|
|
fprintf(stderr, "Not enough texture slots.");
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (tex->number == -1)
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
return;
|
|
|
|
|
2015-02-16 21:19:12 +01:00
|
|
|
GPU_ASSERT_NO_GL_ERRORS("Pre Texture Unbind");
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
|
|
|
|
arbnumber = (GLenum)((GLuint)GL_TEXTURE0_ARB + tex->number);
|
|
|
|
if (tex->number != 0) glActiveTextureARB(arbnumber);
|
|
|
|
glBindTexture(tex->target, 0);
|
|
|
|
glDisable(tex->target);
|
|
|
|
if (tex->number != 0) glActiveTextureARB(GL_TEXTURE0_ARB);
|
|
|
|
|
|
|
|
tex->number = -1;
|
|
|
|
|
2015-02-16 21:19:12 +01:00
|
|
|
GPU_ASSERT_NO_GL_ERRORS("Post Texture Unbind");
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
}
|
|
|
|
|
2015-03-03 17:47:31 +01:00
|
|
|
void GPU_texture_filter_mode(GPUTexture *tex, bool compare, bool use_filter)
|
2015-02-12 18:54:41 +01:00
|
|
|
{
|
|
|
|
GLenum arbnumber;
|
|
|
|
|
|
|
|
if (tex->number >= GG.maxtextures) {
|
2015-02-16 21:19:12 +01:00
|
|
|
fprintf(stderr, "Not enough texture slots.");
|
2015-02-12 18:54:41 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tex->number == -1)
|
|
|
|
return;
|
|
|
|
|
2015-02-16 21:19:12 +01:00
|
|
|
GPU_ASSERT_NO_GL_ERRORS("Pre Texture Unbind");
|
2015-02-12 18:54:41 +01:00
|
|
|
|
|
|
|
arbnumber = (GLenum)((GLuint)GL_TEXTURE0_ARB + tex->number);
|
|
|
|
if (tex->number != 0) glActiveTextureARB(arbnumber);
|
2015-03-03 17:47:31 +01:00
|
|
|
|
|
|
|
if (tex->depth) {
|
|
|
|
if (compare)
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);
|
|
|
|
else
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE);
|
|
|
|
}
|
2015-02-12 18:54:41 +01:00
|
|
|
|
|
|
|
if (use_filter) {
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
|
|
}
|
|
|
|
if (tex->number != 0) glActiveTextureARB(GL_TEXTURE0_ARB);
|
|
|
|
|
2015-02-16 21:19:12 +01:00
|
|
|
GPU_ASSERT_NO_GL_ERRORS("Post Texture Unbind");
|
2015-02-12 18:54:41 +01:00
|
|
|
}
|
|
|
|
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
void GPU_texture_free(GPUTexture *tex)
|
|
|
|
{
|
|
|
|
tex->refcount--;
|
|
|
|
|
|
|
|
if (tex->refcount < 0)
|
|
|
|
fprintf(stderr, "GPUTexture: negative refcount\n");
|
|
|
|
|
|
|
|
if (tex->refcount == 0) {
|
|
|
|
if (tex->fb)
|
2014-11-18 11:56:23 +01:00
|
|
|
GPU_framebuffer_texture_detach(tex);
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
if (tex->bindcode && !tex->fromblender)
|
|
|
|
glDeleteTextures(1, &tex->bindcode);
|
|
|
|
|
|
|
|
MEM_freeN(tex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPU_texture_ref(GPUTexture *tex)
|
|
|
|
{
|
|
|
|
tex->refcount++;
|
|
|
|
}
|
|
|
|
|
2015-03-16 22:57:56 -04:00
|
|
|
int GPU_texture_target(const GPUTexture *tex)
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
{
|
|
|
|
return tex->target;
|
|
|
|
}
|
|
|
|
|
2015-03-16 22:57:56 -04:00
|
|
|
int GPU_texture_opengl_width(const GPUTexture *tex)
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
{
|
|
|
|
return tex->w;
|
|
|
|
}
|
|
|
|
|
2015-03-16 22:57:56 -04:00
|
|
|
int GPU_texture_opengl_height(const GPUTexture *tex)
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
{
|
|
|
|
return tex->h;
|
|
|
|
}
|
|
|
|
|
2015-03-16 22:57:56 -04:00
|
|
|
int GPU_texture_opengl_bindcode(const GPUTexture *tex)
|
2011-09-09 11:55:38 +00:00
|
|
|
{
|
|
|
|
return tex->bindcode;
|
|
|
|
}
|
|
|
|
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
GPUFrameBuffer *GPU_texture_framebuffer(GPUTexture *tex)
|
|
|
|
{
|
|
|
|
return tex->fb;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* GPUFrameBuffer */
|
|
|
|
|
2011-02-13 15:02:21 +00:00
|
|
|
GPUFrameBuffer *GPU_framebuffer_create(void)
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
{
|
|
|
|
GPUFrameBuffer *fb;
|
|
|
|
|
|
|
|
if (!GLEW_EXT_framebuffer_object)
|
|
|
|
return NULL;
|
|
|
|
|
2015-03-23 15:29:42 -04:00
|
|
|
fb = MEM_callocN(sizeof(GPUFrameBuffer), "GPUFrameBuffer");
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
glGenFramebuffersEXT(1, &fb->object);
|
|
|
|
|
|
|
|
if (!fb->object) {
|
|
|
|
fprintf(stderr, "GPUFFrameBuffer: framebuffer gen failed. %d\n",
|
|
|
|
(int)glGetError());
|
|
|
|
GPU_framebuffer_free(fb);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-11-25 16:16:50 +01:00
|
|
|
/* make sure no read buffer is enabled, so completeness check will not fail. We set those at binding time */
|
|
|
|
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb->object);
|
|
|
|
glReadBuffer(GL_NONE);
|
|
|
|
glDrawBuffer(GL_NONE);
|
|
|
|
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
|
|
|
|
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
return fb;
|
|
|
|
}
|
|
|
|
|
2014-11-18 11:56:23 +01:00
|
|
|
int GPU_framebuffer_texture_attach(GPUFrameBuffer *fb, GPUTexture *tex, int slot, char err_out[256])
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
{
|
|
|
|
GLenum attachment;
|
2012-12-03 08:31:16 +00:00
|
|
|
GLenum error;
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
|
2014-11-18 11:56:23 +01:00
|
|
|
if (slot >= GPU_FB_MAX_SLOTS) {
|
|
|
|
fprintf(stderr, "Attaching to index %d framebuffer slot unsupported in blender use at most %d\n", slot, GPU_FB_MAX_SLOTS);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-12-03 17:26:43 -02:00
|
|
|
if ((G.debug & G_DEBUG)) {
|
|
|
|
if (tex->number != -1) {
|
|
|
|
fprintf(stderr, "Feedback loop warning!: Attempting to attach texture to framebuffer while still bound to texture unit for drawing!");
|
|
|
|
}
|
2014-11-18 12:12:28 +01:00
|
|
|
}
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (tex->depth)
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
attachment = GL_DEPTH_ATTACHMENT_EXT;
|
|
|
|
else
|
2014-11-18 11:56:23 +01:00
|
|
|
attachment = GL_COLOR_ATTACHMENT0_EXT + slot;
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
|
|
|
|
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb->object);
|
|
|
|
GG.currentfb = fb->object;
|
|
|
|
|
2014-08-18 13:54:29 +06:00
|
|
|
/* Clean glError buffer. */
|
|
|
|
while (glGetError() != GL_NO_ERROR) {}
|
|
|
|
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, attachment,
|
|
|
|
tex->target, tex->bindcode, 0);
|
|
|
|
|
2012-12-03 08:31:16 +00:00
|
|
|
error = glGetError();
|
|
|
|
|
|
|
|
if (error == GL_INVALID_OPERATION) {
|
|
|
|
GPU_framebuffer_restore();
|
|
|
|
GPU_print_framebuffer_error(error, err_out);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (tex->depth)
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
fb->depthtex = tex;
|
|
|
|
else
|
2014-11-18 11:56:23 +01:00
|
|
|
fb->colortex[slot] = tex;
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
|
|
|
|
tex->fb= fb;
|
2014-11-18 11:56:23 +01:00
|
|
|
tex->fb_attachment = slot;
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-11-18 11:56:23 +01:00
|
|
|
void GPU_framebuffer_texture_detach(GPUTexture *tex)
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
{
|
|
|
|
GLenum attachment;
|
2014-11-18 11:56:23 +01:00
|
|
|
GPUFrameBuffer *fb;
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
|
2014-11-18 12:12:28 +01:00
|
|
|
if (!tex->fb)
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
return;
|
|
|
|
|
2014-11-18 11:56:23 +01:00
|
|
|
fb = tex->fb;
|
|
|
|
|
|
|
|
if (GG.currentfb != fb->object) {
|
|
|
|
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb->object);
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
GG.currentfb = tex->fb->object;
|
|
|
|
}
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (tex->depth) {
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
fb->depthtex = NULL;
|
|
|
|
attachment = GL_DEPTH_ATTACHMENT_EXT;
|
|
|
|
}
|
|
|
|
else {
|
2014-11-18 11:56:23 +01:00
|
|
|
BLI_assert(fb->colortex[tex->fb_attachment] == tex);
|
|
|
|
fb->colortex[tex->fb_attachment] = NULL;
|
|
|
|
attachment = GL_COLOR_ATTACHMENT0_EXT + tex->fb_attachment;
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
}
|
|
|
|
|
2015-03-23 15:29:42 -04:00
|
|
|
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, attachment, tex->target, 0, 0);
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
|
|
|
|
tex->fb = NULL;
|
2014-11-18 11:56:23 +01:00
|
|
|
tex->fb_attachment = -1;
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
}
|
|
|
|
|
2014-11-18 12:37:55 +01:00
|
|
|
void GPU_texture_bind_as_framebuffer(GPUTexture *tex)
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
{
|
2014-11-18 12:37:55 +01:00
|
|
|
if (!tex->fb) {
|
|
|
|
fprintf(stderr, "Error, texture not bound to framebuffer!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
/* push attributes */
|
2013-04-18 16:28:39 +00:00
|
|
|
glPushAttrib(GL_ENABLE_BIT | GL_VIEWPORT_BIT);
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
glDisable(GL_SCISSOR_TEST);
|
|
|
|
|
|
|
|
/* bind framebuffer */
|
|
|
|
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, tex->fb->object);
|
|
|
|
|
2014-12-16 21:52:55 +01:00
|
|
|
if (tex->depth) {
|
|
|
|
glDrawBuffer(GL_NONE);
|
|
|
|
glReadBuffer(GL_NONE);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* last bound prevails here, better allow explicit control here too */
|
|
|
|
glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT + tex->fb_attachment);
|
|
|
|
glReadBuffer(GL_COLOR_ATTACHMENT0_EXT + tex->fb_attachment);
|
|
|
|
}
|
|
|
|
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
/* push matrices and set default viewport and matrix */
|
2015-09-14 13:18:43 +10:00
|
|
|
glViewport(0, 0, tex->w_orig, tex->h_orig);
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
GG.currentfb = tex->fb->object;
|
|
|
|
|
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
glPushMatrix();
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
glPushMatrix();
|
|
|
|
}
|
|
|
|
|
2015-02-12 18:54:41 +01:00
|
|
|
void GPU_framebuffer_slots_bind(GPUFrameBuffer *fb, int slot)
|
2014-11-18 12:37:55 +01:00
|
|
|
{
|
2015-02-12 18:54:41 +01:00
|
|
|
int numslots = 0, i;
|
|
|
|
GLenum attachments[4];
|
|
|
|
|
2014-11-18 12:37:55 +01:00
|
|
|
if (!fb->colortex[slot]) {
|
|
|
|
fprintf(stderr, "Error, framebuffer slot empty!");
|
|
|
|
return;
|
|
|
|
}
|
2015-02-12 18:54:41 +01:00
|
|
|
|
2015-03-23 15:29:42 -04:00
|
|
|
for (i = 0; i < 4; i++) {
|
2015-02-12 18:54:41 +01:00
|
|
|
if (fb->colortex[i]) {
|
|
|
|
attachments[numslots] = GL_COLOR_ATTACHMENT0_EXT + i;
|
|
|
|
numslots++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-18 12:37:55 +01:00
|
|
|
/* push attributes */
|
|
|
|
glPushAttrib(GL_ENABLE_BIT | GL_VIEWPORT_BIT);
|
|
|
|
glDisable(GL_SCISSOR_TEST);
|
|
|
|
|
|
|
|
/* bind framebuffer */
|
|
|
|
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb->object);
|
|
|
|
|
|
|
|
/* last bound prevails here, better allow explicit control here too */
|
2015-02-12 18:54:41 +01:00
|
|
|
glDrawBuffers(numslots, attachments);
|
2014-11-18 12:37:55 +01:00
|
|
|
glReadBuffer(GL_COLOR_ATTACHMENT0_EXT + slot);
|
|
|
|
|
|
|
|
/* push matrices and set default viewport and matrix */
|
2015-09-14 13:18:43 +10:00
|
|
|
glViewport(0, 0, fb->colortex[slot]->w_orig, fb->colortex[slot]->h_orig);
|
2014-11-18 12:37:55 +01:00
|
|
|
GG.currentfb = fb->object;
|
|
|
|
|
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
glPushMatrix();
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
glPushMatrix();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-15 12:29:02 +00:00
|
|
|
void GPU_framebuffer_texture_unbind(GPUFrameBuffer *UNUSED(fb), GPUTexture *UNUSED(tex))
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
{
|
|
|
|
/* restore matrix */
|
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
glPopMatrix();
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
glPopMatrix();
|
|
|
|
|
|
|
|
/* restore attributes */
|
|
|
|
glPopAttrib();
|
|
|
|
}
|
|
|
|
|
2015-02-12 18:54:41 +01:00
|
|
|
void GPU_framebuffer_bind_no_save(GPUFrameBuffer *fb, int slot)
|
|
|
|
{
|
|
|
|
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb->object);
|
|
|
|
/* last bound prevails here, better allow explicit control here too */
|
|
|
|
glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT + slot);
|
|
|
|
glReadBuffer(GL_COLOR_ATTACHMENT0_EXT + slot);
|
|
|
|
|
|
|
|
/* push matrices and set default viewport and matrix */
|
2015-09-14 13:18:43 +10:00
|
|
|
glViewport(0, 0, fb->colortex[slot]->w_orig, fb->colortex[slot]->h_orig);
|
2015-02-12 18:54:41 +01:00
|
|
|
GG.currentfb = fb->object;
|
|
|
|
GG.currentfb = fb->object;
|
|
|
|
}
|
2014-11-25 16:16:50 +01:00
|
|
|
|
|
|
|
bool GPU_framebuffer_check_valid(GPUFrameBuffer *fb, char err_out[256])
|
|
|
|
{
|
|
|
|
GLenum status;
|
|
|
|
|
|
|
|
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb->object);
|
|
|
|
GG.currentfb = fb->object;
|
|
|
|
|
|
|
|
/* Clean glError buffer. */
|
|
|
|
while (glGetError() != GL_NO_ERROR) {}
|
|
|
|
|
|
|
|
status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
|
|
|
|
|
|
|
|
if (status != GL_FRAMEBUFFER_COMPLETE_EXT) {
|
|
|
|
GPU_framebuffer_restore();
|
|
|
|
GPU_print_framebuffer_error(status, err_out);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
void GPU_framebuffer_free(GPUFrameBuffer *fb)
|
|
|
|
{
|
2014-11-18 11:56:23 +01:00
|
|
|
int i;
|
2012-03-24 06:38:07 +00:00
|
|
|
if (fb->depthtex)
|
2014-11-18 11:56:23 +01:00
|
|
|
GPU_framebuffer_texture_detach(fb->depthtex);
|
|
|
|
|
|
|
|
for (i = 0; i < GPU_FB_MAX_SLOTS; i++) {
|
|
|
|
if (fb->colortex[i]) {
|
|
|
|
GPU_framebuffer_texture_detach(fb->colortex[i]);
|
|
|
|
}
|
|
|
|
}
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (fb->object) {
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
glDeleteFramebuffersEXT(1, &fb->object);
|
|
|
|
|
|
|
|
if (GG.currentfb == fb->object) {
|
|
|
|
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
|
|
|
|
GG.currentfb = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MEM_freeN(fb);
|
|
|
|
}
|
|
|
|
|
2011-02-13 15:02:21 +00:00
|
|
|
void GPU_framebuffer_restore(void)
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
{
|
|
|
|
if (GG.currentfb != 0) {
|
|
|
|
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
|
|
|
|
GG.currentfb = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-01 02:50:17 +00:00
|
|
|
void GPU_framebuffer_blur(GPUFrameBuffer *fb, GPUTexture *tex, GPUFrameBuffer *blurfb, GPUTexture *blurtex)
|
|
|
|
{
|
2015-09-14 13:18:43 +10:00
|
|
|
const float scaleh[2] = {1.0f / blurtex->w_orig, 0.0f};
|
|
|
|
const float scalev[2] = {0.0f, 1.0f / tex->h_orig};
|
2012-05-01 02:50:17 +00:00
|
|
|
|
|
|
|
GPUShader *blur_shader = GPU_shader_get_builtin_shader(GPU_SHADER_SEP_GAUSSIAN_BLUR);
|
|
|
|
int scale_uniform, texture_source_uniform;
|
|
|
|
|
|
|
|
if (!blur_shader)
|
|
|
|
return;
|
|
|
|
|
|
|
|
scale_uniform = GPU_shader_get_uniform(blur_shader, "ScaleU");
|
|
|
|
texture_source_uniform = GPU_shader_get_uniform(blur_shader, "textureSource");
|
|
|
|
|
|
|
|
/* Blurring horizontally */
|
|
|
|
|
|
|
|
/* We do the bind ourselves rather than using GPU_framebuffer_texture_bind() to avoid
|
2012-05-16 23:37:23 +00:00
|
|
|
* pushing unnecessary matrices onto the OpenGL stack. */
|
2012-05-01 02:50:17 +00:00
|
|
|
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, blurfb->object);
|
2014-12-05 16:01:08 +01:00
|
|
|
glDrawBuffer(GL_COLOR_ATTACHMENT0);
|
|
|
|
|
|
|
|
/* avoid warnings from texture binding */
|
|
|
|
GG.currentfb = blurfb->object;
|
2012-05-01 02:50:17 +00:00
|
|
|
|
|
|
|
GPU_shader_bind(blur_shader);
|
2015-02-12 18:54:41 +01:00
|
|
|
GPU_shader_uniform_vector(blur_shader, scale_uniform, 2, 1, scaleh);
|
2012-05-01 02:50:17 +00:00
|
|
|
GPU_shader_uniform_texture(blur_shader, texture_source_uniform, tex);
|
2015-09-14 13:18:43 +10:00
|
|
|
glViewport(0, 0, blurtex->w_orig, blurtex->h_orig);
|
2012-05-01 02:50:17 +00:00
|
|
|
|
|
|
|
/* Peparing to draw quad */
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
glLoadIdentity();
|
|
|
|
glMatrixMode(GL_TEXTURE);
|
|
|
|
glLoadIdentity();
|
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
glLoadIdentity();
|
|
|
|
|
2013-07-23 00:52:49 +00:00
|
|
|
glDisable(GL_DEPTH_TEST);
|
|
|
|
|
2012-05-01 02:50:17 +00:00
|
|
|
GPU_texture_bind(tex, 0);
|
|
|
|
|
|
|
|
/* Drawing quad */
|
|
|
|
glBegin(GL_QUADS);
|
2012-05-01 20:08:23 +00:00
|
|
|
glTexCoord2d(0, 0); glVertex2f(1, 1);
|
|
|
|
glTexCoord2d(1, 0); glVertex2f(-1, 1);
|
|
|
|
glTexCoord2d(1, 1); glVertex2f(-1, -1);
|
|
|
|
glTexCoord2d(0, 1); glVertex2f(1, -1);
|
2012-05-01 02:50:17 +00:00
|
|
|
glEnd();
|
2015-02-12 18:54:41 +01:00
|
|
|
|
2012-05-01 02:50:17 +00:00
|
|
|
/* Blurring vertically */
|
|
|
|
|
|
|
|
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb->object);
|
2014-12-05 16:01:08 +01:00
|
|
|
glDrawBuffer(GL_COLOR_ATTACHMENT0);
|
|
|
|
|
|
|
|
GG.currentfb = fb->object;
|
|
|
|
|
2015-09-14 13:18:43 +10:00
|
|
|
glViewport(0, 0, tex->w_orig, tex->h_orig);
|
2015-02-12 18:54:41 +01:00
|
|
|
GPU_shader_uniform_vector(blur_shader, scale_uniform, 2, 1, scalev);
|
2012-05-01 02:50:17 +00:00
|
|
|
GPU_shader_uniform_texture(blur_shader, texture_source_uniform, blurtex);
|
|
|
|
GPU_texture_bind(blurtex, 0);
|
2012-05-01 20:08:23 +00:00
|
|
|
|
2012-05-01 02:50:17 +00:00
|
|
|
glBegin(GL_QUADS);
|
2012-05-01 20:08:23 +00:00
|
|
|
glTexCoord2d(0, 0); glVertex2f(1, 1);
|
|
|
|
glTexCoord2d(1, 0); glVertex2f(-1, 1);
|
|
|
|
glTexCoord2d(1, 1); glVertex2f(-1, -1);
|
|
|
|
glTexCoord2d(0, 1); glVertex2f(1, -1);
|
2012-05-01 02:50:17 +00:00
|
|
|
glEnd();
|
2012-05-01 20:08:23 +00:00
|
|
|
|
2013-02-26 00:49:42 +00:00
|
|
|
GPU_shader_unbind();
|
2012-05-01 02:50:17 +00:00
|
|
|
}
|
|
|
|
|
2009-10-28 18:03:04 +00:00
|
|
|
/* GPUOffScreen */
|
|
|
|
|
|
|
|
struct GPUOffScreen {
|
|
|
|
GPUFrameBuffer *fb;
|
|
|
|
GPUTexture *color;
|
|
|
|
GPUTexture *depth;
|
|
|
|
};
|
|
|
|
|
2011-10-28 16:57:06 +00:00
|
|
|
GPUOffScreen *GPU_offscreen_create(int width, int height, char err_out[256])
|
2009-10-28 18:03:04 +00:00
|
|
|
{
|
|
|
|
GPUOffScreen *ofs;
|
|
|
|
|
2015-03-23 15:29:42 -04:00
|
|
|
ofs = MEM_callocN(sizeof(GPUOffScreen), "GPUOffScreen");
|
2009-10-28 18:03:04 +00:00
|
|
|
|
|
|
|
ofs->fb = GPU_framebuffer_create();
|
2012-03-24 06:38:07 +00:00
|
|
|
if (!ofs->fb) {
|
2009-10-28 18:03:04 +00:00
|
|
|
GPU_offscreen_free(ofs);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-10-28 16:57:06 +00:00
|
|
|
ofs->depth = GPU_texture_create_depth(width, height, err_out);
|
2012-03-24 06:38:07 +00:00
|
|
|
if (!ofs->depth) {
|
2009-10-28 18:03:04 +00:00
|
|
|
GPU_offscreen_free(ofs);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-11-18 11:56:23 +01:00
|
|
|
if (!GPU_framebuffer_texture_attach(ofs->fb, ofs->depth, 0, err_out)) {
|
2009-10-28 18:03:04 +00:00
|
|
|
GPU_offscreen_free(ofs);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-02-12 18:54:41 +01:00
|
|
|
ofs->color = GPU_texture_create_2D(width, height, NULL, GPU_HDR_NONE, err_out);
|
2012-03-24 06:38:07 +00:00
|
|
|
if (!ofs->color) {
|
2009-10-28 18:03:04 +00:00
|
|
|
GPU_offscreen_free(ofs);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-11-18 11:56:23 +01:00
|
|
|
if (!GPU_framebuffer_texture_attach(ofs->fb, ofs->color, 0, err_out)) {
|
2009-10-28 18:03:04 +00:00
|
|
|
GPU_offscreen_free(ofs);
|
|
|
|
return NULL;
|
|
|
|
}
|
2014-11-25 16:16:50 +01:00
|
|
|
|
|
|
|
/* check validity at the very end! */
|
|
|
|
if (!GPU_framebuffer_check_valid(ofs->fb, err_out)) {
|
|
|
|
GPU_offscreen_free(ofs);
|
|
|
|
return NULL;
|
|
|
|
}
|
2009-10-28 18:03:04 +00:00
|
|
|
|
|
|
|
GPU_framebuffer_restore();
|
|
|
|
|
|
|
|
return ofs;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPU_offscreen_free(GPUOffScreen *ofs)
|
|
|
|
{
|
2012-03-24 06:38:07 +00:00
|
|
|
if (ofs->fb)
|
2009-10-28 18:03:04 +00:00
|
|
|
GPU_framebuffer_free(ofs->fb);
|
2012-03-24 06:38:07 +00:00
|
|
|
if (ofs->color)
|
2009-10-28 18:03:04 +00:00
|
|
|
GPU_texture_free(ofs->color);
|
2012-03-24 06:38:07 +00:00
|
|
|
if (ofs->depth)
|
2009-10-28 18:03:04 +00:00
|
|
|
GPU_texture_free(ofs->depth);
|
|
|
|
|
|
|
|
MEM_freeN(ofs);
|
|
|
|
}
|
|
|
|
|
2015-02-12 18:54:41 +01:00
|
|
|
void GPU_offscreen_bind(GPUOffScreen *ofs, bool save)
|
2009-10-28 18:03:04 +00:00
|
|
|
{
|
|
|
|
glDisable(GL_SCISSOR_TEST);
|
2015-02-12 18:54:41 +01:00
|
|
|
if (save)
|
2015-03-09 18:27:27 +01:00
|
|
|
GPU_texture_bind_as_framebuffer(ofs->color);
|
2015-02-12 18:54:41 +01:00
|
|
|
else {
|
|
|
|
GPU_framebuffer_bind_no_save(ofs->fb, 0);
|
|
|
|
}
|
2009-10-28 18:03:04 +00:00
|
|
|
}
|
|
|
|
|
2015-02-12 18:54:41 +01:00
|
|
|
void GPU_offscreen_unbind(GPUOffScreen *ofs, bool restore)
|
2009-10-28 18:03:04 +00:00
|
|
|
{
|
2015-02-12 18:54:41 +01:00
|
|
|
if (restore)
|
|
|
|
GPU_framebuffer_texture_unbind(ofs->fb, ofs->color);
|
2009-10-28 18:03:04 +00:00
|
|
|
GPU_framebuffer_restore();
|
|
|
|
glEnable(GL_SCISSOR_TEST);
|
|
|
|
}
|
|
|
|
|
2011-10-28 16:57:06 +00:00
|
|
|
void GPU_offscreen_read_pixels(GPUOffScreen *ofs, int type, void *pixels)
|
|
|
|
{
|
2015-09-14 13:18:43 +10:00
|
|
|
glReadPixels(0, 0, ofs->color->w_orig, ofs->color->h_orig, GL_RGBA, type, pixels);
|
2011-10-28 16:57:06 +00:00
|
|
|
}
|
|
|
|
|
2015-03-16 22:57:56 -04:00
|
|
|
int GPU_offscreen_width(const GPUOffScreen *ofs)
|
2013-03-15 19:56:33 +00:00
|
|
|
{
|
2015-09-14 13:18:43 +10:00
|
|
|
return ofs->color->w_orig;
|
2013-03-15 19:56:33 +00:00
|
|
|
}
|
|
|
|
|
2015-03-16 22:57:56 -04:00
|
|
|
int GPU_offscreen_height(const GPUOffScreen *ofs)
|
2013-03-15 19:56:33 +00:00
|
|
|
{
|
2015-09-14 13:18:43 +10:00
|
|
|
return ofs->color->h_orig;
|
2013-03-15 19:56:33 +00:00
|
|
|
}
|
|
|
|
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
/* GPUShader */
|
|
|
|
|
|
|
|
struct GPUShader {
|
2015-03-23 15:29:42 -04:00
|
|
|
GLhandleARB object; /* handle for full shader */
|
|
|
|
GLhandleARB vertex; /* handle for vertex shader */
|
|
|
|
GLhandleARB fragment; /* handle for fragment shader */
|
|
|
|
GLhandleARB geometry; /* handle for geometry shader */
|
|
|
|
GLhandleARB lib; /* handle for libment shader */
|
|
|
|
int totattrib; /* total number of attributes */
|
|
|
|
int uniforms; /* required uniforms */
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
};
|
|
|
|
|
2015-04-09 20:20:33 +02:00
|
|
|
struct GPUProgram {
|
|
|
|
GPUProgramType type;
|
|
|
|
GLuint prog;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static void shader_print_errors(const char *task, const char *log, const char **code, int totcode)
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
{
|
2014-08-29 16:23:37 +02:00
|
|
|
int i;
|
2015-03-23 15:19:54 +01:00
|
|
|
int line = 1;
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
|
|
|
|
fprintf(stderr, "GPUShader: %s error:\n", task);
|
|
|
|
|
2014-08-29 16:23:37 +02:00
|
|
|
for (i = 0; i < totcode; i++) {
|
|
|
|
const char *c, *pos, *end = code[i] + strlen(code[i]);
|
2014-12-03 17:26:43 -02:00
|
|
|
|
|
|
|
if ((G.debug & G_DEBUG)) {
|
2014-08-29 16:23:37 +02:00
|
|
|
fprintf(stderr, "===== shader string %d ====\n", i + 1);
|
|
|
|
|
|
|
|
c = code[i];
|
|
|
|
while ((c < end) && (pos = strchr(c, '\n'))) {
|
|
|
|
fprintf(stderr, "%2d ", line);
|
2015-03-23 15:29:42 -04:00
|
|
|
fwrite(c, (pos + 1) - c, 1, stderr);
|
|
|
|
c = pos + 1;
|
2014-08-29 16:23:37 +02:00
|
|
|
line++;
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(stderr, "%s", c);
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
}
|
|
|
|
}
|
2014-08-29 16:23:37 +02:00
|
|
|
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
fprintf(stderr, "%s\n", log);
|
|
|
|
}
|
|
|
|
|
2015-07-20 16:08:06 +02:00
|
|
|
static const char *gpu_shader_version(bool use_opensubdiv)
|
2014-07-11 19:17:29 +03:00
|
|
|
{
|
2015-07-20 16:08:06 +02:00
|
|
|
#ifdef WITH_OPENSUBDIV
|
|
|
|
if (use_opensubdiv) {
|
2015-08-03 15:27:06 +02:00
|
|
|
return "#version 130\n";
|
2015-07-20 16:08:06 +02:00
|
|
|
}
|
2015-07-21 09:54:23 +10:00
|
|
|
#else
|
|
|
|
UNUSED_VARS(use_opensubdiv);
|
2015-07-20 16:08:06 +02:00
|
|
|
#endif
|
|
|
|
|
2014-07-11 19:17:29 +03:00
|
|
|
/* turn on glsl 1.30 for bicubic bump mapping and ATI clipping support */
|
|
|
|
if (GLEW_VERSION_3_0 &&
|
|
|
|
(GPU_bicubic_bump_support() || GPU_type_matches(GPU_DEVICE_ATI, GPU_OS_ANY, GPU_DRIVER_ANY)))
|
|
|
|
{
|
|
|
|
return "#version 130\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-08-20 16:05:24 +03:00
|
|
|
static void gpu_shader_standard_extensions(char defines[MAX_EXT_DEFINE_LENGTH], bool use_opensubdiv)
|
2013-04-02 16:37:31 +00:00
|
|
|
{
|
2015-07-20 16:08:06 +02:00
|
|
|
#ifdef WITH_OPENSUBDIV
|
2015-08-20 16:05:24 +03:00
|
|
|
if (use_opensubdiv) {
|
|
|
|
strcat(defines, "#extension GL_ARB_texture_query_lod: enable\n"
|
|
|
|
"#extension GL_ARB_gpu_shader5 : enable\n"
|
|
|
|
"#extension GL_ARB_explicit_attrib_location : require\n");
|
|
|
|
}
|
2015-08-23 18:20:08 +03:00
|
|
|
else if (GPU_bicubic_bump_support())
|
|
|
|
strcat(defines, "#extension GL_ARB_texture_query_lod: enable\n");
|
2015-07-20 16:08:06 +02:00
|
|
|
#else
|
2015-03-23 15:29:42 -04:00
|
|
|
/* need this extension for high quality bump mapping */
|
2014-07-11 19:17:29 +03:00
|
|
|
if (GPU_bicubic_bump_support())
|
2015-03-03 17:47:31 +01:00
|
|
|
strcat(defines, "#extension GL_ARB_texture_query_lod: enable\n");
|
2015-08-20 16:05:24 +03:00
|
|
|
(void) use_opensubdiv;
|
2015-07-20 16:08:06 +02:00
|
|
|
#endif
|
2013-04-02 16:37:31 +00:00
|
|
|
|
2015-03-03 17:47:31 +01:00
|
|
|
if (GPU_geometry_shader_support())
|
|
|
|
strcat(defines, "#extension GL_EXT_geometry_shader4: enable\n");
|
|
|
|
|
|
|
|
if (GPU_instanced_drawing_support()) {
|
|
|
|
strcat(defines, "#extension GL_EXT_gpu_shader4: enable\n");
|
2015-03-20 15:26:13 +01:00
|
|
|
strcat(defines, "#extension GL_ARB_draw_instanced: enable\n");
|
2015-03-03 17:47:31 +01:00
|
|
|
}
|
2013-04-02 16:37:31 +00:00
|
|
|
}
|
|
|
|
|
2015-07-20 16:08:06 +02:00
|
|
|
static void gpu_shader_standard_defines(bool use_opensubdiv,
|
|
|
|
char defines[MAX_DEFINE_LENGTH])
|
2013-03-13 18:00:13 +00:00
|
|
|
{
|
|
|
|
/* some useful defines to detect GPU type */
|
2014-07-11 19:17:29 +03:00
|
|
|
if (GPU_type_matches(GPU_DEVICE_ATI, GPU_OS_ANY, GPU_DRIVER_ANY)) {
|
|
|
|
strcat(defines, "#define GPU_ATI\n");
|
|
|
|
if (GLEW_VERSION_3_0)
|
2014-08-29 16:23:37 +02:00
|
|
|
strcat(defines, "#define CLIP_WORKAROUND\n");
|
2014-07-11 19:17:29 +03:00
|
|
|
}
|
2013-06-13 11:59:28 +00:00
|
|
|
else if (GPU_type_matches(GPU_DEVICE_NVIDIA, GPU_OS_ANY, GPU_DRIVER_ANY))
|
2014-07-11 19:17:29 +03:00
|
|
|
strcat(defines, "#define GPU_NVIDIA\n");
|
2013-06-13 11:59:28 +00:00
|
|
|
else if (GPU_type_matches(GPU_DEVICE_INTEL, GPU_OS_ANY, GPU_DRIVER_ANY))
|
2014-07-11 19:17:29 +03:00
|
|
|
strcat(defines, "#define GPU_INTEL\n");
|
|
|
|
|
|
|
|
if (GPU_bicubic_bump_support())
|
|
|
|
strcat(defines, "#define BUMP_BICUBIC\n");
|
2015-07-20 16:08:06 +02:00
|
|
|
|
|
|
|
#ifdef WITH_OPENSUBDIV
|
|
|
|
/* TODO(sergey): Check whether we actually compiling shader for
|
|
|
|
* the OpenSubdiv mesh.
|
|
|
|
*/
|
|
|
|
if (use_opensubdiv) {
|
|
|
|
strcat(defines, "#define USE_OPENSUBDIV\n");
|
|
|
|
|
|
|
|
/* TODO(sergey): not strictly speaking a define, but this is
|
|
|
|
* a global typedef which we don't have better place to define
|
|
|
|
* in yet.
|
|
|
|
*/
|
|
|
|
strcat(defines, "struct VertexData {\n"
|
|
|
|
" vec4 position;\n"
|
|
|
|
" vec3 normal;\n"
|
|
|
|
" vec2 uv;"
|
|
|
|
"};\n");
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
UNUSED_VARS(use_opensubdiv);
|
|
|
|
#endif
|
|
|
|
|
2014-07-11 19:17:29 +03:00
|
|
|
return;
|
2013-03-13 18:00:13 +00:00
|
|
|
}
|
|
|
|
|
2015-04-09 20:20:33 +02:00
|
|
|
void GPU_program_bind(GPUProgram *program)
|
|
|
|
{
|
|
|
|
glEnable(program->type);
|
|
|
|
glBindProgramARB(program->type, program->prog);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPU_program_unbind(GPUProgram *program)
|
|
|
|
{
|
|
|
|
glDisable(program->type);
|
|
|
|
glBindProgramARB(program->type, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GPUProgram *GPU_program_shader_create(GPUProgramType type, const char *code)
|
|
|
|
{
|
|
|
|
GPUProgram *program;
|
|
|
|
GLint error_pos, is_native;
|
|
|
|
|
|
|
|
if (!(GLEW_ARB_fragment_program && type == GPU_PROGRAM_TYPE_FRAGMENT))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
program = MEM_callocN(sizeof(GPUProgram), "GPUProgram");
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case GPU_PROGRAM_TYPE_FRAGMENT:
|
|
|
|
program->type = GL_FRAGMENT_PROGRAM_ARB;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* create the object and set its code string */
|
|
|
|
glGenProgramsARB(1, &program->prog);
|
|
|
|
glBindProgramARB(program->type, program->prog);
|
|
|
|
|
|
|
|
glProgramStringARB(program->type, GL_PROGRAM_FORMAT_ASCII_ARB, (GLsizei)strlen(code), code);
|
|
|
|
|
|
|
|
glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &error_pos);
|
|
|
|
glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_UNDER_NATIVE_LIMITS_ARB, &is_native);
|
|
|
|
if ((error_pos == -1) && (is_native == 1)) {
|
|
|
|
return program;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* glGetError is set before that, clear it */
|
|
|
|
while (glGetError() != GL_NO_ERROR)
|
|
|
|
;
|
|
|
|
shader_print_errors("compile", (const char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB), &code, 1);
|
|
|
|
MEM_freeN(program);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPU_program_free(GPUProgram *program)
|
|
|
|
{
|
|
|
|
glDeleteProgramsARB(1, &program->prog);
|
|
|
|
MEM_freeN(program);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPU_program_parameter_4f(GPUProgram *program, unsigned int location, float x, float y, float z, float w)
|
|
|
|
{
|
|
|
|
glProgramLocalParameter4fARB(program->type, location, x, y, z, w);
|
|
|
|
}
|
|
|
|
|
2015-09-16 22:38:46 +05:00
|
|
|
GPUShader *GPU_shader_create(const char *vertexcode,
|
|
|
|
const char *fragcode,
|
|
|
|
const char *geocode,
|
|
|
|
const char *libcode,
|
|
|
|
const char *defines,
|
|
|
|
int input,
|
|
|
|
int output,
|
|
|
|
int number)
|
|
|
|
{
|
|
|
|
return GPU_shader_create_ex(vertexcode,
|
|
|
|
fragcode,
|
|
|
|
geocode,
|
|
|
|
libcode,
|
|
|
|
defines,
|
|
|
|
input,
|
|
|
|
output,
|
|
|
|
number,
|
|
|
|
GPU_SHADER_FLAGS_NONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
GPUShader *GPU_shader_create_ex(const char *vertexcode,
|
|
|
|
const char *fragcode,
|
|
|
|
const char *geocode,
|
|
|
|
const char *libcode,
|
|
|
|
const char *defines,
|
|
|
|
int input,
|
|
|
|
int output,
|
|
|
|
int number,
|
|
|
|
const int flags)
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
{
|
2015-08-03 15:27:06 +02:00
|
|
|
#ifdef WITH_OPENSUBDIV
|
2015-07-20 16:08:06 +02:00
|
|
|
/* TODO(sergey): used to add #version 150 to the geometry shader.
|
2015-09-14 02:21:15 +10:00
|
|
|
* Could safely be renamed to "use_geometry_code" since it's very
|
|
|
|
* likely any of geometry code will want to use GLSL 1.5.
|
2015-07-20 16:08:06 +02:00
|
|
|
*/
|
2015-09-16 22:38:46 +05:00
|
|
|
bool use_opensubdiv = (flags & GPU_SHADER_FLAGS_SPECIAL_OPENSUBDIV) != 0;
|
2015-07-20 16:08:06 +02:00
|
|
|
#else
|
|
|
|
bool use_opensubdiv = false;
|
|
|
|
#endif
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
GLint status;
|
|
|
|
GLcharARB log[5000];
|
|
|
|
GLsizei length = 0;
|
|
|
|
GPUShader *shader;
|
2014-07-11 19:17:29 +03:00
|
|
|
char standard_defines[MAX_DEFINE_LENGTH] = "";
|
2015-03-03 17:47:31 +01:00
|
|
|
char standard_extensions[MAX_EXT_DEFINE_LENGTH] = "";
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
|
2015-09-21 06:59:50 +10:00
|
|
|
#ifndef WITH_OPENSUBDIV
|
|
|
|
UNUSED_VARS(flags);
|
|
|
|
#endif
|
|
|
|
|
2015-03-03 17:47:31 +01:00
|
|
|
if (!GLEW_ARB_vertex_shader || !GLEW_ARB_fragment_shader || (geocode && !GPU_geometry_shader_support()))
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
shader = MEM_callocN(sizeof(GPUShader), "GPUShader");
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (vertexcode)
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
shader->vertex = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB);
|
2012-03-24 06:38:07 +00:00
|
|
|
if (fragcode)
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
shader->fragment = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);
|
2015-03-03 17:47:31 +01:00
|
|
|
if (geocode)
|
|
|
|
shader->geometry = glCreateShaderObjectARB(GL_GEOMETRY_SHADER_EXT);
|
|
|
|
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
shader->object = glCreateProgramObjectARB();
|
|
|
|
|
|
|
|
if (!shader->object ||
|
2012-05-24 16:35:45 +00:00
|
|
|
(vertexcode && !shader->vertex) ||
|
2015-03-03 17:47:31 +01:00
|
|
|
(fragcode && !shader->fragment) ||
|
|
|
|
(geocode && !shader->geometry))
|
2012-05-24 16:35:45 +00:00
|
|
|
{
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
fprintf(stderr, "GPUShader, object creation failed.\n");
|
|
|
|
GPU_shader_free(shader);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-07-20 16:08:06 +02:00
|
|
|
gpu_shader_standard_defines(use_opensubdiv, standard_defines);
|
2015-08-20 16:05:24 +03:00
|
|
|
gpu_shader_standard_extensions(standard_extensions, use_opensubdiv);
|
2014-07-11 19:17:29 +03:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (vertexcode) {
|
2014-07-11 19:17:29 +03:00
|
|
|
const char *source[5];
|
|
|
|
/* custom limit, may be too small, beware */
|
2013-02-26 00:49:42 +00:00
|
|
|
int num_source = 0;
|
|
|
|
|
2015-07-20 16:08:06 +02:00
|
|
|
source[num_source++] = gpu_shader_version(use_opensubdiv);
|
2015-03-03 17:47:31 +01:00
|
|
|
source[num_source++] = standard_extensions;
|
2014-07-11 19:17:29 +03:00
|
|
|
source[num_source++] = standard_defines;
|
2013-03-13 18:00:13 +00:00
|
|
|
|
2013-02-26 00:49:42 +00:00
|
|
|
if (defines) source[num_source++] = defines;
|
2015-03-03 17:47:31 +01:00
|
|
|
source[num_source++] = vertexcode;
|
2013-02-26 00:49:42 +00:00
|
|
|
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
glAttachObjectARB(shader->object, shader->vertex);
|
2013-02-26 00:49:42 +00:00
|
|
|
glShaderSourceARB(shader->vertex, num_source, source, NULL);
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
|
|
|
|
glCompileShaderARB(shader->vertex);
|
|
|
|
glGetObjectParameterivARB(shader->vertex, GL_OBJECT_COMPILE_STATUS_ARB, &status);
|
|
|
|
|
|
|
|
if (!status) {
|
|
|
|
glGetInfoLogARB(shader->vertex, sizeof(log), &length, log);
|
2014-08-29 16:23:37 +02:00
|
|
|
shader_print_errors("compile", log, source, num_source);
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
|
|
|
|
GPU_shader_free(shader);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (fragcode) {
|
2015-07-20 16:08:06 +02:00
|
|
|
const char *source[7];
|
2013-02-26 00:49:42 +00:00
|
|
|
int num_source = 0;
|
|
|
|
|
2015-07-20 16:08:06 +02:00
|
|
|
source[num_source++] = gpu_shader_version(use_opensubdiv);
|
2015-03-03 17:47:31 +01:00
|
|
|
source[num_source++] = standard_extensions;
|
2014-07-11 19:17:29 +03:00
|
|
|
source[num_source++] = standard_defines;
|
2013-03-13 18:00:13 +00:00
|
|
|
|
2015-07-20 16:08:06 +02:00
|
|
|
#ifdef WITH_OPENSUBDIV
|
|
|
|
/* TODO(sergey): Move to fragment shader source code generation. */
|
|
|
|
if (use_opensubdiv) {
|
|
|
|
source[num_source++] =
|
|
|
|
"#ifdef USE_OPENSUBDIV\n"
|
|
|
|
"in block {\n"
|
|
|
|
" VertexData v;\n"
|
|
|
|
"} inpt;\n"
|
|
|
|
"#endif\n";
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-02-26 00:49:42 +00:00
|
|
|
if (defines) source[num_source++] = defines;
|
|
|
|
if (libcode) source[num_source++] = libcode;
|
2015-03-03 17:47:31 +01:00
|
|
|
source[num_source++] = fragcode;
|
2008-09-19 16:09:26 +00:00
|
|
|
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
glAttachObjectARB(shader->object, shader->fragment);
|
2013-02-26 00:49:42 +00:00
|
|
|
glShaderSourceARB(shader->fragment, num_source, source, NULL);
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
|
|
|
|
glCompileShaderARB(shader->fragment);
|
|
|
|
glGetObjectParameterivARB(shader->fragment, GL_OBJECT_COMPILE_STATUS_ARB, &status);
|
|
|
|
|
|
|
|
if (!status) {
|
|
|
|
glGetInfoLogARB(shader->fragment, sizeof(log), &length, log);
|
2014-08-29 16:23:37 +02:00
|
|
|
shader_print_errors("compile", log, source, num_source);
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
|
|
|
|
GPU_shader_free(shader);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-03 17:47:31 +01:00
|
|
|
if (geocode) {
|
|
|
|
const char *source[6];
|
|
|
|
int num_source = 0;
|
|
|
|
|
2015-07-20 16:08:06 +02:00
|
|
|
source[num_source++] = gpu_shader_version(use_opensubdiv);
|
2015-03-03 17:47:31 +01:00
|
|
|
source[num_source++] = standard_extensions;
|
|
|
|
source[num_source++] = standard_defines;
|
|
|
|
|
|
|
|
if (defines) source[num_source++] = defines;
|
|
|
|
source[num_source++] = geocode;
|
|
|
|
|
|
|
|
glAttachObjectARB(shader->object, shader->geometry);
|
|
|
|
glShaderSourceARB(shader->geometry, num_source, source, NULL);
|
|
|
|
|
|
|
|
glCompileShaderARB(shader->geometry);
|
|
|
|
glGetObjectParameterivARB(shader->geometry, GL_OBJECT_COMPILE_STATUS_ARB, &status);
|
|
|
|
|
|
|
|
if (!status) {
|
|
|
|
glGetInfoLogARB(shader->geometry, sizeof(log), &length, log);
|
|
|
|
shader_print_errors("compile", log, source, num_source);
|
|
|
|
|
|
|
|
GPU_shader_free(shader);
|
|
|
|
return NULL;
|
|
|
|
}
|
2015-03-20 15:26:13 +01:00
|
|
|
|
2015-07-20 16:08:06 +02:00
|
|
|
if (!use_opensubdiv) {
|
|
|
|
GPU_shader_geometry_stage_primitive_io(shader, input, output, number);
|
|
|
|
}
|
2015-03-03 17:47:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-09 18:28:30 +00:00
|
|
|
#if 0
|
2012-03-24 06:38:07 +00:00
|
|
|
if (lib && lib->lib)
|
2012-03-09 18:28:30 +00:00
|
|
|
glAttachObjectARB(shader->object, lib->lib);
|
|
|
|
#endif
|
2008-09-15 18:15:11 +00:00
|
|
|
|
2015-07-20 16:08:06 +02:00
|
|
|
#ifdef WITH_OPENSUBDIV
|
|
|
|
if (use_opensubdiv) {
|
|
|
|
glBindAttribLocation(shader->object, 0, "position");
|
|
|
|
glBindAttribLocation(shader->object, 1, "normal");
|
|
|
|
GPU_shader_geometry_stage_primitive_io(shader,
|
|
|
|
GL_LINES_ADJACENCY_EXT,
|
|
|
|
GL_TRIANGLE_STRIP,
|
|
|
|
4);
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
glLinkProgramARB(shader->object);
|
|
|
|
glGetObjectParameterivARB(shader->object, GL_OBJECT_LINK_STATUS_ARB, &status);
|
|
|
|
if (!status) {
|
|
|
|
glGetInfoLogARB(shader->object, sizeof(log), &length, log);
|
2014-08-29 16:23:37 +02:00
|
|
|
if (fragcode) shader_print_errors("linking", log, &fragcode, 1);
|
|
|
|
else if (vertexcode) shader_print_errors("linking", log, &vertexcode, 1);
|
|
|
|
else if (libcode) shader_print_errors("linking", log, &libcode, 1);
|
2015-03-03 17:47:31 +01:00
|
|
|
else if (geocode) shader_print_errors("linking", log, &geocode, 1);
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
|
|
|
|
GPU_shader_free(shader);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-07-20 16:08:06 +02:00
|
|
|
#ifdef WITH_OPENSUBDIV
|
|
|
|
/* TODO(sergey): Find a better place for this. */
|
2015-08-06 01:09:07 +02:00
|
|
|
if (use_opensubdiv && GLEW_VERSION_4_1) {
|
2015-07-20 16:08:06 +02:00
|
|
|
glProgramUniform1i(shader->object,
|
|
|
|
glGetUniformLocation(shader->object, "FVarDataBuffer"),
|
|
|
|
31); /* GL_TEXTURE31 */
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
return shader;
|
|
|
|
}
|
|
|
|
|
2008-09-19 16:09:26 +00:00
|
|
|
#if 0
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
GPUShader *GPU_shader_create_lib(const char *code)
|
|
|
|
{
|
|
|
|
GLint status;
|
|
|
|
GLcharARB log[5000];
|
|
|
|
GLsizei length = 0;
|
|
|
|
GPUShader *shader;
|
|
|
|
|
|
|
|
if (!GLEW_ARB_vertex_shader || !GLEW_ARB_fragment_shader)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
shader = MEM_callocN(sizeof(GPUShader), "GPUShader");
|
|
|
|
|
|
|
|
shader->lib = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);
|
|
|
|
|
|
|
|
if (!shader->lib) {
|
|
|
|
fprintf(stderr, "GPUShader, object creation failed.\n");
|
|
|
|
GPU_shader_free(shader);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
glShaderSourceARB(shader->lib, 1, (const char**)&code, NULL);
|
|
|
|
|
|
|
|
glCompileShaderARB(shader->lib);
|
|
|
|
glGetObjectParameterivARB(shader->lib, GL_OBJECT_COMPILE_STATUS_ARB, &status);
|
|
|
|
|
|
|
|
if (!status) {
|
|
|
|
glGetInfoLogARB(shader->lib, sizeof(log), &length, log);
|
|
|
|
shader_print_errors("compile", log, code);
|
|
|
|
|
|
|
|
GPU_shader_free(shader);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return shader;
|
|
|
|
}
|
2008-09-19 16:09:26 +00:00
|
|
|
#endif
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
|
|
|
|
void GPU_shader_bind(GPUShader *shader)
|
|
|
|
{
|
2015-02-16 21:19:12 +01:00
|
|
|
GPU_ASSERT_NO_GL_ERRORS("Pre Shader Bind");
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
glUseProgramObjectARB(shader->object);
|
2015-02-16 21:19:12 +01:00
|
|
|
GPU_ASSERT_NO_GL_ERRORS("Post Shader Bind");
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
}
|
|
|
|
|
2013-03-12 08:50:02 +00:00
|
|
|
void GPU_shader_unbind(void)
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
{
|
2015-02-16 21:19:12 +01:00
|
|
|
GPU_ASSERT_NO_GL_ERRORS("Pre Shader Unbind");
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
glUseProgramObjectARB(0);
|
2015-02-16 21:19:12 +01:00
|
|
|
GPU_ASSERT_NO_GL_ERRORS("Post Shader Unbind");
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GPU_shader_free(GPUShader *shader)
|
|
|
|
{
|
|
|
|
if (shader->lib)
|
|
|
|
glDeleteObjectARB(shader->lib);
|
|
|
|
if (shader->vertex)
|
|
|
|
glDeleteObjectARB(shader->vertex);
|
|
|
|
if (shader->fragment)
|
|
|
|
glDeleteObjectARB(shader->fragment);
|
|
|
|
if (shader->object)
|
|
|
|
glDeleteObjectARB(shader->object);
|
|
|
|
MEM_freeN(shader);
|
|
|
|
}
|
|
|
|
|
2010-12-03 17:05:21 +00:00
|
|
|
int GPU_shader_get_uniform(GPUShader *shader, const char *name)
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
{
|
|
|
|
return glGetUniformLocationARB(shader->object, name);
|
|
|
|
}
|
|
|
|
|
2015-02-12 18:54:41 +01:00
|
|
|
void GPU_shader_uniform_vector(GPUShader *UNUSED(shader), int location, int length, int arraysize, const float *value)
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
{
|
2015-08-07 16:16:23 +02:00
|
|
|
if (location == -1 || value == NULL)
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
return;
|
|
|
|
|
2015-02-16 21:19:12 +01:00
|
|
|
GPU_ASSERT_NO_GL_ERRORS("Pre Uniform Vector");
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
|
|
|
|
if (length == 1) glUniform1fvARB(location, arraysize, value);
|
|
|
|
else if (length == 2) glUniform2fvARB(location, arraysize, value);
|
|
|
|
else if (length == 3) glUniform3fvARB(location, arraysize, value);
|
|
|
|
else if (length == 4) glUniform4fvARB(location, arraysize, value);
|
|
|
|
else if (length == 9) glUniformMatrix3fvARB(location, arraysize, 0, value);
|
|
|
|
else if (length == 16) glUniformMatrix4fvARB(location, arraysize, 0, value);
|
|
|
|
|
2015-02-16 21:19:12 +01:00
|
|
|
GPU_ASSERT_NO_GL_ERRORS("Post Uniform Vector");
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
}
|
|
|
|
|
2015-03-03 17:47:31 +01:00
|
|
|
void GPU_shader_uniform_vector_int(GPUShader *UNUSED(shader), int location, int length, int arraysize, const int *value)
|
|
|
|
{
|
|
|
|
if (location == -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
GPU_ASSERT_NO_GL_ERRORS("Pre Uniform Vector");
|
|
|
|
|
|
|
|
if (length == 1) glUniform1ivARB(location, arraysize, value);
|
|
|
|
else if (length == 2) glUniform2ivARB(location, arraysize, value);
|
|
|
|
else if (length == 3) glUniform3ivARB(location, arraysize, value);
|
|
|
|
else if (length == 4) glUniform4ivARB(location, arraysize, value);
|
|
|
|
|
|
|
|
GPU_ASSERT_NO_GL_ERRORS("Post Uniform Vector");
|
|
|
|
}
|
|
|
|
|
2013-02-26 00:49:42 +00:00
|
|
|
void GPU_shader_uniform_int(GPUShader *UNUSED(shader), int location, int value)
|
|
|
|
{
|
|
|
|
if (location == -1)
|
|
|
|
return;
|
|
|
|
|
2015-02-16 21:19:12 +01:00
|
|
|
GPU_CHECK_ERRORS_AROUND(glUniform1iARB(location, value));
|
2013-02-26 00:49:42 +00:00
|
|
|
}
|
|
|
|
|
2015-03-03 17:47:31 +01:00
|
|
|
void GPU_shader_geometry_stage_primitive_io(GPUShader *shader, int input, int output, int number)
|
|
|
|
{
|
|
|
|
glProgramParameteriEXT(shader->object, GL_GEOMETRY_INPUT_TYPE_EXT, input);
|
|
|
|
glProgramParameteriEXT(shader->object, GL_GEOMETRY_OUTPUT_TYPE_EXT, output);
|
|
|
|
glProgramParameteriEXT(shader->object, GL_GEOMETRY_VERTICES_OUT_EXT, number);
|
|
|
|
}
|
|
|
|
|
2010-10-15 12:29:02 +00:00
|
|
|
void GPU_shader_uniform_texture(GPUShader *UNUSED(shader), int location, GPUTexture *tex)
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
{
|
|
|
|
GLenum arbnumber;
|
|
|
|
|
|
|
|
if (tex->number >= GG.maxtextures) {
|
2015-02-16 21:19:12 +01:00
|
|
|
fprintf(stderr, "Not enough texture slots.");
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (tex->number == -1)
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
return;
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (location == -1)
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
return;
|
|
|
|
|
2015-02-16 21:19:12 +01:00
|
|
|
GPU_ASSERT_NO_GL_ERRORS("Pre Uniform Texture");
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
|
|
|
|
arbnumber = (GLenum)((GLuint)GL_TEXTURE0_ARB + tex->number);
|
|
|
|
|
|
|
|
if (tex->number != 0) glActiveTextureARB(arbnumber);
|
2014-06-10 01:36:53 +03:00
|
|
|
if (tex->bindcode != 0)
|
|
|
|
glBindTexture(tex->target, tex->bindcode);
|
|
|
|
else
|
|
|
|
GPU_invalid_tex_bind(tex->target);
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
glUniform1iARB(location, tex->number);
|
|
|
|
glEnable(tex->target);
|
|
|
|
if (tex->number != 0) glActiveTextureARB(GL_TEXTURE0_ARB);
|
|
|
|
|
2015-02-16 21:19:12 +01:00
|
|
|
GPU_ASSERT_NO_GL_ERRORS("Post Uniform Texture");
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
}
|
|
|
|
|
2012-01-11 09:33:44 +00:00
|
|
|
int GPU_shader_get_attribute(GPUShader *shader, const char *name)
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
{
|
|
|
|
int index;
|
|
|
|
|
2015-02-16 21:19:12 +01:00
|
|
|
GPU_CHECK_ERRORS_AROUND(index = glGetAttribLocationARB(shader->object, name));
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
2012-05-01 02:50:17 +00:00
|
|
|
GPUShader *GPU_shader_get_builtin_shader(GPUBuiltinShader shader)
|
|
|
|
{
|
|
|
|
GPUShader *retval = NULL;
|
|
|
|
|
2012-05-01 20:08:23 +00:00
|
|
|
switch (shader) {
|
|
|
|
case GPU_SHADER_VSM_STORE:
|
|
|
|
if (!GG.shaders.vsm_store)
|
2015-03-20 15:26:13 +01:00
|
|
|
GG.shaders.vsm_store = GPU_shader_create(datatoc_gpu_shader_vsm_store_vert_glsl, datatoc_gpu_shader_vsm_store_frag_glsl, NULL, NULL, NULL, 0, 0, 0);
|
2012-05-01 20:08:23 +00:00
|
|
|
retval = GG.shaders.vsm_store;
|
|
|
|
break;
|
|
|
|
case GPU_SHADER_SEP_GAUSSIAN_BLUR:
|
|
|
|
if (!GG.shaders.sep_gaussian_blur)
|
2015-03-20 15:26:13 +01:00
|
|
|
GG.shaders.sep_gaussian_blur = GPU_shader_create(datatoc_gpu_shader_sep_gaussian_blur_vert_glsl, datatoc_gpu_shader_sep_gaussian_blur_frag_glsl, NULL, NULL, NULL, 0, 0, 0);
|
2012-05-01 20:08:23 +00:00
|
|
|
retval = GG.shaders.sep_gaussian_blur;
|
|
|
|
break;
|
2012-05-01 02:50:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (retval == NULL)
|
2015-06-19 12:29:06 +02:00
|
|
|
printf("Unable to create a GPUShader for builtin shader: %u\n", shader);
|
2012-05-01 02:50:17 +00:00
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2015-04-09 20:20:33 +02:00
|
|
|
GPUProgram *GPU_shader_get_builtin_program(GPUBuiltinProgram program)
|
|
|
|
{
|
|
|
|
GPUProgram *retval = NULL;
|
|
|
|
|
|
|
|
switch (program) {
|
|
|
|
case GPU_PROGRAM_SMOKE:
|
|
|
|
if (!GG.shaders.smoke)
|
|
|
|
GG.shaders.smoke = GPU_program_shader_create(GPU_PROGRAM_TYPE_FRAGMENT, datatoc_gpu_program_smoke_frag_glsl);
|
|
|
|
retval = GG.shaders.smoke;
|
|
|
|
break;
|
|
|
|
case GPU_PROGRAM_SMOKE_COLORED:
|
|
|
|
if (!GG.shaders.smoke_colored)
|
|
|
|
GG.shaders.smoke_colored = GPU_program_shader_create(GPU_PROGRAM_TYPE_FRAGMENT, datatoc_gpu_program_smoke_color_frag_glsl);
|
|
|
|
retval = GG.shaders.smoke_colored;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (retval == NULL)
|
2015-06-19 12:29:06 +02:00
|
|
|
printf("Unable to create a GPUProgram for builtin program: %u\n", program);
|
2015-04-09 20:20:33 +02:00
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2015-02-12 18:54:41 +01:00
|
|
|
#define MAX_DEFINES 100
|
|
|
|
|
|
|
|
GPUShader *GPU_shader_get_builtin_fx_shader(int effects, bool persp)
|
|
|
|
{
|
|
|
|
int offset;
|
|
|
|
char defines[MAX_DEFINES] = "";
|
|
|
|
/* avoid shaders out of range */
|
|
|
|
if (effects >= MAX_FX_SHADERS)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
offset = 2 * effects;
|
|
|
|
|
|
|
|
if (persp) {
|
|
|
|
offset += 1;
|
|
|
|
strcat(defines, "#define PERSP_MATRIX\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!GG.shaders.fx_shaders[offset]) {
|
2015-03-03 17:47:31 +01:00
|
|
|
GPUShader *shader;
|
|
|
|
|
2015-03-23 15:29:42 -04:00
|
|
|
switch (effects) {
|
2015-02-12 18:54:41 +01:00
|
|
|
case GPU_SHADER_FX_SSAO:
|
2015-03-20 15:26:13 +01:00
|
|
|
GG.shaders.fx_shaders[offset] = GPU_shader_create(datatoc_gpu_shader_fx_vert_glsl, datatoc_gpu_shader_fx_ssao_frag_glsl, NULL, datatoc_gpu_shader_fx_lib_glsl, defines, 0, 0, 0);
|
2015-02-12 18:54:41 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GPU_SHADER_FX_DEPTH_OF_FIELD_PASS_ONE:
|
|
|
|
strcat(defines, "#define FIRST_PASS\n");
|
2015-03-20 15:26:13 +01:00
|
|
|
GG.shaders.fx_shaders[offset] = GPU_shader_create(datatoc_gpu_shader_fx_dof_vert_glsl, datatoc_gpu_shader_fx_dof_frag_glsl, NULL, datatoc_gpu_shader_fx_lib_glsl, defines, 0, 0, 0);
|
2015-02-12 18:54:41 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GPU_SHADER_FX_DEPTH_OF_FIELD_PASS_TWO:
|
|
|
|
strcat(defines, "#define SECOND_PASS\n");
|
2015-03-20 15:26:13 +01:00
|
|
|
GG.shaders.fx_shaders[offset] = GPU_shader_create(datatoc_gpu_shader_fx_dof_vert_glsl, datatoc_gpu_shader_fx_dof_frag_glsl, NULL, datatoc_gpu_shader_fx_lib_glsl, defines, 0, 0, 0);
|
2015-02-12 18:54:41 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GPU_SHADER_FX_DEPTH_OF_FIELD_PASS_THREE:
|
|
|
|
strcat(defines, "#define THIRD_PASS\n");
|
2015-03-20 15:26:13 +01:00
|
|
|
GG.shaders.fx_shaders[offset] = GPU_shader_create(datatoc_gpu_shader_fx_dof_vert_glsl, datatoc_gpu_shader_fx_dof_frag_glsl, NULL, datatoc_gpu_shader_fx_lib_glsl, defines, 0, 0, 0);
|
2015-02-12 18:54:41 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GPU_SHADER_FX_DEPTH_OF_FIELD_PASS_FOUR:
|
|
|
|
strcat(defines, "#define FOURTH_PASS\n");
|
2015-03-20 15:26:13 +01:00
|
|
|
GG.shaders.fx_shaders[offset] = GPU_shader_create(datatoc_gpu_shader_fx_dof_vert_glsl, datatoc_gpu_shader_fx_dof_frag_glsl, NULL, datatoc_gpu_shader_fx_lib_glsl, defines, 0, 0, 0);
|
2015-02-12 18:54:41 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GPU_SHADER_FX_DEPTH_OF_FIELD_PASS_FIVE:
|
|
|
|
strcat(defines, "#define FIFTH_PASS\n");
|
2015-03-20 15:26:13 +01:00
|
|
|
GG.shaders.fx_shaders[offset] = GPU_shader_create(datatoc_gpu_shader_fx_dof_vert_glsl, datatoc_gpu_shader_fx_dof_frag_glsl, NULL, datatoc_gpu_shader_fx_lib_glsl, defines, 0, 0, 0);
|
2015-03-03 17:47:31 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GPU_SHADER_FX_DEPTH_OF_FIELD_HQ_PASS_ONE:
|
|
|
|
strcat(defines, "#define FIRST_PASS\n");
|
2015-03-20 15:26:13 +01:00
|
|
|
GG.shaders.fx_shaders[offset] = GPU_shader_create(datatoc_gpu_shader_fx_dof_hq_vert_glsl, datatoc_gpu_shader_fx_dof_hq_frag_glsl, NULL, datatoc_gpu_shader_fx_lib_glsl, defines, 0, 0, 0);
|
2015-03-03 17:47:31 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GPU_SHADER_FX_DEPTH_OF_FIELD_HQ_PASS_TWO:
|
|
|
|
strcat(defines, "#define SECOND_PASS\n");
|
2015-03-20 15:26:13 +01:00
|
|
|
shader = GPU_shader_create(datatoc_gpu_shader_fx_dof_hq_vert_glsl, datatoc_gpu_shader_fx_dof_hq_frag_glsl, datatoc_gpu_shader_fx_dof_hq_geo_glsl, datatoc_gpu_shader_fx_lib_glsl,
|
|
|
|
defines, GL_POINTS, GL_TRIANGLE_STRIP, 4);
|
|
|
|
GG.shaders.fx_shaders[offset] = shader;
|
2015-03-03 17:47:31 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GPU_SHADER_FX_DEPTH_OF_FIELD_HQ_PASS_THREE:
|
|
|
|
strcat(defines, "#define THIRD_PASS\n");
|
2015-03-20 15:26:13 +01:00
|
|
|
GG.shaders.fx_shaders[offset] = GPU_shader_create(datatoc_gpu_shader_fx_dof_hq_vert_glsl, datatoc_gpu_shader_fx_dof_hq_frag_glsl, NULL, datatoc_gpu_shader_fx_lib_glsl, defines, 0, 0, 0);
|
2015-02-12 18:54:41 +01:00
|
|
|
break;
|
2015-02-17 18:08:28 +01:00
|
|
|
|
|
|
|
case GPU_SHADER_FX_DEPTH_RESOLVE:
|
2015-03-20 15:26:13 +01:00
|
|
|
GG.shaders.fx_shaders[offset] = GPU_shader_create(datatoc_gpu_shader_fx_vert_glsl, datatoc_gpu_shader_fx_depth_resolve_glsl, NULL, NULL, defines, 0, 0, 0);
|
2015-02-12 18:54:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return GG.shaders.fx_shaders[offset];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-01 09:54:00 +00:00
|
|
|
void GPU_shader_free_builtin_shaders(void)
|
2012-05-01 02:50:17 +00:00
|
|
|
{
|
2015-02-12 18:54:41 +01:00
|
|
|
int i;
|
|
|
|
|
2012-05-01 20:08:23 +00:00
|
|
|
if (GG.shaders.vsm_store) {
|
2015-04-09 20:20:33 +02:00
|
|
|
GPU_shader_free(GG.shaders.vsm_store);
|
2012-05-01 02:50:17 +00:00
|
|
|
GG.shaders.vsm_store = NULL;
|
|
|
|
}
|
|
|
|
|
2012-05-01 20:08:23 +00:00
|
|
|
if (GG.shaders.sep_gaussian_blur) {
|
2015-04-09 20:20:33 +02:00
|
|
|
GPU_shader_free(GG.shaders.sep_gaussian_blur);
|
2012-05-01 02:50:17 +00:00
|
|
|
GG.shaders.sep_gaussian_blur = NULL;
|
|
|
|
}
|
2015-02-12 18:54:41 +01:00
|
|
|
|
2015-04-09 20:20:33 +02:00
|
|
|
if (GG.shaders.smoke) {
|
|
|
|
GPU_program_free(GG.shaders.smoke);
|
|
|
|
GG.shaders.smoke = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GG.shaders.smoke_colored) {
|
|
|
|
GPU_program_free(GG.shaders.smoke_colored);
|
|
|
|
GG.shaders.smoke_colored = NULL;
|
|
|
|
}
|
|
|
|
|
2015-02-12 18:54:41 +01:00
|
|
|
for (i = 0; i < 2 * MAX_FX_SHADERS; i++) {
|
|
|
|
if (GG.shaders.fx_shaders[i]) {
|
2015-04-09 20:20:33 +02:00
|
|
|
GPU_shader_free(GG.shaders.fx_shaders[i]);
|
2015-02-12 18:54:41 +01:00
|
|
|
GG.shaders.fx_shaders[i] = NULL;
|
|
|
|
}
|
|
|
|
}
|
2012-05-01 02:50:17 +00:00
|
|
|
}
|
|
|
|
|
2015-04-24 14:11:05 +02:00
|
|
|
bool GPU_mem_stats_supported(void)
|
|
|
|
{
|
|
|
|
return (GLEW_NVX_gpu_memory_info || (GLEW_ATI_meminfo)) && (G.debug & G_DEBUG_GPU_MEM);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GPU_mem_stats_get(int *totalmem, int *freemem)
|
|
|
|
{
|
|
|
|
if (GLEW_NVX_gpu_memory_info) {
|
|
|
|
/* returned value in Kb */
|
|
|
|
glGetIntegerv(GL_GPU_MEMORY_INFO_TOTAL_AVAILABLE_MEMORY_NVX, totalmem);
|
|
|
|
|
|
|
|
glGetIntegerv(GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX, freemem);
|
|
|
|
}
|
|
|
|
else if (GLEW_ATI_meminfo) {
|
|
|
|
int stats[4];
|
|
|
|
|
|
|
|
glGetIntegerv(GL_TEXTURE_FREE_MEMORY_ATI, stats);
|
|
|
|
*freemem = stats[0];
|
|
|
|
*totalmem = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*totalmem = 0;
|
|
|
|
*freemem = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-23 15:29:42 -04:00
|
|
|
#if 0 /* unused */
|
|
|
|
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
/* GPUPixelBuffer */
|
|
|
|
|
|
|
|
typedef struct GPUPixelBuffer {
|
|
|
|
GLuint bindcode[2];
|
|
|
|
GLuint current;
|
|
|
|
int datasize;
|
|
|
|
int numbuffers;
|
|
|
|
int halffloat;
|
|
|
|
} GPUPixelBuffer;
|
|
|
|
|
|
|
|
void GPU_pixelbuffer_free(GPUPixelBuffer *pb)
|
|
|
|
{
|
|
|
|
if (pb->bindcode[0])
|
|
|
|
glDeleteBuffersARB(pb->numbuffers, pb->bindcode);
|
|
|
|
MEM_freeN(pb);
|
|
|
|
}
|
|
|
|
|
|
|
|
GPUPixelBuffer *gpu_pixelbuffer_create(int x, int y, int halffloat, int numbuffers)
|
|
|
|
{
|
|
|
|
GPUPixelBuffer *pb;
|
|
|
|
|
|
|
|
if (!GLEW_ARB_multitexture || !GLEW_EXT_pixel_buffer_object)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
pb = MEM_callocN(sizeof(GPUPixelBuffer), "GPUPBO");
|
2015-03-23 15:29:42 -04:00
|
|
|
pb->datasize = x * y * 4 * (halffloat ? 16 : 8);
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
pb->numbuffers = numbuffers;
|
|
|
|
pb->halffloat = halffloat;
|
|
|
|
|
2011-11-11 13:09:14 +00:00
|
|
|
glGenBuffersARB(pb->numbuffers, pb->bindcode);
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
|
|
|
|
if (!pb->bindcode[0]) {
|
|
|
|
fprintf(stderr, "GPUPixelBuffer allocation failed\n");
|
|
|
|
GPU_pixelbuffer_free(pb);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pb;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPU_pixelbuffer_texture(GPUTexture *tex, GPUPixelBuffer *pb)
|
|
|
|
{
|
|
|
|
void *pixels;
|
|
|
|
int i;
|
|
|
|
|
2010-03-22 09:30:00 +00:00
|
|
|
glBindTexture(GL_TEXTURE_RECTANGLE_EXT, tex->bindcode);
|
2011-04-21 15:53:30 +00:00
|
|
|
|
|
|
|
for (i = 0; i < pb->numbuffers; i++) {
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, pb->bindcode[pb->current]);
|
|
|
|
glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_EXT, pb->datasize, NULL,
|
2011-04-21 15:53:30 +00:00
|
|
|
GL_STREAM_DRAW_ARB);
|
2011-04-21 13:11:51 +00:00
|
|
|
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
pixels = glMapBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, GL_WRITE_ONLY);
|
2015-03-23 15:29:42 -04:00
|
|
|
|
|
|
|
# if 0
|
|
|
|
memcpy(pixels, _oImage.data(), pb->datasize);
|
|
|
|
# endif
|
2011-04-21 13:11:51 +00:00
|
|
|
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
if (!glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT)) {
|
2015-03-23 15:29:42 -04:00
|
|
|
fprintf(stderr, "Could not unmap OpenGL PBO\n");
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-22 09:30:00 +00:00
|
|
|
glBindTexture(GL_TEXTURE_RECTANGLE_EXT, 0);
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int pixelbuffer_map_into_gpu(GLuint bindcode)
|
|
|
|
{
|
|
|
|
void *pixels;
|
|
|
|
|
2010-03-22 09:30:00 +00:00
|
|
|
glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, bindcode);
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
pixels = glMapBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, GL_WRITE_ONLY);
|
|
|
|
|
|
|
|
/* do stuff in pixels */
|
|
|
|
|
2010-03-22 09:30:00 +00:00
|
|
|
if (!glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT)) {
|
2015-03-23 15:29:42 -04:00
|
|
|
fprintf(stderr, "Could not unmap OpenGL PBO\n");
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
return 0;
|
2010-03-22 09:30:00 +00:00
|
|
|
}
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pixelbuffer_copy_to_texture(GPUTexture *tex, GPUPixelBuffer *pb, GLuint bindcode)
|
|
|
|
{
|
|
|
|
GLenum type = (pb->halffloat)? GL_HALF_FLOAT_NV: GL_UNSIGNED_BYTE;
|
2010-03-22 09:30:00 +00:00
|
|
|
glBindTexture(GL_TEXTURE_RECTANGLE_EXT, tex->bindcode);
|
|
|
|
glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, bindcode);
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
|
2015-03-23 15:29:42 -04:00
|
|
|
glTexSubImage2D(GL_TEXTURE_RECTANGLE_EXT, 0, 0, 0, tex->w, tex->h, GL_RGBA, type, NULL);
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
|
|
|
|
glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, 0);
|
2010-03-22 09:30:00 +00:00
|
|
|
glBindTexture(GL_TEXTURE_RECTANGLE_EXT, 0);
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GPU_pixelbuffer_async_to_gpu(GPUTexture *tex, GPUPixelBuffer *pb)
|
|
|
|
{
|
|
|
|
int newbuffer;
|
|
|
|
|
|
|
|
if (pb->numbuffers == 1) {
|
|
|
|
pixelbuffer_copy_to_texture(tex, pb, pb->bindcode[0]);
|
|
|
|
pixelbuffer_map_into_gpu(pb->bindcode[0]);
|
|
|
|
}
|
|
|
|
else {
|
2015-03-23 15:29:42 -04:00
|
|
|
pb->current = (pb->current + 1) % pb->numbuffers;
|
|
|
|
newbuffer = (pb->current + 1) % pb->numbuffers;
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
|
|
|
|
pixelbuffer_map_into_gpu(pb->bindcode[newbuffer]);
|
|
|
|
pixelbuffer_copy_to_texture(tex, pb, pb->bindcode[pb->current]);
|
2010-03-22 09:30:00 +00:00
|
|
|
}
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
}
|
2015-03-23 15:29:42 -04:00
|
|
|
#endif /* unused */
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
|